Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Mar 21, 2024
1 parent c400abd commit 8a2b8c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions protocol/x/vault/keeper/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) {
}

// Refresh orders depending on vault type.
// Currently only supported vault type is CLOB.
switch vaultId.Type {
case types.VaultType_VAULT_TYPE_CLOB:
err := k.RefreshVaultClobOrders(ctx, vaultId)
if err != nil {
log.ErrorLogWithError(ctx, "Failed to refresh vault clob orders", err, "vaultId", vaultId)
}
default:
log.ErrorLog(ctx, "Failed to refresh vault orders: unknown vault type", "vaultId", vaultId)
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion protocol/x/vault/keeper/orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,32 @@ func TestRefreshAllVaultOrders(t *testing.T) {
allStatefulOrders := tApp.App.ClobKeeper.GetAllStatefulOrders(ctx)
require.Len(t, allStatefulOrders, 0)

// Simulate vault orders placed in last block.
numPreviousOrders := 0
for i, vaultId := range tc.vaultIds {
if tc.totalShares[i].NumShares.Cmp(dtypes.NewInt(0)) > 0 {
orders, err := tApp.App.VaultKeeper.GetVaultClobOrders(
ctx.WithBlockHeight(ctx.BlockHeight()-1),
vaultId,
)
require.NoError(t, err)
for _, order := range orders {
err := tApp.App.ClobKeeper.HandleMsgPlaceOrder(
ctx,
clobtypes.NewMsgPlaceOrder(*order),
)
require.NoError(t, err)
}
numPreviousOrders += len(orders)
}
}
require.Len(t, tApp.App.ClobKeeper.GetAllStatefulOrders(ctx), numPreviousOrders)

// Refresh all vault orders.
tApp.App.VaultKeeper.RefreshAllVaultOrders(ctx)

// Check orders are as expected.
// Check orders are as expected, i.e. orders from last block have been
// cancelled and orders from this block have been placed.
numExpectedOrders := 0
allExpectedOrderIds := make(map[clobtypes.OrderId]bool)
for i, vaultId := range tc.vaultIds {
Expand Down

0 comments on commit 8a2b8c5

Please sign in to comment.