From 7faed4c793d6442b8afee0e34dcb4e6d975ffbb1 Mon Sep 17 00:00:00 2001 From: DedicatedDev Date: Fri, 22 Sep 2023 13:06:02 +0300 Subject: [PATCH] chore: add swapfee and swap result variable name neutralization --- .../app/ics-101-interchain-liquidity/README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/app/ics-101-interchain-liquidity/README.md b/spec/app/ics-101-interchain-liquidity/README.md index 85bde96ba..178fd6343 100644 --- a/spec/app/ics-101-interchain-liquidity/README.md +++ b/spec/app/ics-101-interchain-liquidity/README.md @@ -402,10 +402,12 @@ class InterchainMarketMaker { abortTransactionUnless(assetIn != null) const AssetOut = this.pool.findAssetByDenom(amountOut.denom) abortTransactionUnless(assetOut != null) - const balanceIn = assetIn.balance.amount + const balanceIn = this.minusFees(assetIn.balance.amount) const balanceOut = assetOut.balance.amount const weightIn = assetIn.weight / 100 const weightOut = assetOut.weight / 100 + const amount = this.minusFees(amountIn.amount) + const amount = balanceIn * ((balanceOut/(balanceOut - amountOut.amount) ** (weightOut/weightIn) - 1)) abortTransactionUnless(amountIn.amount > amount) @@ -1183,7 +1185,7 @@ function swap(msg: MsgSwapRequest): MsgSwapResponse { const amm = new InterchainMarketMaker(pool); - let tokenOut: sdk.Coin | undefined; + let swappedToken: sdk.Coin | undefined; let tokenIn: sdk.Coin | undefined; let msgType: SwapMessageType; let expected:number @@ -1191,12 +1193,12 @@ function swap(msg: MsgSwapRequest): MsgSwapResponse { switch (msg.swapType) { case "LEFT": msgType = "LEFT_SWAP"; - tokenOut = amm.leftSwap(msg.tokenIn, msg.tokenOut.denom); - expected = msg.tokenOut.amount * (1 - msg.slippage); + swappedToken = amm.leftSwap(msg.tokenIn, msg.tokenOut.denom); + break; case "RIGHT": msgType = "RIGHT_SWAP"; - tokenOut = amm.rightSwap(msg.tokenIn, msg.tokenOut); + swappedToken = amm.rightSwap(msg.tokenIn, msg.tokenOut); expected = msg.tokenIn.amount * (1 - msg.slippage); break; default: @@ -1204,8 +1206,8 @@ function swap(msg: MsgSwapRequest): MsgSwapResponse { } - abortTransactionUnless(tokenOut?.amount? <= 0); - abortTransactionUnless(tokenOut?.amount?.gte(expected)); + abortTransactionUnless(swappedToken?.amount? <= 0); + abortTransactionUnless(swappedToken?.amount?.gte(expected)); const lockErr = store.lockTokens(pool.counterPartyPort, pool.counterPartyChannel, msg.sender, msg.tokenIn); abortTransactionUnless(lockErr === undefined); @@ -1213,7 +1215,7 @@ function swap(msg: MsgSwapRequest): MsgSwapResponse { const packet: IBCSwapPacketData = { type: msgType, data: marshalJSON(msg), - stateChange: { out: [tokenOut] }, + stateChange: { out: [swappedToken] }, }; const sendPacketErr = store.sendIBCSwapPacket(