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-433] Add MarketMapperRevShareDetails state and associated functions #1744

Merged
merged 7 commits into from
Jun 21, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Jun 20, 2024

Changelist

Add MarketMapperRevShareDetails proto, state and associated functions

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

Release Notes

  • New Features

    • Added functionality to query market mapper revenue share details for a specific market.
    • Introduced LCDQueryClient for querying market mapper revenue share details via LCD client.
  • Refactor

    • Updated import structures and namespaces for improved code organization.
  • Tests

    • Added test functions for validating the querying and setting of market mapper revenue share details.

Copy link

linear bot commented Jun 20, 2024

Copy link
Contributor

coderabbitai bot commented Jun 20, 2024

Warning

Rate limit exceeded

@shrenujb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 47 minutes and 33 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 64d71f0 and c68820e.

Walkthrough

The changes involve renaming, reordering, and restructuring imports, introducing new functionalities and tests related to market mapper revenue share details, and updating protocols. New files facilitate querying and managing these market mapper revenue share details via gRPC and LCD clients, enhancing the revenue share module's capabilities.

Changes

File/Path Summary
indexer/.../bundle.ts Reordered and renamed imports and namespaces, affecting structure, especially under dydxprotocol and google namespaces.
indexer/.../v4-protos/src/codegen/dydxprotocol Introduced new revshare/revshare.ts, updated lcd.ts to include revshare property, and added query.lcd.ts file.
proto/dydxprotocol/revshare Added query.proto service for querying market revenue share, introduced revshare.proto defining MarketMapperRevShareDetails.
protocol/...revshare/keeper Added and tested functions for setting/getting and querying market mapper revenue share details, plus new constants.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LCDQueryClient
    participant MarketMapperRevShareService
    participant RevShareKeeper
    
    User->>LCDQueryClient: marketMapperRevShareDetails(market_id)
    LCDQueryClient->>MarketMapperRevShareService: MarketMapperRevShareDetails(QueryMarketMapperRevShareDetails)
    MarketMapperRevShareService->>RevShareKeeper: GetMarketMapperRevShareDetails(market_id)
    RevShareKeeper-->>MarketMapperRevShareService: MarketMapperRevShareDetailsResponse(details)
    MarketMapperRevShareService-->>LCDQueryClient: MarketMapperRevShareDetailsResponse(details)
    LCDQueryClient-->>User: Revenue Share Details
Loading

Poem

In fields of code, a rabbit hops,
Through lines and files, it never stops.
Rev share details, now in view,
For market folks, it's something new.
Queries dance, like summer skies,
Innovation found where logic lies. 🐇🖥️


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cd75f2a and 3746b7c.

Files ignored due to path filters (1)
  • protocol/x/revshare/types/revshare.pb.go is excluded by !**/*.pb.go
Files selected for processing (8)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/revshare.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/revshare.proto (1 hunks)
  • protocol/x/revshare/keeper/revshare.go (2 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (1 hunks)
  • protocol/x/revshare/types/keys.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts
  • protocol/x/revshare/types/keys.go
Additional comments not posted (5)
proto/dydxprotocol/revshare/revshare.proto (1)

6-11: LGTM! The MarketMapperRevShareDetails message is well-defined with clear documentation.

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

8-64: LGTM! The TypeScript interfaces and functions for MarketMapperRevShareDetails are correctly implemented with proper type handling.

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

13-69: LGTM! The unit tests for market rev share functions are thorough. However, please verify the deterministic nature of the block time used in the tests.

Verification successful

To verify if the block time calls are deterministic in the tests, we need to understand how the block time is managed in the context (ctx). The context is initialized using testapp.NewTestAppBuilder(t).Build().InitChain(). Let's inspect the testapp package to see how ctx.BlockTime() is set.


The previous script failed to locate the testapp package, resulting in no output. Let's correct the approach to find the testapp package and inspect its contents to understand how the context (ctx) and block time are managed.


The previous attempt to locate the testapp package and inspect its contents was unsuccessful due to incorrect assumptions about the file naming conventions. To address this, we should search for the NewTestAppBuilder function definition directly, which will help us pinpoint the exact file and understand the context initialization.


We have located the NewTestAppBuilder function definition in protocol/testutil/app/app.go. Now, let's inspect this file to understand how the context (ctx) and block time are managed.


The NewTestAppBuilder function in protocol/testutil/app/app.go initializes the context with a genesis time set to a specific value (time.Unix(0, 1)). This suggests that the block time can be deterministic if the tests are designed to use this initial context consistently.

However, to ensure that the block time remains deterministic throughout the test execution, it is crucial to verify that no other parts of the code modify the block time in a non-deterministic manner.

Given this information, the block time used in the tests appears to be deterministic based on the initial genesis time configuration. Therefore, the review comment's concern about the deterministic nature of the block time can be considered addressed.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if block time calls are deterministic in tests.

# Test: Search for non-deterministic block time usage. Expect: Details on how block time is managed.
grep -r "BlockTime" protocol/x/revshare/keeper/

Length of output: 264



Script:

#!/bin/bash
# Description: Inspect the testapp package to understand context initialization and block time management.

# Locate the testapp package
testapp_path=$(fd testapp | grep -m 1 '.go$' | xargs dirname)

# Display the content of the testapp package to understand context initialization
cat ${testapp_path}/*.go

Length of output: 188



Script:

#!/bin/bash
# Description: Inspect the testapp package to understand context initialization and block time management.

# Locate the testapp package by searching for go files containing 'testapp'
fd -e go -x grep -l 'testapp' | xargs dirname | sort -u | xargs -I {} sh -c 'echo {}; cat {}/testapp*.go'

Length of output: 3795



Script:

#!/bin/bash
# Description: Locate the definition of the NewTestAppBuilder function to understand context initialization and block time management.

# Search for the definition of the NewTestAppBuilder function
fd -e go -x grep -l 'NewTestAppBuilder' | xargs grep -H 'func NewTestAppBuilder'

Length of output: 165



Script:

#!/bin/bash
# Description: Inspect the content of the app.go file to understand context initialization and block time management.

# Display the content of app.go to review the NewTestAppBuilder function and related context initialization
cat ./protocol/testutil/app/app.go

Length of output: 53096

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

40-84: LGTM! The functions for managing market rev share details are correctly implemented. Please ensure that there are no data races due to concurrent access to the KV store.

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

79-84: Renaming and addition of imports related to the revshare module appear correctly integrated into the namespace exports. Ensure that any dependent modules or services are updated to reflect these changes.

Verification successful

The verification process has confirmed that the new import paths are correctly used in the codebase. Both revshare/revshare and revshare/tx are present in the updated imports. Additionally, the old import path revshare/tx is still present but in a different context (revshare/tx.rpc.msg), which is expected and correct.

  • revshare/revshare import is correctly added.
  • revshare/tx import is correctly added and used.

No issues were found with the integration of the new import paths.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new and renamed imports are correctly used throughout the codebase.

# Test: Search for old import usage. Expect: No occurrences of the old import path.
rg --type typescript $'revshare/tx' --files-without-match

Length of output: 91



Script:

#!/bin/bash
# Description: Verify that the new and renamed imports are correctly used throughout the codebase.

# Test 1: Search for old import usage. Expect: No occurrences of the old import path.
rg 'revshare/tx' --type ts

# Test 2: Search for new import usage. Expect: Occurrences of the new import paths.
rg 'revshare/revshare' --type ts
rg 'revshare/tx' --type ts

Length of output: 890

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.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3746b7c and 01778d8.

Files ignored due to path filters (1)
  • protocol/x/revshare/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (5)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/query.rpc.Query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/query.ts (1 hunks)
  • proto/dydxprotocol/revshare/query.proto (1 hunks)
  • protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details.go (1 hunks)
  • protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go (1 hunks)
Additional comments not posted (7)
proto/dydxprotocol/revshare/query.proto (1)

16-21: The message definitions are appropriately structured for the query and response. Ensure that fields like market_id in QueryMarketMapperRevShareDetails are adequately validated on the server side to handle potential invalid inputs.

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

1-1: Ensure all necessary imports are present and correctly referenced.


6-15: The interfaces for querying market mapper details are well-defined and follow consistent naming conventions.


18-25: The response type interfaces are correctly defined and include optional chaining for details, which is a good practice for potentially undefined data.


27-40: The createBaseQueryMarketMapperRevShareDetails function correctly initializes the marketId to a default value of 0. This ensures that the structure is always in a valid state when instantiated.


72-115: The response handling functions, including base creation, encoding, decoding, and partial handling, are well-implemented. Ensure that the details field handling is robust, particularly in scenarios where it might be null or undefined.

Verification successful

The handling of the details field in the response functions is robust, with checks for undefined and null values consistently applied across the project.

  • details field handling in the provided code snippet is correct.
  • Multiple instances in the project show proper handling of details with checks for undefined and null.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robust handling of the `details` field in response functions.

# Test: Search for uses of `details` field in the project to ensure it's handled properly everywhere.
rg --type ts "details" --files-with-matches | xargs cat | rg "null|undefined"

Length of output: 4356


33-69: The encoding and decoding functions are implemented correctly. However, ensure comprehensive testing, especially edge cases where unexpected data types might be passed to these functions.

func (k Keeper) CreateNewMarketRevShare(ctx sdk.Context, marketId uint32) (err error) {
revShareParams := k.GetMarketMapperRevenueShareParams(ctx)

validDurationSeconds := int64(revShareParams.ValidDays * 24 * 60 * 60)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: uint64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unix time is int64 so this needs to be the same for the addition. The result later gets converted to uint64 which is fine because its not possible for these to be negative

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 01778d8 and 642bfef.

Files ignored due to path filters (2)
  • protocol/x/revshare/types/query.pb.go is excluded by !**/*.pb.go
  • protocol/x/revshare/types/revshare.pb.go is excluded by !**/*.pb.go
Files selected for processing (8)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/lcd.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/revshare.ts (1 hunks)
  • proto/dydxprotocol/revshare/query.proto (1 hunks)
  • proto/dydxprotocol/revshare/revshare.proto (1 hunks)
  • protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go (1 hunks)
  • protocol/x/revshare/keeper/revshare.go (2 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/revshare.ts
  • proto/dydxprotocol/revshare/query.proto
  • proto/dydxprotocol/revshare/revshare.proto
  • protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go
  • protocol/x/revshare/keeper/revshare.go
  • protocol/x/revshare/keeper/revshare_test.go
Additional comments not posted (1)
indexer/packages/v4-protos/src/codegen/dydxprotocol/lcd.ts (1)

42-44: Integration of revshare service is correctly implemented.

The addition follows the established pattern of dynamically importing and initializing LCDQueryClient instances for new services. This ensures consistency across service integrations within the createLCDClient function.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 642bfef and 64d71f0.

Files ignored due to path filters (1)
  • protocol/x/revshare/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (1)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/query.lcd.ts (1 hunks)
Additional comments not posted (3)
indexer/packages/v4-protos/src/codegen/dydxprotocol/revshare/query.lcd.ts (3)

1-3: Well-organized imports.

The imports are clearly structured and directly relevant to the functionality of the LCDQueryClient. Keeping imports minimal and relevant helps maintain clarity and reduce potential conflicts.


6-13: Constructor and method binding reviewed.

The constructor is straightforward, taking a requestClient and assigning it to the req property. The binding of marketMapperRevShareDetails is a good practice to ensure that the method retains the correct this context when used as a callback.


17-20: Review of marketMapperRevShareDetails method.

The method marketMapperRevShareDetails is well-implemented. It dynamically constructs the endpoint URL using the marketId parameter and uses the req property to perform a GET request. This design is efficient and makes the function flexible to changes in the endpoint structure.

Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
@shrenujb shrenujb merged commit 1bc1c73 into main Jun 21, 2024
34 checks passed
@shrenujb shrenujb deleted the tra433 branch June 21, 2024 21:04
adamfraser pushed a commit that referenced this pull request Jun 24, 2024
…ons (#1744)

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