Skip to content

Commit

Permalink
feat: integrate ICA (#1963)
Browse files Browse the repository at this point in the history
* feat: integrate ICA

* fix module registration

* upgrades

* changelog
  • Loading branch information
robert-zaremba authored Mar 30, 2023
1 parent 073468e commit 89ee005
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
61 changes: 48 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -173,6 +178,9 @@ func init() {
nftmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ica.AppModuleBasic{},
// intertx.AppModuleBasic{},
// ibcfee.AppModuleBasic{},
gravity.AppModuleBasic{},
leverage.AppModuleBasic{},
oracle.AppModuleBasic{},
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,

Expand All @@ -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,

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
61 changes: 56 additions & 5 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 89ee005

Please sign in to comment.