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 all commits
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
27 changes: 17 additions & 10 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,15 @@ 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],
Expand All @@ -901,8 +910,15 @@ func New(
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
app.RevShareKeeper,
)
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,
Expand Down Expand Up @@ -1120,15 +1136,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
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
7 changes: 6 additions & 1 deletion protocol/testutil/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down
12 changes: 10 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,14 @@ func AssetsKeepers(
transientStoreKey storetypes.StoreKey,
) []GenesisInitializer {
// Define necessary keepers here for unit tests
pricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, transientStoreKey)
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)
Expand Down
10 changes: 9 additions & 1 deletion protocol/testutil/keeper/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ func NewClobKeepersTestContextWithUninitializedMemStore(
indexerEventsTransientStoreKey storetypes.StoreKey,
) []GenesisInitializer {
// Define necessary keepers here for unit tests
ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(stateStore, db, cdc, indexerEventsTransientStoreKey)
revShareKeeper, _, _ := createRevShareKeeper(stateStore, db, cdc)

ks.PricesKeeper, _, _, mockTimeProvider = createPricesKeeper(
stateStore,
db,
cdc,
indexerEventsTransientStoreKey,
revShareKeeper,
)
// Mock time provider response for market creation.
mockTimeProvider.On("Now").Return(constants.TimeT)
epochsKeeper, _ := createEpochsKeeper(stateStore, db, cdc)
Expand Down
2 changes: 2 additions & 0 deletions protocol/testutil/keeper/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +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,
revShareKeeper,
)
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
63 changes: 63 additions & 0 deletions protocol/testutil/keeper/revshare.go
Original file line number Diff line number Diff line change
@@ -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
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
}

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
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 4 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,8 @@ func RewardsKeepers(
transientStoreKey storetypes.StoreKey,
) []GenesisInitializer {
// Define necessary keepers here for unit tests
pricesKeeper, _, _, _ = createPricesKeeper(stateStore, db, cdc, transientStoreKey)
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(
Expand Down
Loading
Loading