Skip to content

Commit

Permalink
Merge pull request #22 from eosnetworkfoundation/elmato/add-token-dep…
Browse files Browse the repository at this point in the history
…osit-proxy

Address review comments in PR #21
  • Loading branch information
elmato authored Sep 11, 2023
2 parents baec916 + 5368174 commit 9af59ee
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(evm_bridge_contracts)

if(NOT DEFINED eosevm_DIR)
message(FATAL_ERROR "The `eosevm_DIR` argument was not provided!")
endif()

set(EXTERNAL_DIR ${CMAKE_SOURCE_DIR}/external)
set(SOLIDITY_BYTECODES_DIR ${CMAKE_BINARY_DIR}/solidity_contracts/bytecodes)

Expand Down
2 changes: 2 additions & 0 deletions antelope_contracts/contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(evm_bridge_antelope_contracts)

find_package(cdt REQUIRED)

add_compile_definitions(ANTELOPE)

add_subdirectory(erc20)
add_subdirectory(stubs)
add_subdirectory(deposit_proxy)
1 change: 0 additions & 1 deletion antelope_contracts/contracts/deposit_proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_contract( deposit_proxy deposit_proxy src/deposit_proxy.cpp )
target_include_directories( deposit_proxy PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include )
target_ricardian_directory( deposit_proxy ${CMAKE_CURRENT_SOURCE_DIR}/ricardian )
target_compile_options(deposit_proxy PUBLIC --no-missing-ricardian-clause)
12 changes: 0 additions & 12 deletions antelope_contracts/contracts/deposit_proxy/README.txt

This file was deleted.

11 changes: 4 additions & 7 deletions antelope_contracts/contracts/deposit_proxy/src/deposit_proxy.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#include <eosio/symbol.hpp>
#include <deposit_proxy.hpp>
#include <deposit_proxy/deposit_proxy.hpp>

void deposit_proxy::transfer(eosio::name from, eosio::name to, eosio::asset quantity, const std::string& memo) {

if (to != get_self() || from == get_self()) return;

constexpr extended_symbol EOS = eosio::extended_symbol{eosio::symbol{"EOS",4}, "eosio.token"_n};
constexpr extended_symbol USDT = eosio::extended_symbol{eosio::symbol{"USDT",4}, "tethertether"_n};

const auto s = eosio::extended_symbol{quantity.symbol, get_first_receiver()};
eosio::check(s == EOS || s == USDT, "unregistered token");

bool memo_has_evm_address = false;
if (memo.size() == 42 && memo[0] == '0' && memo[1] == 'x') {
memo_has_evm_address = std::all_of(memo.begin() + 2, memo.end(), [](char c) {
Expand All @@ -22,6 +16,9 @@ void deposit_proxy::transfer(eosio::name from, eosio::name to, eosio::asset quan

eosio::check(memo_has_evm_address, "memo must be a valid EVM address");

constexpr extended_symbol EOS = eosio::extended_symbol{eosio::symbol{"EOS",4}, "eosio.token"_n};
const auto s = eosio::extended_symbol{quantity.symbol, get_first_receiver()};

auto destination = s == EOS ? "eosio.evm"_n : "eosio.erc2o"_n;
action(std::vector<permission_level>{{get_self(), "active"_n}}, s.get_contract(), "transfer"_n,
std::make_tuple(get_self(), destination, quantity, memo)
Expand Down
1 change: 0 additions & 1 deletion antelope_contracts/contracts/erc20/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ list(APPEND SOURCES
${EXTERNAL_DIR}/silkworm/silkworm/core/rlp/decode.cpp
)

add_compile_definitions(ANTELOPE)
add_contract( erc20 erc20 ${SOURCES} )
target_include_directories( erc20 PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down
6 changes: 4 additions & 2 deletions antelope_contracts/tests/erc20/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ struct contracts {

static std::vector<uint8_t> evm_wasm() { return read_wasm("${eosevm_DIR}/evm_runtime/evm_runtime.wasm"); }
static std::vector<char> evm_abi() { return read_abi("${eosevm_DIR}/evm_runtime/evm_runtime.abi"); }
static std::vector<uint8_t> evm_depoit_proxy_wasm() { return read_wasm("${ANTELOPE_CONTRACTS_BINARY_DIR}/deposit_proxy/deposit_proxy.wasm"); }

static std::vector<uint8_t> evm_deposit_proxy_wasm() { return read_wasm("${ANTELOPE_CONTRACTS_BINARY_DIR}/deposit_proxy/deposit_proxy.wasm"); }
static std::vector<char> evm_deposit_proxy_abi() { return read_abi("${ANTELOPE_CONTRACTS_BINARY_DIR}/deposit_proxy/deposit_proxy.abi"); }
};
} // namespace testing
} // namespace eosio
} // namespace eosio
2 changes: 1 addition & 1 deletion antelope_contracts/tests/erc20/erc20_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ erc20_tester::erc20_tester(bool use_real_evm, std::string native_symbol_str) : n
token_account,
mvo()("to", faucet_account_name)("quantity", asset(1'000'000'000'0000, symbol::from_string("4,USDT")))("memo", ""));

set_code(evmin_account, testing::contracts::evm_depoit_proxy_wasm());
set_code(evmin_account, testing::contracts::evm_deposit_proxy_wasm());

produce_block();

Expand Down
2 changes: 0 additions & 2 deletions antelope_contracts/tests/erc20/erc20_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class erc20_tester : public eosio::testing::base_tester {
prepare_deploy_contract_tx(const unsigned char* contract, size_t size, uint64_t gas_limit) const;
transaction_trace_ptr pushtx(const silkworm::Transaction& trx, name miner = evm_account);

std::string getSolidityContractAddress();

eosio::chain::abi_serializer abi_ser;
eosio::chain::abi_serializer token_abi_ser;

Expand Down
4 changes: 1 addition & 3 deletions antelope_contracts/tests/erc20/transfer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ try {
mvo()("to", dummy_token_account)("quantity", asset(1'000'000'000'0000, eosio::chain::symbol{4,"EOS"}))("memo", ""));

BOOST_REQUIRE_EXCEPTION(transfer_token(dummy_token_account, dummy_token_account, evmin_account, make_asset(10000), "0x0000000000000000000000000000000000000000"),
eosio_assert_message_exception, eosio_assert_message_is("unregistered token"));
eosio_assert_message_exception, eosio_assert_message_is("received unregistered token"));

BOOST_REQUIRE_EXCEPTION(transfer_token(eos_token_account, "alice"_n, evmin_account, make_asset(10000), "0x000000000000000000000000000000000000000Z"),
eosio_assert_message_exception, eosio_assert_message_is("memo must be a valid EVM address"));
Expand Down Expand Up @@ -251,8 +251,6 @@ try {
mvo()("token_contract", token_account)("token_symbol_code", "USDT")("egress_fee", make_asset(1000))),
missing_auth_exception, eosio::testing::fc_exception_message_starts_with("missing authority of eosio.erc2o"));


produce_block();
}
FC_LOG_AND_RETHROW()

Expand Down

0 comments on commit 9af59ee

Please sign in to comment.