-
Notifications
You must be signed in to change notification settings - Fork 104
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
Changes from 6 commits
213977b
368f359
9e422bb
8750e0d
f9d89c7
61a4542
972f274
3deb52e
2184b6a
581f861
6fada43
15ba5e6
f4d0f93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package types | ||
|
||
const ( | ||
// 25 million USDC | ||
Max30dRefereeVolumeQuantums = uint64(25_000_000_000_000) | ||
// 50 million USDC | ||
MaxReferee30dVolumeForAffiliateShareQuantums = uint64(50_000_000_000_000) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib/log" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics" | ||
affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types" | ||
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/rewards/types" | ||
|
@@ -120,15 +121,20 @@ func (k Keeper) GetRewardShare( | |
// | ||
// Within each block, total reward share score for an address is defined as: | ||
// | ||
// reward_share_score = total_taker_fees_paid - total_rev_shared_taker_fee | ||
// reward_share_score = total_taker_fees_paid - max_possible_taker_fee_rev_share | ||
// - max_possible_maker_rebate * taker_volume + total_positive_maker_fees - total_rev_shared_maker_fee | ||
// | ||
// Hence, for each fill, increment reward share score as follow: | ||
// - Let F = sum(percentages of general rev-share) (excluding taker only rev share i.e. affiliate) | ||
// - For maker address, positive_maker_fees * (1 - F) are added to reward share score. | ||
// - For taker address, (positive_taker_fees - max_possible_maker_rebate | ||
// * fill_quote_quantum - taker_fee_rev_share) * (1 - F) | ||
// * fill_quote_quantum - max_possible_taker_fee_rev_share) * (1 - F) | ||
// are added to reward share score. | ||
// max_possible_taker_fee_rev_share is 0 when taker trailing volume is > MaxReferee30dVolumeForAffiliateShareQuantums, | ||
// since taker_fee_share is only affiliate at the moment, and they don’t generate affiliate rev share. | ||
// When taker volume ≤ MaxReferee30dVolumeForAffiliateShareQuantums, | ||
// max_possible_taker_fee_rev_share = max_vip_affiliate_share * taker_fee | ||
// regardless of if the taker has an affiliate or not. | ||
|
||
func (k Keeper) AddRewardSharesForFill( | ||
ctx sdk.Context, | ||
|
@@ -144,8 +150,14 @@ func (k Keeper) AddRewardSharesForFill( | |
totalNetFeeRevSharePpm = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's modify function documentation as needed |
||
} | ||
totalTakerFeeRevShareQuantums := big.NewInt(0) | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
if value, ok := revSharesForFill.FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE]; ok && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my b - didnt realize this when i was working through it fast 😓 |
||
value > 0 && fill.MonthlyRollingTakerVolumeQuantums < revsharetypes.MaxReferee30dVolumeForAffiliateShareQuantums { | ||
totalTakerFeeRevShareQuantums = lib.BigMulPpm(fill.TakerFeeQuoteQuantums, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming of variable is inaccurate, should be |
||
lib.BigU(affiliatetypes.AffiliatesRevSharePpmCap), | ||
false, | ||
) | ||
} | ||
|
||
totalFeeSubNetRevSharePpm := lib.OneMillion - totalNetFeeRevSharePpm | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,7 +483,68 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we cover the following (may already be covered in current tests):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first two are covered by existing tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrote a test for the 3rd one There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)? |
||
}, | ||
expectedMakerShare: types.RewardShare{ | ||
Address: makerAddress, | ||
Weight: dtypes.NewInt(900_000), // 1 * (1 - 0.1) | ||
}, | ||
}, | ||
"positive maker + taker fees reduced by maker rebate, taker + net fee revshare, monthly rolling taker volume > 50 mil": { | ||
prevTakerRewardShare: nil, | ||
prevMakerRewardShare: nil, | ||
fill: clobtypes.FillForProcess{ | ||
TakerAddr: takerAddress, | ||
TakerFeeQuoteQuantums: big.NewInt(2_000_000), | ||
MakerAddr: makerAddress, | ||
MakerFeeQuoteQuantums: big.NewInt(1_000_000), | ||
FillQuoteQuantums: big.NewInt(800_000_000), | ||
ProductId: uint32(1), | ||
MarketId: uint32(1), | ||
MonthlyRollingTakerVolumeQuantums: 50_000_000_000, | ||
}, | ||
revSharesForFill: revsharetypes.RevSharesForFill{ | ||
AllRevShares: []revsharetypes.RevShare{ | ||
{ | ||
Recipient: constants.AliceAccAddress.String(), | ||
RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE, | ||
RevShareType: revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL, | ||
QuoteQuantums: big.NewInt(200_000), | ||
RevSharePpm: 100_000, // 10% | ||
}, | ||
{ | ||
Recipient: takerAddress, | ||
RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE, | ||
RevShareType: revsharetypes.REV_SHARE_TYPE_AFFILIATE, | ||
QuoteQuantums: big.NewInt(200_000), | ||
RevSharePpm: 100_000, // 10% | ||
}, | ||
}, | ||
FeeSourceToQuoteQuantums: map[revsharetypes.RevShareFeeSource]*big.Int{ | ||
revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(200_000), | ||
revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(200_000), | ||
}, | ||
FeeSourceToRevSharePpm: map[revsharetypes.RevShareFeeSource]uint32{ | ||
revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE: 100_000, // 10% | ||
revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 100_000, // 10% | ||
}, | ||
AffiliateRevShare: &revsharetypes.RevShare{ | ||
Recipient: takerAddress, | ||
RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE, | ||
RevShareType: revsharetypes.REV_SHARE_TYPE_AFFILIATE, | ||
QuoteQuantums: big.NewInt(200_000), | ||
RevSharePpm: 100_000, // 10% | ||
}, | ||
}, | ||
feeTiers: []*feetierstypes.PerpetualFeeTier{ | ||
{ | ||
MakerFeePpm: -1_000, // -0.1% | ||
TakerFeePpm: 2_000, // 0.2% | ||
}, | ||
}, | ||
expectedTakerShare: types.RewardShare{ | ||
Address: takerAddress, | ||
Weight: dtypes.NewInt(1_080_000), // (2 - 0.1% * 800 - 0) * (1 - 0.1) | ||
}, | ||
expectedMakerShare: types.RewardShare{ | ||
Address: makerAddress, | ||
|
There was a problem hiding this comment.
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 thresholdMaxReferee30dVolumeForAffiliateShareQuantums
. 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:
types.Max30dRefereeVolumeQuantums
(old) andtypes.MaxReferee30dVolumeForAffiliateShareQuantums
(new).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:
MonthlyRollingTakerVolumeQuantums
is just below, at, and just above the new threshold.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:
Length of output: 301
Script:
Length of output: 118