Skip to content

Commit

Permalink
Update drop amounts calc without BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Jun 13, 2024
1 parent 853cb07 commit 39009b1
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions x/market/keeper/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,23 +433,13 @@ func dropAmounts(drops sdk.Int, pool types.Pool, member1 types.Member, member2 t
return sdk.ZeroInt(), sdk.ZeroInt(), status.Error(codes.InvalidArgument, "invalid drops")
}

// see `msg_server_redeem_drop` for our bigint strategy
// `dropAmtMember1 = (drops * member1.Balance) / pool.Drops`
tmp := big.NewInt(0)
tmp.Mul(drops.BigInt(), member1.Balance.BigInt())
tmp.Quo(tmp, pool.Drops.BigInt())
dropAmtMember1 := sdk.NewIntFromBigInt(tmp).Add(sdk.NewIntFromUint64(1))
tmp = big.NewInt(0)
dropAmtMember1 := (drops.Mul(member1.Balance)).Quo(pool.Drops)

if dropAmtMember1.LTE(sdk.ZeroInt()) {
return dropAmtMember1, sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrAmtZero, "%s", member1.DenomB)
}

// `dropAmtMember2 = (drops * member2.Balance) / pool.Drops`
tmp.Mul(drops.BigInt(), member2.Balance.BigInt())
tmp.Quo(tmp, pool.Drops.BigInt())
dropAmtMember2 := sdk.NewIntFromBigInt(tmp).Add(sdk.NewIntFromUint64(1))
//tmp = big.NewInt(0)
dropAmtMember2 := (dropAmtMember1.Mul(member2.Balance)).Quo(member1.Balance)

if dropAmtMember2.LTE(sdk.ZeroInt()) {
return dropAmtMember1, dropAmtMember2, sdkerrors.Wrapf(types.ErrAmtZero, "%s", member2.DenomB)
Expand Down

0 comments on commit 39009b1

Please sign in to comment.