Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-568] Initial vault PnL endpoints. #2121

Merged
merged 10 commits into from
Aug 22, 2024

Conversation

vincentwschau
Copy link
Contributor

@vincentwschau vincentwschau commented Aug 21, 2024

Changelist

MVP of vault PnL endpoints to un-block FE testing with data.
Notes:

  • vault subaccount ids + tickers are passed in via flags until vault table is added
  • pnl ticks are aggregated with same function as parent/child subaccount pnl tick aggregation, pulled out into separate helper function

Test Plan

Unit tests.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Introduced two new API endpoints for retrieving historical profit and loss (PnL) data for megavaults and vaults.
    • Added functionality to seed a new subaccount type for testing purposes.
    • Implemented a new aggregation function for PnL ticks, streamlining the data processing.
  • Bug Fixes

    • Enhanced unit tests for API endpoints to ensure accurate responses for historical PnL data.
  • Documentation

    • Updated API documentation to include new endpoints and response structures for better clarity and usage.
  • Tests

    • Added comprehensive test cases for the VaultController and PnL aggregation functions to ensure functionality and accuracy.
  • Chores

    • Improved configuration schema to accommodate future vault-related features.

@vincentwschau vincentwschau requested a review from a team as a code owner August 21, 2024 06:21
Copy link

linear bot commented Aug 21, 2024

Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

The changes introduce new API endpoints for retrieving historical profit and loss (PnL) data for megavaults and vaults. Testing functions for these APIs are enhanced, a new helper function for aggregating PnL ticks is added, and relevant documentation and type definitions are updated to reflect these changes, thus improving the overall structure of the codebase.

Changes

Files Change Summary
indexer/packages/postgres/__tests__/helpers/mock-generators.ts
indexer/services/comlink/__tests__/controllers/api/v4/vault-controller.test.ts
indexer/services/comlink/__tests__/lib/helpers.test.ts
Updates to testing functions and data seeding for vault subaccounts and PnL ticks aggregation.
indexer/services/comlink/public/api-documentation.md
indexer/services/comlink/public/swagger.json
New API endpoints and schemas for retrieving megavault and vault PnL data.
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
indexer/services/comlink/src/lib/helpers.ts
indexer/services/comlink/src/types.ts
Introduction of aggregation logic via aggregatePnlTicks and new interfaces for vault data.
indexer/packages/postgres/__tests__/stores/pnl-ticks-table.test.ts Removal of references to vaultSubaccount from tests, signaling a shift in testing strategy.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant VaultController
    participant Database
    participant Helper

    Client->>VaultController: GET /v1/megavault/historicalPnl
    VaultController->>Database: Fetch PnL ticks
    Database-->>VaultController: Return PnL ticks
    VaultController->>Helper: aggregatePnlTicks(pnlTicks)
    Helper-->>VaultController: Return aggregated PnL data
    VaultController-->>Client: Return historical PnL response
Loading
sequenceDiagram
    participant Client
    participant VaultController
    participant Database
    participant Helper

    Client->>VaultController: GET /v1/vaults/historicalPnl
    VaultController->>Database: Fetch vault subaccount PnL ticks
    Database-->>VaultController: Return PnL ticks
    VaultController->>Helper: aggregatePnlTicks(pnlTicks)
    Helper-->>VaultController: Return aggregated PnL data
    VaultController-->>Client: Return historical PnL response
Loading

Poem

🐰 In the meadow, tall and bright,
Vaults now gleam with data’s light.
PnL ticks dance, aggregate and play,
New routes to hop, oh what a day!
With helpers swift and types so clear,
Come join the fun, the API’s here! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (4)
indexer/services/comlink/src/controllers/api/index-v4.ts (1)

23-23: Maintain alphabetical order in imports.

The import statement for VaultController should be placed in alphabetical order to maintain consistency.

+ import VaultController from './v4/vault-controller';
indexer/services/comlink/public/api-documentation.md (3)

3079-3156: Ensure correct endpoint path formatting.

The endpoint path in the code samples is correct, but ensure consistency in formatting across all documentation.

Tools
Markdownlint

3128-3128: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


5364-5365: Correct grammatical errors in schema documentation.

Use "an" instead of "a" before words starting with a vowel sound.

Use this diff to fix the grammatical errors:

- <a id="schemamegavaulthistoricalpnlresponse"></a>
+ <an id="schemamegavaulthistoricalpnlresponse"></an>
- <a id="schema_MegavaultHistoricalPnlResponse"></a>
+ <an id="schema_MegavaultHistoricalPnlResponse"></an>
Tools
LanguageTool

[misspelling] ~5364-~5364: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...emamegavaulthistoricalpnlresponse"> <a id="schema_MegavaultHistoricalPnlRespon...

(EN_A_VS_AN)


[misspelling] ~5365-~5365: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ma_MegavaultHistoricalPnlResponse"> <a id="tocSmegavaulthistoricalpnlresponse"...

(EN_A_VS_AN)


5428-5429: Correct grammatical errors in schema documentation.

Use "an" instead of "a" before words starting with a vowel sound.

Use this diff to fix the grammatical errors:

- <a id="schemavaultshistoricalpnlresponse"></a>
+ <an id="schemavaultshistoricalpnlresponse"></an>
- <a id="schema_VaultsHistoricalPnlResponse"></a>
+ <an id="schema_VaultsHistoricalPnlResponse"></an>
Tools
LanguageTool

[misspelling] ~5428-~5428: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...schemavaultshistoricalpnlresponse"> <a id="schema_VaultsHistoricalPnlResponse"...

(EN_A_VS_AN)


[misspelling] ~5429-~5429: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...chema_VaultsHistoricalPnlResponse"> </...

(EN_A_VS_AN)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 909fc3a and 2fe104c.

Files selected for processing (11)
  • indexer/packages/postgres/tests/helpers/mock-generators.ts (2 hunks)
  • indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts (1 hunks)
  • indexer/services/comlink/tests/lib/helpers.test.ts (4 hunks)
  • indexer/services/comlink/public/api-documentation.md (2 hunks)
  • indexer/services/comlink/public/swagger.json (2 hunks)
  • indexer/services/comlink/src/config.ts (1 hunks)
  • indexer/services/comlink/src/controllers/api/index-v4.ts (2 hunks)
  • indexer/services/comlink/src/controllers/api/v4/historical-pnl-controller.ts (2 hunks)
  • indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (1 hunks)
  • indexer/services/comlink/src/lib/helpers.ts (3 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
Additional context used
Markdownlint
indexer/services/comlink/public/api-documentation.md

3128-3128: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


3207-3207: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

LanguageTool
indexer/services/comlink/public/api-documentation.md

[misspelling] ~5364-~5364: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...emamegavaulthistoricalpnlresponse"> <a id="schema_MegavaultHistoricalPnlRespon...

(EN_A_VS_AN)


[misspelling] ~5365-~5365: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ma_MegavaultHistoricalPnlResponse"> <a id="tocSmegavaulthistoricalpnlresponse"...

(EN_A_VS_AN)


[misspelling] ~5395-~5395: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ... <a ...

(EN_A_VS_AN)


[misspelling] ~5396-~5396: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ... <a id=...

(EN_A_VS_AN)


[misspelling] ~5428-~5428: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...schemavaultshistoricalpnlresponse"> <a id="schema_VaultsHistoricalPnlResponse"...

(EN_A_VS_AN)


[misspelling] ~5429-~5429: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...chema_VaultsHistoricalPnlResponse"> </...

(EN_A_VS_AN)

Additional comments not posted (27)
indexer/services/comlink/src/controllers/api/index-v4.ts (1)

48-48: LGTM!

The addition of the /vault route is consistent with the existing routing structure.

indexer/packages/postgres/__tests__/helpers/mock-generators.ts (1)

45-45: LGTM!

The addition of vaultSubaccount to the seedData function enhances testing capabilities for vault-related scenarios.

indexer/services/comlink/src/config.ts (1)

61-62: LGTM!

The addition of EXPERIMENT_VAULTS and EXPERIMENT_VAULT_MARKETS provides a foundation for future vault-related configurations.

indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (4)

28-32: Clarify placeholder logic.

The VaultMapping interface and related TODO comments indicate placeholder logic. Ensure these are updated once the vault table is implemented.


81-133: LGTM!

The router setup for the new endpoints is consistent with existing patterns and includes rate limiting and error handling.


135-153: Consider pagination or limits.

The getVaultSubaccountPnlTicks function retrieves PnL ticks without explicit pagination or limits. Ensure this aligns with performance and data retrieval requirements.


155-166: Clarify placeholder logic.

The getVaultSubaccountsFromConfig function includes placeholder logic. Ensure these are updated once the vault table is implemented.

indexer/services/comlink/src/controllers/api/v4/historical-pnl-controller.ts (1)

22-22: LGTM!

The use of aggregatePnlTicks improves code modularity and readability, aligning with best practices.

indexer/services/comlink/__tests__/controllers/api/v4/vault-controller.test.ts (6)

21-23: Ensure database migration is necessary.

The beforeAll hook migrates the database. Confirm that this is necessary for the tests to run correctly, as it might slow down the test suite.


25-27: Ensure proper teardown of database resources.

The afterAll hook tears down the database. Verify that this is necessary and that it doesn't affect other tests running in parallel.


48-93: Test coverage for single vault subaccount is comprehensive.

The test for /megavault/historicalPnl with a single vault subaccount is well-structured and covers expected responses.


95-139: Test coverage for multiple vault subaccounts is comprehensive.

The test for /megavault/historicalPnl with two vault subaccounts is well-structured and covers expected responses.


141-189: Test coverage for single vault subaccount in /vaults/historicalPnl is comprehensive.

The test is well-structured and covers expected responses.


191-251: Test coverage for multiple vault subaccounts in /vaults/historicalPnl is comprehensive.

The test is well-structured and covers expected responses.

indexer/services/comlink/src/types.ts (5)

646-649: Ensure PnlTicksResponseObject is defined correctly.

The VaultHistoricalPnl interface relies on PnlTicksResponseObject. Verify that this type is defined correctly and used consistently.


651-653: Ensure consistency in MegavaultHistoricalPnlResponse.

The megavaultsPnl field should consistently use the PnlTicksResponseObject type. Verify its correct usage across the codebase.


655-657: Ensure consistency in VaultsHistoricalPnlResponse.

The vaultsPnl field should consistently use the VaultHistoricalPnl type. Verify its correct usage across the codebase.


659-664: Ensure optional fields in VaultPosition are handled correctly.

The perpetualPosition field is optional. Ensure that the code handles cases where this field might be undefined.


666-668: Ensure MegavaultPositionResponse aligns with expected data structures.

The positions field should use the VaultPosition type. Verify its correct usage across the codebase.

indexer/services/comlink/src/lib/helpers.ts (1)

547-569: Ensure efficiency of aggregatePnlTicks function.

The function aggregates PnL ticks by block height. Ensure that the logic is correct and that it handles large datasets efficiently.

indexer/services/comlink/__tests__/lib/helpers.test.ts (2)

728-742: Test coverage for single PnL tick aggregation is comprehensive.

The test accurately reflects the expected behavior of the aggregatePnlTicks function with a single PnL tick.


744-792: Test coverage for multiple PnL ticks with the same height is comprehensive.

The test accurately reflects the expected behavior of the aggregatePnlTicks function with multiple PnL ticks sharing the same block height.

indexer/services/comlink/public/swagger.json (5)

1363-1377: Ensure MegavaultHistoricalPnlResponse schema is comprehensive.

The schema should accurately represent the expected response structure for megavault historical PnL data.


1378-1396: Ensure VaultHistoricalPnl schema is comprehensive.

The schema should accurately represent the expected structure for vault historical PnL data.


1397-1410: Ensure VaultsHistoricalPnlResponse schema is comprehensive.

The schema should accurately represent the expected response structure for vaults historical PnL data.


3058-3075: Ensure GET /vault/v1/megavault/historicalPnl endpoint is documented correctly.

The endpoint should accurately reflect the expected request and response structure.


3077-3094: Ensure GET /vault/v1/v1/vaults/historicalPnl endpoint is documented correctly.

The endpoint should accurately reflect the expected request and response structure.

Comment on lines 34 to 79
@Route('vault/v1')
class VaultController extends Controller {
@Get('/megavault/historicalPnl')
async getMegavaultHistoricalPnl(): Promise<MegavaultHistoricalPnlResponse> {
const vaultPnlTicks: PnlTicksFromDatabase[] = await getVaultSubaccountPnlTicks();

// aggregate pnlTicks for all vault subaccounts grouped by blockHeight
const aggregatedPnlTicks: Map<number, PnlTicksFromDatabase> = aggregatePnlTicks(vaultPnlTicks);

return {
megavaultsPnl: Array.from(aggregatedPnlTicks.values()).map(
(pnlTick: PnlTicksFromDatabase) => {
return pnlTicksToResponseObject(pnlTick);
}),
};
}

@Get('/v1/vaults/historicalPnl')
async getVaultsHistoricalPnl(): Promise<VaultsHistoricalPnlResponse> {
const vaultSubaccounts: VaultMapping = getVaultSubaccountsFromConfig();
const vaultPnlTicks: PnlTicksFromDatabase[] = await getVaultSubaccountPnlTicks();

const groupedVaultPnlTicks: VaultHistoricalPnl[] = _(vaultPnlTicks)
.groupBy('subaccountId')
.mapValues((pnlTicks: PnlTicksFromDatabase[], subaccountId: string): VaultHistoricalPnl => {
const market: PerpetualMarketFromDatabase | undefined = perpetualMarketRefresher
.getPerpetualMarketFromClobPairId(
vaultSubaccounts[subaccountId],
);

if (market === undefined) {
throw new Error(`Vault clob pair id ${vaultSubaccounts[subaccountId]} does not correspond to a perpetual market.`)
}

return {
ticker: market.ticker,
historicalPnl: pnlTicks,
}})
.values()
.value();

return {
vaultsPnl: groupedVaultPnlTicks,
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling and logging.

The getVaultsHistoricalPnl method throws an error if a market is undefined. Consider logging this error for better traceability.

+ console.error(`Error: Vault clob pair id ${vaultSubaccounts[subaccountId]} does not correspond to a perpetual market.`);

Committable suggestion was skipped due to low confidence.

Comment on lines 3158 to 3240
## GetVaultsHistoricalPnl

<a id="opIdGetVaultsHistoricalPnl"></a>

> Code samples

```python
import requests
headers = {
'Accept': 'application/json'
}

# For the deployment by DYDX token holders, use
# baseURL = 'https://indexer.dydx.trade/v4'
baseURL = 'https://dydx-testnet.imperator.co/v4'

r = requests.get(f'{baseURL}/vault/v1/v1/vaults/historicalPnl', headers = headers)

print(r.json())

```

```javascript

const headers = {
'Accept':'application/json'
};

// For the deployment by DYDX token holders, use
// const baseURL = 'https://indexer.dydx.trade/v4';
const baseURL = 'https://dydx-testnet.imperator.co/v4';

fetch(`${baseURL}/vault/v1/v1/vaults/historicalPnl`,
{
method: 'GET',

headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});

```

`GET /vault/v1/v1/vaults/historicalPnl`

> Example responses

> 200 Response

```json
{
"vaultsPnl": [
{
"ticker": "string",
"historicalPnl": [
{
"id": "string",
"subaccountId": "string",
"equity": "string",
"totalPnl": "string",
"netTransfers": "string",
"createdAt": "string",
"blockHeight": "string",
"blockTime": "string"
}
]
}
]
}
```

### Responses

|Status|Meaning|Description|Schema|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Ok|[VaultsHistoricalPnlResponse](#schemavaultshistoricalpnlresponse)|

<aside class="success">
This operation does not require authentication
</aside>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix duplicate path segment in endpoint URL.

The endpoint URL contains a duplicate "v1" segment. Correct the URL in the documentation and code samples.

Use this diff to fix the endpoint URL:

- r = requests.get(f'{baseURL}/vault/v1/v1/vaults/historicalPnl', headers = headers)
+ r = requests.get(f'{baseURL}/vault/v1/vaults/historicalPnl', headers = headers)
- fetch(`${baseURL}/vault/v1/v1/vaults/historicalPnl`,
+ fetch(`${baseURL}/vault/v1/vaults/historicalPnl`,
Tools
Markdownlint

3207-3207: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

return res.send(response);
} catch (error) {
return handleControllerError(
'VaulController GET /megavault/historicalPnl',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
'VaulController GET /megavault/historicalPnl',
'VaultController GET /megavault/historicalPnl',

try {
const controllers: VaultController = new VaultController();
const response: MegavaultHistoricalPnlResponse = await controllers.getMegavaultHistoricalPnl();
return res.send(response);
Copy link
Contributor

@tqin7 tqin7 Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra indentation here and below?

}
}
return aggregatedPnlTicks;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line needed

totalPnl: (parseFloat(currentPnlTick.totalPnl) + parseFloat(pnlTick.totalPnl)).toString(),
netTransfers: (parseFloat(currentPnlTick.netTransfers) +
parseFloat(pnlTick.netTransfers)).toString(),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in extreme scenarios, these summations might overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The largest float possible is in the order of 1e308, so it's impossible given that these are human read-able dollar amounts.
The largest float possible without loss of precision (with 2 decimal places) I think is ~1e16, which is still near impossible with human-readable dollar amounts.

}

export interface MegavaultHistoricalPnlResponse {
megavaultsPnl: PnlTicksResponseObject[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
megavaultsPnl: PnlTicksResponseObject[];
megavaultPnl: PnlTicksResponseObject[];

};
}

@Get('/v1/vaults/historicalPnl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full url would be
vault/v1/vaults/historicalPnl
Seems a bit redundant?

Also, are we now trying to add versioning to our indexer APIs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually do you even need to put the "v1" here since its already on the route above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment, I put a v1 since this is an MVP and there's corners being cut that we may want to rectify in the future and seemed better to have versioning already added rather than add it in later.
As for vault vs vaults, agree it looks redundant, but vault is the top-level while vaults indicates these are not the megavault specific data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are we now trying to add versioning to our indexer APIs?

Experimenting here since there might need to be a new version of this API for other vault data, and there's more strict type checking on FE/mobile on both protocol and indexer responses and a need for backwards compatability.

[subaccountId: string]: string;
}

@Route('vault/v1')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have 'v1' both here (route) and on the specific API. Could you remove one or the other?

Copy link
Contributor Author

@vincentwschau vincentwschau Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't, this is an annotation for the swagger / doc generation, the other is the actual path being registered with express.

EDIT: Nevermind, misread this, I did add an additional v1 to the path.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2fe104c and 100666a.

Files selected for processing (8)
  • indexer/packages/postgres/tests/stores/pnl-ticks-table.test.ts (2 hunks)
  • indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts (1 hunks)
  • indexer/services/comlink/tests/lib/helpers.test.ts (3 hunks)
  • indexer/services/comlink/public/api-documentation.md (2 hunks)
  • indexer/services/comlink/public/swagger.json (2 hunks)
  • indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (1 hunks)
  • indexer/services/comlink/src/lib/helpers.ts (3 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/packages/postgres/tests/stores/pnl-ticks-table.test.ts
Files skipped from review as they are similar to previous changes (6)
  • indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts
  • indexer/services/comlink/tests/lib/helpers.test.ts
  • indexer/services/comlink/public/swagger.json
  • indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
  • indexer/services/comlink/src/lib/helpers.ts
  • indexer/services/comlink/src/types.ts
Additional context used
Markdownlint
indexer/services/comlink/public/api-documentation.md

3128-3128: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


3207-3207: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

LanguageTool
indexer/services/comlink/public/api-documentation.md

[misspelling] ~5364-~5364: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...emamegavaulthistoricalpnlresponse"> <a id="schema_MegavaultHistoricalPnlRespon...

(EN_A_VS_AN)


[misspelling] ~5365-~5365: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ma_MegavaultHistoricalPnlResponse"> <a id="tocSmegavaulthistoricalpnlresponse"...

(EN_A_VS_AN)


[misspelling] ~5395-~5395: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ... <a ...

(EN_A_VS_AN)


[misspelling] ~5396-~5396: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ... <a id=...

(EN_A_VS_AN)


[misspelling] ~5428-~5428: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...schemavaultshistoricalpnlresponse"> <a id="schema_VaultsHistoricalPnlResponse"...

(EN_A_VS_AN)


[misspelling] ~5429-~5429: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...chema_VaultsHistoricalPnlResponse"> </...

(EN_A_VS_AN)

Additional comments not posted (4)
indexer/services/comlink/public/api-documentation.md (4)

3095-3111: Fix duplicate path segment in endpoint URL.

The endpoint URL contains a duplicate "v1" segment. Correct the URL in the documentation and code samples.

Use this diff to fix the endpoint URL:

- r = requests.get(f'{baseURL}/vault/v1/v1/vaults/historicalPnl', headers = headers)
+ r = requests.get(f'{baseURL}/vault/v1/vaults/historicalPnl', headers = headers)
- fetch(`${baseURL}/vault/v1/v1/vaults/historicalPnl`,
+ fetch(`${baseURL}/vault/v1/vaults/historicalPnl`,

Also applies to: 3174-3190


3158-3240: LGTM! Endpoint documentation is complete.

The documentation for the GetVaultsHistoricalPnl endpoint is well-structured and provides clear examples.

Tools
Markdownlint

3207-3207: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


5364-5365: Correct grammatical errors in schema documentation.

Use "an" instead of "a" before words starting with a vowel sound.

[misspelling]
Apply this diff to correct the grammar:

- <a id="schemamegavaulthistoricalpnlresponse"></a>
+ <an id="schemamegavaulthistoricalpnlresponse"></an>
- <a id="schema_MegavaultHistoricalPnlResponse"></a>
+ <an id="schema_MegavaultHistoricalPnlResponse"></an>
Tools
LanguageTool

[misspelling] ~5364-~5364: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...emamegavaulthistoricalpnlresponse"> <a id="schema_MegavaultHistoricalPnlRespon...

(EN_A_VS_AN)


[misspelling] ~5365-~5365: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ma_MegavaultHistoricalPnlResponse"> <a id="tocSmegavaulthistoricalpnlresponse"...

(EN_A_VS_AN)


5428-5429: Correct grammatical errors in schema documentation.

Use "an" instead of "a" before words starting with a vowel sound.

[misspelling]
Apply this diff to correct the grammar:

- <a id="schemavaultshistoricalpnlresponse"></a>
+ <an id="schemavaultshistoricalpnlresponse"></an>
- <a id="schema_VaultsHistoricalPnlResponse"></a>
+ <an id="schema_VaultsHistoricalPnlResponse"></an>
Tools
LanguageTool

[misspelling] ~5428-~5428: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...schemavaultshistoricalpnlresponse"> <a id="schema_VaultsHistoricalPnlResponse"...

(EN_A_VS_AN)


[misspelling] ~5429-~5429: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...chema_VaultsHistoricalPnlResponse"> </...

(EN_A_VS_AN)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 100666a and b9336d9.

Files selected for processing (1)
  • indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b9336d9 and 168bf23.

Files selected for processing (1)
  • indexer/packages/postgres/tests/stores/pnl-ticks-table.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/packages/postgres/tests/stores/pnl-ticks-table.test.ts

@vincentwschau vincentwschau merged commit 70a7ebd into main Aug 22, 2024
15 checks passed
@vincentwschau vincentwschau deleted the vincentc/tra-568-megavault-pnl branch August 22, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants