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-417] Allocate market mapper revshare for appropriate markets #1773

Merged
merged 10 commits into from
Jun 27, 2024
Merged

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Jun 25, 2024

Changelist

This change calculates the market mapper revenue share for a trade in a specific market and transfers the share amount to the market mapper address

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 revenue sharing functionality across various modules.
    • Added capability to distribute fees to market mappers and fee collectors based on revenue share details.
  • Bug Fixes

    • Fixed error handling in revenue share-related queries.
  • Tests

    • Added extensive test coverage for revenue sharing functionalities, including market mapper revenue sharing and fee distribution.
    • Updated existing tests to incorporate new parameters related to revenue sharing.
  • Refactor

    • Renamed and added parameters to multiple functions to support new revenue sharing features.
    • Enhanced interface definitions to include methods for handling revenue sharing.

Copy link

linear bot commented Jun 25, 2024

Copy link
Contributor

coderabbitai bot commented Jun 25, 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 19 minutes and 29 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 49942c3 and d6b1e71.

Walkthrough

The changes introduce a new RevShareKeeper to various modules, focusing on initializing and incorporating revenue-sharing functionality across the application. Enhancements include updating function signatures to include the RevShareKeeper, modifying methods to handle revenue sharing, and adding relevant tests. The overarching goal is to integrate market mapper revenue-sharing mechanisms within the existing infrastructure while ensuring proper test coverage.

Changes

Files and Paths Change Summary
protocol/app/app.go Added RevShareKeeper to New function for initializing.
protocol/testutil/keeper/clob.go Added revShareKeeper parameter in NewClobKeepersTestContextWithUninitializedMemStore.
protocol/testutil/keeper/prices.go Imported revsharetypes and updated markets revenue-share in CreateTestMarkets.
protocol/testutil/keeper/sending.go Added revShareKeeper parameter to SendingKeepersWithSubaccountsKeeper.
protocol/x/clob/keeper/process_single_match.go Added fee distribution with k.subaccountsKeeper.DistributeFees.
protocol/x/clob/types/expected_keepers.go Added DistributeFees method to SubaccountsKeeper interface.
protocol/x/prices/keeper/keeper.go, market.go Renamed revShareKeeper to RevShareKeeper within the Keeper struct and method calls.
protocol/x/prices/types/expected_keepers.go Added SetMarketMapperRevShareDetails method to RevShareKeeper interface.
protocol/x/revshare/keeper/revshare.go, revshare_test.go Added GetMarketMapperRevenueShareForMarket function and related tests.
protocol/x/revshare/types/errors.go Added ErrMarketMapperRevShareDetailsNotFound error.
protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go Updated error checking assertion in related tests.
protocol/x/subaccounts/genesis_test.go, subaccount_test.go Added an extra underscore parameter for consistency in function calls in tests.
protocol/x/subaccounts/keeper/transfer.go, transfer_test.go Implemented DistributeFees function and modified tests to handle revenue sharing parameters.
protocol/x/subaccounts/types/expected_keepers.go Added RevShareKeeper interface and GetMarketMapperRevenueShareForMarket method.

Poem

In the garden where the code grows bright,
New keepers of revenue share take flight,
With markets mapped in cosmic dance,
Fees distributed in measured prance,
Tests rewritten with careful might.
Progress blooms in lines so tight,
Hopping forward, 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: 9

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d36863c and 0292c2b.

Files selected for processing (23)
  • protocol/app/app.go (1 hunks)
  • protocol/testutil/keeper/clob.go (1 hunks)
  • protocol/testutil/keeper/prices.go (2 hunks)
  • protocol/testutil/keeper/sending.go (1 hunks)
  • protocol/testutil/keeper/subaccounts.go (7 hunks)
  • protocol/x/clob/keeper/process_single_match.go (1 hunks)
  • protocol/x/clob/types/expected_keepers.go (1 hunks)
  • protocol/x/prices/keeper/keeper.go (2 hunks)
  • protocol/x/prices/keeper/market.go (1 hunks)
  • protocol/x/prices/types/expected_keepers.go (2 hunks)
  • protocol/x/revshare/keeper/revshare.go (1 hunks)
  • protocol/x/subaccounts/genesis_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/grpc_query_collateral_pool_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/grpc_query_subaccount_test.go (2 hunks)
  • protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/keeper.go (3 hunks)
  • protocol/x/subaccounts/keeper/negative_tnc_subaccount_test.go (2 hunks)
  • protocol/x/subaccounts/keeper/safety_heap_state_test.go (3 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (10 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (1 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (18 hunks)
  • protocol/x/subaccounts/module_test.go (1 hunks)
  • protocol/x/subaccounts/types/expected_keepers.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/subaccounts/keeper/negative_tnc_subaccount_test.go
Additional comments not posted (36)
protocol/x/prices/types/expected_keepers.go (1)

24-28: New method added to RevShareKeeper interface.

The method SetMarketMapperRevShareDetails has been added to handle the setting of market mapper revenue share details. Ensure that all implementations of this interface are updated to include this new method.

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

22-22: Integration of RevShareKeeper in Keeper struct.

The revShareKeeper field has been added to the Keeper struct and is properly initialized in the NewKeeper function. This change aligns with the system's expansion to include revenue sharing capabilities.

Also applies to: 34-34, 44-44

protocol/x/subaccounts/genesis_test.go (1)

37-37: Updated test function to include new parameter.

The SubaccountsKeepers function now correctly includes an additional parameter, reflecting the integration of the RevShareKeeper. Ensure that the test logic accounts for the new keeper's behavior.

protocol/x/subaccounts/keeper/grpc_query_collateral_pool_test.go (1)

55-55: Updated test function to accommodate new parameter.

The SubaccountsKeepers function call in TestQueryCollateralPoolAddress correctly includes an additional parameter for the RevShareKeeper. Ensure that the test cases are adjusted to account for any new logic introduced by this keeper.

protocol/x/subaccounts/types/expected_keepers.go (1)

100-109: New RevShareKeeper interface added.

The RevShareKeeper interface has been introduced with the method GetMarketMapperRevenueShareForMarket. This method is essential for retrieving revenue share details for a market, aligning with the system's new functionalities.

protocol/x/prices/keeper/keeper.go (2)

30-30: Field naming consistency improved

Renaming revShareKeeper to RevShareKeeper in the Keeper struct improves consistency with Go naming conventions, where exported fields should start with an uppercase letter.


55-55: Constructor updated to accommodate new dependency

The addition of RevShareKeeper as a parameter in the NewKeeper constructor is correctly implemented. This change ensures that the RevShareKeeper is properly initialized when a new Keeper instance is created.

protocol/x/clob/types/expected_keepers.go (1)

76-81: New method added to SubaccountsKeeper interface

The addition of the DistributeFees method to the SubaccountsKeeper interface is appropriate for the new functionality related to fee distribution. This change aligns with the overall feature enhancement described in the PR.

protocol/x/subaccounts/keeper/grpc_query_subaccount_test.go (1)

22-22: Updated test setup to accommodate new parameter

The test setup has been correctly updated to include the new parameter in the SubaccountsKeepers function. This ensures that the tests remain valid and are able to test the new functionality.

Also applies to: 93-93

protocol/testutil/keeper/sending.go (1)

95-95: Proper initialization of SubaccountsKeeper with new parameter

The conditional initialization of SubaccountsKeeper now includes the revShareKeeper when saKeeper is nil. This ensures that all dependencies are correctly set up during testing, reflecting the changes in the main codebase.

protocol/x/subaccounts/keeper/safety_heap_state_test.go (3)

14-14: Code Review: Updated function call to include RevShareKeeper.

The function call has been correctly updated to include the new RevShareKeeper parameter. This change aligns with the modifications made across the repository to integrate RevShareKeeper.


63-63: Code Review: Consistent update in function calls.

Similar to previous changes, the function call here is updated to pass the RevShareKeeper. This maintains consistency across test setups.


112-112: Code Review: Updated function signature in test setup.

The test setup function SubaccountsKeepers has been updated consistently to include the RevShareKeeper across all tests in this file.

protocol/x/prices/keeper/market.go (1)

93-93: Code Review: Updated method call to RevShareKeeper.

The method call CreateNewMarketRevShare has been updated to use the capitalized field name RevShareKeeper, ensuring it adheres to Go's convention for exported fields. This change is part of a larger refactoring to improve code quality and ensure consistency.

protocol/testutil/keeper/subaccounts.go (2)

Line range hint 35-44: Code Review: Comprehensive update to accommodate RevShareKeeper.

The changes in this file correctly integrate RevShareKeeper into the test setup functions for subaccounts keeper. This includes passing the RevShareKeeper to other related keepers and ensuring it is initialized correctly. These changes are crucial for maintaining the integrity of the test environment and ensuring that new functionality related to revenue sharing is correctly tested.

Also applies to: 56-80, 85-91


Line range hint 102-121: Code Review: Correct initialization of RevShareKeeper in helper function.

The helper function createSubaccountsKeeper has been correctly updated to include RevShareKeeper, ensuring that all dependencies are properly initialized. This change is vital for the correct operation of the subaccounts keeper in the context of revenue sharing.

protocol/x/subaccounts/module_test.go (1)

42-42: Code Review: Updated function call in module test setup.

The function call in createAppModuleWithKeeper has been updated to include the RevShareKeeper. This change is consistent with the updates across other test files and is necessary for ensuring that the module tests have access to the correctly initialized keepers.

protocol/testutil/keeper/clob.go (1)

141-141: Code Review: Correct integration of RevShareKeeper in CLOB test setup.

The function createSubaccountsKeeper within the CLOB test setup has been updated to include RevShareKeeper. This change ensures that the subaccounts keeper is correctly initialized with all necessary dependencies, including the new revenue sharing functionality, which is critical for the correct operation of the CLOB module in tests.

protocol/testutil/keeper/prices.go (2)

7-7: Import Addition: revsharetypes

The import of revsharetypes is appropriate given the usage of RevShareKeeper methods in this file.


121-126: Set Market Mapper Revenue Share Details

This block of code correctly sets the revenue share details for each market to have no revenue share. This is consistent with the PR's objective to manage revenue shares more dynamically.

protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info_test.go (1)

270-273: Ensure Proper Initialization of Test Environment

The test setup includes initializing subaccounts, prices, perpetuals, and blocktime keepers, which is essential for the comprehensive testing of withdrawal and transfer block queries. This change reflects an increase in the number of return parameters from SubaccountsKeepers, likely due to the inclusion of RevShareKeeper.

protocol/x/clob/keeper/process_single_match.go (2)

429-431: Consider optimizing repeated data retrieval:

The TODO comment suggests optimizing the retrieval of perpetual objects, which is a valid point given the potential performance impact in high-frequency trading environments.
[REFACTOR_SUGGESTS]


439-455: Refactor suggested for fee distribution logic:

The commented-out block for fee transfer and the new DistributeFees method call indicate a change in how fees are handled. It's crucial to ensure that this new method correctly implements all intended fee logic, especially in a financial application where accurate fee handling is critical.

- //if err := k.subaccountsKeeper.TransferFeesToFeeCollectorModule(
- //	ctx,
- //	assettypes.AssetUsdc.Id,
- //	bigTotalFeeQuoteQuantums,
- //	perpetualId,
- //); err != nil {
- //	return takerUpdateResult, makerUpdateResult, errorsmod.Wrapf(
- //		types.ErrSubaccountFeeTransferFailed,
- //		"persistMatchedOrders: subaccounts (%v, %v) updated, but fee transfer (bigFeeQuoteQuantums: %v)"+
- //			" to fee-collector failed. Err: %v",
- //		matchWithOrders.MakerOrder.GetSubaccountId(),
- //		matchWithOrders.TakerOrder.GetSubaccountId(),
- //		bigTotalFeeQuoteQuantums,
- //		err,
- //	)
- //}
+ if err := k.subaccountsKeeper.DistributeFees(
+	ctx,
+	assettypes.AssetUsdc.Id,
+	bigTotalFeeQuoteQuantums,
+	perpetualId,
+); err != nil {
+	return takerUpdateResult, makerUpdateResult, errorsmod.Wrapf(
+		types.ErrSubaccountFeeTransferFailed,
+		"persistMatchedOrders: subaccounts (%v, %v) updated, but fee transfer (bigFeeQuoteQuantums: %v)"+
+			" to fee-collector failed. Err: %v",
+		matchWithOrders.MakerOrder.GetSubaccountId(),
+		matchWithOrders.TakerOrder.GetSubaccountId(),
+		bigTotalFeeQuoteQuantums,
+		err,
+	)
+ }
protocol/x/subaccounts/keeper/transfer_test.go (2)

23-23: Include package import documentation.

It's a good practice to include comments describing why certain packages are imported, especially for less obvious dependencies.


1598-1598: Ensure comprehensive testing of new functionality.

The function TestTransferInsuranceFundPayments introduces significant new logic. Ensure that all edge cases are covered, especially those involving error states and boundary conditions.

Verification successful

Ensure comprehensive testing of new functionality.

The TestTransferInsuranceFundPayments function in the protocol/x/subaccounts/keeper/transfer_test.go file appears to cover a variety of scenarios, including successful transfers, failures due to insufficient funds, and panics when assets do not exist. These tests encompass a broad range of edge cases and error states, indicating a thorough approach to testing.

  • Success cases: Sending to and from the insurance fund, including zero payments and isolated insurance fund accounts.
  • Failure cases: Insufficient funds in subaccounts and insurance fund, and non-existent assets leading to panics.

The current test cases seem to comprehensively cover the new logic introduced by the TestTransferInsuranceFundPayments function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all edge cases for insurance fund payments are covered.

# Test: Search for test cases in the function. Expect: Comprehensive coverage including edge cases.
rg --type python $'TestTransferInsuranceFundPayments'

Length of output: 83



Script:

#!/bin/bash
# Locate the TestTransferInsuranceFundPayments function in the transfer_test.go file and extract its content.
ast-grep --lang go --pattern 'func TestTransferInsuranceFundPayments($_) $_' --json | jq -r '.[].text'

Length of output: 8396

protocol/app/app.go (1)

1033-1033: Ensure proper initialization of RevShareKeeper.

The RevShareKeeper is added as a parameter to the New function and subsequently used to initialize the App struct. This is a critical integration point for the revenue sharing functionality.

Ensure that all dependencies and configurations required by RevShareKeeper are correctly set up before this point.

protocol/x/subaccounts/keeper/subaccount_test.go (10)

156-156: Ensure consistency in the number of parameters for SubaccountsKeepers across all tests.

The addition of extra parameters in the SubaccountsKeepers function call is consistent with the changes described in the PR and AI-generated summary. Ensure that all tests correctly handle these new parameters.


191-191: Verify that the new parameters are integrated correctly in TestSubaccountGet.

The test function TestSubaccountGet has been updated to include additional parameters. Verify that these parameters are used appropriately within the test to maintain its integrity.


205-205: Check the integration of new parameters in TestSubaccountSet_Empty.

This change reflects the updated function signature. Confirm that the additional parameters do not alter the expected behavior of the test.


223-223: Confirm correct parameter handling in TestSubaccountGetNonExistent.

The test has been adapted to include more parameters, which should be carefully managed to ensure the test's purpose remains clear and effective.


237-237: Ensure the additional parameters are properly utilized in TestGetAllSubaccount.

The integration of additional parameters in the test setup should be checked to ensure they are relevant and correctly used within the test's context.


278-278: Review parameter expansion in TestGetAllSubaccount for specific scenarios.

The addition of extra parameters should support the test's requirements without introducing inconsistencies or errors in the expected outcomes.


2790-2790: Assess the expanded parameter list in complex test scenarios.

The test has been modified to include a more extensive parameter list, which must be correctly handled to preserve the integrity and purpose of the test.
[APROVED]


4234-4234: Ensure the extended parameters are correctly utilized in varied test environments.

This modification introduces additional complexity in parameter management, which should be carefully reviewed to ensure the test remains effective.


5345-5348: Check for correct handling of parameters in dynamic test setups.

This test function's modification involves more parameters, which need to be correctly integrated to maintain the test's functionality and reliability.


5784-5787: Confirm the effective integration of additional parameters in complex test scenarios.

The test setup now includes more parameters, which must be managed effectively to ensure the test achieves its intended outcomes without introducing errors.

protocol/x/subaccounts/keeper/transfer.go Outdated Show resolved Hide resolved
Comment on lines +80 to +105
func (k Keeper) GetMarketMapperRevenueShareForMarket(ctx sdk.Context, marketId uint32) (
address sdk.AccAddress,
revenueSharePpm uint32,
err error,
) {
// get the revenue share details for the market
revShareDetails, err := k.GetMarketMapperRevShareDetails(ctx, marketId)
if err != nil {
return nil, 0, err
}

// check if the rev share details are expired
if revShareDetails.ExpirationTs < uint64(ctx.BlockTime().Unix()) {
return nil, 0, nil
}

// Get revenue share params
revShareParams := k.GetMarketMapperRevenueShareParams(ctx)

revShareAddr, err := sdk.AccAddressFromBech32(revShareParams.Address)
if err != nil {
return nil, 0, err
}

return revShareAddr, revShareParams.RevenueSharePpm, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

New method to retrieve market mapper revenue share

The method GetMarketMapperRevenueShareForMarket is well implemented. It fetches the revenue share details and checks for expiration. However, it returns nil instead of an empty sdk.AccAddress when an error occurs, which could lead to potential issues if not handled properly by the caller.

-		return nil, 0, err
+		return sdk.AccAddress{}, 0, err
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (k Keeper) GetMarketMapperRevenueShareForMarket(ctx sdk.Context, marketId uint32) (
address sdk.AccAddress,
revenueSharePpm uint32,
err error,
) {
// get the revenue share details for the market
revShareDetails, err := k.GetMarketMapperRevShareDetails(ctx, marketId)
if err != nil {
return nil, 0, err
}
// check if the rev share details are expired
if revShareDetails.ExpirationTs < uint64(ctx.BlockTime().Unix()) {
return nil, 0, nil
}
// Get revenue share params
revShareParams := k.GetMarketMapperRevenueShareParams(ctx)
revShareAddr, err := sdk.AccAddressFromBech32(revShareParams.Address)
if err != nil {
return nil, 0, err
}
return revShareAddr, revShareParams.RevenueSharePpm, nil
}
func (k Keeper) GetMarketMapperRevenueShareForMarket(ctx sdk.Context, marketId uint32) (
address sdk.AccAddress,
revenueSharePpm uint32,
err error,
) {
// get the revenue share details for the market
revShareDetails, err := k.GetMarketMapperRevShareDetails(ctx, marketId)
if err != nil {
return sdk.AccAddress{}, 0, err
}
// check if the rev share details are expired
if revShareDetails.ExpirationTs < uint64(ctx.BlockTime().Unix()) {
return sdk.AccAddress{}, 0, nil
}
// Get revenue share params
revShareParams := k.GetMarketMapperRevenueShareParams(ctx)
revShareAddr, err := sdk.AccAddressFromBech32(revShareParams.Address)
if err != nil {
return sdk.AccAddress{}, 0, err
}
return revShareAddr, revShareParams.RevenueSharePpm, nil
}

protocol/x/subaccounts/keeper/transfer.go Outdated Show resolved Hide resolved
Signed-off-by: Shrenuj Bansal <[email protected]>
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 0292c2b and 2fbcffa.

Files selected for processing (4)
  • protocol/testutil/keeper/subaccounts.go (7 hunks)
  • protocol/x/clob/keeper/process_single_match.go (1 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (2 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (17 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/testutil/keeper/subaccounts.go
  • protocol/x/clob/keeper/process_single_match.go
  • protocol/x/subaccounts/keeper/transfer.go
  • protocol/x/subaccounts/keeper/transfer_test.go

Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
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 2fbcffa and bbd93c9.

Files selected for processing (3)
  • protocol/x/clob/types/expected_keepers.go (2 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (2 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/subaccounts/keeper/transfer.go
  • protocol/x/subaccounts/keeper/transfer_test.go
Additional comments not posted (1)
protocol/x/clob/types/expected_keepers.go (1)

75-80: New Method DistributeFees Added to SubaccountsKeeper

The addition of the DistributeFees method in the SubaccountsKeeper interface aligns with the PR's objective to enhance fee distribution mechanisms. This method appears to be well-defined with appropriate parameters for asset ID, quantum amounts, and perpetual ID. Ensure that all implementations of this interface are updated to include this new method to avoid runtime errors.

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 bbd93c9 and 020b8b6.

Files selected for processing (7)
  • protocol/app/app.go (1 hunks)
  • protocol/testutil/keeper/subaccounts.go (7 hunks)
  • protocol/x/clob/keeper/process_single_match.go (1 hunks)
  • protocol/x/subaccounts/genesis_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (12 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (18 hunks)
  • protocol/x/subaccounts/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • protocol/app/app.go
  • protocol/testutil/keeper/subaccounts.go
  • protocol/x/clob/keeper/process_single_match.go
  • protocol/x/subaccounts/genesis_test.go
  • protocol/x/subaccounts/keeper/subaccount_test.go
  • protocol/x/subaccounts/types/expected_keepers.go
Additional comments not posted (4)
protocol/x/subaccounts/keeper/transfer_test.go (4)

24-24: Approved the addition of the revsharetypes import.

This is necessary for the new revenue sharing functionality as indicated by the PR objectives.


197-197: Ensure test setup is properly abstracted.

The repetitive setup code across different test cases (like creating test markets, liquidity tiers, etc.) should ideally be abstracted into helper functions to enhance readability and maintainability.


458-458: Consider abstracting repetitive test setup code.

Similar to the previous test function, consider abstracting repetitive setup code into helper functions to reduce code duplication and improve maintainability.


731-731: Abstract repetitive test setup into helper functions.

The setup code for creating test markets and perpetuals is repeated across tests. Abstracting these into helper functions can reduce code duplication and improve readability.

Signed-off-by: Shrenuj Bansal <[email protected]>
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 020b8b6 and 6c0d0dc.

Files selected for processing (5)
  • protocol/x/revshare/keeper/revshare.go (3 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (2 hunks)
  • protocol/x/revshare/types/errors.go (1 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (3 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/revshare/keeper/revshare.go
  • protocol/x/subaccounts/keeper/transfer.go
Additional comments not posted (8)
protocol/x/revshare/types/errors.go (1)

18-22: Error Definition Approved

The error ErrMarketMapperRevShareDetailsNotFound is clearly defined and follows the existing pattern of error definitions in this module. The error code 3 seems appropriately sequenced following the existing error codes 1 and 2.

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

82-169: Comprehensive Testing of Revenue Share Retrieval

The test function TestGetMarketMapperRevenueShareForMarket effectively tests both valid and invalid scenarios for retrieving revenue share details. The use of a map to define test cases is a good practice for clarity and extensibility. However, the commented-out test case for expired market revenue shares ("expired market rev share") should either be implemented or removed to avoid confusion.

-		// TODO: investigate why tApp blocktime doesn't translate to ctx.BlockTime()
-		//"expired market rev share": {
-		//	revShareParams: types.MarketMapperRevenueShareParams{
-		//		Address:         constants.AliceAccAddress.String(),
-		//		RevenueSharePpm: 100_000, // 10%
-		//		ValidDays:       0,
-		//	},
-		//	marketId:           42,
-		//	expirationDelta:    -10,
-		//	setRevShareDetails: true,
-		//
-		//	expectedMarketMapperAddr: nil,
-		//	expectedRevenueSharePpm:  0,
-		//},
+		// Implement or remove the commented-out test case for clarity.

Additionally, consider verifying the block time synchronization issue noted in the TODO comment, as it may affect the reliability of the test outcomes.

protocol/x/subaccounts/keeper/transfer_test.go (6)

197-197: Ensure test setup is properly abstracted.

The repetitive setup code across different test cases (like creating test markets, liquidity tiers, etc.) should ideally be abstracted into helper functions to enhance readability and maintainability.


458-458: Consider abstracting repetitive test setup code.

Similar to the previous test function, consider abstracting repetitive setup code into helper functions to reduce code duplication and improve maintainability.


731-731: Abstract repetitive test setup into helper functions.

The setup code for creating test markets and perpetuals is repeated across tests. Abstracting these into helper functions can reduce code duplication and improve readability.


1057-1057: Refactor repetitive setup code into helper functions.

The setup code for creating test accounts, markets, and liquidity tiers is being repeated. Consider creating helper functions to handle these operations to improve code readability and reduce duplication.


1179-1179: Clarify the purpose of new fields and methods in documentation.

The introduction of new fields such as marketMapperAccBalance and methods like TestTransferFeesToFeeCollectorModule should be accompanied by comments explaining their purpose and usage, especially when they involve complex financial calculations or business logic.

Would you like me to help draft these explanations?


1415-1415: Document new test scenarios thoroughly.

This test function introduces complex scenarios involving fee distribution and market mappers. It would be beneficial to include detailed comments describing each test case, the expected behaviors, and the setup required.

If you need assistance in documenting these scenarios, please let me know.

Signed-off-by: Shrenuj Bansal <[email protected]>
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 6c0d0dc and 49942c3.

Files selected for processing (3)
  • protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go (1 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (3 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/revshare/keeper/revshare_test.go
  • protocol/x/subaccounts/keeper/transfer.go
Additional comments not posted (1)
protocol/x/revshare/keeper/grpc_query_marketmapper_revshare_details_test.go (1)

43-43: Improved Error Handling in Test Case

The change from ErrorContains to ErrorIs is a significant improvement in testing practices. It ensures that the exact error type ErrMarketMapperRevShareDetailsNotFound is returned, which is crucial for accurate and reliable unit tests.

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