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
2 changes: 1 addition & 1 deletion app/ante/handler_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (suite *AnteTestSuite) TestValidateHandlerOptions() {
SignModeHandler: encoding.MakeConfig().TxConfig.SignModeHandler(),
SigGasConsumer: evmosante.SigVerificationGasConsumer,
MaxTxGasWanted: 40000000,
TxFeeChecker: evmosanteevm.NewDynamicFeeChecker(suite.app.EvmKeeper),
TxFeeChecker: evmosanteevm.NewDynamicFeeChecker(suite.app.FeeMarketKeeper),
},
true,
},
Expand Down
2 changes: 1 addition & 1 deletion app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (suite *AnteTestSuite) BuildTestEthTx(
gasTipCap *big.Int,
accesses *ethtypes.AccessList,
) *evmtypes.MsgEthereumTx {
chainID := suite.app.EvmKeeper.ChainID()
chainID := evmtypes.GetEthChainConfig().ChainID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is static value. We can change to this:

	chainConfig, _ := suite.app.EvmKeeper.EVMConfig()
	
	nonce := suite.app.EvmKeeper.GetNonce(
		suite.ctx,
		common.BytesToAddress(from.Bytes()),
	)
	data := make([]byte, 0)
	gasLimit := uint64(100000)

	args := evmtypes.EvmTxArgs{
		Nonce:     nonce,
		GasLimit:  gasLimit,
		Input:     data,
		GasFeeCap: gasFeeCap,
		GasPrice:  gasPrice,
		ChainID:   chainConfig.ChainConfig.ChainID,
		GasTipCap: gasTipCap,
		Amount:    nil,
		To:        &to,
		Accesses:  accesses,
	}

nonce := suite.app.EvmKeeper.GetNonce(
suite.ctx,
common.BytesToAddress(from.Bytes()),
Expand Down
58 changes: 44 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
multistaking "github.com/realio-tech/multi-staking-module/x/multi-staking"
multistakingkeeper "github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
multistakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types"
realiotypes "github.com/realiotech/realio-network/types"

evmosante "github.com/evmos/os/ante"
evmosanteevm "github.com/evmos/os/ante/evm"
Expand Down Expand Up @@ -238,6 +239,23 @@ var (
_ ibctesting.TestingApp = (*RealioNetwork)(nil)
)

var sealed = false
// EvmosAppOptions allows to setup the global configuration
// for the Evmos chain.
func EvmosAppOptions(chainID string) error {
if sealed {
return nil
}
config := evmtypes.NewEVMConfigurator().
WithEVMCoinInfo(realiotypes.BaseDenom, 18).WithChainConfig(nil)
err := config.Configure()
if err != nil {
return err
}
sealed = true
return nil
}

func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand Down Expand Up @@ -291,7 +309,7 @@ type RealioNetwork struct {
// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
Erc20Keeper erc20keeper.Keeper
Erc20Keeper MockErc20Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -322,6 +340,7 @@ func New(
invCheckPeriod uint,
encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions,
evmosAppOptions func(string) error,
baseAppOptions ...func(*baseapp.BaseApp),
) *RealioNetwork {
appCodec := encodingConfig.Codec
Expand All @@ -334,6 +353,11 @@ func New(
bApp.SetTxEncoder(encodingConfig.TxConfig.TxEncoder())
bApp.SetInterfaceRegistry(interfaceRegistry)

// initialize the evmOS application configuration
if err := evmosAppOptions(bApp.ChainID()); err != nil {
panic(err)
}

keys := storetypes.NewKVStoreKeys(
// sdk keys
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
Expand Down Expand Up @@ -542,21 +566,27 @@ func New(

app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, &app.Erc20Keeper,
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, &app.Erc20Keeper.Keeper,
tracer, app.GetSubspace(evmtypes.ModuleName),
)

// Create Transfer Keepers
app.Erc20Keeper = erc20keeper.NewKeeper(
keys[erc20types.StoreKey],
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
app.Erc20Keeper = NewMockErc20Keeper(
erc20keeper.NewKeeper(
keys[erc20types.StoreKey],
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.EvmKeeper,
app.StakingKeeper,
app.AuthzKeeper,
&app.TransferKeeper,
),
app.BankKeeper,
app.EvmKeeper,
app.StakingKeeper,
app.AuthzKeeper,
&app.TransferKeeper,
app.BridgeKeeper,
)

// instantiate IBC transfer keeper AFTER the ERC-20 keeper to use it in the instantiation
Expand All @@ -565,7 +595,7 @@ func New(
nil, // we are passing no ics4 wrapper
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper,
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
app.Erc20Keeper.Keeper, // Add ERC20 Keeper for ERC20 transfers
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -575,7 +605,7 @@ func New(
var transferStack porttypes.IBCModule

transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = erc20.NewIBCMiddleware(app.Erc20Keeper, transferStack)
transferStack = erc20.NewIBCMiddleware(app.Erc20Keeper.Keeper, transferStack)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand All @@ -587,7 +617,7 @@ func New(
*app.StakingKeeper,
app.DistrKeeper,
app.BankKeeper,
app.Erc20Keeper,
app.Erc20Keeper.Keeper,
app.AuthzKeeper,
app.TransferKeeper,
app.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -635,7 +665,7 @@ func New(
// ethermint
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)),
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)),
erc20.NewAppModule(app.Erc20Keeper.Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)),

// realio network
assetmodule.NewAppModule(appCodec, app.AssetKeeper, app.BankKeeper, app.GetSubspace(assetmoduletypes.ModuleName)),
Expand Down Expand Up @@ -847,7 +877,7 @@ func New(
FeeMarketKeeper: app.FeeMarketKeeper,
MaxTxGasWanted: maxGasWanted,
ExtensionOptionChecker: ostypes.HasDynamicFeeExtensionOption,
TxFeeChecker: evmosanteevm.NewDynamicFeeChecker(app.EvmKeeper),
TxFeeChecker: evmosanteevm.NewDynamicFeeChecker(app.FeeMarketKeeper),
}

if err := options.Validate(); err != nil {
Expand Down
67 changes: 67 additions & 0 deletions app/mock_erc20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package app

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/ethereum/go-ethereum/common"
erc20keeper "github.com/evmos/os/x/erc20/keeper"
"github.com/evmos/os/x/evm/core/vm"
transferkeeper "github.com/evmos/os/x/ibc/transfer/keeper"
"github.com/realiotech/realio-network/precompiles/erc20"
bridgekeeper "github.com/realiotech/realio-network/x/bridge/keeper"
)

type MockErc20Keeper struct {
erc20keeper.Keeper
bridgeKeeper bridgekeeper.Keeper

bankKeeper bankkeeper.Keeper
authzKeeper authzkeeper.Keeper
transferKeeper *transferkeeper.Keeper
}

func NewMockErc20Keeper(
erc20k erc20keeper.Keeper,
bk bankkeeper.Keeper,
ak authzkeeper.Keeper,
tk *transferkeeper.Keeper,
bridgeKeeper bridgekeeper.Keeper,
) MockErc20Keeper {
return MockErc20Keeper{
Keeper: erc20k,
bankKeeper: bk,
authzKeeper: ak,
transferKeeper: tk,
bridgeKeeper: bridgeKeeper,
}
}

func (k MockErc20Keeper) GetERC20PrecompileInstance(ctx sdk.Context, addr common.Address) (contract vm.PrecompiledContract, found bool, err error) {
params := k.GetParams(ctx)

if !k.IsAvailableERC20Precompile(&params, addr) {
return nil, false, nil
}

address := addr.String()

// check if the precompile is an ERC20 contract
id := k.GetTokenPairID(ctx, address)
if len(id) == 0 {
return nil, false, fmt.Errorf("precompile id not found: %s", address)
}
pair, ok := k.GetTokenPair(ctx, id)
if !ok {
return nil, false, fmt.Errorf("token pair not found: %s", address)
}

precompile, err := erc20.NewPrecompile(pair, k.bankKeeper, k.authzKeeper, *k.transferKeeper, k.bridgeKeeper)
if err != nil {
return nil, false, err
}

return precompile, true, nil
}
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Setup(

db := dbm.NewMemDB()
opt := baseapp.SetChainID(types.MainnetChainID + "-1")
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encCdc, simtestutil.EmptyAppOptions{}, opt)
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encCdc, simtestutil.EmptyAppOptions{}, EvmosAppOptions, opt)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState(encCdc.Codec)
Expand Down Expand Up @@ -269,7 +269,7 @@ func NewDefaultGenesisState(cdc codec.JSONCodec) simapp.GenesisState {
func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
db := dbm.NewMemDB()
cfg := MakeEncodingConfig()
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, cfg, simtestutil.EmptyAppOptions{})
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, cfg, simtestutil.EmptyAppOptions{}, EvmosAppOptions)
return app, NewDefaultGenesisState(cfg.Codec)
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/realio-networkd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
tempDir := tempDir()
initAppOptions.Set(flags.FlagHome, tempDir)
// opt := baseapp.SetChainID(types.MainnetChainID)
tempApp := app.New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, tempDir, 5, app.MakeEncodingConfig(), initAppOptions)
tempApp := app.New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, tempDir, 5, app.MakeEncodingConfig(), initAppOptions, app.EvmosAppOptions)
encodingConfig := app.MakeEncodingConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand Down Expand Up @@ -163,7 +163,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
server.StatusCommand(),
queryCommand(),
txCommand(),
ethermintclient.KeyCommands(app.DefaultNodeHome),
ethermintclient.KeyCommands(app.DefaultNodeHome, true),
)

// add rosetta
Expand Down Expand Up @@ -321,6 +321,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
a.encCfg,
// this line is used by starport scaffolding # stargate/root/appArgument
appOpts,
app.EvmosAppOptions,
baseapp.SetChainID(chainID),
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
Expand Down Expand Up @@ -360,6 +361,7 @@ func (a appCreator) appExport(
a.encCfg,
// this line is used by starport scaffolding # stargate/root/exportArgument
appOpts,
app.EvmosAppOptions,
)

if err := anApp.LoadHeight(height); err != nil {
Expand All @@ -377,6 +379,7 @@ func (a appCreator) appExport(
a.encCfg,
// this line is used by starport scaffolding # stargate/root/noHeightExportArgument
appOpts,
app.EvmosAppOptions,
)
}

Expand Down
23 changes: 23 additions & 0 deletions draft_proposal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"messages": [
{
"@type": "/os.erc20.v1.MsgRegisterERC20",
"authority": "realio10d07y265gmmuvt4z0w9aw880jnsr700jnhh02f",
"erc20addresses": ["0x2F5FE4504bc6e4D1B29AE795DE19c839B61F6353"]
},
{
"@type": "/os.erc20.v1.MsgUpdateParams",
"authority": "realio10d07y265gmmuvt4z0w9aw880jnsr700jnhh02f",
"params": {
"enable_erc20": true,
"native_precompiles": [],
"dynamic_precompiles": ["0x2F5FE4504bc6e4D1B29AE795DE19c839B61F6353"]
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000000000000000000ario",
"title": "Test",
"summary": "Test",
"expedited": false
}
Loading
Loading