Skip to content

Commit

Permalink
Update GetAllRevshare to handle liquidations
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Oct 1, 2024
1 parent 6221a9e commit 9565562
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions protocol/x/revshare/keeper/revshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ 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
if netFees.Sign() == 0 {
return types.RevSharesForFill{}, nil
}

affiliateRevShares, affiliateFeesShared, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap)
if err != nil {
return types.RevSharesForFill{}, err
Expand Down
42 changes: 42 additions & 0 deletions protocol/x/revshare/keeper/revshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,48 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) {
affiliatesKeeper *affiliateskeeper.Keeper) {
},
},
{
name: "Revshares with 0 fees from maker and taker",
expectedRevSharesForFill: types.RevSharesForFill{},
fill: clobtypes.FillForProcess{
TakerAddr: constants.AliceAccAddress.String(),
TakerFeeQuoteQuantums: big.NewInt(0),
MakerAddr: constants.BobAccAddress.String(),
MakerFeeQuoteQuantums: big.NewInt(0),
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(),
constants.BobAccAddress.String())
require.NoError(t, err)
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 9565562

Please sign in to comment.