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-415] implement market mapper rev share gov msg #1733

Merged
merged 4 commits into from
Jun 20, 2024
Merged

[TRA-415] implement market mapper rev share gov msg #1733

merged 4 commits into from
Jun 20, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Jun 19, 2024

Changelist

Implement a governance msg to set the market mapper revenue share

Test Plan

Added 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 a comprehensive revenue sharing mechanism for market mappers.
    • Added new RPC method SetMarketMapperRevenueShare.
    • Implemented parameters and validation for market mapper revenue share.
  • Bug Fixes

    • Improved error handling for invalid addresses and revenue share values.
  • Tests

    • Added test cases for the new revenue share functionality to ensure reliability.
  • Chores

    • Reorganized and updated import statements for better code maintainability.

Copy link

linear bot commented Jun 19, 2024

Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Walkthrough

The changes introduce a new revenue-sharing feature to the dydxprotocol, specifically focusing on the market mapper. It includes updates to protobuf definitions, Go code, and TypeScript code for RPC messages. New functionalities include setting market mapper revenue share parameters and handling related messages, along with necessary test cases for validation.

Changes

Files/Directories Change Summary
indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts, google/bundle.ts, gogoproto/bundle.ts Reordered or renamed imports, modified exports, and adjusted object spread assignments for structured namespace.
proto/dydxprotocol/revshare/genesis.proto Added imports and defined params field in GenesisState message.
proto/dydxprotocol/revshare/params.proto Created new file to introduce MarketMapperRevenueShareParams message with revenue share parameters.
proto/dydxprotocol/revshare/tx.proto Added new RPC method SetMarketMapperRevenueShare and related message types.
protocol/app/msgs/all_msgs.go Added declarations for new messages related to revenue sharing in revshare section.
protocol/lib/ante/internal_msg.go Added imports and included new message type in IsInternalMsg function.
protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share.go Introduced SetMarketMapperRevenueShare function to handle setting market mapper revenue share.
protocol/x/revshare/keeper/revshare.go Added functions to set and get market mapper revenue share parameters.
protocol/x/revshare/types/errors.go Introduced new error declarations using an external package.
protocol/x/revshare/types/genesis.go Updated DefaultGenesis function to initialize Params field with DefaultParams().
protocol/x/revshare/types/keys.go Added new constant MarketMapperRevenueShareParamsKey.
protocol/x/revshare/types/params.go Introduced functions for default parameters and validation for market mapper parameters.
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.rpc.msg.ts Added message service Msg with method setMarketMapperRevenueShare and implementation class for RPC communication.
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts Added new interfaces and functions related to market mapper revenue share messages.
protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share_test.go Introduced a test suite for SetMarketMapperRevenueShareParams with scenarios covering various cases.

Poem

🐇 In the realm of dydx, a change unfurls,
Revenue shares now swirl, around the market, pearls.
Code restructured, messages to send,
Mappers' shares to set, on them we depend.
With logic and checks, and tests galore,
All to ensure, revenue flows like before.
Keepers set the rules, ensuring all's right,
A rabbit's work, done day and night. 🌙


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

Outside diff range and nitpick comments (3)
protocol/x/revshare/types/errors.go (1)

3-16: The error definitions look good. Consider adding documentation comments for each error to explain when they should be used, enhancing maintainability.

indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/params.ts (1)

5-20: Clarify documentation for better understanding.
The comments explaining the fields in the MarketMapperRevenueShareParams interface could be more descriptive to provide better clarity on how these parameters are used and their impact.

protocol/scripts/genesis/sample_pregenesis.json (1)

Line range hint 538-538: Sensitive data exposure detected: Generic API Key. This should be removed or securely managed.

- "exchange_config_json": "{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"BTCUSDT\",\"adjustByMarket\":\"USDT-USD\"},{\"exchangeName\":\"Bybit\",\"ticker\":\"BTCUSDT\",\"adjustByMarket\":\"USDT-USD\"},{\"exchangeName\":\"CoinbasePro\",\"ticker\":\"BTC-USD\"},{\"exchangeName\":\"Huobi\",\"ticker\":\"btcusdt\",\"adjustByMarket\":\"USDT-USD\"},{\"exchangeName\":\"Kraken\",\"ticker\":\"XXBTZUSD\"},{\"exchangeName\":\"Kucoin\",\"ticker\":\"BTC-USDT\",\"adjustByMarket\":\"USDT-USD\"},{\"exchangeName\":\"Okx\",\"ticker\":\"BTC-USDT\",\"adjustByMarket\":\"USDT-USD\"}]}"
+ "exchange_config_json": "<REDACTED_FOR_SECURITY>"
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2039998 and ee29b2e.

Files ignored due to path filters (3)
  • protocol/x/revshare/types/genesis.pb.go is excluded by !**/*.pb.go
  • protocol/x/revshare/types/params.pb.go is excluded by !**/*.pb.go
  • protocol/x/revshare/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (26)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/genesis.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/params.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.rpc.msg.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.tx.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)
  • proto/dydxprotocol/revshare/genesis.proto (1 hunks)
  • proto/dydxprotocol/revshare/params.proto (1 hunks)
  • proto/dydxprotocol/revshare/tx.proto (1 hunks)
  • protocol/app/msgs/all_msgs.go (1 hunks)
  • protocol/app/msgs/internal_msgs.go (2 hunks)
  • protocol/app/msgs/internal_msgs_test.go (1 hunks)
  • protocol/app/testdata/default_genesis_state.json (1 hunks)
  • protocol/lib/ante/internal_msg.go (2 hunks)
  • protocol/scripts/genesis/sample_pregenesis.json (1 hunks)
  • protocol/testutil/constants/genesis.go (1 hunks)
  • protocol/x/revshare/genesis.go (1 hunks)
  • protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share.go (1 hunks)
  • protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share_test.go (1 hunks)
  • protocol/x/revshare/keeper/revshare.go (1 hunks)
  • protocol/x/revshare/types/errors.go (1 hunks)
  • protocol/x/revshare/types/genesis.go (1 hunks)
  • protocol/x/revshare/types/keys.go (1 hunks)
  • protocol/x/revshare/types/params.go (1 hunks)
Additional context used
Biome
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts

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

Safe fix: Use a type alias instead.


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

Safe fix: Use a type alias instead.

Gitleaks
protocol/testutil/constants/genesis.go

342-342: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key)

protocol/scripts/genesis/sample_pregenesis.json

538-538: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key)

Additional comments not posted (25)
indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts (1)

1-2: Ensure the updated import _112 correctly points to the intended module version, and verify that all dependent code correctly handles the new import.

protocol/x/revshare/types/keys.go (1)

11-16: The new constant MarketMapperRevenueShareParamsKey is appropriately defined and well-placed within the module's constants. This should facilitate easy reference and maintenance.

proto/dydxprotocol/revshare/genesis.proto (2)

4-5: The import statements are correctly updated to include necessary dependencies.


11-11: The addition of the params field with non-nullability enforced is appropriate for ensuring robust configuration management.

indexer/packages/v4-protos/src/codegen/google/bundle.ts (2)

1-6: The new imports are correctly added and appropriately named, ensuring no namespace conflicts and enabling new functionalities.


8-14: The restructuring of the api and protobuf namespaces using spread syntax is modern and efficient, facilitating easier extension and maintenance.

protocol/x/revshare/genesis.go (2)

11-15: Proper initialization and error handling in InitGenesis. Using panic ensures that initialization errors are not silently ignored, which is crucial for genesis configurations.


20-21: Correct implementation of ExportGenesis to ensure consistent genesis states across exports.

proto/dydxprotocol/revshare/params.proto (1)

8-21: The definition of MarketMapperRevenueShareParams is clear and comprehensive. The use of specific annotations like cosmos_proto.scalar for address validation and parts-per-million for revenue sharing ensures precision and correctness in parameter handling.

protocol/x/revshare/types/params.go (1)

18-31: The validation logic in Validate is robust, ensuring that the address is correctly formatted and the revenue share is within a valid range. Good implementation of error handling.

proto/dydxprotocol/revshare/tx.proto (1)

12-31: The service and message definitions in tx.proto are clear and well-defined. The use of options like cosmos.msg.v1.signer and attributes like cosmos.AddressString ensure that the messages conform to expected standards and types.

indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.rpc.msg.ts (2)

6-8: Clear and concise documentation for the setMarketMapperRevenueShare function.


18-21: Ensure that the encoding and RPC request logic is robust and handles errors appropriately.

indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/genesis.ts (2)

6-8: Ensure the optional nature of params is consistently handled across interfaces and default creation.

Also applies to: 11-13, 16-18


22-26: The encoding, decoding, and partial construction for GenesisState are implemented correctly, ensuring robust type handling.

Also applies to: 39-41, 52-54

protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share_test.go (1)

15-86: The test cases are well-structured and cover a variety of scenarios, including success and error cases.

protocol/lib/ante/internal_msg.go (1)

28-28: Ensure consistent formatting and imports.
The import for the revshare package and the addition of MsgSetMarketMapperRevenueShare to the IsInternalMsg function are correctly implemented. Ensure that the formatting and alignment with other case statements in the switch block are consistent.

Also applies to: 115-116

protocol/app/msgs/internal_msgs.go (2)

29-29: Ensure that the newly added import for revshare is used appropriately throughout the module.


171-172: The addition of MsgSetMarketMapperRevenueShare and its response to InternalMsgSamplesDydxCustom aligns with the PR's objective to manage market mapper revenue shares. Ensure that these messages are integrated correctly in the message handling logic and tested thoroughly.

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

77-83: The addition of imports for revshare components (genesis, params, query, tx) is crucial for supporting the new functionality introduced in this PR. Verify that these imports are correctly mapped in the corresponding namespace exports.


300-302: The namespace exports for revshare have been correctly updated to include the new components. This ensures that the new functionality is accessible as intended.

protocol/app/testdata/default_genesis_state.json (1)

405-410: The initialization of revshare parameters in the genesis state is consistent with the new functionality. Ensure that these parameters (address, revenue_share_ppm, valid_days) are validated during the genesis state initialization to prevent configuration errors.

protocol/app/msgs/all_msgs.go (1)

253-255: Ensure that the new message types are correctly integrated into the system.

This addition aligns with the PR objectives to implement market mapper revenue share functionality. Please ensure these messages are appropriately handled wherever necessary in the application logic.

protocol/testutil/constants/genesis.go (1)

1353-1359: Initialization values for revshare parameters are all set to zero. Please confirm if these are intended defaults or if they should be populated with initial values.

protocol/scripts/genesis/sample_pregenesis.json (1)

1756-1762: The new revshare configuration has been added as expected according to the PR summary.

}

// Revenue share ppm must be less than 1000000 (100%)
if p.RevenueSharePpm >= 1000000 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why can't it be 100%?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't have strong opinion on this since it's never gonna be close to 100% but I was thinking of the implementation to always have something sent to the fee collector

Signed-off-by: Shrenuj Bansal <[email protected]>
@shrenujb shrenujb merged commit cd75f2a into main Jun 20, 2024
33 checks passed
@shrenujb shrenujb deleted the tra415 branch June 20, 2024 18:49
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 ee29b2e and 7ca1235.

Files ignored due to path filters (1)
  • protocol/x/revshare/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (5)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.rpc.msg.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts (1 hunks)
  • proto/dydxprotocol/revshare/tx.proto (1 hunks)
  • protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share_test.go (1 hunks)
  • protocol/x/revshare/types/params.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.rpc.msg.ts
  • proto/dydxprotocol/revshare/tx.proto
  • protocol/x/revshare/keeper/msg_set_marketmapper_revenue_share_test.go
  • protocol/x/revshare/types/params.go
Additional context used
Biome
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts

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

Safe fix: Use a type alias instead.


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

Safe fix: Use a type alias instead.

Additional comments not posted (7)
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/tx.ts (7)

6-11: Interface Definition for MsgSetMarketMapperRevenueShare
The interface is well-defined with clear documentation and optional parameters. This flexibility allows for partial message construction which is useful in scenarios where not all data might be available at the time of message creation.


14-19: Interface Definition for MsgSetMarketMapperRevenueShareSDKType
Similar to the previous interface, this SDK-specific interface maintains consistency and clarity in its structure.


27-32: Base Message Creation Function
The function createBaseMsgSetMarketMapperRevenueShare is effectively setting default values for the message creation, which is a common pattern in TypeScript to handle optional or partial data. Good implementation.


34-45: Message Encoding Function
The function encode in MsgSetMarketMapperRevenueShare is well-implemented with checks for non-default values before encoding, which is efficient as it avoids unnecessary data processing. This is a good practice in protocol buffer handling.


47-70: Message Decoding Function
This function handles decoding efficiently by checking the type of input and using a switch statement to handle different fields based on the protobuf tag. This is robust and ensures that each field is correctly decoded based on its tag.


73-78: Partial Message Construction Function
The method fromPartial allows for the construction of a message from an incomplete data object. This is particularly useful in scenarios where messages are being constructed in stages or from various sources of input.
[APROVED]


82-112: Response Message Handling
The functions related to MsgSetMarketMapperRevenueShareResponse are minimal due to the simplicity of the response structure. This is appropriate given the context, as the response does not need to carry additional data.

/** Response to a MsgSetMarketMapperRevenueShare */

export interface MsgSetMarketMapperRevenueShareResponse {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace empty interfaces with type aliases.
Per the static analysis tool's suggestion and previous comments, these interfaces should be converted to type aliases to simplify the code and adhere to TypeScript best practices.

- export interface MsgSetMarketMapperRevenueShareResponse {}
+ export type MsgSetMarketMapperRevenueShareResponse = {};

- export interface MsgSetMarketMapperRevenueShareResponseSDKType {}
+ export type MsgSetMarketMapperRevenueShareResponseSDKType = {};

Also applies to: 25-25

Tools
Biome

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

Safe fix: Use a type alias instead.

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