From be4d236b96fde104bb8b97f5a020b6c4a6b5549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:28:09 +0100 Subject: [PATCH 1/2] feat(werc20): WERC20 transactions --- precompiles/werc20/tx.go | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/precompiles/werc20/tx.go b/precompiles/werc20/tx.go index cf5bea0572..a50de990c0 100644 --- a/precompiles/werc20/tx.go +++ b/precompiles/werc20/tx.go @@ -3,6 +3,12 @@ package werc20 +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/core/vm" +) + const ( // DepositMethod defines the ABI method name for the IWERC20 deposit // transaction. @@ -11,3 +17,43 @@ const ( // transaction. WithdrawMethod = "withdraw" ) + +// Deposit is a no-op and mock function that provides the same interface as the +// WETH contract to support equality between the native coin and its wrapped +// ERC-20 (eg. EVMOS and WEVMOS). It only emits the Deposit event. +func (p Precompile) Deposit( + ctx sdk.Context, + contract *vm.Contract, + stateDB vm.StateDB, + _ *abi.Method, + _ []interface{}, +) ([]byte, error) { + dst := contract.Caller() + amount := contract.Value() + + if err := p.EmitDepositEvent(ctx, stateDB, dst, amount); err != nil { + return nil, err + } + + return nil, nil +} + +// Withdraw is a no-op and mock function that provides the same interface as the +// WETH contract to support equality between the native coin and its wrapped +// ERC-20 (eg. EVMOS and WEVMOS). It only emits the Withdraw event. +func (p Precompile) Withdraw( + ctx sdk.Context, + contract *vm.Contract, + stateDB vm.StateDB, + _ *abi.Method, + _ []interface{}, +) ([]byte, error) { + src := contract.Caller() + amount := contract.Value() + + if err := p.EmitWithdrawEvent(ctx, stateDB, src, amount); err != nil { + return nil, err + } + + return nil, nil +} From 30e93c9ba79530f08b94cd0fd46c311b693b1c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:29:41 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 830195224a..e3f4bf7295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features - (p256) [#1922](https://github.com/evmos/evmos/pull/1922) [EIP-7212](https://eips.ethereum.org/EIPS/eip-7212) `secp256r1` curve precompile +- (werc20) [#1991](https://github.com/evmos/evmos/pull/1991) Add WERC-20 Precompile transactions. ### Improvements