Skip to content

Commit

Permalink
chore: add swapfee and swap result variable name neutralization
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Sep 22, 2023
1 parent fe21ff7 commit 7faed4c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spec/app/ics-101-interchain-liquidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1183,37 +1185,37 @@ 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

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:
abortTransactionUnless(false);
}


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);

const packet: IBCSwapPacketData = {
type: msgType,
data: marshalJSON(msg),
stateChange: { out: [tokenOut] },
stateChange: { out: [swappedToken] },
};

const sendPacketErr = store.sendIBCSwapPacket(
Expand Down

0 comments on commit 7faed4c

Please sign in to comment.