Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update slippage logic #54

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions wasmbinding/bindings/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type SideQuery struct {
// PoolId string `json:"pool_id"`
// }

type Params struct {
}
type Params struct{}

// type PoolResponse struct {
// Admin string `json:"admin"`
Expand Down
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
Loading