Skip to content

Commit

Permalink
feat: add ibc and ibc-transfer modules (#2145)
Browse files Browse the repository at this point in the history
* add IBC to app.go

* add ibc transfer

* docs

* add changelog

* change capoability order

* add module in setup handler
  • Loading branch information
lumtis authored May 10, 2024
1 parent df947d6 commit 7458093
Show file tree
Hide file tree
Showing 53 changed files with 2,334 additions and 25 deletions.
190 changes: 166 additions & 24 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
"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/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
Expand Down Expand Up @@ -79,7 +82,15 @@ import (
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"

"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"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
evmante "github.com/evmos/ethermint/app/ante"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
Expand Down Expand Up @@ -166,6 +177,8 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
)
return govProposalHandlers
}
Expand All @@ -175,14 +188,18 @@ var (
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
evm.AppModuleBasic{},
Expand All @@ -204,6 +221,7 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
Expand Down Expand Up @@ -250,18 +268,25 @@ type App struct {
// sdk keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
GroupKeeper groupkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

// scoped keepers
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

// evm keepers
EvmKeeper *evmkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
Expand All @@ -273,6 +298,8 @@ type App struct {
ObserverKeeper *observerkeeper.Keeper
FungibleKeeper fungiblekeeper.Keeper
EmissionsKeeper emissionskeeper.Keeper

transferModule transfer.AppModule
}

// New returns a reference to an initialized ZetaApp.
Expand All @@ -299,11 +326,19 @@ func New(
bApp.SetInterfaceRegistry(interfaceRegistry)

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey,
authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
group.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibcexported.StoreKey,
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
authzkeeper.StoreKey,
evmtypes.StoreKey,
feemarkettypes.StoreKey,
Expand All @@ -317,7 +352,7 @@ func New(
crisistypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
memKeys := sdk.NewMemoryStoreKeys()
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

app := &App{
BaseApp: bApp,
Expand All @@ -341,6 +376,16 @@ func New(
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authAddr)
bApp.SetParamStore(&app.ConsensusParamsKeeper)

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey],
)

scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)

// add keepers
// use custom Ethermint account for contracts
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand All @@ -354,27 +399,91 @@ func New(
logger.Info("bank keeper blocklist addresses", "addresses", app.BlockedAddrs())

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.BlockedAddrs(), authAddr,
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
app.BlockedAddrs(),
authAddr,
)

app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, authAddr,
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authAddr,
)

app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, authtypes.FeeCollectorName, authAddr,
appCodec,
keys[distrtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
authAddr,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, app.LegacyAmino(), keys[slashingtypes.StoreKey], app.StakingKeeper, authAddr,
appCodec,
app.LegacyAmino(),
keys[slashingtypes.StoreKey],
app.StakingKeeper,
authAddr,
)

app.CrisisKeeper = *crisiskeeper.NewKeeper(
appCodec, keys[crisistypes.StoreKey], invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, authAddr,
appCodec,
keys[crisistypes.StoreKey],
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
authAddr,
)

app.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
keys[upgradetypes.StoreKey],
appCodec,
homePath,
app.BaseApp,
authAddr,
)

// IBC keepers

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
)

app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authAddr)
ibcRouter := porttypes.NewRouter()

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,
)
app.transferModule = transfer.NewAppModule(app.TransferKeeper)

// create IBC module from bottom to top of stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)

// Add transfer stack to IBC Router
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)

// ZetaChain keepers

app.AuthorityKeeper = authoritykeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -404,7 +513,8 @@ func New(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.ObserverKeeper.Hooks()))
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.ObserverKeeper.Hooks()),
)

app.AuthzKeeper = authzkeeper.NewKeeper(
keys[authzkeeper.StoreKey],
Expand All @@ -429,17 +539,27 @@ func New(
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))
feeSs := app.GetSubspace(feemarkettypes.ModuleName)
app.FeeMarketKeeper = feemarketkeeper.NewKeeper(
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey],
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName),
keys[feemarkettypes.StoreKey],
tkeys[feemarkettypes.TransientKey],
feeSs,
app.ConsensusParamsKeeper,
)
evmSs := app.GetSubspace(evmtypes.ModuleName)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper,
&app.FeeMarketKeeper, nil, geth.NewEVM,
tracer, evmSs,
appCodec,
keys[evmtypes.StoreKey],
tkeys[evmtypes.TransientKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
&app.FeeMarketKeeper,
nil,
geth.NewEVM,
tracer,
evmSs,
app.ConsensusParamsKeeper,
)

Expand All @@ -466,10 +586,16 @@ func New(
app.AuthorityKeeper,
app.LightclientKeeper,
)
app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{
MaxExecutionPeriod: 2 * time.Hour, // Two hours.
MaxMetadataLen: 255,
})
app.GroupKeeper = groupkeeper.NewKeeper(
keys[group.StoreKey],
appCodec,
app.MsgServiceRouter(),
app.AccountKeeper,
group.Config{
MaxExecutionPeriod: 2 * time.Hour, // Two hours.
MaxMetadataLen: 255,
},
)

// register the proposal types
govRouter := govv1beta1.NewRouter()
Expand Down Expand Up @@ -505,6 +631,9 @@ func New(
app.FungibleKeeper.EVMHooks(),
))

// seal the IBC router
app.IBCKeeper.SetRouter(ibcRouter)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand All @@ -522,6 +651,7 @@ func New(
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
Expand All @@ -531,6 +661,9 @@ func New(
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
app.transferModule,
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry),
feemarket.NewAppModule(app.FeeMarketKeeper, feeSs),
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs),
Expand All @@ -547,8 +680,8 @@ func New(
// 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

app.mm.SetOrderBeginBlockers(
capabilitytypes.ModuleName,
upgradetypes.ModuleName,
evmtypes.ModuleName,
distrtypes.ModuleName,
Expand All @@ -563,6 +696,8 @@ func New(
paramstypes.ModuleName,
group.ModuleName,
vestingtypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
feemarkettypes.ModuleName,
crosschaintypes.ModuleName,
observertypes.ModuleName,
Expand All @@ -574,6 +709,7 @@ func New(
consensusparamtypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
capabilitytypes.ModuleName,
banktypes.ModuleName,
authtypes.ModuleName,
upgradetypes.ModuleName,
Expand All @@ -584,6 +720,8 @@ func New(
vestingtypes.ModuleName,
govtypes.ModuleName,
paramstypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
genutiltypes.ModuleName,
group.ModuleName,
crisistypes.ModuleName,
Expand Down Expand Up @@ -652,6 +790,9 @@ func New(
}
}

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper

return app
}

Expand Down Expand Up @@ -813,7 +954,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
//pkt := ibctransfertypes.ParamKeyTable().RegisterParamSet(&ibccoreclienttypes.Params{}).RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName)
paramsKeeper.Subspace(feemarkettypes.ModuleName)
paramsKeeper.Subspace(group.ModuleName)
Expand Down
Loading

0 comments on commit 7458093

Please sign in to comment.