@@ -406,7 +406,8 @@ class InterchainMarketMaker {
406
406
const balanceOut = assetOut .balance .amount
407
407
const weightIn = assetIn .weight / 100
408
408
const weightOut = assetOut .weight / 100
409
- const amount = balanceIn * ((balanceOut / (balanceOut - amountOut .amount ) ** (weightOut / weightIn ) - 1 ))
409
+
410
+ const amount = balanceIn * ((balanceOut / (balanceOut - this .minusFees (amountOut .amount )) ** (weightOut / weightIn ) - 1 ))
410
411
411
412
abortTransactionUnless (amountIn .amount > amount )
412
413
@@ -1183,37 +1184,37 @@ function swap(msg: MsgSwapRequest): MsgSwapResponse {
1183
1184
1184
1185
const amm = new InterchainMarketMaker (pool );
1185
1186
1186
- let tokenOut : sdk .Coin | undefined ;
1187
+ let swappedToken : sdk .Coin | undefined ;
1187
1188
let tokenIn: sdk .Coin | undefined ;
1188
1189
let msgType: SwapMessageType ;
1189
1190
let expected: number
1190
1191
1191
1192
switch (msg .swapType ) {
1192
1193
case " LEFT" :
1193
1194
msgType = " LEFT_SWAP" ;
1194
- tokenOut = amm .leftSwap (msg .tokenIn , msg .tokenOut .denom );
1195
- expected = msg . tokenOut . amount * ( 1 - msg . slippage );
1195
+ swappedToken = amm .leftSwap (msg .tokenIn , msg .tokenOut .denom );
1196
+
1196
1197
break ;
1197
1198
case " RIGHT" :
1198
1199
msgType = " RIGHT_SWAP" ;
1199
- tokenOut = amm .rightSwap (msg .tokenIn , msg .tokenOut );
1200
+ swappedToken = amm .rightSwap (msg .tokenIn , msg .tokenOut );
1200
1201
expected = msg .tokenIn .amount * (1 - msg .slippage );
1201
1202
break ;
1202
1203
default :
1203
1204
abortTransactionUnless (false );
1204
1205
}
1205
1206
1206
1207
1207
- abortTransactionUnless (tokenOut ?.amount ? <= 0 );
1208
- abortTransactionUnless (tokenOut ?.amount ?.gte (expected ));
1208
+ abortTransactionUnless (swappedToken ?.amount ? <= 0 );
1209
+ abortTransactionUnless (swappedToken ?.amount ?.gte (expected ));
1209
1210
1210
1211
const lockErr = store .lockTokens (pool .counterPartyPort , pool .counterPartyChannel , msg .sender , msg .tokenIn );
1211
1212
abortTransactionUnless (lockErr === undefined );
1212
1213
1213
1214
const packet : IBCSwapPacketData = {
1214
1215
type: msgType ,
1215
1216
data: marshalJSON (msg ),
1216
- stateChange: { out: [tokenOut ] },
1217
+ stateChange: { out: [swappedToken ] },
1217
1218
};
1218
1219
1219
1220
const sendPacketErr = store .sendIBCSwapPacket (
0 commit comments