diff --git a/Makefile b/Makefile index aa2c7046..33f261fe 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ print-machine-info: BUILD_DIR := build# build files BIN_DIR := $(BUILD_DIR)/bin# for binary dev dependencies BUILD_CACHE_DIR := $(BUILD_DIR)/.cache# caching for non-artifact outputs -OUT_DIR := out# for artifact intermediates and outputs +OUT_DIR := ./.build# for artifact intermediates and outputs ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))# absolute path to root export PATH := $(ROOT_DIR)/$(BIN_DIR):$(PATH)# add local bin first in path diff --git a/app/_simulate_tx_test.go b/app/_simulate_tx_test.go index b914bb66..c1ae1cee 100644 --- a/app/_simulate_tx_test.go +++ b/app/_simulate_tx_test.go @@ -8,7 +8,6 @@ import ( "net/http/httptest" "testing" - sdkmath "cosmossdk.io/math" "github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/chaincfg" @@ -63,11 +62,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() { bank.MsgSend{ FromAddress: fromAddr, ToAddress: toAddr, - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e6)), }, }, Fee: auth.StdFee{ - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(5e4))), + Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(5e4)), Gas: 1e6, }, Memo: "test memo", diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 17c56489..f4da8b3d 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -69,7 +69,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) { chainID, app.NewFundedGenStateWithSameCoins( tApp.AppCodec(), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)), testAddresses, ), newBep3GenStateMulti(tApp.AppCodec(), deputy), @@ -117,7 +117,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) { banktypes.NewMsgSend( tc.address, testAddresses[0], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1_000_000)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1_000_000)), ), }, sdk.NewCoins(), // no fee diff --git a/app/ante/authorized_test.go b/app/ante/authorized_test.go index e2c4cdf2..efe79007 100644 --- a/app/ante/authorized_test.go +++ b/app/ante/authorized_test.go @@ -12,6 +12,7 @@ import ( "github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app/ante" + "github.com/0glabs/0g-chain/chaincfg" ) var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle @@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) { banktypes.NewMsgSend( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100_000_000)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100_000_000)), ), }, sdk.NewCoins(), // no fee @@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) { banktypes.NewMsgSend( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), ), banktypes.NewMsgSend( testAddresses[2], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), ), }, sdk.NewCoins(), // no fee @@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) { banktypes.NewMsgSend( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), ), }, sdk.NewCoins(), // no fee diff --git a/app/ante/authz_test.go b/app/ante/authz_test.go index 40f6812c..d0808329 100644 --- a/app/ante/authz_test.go +++ b/app/ante/authz_test.go @@ -16,6 +16,7 @@ import ( "github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app/ante" + "github.com/0glabs/0g-chain/chaincfg" ) func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant { @@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { banktypes.NewMsgSend( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)), ), }, checkTx: false, @@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { []sdk.Msg{banktypes.NewMsgSend( testAddresses[0], testAddresses[3], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)), )}), }, checkTx: false, @@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { banktypes.NewMsgSend( testAddresses[0], testAddresses[3], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)), ), &evmtypes.MsgEthereumTx{}, }, diff --git a/app/ante/eip712_test.go b/app/ante/eip712_test.go index 293ad447..37330093 100644 --- a/app/ante/eip712_test.go +++ b/app/ante/eip712_test.go @@ -34,6 +34,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper" evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil" evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types" @@ -155,7 +156,7 @@ func (suite *EIP712TestSuite) SetupTest() { // Genesis states evmGs := evmtypes.NewGenesisState( evmtypes.NewParams( - "neuron", // evmDenom + chaincfg.EvmDenom, // evmDenom false, // allowedUnprotectedTxs true, // enableCreate true, // enableCall @@ -264,10 +265,10 @@ func (suite *EIP712TestSuite) SetupTest() { pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState), } - // funds our test accounts with some ua0gi + // funds our test accounts with some gas denom coinsGenState := app.NewFundedGenStateWithSameCoins( tApp.AppCodec(), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)), []sdk.AccAddress{suite.testAddr, suite.testAddr2}, ) @@ -354,17 +355,17 @@ func (suite *EIP712TestSuite) SetupTest() { params := evmKeeper.GetParams(suite.ctx) params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{ { - MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin", + MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertERC20ToCoin", MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin", ValueTypes: []evmtypes.EIP712MsgAttrType{ {Name: "initiator", Type: "string"}, {Name: "receiver", Type: "string"}, - {Name: "0gchain_erc20_address", Type: "string"}, + {Name: "zgchain_erc20_address", Type: "string"}, {Name: "amount", Type: "string"}, }, }, // { - // MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgCreateCDP", + // MsgTypeUrl: "/zgc.cdp.v1beta1.MsgCreateCDP", // MsgValueTypeName: "MsgValueCDPCreate", // ValueTypes: []evmtypes.EIP712MsgAttrType{ // {Name: "sender", Type: "string"}, @@ -374,7 +375,7 @@ func (suite *EIP712TestSuite) SetupTest() { // }, // }, // { - // MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgDeposit", + // MsgTypeUrl: "/zgc.cdp.v1beta1.MsgDeposit", // MsgValueTypeName: "MsgValueCDPDeposit", // ValueTypes: []evmtypes.EIP712MsgAttrType{ // {Name: "depositor", Type: "string"}, @@ -384,7 +385,7 @@ func (suite *EIP712TestSuite) SetupTest() { // }, // }, // { - // MsgTypeUrl: "/0g-chain.hard.v1beta1.MsgDeposit", + // MsgTypeUrl: "/zgc.hard.v1beta1.MsgDeposit", // MsgValueTypeName: "MsgValueHardDeposit", // ValueTypes: []evmtypes.EIP712MsgAttrType{ // {Name: "depositor", Type: "string"}, @@ -392,7 +393,7 @@ func (suite *EIP712TestSuite) SetupTest() { // }, // }, { - MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20", + MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertCoinToERC20", MsgValueTypeName: "MsgValueEVMConvertCoinToERC20", ValueTypes: []evmtypes.EIP712MsgAttrType{ {Name: "initiator", Type: "string"}, @@ -401,7 +402,7 @@ func (suite *EIP712TestSuite) SetupTest() { }, }, // { - // MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgRepayDebt", + // MsgTypeUrl: "/zgc.cdp.v1beta1.MsgRepayDebt", // MsgValueTypeName: "MsgValueCDPRepayDebt", // ValueTypes: []evmtypes.EIP712MsgAttrType{ // {Name: "sender", Type: "string"}, @@ -410,7 +411,7 @@ func (suite *EIP712TestSuite) SetupTest() { // }, // }, // { - // MsgTypeUrl: "/0g-chain.hard.v1beta1.MsgWithdraw", + // MsgTypeUrl: "/zgc.hard.v1beta1.MsgWithdraw", // MsgValueTypeName: "MsgValueHardWithdraw", // ValueTypes: []evmtypes.EIP712MsgAttrType{ // {Name: "depositor", Type: "string"}, @@ -462,7 +463,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context) suite.tApp.FundModuleAccount( suite.ctx, evmutiltypes.ModuleName, - sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(0)), ) contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18)) @@ -559,7 +560,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() { errMsg: "insufficient funds", updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { bk := suite.tApp.GetBankKeeper() - gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ua0gi") + gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.GasDenom) suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins)) return txBuilder }, @@ -571,7 +572,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() { failCheckTx: true, errMsg: "invalid chain-id", updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { - gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20))) + gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20)) return suite.createTestEIP712CosmosTxBuilder( suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, ) @@ -584,7 +585,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() { failCheckTx: true, errMsg: "invalid pubkey", updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { - gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20))) + gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20)) return suite.createTestEIP712CosmosTxBuilder( suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, ) @@ -624,7 +625,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() { msgs = tc.updateMsgs(msgs) } - gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20))) + gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20)) txBuilder := suite.createTestEIP712CosmosTxBuilder( suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, ) @@ -710,7 +711,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() { } // deliver deposit msg - gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20))) + gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20)) txBuilder := suite.createTestEIP712CosmosTxBuilder( suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs, ) diff --git a/app/ante/min_gas_filter_test.go b/app/ante/min_gas_filter_test.go index 813c01ba..4fda631e 100644 --- a/app/ante/min_gas_filter_test.go +++ b/app/ante/min_gas_filter_test.go @@ -13,6 +13,7 @@ import ( "github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app/ante" + "github.com/0glabs/0g-chain/chaincfg" ) func mustParseDecCoins(value string) sdk.DecCoins { @@ -30,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) { ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()}) tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{ - EvmDenom: "neuron", + EvmDenom: chaincfg.EvmDenom, }) testCases := []struct { diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index fc2d1bed..7e3e72df 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -14,6 +14,7 @@ import ( "github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app/ante" + "github.com/0glabs/0g-chain/chaincfg" ) func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) { @@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing "MsgCreateVestingAccount", vesting.NewMsgCreateVestingAccount( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), false, ), @@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing "MsgCreateVestingAccount", vesting.NewMsgCreatePermanentLockedAccount( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), ), true, "MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported", @@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing "other messages not affected", banktypes.NewMsgSend( testAddresses[0], testAddresses[1], - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)), ), false, "", diff --git a/app/test_common.go b/app/test_common.go index 4b968eec..14622469 100644 --- a/app/test_common.go +++ b/app/test_common.go @@ -169,7 +169,7 @@ func GenesisStateWithSingleValidator( balances := []banktypes.Balance{ { Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(100000000000000))), + Coins: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100000000000000)), }, } @@ -232,7 +232,7 @@ func genesisStateWithValSet( } // set validators and delegations currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState) - currentStakingGenesis.Params.BondDenom = "ua0gi" + currentStakingGenesis.Params.BondDenom = chaincfg.GasDenom // TODO: stakingGenesis := stakingtypes.NewGenesisState( currentStakingGenesis.Params, @@ -252,13 +252,13 @@ func genesisStateWithValSet( for range delegations { // add delegated tokens to total supply - totalSupply = totalSupply.Add(sdk.NewCoin("ua0gi", bondAmt)) + totalSupply = totalSupply.Add(chaincfg.MakeCoinForGasDenom(bondAmt)) } // add bonded amount to bonded pool module account balances = append(balances, banktypes.Balance{ Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(), - Coins: sdk.Coins{sdk.NewCoin("ua0gi", bondAmt)}, + Coins: sdk.Coins{chaincfg.MakeCoinForGasDenom(bondAmt)}, }) bankGenesis := banktypes.NewGenesisState( diff --git a/chaincfg/coin_helper.go b/chaincfg/coin_helper.go new file mode 100644 index 00000000..fb525197 --- /dev/null +++ b/chaincfg/coin_helper.go @@ -0,0 +1,57 @@ +package chaincfg + +import ( + "fmt" + "math/big" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/shopspring/decimal" +) + +func toBigInt(amount any) *big.Int { + if amount == nil { + return big.NewInt(0) + } + var val *big.Int + switch amount.(type) { + case int: + val = big.NewInt(int64(amount.(int))) + case int32: + val = big.NewInt(int64(amount.(int32))) + case int64: + val = big.NewInt(amount.(int64)) + case string: + var ok bool + val, ok = new(big.Int).SetString(amount.(string), 0) + if !ok { + panic(fmt.Sprintf("invalid amount string: %s", amount.(string))) + } + case math.Int: + val = amount.(math.Int).BigInt() + case *big.Int: + val = amount.(*big.Int) + case float64: + val = decimal.NewFromFloat(amount.(float64)).BigInt() + default: + panic(fmt.Sprintf("invalid amount type: %T", amount)) + } + + return val +} + +func MakeCoinForStandardDenom(amount any) sdk.Coin { + return makeCoin(StandardDenom, toBigInt(amount)) +} + +func MakeCoinForGasDenom(amount any) sdk.Coin { + return makeCoin(GasDenom, toBigInt(amount)) +} + +func MakeCoinForEvmDenom(amount any) sdk.Coin { + return makeCoin(EvmDenom, toBigInt(amount)) +} + +func makeCoin(denom string, amount *big.Int) sdk.Coin { + return sdk.NewCoin(denom, math.NewIntFromBigInt(amount)) +} diff --git a/chaincfg/denoms.go b/chaincfg/denoms.go new file mode 100644 index 00000000..6d251643 --- /dev/null +++ b/chaincfg/denoms.go @@ -0,0 +1,37 @@ +package chaincfg + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + StandardDenom = "a0gi" + + GasDenom = "ua0gi" + + EvmDenom = "neuron" + + BondDenom = EvmDenom + + GasDenomUnit = 6 + + EvmDenomUnit = 18 + + GasDenomConversionMultiplier = 1e12 + EvmDenomConversionMultiplier = 1e18 +) + +// RegisterDenoms registers the base and gas denominations to the SDK. +func RegisterDenoms() { + if err := sdk.RegisterDenom(StandardDenom, sdk.OneDec()); err != nil { + panic(err) + } + + if err := sdk.RegisterDenom(GasDenom, sdk.NewDecWithPrec(1, GasDenomUnit)); err != nil { + panic(err) + } + + if err := sdk.RegisterDenom(EvmDenom, sdk.NewDecWithPrec(1, EvmDenomUnit)); err != nil { + panic(err) + } +} diff --git a/chaincfg/denoms_test.go b/chaincfg/denoms_test.go new file mode 100644 index 00000000..9cbaa09f --- /dev/null +++ b/chaincfg/denoms_test.go @@ -0,0 +1,80 @@ +package chaincfg + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" +) + +func TestRegisterDenoms(t *testing.T) { + RegisterDenoms() + tests := []struct { + name string + from sdk.Coin + targetDenom string + expCoin sdk.Coin + expErr error + }{ + { + "standard to gas", + MakeCoinForStandardDenom(99), + GasDenom, + MakeCoinForGasDenom(99 * (EvmDenomConversionMultiplier / GasDenomConversionMultiplier)), + nil, + }, + { + "gas to standard", + MakeCoinForGasDenom(5e7), + StandardDenom, + MakeCoinForStandardDenom(50), + nil, + }, + { + "standard to base", + MakeCoinForStandardDenom(22), + EvmDenom, + MakeCoinForEvmDenom(22 * EvmDenomConversionMultiplier), + nil, + }, + { + "base to standard", + MakeCoinForEvmDenom("97000000000000000000"), + StandardDenom, + MakeCoinForStandardDenom(97), + nil, + }, + { + "gas to base", + MakeCoinForGasDenom(33), + EvmDenom, + MakeCoinForEvmDenom(33 * GasDenomConversionMultiplier), + nil, + }, + { + "base to gas", + MakeCoinForEvmDenom("770000000000000"), + GasDenom, + MakeCoinForGasDenom(770000000000000 / GasDenomConversionMultiplier), + nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ret, err := sdk.ConvertCoin(tt.from, tt.targetDenom) + if tt.expErr != nil { + if err == nil { + t.Errorf("expErr is not nil, but got nil") + return + } + } else { + if err != nil { + t.Errorf("expErr is nil, but got %v", err) + return + } + } + + assert.Equal(t, tt.expCoin, ret) + }) + } +} diff --git a/cmd/0gchaind/root.go b/cmd/0gchaind/root.go index c327c774..07e589fe 100644 --- a/cmd/0gchaind/root.go +++ b/cmd/0gchaind/root.go @@ -75,7 +75,7 @@ func NewRootCmd() *cobra.Command { return err } - customAppTemplate, customAppConfig := servercfg.AppConfig("ua0gi") + customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.GasDenom) return server.InterceptConfigsPreRunHandler( cmd, @@ -131,7 +131,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de ac.addStartCmdFlags, ) - // add keybase, auxiliary RPC, query, and tx child commands + // add keybase, gas RPC, query, and tx child commands rootCmd.AddCommand( newQueryCmd(), newTxCmd(), diff --git a/go.mod b/go.mod index 6194db03..dc1f1249 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/linxGnu/grocksdb v1.8.6 github.com/pelletier/go-toml/v2 v2.0.8 github.com/prometheus/client_golang v1.14.0 + github.com/shopspring/decimal v1.4.0 github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 diff --git a/go.sum b/go.sum index 5d1ece15..6b6d4bcf 100644 --- a/go.sum +++ b/go.sum @@ -1158,6 +1158,8 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= diff --git a/localtestnet.sh b/localtestnet.sh index bde45c2c..33846044 100755 --- a/localtestnet.sh +++ b/localtestnet.sh @@ -24,7 +24,7 @@ DATA=~/.0gchain # remove any old state and config rm -rf $DATA -BINARY=0gchaind +BINARY=./.build/0gchaind # Create new data directory, overwriting any that alread existed chainID="zgchain_8888-1" @@ -48,12 +48,12 @@ $BINARY config keyring-backend test # Create validator keys and add account to genesis validatorKeyName="validator" -printf "$validatorMnemonic\n" | $BINARY keys add $validatorKeyName --recover +printf "$validatorMnemonic\n" | $BINARY keys add $validatorKeyName --eth --recover $BINARY add-genesis-account $validatorKeyName 2000000000000000000000ua0gi # Create faucet keys and add account to genesis faucetKeyName="faucet" -printf "$faucetMnemonic\n" | $BINARY keys add $faucetKeyName --recover +printf "$faucetMnemonic\n" | $BINARY keys add $faucetKeyName --eth --recover $BINARY add-genesis-account $faucetKeyName 1000000000000000000000ua0gi evmFaucetKeyName="evm-faucet" diff --git a/migrate/utils/periodic_vesting_reset_test.go b/migrate/utils/periodic_vesting_reset_test.go index e0a8ed28..5424eb93 100644 --- a/migrate/utils/periodic_vesting_reset_test.go +++ b/migrate/utils/periodic_vesting_reset_test.go @@ -5,6 +5,7 @@ import ( "time" sdkmath "cosmossdk.io/math" + "github.com/0glabs/0g-chain/chaincfg" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) { } func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ @@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) { } func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ @@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) { } func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ @@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing } func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(4e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(4e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // -15 days - vested - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // +15 days - vesting - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // +30 days - vesting - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, } @@ -159,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) { expectedPeriods := []vestingtypes.Period{ { Length: 15 * 24 * 60 * 60, // 15 days - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, { Length: 15 * 24 * 60 * 60, // 15 days - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, } - assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated") + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated") assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated") assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period") assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated") } func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(3e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // -15 days - vested - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // +15 days - vesting - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, } @@ -198,35 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour) ResetPeriodicVestingAccount(vacc, newVestingStartTime) - assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated") - assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated") + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated") + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated") } func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) { - balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6))) + balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(3e6))) vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past periods := vestingtypes.Periods{ vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // -15 days - vested - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, vestingtypes.Period{ Length: 15 * 24 * 60 * 60, // +15 days - vesting - Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), + Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), }, } vacc := createVestingAccount(balance, vestingStartTime, periods) - vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))) + vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6)))) newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour) ResetPeriodicVestingAccount(vacc, newVestingStartTime) assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified") - assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified") + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified") } diff --git a/proto/zgc/evmutil/v1beta1/conversion_pair.proto b/proto/zgc/evmutil/v1beta1/conversion_pair.proto index 3db7f95f..09cf2321 100644 --- a/proto/zgc/evmutil/v1beta1/conversion_pair.proto +++ b/proto/zgc/evmutil/v1beta1/conversion_pair.proto @@ -13,7 +13,7 @@ message ConversionPair { option (gogoproto.goproto_getters) = false; // ERC20 address of the token on the 0gChain EVM - bytes zgChain_erc20_address = 1 [ + bytes zgchain_erc20_address = 1 [ (gogoproto.customname) = "ZgChainERC20Address", (gogoproto.casttype) = "HexBytes" ]; diff --git a/proto/zgc/evmutil/v1beta1/tx.proto b/proto/zgc/evmutil/v1beta1/tx.proto index 91d0991a..8e2943d7 100644 --- a/proto/zgc/evmutil/v1beta1/tx.proto +++ b/proto/zgc/evmutil/v1beta1/tx.proto @@ -24,7 +24,7 @@ service Msg { rpc ConvertCosmosCoinFromERC20(MsgConvertCosmosCoinFromERC20) returns (MsgConvertCosmosCoinFromERC20Response); } -// MsgConvertCoinToERC20 defines a conversion from sdk.Coin to 0g-chain ERC20 for EVM-native assets. +// MsgConvertCoinToERC20 defines a conversion from sdk.Coin to 0gChain ERC20 for EVM-native assets. message MsgConvertCoinToERC20 { // 0gChain bech32 address initiating the conversion. string initiator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; @@ -44,7 +44,7 @@ message MsgConvertERC20ToCoin { // 0gChain bech32 address that will receive the converted sdk.Coin. string receiver = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // EVM 0x hex address of the ERC20 contract. - string zgChain_erc20_address = 3 [(gogoproto.customname) = "ZgChainERC20Address"]; + string zgchain_erc20_address = 3 [(gogoproto.customname) = "ZgChainERC20Address"]; // ERC20 token amount to convert. string amount = 4 [ (cosmos_proto.scalar) = "cosmos.Int", diff --git a/tests/e2e/e2e_convert_cosmos_coins_test.go b/tests/e2e/e2e_convert_cosmos_coins_test.go index 4f81910f..d1439b33 100644 --- a/tests/e2e/e2e_convert_cosmos_coins_test.go +++ b/tests/e2e/e2e_convert_cosmos_coins_test.go @@ -12,6 +12,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/tests/e2e/testutil" "github.com/0glabs/0g-chain/tests/util" evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types" @@ -66,7 +67,7 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance( tx := util.ZgChainMsgRequest{ Msgs: []sdk.Msg{&msg}, GasLimit: 4e5, - FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))), + FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(400)), Data: "converting sdk coin to erc20", } res := user.SignAndBroadcastZgChainTx(tx) @@ -105,7 +106,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() { tx := util.ZgChainMsgRequest{ Msgs: []sdk.Msg{&convertToErc20Msg}, GasLimit: 2e6, - FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))), + FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(2000)), Data: "converting sdk coin to erc20", } res := user.SignAndBroadcastZgChainTx(tx) @@ -147,7 +148,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() { tx = util.ZgChainMsgRequest{ Msgs: []sdk.Msg{&convertFromErc20Msg}, GasLimit: 2e5, - FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))), + FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)), Data: "converting erc20 to cosmos coin", } res = user.SignAndBroadcastZgChainTx(tx) @@ -186,7 +187,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() { user, suite.ZgChain, 2e6, - sdk.NewCoins(a0gi(big.NewInt(1e4))), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)), []sdk.Msg{&convertToErc20Msg}, "this is a memo", ).GetTx() @@ -240,7 +241,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() { user, suite.ZgChain, 2e5, - sdk.NewCoins(a0gi(big.NewInt(200))), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)), []sdk.Msg{&convertFromErc20Msg}, "", ).GetTx() @@ -334,7 +335,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() { "cosmo-coin-converter-complex-alice", initialAliceAmount, ) - gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5))) + gasMoney := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5)) bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney) amount := big.NewInt(1e3) // test assumes this is half of alice's balance. @@ -415,7 +416,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() { convertTx := util.ZgChainMsgRequest{ Msgs: []sdk.Msg{&convertMsg}, GasLimit: 2e5, - FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))), + FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)), Data: "bob converts his new erc20 to an sdk.Coin", } convertRes := bob.SignAndBroadcastZgChainTx(convertTx) diff --git a/tests/e2e/e2e_evm_contracts_test.go b/tests/e2e/e2e_evm_contracts_test.go index ba3c2231..aa24c1f6 100644 --- a/tests/e2e/e2e_evm_contracts_test.go +++ b/tests/e2e/e2e_evm_contracts_test.go @@ -11,8 +11,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/0glabs/0g-chain/app" - evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/tests/e2e/contracts/greeter" "github.com/0glabs/0g-chain/tests/util" ) @@ -21,7 +21,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() { // this test manipulates state of the Greeter contract which means other tests shouldn't use it. // setup funded account to interact with contract - user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(a0gi(big.NewInt(1e6)))) + user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e6))) greeterAddr := suite.ZgChain.ContractAddrs["greeter"] contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient) @@ -64,12 +64,12 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() { func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() { // create new funded account - sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(a0gi(big.NewInt(2e4)))) + sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(2e4))) receiver := app.RandomAddress() - // setup message for sending some a0gi to random receiver + // setup message for sending some gas denom to random receiver msgs := []sdk.Msg{ - banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(a0gi(big.NewInt(1e3)))), + banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e3))), } // create tx @@ -77,7 +77,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() { sender, suite.ZgChain, 1e6, - sdk.NewCoins(a0gi(big.NewInt(1e4))), + sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)), msgs, "this is a memo", ).GetTx() @@ -96,10 +96,10 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() { _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second) suite.NoError(err) - // check that the message was processed & the a0gi is transferred. + // check that the message was processed & the gas denom is transferred. balRes, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{ Address: receiver.String(), - Denom: "ua0gi", + Denom: chaincfg.GasDenom, }) suite.NoError(err) suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount) @@ -107,95 +107,95 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() { // Note that this test works because the deployed erc20 is configured in evmutil & cdp params. // This test matches the webapp's "USDT Earn" workflow -func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() { - // cdp requires minimum of $11 collateral - amount := sdk.NewInt(11e6) // 11 USDT - // principal := sdk.NewCoin("usdx", sdk.NewInt(10e6)) - sdkDenom := suite.DeployedErc20.CosmosDenom +// func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() { +// // cdp requires minimum of $11 collateral +// amount := sdk.NewInt(11e6) // 11 USDT +// principal := sdk.NewCoin("usdx", sdk.NewInt(10e6)) +// sdkDenom := suite.DeployedErc20.CosmosDenom - // create new funded account - depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(a0gi(big.NewInt(1e5)))) - // give them erc20 balance to deposit - fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt()) - suite.NoError(fundRes.Err) +// // create new funded account +// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5))) +// // give them erc20 balance to deposit +// fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt()) +// suite.NoError(fundRes.Err) - // setup messages for convert to coin & deposit into earn - convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin( - evmutiltypes.NewInternalEVMAddress(depositor.EvmAddress), - depositor.SdkAddress, - evmutiltypes.NewInternalEVMAddress(suite.DeployedErc20.Address), - amount, - ) - // depositMsg := cdptypes.NewMsgCreateCDP( - // depositor.SdkAddress, - // sdk.NewCoin(sdkDenom, amount), - // principal, - // suite.DeployedErc20.CdpCollateralType, - // ) - msgs := []sdk.Msg{ - // convert to coin - &convertMsg, - // deposit into cdp (Mint), take out USDX - // &depositMsg, - } +// // setup messages for convert to coin & deposit into earn +// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin( +// evmutiltypes.NewInternalEVMAddress(depositor.EvmAddress), +// depositor.SdkAddress, +// evmutiltypes.NewInternalEVMAddress(suite.DeployedErc20.Address), +// amount, +// ) +// // depositMsg := cdptypes.NewMsgCreateCDP( +// // depositor.SdkAddress, +// // sdk.NewCoin(sdkDenom, amount), +// // principal, +// // suite.DeployedErc20.CdpCollateralType, +// // ) +// msgs := []sdk.Msg{ +// // convert to coin +// &convertMsg, +// // deposit into cdp (Mint), take out USDX +// // &depositMsg, +// } - // create tx - tx := suite.NewEip712TxBuilder( - depositor, - suite.ZgChain, - 1e6, - sdk.NewCoins(a0gi(big.NewInt(1e4))), - msgs, - "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit", - ).GetTx() +// // create tx +// tx := suite.NewEip712TxBuilder( +// depositor, +// suite.ZgChain, +// 1e6, +// sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)), +// msgs, +// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit", +// ).GetTx() - txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx) - suite.NoError(err) +// txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx) +// suite.NoError(err) - // broadcast tx - res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{ - TxBytes: txBytes, - Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC, - }) - suite.NoError(err) - suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code) +// // broadcast tx +// res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{ +// TxBytes: txBytes, +// Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC, +// }) +// suite.NoError(err) +// suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code) - _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second) - suite.Require().NoError(err) +// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second) +// suite.Require().NoError(err) - // check that depositor no longer has erc20 balance - balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress) - suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance") +// // check that depositor no longer has erc20 balance +// balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress) +// suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance") - // check that account has cdp - // cdpRes, err := suite.ZgChain.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{ - // CollateralType: suite.DeployedErc20.CdpCollateralType, - // Owner: depositor.SdkAddress.String(), - // }) - // suite.NoError(err) - // suite.True(cdpRes.Cdp.Collateral.Amount.Equal(amount)) - // suite.True(cdpRes.Cdp.Principal.Equal(principal)) +// // check that account has cdp +// // cdpRes, err := suite.ZgChain.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{ +// // CollateralType: suite.DeployedErc20.CdpCollateralType, +// // Owner: depositor.SdkAddress.String(), +// // }) +// // suite.NoError(err) +// // suite.True(cdpRes.Cdp.Collateral.Amount.Equal(amount)) +// // suite.True(cdpRes.Cdp.Principal.Equal(principal)) - // withdraw deposit & convert back to erc20 (this allows refund to recover erc20s used in test) - // withdraw := cdptypes.NewMsgRepayDebt( - // depositor.SdkAddress, - // suite.DeployedErc20.CdpCollateralType, - // principal, - // ) - convertBack := evmutiltypes.NewMsgConvertCoinToERC20( - depositor.SdkAddress.String(), - depositor.EvmAddress.Hex(), - sdk.NewCoin(sdkDenom, amount), - ) - withdrawAndConvertBack := util.ZgChainMsgRequest{ - Msgs: []sdk.Msg{ /*&withdraw,*/ &convertBack}, - GasLimit: 1e6, - FeeAmount: sdk.NewCoins(a0gi(big.NewInt(1000))), - Data: "withdrawing from mint & converting back to erc20", - } - lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack) - suite.NoError(lastRes.Err) +// // withdraw deposit & convert back to erc20 (this allows refund to recover erc20s used in test) +// // withdraw := cdptypes.NewMsgRepayDebt( +// // depositor.SdkAddress, +// // suite.DeployedErc20.CdpCollateralType, +// // principal, +// // ) +// convertBack := evmutiltypes.NewMsgConvertCoinToERC20( +// depositor.SdkAddress.String(), +// depositor.EvmAddress.Hex(), +// sdk.NewCoin(sdkDenom, amount), +// ) +// withdrawAndConvertBack := util.ZgChainMsgRequest{ +// Msgs: []sdk.Msg{&withdraw, &convertBack}, +// GasLimit: 1e6, +// FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1000)), +// Data: "withdrawing from mint & converting back to erc20", +// } +// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack) +// suite.NoError(lastRes.Err) - balance = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress) - suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance") -} +// balance = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress) +// suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance") +// } diff --git a/tests/e2e/e2e_grpc_client_query_test.go b/tests/e2e/e2e_grpc_client_query_test.go index 70fbcc98..e6a315d1 100644 --- a/tests/e2e/e2e_grpc_client_query_test.go +++ b/tests/e2e/e2e_grpc_client_query_test.go @@ -2,18 +2,18 @@ package e2e_test import ( "context" - "math/big" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/0glabs/0g-chain/chaincfg" evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types" ) func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() { // ARRANGE // setup 0g account - funds := a0gi(big.NewInt(1e5)) + funds := chaincfg.MakeCoinForGasDenom(1e5) zgAcc := suite.ZgChain.NewFundedAccount("balance-test", sdk.NewCoins(funds)) // ACT diff --git a/tests/e2e/e2e_grpc_client_util_test.go b/tests/e2e/e2e_grpc_client_util_test.go index 5376456a..2a22255e 100644 --- a/tests/e2e/e2e_grpc_client_util_test.go +++ b/tests/e2e/e2e_grpc_client_util_test.go @@ -1,15 +1,14 @@ package e2e_test import ( - "math/big" - + "github.com/0glabs/0g-chain/chaincfg" sdk "github.com/cosmos/cosmos-sdk/types" ) func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() { // ARRANGE // setup 0g account - zgAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(a0gi(big.NewInt(1e5)))) + zgAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5))) // ACT rsp, err := suite.ZgChain.Grpc.BaseAccount(zgAcc.SdkAddress.String()) diff --git a/tests/e2e/e2e_min_fees_test.go b/tests/e2e/e2e_min_fees_test.go index 8516f2ba..888143a5 100644 --- a/tests/e2e/e2e_min_fees_test.go +++ b/tests/e2e/e2e_min_fees_test.go @@ -13,6 +13,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/tests/util" ) @@ -23,10 +24,10 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() { minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath()) suite.NoError(err) - // evm uses neuron, get neuron min fee - evmMinGas := minGasPrices.AmountOf("neuron").TruncateInt().BigInt() + // evm uses evm denom, get evm denom min fee + evmMinGas := minGasPrices.AmountOf(chaincfg.EvmDenom).TruncateInt().BigInt() - // returns eth_gasPrice, units in a0gi + // returns eth_gasPrice, units in gas denom gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background()) suite.NoError(err) @@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() { suite.SkipIfKvtoolDisabled() // setup sender & receiver - sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3)))) + sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e3))) randoReceiver := util.SdkToEvmAddress(app.RandomAddress()) // get min gas price for evm (from app.toml) minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath()) suite.NoError(err) - minGasPrice := minFees.AmountOf("neuron").TruncateInt() + minGasPrice := minFees.AmountOf(chaincfg.EvmDenom).TruncateInt() // attempt tx with less than min gas price (min fee - 1) tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt() diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 817fff01..862bdd49 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -19,18 +19,15 @@ import ( emtypes "github.com/evmos/ethermint/types" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/tests/e2e/testutil" "github.com/0glabs/0g-chain/tests/util" ) var ( - minEvmGasPrice = big.NewInt(1e10) // neuron + minEvmGasPrice = big.NewInt(1e10) // evm denom ) -func a0gi(amt *big.Int) sdk.Coin { - return sdk.NewCoin("ua0gi", sdkmath.NewIntFromBigInt(amt)) -} - type IntegrationTestSuite struct { testutil.E2eTestSuite } @@ -57,7 +54,7 @@ func (suite *IntegrationTestSuite) TestChainID() { // example test that funds a new account & queries its balance func (suite *IntegrationTestSuite) TestFundedAccount() { - funds := a0gi(big.NewInt(1e3)) + funds := chaincfg.MakeCoinForGasDenom(1e3) acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds)) // check that the sdk & evm signers are for the same account @@ -66,21 +63,21 @@ func (suite *IntegrationTestSuite) TestFundedAccount() { // check balance via SDK query res, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest( - acc.SdkAddress, "ua0gi", + acc.SdkAddress, chaincfg.GasDenom, )) suite.NoError(err) suite.Equal(funds, *res.Balance) // check balance via EVM query - neuronBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil) + evmDenomBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil) suite.NoError(err) - suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), neuronBal) + suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), evmDenomBal) } // example test that signs & broadcasts an EVM tx func (suite *IntegrationTestSuite) TestTransferOverEVM() { // fund an account that can perform the transfer - initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI + initialFunds := chaincfg.MakeCoinForGasDenom(1e6) // 1 (gas denom acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds)) // get a rando account to send 0gchain to @@ -92,10 +89,10 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() { suite.NoError(err) suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs - // transfer a0gi over EVM - a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals. + // transfer gas denom over EVM + GasDenomToTransfer := big.NewInt(1e17) // .1 (gas denom; evm denom has 18 decimals. req := util.EvmTxRequest{ - Tx: ethtypes.NewTransaction(nonce, to, a0giToTransfer, 1e5, minEvmGasPrice, nil), + Tx: ethtypes.NewTransaction(nonce, to, GasDenomToTransfer, 1e5, minEvmGasPrice, nil), Data: "any ol' data to track this through the system", } res := acc.SignAndBroadcastEvmTx(req) @@ -103,31 +100,31 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() { suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status) // evm txs refund unused gas. so to know the expected balance we need to know how much gas was used. - a0giUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice). + GasDenomUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice). Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)). - QuoRaw(1e12) // convert neuron to a0gi + QuoRaw(1e12) // convert evm denom to gas denom - // expect (9 - gas used) A0GI remaining in account. + // expect (9 - gas used) (gas denom remaining in account. balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress) - suite.Equal(sdkmath.NewInt(9e5).Sub(a0giUsedForGas), balance.AmountOf("ua0gi")) + suite.Equal(sdkmath.NewInt(9e5).Sub(GasDenomUsedForGas), balance.AmountOf(chaincfg.GasDenom)) } -// TestIbcTransfer transfers A0GI from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc). +// TestIbcTransfer transfers (gas denom from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc). // Note that because the IBC chain also runs 0g-chain's binary, this tests both the sending & receiving. func (suite *IntegrationTestSuite) TestIbcTransfer() { suite.SkipIfIbcDisabled() // ARRANGE // setup 0g-chain account - funds := a0gi(big.NewInt(1e5)) // .1 A0GI + funds := chaincfg.MakeCoinForGasDenom(1e5) // .1 (gas denom zgChainAcc := suite.ZgChain.NewFundedAccount("ibc-transfer-0g-side", sdk.NewCoins(funds)) // setup ibc account ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins()) gasLimit := int64(2e5) - fee := a0gi(big.NewInt(200)) + fee := chaincfg.MakeCoinForGasDenom(200) - fundsToSend := a0gi(big.NewInt(5e4)) // .005 A0GI + fundsToSend := chaincfg.MakeCoinForGasDenom(5e4) // .005 (gas denom transferMsg := ibctypes.NewMsgTransfer( testutil.IbcPort, testutil.IbcChannel, @@ -157,7 +154,7 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() { // the balance should be deducted from 0g-chain account suite.Eventually(func() bool { balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress) - return balance.AmountOf("ua0gi").Equal(expectedSrcBalance.Amount) + return balance.AmountOf(chaincfg.GasDenom).Equal(expectedSrcBalance.Amount) }, 10*time.Second, 1*time.Second) // expect the balance to be transferred to the ibc chain! diff --git a/tests/e2e/runner/chain.go b/tests/e2e/runner/chain.go index bbedec03..269a6063 100644 --- a/tests/e2e/runner/chain.go +++ b/tests/e2e/runner/chain.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "github.com/0glabs/0g-chain/chaincfg" rpchttpclient "github.com/cometbft/cometbft/rpc/client/http" "github.com/ethereum/go-ethereum/ethclient" ) @@ -73,7 +74,7 @@ var ( EvmRpcUrl: "http://localhost:8545", ChainId: "0gchainlocalnet_8888-1", - StakingDenom: "ua0gi", + StakingDenom: chaincfg.GasDenom, } kvtoolIbcChain = ChainDetails{ RpcUrl: "http://localhost:26658", diff --git a/tests/e2e/testutil/account.go b/tests/e2e/testutil/account.go index 743a7d31..5e5659aa 100644 --- a/tests/e2e/testutil/account.go +++ b/tests/e2e/testutil/account.go @@ -262,7 +262,7 @@ func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgCh util.ZgChainMsgRequest{ Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)}, GasLimit: 2e5, // 200,000 gas - FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001a0gi + FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001 gas denom Data: fmt.Sprintf("sending %s to %s", amount, to), }, ) diff --git a/third_party/proto/cosmos/bank/v1beta1/bank.proto b/third_party/proto/cosmos/bank/v1beta1/bank.proto index f81bb923..483540db 100644 --- a/third_party/proto/cosmos/bank/v1beta1/bank.proto +++ b/third_party/proto/cosmos/bank/v1beta1/bank.proto @@ -98,7 +98,7 @@ message Metadata { string description = 1; // denom_units represents the list of DenomUnit's for a given coin repeated DenomUnit denom_units = 2; - // base represents the base denom (should be the DenomUnit with exponent = 0). + // base represents the evm denom (should be the DenomUnit with exponent = 0). string base = 3; // display indicates the suggested denom that should be // displayed in clients. diff --git a/third_party/proto/cosmos/tx/v1beta1/tx.proto b/third_party/proto/cosmos/tx/v1beta1/tx.proto index a71a3e11..558b1da6 100644 --- a/third_party/proto/cosmos/tx/v1beta1/tx.proto +++ b/third_party/proto/cosmos/tx/v1beta1/tx.proto @@ -234,18 +234,18 @@ message Tip { string tipper = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; } -// AuxSignerData is the intermediary format that an auxiliary signer (e.g. a +// AuxSignerData is the intermediary format that an gas signer (e.g. a // tipper) builds and sends to the fee payer (who will build and broadcast the // actual tx). AuxSignerData is not a valid tx in itself, and will be rejected // by the node if sent directly as-is. // // Since: cosmos-sdk 0.46 message AuxSignerData { - // address is the bech32-encoded address of the auxiliary signer. If using + // address is the bech32-encoded address of the gas signer. If using // AuxSignerData across different chains, the bech32 prefix of the target // chain (where the final transaction is broadcasted) should be used. string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // sign_doc is the SIGN_MODE_DIRECT_AUX sign doc that the auxiliary signer + // sign_doc is the SIGN_MODE_DIRECT_AUX sign doc that the gas signer // signs. Note: we use the same sign doc even if we're signing with // LEGACY_AMINO_JSON. SignDocDirectAux sign_doc = 2; diff --git a/third_party/proto/ibc/applications/transfer/v1/transfer.proto b/third_party/proto/ibc/applications/transfer/v1/transfer.proto index 21710747..cb50559c 100644 --- a/third_party/proto/ibc/applications/transfer/v1/transfer.proto +++ b/third_party/proto/ibc/applications/transfer/v1/transfer.proto @@ -6,13 +6,13 @@ option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"; import "gogoproto/gogo.proto"; -// DenomTrace contains the base denomination for ICS20 fungible tokens and the +// DenomTrace contains the evm denomination for ICS20 fungible tokens and the // source tracing information path. message DenomTrace { // path defines the chain of port/channel identifiers used for tracing the // source of the fungible token. string path = 1; - // base denomination of the relayed fungible token. + // evm denomination of the relayed fungible token. string base_denom = 2; } diff --git a/x/bep3/client/cli/query.go b/x/bep3/client/cli/query.go index 94fb67d1..2c49b608 100644 --- a/x/bep3/client/cli/query.go +++ b/x/bep3/client/cli/query.go @@ -220,7 +220,7 @@ func QueryGetAtomicSwapsCmd(queryRoute string) *cobra.Command { Short: "query atomic swaps with optional filters", Long: strings.TrimSpace(`Query for all paginated atomic swaps that match optional filters: Example: -$ kvcli q bep3 swaps --involve=kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny +$ kvcli q bep3 swaps --involve=0g1l0xsq2z7gqd7yly0g40y5836g0appumark77ny $ kvcli q bep3 swaps --expiration=280 $ kvcli q bep3 swaps --status=(Open|Completed|Expired) $ kvcli q bep3 swaps --direction=(Incoming|Outgoing) diff --git a/x/bep3/keeper/msg_server_test.go b/x/bep3/keeper/msg_server_test.go index 4b32df79..afd5f274 100644 --- a/x/bep3/keeper/msg_server_test.go +++ b/x/bep3/keeper/msg_server_test.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/bep3" "github.com/0glabs/0g-chain/x/bep3/keeper" "github.com/0glabs/0g-chain/x/bep3/types" @@ -35,7 +36,7 @@ func (suite *MsgServerTestSuite) SetupTest() { // Set up genesis state and initialize _, addrs := app.GeneratePrivKeyAddressPairs(3) - coins := sdk.NewCoins(c("bnb", 10000000000), c("a0gi", 10000)) + coins := sdk.NewCoins(c("bnb", 10000000000), c(chaincfg.GasDenom, 10000)) authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs) tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0])) diff --git a/x/bep3/types/genesis_test.go b/x/bep3/types/genesis_test.go index 2f881c74..447a294d 100644 --- a/x/bep3/types/genesis_test.go +++ b/x/bep3/types/genesis_test.go @@ -20,7 +20,7 @@ type GenesisTestSuite struct { } func (suite *GenesisTestSuite) SetupTest() { - coin := sdk.NewCoin("a0gi", sdk.OneInt()) + coin := chaincfg.MakeCoinForGasDenom(1) suite.swaps = atomicSwaps(10) supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0)) @@ -100,7 +100,6 @@ func (suite *GenesisTestSuite) TestValidate() { for _, tc := range testCases { suite.Run(tc.name, func() { chaincfg.SetSDKConfig() - var gs types.GenesisState if tc.name == "default" { gs = types.DefaultGenesisState() diff --git a/x/bep3/types/supply_test.go b/x/bep3/types/supply_test.go index 35bd5e9f..b27d2928 100644 --- a/x/bep3/types/supply_test.go +++ b/x/bep3/types/supply_test.go @@ -5,12 +5,13 @@ import ( "time" sdkmath "cosmossdk.io/math" + "github.com/0glabs/0g-chain/chaincfg" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) func TestAssetSupplyValidate(t *testing.T) { - coin := sdk.NewCoin("a0gi", sdk.OneInt()) + coin := chaincfg.MakeCoinForGasDenom(1) invalidCoin := sdk.Coin{Denom: "Invalid Denom", Amount: sdkmath.NewInt(-1)} testCases := []struct { msg string diff --git a/x/committee/keeper/msg_server_test.go b/x/committee/keeper/msg_server_test.go index 6e29e612..2a2a7251 100644 --- a/x/committee/keeper/msg_server_test.go +++ b/x/committee/keeper/msg_server_test.go @@ -6,12 +6,12 @@ import ( "github.com/stretchr/testify/suite" - sdkmath "cosmossdk.io/math" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/committee/keeper" "github.com/0glabs/0g-chain/x/committee/types" ) @@ -61,7 +61,7 @@ func (suite *MsgServerTestSuite) SetupTest() { []types.Proposal{}, []types.Vote{}, ) - suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1000))) + suite.communityPoolAmt = sdk.NewCoins(chaincfg.MakeCoinForEvmDenom(1000000000000000)) suite.app.InitializeFromGenesisStates( app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)}, // TODO: not used? diff --git a/x/committee/types/committee.go b/x/committee/types/committee.go index a174fe65..86574e88 100644 --- a/x/committee/types/committee.go +++ b/x/committee/types/committee.go @@ -4,6 +4,7 @@ import ( fmt "fmt" "time" + "github.com/0glabs/0g-chain/chaincfg" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +19,7 @@ const ( BaseCommitteeType = "0g/BaseCommittee" MemberCommitteeType = "0g/MemberCommittee" // Committee is composed of member addresses that vote to enact proposals within their permissions TokenCommitteeType = "0g/TokenCommittee" // Committee is composed of token holders with voting power determined by total token balance - BondDenom = "neuron" + BondDenom = chaincfg.BondDenom ) // Marshal needed for protobuf compatibility. diff --git a/x/council/v1/client/cli/tx.go b/x/council/v1/client/cli/tx.go index 31f12d0e..478708f4 100644 --- a/x/council/v1/client/cli/tx.go +++ b/x/council/v1/client/cli/tx.go @@ -171,10 +171,10 @@ func NewVoteCmd() *cobra.Command { tokens = val.GetTokens() } } - // the denom of token is neuron, need to convert to A0GI - a0gi := tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000)) + // the denom of token is evm denom, need to convert to A0GI + a0giTokenCnt := tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000)) // 1_000 0AGI token / vote - numBallots := a0gi.Quo(sdk.NewInt(1_000)).Uint64() + numBallots := a0giTokenCnt.Quo(sdk.NewInt(1_000)).Uint64() ballots := make([]*types.Ballot, numBallots) for i := range ballots { ballotID := uint64(i) diff --git a/x/council/v1/types/codec.go b/x/council/v1/types/codec.go index fd2b1071..7a2c2031 100644 --- a/x/council/v1/types/codec.go +++ b/x/council/v1/types/codec.go @@ -21,8 +21,8 @@ var ( const ( // Amino names - registerName = "evmos/council/MsgRegister" - voteName = "evmos/council/MsgVote" + registerName = "0g/council/MsgRegister" + voteName = "0g/council/MsgVote" ) // NOTE: This is required for the GetSignBytes function diff --git a/x/evmutil/keeper/bank_keeper.go b/x/evmutil/keeper/bank_keeper.go index e69308f5..c21fd83b 100644 --- a/x/evmutil/keeper/bank_keeper.go +++ b/x/evmutil/keeper/bank_keeper.go @@ -9,64 +9,57 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/types" ) -const ( - // EvmDenom is the gas denom used by the evm - EvmDenom = "neuron" - - // CosmosDenom is the gas denom used by the 0g-chain app - CosmosDenom = "ua0gi" -) - -// ConversionMultiplier is the conversion multiplier between neuron and ua0gi -var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000) +// ConversionMultiplier is the conversion multiplier between evm denom and gas denom +var ConversionMultiplier = sdkmath.NewInt(chaincfg.GasDenomConversionMultiplier) var _ evmtypes.BankKeeper = EvmBankKeeper{} // EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use -// of the 18 decimal neuron coin on the evm. -// x/evm consumes gas and send coins by minting and burning neuron coins in its module +// of the 18 decimal evm denom coin on the evm. +// x/evm consumes gas and send coins by minting and burning evm denom coins in its module // account and then sending the funds to the target account. -// This keeper uses both the a0gi coin and a separate neuron balance to manage the +// This keeper uses both the gas denom coin and a separate evm denom balance to manage the // extra percision needed by the evm. type EvmBankKeeper struct { - neuronKeeper Keeper - bk types.BankKeeper - ak types.AccountKeeper + evmDenomKeeper Keeper + bk types.BankKeeper + ak types.AccountKeeper } -func NewEvmBankKeeper(neuronKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper { +func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper { return EvmBankKeeper{ - neuronKeeper: neuronKeeper, - bk: bk, - ak: ak, + evmDenomKeeper: baseKeeper, + bk: bk, + ak: ak, } } -// GetBalance returns the total **spendable** balance of neuron for a given account by address. +// GetBalance returns the total **spendable** balance of evm denom for a given account by address. func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { - if denom != EvmDenom { - panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom)) + if denom != chaincfg.EvmDenom { + panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.EvmDenom)) } spendableCoins := k.bk.SpendableCoins(ctx, addr) - cosmosDenomFromBank := spendableCoins.AmountOf(CosmosDenom) - evmDenomFromBank := spendableCoins.AmountOf(EvmDenom) - evmDenomFromEvmBank := k.neuronKeeper.GetBalance(ctx, addr) + gasDenomFromBank := spendableCoins.AmountOf(chaincfg.GasDenom) + evmDenomFromBank := spendableCoins.AmountOf(chaincfg.EvmDenom) + evmDenomFromEvmBank := k.evmDenomKeeper.GetBalance(ctx, addr) var total sdkmath.Int - if cosmosDenomFromBank.IsPositive() { - total = cosmosDenomFromBank.Mul(ConversionMultiplier).Add(evmDenomFromBank).Add(evmDenomFromEvmBank) + if gasDenomFromBank.IsPositive() { + total = gasDenomFromBank.Mul(ConversionMultiplier).Add(evmDenomFromBank).Add(evmDenomFromEvmBank) } else { total = evmDenomFromBank.Add(evmDenomFromEvmBank) } - return sdk.NewCoin(EvmDenom, total) + return sdk.NewCoin(chaincfg.EvmDenom, total) } -// SendCoins transfers neuron coins from a AccAddress to an AccAddress. +// SendCoins transfers evm denom coins from a AccAddress to an AccAddress. func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdk.Coins) error { // SendCoins method is not used by the evm module, but is required by the // evmtypes.BankKeeper interface. This must be updated if the evm module @@ -74,101 +67,101 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec panic("not implemented") } -// SendCoinsFromModuleToAccount transfers neuron coins from a ModuleAccount to an AccAddress. +// SendCoinsFromModuleToAccount transfers evm denom coins from a ModuleAccount to an AccAddress. // It will panic if the module account does not exist. An error is returned if the recipient // address is black-listed or if sending the tokens fails. func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error { - ua0gi, neuron, err := SplitNeuronCoins(amt) + gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt) if err != nil { return err } - if ua0gi.Amount.IsPositive() { - if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ua0gi)); err != nil { + if gasDenomCoin.Amount.IsPositive() { + if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(gasDenomCoin)); err != nil { return err } } senderAddr := k.GetModuleAddress(senderModule) - if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil { + if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, senderAddr, baseDemonCnt); err != nil { return err } - if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil { + if err := k.evmDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, baseDemonCnt); err != nil { return err } - return k.ConvertNeuronToUa0gi(ctx, recipientAddr) + return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr) } -// SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount. +// SendCoinsFromAccountToModule transfers evm denom coins from an AccAddress to a ModuleAccount. // It will panic if the module account does not exist. func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error { - ua0gi, neuronNeeded, err := SplitNeuronCoins(amt) + gasDenomCoin, evmDenomCnt, err := SplitEvmDenomCoins(amt) if err != nil { return err } - if ua0gi.IsPositive() { - if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ua0gi)); err != nil { + if gasDenomCoin.IsPositive() { + if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(gasDenomCoin)); err != nil { return err } } - if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil { + if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, senderAddr, evmDenomCnt); err != nil { return err } recipientAddr := k.GetModuleAddress(recipientModule) - if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil { + if err := k.evmDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, evmDenomCnt); err != nil { return err } - return k.ConvertNeuronToUa0gi(ctx, recipientAddr) + return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr) } -// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins. +// MintCoins mints evm denom coins by minting the equivalent gas denom coins and any remaining evm denom coins. // It will panic if the module account does not exist or is unauthorized. func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { - ua0gi, neuron, err := SplitNeuronCoins(amt) + gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt) if err != nil { return err } - if ua0gi.IsPositive() { - if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil { + if gasDenomCoin.IsPositive() { + if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(gasDenomCoin)); err != nil { return err } } recipientAddr := k.GetModuleAddress(moduleName) - if err := k.neuronKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil { + if err := k.evmDenomKeeper.AddBalance(ctx, recipientAddr, baseDemonCnt); err != nil { return err } - return k.ConvertNeuronToUa0gi(ctx, recipientAddr) + return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr) } -// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins. +// BurnCoins burns evm denom coins by burning the equivalent gas denom coins and any remaining evm denom coins. // It will panic if the module account does not exist or is unauthorized. func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { - ua0gi, neuron, err := SplitNeuronCoins(amt) + gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt) if err != nil { return err } - if ua0gi.IsPositive() { - if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil { + if gasDenomCoin.IsPositive() { + if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(gasDenomCoin)); err != nil { return err } } moduleAddr := k.GetModuleAddress(moduleName) - if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil { + if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, moduleAddr, baseDemonCnt); err != nil { return err } - return k.neuronKeeper.RemoveBalance(ctx, moduleAddr, neuron) + return k.evmDenomKeeper.RemoveBalance(ctx, moduleAddr, baseDemonCnt) } // IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled @@ -181,51 +174,51 @@ func (k EvmBankKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) er panic("not implemented") } -// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if -// its neuron balance is smaller than the neuronNeeded amount. -func (k EvmBankKeeper) ConvertOneUa0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error { - neuronBal := k.neuronKeeper.GetBalance(ctx, addr) - if neuronBal.GTE(neuronNeeded) { +// ConvertOnegasDenomToEvmDenomIfNeeded converts 1 gas denom to evm denom for an address if +// its evm denom balance is smaller than the evmDenomCnt amount. +func (k EvmBankKeeper) ConvertOneGasDenomToEvmDenomIfNeeded(ctx sdk.Context, addr sdk.AccAddress, evmDenomCnt sdkmath.Int) error { + evmDenomBal := k.evmDenomKeeper.GetBalance(ctx, addr) + if evmDenomBal.GTE(evmDenomCnt) { return nil } - ua0giToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt())) - if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ua0giToStore); err != nil { + gasDenomToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdk.OneInt())) + if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, gasDenomToStore); err != nil { return err } - // add 1a0gi equivalent of neuron to addr - neuronToReceive := ConversionMultiplier - if err := k.neuronKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil { + // add 1 gas denom equivalent of evm denom to addr + evmDenomToReceive := ConversionMultiplier + if err := k.evmDenomKeeper.AddBalance(ctx, addr, evmDenomToReceive); err != nil { return err } return nil } -// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress. -func (k EvmBankKeeper) ConvertNeuronToUa0gi(ctx sdk.Context, addr sdk.AccAddress) error { - totalNeuron := k.neuronKeeper.GetBalance(ctx, addr) - ua0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalNeuron))) +// ConvertEvmDenomTogasDenom converts all available evm denom to gas denom for a given AccAddress. +func (k EvmBankKeeper) ConvertEvmDenomToGasDenom(ctx sdk.Context, addr sdk.AccAddress) error { + totalEvmDenom := k.evmDenomKeeper.GetBalance(ctx, addr) + gasDenomCoin, _, err := SplitEvmDenomCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.EvmDenom, totalEvmDenom))) if err != nil { return err } - // do nothing if account does not have enough neuron for a single a0gi - ua0giToReceive := ua0gi.Amount - if !ua0giToReceive.IsPositive() { + // do nothing if account does not have enough evm denom for a single gas denom + gasDenomToReceive := gasDenomCoin.Amount + if !gasDenomToReceive.IsPositive() { return nil } - // remove neuron used for converting to ua0gi - neuronToBurn := ua0giToReceive.Mul(ConversionMultiplier) - finalBal := totalNeuron.Sub(neuronToBurn) - if err := k.neuronKeeper.SetBalance(ctx, addr, finalBal); err != nil { + // remove evm denom used for converting to gas denom + evmDenomToBurn := gasDenomToReceive.Mul(ConversionMultiplier) + finalBal := totalEvmDenom.Sub(evmDenomToBurn) + if err := k.evmDenomKeeper.SetBalance(ctx, addr, finalBal); err != nil { return err } fromAddr := k.GetModuleAddress(types.ModuleName) - if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ua0gi)); err != nil { + if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(gasDenomCoin)); err != nil { return err } @@ -240,35 +233,35 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress { return addr } -// SplitNeuronCoins splits neuron coins to the equivalent a0gi coins and any remaining neuron balance. -// An error will be returned if the coins are not valid or if the coins are not the neuron denom. -func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) { - neuron := sdk.ZeroInt() - ua0gi := sdk.NewCoin(CosmosDenom, sdk.ZeroInt()) +// SplitEvmDenomCoins splits evm denom coins to the equivalent gas denom coins and any remaining evm denom balance. +// An error will be returned if the coins are not valid or if the coins are not the evm denom. +func SplitEvmDenomCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) { + baseDemonCnt := sdk.ZeroInt() + gasDenomAmt := sdk.NewCoin(chaincfg.GasDenom, sdk.ZeroInt()) if len(coins) == 0 { - return ua0gi, neuron, nil + return gasDenomAmt, baseDemonCnt, nil } if err := ValidateEvmCoins(coins); err != nil { - return ua0gi, neuron, err + return gasDenomAmt, baseDemonCnt, err } // note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate. coin := coins[0] remainingBalance := coin.Amount.Mod(ConversionMultiplier) if remainingBalance.IsPositive() { - neuron = remainingBalance + baseDemonCnt = remainingBalance } - ua0giAmount := coin.Amount.Quo(ConversionMultiplier) - if ua0giAmount.IsPositive() { - ua0gi = sdk.NewCoin(CosmosDenom, ua0giAmount) + gasDenomAmount := coin.Amount.Quo(ConversionMultiplier) + if gasDenomAmount.IsPositive() { + gasDenomAmt = sdk.NewCoin(chaincfg.GasDenom, gasDenomAmount) } - return ua0gi, neuron, nil + return gasDenomAmt, baseDemonCnt, nil } -// ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (neuron). +// ValidateEvmCoins validates the coins from evm is valid and is the evm denom. func ValidateEvmCoins(coins sdk.Coins) error { if len(coins) == 0 { return nil @@ -279,9 +272,9 @@ func ValidateEvmCoins(coins sdk.Coins) error { return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String()) } - // validate that coin denom is neuron - if len(coins) != 1 || coins[0].Denom != EvmDenom { - errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom) + // validate that coin denom is evm denom + if len(coins) != 1 || coins[0].Denom != chaincfg.EvmDenom { + errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.EvmDenom) return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg) } diff --git a/x/evmutil/keeper/bank_keeper_test.go b/x/evmutil/keeper/bank_keeper_test.go index cf170e58..9fae9f68 100644 --- a/x/evmutil/keeper/bank_keeper_test.go +++ b/x/evmutil/keeper/bank_keeper_test.go @@ -14,6 +14,7 @@ import ( vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/keeper" "github.com/0glabs/0g-chain/x/evmutil/testutil" "github.com/0glabs/0g-chain/x/evmutil/types" @@ -28,8 +29,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() { } func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() { - startingCoins := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10)) - startingNeuron := sdkmath.NewInt(100) + startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10)) + startingEvmDenom := sdkmath.NewInt(100) now := tmtime.Now() endTime := now.Add(24 * time.Hour) @@ -39,24 +40,26 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() { err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins) suite.Require().NoError(err) - err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingNeuron) + err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingEvmDenom) suite.Require().NoError(err) - coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "neuron") - suite.Require().Equal(startingNeuron, coin.Amount) + coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.EvmDenom) + suite.Require().Equal(startingEvmDenom, coin.Amount) ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour)) - coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], "neuron") + coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.EvmDenom) suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount) } + func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() { suite.Require().Panics(func() { - suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ua0gi") + suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom) }) suite.Require().Panics(func() { suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd") }) } + func (suite *evmBankKeeperTestSuite) TestGetBalance() { tests := []struct { name string @@ -64,41 +67,41 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() { expAmount sdkmath.Int }{ { - "ua0gi with neuron", + "gas denom with evm denom", sdk.NewCoins( - sdk.NewInt64Coin("neuron", 100), - sdk.NewInt64Coin("ua0gi", 10), + sdk.NewInt64Coin(chaincfg.EvmDenom, 100), + sdk.NewInt64Coin(chaincfg.GasDenom, 10), ), - sdk.NewIntFromBigInt(makeBigIntByString("10000000000100")), + sdkmath.NewInt(10_000_000_000_100), }, { - "just neuron", + "just evm denom", sdk.NewCoins( - sdk.NewInt64Coin("neuron", 100), + sdk.NewInt64Coin(chaincfg.EvmDenom, 100), sdk.NewInt64Coin("busd", 100), ), sdkmath.NewInt(100), }, { - "just ua0gi", + "just gas denom", sdk.NewCoins( - sdk.NewInt64Coin("ua0gi", 10), + sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin("busd", 100), ), - sdk.NewIntFromBigInt(makeBigIntByString("10000000000000")), + sdkmath.NewInt(10_000_000_000_000), }, { - "no ua0gi or neuron", + "no gas denom or evm denom", sdk.NewCoins(), sdk.ZeroInt(), }, { - "with avaka that is more than 1 ua0gi", + "with avaka that is more than 1 gas denom", sdk.NewCoins( - sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("20000000000220"))), - sdk.NewInt64Coin("ua0gi", 11), + sdk.NewInt64Coin(chaincfg.EvmDenom, 20_000_000_000_220), + sdk.NewInt64Coin(chaincfg.GasDenom, 11), ), - sdk.NewIntFromBigInt(makeBigIntByString("31000000000220")), + sdkmath.NewInt(31_000_000_000_220), }, } @@ -107,15 +110,16 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() { suite.SetupTest() suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount) - coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "neuron") + coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.EvmDenom) suite.Require().Equal(tt.expAmount, coin.Amount) }) } } + func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() { startingModuleCoins := sdk.NewCoins( - sdk.NewInt64Coin("neuron", 200), - sdk.NewInt64Coin("ua0gi", 100), + sdk.NewInt64Coin(chaincfg.EvmDenom, 200), + sdk.NewInt64Coin(chaincfg.GasDenom, 100), ) tests := []struct { name string @@ -125,102 +129,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() { hasErr bool }{ { - "send more than 1 ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12000000000010")))), + "send more than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_010)), sdk.Coins{}, sdk.NewCoins( - sdk.NewInt64Coin("neuron", 10), - sdk.NewInt64Coin("ua0gi", 12), + sdk.NewInt64Coin(chaincfg.EvmDenom, 10), + sdk.NewInt64Coin(chaincfg.GasDenom, 12), ), false, }, { - "send less than 1 ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 122)), + "send less than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)), sdk.Coins{}, sdk.NewCoins( - sdk.NewInt64Coin("neuron", 122), - sdk.NewInt64Coin("ua0gi", 0), + sdk.NewInt64Coin(chaincfg.EvmDenom, 122), + sdk.NewInt64Coin(chaincfg.GasDenom, 0), ), false, }, { - "send an exact amount of ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("98000000000000")))), + "send an exact amount of gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)), sdk.Coins{}, sdk.NewCoins( - sdk.NewInt64Coin("neuron", 0), - sdk.NewInt64Coin("ua0gi", 98), + sdk.NewInt64Coin(chaincfg.EvmDenom, 0o0), + sdk.NewInt64Coin(chaincfg.GasDenom, 98), ), false, }, { - "send no neuron", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 0)), + "send no evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)), sdk.Coins{}, sdk.NewCoins( - sdk.NewInt64Coin("neuron", 0), - sdk.NewInt64Coin("ua0gi", 0), + sdk.NewInt64Coin(chaincfg.EvmDenom, 0), + sdk.NewInt64Coin(chaincfg.GasDenom, 0), ), false, }, { "errors if sending other coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 500), sdk.NewInt64Coin("busd", 1000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)), sdk.Coins{}, sdk.Coins{}, true, }, { - "errors if not enough total neuron to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("100000000001000")))), + "errors if not enough total evm denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_001_000)), sdk.Coins{}, sdk.Coins{}, true, }, { - "errors if not enough ua0gi to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("200000000000000")))), + "errors if not enough gas denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)), sdk.Coins{}, sdk.Coins{}, true, }, { - "converts receiver's neuron to ua0gi if there's enough neuron after the transfer", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("99000000000200")))), + "converts receiver's evm denom to gas denom if there's enough evm denom after the transfer", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_000_000_000_200)), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 999_999_999_900), - sdk.NewInt64Coin("ua0gi", 1), + sdk.NewInt64Coin(chaincfg.EvmDenom, 999_999_999_900), + sdk.NewInt64Coin(chaincfg.GasDenom, 1), ), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 100), - sdk.NewInt64Coin("ua0gi", 101), + sdk.NewInt64Coin(chaincfg.EvmDenom, 100), + sdk.NewInt64Coin(chaincfg.GasDenom, 101), ), false, }, { - "converts all of receiver's neuron to ua0gi even if somehow receiver has more than 1a0gi of neuron", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12000000000100")))), + "converts all of receiver's evm denom to gas denom even if somehow receiver has more than 1 gas denom of evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_100)), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 5_999_999_999_990), - sdk.NewInt64Coin("ua0gi", 1), + sdk.NewInt64Coin(chaincfg.EvmDenom, 5_999_999_999_990), + sdk.NewInt64Coin(chaincfg.GasDenom, 1), ), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 90), - sdk.NewInt64Coin("ua0gi", 19), + sdk.NewInt64Coin(chaincfg.EvmDenom, 90), + sdk.NewInt64Coin(chaincfg.GasDenom, 19), ), false, }, { - "swap 1 ua0gi for neuron if module account doesn't have enough neuron", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("99000000001000")))), + "swap 1 gas denom for evm denom if module account doesn't have enough evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_000_000_001_000)), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 200), - sdk.NewInt64Coin("ua0gi", 1), + sdk.NewInt64Coin(chaincfg.EvmDenom, 200), + sdk.NewInt64Coin(chaincfg.GasDenom, 1), ), sdk.NewCoins( - sdk.NewInt64Coin("neuron", 1200), - sdk.NewInt64Coin("ua0gi", 100), + sdk.NewInt64Coin(chaincfg.EvmDenom, 1200), + sdk.NewInt64Coin(chaincfg.GasDenom, 100), ), false, }, @@ -233,8 +237,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() { suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal) suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins) - // fund our module with some ua0gi to account for converting extra neuron back to ua0gi - suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10))) + // fund our module with some gas denom to account for converting extra evm denom back to gas denom + suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10))) err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins) if tt.hasErr { @@ -244,23 +248,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() { suite.Require().NoError(err) } - // check ua0gi - a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ua0gi") - suite.Require().Equal(tt.expAccBal.AmountOf("ua0gi").Int64(), a0giSender.Amount.Int64()) + // check gas denom + GasDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom) + suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64()) - // check neuron - actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) - suite.Require().Equal(tt.expAccBal.AmountOf("neuron").Int64(), actualNeuron.Int64()) + // check evm denom + actualEvmDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) + suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64()) }) } } + func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() { startingAccCoins := sdk.NewCoins( - sdk.NewInt64Coin("neuron", 200), - sdk.NewInt64Coin("ua0gi", 100), + sdk.NewInt64Coin(chaincfg.EvmDenom, 200), + sdk.NewInt64Coin(chaincfg.GasDenom, 100), ) startingModuleCoins := sdk.NewCoins( - sdk.NewInt64Coin("neuron", 100_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), ) tests := []struct { name string @@ -270,36 +275,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() { hasErr bool }{ { - "send more than 1 ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12000000000010")))), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 190), sdk.NewInt64Coin("ua0gi", 88)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100_000_000_010), sdk.NewInt64Coin("ua0gi", 12)), + "send more than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_010)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 190), sdk.NewInt64Coin(chaincfg.GasDenom, 88)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.GasDenom, 12)), false, }, { - "send less than 1 ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 122)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 78), sdk.NewInt64Coin("ua0gi", 100)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100_000_000_122), sdk.NewInt64Coin("ua0gi", 0)), + "send less than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 78), sdk.NewInt64Coin(chaincfg.GasDenom, 100)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.GasDenom, 0)), false, }, { - "send an exact amount of ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("98000000000000")))), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 200), sdk.NewInt64Coin("ua0gi", 2)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100_000_000_000), sdk.NewInt64Coin("ua0gi", 98)), + "send an exact amount of gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 2)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 98)), false, }, { - "send no neuron", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 0)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 200), sdk.NewInt64Coin("ua0gi", 100)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100_000_000_000), sdk.NewInt64Coin("ua0gi", 0)), + "send no evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 100)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 0)), false, }, { "errors if sending other coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 500), sdk.NewInt64Coin("busd", 1000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)), sdk.Coins{}, sdk.Coins{}, true, @@ -307,39 +312,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() { { "errors if have dup coins", sdk.Coins{ - sdk.NewInt64Coin("neuron", 12_000_000_000_000), - sdk.NewInt64Coin("neuron", 2_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000), }, sdk.Coins{}, sdk.Coins{}, true, }, { - "errors if not enough total neuron to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("100000000001000")))), + "errors if not enough total evm denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_001_000)), sdk.Coins{}, sdk.Coins{}, true, }, { - "errors if not enough ua0gi to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("200000000000000")))), + "errors if not enough gas denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)), sdk.Coins{}, sdk.Coins{}, true, }, { - "converts 1 ua0gi to neuron if not enough neuron to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("99001000000000")))), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 999_000_000_200), sdk.NewInt64Coin("ua0gi", 0)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 101_000_000_000), sdk.NewInt64Coin("ua0gi", 99)), + "converts 1 gas denom to evm denom if not enough evm denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_001_000_000_000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.GasDenom, 0)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 99)), false, }, { - "converts receiver's neuron to ua0gi if there's enough neuron after the transfer", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 5_900_000_000_200)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100_000_000_000), sdk.NewInt64Coin("ua0gi", 94)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 200), sdk.NewInt64Coin("ua0gi", 6)), + "converts receiver's evm denom to gas denom if there's enough evm denom after the transfer", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 5_900_000_000_200)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 94)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 6)), false, }, } @@ -359,66 +364,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() { } // check sender balance - a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ua0gi") - suite.Require().Equal(tt.expSenderCoins.AmountOf("ua0gi").Int64(), a0giSender.Amount.Int64()) - actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) - suite.Require().Equal(tt.expSenderCoins.AmountOf("neuron").Int64(), actualNeuron.Int64()) + GasDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom) + suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64()) + actualEvmDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) + suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64()) // check module balance moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName) - a0giSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, "ua0gi") - suite.Require().Equal(tt.expModuleCoins.AmountOf("ua0gi").Int64(), a0giSender.Amount.Int64()) - actualNeuron = suite.Keeper.GetBalance(suite.Ctx, moduleAddr) - suite.Require().Equal(tt.expModuleCoins.AmountOf("neuron").Int64(), actualNeuron.Int64()) + GasDenomSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.GasDenom) + suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64()) + actualEvmDenom = suite.Keeper.GetBalance(suite.Ctx, moduleAddr) + suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64()) }) } } + func (suite *evmBankKeeperTestSuite) TestBurnCoins() { - startingA0gi := sdkmath.NewInt(100) + startingGasDenom := sdkmath.NewInt(100) tests := []struct { - name string - burnCoins sdk.Coins - expA0gi sdkmath.Int - expNeuron sdkmath.Int - hasErr bool - neuronStart sdkmath.Int + name string + burnCoins sdk.Coins + expGasDenom sdkmath.Int + expEvmDenom sdkmath.Int + hasErr bool + evmDenomStart sdkmath.Int }{ { - "burn more than 1 ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12021000000002")))), + "burn more than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)), sdkmath.NewInt(88), sdkmath.NewInt(100_000_000_000), false, - sdk.NewIntFromBigInt(makeBigIntByString("121000000002")), + sdkmath.NewInt(121_000_000_002), }, { - "burn less than 1 ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 122)), + "burn less than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)), sdkmath.NewInt(100), sdkmath.NewInt(878), false, sdkmath.NewInt(1000), }, { - "burn an exact amount of ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("98000000000000")))), + "burn an exact amount of gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)), sdkmath.NewInt(2), sdkmath.NewInt(10), false, sdkmath.NewInt(10), }, { - "burn no neuron", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 0)), - startingA0gi, + "burn no evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)), + startingGasDenom, sdk.ZeroInt(), false, sdk.ZeroInt(), }, { "errors if burning other coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 500), sdk.NewInt64Coin("busd", 1000)), - startingA0gi, + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)), + startingGasDenom, sdkmath.NewInt(100), true, sdkmath.NewInt(100), @@ -426,41 +432,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() { { "errors if have dup coins", sdk.Coins{ - sdk.NewInt64Coin("neuron", 12_000_000_000_000), - sdk.NewInt64Coin("neuron", 2_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000), }, - startingA0gi, + startingGasDenom, sdk.ZeroInt(), true, sdk.ZeroInt(), }, { "errors if burn amount is negative", - sdk.Coins{sdk.Coin{Denom: "neuron", Amount: sdkmath.NewInt(-100)}}, - startingA0gi, + sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-100)}}, + startingGasDenom, sdkmath.NewInt(50), true, sdkmath.NewInt(50), }, { - "errors if not enough neuron to cover burn", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("100999000000000")))), + "errors if not enough evm denom to cover burn", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_999_000_000_000)), sdkmath.NewInt(0), sdkmath.NewInt(99_000_000_000), true, sdkmath.NewInt(99_000_000_000), }, { - "errors if not enough ua0gi to cover burn", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("200000000000000")))), + "errors if not enough gas denom to cover burn", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)), sdkmath.NewInt(100), sdk.ZeroInt(), true, sdk.ZeroInt(), }, { - "converts 1 ua0gi to neuron if not enough neuron to cover", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12021000000002")))), + "converts 1 gas denom to evm denom if not enough evm denom to cover", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)), sdkmath.NewInt(87), sdkmath.NewInt(980_000_000_000), false, @@ -472,8 +478,8 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() { suite.Run(tt.name, func() { suite.SetupTest() startingCoins := sdk.NewCoins( - sdk.NewCoin("ua0gi", startingA0gi), - sdk.NewCoin("neuron", tt.neuronStart), + sdk.NewCoin(chaincfg.GasDenom, startingGasDenom), + sdk.NewCoin(chaincfg.EvmDenom, tt.evmDenomStart), ) suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingCoins) @@ -485,52 +491,53 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() { suite.Require().NoError(err) } - // check ua0gi - a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ua0gi") - suite.Require().Equal(tt.expA0gi, a0giActual.Amount) + // check gas denom + GasDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.GasDenom) + suite.Require().Equal(tt.expGasDenom, GasDenomActual.Amount) - // check neuron - neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr) - suite.Require().Equal(tt.expNeuron, neuronActual) + // check evm denom + evmDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr) + suite.Require().Equal(tt.expEvmDenom, evmDenomActual) }) } } + func (suite *evmBankKeeperTestSuite) TestMintCoins() { tests := []struct { - name string - mintCoins sdk.Coins - ua0gi sdkmath.Int - neuron sdkmath.Int - hasErr bool - neuronStart sdkmath.Int + name string + mintCoins sdk.Coins + GasDenomCnt sdkmath.Int + evmDenomCnt sdkmath.Int + hasErr bool + evmDenomStart sdkmath.Int }{ { - "mint more than 1 ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12021000000002")))), + "mint more than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)), sdkmath.NewInt(12), sdkmath.NewInt(21_000_000_002), false, sdk.ZeroInt(), }, { - "mint less than 1 ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 901_000_000_001)), + "mint less than 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 901_000_000_001)), sdk.ZeroInt(), sdkmath.NewInt(901_000_000_001), false, sdk.ZeroInt(), }, { - "mint an exact amount of ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("123000000000000000")))), + "mint an exact amount of gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 123_000_000_000_000_000)), sdkmath.NewInt(123_000), sdk.ZeroInt(), false, sdk.ZeroInt(), }, { - "mint no neuron", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 0)), + "mint no evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)), sdk.ZeroInt(), sdk.ZeroInt(), false, @@ -538,7 +545,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() { }, { "errors if minting other coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 500), sdk.NewInt64Coin("busd", 1000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)), sdk.ZeroInt(), sdkmath.NewInt(100), true, @@ -547,8 +554,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() { { "errors if have dup coins", sdk.Coins{ - sdk.NewInt64Coin("neuron", 12_000_000_000_000), - sdk.NewInt64Coin("neuron", 2_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000), + sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000), }, sdk.ZeroInt(), sdk.ZeroInt(), @@ -557,35 +564,35 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() { }, { "errors if mint amount is negative", - sdk.Coins{sdk.Coin{Denom: "neuron", Amount: sdkmath.NewInt(-100)}}, + sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-100)}}, sdk.ZeroInt(), sdkmath.NewInt(50), true, sdkmath.NewInt(50), }, { - "adds to existing neuron balance", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("12021000000002")))), + "adds to existing evm denom balance", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)), sdkmath.NewInt(12), sdkmath.NewInt(21_000_000_102), false, sdkmath.NewInt(100), }, { - "convert neuron balance to ua0gi if it exceeds 1 ua0gi", - sdk.NewCoins(sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("10999000000000")))), + "convert evm denom balance to gas denom if it exceeds 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_999_000_000_000)), sdkmath.NewInt(12), sdkmath.NewInt(1_200_000_001), false, - sdkmath.NewIntFromBigInt(makeBigIntByString("1002200000001")), + sdkmath.NewInt(1_002_200_000_001), }, } for _, tt := range tests { suite.Run(tt.name, func() { suite.SetupTest() - suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10))) - suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin("neuron", tt.neuronStart))) + suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10))) + suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.EvmDenom, tt.evmDenomStart))) err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins) if tt.hasErr { @@ -595,13 +602,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() { suite.Require().NoError(err) } - // check ua0gi - a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ua0gi") - suite.Require().Equal(tt.ua0gi, a0giActual.Amount) + // check gas denom + GasDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.GasDenom) + suite.Require().Equal(tt.GasDenomCnt, GasDenomActual.Amount) - // check neuron - neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr) - suite.Require().Equal(tt.neuron, neuronActual) + // check evm denom + evmDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr) + suite.Require().Equal(tt.evmDenomCnt, evmDenomActual) }) } } @@ -614,22 +621,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() { }{ { "valid coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 500)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500)), false, }, { "dup coins", - sdk.Coins{sdk.NewInt64Coin("neuron", 500), sdk.NewInt64Coin("neuron", 500)}, + sdk.Coins{sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin(chaincfg.EvmDenom, 500)}, true, }, { "not evm coins", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 500)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 500)), true, }, { "negative coins", - sdk.Coins{sdk.Coin{Denom: "neuron", Amount: sdkmath.NewInt(-500)}}, + sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-500)}}, true, }, } @@ -645,8 +652,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() { } } -func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() { - neuronNeeded := sdkmath.NewInt(200) +func (suite *evmBankKeeperTestSuite) TestConvertOneGasDenomToEvmDenomIfNeeded() { + evmDenomNeeded := sdkmath.NewInt(200) tests := []struct { name string startingCoins sdk.Coins @@ -654,21 +661,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() { success bool }{ { - "not enough ua0gi for conversion", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100)), + "not enough gas denom for conversion", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)), false, }, { - "converts 1 ua0gi to neuron", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10), sdk.NewInt64Coin("neuron", 100)), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 9), sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("1000000000100")))), + "converts 1 gas denom to evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 100)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 9), sdk.NewInt64Coin(chaincfg.EvmDenom, 1_000_000_000_100)), true, }, { "conversion not needed", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10), sdk.NewInt64Coin("neuron", 200)), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10), sdk.NewInt64Coin("neuron", 200)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 200)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 200)), true, }, } @@ -677,11 +684,11 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() { suite.SetupTest() suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins) - err := suite.EvmBankKeeper.ConvertOneUa0giToNeuronIfNeeded(suite.Ctx, suite.Addrs[0], neuronNeeded) - moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), "ua0gi") + err := suite.EvmBankKeeper.ConvertOneGasDenomToEvmDenomIfNeeded(suite.Ctx, suite.Addrs[0], evmDenomNeeded) + moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.GasDenom) if tt.success { suite.Require().NoError(err) - if tt.startingCoins.AmountOf("neuron").LT(neuronNeeded) { + if tt.startingCoins.AmountOf(chaincfg.EvmDenom).LT(evmDenomNeeded) { suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount) } } else { @@ -689,52 +696,54 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() { suite.Require().Equal(sdk.ZeroInt(), moduleZgChain.Amount) } - neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) - suite.Require().Equal(tt.expectedCoins.AmountOf("neuron"), neuron) - ua0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ua0gi") - suite.Require().Equal(tt.expectedCoins.AmountOf("ua0gi"), ua0gi.Amount) + evmDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt) + GasDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount) }) } } -func (suite *evmBankKeeperTestSuite) TestConvertNeuronToA0gi() { + +func (suite *evmBankKeeperTestSuite) TestConvertEvmDenomToGasDenom() { tests := []struct { name string startingCoins sdk.Coins expectedCoins sdk.Coins }{ { - "not enough ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 100), sdk.NewInt64Coin("ua0gi", 0)), + "not enough gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100), sdk.NewInt64Coin(chaincfg.GasDenom, 0)), }, { - "converts neuron for 1 ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10), sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("1000000000003")))), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 11), sdk.NewInt64Coin("neuron", 3)), + "converts evm denom for 1 gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 1_000_000_000_003)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 11), sdk.NewInt64Coin(chaincfg.EvmDenom, 3)), }, { - "converts more than 1 ua0gi of neuron", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10), sdk.NewCoin("neuron", sdk.NewIntFromBigInt(makeBigIntByString("8000000000123")))), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 18), sdk.NewInt64Coin("neuron", 123)), + "converts more than 1 gas denom of evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 8_000_000_000_123)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 18), sdk.NewInt64Coin(chaincfg.EvmDenom, 123)), }, } for _, tt := range tests { suite.Run(tt.name, func() { suite.SetupTest() - err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 10))) + err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10))) suite.Require().NoError(err) suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins) - err = suite.EvmBankKeeper.ConvertNeuronToUa0gi(suite.Ctx, suite.Addrs[0]) + err = suite.EvmBankKeeper.ConvertEvmDenomToGasDenom(suite.Ctx, suite.Addrs[0]) suite.Require().NoError(err) - neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) - suite.Require().Equal(tt.expectedCoins.AmountOf("neuron"), neuron) - ua0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ua0gi") - suite.Require().Equal(tt.expectedCoins.AmountOf("ua0gi"), ua0gi.Amount) + evmDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0]) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt) + GasDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount) }) } } -func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() { + +func (suite *evmBankKeeperTestSuite) TestSplitEvmDenomCoins() { tests := []struct { name string coins sdk.Coins @@ -743,7 +752,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() { }{ { "invalid coins", - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 500)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 500)), nil, true, }, @@ -754,33 +763,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() { false, }, { - "ua0gi & neuron coins", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 8_000_000_000_123)), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 8), sdk.NewInt64Coin("neuron", 123)), + "gas denom & evm denom coins", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 8_000_000_000_123)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 8), sdk.NewInt64Coin(chaincfg.EvmDenom, 123)), false, }, { - "only neuron", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 10_123)), - sdk.NewCoins(sdk.NewInt64Coin("neuron", 10_123)), + "only evm denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_123)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_123)), false, }, { - "only ua0gi", - sdk.NewCoins(sdk.NewInt64Coin("neuron", 5_000_000_000_000)), - sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 5)), + "only gas denom", + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 5_000_000_000_000)), + sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 5)), false, }, } for _, tt := range tests { suite.Run(tt.name, func() { - ua0gi, neuron, err := keeper.SplitNeuronCoins(tt.coins) + GasDenomCoin, evmDenomCnt, err := keeper.SplitEvmDenomCoins(tt.coins) if tt.shouldErr { suite.Require().Error(err) } else { suite.Require().NoError(err) - suite.Require().Equal(tt.expectedCoins.AmountOf("ua0gi"), ua0gi.Amount) - suite.Require().Equal(tt.expectedCoins.AmountOf("neuron"), neuron) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount) + suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt) } }) } diff --git a/x/evmutil/keeper/invariants.go b/x/evmutil/keeper/invariants.go index 6b3a1db0..afbfbbf5 100644 --- a/x/evmutil/keeper/invariants.go +++ b/x/evmutil/keeper/invariants.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/types" ) @@ -50,7 +51,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant { }) bankAddr := authtypes.NewModuleAddress(types.ModuleName) - bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier) + bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.GasDenom).Amount.Mul(ConversionMultiplier) broken = totalMinorBalances.GT(bankBalance) diff --git a/x/evmutil/keeper/invariants_test.go b/x/evmutil/keeper/invariants_test.go index 4756b66c..79fc4474 100644 --- a/x/evmutil/keeper/invariants_test.go +++ b/x/evmutil/keeper/invariants_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/keeper" "github.com/0glabs/0g-chain/x/evmutil/testutil" "github.com/0glabs/0g-chain/x/evmutil/types" @@ -49,7 +50,7 @@ func (suite *invariantTestSuite) SetupValidState() { suite.FundModuleAccountWithZgChain( types.ModuleName, sdk.NewCoins( - sdk.NewCoin("ua0gi", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier + sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier ), ) @@ -159,8 +160,8 @@ func (suite *invariantTestSuite) TestSmallBalances() { // increase minor balance at least above conversion multiplier suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier) - // add same number of a0gi to avoid breaking other invariants - amt := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1)) + // add same number of gas denom to avoid breaking other invariants + amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 1)) suite.Require().NoError( suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt), ) diff --git a/x/evmutil/keeper/keeper.go b/x/evmutil/keeper/keeper.go index 967021c3..4c671071 100644 --- a/x/evmutil/keeper/keeper.go +++ b/x/evmutil/keeper/keeper.go @@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error { return nil } -// GetBalance returns the total balance of neuron for a given account by address. +// GetBalance returns the total balance of evm denom for a given account by address. func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int { account := k.GetAccount(ctx, addr) if account == nil { @@ -124,7 +124,7 @@ func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int { return account.Balance } -// SetBalance sets the total balance of neuron for a given account by address. +// SetBalance sets the total balance of evm denom for a given account by address. func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error { account := k.GetAccount(ctx, addr) if account == nil { @@ -140,10 +140,10 @@ func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int return k.SetAccount(ctx, *account) } -// SendBalance transfers the neuron balance from sender addr to recipient addr. +// SendBalance transfers the evm denom balance from sender addr to recipient addr. func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error { if amt.IsNegative() { - return fmt.Errorf("cannot send a negative amount of neuron: %d", amt) + return fmt.Errorf("cannot send a negative amount of evm denom: %d", amt) } if amt.IsZero() { @@ -162,13 +162,13 @@ func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipien return k.SetBalance(ctx, recipientAddr, receiverBal) } -// AddBalance increments the neuron balance of an address. +// AddBalance increments the evm denom balance of an address. func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error { bal := k.GetBalance(ctx, addr) return k.SetBalance(ctx, addr, amt.Add(bal)) } -// RemoveBalance decrements the neuron balance of an address. +// RemoveBalance decrements the evm denom balance of an address. func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error { if amt.IsNegative() { return fmt.Errorf("cannot remove a negative amount from balance: %d", amt) diff --git a/x/evmutil/testutil/suite.go b/x/evmutil/testutil/suite.go index 45080657..c51453a8 100644 --- a/x/evmutil/testutil/suite.go +++ b/x/evmutil/testutil/suite.go @@ -37,6 +37,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/0glabs/0g-chain/app" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/keeper" "github.com/0glabs/0g-chain/x/evmutil/types" ) @@ -81,14 +82,14 @@ func (suite *Suite) SetupTest() { suite.Addrs = addrs evmGenesis := evmtypes.DefaultGenesisState() - evmGenesis.Params.EvmDenom = keeper.EvmDenom + evmGenesis.Params.EvmDenom = chaincfg.EvmDenom feemarketGenesis := feemarkettypes.DefaultGenesisState() feemarketGenesis.Params.EnableHeight = 1 feemarketGenesis.Params.NoBaseFee = false cdc := suite.App.AppCodec() - coins := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1000_000_000_000)) + coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 1000_000_000_000_000_000)) authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{ sdk.AccAddress(suite.Key1.PubKey().Address()), sdk.AccAddress(suite.Key2.PubKey().Address()), @@ -185,28 +186,28 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int { } func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) { - ua0gi := coins.AmountOf("ua0gi") - if ua0gi.IsPositive() { - err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi))) + GasDenomAmt := coins.AmountOf(chaincfg.GasDenom) + if GasDenomAmt.IsPositive() { + err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, GasDenomAmt))) suite.Require().NoError(err) } - neuron := coins.AmountOf("neuron") - if neuron.IsPositive() { - err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron) + evmDenomAmt := coins.AmountOf(chaincfg.EvmDenom) + if evmDenomAmt.IsPositive() { + err := suite.Keeper.SetBalance(suite.Ctx, addr, evmDenomAmt) suite.Require().NoError(err) } } func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) { - ua0gi := coins.AmountOf("ua0gi") - if ua0gi.IsPositive() { - err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi))) + GasDenomAmt := coins.AmountOf(chaincfg.GasDenom) + if GasDenomAmt.IsPositive() { + err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, GasDenomAmt))) suite.Require().NoError(err) } - neuron := coins.AmountOf("neuron") - if neuron.IsPositive() { + evmDenomAmt := coins.AmountOf(chaincfg.EvmDenom) + if evmDenomAmt.IsPositive() { addr := suite.AccountKeeper.GetModuleAddress(moduleName) - err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron) + err := suite.Keeper.SetBalance(suite.Ctx, addr, evmDenomAmt) suite.Require().NoError(err) } } @@ -217,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress { suite.App.FundModuleAccount( suite.Ctx, types.ModuleName, - sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))), + sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(0))), ) contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18)) @@ -318,7 +319,7 @@ func (suite *Suite) SendTx( // Mint the max gas to the FeeCollector to ensure balance in case of refund suite.MintFeeCollector(sdk.NewCoins( sdk.NewCoin( - "ua0gi", + chaincfg.GasDenom, sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)), ))) diff --git a/x/evmutil/types/conversion_pair.pb.go b/x/evmutil/types/conversion_pair.pb.go index 50c8c784..dbf7295c 100644 --- a/x/evmutil/types/conversion_pair.pb.go +++ b/x/evmutil/types/conversion_pair.pb.go @@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // allowed to be converted between ERC20 and sdk.Coin type ConversionPair struct { // ERC20 address of the token on the 0gChain EVM - ZgChainERC20Address HexBytes `protobuf:"bytes,1,opt,name=zgChain_erc20_address,json=zgChainErc20Address,proto3,casttype=HexBytes" json:"zgChain_erc20_address,omitempty"` + ZgChainERC20Address HexBytes `protobuf:"bytes,1,opt,name=zgchain_erc20_address,json=zgchainErc20Address,proto3,casttype=HexBytes" json:"zgchain_erc20_address,omitempty"` // Denom of the corresponding sdk.Coin Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` } @@ -134,20 +134,20 @@ var fileDescriptor_6bad9d4ffa6874ec = []byte{ 0x62, 0xd2, 0xd5, 0xa9, 0x08, 0x67, 0x2c, 0x92, 0x9e, 0x08, 0xed, 0x09, 0xf1, 0x22, 0x6d, 0x12, 0x89, 0x58, 0xa0, 0xda, 0x92, 0x53, 0xad, 0x40, 0xb5, 0x02, 0x6d, 0xd4, 0xb9, 0xe0, 0x22, 0xdb, 0xeb, 0xe9, 0x94, 0xa3, 0xed, 0x67, 0x00, 0x0f, 0xcc, 0x9d, 0xe4, 0x8e, 0x78, 0x11, 0x7a, 0x80, - 0x87, 0x4b, 0x6e, 0x8e, 0x89, 0x17, 0xda, 0x2c, 0xa2, 0x3d, 0xc3, 0x26, 0xae, 0x1b, 0x31, 0x29, - 0x55, 0xd0, 0x02, 0x9d, 0xea, 0xe0, 0x34, 0x59, 0x37, 0x6b, 0xa3, 0x1c, 0x18, 0x5a, 0x66, 0xcf, - 0xe8, 0xe7, 0xeb, 0x9f, 0x75, 0xb3, 0x72, 0xc3, 0xe6, 0x83, 0x45, 0xcc, 0xa4, 0x55, 0x2b, 0x0c, - 0xc3, 0x54, 0x50, 0x00, 0xa8, 0x0e, 0xff, 0xb9, 0x2c, 0x14, 0x81, 0xfa, 0xa7, 0x05, 0x3a, 0xff, - 0xad, 0x3c, 0x5c, 0x95, 0x5e, 0xde, 0x9b, 0x4a, 0xfb, 0x15, 0xc0, 0xe3, 0xbe, 0xef, 0x8b, 0x27, - 0xe6, 0x9a, 0x42, 0x06, 0x42, 0x9a, 0xa2, 0xd0, 0xdf, 0x8b, 0x47, 0x16, 0xa2, 0x13, 0x58, 0xa5, - 0x59, 0x6f, 0xe7, 0x0a, 0x90, 0x29, 0xf6, 0xf2, 0xee, 0x3a, 0xad, 0x10, 0x82, 0xa5, 0x90, 0x04, - 0xac, 0xb0, 0x67, 0x33, 0x3a, 0x82, 0x65, 0xb9, 0x08, 0x1c, 0xe1, 0xab, 0x7f, 0xb3, 0xb6, 0x48, - 0xa8, 0x01, 0x2b, 0x2e, 0xa3, 0x5e, 0x40, 0x7c, 0xa9, 0x96, 0x5a, 0xa0, 0xb3, 0x6f, 0xed, 0x72, - 0x7e, 0xa0, 0xc1, 0xed, 0xe6, 0x1b, 0x83, 0x8f, 0x04, 0x83, 0xcf, 0x04, 0x83, 0x55, 0x82, 0xc1, - 0x26, 0xc1, 0xe0, 0x6d, 0x8b, 0x95, 0xd5, 0x16, 0x2b, 0x5f, 0x5b, 0xac, 0x8c, 0xce, 0xb9, 0x17, - 0x8f, 0xa7, 0x8e, 0x46, 0x45, 0xa0, 0x1b, 0xdc, 0x27, 0x8e, 0xd4, 0x0d, 0x7e, 0x41, 0xd3, 0x6b, - 0xeb, 0xf3, 0xdd, 0x4f, 0xc5, 0x8b, 0x09, 0x93, 0x4e, 0x39, 0x7b, 0xed, 0xcb, 0xdf, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x25, 0x71, 0x3e, 0xe1, 0xc5, 0x01, 0x00, 0x00, + 0x87, 0x4b, 0x4e, 0xc7, 0xc4, 0x0b, 0x6d, 0x16, 0xd1, 0x9e, 0x61, 0x13, 0xd7, 0x8d, 0x98, 0x94, + 0x2a, 0x68, 0x81, 0x4e, 0x75, 0x70, 0x9a, 0xac, 0x9b, 0xb5, 0x11, 0x37, 0x53, 0x60, 0x68, 0x99, + 0x3d, 0xa3, 0x9f, 0xaf, 0x7f, 0xd6, 0xcd, 0xca, 0x0d, 0x9b, 0x0f, 0x16, 0x31, 0x93, 0x56, 0xad, + 0x30, 0x0c, 0x53, 0x41, 0x01, 0xa0, 0x3a, 0xfc, 0xe7, 0xb2, 0x50, 0x04, 0xea, 0x9f, 0x16, 0xe8, + 0xfc, 0xb7, 0xf2, 0x70, 0x55, 0x7a, 0x79, 0x6f, 0x2a, 0xed, 0x57, 0x00, 0x8f, 0xfb, 0xbe, 0x2f, + 0x9e, 0x98, 0x6b, 0x0a, 0x19, 0x08, 0x69, 0x8a, 0x42, 0x7f, 0x2f, 0x1e, 0x59, 0x88, 0x4e, 0x60, + 0x95, 0x66, 0xbd, 0x9d, 0x2b, 0x40, 0xa6, 0xd8, 0xcb, 0xbb, 0xeb, 0xb4, 0x42, 0x08, 0x96, 0x42, + 0x12, 0xb0, 0xc2, 0x9e, 0xcd, 0xe8, 0x08, 0x96, 0xe5, 0x22, 0x70, 0x84, 0xaf, 0xfe, 0xcd, 0xda, + 0x22, 0xa1, 0x06, 0xac, 0xb8, 0x8c, 0x7a, 0x01, 0xf1, 0xa5, 0x5a, 0x6a, 0x81, 0xce, 0xbe, 0xb5, + 0xcb, 0xf9, 0x81, 0x06, 0xb7, 0x9b, 0x6f, 0x0c, 0x3e, 0x12, 0x0c, 0x3e, 0x13, 0x0c, 0x56, 0x09, + 0x06, 0x9b, 0x04, 0x83, 0xb7, 0x2d, 0x56, 0x56, 0x5b, 0xac, 0x7c, 0x6d, 0xb1, 0x32, 0x3a, 0xe7, + 0x5e, 0x3c, 0x9e, 0x3a, 0x1a, 0x15, 0x81, 0x6e, 0x70, 0x9f, 0x38, 0x52, 0x37, 0xf8, 0x45, 0x76, + 0x6d, 0x7d, 0xbe, 0xfb, 0xa9, 0x78, 0x31, 0x61, 0xd2, 0x29, 0x67, 0xaf, 0x7d, 0xf9, 0x1b, 0x00, + 0x00, 0xff, 0xff, 0xfa, 0x07, 0x29, 0xab, 0xc5, 0x01, 0x00, 0x00, } func (this *ConversionPair) VerboseEqual(that interface{}) error { diff --git a/x/evmutil/types/conversion_pairs_test.go b/x/evmutil/types/conversion_pairs_test.go index 0db238f5..0a60e889 100644 --- a/x/evmutil/types/conversion_pairs_test.go +++ b/x/evmutil/types/conversion_pairs_test.go @@ -3,6 +3,7 @@ package types_test import ( "testing" + "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/evmutil/testutil" "github.com/0glabs/0g-chain/x/evmutil/types" "github.com/stretchr/testify/require" @@ -142,7 +143,7 @@ func TestConversionPairs_Validate(t *testing.T) { ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"), - "a0gi", + chaincfg.GasDenom, ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"), @@ -162,7 +163,7 @@ func TestConversionPairs_Validate(t *testing.T) { ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), - "a0gi", + chaincfg.GasDenom, ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"), @@ -183,16 +184,16 @@ func TestConversionPairs_Validate(t *testing.T) { ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"), - "a0gi", + chaincfg.GasDenom, ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"), - "a0gi", + chaincfg.GasDenom, ), ), errArgs{ expectPass: false, - contains: "found duplicate enabled conversion pair denom a0gi", + contains: "found duplicate enabled conversion pair denom " + chaincfg.GasDenom, }, }, { @@ -208,7 +209,7 @@ func TestConversionPairs_Validate(t *testing.T) { ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"), - "a0gi", + chaincfg.GasDenom, ), ), errArgs{ @@ -240,12 +241,12 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) { }{ { name: "valid token", - token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 6), + token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 6), expErr: "", }, { name: "valid - highest allowed decimals", - token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 255), + token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 255), expErr: "", }, { @@ -280,7 +281,7 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) { }, { name: "invalid - decimals higher than uint8", - token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 256), + token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 256), expErr: "decimals must be less than 256", }, } diff --git a/x/evmutil/types/params_test.go b/x/evmutil/types/params_test.go index 8daabd0a..9daa04e1 100644 --- a/x/evmutil/types/params_test.go +++ b/x/evmutil/types/params_test.go @@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() { invalidConversionPairs := types.NewConversionPairs( types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"), - "a0gi", + chaincfg.GasDenom, ), types.NewConversionPair( testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"), - "a0gi", // duplicate denom! + chaincfg.GasDenom, // duplicate denom! ), ) validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens( diff --git a/x/evmutil/types/tx.pb.go b/x/evmutil/types/tx.pb.go index 99dc6193..f4c54584 100644 --- a/x/evmutil/types/tx.pb.go +++ b/x/evmutil/types/tx.pb.go @@ -31,7 +31,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgConvertCoinToERC20 defines a conversion from sdk.Coin to 0g-chain ERC20 for EVM-native assets. +// MsgConvertCoinToERC20 defines a conversion from sdk.Coin to 0gChain ERC20 for EVM-native assets. type MsgConvertCoinToERC20 struct { // 0gChain bech32 address initiating the conversion. Initiator string `protobuf:"bytes,1,opt,name=initiator,proto3" json:"initiator,omitempty"` @@ -139,7 +139,7 @@ type MsgConvertERC20ToCoin struct { // 0gChain bech32 address that will receive the converted sdk.Coin. Receiver string `protobuf:"bytes,2,opt,name=receiver,proto3" json:"receiver,omitempty"` // EVM 0x hex address of the ERC20 contract. - ZgChainERC20Address string `protobuf:"bytes,3,opt,name=zgChain_erc20_address,json=zgChainErc20Address,proto3" json:"zgChain_erc20_address,omitempty"` + ZgChainERC20Address string `protobuf:"bytes,3,opt,name=zgchain_erc20_address,json=zgchainErc20Address,proto3" json:"zgchain_erc20_address,omitempty"` // ERC20 token amount to convert. Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` } @@ -452,7 +452,7 @@ func init() { func init() { proto.RegisterFile("zgc/evmutil/v1beta1/tx.proto", fileDescriptor_b60fa1a7a6ac0cc3) } var fileDescriptor_b60fa1a7a6ac0cc3 = []byte{ - // 563 bytes of a gzipped FileDescriptorProto + // 564 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xc1, 0x6e, 0xd3, 0x30, 0x18, 0xae, 0xb7, 0x69, 0xa2, 0xe6, 0x96, 0x6e, 0xa2, 0x0b, 0x23, 0x9d, 0x8a, 0x06, 0xd3, 0xa4, 0x26, 0x69, 0x40, 0x08, 0x21, 0x2e, 0xb4, 0x1a, 0xd2, 0x04, 0xbb, 0x84, 0x9e, 0x76, 0xa9, 0x92, @@ -471,24 +471,24 @@ var fileDescriptor_b60fa1a7a6ac0cc3 = []byte{ 0x6c, 0xdd, 0xb5, 0xd6, 0x74, 0x99, 0x2d, 0xf2, 0x93, 0x9a, 0xd4, 0x23, 0x15, 0xb6, 0x04, 0x36, 0x1b, 0xf0, 0x41, 0xa1, 0x3e, 0x1b, 0xf1, 0x21, 0xa3, 0x1c, 0x35, 0xbf, 0x2c, 0xe4, 0x1d, 0xc4, 0xb1, 0x1e, 0x8b, 0x80, 0xca, 0xfa, 0x5f, 0x0e, 0xf2, 0x3a, 0x9f, 0x5e, 0xd5, 0x59, 0x62, 0xef, - 0xd2, 0xc1, 0x1b, 0xb8, 0x3a, 0xc1, 0xdd, 0x03, 0x87, 0xd0, 0x3e, 0x0a, 0x3c, 0xcb, 0xec, 0x3b, - 0x09, 0x30, 0x36, 0x54, 0xed, 0xdc, 0x0b, 0xa7, 0x8d, 0xda, 0x7e, 0x02, 0x88, 0xa5, 0xc8, 0x3c, - 0x76, 0x4d, 0xb2, 0x76, 0x22, 0x92, 0xdc, 0x54, 0x7a, 0x59, 0x39, 0x96, 0x62, 0xf6, 0xcb, 0xd3, - 0x69, 0xa3, 0xf2, 0x73, 0xda, 0x78, 0x84, 0x89, 0x38, 0x18, 0xb9, 0xba, 0xc7, 0x7c, 0x79, 0x87, - 0xf2, 0xa7, 0xc5, 0x07, 0xef, 0x0d, 0xf1, 0x61, 0x88, 0xb8, 0xbe, 0x4b, 0xc5, 0xf9, 0x49, 0x0b, - 0x4a, 0xb9, 0xbb, 0x54, 0x14, 0x57, 0x2c, 0x57, 0x8f, 0xac, 0x62, 0x9f, 0x01, 0xbc, 0x9f, 0xaf, - 0x69, 0x94, 0x21, 0x7f, 0xf3, 0xe5, 0x75, 0xfb, 0xcf, 0xf7, 0xbb, 0x09, 0x1f, 0x96, 0x68, 0xc9, - 0x34, 0x1f, 0x83, 0x3f, 0xfb, 0x20, 0xc5, 0xbd, 0x0e, 0x98, 0x7f, 0x0b, 0xaa, 0x1f, 0xc3, 0xcd, - 0x52, 0x35, 0xa9, 0x6e, 0xeb, 0xd3, 0x12, 0x5c, 0xdc, 0xe3, 0x58, 0x11, 0x50, 0x29, 0x98, 0xb1, - 0x6d, 0xbd, 0x60, 0xc8, 0xf5, 0xc2, 0x7e, 0x57, 0xad, 0xeb, 0x63, 0xd3, 0xd3, 0x73, 0xa7, 0xe6, - 0xe7, 0x62, 0xde, 0xa9, 0x39, 0xec, 0xdc, 0x53, 0x0b, 0xfa, 0x4b, 0xf9, 0x08, 0x60, 0xfd, 0x9f, - 0xcd, 0x65, 0xce, 0xb5, 0x71, 0x85, 0xa1, 0x3e, 0xbf, 0x29, 0x23, 0x13, 0x72, 0x0c, 0xa0, 0x5a, - 0xd2, 0x31, 0xd6, 0xb5, 0x13, 0x67, 0x1c, 0xf5, 0xc5, 0xcd, 0x39, 0xa9, 0x9c, 0xce, 0xdb, 0x8b, - 0x5f, 0x1a, 0xf8, 0x1e, 0x6a, 0xe0, 0x34, 0xd4, 0xc0, 0x59, 0xa8, 0x81, 0x8b, 0x50, 0x03, 0x5f, - 0x67, 0x5a, 0xe5, 0x6c, 0xa6, 0x55, 0x7e, 0xcc, 0xb4, 0xca, 0xfe, 0x76, 0x6e, 0xf0, 0x4d, 0x7c, - 0xe8, 0xb8, 0xdc, 0x30, 0x71, 0xcb, 0x8b, 0x1e, 0x0e, 0xe3, 0x28, 0xfb, 0x54, 0xc4, 0x0f, 0x80, - 0xbb, 0x1c, 0x3f, 0xe0, 0x4f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x6e, 0x5d, 0x0b, 0x0a, 0x46, - 0x06, 0x00, 0x00, + 0xd2, 0xc1, 0x1b, 0xb8, 0x3a, 0xc1, 0xde, 0x81, 0x43, 0x68, 0x1f, 0x05, 0x9e, 0x65, 0xf6, 0x9d, + 0x04, 0x18, 0x1b, 0xaa, 0x76, 0xee, 0x85, 0xd3, 0x46, 0x6d, 0x1f, 0x77, 0x23, 0x40, 0x2c, 0x45, + 0xe6, 0xb1, 0x6b, 0x92, 0xb5, 0x13, 0x91, 0xe4, 0xa6, 0xd2, 0xcb, 0xca, 0xb1, 0x14, 0xb3, 0x5f, + 0x9e, 0x4e, 0x1b, 0x95, 0x9f, 0xd3, 0xc6, 0x23, 0x4c, 0xc4, 0xc1, 0xc8, 0xd5, 0x3d, 0xe6, 0xcb, + 0x3b, 0x94, 0x3f, 0x2d, 0x3e, 0x78, 0x6f, 0x88, 0x0f, 0x43, 0xc4, 0xf5, 0x5d, 0x2a, 0xce, 0x4f, + 0x5a, 0x50, 0xca, 0xdd, 0xa5, 0xa2, 0xb8, 0x62, 0xb9, 0x7a, 0x64, 0x15, 0xfb, 0x0c, 0xe0, 0xfd, + 0x7c, 0x4d, 0xa3, 0x0c, 0xf9, 0x9b, 0x2f, 0xaf, 0xdb, 0x7f, 0xbe, 0xdf, 0x4d, 0xf8, 0xb0, 0x44, + 0x4b, 0xa6, 0xf9, 0x18, 0xfc, 0xd9, 0x07, 0x29, 0xee, 0x75, 0xc0, 0xfc, 0x5b, 0x50, 0xfd, 0x18, + 0x6e, 0x96, 0xaa, 0x49, 0x75, 0x5b, 0x9f, 0x96, 0xe0, 0xe2, 0x1e, 0xc7, 0x8a, 0x80, 0x4a, 0xc1, + 0x8c, 0x6d, 0xeb, 0x05, 0x43, 0xae, 0x17, 0xf6, 0xbb, 0x6a, 0x5d, 0x1f, 0x9b, 0x9e, 0x9e, 0x3b, + 0x35, 0x3f, 0x17, 0xf3, 0x4e, 0xcd, 0x61, 0xe7, 0x9e, 0x5a, 0xd0, 0x5f, 0xca, 0x47, 0x00, 0xeb, + 0xff, 0x6c, 0x2e, 0x73, 0xae, 0x8d, 0x2b, 0x0c, 0xf5, 0xf9, 0x4d, 0x19, 0x99, 0x90, 0x63, 0x00, + 0xd5, 0x92, 0x8e, 0xb1, 0xae, 0x9d, 0x38, 0xe3, 0xa8, 0x2f, 0x6e, 0xce, 0x49, 0xe5, 0x74, 0xde, + 0x5e, 0xfc, 0xd2, 0xc0, 0xf7, 0x50, 0x03, 0xa7, 0xa1, 0x06, 0xce, 0x42, 0x0d, 0x5c, 0x84, 0x1a, + 0xf8, 0x3a, 0xd3, 0x2a, 0x67, 0x33, 0xad, 0xf2, 0x63, 0xa6, 0x55, 0xf6, 0xb7, 0x73, 0x83, 0x6f, + 0xe2, 0x43, 0xc7, 0xe5, 0x86, 0x89, 0x5b, 0xf1, 0xc3, 0x61, 0x1c, 0x65, 0x9f, 0x8a, 0xf8, 0x01, + 0x70, 0x97, 0xe3, 0x07, 0xfc, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xc2, 0xb2, 0xda, + 0x46, 0x06, 0x00, 0x00, } func (this *MsgConvertCoinToERC20) VerboseEqual(that interface{}) error { diff --git a/x/pricefeed/types/key_test.go b/x/pricefeed/types/key_test.go index f5eca1ba..ef537900 100644 --- a/x/pricefeed/types/key_test.go +++ b/x/pricefeed/types/key_test.go @@ -3,13 +3,14 @@ package types import ( "testing" + "github.com/0glabs/0g-chain/chaincfg" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) func TestRawPriceKey_Iteration(t *testing.T) { // An iterator key should only match price keys with the same market - iteratorKey := RawPriceIteratorKey("a0gi:usd") + iteratorKey := RawPriceIteratorKey(chaincfg.GasDenom + ":usd") addr := sdk.AccAddress("test addr") @@ -20,12 +21,12 @@ func TestRawPriceKey_Iteration(t *testing.T) { }{ { name: "equal marketID is included in iteration", - priceKey: RawPriceKey("a0gi:usd", addr), + priceKey: RawPriceKey(chaincfg.GasDenom+":usd", addr), expectErr: false, }, { name: "prefix overlapping marketID excluded from iteration", - priceKey: RawPriceKey("a0gi:usd:30", addr), + priceKey: RawPriceKey(chaincfg.GasDenom+":usd:30", addr), expectErr: true, }, }