Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-416] Set market mapper revenue share on market creation #1755

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
[]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,
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
)
pricesModule := pricesmodule.NewAppModule(appCodec, app.PricesKeeper, app.AccountKeeper, app.BankKeeper)

app.AssetsKeeper = *assetsmodulekeeper.NewKeeper(
appCodec,
Expand Down
4 changes: 2 additions & 2 deletions protocol/app/prepare/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocol/app/process/full_node_process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions protocol/app/process/market_prices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion protocol/app/process/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions protocol/app/process/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions protocol/testutil/keeper/assets.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
accountKeeper, _ = createAccountKeeper(stateStore, db, cdc, registry)
bankKeeper, _ = createBankKeeper(stateStore, db, cdc, accountKeeper)
keeper, storeKey = createAssetsKeeper(stateStore, db, cdc, pricesKeeper, transientStoreKey, msgSenderEnabled)
Expand Down
8 changes: 7 additions & 1 deletion protocol/testutil/keeper/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions protocol/testutil/keeper/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func PerpetualsKeepersWithClobHelpers(
db,
cdc,
transientStoreKey,
nil,
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
)
pc.EpochsKeeper, _ = createEpochsKeeper(stateStore, db, cdc)
pc.PerpetualsKeeper, pc.StoreKey = createPerpetualsKeeperWithClobHelpers(
Expand Down
18 changes: 12 additions & 6 deletions protocol/testutil/keeper/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -40,21 +41,25 @@ 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(
stateStore storetypes.CommitMultiStore,
db *dbm.MemDB,
cdc *codec.ProtoCodec,
transientStoreKey storetypes.StoreKey,
revShareKeeper *revsharekeeper.Keeper,
) (
*keeper.Keeper,
storetypes.StoreKey,
Expand Down Expand Up @@ -86,6 +91,7 @@ func createPricesKeeper(
delaymsgmoduletypes.ModuleAddress.String(),
lib.GovModuleAddress.String(),
},
revShareKeeper,
)

return k, storeKey, indexPriceCache, mockTimeProvider
Expand Down
5 changes: 3 additions & 2 deletions protocol/testutil/keeper/rewards.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
// Mock time provider response for market creation.
epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc)
assetsKeeper, _ = createAssetsKeeper(
Expand Down
2 changes: 1 addition & 1 deletion protocol/testutil/keeper/sending.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions protocol/testutil/keeper/subaccounts.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions protocol/x/prices/genesis_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
mockTimeProvider.On("Now").Return(constants.TimeT)

prices.InitGenesis(ctx, *k, *tc.genesisState)
Expand All @@ -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())

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions protocol/x/prices/keeper/grpc_query_market_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
Loading
Loading