diff --git a/x/market/keeper/msg_server_create_drop.go b/x/market/keeper/msg_server_create_drop.go index e12117f..dda8e34 100644 --- a/x/market/keeper/msg_server_create_drop.go +++ b/x/market/keeper/msg_server_create_drop.go @@ -58,17 +58,11 @@ func (k msgServer) CreateDrop(goCtx context.Context, msg *types.MsgCreateDrop) ( return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "drops not >0") } - dropAmtMember1, dropAmtMember2, error := dropAmounts(drops.Add(sdk.NewIntFromUint64(1)), pool, member1, member2) + dropAmtMember1, dropAmtMember2, error := dropAmounts(drops, pool, member1, member2) if error != nil { return nil, error } - if ((dropAmtMember1.Mul(pool.Drops)).Quo(member1.Balance)).LTE((dropAmtMember2.Mul(pool.Drops)).Quo(member2.Balance)) { - drops = (dropAmtMember1.Mul(pool.Drops)).Quo(member1.Balance) - } else { - drops = (dropAmtMember2.Mul(pool.Drops)).Quo(member2.Balance) - } - if !drops.GT(sdk.ZeroInt()) { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "drops not >0") } @@ -77,12 +71,15 @@ func (k msgServer) CreateDrop(goCtx context.Context, msg *types.MsgCreateDrop) ( sqrtMembers := sqrtInt(member1.Balance.Mul(member2.Balance)) + var n uint64 = 1 + for (sqrtDropProduct.Quo(drops)).LT(sqrtMembers.Quo(pool.Drops)) { - dropAmtMember1, dropAmtMember2, error = dropAmounts(drops.Add(sdk.NewIntFromUint64(1)), pool, member1, member2) + dropAmtMember1, dropAmtMember2, error = dropAmounts(drops.Add(sdk.NewIntFromUint64(n)), pool, member1, member2) if error != nil { return nil, error } sqrtDropProduct = sqrtInt(dropAmtMember1.Mul(dropAmtMember2)) + n++ } dropProduct := dropAmtMember1.Mul(dropAmtMember2) diff --git a/x/market/keeper/msg_server_simulate_test.go b/x/market/keeper/msg_server_simulate_test.go index ae2f1f5..891d26b 100644 --- a/x/market/keeper/msg_server_simulate_test.go +++ b/x/market/keeper/msg_server_simulate_test.go @@ -88,7 +88,7 @@ func TestSimulate(t *testing.T) { users := []User{user1, user2, user3} - for i := 1; i < 1000000; i++ { + for i := 1; i < 200000; i++ { j := rand.IntN(6) k := rand.IntN(2)