Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

fix: bridge ERC20 tokens from L1 to L2 using migrations scripts #486

Merged
merged 14 commits into from
Nov 28, 2023

Conversation

leovct
Copy link
Contributor

@leovct leovct commented Nov 17, 2023

Description

The initial approach involved using childChain.addToken to create ChildERC20 and ChildERC721 contracts, but this rendered them unusable due to ownership issues. In this scenario, the ChildChain contract became the owner, preventing updates to the child chain address and leaving it set to 0x0. Consequently, attempts to bridge resulted in reverting transactions (with no explicit error message 😅) due to the restrictive onlyChildChain modifier (see maticnetwork/matic-cli#210).

function addToken(
address _owner,
address _rootToken,
string memory _name,
string memory _symbol,
uint8 _decimals,
bool _isERC721
) public onlyOwner returns (address token) {
// check if root token already exists
require(tokens[_rootToken] == address(0x0), "Token already mapped");
// create new token contract
if (_isERC721) {
token = address(
new ChildERC721(_owner, _rootToken, _name, _symbol)
);
isERC721[_rootToken] = true;
} else {
token = address(
new ChildERC20(_owner, _rootToken, _name, _symbol, _decimals)
);
}

contract ChildERC20 is BaseERC20, ERC20, ERC20Detailed, StateSyncerVerifier, StateReceiver {
constructor(
address /* ignoring parent owner, use contract owner instead */,
address _token,
string memory _name,
string memory _symbol,
uint8 _decimals
) public ERC20Detailed(_name, _symbol, _decimals) {
require(_token != address(0x0));
token = _token;
}

// change child chain address
function changeChildChain(address newAddress) public onlyOwner {
require(
newAddress != address(0),
"Child token: new child address is the zero address"
);
emit ChildChainChanged(childChain, newAddress);
childChain = newAddress;
}

The revised logic aligns with the updated scripts, employing ChildERC20Proxified and ChildERC721Proxified for token creation. This approach allows for proper initialisation, subsequent child chain address updates, and token mapping. As a result, the ChildChain contract can seamlessly send tokens to our L2 address as intended.

Jira Ticket

Test

New deployment.

$ truffle migrate --network bor --f 5 --to 5
> truffle migrate --network bor

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


Starting migrations...
======================
> Network name:    'bor'
> Network id:      15005
> Block gas limit: 10127680 (0x9a8940)

5_deploy_child_contracts.js
===========================

   Deploying 'SafeMath'
   --------------------
   > transaction hash:    0xc946a0a6f0aa40e62cbfe74013f633f28b44127b1c109e4c9bbadf128c4c235b
   > Blocks: 2            Seconds: 4
   > contract address:    0xa487178053E36129Fe5E54b02bE55C00c5B9225F
   > block number:        17
   > block timestamp:     1701078587
   > account:             0x6447Ef2275Dc1Cc203dC54C4d71693Ea795f87C2
   > balance:             999999999.999992591319673058
   > gas used:            71714 (0x11822)
   > gas price:           90 gwei
   > value sent:          0 ETH
   > total cost:          0.00645426 ETH


   Deploying 'ChildChain'
   ----------------------
   > transaction hash:    0x45debf284bced9f80bcc099022b1238e28d8e414b0bd022735fc07e57aaf1ca1
   > Blocks: 2            Seconds: 4
   > contract address:    0xba8D14e74bFD3F57C6a5BD449a80A02bE5BA62e6
   > block number:        19
   > block timestamp:     1701078591
   > account:             0x6447Ef2275Dc1Cc203dC54C4d71693Ea795f87C2
   > balance:             999999999.999575991589673183
   > gas used:            5256439 (0x5034f7)
   > gas price:           90 gwei
   > value sent:          0 ETH
   > total cost:          0.47307951 ETH

Child MaticWethProxified contract deployed
Child MaticWeth proxy contract deployed
Child MaticWeth contract initialized
Child MaticWeth child chain updated
Root and child MaticWeth contracts mapped

Child TestTokenProxified contract deployed
Child TestToken proxy contract deployed
Child TestToken contract initialized
Child TestToken child chain updated
Root and child TestToken contracts mapped

Child TestERC721Proxified contract deployed
Child TestERC721 proxy contract deployed
Child TestERC721 contract initialized
Child TestERC721 child chain updated
Root and child testERC721 contracts mapped
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.47953377 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.47953377 ETH

After bridging some ether and ERC20 tokens.

image

@leovct leovct changed the base branch from main to mardizzone/node-16 November 17, 2023 10:29
@leovct leovct changed the title fix: initialise child ERC20 tokens fix: bridge ERC20 tokens from L1 to L2 using migrations scripts Nov 24, 2023
@leovct leovct marked this pull request as ready for review November 24, 2023 18:12
@marcello33
Copy link

@leovct any idea why the tests are running for 3+ hours?
@simonDos I'd love to get this merged if you agree.
We're leveraging these functionalities in some security tests right now.
Anyway mardizzone/node-16 is a branch we only use for deployment/testing on our devnets

@marcello33
Copy link

It failed after 6h but with no failed tests :/ will rerun it

@leovct
Copy link
Contributor Author

leovct commented Nov 28, 2023

It failed after 6h but with no failed tests :/ will rerun it

@marcello33 I believe these issues are not connected to the recent changes. The tests were failing in the same manner on the last commits.

Screenshot 2023-11-28 at 08 31 25

@marcello33
Copy link

Yes, agreed @leovct
I tested this yesterday and can be merged for me
Thanks

@marcello33 marcello33 merged commit a29ed28 into mardizzone/node-16 Nov 28, 2023
2 of 3 checks passed
@marcello33 marcello33 deleted the fix/initialise-erc20-child-tokens branch November 28, 2023 07:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants