Skip to content

Commit

Permalink
[CLOB-1015][CLOB-1016] Update MatchPerpetualDeleveraging and Delevera…
Browse files Browse the repository at this point in the history
…gingEventV1 to have final settlement flag (#833)

* add protos for final settlement clob pair status and final settlement removal reason

* add missing indexer constants

* update proto formatting

* update proto formatting

* fix indexer test

* fix indexer constant which requires all fields of proto to be specified

* update comment and panic string

* update proto comments
  • Loading branch information
jakob-dydx authored Dec 5, 2023
1 parent f2e78ba commit 11fd8a0
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export interface MatchPerpetualDeleveraging {
/** An ordered list of fills created by this liquidation. */

fills: MatchPerpetualDeleveraging_Fill[];
/**
* Flag denoting whether the deleveraging operation was for the purpose
* of final settlement. Final settlement matches are at the oracle price,
* whereas deleveraging happens at the bankruptcy price of the deleveraged
* subaccount.
*/

isFinalSettlement: boolean;
}
/**
* MatchPerpetualDeleveraging is an injected message used for deleveraging a
Expand All @@ -143,6 +151,14 @@ export interface MatchPerpetualDeleveragingSDKType {
/** An ordered list of fills created by this liquidation. */

fills: MatchPerpetualDeleveraging_FillSDKType[];
/**
* Flag denoting whether the deleveraging operation was for the purpose
* of final settlement. Final settlement matches are at the oracle price,
* whereas deleveraging happens at the bankruptcy price of the deleveraged
* subaccount.
*/

is_final_settlement: boolean;
}
/** Fill represents a fill between the liquidated and offsetting subaccount. */

Expand Down Expand Up @@ -451,7 +467,8 @@ function createBaseMatchPerpetualDeleveraging(): MatchPerpetualDeleveraging {
return {
liquidated: undefined,
perpetualId: 0,
fills: []
fills: [],
isFinalSettlement: false
};
}

Expand All @@ -469,6 +486,10 @@ export const MatchPerpetualDeleveraging = {
MatchPerpetualDeleveraging_Fill.encode(v!, writer.uint32(26).fork()).ldelim();
}

if (message.isFinalSettlement === true) {
writer.uint32(32).bool(message.isFinalSettlement);
}

return writer;
},

Expand All @@ -493,6 +514,10 @@ export const MatchPerpetualDeleveraging = {
message.fills.push(MatchPerpetualDeleveraging_Fill.decode(reader, reader.uint32()));
break;

case 4:
message.isFinalSettlement = reader.bool();
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -507,6 +532,7 @@ export const MatchPerpetualDeleveraging = {
message.liquidated = object.liquidated !== undefined && object.liquidated !== null ? SubaccountId.fromPartial(object.liquidated) : undefined;
message.perpetualId = object.perpetualId ?? 0;
message.fills = object.fills?.map(e => MatchPerpetualDeleveraging_Fill.fromPartial(e)) || [];
message.isFinalSettlement = object.isFinalSettlement ?? false;
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,20 @@ export interface DeleveragingEventV1 {
*/

fillAmount: Long;
/** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */
/** Fill price of deleveraging event, in USDC quote quantums. */

price: Long;
/** `true` if liquidating a short position, `false` otherwise. */

isBuy: boolean;
/**
* `true` if the deleveraging event is for final settlement, indicating
* the match occurred at the oracle price rather than bankruptcy price.
* When this flag is `false`, the fill price is the bankruptcy price
* of the liquidated subaccount.
*/

isFinalSettlement: boolean;
}
/**
* DeleveragingEvent message contains all the information for a deleveraging
Expand All @@ -493,12 +501,20 @@ export interface DeleveragingEventV1SDKType {
*/

fill_amount: Long;
/** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */
/** Fill price of deleveraging event, in USDC quote quantums. */

price: Long;
/** `true` if liquidating a short position, `false` otherwise. */

is_buy: boolean;
/**
* `true` if the deleveraging event is for final settlement, indicating
* the match occurred at the oracle price rather than bankruptcy price.
* When this flag is `false`, the fill price is the bankruptcy price
* of the liquidated subaccount.
*/

is_final_settlement: boolean;
}
/**
* LiquidationOrder represents the liquidation taker order to be included in a
Expand Down Expand Up @@ -1782,7 +1798,8 @@ function createBaseDeleveragingEventV1(): DeleveragingEventV1 {
perpetualId: 0,
fillAmount: Long.UZERO,
price: Long.UZERO,
isBuy: false
isBuy: false,
isFinalSettlement: false
};
}

Expand Down Expand Up @@ -1812,6 +1829,10 @@ export const DeleveragingEventV1 = {
writer.uint32(48).bool(message.isBuy);
}

if (message.isFinalSettlement === true) {
writer.uint32(56).bool(message.isFinalSettlement);
}

return writer;
},

Expand Down Expand Up @@ -1848,6 +1869,10 @@ export const DeleveragingEventV1 = {
message.isBuy = reader.bool();
break;

case 7:
message.isFinalSettlement = reader.bool();
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -1865,6 +1890,7 @@ export const DeleveragingEventV1 = {
message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO;
message.price = object.price !== undefined && object.price !== null ? Long.fromValue(object.price) : Long.UZERO;
message.isBuy = object.isBuy ?? false;
message.isFinalSettlement = object.isFinalSettlement ?? false;
return message;
}

Expand Down
1 change: 1 addition & 0 deletions indexer/services/ender/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const defaultDeleveragingEvent: DeleveragingEventV1 = {
fillAmount: Long.fromValue(10_000, true),
price: Long.fromValue(1_000_000_000, true),
isBuy: true,
isFinalSettlement: false,
};
export const defaultDepositEvent: TransferEventV1 = {
assetId: 0,
Expand Down
6 changes: 6 additions & 0 deletions proto/dydxprotocol/clob/matches.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ message MatchPerpetualDeleveraging {
}
// An ordered list of fills created by this liquidation.
repeated Fill fills = 3 [ (gogoproto.nullable) = false ];

// Flag denoting whether the deleveraging operation was for the purpose
// of final settlement. Final settlement matches are at the oracle price,
// whereas deleveraging happens at the bankruptcy price of the deleveraged
// subaccount.
bool is_final_settlement = 4;
}
7 changes: 6 additions & 1 deletion proto/dydxprotocol/indexer/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,15 @@ message DeleveragingEventV1 {
// The amount filled between the liquidated and offsetting position, in
// base quantums.
uint64 fill_amount = 4;
// Bankruptcy price of liquidated subaccount, in USDC quote quantums.
// Fill price of deleveraging event, in USDC quote quantums.
uint64 price = 5;
// `true` if liquidating a short position, `false` otherwise.
bool is_buy = 6;
// `true` if the deleveraging event is for final settlement, indicating
// the match occurred at the oracle price rather than bankruptcy price.
// When this flag is `false`, the fill price is the bankruptcy price
// of the liquidated subaccount.
bool is_final_settlement = 7;
}

// LiquidationOrder represents the liquidation taker order to be included in a
Expand Down
Loading

0 comments on commit 11fd8a0

Please sign in to comment.