From 6096e2bab0d331ed42fcfc1c8fcd1ed718921e34 Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Fri, 29 Sep 2023 08:26:33 -0500 Subject: [PATCH] refactor(app): Simplify app.go with less redundant imports using struct embedding. (#1610) * refactor: rm x/stablecoin * changelog * change log number * refactor(app): Simplify app.go with less redundant imports using struct embedding. --- CHANGELOG.md | 6 +- app/app.go | 233 ++----------------------------------------------- app/keepers.go | 195 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 198 insertions(+), 236 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4985578f..d74c0def5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,13 +42,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features -* [#xxx](https://github.com/NibiruChain/nibiru/pull/xxx) - epic(tokenfactory): +* [#1596](https://github.com/NibiruChain/nibiru/pull/1596) - epic(tokenfactory): State transitions, collections, genesis import and export, and app wiring ### State Breaking * [#1609](https://github.com/NibiruChain/nibiru/pull/1609) - refactor(app)!: Remove x/stablecoin module. +### Improvements + +* [#1610](https://github.com/NibiruChain/nibiru/pull/1610) - refactor(app): Simplify app.go with less redundant imports using struct embedding. + ## [v0.21.10] ### Features diff --git a/app/app.go b/app/app.go index c2c338283..daadec4d8 100644 --- a/app/app.go +++ b/app/app.go @@ -30,93 +30,20 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/auth/vesting" - authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" - authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/capability" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" - consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" "github.com/cosmos/cosmos-sdk/x/crisis" - crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distr "github.com/cosmos/cosmos-sdk/x/distribution" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/cosmos/cosmos-sdk/x/evidence" - evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" - feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" - "github.com/cosmos/cosmos-sdk/x/params" - paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/cosmos-sdk/x/upgrade" - upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" - upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" - ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" - ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" - ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v7/testing" - ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" "github.com/cosmos/ibc-go/v7/testing/types" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus" "github.com/rakyll/statik/fs" "github.com/spf13/cast" - "github.com/NibiruChain/nibiru/x/common" - devgas "github.com/NibiruChain/nibiru/x/devgas/v1" - devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" - devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types" - - "github.com/NibiruChain/nibiru/x/tokenfactory" - tokenfactorykeeper "github.com/NibiruChain/nibiru/x/tokenfactory/keeper" - tokenfactorytypes "github.com/NibiruChain/nibiru/x/tokenfactory/types" - - "github.com/NibiruChain/nibiru/x/epochs" - epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper" - epochstypes "github.com/NibiruChain/nibiru/x/epochs/types" - "github.com/NibiruChain/nibiru/x/genmsg" - "github.com/NibiruChain/nibiru/x/inflation" - inflationkeeper "github.com/NibiruChain/nibiru/x/inflation/keeper" - inflationtypes "github.com/NibiruChain/nibiru/x/inflation/types" - "github.com/NibiruChain/nibiru/x/oracle" - oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper" - oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" - perpkeeperv2 "github.com/NibiruChain/nibiru/x/perp/v2/keeper" - perpv2 "github.com/NibiruChain/nibiru/x/perp/v2/module" - perptypesv2 "github.com/NibiruChain/nibiru/x/perp/v2/types" - "github.com/NibiruChain/nibiru/x/spot" - spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper" - spottypes "github.com/NibiruChain/nibiru/x/spot/types" - "github.com/NibiruChain/nibiru/x/sudo" - "github.com/NibiruChain/nibiru/x/sudo/keeper" - sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" wasmbinding "github.com/NibiruChain/nibiru/x/wasm/binding" ) @@ -134,71 +61,10 @@ var ( // ModuleBasics defines the module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. - ModuleBasics = module.NewBasicManager( - auth.AppModuleBasic{}, - genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), - BankModule{}, - capability.AppModuleBasic{}, - StakingModule{}, - distr.AppModuleBasic{}, - NewGovModuleBasic( - paramsclient.ProposalHandler, - upgradeclient.LegacyProposalHandler, - upgradeclient.LegacyCancelProposalHandler, - ibcclientclient.UpdateClientProposalHandler, - ibcclientclient.UpgradeProposalHandler, - ), - params.AppModuleBasic{}, - CrisisModule{}, - slashing.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - groupmodule.AppModuleBasic{}, - vesting.AppModuleBasic{}, - // ibc 'AppModuleBasic's - ibc.AppModuleBasic{}, - ibctransfer.AppModuleBasic{}, - ibctm.AppModuleBasic{}, - // native x/ - spot.AppModuleBasic{}, - oracle.AppModuleBasic{}, - epochs.AppModuleBasic{}, - perpv2.AppModuleBasic{}, - inflation.AppModuleBasic{}, - sudo.AppModuleBasic{}, - wasm.AppModuleBasic{}, - devgas.AppModuleBasic{}, - tokenfactory.AppModuleBasic{}, - ibcfee.AppModuleBasic{}, - genmsg.AppModule{}, - ) + ModuleBasics = ModuleBasicManager() // module account permissions - maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - inflationtypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - spottypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - oracletypes.ModuleName: {}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - ibcfeetypes.ModuleName: {}, - - perptypesv2.ModuleName: {}, - perptypesv2.VaultModuleAccount: {}, - perptypesv2.PerpEFModuleAccount: {}, - perptypesv2.FeePoolModuleAccount: {}, - - epochstypes.ModuleName: {}, - sudotypes.ModuleName: {}, - common.TreasuryPoolModuleAccount: {}, - wasm.ModuleName: {authtypes.Burner}, - tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - } + maccPerms = ModuleAccPerms() ) var ( @@ -221,65 +87,7 @@ type NibiruApp struct { tkeys map[string]*storetypes.TransientStoreKey memKeys map[string]*storetypes.MemoryStoreKey - // -------------------------------------------------------------------- - // NibiruTestApp Keepers - // -------------------------------------------------------------------- - - // AccountKeeper encodes/decodes accounts using the go-amino (binary) encoding/decoding library - AccountKeeper authkeeper.AccountKeeper - // BankKeeper defines a module interface that facilitates the transfer of coins between accounts - BankKeeper bankkeeper.Keeper - capabilityKeeper *capabilitykeeper.Keeper - stakingKeeper *stakingkeeper.Keeper - slashingKeeper slashingkeeper.Keeper - /* DistrKeeper is the keeper of the distribution store */ - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - crisisKeeper crisiskeeper.Keeper - upgradeKeeper upgradekeeper.Keeper - paramsKeeper paramskeeper.Keeper - authzKeeper authzkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - ConsensusParamsKeeper consensusparamkeeper.Keeper - - // -------------------------------------------------------------------- - // IBC keepers - // -------------------------------------------------------------------- - /* evidenceKeeper is responsible for managing persistence, state transitions - and query handling for the evidence module. It is required to set up - the IBC light client misbehavior evidence route. */ - evidenceKeeper evidencekeeper.Keeper - - /* ibcKeeper defines each ICS keeper for IBC. ibcKeeper must be a pointer in - the app, so we can SetRouter on it correctly. */ - ibcKeeper *ibckeeper.Keeper - ibcFeeKeeper ibcfeekeeper.Keeper - /* transferKeeper is for cross-chain fungible token transfers. */ - transferKeeper ibctransferkeeper.Keeper - - // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper - - // make IBC modules public for test purposes - // these modules are never directly routed to by the IBC Router - FeeMockModule ibcmock.IBCModule - - // --------------- - // Nibiru keepers - // --------------- - EpochsKeeper epochskeeper.Keeper - PerpKeeperV2 perpkeeperv2.Keeper - SpotKeeper spotkeeper.Keeper - OracleKeeper oraclekeeper.Keeper - InflationKeeper inflationkeeper.Keeper - SudoKeeper keeper.Keeper - DevGasKeeper devgaskeeper.Keeper - TokenFactoryKeeper tokenfactorykeeper.Keeper - - // WASM keepers - WasmKeeper wasm.Keeper - ScopedWasmKeeper capabilitykeeper.ScopedKeeper + AppKeepers // embed all module keepers // the module manager mm *module.Manager @@ -378,12 +186,12 @@ func NewNibiruApp( app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) anteHandler, err := NewAnteHandler(AnteHandlerOptions{ - HandlerOptions: ante.HandlerOptions{ + HandlerOptions: authante.HandlerOptions{ AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, FeegrantKeeper: app.FeeGrantKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + SigGasConsumer: authante.DefaultSigVerificationGasConsumer, }, IBCKeeper: app.ibcKeeper, TxCounterStoreKey: keys[wasm.StoreKey], @@ -603,32 +411,3 @@ func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { staticServer := http.FileServer(statikFS) rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) } - -// initParamsKeeper init params perpammkeeper and its subspaces -func initParamsKeeper( - appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, - tkey storetypes.StoreKey, -) paramskeeper.Keeper { - paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - - paramsKeeper.Subspace(authtypes.ModuleName) - paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName) - paramsKeeper.Subspace(crisistypes.ModuleName) - // Nibiru core params keepers | x/ - paramsKeeper.Subspace(spottypes.ModuleName) - paramsKeeper.Subspace(epochstypes.ModuleName) - paramsKeeper.Subspace(inflationtypes.ModuleName) - // ibc params keepers - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibcexported.ModuleName) - paramsKeeper.Subspace(ibcfeetypes.ModuleName) - // wasm params keepers - paramsKeeper.Subspace(wasm.ModuleName) - paramsKeeper.Subspace(devgastypes.ModuleName) - - return paramsKeeper -} diff --git a/app/keepers.go b/app/keepers.go index 5de5af006..fdba8e1be 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -49,18 +50,29 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + // --------------------------------------------------------------- + // IBC imports + ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" @@ -69,13 +81,19 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" "github.com/spf13/cast" + // --------------------------------------------------------------- + // Nibiru Custom Modules + + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/devgas/v1" devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types" @@ -89,12 +107,14 @@ import ( oracle "github.com/NibiruChain/nibiru/x/oracle" oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" - perpv2keeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper" - perpv2 "github.com/NibiruChain/nibiru/x/perp/v2/module" - perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types" + perpkeeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper" + perpmodule "github.com/NibiruChain/nibiru/x/perp/v2/module" + perptypes "github.com/NibiruChain/nibiru/x/perp/v2/types" + "github.com/NibiruChain/nibiru/x/spot" spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper" spottypes "github.com/NibiruChain/nibiru/x/spot/types" + "github.com/NibiruChain/nibiru/x/sudo" "github.com/NibiruChain/nibiru/x/sudo/keeper" sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" @@ -104,6 +124,64 @@ import ( tokenfactorytypes "github.com/NibiruChain/nibiru/x/tokenfactory/types" ) +type AppKeepers struct { + // AccountKeeper encodes/decodes accounts using the go-amino (binary) encoding/decoding library + AccountKeeper authkeeper.AccountKeeper + // BankKeeper defines a module interface that facilitates the transfer of coins between accounts + BankKeeper bankkeeper.Keeper + capabilityKeeper *capabilitykeeper.Keeper + stakingKeeper *stakingkeeper.Keeper + slashingKeeper slashingkeeper.Keeper + /* DistrKeeper is the keeper of the distribution store */ + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + crisisKeeper crisiskeeper.Keeper + upgradeKeeper upgradekeeper.Keeper + paramsKeeper paramskeeper.Keeper + authzKeeper authzkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + ConsensusParamsKeeper consensusparamkeeper.Keeper + + // -------------------------------------------------------------------- + // IBC keepers + // -------------------------------------------------------------------- + /* evidenceKeeper is responsible for managing persistence, state transitions + and query handling for the evidence module. It is required to set up + the IBC light client misbehavior evidence route. */ + evidenceKeeper evidencekeeper.Keeper + + /* ibcKeeper defines each ICS keeper for IBC. ibcKeeper must be a pointer in + the app, so we can SetRouter on it correctly. */ + ibcKeeper *ibckeeper.Keeper + ibcFeeKeeper ibcfeekeeper.Keeper + /* transferKeeper is for cross-chain fungible token transfers. */ + transferKeeper ibctransferkeeper.Keeper + + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + + // make IBC modules public for test purposes + // these modules are never directly routed to by the IBC Router + FeeMockModule ibcmock.IBCModule + + // --------------- + // Nibiru keepers + // --------------- + EpochsKeeper epochskeeper.Keeper + PerpKeeperV2 perpkeeper.Keeper + SpotKeeper spotkeeper.Keeper + OracleKeeper oraclekeeper.Keeper + InflationKeeper inflationkeeper.Keeper + SudoKeeper keeper.Keeper + DevGasKeeper devgaskeeper.Keeper + TokenFactoryKeeper tokenfactorykeeper.Keeper + + // WASM keepers + WasmKeeper wasm.Keeper + ScopedWasmKeeper capabilitykeeper.ScopedKeeper +} + func initStoreKeys() ( keys map[string]*types.KVStoreKey, tkeys map[string]*types.TransientStoreKey, @@ -134,7 +212,7 @@ func initStoreKeys() ( spottypes.StoreKey, oracletypes.StoreKey, epochstypes.StoreKey, - perpv2types.StoreKey, + perptypes.StoreKey, inflationtypes.StoreKey, sudotypes.StoreKey, wasm.StoreKey, @@ -283,8 +361,8 @@ func (app *NibiruApp) InitKeepers( appCodec, keys[epochstypes.StoreKey], ) - app.PerpKeeperV2 = perpv2keeper.NewKeeper( - appCodec, keys[perpv2types.StoreKey], + app.PerpKeeperV2 = perpkeeper.NewKeeper( + appCodec, keys[perptypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.EpochsKeeper, ) @@ -511,7 +589,7 @@ func (app *NibiruApp) initAppModules( spot.NewAppModule(appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper), oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper), epochs.NewAppModule(appCodec, app.EpochsKeeper), - perpv2.NewAppModule(appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper), + perpmodule.NewAppModule(appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper), inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper), sudo.NewAppModule(appCodec, app.SudoKeeper), genmsg.NewAppModule(app.MsgServiceRouter()), @@ -580,7 +658,7 @@ func orderedModuleNames() []string { epochstypes.ModuleName, spottypes.ModuleName, oracletypes.ModuleName, - perpv2types.ModuleName, + perptypes.ModuleName, inflationtypes.ModuleName, sudotypes.ModuleName, @@ -661,6 +739,107 @@ func (app *NibiruApp) initModuleManager( } } +// ModuleBasicManager: The app's collection of module.AppModuleBasic +// implementations. These set up non-dependant module elements, such as codec +// registration and genesis verification. +func ModuleBasicManager() module.BasicManager { + return module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + BankModule{}, + capability.AppModuleBasic{}, + StakingModule{}, + distr.AppModuleBasic{}, + NewGovModuleBasic( + paramsclient.ProposalHandler, + upgradeclient.LegacyProposalHandler, + upgradeclient.LegacyCancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + ), + params.AppModuleBasic{}, + CrisisModule{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + groupmodule.AppModuleBasic{}, + vesting.AppModuleBasic{}, + // ibc 'AppModuleBasic's + ibc.AppModuleBasic{}, + ibctransfer.AppModuleBasic{}, + ibctm.AppModuleBasic{}, + // native x/ + spot.AppModuleBasic{}, + oracle.AppModuleBasic{}, + epochs.AppModuleBasic{}, + perpmodule.AppModuleBasic{}, + inflation.AppModuleBasic{}, + sudo.AppModuleBasic{}, + wasm.AppModuleBasic{}, + devgas.AppModuleBasic{}, + tokenfactory.AppModuleBasic{}, + ibcfee.AppModuleBasic{}, + genmsg.AppModule{}, + ) +} + +func ModuleAccPerms() map[string][]string { + return map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + inflationtypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + spottypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + oracletypes.ModuleName: {}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibcfeetypes.ModuleName: {}, + + perptypes.ModuleName: {}, + perptypes.VaultModuleAccount: {}, + perptypes.PerpEFModuleAccount: {}, + perptypes.FeePoolModuleAccount: {}, + + epochstypes.ModuleName: {}, + sudotypes.ModuleName: {}, + common.TreasuryPoolModuleAccount: {}, + wasm.ModuleName: {authtypes.Burner}, + tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + } +} + +// initParamsKeeper init params perpammkeeper and its subspaces +func initParamsKeeper( + appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, + tkey storetypes.StoreKey, +) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName) + paramsKeeper.Subspace(crisistypes.ModuleName) + // Nibiru core params keepers | x/ + paramsKeeper.Subspace(spottypes.ModuleName) + paramsKeeper.Subspace(epochstypes.ModuleName) + paramsKeeper.Subspace(inflationtypes.ModuleName) + // ibc params keepers + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibcexported.ModuleName) + paramsKeeper.Subspace(ibcfeetypes.ModuleName) + // wasm params keepers + paramsKeeper.Subspace(wasm.ModuleName) + paramsKeeper.Subspace(devgastypes.ModuleName) + + return paramsKeeper +} + // TODO: Simulation manager func (app *NibiruApp) InitSimulationManager( appCodec codec.Codec,