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-181] Add query function for collateral pool address. #1256

Merged

Conversation

vincentwschau
Copy link
Contributor

@vincentwschau vincentwschau commented Mar 27, 2024

Changelist

Add gRPC query to get the collateral pool address given a perpetual id.

Misc. change:

  • fix URL for GetWithdrawalAndTransfersBlockedInfo

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.

Copy link

linear bot commented Mar 27, 2024

Copy link

coderabbitai bot commented Mar 27, 2024

Walkthrough

The update introduces a new RPC method, CollateralPoolAddress, to the dydxprotocol, enabling queries for the collateral pool account address based on a perpetual ID. This enhancement is part of the Query service, accompanied by modifications to the HTTP endpoint for withdrawal and transfer block information. Additionally, the keeper package now includes functionality to retrieve the specified collateral pool addresses, supported by a comprehensive test suite ensuring reliability for various perpetual markets within the subaccounts module.

Changes

File Path Change Summary
proto/dydxprotocol/subaccounts/query.proto Added CollateralPoolAddress RPC method; Updated Query service and HTTP endpoint for withdrawal info.
protocol/x/subaccounts/keeper/grpc_query_collateral_pool.go Introduced CollateralPoolAddress function to retrieve collateral pool addresses for perpetual IDs.
protocol/x/subaccounts/keeper/grpc_query_collateral_pool_test.go Added test suite for querying collateral pool addresses in different perpetual markets.
protocol/mocks/QueryClient.go Included mock function CollateralPoolAddress for handling collateral pool addresses in testing scenarios.

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

@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 9c25211 and ccc0ef4.
Files ignored due to path filters (2)
  • protocol/x/subaccounts/types/query.pb.go is excluded by: !**/*.pb.go
  • protocol/x/subaccounts/types/query.pb.gw.go is excluded by: !**/*.pb.gw.go
Files selected for processing (3)
  • proto/dydxprotocol/subaccounts/query.proto (2 hunks)
  • protocol/x/subaccounts/keeper/grpc_query_collateral_pool.go (1 hunks)
  • protocol/x/subaccounts/keeper/grpc_query_collateral_pool_test.go (1 hunks)
Additional comments: 9
protocol/x/subaccounts/keeper/grpc_query_collateral_pool.go (6)
  • 19-20: Ensure that the error message provided for an invalid request is descriptive enough to help the caller understand what constitutes a valid request.
  • 22-22: The use of lib.UnwrapSDKContext with a module name is an interesting approach. Verify that this method correctly handles the context unwrapping and that the module name is used appropriately within this context.
  • 24-27: This segment fetches the collateral pool address using the perpetual ID. Ensure that GetCollateralPoolFromPerpetualId method efficiently handles the lookup and consider caching mechanisms if this operation is expected to be high frequency.
  • 29-37: Good error handling for a specific case where the perpetual ID does not exist. This provides clear feedback to the caller.
  • 40-40: Consider providing more detailed error information for the generic internal error case to aid in debugging. This could include logging the original error message or categorizing internal errors more granularly.
  • 43-45: Returning the collateral pool address as a string is straightforward. Verify that the .String() method of collateralPool provides the expected format and consider any potential formatting issues.
protocol/x/subaccounts/keeper/grpc_query_collateral_pool_test.go (1)
  • 16-68: The test cases cover a good range of scenarios including error conditions and successful queries. Ensure that all edge cases are covered, especially those involving invalid input formats and boundary conditions for perpetual IDs.
proto/dydxprotocol/subaccounts/query.proto (2)
  • 36-40: The RPC method CollateralPoolAddress is clearly defined with an appropriate HTTP GET path. Ensure that the path parameter perpetual_id is correctly handled in the implementation of the HTTP endpoint.
  • 81-91: The request and response message types for CollateralPoolAddress are well-defined. Verify that the perpetual_id field in the request and the collateral_pool_address field in the response are correctly used and formatted in the implementation.

Copy link

@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 ccc0ef4 and ac1d0d1.
Files selected for processing (1)
  • protocol/mocks/QueryClient.go (1 hunks)
Additional comments: 1
protocol/mocks/QueryClient.go (1)
  • 366-401: The implementation of the CollateralPoolAddress mock function is consistent with the expected patterns for gRPC query functions and the use of testify for mocking. The function signature, mock setup, return value handling, and panic condition are all correctly implemented.

Copy link

@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 ac1d0d1 and 5d9ba80.
Files ignored due to path filters (1)
  • protocol/x/subaccounts/types/query.pb.go is excluded by: !**/*.pb.go
Files selected for processing (3)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts (2 hunks)
Additional comments: 3
indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts (1)
  • 53-55: The implementation of collateralPoolAddress looks correct and follows best practices for async functions and endpoint construction. However, consider adding a comment about error handling, especially if this.req.get does not handle errors internally. This can help future maintainers understand where and how errors should be managed.
indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts (1)
  • 54-57: The implementation of collateralPoolAddress in both the interface and QueryClientImpl is correct, utilizing protobuf encoding/decoding and making an RPC request appropriately. Consider adding a comment about error handling practices, especially if errors are handled by the RPC framework or upstream, to guide future maintainers.
indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts (1)
  • 93-132: The new interfaces for the collateralPoolAddress query and their SDKType counterparts are correctly defined, and the functions for creating base requests and encoding/decoding responses are implemented appropriately. The use of protobuf for encoding and decoding is correctly applied, ensuring type safety and efficient data serialization.

@@ -29,7 +29,15 @@ service Query {
QueryGetWithdrawalAndTransfersBlockedInfoRequest)
returns (QueryGetWithdrawalAndTransfersBlockedInfoResponse) {
option (google.api.http).get =
"/dydxprotocol/subaccounts/withdrawals_and_transfers_blocked_info";
"/dydxprotocol/subaccounts/withdrawals_and_transfers_blocked_info/"
"{perpetual_id}";
Copy link
Contributor

@shrenujb shrenujb Mar 27, 2024

Choose a reason for hiding this comment

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

Is this supposed to be part of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I noticed I didn't update the URL in a previous PR so rolled it up into this one. Going to update the description.

@vincentwschau vincentwschau merged commit ddd1715 into main Mar 27, 2024
33 checks passed
@vincentwschau vincentwschau deleted the vincentc/add-query-function-collateral-pool-address branch March 27, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants