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-102] add subaccountNumber field in assetPositions return result #1187

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Mar 16, 2024

Changelist

Add subAccountNumber as a field on AssetPositionResponseObject

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.

Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
Copy link

linear bot commented Mar 16, 2024

Copy link
Contributor

coderabbitai bot commented Mar 16, 2024

Walkthrough

The recent updates introduce the subaccountNumber field across various components of the system, including tests, API documentation, and source code. This addition appears to standardize and integrate the handling of subaccount numbers within asset positions, enhancing the data structure and API responses to accommodate this new field. The changes span from updating test suites and validation schemas to modifying controllers and helper functions, ensuring comprehensive support for subaccountNumber throughout the system.

Changes

File(s) Change Summary
indexer/services/comlink/public/api-documentation.md Added subaccountNumber field with default value to data structures and API endpoints.
indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts Renamed AddressesController to AssetPositionsController. Updated routes and method parameters for subaccountNumber. Adjusted instantiation of the controller.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 00cd3d5 and 98ab835.
Files ignored due to path filters (1)
  • indexer/services/comlink/public/swagger.json is excluded by: !**/*.json
Files selected for processing (9)
  • indexer/services/comlink/tests/controllers/api/v4/asset-positions-controller.test.ts (4 hunks)
  • indexer/services/comlink/tests/lib/helpers.test.ts (4 hunks)
  • indexer/services/comlink/tests/lib/validation/schemas.test.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (12 hunks)
  • indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts (1 hunks)
  • indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts (4 hunks)
  • indexer/services/comlink/src/lib/constants.ts (1 hunks)
  • indexer/services/comlink/src/request-helpers/request-transformer.ts (1 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
Additional comments: 13
indexer/services/comlink/src/lib/constants.ts (1)
  • 16-16: The addition of subaccountNumber: 0 to the ZERO_USDC_POSITION constant aligns with the PR's objectives. Ensure that the default value 0 is consistent with the system's handling of subaccount numbers.
indexer/services/comlink/__tests__/lib/validation/schemas.test.ts (1)
  • 13-13: The addition of stringNumber with type any is noted. Consider adding a comment or documentation explaining its use in tests for clarity.
indexer/services/comlink/__tests__/controllers/api/v4/asset-positions-controller.test.ts (4)
  • 49-49: The addition of subaccountNumber to the test cases ensures thorough testing of the new functionality. Well done on covering this aspect.
  • 79-79: The inclusion of subaccountNumber in test cases is appropriate for verifying the new functionality. Good job on ensuring comprehensive test coverage.
  • 115-115: Including subaccountNumber in test cases is crucial for testing the new feature comprehensively. This is a good practice.
  • 160-160: The addition of subaccountNumber in test cases demonstrates attention to detail in testing the new feature. This is commendable.
indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts (1)
  • 55-56: Renaming the controller to AssetPositionsController and updating the @Get decorator to include :subaccountNumber are appropriate changes that align with the PR's objectives.
indexer/services/comlink/src/types.ts (1)
  • 108-108: Adding subaccountNumber to the AssetPositionResponseObject interface is a necessary update to support the new functionality. This ensures consistency in type definitions across the application.
indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts (1)
  • 381-381: The addition of subaccount.subaccountNumber to the assetPositionToResponseObject function call is appropriate and ensures the new functionality is correctly integrated.
indexer/services/comlink/src/request-helpers/request-transformer.ts (1)
  • 118-126: The addition of the subaccountNumber parameter to the assetPositionToResponseObject function is correctly implemented. It enhances the function's capability to include subaccount information in the response object, aligning with the PR's objectives. The change is straightforward, maintains code quality, and follows best practices.
indexer/services/comlink/__tests__/lib/helpers.test.ts (1)
  • 395-395: The addition of the subaccountNumber: 0 field to various objects within the test cases is correctly implemented. These updates ensure that the test suite accurately reflects the system's changes, maintaining the quality and relevance of the tests. The changes are straightforward, maintain code quality, and follow best practices.

Also applies to: 462-462, 518-518, 575-575

indexer/services/comlink/public/api-documentation.md (2)
  • 113-114: The addition of the subaccountNumber field to the asset positions in various API responses is consistent and correctly implemented across the document. This change enhances the API's functionality by allowing users to associate asset positions with specific subaccount numbers, improving data granularity and user experience.

Also applies to: 120-121, 239-240, 246-247, 324-325

  • 276-276: The inclusion of subaccountNumber in the API endpoint examples for GetAssetPositions is correctly done, ensuring that users are aware of how to use this new field in their requests. This change is crucial for maintaining the API's usability and ensuring that the documentation stays up-to-date with the codebase.

Also applies to: 290-290, 304-304

Comment on lines +164 to +171
// The schema checks allow subaccountNumber to be a string, but we know it's a number here.
const subaccountNum : number = +subaccountNumber;

try {
const controller: AddressesController = new AddressesController();
const controller: AssetPositionsController = new AssetPositionsController();
const response: AssetPositionResponse = await controller.getAssetPositions(
address,
subaccountNumber,
subaccountNum,
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The script output indicates that subaccountNumber is directly converted to a number without explicit error handling or range checking in the provided code snippets. This could potentially lead to issues if subaccountNumber is not a valid number. Therefore, the review comment highlighting the need for proper error handling and range checking for subaccountNumber is justified based on the available evidence.

Analysis chain

The handling of subaccountNumber as a number, including its parsing and usage in getAssetPositions, is crucial for the new functionality. Ensure that there's proper error handling for parsing and that subaccountNumber falls within expected ranges or values.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that subaccountNumber parsing handles errors and checks for valid ranges
grep -r "parseNumber" src/controllers/api/v4/asset-positions-controller.ts | grep -v "//"

Length of output: 173



Script:

#!/bin/bash
# Find the correct path for asset-positions-controller.ts
fd asset-positions-controller.ts

Length of output: 112



Script:

#!/bin/bash
# Inspect handling of subaccountNumber in asset-positions-controller.ts for error handling and range checking
grep -C 3 "subaccountNumber" indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts

Length of output: 1200

Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 98ab835 and 6ecc564.
Files selected for processing (3)
  • indexer/services/comlink/tests/controllers/api/v4/addresses-controller.test.ts (3 hunks)
  • indexer/services/comlink/tests/lib/helpers.test.ts (12 hunks)
  • indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • indexer/services/comlink/tests/lib/helpers.test.ts
  • indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts
Additional comments: 5
indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts (5)
  • 116-116: The addition of subaccountNumber to the asset position object in the test case is consistent with the PR objectives to include this new field in the asset positions functionality. This change ensures that the test suite accurately reflects the updated system behavior.
  • 123-123: Similar to the previous comment, the inclusion of subaccountNumber here aligns with the PR's goal to integrate this field into the asset positions. It's good to see that the test cases are being updated to cover this new field, ensuring comprehensive testing.
  • 167-167: Again, the addition of subaccountNumber in this test case is appropriate and follows the PR's objectives. It's crucial for the test suite to validate the presence and correct handling of the subaccountNumber field in all relevant scenarios.
  • 276-276: The consistent update of test cases to include the subaccountNumber field is commendable. This ensures that the new functionality is thoroughly tested across different scenarios, which is essential for maintaining the reliability of the system.
  • 283-283: The inclusion of subaccountNumber in this part of the test suite further demonstrates a thorough approach to testing the new field's integration. It's important to cover as many scenarios as possible to ensure the system behaves as expected with the addition of new fields.

Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6ecc564 and e04918b.
Files ignored due to path filters (1)
  • indexer/services/comlink/public/swagger.json is excluded by: !**/*.json
Files selected for processing (2)
  • indexer/services/comlink/public/api-documentation.md (9 hunks)
  • indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts
Additional comments: 5
indexer/services/comlink/public/api-documentation.md (5)
  • 113-114: The addition of the subaccountNumber field in the assetPositions object is clear and consistent with the PR's objectives. However, ensure that the default value of 0 for subaccountNumber is intended and correctly implemented in the backend logic.
  • 120-121: Similar to the previous comment, the consistent addition of subaccountNumber here is noted. It's crucial to verify that all instances where assetPositions are returned or processed have been updated to include this new field.
  • 239-240: The inclusion of subaccountNumber in the GET /addresses/{address}/subaccountNumber/{subaccountNumber} endpoint's response is appropriate. This ensures that the API's response structure is updated to reflect the new field across relevant endpoints.
  • 246-247: Again, the addition is consistent across different properties within the assetPositions object. This consistency is key to ensuring that the API's contract is clear and predictable for consumers.
  • 324-325: The inclusion of subaccountNumber in the GET /assetPositions endpoint's response is noted. This change aligns with the PR's objectives to enhance the asset positions functionality with subaccount tracking.

@shrenujb shrenujb merged commit f6afd11 into main Mar 19, 2024
11 checks passed
@shrenujb shrenujb deleted the tra102 branch March 19, 2024 03:48
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.

2 participants