Skip to content

Commit

Permalink
pr nits
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-dydx committed Dec 18, 2023
1 parent 0f0d706 commit fee0156
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ export enum ClobPairStatus {
/**
* CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
* deactivated. Clob pairs in this state do not accept new orders and trading
* is blocked. All open positions are closed by the protocol when the clob
* pair gains this status.
* is blocked. All open positions are closed and open stateful orders canceled
* by the protocol when the clob pair transitions to this status. All short-term
* orders are left to expire.
*/
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
Expand Down Expand Up @@ -360,8 +361,9 @@ export enum ClobPairStatusSDKType {
/**
* CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
* deactivated. Clob pairs in this state do not accept new orders and trading
* is blocked. All open positions are closed by the protocol when the clob
* pair gains this status.
* is blocked. All open positions are closed and open stateful orders canceled
* by the protocol when the clob pair transitions to this status. All short-term
* orders are left to expire.
*/
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6,
UNRECOGNIZED = -1,
Expand Down
4 changes: 2 additions & 2 deletions proto/dydxprotocol/indexer/protocol/v1/clob.proto
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ enum ClobPairStatus {
CLOB_PAIR_STATUS_INITIALIZING = 5;
// CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been
// deactivated. Clob pairs in this state do not accept new orders and trading
// is blocked. All open positions are closed by the protocol when the clob
// pair gains this status. All open stateful orders are closed and short-term
// is blocked. All open positions are closed and open stateful orders canceled
// by the protocol when the clob pair transitions to this status. All short-term
// orders are left to expire.
CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6;
}
4 changes: 2 additions & 2 deletions protocol/indexer/protocol/v1/clob.pb.go

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

2 changes: 1 addition & 1 deletion protocol/x/clob/keeper/clob_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (k Keeper) UpdateClobPair(

// If newly transitioning to final settlement, enter final settlement.
if newStatus == types.ClobPair_STATUS_FINAL_SETTLEMENT && oldStatus != newStatus {
k.mustEnterFinalSettlement(ctx, clobPair.GetClobPairId())
k.mustTransitionToFinalSettlement(ctx, clobPair.GetClobPairId())
}

return nil
Expand Down
50 changes: 26 additions & 24 deletions protocol/x/clob/keeper/final_settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
)

// MustEnterFinalSettlement holds logic executed when a market transitions to FINAL_SETTLEMENT status.
// mustTransitionToFinalSettlement holds logic executed when a market transitions to FINAL_SETTLEMENT status.
// This function will forcefully cancel all stateful open orders for the clob pair.
func (k Keeper) mustEnterFinalSettlement(ctx sdk.Context, clobPairId types.ClobPairId) {
// Forcefully cancel all stateful orders from state for this clob pair
func (k Keeper) mustTransitionToFinalSettlement(ctx sdk.Context, clobPairId types.ClobPairId) {
// Forcefully cancel all stateful orders from state for this clob pair.
k.mustCancelStatefulOrdersForFinalSettlement(ctx, clobPairId)

// Delete untriggered conditional orders for this clob pair from memory
// Delete untriggered conditional orders for this clob pair from memory.
delete(k.UntriggeredConditionalOrders, clobPairId)
}

Expand Down Expand Up @@ -42,29 +42,31 @@ func (k Keeper) mustCancelStatefulOrdersForFinalSettlement(ctx sdk.Context, clob

// TODO(CLOB-1053): Iterate over stateful orders for only specified clob pair
for _, order := range statefulOrders {
if order.GetClobPairId() == clobPairId {
// Remove from state, recovering from panic if necessary
safelyRemoveStatefulOrder(ctx, order.OrderId)
if order.GetClobPairId() != clobPairId {
continue
}

// Remove from state, recovering from panic if necessary
safelyRemoveStatefulOrder(ctx, order.OrderId)

// Append to RemovedStatefulOrderIds so this order gets removed
// from the memclob in PrepareCheckState during the PurgeInvalidMemclobState step
processProposerMatchesEvents.RemovedStatefulOrderIds = append(
processProposerMatchesEvents.RemovedStatefulOrderIds,
order.OrderId,
)
// Append to RemovedStatefulOrderIds so this order gets removed
// from the memclob in PrepareCheckState during the PurgeInvalidMemclobState step
processProposerMatchesEvents.RemovedStatefulOrderIds = append(
processProposerMatchesEvents.RemovedStatefulOrderIds,
order.OrderId,
)

k.GetIndexerEventManager().AddTxnEvent(
ctx,
indexerevents.SubtypeStatefulOrder,
indexerevents.StatefulOrderEventVersion,
indexer_manager.GetBytes(
indexerevents.NewStatefulOrderRemovalEvent(
order.OrderId,
indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_FINAL_SETTLEMENT,
),
k.GetIndexerEventManager().AddTxnEvent(
ctx,
indexerevents.SubtypeStatefulOrder,
indexerevents.StatefulOrderEventVersion,
indexer_manager.GetBytes(
indexerevents.NewStatefulOrderRemovalEvent(
order.OrderId,
indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_FINAL_SETTLEMENT,
),
)
}
),
)
}

k.MustSetProcessProposerMatchesEvents(ctx, processProposerMatchesEvents)
Expand Down

0 comments on commit fee0156

Please sign in to comment.