From 80b3113fef9723fc4699e6b12a1f60450ccb92a7 Mon Sep 17 00:00:00 2001 From: vincentwschau <99756290+vincentwschau@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:42:58 -0500 Subject: [PATCH] Revert "[CT-629] Fix entryPrice calc (#2455)" (#2600) --- .../order-fills/liquidation-handler.test.ts | 4 ++-- .../order-fills/order-handler.test.ts | 22 +++---------------- ...ydx_liquidation_fill_handler_per_order.sql | 2 +- ...te_perpetual_position_aggregate_fields.sql | 2 +- 4 files changed, 7 insertions(+), 23 deletions(-) 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 805ca676f0..a5cc41f3d6 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 @@ -137,7 +137,7 @@ describe('LiquidationHandler', () => { perpetualId: testConstants.defaultPerpetualMarket.id, side: PositionSide.LONG, status: PerpetualPositionStatus.OPEN, - size: '5', + size: '10', maxSize: '25', sumOpen: '10', entryPrice: '15000', @@ -392,7 +392,7 @@ describe('LiquidationHandler', () => { defaultPerpetualPosition.openEventId, ), { - sumOpen: Big(defaultPerpetualPosition.sumOpen!).plus(totalFilled).toFixed(), + sumOpen: Big(defaultPerpetualPosition.size).plus(totalFilled).toFixed(), entryPrice: getWeightedAverage( defaultPerpetualPosition.entryPrice!, defaultPerpetualPosition.size, 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 65cb1c0422..ba9a62ab34 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 @@ -138,7 +138,7 @@ describe('OrderHandler', () => { perpetualId: testConstants.defaultPerpetualMarket.id, side: PositionSide.LONG, status: PerpetualPositionStatus.OPEN, - size: '5', + size: '10', maxSize: '25', sumOpen: '10', entryPrice: '15000', @@ -212,7 +212,6 @@ describe('OrderHandler', () => { { goodTilBlock: 15, }, - false, ], [ 'goodTilBlockTime', @@ -222,17 +221,6 @@ describe('OrderHandler', () => { { goodTilBlockTime: 1_000_005_000, }, - false, - ], - [ - 'goodTilBlock', - { - goodTilBlock: 10, - }, - { - goodTilBlock: 15, - }, - true, ], ])( 'creates fills and orders (with %s), sends vulcan messages for order updates and order ' + @@ -241,7 +229,6 @@ describe('OrderHandler', () => { _name: string, makerGoodTilOneof: Partial, takerGoodTilOneof: Partial, - useNegativeSize: boolean, ) => { const transactionIndex: number = 0; const eventIndex: number = 0; @@ -297,10 +284,7 @@ describe('OrderHandler', () => { // create PerpetualPositions await Promise.all([ - PerpetualPositionTable.create({ - ...defaultPerpetualPosition, - size: useNegativeSize ? '-5' : defaultPerpetualPosition.size, - }), + PerpetualPositionTable.create(defaultPerpetualPosition), PerpetualPositionTable.create({ ...defaultPerpetualPosition, subaccountId: testConstants.defaultSubaccountId2, @@ -455,7 +439,7 @@ describe('OrderHandler', () => { defaultPerpetualPosition.openEventId, ), { - sumOpen: Big(defaultPerpetualPosition.sumOpen!).plus(totalFilled).toFixed(), + sumOpen: Big(defaultPerpetualPosition.size).plus(totalFilled).toFixed(), entryPrice: getWeightedAverage( defaultPerpetualPosition.entryPrice!, defaultPerpetualPosition.size, diff --git a/indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql b/indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql index dc3dfa5e4c..493b1257d6 100644 --- a/indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql +++ b/indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql @@ -200,7 +200,7 @@ BEGIN perpetual_position_record."side", order_side) THEN sum_open = dydx_trim_scale(perpetual_position_record."sumOpen" + fill_amount); entry_price = dydx_get_weighted_average( - perpetual_position_record."entryPrice", ABS(perpetual_position_record."size"), + perpetual_position_record."entryPrice", perpetual_position_record."sumOpen", maker_price, fill_amount); perpetual_position_record."sumOpen" = sum_open; perpetual_position_record."entryPrice" = entry_price; diff --git a/indexer/services/ender/src/scripts/helpers/dydx_update_perpetual_position_aggregate_fields.sql b/indexer/services/ender/src/scripts/helpers/dydx_update_perpetual_position_aggregate_fields.sql index f6e269a0b1..d021eecf28 100644 --- a/indexer/services/ender/src/scripts/helpers/dydx_update_perpetual_position_aggregate_fields.sql +++ b/indexer/services/ender/src/scripts/helpers/dydx_update_perpetual_position_aggregate_fields.sql @@ -44,7 +44,7 @@ BEGIN IF dydx_perpetual_position_and_order_side_matching(perpetual_position_record."side", side) THEN sum_open := dydx_trim_scale(perpetual_position_record."sumOpen" + size); entry_price := dydx_get_weighted_average( - perpetual_position_record."entryPrice", ABS(perpetual_position_record."size"), price, size + perpetual_position_record."entryPrice", perpetual_position_record."sumOpen", price, size ); perpetual_position_record."sumOpen" = sum_open; perpetual_position_record."entryPrice" = entry_price;