Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Node Status taker order status protos #2003

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions proto/dydxprotocol/clob/order.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dydxprotocol.clob;

import "gogoproto/gogo.proto";
import "dydxprotocol/subaccounts/subaccount.proto";
import "dydxprotocol/clob/liquidations.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/clob/types";

Expand Down Expand Up @@ -227,3 +228,22 @@ message TransactionOrdering {
// Within the block, the unique transaction index.
uint32 transaction_index = 2;
}

// StreamLiquidationOrder represents an protocol-generated IOC liquidation order.
// Used in full node streaming.
message StreamLiquidationOrder {
// Information about this liquidation order.
PerpetualLiquidationInfo liquidation_info = 1;

// CLOB pair ID of the CLOB pair the liquidation order will be matched against.
uint32 clob_pair_id = 2;

// True if this is a buy order liquidating a short position, false if vice versa.
bool is_buy = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use Side similar to Order for consistency?

no strong preference though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think it would be a little weird since we nest Side in the Order proto currently, and if we change it to Side for liquidation order we would have to nest it in the Liquidation order proto. I'll keep it as is for minimal changes.


// The number of base quantums for this liquidation order.
uint64 quantums = 4;

// The subticks this liquidation order will be submitted at.
uint64 subticks = 5;
}
35 changes: 35 additions & 0 deletions proto/dydxprotocol/clob/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,38 @@ message StreamOrderbookFill {
// Resulting fill amounts for each order in the orders array.
repeated uint64 fill_amounts = 3;
}

// StreamTakerOrder provides information on a taker order that was attempted
// to be matched on the orderbook.
// It is intended to be used only in full node streaming.
message StreamTakerOrder {
// The taker order that was matched on the orderbook. Can be a
// regular order or a liquidation order.
oneof taker_order {
Order order = 1;
StreamLiquidationOrder liquidation_order = 2;
}

// Information on the taker order after it is matched on the book,
// either successfully or unsuccessfully.
StreamTakerOrderStatus taker_order_status = 3;
}

// StreamTakerOrderStatus is a representation of a taker order
// after it is attempted to be matched on the orderbook.
// It is intended to be used only in full node streaming.
message StreamTakerOrderStatus {
// The state of the taker order after attempting to match it against the orderbook.
// Possible enum values can be found here:
// https://github.com/dydxprotocol/v4-chain/blob/main/protocol/x/clob/types/orderbook.go#L105
uint32 order_status = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the possible values of order_status? Link to codebase?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not link main since that is subject to change. link to some release or some commit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also just to make sure - PO is the only thing missing from these enum values? status captures all possible results and we don't need the error, right?


// The amount of remaining (non-matched) base quantums of this taker order.
uint64 remaining_quantums = 2;
Comment on lines +249 to +250
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my understanding - this is the quantums remaining after optimisitic fills?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, after the matching loop, remaining quantums


// The amount of base quantums that were *optimistically* filled for this taker order
// when the order is matched against the orderbook. Note that if any quantums of this order
// were optimistically filled or filled in state before this invocation of the matching loop,
// this value will not include them.
uint64 optimistically_filled_quantums = 3;
}
12 changes: 12 additions & 0 deletions protocol/x/clob/types/liquidation_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func NewLiquidationOrder(
}
}

// ToStreamLiquidationOrder converts the LiquidationOrder to a StreamLiquidationOrder
// to be emitted by full node streaming.
func (lo *LiquidationOrder) ToStreamLiquidationOrder() *StreamLiquidationOrder {
return &StreamLiquidationOrder{
LiquidationInfo: &lo.perpetualLiquidationInfo,
ClobPairId: uint32(lo.clobPairId),
IsBuy: lo.isBuy,
Quantums: lo.quantums.ToUint64(),
Subticks: lo.subticks.ToUint64(),
}
}

// IsBuy returns true if this is a buy order, false if not.
// This function is necessary for the `LiquidationOrder` type to implement the `MatchableOrder` interface.
func (lo *LiquidationOrder) IsBuy() bool {
Expand Down
Loading
Loading