Skip to content

Commit

Permalink
Ensure that empty tranches are deleted instead of being saved as expi…
Browse files Browse the repository at this point in the history
…red tranches
  • Loading branch information
jcompagni10 committed Aug 29, 2024
1 parent 7890f41 commit 0c199f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions x/dex/keeper/integration_cancellimitorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func (s *DexTestSuite) TestCancelEntireLimitOrderBOneExists() {
s.assertDexBalances(0, 0)
s.assertCurr1To0(math.MinInt64)
s.assertCurr0To1(math.MaxInt64)

// Tranche is deleted
tranche, _, found := s.App.DexKeeper.FindLimitOrderTranche(
s.Ctx,
&types.LimitOrderTrancheKey{
TradePairId: types.MustNewTradePairID("TokenA", "TokenB"),
TickIndexTakerToMaker: 0,
TrancheKey: trancheKey,
},
)
s.Nil(tranche)
s.False(found)
}

func (s *DexTestSuite) TestCancelHigherEntireLimitOrderATwoExistDiffTicksSameDirection() {
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/limit_order_tranche.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (k Keeper) SaveTranche(ctx sdk.Context, tranche *types.LimitOrderTranche) {
if tranche.HasTokenIn() {
k.SetLimitOrderTranche(ctx, tranche)
} else {
k.SetInactiveLimitOrderTranche(ctx, tranche)
k.SaveInactiveTranche(ctx, tranche)
k.RemoveLimitOrderTranche(ctx, tranche.Key)
ctx.EventManager().EmitEvents(types.GetEventsDecTotalOrders(tranche.Key.TradePairId))
}
Expand Down

0 comments on commit 0c199f1

Please sign in to comment.