Skip to content

Commit

Permalink
Add AMM safety check to ensure no leakage
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Jun 6, 2024
1 parent 25f9e21 commit 4e60551
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions x/market/keeper/msg_server_create_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package keeper

import (
"context"
"fmt"
"math/big"
"sort"
"strings"

Expand Down Expand Up @@ -60,6 +62,21 @@ func (k msgServer) CreateDrop(goCtx context.Context, msg *types.MsgCreateDrop) (

dropProduct := dropAmtMember1.Mul(dropAmtMember2)

tmp := big.NewInt(0)
tmp.Sqrt(dropProduct.BigInt())
sqrtDropProduct := sdk.NewIntFromBigInt(tmp)

// Drops basis is sqrt(XY)
// Change in XY should always be positive
// As XY total increases then in order to get proportional
// share (drop) then should pay the same per drop or more
// than Pool Creator. Pool creator drops = sqrt(XY).
if sqrtDropProduct.LT(drops) {
fmt.Printf("Sqrt Product: %s", sqrtDropProduct)
fmt.Printf("Drops: %s", drops)
return nil, sdkerrors.Wrapf(types.ErrProductLessThanDrops, "Sqrt of Product not greater than or equal to drops.")

Check failure on line 77 in x/market/keeper/msg_server_create_drop.go

View workflow job for this annotation

GitHub Actions / Build and Test

undefined: types.ErrProductLessThanDrops
}

coin1 := sdk.NewCoin(denom1, dropAmtMember1)
coin2 := sdk.NewCoin(denom2, dropAmtMember2)

Expand Down

0 comments on commit 4e60551

Please sign in to comment.