Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Oct 1, 2024
1 parent 806dc05 commit 08e5f4f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
7 changes: 4 additions & 3 deletions protocol/x/revshare/keeper/revshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (k Keeper) GetAllRevShares(
makerFees := fill.MakerFeeQuoteQuantums
netFees := big.NewInt(0).Add(takerFees, makerFees)

// net fees is 0 in case of liquidations where maker and taker fees are 0
// when net fee is zero, no rev share is generated from the fill
if netFees.Sign() == 0 {
return types.RevSharesForFill{}, nil
}
Expand All @@ -186,7 +186,7 @@ func (k Keeper) GetAllRevShares(
}
netFeesSubAffiliateFeesShared := new(big.Int).Sub(netFees, affiliateFeesShared)
if netFeesSubAffiliateFeesShared.Sign() <= 0 {
return types.RevSharesForFill{}, types.ErrAffiliateFeesSharedExceedsNetFees
return types.RevSharesForFill{}, types.ErrAffiliateFeesSharedGreaterThanOrEqualToNetFees
}

unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFeesSubAffiliateFeesShared)
Expand Down Expand Up @@ -238,7 +238,8 @@ func (k Keeper) getAffiliateRevShares(
) ([]types.RevShare, *big.Int, error) {
takerAddr := fill.TakerAddr
takerFee := fill.TakerFeeQuoteQuantums
if fill.MonthlyRollingTakerVolumeQuantums >= types.MaxReferee30dVolumeForAffiliateShareQuantums {
if fill.MonthlyRollingTakerVolumeQuantums >= types.MaxReferee30dVolumeForAffiliateShareQuantums ||
takerFee.Sign() == 0 {
return nil, big.NewInt(0), nil
}

Expand Down
76 changes: 76 additions & 0 deletions protocol/x/revshare/keeper/revshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,82 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) {
},
})

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: "Valid revenue share with 0 taker fee and positive maker fees",
expectedRevSharesForFill: types.RevSharesForFill{
AllRevShares: []types.RevShare{
{
Recipient: constants.BobAccAddress.String(),
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE,
RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL,
QuoteQuantums: big.NewInt(400_000),
RevSharePpm: 200_000,
},
{
Recipient: constants.AliceAccAddress.String(),
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE,
RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL,
QuoteQuantums: big.NewInt(600_000),
RevSharePpm: 300_000,
},
{
Recipient: constants.AliceAccAddress.String(),
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE,
RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER,
QuoteQuantums: big.NewInt(200_000),
RevSharePpm: 100_000,
},
},
AffiliateRevShare: nil,
FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{
types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0),
// unconditional + market mapper rev shares fees
types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(1_200_000),
},
FeeSourceToRevSharePpm: map[types.RevShareFeeSource]uint32{
types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0,
types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 600_000,
},
},
fill: clobtypes.FillForProcess{
TakerAddr: constants.AliceAccAddress.String(),
TakerFeeQuoteQuantums: big.NewInt(0),
MakerAddr: constants.BobAccAddress.String(),
MakerFeeQuoteQuantums: big.NewInt(2_000_000),
FillQuoteQuantums: big.NewInt(100_000_000_000),
ProductId: perpetualId,
MonthlyRollingTakerVolumeQuantums: 1_000_000_000_000,
MarketId: marketId,
},
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: 100_000, // 10%
ValidDays: 1,
})
require.NoError(t, err)

keeper.SetUnconditionalRevShareConfigParams(ctx, types.UnconditionalRevShareConfig{
Configs: []types.UnconditionalRevShareConfig_RecipientConfig{
{
Address: constants.BobAccAddress.String(),
SharePpm: 200_000, // 20%
},
{
Address: constants.AliceAccAddress.String(),
SharePpm: 300_000, // 30%
},
},
})

err = affiliatesKeeper.UpdateAffiliateTiers(ctx, affiliatetypes.DefaultAffiliateTiers)
require.NoError(t, err)
err = affiliatesKeeper.RegisterAffiliate(ctx, constants.AliceAccAddress.String(),
Expand Down
4 changes: 2 additions & 2 deletions protocol/x/revshare/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var (
6,
"total fees shared exceeds net fees",
)
ErrAffiliateFeesSharedExceedsNetFees = errorsmod.Register(
ErrAffiliateFeesSharedGreaterThanOrEqualToNetFees = errorsmod.Register(
ModuleName,
7,
"affiliate fees shared exceeds net fees",
"net fees minus affiliate fee share is not larger than zero",
)
)

0 comments on commit 08e5f4f

Please sign in to comment.