Skip to content

Commit

Permalink
Merge pull request #392 from bandprotocol/add-ibcfee
Browse files Browse the repository at this point in the history
[feat] Add ibcfee module
  • Loading branch information
taobun committed Sep 2, 2024
2 parents 9c93d9b + d4aa859 commit 3a69eda
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
42 changes: 34 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -174,6 +177,7 @@ var (
ica.AppModuleBasic{},
oracle.AppModuleBasic{},
globalfee.AppModule{},
ibcfee.AppModuleBasic{},
)
// module account permissions
maccPerms = map[string][]string{
Expand All @@ -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}
Expand Down Expand Up @@ -286,6 +291,7 @@ func NewBandApp(
group.StoreKey,
oracletypes.StoreKey,
globalfeetypes.StoreKey,
ibcfeetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand All @@ -637,6 +660,7 @@ func NewBandApp(
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
Expand All @@ -655,6 +679,7 @@ func NewBandApp(
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -693,6 +718,7 @@ func NewBandApp(
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
Expand Down
3 changes: 3 additions & 0 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v2_6/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,6 +32,7 @@ var Upgrade = upgrades.Upgrade{
globalfeetypes.StoreKey,
consensusparamtypes.StoreKey,
crisistypes.StoreKey,
ibcfeetypes.ModuleName,
},
},
}
Expand Down

0 comments on commit 3a69eda

Please sign in to comment.