From d4aa859b777b5d5883717c20b95cf2f631683d9c Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Sun, 9 Jun 2024 20:30:00 +0700 Subject: [PATCH] add ibcfee module --- app/app.go | 42 +++++++++++++++++++++++++++------- app/genesis.go | 3 +++ app/keepers/keepers.go | 2 ++ app/upgrades/v2_6/constants.go | 2 ++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index aa832bed9..e3b6b28cd 100644 --- a/app/app.go +++ b/app/app.go @@ -98,6 +98,9 @@ import ( icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" + ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" + ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -174,6 +177,7 @@ var ( ica.AppModuleBasic{}, oracle.AppModuleBasic{}, globalfee.AppModule{}, + ibcfee.AppModuleBasic{}, ) // module account permissions maccPerms = map[string][]string{ @@ -185,6 +189,7 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibcfeetypes.ModuleName: nil, } Upgrades = []upgrades.Upgrade{v2_6.Upgrade} @@ -286,6 +291,7 @@ func NewBandApp( group.StoreKey, oracletypes.StoreKey, globalfeetypes.StoreKey, + ibcfeetypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -476,18 +482,30 @@ func NewBandApp( ), ) + // IBC Fee Module keeper + app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, keys[ibcfeetypes.StoreKey], + app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, + ) + app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.IBCFeeKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) transferModule := transfer.NewAppModule(app.TransferKeeper) - transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) + + // create IBC module from bottom to top of stack + var transferStack porttypes.IBCModule + transferStack = transfer.NewIBCModule(app.TransferKeeper) + transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) app.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), - app.IBCKeeper.ChannelKeeper, + app.IBCFeeKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, @@ -497,7 +515,10 @@ func NewBandApp( app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter()) icaModule := ica.NewAppModule(nil, &app.ICAHostKeeper) - icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) + + var icaHostStack porttypes.IBCModule + icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper) + icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper) app.OracleKeeper = oraclekeeper.NewKeeper( appCodec, @@ -523,14 +544,15 @@ func NewBandApp( app.StakingKeeper, app.GetSubspace(oracletypes.ModuleName), ) - oracleIBCModule := oracle.NewIBCModule(app.OracleKeeper) + + var oracleStack porttypes.IBCModule = oracle.NewIBCModule(app.OracleKeeper) // Create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() ibcRouter. - AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). - AddRoute(ibctransfertypes.ModuleName, transferIBCModule). - AddRoute(oracletypes.ModuleName, oracleIBCModule) + AddRoute(icahosttypes.SubModuleName, icaHostStack). + AddRoute(ibctransfertypes.ModuleName, transferStack). + AddRoute(oracletypes.ModuleName, oracleStack) app.IBCKeeper.SetRouter(ibcRouter) @@ -615,6 +637,7 @@ func NewBandApp( icaModule, oracleModule, globalfee.NewAppModule(app.GlobalfeeKeeper), + ibcfee.NewAppModule(app.IBCFeeKeeper), ) // NOTE: Oracle module must occur before distr as it takes some fee to distribute to active oracle validators. @@ -637,6 +660,7 @@ func NewBandApp( ibctransfertypes.ModuleName, ibcexported.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, genutiltypes.ModuleName, authz.ModuleName, feegrant.ModuleName, @@ -655,6 +679,7 @@ func NewBandApp( ibctransfertypes.ModuleName, ibcexported.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -693,6 +718,7 @@ func NewBandApp( ibctransfertypes.ModuleName, ibcexported.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, diff --git a/app/genesis.go b/app/genesis.go index 64f6c02b7..4d6478d59 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -32,6 +32,8 @@ import ( icagenesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" + ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransafertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" @@ -105,6 +107,7 @@ func NewDefaultGenesisState() GenesisState { group.ModuleName: groupmodule.AppModuleBasic{}.DefaultGenesis(cdc), ibctransafertypes.ModuleName: ibctransfer.AppModuleBasic{}.DefaultGenesis(cdc), icatypes.ModuleName: cdc.MustMarshalJSON(icaGenesis), + ibcfeetypes.ModuleName: ibcfee.AppModuleBasic{}.DefaultGenesis(cdc), oracletypes.ModuleName: oracle.AppModuleBasic{}.DefaultGenesis(cdc), globalfeetypes.ModuleName: cdc.MustMarshalJSON(globalfeeGenesis), } diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index c4b74b829..c75f15fad 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -17,6 +17,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" @@ -40,6 +41,7 @@ type AppKeepers struct { ParamsKeeper paramskeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCKeeper *ibckeeper.Keeper + IBCFeeKeeper ibcfeekeeper.Keeper ICAHostKeeper icahostkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper TransferKeeper ibctransferkeeper.Keeper diff --git a/app/upgrades/v2_6/constants.go b/app/upgrades/v2_6/constants.go index 1e4de25e9..240518b50 100644 --- a/app/upgrades/v2_6/constants.go +++ b/app/upgrades/v2_6/constants.go @@ -13,6 +13,7 @@ import ( govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" "github.com/bandprotocol/chain/v2/app/upgrades" @@ -31,6 +32,7 @@ var Upgrade = upgrades.Upgrade{ globalfeetypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, + ibcfeetypes.ModuleName, }, }, }