From 76068c9cd59e4dbf83de4cfd0b0aeb3c7c90d323 Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:35:05 -0500 Subject: [PATCH] Remove basePositionNotional from Indexer APIs (#970) --- .../postgres/__tests__/helpers/constants.ts | 2 -- ...410_remove_unused_liquidity_tiers_columns.ts | 17 +++++++++++++++++ .../src/models/liquidity-tiers-model.ts | 7 +------ .../postgres/src/types/db-model-types.ts | 1 - .../postgres/src/types/liquidity-tiers-types.ts | 3 --- .../src/types/websocket-message-types.ts | 1 - .../request-helpers/request-transformer.test.ts | 1 - .../comlink/public/api-documentation.md | 6 ------ indexer/services/comlink/public/swagger.json | 4 ---- .../comlink/public/websocket-documentation.md | 3 --- .../src/request-helpers/request-transformer.ts | 1 - indexer/services/comlink/src/types.ts | 1 - .../handlers/liquidity-tier-handler.test.ts | 10 ---------- .../validators/liquidity-tier-validator.test.ts | 10 ---------- .../services/ender/src/helpers/kafka-helper.ts | 1 - .../handlers/dydx_liquidity_tier_handler.sql | 4 +--- .../src/validators/liquidity-tier-validator.ts | 10 ---------- .../roundtable/src/helpers/websocket.ts | 2 -- .../lib/athena-ddl-tables/liquidity_tiers.ts | 7 ++----- 19 files changed, 21 insertions(+), 70 deletions(-) create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20240117120410_remove_unused_liquidity_tiers_columns.ts diff --git a/indexer/packages/postgres/__tests__/helpers/constants.ts b/indexer/packages/postgres/__tests__/helpers/constants.ts index 4b86020f1d..e8cddb02c6 100644 --- a/indexer/packages/postgres/__tests__/helpers/constants.ts +++ b/indexer/packages/postgres/__tests__/helpers/constants.ts @@ -483,7 +483,6 @@ export const defaultLiquidityTier: LiquidityTiersCreateObject = { name: 'Large-Cap', initialMarginPpm: '50000', // 5% maintenanceFractionPpm: '600000', // 60% - basePositionNotional: '1000000', }; export const defaultLiquidityTier2: LiquidityTiersCreateObject = { @@ -491,7 +490,6 @@ export const defaultLiquidityTier2: LiquidityTiersCreateObject = { name: 'Mid-Cap', initialMarginPpm: '100000', // 10% maintenanceFractionPpm: '500000', // 50% - basePositionNotional: '1000', }; // ============== OraclePrices ============== diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240117120410_remove_unused_liquidity_tiers_columns.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240117120410_remove_unused_liquidity_tiers_columns.ts new file mode 100644 index 0000000000..ba275578dd --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240117120410_remove_unused_liquidity_tiers_columns.ts @@ -0,0 +1,17 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + return knex + .schema + .alterTable('liquidity_tiers', (table) => { + table.dropColumn('basePositionNotional'); + }); +} + +export async function down(knex: Knex): Promise { + return knex + .schema + .alterTable('liquidity_tiers', (table) => { + table.decimal('basePositionNotional', null).notNullable().defaultTo('0'); + }); +} diff --git a/indexer/packages/postgres/src/models/liquidity-tiers-model.ts b/indexer/packages/postgres/src/models/liquidity-tiers-model.ts index 97e595c837..5bb40d66f8 100644 --- a/indexer/packages/postgres/src/models/liquidity-tiers-model.ts +++ b/indexer/packages/postgres/src/models/liquidity-tiers-model.ts @@ -1,4 +1,4 @@ -import { IntegerPattern, NonNegativeNumericPattern } from '../lib/validators'; +import { IntegerPattern } from '../lib/validators'; import UpsertQueryBuilder from '../query-builders/upsert'; import BaseModel from './base-model'; @@ -21,14 +21,12 @@ export default class LiquidityTiersModel extends BaseModel { 'name', 'initialMarginPpm', 'maintenanceFractionPpm', - 'basePositionNotional', ], properties: { id: { type: 'integer' }, name: { type: 'string' }, initialMarginPpm: { type: 'string', pattern: IntegerPattern }, maintenanceFractionPpm: { type: 'string', pattern: IntegerPattern }, - basePositionNotional: { type: 'string', pattern: NonNegativeNumericPattern }, }, }; } @@ -45,7 +43,6 @@ export default class LiquidityTiersModel extends BaseModel { name: 'string', initialMarginPpm: 'string', maintenanceFractionPpm: 'string', - basePositionNotional: 'string', }; } @@ -58,6 +55,4 @@ export default class LiquidityTiersModel extends BaseModel { initialMarginPpm!: string; maintenanceFractionPpm!: string; - - basePositionNotional!: string; } diff --git a/indexer/packages/postgres/src/types/db-model-types.ts b/indexer/packages/postgres/src/types/db-model-types.ts index 3e1c52d8eb..43740af5f7 100644 --- a/indexer/packages/postgres/src/types/db-model-types.ts +++ b/indexer/packages/postgres/src/types/db-model-types.ts @@ -179,7 +179,6 @@ export interface LiquidityTiersFromDatabase { name: string; initialMarginPpm: string; maintenanceFractionPpm: string; - basePositionNotional: string; } export interface CandleFromDatabase extends IdBasedModelFromDatabase { diff --git a/indexer/packages/postgres/src/types/liquidity-tiers-types.ts b/indexer/packages/postgres/src/types/liquidity-tiers-types.ts index 686cebcac5..784dd5f7ff 100644 --- a/indexer/packages/postgres/src/types/liquidity-tiers-types.ts +++ b/indexer/packages/postgres/src/types/liquidity-tiers-types.ts @@ -5,7 +5,6 @@ export interface LiquidityTiersCreateObject { name: string, initialMarginPpm: string, maintenanceFractionPpm: string, - basePositionNotional: string, } export interface LiquidityTiersUpdateObject { @@ -13,7 +12,6 @@ export interface LiquidityTiersUpdateObject { name?: string, initialMarginPpm?: string, maintenanceFractionPpm?: string, - basePositionNotional?: string, } export enum LiquidityTiersColumns { @@ -21,5 +19,4 @@ export enum LiquidityTiersColumns { name = 'name', initialMarginPpm = 'initialMarginPpm', maintenanceFractionPpm = 'maintenanceFractionPpm', - basePositionNotional = 'basePositionNotional', } diff --git a/indexer/packages/postgres/src/types/websocket-message-types.ts b/indexer/packages/postgres/src/types/websocket-message-types.ts index 615ba1d73a..8e68b8f3eb 100644 --- a/indexer/packages/postgres/src/types/websocket-message-types.ts +++ b/indexer/packages/postgres/src/types/websocket-message-types.ts @@ -207,7 +207,6 @@ export interface TradingPerpetualMarketMessage { status?: PerpetualMarketStatus; initialMarginFraction?: string; maintenanceMarginFraction?: string; - basePositionNotional?: string; openInterest?: string; quantumConversionExponent?: number; atomicResolution?: number; diff --git a/indexer/services/comlink/__tests__/lib/request-helpers/request-transformer.test.ts b/indexer/services/comlink/__tests__/lib/request-helpers/request-transformer.test.ts index 2583e6289a..07ebb2d930 100644 --- a/indexer/services/comlink/__tests__/lib/request-helpers/request-transformer.test.ts +++ b/indexer/services/comlink/__tests__/lib/request-helpers/request-transformer.test.ts @@ -70,7 +70,6 @@ describe('request-transformer', () => { Number(liquidityTier.maintenanceFractionPpm), ), ), - basePositionNotional: liquidityTier.basePositionNotional, openInterest: perpetualMarket.openInterest, atomicResolution: perpetualMarket.atomicResolution, quantumConversionExponent: perpetualMarket.quantumConversionExponent, diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index c827bdf3b8..6b7c26babe 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -1410,7 +1410,6 @@ fetch('https://dydx-testnet.imperator.co/v4/perpetualMarkets?limit=0', "nextFundingRate": "string", "initialMarginFraction": "string", "maintenanceMarginFraction": "string", - "basePositionNotional": "string", "openInterest": "string", "atomicResolution": 0, "quantumConversionExponent": 0, @@ -1430,7 +1429,6 @@ fetch('https://dydx-testnet.imperator.co/v4/perpetualMarkets?limit=0', "nextFundingRate": "string", "initialMarginFraction": "string", "maintenanceMarginFraction": "string", - "basePositionNotional": "string", "openInterest": "string", "atomicResolution": 0, "quantumConversionExponent": 0, @@ -3173,7 +3171,6 @@ or "nextFundingRate": "string", "initialMarginFraction": "string", "maintenanceMarginFraction": "string", - "basePositionNotional": "string", "openInterest": "string", "atomicResolution": 0, "quantumConversionExponent": 0, @@ -3199,7 +3196,6 @@ or |nextFundingRate|string|true|none|none| |initialMarginFraction|string|true|none|none| |maintenanceMarginFraction|string|true|none|none| -|basePositionNotional|string|true|none|none| |openInterest|string|true|none|none| |atomicResolution|number(double)|true|none|none| |quantumConversionExponent|number(double)|true|none|none| @@ -3229,7 +3225,6 @@ or "nextFundingRate": "string", "initialMarginFraction": "string", "maintenanceMarginFraction": "string", - "basePositionNotional": "string", "openInterest": "string", "atomicResolution": 0, "quantumConversionExponent": 0, @@ -3249,7 +3244,6 @@ or "nextFundingRate": "string", "initialMarginFraction": "string", "maintenanceMarginFraction": "string", - "basePositionNotional": "string", "openInterest": "string", "atomicResolution": 0, "quantumConversionExponent": 0, diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 5069c88ede..e7247d4257 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -831,9 +831,6 @@ "maintenanceMarginFraction": { "type": "string" }, - "basePositionNotional": { - "type": "string" - }, "openInterest": { "type": "string" }, @@ -871,7 +868,6 @@ "nextFundingRate", "initialMarginFraction", "maintenanceMarginFraction", - "basePositionNotional", "openInterest", "atomicResolution", "quantumConversionExponent", diff --git a/indexer/services/comlink/public/websocket-documentation.md b/indexer/services/comlink/public/websocket-documentation.md index 31fc5bc4cf..172259c09f 100644 --- a/indexer/services/comlink/public/websocket-documentation.md +++ b/indexer/services/comlink/public/websocket-documentation.md @@ -811,7 +811,6 @@ Returns everything from `v4/perpetualMarkets` endpoint. "nextFundingRate": "0", "initialMarginFraction": "0.050000", "maintenanceMarginFraction": "0.030000", - "basePositionNotional": "1000", "basePositionSize": "0", "incrementalPositionSize": "0", "maxPositionSize": "0", @@ -836,7 +835,6 @@ Returns everything from `v4/perpetualMarkets` endpoint. "nextFundingRate": "0", "initialMarginFraction": "0.050000", "maintenanceMarginFraction": "0.030000", - "basePositionNotional": "1000", "basePositionSize": "0", "incrementalPositionSize": "0", "maxPositionSize": "0", @@ -883,7 +881,6 @@ interface TradingPerpetualMarketMessage { quoteAsset?: string; initialMarginFraction?: string; maintenanceMarginFraction?: string; - basePositionNotional?: string; basePositionSize?: string; incrementalPositionSize?: string; maxPositionSize?: string; diff --git a/indexer/services/comlink/src/request-helpers/request-transformer.ts b/indexer/services/comlink/src/request-helpers/request-transformer.ts index bb920ef233..1fe32aa721 100644 --- a/indexer/services/comlink/src/request-helpers/request-transformer.ts +++ b/indexer/services/comlink/src/request-helpers/request-transformer.ts @@ -288,7 +288,6 @@ export function perpetualMarketToResponseObject( Number(liquidityTier.maintenanceFractionPpm), ), ), - basePositionNotional: liquidityTier.basePositionNotional, openInterest: perpetualMarket.openInterest, atomicResolution: perpetualMarket.atomicResolution, quantumConversionExponent: perpetualMarket.quantumConversionExponent, diff --git a/indexer/services/comlink/src/types.ts b/indexer/services/comlink/src/types.ts index 6fcaa098d1..bf9d9ea6d5 100644 --- a/indexer/services/comlink/src/types.ts +++ b/indexer/services/comlink/src/types.ts @@ -226,7 +226,6 @@ export interface PerpetualMarketResponseObject { nextFundingRate: string; initialMarginFraction: string; maintenanceMarginFraction: string; - basePositionNotional: string; openInterest: string; atomicResolution: number; quantumConversionExponent: number; diff --git a/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts b/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts index a9353d03c0..ac14d48f63 100644 --- a/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts @@ -11,10 +11,8 @@ import { LiquidityTiersFromDatabase, LiquidityTiersTable, Ordering, - QUOTE_CURRENCY_ATOMIC_RESOLUTION, TendermintEventTable, testConstants, - protocolTranslations, liquidityTierRefresher, PerpetualMarketFromDatabase, perpetualMarketRefresher, @@ -176,10 +174,6 @@ export function expectLiquidityTier( name: event.name, initialMarginPpm: event.initialMarginPpm.toString(), maintenanceFractionPpm: event.maintenanceFractionPpm.toString(), - basePositionNotional: protocolTranslations.quantumsToHuman( - event.basePositionNotional.toString(), - QUOTE_CURRENCY_ATOMIC_RESOLUTION, - ).toFixed(), })); } @@ -241,10 +235,6 @@ function validateLiquidityTierRefresher( name: liquidityTierEvent.name, initialMarginPpm: liquidityTierEvent.initialMarginPpm.toString(), maintenanceFractionPpm: liquidityTierEvent.maintenanceFractionPpm.toString(), - basePositionNotional: protocolTranslations.quantumsToHuman( - liquidityTierEvent.basePositionNotional.toString(), - QUOTE_CURRENCY_ATOMIC_RESOLUTION, - ).toFixed(), }); } diff --git a/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts b/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts index c1af377c40..3d02a018c8 100644 --- a/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts @@ -15,7 +15,6 @@ import { } from '../helpers/indexer-proto-helpers'; import { expectDidntLogError } from '../helpers/validator-helpers'; import { LiquidityTierValidator } from '../../src/validators/liquidity-tier-validator'; -import Long from 'long'; describe('liquidity-tier-validator', () => { beforeEach(async () => { @@ -75,15 +74,6 @@ describe('liquidity-tier-validator', () => { } as LiquidityTierUpsertEventV1, 'LiquidityTierUpsertEventV1 name is not populated', ], - [ - 'logs error on liquidity tier upsert event with basePositionNotional equal to 0', - { - ...defaultLiquidityTierUpsertEvent, - basePositionNotional: Long.fromValue(0, true), - } as LiquidityTierUpsertEventV1, - 'LiquidityTierUpsertEventV1 basePositionNotional is not populated', - ], - // ... other test cases here ... ])('%s', (_description: string, event: LiquidityTierUpsertEventV1, expectedMessage: string) => { const loggerError = jest.spyOn(logger, 'error'); diff --git a/indexer/services/ender/src/helpers/kafka-helper.ts b/indexer/services/ender/src/helpers/kafka-helper.ts index 169940e2cf..b2223078a9 100644 --- a/indexer/services/ender/src/helpers/kafka-helper.ts +++ b/indexer/services/ender/src/helpers/kafka-helper.ts @@ -326,7 +326,6 @@ export function generatePerpetualMarketMessage( Number(liquidityTier.maintenanceFractionPpm), ), ), - basePositionNotional: liquidityTier.basePositionNotional, }; }) .value(); diff --git a/indexer/services/ender/src/scripts/handlers/dydx_liquidity_tier_handler.sql b/indexer/services/ender/src/scripts/handlers/dydx_liquidity_tier_handler.sql index b3fdac558e..feec03dfd7 100644 --- a/indexer/services/ender/src/scripts/handlers/dydx_liquidity_tier_handler.sql +++ b/indexer/services/ender/src/scripts/handlers/dydx_liquidity_tier_handler.sql @@ -15,7 +15,6 @@ BEGIN liquidity_tier_record."name" = event_data->>'name'; liquidity_tier_record."initialMarginPpm" = (event_data->'initialMarginPpm')::bigint; liquidity_tier_record."maintenanceFractionPpm" = (event_data->'maintenanceFractionPpm')::bigint; - liquidity_tier_record."basePositionNotional" = dydx_trim_scale(power(10, -6)::numeric * dydx_from_jsonlib_long(event_data->'basePositionNotional')); INSERT INTO liquidity_tiers VALUES (liquidity_tier_record.*) @@ -24,8 +23,7 @@ BEGIN SET "name" = liquidity_tier_record."name", "initialMarginPpm" = liquidity_tier_record."initialMarginPpm", - "maintenanceFractionPpm" = liquidity_tier_record."maintenanceFractionPpm", - "basePositionNotional" = liquidity_tier_record."basePositionNotional" + "maintenanceFractionPpm" = liquidity_tier_record."maintenanceFractionPpm" RETURNING * INTO liquidity_tier_record; RETURN jsonb_build_object( diff --git a/indexer/services/ender/src/validators/liquidity-tier-validator.ts b/indexer/services/ender/src/validators/liquidity-tier-validator.ts index 3c6417e0f9..a41d53df71 100644 --- a/indexer/services/ender/src/validators/liquidity-tier-validator.ts +++ b/indexer/services/ender/src/validators/liquidity-tier-validator.ts @@ -1,6 +1,5 @@ import { logger } from '@dydxprotocol-indexer/base'; import { IndexerTendermintEvent, LiquidityTierUpsertEventV1 } from '@dydxprotocol-indexer/v4-protos'; -import Long from 'long'; import { Handler } from '../handlers/handler'; import { LiquidityTierHandler } from '../handlers/liquidity-tier-handler'; @@ -17,15 +16,6 @@ export class LiquidityTierValidator extends Validator