From d09689b875ffc4104376075819c7d22dcfc537a7 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Sun, 28 Jul 2024 21:11:10 -0400 Subject: [PATCH 1/8] core fix --- x/dex/keeper/core.go | 36 ++++++++++++++++++++---------------- x/dex/types/events.go | 4 ++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/x/dex/keeper/core.go b/x/dex/keeper/core.go index 04e0d29fa..9d72c051a 100644 --- a/x/dex/keeper/core.go +++ b/x/dex/keeper/core.go @@ -509,17 +509,21 @@ func (k Keeper) CancelLimitOrderCore( return types.ErrActiveLimitOrderNotFound } - amountToCancel := tranche.RemoveTokenIn(trancheUser) - trancheUser.SharesCancelled = trancheUser.SharesCancelled.Add(amountToCancel) + makerAmountToReturn := tranche.RemoveTokenIn(trancheUser) + _, takerAmountOut := tranche.Withdraw(trancheUser) - if amountToCancel.IsPositive() { - coinOut := sdk.NewCoin(tradePairID.MakerDenom, amountToCancel) + //TODO: delete me + trancheUser.SharesOwned = math.ZeroInt() + if makerAmountToReturn.IsPositive() || takerAmountOut.IsPositive() { + makerCoinOut := sdk.NewCoin(tradePairID.MakerDenom, makerAmountToReturn) + takerCoinOut := sdk.NewCoin(tradePairID.TakerDenom, takerAmountOut) + coinsOut := sdk.NewCoins(makerCoinOut, takerCoinOut) err := k.bankKeeper.SendCoinsFromModuleToAccount( ctx, types.ModuleName, callerAddr, - sdk.Coins{coinOut}, + coinsOut, ) if err != nil { return err @@ -528,6 +532,17 @@ func (k Keeper) CancelLimitOrderCore( k.SaveTrancheUser(ctx, trancheUser) k.SaveTranche(ctx, tranche) + pairID := tradePairID.MustPairID() + ctx.EventManager().EmitEvent(types.CancelLimitOrderEvent( + callerAddr, + pairID.Token0, + pairID.Token1, + tradePairID.MakerDenom, + tradePairID.TakerDenom, + coinsOut, + trancheKey, + )) + if trancheUser.OrderType.HasExpiration() { k.RemoveLimitOrderExpiration(ctx, *tranche.ExpirationTime, tranche.Key.KeyMarshal()) } @@ -535,17 +550,6 @@ func (k Keeper) CancelLimitOrderCore( return sdkerrors.Wrapf(types.ErrCancelEmptyLimitOrder, "%s", tranche.Key.TrancheKey) } - pairID := tradePairID.MustPairID() - ctx.EventManager().EmitEvent(types.CancelLimitOrderEvent( - callerAddr, - pairID.Token0, - pairID.Token1, - tradePairID.MakerDenom, - tradePairID.TakerDenom, - amountToCancel, - trancheKey, - )) - return nil } diff --git a/x/dex/types/events.go b/x/dex/types/events.go index bf3670855..4dd6ca2f4 100644 --- a/x/dex/types/events.go +++ b/x/dex/types/events.go @@ -157,7 +157,7 @@ func CancelLimitOrderEvent( token1 string, makerDenom string, tokenOut string, - amountOut math.Int, + coinsOut sdk.Coins, trancheKey string, ) sdk.Event { attrs := []sdk.Attribute{ @@ -168,7 +168,7 @@ func CancelLimitOrderEvent( sdk.NewAttribute(CancelLimitOrderEventToken1, token1), sdk.NewAttribute(CancelLimitOrderEventTokenIn, makerDenom), sdk.NewAttribute(CancelLimitOrderEventTokenOut, tokenOut), - sdk.NewAttribute(CancelLimitOrderEventAmountOut, amountOut.String()), + sdk.NewAttribute(CancelLimitOrderEventAmountOut, coinsOut.String()), sdk.NewAttribute(CancelLimitOrderEventTrancheKey, trancheKey), } From a1ad559d750c9dcfc0f28c11d664e88566cd2f79 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Sun, 28 Jul 2024 21:24:44 -0400 Subject: [PATCH 2/8] remove shares_cancelled --- .../dex/limit_order_tranche_user.proto | 6 - x/dex/genesis_test.go | 2 - x/dex/keeper/core.go | 11 +- .../integration_cancellimitorder_test.go | 18 +++ x/dex/keeper/limit_order_tranche_user.go | 1 - x/dex/keeper/limit_order_tranche_user_test.go | 4 - x/dex/types/limit_order_tranche.go | 3 +- x/dex/types/limit_order_tranche_user.go | 3 +- x/dex/types/limit_order_tranche_user.pb.go | 107 +++++------------- 9 files changed, 53 insertions(+), 102 deletions(-) diff --git a/proto/neutron/dex/limit_order_tranche_user.proto b/proto/neutron/dex/limit_order_tranche_user.proto index 5ceb413e5..db701b350 100644 --- a/proto/neutron/dex/limit_order_tranche_user.proto +++ b/proto/neutron/dex/limit_order_tranche_user.proto @@ -24,11 +24,5 @@ message LimitOrderTrancheUser { (gogoproto.nullable) = false, (gogoproto.jsontag) = "shares_withdrawn" ]; - string shares_cancelled = 7 [ - (gogoproto.moretags) = "yaml:\"shares_cancelled\"", - (gogoproto.customtype) = "cosmossdk.io/math.Int", - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "shares_cancelled" - ]; LimitOrderType order_type = 8; } diff --git a/x/dex/genesis_test.go b/x/dex/genesis_test.go index 06dae9b4e..ac944c274 100644 --- a/x/dex/genesis_test.go +++ b/x/dex/genesis_test.go @@ -27,7 +27,6 @@ func TestGenesis(t *testing.T) { Address: "fakeAddr", SharesOwned: math.NewInt(10), SharesWithdrawn: math.NewInt(0), - SharesCancelled: math.NewInt(0), }, { TradePairId: &types.TradePairID{ @@ -39,7 +38,6 @@ func TestGenesis(t *testing.T) { Address: "fakeAddr", SharesOwned: math.NewInt(10), SharesWithdrawn: math.NewInt(0), - SharesCancelled: math.NewInt(0), }, }, TickLiquidityList: []*types.TickLiquidity{ diff --git a/x/dex/keeper/core.go b/x/dex/keeper/core.go index 9d72c051a..03dea005f 100644 --- a/x/dex/keeper/core.go +++ b/x/dex/keeper/core.go @@ -512,8 +512,7 @@ func (k Keeper) CancelLimitOrderCore( makerAmountToReturn := tranche.RemoveTokenIn(trancheUser) _, takerAmountOut := tranche.Withdraw(trancheUser) - //TODO: delete me - trancheUser.SharesOwned = math.ZeroInt() + trancheUser.SharesWithdrawn = trancheUser.SharesOwned if makerAmountToReturn.IsPositive() || takerAmountOut.IsPositive() { makerCoinOut := sdk.NewCoin(tradePairID.MakerDenom, makerAmountToReturn) @@ -594,15 +593,13 @@ func (k Keeper) WithdrawFilledLimitOrderCore( // This is only relevant for inactive JIT and GoodTil limit orders remainingTokenIn = tranche.RemoveTokenIn(trancheUser) k.SaveInactiveTranche(ctx, tranche) - - // Treat the removed tokenIn as cancelled shares - trancheUser.SharesCancelled = trancheUser.SharesCancelled.Add(remainingTokenIn) - + // Since the order has already been filled we treat this as a complete withdrawal + trancheUser.SharesWithdrawn = trancheUser.SharesOwned } else { k.SetLimitOrderTranche(ctx, tranche) + trancheUser.SharesWithdrawn = trancheUser.SharesWithdrawn.Add(amountOutTokenIn) } - trancheUser.SharesWithdrawn = trancheUser.SharesWithdrawn.Add(amountOutTokenIn) } k.SaveTrancheUser(ctx, trancheUser) diff --git a/x/dex/keeper/integration_cancellimitorder_test.go b/x/dex/keeper/integration_cancellimitorder_test.go index 0b95f17f4..c88b7b2ac 100644 --- a/x/dex/keeper/integration_cancellimitorder_test.go +++ b/x/dex/keeper/integration_cancellimitorder_test.go @@ -284,3 +284,21 @@ func (s *DexTestSuite) TestCancelJITNextBlock() { s.aliceCancelsLimitSellFails(trancheKey, types.ErrActiveLimitOrderNotFound) s.assertAliceBalances(0, 0) } + +func (s *DexTestSuite) TestCancelWithdraw() { + s.fundAliceBalances(100, 100) + s.fundCarolBalances(100, 0) + + s.carolLimitSells("TokenA", 0, 100) + tk := s.aliceLimitSells("TokenA", 0, 100) + s.aliceLimitSells("TokenB", -1, 2) + s.aliceCancelsLimitSell(tk) + s.assertAliceBalances(101, 98) + s.aliceLimitSells("TokenB", -1, 96) + s.assertAliceBalances(197, 2) + s.aliceWithdrawsLimitSell(tk) + s.assertAliceBalances(197, 51) + s.assertCarolBalances(0, 0) + s.carolWithdrawsLimitSell(tk) + s.assertCarolBalances(0, 49) +} diff --git a/x/dex/keeper/limit_order_tranche_user.go b/x/dex/keeper/limit_order_tranche_user.go index 13ca0fc1c..9df5c072e 100644 --- a/x/dex/keeper/limit_order_tranche_user.go +++ b/x/dex/keeper/limit_order_tranche_user.go @@ -25,7 +25,6 @@ func (k Keeper) GetOrInitLimitOrderTrancheUser( Address: receiver, SharesOwned: math.ZeroInt(), SharesWithdrawn: math.ZeroInt(), - SharesCancelled: math.ZeroInt(), TickIndexTakerToMaker: tickIndex, TradePairId: tradePairID, OrderType: orderType, diff --git a/x/dex/keeper/limit_order_tranche_user_test.go b/x/dex/keeper/limit_order_tranche_user_test.go index 9a4014f36..b4e5cd563 100644 --- a/x/dex/keeper/limit_order_tranche_user_test.go +++ b/x/dex/keeper/limit_order_tranche_user_test.go @@ -24,7 +24,6 @@ func createNLimitOrderTrancheUser(keeper *keeper.Keeper, ctx sdk.Context, n int) TickIndexTakerToMaker: int64(i), SharesOwned: math.NewInt(100), SharesWithdrawn: math.ZeroInt(), - SharesCancelled: math.ZeroInt(), } items[i] = val keeper.SetLimitOrderTrancheUser(ctx, items[i]) @@ -43,7 +42,6 @@ func createNLimitOrderTrancheUserWithAddress(keeper *keeper.Keeper, ctx sdk.Cont TickIndexTakerToMaker: 0, SharesOwned: math.ZeroInt(), SharesWithdrawn: math.ZeroInt(), - SharesCancelled: math.ZeroInt(), } items[i] = val keeper.SetLimitOrderTrancheUser(ctx, items[i]) @@ -93,7 +91,6 @@ func (s *DexTestSuite) TestGetAllLimitOrders() { Address: s.alice.String(), SharesOwned: math.NewInt(10_000_000), SharesWithdrawn: math.NewInt(0), - SharesCancelled: math.NewInt(0), }, LOList[0], ) @@ -104,7 +101,6 @@ func (s *DexTestSuite) TestGetAllLimitOrders() { Address: s.alice.String(), SharesOwned: math.NewInt(10_000_000), SharesWithdrawn: math.NewInt(0), - SharesCancelled: math.NewInt(0), }, LOList[1], ) diff --git a/x/dex/types/limit_order_tranche.go b/x/dex/types/limit_order_tranche.go index 8f6a6cb20..faea72e3d 100644 --- a/x/dex/types/limit_order_tranche.go +++ b/x/dex/types/limit_order_tranche.go @@ -135,10 +135,9 @@ func (t *LimitOrderTranche) RemoveTokenIn( trancheUser *LimitOrderTrancheUser, ) (amountToRemove math.Int) { amountUnfilled := t.AmountUnfilled() - maxAmountToRemove := amountUnfilled.MulInt(trancheUser.SharesOwned). + amountToRemove = amountUnfilled.MulInt(trancheUser.SharesOwned). QuoInt(t.TotalMakerDenom). TruncateInt() - amountToRemove = maxAmountToRemove.Sub(trancheUser.SharesCancelled) t.ReservesMakerDenom = t.ReservesMakerDenom.Sub(amountToRemove) return amountToRemove diff --git a/x/dex/types/limit_order_tranche_user.go b/x/dex/types/limit_order_tranche_user.go index 90dcf34ac..51f923210 100644 --- a/x/dex/types/limit_order_tranche_user.go +++ b/x/dex/types/limit_order_tranche_user.go @@ -1,6 +1,5 @@ package types func (l LimitOrderTrancheUser) IsEmpty() bool { - sharesRemoved := l.SharesCancelled.Add(l.SharesWithdrawn) - return sharesRemoved.Equal(l.SharesOwned) + return l.SharesWithdrawn.Equal(l.SharesOwned) } diff --git a/x/dex/types/limit_order_tranche_user.pb.go b/x/dex/types/limit_order_tranche_user.pb.go index 75737b1c2..b863f41e1 100644 --- a/x/dex/types/limit_order_tranche_user.pb.go +++ b/x/dex/types/limit_order_tranche_user.pb.go @@ -32,7 +32,6 @@ type LimitOrderTrancheUser struct { Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"` SharesOwned cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=shares_owned,json=sharesOwned,proto3,customtype=cosmossdk.io/math.Int" json:"shares_owned" yaml:"shares_owned"` SharesWithdrawn cosmossdk_io_math.Int `protobuf:"bytes,6,opt,name=shares_withdrawn,json=sharesWithdrawn,proto3,customtype=cosmossdk.io/math.Int" json:"shares_withdrawn" yaml:"shares_withdrawn"` - SharesCancelled cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=shares_cancelled,json=sharesCancelled,proto3,customtype=cosmossdk.io/math.Int" json:"shares_cancelled" yaml:"shares_cancelled"` OrderType LimitOrderType `protobuf:"varint,8,opt,name=order_type,json=orderType,proto3,enum=neutron.dex.LimitOrderType" json:"order_type,omitempty"` } @@ -113,37 +112,35 @@ func init() { } var fileDescriptor_67e5ffbd487ea05f = []byte{ - // 469 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0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 0x6d, 0x14, 0xeb, 0x14, 0xa1, 0xfa, 0x3a, 0x8b, 0x0c, 0xf0, 0xbd, - 0x91, 0x31, 0x79, 0x78, 0xf2, 0xbc, 0x77, 0x0a, 0x9d, 0x2b, 0x2a, 0x32, 0xf0, 0x0f, 0x78, 0x53, - 0x9e, 0xbd, 0xbb, 0x5e, 0xdb, 0xc6, 0xcd, 0xda, 0x36, 0x7e, 0xae, 0x6d, 0xe3, 0xdb, 0xc6, 0x1e, - 0xdc, 0x6c, 0xec, 0xc1, 0xf7, 0x8d, 0x3d, 0xf8, 0x72, 0x1c, 0x31, 0x15, 0x2f, 0xaf, 0xdc, 0x90, - 0x27, 0x5e, 0xbd, 0xeb, 0x98, 0x8b, 0xa8, 0xa9, 0xbd, 0xaf, 0xaf, 0xbc, 0xbc, 0xba, 0xd7, 0x22, - 0x03, 0x79, 0xb5, 0xb7, 0xbd, 0xd9, 0x97, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x41, 0xf7, - 0x93, 0x3b, 0x03, 0x00, 0x00, + // 442 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x4d, 0x8b, 0xd3, 0x40, + 0x18, 0x6e, 0xac, 0xae, 0xee, 0xc4, 0x2f, 0xc6, 0x2d, 0x8e, 0x2b, 0x24, 0xa5, 0xa7, 0x22, 0x6c, + 0x02, 0xab, 0x07, 0x59, 0x3c, 0x2d, 0x0b, 0x52, 0x5c, 0x59, 0x09, 0x15, 0xc1, 0xcb, 0x30, 0xdb, + 0x79, 0x49, 0x86, 0x6e, 0x32, 0x61, 0x66, 0x6a, 0x93, 0x7f, 0xe1, 0xcf, 0xda, 0xe3, 0x1e, 0xc5, + 0x43, 0x90, 0xf6, 0x22, 0x1e, 0xf7, 0x17, 0xc8, 0x34, 0x49, 0x69, 0xf0, 0xe0, 0x29, 0xcf, 0xd7, + 0xbc, 0x4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al() (dAtA []byte, err error) { @@ -171,16 +168,6 @@ func (m *LimitOrderTrancheUser) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x40 } - { - size := m.SharesCancelled.Size() - i -= size - if _, err := m.SharesCancelled.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintLimitOrderTrancheUser(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a { size := m.SharesWithdrawn.Size() i -= size @@ -271,8 +258,6 @@ func (m *LimitOrderTrancheUser) Size() (n int) { n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) l = m.SharesWithdrawn.Size() n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) - l = m.SharesCancelled.Size() - n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) if m.OrderType != 0 { n += 1 + sovLimitOrderTrancheUser(uint64(m.OrderType)) } @@ -501,40 +486,6 @@ func (m *LimitOrderTrancheUser) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SharesCancelled", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLimitOrderTrancheUser - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthLimitOrderTrancheUser - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthLimitOrderTrancheUser - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.SharesCancelled.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 8: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field OrderType", wireType) From 9eb3c2079ff5f065afe84a8084b29d73b699d3ba Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Sun, 28 Jul 2024 21:49:11 -0400 Subject: [PATCH 3/8] fix tests --- .../integration_cancellimitorder_test.go | 34 +++++-------------- .../integration_placelimitorder_test.go | 20 +++-------- .../keeper/integration_withdrawfilled_test.go | 3 -- 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/x/dex/keeper/integration_cancellimitorder_test.go b/x/dex/keeper/integration_cancellimitorder_test.go index c88b7b2ac..cecb921f1 100644 --- a/x/dex/keeper/integration_cancellimitorder_test.go +++ b/x/dex/keeper/integration_cancellimitorder_test.go @@ -191,9 +191,9 @@ func (s *DexTestSuite) TestCancelPartiallyFilled() { // WHEN alice cancels her limit order s.aliceCancelsLimitSell(trancheKey) - // Then alice gets back remaining 25 TokenA LO reserves - s.assertAliceBalances(25, 0) - s.assertDexBalances(0, 25) + // Then alice gets back remaining 25 TokenA LO reserves & 25 TokenB taker tokens + s.assertAliceBalances(25, 25) + s.assertDexBalances(0, 0) } func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { @@ -215,12 +215,12 @@ func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { s.aliceCancelsLimitSell(trancheKey) s.carolCancelsLimitSell(trancheKey) - // THEN alice gets back ~41 BIGTokenA (125 * 1/3) - s.assertAliceBalancesInt(sdkmath.NewInt(41_666_666), sdkmath.ZeroInt()) + // THEN alice gets back ~41 BIGTokenA (125 * 1/3) & ~8.3 BIGTokenB Taker tokens (25 * 1/3) + s.assertAliceBalancesInt(sdkmath.NewInt(41_666_666), sdkmath.NewInt(8333333)) - // Carol gets back 83 TokenA (125 * 2/3) - s.assertCarolBalancesInt(sdkmath.NewInt(83_333_333), sdkmath.ZeroInt()) - s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.NewInt(25_000_000)) + // Carol gets back 83 TokenA (125 * 2/3) & ~16.6 BIGTokenB Taker tokens (25 * 2/3) + s.assertCarolBalancesInt(sdkmath.NewInt(83_333_333), sdkmath.NewInt(16666666)) + s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.OneInt()) } func (s *DexTestSuite) TestCancelGoodTil() { @@ -284,21 +284,3 @@ func (s *DexTestSuite) TestCancelJITNextBlock() { s.aliceCancelsLimitSellFails(trancheKey, types.ErrActiveLimitOrderNotFound) s.assertAliceBalances(0, 0) } - -func (s *DexTestSuite) TestCancelWithdraw() { - s.fundAliceBalances(100, 100) - s.fundCarolBalances(100, 0) - - s.carolLimitSells("TokenA", 0, 100) - tk := s.aliceLimitSells("TokenA", 0, 100) - s.aliceLimitSells("TokenB", -1, 2) - s.aliceCancelsLimitSell(tk) - s.assertAliceBalances(101, 98) - s.aliceLimitSells("TokenB", -1, 96) - s.assertAliceBalances(197, 2) - s.aliceWithdrawsLimitSell(tk) - s.assertAliceBalances(197, 51) - s.assertCarolBalances(0, 0) - s.carolWithdrawsLimitSell(tk) - s.assertCarolBalances(0, 49) -} diff --git a/x/dex/keeper/integration_placelimitorder_test.go b/x/dex/keeper/integration_placelimitorder_test.go index fcd074bdc..37c822973 100644 --- a/x/dex/keeper/integration_placelimitorder_test.go +++ b/x/dex/keeper/integration_placelimitorder_test.go @@ -271,31 +271,19 @@ func (s *DexTestSuite) TestLimitOrderPartialFillDepositCancel() { s.aliceCancelsLimitSell(trancheKey0) - s.assertAliceBalances(100, 40) + s.assertAliceBalances(110, 40) s.assertBobBalances(90, 110) - s.assertDexBalances(10, 50) + s.assertDexBalances(0, 50) s.assertCurrentTicks(math.MinInt64, 0) s.bobLimitSells("TokenA", 10, 10, types.LimitOrderType_FILL_OR_KILL) - s.assertAliceBalances(100, 40) + s.assertAliceBalances(110, 40) s.assertBobBalances(80, 120) - s.assertDexBalances(20, 40) + s.assertDexBalances(10, 40) s.aliceCancelsLimitSell(trancheKey1) - s.assertAliceBalances(100, 80) - s.assertBobBalances(80, 120) - s.assertDexBalances(20, 0) - - s.aliceWithdrawsLimitSell(trancheKey0) - - s.assertAliceBalances(110, 80) - s.assertBobBalances(80, 120) - s.assertDexBalances(10, 0) - - s.aliceWithdrawsLimitSell(trancheKey1) - s.assertAliceBalances(120, 80) s.assertBobBalances(80, 120) s.assertDexBalances(0, 0) diff --git a/x/dex/keeper/integration_withdrawfilled_test.go b/x/dex/keeper/integration_withdrawfilled_test.go index 9ddfbf3bc..8d8ba338b 100644 --- a/x/dex/keeper/integration_withdrawfilled_test.go +++ b/x/dex/keeper/integration_withdrawfilled_test.go @@ -339,9 +339,6 @@ func (s *DexTestSuite) TestWithdrawPartiallyFilledCancelled() { // AND alice cancels the remainder s.aliceCancelsLimitSell(trancheKey) - - // THEN she can withdraw the unused portion - s.aliceWithdrawsLimitSell(trancheKey) s.assertAliceBalances(1, 1) // AND her LimitOrderTrancheUser is removed From 39567f7dd0cdaff8cae61229754b99f3f9c385c6 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Sun, 28 Jul 2024 21:58:50 -0400 Subject: [PATCH 4/8] more test logic --- x/dex/keeper/integration_cancellimitorder_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/x/dex/keeper/integration_cancellimitorder_test.go b/x/dex/keeper/integration_cancellimitorder_test.go index cecb921f1..42354a92b 100644 --- a/x/dex/keeper/integration_cancellimitorder_test.go +++ b/x/dex/keeper/integration_cancellimitorder_test.go @@ -194,6 +194,10 @@ func (s *DexTestSuite) TestCancelPartiallyFilled() { // Then alice gets back remaining 25 TokenA LO reserves & 25 TokenB taker tokens s.assertAliceBalances(25, 25) s.assertDexBalances(0, 0) + + // Assert that the LimitOrderTrancheUser has been deleted + _, found := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.alice.String(), trancheKey) + s.Assert().False(found) } func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { @@ -221,6 +225,12 @@ func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { // Carol gets back 83 TokenA (125 * 2/3) & ~16.6 BIGTokenB Taker tokens (25 * 2/3) s.assertCarolBalancesInt(sdkmath.NewInt(83_333_333), sdkmath.NewInt(16666666)) s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.OneInt()) + + // Assert that the LimitOrderTrancheUsers has been deleted + _, found := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.alice.String(), trancheKey) + s.Assert().False(found) + _, found = s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.carol.String(), trancheKey) + s.Assert().False(found) } func (s *DexTestSuite) TestCancelGoodTil() { From c46fd605ffbf6dd72c1f17fbf164aee11c2a6132 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Mon, 29 Jul 2024 00:10:47 -0400 Subject: [PATCH 5/8] Fix cancellation logic --- x/dex/keeper/core.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/dex/keeper/core.go b/x/dex/keeper/core.go index 03dea005f..eb53bbd4b 100644 --- a/x/dex/keeper/core.go +++ b/x/dex/keeper/core.go @@ -514,6 +514,10 @@ func (k Keeper) CancelLimitOrderCore( trancheUser.SharesWithdrawn = trancheUser.SharesOwned + // Remove the canceled shares from the limitOrder + tranche.TotalMakerDenom = tranche.TotalMakerDenom.Sub(trancheUser.SharesOwned) + tranche.TotalTakerDenom = tranche.TotalTakerDenom.Sub(takerAmountOut) + if makerAmountToReturn.IsPositive() || takerAmountOut.IsPositive() { makerCoinOut := sdk.NewCoin(tradePairID.MakerDenom, makerAmountToReturn) takerCoinOut := sdk.NewCoin(tradePairID.TakerDenom, takerAmountOut) From 6721d52411be98c76e570e95e69a9d1bef630480 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Mon, 29 Jul 2024 00:10:59 -0400 Subject: [PATCH 6/8] more tests --- .../integration_cancellimitorder_test.go | 94 ++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/x/dex/keeper/integration_cancellimitorder_test.go b/x/dex/keeper/integration_cancellimitorder_test.go index 42354a92b..9c12b8d0f 100644 --- a/x/dex/keeper/integration_cancellimitorder_test.go +++ b/x/dex/keeper/integration_cancellimitorder_test.go @@ -200,6 +200,32 @@ func (s *DexTestSuite) TestCancelPartiallyFilled() { s.Assert().False(found) } +func (s *DexTestSuite) TestCancelPartiallyFilledWithdrawFails() { + s.fundAliceBalances(50, 0) + s.fundBobBalances(0, 10) + + // GIVEN alice limit sells 50 TokenA + trancheKey := s.aliceLimitSells("TokenA", 2000, 50) + // Bob swaps 10 TokenB for TokenA + s.bobLimitSells("TokenB", -2001, 10, types.LimitOrderType_FILL_OR_KILL) + + s.assertDexBalancesInt(sdkmath.NewInt(37786095), sdkmath.NewInt(10000000)) + s.assertAliceBalances(0, 0) + + // WHEN alice cancels her limit order + s.aliceCancelsLimitSell(trancheKey) + + // Then alice gets back remaining ~37 BIGTokenA LO reserves & 10 BIGTokenB taker tokens + s.assertAliceBalancesInt(sdkmath.NewInt(37786094), sdkmath.NewInt(10000000)) + s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.ZeroInt()) + + // Assert that the LimitOrderTrancheUser has been deleted + _, found := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.alice.String(), trancheKey) + s.Assert().False(found) + + s.aliceWithdrawLimitSellFails(types.ErrValidLimitOrderTrancheNotFound, trancheKey) +} + func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { s.fundAliceBalances(50, 0) s.fundBobBalances(0, 50) @@ -223,8 +249,8 @@ func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { s.assertAliceBalancesInt(sdkmath.NewInt(41_666_666), sdkmath.NewInt(8333333)) // Carol gets back 83 TokenA (125 * 2/3) & ~16.6 BIGTokenB Taker tokens (25 * 2/3) - s.assertCarolBalancesInt(sdkmath.NewInt(83_333_333), sdkmath.NewInt(16666666)) - s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.OneInt()) + s.assertCarolBalancesInt(sdkmath.NewInt(83_333_333), sdkmath.NewInt(16666667)) + s.assertDexBalancesInt(sdkmath.OneInt(), sdkmath.ZeroInt()) // Assert that the LimitOrderTrancheUsers has been deleted _, found := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.alice.String(), trancheKey) @@ -233,6 +259,70 @@ func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser() { s.Assert().False(found) } +func (s *DexTestSuite) TestCancelPartiallyFilledMultiUser2() { + s.fundAliceBalances(50, 0) + s.fundBobBalances(50, 0) + s.fundCarolBalances(0, 40) + + // // GIVEN alice and bob each limit sells 50 TokenA + trancheKey := s.aliceLimitSells("TokenA", 2000, 50) + s.bobLimitSells("TokenA", 2000, 50) + // carol swaps 20 TokenB for TokenA + s.carolLimitSells("TokenB", -2001, 20, types.LimitOrderType_FILL_OR_KILL) + + // WHEN alice cancels her limit order + s.aliceCancelsLimitSell(trancheKey) + + // THEN alice gets back remaining ~38 BIGTokenA LO reserves & 10 BIGTokenB taker tokens + s.assertAliceBalancesInt(sdkmath.NewInt(37786094), sdkmath.NewInt(10000000)) + s.assertDexBalancesInt(sdkmath.NewInt(37786096), sdkmath.NewInt(10000000)) + + // THEN carol swap through more of the limitorder + s.carolLimitSells("TokenB", -2001, 20, types.LimitOrderType_FILL_OR_KILL) + + // And bob can withdraw his portion + s.bobWithdrawsLimitSell(trancheKey) + s.assertBobBalancesInt(sdkmath.ZeroInt(), sdkmath.NewInt(30000000)) +} + +func (s *DexTestSuite) TestCancelFirstMultiCancel() { + s.fundAliceBalances(50, 0) + s.fundBobBalances(50, 0) + s.fundCarolBalances(0, 40) + + // // GIVEN alice and bob each limit sells 50 TokenA + trancheKey := s.aliceLimitSells("TokenA", 0, 50) + s.bobLimitSells("TokenA", 0, 50) + s.bobCancelsLimitSell(trancheKey) + // carol swaps 10 TokenB for TokenA + s.carolLimitSells("TokenB", -1, 10, types.LimitOrderType_FILL_OR_KILL) + + // WHEN alice cancels her limit order + s.aliceCancelsLimitSell(trancheKey) + + // THEN alice gets back remaining 40 tokenA 10 TokenB taker tokens + s.assertAliceBalances(40, 10) +} + +func (s *DexTestSuite) TestCancelFirstMultiWithdraw() { + s.fundAliceBalances(50, 0) + s.fundBobBalances(50, 0) + s.fundCarolBalances(0, 40) + + // // GIVEN alice and bob each limit sells 50 TokenA + trancheKey := s.aliceLimitSells("TokenA", 0, 50) + s.bobLimitSells("TokenA", 0, 50) + s.bobCancelsLimitSell(trancheKey) + // carol swaps 10 TokenB for TokenA + s.carolLimitSells("TokenB", -1, 10, types.LimitOrderType_FILL_OR_KILL) + + // WHEN alice withdraws her limit order + s.aliceWithdrawsLimitSell(trancheKey) + + // THEN alice gets 10 TokenB + s.assertAliceBalances(0, 10) +} + func (s *DexTestSuite) TestCancelGoodTil() { s.fundAliceBalances(50, 0) tomorrow := time.Now().AddDate(0, 0, 1) From 07849e6567115af435bfcf0dffb43b94d1351fc0 Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Mon, 29 Jul 2024 00:13:00 -0400 Subject: [PATCH 7/8] keep shares_cancelled in LimitOrderTrancheUser to avoid breaking changes --- .../dex/limit_order_tranche_user.proto | 7 ++ x/dex/types/limit_order_tranche_user.pb.go | 107 +++++++++++++----- 2 files changed, 85 insertions(+), 29 deletions(-) diff --git a/proto/neutron/dex/limit_order_tranche_user.proto b/proto/neutron/dex/limit_order_tranche_user.proto index db701b350..89cd817b6 100644 --- a/proto/neutron/dex/limit_order_tranche_user.proto +++ b/proto/neutron/dex/limit_order_tranche_user.proto @@ -24,5 +24,12 @@ message LimitOrderTrancheUser { (gogoproto.nullable) = false, (gogoproto.jsontag) = "shares_withdrawn" ]; + // TODO: remove this in next release. It is no longer used + string shares_cancelled = 7 [ + (gogoproto.moretags) = "yaml:\"shares_cancelled\"", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "shares_cancelled" + ]; LimitOrderType order_type = 8; } diff --git a/x/dex/types/limit_order_tranche_user.pb.go b/x/dex/types/limit_order_tranche_user.pb.go index b863f41e1..75737b1c2 100644 --- a/x/dex/types/limit_order_tranche_user.pb.go +++ b/x/dex/types/limit_order_tranche_user.pb.go @@ -32,6 +32,7 @@ type LimitOrderTrancheUser struct { Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"` SharesOwned cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=shares_owned,json=sharesOwned,proto3,customtype=cosmossdk.io/math.Int" json:"shares_owned" yaml:"shares_owned"` SharesWithdrawn cosmossdk_io_math.Int `protobuf:"bytes,6,opt,name=shares_withdrawn,json=sharesWithdrawn,proto3,customtype=cosmossdk.io/math.Int" json:"shares_withdrawn" yaml:"shares_withdrawn"` + SharesCancelled cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=shares_cancelled,json=sharesCancelled,proto3,customtype=cosmossdk.io/math.Int" json:"shares_cancelled" yaml:"shares_cancelled"` OrderType LimitOrderType `protobuf:"varint,8,opt,name=order_type,json=orderType,proto3,enum=neutron.dex.LimitOrderType" json:"order_type,omitempty"` } @@ -112,35 +113,37 @@ func init() { } var fileDescriptor_67e5ffbd487ea05f = []byte{ - // 442 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x4d, 0x8b, 0xd3, 0x40, - 0x18, 0x6e, 0xac, 0xae, 0xee, 0xc4, 0x2f, 0xc6, 0x2d, 0x8e, 0x2b, 0x24, 0xa5, 0xa7, 0x22, 0x6c, - 0x02, 0xab, 0x07, 0x59, 0x3c, 0x2d, 0x0b, 0x52, 0x5c, 0x59, 0x09, 0x15, 0xc1, 0xcb, 0x30, 0xdb, - 0x79, 0x49, 0x86, 0x6e, 0x32, 0x61, 0x66, 0x6a, 0x93, 0x7f, 0xe1, 0xcf, 0xda, 0xe3, 0x1e, 0xc5, - 0x43, 0x90, 0xf6, 0x22, 0x1e, 0xf7, 0x17, 0xc8, 0x34, 0x49, 0x69, 0xf0, 0xe0, 0x29, 0xcf, 0xd7, - 0xbc, 0x4f, 0x92, 0x79, 0xd1, 0xab, 0x0c, 0x16, 0x46, 0xc9, 0x2c, 0xe4, 0x50, 0x84, 0x57, 0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f, 0xcc, 0xa4, 0x4e, 0xa5, 0xd6, 0x7c, 0x1e, 0x08, 0x19, 0xa6, - 0xcc, 0x24, 0xc1, 0x24, 0x33, 0x7f, 0x2a, 0xbf, 0x73, 0xe8, 0xb6, 0xf2, 0x9f, 0x95, 0x2c, 0xbd, - 0x3a, 0x19, 0xed, 0xaa, 0xa3, 0xc8, 0xad, 0xe9, 0x85, 0x65, 0x78, 0x89, 0x9e, 0x36, 0xee, 0x52, - 0x98, 0x84, 0x2b, 0xb6, 0xcc, 0xc8, 0xde, 0xa6, 0xec, 0xfc, 0x7f, 0x65, 0xff, 0x1c, 0xbc, 0xad, - 0xfc, 0xe7, 0x9d, 0xc2, 0xad, 0x33, 0x8a, 0x9e, 0xd4, 0xd2, 0x97, 0x56, 0xc1, 0x27, 0x08, 0x35, - 0x4b, 0x52, 0xe6, 0x40, 0x1e, 0x0c, 0x9d, 0xf1, 0xe3, 0xe3, 0x97, 0x9d, 0x1b, 0xd9, 0xb9, 0xcc, - 0x32, 0x87, 0x68, 0x5f, 0xb6, 0xf0, 0xf4, 0xfd, 0xf5, 0xca, 0x73, 0x6e, 0x56, 0x9e, 0xf3, 0x6b, - 0xe5, 0x39, 0xdf, 0xd7, 0x5e, 0xef, 0x66, 0xed, 0xf5, 0x7e, 0xac, 0xbd, 0xde, 0xd7, 0xa3, 0x58, - 0x98, 0x64, 0x71, 0x19, 0xcc, 0x64, 0x1a, 0x36, 0xb3, 0x8e, 0xa4, 0x8a, 0x5b, 0x1c, 0x7e, 0x7b, - 0x13, 0x16, 0xf5, 0xda, 0x94, 0x39, 0xe8, 0xcb, 0xbd, 0xcd, 0xea, 0xbc, 0xfe, 0x1b, 0x00, 0x00, - 0xff, 0xff, 0x03, 0x0d, 0xdc, 0xa4, 0xc2, 0x02, 0x00, 0x00, + // 469 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x4d, 0x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, 0xfa, 0x3a, 0x8b, 0x0c, 0xf0, 0xbd, + 0x91, 0x31, 0x79, 0x78, 0xf2, 0xbc, 0x77, 0x0a, 0x9d, 0x2b, 0x2a, 0x32, 0xf0, 0x0f, 0x78, 0x53, + 0x9e, 0xbd, 0xbb, 0x5e, 0xdb, 0xc6, 0xcd, 0xda, 0x36, 0x7e, 0xae, 0x6d, 0xe3, 0xdb, 0xc6, 0x1e, + 0xdc, 0x6c, 0xec, 0xc1, 0xf7, 0x8d, 0x3d, 0xf8, 0x72, 0x1c, 0x31, 0x15, 0x2f, 0xaf, 0xdc, 0x90, + 0x27, 0x5e, 0xbd, 0xeb, 0x98, 0x8b, 0xa8, 0xa9, 0xbd, 0xaf, 0xaf, 0xbc, 0xbc, 0xba, 0xd7, 0x22, + 0x03, 0x79, 0xb5, 0xb7, 0xbd, 0xd9, 0x97, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x41, 0xf7, + 0x93, 0x3b, 0x03, 0x00, 0x00, } func (m *LimitOrderTrancheUser) Marshal() (dAtA []byte, err error) { @@ -168,6 +171,16 @@ func (m *LimitOrderTrancheUser) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x40 } + { + size := m.SharesCancelled.Size() + i -= size + if _, err := m.SharesCancelled.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintLimitOrderTrancheUser(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a { size := m.SharesWithdrawn.Size() i -= size @@ -258,6 +271,8 @@ func (m *LimitOrderTrancheUser) Size() (n int) { n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) l = m.SharesWithdrawn.Size() n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) + l = m.SharesCancelled.Size() + n += 1 + l + sovLimitOrderTrancheUser(uint64(l)) if m.OrderType != 0 { n += 1 + sovLimitOrderTrancheUser(uint64(m.OrderType)) } @@ -486,6 +501,40 @@ func (m *LimitOrderTrancheUser) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SharesCancelled", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLimitOrderTrancheUser + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthLimitOrderTrancheUser + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthLimitOrderTrancheUser + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SharesCancelled.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 8: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field OrderType", wireType) From 7b46b12ebbe2181e6e5a3bcc4c25f3d0ad6aeb7d Mon Sep 17 00:00:00 2001 From: Julian Compagni Portis Date: Mon, 29 Jul 2024 06:27:53 -0400 Subject: [PATCH 8/8] fix tests --- x/dex/keeper/limit_order_tranche_user_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/dex/keeper/limit_order_tranche_user_test.go b/x/dex/keeper/limit_order_tranche_user_test.go index b4e5cd563..a5578ee43 100644 --- a/x/dex/keeper/limit_order_tranche_user_test.go +++ b/x/dex/keeper/limit_order_tranche_user_test.go @@ -91,6 +91,7 @@ func (s *DexTestSuite) TestGetAllLimitOrders() { Address: s.alice.String(), SharesOwned: math.NewInt(10_000_000), SharesWithdrawn: math.NewInt(0), + SharesCancelled: math.ZeroInt(), }, LOList[0], ) @@ -101,6 +102,7 @@ func (s *DexTestSuite) TestGetAllLimitOrders() { Address: s.alice.String(), SharesOwned: math.NewInt(10_000_000), SharesWithdrawn: math.NewInt(0), + SharesCancelled: math.ZeroInt(), }, LOList[1], )