From 4c5cd26cb7bbc3f00c443a728fe0a9122675cc00 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Tue, 28 Nov 2023 17:37:44 -0500 Subject: [PATCH] [IND-491]: Remove unused lastPrice from perpetual_markets table --- .../postgres/__tests__/helpers/constants.ts | 3 --- ...171435_remove_perpetual_market_last_price.ts | 17 +++++++++++++++++ .../src/models/perpetual-market-model.ts | 5 ----- .../postgres/src/types/db-model-types.ts | 1 - .../src/types/perpetual-market-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 - .../__tests__/helpers/indexer-proto-helpers.ts | 1 - .../scripts/dydx_perpetual_market_handler.sql | 3 +-- .../lib/athena-ddl-tables/perpetual_markets.ts | 2 -- 15 files changed, 18 insertions(+), 34 deletions(-) create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20231128171435_remove_perpetual_market_last_price.ts diff --git a/indexer/packages/postgres/__tests__/helpers/constants.ts b/indexer/packages/postgres/__tests__/helpers/constants.ts index 8dad14e10c..8fec414605 100644 --- a/indexer/packages/postgres/__tests__/helpers/constants.ts +++ b/indexer/packages/postgres/__tests__/helpers/constants.ts @@ -151,7 +151,6 @@ export const defaultPerpetualMarket: PerpetualMarketCreateObject = { ticker: 'BTC-USD', marketId: 0, status: PerpetualMarketStatus.ACTIVE, - lastPrice: '15000', priceChange24H: '23', volume24H: '1000000', trades24H: 250, @@ -169,7 +168,6 @@ export const defaultPerpetualMarket2: PerpetualMarketCreateObject = { ticker: 'ETH-USD', marketId: 1, status: PerpetualMarketStatus.ACTIVE, - lastPrice: '1500', priceChange24H: '23', volume24H: '100000', trades24H: 200, @@ -187,7 +185,6 @@ export const defaultPerpetualMarket3: PerpetualMarketCreateObject = { ticker: 'SHIB-USD', marketId: 2, status: PerpetualMarketStatus.ACTIVE, - lastPrice: '0.000000065', priceChange24H: '0.000000001', volume24H: '10000000', trades24H: 200, diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20231128171435_remove_perpetual_market_last_price.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20231128171435_remove_perpetual_market_last_price.ts new file mode 100644 index 0000000000..4c9d5225fb --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20231128171435_remove_perpetual_market_last_price.ts @@ -0,0 +1,17 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + return knex + .schema + .alterTable('perpetual_markets', (table) => { + table.dropColumn('lastPrice'); + }); +} + +export async function down(knex: Knex): Promise { + return knex + .schema + .alterTable('perpetual_markets', (table) => { + table.decimal('lastPrice', null).defaultTo('0').notNullable(); + }); +} diff --git a/indexer/packages/postgres/src/models/perpetual-market-model.ts b/indexer/packages/postgres/src/models/perpetual-market-model.ts index 6ad62950a7..124383d11b 100644 --- a/indexer/packages/postgres/src/models/perpetual-market-model.ts +++ b/indexer/packages/postgres/src/models/perpetual-market-model.ts @@ -56,7 +56,6 @@ export default class PerpetualMarketModel extends Model { 'ticker', 'marketId', 'status', - 'lastPrice', 'priceChange24H', 'volume24H', 'trades24H', @@ -74,7 +73,6 @@ export default class PerpetualMarketModel extends Model { ticker: { type: 'string' }, marketId: { type: 'integer' }, status: { type: 'string', enum: [...Object.values(PerpetualMarketStatus)] }, - lastPrice: { type: 'string', pattern: NonNegativeNumericPattern }, priceChange24H: { type: 'string', pattern: NumericPattern }, volume24H: { type: 'string', pattern: NonNegativeNumericPattern }, trades24H: { type: 'integer' }, @@ -102,7 +100,6 @@ export default class PerpetualMarketModel extends Model { ticker: 'string', marketId: 'integer', status: 'string', - lastPrice: 'string', priceChange24H: 'string', volume24H: 'string', trades24H: 'integer', @@ -126,8 +123,6 @@ export default class PerpetualMarketModel extends Model { status!: PerpetualMarketStatus; - lastPrice!: string; - priceChange24H!: string; volume24H!: string; diff --git a/indexer/packages/postgres/src/types/db-model-types.ts b/indexer/packages/postgres/src/types/db-model-types.ts index 5243a413e7..42dd465074 100644 --- a/indexer/packages/postgres/src/types/db-model-types.ts +++ b/indexer/packages/postgres/src/types/db-model-types.ts @@ -78,7 +78,6 @@ export interface PerpetualMarketFromDatabase { ticker: string; marketId: number; status: PerpetualMarketStatus; - lastPrice: string; priceChange24H: string; volume24H: string; trades24H: number; diff --git a/indexer/packages/postgres/src/types/perpetual-market-types.ts b/indexer/packages/postgres/src/types/perpetual-market-types.ts index d527078f38..65962fb655 100644 --- a/indexer/packages/postgres/src/types/perpetual-market-types.ts +++ b/indexer/packages/postgres/src/types/perpetual-market-types.ts @@ -6,7 +6,6 @@ export interface PerpetualMarketCreateObject { ticker: string; marketId: number; status: PerpetualMarketStatus; - lastPrice: string; priceChange24H: string; volume24H: string; trades24H: number; @@ -25,7 +24,6 @@ export interface PerpetualMarketUpdateObject { ticker?: string; marketId?: number; status?: PerpetualMarketStatus; - lastPrice?: string; priceChange24H?: string; volume24H?: string; trades24H?: number; @@ -44,7 +42,6 @@ export enum PerpetualMarketColumns { ticker = 'ticker', marketId = 'marketId', status = 'status', - lastPrice = 'lastPrice', priceChange24H = 'priceChange24H', volume24H = 'volume24H', trades24H = 'trades24H', diff --git a/indexer/packages/postgres/src/types/websocket-message-types.ts b/indexer/packages/postgres/src/types/websocket-message-types.ts index fe22d02866..ffbf1f3127 100644 --- a/indexer/packages/postgres/src/types/websocket-message-types.ts +++ b/indexer/packages/postgres/src/types/websocket-message-types.ts @@ -208,7 +208,6 @@ export interface TradingPerpetualMarketMessage { stepBaseQuantums?: number; // Fields that are likely to change - lastPrice?: string; priceChange24H?: string; volume24H?: string; trades24H?: 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 bef010a3d1..2583e6289a 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 @@ -58,7 +58,6 @@ describe('request-transformer', () => { clobPairId: perpetualMarket.clobPairId, ticker: perpetualMarket.ticker, status: perpetualMarket.status, - lastPrice: perpetualMarket.lastPrice, oraclePrice: market.oraclePrice, priceChange24H: perpetualMarket.priceChange24H, volume24H: perpetualMarket.volume24H, diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index 141caedf8b..b069f94dcf 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -1282,7 +1282,6 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/perpetualMarkets?limit=0', "clobPairId": "string", "ticker": "string", "status": "ACTIVE", - "lastPrice": "string", "oraclePrice": "string", "priceChange24H": "string", "volume24H": "string", @@ -1303,7 +1302,6 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/perpetualMarkets?limit=0', "clobPairId": "string", "ticker": "string", "status": "ACTIVE", - "lastPrice": "string", "oraclePrice": "string", "priceChange24H": "string", "volume24H": "string", @@ -2831,7 +2829,6 @@ or "clobPairId": "string", "ticker": "string", "status": "ACTIVE", - "lastPrice": "string", "oraclePrice": "string", "priceChange24H": "string", "volume24H": "string", @@ -2858,7 +2855,6 @@ or |clobPairId|string|true|none|none| |ticker|string|true|none|none| |status|[PerpetualMarketStatus](#schemaperpetualmarketstatus)|true|none|none| -|lastPrice|string|true|none|none| |oraclePrice|string|true|none|none| |priceChange24H|string|true|none|none| |volume24H|string|true|none|none| @@ -2889,7 +2885,6 @@ or "clobPairId": "string", "ticker": "string", "status": "ACTIVE", - "lastPrice": "string", "oraclePrice": "string", "priceChange24H": "string", "volume24H": "string", @@ -2910,7 +2905,6 @@ or "clobPairId": "string", "ticker": "string", "status": "ACTIVE", - "lastPrice": "string", "oraclePrice": "string", "priceChange24H": "string", "volume24H": "string", diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index f6036eef70..e5b5d205dc 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -701,9 +701,6 @@ "status": { "$ref": "#/components/schemas/PerpetualMarketStatus" }, - "lastPrice": { - "type": "string" - }, "oraclePrice": { "type": "string" }, @@ -759,7 +756,6 @@ "clobPairId", "ticker", "status", - "lastPrice", "oraclePrice", "priceChange24H", "volume24H", diff --git a/indexer/services/comlink/public/websocket-documentation.md b/indexer/services/comlink/public/websocket-documentation.md index 495e3a6eff..31fc5bc4cf 100644 --- a/indexer/services/comlink/public/websocket-documentation.md +++ b/indexer/services/comlink/public/websocket-documentation.md @@ -804,7 +804,6 @@ Returns everything from `v4/perpetualMarkets` endpoint. "status": "ACTIVE", "baseAsset": "", "quoteAsset": "", - "lastPrice": "0", "oraclePrice": "27752.92", "priceChange24H": "0", "volume24H": "63894023.044245577", @@ -830,7 +829,6 @@ Returns everything from `v4/perpetualMarkets` endpoint. "status": "ACTIVE", "baseAsset": "", "quoteAsset": "", - "lastPrice": "0", "oraclePrice": "1808.2", "priceChange24H": "0", "volume24H": "67487133.70842158", @@ -894,7 +892,6 @@ interface TradingPerpetualMarketMessage { atomicResolution?: number; subticksPerTick?: number; stepBaseQuantums?: number; - lastPrice?: string; priceChange24H?: string; volume24H?: string; trades24H?: number; diff --git a/indexer/services/comlink/src/request-helpers/request-transformer.ts b/indexer/services/comlink/src/request-helpers/request-transformer.ts index 52cab29196..521987fcdf 100644 --- a/indexer/services/comlink/src/request-helpers/request-transformer.ts +++ b/indexer/services/comlink/src/request-helpers/request-transformer.ts @@ -272,7 +272,6 @@ export function perpetualMarketToResponseObject( clobPairId: perpetualMarket.clobPairId, ticker: perpetualMarket.ticker, status: perpetualMarket.status, - lastPrice: perpetualMarket.lastPrice, oraclePrice: market.oraclePrice!, priceChange24H: perpetualMarket.priceChange24H, volume24H: perpetualMarket.volume24H, diff --git a/indexer/services/comlink/src/types.ts b/indexer/services/comlink/src/types.ts index 8e855e09bd..0be3b18119 100644 --- a/indexer/services/comlink/src/types.ts +++ b/indexer/services/comlink/src/types.ts @@ -213,7 +213,6 @@ export interface PerpetualMarketResponseObject { clobPairId: string; ticker: string; status: PerpetualMarketStatus; - lastPrice: string; oraclePrice: string; priceChange24H: string; volume24H: string; diff --git a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts index 0a1fc7dbea..6dc900c143 100644 --- a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts +++ b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts @@ -852,7 +852,6 @@ export async function expectPerpetualPosition( // Values of the `PerpetualMarketCreateObject` which are hard-coded and not derived // from PerpetualMarketCreate events. export const HARDCODED_PERPETUAL_MARKET_VALUES: Object = { - lastPrice: '0', priceChange24H: '0', trades24H: 0, volume24H: '0', diff --git a/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql b/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql index 488df44cc9..f79e8b0954 100644 --- a/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql @@ -14,7 +14,6 @@ BEGIN perpetual_market_record."ticker" = event_data->>'ticker'; perpetual_market_record."marketId" = (event_data->'marketId')::integer; perpetual_market_record."status" = dydx_clob_pair_status_to_market_status(event_data->'status'); - perpetual_market_record."lastPrice" = 0; perpetual_market_record."priceChange24H" = 0; perpetual_market_record."trades24H" = 0; perpetual_market_record."volume24H" = 0; @@ -33,4 +32,4 @@ BEGIN dydx_to_jsonb(perpetual_market_record) ); END; -$$ LANGUAGE plpgsql; \ No newline at end of file +$$ LANGUAGE plpgsql; diff --git a/indexer/services/roundtable/src/lib/athena-ddl-tables/perpetual_markets.ts b/indexer/services/roundtable/src/lib/athena-ddl-tables/perpetual_markets.ts index 7e984f2774..d744f1b7e3 100644 --- a/indexer/services/roundtable/src/lib/athena-ddl-tables/perpetual_markets.ts +++ b/indexer/services/roundtable/src/lib/athena-ddl-tables/perpetual_markets.ts @@ -11,7 +11,6 @@ const RAW_TABLE_COLUMNS: string = ` \`ticker\` string, \`marketId\` int, \`status\` string, - \`lastPrice\` string, \`priceChange24H\` string, \`volume24H\` string, \`trades24H\` int, @@ -29,7 +28,6 @@ const TABLE_COLUMNS: string = ` "ticker", "marketId", "status", - ${castToDouble('lastPrice')}, ${castToDouble('priceChange24H')}, ${castToDouble('volume24H')}, "trades24H",