Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Dec 2, 2024
1 parent 498f72a commit 73add8f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
8 changes: 4 additions & 4 deletions protocol/mocks/MemClob.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions protocol/x/clob/keeper/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ func (k Keeper) AddPreexistingStatefulOrder(
// PlaceStatefulOrdersFromLastBlock validates and places stateful orders from the last block onto the memclob.
// Note that stateful orders could fail to be placed due to various reasons such as collateralization
// check failures, self-trade errors, etc. In these cases the `checkState` will not be written to.
// Note that this function also takes in a postOnlyFilter variable and only places post-only orders if
// postOnlyFilter is true and non-post-only orders if postOnlyFilter is false.
//
// This function is used in:
// 1. `PrepareCheckState` to place newly placed long term orders from the last
// block from ProcessProposerMatchesEvents.PlacedStatefulOrderIds. This is step 3 in PrepareCheckState.
Expand All @@ -496,7 +499,7 @@ func (k Keeper) PlaceStatefulOrdersFromLastBlock(
ctx sdk.Context,
placedStatefulOrderIds []types.OrderId,
existingOffchainUpdates *types.OffchainUpdates,
onlyPlacePostOnly bool,
postOnlyFilter bool,
) (
offchainUpdates *types.OffchainUpdates,
) {
Expand All @@ -523,8 +526,8 @@ func (k Keeper) PlaceStatefulOrdersFromLastBlock(

order := orderPlacement.GetOrder()

// Skip the order if it is a post-only order and we are only placing post-only orders.
if onlyPlacePostOnly != order.IsPostOnlyOrder() {
// Skip post-only orders if postOnlyFilter is false or non-post-only orders if postOnlyFilter is true.
if postOnlyFilter != order.IsPostOnlyOrder() {
continue
}

Expand Down Expand Up @@ -582,11 +585,14 @@ func (k Keeper) PlaceStatefulOrdersFromLastBlock(
// PlaceConditionalOrdersTriggeredInLastBlock takes in a list of conditional order ids that were triggered
// in the last block, verifies they are conditional orders, verifies they are in triggered state, and places
// the orders on the memclob.
//
// Note that this function also takes in a postOnlyFilter variable and only places post-only orders if
// postOnlyFilter is true and non-post-only orders if postOnlyFilter is false.
func (k Keeper) PlaceConditionalOrdersTriggeredInLastBlock(
ctx sdk.Context,
conditionalOrderIdsTriggeredInLastBlock []types.OrderId,
existingOffchainUpdates *types.OffchainUpdates,
onlyPlacePostOnly bool,
postOnlyFilter bool,
) (
offchainUpdates *types.OffchainUpdates,
) {
Expand Down Expand Up @@ -620,7 +626,7 @@ func (k Keeper) PlaceConditionalOrdersTriggeredInLastBlock(
ctx,
conditionalOrderIdsTriggeredInLastBlock,
existingOffchainUpdates,
onlyPlacePostOnly,
postOnlyFilter,
)
}

Expand Down
22 changes: 11 additions & 11 deletions protocol/x/clob/keeper/orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2250,36 +2250,36 @@ func TestPlaceStatefulOrdersFromLastBlock(t *testing.T) {

func TestPlaceStatefulOrdersFromLastBlock_PostOnly(t *testing.T) {
tests := map[string]struct {
orders []types.Order
onlyPlacePostOnly bool
orders []types.Order
postOnlyFilter bool

expectedOrderPlacementCalls []types.Order
}{
"places PO stateful orders from last block when onlyPlacePostOnly = true": {
onlyPlacePostOnly: true,
"places PO stateful orders from last block when postOnlyFilter = true": {
postOnlyFilter: true,
orders: []types.Order{
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT5_PO,
},
expectedOrderPlacementCalls: []types.Order{
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT5_PO,
},
},
"does not places non-PO stateful orders when onlyPlacePostOnly = true": {
onlyPlacePostOnly: true,
"does not places non-PO stateful orders when postOnlyFilter = true": {
postOnlyFilter: true,
orders: []types.Order{
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT5,
},
expectedOrderPlacementCalls: []types.Order{},
},
"does not places PO stateful orders from last block, when onlyPlacePostOnly = false": {
onlyPlacePostOnly: false,
"does not places PO stateful orders from last block, when postOnlyFilter = false": {
postOnlyFilter: false,
orders: []types.Order{
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT5_PO,
},
expectedOrderPlacementCalls: []types.Order{},
},
"places non-PO stateful orders from last block when onlyPlacePostOnly = false": {
onlyPlacePostOnly: false,
"places non-PO stateful orders from last block when postOnlyFilter = false": {
postOnlyFilter: false,
orders: []types.Order{
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT5,
},
Expand Down Expand Up @@ -2350,7 +2350,7 @@ func TestPlaceStatefulOrdersFromLastBlock_PostOnly(t *testing.T) {
for _, order := range tc.orders {
orderIds = append(orderIds, order.OrderId)
}
ks.ClobKeeper.PlaceStatefulOrdersFromLastBlock(ctx, orderIds, offchainUpdates, tc.onlyPlacePostOnly)
ks.ClobKeeper.PlaceStatefulOrdersFromLastBlock(ctx, orderIds, offchainUpdates, tc.postOnlyFilter)

// PlaceStatefulOrdersFromLastBlock utilizes the memclob's PlaceOrder flow, but we
// do not want to emit PlaceMessages in offchain events for stateful orders. This assertion
Expand Down
17 changes: 10 additions & 7 deletions protocol/x/clob/memclob/memclob.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,12 +874,15 @@ func (m *MemClobPriceTimePriority) matchOrder(
// - Pre-existing stateful orders.
// - Stateful cancelations.
// Note that match operations are no-op.
//
// Note that this function also takes in a postOnlyFilter variable and only places post-only orders if
// postOnlyFilter is true and non-post-only orders if postOnlyFilter is false.
func (m *MemClobPriceTimePriority) ReplayOperations(
ctx sdk.Context,
localOperations []types.InternalOperation,
shortTermOrderTxBytes map[types.OrderHash][]byte,
existingOffchainUpdates *types.OffchainUpdates,
onlyPlacePostOnly bool,
postOnlyFilter bool,
) *types.OffchainUpdates {
lib.AssertCheckTxMode(ctx)

Expand Down Expand Up @@ -924,8 +927,8 @@ func (m *MemClobPriceTimePriority) ReplayOperations(
case *types.InternalOperation_ShortTermOrderPlacement:
order := operation.GetShortTermOrderPlacement().Order

// Skip the order if it is a post-only order and we are only replaying post-only orders.
if onlyPlacePostOnly != order.IsPostOnlyOrder() {
// Skip post-only orders if postOnlyFilter is false or non-post-only orders if postOnlyFilter is true.
if postOnlyFilter != order.IsPostOnlyOrder() {
continue
}

Expand Down Expand Up @@ -1019,8 +1022,8 @@ func (m *MemClobPriceTimePriority) ReplayOperations(
continue
}

// Skip the order if it is a post-only order and we are only replaying post-only orders.
if onlyPlacePostOnly != statefulOrderPlacement.Order.IsPostOnlyOrder() {
// Skip post-only orders if postOnlyFilter is false or non-post-only orders if postOnlyFilter is true.
if postOnlyFilter != statefulOrderPlacement.Order.IsPostOnlyOrder() {
continue
}

Expand Down Expand Up @@ -1077,8 +1080,8 @@ func (m *MemClobPriceTimePriority) ReplayOperations(
continue
}

// Skip the order if it is a post-only order and we are only replaying post-only orders.
if onlyPlacePostOnly != statefulOrderPlacement.Order.IsPostOnlyOrder() {
// Skip post-only orders if postOnlyFilter is false or non-post-only orders if postOnlyFilter is true.
if postOnlyFilter != statefulOrderPlacement.Order.IsPostOnlyOrder() {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/x/clob/types/memclob.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type MemClob interface {
localOperations []InternalOperation,
shortTermOrderTxBytes map[OrderHash][]byte,
existingOffchainUpdates *OffchainUpdates,
onlyPlacePostOnly bool,
postOnlyFilter bool,
) (offchainUpdates *OffchainUpdates)
SetMemclobGauges(
ctx sdk.Context,
Expand Down

0 comments on commit 73add8f

Please sign in to comment.