Skip to content

Commit

Permalink
feat: update slippage logic
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Feb 11, 2024
1 parent 1c8926f commit 9b6c9d0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions x/gmm/keeper/msg_server_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ func (k msgServer) Swap(goCtx context.Context, msg *types.MsgSwap) (*types.MsgSw
return nil, err
}
// Calculate the absolute difference between the expected and actual token output amounts
differ := msg.TokenOut.Amount.Sub(out.Amount).Abs()

differ := sdkmath.NewInt(0)
if out.Amount.LT(msg.TokenOut.Amount) {
differ = msg.TokenOut.Amount.Sub(out.Amount)
}
// Calculate the expected slippage. Make sure msg.Slippage is in the correct unit (e.g., percentage).
// Divide by 100 if msg.Slippage is a percentage.
expectedDiffer := msg.TokenOut.Amount.Mul(msg.Slippage).Quo(sdkmath.NewInt(100))
Expand Down

0 comments on commit 9b6c9d0

Please sign in to comment.