Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(all): Add EVM, ERC-20, feemarket and precompiles from Evmos #37

Merged
merged 32 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
408300c
import evm feemarket and precompiles
MalteHerrmann Aug 13, 2024
d1bfb7c
add changelog entry
MalteHerrmann Aug 13, 2024
00b2252
more wip
MalteHerrmann Aug 13, 2024
2d1515c
add erc20 module and IBC middleware
MalteHerrmann Aug 13, 2024
56efcc9
regenerate protos
MalteHerrmann Aug 13, 2024
dc2e88f
untangle
MalteHerrmann Aug 13, 2024
b966b96
run go mod tidy
MalteHerrmann Aug 13, 2024
305393e
more wip
MalteHerrmann Aug 13, 2024
1b21e5b
Merge branch 'main' into add-modules
MalteHerrmann Aug 14, 2024
2faaaa1
wip
MalteHerrmann Aug 15, 2024
413d96c
fix all this s
MalteHerrmann Aug 16, 2024
ac682fd
address linters
MalteHerrmann Aug 16, 2024
79ac817
move some chain native stuff to testutils
MalteHerrmann Aug 16, 2024
b731356
fix extension options type url
MalteHerrmann Aug 16, 2024
81d3ef4
use empty default extensions as params
MalteHerrmann Aug 16, 2024
08b54b5
run go work sync
MalteHerrmann Aug 19, 2024
11aad01
rework default EVM genesis after removing default EVM params to be pa…
MalteHerrmann Aug 19, 2024
5e95113
fix error message and tests
MalteHerrmann Aug 19, 2024
013edbf
fix ante tests
MalteHerrmann Aug 19, 2024
774ac37
commit wip fixing tests
MalteHerrmann Aug 19, 2024
bd25c16
linters
MalteHerrmann Aug 19, 2024
ca5e49a
more evm tests fixed
MalteHerrmann Aug 20, 2024
196313c
add ibc module to example app
MalteHerrmann Aug 20, 2024
d8eafcf
use all available precompiles in example app
MalteHerrmann Aug 20, 2024
b99dfdc
fix more tests and add initial token pair to example application
MalteHerrmann Aug 20, 2024
50f5a5f
refactors to align genesis states with example chain and tests
MalteHerrmann Aug 20, 2024
7642c13
add default power reduction for 18 decimals and fixes / linters
MalteHerrmann Aug 21, 2024
c167e7e
fix tests
MalteHerrmann Aug 21, 2024
03c017d
avoid using hardcoded bech32 prefix in distribution precompile
MalteHerrmann Aug 21, 2024
6b6710e
address G115 int overflow linters
MalteHerrmann Aug 21, 2024
175c482
rename example app import alias
MalteHerrmann Aug 23, 2024
a3c4f48
add missing linters
MalteHerrmann Aug 23, 2024
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
8 changes: 2 additions & 6 deletions example_chain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,12 @@ func (app *ExampleChain) TxConfig() client.TxConfig {
func (a *ExampleChain) DefaultGenesis() map[string]json.RawMessage {
genesis := ModuleBasics.DefaultGenesis(a.appCodec)

// NOTE: for the example chain implementation we need to set the default EVM denomination
evmGenState := evmtypes.DefaultGenesisState()
evmGenState.Params.EvmDenom = ExampleChainDenom
evmGenState := NewEVMGenesisState()
genesis[evmtypes.ModuleName] = a.appCodec.MustMarshalJSON(evmGenState)

// NOTE: for the example chain implementation we are also adding a default token pair,
// which is the base denomination of the chain (i.e. the WEVMOS contract)
erc20GenState := erc20types.DefaultGenesisState()
erc20GenState.TokenPairs = ExampleTokenPairs
erc20GenState.Params.NativePrecompiles = append(erc20GenState.Params.NativePrecompiles, WEVMOSContractMainnet)
erc20GenState := NewErc20GenesisState()
genesis[erc20types.ModuleName] = a.appCodec.MustMarshalJSON(erc20GenState)

return genesis
Expand Down
34 changes: 30 additions & 4 deletions example_chain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"cosmossdk.io/simapp"
"github.com/evmos/os/encoding"
erc20types "github.com/evmos/os/x/erc20/types"
evmtypes "github.com/evmos/os/x/evm/types"
)

Expand All @@ -26,10 +27,35 @@ func NewDefaultGenesisState() simapp.GenesisState {

genesisState := ModuleBasics.DefaultGenesis(encCfg.Codec)

// define new chain-specific EVM genesis state with correct EVM denom
evmGenesis := evmtypes.DefaultGenesisState()
evmGenesis.Params.EvmDenom = ExampleChainDenom
genesisState[evmtypes.ModuleName] = encCfg.Codec.MustMarshalJSON(evmGenesis)
evmGenState := NewEVMGenesisState()
genesisState[evmtypes.ModuleName] = encCfg.Codec.MustMarshalJSON(evmGenState)

erc20GenState := NewErc20GenesisState()
genesisState[erc20types.ModuleName] = encCfg.Codec.MustMarshalJSON(erc20GenState)

return genesisState
}

// NewEVMGenesisState returns the default genesis state for the EVM module.
//
// NOTE: for the example chain implementation we need to set the default EVM denomination
// and enable ALL precompiles.
func NewEVMGenesisState() *evmtypes.GenesisState {
evmGenState := evmtypes.DefaultGenesisState()
evmGenState.Params.EvmDenom = ExampleChainDenom
evmGenState.Params.ActiveStaticPrecompiles = evmtypes.AvailableStaticPrecompiles

return evmGenState
}

// NewErc20GenesisState returns the default genesis state for the ERC20 module.
//
// NOTE: for the example chain implementation we are also adding a default token pair,
// which is the base denomination of the chain (i.e. the WEVMOS contract).
func NewErc20GenesisState() *erc20types.GenesisState {
erc20GenState := erc20types.DefaultGenesisState()
erc20GenState.TokenPairs = ExampleTokenPairs
erc20GenState.Params.NativePrecompiles = append(erc20GenState.Params.NativePrecompiles, WEVMOSContractMainnet)

return erc20GenState
}
MalteHerrmann marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion example_chain/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,6 @@ func SetupTestingApp(chainID string) func() (ibctesting.TestingApp, map[string]j
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(chainID),
)
return app, NewDefaultGenesisState()
return app, app.DefaultGenesis()
}
}
3 changes: 3 additions & 0 deletions example_chain/testutil/eth_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func EthSetupWithDB(isCheckTx bool, chainID string, patchGenesis func(*example_a
// NewTestGenesisState generate genesis state with single validator
//
// It is also setting up the EVM parameters to use sensible defaults.
//
// TODO: are these different genesis functions necessary or can they all be refactored into one?
// there's also other genesis state functions; some like app.DefaultGenesis() or others in test helpers only.
MalteHerrmann marked this conversation as resolved.
Show resolved Hide resolved
func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
Expand Down
2 changes: 1 addition & 1 deletion precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (s *PrecompileTestSuite) TestRun() {

precompiles, found, err := s.app.EVMKeeper.GetPrecompileInstance(s.ctx, contractAddr)
s.Require().NoError(err, "failed to instantiate precompile")
s.Require().True(found, "not found precompile")
s.Require().True(found, "precompile not found")
evm.WithPrecompiles(precompiles.Map, precompiles.Addresses)

// Run precompiled contract
Expand Down
10 changes: 5 additions & 5 deletions testutil/integration/os/network/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,16 @@ func setDefaultGovGenesisState(exampleApp *example_app.ExampleChain, genesisStat
}

func setDefaultErc20GenesisState(exampleApp *example_app.ExampleChain, genesisState simapp.GenesisState) simapp.GenesisState {
erc20Gen := erc20types.DefaultGenesisState()
// TODO: add test case to ensure that this is the same as the default genesis for the example app
erc20Gen := example_app.NewErc20GenesisState()

genesisState[erc20types.ModuleName] = exampleApp.AppCodec().MustMarshalJSON(erc20Gen)
return genesisState
}

func setDefaultEVMGenesisState(exampleApp *example_app.ExampleChain, genesisState simapp.GenesisState) simapp.GenesisState {
evmGen := evmtypes.DefaultGenesisState()

// Set the EVM denomination for the given chain
evmGen.Params.EvmDenom = testutil.ExampleAttoDenom
// TODO: add test case to ensure that this is the same as the default genesis for the example app
evmGen := example_app.NewEVMGenesisState()

genesisState[evmtypes.ModuleName] = exampleApp.AppCodec().MustMarshalJSON(evmGen)
return genesisState
Expand Down
33 changes: 16 additions & 17 deletions testutil/integration/os/utils/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package utils
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
example_app "github.com/evmos/os/example_chain"
"github.com/evmos/os/testutil"
testkeyring "github.com/evmos/os/testutil/integration/os/keyring"
"github.com/evmos/os/testutil/integration/os/network"
erc20types "github.com/evmos/os/x/erc20/types"
evmtypes "github.com/evmos/os/x/evm/types"
)

const (
Expand Down Expand Up @@ -44,26 +44,25 @@ func CreateGenesisWithTokenPairs(keyring testkeyring.Keyring) network.CustomGene
}

// Add token pairs to genesis
erc20GenesisState := erc20types.DefaultGenesisState()
erc20GenesisState.TokenPairs = []erc20types.TokenPair{{
Erc20Address: erc20TokenPairHex,
Denom: "xmpl",
Enabled: true,
ContractOwner: erc20types.OWNER_MODULE, // NOTE: Owner is the module account since it's a native token and was registered through governance
}, {
Erc20Address: testutil.WEVMOSContractTestnet,
Denom: testutil.ExampleAttoDenom,
Enabled: true,
ContractOwner: erc20types.OWNER_MODULE, // NOTE: Owner is the module account since it's a native token and was registered through governance
}}

// Add the smart contracts to the EVM genesis
evmGenesisState := evmtypes.DefaultGenesisState()
erc20GenesisState := example_app.NewErc20GenesisState()
erc20GenesisState.TokenPairs = append(erc20GenesisState.TokenPairs,
erc20types.TokenPair{
Erc20Address: erc20TokenPairHex,
Denom: "xmpl",
Enabled: true,
ContractOwner: erc20types.OWNER_MODULE, // NOTE: Owner is the module account since it's a native token and was registered through governance
},
erc20types.TokenPair{
Erc20Address: testutil.WEVMOSContractTestnet,
Denom: testutil.ExampleAttoDenom,
Enabled: true,
ContractOwner: erc20types.OWNER_MODULE, // NOTE: Owner is the module account since it's a native token and was registered through governance
},
)

// Combine module genesis states
return network.CustomGenesisState{
authtypes.ModuleName: accGenesisState,
erc20types.ModuleName: erc20GenesisState,
evmtypes.ModuleName: evmGenesisState,
}
}
Loading