diff --git a/CHANGELOG.md b/CHANGELOG.md index 486a0f2a45..9c1d3521b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +- [1963](https://github.com/umee-network/umee/pull/1963) feat: ICA Host integration. + ### Fixes - [1929](https://github.com/umee-network/umee/pull/1929) Leverage: `MaxWithdraw` now accounts for `MinCollateralLiquidity` diff --git a/app/app.go b/app/app.go index 211f7798da..78542bbaeb 100644 --- a/app/app.go +++ b/app/app.go @@ -94,6 +94,11 @@ import ( gravity "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity" gravitykeeper "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper" gravitytypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types" + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" @@ -173,6 +178,9 @@ func init() { nftmodule.AppModuleBasic{}, ibc.AppModuleBasic{}, ibctransfer.AppModuleBasic{}, + ica.AppModuleBasic{}, + // intertx.AppModuleBasic{}, + // ibcfee.AppModuleBasic{}, gravity.AppModuleBasic{}, leverage.AppModuleBasic{}, oracle.AppModuleBasic{}, @@ -196,6 +204,7 @@ func init() { nft.ModuleName: nil, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + icatypes.ModuleName: nil, gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, leveragetypes.ModuleName: {authtypes.Minter, authtypes.Burner}, oracletypes.ModuleName: nil, @@ -245,6 +254,7 @@ type UmeeApp struct { UIBCTransferKeeper uibctransferkeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + ICAHostKeeper icahostkeeper.Keeper GravityKeeper gravitykeeper.Keeper LeverageKeeper leveragekeeper.Keeper OracleKeeper oraclekeeper.Keeper @@ -309,7 +319,8 @@ func New( govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, - ibchost.StoreKey, ibctransfertypes.StoreKey, gravitytypes.StoreKey, + ibchost.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey, + gravitytypes.StoreKey, leveragetypes.StoreKey, oracletypes.StoreKey, bech32ibctypes.StoreKey, uibc.StoreKey, } @@ -359,6 +370,7 @@ func New( // grant capabilities for the ibc and ibc-transfer modules app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) app.initializeCustomScopedKeepers() @@ -497,6 +509,12 @@ func New( app.UpgradeKeeper, app.ScopedIBCKeeper, ) + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, // app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), + ) var ics4Wrapper ibcporttypes.ICS4Wrapper app.UIbcQuotaKeeper = uibcquotakeeper.NewKeeper( @@ -524,10 +542,10 @@ func New( app.UIBCTransferKeeper = uibctransferkeeper.New(ibcTransferKeeper, app.BankKeeper) // Create Transfer Stack - // SendPacket, since it is originating from the application to core IBC: + // SendPacket, originates from the application to an IBC channel: // transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket - // RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way + // RecvPacket, message that originates from an IBC channel and goes down to app, the flow is the other way // channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket // transfer stack contains (from top to bottom): @@ -541,8 +559,18 @@ func New( ibctransfer.NewIBCModule(ibcTransferKeeper), app.UIBCTransferKeeper, ) + // transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) transferStack = uibcquota.NewIBCMiddleware(transferStack, app.UIbcQuotaKeeper, appCodec) + // Create Interchain Accounts Stack + // SendPacket, since it is originating from the application to core IBC: + // icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket + + // RecvPacket, message that originates from core IBC and goes down to app, the flow is: + // channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket + var icaHostStack ibcporttypes.IBCModule = icahost.NewIBCModule(app.ICAHostKeeper) + // icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper) + /* Create fee enabled wasm ibc Stack var wasmStack ibcporttypes.IBCModule @@ -552,14 +580,14 @@ func New( // Create static IBC router, add app routes, then set and seal it ibcRouter := ibcporttypes.NewRouter(). - AddRoute(ibctransfertypes.ModuleName, transferStack) + AddRoute(ibctransfertypes.ModuleName, transferStack). + AddRoute(icahosttypes.SubModuleName, icaHostStack) /* // we will add cosmwasm IBC routing later AddRoute(wasm.ModuleName, wasmStack). // we don't integrate the controller now AddRoute(intertxtypes.ModuleName, icaControllerStack). AddRoute(icacontrollertypes.SubModuleName, icaControllerStack). - AddRoute(icahosttypes.SubModuleName, icaHostStack) */ app.IBCKeeper.SetRouter(ibcRouter) @@ -611,7 +639,9 @@ func New( // must be passed by reference here. appModules := []module.AppModule{ genutil.NewAppModule( - app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, + app.AccountKeeper, + app.StakingKeeper, + app.DeliverTx, encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, nil), @@ -636,6 +666,8 @@ func New( nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibctransfer.NewAppModule(ibcTransferKeeper), + // ibcfee.NewAppModule(app.IBCFeeKeeper), + ica.NewAppModule(nil, &app.ICAHostKeeper), gravity.NewAppModule(app.GravityKeeper, app.BankKeeper), leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper), oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper), @@ -665,7 +697,7 @@ func New( nft.ModuleName, group.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, - // icatypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, // ibcfeetypes.ModuleName, leveragetypes.ModuleName, oracletypes.ModuleName, gravitytypes.ModuleName, @@ -683,7 +715,7 @@ func New( genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - // icatypes.ModuleName, + icatypes.ModuleName, // ibcfeetypes.ModuleName, leveragetypes.ModuleName, gravitytypes.ModuleName, bech32ibctypes.ModuleName, @@ -700,7 +732,8 @@ func New( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, - authz.ModuleName, ibctransfertypes.ModuleName, // icatypes.ModuleName, + authz.ModuleName, + ibctransfertypes.ModuleName, icatypes.ModuleName, // ibcfeetypes.ModuleName feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, @@ -715,7 +748,7 @@ func New( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, - authz.ModuleName, ibctransfertypes.ModuleName, // icatypes.ModuleName, + authz.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, // ibcfeetypes.ModuleName feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, @@ -757,10 +790,12 @@ func New( simStateModules := genmap.Pick( app.mm.Modules, - []string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName}, + []string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName, + ibchost.ModuleName}, ) // TODO: Ensure x/leverage implements simulator and add it here: - simTestModules := genmap.Pick(simStateModules, []string{oracletypes.ModuleName}) + simTestModules := genmap.Pick(simStateModules, + []string{oracletypes.ModuleName, ibchost.ModuleName}) app.StateSimulationManager = module.NewSimulationManagerFromAppModules(simStateModules, overrideModules) app.sm = module.NewSimulationManagerFromAppModules(simTestModules, nil) @@ -1026,7 +1061,7 @@ func initParamsKeeper( paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) // paramsKeeper.Subspace(icacontrollertypes.SubModuleName) - // paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(gravitytypes.ModuleName) paramsKeeper.Subspace(leveragetypes.ModuleName) paramsKeeper.Subspace(oracletypes.ModuleName) diff --git a/app/upgrades.go b/app/upgrades.go index cb692164b2..5c890cf763 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -6,9 +6,19 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/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/group" "github.com/cosmos/cosmos-sdk/x/nft" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icagenesis "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/genesis/types" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types" "github.com/umee-network/umee/v4/app/upgradev3" @@ -40,9 +50,54 @@ func (app UmeeApp) RegisterUpgradeHandlers(bool) { } // performs upgrade from v4.2 to v4.3 -func (app *UmeeApp) registerUpgrade4_3(_ upgradetypes.Plan) { +func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) { const planName = "v4.3-beta" // TODO: change before the main release app.UpgradeKeeper.SetUpgradeHandler(planName, onlyModuleMigrations(app, planName)) + app.UpgradeKeeper.SetUpgradeHandler(planName, + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Upgrade handler execution", "name", planName) + + // set the ICS27 consensus version so InitGenesis is not run + oldIcaVersion := fromVM[icatypes.ModuleName] + fromVM[icatypes.ModuleName] = app.mm.Modules[icatypes.ModuleName].ConsensusVersion() + g := icagenesis.GenesisState{HostGenesisState: icagenesis.DefaultHostGenesis()} + g.HostGenesisState.Params.AllowMessages = []string{ + sdk.MsgTypeURL(&banktypes.MsgSend{}), + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}), + sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}), + sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), + sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}), + sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}), + sdk.MsgTypeURL(&govv1.MsgVote{}), + sdk.MsgTypeURL(&govv1beta1.MsgVote{}), + + sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}), + } + // initialize ICS27 module + icamodule, ok := app.mm.Modules[icatypes.ModuleName].(ica.AppModule) + if !ok { + panic("Modules[icatypes.ModuleName] is not of type ica.AppModule") + } + // skip InitModule in upgrade tests after the upgrade has gone through. + if oldIcaVersion != fromVM[icatypes.ModuleName] { + icamodule.InitModule(ctx, g.ControllerGenesisState.Params, g.HostGenesisState.Params) + } + + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + + app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{ + Added: []string{ + icahosttypes.StoreKey, + }, + }) + } // performs upgrade from v4.1 to v4.2 @@ -62,7 +117,6 @@ func (app *UmeeApp) registerUpgrade4_1(_ upgradetypes.Plan) { app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Upgrade handler execution", "name", planName) - ctx.Logger().Info("Run v4.1 migration") leverageUpgrader := leveragekeeper.NewMigrator(&app.LeverageKeeper) migrated, err := leverageUpgrader.MigrateBNB(ctx) if err != nil { @@ -193,9 +247,6 @@ func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) { group.ModuleName, nft.ModuleName, bech32ibctypes.ModuleName, - // icacontrollertypes.StoreKey, - // icahosttypes.StoreKey, - oracletypes.ModuleName, leveragetypes.ModuleName, },