diff --git a/app/app.go b/app/app.go index 86b551dd9..f91c59245 100644 --- a/app/app.go +++ b/app/app.go @@ -8,12 +8,6 @@ import ( "os" "path/filepath" - "github.com/NibiruChain/nibiru/x/genmsg" - - "github.com/NibiruChain/nibiru/x/sudo/keeper" - - sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" - "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" dbm "github.com/cometbft/cometbft-db" @@ -96,18 +90,17 @@ import ( "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/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" - - 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" - 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" @@ -120,6 +113,8 @@ import ( stablecoinkeeper "github.com/NibiruChain/nibiru/x/stablecoin/keeper" stablecointypes "github.com/NibiruChain/nibiru/x/stablecoin/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" ) @@ -343,7 +338,7 @@ func NewNibiruApp( bApp.SetInterfaceRegistry(interfaceRegistry) bApp.SetTxEncoder(txConfig.TxEncoder()) - keys, tkeys, memKeys := GetStoreKeys() + keys, tkeys, memKeys := initStoreKeys() app := &NibiruApp{ BaseApp: bApp, legacyAmino: legacyAmino, @@ -363,7 +358,7 @@ func NewNibiruApp( skipGenesisInvariants := cast.ToBool( appOpts.Get(crisis.FlagSkipGenesisInvariants)) - app.InitModuleManager(encodingConfig, skipGenesisInvariants) + app.initModuleManager(encodingConfig, skipGenesisInvariants) // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. diff --git a/app/keepers.go b/app/keepers.go index 170d35669..10051070a 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -3,12 +3,8 @@ package app import ( "path/filepath" - "github.com/NibiruChain/nibiru/x/genmsg" - - "github.com/NibiruChain/nibiru/x/sudo/keeper" - - sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" - + "github.com/CosmWasm/wasmd/x/wasm" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" _ "github.com/cosmos/cosmos-sdk/client/docs/statik" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -80,41 +76,34 @@ import ( ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" "github.com/spf13/cast" + "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/epochs" epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper" epochstypes "github.com/NibiruChain/nibiru/x/epochs/types" - - "github.com/NibiruChain/nibiru/x/sudo" - + "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" - 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" - - "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/spot" spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper" spottypes "github.com/NibiruChain/nibiru/x/spot/types" - "github.com/NibiruChain/nibiru/x/stablecoin" stablecoinkeeper "github.com/NibiruChain/nibiru/x/stablecoin/keeper" stablecointypes "github.com/NibiruChain/nibiru/x/stablecoin/types" - - "github.com/CosmWasm/wasmd/x/wasm" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/NibiruChain/nibiru/x/sudo" + "github.com/NibiruChain/nibiru/x/sudo/keeper" + sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" ) -func GetStoreKeys() ( +func initStoreKeys() ( keys map[string]*types.KVStoreKey, tkeys map[string]*types.TransientStoreKey, memKeys map[string]*types.MemoryStoreKey, @@ -209,7 +198,7 @@ func (app *NibiruApp) InitKeepers( appCodec, keys[banktypes.StoreKey], app.AccountKeeper, - BlockedAddresses(), + blockedAddresses(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.stakingKeeper = stakingkeeper.NewKeeper( @@ -489,29 +478,14 @@ func (app *NibiruApp) InitKeepers( return wasmConfig } -func (app *NibiruApp) AppModules( +func (app *NibiruApp) initAppModules( encodingConfig EncodingConfig, skipGenesisInvariants bool, ) []module.AppModule { appCodec := app.appCodec - spotModule := spot.NewAppModule( - appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper) - oracleModule := oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper) - epochsModule := epochs.NewAppModule(appCodec, app.EpochsKeeper) - stablecoinModule := stablecoin.NewAppModule( - appCodec, app.StablecoinKeeper, app.AccountKeeper, app.BankKeeper, - nil, - ) - perpv2Module := perpv2.NewAppModule( - appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, - ) - inflationModule := inflation.NewAppModule( - app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper, - ) - sudoModule := sudo.NewAppModule(appCodec, app.SudoKeeper) - genMsgModule := genmsg.NewAppModule(app.MsgServiceRouter()) return []module.AppModule{ + // core modules genutil.NewAppModule( app.AccountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig, @@ -522,7 +496,6 @@ func (app *NibiruApp) AppModules( capability.NewAppModule(appCodec, *app.capabilityKeeper, false), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), - // TODO dont we have mint module? slashing.NewAppModule(appCodec, app.slashingKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper, app.GetSubspace(distrtypes.ModuleName)), staking.NewAppModule(appCodec, app.stakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), @@ -530,16 +503,15 @@ func (app *NibiruApp) AppModules( params.NewAppModule(app.paramsKeeper), authzmodule.NewAppModule(appCodec, app.authzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - // native x/ - spotModule, - stablecoinModule, - oracleModule, - epochsModule, - perpv2Module, - inflationModule, - sudoModule, - perpv2Module, - genMsgModule, + // Nibiru modules + spot.NewAppModule(appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper), + stablecoin.NewAppModule(appCodec, app.StablecoinKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper), + 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), + inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper), + sudo.NewAppModule(appCodec, app.SudoKeeper), + genmsg.NewAppModule(app.MsgServiceRouter()), // ibc evidence.NewAppModule(app.evidenceKeeper), @@ -555,12 +527,13 @@ func (app *NibiruApp) AppModules( devgas.NewAppModule( app.DevGasKeeper, app.AccountKeeper, app.GetSubspace(devgastypes.ModuleName)), + crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them } } -// OrderedModuleNames: Module names ordered for the begin and end block hooks -func OrderedModuleNames() []string { +// orderedModuleNames: Module names ordered for the begin and end block hooks +func orderedModuleNames() []string { return []string{ // -------------------------------------------------------------------- // Cosmos-SDK modules @@ -622,22 +595,10 @@ func OrderedModuleNames() []string { } } -// GetMaccPerms returns a copy of the module account permissions -// -// NOTE: This is solely to be used for testing purposes. -func GetMaccPerms() map[string][]string { - dupMaccPerms := make(map[string][]string) - for k, v := range maccPerms { - dupMaccPerms[k] = v - } - - return dupMaccPerms -} - -// BlockedAddresses returns all the app's blocked account addresses. -func BlockedAddresses() map[string]bool { +// blockedAddresses returns all the app's blocked account addresses. +func blockedAddresses() map[string]bool { modAccAddrs := make(map[string]bool) - for acc := range GetMaccPerms() { + for acc := range maccPerms { modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true } @@ -647,22 +608,23 @@ func BlockedAddresses() map[string]bool { return modAccAddrs } -// InitModuleManager Load all the modules and stores them in the module manager +// initModuleManager Load all the modules and stores them in the module manager // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. -func (app *NibiruApp) InitModuleManager( +func (app *NibiruApp) initModuleManager( encodingConfig EncodingConfig, skipGenesisInvariants bool, ) { app.mm = module.NewManager( - app.AppModules(encodingConfig, skipGenesisInvariants)..., + app.initAppModules(encodingConfig, skipGenesisInvariants)..., ) // Init module orders for hooks and genesis - moduleNames := OrderedModuleNames() - app.mm.SetOrderBeginBlockers(moduleNames...) - app.mm.SetOrderEndBlockers(moduleNames...) - app.mm.SetOrderInitGenesis(moduleNames...) + orderedModules := orderedModuleNames() + app.mm.SetOrderBeginBlockers(orderedModules...) + app.mm.SetOrderEndBlockers(orderedModules...) + app.mm.SetOrderInitGenesis(orderedModules...) + app.mm.SetOrderExportGenesis(orderedModules...) // Uncomment if you want to set a custom migration order here. // app.mm.SetOrderMigrations(custom order) diff --git a/app/modules.go b/app/modules.go index e310f4554..2ac2ca7dc 100644 --- a/app/modules.go +++ b/app/modules.go @@ -12,8 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/mint" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -79,19 +77,6 @@ func (CrisisModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(genState) } -// MintModule defines a custom wrapper around the x/mint module's -// AppModuleBasic implementation to provide custom default genesis state. -type MintModule struct { - mint.AppModuleBasic -} - -// DefaultGenesis returns custom Nibiru x/mint module genesis state. -func (MintModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - genState := minttypes.DefaultGenesisState() - genState.Params.MintDenom = BondDenom - return cdc.MustMarshalJSON(genState) -} - // GovModule defines a custom wrapper around the x/gov module's // AppModuleBasic implementation to provide custom default genesis state. type GovModule struct {