From 82c6315c1cf4876e258bf756d62d1c2c6e4631d9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:39:16 -0400 Subject: [PATCH] Add latest block height to /addresses API endpoint (backport #1701) (#1803) Co-authored-by: dydxwill <119354122+dydxwill@users.noreply.github.com> Co-authored-by: Will Liu --- .../api/v4/addresses-controller.test.ts | 23 ++++++++++++++-- .../comlink/public/api-documentation.md | 26 ++++++++++++++----- indexer/services/comlink/public/swagger.json | 10 ++++++- .../api/v4/addresses-controller.ts | 5 ++++ .../request-helpers/request-transformer.ts | 4 +++ indexer/services/comlink/src/types.ts | 2 ++ 6 files changed, 61 insertions(+), 9 deletions(-) diff --git a/indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts b/indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts index 61961fd461..9930eb80df 100644 --- a/indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts +++ b/indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts @@ -15,7 +15,6 @@ import { RequestMethod } from '../../../../src/types'; import request from 'supertest'; import { getFixedRepresentation, sendRequest } from '../../../helpers/helpers'; import { stats } from '@dydxprotocol-indexer/base'; -import { defaultAddress } from '@dydxprotocol-indexer/postgres/build/__tests__/helpers/constants'; describe('addresses-controller#V4', () => { const latestHeight: string = '3'; @@ -82,6 +81,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(159500), freeCollateral: getFixedRepresentation(152000), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: { [testConstants.defaultPerpetualMarket.ticker]: { market: testConstants.defaultPerpetualMarket.ticker, @@ -159,6 +160,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(10000), freeCollateral: getFixedRepresentation(10000), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: { [testConstants.defaultAsset.symbol]: { @@ -243,6 +246,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(159500), freeCollateral: getFixedRepresentation(152000), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: { [testConstants.defaultPerpetualMarket.ticker]: { market: testConstants.defaultPerpetualMarket.ticker, @@ -293,6 +298,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(0), freeCollateral: getFixedRepresentation(0), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount2.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: {}, }, @@ -302,6 +309,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(0), freeCollateral: getFixedRepresentation(0), marginEnabled: true, + updatedAtHeight: testConstants.isolatedSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: {}, }, @@ -311,6 +320,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(0), freeCollateral: getFixedRepresentation(0), marginEnabled: true, + updatedAtHeight: testConstants.isolatedSubaccount2.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: {}, }, @@ -348,6 +359,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(0), freeCollateral: getFixedRepresentation(0), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, assetPositions: {}, openPerpetualPositions: {}, }, @@ -431,6 +444,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(159500), freeCollateral: getFixedRepresentation(152000), marginEnabled: true, + updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: { [testConstants.defaultPerpetualMarket.ticker]: { market: testConstants.defaultPerpetualMarket.ticker, @@ -481,6 +496,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(5000), freeCollateral: getFixedRepresentation(5000), marginEnabled: true, + updatedAtHeight: testConstants.isolatedSubaccount.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: { [testConstants.defaultAsset.symbol]: { @@ -498,6 +515,8 @@ describe('addresses-controller#V4', () => { equity: getFixedRepresentation(0), freeCollateral: getFixedRepresentation(0), marginEnabled: true, + updatedAtHeight: testConstants.isolatedSubaccount2.updatedAtHeight, + latestProcessedBlockHeight: latestHeight, openPerpetualPositions: {}, assetPositions: {}, }, @@ -539,7 +558,7 @@ describe('addresses-controller#V4', () => { const parentSubaccountNumber: number = 128; const response: request.Response = await sendRequest({ type: RequestMethod.GET, - path: `/v4/addresses/${defaultAddress}/parentSubaccountNumber/${parentSubaccountNumber}`, + path: `/v4/addresses/${testConstants.defaultAddress}/parentSubaccountNumber/${parentSubaccountNumber}`, expectedStatus: 400, }); diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index 1a43561cd2..f9b455aeb9 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -123,7 +123,9 @@ fetch('https://dydx-testnet.imperator.co/v4/addresses/{address}', "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ], "totalTradingRewards": "string" @@ -251,7 +253,9 @@ fetch('https://dydx-testnet.imperator.co/v4/addresses/{address}/subaccountNumber "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ``` @@ -382,7 +386,9 @@ fetch('https://dydx-testnet.imperator.co/v4/addresses/{address}/parentSubaccount "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ] } @@ -2982,7 +2988,9 @@ This operation does not require authentication "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ``` @@ -2998,6 +3006,8 @@ This operation does not require authentication |openPerpetualPositions|[PerpetualPositionsMap](#schemaperpetualpositionsmap)|true|none|none| |assetPositions|[AssetPositionsMap](#schemaassetpositionsmap)|true|none|none| |marginEnabled|boolean|true|none|none| +|updatedAtHeight|string|true|none|none| +|latestProcessedBlockHeight|string|true|none|none| ## AddressResponse @@ -3068,7 +3078,9 @@ This operation does not require authentication "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ], "totalTradingRewards": "string" @@ -3156,7 +3168,9 @@ This operation does not require authentication "subaccountNumber": 0 } }, - "marginEnabled": true + "marginEnabled": true, + "updatedAtHeight": "string", + "latestProcessedBlockHeight": "string" } ] } diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index d857a02dfe..dd2b159ada 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -167,6 +167,12 @@ }, "marginEnabled": { "type": "boolean" + }, + "updatedAtHeight": { + "type": "string" + }, + "latestProcessedBlockHeight": { + "type": "string" } }, "required": [ @@ -176,7 +182,9 @@ "freeCollateral", "openPerpetualPositions", "assetPositions", - "marginEnabled" + "marginEnabled", + "updatedAtHeight", + "latestProcessedBlockHeight" ], "type": "object", "additionalProperties": false diff --git a/indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts b/indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts index 23ee3f280e..ed58fdebb9 100644 --- a/indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts +++ b/indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts @@ -154,6 +154,7 @@ class AddressesController extends Controller { assets, markets, unsettledFunding, + latestBlock.blockHeight, ); }, )); @@ -239,6 +240,7 @@ class AddressesController extends Controller { assets, markets, unsettledFunding, + latestBlock.blockHeight, ); return subaccountResponse; } @@ -322,6 +324,7 @@ class AddressesController extends Controller { assets, markets, unsettledFunding, + latestBlock.blockHeight, ); }, )); @@ -491,6 +494,7 @@ async function getSubaccountResponse( assets: AssetFromDatabase[], markets: MarketFromDatabase[], unsettledFunding: Big, + latestBlockHeight: string, ): Promise { const perpetualMarketsMap: PerpetualMarketsMap = perpetualMarketRefresher .getPerpetualMarketsMap(); @@ -567,6 +571,7 @@ async function getSubaccountResponse( subaccount, equity, freeCollateral, + latestBlockHeight, openPerpetualPositions: perpetualPositionsMap, assetPositions: adjustedAssetPositionsMap, }); diff --git a/indexer/services/comlink/src/request-helpers/request-transformer.ts b/indexer/services/comlink/src/request-helpers/request-transformer.ts index 16dc6ff5be..9f82fc4c86 100644 --- a/indexer/services/comlink/src/request-helpers/request-transformer.ts +++ b/indexer/services/comlink/src/request-helpers/request-transformer.ts @@ -311,12 +311,14 @@ export function subaccountToResponseObject({ subaccount, equity, freeCollateral, + latestBlockHeight, openPerpetualPositions = {}, assetPositions = {}, }: { subaccount: SubaccountFromDatabase, equity: string, freeCollateral: string, + latestBlockHeight: string, openPerpetualPositions: PerpetualPositionsMap, assetPositions: AssetPositionsMap, }): SubaccountResponseObject { @@ -329,6 +331,8 @@ export function subaccountToResponseObject({ assetPositions, // TODO(DEC-687): Track `marginEnabled` for subaccounts. marginEnabled: true, + updatedAtHeight: subaccount.updatedAtHeight, + latestProcessedBlockHeight: latestBlockHeight, }; } diff --git a/indexer/services/comlink/src/types.ts b/indexer/services/comlink/src/types.ts index 9d840f2cdc..9108d0d4fd 100644 --- a/indexer/services/comlink/src/types.ts +++ b/indexer/services/comlink/src/types.ts @@ -63,6 +63,8 @@ export interface SubaccountResponseObject { openPerpetualPositions: PerpetualPositionsMap, assetPositions: AssetPositionsMap, marginEnabled: boolean, + updatedAtHeight: string, + latestProcessedBlockHeight: string, } export interface ParentSubaccountResponse {