Skip to content

Commit

Permalink
fix: fix bug in NumMMOrders calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcre committed Aug 10, 2023
1 parent 0709514 commit f300696
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions x/exchange/keeper/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (k Keeper) placeLimitOrder(
k.SetOrdersByOrdererIndex(ctx, order)

if typ == types.OrderTypeMM {
// NOTE: NumMMOrders might have been changed in executeOrder the orderer
// completed own orders.
numMMOrders, _ = k.GetNumMMOrders(ctx, ordererAddr, marketId)
k.SetNumMMOrders(ctx, ordererAddr, marketId, numMMOrders+1)
}
}
Expand Down
19 changes: 19 additions & 0 deletions x/exchange/keeper/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,22 @@ func (s *KeeperTestSuite) TestDecQuantity() {
diff, _ := orderer3BalancesAfter.SafeSub(orderer3BalancesBefore)
s.AssertEqual(sdk.NewInt(380), diff.AmountOf("uusd")) // 2699.7*0.14076=380.009722
}

func (s *KeeperTestSuite) TestNumMMOrdersEdgecase() {
s.keeper.SetMaxNumMMOrders(s.Ctx, 3) // Override the default

market := s.CreateMarket("ucre", "uusd")

ordererAddr := s.FundedAccount(1, enoughCoins)
// Place 2 MM orders
s.PlaceMMLimitOrder(market.Id, ordererAddr, true, utils.ParseDec("4.9"), sdk.NewDec(10_000000), time.Hour)
s.PlaceMMLimitOrder(market.Id, ordererAddr, true, utils.ParseDec("4.85"), sdk.NewDec(10_000000), time.Hour)

// Match against own orders
s.PlaceMMLimitOrder(market.Id, ordererAddr, false, utils.ParseDec("4.5"), sdk.NewDec(30_000000), time.Hour)

numMMOrders, _ := s.keeper.GetNumMMOrders(s.Ctx, ordererAddr, market.Id)
// The number of MM orders should be 1, since previous order are fully matched
// and deleted.
s.Require().Equal(uint32(1), numMMOrders)
}

0 comments on commit f300696

Please sign in to comment.