Skip to content

Commit

Permalink
chore: right swap swap fee fix
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Sep 22, 2023
1 parent fe21ff7 commit e541254
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions spec/app/ics-101-interchain-liquidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ class InterchainMarketMaker {
const balanceOut = assetOut.balance.amount
const weightIn = assetIn.weight / 100
const weightOut = assetOut.weight / 100
const amount = balanceIn * ((balanceOut/(balanceOut - amountOut.amount) ** (weightOut/weightIn) - 1))

const amount = balanceIn * ((balanceOut/(balanceOut -this.minusFees(amountOut.amount)) ** (weightOut/weightIn) - 1))

abortTransactionUnless(amountIn.amount > amount)

Expand Down Expand Up @@ -1183,37 +1184,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 e541254

Please sign in to comment.