From 29ff7947ec538614fdc8dee56b8ee30ad8d47a05 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 28 Sep 2021 09:23:30 -0700 Subject: [PATCH] chore: update vpool AMM for new location of swapIn/swapOut --- .../src/contracts/vpool-xyk-amm/doublePool.js | 19 ++++++++++--------- .../src/contracts/vpool-xyk-amm/singlePool.js | 11 ++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/zoe/src/contracts/vpool-xyk-amm/doublePool.js b/packages/zoe/src/contracts/vpool-xyk-amm/doublePool.js index 76981adff52d..0e046c0d736e 100644 --- a/packages/zoe/src/contracts/vpool-xyk-amm/doublePool.js +++ b/packages/zoe/src/contracts/vpool-xyk-amm/doublePool.js @@ -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 @@ -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, @@ -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, diff --git a/packages/zoe/src/contracts/vpool-xyk-amm/singlePool.js b/packages/zoe/src/contracts/vpool-xyk-amm/singlePool.js index 26337c96e8f2..741af5d2eb35 100644 --- a/packages/zoe/src/contracts/vpool-xyk-amm/singlePool.js +++ b/packages/zoe/src/contracts/vpool-xyk-amm/singlePool.js @@ -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 @@ -47,7 +48,7 @@ export const makeSinglePool = (zcf, pool, protocolFee, poolFee, feeSeat) => { }; const getPriceForInput = (amountIn, amountOut) => { - return swapInPrice( + return calcSwapInPrices( amountIn, getPools(), amountOut, @@ -62,7 +63,7 @@ export const makeSinglePool = (zcf, pool, protocolFee, poolFee, feeSeat) => { }; const getPriceForOutput = (amountIn, amountOut) => { - return swapOutPrice( + return calcSwapOutPrices( amountIn, getPools(), amountOut,