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 1e2cdcb90b..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', @@ -439,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 4e1970c8d2..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", 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 deda80b23f..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", 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;