Skip to content

Commit

Permalink
chore: update vpool AMM for new location of swapIn/swapOut
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Sep 30, 2021
1 parent c640696 commit 29ff794
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 10 additions & 9 deletions packages/zoe/src/contracts/vpool-xyk-amm/doublePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import { Far } from '@agoric/marshal';
import { AmountMath } from '@agoric/ertp';
import { assert, details as X } from '@agoric/assert';

import { swapIn as swapInPrice } from '../constantProduct/swapIn.js';
import { swapOut as swapOutPrice } from '../constantProduct/swapOut.js';
import { makeFeeRatio } from '../constantProduct/calcFees';
import {
calcSwapInPrices,
calcSwapOutPrices,
} from '../constantProduct/calcSwapPrices.js';

// Price calculations and swap using a pair of pools. Both pools map between RUN
// and some collateral. We arrange the trades so collateralInPool will have
Expand Down Expand Up @@ -84,21 +85,21 @@ export const makeDoublePool = (
// less.
// Notice that in the second call, the original amountOut is used, and in
// the third call, the original amountIn is used.
const interimInpoolPrices = swapInPrice(
const interimInpoolPrices = calcSwapInPrices(
amountIn,
inAllocation,
emptyCentralAmount,
protocolFeeRatio,
centralFeeRatio,
);
const outPoolPrices = swapInPrice(
const outPoolPrices = calcSwapInPrices(
interimInpoolPrices.swapperGets,
outAllocation,
amountOut,
protocolFeeRatio,
makeFeeRatio(poolFee, amountOut.brand),
);
const finalInPoolPrices = swapOutPrice(
const finalInPoolPrices = calcSwapOutPrices(
amountIn,
inAllocation,
outPoolPrices.swapperGives,
Expand Down Expand Up @@ -141,21 +142,21 @@ export const makeDoublePool = (
// Notice that the amountIn parameter to the first call to swapOutPrice
// specifies an empty amount. This is interpreted as "no limit", which is
// necessary since we can't guess a reasonable maximum of the central token.
const interimOutpoolPrices = swapOutPrice(
const interimOutpoolPrices = calcSwapOutPrices(
emptyCentralAmount,
outAllocation,
amountOut,
protocolFeeRatio,
centralFeeRatio,
);
const inpoolPrices = swapOutPrice(
const inpoolPrices = calcSwapOutPrices(
amountIn,
inAllocation,
interimOutpoolPrices.swapperGets,
protocolFeeRatio,
makeFeeRatio(poolFee, amountIn.brand),
);
const finalOutpoolPrices = swapInPrice(
const finalOutpoolPrices = calcSwapInPrices(
inpoolPrices.swapperGives,
outAllocation,
amountOut,
Expand Down
11 changes: 6 additions & 5 deletions packages/zoe/src/contracts/vpool-xyk-amm/singlePool.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check

import { Far } from '@agoric/marshal';

import { swapIn as swapInPrice } from '../constantProduct/swapIn.js';
import { swapOut as swapOutPrice } from '../constantProduct/swapOut.js';
import { makeFeeRatio } from '../constantProduct/calcFees';
import {
calcSwapInPrices,
calcSwapOutPrices,
} from '../constantProduct/calcSwapPrices.js';

/**
* @param {ContractFacet} zcf
Expand Down Expand Up @@ -47,7 +48,7 @@ export const makeSinglePool = (zcf, pool, protocolFee, poolFee, feeSeat) => {
};

const getPriceForInput = (amountIn, amountOut) => {
return swapInPrice(
return calcSwapInPrices(
amountIn,
getPools(),
amountOut,
Expand All @@ -62,7 +63,7 @@ export const makeSinglePool = (zcf, pool, protocolFee, poolFee, feeSeat) => {
};

const getPriceForOutput = (amountIn, amountOut) => {
return swapOutPrice(
return calcSwapOutPrices(
amountIn,
getPools(),
amountOut,
Expand Down

0 comments on commit 29ff794

Please sign in to comment.