From 0598e85efd45a33e6bd0207650731e9e2d0a523a Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Fri, 21 Jun 2024 17:49:18 -0400 Subject: [PATCH 1/6] Set market mapper revenue share on market creation Signed-off-by: Shrenuj Bansal --- protocol/app/app.go | 18 +++++++++--------- protocol/app/prepare/prepare_proposal_test.go | 4 ++-- .../process/full_node_process_proposal_test.go | 2 +- protocol/app/process/market_prices_test.go | 6 +++--- protocol/app/process/process_proposal_test.go | 2 +- protocol/app/process/transactions_test.go | 8 ++++---- protocol/testutil/keeper/assets.go | 5 +++-- protocol/testutil/keeper/clob.go | 8 +++++++- protocol/testutil/keeper/perpetuals.go | 1 + protocol/testutil/keeper/prices.go | 18 ++++++++++++------ protocol/testutil/keeper/rewards.go | 5 +++-- protocol/testutil/keeper/sending.go | 2 +- protocol/testutil/keeper/subaccounts.go | 5 +++-- protocol/x/prices/genesis_test.go | 11 ++++++----- .../x/prices/keeper/grpc_query_market_test.go | 11 ++++++----- protocol/x/prices/keeper/keeper.go | 3 +++ protocol/x/prices/keeper/keeper_test.go | 2 +- protocol/x/prices/keeper/market.go | 3 +++ protocol/x/prices/keeper/market_param_test.go | 12 ++++++------ protocol/x/prices/keeper/market_price_test.go | 12 ++++++------ protocol/x/prices/keeper/market_test.go | 13 +++++++++---- .../msg_server_create_oracle_market_test.go | 5 +++-- .../msg_server_update_market_param_test.go | 5 +++-- .../msg_server_update_market_prices_test.go | 8 ++++---- .../x/prices/keeper/slinky_adapter_test.go | 10 +++++----- protocol/x/prices/keeper/update_price_test.go | 2 +- .../validate_market_price_updates_test.go | 8 ++++---- protocol/x/prices/module.go | 9 ++++++--- protocol/x/prices/module_test.go | 6 ++++-- protocol/x/prices/types/expected_keepers.go | 8 +++++++- 30 files changed, 127 insertions(+), 85 deletions(-) diff --git a/protocol/app/app.go b/protocol/app/app.go index 03a2a31603..1ad8f128f5 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -891,18 +891,18 @@ func New( } app.PricesKeeper = *pricesmodulekeeper.NewKeeper( - appCodec, - keys[pricesmoduletypes.StoreKey], - indexPriceCache, - timeProvider, - app.IndexerEventManager, - // set the governance and delaymsg module accounts as the authority for conducting upgrades - []string{ + appCodec, keys[pricesmoduletypes.StoreKey], indexPriceCache, timeProvider, app.IndexerEventManager, []string{ lib.GovModuleAddress.String(), delaymsgmoduletypes.ModuleAddress.String(), - }, + }, nil, + ) + pricesModule := pricesmodule.NewAppModule( + appCodec, + app.PricesKeeper, + app.AccountKeeper, + app.BankKeeper, + app.RevShareKeeper, ) - pricesModule := pricesmodule.NewAppModule(appCodec, app.PricesKeeper, app.AccountKeeper, app.BankKeeper) app.AssetsKeeper = *assetsmodulekeeper.NewKeeper( appCodec, diff --git a/protocol/app/prepare/prepare_proposal_test.go b/protocol/app/prepare/prepare_proposal_test.go index b2cd1e27d7..ff812de091 100644 --- a/protocol/app/prepare/prepare_proposal_test.go +++ b/protocol/app/prepare/prepare_proposal_test.go @@ -361,7 +361,7 @@ func TestPrepareProposalHandler(t *testing.T) { mockClobKeeper.On("GetOperations", mock.Anything, mock.Anything). Return(tc.clobResp) - ctx, _, _, _, _ := keepertest.PricesKeepers(t) + ctx, _, _, _, _, _ := keepertest.PricesKeepers(t) handler := prepare.PrepareProposalHandler( mockTxConfig, @@ -440,7 +440,7 @@ func TestPrepareProposalHandler_OtherTxs(t *testing.T) { mockBridgeKeeper.On("GetAcknowledgeBridges", mock.Anything, mock.Anything). Return(constants.MsgAcknowledgeBridges_Ids0_1_Height0) - ctx, _, _, _, _ := keepertest.PricesKeepers(t) + ctx, _, _, _, _, _ := keepertest.PricesKeepers(t) handler := prepare.PrepareProposalHandler( encodingCfg.TxConfig, diff --git a/protocol/app/process/full_node_process_proposal_test.go b/protocol/app/process/full_node_process_proposal_test.go index e0d0104882..2f62455671 100644 --- a/protocol/app/process/full_node_process_proposal_test.go +++ b/protocol/app/process/full_node_process_proposal_test.go @@ -73,7 +73,7 @@ func TestFullNodeProcessProposalHandler(t *testing.T) { // Setup. _, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t) - ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, pricesKeeper) indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate) diff --git a/protocol/app/process/market_prices_test.go b/protocol/app/process/market_prices_test.go index a77bf9c188..33969f6037 100644 --- a/protocol/app/process/market_prices_test.go +++ b/protocol/app/process/market_prices_test.go @@ -65,7 +65,7 @@ func TestDecodeUpdateMarketPricesTx(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, k, _, _, _ := keepertest.PricesKeepers(t) + ctx, k, _, _, _, _ := keepertest.PricesKeepers(t) pricesTxDecoder := process.NewDefaultUpdateMarketPriceTxDecoder(k, encodingCfg.TxConfig.TxDecoder()) umpt, err := pricesTxDecoder.DecodeUpdateMarketPricesTx(ctx, [][]byte{tc.txBytes}) if tc.expectedErr != nil { @@ -120,7 +120,7 @@ func TestUpdateMarketPricesTx_Validate(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, k) indexPriceCache.UpdatePrices(tc.indexPrices) @@ -162,7 +162,7 @@ func TestUpdateMarketPricesTx_GetMsg(t *testing.T) { t.Run(name, func(t *testing.T) { var msg sdk.Msg if tc.txBytes != nil { - ctx, k, _, _, _ := keepertest.PricesKeepers(t) + ctx, k, _, _, _, _ := keepertest.PricesKeepers(t) // Decode. pricesTxDecoder := process.NewDefaultUpdateMarketPriceTxDecoder(k, constants.TestEncodingCfg.TxConfig.TxDecoder()) diff --git a/protocol/app/process/process_proposal_test.go b/protocol/app/process/process_proposal_test.go index cccf4cee36..5c414e9c8a 100644 --- a/protocol/app/process/process_proposal_test.go +++ b/protocol/app/process/process_proposal_test.go @@ -258,7 +258,7 @@ func TestProcessProposalHandler_Error(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, pricesKeeper) indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate) diff --git a/protocol/app/process/transactions_test.go b/protocol/app/process/transactions_test.go index 62a93bc627..ec127a3ecd 100644 --- a/protocol/app/process/transactions_test.go +++ b/protocol/app/process/transactions_test.go @@ -108,7 +108,7 @@ func TestDecodeProcessProposalTxs_Error(t *testing.T) { t.Run(name, func(t *testing.T) { // Setup. _, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t) - ctx, pricesKeeper, _, _, _ := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, _, _, _ := keepertest.PricesKeepers(t) // Run. _, err := process.DecodeProcessProposalTxs( @@ -188,7 +188,7 @@ func TestDecodeProcessProposalTxs_Valid(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, pricesKeeper, _, _, _ := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, _, _, _ := keepertest.PricesKeepers(t) _, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t) // Run. @@ -318,7 +318,7 @@ func TestProcessProposalTxs_Validate_Error(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, pricesKeeper) indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate) @@ -425,7 +425,7 @@ func TestProcessProposalTxs_Validate_Valid(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, pricesKeeper) indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate) diff --git a/protocol/testutil/keeper/assets.go b/protocol/testutil/keeper/assets.go index 7b159f4f2d..1c11790cba 100644 --- a/protocol/testutil/keeper/assets.go +++ b/protocol/testutil/keeper/assets.go @@ -1,9 +1,10 @@ package keeper import ( + "testing" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" - "testing" indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" @@ -56,7 +57,7 @@ func AssetsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey) + pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) accountKeeper, _ = createAccountKeeper(stateStore, db, cdc, registry) bankKeeper, _ = createBankKeeper(stateStore, db, cdc, accountKeeper) keeper, storeKey = createAssetsKeeper(stateStore, db, cdc, pricesKeeper, transientStoreKey, msgSenderEnabled) diff --git a/protocol/testutil/keeper/clob.go b/protocol/testutil/keeper/clob.go index eea0d216cd..5c4d75b391 100644 --- a/protocol/testutil/keeper/clob.go +++ b/protocol/testutil/keeper/clob.go @@ -79,7 +79,13 @@ func NewClobKeepersTestContextWithUninitializedMemStore( indexerEventsTransientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, indexerEventsTransientStoreKey) + ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper( + stateStore, + db, + cdc, + indexerEventsTransientStoreKey, + nil, + ) // Mock time provider response for market creation. mockTimeProvider.On("Now").Return(constants.TimeT) epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) diff --git a/protocol/testutil/keeper/perpetuals.go b/protocol/testutil/keeper/perpetuals.go index 4655ebc8a2..932658050e 100644 --- a/protocol/testutil/keeper/perpetuals.go +++ b/protocol/testutil/keeper/perpetuals.go @@ -69,6 +69,7 @@ func PerpetualsKeepersWithClobHelpers( db, cdc, transientStoreKey, + nil, ) pc.EpochsKeeper, _ = createEpochsKeeper(stateStore, db, cdc) pc.PerpetualsKeeper, pc.StoreKey = createPerpetualsKeeperWithClobHelpers( diff --git a/protocol/testutil/keeper/prices.go b/protocol/testutil/keeper/prices.go index 862a63f3e3..5e56d5f367 100644 --- a/protocol/testutil/keeper/prices.go +++ b/protocol/testutil/keeper/prices.go @@ -2,9 +2,10 @@ package keeper import ( "fmt" - "github.com/cosmos/gogoproto/proto" "testing" + "github.com/cosmos/gogoproto/proto" + storetypes "cosmossdk.io/store/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/codec" @@ -20,18 +21,18 @@ import ( delaymsgmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/delaymsg/types" "github.com/dydxprotocol/v4-chain/protocol/x/prices/keeper" "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" + revsharekeeper "github.com/dydxprotocol/v4-chain/protocol/x/revshare/keeper" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) -func PricesKeepers( - t testing.TB, -) ( +func PricesKeepers(t testing.TB) ( ctx sdk.Context, keeper *keeper.Keeper, storeKey storetypes.StoreKey, indexPriceCache *pricefeedserver_types.MarketToExchangePrices, mockTimeProvider *mocks.TimeProvider, + revShareKeeper *revsharekeeper.Keeper, ) { ctx = initKeepers(t, func( db *dbm.MemDB, @@ -40,14 +41,17 @@ func PricesKeepers( stateStore storetypes.CommitMultiStore, transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { + // Necessary keeper for testing + revShareKeeper, _, _ = createRevShareKeeper(stateStore, db, cdc) + // Define necessary keepers here for unit tests keeper, storeKey, indexPriceCache, mockTimeProvider = - createPricesKeeper(stateStore, db, cdc, transientStoreKey) + createPricesKeeper(stateStore, db, cdc, transientStoreKey, revShareKeeper) return []GenesisInitializer{keeper} }) - return ctx, keeper, storeKey, indexPriceCache, mockTimeProvider + return ctx, keeper, storeKey, indexPriceCache, mockTimeProvider, revShareKeeper } func createPricesKeeper( @@ -55,6 +59,7 @@ func createPricesKeeper( db *dbm.MemDB, cdc *codec.ProtoCodec, transientStoreKey storetypes.StoreKey, + revShareKeeper *revsharekeeper.Keeper, ) ( *keeper.Keeper, storetypes.StoreKey, @@ -86,6 +91,7 @@ func createPricesKeeper( delaymsgmoduletypes.ModuleAddress.String(), lib.GovModuleAddress.String(), }, + revShareKeeper, ) return k, storeKey, indexPriceCache, mockTimeProvider diff --git a/protocol/testutil/keeper/rewards.go b/protocol/testutil/keeper/rewards.go index c467e278f4..ff50b83ef7 100644 --- a/protocol/testutil/keeper/rewards.go +++ b/protocol/testutil/keeper/rewards.go @@ -1,9 +1,10 @@ package keeper import ( - "github.com/cosmos/gogoproto/proto" "testing" + "github.com/cosmos/gogoproto/proto" + storetypes "cosmossdk.io/store/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/codec" @@ -42,7 +43,7 @@ func RewardsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, _ = createPricesKeeper(stateStore, db, cdc, transientStoreKey) + pricesKeeper, _, _, _ = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) // Mock time provider response for market creation. epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) assetsKeeper, _ = createAssetsKeeper( diff --git a/protocol/testutil/keeper/sending.go b/protocol/testutil/keeper/sending.go index 6fd275bc66..4e67349561 100644 --- a/protocol/testutil/keeper/sending.go +++ b/protocol/testutil/keeper/sending.go @@ -57,7 +57,7 @@ func SendingKeepersWithSubaccountsKeeper(t testing.TB, saKeeper types.Subaccount // Define necessary keepers here for unit tests epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) blockTimeKeeper, _ := createBlockTimeKeeper(stateStore, db, cdc) - ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey) + ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) ks.PerpetualsKeeper, _ = createPerpetualsKeeper( stateStore, db, diff --git a/protocol/testutil/keeper/subaccounts.go b/protocol/testutil/keeper/subaccounts.go index 07b33984b0..365784b5ef 100644 --- a/protocol/testutil/keeper/subaccounts.go +++ b/protocol/testutil/keeper/subaccounts.go @@ -1,10 +1,11 @@ package keeper import ( - "github.com/cosmos/gogoproto/proto" "math/big" "testing" + "github.com/cosmos/gogoproto/proto" + dbm "github.com/cosmos/cosmos-db" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" @@ -52,7 +53,7 @@ func SubaccountsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey) + pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) perpetualsKeeper, _ = createPerpetualsKeeper(stateStore, db, cdc, pricesKeeper, epochsKeeper, transientStoreKey) assetsKeeper, _ = createAssetsKeeper(stateStore, db, cdc, pricesKeeper, transientStoreKey, msgSenderEnabled) diff --git a/protocol/x/prices/genesis_test.go b/protocol/x/prices/genesis_test.go index 3d76af63ac..c067b2e89d 100644 --- a/protocol/x/prices/genesis_test.go +++ b/protocol/x/prices/genesis_test.go @@ -1,9 +1,10 @@ package prices_test import ( - "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" "testing" + "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" "github.com/dydxprotocol/v4-chain/protocol/x/prices" @@ -33,7 +34,7 @@ func TestExportGenesis(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, k, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) prices.InitGenesis(ctx, *k, *tc.genesisState) @@ -50,7 +51,7 @@ func TestExportGenesis(t *testing.T) { } func TestExportGenesis_WithMutation(t *testing.T) { - ctx, k, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) prices.InitGenesis(ctx, *k, *types.DefaultGenesis()) @@ -94,7 +95,7 @@ func invalidGenesis() types.GenesisState { } func TestInitGenesis_Panics(t *testing.T) { - ctx, k, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) // Verify InitGenesis panics when given an invalid genesis state. @@ -104,7 +105,7 @@ func TestInitGenesis_Panics(t *testing.T) { } func TestInitGenesisEmitsMarketUpdates(t *testing.T) { - ctx, k, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) prices.InitGenesis(ctx, *k, constants.Prices_DefaultGenesisState) diff --git a/protocol/x/prices/keeper/grpc_query_market_test.go b/protocol/x/prices/keeper/grpc_query_market_test.go index 959cd646e0..0bb815714e 100644 --- a/protocol/x/prices/keeper/grpc_query_market_test.go +++ b/protocol/x/prices/keeper/grpc_query_market_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "testing" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" @@ -15,7 +16,7 @@ import ( ) func TestMarketPriceQuerySingle(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgs := keepertest.CreateNMarkets(t, ctx, keeper, 2) for _, tc := range []struct { @@ -66,7 +67,7 @@ func TestMarketPriceQuerySingle(t *testing.T) { } func TestMarketPriceQueryPaginated(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgs := keepertest.CreateNMarkets(t, ctx, keeper, 5) prices := make([]types.MarketPrice, len(msgs)) @@ -126,7 +127,7 @@ func TestMarketPriceQueryPaginated(t *testing.T) { } func TestMarketParamQuerySingle(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgs := keepertest.CreateNMarkets(t, ctx, keeper, 2) for _, tc := range []struct { @@ -177,7 +178,7 @@ func TestMarketParamQuerySingle(t *testing.T) { } func TestMarketParamQueryPaginated(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgs := keepertest.CreateNMarkets(t, ctx, keeper, 5) params := make([]types.MarketParam, len(msgs)) diff --git a/protocol/x/prices/keeper/keeper.go b/protocol/x/prices/keeper/keeper.go index 47533ffcc4..45b7503885 100644 --- a/protocol/x/prices/keeper/keeper.go +++ b/protocol/x/prices/keeper/keeper.go @@ -27,6 +27,7 @@ type ( authorities map[string]struct{} currencyPairIDCache *CurrencyPairIDCache currencyPairIdCacheInitialized *atomic.Bool + revShareKeeper types.RevShareKeeper } ) @@ -39,6 +40,7 @@ func NewKeeper( timeProvider libtime.TimeProvider, indexerEventManager indexer_manager.IndexerEventManager, authorities []string, + revShareKeeper types.RevShareKeeper, ) *Keeper { return &Keeper{ cdc: cdc, @@ -50,6 +52,7 @@ func NewKeeper( authorities: lib.UniqueSliceToSet(authorities), currencyPairIDCache: NewCurrencyPairIDCache(), currencyPairIdCacheInitialized: &atomic.Bool{}, // Initialized to false + revShareKeeper: revShareKeeper, } } diff --git a/protocol/x/prices/keeper/keeper_test.go b/protocol/x/prices/keeper/keeper_test.go index a97d761df8..5eaeb54de4 100644 --- a/protocol/x/prices/keeper/keeper_test.go +++ b/protocol/x/prices/keeper/keeper_test.go @@ -8,7 +8,7 @@ import ( ) func TestLogger(t *testing.T) { - ctx, keeper, _, _, _ := keepertest.PricesKeepers(t) + ctx, keeper, _, _, _, _ := keepertest.PricesKeepers(t) logger := keeper.Logger(ctx) require.NotNil(t, logger) } diff --git a/protocol/x/prices/keeper/market.go b/protocol/x/prices/keeper/market.go index e465ec2a87..616d988350 100644 --- a/protocol/x/prices/keeper/market.go +++ b/protocol/x/prices/keeper/market.go @@ -89,6 +89,9 @@ func (k Keeper) CreateMarket( k.marketToCreatedAt[marketParam.Id] = k.timeProvider.Now() metrics.SetMarketPairForTelemetry(marketParam.Id, marketParam.Pair) + // create a new market rev share + k.revShareKeeper.CreateNewMarketRevShare(ctx, marketParam.Id) + return marketParam, nil } diff --git a/protocol/x/prices/keeper/market_param_test.go b/protocol/x/prices/keeper/market_param_test.go index 5591f7aad4..54b0f85b88 100644 --- a/protocol/x/prices/keeper/market_param_test.go +++ b/protocol/x/prices/keeper/market_param_test.go @@ -16,7 +16,7 @@ import ( ) func TestModifyMarketParam(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) @@ -47,7 +47,7 @@ func TestModifyMarketParam(t *testing.T) { } func TestModifyMarketParamUpdatesCache(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) @@ -180,7 +180,7 @@ func TestModifyMarketParam_Errors(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, keeper, _, _, mockTimeKeeper := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeKeeper, _ := keepertest.PricesKeepers(t) mockTimeKeeper.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) keepertest.CreateNMarkets(t, ctx, keeper, 2) @@ -200,7 +200,7 @@ func TestModifyMarketParam_Errors(t *testing.T) { } func TestGetMarketParam(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) for _, item := range items { @@ -215,13 +215,13 @@ func TestGetMarketParam(t *testing.T) { } func TestGetMarketParam_NotFound(t *testing.T) { - ctx, keeper, _, _, _ := keepertest.PricesKeepers(t) + ctx, keeper, _, _, _, _ := keepertest.PricesKeepers(t) _, exists := keeper.GetMarketParam(ctx, uint32(0)) require.False(t, exists) } func TestGetAllMarketParams(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) params := make([]types.MarketParam, len(items)) diff --git a/protocol/x/prices/keeper/market_price_test.go b/protocol/x/prices/keeper/market_price_test.go index 35b720c59f..44afdf7593 100644 --- a/protocol/x/prices/keeper/market_price_test.go +++ b/protocol/x/prices/keeper/market_price_test.go @@ -25,7 +25,7 @@ func createNMarketPriceUpdates( } func TestUpdateMarketPrices(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) @@ -60,7 +60,7 @@ func TestUpdateMarketPrices(t *testing.T) { } func TestUpdateMarketPrices_NotFound(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) priceUpdates := createNMarketPriceUpdates(10) @@ -89,7 +89,7 @@ func TestUpdateMarketPrices_NotFound(t *testing.T) { } func TestGetMarketPrice(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) for _, item := range items { @@ -104,13 +104,13 @@ func TestGetMarketPrice(t *testing.T) { } func TestGetMarketPrice_NotFound(t *testing.T) { - ctx, keeper, _, _, _ := keepertest.PricesKeepers(t) + ctx, keeper, _, _, _, _ := keepertest.PricesKeepers(t) _, err := keeper.GetMarketPrice(ctx, uint32(0)) require.EqualError(t, err, "0: Market price does not exist") } func TestGetAllMarketPrices(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) prices := make([]types.MarketPrice, len(items)) @@ -126,7 +126,7 @@ func TestGetAllMarketPrices(t *testing.T) { } func TestGetMarketIdToValidIndexPrice(t *testing.T) { - ctx, keeper, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) // Now() is used by `GetMarketIdToValidIndexPrice` internally compare with the cutoff time // of each price. mockTimeProvider.On("Now").Return(constants.TimeT) diff --git a/protocol/x/prices/keeper/market_test.go b/protocol/x/prices/keeper/market_test.go index 35872d4091..d5509bfeef 100644 --- a/protocol/x/prices/keeper/market_test.go +++ b/protocol/x/prices/keeper/market_test.go @@ -14,7 +14,7 @@ import ( ) func TestCreateMarket(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, revShareKeeper := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) ctx = ctx.WithTxBytes(constants.TestTxBytes) @@ -57,6 +57,11 @@ func TestCreateMarket(t *testing.T) { // Verify expected market event. keepertest.AssertMarketCreateEventInIndexerBlock(t, keeper, ctx, marketParam) + + // Verify market revenue share creation + revShareDetails, err := revShareKeeper.GetMarketMapperRevShareDetails(ctx, marketParam.Id) + require.NoError(t, err) + require.True(t, revShareDetails.ExpirationTs > 0) } func TestMarketIsRecentlyAvailable(t *testing.T) { @@ -88,7 +93,7 @@ func TestMarketIsRecentlyAvailable(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) // Create market with TimeT creation timestamp. mockTimeProvider.On("Now").Return(constants.TimeT).Once() @@ -187,7 +192,7 @@ func TestCreateMarket_Errors(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, keeper, _, _, mockTimeKeeper := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeKeeper, _ := keepertest.PricesKeepers(t) ctx = ctx.WithTxBytes(constants.TestTxBytes) mockTimeKeeper.On("Now").Return(constants.TimeT) @@ -236,7 +241,7 @@ func TestCreateMarket_Errors(t *testing.T) { } func TestGetAllMarketParamPrices(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) items := keepertest.CreateNMarkets(t, ctx, keeper, 10) diff --git a/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go b/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go index ed9bd80919..b29ab3e022 100644 --- a/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go +++ b/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/lib" "testing" + "github.com/dydxprotocol/v4-chain/protocol/lib" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" @@ -90,7 +91,7 @@ func TestCreateOracleMarket(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - ctx, pricesKeeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(pricesKeeper) tc.setup(t, ctx, pricesKeeper) diff --git a/protocol/x/prices/keeper/msg_server_update_market_param_test.go b/protocol/x/prices/keeper/msg_server_update_market_param_test.go index fb2613f082..69732adcbf 100644 --- a/protocol/x/prices/keeper/msg_server_update_market_param_test.go +++ b/protocol/x/prices/keeper/msg_server_update_market_param_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/lib" "testing" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" pricestest "github.com/dydxprotocol/v4-chain/protocol/testutil/prices" @@ -143,7 +144,7 @@ func TestUpdateMarketParam(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, pricesKeeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(pricesKeeper) initialMarketParam, err := pricesKeeper.CreateMarket(ctx, testMarketParam, testMarketPrice) diff --git a/protocol/x/prices/keeper/msg_server_update_market_prices_test.go b/protocol/x/prices/keeper/msg_server_update_market_prices_test.go index 01cf2aabc1..e8be9e030b 100644 --- a/protocol/x/prices/keeper/msg_server_update_market_prices_test.go +++ b/protocol/x/prices/keeper/msg_server_update_market_prices_test.go @@ -186,7 +186,7 @@ func TestUpdateMarketPrices_Valid(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(k) @@ -312,7 +312,7 @@ func TestUpdateMarketPrices_SkipNonDeterministicCheck_Valid(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(k) @@ -376,7 +376,7 @@ func TestUpdateMarketPrices_Error(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, _, mockTimeKeeper := keepertest.PricesKeepers(t) + ctx, k, _, _, mockTimeKeeper, _ := keepertest.PricesKeepers(t) mockTimeKeeper.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(k) keepertest.CreateTestMarkets(t, ctx, k) @@ -399,7 +399,7 @@ func TestUpdateMarketPrices_Error(t *testing.T) { func TestUpdateMarketPrices_Panic(t *testing.T) { // Init. - ctx, _, _, _, _ := keepertest.PricesKeepers(t) + ctx, _, _, _, _, _ := keepertest.PricesKeepers(t) mockKeeper := &mocks.PricesKeeper{} msgServer := keeper.NewMsgServerImpl(mockKeeper) diff --git a/protocol/x/prices/keeper/slinky_adapter_test.go b/protocol/x/prices/keeper/slinky_adapter_test.go index 766c95597d..063fe4952b 100644 --- a/protocol/x/prices/keeper/slinky_adapter_test.go +++ b/protocol/x/prices/keeper/slinky_adapter_test.go @@ -13,7 +13,7 @@ import ( ) func TestGetCurrencyPairFromID(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) marketNumber := 10 @@ -30,7 +30,7 @@ func TestGetCurrencyPairFromID(t *testing.T) { } func TestIDForCurrencyPair(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) marketNumber := 10 @@ -54,7 +54,7 @@ func TestIDForCurrencyPair(t *testing.T) { } func TestGetPriceForCurrencyPair(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) marketNumber := 10 @@ -78,7 +78,7 @@ func TestGetPriceForCurrencyPair(t *testing.T) { } func TestBadMarketData(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) _, err := keeper.CreateMarket( @@ -104,7 +104,7 @@ func TestBadMarketData(t *testing.T) { } func TestGetPrevBlockCPCounter(t *testing.T) { - ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) marketNumber := 10 diff --git a/protocol/x/prices/keeper/update_price_test.go b/protocol/x/prices/keeper/update_price_test.go index db2b017ce4..a8ed6f5a89 100644 --- a/protocol/x/prices/keeper/update_price_test.go +++ b/protocol/x/prices/keeper/update_price_test.go @@ -123,7 +123,7 @@ func TestGetValidMarketPriceUpdates(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) if !tc.skipCreateMarketsAndExchanges { diff --git a/protocol/x/prices/keeper/validate_market_price_updates_test.go b/protocol/x/prices/keeper/validate_market_price_updates_test.go index a89998d90e..67adcf7aba 100644 --- a/protocol/x/prices/keeper/validate_market_price_updates_test.go +++ b/protocol/x/prices/keeper/validate_market_price_updates_test.go @@ -122,7 +122,7 @@ func TestPerformStatefulPriceUpdateValidation_Valid(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, k) @@ -207,7 +207,7 @@ func TestPerformStatefulPriceUpdateValidation_SkipNonDeterministicCheck_Valid(t for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, k) @@ -340,7 +340,7 @@ func TestPerformStatefulPriceUpdateValidation_Error(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, k) @@ -411,7 +411,7 @@ func TestGetMarketsMissingFromPriceUpdates(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { // Setup. - ctx, k, _, indexPriceCache, mockTimeProvider := keepertest.PricesKeepers(t) + ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) keepertest.CreateTestMarkets(t, ctx, k) diff --git a/protocol/x/prices/module.go b/protocol/x/prices/module.go index 3abe0a8a8d..745b1a12c9 100644 --- a/protocol/x/prices/module.go +++ b/protocol/x/prices/module.go @@ -101,9 +101,10 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + revShareKeeper types.RevShareKeeper } func NewAppModule( @@ -111,12 +112,14 @@ func NewAppModule( keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, + revShareKeeper types.RevShareKeeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, accountKeeper: accountKeeper, bankKeeper: bankKeeper, + revShareKeeper: revShareKeeper, } } diff --git a/protocol/x/prices/module_test.go b/protocol/x/prices/module_test.go index 6dc781c82f..0d198ed3b9 100644 --- a/protocol/x/prices/module_test.go +++ b/protocol/x/prices/module_test.go @@ -3,12 +3,13 @@ package prices_test import ( "bytes" "encoding/json" - "github.com/dydxprotocol/v4-chain/protocol/app/module" "net/http" "net/http/httptest" "reflect" "testing" + "github.com/dydxprotocol/v4-chain/protocol/app/module" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" errorsmod "cosmossdk.io/errors" @@ -49,7 +50,7 @@ func createAppModule(t *testing.T) prices.AppModule { func createAppModuleWithKeeper(t *testing.T) (prices.AppModule, *prices_keeper.Keeper, sdk.Context) { appCodec := codec.NewProtoCodec(module.InterfaceRegistry) - ctx, keeper, _, _, mockTimeProvider := keeper.PricesKeepers(t) + ctx, keeper, _, _, mockTimeProvider, _ := keeper.PricesKeepers(t) // Mock the time provider response for market creation. mockTimeProvider.On("Now").Return(constants.TimeT) @@ -58,6 +59,7 @@ func createAppModuleWithKeeper(t *testing.T) (prices.AppModule, *prices_keeper.K *keeper, nil, nil, + nil, ), keeper, ctx } diff --git a/protocol/x/prices/types/expected_keepers.go b/protocol/x/prices/types/expected_keepers.go index a7da337234..e43f2dd92b 100644 --- a/protocol/x/prices/types/expected_keepers.go +++ b/protocol/x/prices/types/expected_keepers.go @@ -2,6 +2,7 @@ package types import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -10,7 +11,12 @@ type AccountKeeper interface { GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI } -// AccountKeeper defines the expected bank keeper used for simulations. +// BankKeeper defines the expected bank keeper used for simulations. type BankKeeper interface { SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins } + +// RevShareKeeper defines the expected revshare keeper used for simulations. +type RevShareKeeper interface { + CreateNewMarketRevShare(ctx sdk.Context, marketId uint32) (err error) +} From 783f791f5c34a4ca0eb65e24f2fafae3141828d3 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Mon, 24 Jun 2024 11:11:42 -0400 Subject: [PATCH 2/6] fix func signature Signed-off-by: Shrenuj Bansal --- protocol/x/prices/types/expected_keepers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/x/prices/types/expected_keepers.go b/protocol/x/prices/types/expected_keepers.go index e43f2dd92b..8d95f4e8f0 100644 --- a/protocol/x/prices/types/expected_keepers.go +++ b/protocol/x/prices/types/expected_keepers.go @@ -18,5 +18,5 @@ type BankKeeper interface { // RevShareKeeper defines the expected revshare keeper used for simulations. type RevShareKeeper interface { - CreateNewMarketRevShare(ctx sdk.Context, marketId uint32) (err error) + CreateNewMarketRevShare(ctx sdk.Context, marketId uint32) } From 8e150bfc1c147bb467830f8dffa1c96bc4effac2 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Mon, 24 Jun 2024 13:47:22 -0400 Subject: [PATCH 3/6] fix wiring in app init Signed-off-by: Shrenuj Bansal --- protocol/app/app.go | 28 ++++++----- protocol/app/simulation_test.go | 3 ++ protocol/testutil/app/app.go | 7 ++- protocol/testutil/keeper/assets.go | 9 +++- protocol/testutil/keeper/clob.go | 4 +- protocol/testutil/keeper/perpetuals.go | 3 +- protocol/testutil/keeper/revshare.go | 63 +++++++++++++++++++++++++ protocol/testutil/keeper/rewards.go | 3 +- protocol/testutil/keeper/sending.go | 9 +++- protocol/testutil/keeper/subaccounts.go | 9 +++- 10 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 protocol/testutil/keeper/revshare.go diff --git a/protocol/app/app.go b/protocol/app/app.go index 1ad8f128f5..d9abcb62f9 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -890,11 +890,26 @@ func New( }() } + app.RevShareKeeper = *revsharemodulekeeper.NewKeeper( + appCodec, + keys[revsharemoduletypes.StoreKey], + []string{ + lib.GovModuleAddress.String(), + }, + ) + revShareModule := revsharemodule.NewAppModule(appCodec, app.RevShareKeeper) + app.PricesKeeper = *pricesmodulekeeper.NewKeeper( - appCodec, keys[pricesmoduletypes.StoreKey], indexPriceCache, timeProvider, app.IndexerEventManager, []string{ + appCodec, + keys[pricesmoduletypes.StoreKey], + indexPriceCache, + timeProvider, + app.IndexerEventManager, + []string{ lib.GovModuleAddress.String(), delaymsgmoduletypes.ModuleAddress.String(), - }, nil, + }, + app.RevShareKeeper, ) pricesModule := pricesmodule.NewAppModule( appCodec, @@ -1120,15 +1135,6 @@ func New( ) listingModule := listingmodule.NewAppModule(appCodec, app.ListingKeeper) - app.RevShareKeeper = *revsharemodulekeeper.NewKeeper( - appCodec, - keys[revsharemoduletypes.StoreKey], - []string{ - lib.GovModuleAddress.String(), - }, - ) - revShareModule := revsharemodule.NewAppModule(appCodec, app.RevShareKeeper) - /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment diff --git a/protocol/app/simulation_test.go b/protocol/app/simulation_test.go index 5dd103c4be..8b043b4032 100644 --- a/protocol/app/simulation_test.go +++ b/protocol/app/simulation_test.go @@ -9,6 +9,8 @@ import ( "testing" "time" + revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" + "cosmossdk.io/log" "cosmossdk.io/math" "cosmossdk.io/store" @@ -133,6 +135,7 @@ var genesisModuleOrder = []string{ rewardsmodule.ModuleName, epochstypes.ModuleName, blocktimetypes.ModuleName, + revsharetypes.ModuleName, } var skippedGenesisModules = map[string]interface{}{ diff --git a/protocol/testutil/app/app.go b/protocol/testutil/app/app.go index b96ae1c4dc..4c669f1259 100644 --- a/protocol/testutil/app/app.go +++ b/protocol/testutil/app/app.go @@ -15,6 +15,8 @@ import ( "testing" "time" + revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" + "cosmossdk.io/log" "cosmossdk.io/store/rootmulti" storetypes "cosmossdk.io/store/types" @@ -202,7 +204,8 @@ type GenesisStates interface { govtypesv1.GenesisState | ratelimittypes.GenesisState | govplus.GenesisState | - vaulttypes.GenesisState + vaulttypes.GenesisState | + revsharetypes.GenesisState } // UpdateGenesisDocWithAppStateForModule updates the supplied genesis doc using the provided function. The function @@ -258,6 +261,8 @@ func UpdateGenesisDocWithAppStateForModule[T GenesisStates](genesisDoc *types.Ge moduleName = govplus.ModuleName case vaulttypes.GenesisState: moduleName = vaulttypes.ModuleName + case revsharetypes.GenesisState: + moduleName = revsharetypes.ModuleName default: panic(fmt.Errorf("Unsupported type %T", t)) } diff --git a/protocol/testutil/keeper/assets.go b/protocol/testutil/keeper/assets.go index 1c11790cba..28750ad311 100644 --- a/protocol/testutil/keeper/assets.go +++ b/protocol/testutil/keeper/assets.go @@ -57,7 +57,14 @@ func AssetsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) + pricesKeeper, _, _, mockTimeProvider = createPricesKeeper( + stateStore, + db, + cdc, + transientStoreKey, + revShareKeeper, + ) accountKeeper, _ = createAccountKeeper(stateStore, db, cdc, registry) bankKeeper, _ = createBankKeeper(stateStore, db, cdc, accountKeeper) keeper, storeKey = createAssetsKeeper(stateStore, db, cdc, pricesKeeper, transientStoreKey, msgSenderEnabled) diff --git a/protocol/testutil/keeper/clob.go b/protocol/testutil/keeper/clob.go index 5c4d75b391..a71dda33dc 100644 --- a/protocol/testutil/keeper/clob.go +++ b/protocol/testutil/keeper/clob.go @@ -79,12 +79,14 @@ func NewClobKeepersTestContextWithUninitializedMemStore( indexerEventsTransientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) + ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper( stateStore, db, cdc, indexerEventsTransientStoreKey, - nil, + revShareKeeper, ) // Mock time provider response for market creation. mockTimeProvider.On("Now").Return(constants.TimeT) diff --git a/protocol/testutil/keeper/perpetuals.go b/protocol/testutil/keeper/perpetuals.go index 932658050e..d294a91ace 100644 --- a/protocol/testutil/keeper/perpetuals.go +++ b/protocol/testutil/keeper/perpetuals.go @@ -64,12 +64,13 @@ func PerpetualsKeepersWithClobHelpers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) pc.PricesKeeper, _, pc.IndexPriceCache, pc.MockTimeProvider = createPricesKeeper( stateStore, db, cdc, transientStoreKey, - nil, + revShareKeeper, ) pc.EpochsKeeper, _ = createEpochsKeeper(stateStore, db, cdc) pc.PerpetualsKeeper, pc.StoreKey = createPerpetualsKeeperWithClobHelpers( diff --git a/protocol/testutil/keeper/revshare.go b/protocol/testutil/keeper/revshare.go new file mode 100644 index 0000000000..a097a3c7e1 --- /dev/null +++ b/protocol/testutil/keeper/revshare.go @@ -0,0 +1,63 @@ +package keeper + +import ( + "testing" + + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" + + storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dydxprotocol/v4-chain/protocol/mocks" + keeper "github.com/dydxprotocol/v4-chain/protocol/x/revshare/keeper" +) + +func RevShareKeepers(t testing.TB) ( + ctx sdk.Context, + keeper *keeper.Keeper, + storeKey storetypes.StoreKey, + mockTimeProvider *mocks.TimeProvider, +) { + ctx = initKeepers( + t, func( + db *dbm.MemDB, + registry codectypes.InterfaceRegistry, + cdc *codec.ProtoCodec, + stateStore storetypes.CommitMultiStore, + transientStoreKey storetypes.StoreKey, + ) []GenesisInitializer { + // Define necessary keepers here for unit tests + keeper, storeKey, mockTimeProvider = + createRevShareKeeper(stateStore, db, cdc) + + return []GenesisInitializer{keeper} + }, + ) + + return ctx, keeper, storeKey, mockTimeProvider +} + +func createRevShareKeeper( + stateStore storetypes.CommitMultiStore, + db *dbm.MemDB, + cdc *codec.ProtoCodec, +) ( + *keeper.Keeper, + storetypes.StoreKey, + *mocks.TimeProvider, +) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + mockTimeProvider := &mocks.TimeProvider{} + + k := keeper.NewKeeper( + cdc, storeKey, []string{ + lib.GovModuleAddress.String(), + }, + ) + + return k, storeKey, mockTimeProvider +} diff --git a/protocol/testutil/keeper/rewards.go b/protocol/testutil/keeper/rewards.go index ff50b83ef7..77976785e8 100644 --- a/protocol/testutil/keeper/rewards.go +++ b/protocol/testutil/keeper/rewards.go @@ -43,7 +43,8 @@ func RewardsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, _ = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) + pricesKeeper, _, _, _ = createPricesKeeper(stateStore, db, cdc, transientStoreKey, revShareKeeper) // Mock time provider response for market creation. epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) assetsKeeper, _ = createAssetsKeeper( diff --git a/protocol/testutil/keeper/sending.go b/protocol/testutil/keeper/sending.go index 4e67349561..7361e6ab72 100644 --- a/protocol/testutil/keeper/sending.go +++ b/protocol/testutil/keeper/sending.go @@ -57,7 +57,14 @@ func SendingKeepersWithSubaccountsKeeper(t testing.TB, saKeeper types.Subaccount // Define necessary keepers here for unit tests epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) blockTimeKeeper, _ := createBlockTimeKeeper(stateStore, db, cdc) - ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) + ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper( + stateStore, + db, + cdc, + transientStoreKey, + revShareKeeper, + ) ks.PerpetualsKeeper, _ = createPerpetualsKeeper( stateStore, db, diff --git a/protocol/testutil/keeper/subaccounts.go b/protocol/testutil/keeper/subaccounts.go index 365784b5ef..cf95cc5980 100644 --- a/protocol/testutil/keeper/subaccounts.go +++ b/protocol/testutil/keeper/subaccounts.go @@ -53,7 +53,14 @@ func SubaccountsKeepers( transientStoreKey storetypes.StoreKey, ) []GenesisInitializer { // Define necessary keepers here for unit tests - pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey, nil) + revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc) + pricesKeeper, _, _, mockTimeProvider = createPricesKeeper( + stateStore, + db, + cdc, + transientStoreKey, + revShareKeeper, + ) epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc) perpetualsKeeper, _ = createPerpetualsKeeper(stateStore, db, cdc, pricesKeeper, epochsKeeper, transientStoreKey) assetsKeeper, _ = createAssetsKeeper(stateStore, db, cdc, pricesKeeper, transientStoreKey, msgSenderEnabled) From 8d09705a85af23f5ad86e966b0ad01bddb33f490 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Mon, 24 Jun 2024 13:57:23 -0400 Subject: [PATCH 4/6] remove revshare from simulation test Signed-off-by: Shrenuj Bansal --- protocol/app/simulation_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/protocol/app/simulation_test.go b/protocol/app/simulation_test.go index 8b043b4032..5dd103c4be 100644 --- a/protocol/app/simulation_test.go +++ b/protocol/app/simulation_test.go @@ -9,8 +9,6 @@ import ( "testing" "time" - revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" - "cosmossdk.io/log" "cosmossdk.io/math" "cosmossdk.io/store" @@ -135,7 +133,6 @@ var genesisModuleOrder = []string{ rewardsmodule.ModuleName, epochstypes.ModuleName, blocktimetypes.ModuleName, - revsharetypes.ModuleName, } var skippedGenesisModules = map[string]interface{}{ From 052641985146422b7afc9f7bdf9ebf219a56ac69 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Mon, 24 Jun 2024 16:25:32 -0400 Subject: [PATCH 5/6] address comment Signed-off-by: Shrenuj Bansal --- protocol/x/prices/keeper/market_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol/x/prices/keeper/market_test.go b/protocol/x/prices/keeper/market_test.go index d5509bfeef..fa988af2fc 100644 --- a/protocol/x/prices/keeper/market_test.go +++ b/protocol/x/prices/keeper/market_test.go @@ -59,9 +59,12 @@ func TestCreateMarket(t *testing.T) { keepertest.AssertMarketCreateEventInIndexerBlock(t, keeper, ctx, marketParam) // Verify market revenue share creation + revShareParams := revShareKeeper.GetMarketMapperRevenueShareParams(ctx) revShareDetails, err := revShareKeeper.GetMarketMapperRevShareDetails(ctx, marketParam.Id) require.NoError(t, err) - require.True(t, revShareDetails.ExpirationTs > 0) + + expirationTs := uint64(ctx.BlockTime().Unix() + int64(revShareParams.ValidDays*24*3600)) + require.Equal(t, revShareDetails.ExpirationTs, expirationTs) } func TestMarketIsRecentlyAvailable(t *testing.T) { From 729116752b73b587dceca4584201a497b5dee31f Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Mon, 24 Jun 2024 16:27:38 -0400 Subject: [PATCH 6/6] reinstate comment Signed-off-by: Shrenuj Bansal --- protocol/app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/protocol/app/app.go b/protocol/app/app.go index d9abcb62f9..454dfdd1b8 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -905,6 +905,7 @@ func New( indexPriceCache, timeProvider, app.IndexerEventManager, + // set the governance and delaymsg module accounts as the authority for conducting upgrades []string{ lib.GovModuleAddress.String(), delaymsgmoduletypes.ModuleAddress.String(),