From 809a0ce556f4e96ab8fc617631f78c3ffa14c281 Mon Sep 17 00:00:00 2001 From: affan Date: Thu, 19 Sep 2024 13:52:14 -0400 Subject: [PATCH 1/4] update revshare logic --- protocol/x/revshare/keeper/revshare.go | 18 ++--- protocol/x/revshare/keeper/revshare_test.go | 72 ++++--------------- .../x/subaccounts/keeper/transfer_test.go | 6 +- 3 files changed, 25 insertions(+), 71 deletions(-) diff --git a/protocol/x/revshare/keeper/revshare.go b/protocol/x/revshare/keeper/revshare.go index aa5a1df2c5..d46a65ba18 100644 --- a/protocol/x/revshare/keeper/revshare.go +++ b/protocol/x/revshare/keeper/revshare.go @@ -164,17 +164,17 @@ func (k Keeper) GetAllRevShares( makerFees := fill.MakerFeeQuoteQuantums netFees := big.NewInt(0).Add(takerFees, makerFees) - affiliateRevShares, err := k.getAffiliateRevShares(ctx, fill) + affiliateRevShares, affiliateFeesShared, err := k.getAffiliateRevShares(ctx, fill) 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) if err != nil { return types.RevSharesForFill{}, err } - marketMapperRevShares, err := k.getMarketMapperRevShare(ctx, fill.MarketId, netFees) + marketMapperRevShares, err := k.getMarketMapperRevShare(ctx, fill.MarketId, netFeesSubAffiliateFeesShared) if err != nil { return types.RevSharesForFill{}, err } @@ -216,19 +216,19 @@ func (k Keeper) GetAllRevShares( func (k Keeper) getAffiliateRevShares( ctx sdk.Context, fill clobtypes.FillForProcess, -) ([]types.RevShare, error) { +) ([]types.RevShare, *big.Int, error) { takerAddr := fill.TakerAddr takerFee := fill.TakerFeeQuoteQuantums if fill.MonthlyRollingTakerVolumeQuantums >= types.Max30dRefereeVolumeQuantums { - return nil, nil + return nil, big.NewInt(0), nil } takerAffiliateAddr, feeSharePpm, exists, err := k.affiliatesKeeper.GetTakerFeeShare(ctx, takerAddr) if err != nil { - return nil, err + return nil, big.NewInt(0), err } if !exists { - return nil, nil + return nil, big.NewInt(0), nil } feesShared := lib.BigMulPpm(takerFee, lib.BigU(feeSharePpm), false) return []types.RevShare{ @@ -239,7 +239,7 @@ func (k Keeper) getAffiliateRevShares( QuoteQuantums: feesShared, RevSharePpm: feeSharePpm, }, - }, nil + }, feesShared, nil } func (k Keeper) getUnconditionalRevShares( diff --git a/protocol/x/revshare/keeper/revshare_test.go b/protocol/x/revshare/keeper/revshare_test.go index 0a8a0cf291..e2cc9c4ab8 100644 --- a/protocol/x/revshare/keeper/revshare_test.go +++ b/protocol/x/revshare/keeper/revshare_test.go @@ -291,21 +291,21 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { Recipient: constants.BobAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, - QuoteQuantums: big.NewInt(2_400_000), + QuoteQuantums: big.NewInt(2_100_000), RevSharePpm: 200_000, }, { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, - QuoteQuantums: big.NewInt(3_600_000), + QuoteQuantums: big.NewInt(3_150_000), RevSharePpm: 300_000, }, { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, - QuoteQuantums: big.NewInt(1_200_000), + QuoteQuantums: big.NewInt(1_050_000), RevSharePpm: 100_000, }, }, @@ -318,7 +318,7 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(7_200_000), + types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(6_300_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, @@ -379,27 +379,27 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { Recipient: constants.BobAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, - QuoteQuantums: big.NewInt(1_600_000), + QuoteQuantums: big.NewInt(1_300_000), RevSharePpm: 200_000, }, { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, - QuoteQuantums: big.NewInt(2_400_000), + QuoteQuantums: big.NewInt(1_950_000), RevSharePpm: 300_000, }, { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, - QuoteQuantums: big.NewInt(800_000), + QuoteQuantums: big.NewInt(650_000), RevSharePpm: 100_000, }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(4_800_000), + types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(3_900_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, @@ -541,12 +541,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, - QuoteQuantums: big.NewInt(1_200_000), + QuoteQuantums: big.NewInt(1_050_000), RevSharePpm: 100_000, // 10% }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(1_200_000), + types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(1_050_000), types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ @@ -602,12 +602,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { Recipient: constants.BobAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, - QuoteQuantums: big.NewInt(2_400_000), + QuoteQuantums: big.NewInt(2_100_000), RevSharePpm: 200_000, // 20% }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(2_400_000), + types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(2_100_000), types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ @@ -731,7 +731,7 @@ func TestKeeper_GetAllRevShares_Invalid(t *testing.T) { Configs: []types.UnconditionalRevShareConfig_RecipientConfig{ { Address: constants.BobAccAddress.String(), - SharePpm: 150_000, // 15% + SharePpm: 250_000, // 25% }, }, }) @@ -742,52 +742,6 @@ func TestKeeper_GetAllRevShares_Invalid(t *testing.T) { require.NoError(t, err) }, }, - { - name: "Total fees shared exceeds net fees from market mapper and affiliates", - revenueSharePpmNetFees: 950_000, // 95%, - revenueSharePpmTakerFees: 150_000, // 15% - expectedError: types.ErrTotalFeesSharedExceedsNetFees, - monthlyRollingTakerVolumeQuantums: 1_000_000_000_000, // 1 million USDC - setup: func(tApp *testapp.TestApp, ctx sdk.Context, keeper *keeper.Keeper, - affiliatesKeeper *affiliateskeeper.Keeper) { - err := keeper.SetMarketMapperRevenueShareParams(ctx, types.MarketMapperRevenueShareParams{ - Address: constants.AliceAccAddress.String(), - RevenueSharePpm: 950_000, // 95% - ValidDays: 1, - }) - require.NoError(t, err) - - err = affiliatesKeeper.UpdateAffiliateTiers(ctx, affiliatetypes.DefaultAffiliateTiers) - require.NoError(t, err) - err = affiliatesKeeper.RegisterAffiliate(ctx, constants.AliceAccAddress.String(), - constants.BobAccAddress.String()) - require.NoError(t, err) - }, - }, - { - name: "Total fees shared exceeds net fees from affiliates and unconditional rev shares", - revenueSharePpmNetFees: 950_000, // 95%, - revenueSharePpmTakerFees: 150_000, // 15% - expectedError: types.ErrTotalFeesSharedExceedsNetFees, - monthlyRollingTakerVolumeQuantums: 1_000_000_000_000, // 1 million USDC - setup: func(tApp *testapp.TestApp, ctx sdk.Context, keeper *keeper.Keeper, - affiliatesKeeper *affiliateskeeper.Keeper) { - keeper.SetUnconditionalRevShareConfigParams(ctx, types.UnconditionalRevShareConfig{ - Configs: []types.UnconditionalRevShareConfig_RecipientConfig{ - { - Address: constants.BobAccAddress.String(), - SharePpm: 950_000, // 95% - }, - }, - }) - - err := affiliatesKeeper.UpdateAffiliateTiers(ctx, affiliatetypes.DefaultAffiliateTiers) - require.NoError(t, err) - err = affiliatesKeeper.RegisterAffiliate(ctx, constants.AliceAccAddress.String(), - constants.BobAccAddress.String()) - require.NoError(t, err) - }, - }, { name: "Total fees shared exceeds net fees - no affiliate rev shares", revenueSharePpmNetFees: 1_150_000, // 115%, diff --git a/protocol/x/subaccounts/keeper/transfer_test.go b/protocol/x/subaccounts/keeper/transfer_test.go index 79ea1c5afd..d22d4d1fe8 100644 --- a/protocol/x/subaccounts/keeper/transfer_test.go +++ b/protocol/x/subaccounts/keeper/transfer_test.go @@ -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 + expectedMarketMapperAccBalance: big.NewInt(48), // 10% of 500 expectedAffiliateAccBalance: big.NewInt(12), // 5% of 250 - expectedUnconditionalRevShareAccBalance: big.NewInt(50), // 10% of 500 + expectedUnconditionalRevShareAccBalance: big.NewInt(48), // 10% of 500 collateralPoolAddr: authtypes.NewModuleAddress( types.ModuleName + ":" + lib.IntToString(4), ), From 5c2fa1392bd9bf5094594807ac7478b1df934381 Mon Sep 17 00:00:00 2001 From: affan Date: Thu, 19 Sep 2024 14:34:32 -0400 Subject: [PATCH 2/4] fix test --- protocol/x/revshare/keeper/revshare_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/x/revshare/keeper/revshare_test.go b/protocol/x/revshare/keeper/revshare_test.go index ae7c7cafea..a78f8dbbf9 100644 --- a/protocol/x/revshare/keeper/revshare_test.go +++ b/protocol/x/revshare/keeper/revshare_test.go @@ -707,7 +707,7 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { Recipient: constants.AliceAccAddress.String(), RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, - QuoteQuantums: big.NewInt(1_200_000), + QuoteQuantums: big.NewInt(950_000), RevSharePpm: 100_000, // 10% }, }, @@ -719,7 +719,7 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { RevSharePpm: 250_000, // 25% }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(1_200_000), + types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(950_000), types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(2_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ From 2060d2164a9c6db90d48ebaea8eafcf7e6dbd6ae Mon Sep 17 00:00:00 2001 From: affan Date: Thu, 19 Sep 2024 14:44:11 -0400 Subject: [PATCH 3/4] update comment --- protocol/x/subaccounts/keeper/transfer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/x/subaccounts/keeper/transfer_test.go b/protocol/x/subaccounts/keeper/transfer_test.go index 0b78734ec8..6c0bd2a014 100644 --- a/protocol/x/subaccounts/keeper/transfer_test.go +++ b/protocol/x/subaccounts/keeper/transfer_test.go @@ -1501,9 +1501,9 @@ func TestDistributeFees(t *testing.T) { }, expectedSubaccountsModuleAccBalance: big.NewInt(100), // 600 - 500 expectedFeeModuleAccBalance: big.NewInt(2892), // 2500 + 500 - 108 - expectedMarketMapperAccBalance: big.NewInt(48), // 10% of 500 + expectedMarketMapperAccBalance: big.NewInt(48), // 10% of 488 expectedAffiliateAccBalance: big.NewInt(12), // 5% of 250 - expectedUnconditionalRevShareAccBalance: big.NewInt(48), // 10% of 500 + expectedUnconditionalRevShareAccBalance: big.NewInt(48), // 10% of 488 collateralPoolAddr: authtypes.NewModuleAddress( types.ModuleName + ":" + lib.IntToString(4), ), From 3f21cf6fe7405add056675e06d5949899ea00b9f Mon Sep 17 00:00:00 2001 From: affan Date: Thu, 19 Sep 2024 17:03:53 -0400 Subject: [PATCH 4/4] rename --- protocol/x/revshare/keeper/revshare.go | 8 +-- protocol/x/revshare/keeper/revshare_test.go | 80 ++++++++++----------- protocol/x/revshare/types/types.go | 2 +- protocol/x/rewards/keeper/keeper.go | 2 +- protocol/x/rewards/keeper/keeper_test.go | 32 ++++----- protocol/x/subaccounts/keeper/transfer.go | 3 +- 6 files changed, 64 insertions(+), 63 deletions(-) diff --git a/protocol/x/revshare/keeper/revshare.go b/protocol/x/revshare/keeper/revshare.go index bd7636e5c7..631d3f7ad9 100644 --- a/protocol/x/revshare/keeper/revshare.go +++ b/protocol/x/revshare/keeper/revshare.go @@ -163,8 +163,8 @@ func (k Keeper) GetAllRevShares( feeSourceToRevSharePpm := make(map[types.RevShareFeeSource]uint32) feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_TAKER_FEE] = big.NewInt(0) feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_TAKER_FEE] = 0 - feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_NET_FEE] = big.NewInt(0) - feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_NET_FEE] = 0 + feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE] = big.NewInt(0) + feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE] = 0 totalFeesShared := big.NewInt(0) takerFees := fill.TakerFeeQuoteQuantums @@ -264,7 +264,7 @@ func (k Keeper) getUnconditionalRevShares( feeShared := lib.BigMulPpm(netFees, lib.BigU(revShare.SharePpm), false) revShare := types.RevShare{ Recipient: revShare.Address, - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: feeShared, RevSharePpm: revShare.SharePpm, @@ -291,7 +291,7 @@ func (k Keeper) getMarketMapperRevShare( marketMapperRevshareAmount := lib.BigMulPpm(netFees, lib.BigU(revenueSharePpm), false) revShares = append(revShares, types.RevShare{ Recipient: marketMapperRevshareAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: marketMapperRevshareAmount, RevSharePpm: revenueSharePpm, diff --git a/protocol/x/revshare/keeper/revshare_test.go b/protocol/x/revshare/keeper/revshare_test.go index a78f8dbbf9..4c59d5b489 100644 --- a/protocol/x/revshare/keeper/revshare_test.go +++ b/protocol/x/revshare/keeper/revshare_test.go @@ -332,21 +332,21 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, { Recipient: constants.BobAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(2_100_000), RevSharePpm: 200_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(3_150_000), RevSharePpm: 300_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: big.NewInt(1_050_000), RevSharePpm: 100_000, @@ -360,12 +360,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { RevSharePpm: 150_000, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(6_300_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(6_300_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, - types.REV_SHARE_FEE_SOURCE_NET_FEE: 600_000, + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 600_000, }, }, fill: clobtypes.FillForProcess{ @@ -420,33 +420,33 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, { Recipient: constants.BobAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(1_300_000), RevSharePpm: 200_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(1_950_000), RevSharePpm: 300_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: big.NewInt(650_000), RevSharePpm: 100_000, }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(3_900_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(3_900_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, - types.REV_SHARE_FEE_SOURCE_NET_FEE: 600_000, + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 600_000, }, AffiliateRevShare: &types.RevShare{ Recipient: constants.BobAccAddress.String(), @@ -511,21 +511,21 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { AllRevShares: []types.RevShare{ { Recipient: constants.BobAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(2_400_000), RevSharePpm: 200_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(3_600_000), RevSharePpm: 300_000, }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: big.NewInt(1_200_000), RevSharePpm: 100_000, @@ -533,12 +533,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, AffiliateRevShare: nil, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(7_200_000), - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(7_200_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: 600_000, - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 600_000, + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, }, }, setup: func(tApp *testapp.TestApp, ctx sdk.Context, keeper *keeper.Keeper, @@ -582,19 +582,19 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: big.NewInt(1_050_000), RevSharePpm: 100_000, // 10% }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(1_050_000), - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(1_050_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: 100_000, // 10% - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, // 15% + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 100_000, // 10% + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, // 15% }, AffiliateRevShare: &types.RevShare{ Recipient: constants.BobAccAddress.String(), @@ -643,19 +643,19 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, { Recipient: constants.BobAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(2_100_000), RevSharePpm: 200_000, // 20% }, }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(2_100_000), - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(2_100_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: 200_000, // 20% - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, // 15% + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 200_000, // 20% + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 150_000, // 15% }, AffiliateRevShare: &types.RevShare{ Recipient: constants.BobAccAddress.String(), @@ -705,7 +705,7 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { }, { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, QuoteQuantums: big.NewInt(950_000), RevSharePpm: 100_000, // 10% @@ -719,12 +719,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { RevSharePpm: 250_000, // 25% }, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(950_000), - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(2_500_000), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(950_000), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(2_500_000), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: 100_000, // 10% - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 250_000, // 25% + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 100_000, // 10% + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 250_000, // 25% }, }, fill: clobtypes.FillForProcess{ @@ -767,12 +767,12 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) { AllRevShares: []types.RevShare{}, AffiliateRevShare: nil, FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(0), - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(0), + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), }, FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{ - types.REV_SHARE_FEE_SOURCE_NET_FEE: 0, - types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, + types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 0, + types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, }, }, fill: clobtypes.FillForProcess{ diff --git a/protocol/x/revshare/types/types.go b/protocol/x/revshare/types/types.go index c17a50584d..17ecd548a3 100644 --- a/protocol/x/revshare/types/types.go +++ b/protocol/x/revshare/types/types.go @@ -41,7 +41,7 @@ type RevShareFeeSource int const ( REV_SHARE_FEE_SOURCE_UNSPECIFIED RevShareFeeSource = iota - REV_SHARE_FEE_SOURCE_NET_FEE + REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE REV_SHARE_FEE_SOURCE_TAKER_FEE ) diff --git a/protocol/x/rewards/keeper/keeper.go b/protocol/x/rewards/keeper/keeper.go index 14f14d1aa7..182565d246 100644 --- a/protocol/x/rewards/keeper/keeper.go +++ b/protocol/x/rewards/keeper/keeper.go @@ -140,7 +140,7 @@ func (k Keeper) AddRewardSharesForFill( maxMakerRebatePpm := lib.Min(int32(0), lowestMakerFee) totalNetFeeRevSharePpm := uint32(0) - if value, ok := revSharesForFill.FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE]; ok { + if value, ok := revSharesForFill.FeeSourceToRevSharePpm[revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE]; ok { totalNetFeeRevSharePpm = value } totalTakerFeeRevShareQuantums := big.NewInt(0) diff --git a/protocol/x/rewards/keeper/keeper_test.go b/protocol/x/rewards/keeper/keeper_test.go index d41f89b738..4dcd4bab9f 100644 --- a/protocol/x/rewards/keeper/keeper_test.go +++ b/protocol/x/rewards/keeper/keeper_test.go @@ -343,19 +343,19 @@ func TestAddRewardSharesForFill(t *testing.T) { AllRevShares: []revsharetypes.RevShare{ { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL, 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(0), + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(200_000), + revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), }, FeeSourceToRevSharePpm: map[revsharetypes.RevShareFeeSource]uint32{ - revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE: 100_000, // 10% - revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 100_000, // 10% + revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, }, AffiliateRevShare: nil, }, @@ -391,26 +391,26 @@ func TestAddRewardSharesForFill(t *testing.T) { AllRevShares: []revsharetypes.RevShare{ { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(200_000), RevSharePpm: 100_000, // 10% }, { Recipient: constants.BobAccAddress.String(), - RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(200_000), RevSharePpm: 100_000, // 10% }, }, FeeSourceToQuoteQuantums: map[revsharetypes.RevShareFeeSource]*big.Int{ - revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE: big.NewInt(400_000), - revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(400_000), + revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0), }, FeeSourceToRevSharePpm: map[revsharetypes.RevShareFeeSource]uint32{ - revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE: 200_000, // 20% - revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 200_000, // 20% + revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, }, AffiliateRevShare: nil, }, @@ -446,7 +446,7 @@ func TestAddRewardSharesForFill(t *testing.T) { AllRevShares: []revsharetypes.RevShare{ { Recipient: constants.AliceAccAddress.String(), - RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE, + RevShareFeeSource: revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, RevShareType: revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL, QuoteQuantums: big.NewInt(200_000), RevSharePpm: 100_000, // 10% @@ -460,12 +460,12 @@ func TestAddRewardSharesForFill(t *testing.T) { }, }, 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), + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 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% + revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 100_000, // 10% + revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 100_000, // 10% }, AffiliateRevShare: &revsharetypes.RevShare{ Recipient: takerAddress, diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index 5724fbd777..ecf79952be 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -268,7 +268,8 @@ func (k Keeper) DistributeFees( totalTakerFeeRevShareQuantums = value } totalNetFeeRevShareQuantums := big.NewInt(0) - if value, ok := revSharesForFill.FeeSourceToQuoteQuantums[revsharetypes.REV_SHARE_FEE_SOURCE_NET_FEE]; ok { + if value, ok := + revSharesForFill.FeeSourceToQuoteQuantums[revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE]; ok { totalNetFeeRevShareQuantums = value }