Skip to content

Commit

Permalink
Add latest block height to /addresses API endpoint (backport #1701) (#…
Browse files Browse the repository at this point in the history
…1803)

Co-authored-by: dydxwill <[email protected]>
Co-authored-by: Will Liu <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent ce6acc8 commit 82c6315
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -293,6 +298,8 @@ describe('addresses-controller#V4', () => {
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
updatedAtHeight: testConstants.defaultSubaccount2.updatedAtHeight,
latestProcessedBlockHeight: latestHeight,
openPerpetualPositions: {},
assetPositions: {},
},
Expand All @@ -302,6 +309,8 @@ describe('addresses-controller#V4', () => {
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
updatedAtHeight: testConstants.isolatedSubaccount.updatedAtHeight,
latestProcessedBlockHeight: latestHeight,
openPerpetualPositions: {},
assetPositions: {},
},
Expand All @@ -311,6 +320,8 @@ describe('addresses-controller#V4', () => {
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
updatedAtHeight: testConstants.isolatedSubaccount2.updatedAtHeight,
latestProcessedBlockHeight: latestHeight,
openPerpetualPositions: {},
assetPositions: {},
},
Expand Down Expand Up @@ -348,6 +359,8 @@ describe('addresses-controller#V4', () => {
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
updatedAtHeight: testConstants.defaultSubaccount.updatedAtHeight,
latestProcessedBlockHeight: latestHeight,
assetPositions: {},
openPerpetualPositions: {},
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]: {
Expand All @@ -498,6 +515,8 @@ describe('addresses-controller#V4', () => {
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
updatedAtHeight: testConstants.isolatedSubaccount2.updatedAtHeight,
latestProcessedBlockHeight: latestHeight,
openPerpetualPositions: {},
assetPositions: {},
},
Expand Down Expand Up @@ -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,
});

Expand Down
26 changes: 20 additions & 6 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -251,7 +253,9 @@ fetch('https://dydx-testnet.imperator.co/v4/addresses/{address}/subaccountNumber
"subaccountNumber": 0
}
},
"marginEnabled": true
"marginEnabled": true,
"updatedAtHeight": "string",
"latestProcessedBlockHeight": "string"
}
```

Expand Down Expand Up @@ -382,7 +386,9 @@ fetch('https://dydx-testnet.imperator.co/v4/addresses/{address}/parentSubaccount
"subaccountNumber": 0
}
},
"marginEnabled": true
"marginEnabled": true,
"updatedAtHeight": "string",
"latestProcessedBlockHeight": "string"
}
]
}
Expand Down Expand Up @@ -2982,7 +2988,9 @@ This operation does not require authentication
"subaccountNumber": 0
}
},
"marginEnabled": true
"marginEnabled": true,
"updatedAtHeight": "string",
"latestProcessedBlockHeight": "string"
}

```
Expand All @@ -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

Expand Down Expand Up @@ -3068,7 +3078,9 @@ This operation does not require authentication
"subaccountNumber": 0
}
},
"marginEnabled": true
"marginEnabled": true,
"updatedAtHeight": "string",
"latestProcessedBlockHeight": "string"
}
],
"totalTradingRewards": "string"
Expand Down Expand Up @@ -3156,7 +3168,9 @@ This operation does not require authentication
"subaccountNumber": 0
}
},
"marginEnabled": true
"marginEnabled": true,
"updatedAtHeight": "string",
"latestProcessedBlockHeight": "string"
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
},
"marginEnabled": {
"type": "boolean"
},
"updatedAtHeight": {
"type": "string"
},
"latestProcessedBlockHeight": {
"type": "string"
}
},
"required": [
Expand All @@ -176,7 +182,9 @@
"freeCollateral",
"openPerpetualPositions",
"assetPositions",
"marginEnabled"
"marginEnabled",
"updatedAtHeight",
"latestProcessedBlockHeight"
],
"type": "object",
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class AddressesController extends Controller {
assets,
markets,
unsettledFunding,
latestBlock.blockHeight,
);
},
));
Expand Down Expand Up @@ -239,6 +240,7 @@ class AddressesController extends Controller {
assets,
markets,
unsettledFunding,
latestBlock.blockHeight,
);
return subaccountResponse;
}
Expand Down Expand Up @@ -322,6 +324,7 @@ class AddressesController extends Controller {
assets,
markets,
unsettledFunding,
latestBlock.blockHeight,
);
},
));
Expand Down Expand Up @@ -491,6 +494,7 @@ async function getSubaccountResponse(
assets: AssetFromDatabase[],
markets: MarketFromDatabase[],
unsettledFunding: Big,
latestBlockHeight: string,
): Promise<SubaccountResponseObject> {
const perpetualMarketsMap: PerpetualMarketsMap = perpetualMarketRefresher
.getPerpetualMarketsMap();
Expand Down Expand Up @@ -567,6 +571,7 @@ async function getSubaccountResponse(
subaccount,
equity,
freeCollateral,
latestBlockHeight,
openPerpetualPositions: perpetualPositionsMap,
assetPositions: adjustedAssetPositionsMap,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -329,6 +331,8 @@ export function subaccountToResponseObject({
assetPositions,
// TODO(DEC-687): Track `marginEnabled` for subaccounts.
marginEnabled: true,
updatedAtHeight: subaccount.updatedAtHeight,
latestProcessedBlockHeight: latestBlockHeight,
};
}

Expand Down
2 changes: 2 additions & 0 deletions indexer/services/comlink/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export interface SubaccountResponseObject {
openPerpetualPositions: PerpetualPositionsMap,
assetPositions: AssetPositionsMap,
marginEnabled: boolean,
updatedAtHeight: string,
latestProcessedBlockHeight: string,
}

export interface ParentSubaccountResponse {
Expand Down

0 comments on commit 82c6315

Please sign in to comment.