From 6c6dcde98198096fd192ef3e85a2ac7add8e20fe Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:19:21 -0500 Subject: [PATCH] [IND-460] Emit deleveraging events from protocol (#736) --- .../dydxprotocol/indexer/events/events.ts | 151 ++++ .../ender/__tests__/helpers/constants.ts | 14 +- .../ender/__tests__/lib/on-message.test.ts | 70 ++ .../validators/deleveraging-validator.test.ts | 80 +++ indexer/services/ender/src/constants.ts | 4 + .../src/handlers/deleveraging-handler.ts | 18 + .../services/ender/src/lib/block-processor.ts | 2 + indexer/services/ender/src/lib/helper.ts | 9 + indexer/services/ender/src/lib/types.ts | 7 + .../src/validators/deleveraging-validator.ts | 38 + .../dydxprotocol/indexer/events/events.proto | 21 + protocol/indexer/events/constants.go | 4 + protocol/indexer/events/deleveraging.go | 28 + protocol/indexer/events/deleveraging_test.go | 41 ++ protocol/indexer/events/events.pb.go | 653 ++++++++++++++---- .../indexer/indexer_manager/event_manager.go | 12 +- protocol/x/clob/keeper/deleveraging.go | 20 + protocol/x/clob/keeper/deleveraging_test.go | 89 ++- protocol/x/clob/keeper/liquidations_test.go | 5 + .../x/clob/keeper/process_operations_test.go | 23 + 20 files changed, 1144 insertions(+), 145 deletions(-) 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 create mode 100644 protocol/indexer/events/deleveraging.go create mode 100644 protocol/indexer/events/deleveraging_test.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..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 @@ -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 perpetual that was liquidated. */ + + perpetualId: number; + /** + * The amount filled between the liquidated and offsetting position, in + * base quantums. + */ + + fillAmount: Long; + /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ + + price: 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 perpetual that was liquidated. */ + + perpetual_id: number; + /** + * The amount filled between the liquidated and offsetting position, in + * base quantums. + */ + + fill_amount: Long; + /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ + + price: 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, + perpetualId: 0, + fillAmount: Long.UZERO, + price: 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.perpetualId !== 0) { + writer.uint32(24).uint32(message.perpetualId); + } + + if (!message.fillAmount.isZero()) { + writer.uint32(32).uint64(message.fillAmount); + } + + if (!message.price.isZero()) { + writer.uint32(40).uint64(message.price); + } + + 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.perpetualId = reader.uint32(); + break; + + case 4: + message.fillAmount = (reader.uint64() as Long); + break; + + case 5: + message.price = (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.perpetualId = object.perpetualId ?? 0; + message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO; + message.price = object.price !== undefined && object.price !== null ? Long.fromValue(object.price) : Long.UZERO; + message.isBuy = object.isBuy ?? false; + return message; + } + +}; + function createBaseLiquidationOrderV1(): LiquidationOrderV1 { return { liquidated: undefined, diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index 80f0d9c035..751b52390d 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, + perpetualId: 1, + fillAmount: Long.fromValue(10_000, true), + price: 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__/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/__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/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 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/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({ 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, + ), + ]; + } +} diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index 353ccdf151..c7a55a1bc8 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 perpetual that was liquidated. + uint32 perpetual_id = 3; + // The amount filled between the liquidated and offsetting position, in + // base quantums. + uint64 fill_amount = 4; + // Bankruptcy price of liquidated subaccount, in USDC quote quantums. + uint64 price = 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/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 new file mode 100644 index 0000000000..7e67f0ea0b --- /dev/null +++ b/protocol/indexer/events/deleveraging.go @@ -0,0 +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, + perpetualId uint32, + fillAmount satypes.BaseQuantums, + price satypes.BaseQuantums, + isBuy bool, +) *DeleveragingEventV1 { + indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) + indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) + return &DeleveragingEventV1{ + 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 new file mode 100644 index 0000000000..3578cc6b51 --- /dev/null +++ b/protocol/indexer/events/deleveraging_test.go @@ -0,0 +1,41 @@ +package events_test + +import ( + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + "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 + perpetualId = uint32(1) + price = satypes.BaseQuantums(1000) + isBuy = true +) + +func TestNewDeleveragingEvent_Success(t *testing.T) { + deleveragingEvent := events.NewDeleveragingEvent( + liquidatedSubaccountId, + offsettingSubaccountId, + perpetualId, + fillAmount, + price, + isBuy, + ) + indexerLiquidatedSubaccountId := v1.SubaccountIdToIndexerSubaccountId(liquidatedSubaccountId) + indexerOffsettingSubaccountId := v1.SubaccountIdToIndexerSubaccountId(offsettingSubaccountId) + expectedDeleveragingEventProto := &events.DeleveragingEventV1{ + 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 bf3ac37677..e9bb3e3dfd 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 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"` + // 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"` +} + +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) GetPerpetualId() uint32 { + if m != nil { + return m.PerpetualId + } + return 0 +} + +func (m *DeleveragingEventV1) GetFillAmount() uint64 { + if m != nil { + return m.FillAmount + } + return 0 +} + +func (m *DeleveragingEventV1) GetPrice() uint64 { + if m != nil { + return m.Price + } + 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,131 @@ 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, -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 0xec, 0x1c, 0x35, - 0x0f, 0xeb, 0x25, 0x0d, 0xdd, 0x83, 0x35, 0xc1, 0xd8, 0x3f, 0x3d, 0xde, 0x6b, 0x1c, 0x7f, 0x62, - 0x99, 0x3b, 0xad, 0xba, 0xb5, 0x73, 0xbc, 0x67, 0x35, 0x8e, 0xf7, 0xea, 0x9f, 0x95, 0x72, 0xe8, - 0x0e, 0x94, 0xfb, 0x24, 0x9f, 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,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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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2, 0xf9, 0x16, 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, 0xbd, 0x57, 0xef, 0xf7, 0x3e, 0xab, 0xde, 0xab, + 0x06, 0x36, 0xdc, 0x4b, 0xf7, 0x79, 0x14, 0x87, 0x3c, 0x74, 0x42, 0x6f, 0x93, 0x06, 0x2e, 0x79, + 0x4e, 0xe2, 0x4d, 0x72, 0x41, 0x02, 0xce, 0xf4, 0x9f, 0x8a, 0x64, 0xa3, 0xd5, 0xde, 0x9d, 0x15, + 0xbd, 0xb3, 0xa2, 0xb6, 0xac, 0x2c, 0x3b, 0x21, 0xf3, 0x43, 0x66, 0x4b, 0xfe, 0xa6, 0x5a, 0x28, + 0xb9, 0x95, 0x85, 0x76, 0xd8, 0x0e, 0x15, 0x5d, 0xfc, 0xd2, 0xd4, 0x07, 0x43, 0xf5, 0xb2, 0x33,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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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x2c, 0x37, 0x38, 0x9a, 0x5d, 0x49, 0x9d, 0x31, 0x90, 0xba, 0x05, 0x98, 0x94, 0xbd, + 0x44, 0xa6, 0xcd, 0xb0, 0xd4, 0x02, 0x2d, 0x42, 0x9e, 0x32, 0xfb, 0xb4, 0x73, 0x29, 0x13, 0x36, + 0x6d, 0x4d, 0x52, 0x56, 0xed, 0x5c, 0x9a, 0xbf, 0xce, 0x02, 0x1a, 0xac, 0x99, 0x6f, 0x36, 0x82, + 0xeb, 0x30, 0x27, 0x86, 0x5a, 0x5b, 0x74, 0xbf, 0xe4, 0xd6, 0x2a, 0x58, 0x20, 0x68, 0x0d, 0x4c, + 0xe3, 0xba, 0x3b, 0x4e, 0x18, 0xbe, 0x0d, 0xa0, 0x0a, 0x87, 0xd1, 0x17, 0x44, 0x47, 0x61, 0x46, + 0x52, 0x8e, 0xe9, 0x8b, 0x5e, 0x77, 0x27, 0x7b, 0xdc, 0x15, 0xfd, 0x8d, 0x75, 0x4e, 0x39, 0x75, + 0xce, 0x99, 0x8c, 0x83, 0x61, 0xa5, 0x6b, 0xf3, 0x7f, 0x59, 0xb8, 0xd7, 0xb5, 0xbc, 0xbf, 0xf9, + 0x3f, 0xbb, 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, 0x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, 0x9e, 0x66, 0x0b, + 0xc9, 0x47, 0xb0, 0x24, 0x5d, 0x4f, 0x66, 0x14, 0x3b, 0x08, 0xd5, 0x9d, 0xa0, 0x27, 0xdd, 0x05, + 0xc1, 0x4d, 0x66, 0x8d, 0x23, 0xcd, 0x33, 0x7f, 0x9f, 0x85, 0x45, 0x35, 0xcc, 0x25, 0xf9, 0x4e, + 0x7c, 0xbb, 0x5a, 0x89, 0x99, 0x81, 0x4a, 0xec, 0x16, 0x55, 0xf6, 0x9b, 0x2d, 0xaa, 0xdc, 0x9b, + 0x8a, 0x6a, 0x68, 0x9d, 0x18, 0x6f, 0x53, 0x27, 0x93, 0xc3, 0xeb, 0xc4, 0xfc, 0x4b, 0x06, 0x96, + 0x54, 0x7c, 0xd2, 0x63, 0x7c, 0xcd, 0x65, 0xa3, 0x0f, 0x66, 0x76, 0xf4, 0xc1, 0xcc, 0x8d, 0x73, + 0x9b, 0x18, 0x23, 0x8e, 0xc3, 0x60, 0xd1, 0x4e, 0x0e, 0x29, 0xda, 0xaa, 0xf5, 0xd5, 0xab, 0xb5, + 0xcc, 0xd7, 0xaf, 0xd6, 0x32, 0xff, 0x7d, 0xb5, 0x96, 0xf9, 0xed, 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) { @@ -2633,6 +2732,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.Price != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.Price)) + i-- + dAtA[i] = 0x28 + } + if m.FillAmount != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.FillAmount)) + i-- + dAtA[i] = 0x20 + } + if m.PerpetualId != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.PerpetualId)) + 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 +3793,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.PerpetualId != 0 { + n += 1 + sovEvents(uint64(m.PerpetualId)) + } + if m.FillAmount != 0 { + n += 1 + sovEvents(uint64(m.FillAmount)) + } + if m.Price != 0 { + n += 1 + sovEvents(uint64(m.Price)) + } + if m.IsBuy { + n += 2 + } + return n +} + func (m *LiquidationOrderV1) Size() (n int) { if m == nil { return 0 @@ -5324,6 +5516,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 PerpetualId", wireType) + } + m.PerpetualId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PerpetualId |= 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 Price", wireType) + } + m.Price = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Price |= 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 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.go b/protocol/x/clob/keeper/deleveraging.go index f47246c477..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" @@ -451,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/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..bcaed32fd3 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -2018,6 +2018,11 @@ 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() _, 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..dd56a3a7c8 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1912,7 +1912,30 @@ 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, + 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(