diff --git a/precompiles/bank/method_deposit.go b/precompiles/bank/method_deposit.go index 60f166de97..1d5792d8a3 100644 --- a/precompiles/bank/method_deposit.go +++ b/precompiles/bank/method_deposit.go @@ -92,8 +92,8 @@ func (c *Contract) deposit( // The process of creating a new cosmos coin is: // - Generate the new coin denom using ZRC20 address, // this way we map ZRC20 addresses to cosmos denoms "zevm/0x12345". - // - Mint coins. - // - Send coins to the caller. + // - Mint coins to the fungible module. + // - Send coins from fungible to the caller. coinSet, err := createCoinSet(ZRC20ToCosmosDenom(zrc20Addr), amount) if err != nil { return nil, err diff --git a/precompiles/bank/method_test.go b/precompiles/bank/method_test.go index 8921c787af..e2eda3237d 100644 --- a/precompiles/bank/method_test.go +++ b/precompiles/bank/method_test.go @@ -28,7 +28,7 @@ import ( func Test_Methods(t *testing.T) { t.Run("should fail when trying to run deposit as read only method", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM methodID := ts.bankABI.Methods[DepositMethodName] // Set CallerAddress and evm.Origin to the caller address. @@ -55,7 +55,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when trying to run withdraw as read only method", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM methodID := ts.bankABI.Methods[WithdrawMethodName] // Set CallerAddress and evm.Origin to the caller address. @@ -82,7 +82,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when caller has 0 token balance", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM methodID := ts.bankABI.Methods[DepositMethodName] // Set CallerAddress and evm.Origin to the caller address. @@ -116,7 +116,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when bank has 0 token allowance", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) methodID := ts.bankABI.Methods[DepositMethodName] @@ -146,7 +146,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when trying to deposit 0", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) methodID := ts.bankABI.Methods[DepositMethodName] @@ -173,7 +173,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when trying to deposit more than allowed to bank", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) // Allow bank to spend 500 ZRC20 tokens. @@ -225,7 +225,7 @@ func Test_Methods(t *testing.T) { t.Run("should fail when trying to deposit more than user balance", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) // Allow bank to spend 500 ZRC20 tokens. @@ -279,7 +279,7 @@ func Test_Methods(t *testing.T) { t.Run("should deposit tokens and retrieve balance of cosmos coin", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) methodID := ts.bankABI.Methods[DepositMethodName] @@ -325,7 +325,7 @@ func Test_Methods(t *testing.T) { t.Run("should deposit tokens, withdraw and check with balanceOf", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) methodID := ts.bankABI.Methods[DepositMethodName] @@ -404,7 +404,7 @@ func Test_Methods(t *testing.T) { t.Run("should deposit tokens and fail when withdrawing more than depositted", func(t *testing.T) { ts := setupChain(t) - caller := fungibletypes.ModuleAddressZEVM + caller := fungibletypes.ModuleAddressEVM ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000)) methodID := ts.bankABI.Methods[DepositMethodName] @@ -573,7 +573,7 @@ func allowBank(t *testing.T, ts testSuite, amount *big.Int) { ts.ctx, ts.fungibleKeeper, &ts.zrc20ABI, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, ts.zrc20Address, "approve", []interface{}{ts.bankContract.Address(), amount}, diff --git a/x/fungible/keeper/zrc20_cosmos_coin_mapping_test.go b/x/fungible/keeper/zrc20_cosmos_coin_mapping_test.go index 941b81e98c..16803a917c 100644 --- a/x/fungible/keeper/zrc20_cosmos_coin_mapping_test.go +++ b/x/fungible/keeper/zrc20_cosmos_coin_mapping_test.go @@ -22,7 +22,7 @@ func Test_LockZRC20(t *testing.T) { ts := setupChain(t) - owner := fungibletypes.ModuleAddressZEVM + owner := fungibletypes.ModuleAddressEVM locker := sample.EthAddress() depositTotal := big.NewInt(1000) allowanceTotal := big.NewInt(100) @@ -148,7 +148,7 @@ func Test_UnlockZRC20(t *testing.T) { ts := setupChain(t) - owner := fungibletypes.ModuleAddressZEVM + owner := fungibletypes.ModuleAddressEVM locker := sample.EthAddress() depositTotal := big.NewInt(1000) allowanceTotal := big.NewInt(100) @@ -217,7 +217,7 @@ func Test_CheckZRC20Allowance(t *testing.T) { ts := setupChain(t) - owner := fungibletypes.ModuleAddressZEVM + owner := fungibletypes.ModuleAddressEVM spender := sample.EthAddress() depositTotal := big.NewInt(1000) allowanceTotal := big.NewInt(100) @@ -229,7 +229,7 @@ func Test_CheckZRC20Allowance(t *testing.T) { ts.fungibleKeeper.GetAuthKeeper().SetAccount(ts.ctx, authtypes.NewBaseAccount(accAddress, nil, 0, 0)) // Deposit ZRC20 tokens into the fungible. - ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressZEVM, depositTotal) + ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressEVM, depositTotal) t.Run("should fail when checking zero amount", func(t *testing.T) { err = ts.fungibleKeeper.CheckZRC20Allowance(ts.ctx, zrc20ABI, owner, spender, ts.zrc20Address, big.NewInt(0)) diff --git a/x/fungible/keeper/zrc20_methods.go b/x/fungible/keeper/zrc20_methods.go index a90cc511bb..5c9f2d4645 100644 --- a/x/fungible/keeper/zrc20_methods.go +++ b/x/fungible/keeper/zrc20_methods.go @@ -45,7 +45,7 @@ func (k Keeper) ZRC20Allowance( res, err := k.CallEVM( ctx, *zrc20ABI, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, zrc20Address, big.NewInt(0), nil, @@ -101,7 +101,7 @@ func (k Keeper) ZRC20BalanceOf( res, err := k.CallEVM( ctx, *zrc20ABI, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, zrc20Address, big.NewInt(0), nil, @@ -153,7 +153,7 @@ func (k Keeper) ZRC20TotalSupply( res, err := k.CallEVM( ctx, *zrc20ABI, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, zrc20Address, big.NewInt(0), nil, diff --git a/x/fungible/keeper/zrc20_methods_test.go b/x/fungible/keeper/zrc20_methods_test.go index a5010c332a..7b124f3050 100644 --- a/x/fungible/keeper/zrc20_methods_test.go +++ b/x/fungible/keeper/zrc20_methods_test.go @@ -57,7 +57,7 @@ func Test_ZRC20Allowance(t *testing.T) { zrc20ABI, common.Address{}, sample.EthAddress(), - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, ) require.Error(t, err) require.ErrorAs(t, err, &fungibletypes.ErrZRC20ZeroAddress) @@ -68,7 +68,7 @@ func Test_ZRC20Allowance(t *testing.T) { ts.ctx, zrc20ABI, ts.zrc20Address, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, sample.EthAddress(), ) require.NoError(t, err) @@ -107,7 +107,7 @@ func Test_ZRC20BalanceOf(t *testing.T) { ts.ctx, zrc20ABI, ts.zrc20Address, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, ) require.NoError(t, err) require.Equal(t, uint64(0), balance.Uint64()) @@ -198,7 +198,7 @@ func Test_ZRC20Transfer(t *testing.T) { zrc20ABI, common.Address{}, sample.EthAddress(), - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, big.NewInt(0), ) require.Error(t, err) @@ -206,12 +206,12 @@ func Test_ZRC20Transfer(t *testing.T) { }) t.Run("should pass with correct input", func(t *testing.T) { - ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressZEVM, big.NewInt(10)) + ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressEVM, big.NewInt(10)) transferred, err := ts.fungibleKeeper.ZRC20Transfer( ts.ctx, zrc20ABI, ts.zrc20Address, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, sample.EthAddress(), big.NewInt(10), ) @@ -295,7 +295,7 @@ func Test_ZRC20TransferFrom(t *testing.T) { common.Address{}, sample.EthAddress(), sample.EthAddress(), - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, big.NewInt(0), ) require.Error(t, err) @@ -304,16 +304,16 @@ func Test_ZRC20TransferFrom(t *testing.T) { t.Run("should fail without an allowance approval", func(t *testing.T) { // Deposit ZRC20 into fungible EOA. - ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressZEVM, big.NewInt(1000)) + ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressEVM, big.NewInt(1000)) // Transferring the tokens with transferFrom without approval should fail. _, err = ts.fungibleKeeper.ZRC20TransferFrom( ts.ctx, zrc20ABI, ts.zrc20Address, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, sample.EthAddress(), - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, big.NewInt(10), ) require.Error(t, err) @@ -321,19 +321,19 @@ func Test_ZRC20TransferFrom(t *testing.T) { t.Run("should success with an allowance approval", func(t *testing.T) { // Deposit ZRC20 into fungible EOA. - ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressZEVM, big.NewInt(1000)) + ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, fungibletypes.ModuleAddressEVM, big.NewInt(1000)) // Approve allowance to sample.EthAddress() to spend 10 ZRC20 tokens. - approveAllowance(t, ts, zrc20ABI, fungibletypes.ModuleAddressZEVM, sample.EthAddress(), big.NewInt(10)) + approveAllowance(t, ts, zrc20ABI, fungibletypes.ModuleAddressEVM, sample.EthAddress(), big.NewInt(10)) // Transferring the tokens with transferFrom without approval should fail. _, err = ts.fungibleKeeper.ZRC20TransferFrom( ts.ctx, zrc20ABI, ts.zrc20Address, - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, sample.EthAddress(), - fungibletypes.ModuleAddressZEVM, + fungibletypes.ModuleAddressEVM, big.NewInt(10), ) require.Error(t, err) diff --git a/x/fungible/types/keys.go b/x/fungible/types/keys.go index 339cc63560..4c02d9c2ef 100644 --- a/x/fungible/types/keys.go +++ b/x/fungible/types/keys.go @@ -29,10 +29,6 @@ func KeyPrefix(p string) []byte { var ( ModuleAddress = authtypes.NewModuleAddress(ModuleName) ModuleAddressEVM = common.BytesToAddress(ModuleAddress.Bytes()) - // ModuleAddressZEVM is calculated in the same way as ModuleAddressEVM. - // Maintain it for legibility in functions calling fungible module address from zEVM. - ModuleAddressZEVM = common.BytesToAddress(ModuleAddress.Bytes()) - AdminAddress = "zeta1rx9r8hff0adaqhr5tuadkzj4e7ns2ntg446vtt" ) const (