Skip to content

Commit

Permalink
[TRA-195] Add new error code to be returned when orders fail isolated…
Browse files Browse the repository at this point in the history
… subaccount checks. (#1331)

(cherry picked from commit 360ee9c)
  • Loading branch information
vincentwschau authored and mergify[bot] committed Apr 4, 2024
1 parent 4b61211 commit 6037684
Show file tree
Hide file tree
Showing 26 changed files with 782 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export enum OrderRemovalReason {

/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14,

/**
* ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS - The order has been removed since filling it would lead to the subaccount
* violating isolated subaccount constraints.
*/
ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS = 15,
UNRECOGNIZED = -1,
}
/** OrderRemovalReason is an enum of all the reasons an order was removed. */
Expand Down Expand Up @@ -161,6 +167,12 @@ export enum OrderRemovalReasonSDKType {

/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14,

/**
* ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS - The order has been removed since filling it would lead to the subaccount
* violating isolated subaccount constraints.
*/
ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS = 15,
UNRECOGNIZED = -1,
}
export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason {
Expand Down Expand Up @@ -225,6 +237,10 @@ export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason {
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
return OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT;

case 15:
case "ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS":
return OrderRemovalReason.ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS;

case -1:
case "UNRECOGNIZED":
default:
Expand Down Expand Up @@ -278,6 +294,9 @@ export function orderRemovalReasonToJSON(object: OrderRemovalReason): string {
case OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT:
return "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT";

case OrderRemovalReason.ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS:
return "ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS";

case OrderRemovalReason.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand Down
3 changes: 3 additions & 0 deletions proto/dydxprotocol/indexer/shared/removal_reason.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ enum OrderRemovalReason {
ORDER_REMOVAL_REASON_EQUITY_TIER = 13;
// The order has been removed since its ClobPair has entered final settlement.
ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14;
// The order has been removed since filling it would lead to the subaccount
// violating isolated subaccount constraints.
ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS = 15;
}
2 changes: 2 additions & 0 deletions protocol/indexer/shared/order_removal_reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func GetOrderRemovalReason(
return sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_IMMEDIATE_OR_CANCEL_WOULD_REST_ON_BOOK, nil
case clobtypes.ReduceOnlyResized:
return sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_REDUCE_ONLY_RESIZE, nil
case clobtypes.ViolatesIsolatedSubaccountConstraints:
return sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS, nil
default:
return 0, fmt.Errorf("unrecognized order status %d and error \"%w\"", orderStatus, orderError)
}
Expand Down
5 changes: 5 additions & 0 deletions protocol/indexer/shared/order_removal_reason_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func TestGetOrderRemovalReason_Success(t *testing.T) {
expectedReason: sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_IMMEDIATE_OR_CANCEL_WOULD_REST_ON_BOOK,
expectedErr: nil,
},
"Gets order removal reason for order status ViolatesIsolatedSubaccountConstraints": {
orderStatus: clobtypes.ViolatesIsolatedSubaccountConstraints,
expectedReason: sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_VIOLATES_ISOLATED_SUBACCOUNT_CONSTRAINTS,
expectedErr: nil,
},
"Gets order removal reason for order error ErrFokOrderCouldNotBeFullyFilled": {
orderError: clobtypes.ErrFokOrderCouldNotBeFullyFilled,
expectedReason: sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_FOK_ORDER_COULD_NOT_BE_FULLY_FULLED,
Expand Down
97 changes: 52 additions & 45 deletions protocol/indexer/shared/types/removal_reason.pb.go

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

6 changes: 3 additions & 3 deletions protocol/mocks/ClobKeeper.go

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

8 changes: 4 additions & 4 deletions protocol/mocks/MemClobKeeper.go

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

Loading

0 comments on commit 6037684

Please sign in to comment.