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-816] Update Revshare logic for affiliates #2298

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

affanv14
Copy link
Contributor

@affanv14 affanv14 commented Sep 19, 2024

Changelist

[Describe or list the changes made in this PR]

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 revenue sharing calculations to include affiliate fee impacts, improving accuracy in revenue distribution.
  • Bug Fixes

    • Adjusted expected balances in fee distribution tests to reflect updated revenue share logic.
  • Refactor

    • Streamlined test cases by removing scenarios related to exceeding net fees, indicating a refined focus in revenue sharing behavior.

@affanv14 affanv14 requested a review from a team as a code owner September 19, 2024 18:42
Copy link

linear bot commented Sep 19, 2024

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes enhance the revenue sharing functionality by modifying the GetAllRevShares and getAffiliateRevShares methods in the Keeper struct. A new return value in getAffiliateRevShares allows for the calculation of net fees after deducting shared affiliate fees. This adjustment refines the revenue share calculations for affiliates and market mappers. Additionally, test cases have been updated to reflect changes in revenue share configurations and to simplify invalid scenario checks.

Changes

File Path Change Summary
protocol/x/revshare/keeper/revshare.go Modified getAffiliateRevShares to return an additional *big.Int representing total fees shared, impacting how GetAllRevShares calculates net fees and revenue shares. Updated fee source for revenue shares to align with new logic.
protocol/x/revshare/keeper/revshare_test.go Adjusted revenue share configurations with reduced QuoteQuantums for various recipients. Removed test cases for exceeding net fees from market mappers and affiliates, indicating a shift in focus for tests.
protocol/x/rewards/keeper/keeper.go Updated AddRewardSharesForFill function to reference the new revenue source, changing from net fee to net protocol revenue for reward calculations.
protocol/x/rewards/keeper/keeper_test.go Modified test cases to reflect the updated RevShareFeeSource values, ensuring alignment with the new revenue sharing logic.
protocol/x/subaccounts/keeper/transfer.go Updated DistributeFees function to use the new revenue source key, changing from net fee to net protocol revenue in fee distribution logic.

Possibly related PRs

Suggested labels

feature:indexer/affiliates

Poem

🐰 In the fields where numbers play,
Revenue shares find their way.
Affiliates dance, fees align,
With new logic, all is fine.
Hopping forth, we celebrate,
Changes sweet, oh, what a fate! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2060d21 and 3f21cf6.

Files selected for processing (6)
  • protocol/x/revshare/keeper/revshare.go (5 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (10 hunks)
  • protocol/x/revshare/types/types.go (1 hunks)
  • protocol/x/rewards/keeper/keeper.go (1 hunks)
  • protocol/x/rewards/keeper/keeper_test.go (4 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/revshare/keeper/revshare_test.go
Additional comments not posted (11)
protocol/x/revshare/types/types.go (1)

44-44: Verify the usage of the renamed constant across the codebase.

The renaming of the constant from REV_SHARE_FEE_SOURCE_NET_FEE to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE improves the clarity and specificity of the constant name. It indicates that the revenue source is specifically related to protocol operations rather than a general net fee.

Please ensure that all references to this constant have been updated consistently across the codebase to avoid compile-time errors and maintain the correct semantics.

Run the following script to verify the constant usage:

Verification successful

Constant renaming verified successfully across the codebase.

The renaming of REV_SHARE_FEE_SOURCE_NET_FEE to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE has been implemented consistently throughout the codebase. The old constant name is not present, and the new constant name is used correctly in multiple files, including keeper functions, test cases, and type definitions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the renamed constant across the codebase.

# Test 1: Search for the old constant name. Expect: No occurrences.
rg --type go $'REV_SHARE_FEE_SOURCE_NET_FEE'

# Test 2: Search for the new constant name. Expect: Only valid occurrences.
rg --type go -A 5 $'REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE'

Length of output: 20321

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

166-167: LGTM!

The initialization of fee source maps with the new key REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE aligns with the updated revenue sharing logic to use net protocol revenue.


174-179: Calculation of net protocol revenue looks good!

The updated logic correctly calculates netFeesSubAffiliateFeesShared by deducting affiliateFeesShared from netFees. This ensures that unconditional revenue shares are calculated based on the net protocol revenue after accounting for affiliate fees.


184-184: Market mapper revenue shares calculation is updated correctly!

The function now uses netFeesSubAffiliateFeesShared to calculate market mapper revenue shares, ensuring consistency with the updated net protocol revenue calculation.


Line range hint 227-251: Affiliate revenue shares function updates are valid!

The updated getAffiliateRevShares function now returns the total affiliate fees shared along with the affiliate revenue shares. This enables accurate calculation of net protocol revenue in the calling function.

Returning big.NewInt(0) instead of nil in error cases and when no affiliate revenue share exists ensures a consistent return type and avoids potential nil pointer dereferences.


267-267: Unconditional revenue shares fee source update is correct!

Setting the RevShareFeeSource to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE for unconditional revenue shares aligns with the updated revenue sharing logic to use net protocol revenue.


294-294: Market mapper revenue shares fee source update is correct!

Setting the RevShareFeeSource to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE for market mapper revenue shares aligns with the updated revenue sharing logic to use net protocol revenue.

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

143-143: Verify the impact of the revenue share percentage source change.

The change from revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE to revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE suggests a shift in the source of revenue being referenced for calculating the total net fee revenue share. This could potentially impact how rewards are calculated and distributed, aligning the reward mechanism more closely with overall protocol performance.

To verify the impact of this change, consider running the following script:

Please review the results of the above tests to ensure that the rewards are being calculated and distributed as expected based on the protocol revenue.

Verification successful

Approve the change from NET_FEE to NET_PROTOCOL_REVENUE

The change from REV_SHARE_FEE_SOURCE_NET_FEE to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE has been consistently implemented across the codebase, including in the AddRewardSharesForFill function and related test files. This modification affects the calculation of totalNetFeeRevSharePpm, which in turn impacts the reward distribution for both takers and makers.

The rename appears to be part of a deliberate effort to more accurately represent the source of funds used for rewards, shifting from a general "net fee" concept to a more specific "net protocol revenue" terminology. This change has been properly reflected in the implementation and thoroughly tested, indicating a well-executed and intentional modification to the reward system.

Given the comprehensive nature of the change and its consistent application, the modification is approved and can be considered verified.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the revenue share percentage source change on reward calculation and distribution.

# Test 1: Search for usages of `revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE` in the rewards module.
# Expect: References in reward calculation and distribution logic.
rg --type go -A 5 $'revsharetypes\.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE' protocol/x/rewards

# Test 2: Search for reward calculation logic that uses the total net fee revenue share.
# Expect: Logic that calculates rewards based on the protocol revenue.
ast-grep --lang go --pattern $'func $$$($$$) {
  $$$
  totalNetFeeRevSharePpm := $$$
  $$$
}'

# Test 3: Search for reward distribution logic that uses the calculated rewards.
# Expect: Logic that distributes the calculated rewards to users.
ast-grep --lang go --pattern $'func $$$($$$) {
  $$$
  rewardAmountForAddress := $$$
  $$$
}'

Length of output: 5611


Script:

#!/bin/bash
# Description: Gather more information about the impact of the revenue share percentage source change.

# Test 1: View the full implementation of AddRewardSharesForFill
echo "=== AddRewardSharesForFill Implementation ==="
ast-grep --lang go --pattern 'func (k Keeper) AddRewardSharesForFill($$$) {
  $$$
}'

# Test 2: Search for other usages of totalNetFeeRevSharePpm
echo "=== Other usages of totalNetFeeRevSharePpm ==="
rg --type go -A 5 'totalNetFeeRevSharePpm'

# Test 3: Search for comments or documentation related to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE
echo "=== Documentation for REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE ==="
rg --type go -A 5 'REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE.*//|// .*REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE'

# Test 4: Look for any recent changes or discussions related to this constant
echo "=== Recent changes or discussions ==="
git log -p -S "REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE" -- protocol/x/rewards

Length of output: 15340

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

271-272: Verify the impact of updating the net protocol revenue key.

The key used to access the net protocol revenue from the FeeSourceToQuoteQuantums map has been updated from revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE to revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE.

This change suggests a more precise categorization of revenue sources within the fee distribution logic. Please ensure that this update aligns with the intended revenue sharing mechanism and doesn't introduce any unintended consequences in the calculation and distribution of fees.

Verification successful

Change consistently applied, manual verification recommended

The update from REV_SHARE_FEE_SOURCE_NET_FEE to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE has been consistently applied across the codebase. The new key is correctly used in relevant fee distribution logic in the following files:

  • protocol/x/subaccounts/keeper/transfer.go
  • protocol/x/rewards/keeper/keeper.go
  • protocol/x/rewards/keeper/keeper_test.go

The change appears to be systematically implemented, affecting both core logic and test files. However, to ensure complete correctness, we recommend a final manual review to verify that the semantic meaning of the net protocol revenue is accurately represented in all contexts where it's used.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated net protocol revenue key.

# Test 1: Search for usage of the old key. Expect: No occurrences.
rg --type go $'revsharetypes\\.REV_SHARE_FEE_SOURCE_NET_FEE'

# Test 2: Search for usage of the new key. Expect: Only occurrences in relevant fee distribution logic.
rg --type go -A 5 $'revsharetypes\\.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE'

Length of output: 5950

protocol/x/rewards/keeper/keeper_test.go (2)

346-346: LGTM!

The change in RevShareFeeSource from NET_FEE to NET_PROTOCOL_REVENUE aligns with the test case description.


353-354: The mapping changes are consistent with the shift to net protocol revenue.

Updating the mappings to use REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE instead of REV_SHARE_FEE_SOURCE_NET_FEE, and adding REV_SHARE_FEE_SOURCE_TAKER_FEE with a value of 0, aligns with the test case description and the change in RevShareFeeSource.

Also applies to: 357-358


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.

@@ -856,52 +856,6 @@ func TestKeeper_GetAllRevShares_Invalid(t *testing.T) {
require.NoError(t, err)
},
},
{
name: "Total fees shared exceeds net fees from market mapper and affiliates",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests wont work anymore

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

Outside diff range and nitpick comments (2)
protocol/x/revshare/keeper/revshare.go (2)

Line range hint 227-251: Update unit tests to cover changes in getAffiliateRevShares

The function getAffiliateRevShares now returns an additional *big.Int representing affiliateFeesShared. Ensure that unit tests are updated or added to cover this new return value and to verify the correctness of affiliateFeesShared in various scenarios.


227-227: Document the new return value in getAffiliateRevShares

Update the function comment for getAffiliateRevShares to include information about the new *big.Int return value affiliateFeesShared. This helps maintain clarity for future maintainers.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cee80fc and 2060d21.

Files selected for processing (3)
  • protocol/x/revshare/keeper/revshare.go (3 hunks)
  • protocol/x/revshare/keeper/revshare_test.go (8 hunks)
  • protocol/x/subaccounts/keeper/transfer_test.go (1 hunks)
Additional comments not posted (5)
protocol/x/revshare/keeper/revshare_test.go (2)

Line range hint 337-364: LGTM!

The changes in the test cases consistently reduce the expected QuoteQuantums for various recipients and fee sources. This suggests a deliberate adjustment in the revenue share calculation, potentially to align with updated business requirements or to optimize the distribution of fees among the participants.

The reductions appear to be proportional across the test cases, maintaining the overall integrity of the revenue share logic. The updated values should be verified against the intended revenue share model to ensure accuracy.


Line range hint 848-860: Verify the reason for removing the test cases.

The test cases that specifically checked for exceeding net fees from market mappers and affiliates have been removed. This suggests a change in the validation logic or requirements related to these entities.

Please confirm the following:

  1. Is the validation for exceeding net fees from market mappers and affiliates still necessary? If not, please provide the rationale for removing these test cases.
  2. Are there any alternative mechanisms in place to validate the fee distribution for market mappers and affiliates?

Ensuring comprehensive test coverage is crucial for maintaining the integrity of the revenue share system. If the removed test cases are no longer relevant, please consider adding comments to document the reasons for their removal.

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

1503-1506: LGTM!

The updated expected balances for the fee module account, market mapper account, affiliate account, and unconditional rev share account are calculated correctly based on the respective revenue share percentages.

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

184-184: Ensure getMarketMapperRevShare handles updated net fees correctly

Passing the adjusted netFeesSubAffiliateFeesShared to getMarketMapperRevShare is appropriate. Verify that getMarketMapperRevShare correctly handles cases where the net fees might be reduced due to affiliate fee sharing.


Line range hint 227-251: Ensure all callers handle the new return value from getAffiliateRevShares

With the addition of the new return value *big.Int, verify that all callers of getAffiliateRevShares have been updated to handle the extra return parameter to prevent potential runtime errors.

Run the following script to identify all usages of getAffiliateRevShares:

Verification successful

To ensure a comprehensive verification, we need to perform two additional checks. First, let's search for any other potential usages of the function, and then we'll examine the context around the function call we found.


Changes to getAffiliateRevShares have been correctly implemented

The verification process has confirmed that the new return value from getAffiliateRevShares is being properly handled in its only usage within the codebase. The function call correctly assigns three variables, including the new affiliateFeesShared return value, which is then used in subsequent calculations. No other calls to this function were found in the codebase, so no further updates are necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of `getAffiliateRevShares` to ensure they are handling the new return value.

# Search for the function calls in the Go codebase.
rg --type go --fixed-strings 'getAffiliateRevShares(' -A 2

Length of output: 550


Script:

#!/bin/bash
# Search for any mentions of 'getAffiliateRevShares' in the entire codebase
rg --type go 'getAffiliateRevShares'

# Show more context around the function call we found
rg --type go --fixed-strings 'getAffiliateRevShares(' -B 5 -A 10

Length of output: 2723

Comment on lines +174 to +179
affiliateRevShares, affiliateFeesShared, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap)
if err != nil {
return types.RevSharesForFill{}, err
}

unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFees)
netFeesSubAffiliateFeesShared := big.NewInt(0).Sub(netFees, affiliateFeesShared)
unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFeesSubAffiliateFeesShared)
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify that netFeesSubAffiliateFeesShared is non-negative after subtraction

Subtracting affiliateFeesShared from netFees may result in netFeesSubAffiliateFeesShared becoming negative if affiliateFeesShared exceeds netFees. This could lead to unexpected behavior in subsequent revenue share calculations.

Consider adding a check to ensure netFeesSubAffiliateFeesShared is not negative, or handle scenarios where it could be zero or negative appropriately.

}

takerAffiliateAddr, feeSharePpm, exists, err := k.affiliatesKeeper.GetTakerFeeShare(
ctx, takerAddr, affiliatesWhitelistMap)
if err != nil {
return nil, err
return nil, big.NewInt(0), err
Copy link
Contributor

Choose a reason for hiding this comment

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

Return nil for affiliateFeesShared when an error occurs

In the error case at line 237, consider returning nil for affiliateFeesShared instead of big.NewInt(0). This makes it clear that the value is invalid due to the error, aligning with common Go practices.

Apply this diff to adjust the return value:

-return nil, big.NewInt(0), err
+return nil, nil, 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
return nil, big.NewInt(0), err
return nil, nil, err

@@ -171,17 +171,17 @@ func (k Keeper) GetAllRevShares(
makerFees := fill.MakerFeeQuoteQuantums
Copy link
Contributor

@teddyding teddyding Sep 19, 2024

Choose a reason for hiding this comment

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

Let's also change REV_SHARE_FEE_SOURCE_NET_FEE to REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE to disambiguate

NET_FEE could be understood as taker fee minus rebates


totalFeesShared := big.NewInt(0)
takerFees := fill.TakerFeeQuoteQuantums
makerFees := fill.MakerFeeQuoteQuantums
netFees := big.NewInt(0).Add(takerFees, makerFees)

affiliateRevShares, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap)
affiliateRevShares, affiliateFeesShared, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap)
if err != nil {
return types.RevSharesForFill{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on caller function persistMatchedOrders:

Instead propagating error returned from GetAllRevShares (which would ultimately fail the match transaction), it's better to just pass in empty RevSharesForFill to DistributeFees. This way if any rev share calculation encounters issue, the chain will continue to be able to process matches (without rev share).

Order matching + rev share both working > Only order matching working > Order matching not working

if err != nil {
return types.RevSharesForFill{}, err
}

unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFees)
netFeesSubAffiliateFeesShared := big.NewInt(0).Sub(netFees, affiliateFeesShared)
Copy link
Contributor

Choose a reason for hiding this comment

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

For sanity check, let's return error if netFeesSubAffiliateFeesShared <= 0

if err != nil {
return types.RevSharesForFill{}, err
}

unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFees)
netFeesSubAffiliateFeesShared := big.NewInt(0).Sub(netFees, affiliateFeesShared)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
netFeesSubAffiliateFeesShared := big.NewInt(0).Sub(netFees, affiliateFeesShared)
netFeesSubAffiliateFeesShared := new(big.Int).Sub(
netFees,
affiliateFeesShared,
)


unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFees)
netFeesSubAffiliateFeesShared := big.NewInt(0).Sub(netFees, affiliateFeesShared)
unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFeesSubAffiliateFeesShared)
Copy link
Contributor

Choose a reason for hiding this comment

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

For getMarketMapperRevShare and getUnconditionalRevShares update input variable name from netFees to netFeesSubAffiliateFeesShared

@@ -1500,10 +1500,10 @@ func TestDistributeFees(t *testing.T) {
MonthlyRollingTakerVolumeQuantums: 1_000_000,
},
expectedSubaccountsModuleAccBalance: big.NewInt(100), // 600 - 500
expectedFeeModuleAccBalance: big.NewInt(2888), // 2500 + 500 - 50
expectedMarketMapperAccBalance: big.NewInt(50), // 10% of 500
expectedFeeModuleAccBalance: big.NewInt(2892), // 2500 + 500 - 108
Copy link
Contributor

Choose a reason for hiding this comment

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

Realized that we aren't purely testing DistributeFees function in here, but it's more of an e2e test on affiliate + rev share + distribute fees. This isn't the best practice - should have a function that exclusively tests DistributeFees, which doesn't rely on affiliatesKeeper or revshareKeeper. (We should also remove delete the revShareKeeper on subaccountsKeeper

@@ -332,23 +332,23 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) {
},
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding, how did we set up the tier for Bob in this test case? Didn't find anything related in the setUp()

@@ -420,33 +420,33 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) {
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on line 411: negative unconditional and market mapper doesn't make sense - did you mean maker fee is negative

RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL,
QuoteQuantums: big.NewInt(1_600_000),
QuoteQuantums: big.NewInt(1_300_000),
Copy link
Contributor

@teddyding teddyding Sep 20, 2024

Choose a reason for hiding this comment

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

At least for one of the test cases, could we add comment on math behind these expected values? For example,

						QuoteQuantums:     big.NewInt(1_300_000), // (10 - 2 - 10 * 0.15) * 20% = 1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants