diff --git a/Makefile b/Makefile index b00572ee4..731738f6c 100755 --- a/Makefile +++ b/Makefile @@ -400,9 +400,9 @@ lint-fix: .PHONY: lint lint-fix format: - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs gofmt -w -s - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs misspell -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs goimports -w -local github.com/ingenuity-build/quicksilver + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' -not -name '*.gw.go' | xargs gofumpt -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' -not -name '*.gw.go' | xargs misspell -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' -not -name '*.gw.go' | xargs goimports -w -local github.com/ingenuity-build/quicksilver .PHONY: format mdlint: diff --git a/app/app.go b/app/app.go index 40c58c1d3..110f4fba3 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,9 @@ import ( "path/filepath" "strings" + "github.com/ingenuity-build/quicksilver/app/keepers" + + "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -19,34 +22,19 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - 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" "github.com/cosmos/cosmos-sdk/x/auth/ante" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" 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" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types" "github.com/gorilla/mux" - appconfig "github.com/ingenuity-build/quicksilver/cmd/config" - "github.com/ingenuity-build/quicksilver/utils" - "github.com/ingenuity-build/quicksilver/wasmbinding" "github.com/prometheus/client_golang/prometheus" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -55,97 +43,8 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - "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/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" - - 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/ingenuity-build/quicksilver/x/mint" - mintkeeper "github.com/ingenuity-build/quicksilver/x/mint/keeper" - minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" - "github.com/ingenuity-build/quicksilver/x/tokenfactory" - - ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts" - icacontroller "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller" - icacontrollerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" - icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" - icahost "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host" - icahostkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/keeper" - icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" - icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" - "github.com/cosmos/ibc-go/v5/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v5/modules/core" - ibcclient "github.com/cosmos/ibc-go/v5/modules/core/02-client" - ibcclientclient "github.com/cosmos/ibc-go/v5/modules/core/02-client/client" - ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" - porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" - ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" - ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" - - ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types" - - "github.com/ingenuity-build/quicksilver/x/claimsmanager" - claimsmanagerkeeper "github.com/ingenuity-build/quicksilver/x/claimsmanager/keeper" - claimsmanagertypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" - - "github.com/ingenuity-build/quicksilver/x/epochs" - epochskeeper "github.com/ingenuity-build/quicksilver/x/epochs/keeper" - epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" - - "github.com/ingenuity-build/quicksilver/x/interchainstaking" - interchainstakingclient "github.com/ingenuity-build/quicksilver/x/interchainstaking/client" - interchainstakingkeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" - interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - - "github.com/ingenuity-build/quicksilver/x/interchainquery" - interchainquerykeeper "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" - interchainquerytypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" - - "github.com/ingenuity-build/quicksilver/x/participationrewards" - participationrewardsclient "github.com/ingenuity-build/quicksilver/x/participationrewards/client" - participationrewardskeeper "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" - participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" - - "github.com/ingenuity-build/quicksilver/x/airdrop" - airdropkeeper "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" airdroptypes "github.com/ingenuity-build/quicksilver/x/airdrop/types" - - tokenfactorykeeper "github.com/ingenuity-build/quicksilver/x/tokenfactory/keeper" - tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" - - "github.com/CosmWasm/wasmd/x/wasm" + interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) func Init() { @@ -165,65 +64,6 @@ var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string - // ModuleBasics defines the module BasicManager is in charge of setting up basic, - // non-dependant module elements, such as codec registration - // and genesis verification. - ModuleBasics = module.NewBasicManager( - auth.AppModuleBasic{}, - genutil.AppModuleBasic{}, - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - staking.AppModuleBasic{}, - distr.AppModuleBasic{}, - mint.AppModuleBasic{}, - gov.NewAppModuleBasic( - []govclient.ProposalHandler{ - paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler, - ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, interchainstakingclient.RegisterProposalHandler, interchainstakingclient.UpdateProposalHandler, - participationrewardsclient.AddProtocolDataProposalHandler, - }, - ), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - ibc.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - transfer.AppModuleBasic{}, - ica.AppModuleBasic{}, - vesting.AppModuleBasic{}, - claimsmanager.AppModuleBasic{}, - epochs.AppModuleBasic{}, - interchainstaking.AppModuleBasic{}, - interchainquery.AppModuleBasic{}, - participationrewards.AppModuleBasic{}, - airdrop.AppModuleBasic{}, - tokenfactory.AppModuleBasic{}, - wasm.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}, - icatypes.ModuleName: nil, - claimsmanagertypes.ModuleName: nil, - interchainstakingtypes.ModuleName: {authtypes.Minter}, - interchainstakingtypes.EscrowModuleAccount: {authtypes.Burner}, - interchainquerytypes.ModuleName: nil, - participationrewardstypes.ModuleName: nil, - airdroptypes.ModuleName: nil, - wasm.ModuleName: {authtypes.Burner}, - tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - } - // module accounts that are allowed to receive tokens allowedReceivingModAcc = map[string]bool{ distrtypes.ModuleName: true, @@ -240,6 +80,7 @@ var ( // Quicksilver implements an extended ABCI application. type Quicksilver struct { *baseapp.BaseApp + keepers.AppKeepers // encoding cdc *codec.LegacyAmino @@ -248,49 +89,6 @@ type Quicksilver struct { invCheckPeriod uint - // keys to access the substores - keys map[string]*storetypes.KVStoreKey - tkeys map[string]*storetypes.TransientStoreKey - memKeys map[string]*storetypes.MemoryStoreKey - - // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.BaseKeeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - DistrKeeper distrkeeper.Keeper - MintKeeper mintkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - AuthzKeeper authzkeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - ICAControllerKeeper icacontrollerkeeper.Keeper - ICAHostKeeper icahostkeeper.Keeper - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - - // Quicksilver keepers - EpochsKeeper epochskeeper.Keeper - ClaimsManagerKeeper claimsmanagerkeeper.Keeper - InterchainstakingKeeper interchainstakingkeeper.Keeper - InterchainQueryKeeper interchainquerykeeper.Keeper - ParticipationRewardsKeeper participationrewardskeeper.Keeper - AirdropKeeper airdropkeeper.Keeper - TokenFactoryKeeper *tokenfactorykeeper.Keeper - // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper - ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper - ScopedICAHostKeeper capabilitykeeper.ScopedKeeper - ScopedInterchainStakingAccountKeeper capabilitykeeper.ScopedKeeper - - WasmKeeper wasm.Keeper - scopedWasmKeeper capabilitykeeper.ScopedKeeper //nolint:unused //TODO: we can use this for testing - // the module manager mm *module.Manager @@ -335,508 +133,70 @@ func NewQuicksilver( bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - keys := sdk.NewKVStoreKeys( - // SDK keys - authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - distrtypes.StoreKey, minttypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, - feegrant.StoreKey, authzkeeper.StoreKey, - // ibc keys - ibchost.StoreKey, ibctransfertypes.StoreKey, - icacontrollertypes.StoreKey, - icahosttypes.StoreKey, - // quicksilver keys - claimsmanagertypes.StoreKey, - epochstypes.StoreKey, - interchainstakingtypes.StoreKey, - interchainquerytypes.StoreKey, - participationrewardstypes.StoreKey, - airdroptypes.StoreKey, - wasm.StoreKey, - tokenfactorytypes.StoreKey, - ) - - // Add the transient store key - tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) - memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) - app := &Quicksilver{ BaseApp: bApp, cdc: cdc, appCodec: appCodec, interfaceRegistry: interfaceRegistry, invCheckPeriod: invCheckPeriod, - keys: keys, - tkeys: tkeys, - memKeys: memKeys, } - // init params keeper and subspaces - 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]) - - scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) - scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) - scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) - scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) - scopedInterchainStakingKeeper := app.CapabilityKeeper.ScopeToModule(interchainstakingtypes.ModuleName) - scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName) - - // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating - // their scoped modules in `NewApp` with `ScopeToModule` - app.CapabilityKeeper.Seal() - - proofOpsFn := utils.ValidateProofOps - if mock { - proofOpsFn = utils.MockProofOps - } - - selfProofOpsFn := utils.ValidateSelfProofOps - if mock { - selfProofOpsFn = utils.MockSelfProofOps - } - - // use custom account for contracts - app.AccountKeeper = authkeeper.NewAccountKeeper( - appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, appconfig.Bech32PrefixAccAddr, - ) - app.BankKeeper = bankkeeper.NewBaseKeeper( - appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(), - ) - stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), - ) - app.DistrKeeper = distrkeeper.NewKeeper( - appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, authtypes.FeeCollectorName, - ) - app.MintKeeper = mintkeeper.NewKeeper( - appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.AccountKeeper, app.BankKeeper, - app.DistrKeeper, app.EpochsKeeper, 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()), - ) - - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper) - - // Create IBC Keeper - app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, - ) - - // Create Transfer Keepers - app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, - ) - transferModule := transfer.NewAppModule(app.TransferKeeper) - transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) - - // ICA Keepers - app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), - app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - scopedICAControllerKeeper, app.MsgServiceRouter(), - ) - - app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), - app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), - ) - - icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper) - - app.ClaimsManagerKeeper = claimsmanagerkeeper.NewKeeper( - appCodec, - keys[claimsmanagertypes.StoreKey], - *app.IBCKeeper, - ) - - claimsmanagerModule := claimsmanager.NewAppModule(appCodec, app.ClaimsManagerKeeper) - - app.InterchainQueryKeeper = interchainquerykeeper.NewKeeper(appCodec, keys[interchainquerytypes.StoreKey], app.IBCKeeper) - interchainQueryModule := interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper) - - app.InterchainstakingKeeper = interchainstakingkeeper.NewKeeper( - appCodec, - keys[interchainstakingtypes.StoreKey], - app.AccountKeeper, - app.BankKeeper, - app.ICAControllerKeeper, - &scopedInterchainStakingKeeper, - app.InterchainQueryKeeper, - *app.IBCKeeper, - app.TransferKeeper, - app.ClaimsManagerKeeper, - app.GetSubspace(interchainstakingtypes.ModuleName), - ) - interchainstakingModule := interchainstaking.NewAppModule(appCodec, app.InterchainstakingKeeper) - - interchainstakingIBCModule := interchainstaking.NewIBCModule(app.InterchainstakingKeeper) - - app.ParticipationRewardsKeeper = participationrewardskeeper.NewKeeper( - appCodec, - keys[participationrewardstypes.StoreKey], - app.GetSubspace(participationrewardstypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - app.StakingKeeper, - app.InterchainQueryKeeper, - app.InterchainstakingKeeper, - authtypes.FeeCollectorName, - proofOpsFn, - selfProofOpsFn, - ) - if err := app.InterchainQueryKeeper.SetCallbackHandler(interchainstakingtypes.ModuleName, app.InterchainstakingKeeper.CallbackHandler()); err != nil { - panic(err) - } - - participationrewardsModule := participationrewards.NewAppModule(appCodec, app.ParticipationRewardsKeeper) - - if err := app.InterchainQueryKeeper.SetCallbackHandler(participationrewardstypes.ModuleName, app.ParticipationRewardsKeeper.CallbackHandler()); err != nil { - panic(err) - } - - tokenFactoryKeeper := tokenfactorykeeper.NewKeeper( - keys[tokenfactorytypes.StoreKey], - app.GetSubspace(tokenfactorytypes.ModuleName), - app.AccountKeeper, - app.BankKeeper.WithMintCoinsRestriction(tokenfactorytypes.NewTokenFactoryDenomMintCoinsRestriction()), - app.DistrKeeper, - ) - - app.TokenFactoryKeeper = &tokenFactoryKeeper - // Quicksilver Keepers - epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey]) - app.EpochsKeeper = *epochsKeeper.SetHooks( - epochstypes.NewMultiEpochHooks( - app.MintKeeper.Hooks(), - app.ClaimsManagerKeeper.Hooks(), - app.InterchainstakingKeeper.Hooks(), - app.ParticipationRewardsKeeper.Hooks(), - ), - ) - - app.ParticipationRewardsKeeper.SetEpochsKeeper(app.EpochsKeeper) - - // this line is used by starport scaffolding # stargate/app/keeperDefinition wasmDir := filepath.Join(homePath, "data") - wasmConfig, err := wasm.ReadWasmConfig(appOpts) if err != nil { panic("error while reading wasm config: " + err.Error()) } - // The last arguments can contain custom message handlers, and custom query handlers, - // if we want to allow any custom callbacks - supportedFeatures := "iterator,staking,stargate,osmosis" - wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.BankKeeper, app.TokenFactoryKeeper), wasmOpts...) - wasmOpts = append(wasmbinding.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...) - - app.WasmKeeper = wasm.NewKeeper( + app.AppKeepers = keepers.NewAppKeepers( appCodec, - keys[wasm.StoreKey], - app.GetSubspace(wasm.ModuleName), - app.AccountKeeper, - app.BankKeeper, - app.StakingKeeper, - app.DistrKeeper, - app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - scopedWasmKeeper, - app.TransferKeeper, - app.MsgServiceRouter(), - app.GRPCQueryRouter(), + bApp, + cdc, + maccPerms, + app.BlockedAddrs(), + skipUpgradeHeights, + mock, + homePath, + invCheckPeriod, + appOpts, wasmDir, wasmConfig, - supportedFeatures, - wasmOpts..., - ) - - icaControllerIBCModule := icacontroller.NewIBCMiddleware(interchainstakingIBCModule, app.ICAControllerKeeper) - icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) - - // Create static IBC router, add transfer route, then set and seal it - ibcRouter := porttypes.NewRouter() - ibcRouter. - AddRoute(ibctransfertypes.ModuleName, transferIBCModule). - AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper)). - AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). - AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). - AddRoute(interchainstakingtypes.ModuleName, icaControllerIBCModule) - app.IBCKeeper.SetRouter(ibcRouter) - - // create evidence keeper with router - 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() - - // register the proposal types - govRouter := govv1beta1.NewRouter() - - // The gov proposal types can be individually enabled - if len(enabledProposals) != 0 { - govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) - } - - 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(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(interchainstakingtypes.RouterKey, interchainstaking.NewProposalHandler(app.InterchainstakingKeeper)). - AddRoute(participationrewardstypes.RouterKey, participationrewards.NewProposalHandler(app.ParticipationRewardsKeeper)) - // add custom proposal routes here. - - app.GovKeeper = govkeeper.NewKeeper( - appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, - ) - - app.AirdropKeeper = airdropkeeper.NewKeeper( - appCodec, - keys[airdroptypes.StoreKey], - app.GetSubspace(airdroptypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - app.StakingKeeper, - app.GovKeeper, - app.InterchainstakingKeeper, - app.InterchainQueryKeeper, - app.ParticipationRewardsKeeper, - proofOpsFn, + enabledProposals, + wasmOpts, ) - airdropModule := airdrop.NewAppModule(appCodec, app.AirdropKeeper) /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + app.mm = module.NewManager(appModules(app, encodingConfig, skipGenesisInvariants)...) - // NOTE: Any module instantiated in the module manager that is later modified - // must be passed by reference here. - app.mm = module.NewManager( - // SDK app modules - genutil.NewAppModule( - app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, - encodingConfig.TxConfig, - ), - auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), - vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), - crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - upgrade.NewAppModule(app.UpgradeKeeper), - evidence.NewAppModule(app.EvidenceKeeper), - params.NewAppModule(app.ParamsKeeper), - feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - // ibc modules - ibc.NewAppModule(app.IBCKeeper), - transferModule, - icaModule, - // Quicksilver app modules - claimsmanagerModule, - epochs.NewAppModule(appCodec, app.EpochsKeeper), - interchainstakingModule, - interchainQueryModule, - participationrewardsModule, - airdropModule, - tokenfactory.NewAppModule(*app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), - wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - ) - - // 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: upgrade module must go first to handle software upgrades. - // NOTE: staking module is required if HistoricalEntries param > 0. - // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) - app.mm.SetOrderBeginBlockers( - upgradetypes.ModuleName, - capabilitytypes.ModuleName, - // Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning - epochstypes.ModuleName, - distrtypes.ModuleName, - minttypes.ModuleName, - slashingtypes.ModuleName, - evidencetypes.ModuleName, - stakingtypes.ModuleName, - ibchost.ModuleName, - interchainstakingtypes.ModuleName, - interchainquerytypes.ModuleName, // check ordering here. - // no-op modules - ibctransfertypes.ModuleName, - icatypes.ModuleName, - claimsmanagertypes.ModuleName, - participationrewardstypes.ModuleName, - airdroptypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - govtypes.ModuleName, - crisistypes.ModuleName, - genutiltypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - vestingtypes.ModuleName, - tokenfactorytypes.ModuleName, - wasm.ModuleName, - ) - - // NOTE: fee market module must go last in order to retrieve the block gas used. - app.mm.SetOrderEndBlockers( - crisistypes.ModuleName, - govtypes.ModuleName, - stakingtypes.ModuleName, - // Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end - interchainquerytypes.ModuleName, - epochstypes.ModuleName, - // no-op modules - ibchost.ModuleName, - ibctransfertypes.ModuleName, - icatypes.ModuleName, - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - minttypes.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, - claimsmanagertypes.ModuleName, - interchainstakingtypes.ModuleName, - participationrewardstypes.ModuleName, - airdroptypes.ModuleName, - tokenfactorytypes.ModuleName, - wasm.ModuleName, - // currently no-op. - ) - - // 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( - // SDK modules - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - stakingtypes.ModuleName, - slashingtypes.ModuleName, - govtypes.ModuleName, - minttypes.ModuleName, - ibchost.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - ibctransfertypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, - icatypes.ModuleName, - // Quicksilver modules - epochstypes.ModuleName, - claimsmanagertypes.ModuleName, - interchainstakingtypes.ModuleName, - interchainquerytypes.ModuleName, - participationrewardstypes.ModuleName, - airdroptypes.ModuleName, - tokenfactorytypes.ModuleName, - // wasmd - wasm.ModuleName, - // NOTE: crisis module must go at the end to check for invariants on each module - crisistypes.ModuleName, - ) + app.mm.SetOrderBeginBlockers(orderBeginBlockers()...) + app.mm.SetOrderEndBlockers(orderEndBlockers()...) + app.mm.SetOrderInitGenesis(orderInitBlockers()...) app.mm.RegisterInvariants(&app.CrisisKeeper) app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) - // handle upgrades here - setUpgradeHandlers(app) - app.mm.RegisterServices(app.configurator) // // add test gRPC service for testing gRPC queries in isolation // // testdata.RegisterTestServiceServer(app.GRPCQueryRouter(), testdata.TestServiceImpl{}) - // // create the simulation manager and define the order of the modules for deterministic simulations - - // // NOTE: this is not required apps that don't use the simulator for fuzz testing - // // transactions - // app.sm = module.NewSimulationManager( - // auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), - // bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - // capability.NewAppModule(appCodec, *app.CapabilityKeeper), - // gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - // mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), - // staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - // distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - // slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - // params.NewAppModule(app.ParamsKeeper), - // evidence.NewAppModule(app.EvidenceKeeper), - // feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - // authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - // // ibc modules - // ibc.NewAppModule(app.IBCKeeper), - // transferModule, - // //icaModule, - // // Quicksilver app modules - // epochs.NewAppModule(appCodec, app.EpochsKeeper), - // interchainstakingModule, - // ) - - // app.sm.RegisterStoreDecoders() + // create the simulation manager and define the order of the modules for deterministic simulations + // + // NOTE: this is not required apps that don't use the simulator for fuzz testing + // transactions + app.sm = module.NewSimulationManager(simulationModules(app, encodingConfig)...) + + app.sm.RegisterStoreDecoders() // initialize stores - app.MountKVStores(keys) - app.MountTransientStores(tkeys) - app.MountMemoryStores(memKeys) + app.MountKVStores(app.GetKVStoreKey()) + app.MountTransientStores(app.GetTransientStoreKey()) + app.MountMemoryStores(app.GetMemoryStoreKey()) // initialize BaseApp - app.SetInitChainer(app.InitChainer) - app.SetBeginBlocker(app.BeginBlocker) - options := HandlerOptions{ HandlerOptions: ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, @@ -846,24 +206,25 @@ func NewQuicksilver( SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, WasmConfig: wasmConfig, - TxCounterStoreKey: keys[wasm.StoreKey], + TxCounterStoreKey: app.GetKey(wasm.StoreKey), IBCKeeper: app.IBCKeeper, } + app.SetInitChainer(app.InitChainer) + app.SetBeginBlocker(app.BeginBlocker) app.SetAnteHandler(NewAnteHandler(options)) app.SetEndBlocker(app.EndBlocker) + // handle upgrades here + app.setUpgradeHandlers() + app.setUpgradeStoreLoaders() + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) } } - app.ScopedIBCKeeper = scopedIBCKeeper - app.ScopedTransferKeeper = scopedTransferKeeper - app.ScopedICAControllerKeeper = scopedICAControllerKeeper - app.ScopedICAHostKeeper = scopedICAHostKeeper - // Finally start the tpsCounter. app.tpsCounter = newTPSCounter(logger) go func() { @@ -968,27 +329,6 @@ func (app *Quicksilver) 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 *Quicksilver) 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 *Quicksilver) 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 *Quicksilver) 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. @@ -1083,39 +423,6 @@ func GetMaccPerms() map[string][]string { 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) - - // SDK subspaces - paramsKeeper.Subspace(authtypes.ModuleName) - paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(minttypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName) - // ibc subspaces - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(icacontrollertypes.SubModuleName) - paramsKeeper.Subspace(icahosttypes.SubModuleName) - paramsKeeper.Subspace(ibchost.ModuleName) - // quicksilver subspaces - paramsKeeper.Subspace(claimsmanagertypes.ModuleName) - paramsKeeper.Subspace(interchainstakingtypes.ModuleName) - paramsKeeper.Subspace(interchainquerytypes.ModuleName) - paramsKeeper.Subspace(participationrewardstypes.ModuleName) - paramsKeeper.Subspace(airdroptypes.ModuleName) - paramsKeeper.Subspace(tokenfactorytypes.ModuleName) - // wasm subspace - paramsKeeper.Subspace(wasm.ModuleName) - - return paramsKeeper -} - func GetWasmOpts(appOpts servertypes.AppOptions) []wasm.Option { var wasmOpts []wasm.Option if cast.ToBool(appOpts.Get("telemetry.enabled")) { diff --git a/app/export.go b/app/export.go index f91f58db1..991c2d448 100644 --- a/app/export.go +++ b/app/export.go @@ -55,7 +55,7 @@ func (app *Quicksilver) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + validators, err := staking.WriteValidators(ctx, *app.StakingKeeper) if err != nil { return servertypes.ExportedApp{}, err } @@ -184,7 +184,7 @@ func (app *Quicksilver) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAdd // 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/helpers/test_helpers.go b/app/helpers/test_helpers.go new file mode 100644 index 000000000..d91280c23 --- /dev/null +++ b/app/helpers/test_helpers.go @@ -0,0 +1,6 @@ +package helpers + +// SimAppChainID hardcoded chainID for simulation. +const ( + SimAppChainID = "quicksilver-app" +) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go new file mode 100644 index 000000000..db257bb89 --- /dev/null +++ b/app/keepers/keepers.go @@ -0,0 +1,582 @@ +package keepers + +import ( + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/store/streaming" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + 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" + "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" + ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts" + icacontroller "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" + "github.com/cosmos/ibc-go/v5/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + ibcclient "github.com/cosmos/ibc-go/v5/modules/core/02-client" + ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" + ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" + tmos "github.com/tendermint/tendermint/libs/os" + + appconfig "github.com/ingenuity-build/quicksilver/cmd/config" + "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/wasmbinding" + airdropkeeper "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" + airdroptypes "github.com/ingenuity-build/quicksilver/x/airdrop/types" + claimsmanagerkeeper "github.com/ingenuity-build/quicksilver/x/claimsmanager/keeper" + claimsmanagertypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" + epochskeeper "github.com/ingenuity-build/quicksilver/x/epochs/keeper" + epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" + interchainquerykeeper "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" + interchainquerytypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" + "github.com/ingenuity-build/quicksilver/x/interchainstaking" + interchainstakingkeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" + interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + mintkeeper "github.com/ingenuity-build/quicksilver/x/mint/keeper" + minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" + "github.com/ingenuity-build/quicksilver/x/participationrewards" + participationrewardskeeper "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" + participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" + tokenfactorykeeper "github.com/ingenuity-build/quicksilver/x/tokenfactory/keeper" + tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" +) + +type AppKeepers struct { + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper + ScopedInterchainStakingAccountKeeper capabilitykeeper.ScopedKeeper + scopedWasmKeeper capabilitykeeper.ScopedKeeper // TODO: we can use this for testing + + // "Normal" keepers + // SDK + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.BaseKeeper + DistrKeeper distrkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + EvidenceKeeper evidencekeeper.Keeper + GovKeeper govkeeper.Keeper + WasmKeeper wasm.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + ParamsKeeper paramskeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + + // Quicksilver keepers + EpochsKeeper epochskeeper.Keeper + MintKeeper mintkeeper.Keeper + ClaimsManagerKeeper claimsmanagerkeeper.Keeper + InterchainstakingKeeper interchainstakingkeeper.Keeper + InterchainQueryKeeper interchainquerykeeper.Keeper + ParticipationRewardsKeeper participationrewardskeeper.Keeper + AirdropKeeper airdropkeeper.Keeper + TokenFactoryKeeper tokenfactorykeeper.Keeper + + // IBC keepers + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + ICAControllerKeeper icacontrollerkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + + // Modules + ICAModule ica.AppModule + TransferModule transfer.AppModule + + // keys to access the substores + keys map[string]*storetypes.KVStoreKey + tkeys map[string]*storetypes.TransientStoreKey + memKeys map[string]*storetypes.MemoryStoreKey +} + +func NewAppKeepers( + appCodec codec.Codec, + bApp *baseapp.BaseApp, + legacyAmino *codec.LegacyAmino, + maccPerms map[string][]string, + blockedAddresses map[string]bool, + skipUpgradeHeights map[int64]bool, + mock bool, + homePath string, + invCheckPeriod uint, + appOpts servertypes.AppOptions, + wasmDir string, + wasmConfig wasm.Config, + wasmEnabledProposals []wasm.ProposalType, + wasmOpts []wasm.Option, +) AppKeepers { + appKeepers := AppKeepers{} + + // Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey + appKeepers.GenerateKeys() + + /* + configure state listening capabilities using AppOptions + we are doing nothing with the returned streamingServices and waitGroup in this case + */ + if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, appKeepers.keys); err != nil { + tmos.Exit(err.Error()) + } + + appKeepers.InitKeepers( + appCodec, + bApp, + legacyAmino, + maccPerms, + blockedAddresses, + skipUpgradeHeights, + mock, + homePath, + invCheckPeriod, + appOpts, + wasmDir, + wasmConfig, + wasmEnabledProposals, + wasmOpts, + ) + + appKeepers.SetupHooks() + + return appKeepers +} + +// InitKeepers initializes all keepers. +func (appKeepers *AppKeepers) InitKeepers( + appCodec codec.Codec, + bApp *baseapp.BaseApp, + cdc *codec.LegacyAmino, + maccPerms map[string][]string, + blockedAddresses map[string]bool, + skipUpgradeHeights map[int64]bool, + mock bool, + homePath string, + invCheckPeriod uint, + appOpts servertypes.AppOptions, + wasmDir string, + wasmConfig wasm.Config, + wasmEnabledProposals []wasm.ProposalType, + wasmOpts []wasm.Option, +) { + // Add 'normal' keepers + proofOpsFn := utils.ValidateProofOps + if mock { + proofOpsFn = utils.MockProofOps + } + + selfProofOpsFn := utils.ValidateSelfProofOps + if mock { + selfProofOpsFn = utils.MockSelfProofOps + } + + appKeepers.ParamsKeeper = appKeepers.initParamsKeeper(appCodec, cdc, appKeepers.keys[paramstypes.StoreKey], appKeepers.tkeys[paramstypes.TStoreKey]) + // set the BaseApp's parameter store + bApp.SetParamStore(appKeepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) + + // add capability keeper and ScopeToModule for ibc module + appKeepers.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, appKeepers.keys[capabilitytypes.StoreKey], appKeepers.memKeys[capabilitytypes.MemStoreKey]) + scopedIBCKeeper := appKeepers.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + scopedTransferKeeper := appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedICAControllerKeeper := appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) + scopedICAHostKeeper := appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + scopedInterchainStakingKeeper := appKeepers.CapabilityKeeper.ScopeToModule(interchainstakingtypes.ModuleName) + scopedWasmKeeper := appKeepers.CapabilityKeeper.ScopeToModule(wasm.ModuleName) + + appKeepers.CapabilityKeeper.Seal() + + // TODO: Make a SetInvCheckPeriod fn on CrisisKeeper. + // IMO, its bad design atm that it requires this in state machine initialization + appKeepers.CrisisKeeper = crisiskeeper.NewKeeper( + appKeepers.GetSubspace(crisistypes.ModuleName), invCheckPeriod, appKeepers.BankKeeper, authtypes.FeeCollectorName, + ) + + appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper( + skipUpgradeHeights, appKeepers.keys[upgradetypes.StoreKey], appCodec, homePath, bApp, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + // use custom account for contracts + appKeepers.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, + appKeepers.keys[authtypes.StoreKey], + appKeepers.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + maccPerms, + appconfig.Bech32PrefixAccAddr, + ) + + appKeepers.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, + appKeepers.keys[banktypes.StoreKey], + appKeepers.AccountKeeper, + appKeepers.GetSubspace(banktypes.ModuleName), + blockedAddresses, + ) + + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, + appKeepers.keys[stakingtypes.StoreKey], + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.GetSubspace(stakingtypes.ModuleName), + ) + appKeepers.StakingKeeper = &stakingKeeper + + appKeepers.DistrKeeper = distrkeeper.NewKeeper( + appCodec, + appKeepers.keys[distrtypes.StoreKey], + appKeepers.GetSubspace(distrtypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + authtypes.FeeCollectorName, + ) + + appKeepers.MintKeeper = mintkeeper.NewKeeper( + appCodec, + appKeepers.keys[minttypes.StoreKey], + appKeepers.GetSubspace(minttypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.DistrKeeper, + appKeepers.EpochsKeeper, + authtypes.FeeCollectorName, + ) + + appKeepers.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + appKeepers.keys[slashingtypes.StoreKey], + appKeepers.StakingKeeper, + appKeepers.GetSubspace(slashingtypes.ModuleName), + ) + + appKeepers.FeeGrantKeeper = feegrantkeeper.NewKeeper( + appCodec, + appKeepers.keys[feegrant.StoreKey], + appKeepers.AccountKeeper, + ) + + appKeepers.AuthzKeeper = authzkeeper.NewKeeper( + appKeepers.keys[authzkeeper.StoreKey], + appCodec, bApp.MsgServiceRouter(), + appKeepers.AccountKeeper, + ) + + // Create IBC Keeper + appKeepers.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + appKeepers.keys[ibchost.StoreKey], + appKeepers.GetSubspace(ibchost.ModuleName), + stakingKeeper, + appKeepers.UpgradeKeeper, + scopedIBCKeeper, + ) + + // Create Transfer Keepers + appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + appKeepers.keys[ibctransfertypes.StoreKey], + appKeepers.GetSubspace(ibctransfertypes.ModuleName), + appKeepers.IBCKeeper.ChannelKeeper, + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + scopedTransferKeeper, + ) + + appKeepers.TransferModule = transfer.NewAppModule(appKeepers.TransferKeeper) + transferIBCModule := transfer.NewIBCModule(appKeepers.TransferKeeper) + + // ICA Keepers + appKeepers.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( + appCodec, + appKeepers.keys[icacontrollertypes.StoreKey], + appKeepers.GetSubspace(icacontrollertypes.SubModuleName), + appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + scopedICAControllerKeeper, + bApp.MsgServiceRouter(), + ) + + appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, + appKeepers.keys[icahosttypes.StoreKey], + appKeepers.GetSubspace(icahosttypes.SubModuleName), + appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.AccountKeeper, + scopedICAHostKeeper, + bApp.MsgServiceRouter(), + ) + appKeepers.ICAModule = ica.NewAppModule(&appKeepers.ICAControllerKeeper, &appKeepers.ICAHostKeeper) + icaHostIBCModule := icahost.NewIBCModule(appKeepers.ICAHostKeeper) + + appKeepers.ClaimsManagerKeeper = claimsmanagerkeeper.NewKeeper( + appCodec, + appKeepers.keys[claimsmanagertypes.StoreKey], + *appKeepers.IBCKeeper, + ) + + // claimsmanagerModule := claimsmanager.NewAppModule(appCodec, appKeepers.ClaimsManagerKeeper) + + appKeepers.InterchainQueryKeeper = interchainquerykeeper.NewKeeper(appCodec, appKeepers.keys[interchainquerytypes.StoreKey], appKeepers.IBCKeeper) + + // interchainQueryModule := interchainquery.NewAppModule(appCodec, appKeepers.InterchainQueryKeeper) + + appKeepers.InterchainstakingKeeper = interchainstakingkeeper.NewKeeper( + appCodec, + appKeepers.keys[interchainstakingtypes.StoreKey], + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.ICAControllerKeeper, + &scopedInterchainStakingKeeper, + appKeepers.InterchainQueryKeeper, + *appKeepers.IBCKeeper, + appKeepers.TransferKeeper, + appKeepers.ClaimsManagerKeeper, + appKeepers.GetSubspace(interchainstakingtypes.ModuleName), + ) + + // interchainstakingModule := interchainstaking.NewAppModule(appCodec, app.InterchainstakingKeeper) + + interchainstakingIBCModule := interchainstaking.NewIBCModule(appKeepers.InterchainstakingKeeper) + + appKeepers.ParticipationRewardsKeeper = participationrewardskeeper.NewKeeper( + appCodec, + appKeepers.keys[participationrewardstypes.StoreKey], + appKeepers.GetSubspace(participationrewardstypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + appKeepers.InterchainQueryKeeper, + appKeepers.InterchainstakingKeeper, + authtypes.FeeCollectorName, + proofOpsFn, + selfProofOpsFn, + ) + + if err := appKeepers.InterchainQueryKeeper.SetCallbackHandler(interchainstakingtypes.ModuleName, appKeepers.InterchainstakingKeeper.CallbackHandler()); err != nil { + panic(err) + } + + // participationrewardsModule := participationrewards.NewAppModule(appCodec, appKeepers.ParticipationRewardsKeeper) + + if err := appKeepers.InterchainQueryKeeper.SetCallbackHandler(participationrewardstypes.ModuleName, appKeepers.ParticipationRewardsKeeper.CallbackHandler()); err != nil { + panic(err) + } + + appKeepers.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper( + appKeepers.keys[tokenfactorytypes.StoreKey], + appKeepers.GetSubspace(tokenfactorytypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper.WithMintCoinsRestriction(tokenfactorytypes.NewTokenFactoryDenomMintCoinsRestriction()), + appKeepers.DistrKeeper, + ) + + // Quicksilver Keepers + appKeepers.EpochsKeeper = epochskeeper.NewKeeper(appCodec, appKeepers.keys[epochstypes.StoreKey]) + appKeepers.ParticipationRewardsKeeper.SetEpochsKeeper(appKeepers.EpochsKeeper) + + // The last arguments can contain custom message handlers, and custom query handlers, + // if we want to allow any custom callbacks + supportedFeatures := "iterator,staking,stargate,osmosis" + wasmOpts = append(wasmbinding.RegisterCustomPlugins(&appKeepers.BankKeeper, &appKeepers.TokenFactoryKeeper), wasmOpts...) + wasmOpts = append(wasmbinding.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...) + + appKeepers.WasmKeeper = wasm.NewKeeper( + appCodec, + appKeepers.keys[wasm.StoreKey], + appKeepers.GetSubspace(wasm.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + appKeepers.DistrKeeper, + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + scopedWasmKeeper, + appKeepers.TransferKeeper, + bApp.MsgServiceRouter(), + bApp.GRPCQueryRouter(), + wasmDir, + wasmConfig, + supportedFeatures, + wasmOpts..., + ) + + icaControllerIBCModule := icacontroller.NewIBCMiddleware(interchainstakingIBCModule, appKeepers.ICAControllerKeeper) + + // Create static IBC router, add transfer route, then set and seal it + ibcRouter := porttypes.NewRouter() + ibcRouter. + AddRoute(ibctransfertypes.ModuleName, transferIBCModule). + AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper)). + AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). + AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). + AddRoute(interchainstakingtypes.ModuleName, icaControllerIBCModule) + appKeepers.IBCKeeper.SetRouter(ibcRouter) + + // create evidence keeper with router + appKeepers.EvidenceKeeper = *evidencekeeper.NewKeeper( + appCodec, + appKeepers.keys[evidencetypes.StoreKey], + appKeepers.StakingKeeper, + appKeepers.SlashingKeeper, + ) + + govConfig := govtypes.DefaultConfig() + + // register the proposal types + govRouter := govv1beta1.NewRouter() + + // The gov proposal types can be individually enabled + if len(wasmEnabledProposals) != 0 { + govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(appKeepers.WasmKeeper, wasmEnabledProposals)) + } + + govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)). + AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(appKeepers.DistrKeeper)). + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)). + AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). + AddRoute(interchainstakingtypes.RouterKey, interchainstaking.NewProposalHandler(appKeepers.InterchainstakingKeeper)). + AddRoute(participationrewardstypes.RouterKey, participationrewards.NewProposalHandler(appKeepers.ParticipationRewardsKeeper)) + // add custom proposal routes here. + + appKeepers.GovKeeper = govkeeper.NewKeeper( + appCodec, + appKeepers.keys[govtypes.StoreKey], + appKeepers.GetSubspace(govtypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + govRouter, + bApp.MsgServiceRouter(), + govConfig, + ) + + appKeepers.AirdropKeeper = airdropkeeper.NewKeeper( + appCodec, + appKeepers.keys[airdroptypes.StoreKey], + appKeepers.GetSubspace(airdroptypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + appKeepers.GovKeeper, + appKeepers.InterchainstakingKeeper, + appKeepers.InterchainQueryKeeper, + appKeepers.ParticipationRewardsKeeper, + proofOpsFn, + ) + // airdropModule := airdrop.NewAppModule(appCodec, appKeepers.AirdropKeeper) + + appKeepers.ScopedIBCKeeper = scopedIBCKeeper + appKeepers.ScopedTransferKeeper = scopedTransferKeeper + appKeepers.ScopedICAControllerKeeper = scopedICAControllerKeeper + appKeepers.ScopedInterchainStakingAccountKeeper = scopedInterchainStakingKeeper + appKeepers.ScopedICAHostKeeper = scopedICAHostKeeper + appKeepers.scopedWasmKeeper = scopedWasmKeeper +} + +// initParamsKeeper init params keeper and its subspaces. +func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + // SDK subspaces + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + // ibc subspaces + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + // quicksilver subspaces + paramsKeeper.Subspace(claimsmanagertypes.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + paramsKeeper.Subspace(interchainstakingtypes.ModuleName) + paramsKeeper.Subspace(interchainquerytypes.ModuleName) + paramsKeeper.Subspace(participationrewardstypes.ModuleName) + paramsKeeper.Subspace(airdroptypes.ModuleName) + paramsKeeper.Subspace(tokenfactorytypes.ModuleName) + // wasm subspace + paramsKeeper.Subspace(wasm.ModuleName) + + return paramsKeeper +} + +// SetupHooks sets up hooks for modules. +func (appKeepers *AppKeepers) SetupHooks() { + // For every module that has hooks set on it, + // you must check InitNormalKeepers to ensure that its not passed by de-reference + // e.g. *app.StakingKeeper doesn't appear + + // Recall that SetHooks is a mutative call. + appKeepers.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + appKeepers.DistrKeeper.Hooks(), + appKeepers.SlashingKeeper.Hooks(), + ), + ) + + appKeepers.EpochsKeeper.SetHooks( + epochstypes.NewMultiEpochHooks( + appKeepers.MintKeeper.Hooks(), + appKeepers.ClaimsManagerKeeper.Hooks(), + appKeepers.InterchainstakingKeeper.Hooks(), + appKeepers.ParticipationRewardsKeeper.Hooks(), + ), + ) + + appKeepers.GovKeeper.SetHooks( + govtypes.NewMultiGovHooks( + // insert governance hooks receivers here + ), + ) +} diff --git a/app/keepers/keys.go b/app/keepers/keys.go new file mode 100644 index 000000000..becf8e1ff --- /dev/null +++ b/app/keepers/keys.go @@ -0,0 +1,121 @@ +package keepers + +import ( + "github.com/CosmWasm/wasmd/x/wasm" + 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" + 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" + icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" + + airdroptypes "github.com/ingenuity-build/quicksilver/x/airdrop/types" + claimsmanagertypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" + epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" + interchainquerytypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" + interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" + participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" + tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" +) + +// TODO: We need to automate this, by bundling with a module struct... +func KVStoreKeys() []string { + return []string{ + // SDK keys + authtypes.StoreKey, + banktypes.StoreKey, + stakingtypes.StoreKey, + distrtypes.StoreKey, + slashingtypes.StoreKey, + govtypes.StoreKey, + paramstypes.StoreKey, + upgradetypes.StoreKey, + evidencetypes.StoreKey, + capabilitytypes.StoreKey, + feegrant.StoreKey, + authzkeeper.StoreKey, + // ibc keys + ibchost.StoreKey, + ibctransfertypes.StoreKey, + icacontrollertypes.StoreKey, + icahosttypes.StoreKey, + // quicksilver keys + minttypes.StoreKey, + claimsmanagertypes.StoreKey, + epochstypes.StoreKey, + interchainstakingtypes.StoreKey, + interchainquerytypes.StoreKey, + participationrewardstypes.StoreKey, + airdroptypes.StoreKey, + wasm.StoreKey, + tokenfactorytypes.StoreKey, + } +} + +// GenerateKeys generates new keys (KV Store, Transient store, and memory store). +func (appKeepers *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. + appKeepers.keys = sdk.NewKVStoreKeys(KVStoreKeys()...) + + // Define transient store keys + appKeepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey) + + // MemKeys are for information that is stored only in RAM. + appKeepers.memKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) +} + +// GetSubspace gets existing substore from keeper. +func (appKeepers *AppKeepers) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := appKeepers.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// GetKVStoreKey gets KV Store keys. +func (appKeepers *AppKeepers) GetKVStoreKey() map[string]*storetypes.KVStoreKey { + return appKeepers.keys +} + +// GetTransientStoreKey gets Transient Store keys. +func (appKeepers *AppKeepers) GetTransientStoreKey() map[string]*storetypes.TransientStoreKey { + return appKeepers.tkeys +} + +// GetMemoryStoreKey get memory Store keys. +func (appKeepers *AppKeepers) GetMemoryStoreKey() map[string]*storetypes.MemoryStoreKey { + return appKeepers.memKeys +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (appKeepers *AppKeepers) GetKey(storeKey string) *storetypes.KVStoreKey { + return appKeepers.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (appKeepers *AppKeepers) GetTKey(storeKey string) *storetypes.TransientStoreKey { + return appKeepers.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (appKeepers *AppKeepers) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { + return appKeepers.memKeys[storeKey] +} diff --git a/app/modules.go b/app/modules.go new file mode 100644 index 000000000..d8473851c --- /dev/null +++ b/app/modules.go @@ -0,0 +1,346 @@ +package app + +import ( + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + 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" + 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" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/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" + ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts" + icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + "github.com/cosmos/ibc-go/v5/modules/apps/transfer" + ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v5/modules/core" + ibcclientclient "github.com/cosmos/ibc-go/v5/modules/core/02-client/client" + ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" + + "github.com/ingenuity-build/quicksilver/x/airdrop" + airdroptypes "github.com/ingenuity-build/quicksilver/x/airdrop/types" + "github.com/ingenuity-build/quicksilver/x/claimsmanager" + claimsmanagertypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" + "github.com/ingenuity-build/quicksilver/x/epochs" + epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" + "github.com/ingenuity-build/quicksilver/x/interchainquery" + interchainquerytypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" + "github.com/ingenuity-build/quicksilver/x/interchainstaking" + interchainstakingclient "github.com/ingenuity-build/quicksilver/x/interchainstaking/client" + interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + "github.com/ingenuity-build/quicksilver/x/mint" + minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" + "github.com/ingenuity-build/quicksilver/x/participationrewards" + participationrewardsclient "github.com/ingenuity-build/quicksilver/x/participationrewards/client" + participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" + "github.com/ingenuity-build/quicksilver/x/tokenfactory" + tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" +) + +var ( + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + distr.AppModuleBasic{}, + mint.AppModuleBasic{}, + gov.NewAppModuleBasic( + []govclient.ProposalHandler{ + paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, interchainstakingclient.RegisterProposalHandler, interchainstakingclient.UpdateProposalHandler, + participationrewardsclient.AddProtocolDataProposalHandler, + }, + ), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + ibc.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + ica.AppModuleBasic{}, + vesting.AppModuleBasic{}, + claimsmanager.AppModuleBasic{}, + epochs.AppModuleBasic{}, + interchainstaking.AppModuleBasic{}, + interchainquery.AppModuleBasic{}, + participationrewards.AppModuleBasic{}, + airdrop.AppModuleBasic{}, + tokenfactory.AppModuleBasic{}, + wasm.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}, + icatypes.ModuleName: nil, + claimsmanagertypes.ModuleName: nil, + interchainstakingtypes.ModuleName: {authtypes.Minter}, + interchainstakingtypes.EscrowModuleAccount: {authtypes.Burner}, + interchainquerytypes.ModuleName: nil, + participationrewardstypes.ModuleName: nil, + airdroptypes.ModuleName: nil, + wasm.ModuleName: {authtypes.Burner}, + tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + } +) + +func appModules( + app *Quicksilver, + encodingConfig EncodingConfig, + skipGenesisInvariants bool, +) []module.AppModule { + appCodec := encodingConfig.Marshaler + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + return []module.AppModule{ + // SDK app modules + genutil.NewAppModule( + app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, + encodingConfig.TxConfig, + ), + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + 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), + params.NewAppModule(app.ParamsKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + // ibc modules + ibc.NewAppModule(app.IBCKeeper), + app.TransferModule, + app.ICAModule, + // Quicksilver app modules + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper), + claimsmanager.NewAppModule(appCodec, app.ClaimsManagerKeeper), + epochs.NewAppModule(appCodec, app.EpochsKeeper), + interchainstaking.NewAppModule(appCodec, app.InterchainstakingKeeper), + interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper), + participationrewards.NewAppModule(appCodec, app.ParticipationRewardsKeeper), + airdrop.NewAppModule(appCodec, app.AirdropKeeper), + tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), + wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + } +} + +// simulationModules returns modules for simulation manager +// define the order of the modules for deterministic simulations +func simulationModules( + app *Quicksilver, + encodingConfig EncodingConfig, +) []module.AppModuleSimulation { + appCodec := encodingConfig.Marshaler + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + return []module.AppModuleSimulation{ + // SDK app modules + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + 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), + evidence.NewAppModule(app.EvidenceKeeper), + params.NewAppModule(app.ParamsKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + // ibc modules + ibc.NewAppModule(app.IBCKeeper), + app.TransferModule, + app.ICAModule, + // Quicksilver app modules + // mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper), + // claimsmanager.NewAppModule(appCodec, app.ClaimsManagerKeeper), + epochs.NewAppModule(appCodec, app.EpochsKeeper), + interchainstaking.NewAppModule(appCodec, app.InterchainstakingKeeper), + interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper), + // participationrewards.NewAppModule(appCodec, app.ParticipationRewardsKeeper), + // airdrop.NewAppModule(appCodec, app.AirdropKeeper), + // tokenfactory.NewAppModule(*app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), + wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + } +} + +/* +orderBeginBlockers tells the app's module manager how to set the order of +BeginBlockers, which are run at the beginning of every block. +Interchain Security Requirements: +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 +NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) +*/ + +func orderBeginBlockers() []string { + return []string{ + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + // Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning + epochstypes.ModuleName, + distrtypes.ModuleName, + minttypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + ibchost.ModuleName, + interchainstakingtypes.ModuleName, + interchainquerytypes.ModuleName, // check ordering here. + // no-op modules + ibctransfertypes.ModuleName, + icatypes.ModuleName, + claimsmanagertypes.ModuleName, + participationrewardstypes.ModuleName, + airdroptypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + govtypes.ModuleName, + crisistypes.ModuleName, + genutiltypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + vestingtypes.ModuleName, + tokenfactorytypes.ModuleName, + wasm.ModuleName, + } +} + +/* +Interchain Security Requirements: +- provider.EndBlock gets validator updates from the staking module; +thus, staking.EndBlock must be executed before provider.EndBlock; +- creating a new consumer chain requires the following order, +CreateChildClient(), staking.EndBlock, provider.EndBlock; +thus, gov.EndBlock must be executed before staking.EndBlock +*/ +func orderEndBlockers() []string { + return []string{ + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + // Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end + interchainquerytypes.ModuleName, + epochstypes.ModuleName, + // no-op modules + ibchost.ModuleName, + ibctransfertypes.ModuleName, + icatypes.ModuleName, + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + claimsmanagertypes.ModuleName, + interchainstakingtypes.ModuleName, + participationrewardstypes.ModuleName, + airdroptypes.ModuleName, + tokenfactorytypes.ModuleName, + wasm.ModuleName, + // currently no-op. + } +} + +/* +NOTE: The genutils module must occur after staking so that pools are +properly initialized with tokens from genesis accounts. +NOTE: The genutils module must also occur after auth so that it can access the params from auth. +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. +*/ +func orderInitBlockers() []string { + return []string{ + // SDK modules + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + ibchost.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + ibctransfertypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + icatypes.ModuleName, + // Quicksilver modules + epochstypes.ModuleName, + claimsmanagertypes.ModuleName, + interchainstakingtypes.ModuleName, + interchainquerytypes.ModuleName, + participationrewardstypes.ModuleName, + airdroptypes.ModuleName, + tokenfactorytypes.ModuleName, + // wasmd + wasm.ModuleName, + // NOTE: crisis module must go at the end to check for invariants on each module + crisistypes.ModuleName, + } +} diff --git a/app/sim_test.go b/app/sim_test.go new file mode 100644 index 000000000..44b5914b4 --- /dev/null +++ b/app/sim_test.go @@ -0,0 +1,9 @@ +package app_test + +import "github.com/ingenuity-build/quicksilver/app/simulation" + +func init() { + simulation.GetSimulatorFlags() +} + +// TODO add simulation tests diff --git a/app/simulation/config.go b/app/simulation/config.go new file mode 100644 index 000000000..74340e4ea --- /dev/null +++ b/app/simulation/config.go @@ -0,0 +1,75 @@ +package simulation + +import ( + "flag" + + "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// List of available flags for the simulator +var ( + FlagGenesisFileValue string + FlagParamsFileValue string + FlagExportParamsPathValue string + FlagExportParamsHeightValue int + FlagExportStatePathValue string + FlagExportStatsPathValue string + FlagSeedValue int64 + FlagInitialBlockHeightValue int + FlagNumBlocksValue int + FlagBlockSizeValue int + FlagLeanValue bool + FlagCommitValue bool + FlagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation + FlagAllInvariantsValue bool + + FlagEnabledValue bool + FlagVerboseValue bool + FlagPeriodValue uint + FlagGenesisTimeValue int64 +) + +// GetSimulatorFlags gets the values of all the available simulation flags +func GetSimulatorFlags() { + // config fields + flag.StringVar(&FlagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file") + flag.StringVar(&FlagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis") + flag.StringVar(&FlagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON") + flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params") + flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON") + flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON") + flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed") + flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation") + flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height") + flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block") + flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output") + flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit") + flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation") + flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found") + + // simulation flags + flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation") + flag.BoolVar(&FlagVerboseValue, "Verbose", false, "verbose log output") + flag.UintVar(&FlagPeriodValue, "Period", 0, "run slow invariants only once every period assertions") + flag.Int64Var(&FlagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time") +} + +// NewConfigFromFlags creates a simulation from the retrieved values of the flags. +func NewConfigFromFlags() simulation.Config { + return simulation.Config{ + GenesisFile: FlagGenesisFileValue, + ParamsFile: FlagParamsFileValue, + ExportParamsPath: FlagExportParamsPathValue, + ExportParamsHeight: FlagExportParamsHeightValue, + ExportStatePath: FlagExportStatePathValue, + ExportStatsPath: FlagExportStatsPathValue, + Seed: FlagSeedValue, + InitialBlockHeight: FlagInitialBlockHeightValue, + NumBlocks: FlagNumBlocksValue, + BlockSize: FlagBlockSizeValue, + Lean: FlagLeanValue, + Commit: FlagCommitValue, + OnOperation: FlagOnOperationValue, + AllInvariants: FlagAllInvariantsValue, + } +} diff --git a/app/simulation/helpers.go b/app/simulation/helpers.go new file mode 100644 index 000000000..77beb1eb3 --- /dev/null +++ b/app/simulation/helpers.go @@ -0,0 +1,134 @@ +package simulation + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" + + "github.com/ingenuity-build/quicksilver/app" + "github.com/ingenuity-build/quicksilver/app/helpers" +) + +// SetupSimulation creates the config, db (levelDB), temporary directory and logger for +// the simulation tests. If `FlagEnabledValue` is false it skips the current test. +// Returns error on an invalid db intantiation or temp dir creation. +func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { + if !FlagEnabledValue { + return simtypes.Config{}, nil, "", nil, true, nil + } + + config := NewConfigFromFlags() + config.ChainID = helpers.SimAppChainID + + var logger log.Logger + if FlagVerboseValue { + logger = log.TestingLogger() + } else { + logger = log.NewNopLogger() + } + + dir, err := os.MkdirTemp("", dirPrefix) + if err != nil { + return simtypes.Config{}, nil, "", nil, false, err + } + + db, err := dbm.NewGoLevelDB(dbName, dir) + if err != nil { + return simtypes.Config{}, nil, "", nil, false, err + } + + return config, db, dir, logger, false, nil +} + +// Operations retrieves the simulation params from the provided file path +// and returns all the modules weighted operations +func Operations(app *app.Quicksilver, cdc codec.JSONCodec, config simtypes.Config) []simtypes.WeightedOperation { + simState := module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + } + + if config.ParamsFile != "" { + bz, err := os.ReadFile(config.ParamsFile) + if err != nil { + panic(err) + } + + err = json.Unmarshal(bz, &simState.AppParams) + if err != nil { + panic(err) + } + } + + simState.ParamChanges = app.SimulationManager().GenerateParamChanges(config.Seed) + simState.Contents = app.SimulationManager().GetProposalContents(simState) + return app.SimulationManager().WeightedOperations(simState) +} + +// CheckExportSimulation exports the app state and simulation parameters to JSON +// if the export paths are defined. +func CheckExportSimulation( + app *app.Quicksilver, + config simtypes.Config, + params simtypes.Params, +) error { + if config.ExportStatePath != "" { + fmt.Println("exporting app state...") + exported, err := app.ExportAppStateAndValidators(false, nil) + if err != nil { + return err + } + + if err := os.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0o600); err != nil { + return err + } + } + + if config.ExportParamsPath != "" { + fmt.Println("exporting simulation params...") + paramsBz, err := json.MarshalIndent(params, "", " ") + if err != nil { + return err + } + + if err := os.WriteFile(config.ExportParamsPath, paramsBz, 0o600); err != nil { + return err + } + } + return nil +} + +// PrintStats prints the corresponding statistics from the app DB. +func PrintStats(db dbm.DB) { + fmt.Println("\nLevelDB Stats") + fmt.Println(db.Stats()["leveldb.stats"]) + fmt.Println("LevelDB cached block size", db.Stats()["leveldb.cachedblock"]) +} + +// GetSimulationLog unmarshals the KVPair's Value to the corresponding type based on +// each module store key and the prefix bytes of the KVPair's key. +func GetSimulationLog(storeName string, sdr sdk.StoreDecoderRegistry, kvAs, kvBs []kv.Pair) (log string) { + for i := 0; i < len(kvAs); i++ { + if len(kvAs[i].Value) == 0 && len(kvBs[i].Value) == 0 { + // skip if the value doesn't have any bytes + continue + } + + decoder, ok := sdr[storeName] + if ok { + log += decoder(kvAs[i], kvBs[i]) + } else { + log += fmt.Sprintf("store A %X => %X\nstore B %X => %X\n", kvAs[i].Key, kvAs[i].Value, kvBs[i].Key, kvBs[i].Value) + } + } + + return log +} diff --git a/app/upgrades.go b/app/upgrades.go index 5ad872505..a455b3957 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -2,57 +2,27 @@ package app import ( "fmt" - "time" - sdkmath "cosmossdk.io/math" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/ingenuity-build/quicksilver/utils" - icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" - icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" -) - -// upgrade name consts: vMMmmppUpgradeName (M=Major, m=minor, p=patch) -const ( - ProductionChainID = "quicksilver-2" - InnuendoChainID = "innuendo-5" - DevnetChainID = "quicktest-1" - TestChainID = "testchain1" - v010300UpgradeName = "v1.3.0" - v010400UpgradeName = "v1.4.0" - v010400rc6UpgradeName = "v1.4.0-rc6" - v010400rc7UpgradeName = "v1.4.0-rc7" - v010400rc8UpgradeName = "v1.4.0-rc8" + "github.com/ingenuity-build/quicksilver/app/upgrades" ) -func isTest(ctx sdk.Context) bool { - return ctx.ChainID() == TestChainID -} - -func isDevnet(ctx sdk.Context) bool { - return ctx.ChainID() == DevnetChainID -} - -func isTestnet(ctx sdk.Context) bool { - return ctx.ChainID() == InnuendoChainID -} - -//nolint:all //function useful for writing network specific upgrade handlers -func isMainnet(ctx sdk.Context) bool { - return ctx.ChainID() == ProductionChainID +func (app *Quicksilver) setUpgradeHandlers() { + for _, upgrade := range upgrades.Upgrades() { + app.UpgradeKeeper.SetUpgradeHandler( + upgrade.UpgradeName, + upgrade.CreateUpgradeHandler( + app.mm, + app.configurator, + &app.AppKeepers, + ), + ) + } } -func setUpgradeHandlers(app *Quicksilver) { - app.UpgradeKeeper.SetUpgradeHandler(v010300UpgradeName, noOpHandler(app)) - app.UpgradeKeeper.SetUpgradeHandler(v010400UpgradeName, v010400UpgradeHandler(app)) - app.UpgradeKeeper.SetUpgradeHandler(v010400rc6UpgradeName, v010400rc6UpgradeHandler(app)) - app.UpgradeKeeper.SetUpgradeHandler(v010400rc7UpgradeName, noOpHandler(app)) - app.UpgradeKeeper.SetUpgradeHandler(v010400rc8UpgradeName, v010400rc8UpgradeHandler(app)) - +func (app *Quicksilver) setUpgradeStoreLoaders() { // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. @@ -81,148 +51,3 @@ func setUpgradeHandlers(app *Quicksilver) { app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) } } - -func noOpHandler(app *Quicksilver) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - } -} - -func v010400UpgradeHandler(app *Quicksilver) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // upgrade zones - app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone icstypes.Zone) (stop bool) { - zone.DepositsEnabled = true - zone.ReturnToSender = false - zone.UnbondingEnabled = false - zone.Decimals = 6 - app.InterchainstakingKeeper.SetZone(ctx, &zone) - return false - }) - - // upgrade receipts - time := ctx.BlockTime() - for _, r := range app.InterchainstakingKeeper.AllReceipts(ctx) { - r.FirstSeen = &time - r.Completed = &time - app.InterchainstakingKeeper.SetReceipt(ctx, r) - } - if isTestnet(ctx) || isTest(ctx) { - - app.InterchainstakingKeeper.RemoveZoneAndAssociatedRecords(ctx, "uni-5") - - // burn uqjunox - addr1, err := utils.AccAddressFromBech32("quick17v9kk34km3w6hdjs2sn5s5qjdu2zrm0m3rgtmq", "quick") - if err != nil { - return nil, err - } - addr2, err := utils.AccAddressFromBech32("quick16x03wcp37kx5e8ehckjxvwcgk9j0cqnhcccnty", "quick") - if err != nil { - return nil, err - } - - err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addr1, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(1600000)))) - if err != nil { - return nil, err - } - - err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addr2, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(200000000)))) - if err != nil { - return nil, err - } - - err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, icstypes.EscrowModuleAccount, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(400000)))) - if err != nil { - return nil, err - } - - err = app.BankKeeper.BurnCoins(ctx, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(202000000)))) - if err != nil { - return nil, err - } - } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - } -} - -func v010400rc6UpgradeHandler(app *Quicksilver) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - if isTestnet(ctx) { - app.InterchainstakingKeeper.RemoveZoneAndAssociatedRecords(ctx, "regen-redwood-1") - // re-register regen-redwood-1 with new connection - regenProp := icstypes.NewRegisterZoneProposal("register regen-redwood-1 zone", - "register regen-redwood-1 (regen-testnet) zone with multisend and lsm disabled", - "connection-8", - "uregen", - "uqregen", - "regen", - false, - true, - true, - false, - 6) - err := icskeeper.HandleRegisterZoneProposal(ctx, app.InterchainstakingKeeper, regenProp) - if err != nil { - return nil, err - } - } - - // remove expired failed redelegation records - app.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(_ int64, key []byte, record icstypes.RedelegationRecord) (stop bool) { - if record.CompletionTime.Equal(time.Time{}) { - app.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, record.ChainId, record.Source, record.Destination, record.EpochNumber) - } - return false - }) - - // remove and refund failed unbondings - app.InterchainstakingKeeper.IterateWithdrawalRecords(ctx, func(index int64, record icstypes.WithdrawalRecord) (stop bool) { - if record.Status == icskeeper.WithdrawStatusUnbond && record.CompletionTime.Equal(time.Time{}) { - delegatorAcc, err := utils.AccAddressFromBech32(record.Delegator, "quick") - if err != nil { - panic(err) - } - if err = app.InterchainstakingKeeper.BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.EscrowModuleAccount, delegatorAcc, sdk.NewCoins(record.BurnAmount)); err != nil { - panic(err) - } - app.InterchainstakingKeeper.DeleteWithdrawalRecord(ctx, record.ChainId, record.Txhash, record.Status) - } - return false - }) - - if isTestnet(ctx) || isDevnet(ctx) { - app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zoneInfo icstypes.Zone) (stop bool) { - app.InterchainstakingKeeper.OverrideRedemptionRateNoCap(ctx, zoneInfo) - return false - }) - } - - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - } -} - -func v010400rc8UpgradeHandler(app *Quicksilver) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // remove expired failed redelegation records - app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone icstypes.Zone) (stop bool) { - app.InterchainstakingKeeper.IterateAllDelegations(ctx, &zone, func(delegation icstypes.Delegation) (stop bool) { - if delegation.RedelegationEnd < 0 { - delegation.RedelegationEnd = 0 - app.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) - } - return false - }) - return false - }) - - app.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(_ int64, key []byte, record icstypes.RedelegationRecord) (stop bool) { - if record.CompletionTime.Unix() <= 0 { - app.InterchainstakingKeeper.Logger(ctx).Info("Removing delegation record", "chainid", record.ChainId, "source", record.Source, "destination", record.Destination, "epoch", record.EpochNumber) - app.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, record.ChainId, record.Source, record.Destination, record.EpochNumber) - } - return false - }) - - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - } -} diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 000000000..9a960a820 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,56 @@ +package upgrades + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/ingenuity-build/quicksilver/app/keepers" +) + +// upgrade name consts: vMMmmppUpgradeName (M=Major, m=minor, p=patch) +const ( + ProductionChainID = "quicksilver-2" + InnuendoChainID = "innuendo-5" + DevnetChainID = "quicktest-1" + TestChainID = "testchain1" + + V010300UpgradeName = "v1.3.0" + V010400UpgradeName = "v1.4.0" + V010400rc6UpgradeName = "v1.4.0-rc6" + V010400rc7UpgradeName = "v1.4.0-rc7" + V010400rc8UpgradeName = "v1.4.0-rc8" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +// must have written, in order for the state migration to go smoothly. +// An upgrade must implement this struct, and then set it in the app.go. +// The app.go will then define the handler. +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + + // CreateUpgradeHandler defines the function that creates an upgrade handler + CreateUpgradeHandler func(*module.Manager, module.Configurator, *keepers.AppKeepers) upgradetypes.UpgradeHandler + + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades storetypes.StoreUpgrades +} + +func isTest(ctx sdk.Context) bool { + return ctx.ChainID() == TestChainID +} + +func isDevnet(ctx sdk.Context) bool { + return ctx.ChainID() == DevnetChainID +} + +func isTestnet(ctx sdk.Context) bool { + return ctx.ChainID() == InnuendoChainID +} + +//nolint:all //function useful for writing network specific upgrade handlers +func isMainnet(ctx sdk.Context) bool { + return ctx.ChainID() == ProductionChainID +} diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go new file mode 100644 index 000000000..71e1c161d --- /dev/null +++ b/app/upgrades/upgrades.go @@ -0,0 +1,208 @@ +package upgrades + +import ( + "time" + + sdkmath "cosmossdk.io/math" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/ingenuity-build/quicksilver/app/keepers" + "github.com/ingenuity-build/quicksilver/utils" + icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" + icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" +) + +func Upgrades() []Upgrade { + return []Upgrade{ + { + UpgradeName: V010300UpgradeName, + CreateUpgradeHandler: NoOpHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, + }, + { + UpgradeName: V010400UpgradeName, + CreateUpgradeHandler: V010400UpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, + }, + { + UpgradeName: V010400rc6UpgradeName, + CreateUpgradeHandler: V010400rc6UpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, + }, + { + UpgradeName: V010400rc7UpgradeName, + CreateUpgradeHandler: NoOpHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, + }, + { + UpgradeName: V010400rc8UpgradeName, + CreateUpgradeHandler: V010400rc8UpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{}, + }, + } +} + +func NoOpHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + +func V010400UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // upgrade zones + keepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone icstypes.Zone) (stop bool) { + zone.DepositsEnabled = true + zone.ReturnToSender = false + zone.UnbondingEnabled = false + zone.Decimals = 6 + keepers.InterchainstakingKeeper.SetZone(ctx, &zone) + return false + }) + + // upgrade receipts + time := ctx.BlockTime() + for _, r := range keepers.InterchainstakingKeeper.AllReceipts(ctx) { + r.FirstSeen = &time + r.Completed = &time + keepers.InterchainstakingKeeper.SetReceipt(ctx, r) + } + if isTestnet(ctx) || isTest(ctx) { + + keepers.InterchainstakingKeeper.RemoveZoneAndAssociatedRecords(ctx, "uni-5") + + // burn uqjunox + addr1, err := utils.AccAddressFromBech32("quick17v9kk34km3w6hdjs2sn5s5qjdu2zrm0m3rgtmq", "quick") + if err != nil { + return nil, err + } + addr2, err := utils.AccAddressFromBech32("quick16x03wcp37kx5e8ehckjxvwcgk9j0cqnhcccnty", "quick") + if err != nil { + return nil, err + } + + err = keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, addr1, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(1600000)))) + if err != nil { + return nil, err + } + + err = keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, addr2, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(200000000)))) + if err != nil { + return nil, err + } + + err = keepers.BankKeeper.SendCoinsFromModuleToModule(ctx, icstypes.EscrowModuleAccount, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(400000)))) + if err != nil { + return nil, err + } + + err = keepers.BankKeeper.BurnCoins(ctx, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(202000000)))) + if err != nil { + return nil, err + } + } + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + +func V010400rc6UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if isTestnet(ctx) { + keepers.InterchainstakingKeeper.RemoveZoneAndAssociatedRecords(ctx, "regen-redwood-1") + // re-register regen-redwood-1 with new connection + regenProp := icstypes.NewRegisterZoneProposal("register regen-redwood-1 zone", + "register regen-redwood-1 (regen-testnet) zone with multisend and lsm disabled", + "connection-8", + "uregen", + "uqregen", + "regen", + false, + true, + true, + false, + 6) + err := icskeeper.HandleRegisterZoneProposal(ctx, keepers.InterchainstakingKeeper, regenProp) + if err != nil { + return nil, err + } + } + + // remove expired failed redelegation records + keepers.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(_ int64, key []byte, record icstypes.RedelegationRecord) (stop bool) { + if record.CompletionTime.Equal(time.Time{}) { + keepers.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, record.ChainId, record.Source, record.Destination, record.EpochNumber) + } + return false + }) + + // remove and refund failed unbondings + keepers.InterchainstakingKeeper.IterateWithdrawalRecords(ctx, func(index int64, record icstypes.WithdrawalRecord) (stop bool) { + if record.Status == icskeeper.WithdrawStatusUnbond && record.CompletionTime.Equal(time.Time{}) { + delegatorAcc, err := utils.AccAddressFromBech32(record.Delegator, "quick") + if err != nil { + panic(err) + } + if err = keepers.InterchainstakingKeeper.BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.EscrowModuleAccount, delegatorAcc, sdk.NewCoins(record.BurnAmount)); err != nil { + panic(err) + } + keepers.InterchainstakingKeeper.DeleteWithdrawalRecord(ctx, record.ChainId, record.Txhash, record.Status) + } + return false + }) + + if isTestnet(ctx) || isDevnet(ctx) { + keepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zoneInfo icstypes.Zone) (stop bool) { + keepers.InterchainstakingKeeper.OverrideRedemptionRateNoCap(ctx, zoneInfo) + return false + }) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + +func V010400rc8UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // remove expired failed redelegation records + keepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone icstypes.Zone) (stop bool) { + keepers.InterchainstakingKeeper.IterateAllDelegations(ctx, &zone, func(delegation icstypes.Delegation) (stop bool) { + if delegation.RedelegationEnd < 0 { + delegation.RedelegationEnd = 0 + keepers.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) + } + return false + }) + return false + }) + + keepers.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(_ int64, key []byte, record icstypes.RedelegationRecord) (stop bool) { + if record.CompletionTime.Unix() <= 0 { + keepers.InterchainstakingKeeper.Logger(ctx).Info("Removing delegation record", "chainid", record.ChainId, "source", record.Source, "destination", record.Destination, "epoch", record.EpochNumber) + keepers.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, record.ChainId, record.Source, record.Destination, record.EpochNumber) + } + return false + }) + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index b1035662c..37ed6874d 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -4,17 +4,18 @@ import ( "testing" "time" + "github.com/ingenuity-build/quicksilver/app/upgrades" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/utils" - icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" - tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibctesting "github.com/cosmos/ibc-go/v5/testing" "github.com/stretchr/testify/suite" + "github.com/ingenuity-build/quicksilver/utils" + icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" ) func init() { @@ -118,7 +119,7 @@ func (suite *AppTestSuite) initTestZone() { } suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) - reciept := icstypes.Receipt{ + receipt := icstypes.Receipt{ ChainId: "uni-5", Sender: utils.GenerateAccAddressForTest().String(), Txhash: "TestDeposit01", @@ -130,7 +131,7 @@ func (suite *AppTestSuite) initTestZone() { ), } - suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), reciept) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), receipt) ubRecord := icstypes.UnbondingRecord{ ChainId: "uni-5", @@ -214,7 +215,7 @@ func (suite *AppTestSuite) initTestZone() { func (s *AppTestSuite) TestV010400UpgradeHandler() { app := s.GetQuicksilverApp(s.chainA) - handler := v010400UpgradeHandler(app) + handler := upgrades.V010400UpgradeHandler(app.mm, app.configurator, &app.AppKeepers) ctx := s.chainA.GetContext() _, err := handler(ctx, types.Plan{}, app.mm.GetVersionMap()) s.Require().NoError(err) @@ -268,7 +269,8 @@ func (s *AppTestSuite) TestV010400UpgradeHandler() { func (s *AppTestSuite) TestV010400rc6UpgradeHandler() { app := s.GetQuicksilverApp(s.chainA) - handler := v010400rc6UpgradeHandler(app) + + handler := upgrades.V010400rc6UpgradeHandler(app.mm, app.configurator, &app.AppKeepers) ctx := s.chainA.GetContext() redelegations := app.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "osmosis-1") @@ -279,12 +281,12 @@ func (s *AppTestSuite) TestV010400rc6UpgradeHandler() { redelegations = app.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "osmosis-1") s.Require().Equal(0, len(redelegations)) - } func (s *AppTestSuite) TestV010400rc8UpgradeHandler() { app := s.GetQuicksilverApp(s.chainA) - handler := v010400rc8UpgradeHandler(app) + + handler := upgrades.V010400rc8UpgradeHandler(app.mm, app.configurator, &app.AppKeepers) ctx := s.chainA.GetContext() zone, _ := app.InterchainstakingKeeper.GetZone(ctx, "osmosis-1") @@ -342,5 +344,4 @@ func (s *AppTestSuite) TestV010400rc8UpgradeHandler() { s.Require().Equal(0, len(negRedelEndsAfter)) redelegations = app.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "osmosis-1") s.Require().Equal(0, len(redelegations)) - } diff --git a/cmd/quicksilverd/bulk_airdrop.go b/cmd/quicksilverd/bulk_airdrop.go index 1e253547d..eac506368 100644 --- a/cmd/quicksilverd/bulk_airdrop.go +++ b/cmd/quicksilverd/bulk_airdrop.go @@ -12,9 +12,6 @@ import ( "strings" "time" - "github.com/ingenuity-build/quicksilver/x/airdrop/types" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -23,6 +20,9 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/cobra" + + "github.com/ingenuity-build/quicksilver/x/airdrop/types" ) // AddZonedropCmd returns add-zonedrop cobra Command. diff --git a/cmd/quicksilverd/forceprune.go b/cmd/quicksilverd/forceprune.go index 9e9665940..ffb95380e 100644 --- a/cmd/quicksilverd/forceprune.go +++ b/cmd/quicksilverd/forceprune.go @@ -8,7 +8,6 @@ import ( "strconv" "github.com/spf13/cobra" - "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/util" diff --git a/cmd/quicksilverd/genaccounts.go b/cmd/quicksilverd/genaccounts.go index 3f897e274..f46f2ccf4 100644 --- a/cmd/quicksilverd/genaccounts.go +++ b/cmd/quicksilverd/genaccounts.go @@ -6,8 +6,6 @@ import ( "errors" "fmt" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -18,6 +16,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/cobra" ) const ( diff --git a/cmd/quicksilverd/genairdrop.go b/cmd/quicksilverd/genairdrop.go index 21ae7393e..a1020ecbf 100644 --- a/cmd/quicksilverd/genairdrop.go +++ b/cmd/quicksilverd/genairdrop.go @@ -5,9 +5,6 @@ import ( "fmt" "strconv" - "github.com/ingenuity-build/quicksilver/x/airdrop/types" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -16,6 +13,9 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/cobra" + + "github.com/ingenuity-build/quicksilver/x/airdrop/types" ) // AddGenesisAirdropCmd returns add-genesis-airdrop cobra Command. diff --git a/cmd/quicksilverd/root.go b/cmd/quicksilverd/root.go index d555edcb9..214582ad3 100644 --- a/cmd/quicksilverd/root.go +++ b/cmd/quicksilverd/root.go @@ -10,11 +10,6 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/prometheus/client_golang/prometheus" - "github.com/spf13/cast" - "github.com/spf13/cobra" - tmcli "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -23,26 +18,27 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/snapshots" + snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - tmcfg "github.com/tendermint/tendermint/config" - - servercfg "github.com/ingenuity-build/quicksilver/server/config" - + "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + "github.com/prometheus/client_golang/prometheus" + "github.com/spf13/cast" + "github.com/spf13/cobra" + tmcfg "github.com/tendermint/tendermint/config" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" - snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/ingenuity-build/quicksilver/app" quicksilverconfig "github.com/ingenuity-build/quicksilver/cmd/config" - - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/x/crisis" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" + servercfg "github.com/ingenuity-build/quicksilver/server/config" ) const ( diff --git a/osmosis-types/gamm/pool-models/balancer/amm.go b/osmosis-types/gamm/pool-models/balancer/amm.go index 6a3899154..1662449c7 100644 --- a/osmosis-types/gamm/pool-models/balancer/amm.go +++ b/osmosis-types/gamm/pool-models/balancer/amm.go @@ -6,8 +6,8 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/osmomath" ) diff --git a/osmosis-types/gamm/pool-models/balancer/codec.go b/osmosis-types/gamm/pool-models/balancer/codec.go index 5f84514fe..1fc0003c6 100644 --- a/osmosis-types/gamm/pool-models/balancer/codec.go +++ b/osmosis-types/gamm/pool-models/balancer/codec.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" proto "github.com/gogo/protobuf/proto" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/balancer/msgs.go b/osmosis-types/gamm/pool-models/balancer/msgs.go index f436db8f6..363d63764 100644 --- a/osmosis-types/gamm/pool-models/balancer/msgs.go +++ b/osmosis-types/gamm/pool-models/balancer/msgs.go @@ -4,6 +4,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/balancer/pool.go b/osmosis-types/gamm/pool-models/balancer/pool.go index b6d208817..23514e7c2 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/osmosis-types/gamm/pool-models/balancer/pool.go @@ -8,8 +8,8 @@ import ( "time" sdkioerrors "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" ) diff --git a/osmosis-types/gamm/pool-models/balancer/pool_asset.go b/osmosis-types/gamm/pool-models/balancer/pool_asset.go index c1e978b2e..b50487c16 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool_asset.go +++ b/osmosis-types/gamm/pool-models/balancer/pool_asset.go @@ -5,12 +5,12 @@ import ( "sort" "strings" - sdkioerrors "cosmossdk.io/errors" - "gopkg.in/yaml.v2" + sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/balancer/pool_params.go b/osmosis-types/gamm/pool-models/balancer/pool_params.go index 362f64bcd..d48559bfd 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool_params.go +++ b/osmosis-types/gamm/pool-models/balancer/pool_params.go @@ -4,6 +4,7 @@ import ( "errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/internal/cfmm_common/lp.go b/osmosis-types/gamm/pool-models/internal/cfmm_common/lp.go index fee52ed13..459c3a524 100644 --- a/osmosis-types/gamm/pool-models/internal/cfmm_common/lp.go +++ b/osmosis-types/gamm/pool-models/internal/cfmm_common/lp.go @@ -6,8 +6,8 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/osmoutils" ) diff --git a/osmosis-types/gamm/pool-models/internal/cfmm_common/lp_test.go b/osmosis-types/gamm/pool-models/internal/cfmm_common/lp_test.go index defea63e0..54f3a071e 100644 --- a/osmosis-types/gamm/pool-models/internal/cfmm_common/lp_test.go +++ b/osmosis-types/gamm/pool-models/internal/cfmm_common/lp_test.go @@ -6,12 +6,12 @@ import ( "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + gammtypes "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" - - sdk "github.com/cosmos/cosmos-sdk/types" ) // a helper function used to multiply coins diff --git a/osmosis-types/gamm/pool-models/stableswap/amm.go b/osmosis-types/gamm/pool-models/stableswap/amm.go index dcc942496..6c3cc86ae 100644 --- a/osmosis-types/gamm/pool-models/stableswap/amm.go +++ b/osmosis-types/gamm/pool-models/stableswap/amm.go @@ -4,6 +4,7 @@ import ( "errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" ) diff --git a/osmosis-types/gamm/pool-models/stableswap/codec.go b/osmosis-types/gamm/pool-models/stableswap/codec.go index 0ecabda4a..224969266 100644 --- a/osmosis-types/gamm/pool-models/stableswap/codec.go +++ b/osmosis-types/gamm/pool-models/stableswap/codec.go @@ -5,6 +5,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/stableswap/msgs.go b/osmosis-types/gamm/pool-models/stableswap/msgs.go index 55c84b66a..fee47698f 100644 --- a/osmosis-types/gamm/pool-models/stableswap/msgs.go +++ b/osmosis-types/gamm/pool-models/stableswap/msgs.go @@ -4,6 +4,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/gamm/pool-models/stableswap/pool.go b/osmosis-types/gamm/pool-models/stableswap/pool.go index fdb51d437..37498cc50 100644 --- a/osmosis-types/gamm/pool-models/stableswap/pool.go +++ b/osmosis-types/gamm/pool-models/stableswap/pool.go @@ -7,10 +7,9 @@ import ( "time" sdkioerrors "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" ) diff --git a/osmosis-types/gamm/pool-models/stableswap/pool_params.go b/osmosis-types/gamm/pool-models/stableswap/pool_params.go index 4880122b7..8972550af 100644 --- a/osmosis-types/gamm/pool-models/stableswap/pool_params.go +++ b/osmosis-types/gamm/pool-models/stableswap/pool_params.go @@ -2,6 +2,7 @@ package stableswap import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" ) diff --git a/osmosis-types/validation.go b/osmosis-types/validation.go index 39ab757f6..98ec28d33 100644 --- a/osmosis-types/validation.go +++ b/osmosis-types/validation.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + osmosislockuptypes "github.com/ingenuity-build/quicksilver/osmosis-types/lockup" participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) diff --git a/utils/proofs.go b/utils/proofs.go index 8c30cbbdb..e6dee5156 100644 --- a/utils/proofs.go +++ b/utils/proofs.go @@ -10,8 +10,9 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v5/modules/core/23-commitment/types" ibcKeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" - claimsmanagerkeeper "github.com/ingenuity-build/quicksilver/x/claimsmanager/keeper" "github.com/tendermint/tendermint/proto/tendermint/crypto" + + claimsmanagerkeeper "github.com/ingenuity-build/quicksilver/x/claimsmanager/keeper" ) type ProofOpsFn func(ctx sdk.Context, ibcKeeper *ibcKeeper.Keeper, connectionID string, chainID string, height int64, module string, key []byte, data []byte, proofOps *crypto.ProofOps) error diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 8444d93fb..f5257bb24 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -8,6 +8,7 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/ingenuity-build/quicksilver/wasmbinding/bindings" tokenfactorykeeper "github.com/ingenuity-build/quicksilver/x/tokenfactory/keeper" tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" diff --git a/wasmbinding/query_plugin.go b/wasmbinding/query_plugin.go index 8cbf02c15..352b4bce8 100644 --- a/wasmbinding/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -9,8 +9,9 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/wasmbinding/bindings" abci "github.com/tendermint/tendermint/abci/types" + + "github.com/ingenuity-build/quicksilver/wasmbinding/bindings" ) // StargateQuerier dispatches whitelisted stargate queries diff --git a/wasmbinding/test/custom_query_test.go b/wasmbinding/test/custom_query_test.go index 9cc81bb86..616a1e361 100644 --- a/wasmbinding/test/custom_query_test.go +++ b/wasmbinding/test/custom_query_test.go @@ -13,9 +13,10 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/stretchr/testify/require" + "github.com/ingenuity-build/quicksilver/app" "github.com/ingenuity-build/quicksilver/wasmbinding/bindings" - "github.com/stretchr/testify/require" ) // we must pay this many uosmo for every pool we create diff --git a/wasmbinding/test/store_run_test.go b/wasmbinding/test/store_run_test.go index 0d98e84dc..7b523a60f 100644 --- a/wasmbinding/test/store_run_test.go +++ b/wasmbinding/test/store_run_test.go @@ -5,15 +5,15 @@ import ( "os" "testing" - "github.com/ingenuity-build/quicksilver/app" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" - sdk "github.com/cosmos/cosmos-sdk/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + + "github.com/ingenuity-build/quicksilver/app" ) func TestNoStorageWithoutProposal(t *testing.T) { diff --git a/x/airdrop/keeper/keeper.go b/x/airdrop/keeper/keeper.go index a11f0b788..6fec28b16 100644 --- a/x/airdrop/keeper/keeper.go +++ b/x/airdrop/keeper/keeper.go @@ -6,11 +6,8 @@ import ( "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" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/tendermint/tendermint/libs/log" "github.com/ingenuity-build/quicksilver/utils" @@ -24,9 +21,9 @@ type Keeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey paramSpace paramtypes.Subspace - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper - stakingKeeper stakingkeeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + stakingKeeper types.StakingKeeper govKeeper govkeeper.Keeper icsKeeper icskeeper.Keeper icqKeeper icqkeeper.Keeper @@ -41,9 +38,9 @@ func NewKeeper( cdc codec.Codec, key storetypes.StoreKey, ps paramtypes.Subspace, - ak authkeeper.AccountKeeper, - bk bankkeeper.Keeper, - sk stakingkeeper.Keeper, + ak types.AccountKeeper, + bk types.BankKeeper, + sk types.StakingKeeper, gk govkeeper.Keeper, icsk icskeeper.Keeper, icqk icqkeeper.Keeper, diff --git a/x/airdrop/keeper/proposal_handler_test.go b/x/airdrop/keeper/proposal_handler_test.go index 629283c6c..02402e5fd 100644 --- a/x/airdrop/keeper/proposal_handler_test.go +++ b/x/airdrop/keeper/proposal_handler_test.go @@ -4,6 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/utils" "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" "github.com/ingenuity-build/quicksilver/x/airdrop/types" diff --git a/x/airdrop/types/expected_keepers.go b/x/airdrop/types/expected_keepers.go index 803c518ae..53b794f2e 100644 --- a/x/airdrop/types/expected_keepers.go +++ b/x/airdrop/types/expected_keepers.go @@ -1,11 +1,27 @@ package types // noalias +import ( + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + // AccountKeeper defines the contract required for account APIs. -type AccountKeeper interface{} +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress +} // BankKeeper defines the contract needed to be fulfilled for banking and supply // dependencies. -type BankKeeper interface{} +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error +} // StakingKeeper defines the contract for staking APIs. -type StakingKeeper interface{} +type StakingKeeper interface { + BondDenom(ctx sdk.Context) string + GetDelegatorBonded(ctx sdk.Context, delegator sdk.AccAddress) sdkmath.Int +} diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index 571cd41b3..bd5684ef1 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -3,9 +3,10 @@ package types import ( "testing" - cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" + + cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) func TestMsgClaim_ValidateBasic(t *testing.T) { diff --git a/x/claimsmanager/keeper/grpc_query_test.go b/x/claimsmanager/keeper/grpc_query_test.go index cbddae2b3..dc6929563 100644 --- a/x/claimsmanager/keeper/grpc_query_test.go +++ b/x/claimsmanager/keeper/grpc_query_test.go @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestKeeper_Queries() { Address: testAddress, }, k.UserLastEpochClaims, - 2, // 2 expected from chainB, 1 ommited as it was not archived + 2, // 2 expected from chainB, 1 omitted as it was not archived }, } diff --git a/x/claimsmanager/keeper/hooks.go b/x/claimsmanager/keeper/hooks.go index 9140048aa..3f0fd4835 100644 --- a/x/claimsmanager/keeper/hooks.go +++ b/x/claimsmanager/keeper/hooks.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" ) diff --git a/x/claimsmanager/keeper/keeper.go b/x/claimsmanager/keeper/keeper.go index 1d4c36c77..e3c652d17 100644 --- a/x/claimsmanager/keeper/keeper.go +++ b/x/claimsmanager/keeper/keeper.go @@ -11,8 +11,9 @@ import ( ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" - "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/tendermint/tendermint/libs/log" + + "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) type Keeper struct { diff --git a/x/claimsmanager/keeper/self_consensus_state.go b/x/claimsmanager/keeper/self_consensus_state.go index e5859db61..943a46f5f 100644 --- a/x/claimsmanager/keeper/self_consensus_state.go +++ b/x/claimsmanager/keeper/self_consensus_state.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) diff --git a/x/claimsmanager/types/claimsmanager.go b/x/claimsmanager/types/claimsmanager.go index bd35bf133..f4384ba74 100644 --- a/x/claimsmanager/types/claimsmanager.go +++ b/x/claimsmanager/types/claimsmanager.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/internal/multierror" ) diff --git a/x/claimsmanager/types/codec.go b/x/claimsmanager/types/codec.go index fa0cb8330..71a7be9c1 100644 --- a/x/claimsmanager/types/codec.go +++ b/x/claimsmanager/types/codec.go @@ -6,6 +6,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" ) diff --git a/x/epochs/handler.go b/x/epochs/handler.go index f6cebfc24..d1bbcb7b7 100644 --- a/x/epochs/handler.go +++ b/x/epochs/handler.go @@ -6,6 +6,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ingenuity-build/quicksilver/x/epochs/keeper" "github.com/ingenuity-build/quicksilver/x/epochs/types" ) diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index 8c2cf9464..67bbeb9b6 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/osmoutils" ) diff --git a/x/interchainquery/handler.go b/x/interchainquery/handler.go index 8ee7bf7be..0115dac46 100644 --- a/x/interchainquery/handler.go +++ b/x/interchainquery/handler.go @@ -6,6 +6,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" "github.com/ingenuity-build/quicksilver/x/interchainquery/types" ) diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index 524bbe1a8..5cc8099a0 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -16,10 +16,11 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/ingenuity-build/quicksilver/utils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - tmtypes "github.com/tendermint/tendermint/types" ) // ___________________________________________________________________________________________________ diff --git a/x/interchainstaking/keeper/callbacks_test.go b/x/interchainstaking/keeper/callbacks_test.go index 7316e1472..c5014946b 100644 --- a/x/interchainstaking/keeper/callbacks_test.go +++ b/x/interchainstaking/keeper/callbacks_test.go @@ -14,12 +14,13 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" + "github.com/ingenuity-build/quicksilver/app" "github.com/ingenuity-build/quicksilver/utils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - "github.com/stretchr/testify/require" ) func TestCoinFromRequestKey(t *testing.T) { diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index 93c5cae46..4430f851b 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -8,10 +8,11 @@ import ( cosmosmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" + "github.com/ingenuity-build/quicksilver/utils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - "github.com/stretchr/testify/require" ) func (suite *KeeperTestSuite) TestKeeper_DelegationStore() { diff --git a/x/interchainstaking/keeper/grpc_query_test.go b/x/interchainstaking/keeper/grpc_query_test.go index 75dfc1602..25b1e4755 100644 --- a/x/interchainstaking/keeper/grpc_query_test.go +++ b/x/interchainstaking/keeper/grpc_query_test.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/interchainstaking/keeper/hooks.go b/x/interchainstaking/keeper/hooks.go index 04d2f61df..7dcae829f 100644 --- a/x/interchainstaking/keeper/hooks.go +++ b/x/interchainstaking/keeper/hooks.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index ee045dc70..5eee175d9 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -18,11 +18,12 @@ import ( icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + "github.com/stretchr/testify/require" + "github.com/ingenuity-build/quicksilver/app" "github.com/ingenuity-build/quicksilver/utils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - "github.com/stretchr/testify/require" ) func TestHandleMsgTransferGood(t *testing.T) { @@ -1262,8 +1263,8 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { }) } } -func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { +func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { s.SetupTest() s.setupTestZones() @@ -1294,7 +1295,8 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { ValidatorAddress: vals[2].ValoperAddress, Amount: sdk.NewCoin("uatom", sdk.NewInt(1000)), RedelegationEnd: 0, - }, { + }, + { DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[3].ValoperAddress, Amount: sdk.NewCoin("uatom", sdk.NewInt(1000)), @@ -1314,7 +1316,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { err := app.InterchainstakingKeeper.Rebalance(ctx, zone, 1) s.Require().NoError(err) - //change intents to trigger redelegations from val[3] + // change intents to trigger redelegations from val[3] intents := icstypes.ValidatorIntents{ {ValoperAddress: vals[0].ValoperAddress, Weight: sdk.NewDecWithPrec(3, 1)}, {ValoperAddress: vals[1].ValoperAddress, Weight: sdk.NewDecWithPrec(3, 1)}, @@ -1329,10 +1331,12 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // mock ack for redelegations app.InterchainstakingKeeper.IteratePrefixedRedelegationRecords(ctx, []byte(zone.ChainId), func(idx int64, _ []byte, record icstypes.RedelegationRecord) (stop bool) { if record.EpochNumber == 2 { - msg := stakingtypes.MsgBeginRedelegate{zone.DelegationAddress.Address, + msg := stakingtypes.MsgBeginRedelegate{ + zone.DelegationAddress.Address, record.Source, record.Destination, - sdk.NewCoin("uatom", sdkmath.NewInt(record.Amount))} + sdk.NewCoin("uatom", sdkmath.NewInt(record.Amount)), + } err := app.InterchainstakingKeeper.HandleBeginRedelegate(ctx, &msg, time.Now().Add(time.Hour*24*7), fmt.Sprintf("rebalance/%d", 2)) if err != nil { return false @@ -1362,7 +1366,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // trigger rebalance err = app.InterchainstakingKeeper.Rebalance(ctx, zone, 3) - //check for redelegations originating from val[0], they should not be present + // check for redelegations originating from val[0], they should not be present _, present = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[0].ValoperAddress, vals[1].ValoperAddress, 3) s.Require().False(present) _, present = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[0].ValoperAddress, vals[2].ValoperAddress, 3) @@ -1372,7 +1376,6 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { } func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { - s.SetupTest() s.setupTestZones() @@ -1403,7 +1406,8 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { ValidatorAddress: vals[2].ValoperAddress, Amount: sdk.NewCoin("uatom", sdk.NewInt(1000)), RedelegationEnd: 0, - }, { + }, + { DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[3].ValoperAddress, Amount: sdk.NewCoin("uatom", sdk.NewInt(1000)), @@ -1475,7 +1479,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // trigger rebalance err = app.InterchainstakingKeeper.Rebalance(ctx, zone, 3) - //check for redelegations originating from val[1], they should not be present + // check for redelegations originating from val[1], they should not be present _, present = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[2].ValoperAddress, vals[0].ValoperAddress, 3) s.Require().False(present) _, present = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[2].ValoperAddress, vals[1].ValoperAddress, 3) diff --git a/x/interchainstaking/keeper/intent_test.go b/x/interchainstaking/keeper/intent_test.go index bdd9b81e8..6aec954d4 100644 --- a/x/interchainstaking/keeper/intent_test.go +++ b/x/interchainstaking/keeper/intent_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/utils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/interchainstaking/keeper/keeper.go b/x/interchainstaking/keeper/keeper.go index 73116b834..56b701745 100644 --- a/x/interchainstaking/keeper/keeper.go +++ b/x/interchainstaking/keeper/keeper.go @@ -15,8 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/types/tx" - authKeeper "github.com/cosmos/cosmos-sdk/x/auth/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" @@ -27,12 +25,13 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/tendermint/tendermint/libs/log" + config "github.com/ingenuity-build/quicksilver/cmd/config" "github.com/ingenuity-build/quicksilver/utils" claimsmanagerkeeper "github.com/ingenuity-build/quicksilver/x/claimsmanager/keeper" interchainquerykeeper "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - "github.com/tendermint/tendermint/libs/log" ) // Keeper of this module maintains collections of registered zones. @@ -42,8 +41,8 @@ type Keeper struct { scopedKeeper *capabilitykeeper.ScopedKeeper ICAControllerKeeper icacontrollerkeeper.Keeper ICQKeeper interchainquerykeeper.Keeper - AccountKeeper authKeeper.AccountKeeper - BankKeeper bankkeeper.Keeper + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper IBCKeeper ibckeeper.Keeper TransferKeeper ibctransferkeeper.Keeper ClaimsManagerKeeper claimsmanagerkeeper.Keeper @@ -52,7 +51,19 @@ type Keeper struct { // NewKeeper returns a new instance of zones Keeper. // This function will panic on failure. -func NewKeeper(cdc codec.Codec, storeKey storetypes.StoreKey, accountKeeper authKeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, icacontrollerkeeper icacontrollerkeeper.Keeper, scopedKeeper *capabilitykeeper.ScopedKeeper, icqKeeper interchainquerykeeper.Keeper, ibcKeeper ibckeeper.Keeper, transferKeeper ibctransferkeeper.Keeper, claimsManagerKeeper claimsmanagerkeeper.Keeper, ps paramtypes.Subspace) Keeper { +func NewKeeper( + cdc codec.Codec, + storeKey storetypes.StoreKey, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, + icacontrollerkeeper icacontrollerkeeper.Keeper, + scopedKeeper *capabilitykeeper.ScopedKeeper, + icqKeeper interchainquerykeeper.Keeper, + ibcKeeper ibckeeper.Keeper, + transferKeeper ibctransferkeeper.Keeper, + claimsManagerKeeper claimsmanagerkeeper.Keeper, + ps paramtypes.Subspace, +) Keeper { if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 6b4a73112..2a455ed54 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -18,6 +18,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v5/modules/core/24-host" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/ingenuity-build/quicksilver/app" "github.com/ingenuity-build/quicksilver/utils" ics "github.com/ingenuity-build/quicksilver/x/interchainstaking" diff --git a/x/interchainstaking/keeper/redelegation_record.go b/x/interchainstaking/keeper/redelegation_record.go index 2316b891d..406022cc4 100644 --- a/x/interchainstaking/keeper/redelegation_record.go +++ b/x/interchainstaking/keeper/redelegation_record.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/interchainstaking/keeper/redemptions.go b/x/interchainstaking/keeper/redemptions.go index 0b0813162..2a7471eef 100644 --- a/x/interchainstaking/keeper/redemptions.go +++ b/x/interchainstaking/keeper/redemptions.go @@ -9,9 +9,10 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + lsmstakingtypes "github.com/iqlusioninc/liquidity-staking-module/x/staking/types" + "github.com/ingenuity-build/quicksilver/utils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - lsmstakingtypes "github.com/iqlusioninc/liquidity-staking-module/x/staking/types" ) // processRedemptionForLsm will determine based on user intent, the tokens to return to the user, generate Redeem message and send them. diff --git a/x/interchainstaking/keeper/redemptions_test.go b/x/interchainstaking/keeper/redemptions_test.go index 01055dac1..929b1e90c 100644 --- a/x/interchainstaking/keeper/redemptions_test.go +++ b/x/interchainstaking/keeper/redemptions_test.go @@ -6,8 +6,9 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) func TestDetermineAllocationsForUndelegation(t *testing.T) { diff --git a/x/interchainstaking/keeper/zones.go b/x/interchainstaking/keeper/zones.go index 1444af63f..a55b00ade 100644 --- a/x/interchainstaking/keeper/zones.go +++ b/x/interchainstaking/keeper/zones.go @@ -14,6 +14,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/interchainstaking/types/expected_keepers.go b/x/interchainstaking/types/expected_keepers.go index e135f9b73..46e539abe 100644 --- a/x/interchainstaking/types/expected_keepers.go +++ b/x/interchainstaking/types/expected_keepers.go @@ -20,3 +20,20 @@ type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability IsBound(ctx sdk.Context, portID string) bool } + +// AccountKeeper defines the expected account keeper. +type AccountKeeper interface { + GetModuleAddress(moduleName string) sdk.AccAddress +} + +// BankKeeper defines the expected bank keeper. +type BankKeeper interface { + GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + GetSupply(ctx sdk.Context, denom string) sdk.Coin + HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool + MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error +} diff --git a/x/interchainstaking/types/msgs_test.go b/x/interchainstaking/types/msgs_test.go index 96e1b4c3a..eaf47bdb6 100644 --- a/x/interchainstaking/types/msgs_test.go +++ b/x/interchainstaking/types/msgs_test.go @@ -5,9 +5,10 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/ingenuity-build/quicksilver/utils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" - "github.com/stretchr/testify/require" ) func TestIntentsFromString(t *testing.T) { diff --git a/x/interchainstaking/types/zones_test.go b/x/interchainstaking/types/zones_test.go index cd384dec5..818c4d2d4 100644 --- a/x/interchainstaking/types/zones_test.go +++ b/x/interchainstaking/types/zones_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ingenuity-build/quicksilver/utils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index 4be56dd82..dd19634ac 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" sdk "github.com/cosmos/cosmos-sdk/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" icqkeeper "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" diff --git a/x/participationrewards/keeper/distribution_test.go b/x/participationrewards/keeper/distribution_test.go index 59d55fd4f..ab7e0cc39 100644 --- a/x/participationrewards/keeper/distribution_test.go +++ b/x/participationrewards/keeper/distribution_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) diff --git a/x/participationrewards/keeper/keeper.go b/x/participationrewards/keeper/keeper.go index a4d13e59d..b6ba5c70d 100644 --- a/x/participationrewards/keeper/keeper.go +++ b/x/participationrewards/keeper/keeper.go @@ -8,10 +8,9 @@ import ( "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" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/tendermint/tendermint/libs/log" + config "github.com/ingenuity-build/quicksilver/cmd/config" osmosistypes "github.com/ingenuity-build/quicksilver/osmosis-types" "github.com/ingenuity-build/quicksilver/utils" @@ -20,7 +19,6 @@ import ( icqkeeper "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" - "github.com/tendermint/tendermint/libs/log" ) // userAllocation is an internal keeper struct to track transient state for @@ -37,9 +35,9 @@ type Keeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey paramSpace paramtypes.Subspace - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper - stakingKeeper stakingkeeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + stakingKeeper types.StakingKeeper IcqKeeper icqkeeper.Keeper icsKeeper icskeeper.Keeper epochsKeeper epochskeeper.Keeper @@ -55,9 +53,9 @@ func NewKeeper( cdc codec.Codec, key storetypes.StoreKey, ps paramtypes.Subspace, - ak authkeeper.AccountKeeper, - bk bankkeeper.Keeper, - sk stakingkeeper.Keeper, + ak types.AccountKeeper, + bk types.BankKeeper, + sk types.StakingKeeper, icqk icqkeeper.Keeper, icsk icskeeper.Keeper, feeCollectorName string, diff --git a/x/participationrewards/types/codec.go b/x/participationrewards/types/codec.go index 811a7ffa5..06bbd1ab6 100644 --- a/x/participationrewards/types/codec.go +++ b/x/participationrewards/types/codec.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" diff --git a/x/participationrewards/types/msgs.go b/x/participationrewards/types/msgs.go index 5db71e1b5..3e51a4b96 100644 --- a/x/participationrewards/types/msgs.go +++ b/x/participationrewards/types/msgs.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/internal/multierror" diff --git a/x/participationrewards/types/msgs_test.go b/x/participationrewards/types/msgs_test.go index b35625f20..ddfbc25ff 100644 --- a/x/participationrewards/types/msgs_test.go +++ b/x/participationrewards/types/msgs_test.go @@ -6,10 +6,11 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/utils" - cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/stretchr/testify/require" crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + + "github.com/ingenuity-build/quicksilver/utils" + cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) func TestMsgSubmitClaim_ValidateBasic(t *testing.T) { diff --git a/x/participationrewards/types/participationrewards.go b/x/participationrewards/types/participationrewards.go index bd27ba0f7..5e4b1bf70 100644 --- a/x/participationrewards/types/participationrewards.go +++ b/x/participationrewards/types/participationrewards.go @@ -5,6 +5,7 @@ import ( fmt "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ingenuity-build/quicksilver/internal/multierror" ) diff --git a/x/participationrewards/types/proposals.go b/x/participationrewards/types/proposals.go index 45d66f75b..25e3a67c0 100644 --- a/x/participationrewards/types/proposals.go +++ b/x/participationrewards/types/proposals.go @@ -5,6 +5,7 @@ import ( "fmt" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/ingenuity-build/quicksilver/internal/multierror" ) diff --git a/x/tokenfactory/keeper/keeper.go b/x/tokenfactory/keeper/keeper.go index 891ed1ae3..ff0ea79c0 100644 --- a/x/tokenfactory/keeper/keeper.go +++ b/x/tokenfactory/keeper/keeper.go @@ -3,16 +3,15 @@ package keeper import ( "fmt" - "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/libs/log" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" ) type ( diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index f62d62da4..77506a460 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -7,14 +7,15 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/ingenuity-build/quicksilver/app" - cmdcfg "github.com/ingenuity-build/quicksilver/cmd/config" - "github.com/ingenuity-build/quicksilver/x/tokenfactory/keeper" - "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/crypto/ed25519" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/ingenuity-build/quicksilver/app" + cmdcfg "github.com/ingenuity-build/quicksilver/cmd/config" + "github.com/ingenuity-build/quicksilver/x/tokenfactory/keeper" + "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" ) var ( @@ -101,7 +102,7 @@ func (suite *KeeperTestSuite) SetupTest() { } suite.queryClient = types.NewQueryClient(suite.QueryHelper) - suite.msgServer = keeper.NewMsgServerImpl(*suite.App.TokenFactoryKeeper) + suite.msgServer = keeper.NewMsgServerImpl(suite.App.TokenFactoryKeeper) } func (suite *KeeperTestSuite) CreateDefaultDenom() { diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index 833655d49..6e66e9ab5 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" ) diff --git a/x/tokenfactory/types/denoms_test.go b/x/tokenfactory/types/denoms_test.go index cd67c383a..51171e7bf 100644 --- a/x/tokenfactory/types/denoms_test.go +++ b/x/tokenfactory/types/denoms_test.go @@ -4,9 +4,10 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + cmdcfg "github.com/ingenuity-build/quicksilver/cmd/config" "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" - "github.com/stretchr/testify/require" ) func TestDeconstructDenom(t *testing.T) {