diff --git a/app/app.go b/app/app.go index 5366b13b0..c5db7e273 100644 --- a/app/app.go +++ b/app/app.go @@ -9,16 +9,7 @@ import ( "os" "path/filepath" - "github.com/dymensionxyz/dymension/v3/app/keepers" - "github.com/dymensionxyz/dymension/v3/app/upgrades" - v3 "github.com/dymensionxyz/dymension/v3/app/upgrades/v3" - v4 "github.com/dymensionxyz/dymension/v3/app/upgrades/v4" - "github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis" - - "github.com/dymensionxyz/dymension/v3/x/bridgingfee" - - vfchooks "github.com/dymensionxyz/dymension/v3/x/vfc/hooks" - + "github.com/cosmos/cosmos-sdk/store/streaming" "github.com/gorilla/mux" "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" @@ -27,6 +18,11 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" + "github.com/dymensionxyz/dymension/v3/app/keepers" + "github.com/dymensionxyz/dymension/v3/app/upgrades" + v3 "github.com/dymensionxyz/dymension/v3/app/upgrades/v3" + v4 "github.com/dymensionxyz/dymension/v3/app/upgrades/v4" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -37,116 +33,21 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/store/streaming" - - 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/version" - "github.com/cosmos/cosmos-sdk/x/auth" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" 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" - vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - "github.com/cosmos/cosmos-sdk/x/authz" - authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" - authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" - "github.com/cosmos/cosmos-sdk/x/bank" - 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" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "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" - distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" - 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" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" - 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" - "github.com/cosmos/cosmos-sdk/x/gov" - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/cosmos/cosmos-sdk/x/mint" - mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "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" "github.com/dymensionxyz/dymension/v3/docs" - ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v6/modules/core" - ibcclient "github.com/cosmos/ibc-go/v6/modules/core/02-client" - ibcclientclient "github.com/cosmos/ibc-go/v6/modules/core/02-client/client" - ibcclienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" - ibcporttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" - ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" - ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" - ibctesting "github.com/cosmos/ibc-go/v6/testing" - ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + ibctesting "github.com/cosmos/ibc-go/v6/testing" "github.com/dymensionxyz/dymension/v3/app/ante" appparams "github.com/dymensionxyz/dymension/v3/app/params" - rollappmodule "github.com/dymensionxyz/dymension/v3/x/rollapp" - rollappmoduleclient "github.com/dymensionxyz/dymension/v3/x/rollapp/client" - rollappmodulekeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" - rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" - - sequencermodule "github.com/dymensionxyz/dymension/v3/x/sequencer" - sequencermodulekeeper "github.com/dymensionxyz/dymension/v3/x/sequencer/keeper" - sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" - - streamermodule "github.com/dymensionxyz/dymension/v3/x/streamer" - streamermoduleclient "github.com/dymensionxyz/dymension/v3/x/streamer/client" - streamermodulekeeper "github.com/dymensionxyz/dymension/v3/x/streamer/keeper" - streamermoduletypes "github.com/dymensionxyz/dymension/v3/x/streamer/types" - - denommetadatamodule "github.com/dymensionxyz/dymension/v3/x/denommetadata" - denommetadatamoduleclient "github.com/dymensionxyz/dymension/v3/x/denommetadata/client" - denommetadatamodulekeeper "github.com/dymensionxyz/dymension/v3/x/denommetadata/keeper" - denommetadatamoduletypes "github.com/dymensionxyz/dymension/v3/x/denommetadata/types" - - delayedackmodule "github.com/dymensionxyz/dymension/v3/x/delayedack" - delayedackkeeper "github.com/dymensionxyz/dymension/v3/x/delayedack/keeper" - delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" - - eibcmodule "github.com/dymensionxyz/dymension/v3/x/eibc" - eibckeeper "github.com/dymensionxyz/dymension/v3/x/eibc/keeper" - eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types" - packetforwardmiddleware "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper" packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" @@ -157,142 +58,22 @@ import ( "github.com/evmos/ethermint/server/flags" ethermint "github.com/evmos/ethermint/types" - "github.com/evmos/ethermint/x/evm" - evmclient "github.com/evmos/ethermint/x/evm/client" - evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/evmos/ethermint/x/evm/vm/geth" - "github.com/evmos/ethermint/x/feemarket" - feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper" - feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - - /* ----------------------------- osmosis imports ---------------------------- */ - - "github.com/osmosis-labs/osmosis/v15/x/epochs" - epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper" - epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types" - "github.com/osmosis-labs/osmosis/v15/x/lockup" - lockupkeeper "github.com/osmosis-labs/osmosis/v15/x/lockup/keeper" - lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" - - "github.com/osmosis-labs/osmosis/v15/x/gamm" - gammkeeper "github.com/osmosis-labs/osmosis/v15/x/gamm/keeper" - gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" - "github.com/osmosis-labs/osmosis/v15/x/incentives" - incentiveskeeper "github.com/osmosis-labs/osmosis/v15/x/incentives/keeper" - incentivestypes "github.com/osmosis-labs/osmosis/v15/x/incentives/types" - "github.com/osmosis-labs/osmosis/v15/x/poolmanager" - poolmanagerkeeper "github.com/osmosis-labs/osmosis/v15/x/poolmanager/keeper" - poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" - - "github.com/osmosis-labs/osmosis/v15/x/txfees" - txfeeskeeper "github.com/osmosis-labs/osmosis/v15/x/txfees/keeper" - txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types" -) + /* ----------------------------- osmosis imports ---------------------------- */ /* ---------------------------- upgrade handlers ---------------------------- */) var ( _ = packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp _ = packetforwardmiddleware.AppModule{} _ = packetforwardtypes.ErrIntOverflowGenesis -) - -func getGovProposalHandlers() []govclient.ProposalHandler { - var govProposalHandlers []govclient.ProposalHandler - - govProposalHandlers = append(govProposalHandlers, - paramsclient.ProposalHandler, - distrclient.ProposalHandler, - upgradeclient.LegacyProposalHandler, - upgradeclient.LegacyCancelProposalHandler, - ibcclientclient.UpdateClientProposalHandler, - ibcclientclient.UpgradeProposalHandler, - streamermoduleclient.CreateStreamHandler, - streamermoduleclient.TerminateStreamHandler, - streamermoduleclient.ReplaceStreamHandler, - streamermoduleclient.UpdateStreamHandler, - rollappmoduleclient.SubmitFraudHandler, - denommetadatamoduleclient.CreateDenomMetadataHandler, - denommetadatamoduleclient.UpdateDenomMetadataHandler, - evmclient.UpdateVirtualFrontierBankContractProposalHandler, - ) - return govProposalHandlers -} + _ servertypes.Application = (*App)(nil) + _ simapp.App = (*App)(nil) + _ ibctesting.TestingApp = (*App)(nil) -var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string + // Upgrades contains the upgrade handlers for the application Upgrades = []upgrades.Upgrade{v3.Upgrade, v4.Upgrade} - - // 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{}, - authzmodule.AppModuleBasic{}, - genutil.AppModuleBasic{}, - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - staking.AppModuleBasic{}, - mint.AppModuleBasic{}, - distr.AppModuleBasic{}, - gov.NewAppModuleBasic(getGovProposalHandlers()), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - ibc.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - ibctransfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - rollappmodule.AppModuleBasic{}, - sequencermodule.AppModuleBasic{}, - streamermodule.AppModuleBasic{}, - denommetadatamodule.AppModuleBasic{}, - packetforwardmiddleware.AppModuleBasic{}, - delayedackmodule.AppModuleBasic{}, - eibcmodule.AppModuleBasic{}, - - // Ethermint modules - evm.AppModuleBasic{}, - feemarket.AppModuleBasic{}, - - // Osmosis modules - lockup.AppModuleBasic{}, - epochs.AppModuleBasic{}, - gamm.AppModuleBasic{}, - poolmanager.AppModuleBasic{}, - incentives.AppModuleBasic{}, - txfees.AppModuleBasic{}, - ) - - // module account permissions - maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - sequencermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, - rollappmoduletypes.ModuleName: {}, - streamermoduletypes.ModuleName: nil, - evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account. - evmtypes.ModuleVirtualFrontierContractDeployerName: nil, // used for deploying virtual frontier bank contract. - gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - txfeestypes.ModuleName: {authtypes.Burner}, - } -) - -var ( - _ servertypes.Application = (*App)(nil) - _ simapp.App = (*App)(nil) - _ ibctesting.TestingApp = (*App)(nil) ) func init() { @@ -316,18 +97,10 @@ type App struct { appCodec codec.Codec interfaceRegistry types.InterfaceRegistry - invCheckPeriod uint - - // keys to access the substores - keys map[string]*storetypes.KVStoreKey - tkeys map[string]*storetypes.TransientStoreKey - memKeys map[string]*storetypes.MemoryStoreKey - // keepers keepers.AppKeepers // the module manager mm *module.Manager - // module configurator configurator module.Configurator } @@ -361,350 +134,26 @@ func New( bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - keys := sdk.NewKVStoreKeys( - authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, - rollappmoduletypes.StoreKey, - sequencermoduletypes.StoreKey, - streamermoduletypes.StoreKey, - packetforwardtypes.StoreKey, - delayedacktypes.StoreKey, - eibcmoduletypes.StoreKey, - - // ethermint keys - evmtypes.StoreKey, feemarkettypes.StoreKey, - - // osmosis keys - lockuptypes.StoreKey, - epochstypes.StoreKey, - gammtypes.StoreKey, - poolmanagertypes.StoreKey, - incentivestypes.StoreKey, - txfeestypes.StoreKey, - ) - - tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey) - memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) - - // load state streaming if enabled - if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, keys); err != nil { - panic("failed to load state streaming services: " + err.Error()) - } - app := &App{ BaseApp: bApp, cdc: cdc, appCodec: appCodec, interfaceRegistry: interfaceRegistry, - invCheckPeriod: invCheckPeriod, - keys: keys, - tkeys: tkeys, - memKeys: memKeys, + AppKeepers: keepers.AppKeepers{}, } - app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) - - // set the BaseApp's parameter store - bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) - - // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) - - // grant capabilities for the ibc and ibc-transfer modules - scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) - scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) - - app.CapabilityKeeper.Seal() - - // add keepers - app.AccountKeeper = authkeeper.NewAccountKeeper( - appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.GetConfig().GetBech32AccountAddrPrefix(), - ) - - app.AuthzKeeper = authzkeeper.NewKeeper( - keys[authz.ModuleName], appCodec, app.MsgServiceRouter(), app.AccountKeeper, - ) + app.GenerateKeys() - app.BankKeeper = bankkeeper.NewBaseKeeper( - appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), - ) - stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), - ) - app.MintKeeper = mintkeeper.NewKeeper( - appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, - app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, - ) - app.DistrKeeper = distrkeeper.NewKeeper( - appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, authtypes.FeeCollectorName, - ) - app.SlashingKeeper = slashingkeeper.NewKeeper( - appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), - ) - app.CrisisKeeper = crisiskeeper.NewKeeper( - app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, - ) - - app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *stakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), - ) - - // Create Ethermint keepers - app.FeeMarketKeeper = feemarketkeeper.NewKeeper( - appCodec, authtypes.NewModuleAddress(govtypes.ModuleName), - keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], app.GetSubspace(feemarkettypes.ModuleName), - ) + // load state streaming if enabled + if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, keepers.KVStoreKeys); err != nil { + panic("failed to load state streaming services: " + err.Error()) + } - // Create evmos keeper tracer := cast.ToString(appOpts.Get(flags.EVMTracer)) - app.EvmKeeper = evmkeeper.NewKeeper( - appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName), - app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, - nil, geth.NewEVM, tracer, app.GetSubspace(evmtypes.ModuleName), - ) - // Osmosis keepers - - app.LockupKeeper = lockupkeeper.NewKeeper( - app.keys[lockuptypes.StoreKey], - app.GetSubspace(lockuptypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - ) - - app.LockupKeeper.SetHooks( - lockuptypes.NewMultiLockupHooks( - // insert lockup hooks receivers here - ), - ) - - app.EpochsKeeper = epochskeeper.NewKeeper(app.keys[epochstypes.StoreKey]) - - gammKeeper := gammkeeper.NewKeeper( - appCodec, keys[gammtypes.StoreKey], - app.GetSubspace(gammtypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, app.DistrKeeper) - app.GAMMKeeper = &gammKeeper - - app.PoolManagerKeeper = poolmanagerkeeper.NewKeeper( - keys[poolmanagertypes.StoreKey], - app.GAMMKeeper, - app.BankKeeper, - app.AccountKeeper, - ) - - txFeesKeeper := txfeeskeeper.NewKeeper( - app.keys[txfeestypes.StoreKey], - app.GetSubspace(txfeestypes.ModuleName), - app.AccountKeeper, - app.EpochsKeeper, - app.BankKeeper, - app.PoolManagerKeeper, - app.GAMMKeeper, - ) - app.TxFeesKeeper = &txFeesKeeper - app.GAMMKeeper.SetPoolManager(app.PoolManagerKeeper) - app.GAMMKeeper.SetTxFees(app.TxFeesKeeper) - - // Create IBC Keeper - app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, - keys[ibchost.StoreKey], - app.GetSubspace(ibchost.ModuleName), - app.StakingKeeper, - app.UpgradeKeeper, - scopedIBCKeeper, - ) - - app.IncentivesKeeper = incentiveskeeper.NewKeeper( - app.keys[incentivestypes.StoreKey], - app.GetSubspace(incentivestypes.ModuleName), - app.BankKeeper, - app.LockupKeeper, - app.EpochsKeeper, - app.DistrKeeper, - app.TxFeesKeeper, - ) - - app.StreamerKeeper = *streamermodulekeeper.NewKeeper( - keys[streamermoduletypes.StoreKey], - app.GetSubspace(streamermoduletypes.ModuleName), - - app.BankKeeper, - app.EpochsKeeper, - app.AccountKeeper, - app.IncentivesKeeper, - ) - - app.EIBCKeeper = *eibckeeper.NewKeeper( - appCodec, - keys[eibcmoduletypes.StoreKey], - keys[eibcmoduletypes.MemStoreKey], - app.GetSubspace(eibcmoduletypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - nil, - ) - - app.DenomMetadataKeeper = denommetadatamodulekeeper.NewKeeper( - app.BankKeeper, - ) - - app.DenomMetadataKeeper.SetHooks( - denommetadatamoduletypes.NewMultiDenomMetadataHooks( - vfchooks.NewVirtualFrontierBankContractRegistrationHook(*app.EvmKeeper), - ), - ) - - app.RollappKeeper = *rollappmodulekeeper.NewKeeper(appCodec, keys[rollappmoduletypes.StoreKey], app.GetSubspace(rollappmoduletypes.ModuleName), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) - - // Create Transfer Keepers - app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, - keys[ibctransfertypes.StoreKey], - app.GetSubspace(ibctransfertypes.ModuleName), - denommetadatamodule.NewICS4Wrapper(app.IBCKeeper.ChannelKeeper, app.RollappKeeper, app.BankKeeper), - app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.AccountKeeper, - app.BankKeeper, - scopedTransferKeeper, - ) - - app.SequencerKeeper = *sequencermodulekeeper.NewKeeper( - appCodec, - keys[sequencermoduletypes.StoreKey], - keys[sequencermoduletypes.MemStoreKey], - app.GetSubspace(sequencermoduletypes.ModuleName), - app.BankKeeper, - app.RollappKeeper, - ) - - app.DelayedAckKeeper = *delayedackkeeper.NewKeeper( - appCodec, - keys[delayedacktypes.StoreKey], - app.GetSubspace(delayedacktypes.ModuleName), - app.RollappKeeper, - app.IBCKeeper.ChannelKeeper, - app.IBCKeeper.ChannelKeeper, - &app.EIBCKeeper, - ) - - app.EIBCKeeper.SetDelayedAckKeeper(app.DelayedAckKeeper) - - /* -------------------------------- set hooks ------------------------------- */ - // Set hooks - app.GAMMKeeper.SetHooks( - gammtypes.NewMultiGammHooks( - // insert gamm hooks receivers here - app.StreamerKeeper.Hooks(), - app.TxFeesKeeper.Hooks(), - ), - ) - - app.IncentivesKeeper.SetHooks( - incentivestypes.NewMultiIncentiveHooks( - // insert incentive hooks receivers here - ), - ) - - app.DelayedAckKeeper.SetHooks(delayedacktypes.NewMultiDelayedAckHooks( - // insert delayedAck hooks receivers here - app.EIBCKeeper.GetDelayedAckHooks(), - )) - - app.EpochsKeeper.SetHooks( - epochstypes.NewMultiEpochHooks( - // insert epochs hooks receivers here - app.IncentivesKeeper.Hooks(), - app.StreamerKeeper.Hooks(), - app.TxFeesKeeper.Hooks(), - app.DelayedAckKeeper.GetEpochHooks(), - ), - ) - - app.EIBCKeeper.SetHooks(eibcmoduletypes.NewMultiEIBCHooks( - // insert eibc hooks receivers here - app.DelayedAckKeeper.GetEIBCHooks(), - )) - - sequencerModule := sequencermodule.NewAppModule(appCodec, app.SequencerKeeper, app.AccountKeeper, app.BankKeeper) - rollappModule := rollappmodule.NewAppModule(appCodec, &app.RollappKeeper, app.AccountKeeper, app.BankKeeper) - streamerModule := streamermodule.NewAppModule(app.StreamerKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper) - delayedackModule := delayedackmodule.NewAppModule(appCodec, app.DelayedAckKeeper) - denomMetadataModule := denommetadatamodule.NewAppModule(app.DenomMetadataKeeper, *app.EvmKeeper, app.BankKeeper) - // Register the proposal types - // Deprecated: Avoid adding new handlers, instead use the new proposal flow - // by granting the governance module the right to execute the message. - // See: https://github.com/cosmos/cosmos-sdk/blob/release/v0.46.x/x/gov/spec/01_concepts.md#proposal-messages - govRouter := govv1beta1.NewRouter() - govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). - AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). - AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). - AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(streamermoduletypes.RouterKey, streamermodule.NewStreamerProposalHandler(app.StreamerKeeper)). - AddRoute(rollappmoduletypes.RouterKey, rollappmodule.NewRollappProposalHandler(&app.RollappKeeper)). - AddRoute(denommetadatamoduletypes.RouterKey, denommetadatamodule.NewDenomMetadataProposalHandler(app.DenomMetadataKeeper)). - AddRoute(evmtypes.RouterKey, evm.NewEvmProposalHandler(app.EvmKeeper)) - - // Create evidence Keeper for to register the IBC light client misbehaviour evidence route - evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, - ) - // If evidence needs to be handled for the app, set routes in router here and seal - app.EvidenceKeeper = *evidenceKeeper - - govConfig := govtypes.DefaultConfig() - app.GovKeeper = govkeeper.NewKeeper( - appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, - ) - - app.PacketForwardMiddlewareKeeper = packetforwardkeeper.NewKeeper( - appCodec, keys[packetforwardtypes.StoreKey], - app.GetSubspace(packetforwardtypes.ModuleName), - app.TransferKeeper, - app.IBCKeeper.ChannelKeeper, - app.DistrKeeper, - app.BankKeeper, - app.IBCKeeper.ChannelKeeper, - ) - - transferModule := ibctransfer.NewAppModule(app.TransferKeeper) - - var transferStack ibcporttypes.IBCModule - transferStack = ibctransfer.NewIBCModule(app.TransferKeeper) - transferStack = bridgingfee.NewIBCModule(transferStack.(ibctransfer.IBCModule), app.DelayedAckKeeper, app.TransferKeeper, app.AccountKeeper.GetModuleAddress(txfeestypes.ModuleName), app.RollappKeeper) - transferStack = packetforwardmiddleware.NewIBCMiddleware(transferStack, app.PacketForwardMiddlewareKeeper, 0, packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp) - - transferStack = denommetadatamodule.NewIBCModule(transferStack, app.DenomMetadataKeeper, app.RollappKeeper) - delayedAckMiddleware := delayedackmodule.NewIBCMiddleware(transferStack, app.DelayedAckKeeper, app.RollappKeeper) - transferStack = delayedAckMiddleware - transferStack = transfergenesis.NewIBCModule(transferStack, app.DelayedAckKeeper, app.RollappKeeper, app.TransferKeeper, app.DenomMetadataKeeper) - transferStack = transfergenesis.NewIBCModuleCanonicalChannelHack(transferStack, app.RollappKeeper, app.IBCKeeper.ChannelKeeper) - - // Create static IBC router, add transfer route, then set and seal it - ibcRouter := ibcporttypes.NewRouter() - ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) - // this line is used by starport scaffolding # ibc/app/router - app.IBCKeeper.SetRouter(ibcRouter) - - // register the rollapp hooks - app.RollappKeeper.SetHooks(rollappmoduletypes.NewMultiRollappHooks( - // insert rollapp hooks receivers here - app.SequencerKeeper.RollappHooks(), - delayedAckMiddleware, - )) + app.AppKeepers.InitKeepers(appCodec, cdc, bApp, app.ModuleAccountAddrs(), skipUpgradeHeights, invCheckPeriod, tracer, homePath) + app.AppKeepers.SetupHooks() + app.AppKeepers.InitTransferStack() /**** Module Options ****/ @@ -714,176 +163,31 @@ func New( // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. - app.mm = module.NewManager( - genutil.NewAppModule( - app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, - encodingConfig.TxConfig, - ), - auth.NewAppModule(appCodec, app.AccountKeeper, nil), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), - feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - upgrade.NewAppModule(app.UpgradeKeeper), - evidence.NewAppModule(app.EvidenceKeeper), - ibc.NewAppModule(app.IBCKeeper), - params.NewAppModule(app.ParamsKeeper), - packetforwardmiddleware.NewAppModule(app.PacketForwardMiddlewareKeeper), - transferModule, - rollappModule, - sequencerModule, - streamerModule, - denomMetadataModule, - delayedackModule, - eibcmodule.NewAppModule(appCodec, app.EIBCKeeper, app.AccountKeeper, app.BankKeeper), - - // Ethermint app modules - evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())), - feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())), - - // osmosis modules - lockup.NewAppModule(*app.LockupKeeper, app.AccountKeeper, app.BankKeeper), - epochs.NewAppModule(*app.EpochsKeeper), - gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper), - poolmanager.NewAppModule(*app.PoolManagerKeeper, app.GAMMKeeper), - incentives.NewAppModule(*app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper), - txfees.NewAppModule(*app.TxFeesKeeper), - ) + app.mm = module.NewManager(app.SetupModules(appCodec, bApp, encodingConfig, skipGenesisInvariants)...) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 - app.mm.SetOrderBeginBlockers( - epochstypes.ModuleName, - upgradetypes.ModuleName, - capabilitytypes.ModuleName, - minttypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - evidencetypes.ModuleName, - stakingtypes.ModuleName, - vestingtypes.ModuleName, - feemarkettypes.ModuleName, - evmtypes.ModuleName, - ibchost.ModuleName, - ibctransfertypes.ModuleName, - packetforwardtypes.ModuleName, - authtypes.ModuleName, - authz.ModuleName, - banktypes.ModuleName, - govtypes.ModuleName, - crisistypes.ModuleName, - genutiltypes.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - rollappmoduletypes.ModuleName, - sequencermoduletypes.ModuleName, - streamermoduletypes.ModuleName, - denommetadatamoduletypes.ModuleName, - delayedacktypes.ModuleName, - eibcmoduletypes.ModuleName, - lockuptypes.ModuleName, - gammtypes.ModuleName, - poolmanagertypes.ModuleName, - incentivestypes.ModuleName, - txfeestypes.ModuleName, - ) - - app.mm.SetOrderEndBlockers( - crisistypes.ModuleName, - govtypes.ModuleName, - stakingtypes.ModuleName, - capabilitytypes.ModuleName, - authtypes.ModuleName, - authz.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - feemarkettypes.ModuleName, - evmtypes.ModuleName, - slashingtypes.ModuleName, - vestingtypes.ModuleName, - minttypes.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - ibchost.ModuleName, - ibctransfertypes.ModuleName, - packetforwardtypes.ModuleName, - rollappmoduletypes.ModuleName, - sequencermoduletypes.ModuleName, - streamermoduletypes.ModuleName, - denommetadatamoduletypes.ModuleName, - delayedacktypes.ModuleName, - eibcmoduletypes.ModuleName, - epochstypes.ModuleName, - lockuptypes.ModuleName, - gammtypes.ModuleName, - poolmanagertypes.ModuleName, - incentivestypes.ModuleName, - txfeestypes.ModuleName, - ) + // TODO: use "github.com/osmosis-labs/osmosis/osmoutils/partialord" to order modules + app.mm.SetOrderBeginBlockers(keepers.BeginBlockers...) + app.mm.SetOrderEndBlockers(keepers.EndBlockers...) // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. // NOTE: Capability module must occur first so that it can initialize any capabilities // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. - app.mm.SetOrderInitGenesis( - capabilitytypes.ModuleName, - authtypes.ModuleName, - authz.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - stakingtypes.ModuleName, - vestingtypes.ModuleName, - slashingtypes.ModuleName, - feemarkettypes.ModuleName, - evmtypes.ModuleName, - govtypes.ModuleName, - minttypes.ModuleName, - crisistypes.ModuleName, - ibchost.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - ibctransfertypes.ModuleName, - packetforwardtypes.ModuleName, - feegrant.ModuleName, - rollappmoduletypes.ModuleName, - sequencermoduletypes.ModuleName, - streamermoduletypes.ModuleName, - denommetadatamoduletypes.ModuleName, // must after `x/bank` to trigger hooks - delayedacktypes.ModuleName, - eibcmoduletypes.ModuleName, - - epochstypes.ModuleName, - lockuptypes.ModuleName, - gammtypes.ModuleName, - poolmanagertypes.ModuleName, - incentivestypes.ModuleName, - txfeestypes.ModuleName, - ) - + app.mm.SetOrderInitGenesis(keepers.InitGenesis...) app.mm.RegisterInvariants(&app.CrisisKeeper) app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) // initialize stores - app.MountKVStores(keys) - app.MountTransientStores(tkeys) - app.MountMemoryStores(memKeys) + app.MountKVStores(keepers.KVStoreKeys) + app.MountTransientStores(app.GetTransientStoreKey()) + app.MountMemoryStores(app.GetMemoryStoreKey()) // initialize BaseApp app.SetInitChainer(app.InitChainer) @@ -917,9 +221,6 @@ func New( } } - app.ScopedIBCKeeper = scopedIBCKeeper - app.ScopedTransferKeeper = scopedTransferKeeper - return app } @@ -954,19 +255,6 @@ func (app *App) LoadHeight(height int64) error { return app.LoadVersion(height) } -// ModuleAccountAddrs returns all the app's module account addresses. -func (app *App) ModuleAccountAddrs() map[string]bool { - modAccAddrs := make(map[string]bool) - for acc := range maccPerms { - modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true - } - - // exclude the streamer as we want him to be able to get external incentives - modAccAddrs[authtypes.NewModuleAddress(streamermoduletypes.ModuleName).String()] = false - modAccAddrs[authtypes.NewModuleAddress(txfeestypes.ModuleName).String()] = false - return modAccAddrs -} - // LegacyAmino returns SimApp's amino codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable @@ -988,35 +276,6 @@ func (app *App) InterfaceRegistry() types.InterfaceRegistry { return app.interfaceRegistry } -// GetKey returns the KVStoreKey for the provided store key. -// -// NOTE: This is solely to be used for testing purposes. -func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey { - return app.keys[storeKey] -} - -// GetTKey returns the TransientStoreKey for the provided store key. -// -// NOTE: This is solely to be used for testing purposes. -func (app *App) GetTKey(storeKey string) *storetypes.TransientStoreKey { - return app.tkeys[storeKey] -} - -// GetMemKey returns the MemStoreKey for the provided mem key. -// -// NOTE: This is solely used for testing purposes. -func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { - return app.memKeys[storeKey] -} - -// GetSubspace returns a param subspace for a given module name. -// -// NOTE: This is solely to be used for testing purposes. -func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { - subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) - return subspace -} - // RegisterAPIRoutes registers all application module routes with the provided // API server. func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { @@ -1031,7 +290,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register grpc-gateway routes for all modules. - ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + keepers.ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // register swagger API from root so that other applications can override easily if apiConfig.Swagger { @@ -1070,71 +329,11 @@ func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) { rtr.PathPrefix("/static/").Handler(http.StripPrefix("/static/", staticServer)) } -// GetMaccPerms returns a copy of the module account permissions -func GetMaccPerms() map[string][]string { - dupMaccPerms := make(map[string][]string) - for k, v := range maccPerms { - dupMaccPerms[k] = v - } - return dupMaccPerms -} - -// initParamsKeeper init params keeper 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(minttypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName) - paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibchost.ModuleName) - paramsKeeper.Subspace(rollappmoduletypes.ModuleName) - paramsKeeper.Subspace(sequencermoduletypes.ModuleName) - paramsKeeper.Subspace(streamermoduletypes.ModuleName) - paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName) - paramsKeeper.Subspace(delayedacktypes.ModuleName) - paramsKeeper.Subspace(eibcmoduletypes.ModuleName) - - // ethermint subspaces - paramsKeeper.Subspace(evmtypes.ModuleName) - paramsKeeper.Subspace(feemarkettypes.ModuleName) - - // osmosis subspaces - paramsKeeper.Subspace(lockuptypes.ModuleName) - paramsKeeper.Subspace(epochstypes.ModuleName) - paramsKeeper.Subspace(gammtypes.ModuleName) - paramsKeeper.Subspace(incentivestypes.ModuleName) - paramsKeeper.Subspace(txfeestypes.ModuleName) - - return paramsKeeper -} - // SimulationManager implements the SimulationApp interface func (app *App) SimulationManager() *module.SimulationManager { return nil } -// GetIBCKeeper implements ibctesting.TestingApp -func (app *App) GetIBCKeeper() *ibckeeper.Keeper { - return app.IBCKeeper -} - -// GetScopedIBCKeeper implements ibctesting.TestingApp -func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { - return app.ScopedIBCKeeper -} - -// GetStakingKeeper implements ibctesting.TestingApp -func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper { - return app.StakingKeeper -} - // GetTxConfig implements ibctesting.TestingApp func (app *App) GetTxConfig() client.TxConfig { return simappparams.MakeTestEncodingConfig().TxConfig @@ -1152,8 +351,8 @@ func (app *App) setupUpgradeHandlers() { func (app *App) setupUpgradeHandler(upgrade upgrades.Upgrade) { app.UpgradeKeeper.SetUpgradeHandler( - upgrade.UpgradeName, - upgrade.CreateUpgradeHandler( + upgrade.Name, + upgrade.CreateHandler( app.mm, app.configurator, app.BaseApp, @@ -1174,7 +373,7 @@ func (app *App) setupUpgradeHandler(upgrade upgrades.Upgrade) { // do nothing } - if upgradeInfo.Name == upgrade.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + if upgradeInfo.Name == upgrade.Name && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { // configure store loader with the store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) } diff --git a/app/encoding.go b/app/encoding.go index b5f2add79..51a2247a0 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/x/auth/tx" + "github.com/dymensionxyz/dymension/v3/app/keepers" "github.com/dymensionxyz/dymension/v3/app/params" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,8 +38,8 @@ func MakeEncodingConfig() params.EncodingConfig { RegisterLegacyAminoCodec(encodingConfig.Amino) RegisterInterfaces(encodingConfig.InterfaceRegistry) - ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) - ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) + keepers.ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) + keepers.ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } diff --git a/app/export.go b/app/export.go index b98d109c1..87459bcc3 100644 --- a/app/export.go +++ b/app/export.go @@ -156,7 +156,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. - store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) counter := int16(0) diff --git a/app/genesis.go b/app/genesis.go index 39181c0dc..be3474f72 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -4,6 +4,8 @@ import ( "encoding/json" "github.com/cosmos/cosmos-sdk/codec" + + "github.com/dymensionxyz/dymension/v3/app/keepers" ) // The genesis state of the blockchain is represented here as a map of raw json @@ -17,6 +19,6 @@ type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - defaultGenesisState := ModuleBasics.DefaultGenesis(cdc) + defaultGenesisState := keepers.ModuleBasics.DefaultGenesis(cdc) return defaultGenesisState } diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 505d17d2d..103781d65 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -1,38 +1,94 @@ package keepers import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" 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" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" 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" 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" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + packetforwardmiddleware "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" + ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + ibcclient "github.com/cosmos/ibc-go/v6/modules/core/02-client" + ibcclienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + ibcporttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" + "github.com/evmos/ethermint/x/evm" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" + evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/evmos/ethermint/x/evm/vm/geth" feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper" + feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper" + epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types" gammkeeper "github.com/osmosis-labs/osmosis/v15/x/gamm/keeper" + gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" incentiveskeeper "github.com/osmosis-labs/osmosis/v15/x/incentives/keeper" + incentivestypes "github.com/osmosis-labs/osmosis/v15/x/incentives/types" lockupkeeper "github.com/osmosis-labs/osmosis/v15/x/lockup/keeper" + lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" poolmanagerkeeper "github.com/osmosis-labs/osmosis/v15/x/poolmanager/keeper" + poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" txfeeskeeper "github.com/osmosis-labs/osmosis/v15/x/txfees/keeper" + txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types" + "github.com/dymensionxyz/dymension/v3/x/bridgingfee" + delayedackmodule "github.com/dymensionxyz/dymension/v3/x/delayedack" delayedackkeeper "github.com/dymensionxyz/dymension/v3/x/delayedack/keeper" + delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" + denommetadatamodule "github.com/dymensionxyz/dymension/v3/x/denommetadata" denommetadatamodulekeeper "github.com/dymensionxyz/dymension/v3/x/denommetadata/keeper" + denommetadatamoduletypes "github.com/dymensionxyz/dymension/v3/x/denommetadata/types" eibckeeper "github.com/dymensionxyz/dymension/v3/x/eibc/keeper" + eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types" + rollappmodule "github.com/dymensionxyz/dymension/v3/x/rollapp" rollappmodulekeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" + "github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis" + rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" sequencermodulekeeper "github.com/dymensionxyz/dymension/v3/x/sequencer/keeper" + sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" + streamermodule "github.com/dymensionxyz/dymension/v3/x/streamer" streamermodulekeeper "github.com/dymensionxyz/dymension/v3/x/streamer/keeper" + streamermoduletypes "github.com/dymensionxyz/dymension/v3/x/streamer/types" + vfchooks "github.com/dymensionxyz/dymension/v3/x/vfc/hooks" ) type AppKeepers struct { @@ -50,6 +106,9 @@ type AppKeepers struct { UpgradeKeeper upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + TransferStack ibcporttypes.IBCModule + ICS4Wrapper ibcporttypes.ICS4Wrapper + delayedAckMiddleware *delayedackmodule.IBCMiddleware EvidenceKeeper evidencekeeper.Keeper TransferKeeper ibctransferkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper @@ -76,7 +135,452 @@ type AppKeepers struct { StreamerKeeper streamermodulekeeper.Keeper EIBCKeeper eibckeeper.Keeper - // this line is used by starport scaffolding # stargate/app/keeperDeclaration DelayedAckKeeper delayedackkeeper.Keeper DenomMetadataKeeper *denommetadatamodulekeeper.Keeper + + // keys to access the substores + keys map[string]*storetypes.KVStoreKey + tkeys map[string]*storetypes.TransientStoreKey + memKeys map[string]*storetypes.MemoryStoreKey +} + +// InitKeepers initializes all keepers for the app +func (a *AppKeepers) InitKeepers( + appCodec codec.Codec, + cdc *codec.LegacyAmino, + bApp *baseapp.BaseApp, + moduleAccountAddrs map[string]bool, + skipUpgradeHeights map[int64]bool, + invCheckPeriod uint, + tracer, homePath string, +) { + // init keepers + + a.ParamsKeeper = initParamsKeeper(appCodec, cdc, a.keys[paramstypes.StoreKey], a.tkeys[paramstypes.TStoreKey]) + // set the BaseApp's parameter store + bApp.SetParamStore(a.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) + + // add capability keeper and ScopeToModule for ibc module + a.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, a.keys[capabilitytypes.StoreKey], a.memKeys[capabilitytypes.MemStoreKey]) + + // grant capabilities for the ibc and ibc-transfer modules + a.ScopedIBCKeeper = a.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + a.ScopedTransferKeeper = a.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + + a.CapabilityKeeper.Seal() + + a.CrisisKeeper = crisiskeeper.NewKeeper( + a.GetSubspace(crisistypes.ModuleName), invCheckPeriod, a.BankKeeper, authtypes.FeeCollectorName, + ) + + a.UpgradeKeeper = upgradekeeper.NewKeeper( + skipUpgradeHeights, + a.keys[upgradetypes.StoreKey], + appCodec, + homePath, + bApp, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + a.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, + a.keys[authtypes.StoreKey], + a.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + maccPerms, + sdk.GetConfig().GetBech32AccountAddrPrefix(), + ) + + a.AuthzKeeper = authzkeeper.NewKeeper( + a.keys[authz.ModuleName], + appCodec, + bApp.MsgServiceRouter(), + a.AccountKeeper, + ) + + a.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, + a.keys[banktypes.StoreKey], + a.AccountKeeper, + a.GetSubspace(banktypes.ModuleName), + moduleAccountAddrs, + ) + + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, + a.keys[stakingtypes.StoreKey], + a.AccountKeeper, + a.BankKeeper, + a.GetSubspace(stakingtypes.ModuleName), + ) + + a.MintKeeper = mintkeeper.NewKeeper( + appCodec, + a.keys[minttypes.StoreKey], + a.GetSubspace(minttypes.ModuleName), + &stakingKeeper, + a.AccountKeeper, + a.BankKeeper, + authtypes.FeeCollectorName, + ) + + a.DistrKeeper = distrkeeper.NewKeeper( + appCodec, + a.keys[distrtypes.StoreKey], + a.GetSubspace(distrtypes.ModuleName), + a.AccountKeeper, + a.BankKeeper, + &stakingKeeper, + authtypes.FeeCollectorName, + ) + + a.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + a.keys[slashingtypes.StoreKey], + &stakingKeeper, + a.GetSubspace(slashingtypes.ModuleName), + ) + + // TODO: move back to SetupHooks after https://github.com/dymensionxyz/dymension/pull/970 is merged + a.StakingKeeper = *stakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks(a.DistrKeeper.Hooks(), a.SlashingKeeper.Hooks()), + ) + + a.FeeGrantKeeper = feegrantkeeper.NewKeeper( + appCodec, + a.keys[feegrant.StoreKey], + a.AccountKeeper, + ) + + // Create Ethermint keepers + a.FeeMarketKeeper = feemarketkeeper.NewKeeper( + appCodec, + authtypes.NewModuleAddress(govtypes.ModuleName), + a.keys[feemarkettypes.StoreKey], + a.tkeys[feemarkettypes.TransientKey], + a.GetSubspace(feemarkettypes.ModuleName), + ) + + // Create evmos keeper + a.EvmKeeper = evmkeeper.NewKeeper( + appCodec, + a.keys[evmtypes.StoreKey], + a.tkeys[evmtypes.TransientKey], + authtypes.NewModuleAddress(govtypes.ModuleName), + a.AccountKeeper, + a.BankKeeper, + &stakingKeeper, + a.FeeMarketKeeper, + nil, + geth.NewEVM, + tracer, + a.GetSubspace(evmtypes.ModuleName), + ) + + // Osmosis keepers + + a.LockupKeeper = lockupkeeper.NewKeeper( + a.keys[lockuptypes.StoreKey], + a.GetSubspace(lockuptypes.ModuleName), + a.AccountKeeper, + a.BankKeeper, + ) + + a.EpochsKeeper = epochskeeper.NewKeeper( + a.keys[epochstypes.StoreKey], + ) + + gammKeeper := gammkeeper.NewKeeper( + appCodec, a.keys[gammtypes.StoreKey], + a.GetSubspace(gammtypes.ModuleName), + a.AccountKeeper, + a.BankKeeper, a.DistrKeeper, + ) + a.GAMMKeeper = &gammKeeper + + a.PoolManagerKeeper = poolmanagerkeeper.NewKeeper( + a.keys[poolmanagertypes.StoreKey], + a.GAMMKeeper, + a.BankKeeper, + a.AccountKeeper, + ) + + txFeesKeeper := txfeeskeeper.NewKeeper( + a.keys[txfeestypes.StoreKey], + a.GetSubspace(txfeestypes.ModuleName), + a.AccountKeeper, + a.EpochsKeeper, + a.BankKeeper, + a.PoolManagerKeeper, + a.GAMMKeeper, + ) + a.TxFeesKeeper = &txFeesKeeper + + a.GAMMKeeper.SetPoolManager(a.PoolManagerKeeper) + a.GAMMKeeper.SetTxFees(a.TxFeesKeeper) + + // Create IBC Keeper + a.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + a.keys[ibchost.StoreKey], + a.GetSubspace(ibchost.ModuleName), + stakingKeeper, + a.UpgradeKeeper, + a.ScopedIBCKeeper, + ) + + a.IncentivesKeeper = incentiveskeeper.NewKeeper( + a.keys[incentivestypes.StoreKey], + a.GetSubspace(incentivestypes.ModuleName), + a.BankKeeper, + a.LockupKeeper, + a.EpochsKeeper, + a.DistrKeeper, + a.TxFeesKeeper, + ) + + a.StreamerKeeper = *streamermodulekeeper.NewKeeper( + a.keys[streamermoduletypes.StoreKey], + a.GetSubspace(streamermoduletypes.ModuleName), + a.BankKeeper, + a.EpochsKeeper, + a.AccountKeeper, + a.IncentivesKeeper, + ) + + a.EIBCKeeper = *eibckeeper.NewKeeper( + appCodec, + a.keys[eibcmoduletypes.StoreKey], + a.keys[eibcmoduletypes.MemStoreKey], + a.GetSubspace(eibcmoduletypes.ModuleName), + a.AccountKeeper, + a.BankKeeper, + nil, + ) + + a.DenomMetadataKeeper = denommetadatamodulekeeper.NewKeeper( + a.BankKeeper, + ) + + a.RollappKeeper = *rollappmodulekeeper.NewKeeper( + appCodec, + a.keys[rollappmoduletypes.StoreKey], + a.GetSubspace(rollappmoduletypes.ModuleName), + a.IBCKeeper.ChannelKeeper, + a.IBCKeeper.ClientKeeper, + ) + + // Create Transfer Keepers + a.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + a.keys[ibctransfertypes.StoreKey], + a.GetSubspace(ibctransfertypes.ModuleName), + denommetadatamodule.NewICS4Wrapper(a.IBCKeeper.ChannelKeeper, a.RollappKeeper, a.BankKeeper), + a.IBCKeeper.ChannelKeeper, + &a.IBCKeeper.PortKeeper, + a.AccountKeeper, + a.BankKeeper, + a.ScopedTransferKeeper, + ) + + a.SequencerKeeper = *sequencermodulekeeper.NewKeeper( + appCodec, + a.keys[sequencermoduletypes.StoreKey], + a.keys[sequencermoduletypes.MemStoreKey], + a.GetSubspace(sequencermoduletypes.ModuleName), + a.BankKeeper, + a.RollappKeeper, + ) + + a.DelayedAckKeeper = *delayedackkeeper.NewKeeper( + appCodec, + a.keys[delayedacktypes.StoreKey], + a.GetSubspace(delayedacktypes.ModuleName), + a.RollappKeeper, + a.IBCKeeper.ChannelKeeper, + a.IBCKeeper.ChannelKeeper, + &a.EIBCKeeper, + ) + + a.EIBCKeeper.SetDelayedAckKeeper(a.DelayedAckKeeper) + + // Register the proposal types + // Deprecated: Avoid adding new handlers, instead use the new proposal flow + // by granting the governance module the right to execute the message. + // See: https://github.com/cosmos/cosmos-sdk/blob/release/v0.46.x/x/gov/spec/01_concepts.md#proposal-messages + govRouter := govv1beta1.NewRouter() + govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(a.ParamsKeeper)). + AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(a.DistrKeeper)). + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(a.UpgradeKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(a.IBCKeeper.ClientKeeper)). + AddRoute(streamermoduletypes.RouterKey, streamermodule.NewStreamerProposalHandler(a.StreamerKeeper)). + AddRoute(rollappmoduletypes.RouterKey, rollappmodule.NewRollappProposalHandler(&a.RollappKeeper)). + AddRoute(denommetadatamoduletypes.RouterKey, denommetadatamodule.NewDenomMetadataProposalHandler(a.DenomMetadataKeeper)). + AddRoute(evmtypes.RouterKey, evm.NewEvmProposalHandler(a.EvmKeeper)) + + // Create evidence Keeper for to register the IBC light client misbehaviour evidence route + // If evidence needs to be handled for the app, set routes in router here and seal + a.EvidenceKeeper = *evidencekeeper.NewKeeper( + appCodec, a.keys[evidencetypes.StoreKey], stakingKeeper, a.SlashingKeeper, + ) + + govConfig := govtypes.DefaultConfig() + a.GovKeeper = govkeeper.NewKeeper( + appCodec, a.keys[govtypes.StoreKey], a.GetSubspace(govtypes.ModuleName), a.AccountKeeper, a.BankKeeper, + &stakingKeeper, govRouter, bApp.MsgServiceRouter(), govConfig, + ) + + a.PacketForwardMiddlewareKeeper = packetforwardkeeper.NewKeeper( + appCodec, a.keys[packetforwardtypes.StoreKey], + a.GetSubspace(packetforwardtypes.ModuleName), + a.TransferKeeper, + a.IBCKeeper.ChannelKeeper, + a.DistrKeeper, + a.BankKeeper, + a.IBCKeeper.ChannelKeeper, + ) +} + +func (a *AppKeepers) InitTransferStack() { + a.TransferStack = ibctransfer.NewIBCModule(a.TransferKeeper) + a.TransferStack = bridgingfee.NewIBCModule( + a.TransferStack.(ibctransfer.IBCModule), + a.DelayedAckKeeper, + a.TransferKeeper, + a.AccountKeeper.GetModuleAddress(txfeestypes.ModuleName), + a.RollappKeeper, + ) + a.TransferStack = packetforwardmiddleware.NewIBCMiddleware( + a.TransferStack, + a.PacketForwardMiddlewareKeeper, + 0, + packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, + packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, + ) + + a.TransferStack = denommetadatamodule.NewIBCModule(a.TransferStack, a.DenomMetadataKeeper, a.RollappKeeper) + // already instantiated in SetupHooks() + a.delayedAckMiddleware.Setup( + delayedackmodule.WithIBCModule(a.TransferStack), + delayedackmodule.WithKeeper(a.DelayedAckKeeper), + delayedackmodule.WithRollappKeeper(a.RollappKeeper), + ) + a.TransferStack = a.delayedAckMiddleware + a.TransferStack = transfergenesis.NewIBCModule(a.TransferStack, a.DelayedAckKeeper, a.RollappKeeper, a.TransferKeeper, a.DenomMetadataKeeper) + a.TransferStack = transfergenesis.NewIBCModuleCanonicalChannelHack(a.TransferStack, a.RollappKeeper, a.IBCKeeper.ChannelKeeper) + + // Create static IBC router, add transfer route, then set and seal it + ibcRouter := ibcporttypes.NewRouter() + ibcRouter.AddRoute(ibctransfertypes.ModuleName, a.TransferStack) + a.IBCKeeper.SetRouter(ibcRouter) +} + +func (a *AppKeepers) SetupHooks() { + // register the staking hooks + a.LockupKeeper.SetHooks( + lockuptypes.NewMultiLockupHooks( + // insert lockup hooks receivers here + ), + ) + + a.DenomMetadataKeeper.SetHooks( + denommetadatamoduletypes.NewMultiDenomMetadataHooks( + vfchooks.NewVirtualFrontierBankContractRegistrationHook(*a.EvmKeeper), + ), + ) + + a.GAMMKeeper.SetHooks( + gammtypes.NewMultiGammHooks( + // insert gamm hooks receivers here + a.StreamerKeeper.Hooks(), + a.TxFeesKeeper.Hooks(), + ), + ) + + a.IncentivesKeeper.SetHooks( + incentivestypes.NewMultiIncentiveHooks( + // insert incentive hooks receivers here + ), + ) + + a.DelayedAckKeeper.SetHooks(delayedacktypes.NewMultiDelayedAckHooks( + // insert delayedAck hooks receivers here + a.EIBCKeeper.GetDelayedAckHooks(), + )) + + a.EpochsKeeper.SetHooks( + epochstypes.NewMultiEpochHooks( + // insert epochs hooks receivers here + a.IncentivesKeeper.Hooks(), + a.StreamerKeeper.Hooks(), + a.TxFeesKeeper.Hooks(), + a.DelayedAckKeeper.GetEpochHooks(), + ), + ) + + a.EIBCKeeper.SetHooks(eibcmoduletypes.NewMultiEIBCHooks( + // insert eibc hooks receivers here + a.DelayedAckKeeper.GetEIBCHooks(), + )) + + // dependencies injected in InitTransferStack() + a.delayedAckMiddleware = delayedackmodule.NewIBCMiddleware() + // register the rollapp hooks + a.RollappKeeper.SetHooks(rollappmoduletypes.NewMultiRollappHooks( + // insert rollapp hooks receivers here + a.SequencerKeeper.RollappHooks(), + a.delayedAckMiddleware, + )) +} + +// GetIBCKeeper implements ibctesting.TestingApp +func (a *AppKeepers) GetIBCKeeper() *ibckeeper.Keeper { + return a.IBCKeeper +} + +// GetScopedIBCKeeper implements ibctesting.TestingApp +func (a *AppKeepers) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return a.ScopedIBCKeeper +} + +// GetStakingKeeper implements ibctesting.TestingApp +func (a *AppKeepers) GetStakingKeeper() ibctestingtypes.StakingKeeper { + return a.StakingKeeper +} + +// initParamsKeeper init params keeper 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(minttypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(rollappmoduletypes.ModuleName) + paramsKeeper.Subspace(sequencermoduletypes.ModuleName) + paramsKeeper.Subspace(streamermoduletypes.ModuleName) + paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName) + paramsKeeper.Subspace(delayedacktypes.ModuleName) + paramsKeeper.Subspace(eibcmoduletypes.ModuleName) + + // ethermint subspaces + paramsKeeper.Subspace(evmtypes.ModuleName) + paramsKeeper.Subspace(feemarkettypes.ModuleName) + + // osmosis subspaces + paramsKeeper.Subspace(lockuptypes.ModuleName) + paramsKeeper.Subspace(epochstypes.ModuleName) + paramsKeeper.Subspace(gammtypes.ModuleName) + paramsKeeper.Subspace(incentivestypes.ModuleName) + paramsKeeper.Subspace(txfeestypes.ModuleName) + + return paramsKeeper } diff --git a/app/keepers/keys.go b/app/keepers/keys.go new file mode 100644 index 000000000..17336d025 --- /dev/null +++ b/app/keepers/keys.go @@ -0,0 +1,125 @@ +package keepers + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" + ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" + evmtypes "github.com/evmos/ethermint/x/evm/types" + feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" + epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types" + gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" + incentivestypes "github.com/osmosis-labs/osmosis/v15/x/incentives/types" + lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" + poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" + txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types" + + delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" + eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types" + rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" + sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" + streamermoduletypes "github.com/dymensionxyz/dymension/v3/x/streamer/types" +) + +// GenerateKeys generates new keys (KV Store, Transient store, and memory store). +func (a *AppKeepers) GenerateKeys() { + // Define what keys will be used in the cosmos-sdk key/value store. + // Cosmos-SDK modules each have a "key" that allows the application to reference what they've stored on the chain. + a.keys = KVStoreKeys + + // Define transient store keys + a.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey) + + // MemKeys are for information that is stored only in RAM. + a.memKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) +} + +// GetSubspace gets existing substore from keeper. +func (a *AppKeepers) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := a.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// GetKVStoreKeys gets KV Store keys. +func (a *AppKeepers) GetKVStoreKeys() map[string]*storetypes.KVStoreKey { + return a.keys +} + +// GetTransientStoreKey gets Transient Store keys. +func (a *AppKeepers) GetTransientStoreKey() map[string]*storetypes.TransientStoreKey { + return a.tkeys +} + +// GetMemoryStoreKey get memory Store keys. +func (a *AppKeepers) GetMemoryStoreKey() map[string]*storetypes.MemoryStoreKey { + return a.memKeys +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (a *AppKeepers) GetKey(storeKey string) *storetypes.KVStoreKey { + return a.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (a *AppKeepers) GetTKey(storeKey string) *storetypes.TransientStoreKey { + return a.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (a *AppKeepers) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { + return a.memKeys[storeKey] +} + +var KVStoreKeys = sdk.NewKVStoreKeys( + authtypes.StoreKey, + authzkeeper.StoreKey, + banktypes.StoreKey, + stakingtypes.StoreKey, + minttypes.StoreKey, + distrtypes.StoreKey, + slashingtypes.StoreKey, + govtypes.StoreKey, + paramstypes.StoreKey, + ibchost.StoreKey, + upgradetypes.StoreKey, + feegrant.StoreKey, + evidencetypes.StoreKey, + ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, + rollappmoduletypes.StoreKey, + sequencermoduletypes.StoreKey, + streamermoduletypes.StoreKey, + packetforwardtypes.StoreKey, + delayedacktypes.StoreKey, + eibcmoduletypes.StoreKey, + // ethermint keys + evmtypes.StoreKey, + feemarkettypes.StoreKey, + // osmosis keys + lockuptypes.StoreKey, + epochstypes.StoreKey, + gammtypes.StoreKey, + poolmanagertypes.StoreKey, + incentivestypes.StoreKey, + txfeestypes.StoreKey, +) diff --git a/app/keepers/modules.go b/app/keepers/modules.go new file mode 100644 index 000000000..651019b25 --- /dev/null +++ b/app/keepers/modules.go @@ -0,0 +1,343 @@ +package keepers + +import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/capability" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/cosmos/cosmos-sdk/x/distribution" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + 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" + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/client" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + 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" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" + packetforwardmiddleware "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" + "github.com/cosmos/ibc-go/v6/modules/apps/transfer" + ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer" + ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v6/modules/core" + ibcclientclient "github.com/cosmos/ibc-go/v6/modules/core/02-client/client" + ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/evmos/ethermint/x/evm" + evmclient "github.com/evmos/ethermint/x/evm/client" + evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/evmos/ethermint/x/feemarket" + feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" + "github.com/osmosis-labs/osmosis/v15/x/epochs" + epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types" + "github.com/osmosis-labs/osmosis/v15/x/gamm" + gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" + "github.com/osmosis-labs/osmosis/v15/x/incentives" + incentivestypes "github.com/osmosis-labs/osmosis/v15/x/incentives/types" + "github.com/osmosis-labs/osmosis/v15/x/lockup" + lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" + "github.com/osmosis-labs/osmosis/v15/x/poolmanager" + poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" + "github.com/osmosis-labs/osmosis/v15/x/txfees" + txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types" + + appparams "github.com/dymensionxyz/dymension/v3/app/params" + delayedackmodule "github.com/dymensionxyz/dymension/v3/x/delayedack" + denommetadatamodule "github.com/dymensionxyz/dymension/v3/x/denommetadata" + eibcmodule "github.com/dymensionxyz/dymension/v3/x/eibc" + rollappmodule "github.com/dymensionxyz/dymension/v3/x/rollapp" + sequencermodule "github.com/dymensionxyz/dymension/v3/x/sequencer" + streamermodule "github.com/dymensionxyz/dymension/v3/x/streamer" + + "github.com/dymensionxyz/dymension/v3/x/delayedack" + delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" + "github.com/dymensionxyz/dymension/v3/x/denommetadata" + denommetadatamoduleclient "github.com/dymensionxyz/dymension/v3/x/denommetadata/client" + denommetadatamoduletypes "github.com/dymensionxyz/dymension/v3/x/denommetadata/types" + "github.com/dymensionxyz/dymension/v3/x/eibc" + eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types" + "github.com/dymensionxyz/dymension/v3/x/rollapp" + rollappmoduleclient "github.com/dymensionxyz/dymension/v3/x/rollapp/client" + rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" + "github.com/dymensionxyz/dymension/v3/x/sequencer" + sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types" + "github.com/dymensionxyz/dymension/v3/x/streamer" + streamermoduleclient "github.com/dymensionxyz/dymension/v3/x/streamer/client" + streamermoduletypes "github.com/dymensionxyz/dymension/v3/x/streamer/types" +) + +// ModuleBasics defines the module BasicManager is in charge of setting up basic, +// non-dependant module elements, such as codec registration +// and genesis verification. +var ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + distribution.AppModuleBasic{}, + gov.NewAppModuleBasic([]client.ProposalHandler{ + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.LegacyProposalHandler, + upgradeclient.LegacyCancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + streamermoduleclient.CreateStreamHandler, + streamermoduleclient.TerminateStreamHandler, + streamermoduleclient.ReplaceStreamHandler, + streamermoduleclient.UpdateStreamHandler, + rollappmoduleclient.SubmitFraudHandler, + denommetadatamoduleclient.CreateDenomMetadataHandler, + denommetadatamoduleclient.UpdateDenomMetadataHandler, + evmclient.UpdateVirtualFrontierBankContractProposalHandler, + }), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + rollapp.AppModuleBasic{}, + sequencer.AppModuleBasic{}, + streamer.AppModuleBasic{}, + denommetadata.AppModuleBasic{}, + packetforward.AppModuleBasic{}, + delayedack.AppModuleBasic{}, + eibc.AppModuleBasic{}, + + // Ethermint modules + evm.AppModuleBasic{}, + feemarket.AppModuleBasic{}, + + // Osmosis modules + lockup.AppModuleBasic{}, + epochs.AppModuleBasic{}, + gamm.AppModuleBasic{}, + poolmanager.AppModuleBasic{}, + incentives.AppModuleBasic{}, + txfees.AppModuleBasic{}, +) + +func (a *AppKeepers) SetupModules( + appCodec codec.Codec, + bApp *baseapp.BaseApp, + encodingConfig appparams.EncodingConfig, + skipGenesisInvariants bool, +) []module.AppModule { + return []module.AppModule{ + genutil.NewAppModule( + a.AccountKeeper, a.StakingKeeper, bApp.DeliverTx, + encodingConfig.TxConfig, + ), + auth.NewAppModule(appCodec, a.AccountKeeper, nil), + authzmodule.NewAppModule(appCodec, a.AuthzKeeper, a.AccountKeeper, a.BankKeeper, encodingConfig.InterfaceRegistry), + vesting.NewAppModule(a.AccountKeeper, a.BankKeeper), + bank.NewAppModule(appCodec, a.BankKeeper, a.AccountKeeper), + capability.NewAppModule(appCodec, *a.CapabilityKeeper), + feegrantmodule.NewAppModule(appCodec, a.AccountKeeper, a.BankKeeper, a.FeeGrantKeeper, encodingConfig.InterfaceRegistry), + crisis.NewAppModule(&a.CrisisKeeper, skipGenesisInvariants), + gov.NewAppModule(appCodec, a.GovKeeper, a.AccountKeeper, a.BankKeeper), + mint.NewAppModule(appCodec, a.MintKeeper, a.AccountKeeper, nil), + slashing.NewAppModule(appCodec, a.SlashingKeeper, a.AccountKeeper, a.BankKeeper, a.StakingKeeper), + distr.NewAppModule(appCodec, a.DistrKeeper, a.AccountKeeper, a.BankKeeper, a.StakingKeeper), + staking.NewAppModule(appCodec, a.StakingKeeper, a.AccountKeeper, a.BankKeeper), + upgrade.NewAppModule(a.UpgradeKeeper), + evidence.NewAppModule(a.EvidenceKeeper), + ibc.NewAppModule(a.IBCKeeper), + params.NewAppModule(a.ParamsKeeper), + packetforwardmiddleware.NewAppModule(a.PacketForwardMiddlewareKeeper), + ibctransfer.NewAppModule(a.TransferKeeper), + rollappmodule.NewAppModule(appCodec, &a.RollappKeeper, a.AccountKeeper, a.BankKeeper), + sequencermodule.NewAppModule(appCodec, a.SequencerKeeper, a.AccountKeeper, a.BankKeeper), + streamermodule.NewAppModule(a.StreamerKeeper, a.AccountKeeper, a.BankKeeper, a.EpochsKeeper), + delayedackmodule.NewAppModule(appCodec, a.DelayedAckKeeper), + denommetadatamodule.NewAppModule(a.DenomMetadataKeeper, *a.EvmKeeper, a.BankKeeper), + eibcmodule.NewAppModule(appCodec, a.EIBCKeeper, a.AccountKeeper, a.BankKeeper), + + // Ethermint app modules + evm.NewAppModule(a.EvmKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())), + feemarket.NewAppModule(a.FeeMarketKeeper, a.GetSubspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())), + + // osmosis modules + lockup.NewAppModule(*a.LockupKeeper, a.AccountKeeper, a.BankKeeper), + epochs.NewAppModule(*a.EpochsKeeper), + gamm.NewAppModule(appCodec, *a.GAMMKeeper, a.AccountKeeper, a.BankKeeper), + poolmanager.NewAppModule(*a.PoolManagerKeeper, a.GAMMKeeper), + incentives.NewAppModule(*a.IncentivesKeeper, a.AccountKeeper, a.BankKeeper, a.EpochsKeeper), + txfees.NewAppModule(*a.TxFeesKeeper), + } +} + +// ModuleAccountAddrs returns all the app's module account addresses. +func (*AppKeepers) ModuleAccountAddrs() map[string]bool { + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + + // exclude the streamer as we want him to be able to get external incentives + modAccAddrs[authtypes.NewModuleAddress(streamermoduletypes.ModuleName).String()] = false + modAccAddrs[authtypes.NewModuleAddress(txfeestypes.ModuleName).String()] = false + return modAccAddrs +} + +// module account permissions +var maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + sequencermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, + rollappmoduletypes.ModuleName: {}, + streamermoduletypes.ModuleName: nil, + evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account. + evmtypes.ModuleVirtualFrontierContractDeployerName: nil, // used for deploying virtual frontier bank contract. + gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + txfeestypes.ModuleName: {authtypes.Burner}, +} + +var BeginBlockers = []string{ + epochstypes.ModuleName, + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + vestingtypes.ModuleName, + feemarkettypes.ModuleName, + evmtypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + packetforwardtypes.ModuleName, + authtypes.ModuleName, + authz.ModuleName, + banktypes.ModuleName, + govtypes.ModuleName, + crisistypes.ModuleName, + genutiltypes.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + rollappmoduletypes.ModuleName, + sequencermoduletypes.ModuleName, + streamermoduletypes.ModuleName, + denommetadatamoduletypes.ModuleName, + delayedacktypes.ModuleName, + eibcmoduletypes.ModuleName, + lockuptypes.ModuleName, + gammtypes.ModuleName, + poolmanagertypes.ModuleName, + incentivestypes.ModuleName, + txfeestypes.ModuleName, +} + +var EndBlockers = []string{ + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + capabilitytypes.ModuleName, + authtypes.ModuleName, + authz.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + feemarkettypes.ModuleName, + evmtypes.ModuleName, + slashingtypes.ModuleName, + vestingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + packetforwardtypes.ModuleName, + rollappmoduletypes.ModuleName, + sequencermoduletypes.ModuleName, + streamermoduletypes.ModuleName, + denommetadatamoduletypes.ModuleName, + delayedacktypes.ModuleName, + eibcmoduletypes.ModuleName, + epochstypes.ModuleName, + lockuptypes.ModuleName, + gammtypes.ModuleName, + poolmanagertypes.ModuleName, + incentivestypes.ModuleName, + txfeestypes.ModuleName, +} + +var InitGenesis = []string{ + capabilitytypes.ModuleName, + authtypes.ModuleName, + authz.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + vestingtypes.ModuleName, + slashingtypes.ModuleName, + feemarkettypes.ModuleName, + evmtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + crisistypes.ModuleName, + ibchost.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + ibctransfertypes.ModuleName, + packetforwardtypes.ModuleName, + feegrant.ModuleName, + rollappmoduletypes.ModuleName, + sequencermoduletypes.ModuleName, + streamermoduletypes.ModuleName, + denommetadatamoduletypes.ModuleName, // must after `x/bank` to trigger hooks + delayedacktypes.ModuleName, + eibcmoduletypes.ModuleName, + epochstypes.ModuleName, + lockuptypes.ModuleName, + gammtypes.ModuleName, + poolmanagertypes.ModuleName, + incentivestypes.ModuleName, + txfeestypes.ModuleName, +} diff --git a/app/upgrades/types.go b/app/upgrades/types.go index c4dbf0ff0..ccb3f909b 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -23,10 +23,10 @@ type BaseAppParamManager interface { // The app.go will then define the handler. type Upgrade struct { // Upgrade version name, for the upgrade handler, e.g. `v4` - UpgradeName string + Name string - // CreateUpgradeHandler defines the function that creates an upgrade handler - CreateUpgradeHandler func(*module.Manager, module.Configurator, BaseAppParamManager, *keepers.AppKeepers) upgradetypes.UpgradeHandler + // CreateHandler defines the function that creates an upgrade handler + CreateHandler func(*module.Manager, module.Configurator, BaseAppParamManager, *keepers.AppKeepers) upgradetypes.UpgradeHandler // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. StoreUpgrades storetypes.StoreUpgrades diff --git a/app/upgrades/v3/constants.go b/app/upgrades/v3/constants.go index f4a2dd3fc..f53287a1b 100644 --- a/app/upgrades/v3/constants.go +++ b/app/upgrades/v3/constants.go @@ -12,8 +12,8 @@ const ( ) var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, + Name: UpgradeName, + CreateHandler: CreateUpgradeHandler, StoreUpgrades: storetypes.StoreUpgrades{ Added: []string{eibctypes.ModuleName}, }, diff --git a/app/upgrades/v4/constants.go b/app/upgrades/v4/constants.go index dbb376ada..5767968b7 100644 --- a/app/upgrades/v4/constants.go +++ b/app/upgrades/v4/constants.go @@ -4,7 +4,6 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/dymensionxyz/dymension/v3/app/upgrades" - delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" ) const ( @@ -12,9 +11,7 @@ const ( ) var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{delayedacktypes.ModuleName}, - }, + Name: UpgradeName, + CreateHandler: CreateUpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, } diff --git a/cmd/dymd/cmd/root.go b/cmd/dymd/cmd/root.go index e9c30c57a..4e2da78ca 100644 --- a/cmd/dymd/cmd/root.go +++ b/cmd/dymd/cmd/root.go @@ -32,6 +32,7 @@ import ( // this line is used by starport scaffolding # root/moduleImport "github.com/dymensionxyz/dymension/v3/app" + "github.com/dymensionxyz/dymension/v3/app/keepers" appparams "github.com/dymensionxyz/dymension/v3/app/params" ethermintclient "github.com/evmos/ethermint/client" @@ -124,17 +125,17 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig a := appCreator{encodingConfig} rootCmd.AddCommand( ethermintclient.ValidateChainID( - genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), + genutilcli.InitCmd(keepers.ModuleBasics, app.DefaultNodeHome), ), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.MigrateGenesisCmd(), genutilcli.GenTxCmd( - app.ModuleBasics, + keepers.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, ), - genutilcli.ValidateGenesisCmd(app.ModuleBasics), + genutilcli.ValidateGenesisCmd(keepers.ModuleBasics), AddGenesisAccountCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), debug.Cmd(), @@ -180,7 +181,7 @@ func queryCommand() *cobra.Command { authcmd.QueryTxCmd(), ) - app.ModuleBasics.AddQueryCommands(cmd) + keepers.ModuleBasics.AddQueryCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd @@ -209,7 +210,7 @@ func txCommand() *cobra.Command { authcmd.GetAuxToFeeCommand(), ) - app.ModuleBasics.AddTxCommands(cmd) + keepers.ModuleBasics.AddTxCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd diff --git a/testutil/network/network.go b/testutil/network/network.go index 250e5dbad..f7e73206b 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -15,6 +15,7 @@ import ( tmdb "github.com/tendermint/tm-db" "github.com/dymensionxyz/dymension/v3/app" + "github.com/dymensionxyz/dymension/v3/app/keepers" ) type ( @@ -59,7 +60,7 @@ func DefaultConfig() network.Config { ) } - cfg.GenesisState = app.ModuleBasics.DefaultGenesis(encoding.Codec) + cfg.GenesisState = keepers.ModuleBasics.DefaultGenesis(encoding.Codec) if evmGenesisStateJson, found := cfg.GenesisState[evmtypes.ModuleName]; found { // force disable Enable Create of x/evm var evmGenesisState evmtypes.GenesisState diff --git a/x/delayedack/ibc_middleware.go b/x/delayedack/ibc_middleware.go index bdc4b2326..eddba5ebf 100644 --- a/x/delayedack/ibc_middleware.go +++ b/x/delayedack/ibc_middleware.go @@ -21,15 +21,41 @@ var _ porttypes.Middleware = &IBCMiddleware{} type IBCMiddleware struct { porttypes.IBCModule - *keeper.Keeper // keeper is an ics4 wrapper - raKeeper rollappkeeper.Keeper + keeper.Keeper // keeper is an ics4 wrapper + raKeeper rollappkeeper.Keeper } -func NewIBCMiddleware(app porttypes.IBCModule, keeper keeper.Keeper, raK rollappkeeper.Keeper) IBCMiddleware { - return IBCMiddleware{ - IBCModule: app, - Keeper: &keeper, - raKeeper: raK, +type option func(*IBCMiddleware) + +func WithIBCModule(m porttypes.IBCModule) option { + return func(i *IBCMiddleware) { + i.IBCModule = m + } +} + +func WithKeeper(k keeper.Keeper) option { + return func(m *IBCMiddleware) { + m.Keeper = k + } +} + +func WithRollappKeeper(k rollappkeeper.Keeper) option { + return func(m *IBCMiddleware) { + m.raKeeper = k + } +} + +func NewIBCMiddleware(opts ...option) *IBCMiddleware { + w := &IBCMiddleware{} + for _, opt := range opts { + opt(w) + } + return w +} + +func (w *IBCMiddleware) Setup(opts ...option) { + for _, opt := range opts { + opt(w) } } diff --git a/x/delayedack/keeper/fraud_test.go b/x/delayedack/keeper/fraud_test.go index e552d06d1..d57e75cf2 100644 --- a/x/delayedack/keeper/fraud_test.go +++ b/x/delayedack/keeper/fraud_test.go @@ -10,8 +10,12 @@ import ( ) func (suite *DelayedAckTestSuite) TestHandleFraud() { - keeper, ctx, rollappKeeper := suite.App.DelayedAckKeeper, suite.Ctx, suite.App.RollappKeeper - transferStack := damodule.NewIBCMiddleware(ibctransfer.NewIBCModule(suite.App.TransferKeeper), keeper, rollappKeeper) + keeper, ctx := suite.App.DelayedAckKeeper, suite.Ctx + transferStack := damodule.NewIBCMiddleware( + damodule.WithIBCModule(ibctransfer.NewIBCModule(suite.App.TransferKeeper)), + damodule.WithKeeper(keeper), + damodule.WithRollappKeeper(suite.App.RollappKeeper), + ) rollappId := "testRollappId" pkts := generatePackets(rollappId, 5) @@ -47,8 +51,12 @@ func (suite *DelayedAckTestSuite) TestHandleFraud() { } func (suite *DelayedAckTestSuite) TestDeletionOfRevertedPackets() { - keeper, ctx, rollappKeeper := suite.App.DelayedAckKeeper, suite.Ctx, suite.App.RollappKeeper - transferStack := damodule.NewIBCMiddleware(ibctransfer.NewIBCModule(suite.App.TransferKeeper), keeper, rollappKeeper) + keeper, ctx := suite.App.DelayedAckKeeper, suite.Ctx + transferStack := damodule.NewIBCMiddleware( + damodule.WithIBCModule(ibctransfer.NewIBCModule(suite.App.TransferKeeper)), + damodule.WithKeeper(keeper), + damodule.WithRollappKeeper(suite.App.RollappKeeper), + ) rollappId := "testRollappId" pkts := generatePackets(rollappId, 5) diff --git a/x/delayedack/keeper/invariants_test.go b/x/delayedack/keeper/invariants_test.go index 3b4ee059c..8dd627ba5 100644 --- a/x/delayedack/keeper/invariants_test.go +++ b/x/delayedack/keeper/invariants_test.go @@ -15,8 +15,11 @@ import ( func (suite *DelayedAckTestSuite) TestInvariants() { suite.SetupTest() - keeper, rollappKeeper := suite.App.DelayedAckKeeper, suite.App.RollappKeeper - transferStack := damodule.NewIBCMiddleware(ibctransfer.NewIBCModule(suite.App.TransferKeeper), keeper, rollappKeeper) + transferStack := damodule.NewIBCMiddleware( + damodule.WithIBCModule(ibctransfer.NewIBCModule(suite.App.TransferKeeper)), + damodule.WithKeeper(suite.App.DelayedAckKeeper), + damodule.WithRollappKeeper(suite.App.RollappKeeper), + ) initialHeight := int64(10) suite.Ctx = suite.Ctx.WithBlockHeight(initialHeight) diff --git a/x/delayedack/keeper/params.go b/x/delayedack/keeper/params.go index 5d1f5e27e..6c67d04aa 100644 --- a/x/delayedack/keeper/params.go +++ b/x/delayedack/keeper/params.go @@ -17,6 +17,11 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramstore.SetParamSet(ctx, ¶ms) } +func (k Keeper) EpochIdentifier(ctx sdk.Context) (res string) { + k.paramstore.Get(ctx, types.KeyEpochIdentifier, &res) + return +} + func (k Keeper) BridgingFee(ctx sdk.Context) (res sdk.Dec) { k.paramstore.Get(ctx, types.KeyBridgeFee, &res) return diff --git a/x/rollapp/keeper/invariants_test.go b/x/rollapp/keeper/invariants_test.go index 73514ac71..b94d5d6fb 100644 --- a/x/rollapp/keeper/invariants_test.go +++ b/x/rollapp/keeper/invariants_test.go @@ -1,10 +1,11 @@ package keeper_test import ( + "github.com/tendermint/tendermint/libs/rand" + commontypes "github.com/dymensionxyz/dymension/v3/x/common/types" "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" "github.com/dymensionxyz/dymension/v3/x/rollapp/types" - "github.com/tendermint/tendermint/libs/rand" ) func (suite *RollappTestSuite) TestInvariants() { diff --git a/x/rollapp/keeper/rollapp_suite_test.go b/x/rollapp/keeper/rollapp_suite_test.go index fcfb6714b..1f206b155 100644 --- a/x/rollapp/keeper/rollapp_suite_test.go +++ b/x/rollapp/keeper/rollapp_suite_test.go @@ -4,16 +4,16 @@ import ( "strconv" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dymensionxyz/dymension/v3/app/apptesting" - "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" - "github.com/dymensionxyz/dymension/v3/x/rollapp/types" - "github.com/stretchr/testify/suite" - "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/dymensionxyz/dymension/v3/app/apptesting" + "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" + "github.com/dymensionxyz/dymension/v3/x/rollapp/types" ) // Prevent strconv unused error