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-572] Add upsert vault event. #2250

Merged
merged 7 commits into from
Sep 16, 2024

Conversation

vincentwschau
Copy link
Contributor

@vincentwschau vincentwschau commented Sep 12, 2024

Changelist

Add upsert vault event.

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

    • Enhanced the dydxprotocol namespace with the addition of the vault module, improving functionality related to vault operations.
    • Updated export structures to include new modules, enhancing modularity and overall protocol functionality.
  • Bug Fixes

    • Adjusted import statements in various modules to streamline dependencies and improve organization.

@vincentwschau vincentwschau requested a review from a team as a code owner September 12, 2024 21:38
Copy link

linear bot commented Sep 12, 2024

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve a significant restructuring of the dydxprotocol namespace in the bundle.ts file, including the addition of a new vault module and updates to various export structures. Import statements have been reorganized, and several components have been modified to enhance the protocol's modularity and functionality. Additionally, changes in the gogoproto and google namespaces reflect updates in import sources and the organization of exported modules.

Changes

Files Change Summary
indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts Restructured dydxprotocol namespace, added vault module, and updated various export structures.
indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts Changed import alias from _126 to _127, no changes to the exported structure.
indexer/packages/v4-protos/src/codegen/google/bundle.ts Removed import from ./api/annotations, added import from ./protobuf/any, and updated export structures for api and protobuf.

Possibly related PRs

  • [CT-1160] add relevant protos to dydxprotocol #2162: The changes in this PR involve adding relevant protocol buffers to the dydxprotocol, which aligns with the restructuring and enhancement of the dydxprotocol namespace in the main PR, particularly regarding the organization and functionality of the protocol's components.

Poem

🐇 In the code where modules play,
A vault now shines, bright as day.
Imports dance in a new array,
Enhancing functions in a clever way.
Hop along, dear code, take flight,
For changes made bring pure delight! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3baeb7 and ff6e2bd.

Files selected for processing (3)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts
Additional comments not posted (4)
indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4)

64-71: LGTM!

The added import statements for vault, redis, shared, and socks modules follow the correct syntax and naming conventions.


293-301: LGTM!

The updates to the protocol.v1 export and the addition of new exports for redis, shared, and socks modules within the indexer namespace are consistent with the added import statements and maintain a coherent structure.


382-391: LGTM!

The addition of the vault export within the dydxprotocol namespace is consistent with the added import statements and follows the established structure of the namespace. The export correctly references the relevant imported modules.


190-192: LGTM!

The updates to the export statements for various modules within the dydxprotocol namespace correctly include the newly imported modules while maintaining a consistent structure. The use of the spread operator ensures that the existing exported entities are preserved. The changes are coherent and align with the overall structure of the namespace.

Also applies to: 198-199, 205-206, 213-215, 223-225, 241-243, 258-260, 265-266, 272-274, 279-280, 306-309, 315-318, 324-327, 334-337, 343-346, 352-355, 360-362, 368-371, 373-380, 392-399, 400-402


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>, please review it.
    -- 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 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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fd093a and bb9c1f9.

Files ignored due to path filters (2)
  • protocol/indexer/events/events.pb.go is excluded by !**/*.pb.go
  • protocol/indexer/protocol/v1/types/vault.pb.go is excluded by !**/*.pb.go
Files selected for processing (6)
  • proto/dydxprotocol/indexer/events/events.proto (2 hunks)
  • proto/dydxprotocol/indexer/protocol/v1/vault.proto (1 hunks)
  • protocol/indexer/events/upsert_vault.go (1 hunks)
  • protocol/indexer/events/upsert_vault_test.go (1 hunks)
  • protocol/indexer/protocol/v1/v1_mappers.go (2 hunks)
  • protocol/indexer/protocol/v1/v1_mappers_test.go (2 hunks)
Additional context used
buf
proto/dydxprotocol/indexer/protocol/v1/vault.proto

2-2: Files with package "dydxprotocol.indexer.protocol.v1" must be within a directory "dydxprotocol/indexer/protocol/v1" relative to root but were in directory "proto/dydxprotocol/indexer/protocol/v1".

(PACKAGE_DIRECTORY_MATCH)

Additional comments not posted (6)
protocol/indexer/events/upsert_vault.go (1)

11-21: LGTM!

The function implementation looks good:

  • The function signature and return type are appropriate.
  • The struct fields are correctly populated using the function parameters.
  • The clobPairId and status conversions are correct, assuming the types and conversion functions are properly defined.

The function name NewUpsertVaultEvent and the struct name UpsertVaultEventV1 suggest that this event represents both creation and update of a vault.

Please verify if separate events for vault creation and update are needed, or if a single upsert event is sufficient. This may depend on how the indexer processes these events and if it needs to differentiate between creation and update.

You can use the following script to search for usage of vault creation and update events in the codebase:

protocol/indexer/events/upsert_vault_test.go (1)

14-26: LGTM!

The test function is correctly testing the creation of a new UpsertVaultEvent with the expected parameters. The test is using the correct assertion to compare the actual and expected objects. The test is not missing any important scenarios or edge cases.

proto/dydxprotocol/indexer/protocol/v1/vault.proto (1)

12-27: LGTM!

The VaultStatus enum definition follows the protobuf style guide and the values are well-documented.

protocol/indexer/protocol/v1/v1_mappers.go (1)

210-212: LGTM!

The VaultStatusToIndexerVaultStatus function is correctly implemented. It simply casts the input vaulttypes.VaultStatus to the output v1types.VaultStatus.

The function name clearly describes its purpose, and the implementation is straightforward and easy to understand.

protocol/indexer/protocol/v1/v1_mappers_test.go (1)

478-506: LGTM!

The test function TestVaultStatusToVaultStatus is well-structured and provides comprehensive test coverage for the VaultStatusToIndexerVaultStatus conversion function. It iterates over all possible values of VaultStatus and ensures that the conversion produces the expected results using appropriate assertions.

proto/dydxprotocol/indexer/events/events.proto (1)

594-605: LGTM!

The new UpsertVaultEventV1 message is well-structured and captures the necessary information for a vault upsert event.

Observations:

  • The field names are clear and descriptive.
  • Using the cosmos.AddressString scalar for the address field promotes standardization.
  • Referencing the VaultStatus enum from vault.proto is a good practice for code reuse and consistency.

No issues found.

@@ -0,0 +1,27 @@
syntax = "proto3";
package dydxprotocol.indexer.protocol.v1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the package directory to match the package name.

The static analysis tool buf has flagged an issue with the package directory not matching the package name. To fix this, move the file to the directory dydxprotocol/indexer/protocol/v1 relative to the root of the repository.

Apply this fix to resolve the buf issue:

  1. Create the directory dydxprotocol/indexer/protocol/v1 relative to the root of the repository if it doesn't exist.
  2. Move the file proto/dydxprotocol/indexer/protocol/v1/vault.proto to the new directory dydxprotocol/indexer/protocol/v1/vault.proto.
  3. Update any import statements in other files that reference this file to use the new path.
Tools
buf

2-2: Files with package "dydxprotocol.indexer.protocol.v1" must be within a directory "dydxprotocol/indexer/protocol/v1" relative to root but were in directory "proto/dydxprotocol/indexer/protocol/v1".

(PACKAGE_DIRECTORY_MATCH)

@@ -473,3 +474,33 @@ func TestConvertToPerpetualMarketType(t *testing.T) {
})
}
}

func TestVaultStatusToVaultStatus(t *testing.T) {
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
func TestVaultStatusToVaultStatus(t *testing.T) {
func TestVaultStatusToIndexerVaultStatus(t *testing.T) {

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)
indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/vault.ts (2)

38-65: LGTM with a minor suggestion!

The vaultStatusFromJSON function is correctly implemented and handles both number and string representations of the status.

However, the case clauses at lines 60-61 are redundant because of the default clause. Please consider removing them to simplify the code.

Apply this diff to remove the redundant case clauses:

-    case -1:
-    case "UNRECOGNIZED":
     default:
       return VaultStatus.UNRECOGNIZED;
Tools
Biome

[error] 60-61: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 61-62: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


66-87: LGTM with a minor suggestion!

The vaultStatusToJSON function is correctly implemented and handles all possible VaultStatus enum values.

However, the case clause at lines 83-84 is redundant because of the default clause. Please consider removing it to simplify the code.

Apply this diff to remove the redundant case clause:

-    case VaultStatus.UNRECOGNIZED:
     default:
       return "UNRECOGNIZED";
Tools
Biome

[error] 83-84: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 545ae92 and d3baeb7.

Files selected for processing (5)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/vault.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts
Additional context used
Biome
indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/vault.ts

[error] 60-61: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 61-62: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 83-84: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

Additional comments not posted (12)
indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/vault.ts (2)

2-18: LGTM!

The VaultStatus enum is well-defined and follows best practices:

  • Each status has a clear description.
  • An UNRECOGNIZED status is included to handle unexpected values.
  • The default VAULT_STATUS_UNSPECIFIED status is marked as invalid and unused.

21-37: What is the purpose of the VaultStatusSDKType enum?

The VaultStatusSDKType enum is identical to the VaultStatus enum. Please clarify the purpose of having this duplicate enum. If it serves a specific purpose, consider adding a comment to explain its usage.

indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4)

60-67: LGTM!

The new import statements for protocol, redis, shared, and socks modules follow the correct syntax and naming conventions. Their addition suggests an expansion of functionality within the dydxprotocol namespace.


Line range hint 184-385: LGTM!

The updated export declarations for various modules maintain a consistent structure and correctly reference the additional imported entities using the spread operator and import aliases. These changes suggest an enhancement of functionality within each module by incorporating new components.


368-377: Significant enhancement: Addition of the vault module.

The introduction of the vault module to the dydxprotocol namespace represents a significant enhancement to the protocol's functionality related to vault operations. The exported entities within the vault module, including genesis, params, query, share, tx, and vault, follow a consistent naming convention and structure.

This addition is likely to interact with other modules within the namespace to provide a cohesive set of features for managing vaults.


386-389: New feature: Addition of the ClientFactory export.

The introduction of the ClientFactory export to the dydxprotocol namespace suggests the implementation of a factory pattern for creating client instances. The imported entities used in the ClientFactory export are likely related to LCD, RPC query, and RPC transaction functionality.

This addition follows the same structure as other exports within the namespace and may provide a convenient way to instantiate clients with specific configurations or dependencies.

indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (6)

1509-1518: LGTM!

The UpsertVaultEventV1 interface looks good. The properties address, clobPairId, and status seem appropriate to represent an event emitted when a vault is created or updated.


1521-1530: Looks good!

The UpsertVaultEventV1SDKType interface correctly mirrors the UpsertVaultEventV1 interface using the snake_case naming convention for the SDK type.


3832-3838: LGTM!

The createBaseUpsertVaultEventV1 function correctly initializes a base instance of UpsertVaultEventV1 with the expected default values for the properties.


3841-3855: Looks good!

The UpsertVaultEventV1.encode function correctly encodes an instance of UpsertVaultEventV1 by writing the address, clobPairId, and status properties to the Writer.


3857-3885: LGTM!

The UpsertVaultEventV1.decode function correctly decodes an instance of UpsertVaultEventV1 by reading the address, clobPairId, and status properties from the Reader and returning the decoded message.


3887-3894: Looks good!

The UpsertVaultEventV1.fromPartial function correctly creates an instance of UpsertVaultEventV1 from a partial object. It assigns the provided values to the corresponding properties or uses default values if not provided.

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.

3 participants