Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Sep 23, 2024
1 parent f162535 commit 71e434a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 63 deletions.
1 change: 0 additions & 1 deletion protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,6 @@ func New(
app.BankKeeper,
app.PerpetualsKeeper,
app.BlockTimeKeeper,
app.RevShareKeeper,
app.IndexerEventManager,
app.FullNodeStreamingManager,
)
Expand Down
1 change: 0 additions & 1 deletion protocol/testutil/keeper/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func NewClobKeepersTestContextWithUninitializedMemStore(
bankKeeper,
ks.PerpetualsKeeper,
ks.BlockTimeKeeper,
revShareKeeper,
indexerEventsTransientStoreKey,
true,
)
Expand Down
1 change: 0 additions & 1 deletion protocol/testutil/keeper/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func ListingKeepers(
bankKeeper,
perpetualsKeeper,
blockTimeKeeper,
revShareKeeper,
transientStoreKey,
true,
)
Expand Down
1 change: 0 additions & 1 deletion protocol/testutil/keeper/sending.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func SendingKeepersWithSubaccountsKeeper(t testing.TB, saKeeper types.Subaccount
ks.BankKeeper,
ks.PerpetualsKeeper,
blockTimeKeeper,
revShareKeeper,
transientStoreKey,
true,
)
Expand Down
3 changes: 0 additions & 3 deletions protocol/testutil/keeper/subaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func SubaccountsKeepers(t testing.TB, msgSenderEnabled bool) (
bankKeeper,
perpetualsKeeper,
blocktimeKeeper,
revShareKeeper,
transientStoreKey,
msgSenderEnabled,
)
Expand Down Expand Up @@ -132,7 +131,6 @@ func createSubaccountsKeeper(
bk types.BankKeeper,
pk *perpskeeper.Keeper,
btk *blocktimekeeper.Keeper,
rsk *revsharekeeper.Keeper,
transientStoreKey storetypes.StoreKey,
msgSenderEnabled bool,
) (*keeper.Keeper, storetypes.StoreKey) {
Expand All @@ -151,7 +149,6 @@ func createSubaccountsKeeper(
bk,
pk,
btk,
rsk,
mockIndexerEventsManager,
streaming.NewNoopGrpcStreamingManager(),
)
Expand Down
48 changes: 46 additions & 2 deletions protocol/x/revshare/keeper/revshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ 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), // affiliate rev share fees
types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(6_300_000), // unconditional + market mapper rev shares fees
types.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(1_500_000), // affiliate rev share fees
// unconditional + market mapper rev shares fees
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, // affiliate rev share fee ppm
Expand Down Expand Up @@ -630,6 +631,49 @@ func TestKeeper_GetAllRevShares_Valid(t *testing.T) {
require.NoError(t, err)
},
},
{
name: "Market mapper rev shares expired",
expectedRevSharesForFill: types.RevSharesForFill{
AllRevShares: []types.RevShare{},
FeeSourceToQuoteQuantums: map[types.RevShareFeeSource]*big.Int{
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_PROTOCOL_REVENUE: 0, // 0%
types.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, // 0%
},
AffiliateRevShare: nil,
},
fill: clobtypes.FillForProcess{
TakerAddr: constants.AliceAccAddress.String(),
TakerFeeQuoteQuantums: big.NewInt(10_000_000),
MakerAddr: constants.BobAccAddress.String(),
MakerFeeQuoteQuantums: big.NewInt(2_000_000),
FillQuoteQuantums: big.NewInt(100_000_000_000),
ProductId: perpetualId,
MarketId: marketId,
MonthlyRollingTakerVolumeQuantums: 1_000_000_000_000,
},
setup: func(tApp *testapp.TestApp, ctx sdk.Context, keeper *keeper.Keeper,
affiliatesKeeper *affiliateskeeper.Keeper) {
keeper.SetMarketMapperRevShareDetails(ctx, marketId, types.MarketMapperRevShareDetails{
ExpirationTs: uint64(ctx.BlockTime().Unix() + -1),
})
err := keeper.SetMarketMapperRevenueShareParams(ctx, types.MarketMapperRevenueShareParams{
Address: constants.AliceAccAddress.String(),
RevenueSharePpm: 100_000, // 10%
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: "Valid revenue share with no market mapper rev share",
expectedRevSharesForFill: types.RevSharesForFill{
Expand Down
4 changes: 1 addition & 3 deletions protocol/x/subaccounts/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"

streamingtypes "github.com/dydxprotocol/v4-chain/protocol/streaming/types"

"cosmossdk.io/log"
Expand All @@ -20,7 +21,6 @@ type (
bankKeeper types.BankKeeper
perpetualsKeeper types.PerpetualsKeeper
blocktimeKeeper types.BlocktimeKeeper
revShareKeeper types.RevShareKeeper
indexerEventManager indexer_manager.IndexerEventManager
streamingManager streamingtypes.FullNodeStreamingManager
}
Expand All @@ -33,7 +33,6 @@ func NewKeeper(
bankKeeper types.BankKeeper,
perpetualsKeeper types.PerpetualsKeeper,
blocktimeKeeper types.BlocktimeKeeper,
revShareKeeper types.RevShareKeeper,
indexerEventManager indexer_manager.IndexerEventManager,
streamingManager streamingtypes.FullNodeStreamingManager,
) *Keeper {
Expand All @@ -44,7 +43,6 @@ func NewKeeper(
bankKeeper: bankKeeper,
perpetualsKeeper: perpetualsKeeper,
blocktimeKeeper: blocktimeKeeper,
revShareKeeper: revShareKeeper,
indexerEventManager: indexerEventManager,
streamingManager: streamingManager,
}
Expand Down
40 changes: 0 additions & 40 deletions protocol/x/subaccounts/keeper/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,46 +1411,6 @@ func TestDistributeFees(t *testing.T) {
},
revShareExpiration: 100,
},
"success - market mapper rev share expired": {
asset: *constants.Usdc,
feeModuleAccBalance: big.NewInt(2500),
subaccountModuleAccBalance: big.NewInt(600),
marketMapperAccBalance: big.NewInt(0),
fill: clobtypes.FillForProcess{
TakerAddr: constants.AliceAccAddress.String(),
TakerFeeQuoteQuantums: big.NewInt(250),
MakerAddr: constants.BobAccAddress.String(),
MakerFeeQuoteQuantums: big.NewInt(250),
FillQuoteQuantums: big.NewInt(500),
ProductId: uint32(4),
MarketId: uint32(4),
MonthlyRollingTakerVolumeQuantums: 1_000_000,
},
affiliateRevShareAcctAddr: "",
marketMapperRevShareAcctAddr: constants.AliceAccAddress.String(),
unconditionalRevShareAcctAddr: "",
expectedSubaccountsModuleAccBalance: big.NewInt(100), // 600 - 500
expectedFeeModuleAccBalance: big.NewInt(3000), // 500 + 2500
expectedMarketMapperAccBalance: big.NewInt(0),
expectedAffiliateAccBalance: big.NewInt(0),
expectedUnconditionalRevShareAccBalance: big.NewInt(0),
collateralPoolAddr: authtypes.NewModuleAddress(
types.ModuleName + ":" + lib.IntToString(4),
),
revShare: revsharetypes.RevSharesForFill{
AffiliateRevShare: nil,
FeeSourceToQuoteQuantums: map[revsharetypes.RevShareFeeSource]*big.Int{
revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: big.NewInt(0),
revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: big.NewInt(0),
},
FeeSourceToRevSharePpm: map[revsharetypes.RevShareFeeSource]uint32{
revsharetypes.REV_SHARE_FEE_SOURCE_TAKER_FEE: 0, // 0%
revsharetypes.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE: 0, // 0%
},
AllRevShares: []revsharetypes.RevShare{},
},
revShareExpiration: -10,
},
"success - market mapper rev share rounded down to 0": {
asset: *constants.Usdc,
feeModuleAccBalance: big.NewInt(100),
Expand Down
11 changes: 0 additions & 11 deletions protocol/x/subaccounts/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,3 @@ type BankKeeper interface {
type BlocktimeKeeper interface {
GetDowntimeInfoFor(ctx sdk.Context, duration time.Duration) blocktimetypes.AllDowntimeInfo_DowntimeInfo
}

type RevShareKeeper interface {
GetMarketMapperRevenueShareForMarket(
ctx sdk.Context,
marketId uint32,
) (
address sdk.AccAddress,
revenueSharePpm uint32,
err error,
)
}

0 comments on commit 71e434a

Please sign in to comment.