Skip to content

Commit

Permalink
After discussion, we decide that we should only keep the token
Browse files Browse the repository at this point in the history
address+symbol API
  • Loading branch information
yarkinwho committed Aug 7, 2024
1 parent 290b3fd commit 9778a59
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 102 deletions.
3 changes: 1 addition & 2 deletions antelope_contracts/contracts/erc20/include/erc20/erc20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class [[eosio::contract]] erc20 : public contract {
[[eosio::action]] void init(eosio::name evm_account, eosio::symbol gas_token_symbol, uint64_t gaslimit, uint64_t init_gaslimit);

[[eosio::action]] void setgaslimit(std::optional<uint64_t> gaslimit, std::optional<uint64_t> init_gaslimit);
[[eosio::action]] void callupgaddr(std::string proxy_address);
[[eosio::action]] void callupgsym(eosio::name token_contract, eosio::symbol token_symbol);
[[eosio::action]] void callupgrade(eosio::name token_contract, eosio::symbol token_symbol);

struct [[eosio::table("implcontract")]] impl_contract_t {
uint64_t id = 0;
Expand Down
19 changes: 1 addition & 18 deletions antelope_contracts/contracts/erc20/src/erc20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,24 +477,7 @@ inline eosio::name erc20::receiver_account()const {
return get_self();
}

void erc20::callupgaddr(std::string proxy_address){
require_auth(get_self());

auto address_bytes = from_hex(proxy_address);
eosio::check(!!address_bytes, "token address must be valid 0x EVM address");
eosio::check(address_bytes->size() == kAddressLength, "invalid length of token address");

checksum256 addr_key = make_key(*address_bytes);
token_table_t token_table(_self, _self.value);
auto index = token_table.get_index<"by.address"_n>();
auto token_table_iter = index.find(addr_key);

check(token_table_iter != index.end() && token_table_iter->address == address_bytes, "ERC-20 token not registerred");

handle_call_upgrade(token_table_iter->address);
}

void erc20::callupgsym(eosio::name token_contract, eosio::symbol token_symbol){
void erc20::callupgrade(eosio::name token_contract, eosio::symbol token_symbol){
require_auth(get_self());

token_table_t token_table(_self, _self.value);
Expand Down
84 changes: 2 additions & 82 deletions antelope_contracts/tests/erc20/integrated_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,87 +274,7 @@ try {
}
FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(it_upgrade_addr, it_tester)
try {
evm_eoa evm1;
auto addr_alice = silkworm::make_reserved_address("alice"_n.to_uint64_t());

// Give evm1 some EOS
transfer_token(eos_token_account, "alice"_n, evm_account, make_asset(1000000, eos_token_symbol), evm1.address_0x().c_str());
produce_block();


// USDT balance should be zero
auto bal = balanceOf(evm1.address_0x().c_str());
BOOST_REQUIRE(bal == 0);

produce_block();

transfer_token(token_account, "alice"_n, erc20_account, make_asset(10000, token_symbol), evm1.address_0x().c_str());

bal = balanceOf(evm1.address_0x().c_str());
BOOST_REQUIRE(bal == 990000);
BOOST_REQUIRE(99990000 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount());
auto tokenInfo = getRegistedTokenInfo();
BOOST_REQUIRE(tokenInfo.balance == make_asset(9900, token_symbol));
BOOST_REQUIRE(tokenInfo.fee_balance == make_asset(100, token_symbol));

produce_block();

auto fee = egressFee();
// received = 1000/1e6*1e4 = 10
bridgeTransferERC20(evm1, addr_alice, 1000, "aaa", fee);
produce_block();

bal = balanceOf(evm1.address_0x().c_str());

BOOST_REQUIRE(bal == 989000);
bal = get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount();

BOOST_REQUIRE(99990010 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount());

// upgrade

evm_eoa deployer;
evmc::address impl_addr = silkworm::create_address(deployer.address, deployer.next_nonce);

transfer_token(eos_token_account, faucet_account_name, evmin_account, make_asset(1000000, eos_token_symbol), deployer.address_0x().c_str());

auto txn = prepare_deploy_contract_tx(solidity::erc20::bytecode, sizeof(solidity::erc20::bytecode), 10'000'000);

deployer.sign(txn);
pushtx(txn);
produce_block();

push_action(erc20_account, "upgradeto"_n, erc20_account, mvo()("impl_address",fc::variant(impl_addr).as_string()));

produce_block();

push_action(erc20_account, "callupgaddr"_n, erc20_account, mvo()("proxy_address",evm_address.substr(2)));

produce_block();

// Perform some basic tests again

transfer_token(token_account, "alice"_n, erc20_account, make_asset(10000, token_symbol), evm1.address_0x().c_str());

bal = balanceOf(evm1.address_0x().c_str());

BOOST_REQUIRE(bal == 989000 + 990000);

fee = egressFee();
// received = 1000/1e6*1e4 = 10
bridgeTransferERC20(evm1, addr_alice, 1000, "aaa", fee);
produce_block();

bal = balanceOf(evm1.address_0x().c_str());

BOOST_REQUIRE(bal == 989000 * 2);

}
FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(it_upgrade_symbol, it_tester)
BOOST_FIXTURE_TEST_CASE(it_upgrade, it_tester)
try {


Expand Down Expand Up @@ -413,7 +333,7 @@ try {

produce_block();

push_action(erc20_account, "callupgsym"_n, erc20_account, mvo()("token_contract",token_account)("token_symbol",symbol::from_string("4,USDT")));
push_action(erc20_account, "callupgrade"_n, erc20_account, mvo()("token_contract",token_account)("token_symbol",symbol::from_string("4,USDT")));

produce_block();

Expand Down

0 comments on commit 9778a59

Please sign in to comment.