Skip to content

Instantly share code, notes, and snippets.

@anilhelvaci
Created September 5, 2022 23:26
Show Gist options
  • Save anilhelvaci/aee3a844292a0b9834ef88fa414757c4 to your computer and use it in GitHub Desktop.
Save anilhelvaci/aee3a844292a0b9834ef88fa414757c4 to your computer and use it in GitHub Desktop.
This code snippet shows how to push a price up in native Agoric AMM
export const moveFromCentralPriceUp = async (zoe,
ammPublicFacet,
secondaryR,
centralR,
liquidityIssuer,
upperBoundry,
swapInterval = 1n) => {
const {
swapSecondaryForCentral,
makeCentral,
makeSecondary,
} = await makeLiquidityInvitations(zoe, ammPublicFacet, secondaryR, centralR, liquidityIssuer);
const { amountOut } = await E(ammPublicFacet).getInputPrice(makeCentral(1n), makeSecondary(0n));
let inputPriceAmountOut = amountOut;
while (AmountMath.isGTE(upperBoundry.numerator, inputPriceAmountOut)) {
await swapSecondaryForCentral(swapInterval);
const { amountOut } = await E(ammPublicFacet).getInputPrice(makeCentral(1n), makeSecondary(0n));
inputPriceAmountOut = amountOut;
// console.log('INTER_INPUT_PRICE', inputPriceAmountOut);
}
return harden({ inputPriceAmountOut, swapInterval });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment