From bbf3d92c9c802c9dd34317873d6971cf4d7f7ab4 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 12:26:38 -0400 Subject: [PATCH 01/17] proto --- .../dydxprotocol/indexer/events/events.ts | 151 ++++ .../dydxprotocol/indexer/events/events.proto | 21 + protocol/indexer/events/deleveraging.go | 1 + protocol/indexer/events/events.pb.go | 652 ++++++++++++++---- 4 files changed, 691 insertions(+), 134 deletions(-) create mode 100644 protocol/indexer/events/deleveraging.go diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts index 0e4160014b..b7af972194 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts @@ -444,6 +444,62 @@ export interface OrderFillEventV1SDKType { total_filled_taker: Long; } +/** + * DeleveragingEvent message contains all the information for a deleveraging + * on the dYdX chain. This includes the liquidated/offsetting subaccounts and the + * amount filled. + */ + +export interface DeleveragingEventV1 { + /** ID of the subaccount that was liquidated. */ + liquidated?: IndexerSubaccountId; + /** ID of the subaccount that was used to offset the position. */ + + offsetting?: IndexerSubaccountId; + /** The ID of the clob pair that was liquidated. */ + + clobPairId: number; + /** + * The amount filled between the liquidated and offsetting position, in + * base quantums. + */ + + fillAmount: Long; + /** The closing price in subticks. */ + + subticks: Long; + /** `true` if liquidating a short position, `false` otherwise. */ + + isBuy: boolean; +} +/** + * DeleveragingEvent message contains all the information for a deleveraging + * on the dYdX chain. This includes the liquidated/offsetting subaccounts and the + * amount filled. + */ + +export interface DeleveragingEventV1SDKType { + /** ID of the subaccount that was liquidated. */ + liquidated?: IndexerSubaccountIdSDKType; + /** ID of the subaccount that was used to offset the position. */ + + offsetting?: IndexerSubaccountIdSDKType; + /** The ID of the clob pair that was liquidated. */ + + clob_pair_id: number; + /** + * The amount filled between the liquidated and offsetting position, in + * base quantums. + */ + + fill_amount: Long; + /** The closing price in subticks. */ + + subticks: Long; + /** `true` if liquidating a short position, `false` otherwise. */ + + is_buy: boolean; +} /** * LiquidationOrder represents the liquidation taker order to be included in a * liquidation order fill event. @@ -1719,6 +1775,101 @@ export const OrderFillEventV1 = { }; +function createBaseDeleveragingEventV1(): DeleveragingEventV1 { + return { + liquidated: undefined, + offsetting: undefined, + clobPairId: 0, + fillAmount: Long.UZERO, + subticks: Long.UZERO, + isBuy: false + }; +} + +export const DeleveragingEventV1 = { + encode(message: DeleveragingEventV1, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.liquidated !== undefined) { + IndexerSubaccountId.encode(message.liquidated, writer.uint32(10).fork()).ldelim(); + } + + if (message.offsetting !== undefined) { + IndexerSubaccountId.encode(message.offsetting, writer.uint32(18).fork()).ldelim(); + } + + if (message.clobPairId !== 0) { + writer.uint32(24).uint32(message.clobPairId); + } + + if (!message.fillAmount.isZero()) { + writer.uint32(32).uint64(message.fillAmount); + } + + if (!message.subticks.isZero()) { + writer.uint32(40).uint64(message.subticks); + } + + if (message.isBuy === true) { + writer.uint32(48).bool(message.isBuy); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): DeleveragingEventV1 { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDeleveragingEventV1(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.liquidated = IndexerSubaccountId.decode(reader, reader.uint32()); + break; + + case 2: + message.offsetting = IndexerSubaccountId.decode(reader, reader.uint32()); + break; + + case 3: + message.clobPairId = reader.uint32(); + break; + + case 4: + message.fillAmount = (reader.uint64() as Long); + break; + + case 5: + message.subticks = (reader.uint64() as Long); + break; + + case 6: + message.isBuy = reader.bool(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): DeleveragingEventV1 { + const message = createBaseDeleveragingEventV1(); + message.liquidated = object.liquidated !== undefined && object.liquidated !== null ? IndexerSubaccountId.fromPartial(object.liquidated) : undefined; + message.offsetting = object.offsetting !== undefined && object.offsetting !== null ? IndexerSubaccountId.fromPartial(object.offsetting) : undefined; + message.clobPairId = object.clobPairId ?? 0; + message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO; + message.subticks = object.subticks !== undefined && object.subticks !== null ? Long.fromValue(object.subticks) : Long.UZERO; + message.isBuy = object.isBuy ?? false; + return message; + } + +}; + function createBaseLiquidationOrderV1(): LiquidationOrderV1 { return { liquidated: undefined, diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index 353ccdf151..25a7260961 100644 --- a/proto/dydxprotocol/indexer/events/events.proto +++ b/proto/dydxprotocol/indexer/events/events.proto @@ -165,6 +165,27 @@ message OrderFillEventV1 { uint64 total_filled_taker = 8; } +// DeleveragingEvent message contains all the information for a deleveraging +// on the dYdX chain. This includes the liquidated/offsetting subaccounts and the +// amount filled. +message DeleveragingEventV1 { + // ID of the subaccount that was liquidated. + dydxprotocol.indexer.protocol.v1.IndexerSubaccountId liquidated = 1 + [ (gogoproto.nullable) = false ]; + // ID of the subaccount that was used to offset the position. + dydxprotocol.indexer.protocol.v1.IndexerSubaccountId offsetting = 2 + [ (gogoproto.nullable) = false ]; + // The ID of the clob pair that was liquidated. + uint32 clob_pair_id = 3; + // The amount filled between the liquidated and offsetting position, in + // base quantums. + uint64 fill_amount = 4; + // The closing price in subticks. + uint64 subticks = 5; + // `true` if liquidating a short position, `false` otherwise. + bool is_buy = 6; +} + // LiquidationOrder represents the liquidation taker order to be included in a // liquidation order fill event. message LiquidationOrderV1 { diff --git a/protocol/indexer/events/deleveraging.go b/protocol/indexer/events/deleveraging.go new file mode 100644 index 0000000000..b3adf695cc --- /dev/null +++ b/protocol/indexer/events/deleveraging.go @@ -0,0 +1 @@ +package events diff --git a/protocol/indexer/events/events.pb.go b/protocol/indexer/events/events.pb.go index bf3ac37677..dbff0b3b1a 100644 --- a/protocol/indexer/events/events.pb.go +++ b/protocol/indexer/events/events.pb.go @@ -843,6 +843,100 @@ func (*OrderFillEventV1) XXX_OneofWrappers() []interface{} { } } +// DeleveragingEvent message contains all the information for a deleveraging +// on the dYdX chain. This includes the liquidated/offsetting subaccounts and the +// amount filled. +type DeleveragingEventV1 struct { + // ID of the subaccount that was liquidated. + Liquidated v1.IndexerSubaccountId `protobuf:"bytes,1,opt,name=liquidated,proto3" json:"liquidated"` + // ID of the subaccount that was used to offset the position. + Offsetting v1.IndexerSubaccountId `protobuf:"bytes,2,opt,name=offsetting,proto3" json:"offsetting"` + // The ID of the clob pair that was liquidated. + ClobPairId uint32 `protobuf:"varint,3,opt,name=clob_pair_id,json=clobPairId,proto3" json:"clob_pair_id,omitempty"` + // The amount filled between the liquidated and offsetting position, in + // base quantums. + FillAmount uint64 `protobuf:"varint,4,opt,name=fill_amount,json=fillAmount,proto3" json:"fill_amount,omitempty"` + // The closing price in subticks. + Subticks uint64 `protobuf:"varint,5,opt,name=subticks,proto3" json:"subticks,omitempty"` + // `true` if liquidating a short position, `false` otherwise. + IsBuy bool `protobuf:"varint,6,opt,name=is_buy,json=isBuy,proto3" json:"is_buy,omitempty"` +} + +func (m *DeleveragingEventV1) Reset() { *m = DeleveragingEventV1{} } +func (m *DeleveragingEventV1) String() string { return proto.CompactTextString(m) } +func (*DeleveragingEventV1) ProtoMessage() {} +func (*DeleveragingEventV1) Descriptor() ([]byte, []int) { + return fileDescriptor_6331dfb59c6fd2bb, []int{10} +} +func (m *DeleveragingEventV1) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeleveragingEventV1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeleveragingEventV1.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeleveragingEventV1) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleveragingEventV1.Merge(m, src) +} +func (m *DeleveragingEventV1) XXX_Size() int { + return m.Size() +} +func (m *DeleveragingEventV1) XXX_DiscardUnknown() { + xxx_messageInfo_DeleveragingEventV1.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleveragingEventV1 proto.InternalMessageInfo + +func (m *DeleveragingEventV1) GetLiquidated() v1.IndexerSubaccountId { + if m != nil { + return m.Liquidated + } + return v1.IndexerSubaccountId{} +} + +func (m *DeleveragingEventV1) GetOffsetting() v1.IndexerSubaccountId { + if m != nil { + return m.Offsetting + } + return v1.IndexerSubaccountId{} +} + +func (m *DeleveragingEventV1) GetClobPairId() uint32 { + if m != nil { + return m.ClobPairId + } + return 0 +} + +func (m *DeleveragingEventV1) GetFillAmount() uint64 { + if m != nil { + return m.FillAmount + } + return 0 +} + +func (m *DeleveragingEventV1) GetSubticks() uint64 { + if m != nil { + return m.Subticks + } + return 0 +} + +func (m *DeleveragingEventV1) GetIsBuy() bool { + if m != nil { + return m.IsBuy + } + return false +} + // LiquidationOrder represents the liquidation taker order to be included in a // liquidation order fill event. type LiquidationOrderV1 struct { @@ -869,7 +963,7 @@ func (m *LiquidationOrderV1) Reset() { *m = LiquidationOrderV1{} } func (m *LiquidationOrderV1) String() string { return proto.CompactTextString(m) } func (*LiquidationOrderV1) ProtoMessage() {} func (*LiquidationOrderV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{10} + return fileDescriptor_6331dfb59c6fd2bb, []int{11} } func (m *LiquidationOrderV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -958,7 +1052,7 @@ func (m *SubaccountUpdateEventV1) Reset() { *m = SubaccountUpdateEventV1 func (m *SubaccountUpdateEventV1) String() string { return proto.CompactTextString(m) } func (*SubaccountUpdateEventV1) ProtoMessage() {} func (*SubaccountUpdateEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{11} + return fileDescriptor_6331dfb59c6fd2bb, []int{12} } func (m *SubaccountUpdateEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1029,7 +1123,7 @@ func (m *StatefulOrderEventV1) Reset() { *m = StatefulOrderEventV1{} } func (m *StatefulOrderEventV1) String() string { return proto.CompactTextString(m) } func (*StatefulOrderEventV1) ProtoMessage() {} func (*StatefulOrderEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12} + return fileDescriptor_6331dfb59c6fd2bb, []int{13} } func (m *StatefulOrderEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1152,7 +1246,7 @@ func (m *StatefulOrderEventV1_StatefulOrderPlacementV1) String() string { } func (*StatefulOrderEventV1_StatefulOrderPlacementV1) ProtoMessage() {} func (*StatefulOrderEventV1_StatefulOrderPlacementV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12, 0} + return fileDescriptor_6331dfb59c6fd2bb, []int{13, 0} } func (m *StatefulOrderEventV1_StatefulOrderPlacementV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1203,7 +1297,7 @@ func (m *StatefulOrderEventV1_StatefulOrderRemovalV1) String() string { } func (*StatefulOrderEventV1_StatefulOrderRemovalV1) ProtoMessage() {} func (*StatefulOrderEventV1_StatefulOrderRemovalV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12, 1} + return fileDescriptor_6331dfb59c6fd2bb, []int{13, 1} } func (m *StatefulOrderEventV1_StatefulOrderRemovalV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1260,7 +1354,7 @@ func (m *StatefulOrderEventV1_ConditionalOrderPlacementV1) String() string { } func (*StatefulOrderEventV1_ConditionalOrderPlacementV1) ProtoMessage() {} func (*StatefulOrderEventV1_ConditionalOrderPlacementV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12, 2} + return fileDescriptor_6331dfb59c6fd2bb, []int{13, 2} } func (m *StatefulOrderEventV1_ConditionalOrderPlacementV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1310,7 +1404,7 @@ func (m *StatefulOrderEventV1_ConditionalOrderTriggeredV1) String() string { } func (*StatefulOrderEventV1_ConditionalOrderTriggeredV1) ProtoMessage() {} func (*StatefulOrderEventV1_ConditionalOrderTriggeredV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12, 3} + return fileDescriptor_6331dfb59c6fd2bb, []int{13, 3} } func (m *StatefulOrderEventV1_ConditionalOrderTriggeredV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1359,7 +1453,7 @@ func (m *StatefulOrderEventV1_LongTermOrderPlacementV1) String() string { } func (*StatefulOrderEventV1_LongTermOrderPlacementV1) ProtoMessage() {} func (*StatefulOrderEventV1_LongTermOrderPlacementV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{12, 4} + return fileDescriptor_6331dfb59c6fd2bb, []int{13, 4} } func (m *StatefulOrderEventV1_LongTermOrderPlacementV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1421,7 +1515,7 @@ func (m *AssetCreateEventV1) Reset() { *m = AssetCreateEventV1{} } func (m *AssetCreateEventV1) String() string { return proto.CompactTextString(m) } func (*AssetCreateEventV1) ProtoMessage() {} func (*AssetCreateEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{13} + return fileDescriptor_6331dfb59c6fd2bb, []int{14} } func (m *AssetCreateEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1530,7 +1624,7 @@ func (m *PerpetualMarketCreateEventV1) Reset() { *m = PerpetualMarketCre func (m *PerpetualMarketCreateEventV1) String() string { return proto.CompactTextString(m) } func (*PerpetualMarketCreateEventV1) ProtoMessage() {} func (*PerpetualMarketCreateEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{14} + return fileDescriptor_6331dfb59c6fd2bb, []int{15} } func (m *PerpetualMarketCreateEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1652,7 +1746,7 @@ func (m *LiquidityTierUpsertEventV1) Reset() { *m = LiquidityTierUpsertE func (m *LiquidityTierUpsertEventV1) String() string { return proto.CompactTextString(m) } func (*LiquidityTierUpsertEventV1) ProtoMessage() {} func (*LiquidityTierUpsertEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{15} + return fileDescriptor_6331dfb59c6fd2bb, []int{16} } func (m *LiquidityTierUpsertEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1743,7 +1837,7 @@ func (m *UpdateClobPairEventV1) Reset() { *m = UpdateClobPairEventV1{} } func (m *UpdateClobPairEventV1) String() string { return proto.CompactTextString(m) } func (*UpdateClobPairEventV1) ProtoMessage() {} func (*UpdateClobPairEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{16} + return fileDescriptor_6331dfb59c6fd2bb, []int{17} } func (m *UpdateClobPairEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1834,7 +1928,7 @@ func (m *UpdatePerpetualEventV1) Reset() { *m = UpdatePerpetualEventV1{} func (m *UpdatePerpetualEventV1) String() string { return proto.CompactTextString(m) } func (*UpdatePerpetualEventV1) ProtoMessage() {} func (*UpdatePerpetualEventV1) Descriptor() ([]byte, []int) { - return fileDescriptor_6331dfb59c6fd2bb, []int{17} + return fileDescriptor_6331dfb59c6fd2bb, []int{18} } func (m *UpdatePerpetualEventV1) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1910,6 +2004,7 @@ func init() { proto.RegisterType((*SourceOfFunds)(nil), "dydxprotocol.indexer.events.SourceOfFunds") proto.RegisterType((*TransferEventV1)(nil), "dydxprotocol.indexer.events.TransferEventV1") proto.RegisterType((*OrderFillEventV1)(nil), "dydxprotocol.indexer.events.OrderFillEventV1") + proto.RegisterType((*DeleveragingEventV1)(nil), "dydxprotocol.indexer.events.DeleveragingEventV1") proto.RegisterType((*LiquidationOrderV1)(nil), "dydxprotocol.indexer.events.LiquidationOrderV1") proto.RegisterType((*SubaccountUpdateEventV1)(nil), "dydxprotocol.indexer.events.SubaccountUpdateEventV1") proto.RegisterType((*StatefulOrderEventV1)(nil), "dydxprotocol.indexer.events.StatefulOrderEventV1") @@ -1930,127 +2025,130 @@ func init() { } var fileDescriptor_6331dfb59c6fd2bb = []byte{ - // 1914 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0xcd, 0x6f, 0x1c, 0x49, - 0x15, 0x77, 0xcf, 0xb4, 0xc7, 0xf6, 0xb3, 0xc7, 0x99, 0xa9, 0x38, 0xce, 0xd8, 0x06, 0xc7, 0xb4, - 0x84, 0x64, 0x65, 0x77, 0xc7, 0x71, 0x08, 0x68, 0xc5, 0x01, 0xe1, 0xb1, 0xc7, 0xeb, 0x89, 0x6c, - 0x67, 0x68, 0x8f, 0xb3, 0xbb, 0x01, 0x6d, 0x53, 0xd3, 0x5d, 0x1e, 0x97, 0xdc, 0x5f, 0xdb, 0xd5, - 0x6d, 0xe2, 0x48, 0x9c, 0xe1, 0x06, 0x12, 0x67, 0x0e, 0x1c, 0xb8, 0x20, 0x71, 0x40, 0xe2, 0xba, - 0x27, 0x2e, 0x7b, 0x63, 0xc5, 0x05, 0xc4, 0x21, 0x42, 0xc9, 0x81, 0x7f, 0x03, 0xd5, 0x47, 0xf7, - 0xcc, 0x78, 0x3e, 0x32, 0x49, 0xcc, 0xc9, 0xd3, 0xef, 0xd5, 0xfb, 0xbd, 0xcf, 0x7a, 0xf5, 0x9e, - 0x61, 0xd3, 0xb9, 0x72, 0x9e, 0x87, 0x51, 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x9f, 0x3e, 0x69, 0xd5, 0x4b, 0x79, 0xe3, 0x6f, 0x39, 0x28, 0x1e, 0xe1, - 0xe8, 0x82, 0xc4, 0x69, 0x50, 0xd6, 0x60, 0xce, 0x13, 0x84, 0x6e, 0x8a, 0x67, 0x25, 0xa1, 0xe1, - 0xa0, 0x67, 0xb0, 0x10, 0x46, 0xd4, 0x26, 0x96, 0x74, 0x5a, 0xf8, 0x3a, 0xff, 0xf0, 0xfb, 0x63, - 0x7d, 0x95, 0xf0, 0x4d, 0x2e, 0x26, 0x43, 0xa7, 0x34, 0x1d, 0x4c, 0x99, 0xf3, 0x61, 0x97, 0x8a, - 0x3e, 0x85, 0xa2, 0x52, 0x6c, 0x47, 0x84, 0x83, 0xe7, 0x05, 0xf8, 0x83, 0x09, 0xc0, 0x77, 0x85, - 0x40, 0x17, 0x77, 0xc1, 0xeb, 0x21, 0xf7, 0x00, 0x7b, 0x81, 0x43, 0xcf, 0xae, 0x2a, 0xfa, 0xc4, - 0xc0, 0x47, 0x42, 0x60, 0x00, 0x58, 0x92, 0x6b, 0x33, 0x30, 0x2d, 0x4e, 0x1b, 0x8f, 0xa1, 0x32, - 0xca, 0x4b, 0x54, 0x85, 0xdb, 0x32, 0x64, 0xbf, 0xa0, 0xf1, 0xb9, 0x45, 0x9e, 0x87, 0x81, 0x4f, - 0xfc, 0x58, 0x44, 0x56, 0x37, 0xcb, 0x82, 0xf5, 0x29, 0x8d, 0xcf, 0xeb, 0x8a, 0x61, 0x7c, 0x06, - 0x65, 0x89, 0x55, 0xc3, 0x2c, 0x03, 0x41, 0xa0, 0x87, 0x98, 0x46, 0x42, 0x6a, 0xce, 0x14, 0xbf, - 0xd1, 0x16, 0x2c, 0x79, 0xd4, 0xb7, 0x24, 0xb8, 0x7d, 0x8e, 0xfd, 0x4e, 0xf7, 0xba, 0x15, 0xcd, - 0xb2, 0x47, 0x7d, 0x61, 0xcd, 0xae, 0xe0, 0x34, 0x43, 0xcf, 0x48, 0xe0, 0xf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 0x60, 0x8f, 0x1f, 0x13, 0x37, 0x51, 0x37, 0xd5, 0x17, 0xaa, 0x41, 0x41, 0xda, 0x5d, - 0x99, 0x16, 0x06, 0xdd, 0x1f, 0x5b, 0x14, 0x7d, 0x89, 0x37, 0x95, 0x24, 0x3a, 0x80, 0xb9, 0xcc, - 0x9e, 0x4a, 0xe1, 0xad, 0x61, 0xba, 0xc2, 0xc6, 0x3f, 0xf3, 0x50, 0x7a, 0x12, 0x39, 0x24, 0xda, - 0xa7, 0xae, 0x9b, 0x66, 0xeb, 0x14, 0xe6, 0x3d, 0x7c, 0x41, 0x22, 0x2b, 0xe0, 0x9c, 0xf1, 0xc5, - 0x3b, 0x24, 0x70, 0x02, 0x4f, 0x3d, 0x1c, 0x20, 0x80, 0x04, 0x05, 0xed, 0xc3, 0xb4, 0x04, 0xcc, - 0xbd, 0x0b, 0xe0, 0xc1, 0x94, 0x29, 0xc5, 0xd1, 0x17, 0x50, 0x76, 0xe9, 0x97, 0x09, 0x75, 0x70, - 0x4c, 0x03, 0x5f, 0x19, 0x29, 0xdb, 0xdd, 0xd6, 0xd8, 0x28, 0x1c, 0x76, 0xa5, 0x04, 0xa4, 0xe8, - 0x76, 0x25, 0xf7, 0x1a, 0x15, 0xdd, 0x83, 0xf9, 0x33, 0xea, 0xba, 0x96, 0x4a, 0x5f, 0x5e, 0xa4, - 0x0f, 0x38, 0x69, 0x47, 0xa6, 0x50, 0xbc, 0x1e, 0x3c, 0x3e, 0x67, 0x84, 0x88, 0x2c, 0x22, 0xfe, - 0x7a, 0x5c, 0x90, 0x68, 0x9f, 0x10, 0xce, 0x8c, 0x33, 0x66, 0x41, 0x32, 0xe3, 0x94, 0xf9, 0x21, - 0xa0, 0x38, 0x88, 0xb1, 0x6b, 0x71, 0x34, 0xe2, 0x58, 0x42, 0xaa, 0x32, 0x23, 0x34, 0x94, 0x04, - 0x67, 0x5f, 0x30, 0x8e, 0x38, 0x7d, 0xe0, 0xb4, 0x80, 0xa9, 0xcc, 0x0e, 0x9c, 0x6e, 0x71, 0x7a, - 0xad, 0x08, 0xf3, 0x71, 0x37, 0x6b, 0xc6, 0xaf, 0x73, 0x80, 0x06, 0x1d, 0x46, 0x3f, 0x05, 0x48, - 0x1d, 0x26, 0xef, 0x77, 0xff, 0xd2, 0x0c, 0x77, 0xe1, 0xd0, 0x06, 0x2c, 0xf0, 0x89, 0xcc, 0xe2, - 0xad, 0x3b, 0xbd, 0x72, 0x45, 0x13, 0x38, 0xad, 0x89, 0x69, 0xd4, 0x70, 0x06, 0xc6, 0xab, 0xfc, - 0xe0, 0x78, 0xf5, 0x6d, 0x00, 0xe9, 0x35, 0xa3, 0x2f, 0x88, 0xba, 0x3c, 0x73, 0x82, 0x72, 0x42, - 0x5f, 0x10, 0x74, 0x07, 0x0a, 0x94, 0x59, 0xed, 0xe4, 0x4a, 0x44, 0x7e, 0xd6, 0x9c, 0xa6, 0xac, - 0x96, 0x5c, 0xf1, 0xe6, 0xcc, 0x92, 0x76, 0x4c, 0xed, 0x0b, 0x26, 0xa2, 0xae, 0x9b, 0xd9, 0xb7, - 0xf1, 0xdf, 0x1c, 0xdc, 0xed, 0x5a, 0xde, 0xff, 0x72, 0x3d, 0xbb, 0xc9, 0x5e, 0x7a, 0xad, 0x93, - 0xbe, 0x80, 0x35, 0x39, 0x42, 0x38, 0x56, 0xd7, 0xe9, 0x30, 0x60, 0x94, 0x27, 0x84, 0x55, 0xf2, - 0x62, 0x1c, 0xfb, 0xe1, 0xc4, 0x9a, 0x9a, 0x29, 0x46, 0x53, 0x41, 0x98, 0x2b, 0x0a, 0x7e, 0x80, - 0xc3, 0x90, 0x0f, 0x77, 0x53, 0xdd, 0xb2, 0x43, 0x75, 0xf5, 0xea, 0x42, 0xef, 0x0f, 0x26, 0xd6, - 0xbb, 0xc3, 0xe5, 0x33, 0x9d, 0x77, 0x14, 0x6c, 0x1f, 0x95, 0x3d, 0xd6, 0x67, 0x73, 0xa5, 0xbc, - 0xf1, 0x07, 0x80, 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0x7c, 0x04, 0xcb, 0xc2, 0xf5, 0x74, 0x46, 0xb1, 0xfc, - 0x40, 0xf6, 0x04, 0x91, 0x72, 0xdd, 0x5c, 0xe2, 0xdc, 0x74, 0xd6, 0x38, 0x56, 0x3c, 0xe3, 0xf7, - 0x39, 0xb8, 0x23, 0x87, 0xb9, 0x34, 0xdf, 0xa9, 0x6f, 0xd7, 0x2b, 0x51, 0x1b, 0xa8, 0xc4, 0x6e, - 0x51, 0xe5, 0xfe, 0xbf, 0x45, 0x95, 0x7f, 0x53, 0x51, 0x0d, 0xad, 0x13, 0xfd, 0x6d, 0xea, 0x64, - 0x7a, 0x78, 0x9d, 0x18, 0x7f, 0xd1, 0x60, 0x59, 0xc6, 0x27, 0xbb, 0xc6, 0x63, 0x9a, 0x8d, 0xba, - 0x98, 0xb9, 0xd1, 0x17, 0x33, 0x3f, 0x49, 0x37, 0xd1, 0x47, 0x5c, 0x87, 0xc1, 0xa2, 0x9d, 0x1e, - 0x52, 0xb4, 0x35, 0xf3, 0xeb, 0x57, 0xeb, 0xda, 0x37, 0xaf, 0xd6, 0xb5, 0xff, 0xbc, 0x5a, 0xd7, - 0x7e, 0xfb, 0x7a, 0x7d, 0xea, 0x9b, 0xd7, 0xeb, 0x53, 0xff, 0x7a, 0xbd, 0x3e, 0xf5, 0xec, 0xe3, - 0xc9, 0xff, 0x55, 0xda, 0xff, 0x3f, 0xed, 0x76, 0x41, 0x30, 0xbe, 0xf7, 0xbf, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xc3, 0xa2, 0xc7, 0xf2, 0xf9, 0x16, 0x00, 0x00, + // 1968 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0xcd, 0x6f, 0x1c, 0x49, + 0x15, 0xf7, 0x7c, 0x78, 0x3c, 0x7e, 0xf6, 0x38, 0x33, 0x15, 0xdb, 0x19, 0xdb, 0xe0, 0x98, 0x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 0x60, 0x08, 0x58, 0x91, 0xab, 0x33, 0x30, 0x2d, 0x77, 0x1b, 0x8f, 0xa1, 0x3c, + 0xce, 0x4b, 0x54, 0x81, 0xbb, 0x2a, 0x64, 0xbf, 0xa0, 0xfc, 0xdc, 0x22, 0xcf, 0xc3, 0xc0, 0x27, + 0x3e, 0x97, 0x91, 0xcd, 0x9a, 0x25, 0xc9, 0xfa, 0x84, 0xf2, 0xf3, 0x9a, 0x66, 0x18, 0x9f, 0x42, + 0x49, 0x61, 0x55, 0x31, 0x4b, 0x40, 0x10, 0x64, 0x43, 0x4c, 0x23, 0x29, 0x35, 0x6b, 0xca, 0xdf, + 0x68, 0x0b, 0x16, 0x3d, 0xea, 0x5b, 0x0a, 0xdc, 0x3e, 0xc7, 0x7e, 0xbb, 0x7b, 0xdc, 0x0a, 0x66, + 0xc9, 0xa3, 0xbe, 0xb4, 0x66, 0x57, 0x72, 0x1a, 0xa1, 0x67, 0x74, 0xe0, 0xee, 0x88, 0x70, 0xa1, + 0x2a, 0x64, 0xcf, 0x30, 0x23, 0x12, 0x7b, 0xee, 0x61, 0x65, 0x82, 0xa8, 0xf4, 0x58, 0x66, 0x4a, + 0x59, 0xb4, 0x0a, 0xf9, 0xc4, 0x33, 0xa1, 0xbf, 0x64, 0x26, 0x6b, 0xe3, 0xb3, 0x58, 0x6d, 0x5f, + 0x30, 0x6f, 0x43, 0xad, 0xf1, 0xe7, 0x14, 0x14, 0x4e, 0x82, 0x4e, 0x64, 0x93, 0x27, 0x2d, 0x71, + 0xa4, 0x18, 0xfa, 0x19, 0x14, 0xba, 0x77, 0x59, 0x5c, 0xc1, 0x63, 0x2b, 0x34, 0x21, 0x5c, 0x6e, + 0x57, 0xea, 0x8a, 0x76, 0x92, 0x48, 0xd7, 0x1d, 0x91, 0x70, 0xd6, 0xb3, 0x46, 0x8f, 0x60, 0x06, + 0x3b, 0x4e, 0x44, 0x18, 0x93, 0x5e, 0xce, 0x56, 0xcb, 0xff, 0xfc, 0xe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xb5, 0x91, 0xea, 0xba, 0xdb, 0xba, 0x36, 0x0a, 0x87, 0x5d, 0x29, 0x09, 0x29, 0x6f, + 0xbb, 0xa2, 0x3b, 0x40, 0x45, 0xf7, 0x61, 0xae, 0x45, 0x5d, 0xd7, 0xd2, 0xe9, 0xcb, 0xc8, 0xf4, + 0x81, 0x20, 0xed, 0xa8, 0x14, 0xca, 0xee, 0x21, 0xe2, 0xd3, 0x22, 0x44, 0x66, 0x11, 0x89, 0xee, + 0x71, 0x41, 0xa2, 0x7d, 0x42, 0x04, 0x93, 0x27, 0xcc, 0x9c, 0x62, 0xf2, 0x98, 0xf9, 0x01, 0x20, + 0x1e, 0x70, 0xec, 0x5a, 0x02, 0x8d, 0x38, 0x96, 0x94, 0x2a, 0xcf, 0x48, 0x0d, 0x45, 0xc9, 0xd9, + 0x97, 0x8c, 0x23, 0x41, 0x1f, 0xda, 0x2d, 0x61, 0xca, 0xf9, 0xa1, 0xdd, 0x4d, 0x41, 0xaf, 0x16, + 0x60, 0x8e, 0x77, 0xb3, 0x66, 0xfc, 0x3d, 0x0d, 0x77, 0xf7, 0x88, 0x4b, 0x2e, 0x49, 0x84, 0xdb, + 0x3d, 0xf3, 0xc0, 0x4f, 0x01, 0x62, 0x8f, 0xc9, 0xcd, 0x0e, 0x60, 0x9c, 0xe2, 0x2e, 0x9c, 0x00, + 0x0f, 0x5a, 0x2d, 0x46, 0x38, 0xa7, 0x7e, 0xfb, 0x46, 0x27, 0x2e, 0x06, 0xef, 0xc2, 0xa1, 0x0d, + 0x98, 0x17, 0xf3, 0x9e, 0x25, 0x1a, 0x43, 0xf7, 0xc0, 0x81, 0xa0, 0x35, 0x30, 0x8d, 0xea, 0xce, + 0x60, 0xe6, 0xb2, 0x43, 0x99, 0x5b, 0x85, 0x3c, 0xeb, 0x9c, 0x71, 0x6a, 0x5f, 0x30, 0x99, 0xb8, + 0xac, 0x99, 0xac, 0xd1, 0x12, 0xe4, 0x28, 0xb3, 0xce, 0x3a, 0x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x54, 0x89, 0xdd, 0xa2, 0x4a, 0x7f, 0xb3, 0x45, 0x95, 0x79, 0x53, 0x51, 0x8d, 0xac, + 0x93, 0xec, 0xdb, 0xd4, 0xc9, 0xf4, 0xe8, 0x3a, 0x31, 0xfe, 0x92, 0x82, 0x65, 0x15, 0x9f, 0xe4, + 0x18, 0x5f, 0x73, 0xd9, 0xe8, 0x83, 0x99, 0x1e, 0x7f, 0x30, 0x33, 0x93, 0xdc, 0x26, 0xd9, 0x31, + 0xc7, 0x61, 0xb8, 0x68, 0xa7, 0x47, 0x14, 0x6d, 0xd5, 0xfc, 0xea, 0xd5, 0x7a, 0xea, 0xeb, 0x57, + 0xeb, 0xa9, 0xff, 0xbe, 0x5a, 0x4f, 0xfd, 0xf6, 0xf5, 0xfa, 0xd4, 0xd7, 0xaf, 0xd7, 0xa7, 0xfe, + 0xfd, 0x7a, 0x7d, 0xea, 0xd9, 0x47, 0x93, 0x7f, 0x72, 0xee, 0xff, 0xdf, 0xc0, 0x59, 0x4e, 0x32, + 0xbe, 0xf7, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf3, 0xe6, 0xf8, 0xa1, 0x41, 0x18, 0x00, 0x00, } func (m *FundingUpdateV1) Marshal() (dAtA []byte, err error) { @@ -2633,6 +2731,74 @@ func (m *OrderFillEventV1_LiquidationOrder) MarshalToSizedBuffer(dAtA []byte) (i } return len(dAtA) - i, nil } +func (m *DeleveragingEventV1) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DeleveragingEventV1) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeleveragingEventV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.IsBuy { + i-- + if m.IsBuy { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if m.Subticks != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.Subticks)) + i-- + dAtA[i] = 0x28 + } + if m.FillAmount != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.FillAmount)) + i-- + dAtA[i] = 0x20 + } + if m.ClobPairId != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.ClobPairId)) + i-- + dAtA[i] = 0x18 + } + { + size, err := m.Offsetting.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Liquidated.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *LiquidationOrderV1) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -3626,6 +3792,31 @@ func (m *OrderFillEventV1_LiquidationOrder) Size() (n int) { } return n } +func (m *DeleveragingEventV1) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Liquidated.Size() + n += 1 + l + sovEvents(uint64(l)) + l = m.Offsetting.Size() + n += 1 + l + sovEvents(uint64(l)) + if m.ClobPairId != 0 { + n += 1 + sovEvents(uint64(m.ClobPairId)) + } + if m.FillAmount != 0 { + n += 1 + sovEvents(uint64(m.FillAmount)) + } + if m.Subticks != 0 { + n += 1 + sovEvents(uint64(m.Subticks)) + } + if m.IsBuy { + n += 2 + } + return n +} + func (m *LiquidationOrderV1) Size() (n int) { if m == nil { return 0 @@ -5324,6 +5515,199 @@ func (m *OrderFillEventV1) Unmarshal(dAtA []byte) error { } return nil } +func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DeleveragingEventV1: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeleveragingEventV1: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Liquidated", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Liquidated.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Offsetting", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Offsetting.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ClobPairId", wireType) + } + m.ClobPairId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ClobPairId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FillAmount", wireType) + } + m.FillAmount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FillAmount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Subticks", wireType) + } + m.Subticks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Subticks |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsBuy", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsBuy = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *LiquidationOrderV1) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 607ec573cc58f8393fcea55a609cce07e3ea8377 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 13:16:23 -0400 Subject: [PATCH 02/17] add deleveraging events --- protocol/indexer/events/constants.go | 4 ++ protocol/indexer/events/deleveraging.go | 27 +++++++++++++ protocol/indexer/events/deleveraging_test.go | 40 ++++++++++++++++++++ protocol/mocks/MemClob.go | 25 ++++++++---- protocol/x/clob/keeper/deleveraging.go | 11 +++--- protocol/x/clob/keeper/liquidations.go | 27 ++++++++++++- protocol/x/clob/keeper/liquidations_test.go | 2 +- protocol/x/clob/memclob/memclob.go | 3 +- protocol/x/clob/types/liquidations_keeper.go | 1 + protocol/x/clob/types/memclob.go | 1 + 10 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 protocol/indexer/events/deleveraging_test.go diff --git a/protocol/indexer/events/constants.go b/protocol/indexer/events/constants.go index dcf1273039..bfb182a71c 100644 --- a/protocol/indexer/events/constants.go +++ b/protocol/indexer/events/constants.go @@ -16,6 +16,7 @@ const ( SubtypeLiquidityTier = "liquidity_tier" SubtypeUpdatePerpetual = "update_perpetual" SubtypeUpdateClobPair = "update_clob_pair" + SubtypeDeleveraging = "deleveraging" ) const ( @@ -31,6 +32,7 @@ const ( LiquidityTierEventVersion uint32 = 1 UpdatePerpetualEventVersion uint32 = 1 UpdateClobPairEventVersion uint32 = 1 + DeleveragingEventVersion uint32 = 1 ) var OnChainEventSubtypes = []string{ @@ -44,4 +46,6 @@ var OnChainEventSubtypes = []string{ SubtypePerpetualMarket, SubtypeLiquidityTier, SubtypeUpdatePerpetual, + SubtypeUpdateClobPair, + SubtypeDeleveraging, } diff --git a/protocol/indexer/events/deleveraging.go b/protocol/indexer/events/deleveraging.go index b3adf695cc..e4fcc303cc 100644 --- a/protocol/indexer/events/deleveraging.go +++ b/protocol/indexer/events/deleveraging.go @@ -1 +1,28 @@ package events + +import ( + v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1" + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" +) + +// NewDeleveragingEvent creates a DeleveragingEvent representing a deleveraging +// where a liquidated subaccount's position is offset by another subaccount. +func NewDeleveragingEvent( + liquidatedSubaccountId satypes.SubaccountId, + offsettingSubaccountId satypes.SubaccountId, + clobPairId uint32, + fillAmount satypes.BaseQuantums, + subticks uint64, + isBuy bool, +) *DeleveragingEventV1 { + indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) + indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) + return &DeleveragingEventV1{ + Liquidated: indexerLiquidatedSubaccountId, + Offsetting: indexerOffsettingSubaccountId, + ClobPairId: clobPairId, + FillAmount: fillAmount.ToUint64(), + Subticks: subticks, + IsBuy: isBuy, + } +} diff --git a/protocol/indexer/events/deleveraging_test.go b/protocol/indexer/events/deleveraging_test.go new file mode 100644 index 0000000000..1ce2014b32 --- /dev/null +++ b/protocol/indexer/events/deleveraging_test.go @@ -0,0 +1,40 @@ +package events_test + +import ( + "testing" + + "github.com/dydxprotocol/v4-chain/protocol/indexer/events" + v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + "github.com/stretchr/testify/require" +) + +var ( + liquidatedSubaccountId = constants.Alice_Num0 + offsettingSubaccountId = constants.Bob_Num0 + clobPairId = uint32(1) + subticks = uint64(1000) + isBuy = true +) + +func TestNewDeleveragingEvent_Success(t *testing.T) { + deleveragingEvent := events.NewDeleveragingEvent( + liquidatedSubaccountId, + offsettingSubaccountId, + clobPairId, + fillAmount, + subticks, + isBuy, + ) + indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) + indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) + expectedDeleveragingEventProto := &events.DeleveragingEventV1{ + Liquidated: indexerLiquidatedSubaccountId, + Offsetting: indexerOffsettingSubaccountId, + ClobPairId: clobPairId, + FillAmount: fillAmount.ToUint64(), + Subticks: subticks, + IsBuy: isBuy, + } + require.Equal(t, expectedDeleveragingEventProto, deleveragingEvent) +} diff --git a/protocol/mocks/MemClob.go b/protocol/mocks/MemClob.go index a57c83df6a..9263751e93 100644 --- a/protocol/mocks/MemClob.go +++ b/protocol/mocks/MemClob.go @@ -63,26 +63,35 @@ func (_m *MemClob) CreateOrderbook(ctx types.Context, clobPair clobtypes.ClobPai } // DeleverageSubaccount provides a mock function with given fields: ctx, subaccountId, perpetualId, deltaQuantums -func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32, deltaQuantums *big.Int) (*big.Int, error) { +func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32, deltaQuantums *big.Int) ([]clobtypes.MatchPerpetualDeleveraging_Fill, *big.Int, error) { ret := _m.Called(ctx, subaccountId, perpetualId, deltaQuantums) - var r0 *big.Int - if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) *big.Int); ok { + var r0 []clobtypes.MatchPerpetualDeleveraging_Fill + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) []clobtypes.MatchPerpetualDeleveraging_Fill); ok { r0 = rf(ctx, subaccountId, perpetualId, deltaQuantums) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) + r0 = ret.Get(0).([]clobtypes.MatchPerpetualDeleveraging_Fill) } } - var r1 error - if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) error); ok { + var r1 *big.Int + if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) *big.Int); ok { r1 = rf(ctx, subaccountId, perpetualId, deltaQuantums) } else { - r1 = ret.Error(1) + if ret.Get(1) != nil { + r1 = ret.Get(1).(*big.Int) + } } - return r0, r1 + var r2 error + if rf, ok := ret.Get(2).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) error); ok { + r2 = rf(ctx, subaccountId, perpetualId, deltaQuantums) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // GetCancelOrder provides a mock function with given fields: ctx, orderId diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index f47246c477..33ca1e9e6e 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -27,6 +27,7 @@ func (k Keeper) MaybeDeleverageSubaccount( subaccountId satypes.SubaccountId, perpetualId uint32, ) ( + fills []types.MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) { @@ -34,7 +35,7 @@ func (k Keeper) MaybeDeleverageSubaccount( canPerformDeleveraging, err := k.CanDeleverageSubaccount(ctx, subaccountId) if err != nil { - return new(big.Int), err + return nil, new(big.Int), err } // Early return to skip deleveraging if the subaccount can't be deleveraged. @@ -45,7 +46,7 @@ func (k Keeper) MaybeDeleverageSubaccount( metrics.PrepareCheckState, metrics.CannotDeleverageSubaccount, ) - return new(big.Int), nil + return nil, new(big.Int), nil } // Deleverage the entire position for the given perpetual id. @@ -59,11 +60,11 @@ func (k Keeper) MaybeDeleverageSubaccount( "subaccount", subaccount, "perpetualId", perpetualId, ) - return new(big.Int), nil + return nil, new(big.Int), nil } deltaQuantums := new(big.Int).Neg(position.GetBigQuantums()) - quantumsDeleveraged, err = k.MemClob.DeleverageSubaccount(ctx, subaccountId, perpetualId, deltaQuantums) + fills, quantumsDeleveraged, err = k.MemClob.DeleverageSubaccount(ctx, subaccountId, perpetualId, deltaQuantums) labels := []gometrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), @@ -107,7 +108,7 @@ func (k Keeper) MaybeDeleverageSubaccount( labels, ) - return quantumsDeleveraged, err + return fills, quantumsDeleveraged, err } // GetInsuranceFundBalance returns the current balance of the insurance fund (in quote quantums). diff --git a/protocol/x/clob/keeper/liquidations.go b/protocol/x/clob/keeper/liquidations.go index eb5d4190b8..f0d2f1785d 100644 --- a/protocol/x/clob/keeper/liquidations.go +++ b/protocol/x/clob/keeper/liquidations.go @@ -3,6 +3,8 @@ package keeper import ( "bytes" "errors" + indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" + "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "math" "math/big" "sort" @@ -142,7 +144,11 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( subaccountId := liquidationOrder.GetSubaccountId() perpetualId := liquidationOrder.MustGetLiquidatedPerpetualId() - _, err := k.MaybeDeleverageSubaccount(ctx, subaccountId, perpetualId) + fills, _, err := k.MaybeDeleverageSubaccount(ctx, subaccountId, perpetualId) + clobPairId := k.mustGetClobPairForPerpetualId(ctx, perpetualId).Id + subticks := liquidationOrder.GetOrderSubticks() + isBuy := liquidationOrder.IsBuy() + if err != nil { k.Logger(ctx).Error( "Failed to deleverage subaccount.", @@ -152,6 +158,25 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( ) return err } + // Send on-chain deleveraging event for each fill. + for _, fill := range fills { + k.GetIndexerEventManager().AddTxnEvent( + ctx, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + indexer_manager.GetBytes( + indexerevents.NewDeleveragingEvent( + subaccountId, + fill.OffsettingSubaccountId, + clobPairId, + satypes.BaseQuantums(fill.FillAmount), + uint64(subticks), + isBuy, + ), + ), + ) + } + } telemetry.MeasureSince( startDeleverageSubaccounts, diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 38b7f6634d..8cb572be99 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -2018,7 +2018,7 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { } if tc.expectedFilledSize == 0 { - _, err = ks.ClobKeeper.MaybeDeleverageSubaccount( + _, _, err = ks.ClobKeeper.MaybeDeleverageSubaccount( ctx, tc.order.GetSubaccountId(), tc.order.MustGetLiquidatedPerpetualId(), diff --git a/protocol/x/clob/memclob/memclob.go b/protocol/x/clob/memclob/memclob.go index 6cd0f93a19..1301c10fbc 100644 --- a/protocol/x/clob/memclob/memclob.go +++ b/protocol/x/clob/memclob/memclob.go @@ -695,6 +695,7 @@ func (m *MemClobPriceTimePriority) DeleverageSubaccount( perpetualId uint32, deltaQuantums *big.Int, ) ( + fills []types.MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) { @@ -716,7 +717,7 @@ func (m *MemClobPriceTimePriority) DeleverageSubaccount( } quantumsDeleveraged = new(big.Int).Abs(new(big.Int).Sub(deltaQuantums, deltaQuantumsRemaining)) - return quantumsDeleveraged, nil + return fills, quantumsDeleveraged, nil } // matchOrder will match the provided `MatchableOrder` as a taker order against the respective orderbook. diff --git a/protocol/x/clob/types/liquidations_keeper.go b/protocol/x/clob/types/liquidations_keeper.go index 07281ad3d2..93c93a8415 100644 --- a/protocol/x/clob/types/liquidations_keeper.go +++ b/protocol/x/clob/types/liquidations_keeper.go @@ -23,6 +23,7 @@ type LiquidationsKeeper interface { subaccountId satypes.SubaccountId, perpetualId uint32, ) ( + fills []MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) diff --git a/protocol/x/clob/types/memclob.go b/protocol/x/clob/types/memclob.go index b3941fa00a..f1d042026e 100644 --- a/protocol/x/clob/types/memclob.go +++ b/protocol/x/clob/types/memclob.go @@ -91,6 +91,7 @@ type MemClob interface { perpetualId uint32, deltaQuantums *big.Int, ) ( + fills []MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) From de570362eb9c6afaedcc90de6b58a448297fe4ed Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 13:16:55 -0400 Subject: [PATCH 03/17] ender skeleton --- .../ender/__tests__/helpers/constants.ts | 14 +++- .../validators/deleveraging-validator.test.ts | 80 +++++++++++++++++++ .../src/handlers/deleveraging-handler.ts | 18 +++++ .../services/ender/src/lib/block-processor.ts | 2 + indexer/services/ender/src/lib/types.ts | 7 ++ .../src/validators/deleveraging-validator.ts | 38 +++++++++ 6 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts create mode 100644 indexer/services/ender/src/handlers/deleveraging-handler.ts create mode 100644 indexer/services/ender/src/validators/deleveraging-validator.ts diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index 80f0d9c035..8d73fda0f1 100644 --- a/indexer/services/ender/__tests__/helpers/constants.ts +++ b/indexer/services/ender/__tests__/helpers/constants.ts @@ -26,7 +26,11 @@ import { OrderRemovalReason, AssetCreateEventV1, PerpetualMarketCreateEventV1, - ClobPairStatus, LiquidityTierUpsertEventV1, UpdatePerpetualEventV1, UpdateClobPairEventV1, + ClobPairStatus, + LiquidityTierUpsertEventV1, + UpdatePerpetualEventV1, + UpdateClobPairEventV1, + DeleveragingEventV1, } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; import { DateTime } from 'luxon'; @@ -276,6 +280,14 @@ export const defaultTransferEvent: TransferEventV1 = { subaccountId: defaultRecipientSubaccountId, }, }; +export const defaultDeleveragingEvent: DeleveragingEventV1 = { + liquidated: defaultSenderSubaccountId, + offsetting: defaultRecipientSubaccountId, + clobPairId: 0, + fillAmount: Long.fromValue(10_000, true), + subticks: Long.fromValue(1_000_000_000, true), + isBuy: true, +}; export const defaultDepositEvent: TransferEventV1 = { assetId: 0, amount: Long.fromValue(100, true), diff --git a/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts b/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts new file mode 100644 index 0000000000..93dc4347d6 --- /dev/null +++ b/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts @@ -0,0 +1,80 @@ +import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; +import { DeleveragingEventV1, IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos'; +import { DydxIndexerSubtypes } from '../../src/lib/types'; +import { DeleveragingValidator } from '../../src/validators/deleveraging-validator'; +import { + defaultDeleveragingEvent, defaultHeight, defaultTime, defaultTxHash, +} from '../helpers/constants'; +import { createIndexerTendermintBlock, createIndexerTendermintEvent } from '../helpers/indexer-proto-helpers'; +import { expectDidntLogError, expectLoggedParseMessageError } from '../helpers/validator-helpers'; + +describe('deleveraging-validator', () => { + beforeEach(() => { + jest.spyOn(logger, 'error'); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + describe('validate', () => { + it('does not throw error on valid deleveraging', () => { + const validator: DeleveragingValidator = new DeleveragingValidator( + defaultDeleveragingEvent, + createBlock(defaultDeleveragingEvent), + ); + + validator.validate(); + expectDidntLogError(); + }); + + it.each([ + [ + 'does not contain liquidated', + { + ...defaultDeleveragingEvent, + liquidated: undefined, + }, + 'DeleveragingEvent must have a liquidated subaccount id', + ], + [ + 'does not contain offsetting', + { + ...defaultDeleveragingEvent, + offsetting: undefined, + }, + 'DeleveragingEvent must have an offsetting subaccount id', + ], + ])('throws error if event %s', (_message: string, event: DeleveragingEventV1, message: string) => { + const validator: DeleveragingValidator = new DeleveragingValidator( + event, + createBlock(event), + ); + + expect(() => validator.validate()).toThrow(new ParseMessageError(message)); + expectLoggedParseMessageError( + DeleveragingValidator.name, + message, + { event }, + ); + }); + }); +}); + +function createBlock( + deleveragingEvent: DeleveragingEventV1, +): IndexerTendermintBlock { + const event: IndexerTendermintEvent = createIndexerTendermintEvent( + DydxIndexerSubtypes.DELEVERAGING, + DeleveragingEventV1.encode(deleveragingEvent).finish(), + 0, + 0, + ); + + return createIndexerTendermintBlock( + defaultHeight, + defaultTime, + [event], + [defaultTxHash], + ); +} diff --git a/indexer/services/ender/src/handlers/deleveraging-handler.ts b/indexer/services/ender/src/handlers/deleveraging-handler.ts new file mode 100644 index 0000000000..e5a2755f5c --- /dev/null +++ b/indexer/services/ender/src/handlers/deleveraging-handler.ts @@ -0,0 +1,18 @@ +import { DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; + +import { ConsolidatedKafkaEvent } from '../lib/types'; +import { Handler } from './handler'; + +export class DeleveragingHandler extends Handler { + eventType: string = 'DeleveragingEvent'; + + public getParallelizationIds(): string[] { + return []; + } + + // eslint-disable-next-line @typescript-eslint/require-await + public async internalHandle(): Promise { + // Implement this + return []; + } +} diff --git a/indexer/services/ender/src/lib/block-processor.ts b/indexer/services/ender/src/lib/block-processor.ts index d35b26c72a..c284966c15 100644 --- a/indexer/services/ender/src/lib/block-processor.ts +++ b/indexer/services/ender/src/lib/block-processor.ts @@ -5,6 +5,7 @@ import _ from 'lodash'; import { Handler } from '../handlers/handler'; import { AssetValidator } from '../validators/asset-validator'; +import { DeleveragingValidator } from '../validators/deleveraging-validator'; import { FundingValidator } from '../validators/funding-validator'; import { LiquidityTierValidator } from '../validators/liquidity-tier-validator'; import { MarketValidator } from '../validators/market-validator'; @@ -35,6 +36,7 @@ const TXN_EVENT_SUBTYPE_VERSION_TO_VALIDATOR_MAPPING: Record = { diff --git a/indexer/services/ender/src/lib/types.ts b/indexer/services/ender/src/lib/types.ts index 2e07c42aea..5984f8fa61 100644 --- a/indexer/services/ender/src/lib/types.ts +++ b/indexer/services/ender/src/lib/types.ts @@ -30,6 +30,7 @@ import { LiquidityTierUpsertEventV1, UpdatePerpetualEventV1, UpdateClobPairEventV1, + DeleveragingEventV1, } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; @@ -47,6 +48,7 @@ export enum DydxIndexerSubtypes { LIQUIDITY_TIER = 'liquidity_tier', UPDATE_PERPETUAL = 'update_perpetual', UPDATE_CLOB_PAIR = 'update_clob_pair', + DELEVERAGING = 'deleveraging', } // Generic interface used for creating the Handler objects @@ -113,6 +115,11 @@ export type EventProtoWithTypeAndVersion = { eventProto: UpdateClobPairEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, +} | { + type: DydxIndexerSubtypes.DELEVERAGING, + eventProto: DeleveragingEventV1, + indexerTendermintEvent: IndexerTendermintEvent, + version: number, }); // Events grouped into events block events and events for each transactionIndex diff --git a/indexer/services/ender/src/validators/deleveraging-validator.ts b/indexer/services/ender/src/validators/deleveraging-validator.ts new file mode 100644 index 0000000000..4dde432b07 --- /dev/null +++ b/indexer/services/ender/src/validators/deleveraging-validator.ts @@ -0,0 +1,38 @@ +import { IndexerTendermintEvent, DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; + +import { DeleveragingHandler } from '../handlers/deleveraging-handler'; +import { Handler } from '../handlers/handler'; +import { Validator } from './validator'; + +export class DeleveragingValidator extends Validator { + public validate(): void { + if (this.event.liquidated === undefined) { + return this.logAndThrowParseMessageError( + 'DeleveragingEvent must have a liquidated subaccount id', + { event: this.event }, + ); + } + + if (this.event.offsetting === undefined) { + return this.logAndThrowParseMessageError( + 'DeleveragingEvent must have an offsetting subaccount id', + { event: this.event }, + ); + } + + } + + public createHandlers( + indexerTendermintEvent: IndexerTendermintEvent, + txId: number, + ): Handler[] { + return [ + new DeleveragingHandler( + this.block, + indexerTendermintEvent, + txId, + this.event, + ), + ]; + } +} From fc3899b570e7de7552dbd256b2cabba7c82c517b Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 14:33:33 -0400 Subject: [PATCH 04/17] fix mock --- protocol/mocks/ClobKeeper.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/protocol/mocks/ClobKeeper.go b/protocol/mocks/ClobKeeper.go index 942e3b3182..7ac9a44e2c 100644 --- a/protocol/mocks/ClobKeeper.go +++ b/protocol/mocks/ClobKeeper.go @@ -527,26 +527,35 @@ func (_m *ClobKeeper) Logger(ctx types.Context) log.Logger { } // MaybeDeleverageSubaccount provides a mock function with given fields: ctx, subaccountId, perpetualId -func (_m *ClobKeeper) MaybeDeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32) (*big.Int, error) { +func (_m *ClobKeeper) MaybeDeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32) ([]clobtypes.MatchPerpetualDeleveraging_Fill, *big.Int, error) { ret := _m.Called(ctx, subaccountId, perpetualId) - var r0 *big.Int - if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) *big.Int); ok { + var r0 []clobtypes.MatchPerpetualDeleveraging_Fill + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) []clobtypes.MatchPerpetualDeleveraging_Fill); ok { r0 = rf(ctx, subaccountId, perpetualId) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) + r0 = ret.Get(0).([]clobtypes.MatchPerpetualDeleveraging_Fill) } } - var r1 error - if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32) error); ok { + var r1 *big.Int + if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32) *big.Int); ok { r1 = rf(ctx, subaccountId, perpetualId) } else { - r1 = ret.Error(1) + if ret.Get(1) != nil { + r1 = ret.Get(1).(*big.Int) + } } - return r0, r1 + var r2 error + if rf, ok := ret.Get(2).(func(types.Context, subaccountstypes.SubaccountId, uint32) error); ok { + r2 = rf(ctx, subaccountId, perpetualId) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // MaybeGetLiquidationOrder provides a mock function with given fields: ctx, subaccountId From 8229d67cec6c3f6ffcbd607b7525110073c8c275 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 16:01:23 -0400 Subject: [PATCH 05/17] update --- .../src/codegen/dydxprotocol/indexer/events/events.ts | 10 ++++++++-- proto/dydxprotocol/indexer/events/events.proto | 7 ++++--- protocol/indexer/events/events.pb.go | 3 ++- protocol/x/clob/keeper/liquidations.go | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts index b7af972194..018e49a597 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts @@ -465,7 +465,10 @@ export interface DeleveragingEventV1 { */ fillAmount: Long; - /** The closing price in subticks. */ + /** + * The closing price in subticks. Bankruptcy price of liquidated subaccount + * is not guaranteed to be a multiple of subticks_per_tick. + */ subticks: Long; /** `true` if liquidating a short position, `false` otherwise. */ @@ -493,7 +496,10 @@ export interface DeleveragingEventV1SDKType { */ fill_amount: Long; - /** The closing price in subticks. */ + /** + * The closing price in subticks. Bankruptcy price of liquidated subaccount + * is not guaranteed to be a multiple of subticks_per_tick. + */ subticks: Long; /** `true` if liquidating a short position, `false` otherwise. */ diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index 25a7260961..a3f7a1b730 100644 --- a/proto/dydxprotocol/indexer/events/events.proto +++ b/proto/dydxprotocol/indexer/events/events.proto @@ -171,16 +171,17 @@ message OrderFillEventV1 { message DeleveragingEventV1 { // ID of the subaccount that was liquidated. dydxprotocol.indexer.protocol.v1.IndexerSubaccountId liquidated = 1 - [ (gogoproto.nullable) = false ]; + [ (gogoproto.nullable) = false ]; // ID of the subaccount that was used to offset the position. dydxprotocol.indexer.protocol.v1.IndexerSubaccountId offsetting = 2 - [ (gogoproto.nullable) = false ]; + [ (gogoproto.nullable) = false ]; // The ID of the clob pair that was liquidated. uint32 clob_pair_id = 3; // The amount filled between the liquidated and offsetting position, in // base quantums. uint64 fill_amount = 4; - // The closing price in subticks. + // The closing price in subticks. Bankruptcy price of liquidated subaccount + // is not guaranteed to be a multiple of subticks_per_tick. uint64 subticks = 5; // `true` if liquidating a short position, `false` otherwise. bool is_buy = 6; diff --git a/protocol/indexer/events/events.pb.go b/protocol/indexer/events/events.pb.go index dbff0b3b1a..c3f85a430c 100644 --- a/protocol/indexer/events/events.pb.go +++ b/protocol/indexer/events/events.pb.go @@ -856,7 +856,8 @@ type DeleveragingEventV1 struct { // The amount filled between the liquidated and offsetting position, in // base quantums. FillAmount uint64 `protobuf:"varint,4,opt,name=fill_amount,json=fillAmount,proto3" json:"fill_amount,omitempty"` - // The closing price in subticks. + // The closing price in subticks. Bankruptcy price of liquidated subaccount + // is not guaranteed to be a multiple of subticks_per_tick. Subticks uint64 `protobuf:"varint,5,opt,name=subticks,proto3" json:"subticks,omitempty"` // `true` if liquidating a short position, `false` otherwise. IsBuy bool `protobuf:"varint,6,opt,name=is_buy,json=isBuy,proto3" json:"is_buy,omitempty"` diff --git a/protocol/x/clob/keeper/liquidations.go b/protocol/x/clob/keeper/liquidations.go index f0d2f1785d..de7bf0045d 100644 --- a/protocol/x/clob/keeper/liquidations.go +++ b/protocol/x/clob/keeper/liquidations.go @@ -145,9 +145,6 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( perpetualId := liquidationOrder.MustGetLiquidatedPerpetualId() fills, _, err := k.MaybeDeleverageSubaccount(ctx, subaccountId, perpetualId) - clobPairId := k.mustGetClobPairForPerpetualId(ctx, perpetualId).Id - subticks := liquidationOrder.GetOrderSubticks() - isBuy := liquidationOrder.IsBuy() if err != nil { k.Logger(ctx).Error( @@ -158,6 +155,9 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( ) return err } + clobPairId := k.mustGetClobPairForPerpetualId(ctx, perpetualId).Id + subticks := liquidationOrder.GetOrderSubticks() + isBuy := liquidationOrder.IsBuy() // Send on-chain deleveraging event for each fill. for _, fill := range fills { k.GetIndexerEventManager().AddTxnEvent( From 00146ea8d5757fbc626f72102934e037b2d1a8b9 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 16:23:14 -0400 Subject: [PATCH 06/17] proto updates --- .../src/codegen/dydxprotocol/indexer/events/events.ts | 8 ++++---- proto/dydxprotocol/indexer/events/events.proto | 4 ++-- protocol/indexer/events/events.pb.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts index 018e49a597..fd2cf3ba2e 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts @@ -446,8 +446,8 @@ export interface OrderFillEventV1SDKType { } /** * DeleveragingEvent message contains all the information for a deleveraging - * on the dYdX chain. This includes the liquidated/offsetting subaccounts and the - * amount filled. + * on the dYdX chain. This includes the liquidated/offsetting subaccounts and + * the amount filled. */ export interface DeleveragingEventV1 { @@ -477,8 +477,8 @@ export interface DeleveragingEventV1 { } /** * DeleveragingEvent message contains all the information for a deleveraging - * on the dYdX chain. This includes the liquidated/offsetting subaccounts and the - * amount filled. + * on the dYdX chain. This includes the liquidated/offsetting subaccounts and + * the amount filled. */ export interface DeleveragingEventV1SDKType { diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index a3f7a1b730..cce6502484 100644 --- a/proto/dydxprotocol/indexer/events/events.proto +++ b/proto/dydxprotocol/indexer/events/events.proto @@ -166,8 +166,8 @@ message OrderFillEventV1 { } // DeleveragingEvent message contains all the information for a deleveraging -// on the dYdX chain. This includes the liquidated/offsetting subaccounts and the -// amount filled. +// on the dYdX chain. This includes the liquidated/offsetting subaccounts and +// the amount filled. message DeleveragingEventV1 { // ID of the subaccount that was liquidated. dydxprotocol.indexer.protocol.v1.IndexerSubaccountId liquidated = 1 diff --git a/protocol/indexer/events/events.pb.go b/protocol/indexer/events/events.pb.go index c3f85a430c..71749cc332 100644 --- a/protocol/indexer/events/events.pb.go +++ b/protocol/indexer/events/events.pb.go @@ -844,8 +844,8 @@ func (*OrderFillEventV1) XXX_OneofWrappers() []interface{} { } // DeleveragingEvent message contains all the information for a deleveraging -// on the dYdX chain. This includes the liquidated/offsetting subaccounts and the -// amount filled. +// on the dYdX chain. This includes the liquidated/offsetting subaccounts and +// the amount filled. type DeleveragingEventV1 struct { // ID of the subaccount that was liquidated. Liquidated v1.IndexerSubaccountId `protobuf:"bytes,1,opt,name=liquidated,proto3" json:"liquidated"` From c07f821938061c560e99c3e16b1e18e974297a14 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 16:29:58 -0400 Subject: [PATCH 07/17] lint --- protocol/x/clob/keeper/liquidations.go | 1 - 1 file changed, 1 deletion(-) diff --git a/protocol/x/clob/keeper/liquidations.go b/protocol/x/clob/keeper/liquidations.go index de7bf0045d..1b7ca63b2e 100644 --- a/protocol/x/clob/keeper/liquidations.go +++ b/protocol/x/clob/keeper/liquidations.go @@ -176,7 +176,6 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( ), ) } - } telemetry.MeasureSince( startDeleverageSubaccounts, From 46fc9144a5466f630301bc65f27676ccfce34893 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Tue, 31 Oct 2023 16:32:22 -0400 Subject: [PATCH 08/17] add deleveraging handler logic --- .../packages/postgres/src/types/fill-types.ts | 6 + .../src/types/websocket-message-types.ts | 3 +- .../handlers/deleveraging-handler.test.ts | 0 .../src/handlers/deleveraging-handler.ts | 281 +++++++++++++++++- 4 files changed, 285 insertions(+), 5 deletions(-) create mode 100644 indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts diff --git a/indexer/packages/postgres/src/types/fill-types.ts b/indexer/packages/postgres/src/types/fill-types.ts index b8006d1cab..a46aa2781d 100644 --- a/indexer/packages/postgres/src/types/fill-types.ts +++ b/indexer/packages/postgres/src/types/fill-types.ts @@ -23,6 +23,12 @@ export enum FillType { LIQUIDATED = 'LIQUIDATED', // LIQUIDATION is for the maker side of the fill, never used for orders LIQUIDATION = 'LIQUIDATION', + // DELEVERAGED is for the subaccount that was deleveraged in a deleveraging event. + // The fill type will be set to taker. + DELEVERAGED = 'DELEVERAGED', + // OFFSETTING is for the offsetting subaccount in a deleveraging event. + // The fill type will be set to maker. + OFFSETTING = 'OFFSETTING', } export interface FillCreateObject { diff --git a/indexer/packages/postgres/src/types/websocket-message-types.ts b/indexer/packages/postgres/src/types/websocket-message-types.ts index 51376e1f06..2c081e49d1 100644 --- a/indexer/packages/postgres/src/types/websocket-message-types.ts +++ b/indexer/packages/postgres/src/types/websocket-message-types.ts @@ -175,7 +175,8 @@ export interface TradeContent { price: string, side: string, createdAt: IsoString, - liquidation: boolean, + liquidation?: boolean, + deleveraging?: boolean, } /* ------- MarketMessageContents ------- */ diff --git a/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts b/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/indexer/services/ender/src/handlers/deleveraging-handler.ts b/indexer/services/ender/src/handlers/deleveraging-handler.ts index e5a2755f5c..3050e415e6 100644 --- a/indexer/services/ender/src/handlers/deleveraging-handler.ts +++ b/indexer/services/ender/src/handlers/deleveraging-handler.ts @@ -1,6 +1,33 @@ -import { DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; +import { logger } from '@dydxprotocol-indexer/base'; +import { + FillCreateObject, + FillFromDatabase, + FillTable, + FillType, + Liquidity, + OrderSide, + PerpetualMarketFromDatabase, + perpetualMarketRefresher, + PerpetualPositionColumns, + PerpetualPositionFromDatabase, + PerpetualPositionTable, + protocolTranslations, + SubaccountMessageContents, + SubaccountTable, + TendermintEventTable, + TradeMessageContents, + UpdatedPerpetualPositionSubaccountKafkaObject, +} from '@dydxprotocol-indexer/postgres'; +import { DeleveragingEventV1, IndexerSubaccountId } from '@dydxprotocol-indexer/v4-protos'; +import Big from 'big.js'; -import { ConsolidatedKafkaEvent } from '../lib/types'; +import { generateFillSubaccountMessage, generatePerpetualPositionsContents } from '../helpers/kafka-helper'; +import { + getWeightedAverage, + indexerTendermintEventToTransactionIndex, + perpetualPositionAndOrderSideMatching, +} from '../lib/helper'; +import { ConsolidatedKafkaEvent, PriceFields, SumFields } from '../lib/types'; import { Handler } from './handler'; export class DeleveragingHandler extends Handler { @@ -10,9 +37,255 @@ export class DeleveragingHandler extends Handler { return []; } + protected createFillsFromEvent( + perpetualMarket: PerpetualMarketFromDatabase, + event: DeleveragingEventV1, + ): Promise[] { + const eventId: Buffer = TendermintEventTable.createEventId( + this.block.height.toString(), + indexerTendermintEventToTransactionIndex(this.indexerTendermintEvent), + this.indexerTendermintEvent.eventIndex, + ); + const size: string = protocolTranslations.quantumsToHumanFixedString( + event.fillAmount.toString(), + perpetualMarket.atomicResolution, + ); + const price: string = protocolTranslations.subticksToPrice( + event.subticks.toString(10), + perpetualMarket, + ); + const transactionIndex: number = indexerTendermintEventToTransactionIndex( + this.indexerTendermintEvent, + ); + + const liquidatedSubaccountFill: FillCreateObject = { + subaccountId: SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number), + side: event.isBuy ? OrderSide.BUY : OrderSide.SELL, + liquidity: Liquidity.TAKER, + type: FillType.DELEVERAGED, + clobPairId: event.clobPairId.toString(), + size, + price, + quoteAmount: Big(size).times(price).toFixed(), + eventId, + transactionHash: this.block.txHashes[transactionIndex], + createdAt: this.timestamp.toISO(), + createdAtHeight: this.block.height.toString(), + fee: '0', + }; + const offsettingSubaccountFill: FillCreateObject = { + ...liquidatedSubaccountFill, + side: event.isBuy ? OrderSide.SELL : OrderSide.BUY, + liquidity: Liquidity.MAKER, + type: FillType.OFFSETTING, + }; + + return [ + FillTable.create(liquidatedSubaccountFill, { txId: this.txId }), + FillTable.create(offsettingSubaccountFill, { txId: this.txId }), + ]; + } + + protected async getLatestPerpetualPosition( + perpetualMarket: PerpetualMarketFromDatabase, + event: DeleveragingEventV1, + deleveraged: boolean, + ): Promise { + const latestPerpetualPositions: + PerpetualPositionFromDatabase[] = await PerpetualPositionTable.findAll( + { + subaccountId: deleveraged ? [ + SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number), + ] : [ + SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), + ], + perpetualId: [perpetualMarket.id], + limit: 1, + }, + [], + { txId: this.txId }, + ); + + if (latestPerpetualPositions.length === 0) { + logger.error({ + at: 'deleveragingHandler#getLatestPerpetualPosition', + message: 'Unable to find existing perpetual position.', + blockHeight: this.block.height, + clobPairId: event.clobPairId, + subaccountId: deleveraged + ? SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number) + : SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), + }); + throw new Error('Unable to find existing perpetual position'); + } + + return latestPerpetualPositions[0]; + } + + protected getOrderSide( + event: DeleveragingEventV1, + deleveraged: boolean, + ): OrderSide { + if (deleveraged) { + return event.isBuy ? OrderSide.BUY : OrderSide.SELL; + } + return event.isBuy ? OrderSide.SELL : OrderSide.BUY; + } + + protected async updatePerpetualPosition( + perpetualMarket: PerpetualMarketFromDatabase, + event: DeleveragingEventV1, + deleveraged: boolean, + ): Promise { + const latestPerpetualPosition: + PerpetualPositionFromDatabase = await this.getLatestPerpetualPosition( + perpetualMarket, + event, + deleveraged, + ); + + // update (sumOpen and entryPrice) or (sumClose and exitPrice) + let sumField: SumFields; + let priceField: PriceFields; + if (perpetualPositionAndOrderSideMatching( + latestPerpetualPosition.side, + this.getOrderSide(event, deleveraged), + )) { + sumField = PerpetualPositionColumns.sumOpen; + priceField = PerpetualPositionColumns.entryPrice; + } else { + sumField = PerpetualPositionColumns.sumClose; + priceField = PerpetualPositionColumns.exitPrice; + } + + const size: string = protocolTranslations.quantumsToHumanFixedString( + event.fillAmount.toString(), + perpetualMarket.atomicResolution, + ); + const price: string = protocolTranslations.subticksToPrice( + event.subticks.toString(10), + perpetualMarket, + ); + + const updatedPerpetualPosition: PerpetualPositionFromDatabase | undefined = await + PerpetualPositionTable.update( + { + id: latestPerpetualPosition.id, + [sumField]: Big(latestPerpetualPosition[sumField]).plus(size).toFixed(), + [priceField]: getWeightedAverage( + latestPerpetualPosition[priceField] ?? '0', + latestPerpetualPosition[sumField], + price, + size, + ), + }, + { txId: this.txId }, + ); + if (updatedPerpetualPosition === undefined) { + logger.error({ + at: 'deleveragingHandler#handle', + message: 'Unable to update perpetual position', + latestPerpetualPositionId: latestPerpetualPosition.id, + event, + }); + throw new Error(`Unable to update perpetual position with id: ${latestPerpetualPosition.id}`); + } + return updatedPerpetualPosition; + } + + protected generateConsolidatedKafkaEvent( + subaccountIdProto: IndexerSubaccountId, + position: UpdatedPerpetualPositionSubaccountKafkaObject | undefined, + fill: FillFromDatabase, + perpetualMarket: PerpetualMarketFromDatabase, + ): ConsolidatedKafkaEvent { + const message: SubaccountMessageContents = { + fills: [ + generateFillSubaccountMessage(fill, perpetualMarket.ticker), + ], + perpetualPositions: position === undefined ? undefined : generatePerpetualPositionsContents( + subaccountIdProto, + [position], + perpetualMarketRefresher.getPerpetualMarketsMap(), + ), + }; + return this.generateConsolidatedSubaccountKafkaEvent( + JSON.stringify(message), + subaccountIdProto, + undefined, + true, + message, + ); + } + + protected generateTradeKafkaEventFromDeleveraging( + fill: FillFromDatabase, + ): ConsolidatedKafkaEvent { + const tradeContents: TradeMessageContents = { + trades: [ + { + id: fill.eventId.toString('hex'), + size: fill.size, + price: fill.price, + side: fill.side.toString(), + createdAt: fill.createdAt, + deleveraging: true, + }, + ], + }; + return this.generateConsolidatedTradeKafkaEvent( + JSON.stringify(tradeContents), + fill.clobPairId, + ); + } + // eslint-disable-next-line @typescript-eslint/require-await public async internalHandle(): Promise { - // Implement this - return []; + const clobPairId: + string = this.event.clobPairId.toString(); + const perpetualMarket: PerpetualMarketFromDatabase | undefined = perpetualMarketRefresher + .getPerpetualMarketFromClobPairId(clobPairId); + if (perpetualMarket === undefined) { + logger.error({ + at: 'DeleveragingHandler#internalHandle', + message: 'Unable to find perpetual market', + clobPairId, + event: this.event, + }); + throw new Error(`Unable to find perpetual market with clobPairId: ${clobPairId}`); + } + const fills: FillFromDatabase[] = await this.runFuncWithTimingStatAndErrorLogging( + Promise.all( + this.createFillsFromEvent(perpetualMarket, this.event), + ), + this.generateTimingStatsOptions('create_fill'), + ); + + const positions: PerpetualPositionFromDatabase[] = await + this.runFuncWithTimingStatAndErrorLogging( + Promise.all([ + this.updatePerpetualPosition(perpetualMarket, this.event, true), + this.updatePerpetualPosition(perpetualMarket, this.event, false), + ]), + this.generateTimingStatsOptions('update_perpetual_position'), + ); + const kafkaEvents: ConsolidatedKafkaEvent[] = [ + this.generateConsolidatedKafkaEvent( + this.event.liquidated!, + positions[0], + fills[0], + perpetualMarket, + ), + this.generateConsolidatedKafkaEvent( + this.event.offsetting!, + positions[1], + fills[1], + perpetualMarket, + ), + this.generateTradeKafkaEventFromDeleveraging( + fills[0], + ), + ]; + return kafkaEvents; } } From 582296588570ba9d503e3652de22ffc284f06940 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Wed, 1 Nov 2023 12:23:39 -0400 Subject: [PATCH 09/17] add on-message unit test --- .../ender/__tests__/lib/on-message.test.ts | 70 +++++++++++++++++++ indexer/services/ender/src/lib/helper.ts | 9 +++ 2 files changed, 79 insertions(+) diff --git a/indexer/services/ender/__tests__/lib/on-message.test.ts b/indexer/services/ender/__tests__/lib/on-message.test.ts index 727bacd92c..7b29eba4a4 100644 --- a/indexer/services/ender/__tests__/lib/on-message.test.ts +++ b/indexer/services/ender/__tests__/lib/on-message.test.ts @@ -18,6 +18,7 @@ import { TransactionTable, } from '@dydxprotocol-indexer/postgres'; import { + DeleveragingEventV1, FundingEventV1, IndexerTendermintBlock, IndexerTendermintEvent, @@ -39,6 +40,7 @@ import { logger, stats } from '@dydxprotocol-indexer/base'; import { TransferHandler } from '../../src/handlers/transfer-handler'; import { FundingHandler } from '../../src/handlers/funding-handler'; import { + defaultDeleveragingEvent, defaultFundingUpdateSampleEvent, defaultHeight, defaultMarketModify, @@ -49,10 +51,12 @@ import { updateBlockCache } from '../../src/caches/block-cache'; import { MarketModifyHandler } from '../../src/handlers/markets/market-modify-handler'; import Long from 'long'; import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; +import { DeleveragingHandler } from '../../src/handlers/deleveraging-handler'; jest.mock('../../src/handlers/subaccount-update-handler'); jest.mock('../../src/handlers/transfer-handler'); jest.mock('../../src/handlers/funding-handler'); +jest.mock('../../src/handlers/deleveraging-handler'); jest.mock('../../src/handlers/markets/market-modify-handler'); describe('on-message', () => { @@ -80,6 +84,11 @@ describe('on-message', () => { validate: () => null, getParallelizationIds: () => [], }); + (DeleveragingHandler as jest.Mock).mockReturnValue({ + handle: () => [], + validate: () => null, + getParallelizationIds: () => [], + }); producerSendMock = jest.spyOn(producer, 'send'); producerSendMock.mockImplementation(() => { }); @@ -153,6 +162,10 @@ describe('on-message', () => { defaultMarketModify, ).finish()); + const defaultDeleveragingEventBinary: Uint8Array = Uint8Array.from(DeleveragingEventV1.encode( + defaultDeleveragingEvent, + ).finish()); + it.each([ [ 'via knex', @@ -369,6 +382,63 @@ describe('on-message', () => { expect.any(Number), 1, { success: 'true' }); }); + it('successfully processes block with deleveraging event', async () => { + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + MarketTable.create(testConstants.defaultMarket2), + ]); + await Promise.all([ + LiquidityTiersTable.create(testConstants.defaultLiquidityTier), + LiquidityTiersTable.create(testConstants.defaultLiquidityTier2), + ]); + await Promise.all([ + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket), + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket2), + ]); + await perpetualMarketRefresher.updatePerpetualMarkets(); + + const transactionIndex: number = 0; + const eventIndex: number = 0; + const events: IndexerTendermintEvent[] = [ + createIndexerTendermintEvent( + DydxIndexerSubtypes.DELEVERAGING, + defaultDeleveragingEventBinary, + transactionIndex, + eventIndex, + ), + ]; + + const block: IndexerTendermintBlock = createIndexerTendermintBlock( + defaultHeight, + defaultTime, + events, + [defaultTxHash], + ); + const binaryBlock: Uint8Array = Uint8Array.from(IndexerTendermintBlock.encode(block).finish()); + const kafkaMessage: KafkaMessage = createKafkaMessage(Buffer.from(binaryBlock)); + + await onMessage(kafkaMessage); + await Promise.all([ + expectTendermintEvent(defaultHeight.toString(), transactionIndex, eventIndex), + expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), + ]); + + expect((DeleveragingHandler as jest.Mock)).toHaveBeenCalledTimes(1); + expect((DeleveragingHandler as jest.Mock)).toHaveBeenNthCalledWith( + 1, + block, + events[0], + expect.any(Number), + defaultDeleveragingEvent, + ); + expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); + expect(stats.timing).toHaveBeenCalledWith( + 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); + expect(stats.gauge).toHaveBeenCalledWith('ender.processing_block_height', expect.any(Number)); + expect(stats.timing).toHaveBeenCalledWith('ender.processed_block.timing', + expect.any(Number), 1, { success: 'true' }); + }); + it('throws error while processing unparsable messages', async () => { const transactionIndex: number = 0; const eventIndex: number = 0; diff --git a/indexer/services/ender/src/lib/helper.ts b/indexer/services/ender/src/lib/helper.ts index 34d048e123..d1ee2f9a9c 100644 --- a/indexer/services/ender/src/lib/helper.ts +++ b/indexer/services/ender/src/lib/helper.ts @@ -22,6 +22,7 @@ import { UpdatePerpetualEventV1, UpdateClobPairEventV1, SubaccountMessage, + DeleveragingEventV1, } from '@dydxprotocol-indexer/v4-protos'; import Big from 'big.js'; import _ from 'lodash'; @@ -184,6 +185,14 @@ export function indexerTendermintEventToEventProtoWithType( version, }; } + case (DydxIndexerSubtypes.DELEVERAGING.toString()): { + return { + type: DydxIndexerSubtypes.DELEVERAGING, + eventProto: DeleveragingEventV1.decode(eventDataBinary), + indexerTendermintEvent: event, + version, + }; + } default: { const message: string = `Unable to parse event subtype: ${event.subtype}`; logger.error({ From f2d0dcef201b435a5b9249d62ea3477e006ae2ca Mon Sep 17 00:00:00 2001 From: Will Liu Date: Wed, 1 Nov 2023 12:25:16 -0400 Subject: [PATCH 10/17] add swagger docs --- indexer/services/comlink/public/api-documentation.md | 2 ++ indexer/services/comlink/public/swagger.json | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index cc2bbc80ed..82bea70654 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -2287,6 +2287,8 @@ This operation does not require authentication |*anonymous*|LIMIT| |*anonymous*|LIQUIDATED| |*anonymous*|LIQUIDATION| +|*anonymous*|DELEVERAGED| +|*anonymous*|OFFSETTING| ## MarketType diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 080629ef8e..324e83501e 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -304,7 +304,9 @@ "MARKET", "LIMIT", "LIQUIDATED", - "LIQUIDATION" + "LIQUIDATION", + "DELEVERAGED", + "OFFSETTING" ], "type": "string" }, From 3275946bb4623f5e2ecd20216f080911f1021d78 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Wed, 1 Nov 2023 16:48:58 -0400 Subject: [PATCH 11/17] update parallelization ids --- indexer/services/ender/src/constants.ts | 4 ++++ .../src/handlers/deleveraging-handler.ts | 22 ++++++++++++++++++- .../order-fills/liquidation-handler.ts | 12 +++++++++- .../src/handlers/order-fills/order-handler.ts | 9 +++++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/indexer/services/ender/src/constants.ts b/indexer/services/ender/src/constants.ts index bbfbb7e3b7..1d090feeb9 100644 --- a/indexer/services/ender/src/constants.ts +++ b/indexer/services/ender/src/constants.ts @@ -13,3 +13,7 @@ export const SUBACCOUNT_ORDER_FILL_EVENT_TYPE: string = 'subaccount_order_fill'; // StatefulOrder and OrderFill events for the same order are processed chronologically. export const STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE: string = 'stateful_order_order_fill'; + +// Deleveraging, SubaccountUpdate, and OrderFill events for the same subaccount +// are processed chronologically. +export const DELEVERAGING_EVENT_TYPE: string = 'deleveraging'; diff --git a/indexer/services/ender/src/handlers/deleveraging-handler.ts b/indexer/services/ender/src/handlers/deleveraging-handler.ts index 3050e415e6..2097b514dd 100644 --- a/indexer/services/ender/src/handlers/deleveraging-handler.ts +++ b/indexer/services/ender/src/handlers/deleveraging-handler.ts @@ -21,6 +21,11 @@ import { import { DeleveragingEventV1, IndexerSubaccountId } from '@dydxprotocol-indexer/v4-protos'; import Big from 'big.js'; +import { + DELEVERAGING_EVENT_TYPE, + STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, + SUBACCOUNT_ORDER_FILL_EVENT_TYPE, +} from '../constants'; import { generateFillSubaccountMessage, generatePerpetualPositionsContents } from '../helpers/kafka-helper'; import { getWeightedAverage, @@ -34,7 +39,22 @@ export class DeleveragingHandler extends Handler { eventType: string = 'DeleveragingEvent'; public getParallelizationIds(): string[] { - return []; + const offsettingSubaccountUuid: string = SubaccountTable + .uuid(this.event.offsetting!.owner, this.event.offsetting!.number); + const deleveragedSubaccountUuid: string = SubaccountTable + .uuid(this.event.liquidated!.owner, this.event.liquidated!.number); + return [ + `${this.eventType}_${offsettingSubaccountUuid}_${this.event.clobPairId}`, + `${this.eventType}_${deleveragedSubaccountUuid}_${this.event.clobPairId}`, + // To ensure that SubaccountUpdateEvents and OrderFillEvents for the same subaccount are not + // processed in parallel + `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${offsettingSubaccountUuid}`, + `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${deleveragedSubaccountUuid}`, + // To ensure that StatefulOrderEvents and OrderFillEvents for the same order are not + // processed in parallel + `${DELEVERAGING_EVENT_TYPE}_${offsettingSubaccountUuid}`, + `${DELEVERAGING_EVENT_TYPE}_${deleveragedSubaccountUuid}`, + ]; } protected createFillsFromEvent( diff --git a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts index 8ee0073793..b52e0206f5 100644 --- a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts @@ -16,7 +16,11 @@ import { } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; -import { STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../../constants'; +import { + DELEVERAGING_EVENT_TYPE, + STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, + SUBACCOUNT_ORDER_FILL_EVENT_TYPE, +} from '../../constants'; import { convertPerpetualPosition } from '../../helpers/kafka-helper'; import { orderFillWithLiquidityToOrderFillEventWithLiquidation } from '../../helpers/translation-helper'; import { OrderFillWithLiquidity } from '../../lib/translated-types'; @@ -50,6 +54,9 @@ export class LiquidationHandler extends AbstractOrderFillHandler Date: Wed, 1 Nov 2023 18:12:24 -0400 Subject: [PATCH 12/17] add/fix unit tests --- .../20220727134954_create_fills.ts | 2 + ...73444_update_fills_type_with_deleverage.ts | 23 ++ .../handlers/deleveraging-handler.test.ts | 329 ++++++++++++++++++ .../order-fills/liquidation-handler.test.ts | 4 + .../order-fills/order-handler.test.ts | 2 + .../ender/__tests__/helpers/constants.ts | 2 +- .../helpers/indexer-proto-helpers.ts | 39 ++- .../src/handlers/deleveraging-handler.ts | 12 +- .../abstract-order-fill-handler.ts | 3 +- .../ender/src/helpers/kafka-helper.ts | 4 + 10 files changed, 410 insertions(+), 10 deletions(-) create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts index d30b6348f8..0f4cb4d086 100644 --- a/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts @@ -19,6 +19,8 @@ export async function up(knex: Knex): Promise { 'LIMIT', 'LIQUIDATED', 'LIQUIDATION', + 'DELEVERAGED', + 'OFFSETTING', ]).notNullable(); table.bigInteger('clobPairId').notNullable(); table.uuid('orderId').nullable(); diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts new file mode 100644 index 0000000000..85a5075201 --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts @@ -0,0 +1,23 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE ONLY fills + DROP CONSTRAINT IF EXISTS fills_type_check; + + ALTER TABLE ONLY fills + ADD CONSTRAINT fills_type_check + CHECK (type = ANY (ARRAY['MARKET'::text, 'LIMIT'::text, 'LIQUIDATED'::text, 'LIQUIDATION'::text, 'DELEVERAGED'::text, 'OFFSETTING'::text])); + `); +} + +export async function down(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE ONLY fills + DROP CONSTRAINT IF EXISTS fills_type_check; + + ALTER TABLE ONLY fills + ADD CONSTRAINT fills_type_check + CHECK (type = ANY (ARRAY['MARKET'::text, 'LIMIT'::text, 'LIQUIDATED'::text, 'LIQUIDATION'::text])); + `); +} diff --git a/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts b/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts index e69de29bb2..997f13b311 100644 --- a/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts @@ -0,0 +1,329 @@ +import { logger, stats, STATS_FUNCTION_NAME } from '@dydxprotocol-indexer/base'; +import { redis } from '@dydxprotocol-indexer/redis'; +import { + assetRefresher, + dbHelpers, + FillTable, + FillType, + Liquidity, + OrderSide, + perpetualMarketRefresher, + PerpetualPositionCreateObject, + PerpetualPositionStatus, + PerpetualPositionTable, + PositionSide, + SubaccountCreateObject, + SubaccountTable, + TendermintEventTable, + testConstants, + testMocks, +} from '@dydxprotocol-indexer/postgres'; +import { updateBlockCache } from '../../src/caches/block-cache'; +import { defaultDeleveragingEvent, defaultPreviousHeight } from '../helpers/constants'; +import { clearCandlesMap } from '../../src/caches/candle-cache'; +import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; +import { redisClient } from '../../src/helpers/redis/redis-controller'; +import { + DeleveragingEventV1, + IndexerSubaccountId, + IndexerTendermintBlock, + IndexerTendermintEvent, + Timestamp, +} from '@dydxprotocol-indexer/v4-protos'; +import { + createIndexerTendermintBlock, + createIndexerTendermintEvent, + createKafkaMessageFromDeleveragingEvent, + expectDefaultTradeKafkaMessageFromTakerFillId, + expectFillInDatabase, + expectFillSubaccountKafkaMessageFromLiquidationEvent, +} from '../helpers/indexer-proto-helpers'; +import { DydxIndexerSubtypes } from '../../src/lib/types'; +import { + DELEVERAGING_EVENT_TYPE, + MILLIS_IN_NANOS, + SECONDS_IN_MILLIS, + SUBACCOUNT_ORDER_FILL_EVENT_TYPE, +} from '../../src/constants'; +import { DateTime } from 'luxon'; +import Long from 'long'; +import { DeleveragingHandler } from '../../src/handlers/deleveraging-handler'; +import { KafkaMessage } from 'kafkajs'; +import { onMessage } from '../../src/lib/on-message'; +import { producer } from '@dydxprotocol-indexer/kafka'; +import { createdDateTime, createdHeight } from '@dydxprotocol-indexer/postgres/build/__tests__/helpers/constants'; + +describe('DeleveragingHandler', () => { + const offsettingSubaccount: SubaccountCreateObject = { + address: defaultDeleveragingEvent.offsetting!.owner, + subaccountNumber: defaultDeleveragingEvent.offsetting!.number, + updatedAt: createdDateTime.toISO(), + updatedAtHeight: createdHeight, + }; + + const deleveragedSubaccount: SubaccountCreateObject = { + address: defaultDeleveragingEvent.liquidated!.owner, + subaccountNumber: defaultDeleveragingEvent.liquidated!.number, + updatedAt: createdDateTime.toISO(), + updatedAtHeight: createdHeight, + }; + + beforeAll(async () => { + await dbHelpers.migrate(); + await createPostgresFunctions(); + jest.spyOn(stats, 'increment'); + jest.spyOn(stats, 'timing'); + jest.spyOn(stats, 'gauge'); + }); + + beforeEach(async () => { + await testMocks.seedData(); + await perpetualMarketRefresher.updatePerpetualMarkets(); + await assetRefresher.updateAssets(); + updateBlockCache(defaultPreviousHeight); + }); + + afterEach(async () => { + await dbHelpers.clearData(); + jest.clearAllMocks(); + clearCandlesMap(); + await redis.deleteAllAsync(redisClient); + }); + + afterAll(async () => { + await dbHelpers.teardown(); + jest.resetAllMocks(); + }); + + const defaultHeight: string = '3'; + const defaultDateTime: DateTime = DateTime.utc(2022, 6, 1, 12, 1, 1, 2); + const defaultTime: Timestamp = { + seconds: Long.fromValue(Math.floor(defaultDateTime.toSeconds()), true), + nanos: (defaultDateTime.toMillis() % SECONDS_IN_MILLIS) * MILLIS_IN_NANOS, + }; + const defaultTxHash: string = '0x32343534306431622d306461302d343831322d613730372d3965613162336162'; + + const offsettingPerpetualPosition: PerpetualPositionCreateObject = { + subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.offsetting!), + perpetualId: testConstants.defaultPerpetualMarket.id, + side: PositionSide.LONG, + status: PerpetualPositionStatus.OPEN, + size: '10', + maxSize: '25', + sumOpen: '10', + entryPrice: '15000', + createdAt: DateTime.utc().toISO(), + createdAtHeight: '1', + openEventId: testConstants.defaultTendermintEventId, + lastEventId: testConstants.defaultTendermintEventId, + settledFunding: '200000', + }; + + it('getParallelizationIds', () => { + const offsettingSubaccountId: IndexerSubaccountId = defaultDeleveragingEvent.offsetting!; + const deleveragedSubaccountId: IndexerSubaccountId = defaultDeleveragingEvent.liquidated!; + const transactionIndex: number = 0; + const eventIndex: number = 0; + + const indexerTendermintEvent: IndexerTendermintEvent = createIndexerTendermintEvent( + DydxIndexerSubtypes.DELEVERAGING, + DeleveragingEventV1.encode(defaultDeleveragingEvent).finish(), + transactionIndex, + eventIndex, + ); + const block: IndexerTendermintBlock = createIndexerTendermintBlock( + 0, + defaultTime, + [indexerTendermintEvent], + [defaultTxHash], + ); + + const handler: DeleveragingHandler = new DeleveragingHandler( + block, + indexerTendermintEvent, + 0, + defaultDeleveragingEvent, + ); + + const offsettingSubaccountUuid: string = SubaccountTable.subaccountIdToUuid( + offsettingSubaccountId, + ); + const deleveragedSubaccountUuid: string = SubaccountTable.subaccountIdToUuid( + deleveragedSubaccountId, + ); + + expect(handler.getParallelizationIds()).toEqual([ + `${handler.eventType}_${offsettingSubaccountUuid}_${defaultDeleveragingEvent.clobPairId}`, + `${handler.eventType}_${deleveragedSubaccountUuid}_${defaultDeleveragingEvent.clobPairId}`, + // To ensure that SubaccountUpdateEvents and OrderFillEvents for the same subaccount are not + // processed in parallel + `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${offsettingSubaccountUuid}`, + `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${deleveragedSubaccountUuid}`, + // To ensure that StatefulOrderEvents and OrderFillEvents for the same order are not + // processed in parallel + `${DELEVERAGING_EVENT_TYPE}_${offsettingSubaccountUuid}`, + `${DELEVERAGING_EVENT_TYPE}_${deleveragedSubaccountUuid}`, + ]); + }); + + it('DeleveragingEvent fails validation', async () => { + const deleveragingEvent: DeleveragingEventV1 = DeleveragingEventV1 + .fromPartial({ // no liquidated subaccount + ...defaultDeleveragingEvent, + liquidated: undefined, + }); + const transactionIndex: number = 0; + const eventIndex: number = 0; + const kafkaMessage: KafkaMessage = createKafkaMessageFromDeleveragingEvent({ + deleveragingEvent, + transactionIndex, + eventIndex, + height: parseInt(defaultHeight, 10), + time: defaultTime, + txHash: defaultTxHash, + }); + const loggerCrit = jest.spyOn(logger, 'crit'); + await expect(onMessage(kafkaMessage)).rejects.toThrowError(); + + expect(loggerCrit).toHaveBeenCalledWith(expect.objectContaining({ + at: 'onMessage#onMessage', + message: 'Error: Unable to parse message, this must be due to a bug in V4 node', + })); + }); + + it('creates fills and updates perpetual positions', async () => { + const transactionIndex: number = 0; + const eventIndex: number = 0; + const kafkaMessage: KafkaMessage = createKafkaMessageFromDeleveragingEvent({ + deleveragingEvent: defaultDeleveragingEvent, + transactionIndex, + eventIndex, + height: parseInt(defaultHeight, 10), + time: defaultTime, + txHash: defaultTxHash, + }); + + // create initial Subaccounts + await Promise.all([ + SubaccountTable.create(offsettingSubaccount), + SubaccountTable.create(deleveragedSubaccount), + ]); + // create initial PerpetualPositions + await Promise.all([ + PerpetualPositionTable.create(offsettingPerpetualPosition), + PerpetualPositionTable.create({ + ...offsettingPerpetualPosition, + subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.liquidated!), + }), + ]); + + const producerSendMock: jest.SpyInstance = jest.spyOn(producer, 'send'); + await onMessage(kafkaMessage); + + const eventId: Buffer = TendermintEventTable.createEventId( + defaultHeight, + transactionIndex, + eventIndex, + ); + + // This size should be in fixed-point notation rather than exponential notation. + const quoteAmount: string = '0.1'; // quote amount is price * fillAmount = 1e5 * 1e-6 = 1e-1 + const totalFilled: string = '0.000001'; // fillAmount in human = 1e4 * 1e-10 = 1e-6 + const price: string = '100000'; // 10^9*10^-8*10^-6/10^-10=10^5 + + await expectFillInDatabase({ + subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.offsetting!), + clientId: '0', + liquidity: Liquidity.MAKER, + size: totalFilled, + price, + quoteAmount, + eventId, + transactionHash: defaultTxHash, + createdAt: defaultDateTime.toISO(), + createdAtHeight: defaultHeight, + type: FillType.OFFSETTING, + clobPairId: defaultDeleveragingEvent.clobPairId.toString(), + side: OrderSide.SELL, + orderFlags: '0', + clientMetadata: null, + hasOrderId: false, + fee: '0', + }); + await expectFillInDatabase({ + subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.liquidated!), + clientId: '0', + liquidity: Liquidity.TAKER, + size: totalFilled, + price, + quoteAmount, + eventId, + transactionHash: defaultTxHash, + createdAt: defaultDateTime.toISO(), + createdAtHeight: defaultHeight, + type: FillType.DELEVERAGED, + clobPairId: defaultDeleveragingEvent.clobPairId.toString(), + side: OrderSide.BUY, + orderFlags: '0', + clientMetadata: null, + hasOrderId: false, + fee: '0', + }); + + await Promise.all([ + expectFillsAndPositionsSubaccountKafkaMessages( + producerSendMock, + eventId, + true, + ), + expectFillsAndPositionsSubaccountKafkaMessages( + producerSendMock, + eventId, + false, + ), + expectDefaultTradeKafkaMessageFromTakerFillId( + producerSendMock, + eventId, + ), + ]); + expectTimingStats(); + }); + + async function expectFillsAndPositionsSubaccountKafkaMessages( + producerSendMock: jest.SpyInstance, + eventId: Buffer, + deleveraged: boolean, + ) { + const subaccountId: IndexerSubaccountId = deleveraged + ? defaultDeleveragingEvent.liquidated! : defaultDeleveragingEvent.offsetting!; + const liquidity: Liquidity = deleveraged ? Liquidity.TAKER : Liquidity.MAKER; + const positionId: string = ( + await PerpetualPositionTable.findOpenPositionForSubaccountPerpetual( + SubaccountTable.subaccountIdToUuid(subaccountId), + testConstants.defaultPerpetualMarket.id, + ) + )!.id; + + await Promise.all([ + expectFillSubaccountKafkaMessageFromLiquidationEvent( + producerSendMock, + subaccountId, + FillTable.uuid(eventId, liquidity), + positionId, + ), + ]); + } +}); + +function expectTimingStats() { + expectTimingStat('create_fills'); + expectTimingStat('update_perpetual_positions'); +} + +function expectTimingStat(fnName: string) { + expect(stats.timing).toHaveBeenCalledWith( + `ender.${STATS_FUNCTION_NAME}.timing`, + expect.any(Number), + { className: 'DeleveragingHandler', eventType: 'DeleveragingEvent', fnName }, + ); +} diff --git a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts index a88f11efdc..1845c4bc46 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts @@ -40,6 +40,7 @@ import { import { KafkaMessage } from 'kafkajs'; import { DateTime } from 'luxon'; import { + DELEVERAGING_EVENT_TYPE, MILLIS_IN_NANOS, SECONDS_IN_MILLIS, STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, @@ -197,6 +198,9 @@ describe('LiquidationHandler', () => { if (orderId !== undefined) { parallelizationIds.push(`${STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE}_${orderId}`); } + parallelizationIds.push( + `${DELEVERAGING_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, + ); expect(handler.getParallelizationIds()).toEqual(parallelizationIds); }); }); diff --git a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts index 8fb3468971..71d72cd845 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts @@ -42,6 +42,7 @@ import { import { KafkaMessage } from 'kafkajs'; import { DateTime } from 'luxon'; import { + DELEVERAGING_EVENT_TYPE, MILLIS_IN_NANOS, SECONDS_IN_MILLIS, STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, @@ -196,6 +197,7 @@ describe('OrderHandler', () => { `${handler.eventType}_${SubaccountTable.subaccountIdToUuid(subaccountId)}_${defaultOrderEvent.makerOrder!.orderId!.clobPairId}`, `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, `${STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE}_${orderUuid}`, + `${DELEVERAGING_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, ]); }); }); diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index 8d73fda0f1..0b86c0c59b 100644 --- a/indexer/services/ender/__tests__/helpers/constants.ts +++ b/indexer/services/ender/__tests__/helpers/constants.ts @@ -283,7 +283,7 @@ export const defaultTransferEvent: TransferEventV1 = { export const defaultDeleveragingEvent: DeleveragingEventV1 = { liquidated: defaultSenderSubaccountId, offsetting: defaultRecipientSubaccountId, - clobPairId: 0, + clobPairId: 1, fillAmount: Long.fromValue(10_000, true), subticks: Long.fromValue(1_000_000_000, true), isBuy: true, diff --git a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts index 576ee0e89e..11153077a3 100644 --- a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts +++ b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts @@ -48,6 +48,7 @@ import { OffChainUpdateV1, IndexerOrderId, PerpetualMarketCreateEventV1, + DeleveragingEventV1, } from '@dydxprotocol-indexer/v4-protos'; import { Message, ProducerRecord } from 'kafkajs'; import _ from 'lodash'; @@ -56,7 +57,7 @@ import { convertPerpetualPosition, generateFillSubaccountMessage, generatePerpetualMarketMessage, - generatePerpetualPositionsContents, + generatePerpetualPositionsContents, isDeleveraging, isLiquidation, } from '../../src/helpers/kafka-helper'; import { protoTimestampToDate } from '../../src/lib/helper'; @@ -471,6 +472,41 @@ export function createKafkaMessageFromOrderFillEvent({ return createKafkaMessage(Buffer.from(binaryBlock)); } +export function createKafkaMessageFromDeleveragingEvent({ + deleveragingEvent, + transactionIndex, + eventIndex, + height, + time, + txHash, +}: { + deleveragingEvent: DeleveragingEventV1, + transactionIndex: number, + eventIndex: number, + height: number, + time: Timestamp, + txHash: string, +}) { + const events: IndexerTendermintEvent[] = [ + createIndexerTendermintEvent( + DydxIndexerSubtypes.DELEVERAGING, + Uint8Array.from(DeleveragingEventV1.encode(deleveragingEvent).finish()), + transactionIndex, + eventIndex, + ), + ]; + + const block: IndexerTendermintBlock = createIndexerTendermintBlock( + height, + time, + events, + [txHash], + ); + + const binaryBlock: Uint8Array = Uint8Array.from(IndexerTendermintBlock.encode(block).finish()); + return createKafkaMessage(Buffer.from(binaryBlock)); +} + export function liquidationOrderToOrderSide( liquidationOrder: LiquidationOrderV1, ): OrderSide { @@ -771,6 +807,7 @@ export async function expectDefaultTradeKafkaMessageFromTakerFillId( side: takerFill!.side.toString(), createdAt: takerFill!.createdAt, liquidation: isLiquidation(takerFill!), + deleveraging: isDeleveraging(takerFill!), }, ], }; diff --git a/indexer/services/ender/src/handlers/deleveraging-handler.ts b/indexer/services/ender/src/handlers/deleveraging-handler.ts index 2097b514dd..9a0eb3ee55 100644 --- a/indexer/services/ender/src/handlers/deleveraging-handler.ts +++ b/indexer/services/ender/src/handlers/deleveraging-handler.ts @@ -21,11 +21,7 @@ import { import { DeleveragingEventV1, IndexerSubaccountId } from '@dydxprotocol-indexer/v4-protos'; import Big from 'big.js'; -import { - DELEVERAGING_EVENT_TYPE, - STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, - SUBACCOUNT_ORDER_FILL_EVENT_TYPE, -} from '../constants'; +import { DELEVERAGING_EVENT_TYPE, SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../constants'; import { generateFillSubaccountMessage, generatePerpetualPositionsContents } from '../helpers/kafka-helper'; import { getWeightedAverage, @@ -95,6 +91,7 @@ export class DeleveragingHandler extends Handler { }; const offsettingSubaccountFill: FillCreateObject = { ...liquidatedSubaccountFill, + subaccountId: SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), side: event.isBuy ? OrderSide.SELL : OrderSide.BUY, liquidity: Liquidity.MAKER, type: FillType.OFFSETTING, @@ -249,6 +246,7 @@ export class DeleveragingHandler extends Handler { price: fill.price, side: fill.side.toString(), createdAt: fill.createdAt, + liquidation: false, deleveraging: true, }, ], @@ -278,7 +276,7 @@ export class DeleveragingHandler extends Handler { Promise.all( this.createFillsFromEvent(perpetualMarket, this.event), ), - this.generateTimingStatsOptions('create_fill'), + this.generateTimingStatsOptions('create_fills'), ); const positions: PerpetualPositionFromDatabase[] = await @@ -287,7 +285,7 @@ export class DeleveragingHandler extends Handler { this.updatePerpetualPosition(perpetualMarket, this.event, true), this.updatePerpetualPosition(perpetualMarket, this.event, false), ]), - this.generateTimingStatsOptions('update_perpetual_position'), + this.generateTimingStatsOptions('update_perpetual_positions'), ); const kafkaEvents: ConsolidatedKafkaEvent[] = [ this.generateConsolidatedKafkaEvent( diff --git a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts index 670911c9a8..369376d0e1 100644 --- a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts @@ -43,7 +43,7 @@ import { DateTime } from 'luxon'; import { generateFillSubaccountMessage, generateOrderSubaccountMessage, - generatePerpetualPositionsContents, + generatePerpetualPositionsContents, isDeleveraging, isLiquidation, } from '../../helpers/kafka-helper'; import { @@ -425,6 +425,7 @@ export abstract class AbstractOrderFillHandler extends Handler { side: fill.side.toString(), createdAt: fill.createdAt, liquidation: isLiquidation(fill), + deleveraging: isDeleveraging(fill), }, ], }; diff --git a/indexer/services/ender/src/helpers/kafka-helper.ts b/indexer/services/ender/src/helpers/kafka-helper.ts index cfda119ef4..8e1f1fa579 100644 --- a/indexer/services/ender/src/helpers/kafka-helper.ts +++ b/indexer/services/ender/src/helpers/kafka-helper.ts @@ -278,6 +278,10 @@ export function isLiquidation(fill: FillFromDatabase): boolean { return fill.type === FillType.LIQUIDATION || fill.type === FillType.LIQUIDATED; } +export function isDeleveraging(fill: FillFromDatabase): boolean { + return fill.type === FillType.DELEVERAGED || fill.type === FillType.OFFSETTING; +} + export function generateFillSubaccountMessage( fill: FillFromDatabase, ticker: string, From d2c4781d38d4eeba06dbfb322e99ea90b20542b5 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Thu, 2 Nov 2023 12:05:18 -0400 Subject: [PATCH 13/17] rm --- .../20220727134954_create_fills.ts | 2 - ...73444_update_fills_type_with_deleverage.ts | 23 -- .../packages/postgres/src/types/fill-types.ts | 6 - .../src/types/websocket-message-types.ts | 3 +- .../comlink/public/api-documentation.md | 2 - indexer/services/comlink/public/swagger.json | 4 +- .../handlers/deleveraging-handler.test.ts | 329 ------------------ .../order-fills/liquidation-handler.test.ts | 4 - .../order-fills/order-handler.test.ts | 2 - .../helpers/indexer-proto-helpers.ts | 39 +-- .../src/handlers/deleveraging-handler.ts | 301 +--------------- .../abstract-order-fill-handler.ts | 3 +- .../order-fills/liquidation-handler.ts | 12 +- .../src/handlers/order-fills/order-handler.ts | 9 +- .../ender/src/helpers/kafka-helper.ts | 4 - 15 files changed, 11 insertions(+), 732 deletions(-) delete mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts delete mode 100644 indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts index 0f4cb4d086..d30b6348f8 100644 --- a/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20220727134954_create_fills.ts @@ -19,8 +19,6 @@ export async function up(knex: Knex): Promise { 'LIMIT', 'LIQUIDATED', 'LIQUIDATION', - 'DELEVERAGED', - 'OFFSETTING', ]).notNullable(); table.bigInteger('clobPairId').notNullable(); table.uuid('orderId').nullable(); diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts deleted file mode 100644 index 85a5075201..0000000000 --- a/indexer/packages/postgres/src/db/migrations/migration_files/20231101173444_update_fills_type_with_deleverage.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as Knex from 'knex'; - -export async function up(knex: Knex): Promise { - return knex.raw(` - ALTER TABLE ONLY fills - DROP CONSTRAINT IF EXISTS fills_type_check; - - ALTER TABLE ONLY fills - ADD CONSTRAINT fills_type_check - CHECK (type = ANY (ARRAY['MARKET'::text, 'LIMIT'::text, 'LIQUIDATED'::text, 'LIQUIDATION'::text, 'DELEVERAGED'::text, 'OFFSETTING'::text])); - `); -} - -export async function down(knex: Knex): Promise { - return knex.raw(` - ALTER TABLE ONLY fills - DROP CONSTRAINT IF EXISTS fills_type_check; - - ALTER TABLE ONLY fills - ADD CONSTRAINT fills_type_check - CHECK (type = ANY (ARRAY['MARKET'::text, 'LIMIT'::text, 'LIQUIDATED'::text, 'LIQUIDATION'::text])); - `); -} diff --git a/indexer/packages/postgres/src/types/fill-types.ts b/indexer/packages/postgres/src/types/fill-types.ts index a46aa2781d..b8006d1cab 100644 --- a/indexer/packages/postgres/src/types/fill-types.ts +++ b/indexer/packages/postgres/src/types/fill-types.ts @@ -23,12 +23,6 @@ export enum FillType { LIQUIDATED = 'LIQUIDATED', // LIQUIDATION is for the maker side of the fill, never used for orders LIQUIDATION = 'LIQUIDATION', - // DELEVERAGED is for the subaccount that was deleveraged in a deleveraging event. - // The fill type will be set to taker. - DELEVERAGED = 'DELEVERAGED', - // OFFSETTING is for the offsetting subaccount in a deleveraging event. - // The fill type will be set to maker. - OFFSETTING = 'OFFSETTING', } export interface FillCreateObject { diff --git a/indexer/packages/postgres/src/types/websocket-message-types.ts b/indexer/packages/postgres/src/types/websocket-message-types.ts index 2c081e49d1..51376e1f06 100644 --- a/indexer/packages/postgres/src/types/websocket-message-types.ts +++ b/indexer/packages/postgres/src/types/websocket-message-types.ts @@ -175,8 +175,7 @@ export interface TradeContent { price: string, side: string, createdAt: IsoString, - liquidation?: boolean, - deleveraging?: boolean, + liquidation: boolean, } /* ------- MarketMessageContents ------- */ diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index 82bea70654..cc2bbc80ed 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -2287,8 +2287,6 @@ This operation does not require authentication |*anonymous*|LIMIT| |*anonymous*|LIQUIDATED| |*anonymous*|LIQUIDATION| -|*anonymous*|DELEVERAGED| -|*anonymous*|OFFSETTING| ## MarketType diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 324e83501e..080629ef8e 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -304,9 +304,7 @@ "MARKET", "LIMIT", "LIQUIDATED", - "LIQUIDATION", - "DELEVERAGED", - "OFFSETTING" + "LIQUIDATION" ], "type": "string" }, diff --git a/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts b/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts deleted file mode 100644 index 997f13b311..0000000000 --- a/indexer/services/ender/__tests__/handlers/deleveraging-handler.test.ts +++ /dev/null @@ -1,329 +0,0 @@ -import { logger, stats, STATS_FUNCTION_NAME } from '@dydxprotocol-indexer/base'; -import { redis } from '@dydxprotocol-indexer/redis'; -import { - assetRefresher, - dbHelpers, - FillTable, - FillType, - Liquidity, - OrderSide, - perpetualMarketRefresher, - PerpetualPositionCreateObject, - PerpetualPositionStatus, - PerpetualPositionTable, - PositionSide, - SubaccountCreateObject, - SubaccountTable, - TendermintEventTable, - testConstants, - testMocks, -} from '@dydxprotocol-indexer/postgres'; -import { updateBlockCache } from '../../src/caches/block-cache'; -import { defaultDeleveragingEvent, defaultPreviousHeight } from '../helpers/constants'; -import { clearCandlesMap } from '../../src/caches/candle-cache'; -import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; -import { redisClient } from '../../src/helpers/redis/redis-controller'; -import { - DeleveragingEventV1, - IndexerSubaccountId, - IndexerTendermintBlock, - IndexerTendermintEvent, - Timestamp, -} from '@dydxprotocol-indexer/v4-protos'; -import { - createIndexerTendermintBlock, - createIndexerTendermintEvent, - createKafkaMessageFromDeleveragingEvent, - expectDefaultTradeKafkaMessageFromTakerFillId, - expectFillInDatabase, - expectFillSubaccountKafkaMessageFromLiquidationEvent, -} from '../helpers/indexer-proto-helpers'; -import { DydxIndexerSubtypes } from '../../src/lib/types'; -import { - DELEVERAGING_EVENT_TYPE, - MILLIS_IN_NANOS, - SECONDS_IN_MILLIS, - SUBACCOUNT_ORDER_FILL_EVENT_TYPE, -} from '../../src/constants'; -import { DateTime } from 'luxon'; -import Long from 'long'; -import { DeleveragingHandler } from '../../src/handlers/deleveraging-handler'; -import { KafkaMessage } from 'kafkajs'; -import { onMessage } from '../../src/lib/on-message'; -import { producer } from '@dydxprotocol-indexer/kafka'; -import { createdDateTime, createdHeight } from '@dydxprotocol-indexer/postgres/build/__tests__/helpers/constants'; - -describe('DeleveragingHandler', () => { - const offsettingSubaccount: SubaccountCreateObject = { - address: defaultDeleveragingEvent.offsetting!.owner, - subaccountNumber: defaultDeleveragingEvent.offsetting!.number, - updatedAt: createdDateTime.toISO(), - updatedAtHeight: createdHeight, - }; - - const deleveragedSubaccount: SubaccountCreateObject = { - address: defaultDeleveragingEvent.liquidated!.owner, - subaccountNumber: defaultDeleveragingEvent.liquidated!.number, - updatedAt: createdDateTime.toISO(), - updatedAtHeight: createdHeight, - }; - - beforeAll(async () => { - await dbHelpers.migrate(); - await createPostgresFunctions(); - jest.spyOn(stats, 'increment'); - jest.spyOn(stats, 'timing'); - jest.spyOn(stats, 'gauge'); - }); - - beforeEach(async () => { - await testMocks.seedData(); - await perpetualMarketRefresher.updatePerpetualMarkets(); - await assetRefresher.updateAssets(); - updateBlockCache(defaultPreviousHeight); - }); - - afterEach(async () => { - await dbHelpers.clearData(); - jest.clearAllMocks(); - clearCandlesMap(); - await redis.deleteAllAsync(redisClient); - }); - - afterAll(async () => { - await dbHelpers.teardown(); - jest.resetAllMocks(); - }); - - const defaultHeight: string = '3'; - const defaultDateTime: DateTime = DateTime.utc(2022, 6, 1, 12, 1, 1, 2); - const defaultTime: Timestamp = { - seconds: Long.fromValue(Math.floor(defaultDateTime.toSeconds()), true), - nanos: (defaultDateTime.toMillis() % SECONDS_IN_MILLIS) * MILLIS_IN_NANOS, - }; - const defaultTxHash: string = '0x32343534306431622d306461302d343831322d613730372d3965613162336162'; - - const offsettingPerpetualPosition: PerpetualPositionCreateObject = { - subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.offsetting!), - perpetualId: testConstants.defaultPerpetualMarket.id, - side: PositionSide.LONG, - status: PerpetualPositionStatus.OPEN, - size: '10', - maxSize: '25', - sumOpen: '10', - entryPrice: '15000', - createdAt: DateTime.utc().toISO(), - createdAtHeight: '1', - openEventId: testConstants.defaultTendermintEventId, - lastEventId: testConstants.defaultTendermintEventId, - settledFunding: '200000', - }; - - it('getParallelizationIds', () => { - const offsettingSubaccountId: IndexerSubaccountId = defaultDeleveragingEvent.offsetting!; - const deleveragedSubaccountId: IndexerSubaccountId = defaultDeleveragingEvent.liquidated!; - const transactionIndex: number = 0; - const eventIndex: number = 0; - - const indexerTendermintEvent: IndexerTendermintEvent = createIndexerTendermintEvent( - DydxIndexerSubtypes.DELEVERAGING, - DeleveragingEventV1.encode(defaultDeleveragingEvent).finish(), - transactionIndex, - eventIndex, - ); - const block: IndexerTendermintBlock = createIndexerTendermintBlock( - 0, - defaultTime, - [indexerTendermintEvent], - [defaultTxHash], - ); - - const handler: DeleveragingHandler = new DeleveragingHandler( - block, - indexerTendermintEvent, - 0, - defaultDeleveragingEvent, - ); - - const offsettingSubaccountUuid: string = SubaccountTable.subaccountIdToUuid( - offsettingSubaccountId, - ); - const deleveragedSubaccountUuid: string = SubaccountTable.subaccountIdToUuid( - deleveragedSubaccountId, - ); - - expect(handler.getParallelizationIds()).toEqual([ - `${handler.eventType}_${offsettingSubaccountUuid}_${defaultDeleveragingEvent.clobPairId}`, - `${handler.eventType}_${deleveragedSubaccountUuid}_${defaultDeleveragingEvent.clobPairId}`, - // To ensure that SubaccountUpdateEvents and OrderFillEvents for the same subaccount are not - // processed in parallel - `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${offsettingSubaccountUuid}`, - `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${deleveragedSubaccountUuid}`, - // To ensure that StatefulOrderEvents and OrderFillEvents for the same order are not - // processed in parallel - `${DELEVERAGING_EVENT_TYPE}_${offsettingSubaccountUuid}`, - `${DELEVERAGING_EVENT_TYPE}_${deleveragedSubaccountUuid}`, - ]); - }); - - it('DeleveragingEvent fails validation', async () => { - const deleveragingEvent: DeleveragingEventV1 = DeleveragingEventV1 - .fromPartial({ // no liquidated subaccount - ...defaultDeleveragingEvent, - liquidated: undefined, - }); - const transactionIndex: number = 0; - const eventIndex: number = 0; - const kafkaMessage: KafkaMessage = createKafkaMessageFromDeleveragingEvent({ - deleveragingEvent, - transactionIndex, - eventIndex, - height: parseInt(defaultHeight, 10), - time: defaultTime, - txHash: defaultTxHash, - }); - const loggerCrit = jest.spyOn(logger, 'crit'); - await expect(onMessage(kafkaMessage)).rejects.toThrowError(); - - expect(loggerCrit).toHaveBeenCalledWith(expect.objectContaining({ - at: 'onMessage#onMessage', - message: 'Error: Unable to parse message, this must be due to a bug in V4 node', - })); - }); - - it('creates fills and updates perpetual positions', async () => { - const transactionIndex: number = 0; - const eventIndex: number = 0; - const kafkaMessage: KafkaMessage = createKafkaMessageFromDeleveragingEvent({ - deleveragingEvent: defaultDeleveragingEvent, - transactionIndex, - eventIndex, - height: parseInt(defaultHeight, 10), - time: defaultTime, - txHash: defaultTxHash, - }); - - // create initial Subaccounts - await Promise.all([ - SubaccountTable.create(offsettingSubaccount), - SubaccountTable.create(deleveragedSubaccount), - ]); - // create initial PerpetualPositions - await Promise.all([ - PerpetualPositionTable.create(offsettingPerpetualPosition), - PerpetualPositionTable.create({ - ...offsettingPerpetualPosition, - subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.liquidated!), - }), - ]); - - const producerSendMock: jest.SpyInstance = jest.spyOn(producer, 'send'); - await onMessage(kafkaMessage); - - const eventId: Buffer = TendermintEventTable.createEventId( - defaultHeight, - transactionIndex, - eventIndex, - ); - - // This size should be in fixed-point notation rather than exponential notation. - const quoteAmount: string = '0.1'; // quote amount is price * fillAmount = 1e5 * 1e-6 = 1e-1 - const totalFilled: string = '0.000001'; // fillAmount in human = 1e4 * 1e-10 = 1e-6 - const price: string = '100000'; // 10^9*10^-8*10^-6/10^-10=10^5 - - await expectFillInDatabase({ - subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.offsetting!), - clientId: '0', - liquidity: Liquidity.MAKER, - size: totalFilled, - price, - quoteAmount, - eventId, - transactionHash: defaultTxHash, - createdAt: defaultDateTime.toISO(), - createdAtHeight: defaultHeight, - type: FillType.OFFSETTING, - clobPairId: defaultDeleveragingEvent.clobPairId.toString(), - side: OrderSide.SELL, - orderFlags: '0', - clientMetadata: null, - hasOrderId: false, - fee: '0', - }); - await expectFillInDatabase({ - subaccountId: SubaccountTable.subaccountIdToUuid(defaultDeleveragingEvent.liquidated!), - clientId: '0', - liquidity: Liquidity.TAKER, - size: totalFilled, - price, - quoteAmount, - eventId, - transactionHash: defaultTxHash, - createdAt: defaultDateTime.toISO(), - createdAtHeight: defaultHeight, - type: FillType.DELEVERAGED, - clobPairId: defaultDeleveragingEvent.clobPairId.toString(), - side: OrderSide.BUY, - orderFlags: '0', - clientMetadata: null, - hasOrderId: false, - fee: '0', - }); - - await Promise.all([ - expectFillsAndPositionsSubaccountKafkaMessages( - producerSendMock, - eventId, - true, - ), - expectFillsAndPositionsSubaccountKafkaMessages( - producerSendMock, - eventId, - false, - ), - expectDefaultTradeKafkaMessageFromTakerFillId( - producerSendMock, - eventId, - ), - ]); - expectTimingStats(); - }); - - async function expectFillsAndPositionsSubaccountKafkaMessages( - producerSendMock: jest.SpyInstance, - eventId: Buffer, - deleveraged: boolean, - ) { - const subaccountId: IndexerSubaccountId = deleveraged - ? defaultDeleveragingEvent.liquidated! : defaultDeleveragingEvent.offsetting!; - const liquidity: Liquidity = deleveraged ? Liquidity.TAKER : Liquidity.MAKER; - const positionId: string = ( - await PerpetualPositionTable.findOpenPositionForSubaccountPerpetual( - SubaccountTable.subaccountIdToUuid(subaccountId), - testConstants.defaultPerpetualMarket.id, - ) - )!.id; - - await Promise.all([ - expectFillSubaccountKafkaMessageFromLiquidationEvent( - producerSendMock, - subaccountId, - FillTable.uuid(eventId, liquidity), - positionId, - ), - ]); - } -}); - -function expectTimingStats() { - expectTimingStat('create_fills'); - expectTimingStat('update_perpetual_positions'); -} - -function expectTimingStat(fnName: string) { - expect(stats.timing).toHaveBeenCalledWith( - `ender.${STATS_FUNCTION_NAME}.timing`, - expect.any(Number), - { className: 'DeleveragingHandler', eventType: 'DeleveragingEvent', fnName }, - ); -} diff --git a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts index 1845c4bc46..a88f11efdc 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts @@ -40,7 +40,6 @@ import { import { KafkaMessage } from 'kafkajs'; import { DateTime } from 'luxon'; import { - DELEVERAGING_EVENT_TYPE, MILLIS_IN_NANOS, SECONDS_IN_MILLIS, STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, @@ -198,9 +197,6 @@ describe('LiquidationHandler', () => { if (orderId !== undefined) { parallelizationIds.push(`${STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE}_${orderId}`); } - parallelizationIds.push( - `${DELEVERAGING_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, - ); expect(handler.getParallelizationIds()).toEqual(parallelizationIds); }); }); diff --git a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts index 657cede888..a8bf586610 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts @@ -42,7 +42,6 @@ import { import { KafkaMessage } from 'kafkajs'; import { DateTime } from 'luxon'; import { - DELEVERAGING_EVENT_TYPE, MILLIS_IN_NANOS, SECONDS_IN_MILLIS, STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, @@ -197,7 +196,6 @@ describe('OrderHandler', () => { `${handler.eventType}_${SubaccountTable.subaccountIdToUuid(subaccountId)}_${defaultOrderEvent.makerOrder!.orderId!.clobPairId}`, `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, `${STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE}_${orderUuid}`, - `${DELEVERAGING_EVENT_TYPE}_${SubaccountTable.subaccountIdToUuid(subaccountId)}`, ]); }); }); diff --git a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts index 11153077a3..576ee0e89e 100644 --- a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts +++ b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts @@ -48,7 +48,6 @@ import { OffChainUpdateV1, IndexerOrderId, PerpetualMarketCreateEventV1, - DeleveragingEventV1, } from '@dydxprotocol-indexer/v4-protos'; import { Message, ProducerRecord } from 'kafkajs'; import _ from 'lodash'; @@ -57,7 +56,7 @@ import { convertPerpetualPosition, generateFillSubaccountMessage, generatePerpetualMarketMessage, - generatePerpetualPositionsContents, isDeleveraging, + generatePerpetualPositionsContents, isLiquidation, } from '../../src/helpers/kafka-helper'; import { protoTimestampToDate } from '../../src/lib/helper'; @@ -472,41 +471,6 @@ export function createKafkaMessageFromOrderFillEvent({ return createKafkaMessage(Buffer.from(binaryBlock)); } -export function createKafkaMessageFromDeleveragingEvent({ - deleveragingEvent, - transactionIndex, - eventIndex, - height, - time, - txHash, -}: { - deleveragingEvent: DeleveragingEventV1, - transactionIndex: number, - eventIndex: number, - height: number, - time: Timestamp, - txHash: string, -}) { - const events: IndexerTendermintEvent[] = [ - createIndexerTendermintEvent( - DydxIndexerSubtypes.DELEVERAGING, - Uint8Array.from(DeleveragingEventV1.encode(deleveragingEvent).finish()), - transactionIndex, - eventIndex, - ), - ]; - - const block: IndexerTendermintBlock = createIndexerTendermintBlock( - height, - time, - events, - [txHash], - ); - - const binaryBlock: Uint8Array = Uint8Array.from(IndexerTendermintBlock.encode(block).finish()); - return createKafkaMessage(Buffer.from(binaryBlock)); -} - export function liquidationOrderToOrderSide( liquidationOrder: LiquidationOrderV1, ): OrderSide { @@ -807,7 +771,6 @@ export async function expectDefaultTradeKafkaMessageFromTakerFillId( side: takerFill!.side.toString(), createdAt: takerFill!.createdAt, liquidation: isLiquidation(takerFill!), - deleveraging: isDeleveraging(takerFill!), }, ], }; diff --git a/indexer/services/ender/src/handlers/deleveraging-handler.ts b/indexer/services/ender/src/handlers/deleveraging-handler.ts index 9a0eb3ee55..e5a2755f5c 100644 --- a/indexer/services/ender/src/handlers/deleveraging-handler.ts +++ b/indexer/services/ender/src/handlers/deleveraging-handler.ts @@ -1,309 +1,18 @@ -import { logger } from '@dydxprotocol-indexer/base'; -import { - FillCreateObject, - FillFromDatabase, - FillTable, - FillType, - Liquidity, - OrderSide, - PerpetualMarketFromDatabase, - perpetualMarketRefresher, - PerpetualPositionColumns, - PerpetualPositionFromDatabase, - PerpetualPositionTable, - protocolTranslations, - SubaccountMessageContents, - SubaccountTable, - TendermintEventTable, - TradeMessageContents, - UpdatedPerpetualPositionSubaccountKafkaObject, -} from '@dydxprotocol-indexer/postgres'; -import { DeleveragingEventV1, IndexerSubaccountId } from '@dydxprotocol-indexer/v4-protos'; -import Big from 'big.js'; +import { DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; -import { DELEVERAGING_EVENT_TYPE, SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../constants'; -import { generateFillSubaccountMessage, generatePerpetualPositionsContents } from '../helpers/kafka-helper'; -import { - getWeightedAverage, - indexerTendermintEventToTransactionIndex, - perpetualPositionAndOrderSideMatching, -} from '../lib/helper'; -import { ConsolidatedKafkaEvent, PriceFields, SumFields } from '../lib/types'; +import { ConsolidatedKafkaEvent } from '../lib/types'; import { Handler } from './handler'; export class DeleveragingHandler extends Handler { eventType: string = 'DeleveragingEvent'; public getParallelizationIds(): string[] { - const offsettingSubaccountUuid: string = SubaccountTable - .uuid(this.event.offsetting!.owner, this.event.offsetting!.number); - const deleveragedSubaccountUuid: string = SubaccountTable - .uuid(this.event.liquidated!.owner, this.event.liquidated!.number); - return [ - `${this.eventType}_${offsettingSubaccountUuid}_${this.event.clobPairId}`, - `${this.eventType}_${deleveragedSubaccountUuid}_${this.event.clobPairId}`, - // To ensure that SubaccountUpdateEvents and OrderFillEvents for the same subaccount are not - // processed in parallel - `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${offsettingSubaccountUuid}`, - `${SUBACCOUNT_ORDER_FILL_EVENT_TYPE}_${deleveragedSubaccountUuid}`, - // To ensure that StatefulOrderEvents and OrderFillEvents for the same order are not - // processed in parallel - `${DELEVERAGING_EVENT_TYPE}_${offsettingSubaccountUuid}`, - `${DELEVERAGING_EVENT_TYPE}_${deleveragedSubaccountUuid}`, - ]; - } - - protected createFillsFromEvent( - perpetualMarket: PerpetualMarketFromDatabase, - event: DeleveragingEventV1, - ): Promise[] { - const eventId: Buffer = TendermintEventTable.createEventId( - this.block.height.toString(), - indexerTendermintEventToTransactionIndex(this.indexerTendermintEvent), - this.indexerTendermintEvent.eventIndex, - ); - const size: string = protocolTranslations.quantumsToHumanFixedString( - event.fillAmount.toString(), - perpetualMarket.atomicResolution, - ); - const price: string = protocolTranslations.subticksToPrice( - event.subticks.toString(10), - perpetualMarket, - ); - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - - const liquidatedSubaccountFill: FillCreateObject = { - subaccountId: SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number), - side: event.isBuy ? OrderSide.BUY : OrderSide.SELL, - liquidity: Liquidity.TAKER, - type: FillType.DELEVERAGED, - clobPairId: event.clobPairId.toString(), - size, - price, - quoteAmount: Big(size).times(price).toFixed(), - eventId, - transactionHash: this.block.txHashes[transactionIndex], - createdAt: this.timestamp.toISO(), - createdAtHeight: this.block.height.toString(), - fee: '0', - }; - const offsettingSubaccountFill: FillCreateObject = { - ...liquidatedSubaccountFill, - subaccountId: SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), - side: event.isBuy ? OrderSide.SELL : OrderSide.BUY, - liquidity: Liquidity.MAKER, - type: FillType.OFFSETTING, - }; - - return [ - FillTable.create(liquidatedSubaccountFill, { txId: this.txId }), - FillTable.create(offsettingSubaccountFill, { txId: this.txId }), - ]; - } - - protected async getLatestPerpetualPosition( - perpetualMarket: PerpetualMarketFromDatabase, - event: DeleveragingEventV1, - deleveraged: boolean, - ): Promise { - const latestPerpetualPositions: - PerpetualPositionFromDatabase[] = await PerpetualPositionTable.findAll( - { - subaccountId: deleveraged ? [ - SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number), - ] : [ - SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), - ], - perpetualId: [perpetualMarket.id], - limit: 1, - }, - [], - { txId: this.txId }, - ); - - if (latestPerpetualPositions.length === 0) { - logger.error({ - at: 'deleveragingHandler#getLatestPerpetualPosition', - message: 'Unable to find existing perpetual position.', - blockHeight: this.block.height, - clobPairId: event.clobPairId, - subaccountId: deleveraged - ? SubaccountTable.uuid(event.liquidated!.owner, event.liquidated!.number) - : SubaccountTable.uuid(event.offsetting!.owner, event.offsetting!.number), - }); - throw new Error('Unable to find existing perpetual position'); - } - - return latestPerpetualPositions[0]; - } - - protected getOrderSide( - event: DeleveragingEventV1, - deleveraged: boolean, - ): OrderSide { - if (deleveraged) { - return event.isBuy ? OrderSide.BUY : OrderSide.SELL; - } - return event.isBuy ? OrderSide.SELL : OrderSide.BUY; - } - - protected async updatePerpetualPosition( - perpetualMarket: PerpetualMarketFromDatabase, - event: DeleveragingEventV1, - deleveraged: boolean, - ): Promise { - const latestPerpetualPosition: - PerpetualPositionFromDatabase = await this.getLatestPerpetualPosition( - perpetualMarket, - event, - deleveraged, - ); - - // update (sumOpen and entryPrice) or (sumClose and exitPrice) - let sumField: SumFields; - let priceField: PriceFields; - if (perpetualPositionAndOrderSideMatching( - latestPerpetualPosition.side, - this.getOrderSide(event, deleveraged), - )) { - sumField = PerpetualPositionColumns.sumOpen; - priceField = PerpetualPositionColumns.entryPrice; - } else { - sumField = PerpetualPositionColumns.sumClose; - priceField = PerpetualPositionColumns.exitPrice; - } - - const size: string = protocolTranslations.quantumsToHumanFixedString( - event.fillAmount.toString(), - perpetualMarket.atomicResolution, - ); - const price: string = protocolTranslations.subticksToPrice( - event.subticks.toString(10), - perpetualMarket, - ); - - const updatedPerpetualPosition: PerpetualPositionFromDatabase | undefined = await - PerpetualPositionTable.update( - { - id: latestPerpetualPosition.id, - [sumField]: Big(latestPerpetualPosition[sumField]).plus(size).toFixed(), - [priceField]: getWeightedAverage( - latestPerpetualPosition[priceField] ?? '0', - latestPerpetualPosition[sumField], - price, - size, - ), - }, - { txId: this.txId }, - ); - if (updatedPerpetualPosition === undefined) { - logger.error({ - at: 'deleveragingHandler#handle', - message: 'Unable to update perpetual position', - latestPerpetualPositionId: latestPerpetualPosition.id, - event, - }); - throw new Error(`Unable to update perpetual position with id: ${latestPerpetualPosition.id}`); - } - return updatedPerpetualPosition; - } - - protected generateConsolidatedKafkaEvent( - subaccountIdProto: IndexerSubaccountId, - position: UpdatedPerpetualPositionSubaccountKafkaObject | undefined, - fill: FillFromDatabase, - perpetualMarket: PerpetualMarketFromDatabase, - ): ConsolidatedKafkaEvent { - const message: SubaccountMessageContents = { - fills: [ - generateFillSubaccountMessage(fill, perpetualMarket.ticker), - ], - perpetualPositions: position === undefined ? undefined : generatePerpetualPositionsContents( - subaccountIdProto, - [position], - perpetualMarketRefresher.getPerpetualMarketsMap(), - ), - }; - return this.generateConsolidatedSubaccountKafkaEvent( - JSON.stringify(message), - subaccountIdProto, - undefined, - true, - message, - ); - } - - protected generateTradeKafkaEventFromDeleveraging( - fill: FillFromDatabase, - ): ConsolidatedKafkaEvent { - const tradeContents: TradeMessageContents = { - trades: [ - { - id: fill.eventId.toString('hex'), - size: fill.size, - price: fill.price, - side: fill.side.toString(), - createdAt: fill.createdAt, - liquidation: false, - deleveraging: true, - }, - ], - }; - return this.generateConsolidatedTradeKafkaEvent( - JSON.stringify(tradeContents), - fill.clobPairId, - ); + return []; } // eslint-disable-next-line @typescript-eslint/require-await public async internalHandle(): Promise { - const clobPairId: - string = this.event.clobPairId.toString(); - const perpetualMarket: PerpetualMarketFromDatabase | undefined = perpetualMarketRefresher - .getPerpetualMarketFromClobPairId(clobPairId); - if (perpetualMarket === undefined) { - logger.error({ - at: 'DeleveragingHandler#internalHandle', - message: 'Unable to find perpetual market', - clobPairId, - event: this.event, - }); - throw new Error(`Unable to find perpetual market with clobPairId: ${clobPairId}`); - } - const fills: FillFromDatabase[] = await this.runFuncWithTimingStatAndErrorLogging( - Promise.all( - this.createFillsFromEvent(perpetualMarket, this.event), - ), - this.generateTimingStatsOptions('create_fills'), - ); - - const positions: PerpetualPositionFromDatabase[] = await - this.runFuncWithTimingStatAndErrorLogging( - Promise.all([ - this.updatePerpetualPosition(perpetualMarket, this.event, true), - this.updatePerpetualPosition(perpetualMarket, this.event, false), - ]), - this.generateTimingStatsOptions('update_perpetual_positions'), - ); - const kafkaEvents: ConsolidatedKafkaEvent[] = [ - this.generateConsolidatedKafkaEvent( - this.event.liquidated!, - positions[0], - fills[0], - perpetualMarket, - ), - this.generateConsolidatedKafkaEvent( - this.event.offsetting!, - positions[1], - fills[1], - perpetualMarket, - ), - this.generateTradeKafkaEventFromDeleveraging( - fills[0], - ), - ]; - return kafkaEvents; + // Implement this + return []; } } diff --git a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts index 369376d0e1..670911c9a8 100644 --- a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts @@ -43,7 +43,7 @@ import { DateTime } from 'luxon'; import { generateFillSubaccountMessage, generateOrderSubaccountMessage, - generatePerpetualPositionsContents, isDeleveraging, + generatePerpetualPositionsContents, isLiquidation, } from '../../helpers/kafka-helper'; import { @@ -425,7 +425,6 @@ export abstract class AbstractOrderFillHandler extends Handler { side: fill.side.toString(), createdAt: fill.createdAt, liquidation: isLiquidation(fill), - deleveraging: isDeleveraging(fill), }, ], }; diff --git a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts index b52e0206f5..8ee0073793 100644 --- a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts @@ -16,11 +16,7 @@ import { } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; -import { - DELEVERAGING_EVENT_TYPE, - STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, - SUBACCOUNT_ORDER_FILL_EVENT_TYPE, -} from '../../constants'; +import { STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../../constants'; import { convertPerpetualPosition } from '../../helpers/kafka-helper'; import { orderFillWithLiquidityToOrderFillEventWithLiquidation } from '../../helpers/translation-helper'; import { OrderFillWithLiquidity } from '../../lib/translated-types'; @@ -54,9 +50,6 @@ export class LiquidationHandler extends AbstractOrderFillHandler Date: Fri, 3 Nov 2023 17:09:29 -0400 Subject: [PATCH 14/17] address cmts --- .../dydxprotocol/indexer/events/events.ts | 42 ++- .../dydxprotocol/indexer/events/events.proto | 9 +- protocol/indexer/events/deleveraging.go | 16 +- protocol/indexer/events/deleveraging_test.go | 21 +- protocol/indexer/events/events.pb.go | 294 +++++++++--------- protocol/mocks/ClobKeeper.go | 25 +- protocol/mocks/MemClob.go | 25 +- protocol/x/clob/keeper/deleveraging.go | 31 +- protocol/x/clob/keeper/liquidations.go | 26 +- protocol/x/clob/keeper/liquidations_test.go | 2 +- protocol/x/clob/memclob/memclob.go | 3 +- protocol/x/clob/types/liquidations_keeper.go | 1 - protocol/x/clob/types/memclob.go | 1 - 13 files changed, 232 insertions(+), 264 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts index fd2cf3ba2e..1c11aa4faa 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts @@ -456,21 +456,18 @@ export interface DeleveragingEventV1 { /** ID of the subaccount that was used to offset the position. */ offsetting?: IndexerSubaccountId; - /** The ID of the clob pair that was liquidated. */ + /** The ID of the perpetual that was liquidated. */ - clobPairId: number; + perpetualId: number; /** * The amount filled between the liquidated and offsetting position, in * base quantums. */ fillAmount: Long; - /** - * The closing price in subticks. Bankruptcy price of liquidated subaccount - * is not guaranteed to be a multiple of subticks_per_tick. - */ + /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ - subticks: Long; + price: Long; /** `true` if liquidating a short position, `false` otherwise. */ isBuy: boolean; @@ -487,21 +484,18 @@ export interface DeleveragingEventV1SDKType { /** ID of the subaccount that was used to offset the position. */ offsetting?: IndexerSubaccountIdSDKType; - /** The ID of the clob pair that was liquidated. */ + /** The ID of the perpetual that was liquidated. */ - clob_pair_id: number; + perpetual_id: number; /** * The amount filled between the liquidated and offsetting position, in * base quantums. */ fill_amount: Long; - /** - * The closing price in subticks. Bankruptcy price of liquidated subaccount - * is not guaranteed to be a multiple of subticks_per_tick. - */ + /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ - subticks: Long; + price: Long; /** `true` if liquidating a short position, `false` otherwise. */ is_buy: boolean; @@ -1785,9 +1779,9 @@ function createBaseDeleveragingEventV1(): DeleveragingEventV1 { return { liquidated: undefined, offsetting: undefined, - clobPairId: 0, + perpetualId: 0, fillAmount: Long.UZERO, - subticks: Long.UZERO, + price: Long.UZERO, isBuy: false }; } @@ -1802,16 +1796,16 @@ export const DeleveragingEventV1 = { IndexerSubaccountId.encode(message.offsetting, writer.uint32(18).fork()).ldelim(); } - if (message.clobPairId !== 0) { - writer.uint32(24).uint32(message.clobPairId); + if (message.perpetualId !== 0) { + writer.uint32(24).uint32(message.perpetualId); } if (!message.fillAmount.isZero()) { writer.uint32(32).uint64(message.fillAmount); } - if (!message.subticks.isZero()) { - writer.uint32(40).uint64(message.subticks); + if (!message.price.isZero()) { + writer.uint32(40).uint64(message.price); } if (message.isBuy === true) { @@ -1839,7 +1833,7 @@ export const DeleveragingEventV1 = { break; case 3: - message.clobPairId = reader.uint32(); + message.perpetualId = reader.uint32(); break; case 4: @@ -1847,7 +1841,7 @@ export const DeleveragingEventV1 = { break; case 5: - message.subticks = (reader.uint64() as Long); + message.price = (reader.uint64() as Long); break; case 6: @@ -1867,9 +1861,9 @@ export const DeleveragingEventV1 = { const message = createBaseDeleveragingEventV1(); message.liquidated = object.liquidated !== undefined && object.liquidated !== null ? IndexerSubaccountId.fromPartial(object.liquidated) : undefined; message.offsetting = object.offsetting !== undefined && object.offsetting !== null ? IndexerSubaccountId.fromPartial(object.offsetting) : undefined; - message.clobPairId = object.clobPairId ?? 0; + message.perpetualId = object.perpetualId ?? 0; message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO; - message.subticks = object.subticks !== undefined && object.subticks !== null ? Long.fromValue(object.subticks) : Long.UZERO; + message.price = object.price !== undefined && object.price !== null ? Long.fromValue(object.price) : Long.UZERO; message.isBuy = object.isBuy ?? false; return message; } diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index cce6502484..c7a55a1bc8 100644 --- a/proto/dydxprotocol/indexer/events/events.proto +++ b/proto/dydxprotocol/indexer/events/events.proto @@ -175,14 +175,13 @@ message DeleveragingEventV1 { // ID of the subaccount that was used to offset the position. dydxprotocol.indexer.protocol.v1.IndexerSubaccountId offsetting = 2 [ (gogoproto.nullable) = false ]; - // The ID of the clob pair that was liquidated. - uint32 clob_pair_id = 3; + // The ID of the perpetual that was liquidated. + uint32 perpetual_id = 3; // The amount filled between the liquidated and offsetting position, in // base quantums. uint64 fill_amount = 4; - // The closing price in subticks. Bankruptcy price of liquidated subaccount - // is not guaranteed to be a multiple of subticks_per_tick. - uint64 subticks = 5; + // Bankruptcy price of liquidated subaccount, in USDC quote quantums. + uint64 price = 5; // `true` if liquidating a short position, `false` otherwise. bool is_buy = 6; } diff --git a/protocol/indexer/events/deleveraging.go b/protocol/indexer/events/deleveraging.go index e4fcc303cc..7e67f0ea0b 100644 --- a/protocol/indexer/events/deleveraging.go +++ b/protocol/indexer/events/deleveraging.go @@ -10,19 +10,19 @@ import ( func NewDeleveragingEvent( liquidatedSubaccountId satypes.SubaccountId, offsettingSubaccountId satypes.SubaccountId, - clobPairId uint32, + perpetualId uint32, fillAmount satypes.BaseQuantums, - subticks uint64, + price satypes.BaseQuantums, isBuy bool, ) *DeleveragingEventV1 { indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) return &DeleveragingEventV1{ - Liquidated: indexerLiquidatedSubaccountId, - Offsetting: indexerOffsettingSubaccountId, - ClobPairId: clobPairId, - FillAmount: fillAmount.ToUint64(), - Subticks: subticks, - IsBuy: isBuy, + Liquidated: indexerLiquidatedSubaccountId, + Offsetting: indexerOffsettingSubaccountId, + PerpetualId: perpetualId, + FillAmount: fillAmount.ToUint64(), + Price: price.ToUint64(), + IsBuy: isBuy, } } diff --git a/protocol/indexer/events/deleveraging_test.go b/protocol/indexer/events/deleveraging_test.go index 1ce2014b32..3578cc6b51 100644 --- a/protocol/indexer/events/deleveraging_test.go +++ b/protocol/indexer/events/deleveraging_test.go @@ -1,6 +1,7 @@ package events_test import ( + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "testing" "github.com/dydxprotocol/v4-chain/protocol/indexer/events" @@ -12,8 +13,8 @@ import ( var ( liquidatedSubaccountId = constants.Alice_Num0 offsettingSubaccountId = constants.Bob_Num0 - clobPairId = uint32(1) - subticks = uint64(1000) + perpetualId = uint32(1) + price = satypes.BaseQuantums(1000) isBuy = true ) @@ -21,20 +22,20 @@ func TestNewDeleveragingEvent_Success(t *testing.T) { deleveragingEvent := events.NewDeleveragingEvent( liquidatedSubaccountId, offsettingSubaccountId, - clobPairId, + perpetualId, fillAmount, - subticks, + price, isBuy, ) indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) expectedDeleveragingEventProto := &events.DeleveragingEventV1{ - Liquidated: indexerLiquidatedSubaccountId, - Offsetting: indexerOffsettingSubaccountId, - ClobPairId: clobPairId, - FillAmount: fillAmount.ToUint64(), - Subticks: subticks, - IsBuy: isBuy, + Liquidated: indexerLiquidatedSubaccountId, + Offsetting: indexerOffsettingSubaccountId, + PerpetualId: perpetualId, + FillAmount: fillAmount.ToUint64(), + Price: price.ToUint64(), + IsBuy: isBuy, } require.Equal(t, expectedDeleveragingEventProto, deleveragingEvent) } diff --git a/protocol/indexer/events/events.pb.go b/protocol/indexer/events/events.pb.go index 71749cc332..e9bb3e3dfd 100644 --- a/protocol/indexer/events/events.pb.go +++ b/protocol/indexer/events/events.pb.go @@ -851,14 +851,13 @@ type DeleveragingEventV1 struct { Liquidated v1.IndexerSubaccountId `protobuf:"bytes,1,opt,name=liquidated,proto3" json:"liquidated"` // ID of the subaccount that was used to offset the position. Offsetting v1.IndexerSubaccountId `protobuf:"bytes,2,opt,name=offsetting,proto3" json:"offsetting"` - // The ID of the clob pair that was liquidated. - ClobPairId uint32 `protobuf:"varint,3,opt,name=clob_pair_id,json=clobPairId,proto3" json:"clob_pair_id,omitempty"` + // The ID of the perpetual that was liquidated. + PerpetualId uint32 `protobuf:"varint,3,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` // The amount filled between the liquidated and offsetting position, in // base quantums. FillAmount uint64 `protobuf:"varint,4,opt,name=fill_amount,json=fillAmount,proto3" json:"fill_amount,omitempty"` - // The closing price in subticks. Bankruptcy price of liquidated subaccount - // is not guaranteed to be a multiple of subticks_per_tick. - Subticks uint64 `protobuf:"varint,5,opt,name=subticks,proto3" json:"subticks,omitempty"` + // Bankruptcy price of liquidated subaccount, in USDC quote quantums. + Price uint64 `protobuf:"varint,5,opt,name=price,proto3" json:"price,omitempty"` // `true` if liquidating a short position, `false` otherwise. IsBuy bool `protobuf:"varint,6,opt,name=is_buy,json=isBuy,proto3" json:"is_buy,omitempty"` } @@ -910,9 +909,9 @@ func (m *DeleveragingEventV1) GetOffsetting() v1.IndexerSubaccountId { return v1.IndexerSubaccountId{} } -func (m *DeleveragingEventV1) GetClobPairId() uint32 { +func (m *DeleveragingEventV1) GetPerpetualId() uint32 { if m != nil { - return m.ClobPairId + return m.PerpetualId } return 0 } @@ -924,9 +923,9 @@ func (m *DeleveragingEventV1) GetFillAmount() uint64 { return 0 } -func (m *DeleveragingEventV1) GetSubticks() uint64 { +func (m *DeleveragingEventV1) GetPrice() uint64 { if m != nil { - return m.Subticks + return m.Price } return 0 } @@ -2026,130 +2025,131 @@ func init() { } var fileDescriptor_6331dfb59c6fd2bb = []byte{ - // 1968 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0xcd, 0x6f, 0x1c, 0x49, - 0x15, 0xf7, 0x7c, 0x78, 0x3c, 0x7e, 0xf6, 0x38, 0x33, 0x15, 0xdb, 0x19, 0xdb, 0xe0, 0x98, 0x96, - 0x90, 0xac, 0xfd, 0x18, 0xc7, 0x21, 0xa0, 0x15, 0x07, 0x84, 0xc7, 0x1e, 0xaf, 0x27, 0xb2, 0x9d, - 0xa1, 0x3d, 0xce, 0xee, 0x06, 0xb4, 0x4d, 0xb9, 0xbb, 0x66, 0x5c, 0x72, 0x7f, 0x6d, 0x57, 0x8d, - 0x89, 0x23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x25, 0xc9, 0xfa, 0x84, 0xf2, 0xf3, 0x9a, 0x66, 0x18, 0x9f, 0x42, - 0x49, 0x61, 0x55, 0x31, 0x4b, 0x40, 0x10, 0x64, 0x43, 0x4c, 0x23, 0x29, 0x35, 0x6b, 0xca, 0xdf, - 0x68, 0x0b, 0x16, 0x3d, 0xea, 0x5b, 0x0a, 0xdc, 0x3e, 0xc7, 0x7e, 0xbb, 0x7b, 0xdc, 0x0a, 0x66, - 0xc9, 0xa3, 0xbe, 0xb4, 0x66, 0x57, 0x72, 0x1a, 0xa1, 0x67, 0x74, 0xe0, 0xee, 0x88, 0x70, 0xa1, - 0x2a, 0x64, 0xcf, 0x30, 0x23, 0x12, 0x7b, 0xee, 0x61, 0x65, 0x82, 0xa8, 0xf4, 0x58, 0x66, 0x4a, - 0x59, 0xb4, 0x0a, 0xf9, 0xc4, 0x33, 0xa1, 0xbf, 0x64, 0x26, 0x6b, 0xe3, 0xb3, 0x58, 0x6d, 0x5f, - 0x30, 0x6f, 0x43, 0xad, 0xf1, 0xe7, 0x14, 0x14, 0x4e, 0x82, 0x4e, 0x64, 0x93, 0x27, 0x2d, 0x71, - 0xa4, 0x18, 0xfa, 0x19, 0x14, 0xba, 0x77, 0x59, 0x5c, 0xc1, 0x63, 0x2b, 0x34, 0x21, 0x5c, 0x6e, - 0x57, 0xea, 0x8a, 0x76, 0x92, 0x48, 0xd7, 0x1d, 0x91, 0x70, 0xd6, 0xb3, 0x46, 0x8f, 0x60, 0x06, - 0x3b, 0x4e, 0x44, 0x18, 0x93, 0x5e, 0xce, 0x56, 0xcb, 0xff, 0xfc, 0xeb, 0x87, 0x8b, 0xfa, 0x82, - 0xdf, 0x51, 0x9c, 0x13, 0x1e, 0x51, 0xbf, 0x7d, 0x30, 0x65, 0xc6, 0x5b, 0xab, 0x79, 0xc8, 0x31, - 0x69, 0xa4, 0xf1, 0xa7, 0x0c, 0xdc, 0x69, 0x46, 0xd8, 0x67, 0x2d, 0x12, 0xc5, 0x71,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, 0x83, 0x99, 0x1e, 0x7f, 0x30, 0x33, 0x93, 0xdc, 0x26, 0xd9, 0x31, - 0xc7, 0x61, 0xb8, 0x68, 0xa7, 0x47, 0x14, 0x6d, 0xd5, 0xfc, 0xea, 0xd5, 0x7a, 0xea, 0xeb, 0x57, - 0xeb, 0xa9, 0xff, 0xbe, 0x5a, 0x4f, 0xfd, 0xf6, 0xf5, 0xfa, 0xd4, 0xd7, 0xaf, 0xd7, 0xa7, 0xfe, - 0xfd, 0x7a, 0x7d, 0xea, 0xd9, 0x47, 0x93, 0x7f, 0x72, 0xee, 0xff, 0xdf, 0xc0, 0x59, 0x4e, 0x32, - 0xbe, 0xf7, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf3, 0xe6, 0xf8, 0xa1, 0x41, 0x18, 0x00, 0x00, + // 1971 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0xcd, 0x4f, 0x23, 0xc9, + 0x15, 0xc7, 0x76, 0x63, 0xe0, 0x81, 0x19, 0xbb, 0x06, 0x18, 0x03, 0x09, 0x43, 0x5a, 0x8a, 0x84, + 0xf6, 0xc3, 0x0c, 0x93, 0x49, 0xb4, 0xca, 0x21, 0x0a, 0x06, 0xb3, 0x78, 0x04, 0x8c, 0xd3, 0x98, + 0xd9, 0xdd, 0x49, 0xb4, 0x9d, 0xa2, 0xbb, 0x6c, 0x4a, 0xf4, 0xd7, 0x76, 0x95, 0xc9, 0x30, 0x52, + 0xce, 0xc9, 0x2d, 0x91, 0x72, 0xce, 0x21, 0x87, 0x5c, 0x22, 0xe5, 0x10, 0x29, 0xd7, 0x95, 0x22, + 0xe5, 0xb2, 0xb7, 0xac, 0x72, 0x49, 0x94, 0xc3, 0x28, 0x9a, 0x39, 0xe4, 0xdf, 0x88, 0xea, 0xa3, + 0xdb, 0x36, 0xb6, 0x19, 0xcf, 0xc0, 0x9e, 0x70, 0x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3, 0xb7, 0x8f, 0x76, 0xed, 0xfa, 0xd1, 0x6e, 0xed, 0xd3, 0x62, + 0x16, 0x2d, 0x42, 0xa9, 0x4f, 0xf2, 0xe9, 0x93, 0x66, 0xad, 0x98, 0x33, 0xff, 0x9e, 0x85, 0xc2, + 0x21, 0x8e, 0xcf, 0x09, 0x4f, 0x82, 0xb2, 0x0a, 0x33, 0xbe, 0x24, 0x74, 0x53, 0x3c, 0xad, 0x08, + 0x75, 0x17, 0x3d, 0x83, 0xb9, 0x28, 0xa6, 0x0e, 0xb1, 0x95, 0xd3, 0xd2, 0xd7, 0xd9, 0x87, 0xdf, + 0xbf, 0xd6, 0x57, 0x05, 0xdf, 0x10, 0x62, 0x2a, 0x74, 0x5a, 0xd3, 0xfe, 0x84, 0x35, 0x1b, 0x75, + 0xa9, 0xe8, 0x13, 0x28, 0x68, 0xc5, 0x4e, 0x4c, 0x04, 0x78, 0x4e, 0x82, 0x3f, 0x18, 0x03, 0x7c, + 0x47, 0x0a, 0x74, 0x71, 0xe7, 0xfc, 0x1e, 0x72, 0x0f, 0xb0, 0x1f, 0xba, 0xb4, 0x75, 0x59, 0x36, + 0xc6, 0x06, 0x3e, 0x94, 0x02, 0x03, 0xc0, 0x8a, 0x5c, 0x9d, 0x82, 0x49, 0xb9, 0xdb, 0x7c, 0x0c, + 0xe5, 0x51, 0x5e, 0xa2, 0x0a, 0xdc, 0x55, 0x21, 0xfb, 0x05, 0xe5, 0x67, 0x36, 0x79, 0x1e, 0x85, + 0x01, 0x09, 0xb8, 0x8c, 0xac, 0x61, 0x95, 0x24, 0xeb, 0x13, 0xca, 0xcf, 0x6a, 0x9a, 0x61, 0x7e, + 0x0a, 0x25, 0x85, 0x55, 0xc5, 0x2c, 0x05, 0x41, 0x60, 0x44, 0x98, 0xc6, 0x52, 0x6a, 0xc6, 0x92, + 0xbf, 0xd1, 0x26, 0x2c, 0xf8, 0x34, 0xb0, 0x15, 0xb8, 0x73, 0x86, 0x83, 0x76, 0xf7, 0xb8, 0x15, + 0xac, 0x92, 0x4f, 0x03, 0x69, 0xcd, 0x8e, 0xe4, 0x34, 0x22, 0xdf, 0xec, 0xc0, 0xdd, 0x21, 0xe1, + 0x42, 0x55, 0x30, 0x4e, 0x31, 0x23, 0x12, 0x7b, 0xf6, 0x61, 0x65, 0x8c, 0xa8, 0xf4, 0x58, 0x66, + 0x49, 0x59, 0xb4, 0x02, 0xd3, 0xa9, 0x67, 0x42, 0x7f, 0xc9, 0x4a, 0xd7, 0xe6, 0x67, 0x89, 0xda, + 0xbe, 0x60, 0xde, 0x86, 0x5a, 0xf3, 0xcf, 0x19, 0x28, 0x1c, 0x87, 0x9d, 0xd8, 0x21, 0x4f, 0x5a, + 0xe2, 0x48, 0x31, 0xf4, 0x33, 0x28, 0x74, 0xef, 0xb2, 0xa4, 0x82, 0x47, 0x56, 0x68, 0x4a, 0xb8, + 0xd8, 0xaa, 0xd4, 0x15, 0xed, 0x38, 0x95, 0xae, 0xbb, 0x22, 0xe1, 0xac, 0x67, 0x8d, 0x1e, 0xc1, + 0x14, 0x76, 0xdd, 0x98, 0x30, 0x26, 0xbd, 0x9c, 0xa9, 0x96, 0xff, 0xf9, 0xd7, 0x0f, 0x17, 0xf4, + 0x05, 0xbf, 0xad, 0x38, 0xc7, 0x3c, 0xa6, 0x41, 0x7b, 0x7f, 0xc2, 0x4a, 0xb6, 0x56, 0xa7, 0x21, + 0xcf, 0xa4, 0x91, 0xe6, 0x9f, 0x72, 0x70, 0xa7, 0x19, 0xe3, 0x80, 0xb5, 0x48, 0x9c, 0xc4, 0xa1, + 0x0d, 0x0b, 0x8c, 0x04, 0x2e, 0x89, 0xed, 0xdb, 0x33, 0xdc, 0x42, 0x0a, 0xb2, 0x97, 0x86, 0x7c, + 0xb8, 0x17, 0x13, 0x87, 0x46, 0x94, 0x04, 0xfc, 0x8a, 0xae, 0xec, 0x4d, 0x74, 0x2d, 0xa6, 0xa8, + 0x7d, 0xea, 0x96, 0x61, 0x1a, 0x33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0xcd, 0x76, 0x74, 0xa5, 0x19, 0xbd, 0x80, 0x55, 0x35, 0x85, 0xb9, 0x76, 0xd7, 0xe9, + 0x28, 0x64, 0x54, 0x24, 0x84, 0x95, 0x73, 0x72, 0xa2, 0xfd, 0xe1, 0xd8, 0x9a, 0x1a, 0x09, 0x46, + 0x43, 0x43, 0x58, 0xcb, 0x1a, 0x7e, 0x80, 0xc3, 0x50, 0x00, 0xf7, 0x12, 0xdd, 0xea, 0x92, 0xef, + 0xea, 0x35, 0xa4, 0xde, 0x1f, 0x8c, 0xad, 0x77, 0x5b, 0xc8, 0xa7, 0x3a, 0x17, 0x35, 0x6c, 0x1f, + 0x95, 0x3d, 0x36, 0xa6, 0xb3, 0xc5, 0x9c, 0xf9, 0x07, 0x80, 0x85, 0x63, 0x8e, 0x39, 0x69, 0x75, + 0x3c, 0x59, 0x71, 0x49, 0x98, 0x7d, 0x98, 0x95, 0x27, 0xdb, 0x8e, 0x3c, 0xec, 0x24, 0x23, 0xc5, + 0xe3, 0xeb, 0xaf, 0xfd, 0x21, 0x38, 0xfd, 0xc4, 0x86, 0xc0, 0xf2, 0x93, 0xc9, 0x0f, 0xc2, 0x94, + 0x86, 0x42, 0x28, 0x28, 0x75, 0xfa, 0x69, 0xa6, 0x6f, 0xd8, 0xfd, 0x1b, 0x2a, 0xb4, 0x14, 0x9a, + 0x1a, 0x34, 0xc3, 0x1e, 0x0a, 0xfa, 0x4d, 0x06, 0x56, 0x9d, 0x30, 0x70, 0x65, 0x34, 0xb0, 0x67, + 0xf7, 0x38, 0x2b, 0x0c, 0xd4, 0xed, 0xf2, 0xf0, 0xed, 0xf5, 0xef, 0x74, 0x41, 0x87, 0xf8, 0xbc, + 0xec, 0x8c, 0x62, 0x8f, 0xb0, 0x88, 0xc7, 0xb4, 0xdd, 0x26, 0x31, 0x71, 0x75, 0xe7, 0xbd, 0x05, + 0x8b, 0x9a, 0x09, 0xe4, 0x70, 0x8b, 0x52, 0x36, 0xfa, 0x55, 0x06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0xeb, 0xb5, 0x89, 0xaf, 0x5f, + 0xaf, 0x4d, 0xfc, 0xfb, 0xf5, 0xda, 0xc4, 0xb3, 0x8f, 0xc6, 0xff, 0xda, 0xdc, 0xff, 0x6f, 0x81, + 0xd3, 0xbc, 0x64, 0x7c, 0xef, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x9d, 0xde, 0x80, 0x3c, + 0x18, 0x00, 0x00, } func (m *FundingUpdateV1) Marshal() (dAtA []byte, err error) { @@ -2762,8 +2762,8 @@ func (m *DeleveragingEventV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x30 } - if m.Subticks != 0 { - i = encodeVarintEvents(dAtA, i, uint64(m.Subticks)) + if m.Price != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.Price)) i-- dAtA[i] = 0x28 } @@ -2772,8 +2772,8 @@ func (m *DeleveragingEventV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x20 } - if m.ClobPairId != 0 { - i = encodeVarintEvents(dAtA, i, uint64(m.ClobPairId)) + if m.PerpetualId != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.PerpetualId)) i-- dAtA[i] = 0x18 } @@ -3803,14 +3803,14 @@ func (m *DeleveragingEventV1) Size() (n int) { n += 1 + l + sovEvents(uint64(l)) l = m.Offsetting.Size() n += 1 + l + sovEvents(uint64(l)) - if m.ClobPairId != 0 { - n += 1 + sovEvents(uint64(m.ClobPairId)) + if m.PerpetualId != 0 { + n += 1 + sovEvents(uint64(m.PerpetualId)) } if m.FillAmount != 0 { n += 1 + sovEvents(uint64(m.FillAmount)) } - if m.Subticks != 0 { - n += 1 + sovEvents(uint64(m.Subticks)) + if m.Price != 0 { + n += 1 + sovEvents(uint64(m.Price)) } if m.IsBuy { n += 2 @@ -5613,9 +5613,9 @@ func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClobPairId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) } - m.ClobPairId = 0 + m.PerpetualId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvents @@ -5625,7 +5625,7 @@ func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ClobPairId |= uint32(b&0x7F) << shift + m.PerpetualId |= uint32(b&0x7F) << shift if b < 0x80 { break } @@ -5651,9 +5651,9 @@ func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { } case 5: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Subticks", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) } - m.Subticks = 0 + m.Price = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvents @@ -5663,7 +5663,7 @@ func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Subticks |= uint64(b&0x7F) << shift + m.Price |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/protocol/mocks/ClobKeeper.go b/protocol/mocks/ClobKeeper.go index 7ac9a44e2c..942e3b3182 100644 --- a/protocol/mocks/ClobKeeper.go +++ b/protocol/mocks/ClobKeeper.go @@ -527,35 +527,26 @@ func (_m *ClobKeeper) Logger(ctx types.Context) log.Logger { } // MaybeDeleverageSubaccount provides a mock function with given fields: ctx, subaccountId, perpetualId -func (_m *ClobKeeper) MaybeDeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32) ([]clobtypes.MatchPerpetualDeleveraging_Fill, *big.Int, error) { +func (_m *ClobKeeper) MaybeDeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32) (*big.Int, error) { ret := _m.Called(ctx, subaccountId, perpetualId) - var r0 []clobtypes.MatchPerpetualDeleveraging_Fill - if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) []clobtypes.MatchPerpetualDeleveraging_Fill); ok { + var r0 *big.Int + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) *big.Int); ok { r0 = rf(ctx, subaccountId, perpetualId) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]clobtypes.MatchPerpetualDeleveraging_Fill) + r0 = ret.Get(0).(*big.Int) } } - var r1 *big.Int - if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32) *big.Int); ok { + var r1 error + if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32) error); ok { r1 = rf(ctx, subaccountId, perpetualId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*big.Int) - } - } - - var r2 error - if rf, ok := ret.Get(2).(func(types.Context, subaccountstypes.SubaccountId, uint32) error); ok { - r2 = rf(ctx, subaccountId, perpetualId) - } else { - r2 = ret.Error(2) + r1 = ret.Error(1) } - return r0, r1, r2 + return r0, r1 } // MaybeGetLiquidationOrder provides a mock function with given fields: ctx, subaccountId diff --git a/protocol/mocks/MemClob.go b/protocol/mocks/MemClob.go index 9263751e93..a57c83df6a 100644 --- a/protocol/mocks/MemClob.go +++ b/protocol/mocks/MemClob.go @@ -63,35 +63,26 @@ func (_m *MemClob) CreateOrderbook(ctx types.Context, clobPair clobtypes.ClobPai } // DeleverageSubaccount provides a mock function with given fields: ctx, subaccountId, perpetualId, deltaQuantums -func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32, deltaQuantums *big.Int) ([]clobtypes.MatchPerpetualDeleveraging_Fill, *big.Int, error) { +func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32, deltaQuantums *big.Int) (*big.Int, error) { ret := _m.Called(ctx, subaccountId, perpetualId, deltaQuantums) - var r0 []clobtypes.MatchPerpetualDeleveraging_Fill - if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) []clobtypes.MatchPerpetualDeleveraging_Fill); ok { + var r0 *big.Int + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) *big.Int); ok { r0 = rf(ctx, subaccountId, perpetualId, deltaQuantums) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]clobtypes.MatchPerpetualDeleveraging_Fill) + r0 = ret.Get(0).(*big.Int) } } - var r1 *big.Int - if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) *big.Int); ok { + var r1 error + if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) error); ok { r1 = rf(ctx, subaccountId, perpetualId, deltaQuantums) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*big.Int) - } - } - - var r2 error - if rf, ok := ret.Get(2).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int) error); ok { - r2 = rf(ctx, subaccountId, perpetualId, deltaQuantums) - } else { - r2 = ret.Error(2) + r1 = ret.Error(1) } - return r0, r1, r2 + return r0, r1 } // GetCancelOrder provides a mock function with given fields: ctx, orderId diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index 33ca1e9e6e..50e055e3ab 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -3,6 +3,8 @@ package keeper import ( "errors" "fmt" + indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" + "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "math/big" "time" @@ -27,7 +29,6 @@ func (k Keeper) MaybeDeleverageSubaccount( subaccountId satypes.SubaccountId, perpetualId uint32, ) ( - fills []types.MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) { @@ -35,7 +36,7 @@ func (k Keeper) MaybeDeleverageSubaccount( canPerformDeleveraging, err := k.CanDeleverageSubaccount(ctx, subaccountId) if err != nil { - return nil, new(big.Int), err + return new(big.Int), err } // Early return to skip deleveraging if the subaccount can't be deleveraged. @@ -46,7 +47,7 @@ func (k Keeper) MaybeDeleverageSubaccount( metrics.PrepareCheckState, metrics.CannotDeleverageSubaccount, ) - return nil, new(big.Int), nil + return new(big.Int), nil } // Deleverage the entire position for the given perpetual id. @@ -60,11 +61,11 @@ func (k Keeper) MaybeDeleverageSubaccount( "subaccount", subaccount, "perpetualId", perpetualId, ) - return nil, new(big.Int), nil + return new(big.Int), nil } deltaQuantums := new(big.Int).Neg(position.GetBigQuantums()) - fills, quantumsDeleveraged, err = k.MemClob.DeleverageSubaccount(ctx, subaccountId, perpetualId, deltaQuantums) + quantumsDeleveraged, err = k.MemClob.DeleverageSubaccount(ctx, subaccountId, perpetualId, deltaQuantums) labels := []gometrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), @@ -108,7 +109,7 @@ func (k Keeper) MaybeDeleverageSubaccount( labels, ) - return fills, quantumsDeleveraged, err + return quantumsDeleveraged, err } // GetInsuranceFundBalance returns the current balance of the insurance fund (in quote quantums). @@ -452,5 +453,23 @@ func (k Keeper) ProcessDeleveraging( ), ) + // Send on-chain update for the deleveraging. The events are stored in a TransientStore which should be rolled-back + // if the branched state is discarded, so batching is not necessary. + k.GetIndexerEventManager().AddTxnEvent( + ctx, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + indexer_manager.GetBytes( + indexerevents.NewDeleveragingEvent( + liquidatedSubaccountId, + offsettingSubaccountId, + perpetualId, + satypes.BaseQuantums(new(big.Int).Abs(deltaQuantums).Uint64()), + satypes.BaseQuantums(bankruptcyPriceQuoteQuantums.Uint64()), + deltaQuantums.Sign() > 0, + ), + ), + ) + return nil } diff --git a/protocol/x/clob/keeper/liquidations.go b/protocol/x/clob/keeper/liquidations.go index 1b7ca63b2e..eb5d4190b8 100644 --- a/protocol/x/clob/keeper/liquidations.go +++ b/protocol/x/clob/keeper/liquidations.go @@ -3,8 +3,6 @@ package keeper import ( "bytes" "errors" - indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" - "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "math" "math/big" "sort" @@ -144,8 +142,7 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( subaccountId := liquidationOrder.GetSubaccountId() perpetualId := liquidationOrder.MustGetLiquidatedPerpetualId() - fills, _, err := k.MaybeDeleverageSubaccount(ctx, subaccountId, perpetualId) - + _, err := k.MaybeDeleverageSubaccount(ctx, subaccountId, perpetualId) if err != nil { k.Logger(ctx).Error( "Failed to deleverage subaccount.", @@ -155,27 +152,6 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( ) return err } - clobPairId := k.mustGetClobPairForPerpetualId(ctx, perpetualId).Id - subticks := liquidationOrder.GetOrderSubticks() - isBuy := liquidationOrder.IsBuy() - // Send on-chain deleveraging event for each fill. - for _, fill := range fills { - k.GetIndexerEventManager().AddTxnEvent( - ctx, - indexerevents.SubtypeDeleveraging, - indexerevents.DeleveragingEventVersion, - indexer_manager.GetBytes( - indexerevents.NewDeleveragingEvent( - subaccountId, - fill.OffsettingSubaccountId, - clobPairId, - satypes.BaseQuantums(fill.FillAmount), - uint64(subticks), - isBuy, - ), - ), - ) - } } telemetry.MeasureSince( startDeleverageSubaccounts, diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 8cb572be99..38b7f6634d 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -2018,7 +2018,7 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { } if tc.expectedFilledSize == 0 { - _, _, err = ks.ClobKeeper.MaybeDeleverageSubaccount( + _, err = ks.ClobKeeper.MaybeDeleverageSubaccount( ctx, tc.order.GetSubaccountId(), tc.order.MustGetLiquidatedPerpetualId(), diff --git a/protocol/x/clob/memclob/memclob.go b/protocol/x/clob/memclob/memclob.go index 1301c10fbc..6cd0f93a19 100644 --- a/protocol/x/clob/memclob/memclob.go +++ b/protocol/x/clob/memclob/memclob.go @@ -695,7 +695,6 @@ func (m *MemClobPriceTimePriority) DeleverageSubaccount( perpetualId uint32, deltaQuantums *big.Int, ) ( - fills []types.MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) { @@ -717,7 +716,7 @@ func (m *MemClobPriceTimePriority) DeleverageSubaccount( } quantumsDeleveraged = new(big.Int).Abs(new(big.Int).Sub(deltaQuantums, deltaQuantumsRemaining)) - return fills, quantumsDeleveraged, nil + return quantumsDeleveraged, nil } // matchOrder will match the provided `MatchableOrder` as a taker order against the respective orderbook. diff --git a/protocol/x/clob/types/liquidations_keeper.go b/protocol/x/clob/types/liquidations_keeper.go index 93c93a8415..07281ad3d2 100644 --- a/protocol/x/clob/types/liquidations_keeper.go +++ b/protocol/x/clob/types/liquidations_keeper.go @@ -23,7 +23,6 @@ type LiquidationsKeeper interface { subaccountId satypes.SubaccountId, perpetualId uint32, ) ( - fills []MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) diff --git a/protocol/x/clob/types/memclob.go b/protocol/x/clob/types/memclob.go index f1d042026e..b3941fa00a 100644 --- a/protocol/x/clob/types/memclob.go +++ b/protocol/x/clob/types/memclob.go @@ -91,7 +91,6 @@ type MemClob interface { perpetualId uint32, deltaQuantums *big.Int, ) ( - fills []MatchPerpetualDeleveraging_Fill, quantumsDeleveraged *big.Int, err error, ) From c8f96e220556a93a86aaefcb2177a8e5d150f355 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Sat, 4 Nov 2023 23:13:09 -0400 Subject: [PATCH 15/17] fix tests --- .../indexer/indexer_manager/event_manager.go | 12 +-- protocol/x/clob/keeper/deleveraging_test.go | 89 ++++++++++++++++++- protocol/x/clob/keeper/liquidations_test.go | 3 + .../x/clob/keeper/process_operations_test.go | 21 +++++ 4 files changed, 115 insertions(+), 10 deletions(-) diff --git a/protocol/indexer/indexer_manager/event_manager.go b/protocol/indexer/indexer_manager/event_manager.go index 5f540037c4..d764919db2 100644 --- a/protocol/indexer/indexer_manager/event_manager.go +++ b/protocol/indexer/indexer_manager/event_manager.go @@ -52,13 +52,13 @@ func (i *indexerEventManagerImpl) GetIndexerEventsTransientStoreKey() storetypes } func (i *indexerEventManagerImpl) SendOffchainData(message msgsender.Message) { - if i.indexerMessageSender.Enabled() && i.sendOffchainData { + if i.Enabled() && i.sendOffchainData { i.indexerMessageSender.SendOffchainData(message) } } func (i *indexerEventManagerImpl) SendOnchainData(block *IndexerTendermintBlock) { - if i.indexerMessageSender.Enabled() { + if i.Enabled() { message := CreateIndexerBlockEventMessage(block) i.indexerMessageSender.SendOnchainData(message) } @@ -71,7 +71,7 @@ func (i *indexerEventManagerImpl) AddTxnEvent( version uint32, dataBytes []byte, ) { - if i.indexerMessageSender.Enabled() { + if i.Enabled() { addTxnEvent(ctx, subType, version, i.indexerEventsTransientStoreKey, dataBytes) } } @@ -80,7 +80,7 @@ func (i *indexerEventManagerImpl) AddTxnEvent( func (i *indexerEventManagerImpl) ClearEvents( ctx sdk.Context, ) { - if i.indexerMessageSender.Enabled() { + if i.Enabled() { clearEvents(ctx, i.indexerEventsTransientStoreKey) } } @@ -93,7 +93,7 @@ func (i *indexerEventManagerImpl) AddBlockEvent( version uint32, dataBytes []byte, ) { - if i.indexerMessageSender.Enabled() { + if i.Enabled() { addBlockEvent(ctx, subType, i.indexerEventsTransientStoreKey, blockEvent, version, dataBytes) } } @@ -104,7 +104,7 @@ func (i *indexerEventManagerImpl) AddBlockEvent( func (i *indexerEventManagerImpl) ProduceBlock( ctx sdk.Context, ) *IndexerTendermintBlock { - if i.indexerMessageSender.Enabled() { + if i.Enabled() { return produceBlock(ctx, i.indexerEventsTransientStoreKey) } return nil diff --git a/protocol/x/clob/keeper/deleveraging_test.go b/protocol/x/clob/keeper/deleveraging_test.go index 694618f6fc..0f1fd8c15a 100644 --- a/protocol/x/clob/keeper/deleveraging_test.go +++ b/protocol/x/clob/keeper/deleveraging_test.go @@ -2,6 +2,8 @@ package keeper_test import ( "errors" + indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" + "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "math" "math/big" "testing" @@ -610,7 +612,8 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { memClob := memclob.NewMemClobPriceTimePriority(false) - ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, &mocks.IndexerEventManager{}) + mockIndexerEventManager := &mocks.IndexerEventManager{} + ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, mockIndexerEventManager) // Create the default markets. keepertest.CreateTestMarkets(t, ks.Ctx, ks.PricesKeeper) @@ -644,6 +647,35 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { ks.BlockTimeKeeper.SetPreviousBlockInfo(ks.Ctx, &blocktimetypes.BlockInfo{ Timestamp: time.Unix(5, 0), }) + // check that an event is emitted per fill + for _, fill := range tc.expectedFills { + fillAmount := new(big.Int).SetUint64(fill.FillAmount) + if tc.deltaQuantums.Sign() < 0 { + fillAmount = new(big.Int).Neg(fillAmount) + } + bankruptcyPriceQuoteQuantums, err := ks.ClobKeeper.GetBankruptcyPriceInQuoteQuantums( + ks.Ctx, + tc.liquidatedSubaccountId, + tc.perpetualId, + fillAmount, + ) + require.NoError(t, err) + mockIndexerEventManager.On("AddTxnEvent", + ks.Ctx, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + indexer_manager.GetBytes( + indexerevents.NewDeleveragingEvent( + tc.liquidatedSubaccountId, + fill.OffsettingSubaccountId, + tc.perpetualId, + satypes.BaseQuantums(fill.FillAmount), + satypes.BaseQuantums(bankruptcyPriceQuoteQuantums.Uint64()), + tc.deltaQuantums.Sign() > 0, + ), + ), + ).Return() + } fills, deltaQuantumsRemaining := ks.ClobKeeper.OffsetSubaccountPerpetualPosition( ks.Ctx, @@ -1002,7 +1034,8 @@ func TestProcessDeleveraging(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { memClob := memclob.NewMemClobPriceTimePriority(false) - ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, &mocks.IndexerEventManager{}) + mockIndexerEventManager := &mocks.IndexerEventManager{} + ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, mockIndexerEventManager) // Create the default markets. keepertest.CreateTestMarkets(t, ks.Ctx, ks.PricesKeeper) @@ -1032,6 +1065,30 @@ func TestProcessDeleveraging(t *testing.T) { ks.SubaccountsKeeper.SetSubaccount(ks.Ctx, tc.liquidatedSubaccount) ks.SubaccountsKeeper.SetSubaccount(ks.Ctx, tc.offsettingSubaccount) + if tc.expectedErr == nil { + bankruptcyPriceQuoteQuantums, err := ks.ClobKeeper.GetBankruptcyPriceInQuoteQuantums( + ks.Ctx, + *tc.liquidatedSubaccount.GetId(), + uint32(0), + tc.deltaQuantums, + ) + require.NoError(t, err) + mockIndexerEventManager.On("AddTxnEvent", + ks.Ctx, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + indexer_manager.GetBytes( + indexerevents.NewDeleveragingEvent( + *tc.liquidatedSubaccount.GetId(), + *tc.offsettingSubaccount.GetId(), + uint32(0), + satypes.BaseQuantums(new(big.Int).Abs(tc.deltaQuantums).Uint64()), + satypes.BaseQuantums(bankruptcyPriceQuoteQuantums.Uint64()), + tc.deltaQuantums.Sign() > 0, + ), + ), + ).Return() + } err = ks.ClobKeeper.ProcessDeleveraging( ks.Ctx, *tc.liquidatedSubaccount.GetId(), @@ -1126,7 +1183,8 @@ func TestProcessDeleveraging_Rounding(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { memClob := memclob.NewMemClobPriceTimePriority(false) - ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, &mocks.IndexerEventManager{}) + mockIndexerEventManager := &mocks.IndexerEventManager{} + ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, mockIndexerEventManager) // Create the default markets. keepertest.CreateTestMarkets(t, ks.Ctx, ks.PricesKeeper) @@ -1164,7 +1222,30 @@ func TestProcessDeleveraging_Rounding(t *testing.T) { ks.SubaccountsKeeper.SetSubaccount(ks.Ctx, tc.liquidatedSubaccount) ks.SubaccountsKeeper.SetSubaccount(ks.Ctx, tc.offsettingSubaccount) - + if tc.expectedErr == nil { + bankruptcyPriceQuoteQuantums, err := ks.ClobKeeper.GetBankruptcyPriceInQuoteQuantums( + ks.Ctx, + *tc.liquidatedSubaccount.GetId(), + uint32(0), + tc.deltaQuantums, + ) + require.NoError(t, err) + mockIndexerEventManager.On("AddTxnEvent", + ks.Ctx, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + indexer_manager.GetBytes( + indexerevents.NewDeleveragingEvent( + *tc.liquidatedSubaccount.GetId(), + *tc.offsettingSubaccount.GetId(), + uint32(0), + satypes.BaseQuantums(new(big.Int).Abs(tc.deltaQuantums).Uint64()), + satypes.BaseQuantums(bankruptcyPriceQuoteQuantums.Uint64()), + tc.deltaQuantums.Sign() > 0, + ), + ), + ).Return() + } err = ks.ClobKeeper.ProcessDeleveraging( ks.Ctx, *tc.liquidatedSubaccount.GetId(), diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 38b7f6634d..1597dabee1 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -2018,6 +2018,9 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { } if tc.expectedFilledSize == 0 { + mockIndexerEventManager.On("AddTxnEvent", + mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, + ).Return() _, err = ks.ClobKeeper.MaybeDeleverageSubaccount( ctx, tc.order.GetSubaccountId(), diff --git a/protocol/x/clob/keeper/process_operations_test.go b/protocol/x/clob/keeper/process_operations_test.go index e819748b32..ba39a1b5bf 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1912,7 +1912,28 @@ func setupNewMockEventManager( ), ).Once().Return() } + if isClobMatchPerpetualDeleveraging(operation) { + mockIndexerEventManager.On("AddTxnEvent", + mock.Anything, + indexerevents.SubtypeDeleveraging, + indexerevents.DeleveragingEventVersion, + mock.Anything, + ).Return() + } + } +} + +// isClobMatchPerpetualDeleveraging checks if the Operation field is a ClobMatch with a MatchPerpetualDeleveraging. +// It returns true if it is, otherwise false. +func isClobMatchPerpetualDeleveraging( + operationRaw types.OperationRaw, +) bool { + matchOperation, ok := operationRaw.Operation.(*types.OperationRaw_Match) + if !ok { + return false } + _, ok = matchOperation.Match.Match.(*types.ClobMatch_MatchPerpetualDeleveraging) + return ok } func assertSubaccountState( From bea74c103b2003fd6f8c0656165e76f1a53d2d6e Mon Sep 17 00:00:00 2001 From: Will Liu Date: Mon, 6 Nov 2023 08:29:43 -0500 Subject: [PATCH 16/17] fix --- indexer/services/ender/__tests__/helpers/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index 0b86c0c59b..751b52390d 100644 --- a/indexer/services/ender/__tests__/helpers/constants.ts +++ b/indexer/services/ender/__tests__/helpers/constants.ts @@ -283,9 +283,9 @@ export const defaultTransferEvent: TransferEventV1 = { export const defaultDeleveragingEvent: DeleveragingEventV1 = { liquidated: defaultSenderSubaccountId, offsetting: defaultRecipientSubaccountId, - clobPairId: 1, + perpetualId: 1, fillAmount: Long.fromValue(10_000, true), - subticks: Long.fromValue(1_000_000_000, true), + price: Long.fromValue(1_000_000_000, true), isBuy: true, }; export const defaultDepositEvent: TransferEventV1 = { From e8b436618e42155913fc4af2b899490328edf024 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Mon, 6 Nov 2023 11:42:05 -0500 Subject: [PATCH 17/17] address cmts --- protocol/x/clob/keeper/liquidations_test.go | 2 ++ protocol/x/clob/keeper/process_operations_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 1597dabee1..bcaed32fd3 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -2018,6 +2018,8 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { } if tc.expectedFilledSize == 0 { + // Bankruptcy price in DeleveragingEvent is not exposed by API. It is also + // being tested in other e2e tests. So we don't test it here. mockIndexerEventManager.On("AddTxnEvent", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, ).Return() diff --git a/protocol/x/clob/keeper/process_operations_test.go b/protocol/x/clob/keeper/process_operations_test.go index ba39a1b5bf..dd56a3a7c8 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1913,6 +1913,8 @@ func setupNewMockEventManager( ).Once().Return() } if isClobMatchPerpetualDeleveraging(operation) { + // Bankruptcy price in DeleveragingEvent is not exposed by API. It is also + // being tested in other e2e tests. So we don't test it here. mockIndexerEventManager.On("AddTxnEvent", mock.Anything, indexerevents.SubtypeDeleveraging,