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-817] update trading rewards with new logic #2300

Merged
merged 13 commits into from
Sep 24, 2024

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

    • Increased the maximum allowable volume for referees from 25 million USDC to 50 million USDC over a 30-day period, enhancing financial capacity for referee transactions.
    • Refined the logic for calculating taker fee revenue shares, improving the accuracy of reward distribution based on taker volume.
  • Bug Fixes

    • Adjusted the expected weight calculation for reward shares, ensuring accurate distribution between takers and makers.
    • Updated expected balances and reward calculations for various accounts, reflecting the revised reward distribution mechanics.

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

linear bot commented Sep 19, 2024

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Warning

Rate limit exceeded

@teddyding has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 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

Reviewing files that changed from the base of the PR and between 6fada43 and f4d0f93.

Walkthrough

The pull request introduces significant updates to the revenue sharing mechanism, including the renaming and value increase of the constant Max30dRefereeVolumeQuantums to MaxReferee30dVolumeForAffiliateShareQuantums, raising its value from 25 million USDC to 50 million USDC. Additionally, it modifies the logic for calculating taker fee revenue shares and updates relevant test cases to reflect these changes, enhancing the clarity and functionality of the revenue sharing calculations within the application.

Changes

File Path Change Summary
protocol/x/revshare/types/constants.go Updated Max30dRefereeVolumeQuantums to MaxReferee30dVolumeForAffiliateShareQuantums and increased its value from 25 million USDC to 50 million USDC.
protocol/x/revshare/keeper/revshare.go Modified the condition in getAffiliateRevShares to compare against the new constant MaxReferee30dVolumeForAffiliateShareQuantums.
protocol/x/revshare/keeper/revshare_test.go Updated the test case TestKeeper_GetAllRevShares_Valid to use the new constant for MonthlyRollingTakerVolumeQuantums.
protocol/x/rewards/keeper/keeper.go Revised the logic for calculating total taker fee revenue share, clarifying the relationship between taker volume and maximum possible revenue share based on the new constant.
protocol/x/rewards/keeper/keeper_test.go Adjusted expected weight calculations for expectedTakerShare and incorporated scenarios involving the new constant in the test case TestAddRewardSharesForFill.
protocol/testing/e2e/trading_rewards/trading_rewards_test.go Updated the TestTradingRewards function to reflect new expected balances and reward calculations across multiple accounts, ensuring alignment with the revised reward distribution logic.

Possibly related PRs

Suggested labels

revshare, performance

Suggested reviewers

  • roy-dydx
  • teddyding

🐰 In the meadow, changes bloom,
With numbers rising, there's more room.
Referees cheer, their volumes soar,
Takers rejoice, rewards galore!
A hop, a skip, a joyful dance,
In this code, we take our chance! 🌼


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.

// 25 million USDC
Max30dRefereeVolumeQuantums = uint64(25_000_000_000_000)
// 50 million USDC
Max30dRefereeVolumeQuantums = uint64(50_000_000_000_000)
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
Max30dRefereeVolumeQuantums = uint64(50_000_000_000_000)
MaxReferee30dVolumeForAffiliateShareQuantums= uint64(50_000_000_000_000)

For accuracy

if value, ok := revSharesForFill.FeeSourceToQuoteQuantums[revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE]; ok {
totalTakerFeeRevShareQuantums = value

// taker revshare is not returned if taker volume is greater than Max30dTakerVolumeQuantums
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't using Max30dRefereeVolumeQuantums below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We dont need to - since no taker revshares are returned over 50 million - the if condition is never hit for value > 0

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.

The new trading rewards logic is below:

If taker volume is <50M (equal statement: they would generate affiliate rev share if referred), then the max possible affiliate rev share is deducted from their trading rewards score.

The following implementation doesn't work correctly for a non-referred user under 50M volume

@@ -144,8 +145,14 @@ func (k Keeper) AddRewardSharesForFill(
totalNetFeeRevSharePpm = value
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's modify function documentation as needed

@@ -483,7 +483,7 @@ func TestAddRewardSharesForFill(t *testing.T) {
},
expectedTakerShare: types.RewardShare{
Address: takerAddress,
Weight: dtypes.NewInt(900_000), // (2 - 0.1% * 800 - 0.2) * (1 - 0.1)
Weight: dtypes.NewInt(180_000), // (2 - 0.1% * 800 - 1) * (1 - 0.1)
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.

Could we cover the following (may already be covered in current tests):

  • Deduct MaxPossibleAffiliateRevShare for non-referred user <50M trailing volume
  • Deduct MaxPossibleAffiliateRevShare for referred user <50M trailing volume
  • Don't deduct MaxPossibleAffiliateRevShare for non-referred or referred user >=50M trailing volume

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first two are covered by existing tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrote a test for the 3rd one

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, which one tests 1 (Deduct MaxPossibleAffiliateRevShare for non-referred user <50M trailing volume)?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
protocol/x/rewards/keeper/keeper_test.go (1)

486-486: Address suggested test cases from previous comment

Regarding the previous comment by teddyding, it's important to ensure comprehensive test coverage. While the new test cases cover some aspects, please consider adding explicit tests for the following scenarios:

  1. Deduct MaxPossibleAffiliateRevShare for non-referred user <50M trailing volume
  2. Deduct MaxPossibleAffiliateRevShare for referred user <50M trailing volume
  3. Don't deduct MaxPossibleAffiliateRevShare for non-referred or referred user >=50M trailing volume

Adding these test cases will improve the robustness of the test suite and ensure that all edge cases are properly handled.

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

507-507: LGTM! Consider adding a comment explaining the significance of this value.

The change from Max30dRefereeVolumeQuantums to MaxReferee30dVolumeForAffiliateShareQuantums is appropriate and more descriptive. It accurately reflects the purpose of this constant in the context of affiliate share calculations.

Consider adding a brief comment explaining why we're using MaxReferee30dVolumeForAffiliateShareQuantums + 1. This would help clarify that we're testing the case where the volume just exceeds the maximum threshold for affiliate share eligibility.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e422bb and 61a4542.

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

493-547: New test case for high-volume traders looks good

The new test case for monthly rolling taker volume > 50 million is a valuable addition. It covers an important scenario for high-volume traders and includes revenue sharing for both net fee and taker fee. The expected weights are:

  1. Taker weight: (2 - 0.1% * 800 - 0) * (1 - 0.1) = 1,080,000
  2. Maker weight: 1 * (1 - 0.1) = 900,000

These calculations seem consistent with the intended logic. However, to ensure completeness:

  1. Consider adding a test case for a scenario just below the 50 million threshold to verify the boundary condition.
  2. Verify if there are any other volume-based thresholds that should be tested.
#!/bin/bash
# Check for other volume thresholds in the codebase
rg --type go "MonthlyRollingTakerVolumeQuantums"

486-491: Verify the calculation of taker and maker weights

The calculation of taker and maker weights has been updated. Please ensure these calculations are correct:

  1. Taker weight: (2 - 0.1% * 800 - 1) * (1 - 0.1) = 180,000
  2. Maker weight: 1 * (1 - 0.1) = 900,000

These calculations seem to account for fee reductions and revenue sharing. However, it's important to verify that these align with the intended business logic.

@@ -227,7 +227,7 @@ func (k Keeper) getAffiliateRevShares(
) ([]types.RevShare, error) {
takerAddr := fill.TakerAddr
takerFee := fill.TakerFeeQuoteQuantums
if fill.MonthlyRollingTakerVolumeQuantums >= types.Max30dRefereeVolumeQuantums {
if fill.MonthlyRollingTakerVolumeQuantums >= types.MaxReferee30dVolumeForAffiliateShareQuantums {
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Issues Detected with the Recent Change.

  • The old threshold constant Max30dRefereeVolumeQuantums was not found in the codebase. Please confirm if its removal is intentional.

  • No existing test cases were identified for getAffiliateRevShares or the new threshold MaxReferee30dVolumeForAffiliateShareQuantums. It is crucial to add appropriate tests to validate the new threshold's functionality and ensure no regressions.

Analysis chain

Approve change with suggestions for verification and documentation.

The update to use types.MaxReferee30dVolumeForAffiliateShareQuantums as the threshold for affiliate revenue shares looks good. This change appears to refine the eligibility criteria for affiliate shares based on the monthly rolling taker volume.

To ensure this change doesn't have unintended consequences:

  1. Please verify the relative values of types.Max30dRefereeVolumeQuantums (old) and types.MaxReferee30dVolumeForAffiliateShareQuantums (new).
  2. Confirm that this change aligns with the intended business logic for affiliate revenue sharing.

Consider updating any related documentation or comments that explain the affiliate revenue share eligibility criteria to reflect this change.

Ensure thorough testing of this change:

  1. Test cases where MonthlyRollingTakerVolumeQuantums is just below, at, and just above the new threshold.
  2. Verify that the behavior for edge cases (e.g., MonthlyRollingTakerVolumeQuantums = 0 or very large values) remains correct.

If no relevant tests are found, please add appropriate test cases to cover this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare the old and new threshold values
# Expected result: The new threshold should be intentionally different from the old one

# Search for the old constant
echo "Old threshold:"
rg --type go "Max30dRefereeVolumeQuantums\s*=\s*" --no-filename

# Search for the new constant
echo "New threshold:"
rg --type go "MaxReferee30dVolumeForAffiliateShareQuantums\s*=\s*" --no-filename

Length of output: 301


Script:

#!/bin/bash
# Description: Check for existing tests related to this threshold
# Expected result: There should be test cases covering various scenarios around the threshold

rg --type go -C 5 "TestGetAffiliateRevShares|TestMaxReferee30dVolumeForAffiliateShareQuantums" ./protocol/x/revshare

Length of output: 118

@@ -152,7 +153,7 @@ func (k Keeper) AddRewardSharesForFill(

// taker revshare is not returned if taker volume is greater than Max30dTakerVolumeQuantums
if value, ok := revSharesForFill.FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE]; ok &&
value > 0 {
value > 0 && fill.MonthlyRollingTakerVolumeQuantums < revsharetypes.MaxReferee30dVolumeForAffiliateShareQuantums {
totalTakerFeeRevShareQuantums = lib.BigMulPpm(fill.TakerFeeQuoteQuantums,
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming of variable is inaccurate, should be max_possible_taker_fee_rev_share

@@ -152,7 +153,7 @@ func (k Keeper) AddRewardSharesForFill(

// taker revshare is not returned if taker volume is greater than Max30dTakerVolumeQuantums
if value, ok := revSharesForFill.FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE]; ok &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we remove FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE from the if condition and only rely on fill.MonthlyRollingTakerVolumeQuantums < revsharetypes.MaxReferee30dVolumeForAffiliateShareQuantums only?

Copy link
Contributor Author

@affanv14 affanv14 Sep 23, 2024

Choose a reason for hiding this comment

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

my b - didnt realize this when i was working through it fast 😓

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

Outside diff range and nitpick comments (2)
protocol/testing/e2e/trading_rewards/trading_rewards_test.go (2)

Line range hint 510-520: Consistent use of constants for reward amounts

The reward amounts "3980734153846153845" for Alice and Bob are hardcoded. Consider defining these as constants or computing them programmatically to maintain consistency and facilitate updates.


Line range hint 530-540: Define reward amounts as constants or compute dynamically

The hardcoded reward amounts "2281569230769230769" for Carl and Dave should be defined as constants or calculated dynamically to ensure accuracy and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3deb52e and 581f861.

Files selected for processing (3)
  • protocol/testing/e2e/trading_rewards/trading_rewards_test.go (13 hunks)
  • protocol/x/rewards/keeper/keeper.go (4 hunks)
  • protocol/x/rewards/keeper/keeper_test.go (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/rewards/keeper/keeper.go
  • protocol/x/rewards/keeper/keeper_test.go
Additional comments not posted (3)
protocol/testing/e2e/trading_rewards/trading_rewards_test.go (3)

8-9: Approved

The added imports sdkmath and proto are appropriate for math operations and protocol buffer manipulations used in the updated test code.


281-284: Verify the calculation of the treasury balance

The updated treasury balance "28417709308164802417" seems to be based on previous calculations. Ensure that this value accurately reflects the expected treasury balance after rewards distribution.

You can verify the treasury balance calculation with the following script:

#!/bin/bash
# Description: Calculate the expected treasury balance.

# Assume vested amount per block is 2.534006365423989945 full coins
# Total vested over 12 blocks: 2.534006365423989945 * 12

# Subtract total rewards distributed to users from total vested amount
# Expected treasury balance = (Total vested) - (Total rewards to users)

echo "Expected treasury balance calculation needs to be done based on actual parameters."

Please adjust the script with the accurate values from your test case.


486-487: Update comments to reflect accurate calculations

The comments mention "Entitled reward tokens:

  • Alice and Bob: 3.98073
  • Carl and Dave: 2.28156"

Ensure that these values are consistent with the actual calculations in the code or update them to reflect the correct amounts.

To verify the correctness of these values, you can run the following script:

Note: Adjust the calculations as per the actual parameters used in the test.

Comment on lines +233 to +236
// Total of ~5.06 full coins have vested, calculated rewards are
// ~1.99 full coins. So remaining rewards are ~3.07 full coins.
Balance: big_testutil.MustFirst(new(big.Int).SetString(
"0",
"3077645653924902967",
Copy link
Contributor

Choose a reason for hiding this comment

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

Define magic numbers as constants for clarity

The hardcoded value "3077645653924902967" represents a significant numerical value in the balance calculations. Defining this value as a named constant would improve readability and maintainability.

Comment on lines +242 to +246
// starting balance + ~1.99 full coins rewards
Balance: new(big.Int).Add(
TestAccountStartingTokenBalance,
big_testutil.MustFirst(new(big.Int).SetString(
"5068012730847979890",
"1990367076923076923",
Copy link
Contributor

Choose a reason for hiding this comment

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

Define repeated magic numbers as constants

The value "1990367076923076923" is used multiple times in the code. Consider defining it as a constant to enhance code clarity and reduce potential errors due to manual updates.

@@ -258,7 +259,7 @@
TradingRewards: []*indexerevents.AddressTradingReward{
{
Owner: constants.AliceAccAddress.String(),
DenomAmount: dtypes.NewIntFromUint64(5068012730847979890),
DenomAmount: dtypes.NewIntFromUint64(1990367076923076923),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consistent use of constants for repeated values

The DenomAmount of 1990367076923076923 is hardcoded here. Defining this repeated value as a constant would improve consistency and maintainability across the test cases.

Comment on lines +281 to +284
// balance + ~25.34 full coins. Note this is exactly 10x the amount vested per block,
// since 10 blocks has passed since the last check.
Balance: big_testutil.MustFirst(new(big.Int).SetString(
"25340063654239899450",
"28417709308164802417",
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider defining large numeric literals as constants

The hardcoded balance "28417709308164802417" could be defined as a constant to improve readability and make future updates easier.

Balance: big_testutil.MustFirst(new(big.Int).SetString(
"22329476019663889395",
"28961348596665715439",
Copy link
Contributor

Choose a reason for hiding this comment

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

Define large numeric literals as constants

The hardcoded value "28961348596665715439" in the balance calculation represents a significant amount. Defining it as a constant would improve code readability and ease future maintenance.

Comment on lines +551 to +563
DenomAmount: dtypes.NewIntFromUint64(3980734153846153845),
},
{
Owner: constants.AliceAccAddress.String(),
DenomAmount: dtypes.NewIntFromUint64(8053910091363583686),
DenomAmount: dtypes.NewIntFromUint64(3980734153846153845),
},
{
Owner: constants.CarlAccAddress.String(),
DenomAmount: dtypes.NewIntFromUint64(4616121735756366038),
DenomAmount: dtypes.NewIntFromUint64(2281569230769230769),
},
{
Owner: constants.DaveAccAddress.String(),
DenomAmount: dtypes.NewIntFromUint64(4616121735756366038),
DenomAmount: dtypes.NewIntFromUint64(2281569230769230769),
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid hardcoding values in event assertions

In the ExpectedTradingRewardEvents, the DenomAmount values are hardcoded. Calculating these values within the test or defining them as constants would reduce the risk of errors and improve test robustness.

Comment on lines +304 to +311
// Total rewards = (TakerFee - TakerVolume * MaxMakerRebate - (takerFee * MaxPossibleTakerFeeRevShare)) * 0.99
// = ($28003 * 0.05% - $28003 * 0.011% - $28003 * 0.05% * 0.5) * 0.99
// = ($14.0015 - $3.08033 - $7.00075) 0.99 = $3.8812158
// Reward tokens = $3.8812158 / $1.95 = 1.9903670769 full coins
Balance: new(big.Int).Add(
TestAccountStartingTokenBalance,
big_testutil.MustFirst(new(big.Int).SetString(
"5544594000000000000",
"1990367076923076923",
Copy link
Contributor

Choose a reason for hiding this comment

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

Compute expected reward amounts programmatically

The calculation for the rewards is detailed in comments, but the final value "1990367076923076923" is hardcoded. To prevent discrepancies between the comments and the code, consider calculating this value programmatically within the test.

Apply this change to compute the reward amount:

 Balance: new(big.Int).Add(
     TestAccountStartingTokenBalance,
-    big_testutil.MustFirst(new(big.Int).SetString(
-        "1990367076923076923",
-        10,
-    )),
+    calculateExpectedRewardAmount(),
 ),

Where calculateExpectedRewardAmount() is a function that performs the reward calculation based on the parameters defined in the comments.

Committable suggestion was skipped due to low confidence.

// = ($28003 * 0.05% - $28003 * 0.011%) * 0.99
// = ($14.0015 - $3.08033) 0.99 = $10.8119583
// Reward tokens = $10.8119583 / $1.95 = 5.544594 full coins
// Total rewards = (TakerFee - TakerVolume * MaxMakerRebate - (takerFee * MaxPossibleTakerFeeRevShare)) * 0.99
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@affanv14 affanv14 merged commit cc59dd2 into main Sep 24, 2024
22 checks passed
@affanv14 affanv14 deleted the affan/update-trading-rewards branch September 24, 2024 01:57
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