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

[OTE-687] Bump fee tiers for referees #2217

Merged
merged 4 commits into from
Sep 16, 2024
Merged

[OTE-687] Bump fee tiers for referees #2217

merged 4 commits into from
Sep 16, 2024

Conversation

affanv14
Copy link
Contributor

@affanv14 affanv14 commented Sep 5, 2024

Changelist

Bumps addresses to a starting fee tier if the address has a referral

Test Plan

[Describe how this PR was tested (if applicable)]

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 integration of the AffiliatesKeeper for improved affiliate management within the application.
    • Added functionality to calculate user fees based on affiliate referrals, including a new constant for the starting fee tier for referees.
    • Introduced a new interface for AffiliatesKeeper to manage referral relationships.
  • Bug Fixes

    • Improved logic for fee tier calculations related to user referrals.
  • Tests

    • Added tests to validate fee calculations based on user referrals.
  • Documentation

    • Updated documentation to reflect new functionalities and interfaces.

@affanv14 affanv14 requested a review from a team as a code owner September 5, 2024 21:53
Copy link

linear bot commented Sep 5, 2024

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve modifications to several keeper functions to incorporate the affiliatesKeeper parameter. This includes updates to the createClobKeeper and createListingKeeper functions, which now require an affiliatesKeeper instance during their initialization. Additionally, the RewardsKeepers function has been adjusted to include the affiliatesKeeper when creating the feetiersKeeper. These changes enhance the interaction of various keepers with affiliate-related logic within the application.

Changes

Files Change Summary
protocol/testutil/keeper/clob.go Updated createClobKeeper to include affiliatesKeeper in the function signature and instantiation.
protocol/testutil/keeper/listing.go Modified createListingKeeper to accept affiliatesKeeper and updated its usage in the ListingKeepers function.
protocol/testutil/keeper/rewards.go Added affiliatesKeeper parameter to the createFeeTiersKeeper call within the RewardsKeepers function.

Possibly related PRs

Suggested labels

indexer, proto

Suggested reviewers

  • jayy04

Poem

🐇
In the fields where changes bloom,
Affiliates rise, dispelling gloom.
With fees adjusted, all is fair,
Hopping 'round without a care!
New keepers join the joyful fray,
Bringing light to every day!
🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 44432d4 and 52cff79.

📒 Files selected for processing (3)
  • protocol/testutil/keeper/clob.go (1 hunks)
  • protocol/testutil/keeper/listing.go (1 hunks)
  • protocol/testutil/keeper/rewards.go (1 hunks)

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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@affanv14 affanv14 force-pushed the affan/fee-tier branch 2 times, most recently from e610afc to 44bace9 Compare September 5, 2024 21:56
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: 3

Outside diff range, codebase verification and nitpick comments (4)
protocol/x/feetiers/types/expected_keepers.go (1)

19-22: New interface AffiliatesKeeper added.

The addition of the AffiliatesKeeper interface with the GetReferredBy method is well-implemented. However, it would be beneficial to add documentation to explain the purpose and usage of this interface and its method to aid future developers.

Consider adding comments like:

// AffiliatesKeeper defines the expected affiliates keeper.
// It provides methods to manage and retrieve affiliate relationships.
type AffiliatesKeeper interface {
    // GetReferredBy returns the referrer of the given referee.
    // The boolean return value indicates whether a referrer was found.
    GetReferredBy(ctx sdk.Context, referee string) (string, bool)
}
protocol/testutil/keeper/affiliates.go (1)

12-28: Function createAffiliatesKeeper implemented correctly.

The implementation of createAffiliatesKeeper is correct and follows best practices for dependency injection and store setup. However, adding documentation would enhance understandability and maintainability.

Consider adding function documentation like:

// createAffiliatesKeeper initializes a new instance of AffiliatesKeeper.
// It configures the keeper with necessary dependencies and store configurations.
func createAffiliatesKeeper(
    stateStore storetypes.CommitMultiStore,
    db *dbm.MemDB,
    cdc *codec.ProtoCodec,
    statsKeeper *statskeeper.Keeper,
) (*affiliateskeeper.Keeper, storetypes.StoreKey) {
    // function body
}
protocol/testutil/keeper/feetiers.go (1)

Line range hint 22-39: Integration of affiliatesKeeper into createFeeTiersKeeper.

The modification to include affiliatesKeeper in createFeeTiersKeeper is correctly implemented. This change allows for enhanced functionality by integrating affiliate management into the fee tiers logic. It is recommended to add tests to verify this integration and ensure that it functions as expected without introducing regressions.

Would you like assistance in writing the integration tests for this modification?

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

23-23: Add documentation for affiliatesKeeper.

The addition of affiliatesKeeper to the Keeper struct is correctly implemented. However, it would be beneficial to add documentation explaining its role and interactions within the Keeper.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3faadf9 and 44bace9.

Files selected for processing (10)
  • protocol/app/app.go (2 hunks)
  • protocol/testutil/keeper/affiliates.go (1 hunks)
  • protocol/testutil/keeper/clob.go (1 hunks)
  • protocol/testutil/keeper/feetiers.go (3 hunks)
  • protocol/testutil/keeper/listing.go (1 hunks)
  • protocol/testutil/keeper/rewards.go (1 hunks)
  • protocol/x/feetiers/keeper/keeper.go (2 hunks)
  • protocol/x/feetiers/keeper/keeper_test.go (2 hunks)
  • protocol/x/feetiers/types/constants.go (1 hunks)
  • protocol/x/feetiers/types/expected_keepers.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/feetiers/types/constants.go
Additional context used
Learnings (1)
protocol/x/feetiers/types/expected_keepers.go (1)
Learnt from: teddyding
PR: dydxprotocol/v4-chain#2141
File: protocol/x/affiliates/types/expected_keepers.go:9-11
Timestamp: 2024-08-22T20:17:56.228Z
Learning: Always use pointers for `big.Int` return types in interfaces to avoid unnecessary copying.
Additional comments not posted (4)
protocol/x/feetiers/keeper/keeper.go (1)

30-39: Constructor function NewKeeper correctly initializes affiliatesKeeper.

The updated NewKeeper function properly initializes the Keeper struct with the new affiliatesKeeper parameter. The parameter ordering and initialization are correctly handled.

protocol/x/feetiers/keeper/keeper_test.go (1)

136-204: Well-structured test function for perpetual fee calculation with referrals.

The test function TestGetPerpetualFeePpm_Referral is well-structured and effectively tests the perpetual fee calculation for users with and without referrals. The use of a setup function to configure the test environment is appropriate, and the test cases cover relevant scenarios.

Consider adding more test cases if there are additional scenarios or edge cases that could affect the perpetual fee calculation.

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

142-152: Enhanced test setup with integration of affiliatesKeeper.

The modifications to the NewClobKeepersTestContextWithUninitializedMemStore function effectively integrate the affiliatesKeeper into the test setup. This enhancement allows the fee tiers module to potentially access affiliate-related functionalities, aligning with the PR objectives.

Ensure that all dependencies and interactions with the affiliatesKeeper are correctly handled and tested.

protocol/app/app.go (1)

1026-1039: Cohesive architecture with enhanced integration of AffiliatesKeeper.

The modifications to the initialization of the AffiliatesKeeper and the updates to the FeeTiersKeeper reflect a more cohesive architecture. The integration of the AffiliatesKeeper with the StatsKeeper enhances the management of affiliate relationships and fee tier calculations. The updates to the FeeTiersKeeper suggest improved functionality related to affiliate management.

Ensure that the new functionalities are thoroughly tested to verify correct integration and operation within the application.

Comment on lines 103 to 111
// Bump up to RefereeStartingFeeTier if the user is referred by an affiliate.
// We subtract 1 because the fee tiers are 1-indexed.
if idx < types.RefereeStartingFeeTier-1 {
_, hasReferree := k.affiliatesKeeper.GetReferredBy(ctx, address)
if hasReferree {
idx = types.RefereeStartingFeeTier - 1
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Review the affiliate referral logic in getUserFeeTier.

The modification to getUserFeeTier to incorporate affiliate referral logic is correctly implemented. However, consider adding error handling or logging for the call to GetReferredBy to ensure that any issues in fetching referral data are appropriately managed.

Comment on lines 93 to 103
affiliatesKeeper, _ := createAffiliatesKeeper(
stateStore,
db,
cdc,
statsKeeper,
)
feetiersKeeper, _ = createFeeTiersKeeper(
stateStore,
statsKeeper,
vaultKeeper,
affiliatesKeeper,
Copy link
Contributor

Choose a reason for hiding this comment

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

Proper integration of affiliatesKeeper in RewardsKeepers.

The creation and integration of affiliatesKeeper using createAffiliatesKeeper and its subsequent passing to createFeeTiersKeeper are correctly implemented. However, consider adding error handling in the createAffiliatesKeeper function to manage potential initialization failures effectively.

Comment on lines 115 to 125
affiliatesKeeper, _ := createAffiliatesKeeper(
stateStore,
db,
cdc,
statsKeeper,
)
feeTiersKeeper, _ := createFeeTiersKeeper(
stateStore,
statsKeeper,
vaultKeeper,
affiliatesKeeper,
Copy link
Contributor

Choose a reason for hiding this comment

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

Proper integration of affiliatesKeeper in ListingKeepers.

The creation and integration of affiliatesKeeper using createAffiliatesKeeper and its subsequent passing to createFeeTiersKeeper are correctly implemented. However, consider adding error handling in the createAffiliatesKeeper function to manage potential initialization failures effectively.

@@ -97,6 +100,15 @@ func (k Keeper) getUserFeeTier(ctx sdk.Context, address string) (uint32, *types.
idx = uint32(i)
}

// Bump up to RefereeStartingFeeTier if the user is referred by an affiliate.
// We subtract 1 because the fee tiers are 1-indexed.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit annoying that we have to do this, thanks for being attentive to details here.

Feel like below would be cleaner:

  • Rename constant to RefereeStartingFeeTierIndex, make this 2, and add a comment this is 0-indexed and refers to the index of the feeTiers array instead of fee tier name. This way we aren't making assumption that fee tier name is well aligned to the indexes.

tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()
k := tApp.App.FeeTiersKeeper
err := k.SetPerpetualFeeParams(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: take this object to the top of function:

testPerpetualFeeParams := ....

err := affiliatesKeeper.RegisterAffiliate(ctx, constants.AliceAccAddress.String(), constants.BobAccAddress.String())
require.NoError(t, err)
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add two test cases that a user already at and larger than StartingFeeTier still gets correct fee tier

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 44bace9 and a4da10d.

Files selected for processing (10)
  • protocol/app/app.go (2 hunks)
  • protocol/testutil/keeper/affiliates.go (1 hunks)
  • protocol/testutil/keeper/clob.go (1 hunks)
  • protocol/testutil/keeper/feetiers.go (3 hunks)
  • protocol/testutil/keeper/listing.go (1 hunks)
  • protocol/testutil/keeper/rewards.go (1 hunks)
  • protocol/x/feetiers/keeper/keeper.go (2 hunks)
  • protocol/x/feetiers/keeper/keeper_test.go (2 hunks)
  • protocol/x/feetiers/types/constants.go (1 hunks)
  • protocol/x/feetiers/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • protocol/testutil/keeper/affiliates.go
  • protocol/testutil/keeper/clob.go
  • protocol/testutil/keeper/feetiers.go
  • protocol/testutil/keeper/listing.go
  • protocol/testutil/keeper/rewards.go
  • protocol/x/feetiers/keeper/keeper.go
  • protocol/x/feetiers/keeper/keeper_test.go
  • protocol/x/feetiers/types/constants.go
  • protocol/x/feetiers/types/expected_keepers.go
Additional comments not posted (2)
protocol/app/app.go (2)

1026-1035: Review of AffiliatesKeeper Initialization

The initialization of AffiliatesKeeper has been updated to include a dependency on StatsKeeper. This change aligns with the PR's objective to enhance the fee model by potentially using statistical data in fee calculations.

  • Correctness: The initialization appears correct and follows the typical pattern for keeper initialization in the Cosmos SDK.
  • Performance: No immediate concerns as the initialization happens once and the impact on runtime performance should be minimal.
  • Maintainability: The addition of StatsKeeper as a dependency is clearly stated, making the code easy to understand and maintain.

Overall, the changes are aligned with the PR objectives and are implemented correctly.


Line range hint 1039-1049: Review of FeeTiersKeeper Initialization

The FeeTiersKeeper now includes AffiliatesKeeper as a parameter. This modification is crucial for the PR's goal to integrate affiliate data into fee tier calculations.

  • Correctness: The code correctly passes the AffiliatesKeeper into the FeeTiersKeeper. This ensures that the fee tier logic can access affiliate-related functionalities.
  • Security: No security issues are apparent in this change.
  • Maintainability: The change is minimal and does not complicate the existing code structure. It is also well-documented through the code itself, making it easy to understand the new dependency.

This change is essential for achieving the PR's objectives and is implemented correctly.

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