Skip to content

Commit

Permalink
Remove basePositionNotional from Indexer APIs (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill authored Jan 17, 2024
1 parent 2362bdb commit 76068c9
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 70 deletions.
2 changes: 0 additions & 2 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,13 @@ export const defaultLiquidityTier: LiquidityTiersCreateObject = {
name: 'Large-Cap',
initialMarginPpm: '50000', // 5%
maintenanceFractionPpm: '600000', // 60%
basePositionNotional: '1000000',
};

export const defaultLiquidityTier2: LiquidityTiersCreateObject = {
id: 1,
name: 'Mid-Cap',
initialMarginPpm: '100000', // 10%
maintenanceFractionPpm: '500000', // 50%
basePositionNotional: '1000',
};

// ============== OraclePrices ==============
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex
.schema
.alterTable('liquidity_tiers', (table) => {
table.dropColumn('basePositionNotional');
});
}

export async function down(knex: Knex): Promise<void> {
return knex
.schema
.alterTable('liquidity_tiers', (table) => {
table.decimal('basePositionNotional', null).notNullable().defaultTo('0');
});
}
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 },
},
};
}
Expand All @@ -45,7 +43,6 @@ export default class LiquidityTiersModel extends BaseModel {
name: 'string',
initialMarginPpm: 'string',
maintenanceFractionPpm: 'string',
basePositionNotional: 'string',
};
}

Expand All @@ -58,6 +55,4 @@ export default class LiquidityTiersModel extends BaseModel {
initialMarginPpm!: string;

maintenanceFractionPpm!: string;

basePositionNotional!: string;
}
1 change: 0 additions & 1 deletion indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export interface LiquidityTiersFromDatabase {
name: string;
initialMarginPpm: string;
maintenanceFractionPpm: string;
basePositionNotional: string;
}

export interface CandleFromDatabase extends IdBasedModelFromDatabase {
Expand Down
3 changes: 0 additions & 3 deletions indexer/packages/postgres/src/types/liquidity-tiers-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ export interface LiquidityTiersCreateObject {
name: string,
initialMarginPpm: string,
maintenanceFractionPpm: string,
basePositionNotional: string,
}

export interface LiquidityTiersUpdateObject {
id: number,
name?: string,
initialMarginPpm?: string,
maintenanceFractionPpm?: string,
basePositionNotional?: string,
}

export enum LiquidityTiersColumns {
id = 'id',
name = 'name',
initialMarginPpm = 'initialMarginPpm',
maintenanceFractionPpm = 'maintenanceFractionPpm',
basePositionNotional = 'basePositionNotional',
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export interface TradingPerpetualMarketMessage {
status?: PerpetualMarketStatus;
initialMarginFraction?: string;
maintenanceMarginFraction?: string;
basePositionNotional?: string;
openInterest?: string;
quantumConversionExponent?: number;
atomicResolution?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('request-transformer', () => {
Number(liquidityTier.maintenanceFractionPpm),
),
),
basePositionNotional: liquidityTier.basePositionNotional,
openInterest: perpetualMarket.openInterest,
atomicResolution: perpetualMarket.atomicResolution,
quantumConversionExponent: perpetualMarket.quantumConversionExponent,
Expand Down
6 changes: 0 additions & 6 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -3173,7 +3171,6 @@ or
"nextFundingRate": "string",
"initialMarginFraction": "string",
"maintenanceMarginFraction": "string",
"basePositionNotional": "string",
"openInterest": "string",
"atomicResolution": 0,
"quantumConversionExponent": 0,
Expand All @@ -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|
Expand Down Expand Up @@ -3229,7 +3225,6 @@ or
"nextFundingRate": "string",
"initialMarginFraction": "string",
"maintenanceMarginFraction": "string",
"basePositionNotional": "string",
"openInterest": "string",
"atomicResolution": 0,
"quantumConversionExponent": 0,
Expand All @@ -3249,7 +3244,6 @@ or
"nextFundingRate": "string",
"initialMarginFraction": "string",
"maintenanceMarginFraction": "string",
"basePositionNotional": "string",
"openInterest": "string",
"atomicResolution": 0,
"quantumConversionExponent": 0,
Expand Down
4 changes: 0 additions & 4 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,6 @@
"maintenanceMarginFraction": {
"type": "string"
},
"basePositionNotional": {
"type": "string"
},
"openInterest": {
"type": "string"
},
Expand Down Expand Up @@ -871,7 +868,6 @@
"nextFundingRate",
"initialMarginFraction",
"maintenanceMarginFraction",
"basePositionNotional",
"openInterest",
"atomicResolution",
"quantumConversionExponent",
Expand Down
3 changes: 0 additions & 3 deletions indexer/services/comlink/public/websocket-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -883,7 +881,6 @@ interface TradingPerpetualMarketMessage {
quoteAsset?: string;
initialMarginFraction?: string;
maintenanceMarginFraction?: string;
basePositionNotional?: string;
basePositionSize?: string;
incrementalPositionSize?: string;
maxPositionSize?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ export function perpetualMarketToResponseObject(
Number(liquidityTier.maintenanceFractionPpm),
),
),
basePositionNotional: liquidityTier.basePositionNotional,
openInterest: perpetualMarket.openInterest,
atomicResolution: perpetualMarket.atomicResolution,
quantumConversionExponent: perpetualMarket.quantumConversionExponent,
Expand Down
1 change: 0 additions & 1 deletion indexer/services/comlink/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export interface PerpetualMarketResponseObject {
nextFundingRate: string;
initialMarginFraction: string;
maintenanceMarginFraction: string;
basePositionNotional: string;
openInterest: string;
atomicResolution: number;
quantumConversionExponent: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import {
LiquidityTiersFromDatabase,
LiquidityTiersTable,
Ordering,
QUOTE_CURRENCY_ATOMIC_RESOLUTION,
TendermintEventTable,
testConstants,
protocolTranslations,
liquidityTierRefresher,
PerpetualMarketFromDatabase,
perpetualMarketRefresher,
Expand Down Expand Up @@ -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(),
}));
}

Expand Down Expand Up @@ -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(),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion indexer/services/ender/src/helpers/kafka-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ export function generatePerpetualMarketMessage(
Number(liquidityTier.maintenanceFractionPpm),
),
),
basePositionNotional: liquidityTier.basePositionNotional,
};
})
.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*)
Expand All @@ -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(
Expand Down
10 changes: 0 additions & 10 deletions indexer/services/ender/src/validators/liquidity-tier-validator.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,15 +16,6 @@ export class LiquidityTierValidator extends Validator<LiquidityTierUpsertEventV1
});
}

if (this.event.basePositionNotional.eq(Long.fromValue(0))) {
logger.error({
at: `${this.constructor.name}#validate`,
message: 'LiquidityTierUpsertEventV1 basePositionNotional is not populated',
blockHeight: this.block.height,
event: this.event,
});
}

if (this.event.initialMarginPpm === 0) {
return this.logAndThrowParseMessageError(
'LiquidityTierUpsertEventV1 initialMarginPpm is not populated',
Expand Down
2 changes: 0 additions & 2 deletions indexer/services/roundtable/src/helpers/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function getMarginFields(
): {
initialMarginFraction: string,
maintenanceMarginFraction: string,
basePositionNotional: string,
} {

if (liquidityTiers[perpetualMarket.liquidityTierId] === undefined) {
Expand All @@ -45,7 +44,6 @@ export function getMarginFields(
Number(liquidityTier.maintenanceFractionPpm),
),
),
basePositionNotional: liquidityTier.basePositionNotional,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {
getAthenaTableCreationStatement,
getExternalAthenaTableCreationStatement,
castToDouble,
} from '../../helpers/sql';

const TABLE_NAME: string = 'liquidity_tiers';
const RAW_TABLE_COLUMNS: string = `
\`id\` int,
\`name\` string,
\`initialMarginPpm\` bigint,
\`maintenanceFractionPpm\` bigint,
\`basePositionNotional\` decimal
\`maintenanceFractionPpm\` bigint
`;
const TABLE_COLUMNS: string = `
"id",
"name",
"initialMarginPpm",
"maintenanceFractionPpm",
${castToDouble('basePositionNotional')}
"maintenanceFractionPpm"
`;

export function generateRawTable(tablePrefix: string, rdsExportIdentifier: string): string {
Expand Down

0 comments on commit 76068c9

Please sign in to comment.