Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ante/evm/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/cosmos/evm/testutil"
utiltx "github.com/cosmos/evm/testutil/tx"
evmtypes "github.com/cosmos/evm/x/vm/types"
ibctypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibctypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"

sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
Expand Down
15 changes: 5 additions & 10 deletions cmd/evmd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -13,10 +14,12 @@ import (
cmtcli "github.com/cometbft/cometbft/libs/cli"

dbm "github.com/cosmos/cosmos-db"

cosmosevmcmd "github.com/cosmos/evm/client"
evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring"
"github.com/cosmos/evm/evmd"
"github.com/cosmos/evm/evmd/testutil"
cosmosevmserver "github.com/cosmos/evm/server"
cosmosevmserverconfig "github.com/cosmos/evm/server/config"
srvflags "github.com/cosmos/evm/server/flags"
Expand Down Expand Up @@ -49,14 +52,6 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)

type emptyAppOptions struct{}

func (ao emptyAppOptions) Get(_ string) interface{} { return nil }

func NoOpEvmAppOptions(_ string) error {
return nil
}

// NewRootCmd creates a new root command for evmd. It is called once in the
// main function.
func NewRootCmd() *cobra.Command {
Expand All @@ -68,8 +63,8 @@ func NewRootCmd() *cobra.Command {
dbm.NewMemDB(),
nil,
true,
emptyAppOptions{},
NoOpEvmAppOptions,
simtestutil.EmptyAppOptions{},
testutil.NoOpEvmAppOptions,
)

encodingConfig := sdktestutil.TestEncodingConfig{
Expand Down
4 changes: 2 additions & 2 deletions contracts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion evmd/ante/cosmos_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
cosmosante "github.com/cosmos/evm/ante/cosmos"
evmante "github.com/cosmos/evm/ante/evm"
evmtypes "github.com/cosmos/evm/x/vm/types"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibcante "github.com/cosmos/ibc-go/v10/modules/core/ante"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand Down
2 changes: 1 addition & 1 deletion evmd/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ante

import (
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
Expand Down
119 changes: 55 additions & 64 deletions evmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"sort"

ibcapi "github.com/cosmos/ibc-go/v10/modules/core/api"
"github.com/spf13/cast"

// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
Expand All @@ -17,6 +18,19 @@ import (
abci "github.com/cometbft/cometbft/abci/types"

dbm "github.com/cosmos/cosmos-db"

"github.com/cosmos/gogoproto/proto"
ibctransfer "github.com/cosmos/ibc-go/v10/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v10/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v10/testing"

evmante "github.com/cosmos/evm/ante"
cosmosevmante "github.com/cosmos/evm/ante/evm"
evmosencoding "github.com/cosmos/evm/encoding"
Expand All @@ -27,30 +41,19 @@ import (
"github.com/cosmos/evm/x/erc20"
erc20keeper "github.com/cosmos/evm/x/erc20/keeper"
erc20types "github.com/cosmos/evm/x/erc20/types"
erc20v2 "github.com/cosmos/evm/x/erc20/v2"
"github.com/cosmos/evm/x/feemarket"
feemarketkeeper "github.com/cosmos/evm/x/feemarket/keeper"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"

// NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens
"github.com/cosmos/evm/x/ibc/transfer"
transferkeeper "github.com/cosmos/evm/x/ibc/transfer/keeper"
transferv2 "github.com/cosmos/evm/x/ibc/transfer/v2"
"github.com/cosmos/evm/x/vm"
corevm "github.com/cosmos/evm/x/vm/core/vm"
evmkeeper "github.com/cosmos/evm/x/vm/keeper"
evmtypes "github.com/cosmos/evm/x/vm/types"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -167,11 +170,10 @@ var (
var (
_ runtime.AppI = (*EVMD)(nil)
_ servertypes.Application = (*EVMD)(nil)
_ ibctesting.TestingApp = (*EVMD)(nil)
)

// EVMD extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type EVMD struct {
*baseapp.BaseApp

Expand All @@ -188,7 +190,6 @@ type EVMD struct {
// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand All @@ -202,10 +203,8 @@ type EVMD struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper

// IBC keepers
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
TransferKeeper transferkeeper.Keeper
scopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
TransferKeeper transferkeeper.Keeper

// Cosmos EVM keepers
FeeMarketKeeper feemarketkeeper.Keeper
Expand Down Expand Up @@ -287,17 +286,15 @@ func NewExampleApp(
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey,
upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, authzkeeper.StoreKey,
// ibc keys
ibcexported.StoreKey, ibctransfertypes.StoreKey,
// Cosmos EVM store keys
evmtypes.StoreKey, feemarkettypes.StoreKey, erc20types.StoreKey,
)

tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

// load state streaming if enabled
if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil {
Expand All @@ -318,7 +315,6 @@ func NewExampleApp(
interfaceRegistry: interfaceRegistry,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
}

app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand All @@ -335,15 +331,6 @@ func NewExampleApp(
)
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])

app.scopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]),
Expand Down Expand Up @@ -449,11 +436,9 @@ func NewExampleApp(
// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
runtime.NewKVStoreService(keys[ibcexported.StoreKey]),
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
app.scopedIBCKeeper,
authAddr,
)

Expand Down Expand Up @@ -523,17 +508,18 @@ func NewExampleApp(

// instantiate IBC transfer keeper AFTER the ERC-20 keeper to use it in the instantiation
app.TransferKeeper = transferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
nil, // we are passing no ics4 wrapper
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper,
appCodec,
runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]),
app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
app.AccountKeeper,
app.BankKeeper,
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
authAddr,
)

// Override the ICS20 app module
transferModule := transfer.NewAppModule(app.TransferKeeper)

/*
Create Transfer Stack

Expand All @@ -554,11 +540,26 @@ func NewExampleApp(
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = erc20.NewIBCMiddleware(app.Erc20Keeper, transferStack)

var transferStackV2 ibcapi.IBCModule
transferStackV2 = transferv2.NewIBCModule(app.TransferKeeper)
transferStackV2 = erc20v2.NewIBCMiddleware(transferStackV2, app.Erc20Keeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
ibcRouterV2 := ibcapi.NewRouter()
ibcRouterV2.AddRoute(ibctransfertypes.ModuleName, transferStackV2)

app.IBCKeeper.SetRouter(ibcRouter)
app.IBCKeeper.SetRouterV2(ibcRouterV2)

clientKeeper := app.IBCKeeper.ClientKeeper
storeProvider := app.IBCKeeper.ClientKeeper.GetStoreProvider()
tmLightClientModule := ibctm.NewLightClientModule(appCodec, storeProvider)
clientKeeper.AddRoute(ibctm.ModuleName, &tmLightClientModule)

// Override the ICS20 app module
transferModule := transfer.NewAppModule(app.TransferKeeper)

// NOTE: we are adding all available Cosmos EVM EVM extensions.
// Not all of them need to be enabled, which can be configured on a per-chain basis.
Expand Down Expand Up @@ -589,7 +590,6 @@ func NewExampleApp(
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
Expand All @@ -603,7 +603,7 @@ func NewExampleApp(
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
// IBC modules
ibc.NewAppModule(app.IBCKeeper),
ibctm.NewAppModule(),
ibctm.NewAppModule(tmLightClientModule),
transferModule,
// Cosmos EVM modules
vm.NewAppModule(app.EVMKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
Expand Down Expand Up @@ -643,7 +643,7 @@ func NewExampleApp(
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.ModuleManager.SetOrderBeginBlockers(
capabilitytypes.ModuleName, minttypes.ModuleName,
minttypes.ModuleName,

// IBC modules
ibcexported.ModuleName, ibctransfertypes.ModuleName,
Expand All @@ -664,7 +664,7 @@ func NewExampleApp(
// to get the full block gas used.
app.ModuleManager.SetOrderEndBlockers(
govtypes.ModuleName, stakingtypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName,

// Cosmos EVM EndBlockers
evmtypes.ModuleName, erc20types.ModuleName, feemarkettypes.ModuleName,
Expand All @@ -680,11 +680,8 @@ func NewExampleApp(
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
genesisModuleOrder := []string{
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName,
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
minttypes.ModuleName,
ibcexported.ModuleName,
Expand Down Expand Up @@ -741,7 +738,6 @@ func NewExampleApp(
// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))

Expand Down Expand Up @@ -914,6 +910,11 @@ func (app *EVMD) DefaultGenesis() map[string]json.RawMessage {
erc20GenState := NewErc20GenesisState()
genesis[erc20types.ModuleName] = app.appCodec.MustMarshalJSON(erc20GenState)

// This is for making tests easier, as we don't need to set gas prices.
// For example, without this, we must copy many util functions like SignAndDeliver to set gas prices to test IBC.
feeMarketState := NewFeeMarketGenesisState()
genesis[feemarkettypes.ModuleName] = app.appCodec.MustMarshalJSON(feeMarketState)

return genesis
}

Expand Down Expand Up @@ -1001,11 +1002,6 @@ func (app *EVMD) GetBaseApp() *baseapp.BaseApp {
return app.BaseApp
}

// GetStakingKeeper implements the TestingApp interface.
func (app *EVMD) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return app.StakingKeeper
}

// GetStakingKeeperSDK implements the TestingApp interface.
func (app *EVMD) GetStakingKeeperSDK() stakingkeeper.Keeper {
return *app.StakingKeeper
Expand All @@ -1016,11 +1012,6 @@ func (app *EVMD) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetScopedIBCKeeper implements the TestingApp interface.
func (app *EVMD) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.scopedIBCKeeper
}

// GetTxConfig implements the TestingApp interface.
func (app *EVMD) GetTxConfig() client.TxConfig {
return app.txConfig
Expand Down
Loading
Loading