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

Commit a29ed28

Browse files
authored
fix: bridge ERC20 tokens from L1 to L2 using migrations scripts (#486)
* fix: initialise child ERC20 tokens * test * fix: update child chain address of newly created tokens * chore: simplify * chore: rename variables * test: update erc20/erc721 deployment * chore: typo * fix: small issue when initializing erc721 * chore: use `new` instead of `deploy` * chore: nit * test * chore: nit * chore: update the other migration file * chore: nit
1 parent fa783ea commit a29ed28

File tree

2 files changed

+102
-58
lines changed

2 files changed

+102
-58
lines changed

deploy-migrations/4_deploy_child_contracts.js

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ const SafeMath = artifacts.require(
44
'openzeppelin-solidity/contracts/math/SafeMath.sol'
55
)
66
const ChildChain = artifacts.require('ChildChain')
7+
8+
const ChildERC20Proxified = artifacts.require('ChildERC20Proxified')
9+
const ChildERC721Proxified = artifacts.require('ChildERC721Proxified')
10+
const ChildTokenProxy = artifacts.require('ChildTokenProxy')
11+
712
const MRC20 = artifacts.require('MRC20')
813

9-
module.exports = async function(deployer, network, accounts) {
14+
module.exports = async function(deployer, _, _) {
1015
deployer.then(async() => {
1116
await deployer.deploy(SafeMath)
1217
await deployer.link(SafeMath, [ChildChain])
@@ -15,33 +20,50 @@ module.exports = async function(deployer, network, accounts) {
1520
const childChain = await ChildChain.deployed()
1621
const contractAddresses = utils.getContractAddresses()
1722

18-
let MaticWeth = await childChain.addToken(
19-
accounts[0],
20-
contractAddresses.root.tokens.MaticWeth,
21-
'ETH on Matic',
22-
'ETH',
23-
18,
24-
false // _isERC721
25-
)
23+
// Deploy MaticWeth (ERC20) child contract and its proxy.
24+
// Initialize the contract, update the child chain and map the token with its root contract.
25+
const childMaticWethProxified = await ChildERC20Proxified.new()
26+
console.log('Child MaticWethProxified contract deployed')
27+
const childMaticWethProxy = await ChildTokenProxy.new(childMaticWethProxified.address)
28+
console.log('Child MaticWeth proxy contract deployed')
29+
const childMaticWeth = await ChildERC20Proxified.at(childMaticWethProxy.address)
30+
31+
await childMaticWeth.initialize(contractAddresses.root.tokens.MaticWeth, 'Eth on Matic', 'ETH', 18)
32+
console.log('Child MaticWeth contract initialized')
33+
await childMaticWeth.changeChildChain(childChain.address)
34+
console.log('Child MaticWeth child chain updated')
35+
await childChain.mapToken(contractAddresses.root.tokens.MaticWeth, childMaticWeth.address, false)
36+
console.log('Root and child MaticWeth contracts mapped')
37+
38+
// Same thing for TestToken (ERC20).
39+
const childTestTokenProxified = await ChildERC20Proxified.new()
40+
console.log('\nChild TestTokenProxified contract deployed')
41+
const childTestTokenProxy = await ChildTokenProxy.new(childTestTokenProxified.address)
42+
console.log('Child TestToken proxy contract deployed')
43+
const childTestToken = await ChildERC20Proxified.at(childTestTokenProxy.address)
44+
45+
await childTestToken.initialize(contractAddresses.root.tokens.TestToken, 'Test Token', 'TST', 18)
46+
console.log('Child TestToken contract initialized')
47+
await childTestToken.changeChildChain(childChain.address)
48+
console.log('Child TestToken child chain updated')
49+
await childChain.mapToken(contractAddresses.root.tokens.TestToken, childTestToken.address, false)
50+
console.log('Root and child TestToken contracts mapped')
2651

27-
let TestToken = await childChain.addToken(
28-
accounts[0],
29-
contractAddresses.root.tokens.TestToken,
30-
'Test Token',
31-
'TST',
32-
18,
33-
false // _isERC721
34-
)
52+
// Same thing for TestERC721.
53+
const childTestERC721Proxified = await ChildERC721Proxified.new()
54+
console.log('\nChild TestERC721Proxified contract deployed')
55+
const childTestERC721Proxy = await ChildTokenProxy.new(childTestERC721Proxified.address)
56+
console.log('Child TestERC721 proxy contract deployed')
57+
const childTestERC721 = await ChildERC721Proxified.at(childTestERC721Proxy.address)
3558

36-
let RootERC721 = await childChain.addToken(
37-
accounts[0],
38-
contractAddresses.root.tokens.RootERC721,
39-
'Test ERC721',
40-
'TST721',
41-
0,
42-
true // _isERC721
43-
)
59+
await childTestERC721.initialize(contractAddresses.root.tokens.RootERC721, 'Test ERC721', 'TST721')
60+
console.log('Child TestERC721 contract initialized')
61+
await childTestERC721.changeChildChain(childChain.address)
62+
console.log('Child TestERC721 child chain updated')
63+
await childChain.mapToken(contractAddresses.root.tokens.RootERC721, childTestERC721.address, true) // ERC721
64+
console.log('Root and child testERC721 contracts mapped')
4465

66+
// Initialize and map MaticToken.
4567
const maticToken = await MRC20.at('0x0000000000000000000000000000000000001010')
4668
const maticOwner = await maticToken.owner()
4769
if (maticOwner === '0x0000000000000000000000000000000000000000') {
@@ -51,12 +73,12 @@ module.exports = async function(deployer, network, accounts) {
5173
await childChain.mapToken(contractAddresses.root.tokens.MaticToken, '0x0000000000000000000000000000000000001010', false)
5274

5375
contractAddresses.child = {
54-
ChildChain: ChildChain.address,
76+
ChildChain: childChain.address,
5577
tokens: {
56-
MaticWeth: MaticWeth.logs.find(log => log.event === 'NewToken').args.token,
78+
MaticWeth: childMaticWeth.address,
5779
MaticToken: '0x0000000000000000000000000000000000001010',
58-
TestToken: TestToken.logs.find(log => log.event === 'NewToken').args.token,
59-
RootERC721: RootERC721.logs.find(log => log.event === 'NewToken').args.token
80+
TestToken: childTestToken.address,
81+
RootERC721: childTestERC721.address
6082
}
6183
}
6284
utils.writeContractAddresses(contractAddresses)

migrations/5_deploy_child_contracts.js

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ const SafeMath = artifacts.require(
44
'openzeppelin-solidity/contracts/math/SafeMath.sol'
55
)
66
const ChildChain = artifacts.require('ChildChain')
7+
8+
const ChildERC20Proxified = artifacts.require('ChildERC20Proxified')
9+
const ChildERC721Proxified = artifacts.require('ChildERC721Proxified')
10+
const ChildTokenProxy = artifacts.require('ChildTokenProxy')
11+
712
const MRC20 = artifacts.require('MRC20')
813

9-
module.exports = async function(deployer, network, accounts) {
14+
module.exports = async function(deployer, _, _) {
1015
if (deployer.network !== 'bor') {
1116
return
1217
}
@@ -19,33 +24,50 @@ module.exports = async function(deployer, network, accounts) {
1924
const childChain = await ChildChain.deployed()
2025
const contractAddresses = utils.getContractAddresses()
2126

22-
let MaticWeth = await childChain.addToken(
23-
accounts[0],
24-
contractAddresses.root.tokens.MaticWeth,
25-
'ETH on Matic',
26-
'ETH',
27-
18,
28-
false // _isERC721
29-
)
27+
// Deploy MaticWeth (ERC20) child contract and its proxy.
28+
// Initialize the contract, update the child chain and map the token with its root contract.
29+
const childMaticWethProxified = await ChildERC20Proxified.new()
30+
console.log('Child MaticWethProxified contract deployed')
31+
const childMaticWethProxy = await ChildTokenProxy.new(childMaticWethProxified.address)
32+
console.log('Child MaticWeth proxy contract deployed')
33+
const childMaticWeth = await ChildERC20Proxified.at(childMaticWethProxy.address)
34+
35+
await childMaticWeth.initialize(contractAddresses.root.tokens.MaticWeth, 'Eth on Matic', 'ETH', 18)
36+
console.log('Child MaticWeth contract initialized')
37+
await childMaticWeth.changeChildChain(childChain.address)
38+
console.log('Child MaticWeth child chain updated')
39+
await childChain.mapToken(contractAddresses.root.tokens.MaticWeth, childMaticWeth.address, false)
40+
console.log('Root and child MaticWeth contracts mapped')
41+
42+
// Same thing for TestToken (ERC20).
43+
const childTestTokenProxified = await ChildERC20Proxified.new()
44+
console.log('\nChild TestTokenProxified contract deployed')
45+
const childTestTokenProxy = await ChildTokenProxy.new(childTestTokenProxified.address)
46+
console.log('Child TestToken proxy contract deployed')
47+
const childTestToken = await ChildERC20Proxified.at(childTestTokenProxy.address)
48+
49+
await childTestToken.initialize(contractAddresses.root.tokens.TestToken, 'Test Token', 'TST', 18)
50+
console.log('Child TestToken contract initialized')
51+
await childTestToken.changeChildChain(childChain.address)
52+
console.log('Child TestToken child chain updated')
53+
await childChain.mapToken(contractAddresses.root.tokens.TestToken, childTestToken.address, false)
54+
console.log('Root and child TestToken contracts mapped')
3055

31-
let TestToken = await childChain.addToken(
32-
accounts[0],
33-
contractAddresses.root.tokens.TestToken,
34-
'Test Token',
35-
'TST',
36-
18,
37-
false // _isERC721
38-
)
56+
// Same thing for TestERC721.
57+
const childTestERC721Proxified = await ChildERC721Proxified.new()
58+
console.log('\nChild TestERC721Proxified contract deployed')
59+
const childTestERC721Proxy = await ChildTokenProxy.new(childTestERC721Proxified.address)
60+
console.log('Child TestERC721 proxy contract deployed')
61+
const childTestERC721 = await ChildERC721Proxified.at(childTestERC721Proxy.address)
3962

40-
let RootERC721 = await childChain.addToken(
41-
accounts[0],
42-
contractAddresses.root.tokens.RootERC721,
43-
'Test ERC721',
44-
'TST721',
45-
0,
46-
true // _isERC721
47-
)
63+
await childTestERC721.initialize(contractAddresses.root.tokens.RootERC721, 'Test ERC721', 'TST721')
64+
console.log('Child TestERC721 contract initialized')
65+
await childTestERC721.changeChildChain(childChain.address)
66+
console.log('Child TestERC721 child chain updated')
67+
await childChain.mapToken(contractAddresses.root.tokens.RootERC721, childTestERC721.address, true) // ERC721
68+
console.log('Root and child testERC721 contracts mapped')
4869

70+
// Initialize and map MaticToken.
4971
const maticToken = await MRC20.at('0x0000000000000000000000000000000000001010')
5072
const maticOwner = await maticToken.owner()
5173
if (maticOwner === '0x0000000000000000000000000000000000000000') {
@@ -55,12 +77,12 @@ module.exports = async function(deployer, network, accounts) {
5577
await childChain.mapToken(contractAddresses.root.tokens.MaticToken, '0x0000000000000000000000000000000000001010', false)
5678

5779
contractAddresses.child = {
58-
ChildChain: ChildChain.address,
80+
ChildChain: childChain.address,
5981
tokens: {
60-
MaticWeth: MaticWeth.logs.find(log => log.event === 'NewToken').args.token,
82+
MaticWeth: childMaticWeth.address,
6183
MaticToken: '0x0000000000000000000000000000000000001010',
62-
TestToken: TestToken.logs.find(log => log.event === 'NewToken').args.token,
63-
RootERC721: RootERC721.logs.find(log => log.event === 'NewToken').args.token
84+
TestToken: childTestToken.address,
85+
RootERC721: childTestERC721.address
6486
}
6587
}
6688
utils.writeContractAddresses(contractAddresses)

0 commit comments

Comments
 (0)