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-380] use serializable int for equity and inventory in vault query #1688

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Jun 12, 2024

Changelist

use serializable int for equity and inventory in vault query as equity and inventory can be negative

Test Plan

  • unit testing
  • localnet testing

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

  • Refactor

    • Updated internal handling of equity and inventory fields to improve performance and reliability.
  • Tests

    • Enhanced test cases to support new data types and scenarios involving negative values for equity and inventory.

These changes ensure more efficient data processing and robustness in various financial computations.

Copy link

linear bot commented Jun 12, 2024

TRA-380 fix vault query

Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

The recent changes involve updating the types of equity and inventory fields from Long to Uint8Array in the QueryVaultResponse and QueryVaultResponseSDKType interfaces within the dydxprotocol/vault package. This transition impacts the initialization, serialization, deserialization, and object creation processes. Additionally, corresponding changes were made in the proto files and Go code to handle these new types appropriately.

Changes

File Path Change Summary
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts Switched equity and inventory fields from Long to Uint8Array in interfaces and updated related functions.
proto/dydxprotocol/vault/query.proto Changed equity and inventory fields from uint64 to bytes with custom types in QueryVaultResponse message.
protocol/x/vault/keeper/grpc_query_vault.go Updated handling of Equity and Inventory values to use dtypes.NewIntFromBigInt instead of Uint64.
protocol/x/vault/keeper/grpc_query_vault_test.go Modified expectedEquity type to *big.Int and adjusted test cases to handle negative values using big.Int.

Poem

In the vault where numbers dance,
Equity and inventory took a chance,
From Long to Uint8Array they did sway,
Bytes now lead the data way.
With BigInt they now align,
A smoother flow, a code refined.
Cheers to change, a future bright,
Code evolves in the digital light! 🌟🐇


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 Configration 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: 0

Outside diff range and nitpick comments (1)
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (1)

Line range hint 9-9: The use of empty interfaces has been flagged by the static analysis tool. Consider using a type alias for better clarity and maintainability.

type QueryParamsRequest = {};
type QueryParamsRequestSDKType = {};

Also applies to: 12-12

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2446abf and def44d8.

Files ignored due to path filters (1)
  • protocol/x/vault/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (5 hunks)
  • proto/dydxprotocol/vault/query.proto (1 hunks)
  • protocol/x/vault/keeper/grpc_query_vault.go (2 hunks)
  • protocol/x/vault/keeper/grpc_query_vault_test.go (3 hunks)
Additional context used
golangci-lint
protocol/x/vault/keeper/grpc_query_vault.go

18-18: undefined: Keeper (typecheck)


61-61: undefined: Keeper (typecheck)

Biome
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts

[error] 9-9: An empty interface is equivalent to {}. (lint/suspicious/noEmptyInterface)

Safe fix: Use a type alias instead.


[error] 12-12: An empty interface is equivalent to {}. (lint/suspicious/noEmptyInterface)

Safe fix: Use a type alias instead.

Additional comments not posted (7)
protocol/x/vault/keeper/grpc_query_vault.go (3)

12-12: The import of dtypes is necessary for handling the new data types for equity and inventory. Ensure that this package is correctly versioned and maintained to avoid future compatibility issues.


55-56: The conversion of equity and inventory to use dtypes.NewIntFromBigInt aligns with the new data type requirements. This change ensures that negative values are correctly handled, which is crucial for financial calculations.


Line range hint 18-18: The static analysis tool has flagged an undefined Keeper type. This might be a false positive if Keeper is defined elsewhere in the project that wasn't included in the review materials. Please verify the definition of Keeper.

Also applies to: 61-61

proto/dydxprotocol/vault/query.proto (1)

54-63: The update to use bytes type with a custom serialization type SerializableInt for equity and inventory fields is a significant change. This ensures that these fields can handle large numbers and negative values more robustly than the previous uint64 type.

protocol/x/vault/keeper/grpc_query_vault_test.go (2)

Line range hint 34-59: The test cases have been updated to handle the new data types for equity and inventory. It's good to see both positive and negative scenarios being tested, which is crucial for financial applications to ensure robustness.


128-129: The use of dtypes.NewIntFromBigInt in the test assertions is consistent with the changes in the main implementation. This consistency is key to ensuring that the tests accurately reflect the behavior of the production code.

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (1)

40-41: The update to use Uint8Array for equity and inventory in TypeScript interfaces aligns with the changes in other parts of the system. This ensures type consistency across the stack, which is crucial for data integrity and error prevention.
[APROVED]

Also applies to: 49-50

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

Outside diff range and nitpick comments (2)
protocol/x/vault/keeper/grpc_query_vault.go (1)

Line range hint 18-18: The static analysis tool has flagged an issue with the Keeper type being undefined. Please ensure that the Keeper type is correctly defined and accessible within this context.

Also applies to: 61-61

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (1)

Line range hint 9-9: The interfaces QueryParamsRequest and QueryParamsRequestSDKType are defined as empty, which is equivalent to {}. Consider using a type alias for clarity and to address the linting issue.

type QueryParamsRequest = {};
type QueryParamsRequestSDKType = {};

Also applies to: 12-12

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between def44d8 and f47b930.

Files ignored due to path filters (1)
  • protocol/x/vault/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (5 hunks)
  • proto/dydxprotocol/vault/query.proto (1 hunks)
  • protocol/x/vault/keeper/grpc_query_vault.go (2 hunks)
  • protocol/x/vault/keeper/grpc_query_vault_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • proto/dydxprotocol/vault/query.proto
  • protocol/x/vault/keeper/grpc_query_vault_test.go
Additional context used
golangci-lint
protocol/x/vault/keeper/grpc_query_vault.go

18-18: undefined: Keeper (typecheck)


61-61: undefined: Keeper (typecheck)

Biome
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts

[error] 9-9: An empty interface is equivalent to {}. (lint/suspicious/noEmptyInterface)

Safe fix: Use a type alias instead.


[error] 12-12: An empty interface is equivalent to {}. (lint/suspicious/noEmptyInterface)

Safe fix: Use a type alias instead.

Additional comments not posted (5)
protocol/x/vault/keeper/grpc_query_vault.go (2)

12-12: Ensure the dtypes package is correctly imported and used, as it's crucial for handling the new data types.


55-56: The conversion of equity and inventory using dtypes.NewIntFromBigInt aligns with the PR's goal to handle potentially negative values correctly.

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (3)

40-41: The update of equity and inventory fields from Long to Uint8Array in both QueryVaultResponse and QueryVaultResponseSDKType interfaces is correctly implemented to handle the new data types.

Also applies to: 49-50


252-253: The initialization of equity and inventory as new Uint8Array() in the createBaseQueryVaultResponse and fromPartial functions correctly reflects the changes in the data type.

Also applies to: 325-326


268-273: The encoding and decoding logic for equity and inventory fields has been updated to handle Uint8Array, ensuring correct serialization and deserialization.

Also applies to: 301-305

@tqin7 tqin7 merged commit 43c96ea into main Jun 13, 2024
33 of 34 checks passed
@tqin7 tqin7 deleted the tq/tra-380 branch June 13, 2024 04:08
@tqin7
Copy link
Contributor Author

tqin7 commented Jun 13, 2024

@Mergifyio backport release/protocol/v5.x

Copy link
Contributor

mergify bot commented Jun 13, 2024

backport release/protocol/v5.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants