This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from maticnetwork/migration-fix
Migration fix
- Loading branch information
Showing
10 changed files
with
237 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const utils = require('./utils') | ||
|
||
const SafeMath = artifacts.require( | ||
'openzeppelin-solidity/contracts/math/SafeMath.sol' | ||
) | ||
const ChildChain = artifacts.require('ChildChain') | ||
const MRC20 = artifacts.require('MRC20') | ||
|
||
module.exports = async function(deployer, network, accounts) { | ||
if (deployer.network !== 'bor') { | ||
return | ||
} | ||
|
||
deployer.then(async() => { | ||
await deployer.deploy(SafeMath) | ||
await deployer.link(SafeMath, [ChildChain]) | ||
await deployer.deploy(ChildChain) | ||
|
||
const childChain = await ChildChain.deployed() | ||
const contractAddresses = utils.getContractAddresses() | ||
|
||
let MaticWeth = await childChain.addToken( | ||
accounts[0], | ||
contractAddresses.root.tokens.MaticWeth, | ||
'ETH on Matic', | ||
'ETH', | ||
18, | ||
false // _isERC721 | ||
) | ||
|
||
let TestToken = await childChain.addToken( | ||
accounts[0], | ||
contractAddresses.root.tokens.TestToken, | ||
'Test Token', | ||
'TST', | ||
18, | ||
false // _isERC721 | ||
) | ||
|
||
let RootERC721 = await childChain.addToken( | ||
accounts[0], | ||
contractAddresses.root.tokens.RootERC721, | ||
'Test ERC721', | ||
'TST721', | ||
0, | ||
true // _isERC721 | ||
) | ||
|
||
const maticToken = await MRC20.at('0x0000000000000000000000000000000000001010') | ||
const maticOwner = await maticToken.owner() | ||
if (maticOwner === '0x0000000000000000000000000000000000000000') { | ||
// matic contract at 0x1010 can only be initialized once, after the bor image starts to run | ||
await maticToken.initialize(ChildChain.address, contractAddresses.root.tokens.MaticToken) | ||
} | ||
await childChain.mapToken(contractAddresses.root.tokens.MaticToken, '0x0000000000000000000000000000000000001010', false) | ||
|
||
contractAddresses.child = { | ||
ChildChain: ChildChain.address, | ||
tokens: { | ||
MaticWeth: MaticWeth.logs.find(log => log.event === 'NewToken').args.token, | ||
MaticToken: '0x0000000000000000000000000000000000001010', | ||
TestToken: TestToken.logs.find(log => log.event === 'NewToken').args.token, | ||
RootERC721: RootERC721.logs.find(log => log.event === 'NewToken').args.token | ||
} | ||
} | ||
utils.writeContractAddresses(contractAddresses) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const ethUtils = require('ethereumjs-util') | ||
const utils = require('./utils') | ||
|
||
const Registry = artifacts.require('Registry') | ||
const Governance = artifacts.require('Governance') | ||
const StateSender = artifacts.require('StateSender') | ||
const DepositManager = artifacts.require('DepositManager') | ||
|
||
module.exports = async function(deployer, network, accounts) { | ||
deployer.then(async() => { | ||
const contractAddresses = utils.getContractAddresses() | ||
|
||
if (!contractAddresses.child) { | ||
return | ||
} | ||
|
||
const registry = await Registry.at(contractAddresses.root.Registry) | ||
const governance = await Governance.at(contractAddresses.root.GovernanceProxy) | ||
|
||
await governance.update( | ||
registry.address, | ||
registry.contract.methods.mapToken( | ||
contractAddresses.root.tokens.MaticWeth, | ||
contractAddresses.child.tokens.MaticWeth, | ||
false /* isERC721 */ | ||
).encodeABI() | ||
) | ||
|
||
await governance.update( | ||
registry.address, | ||
registry.contract.methods.mapToken( | ||
contractAddresses.root.tokens.MaticToken, | ||
contractAddresses.child.tokens.MaticToken, | ||
false /* isERC721 */ | ||
).encodeABI() | ||
) | ||
|
||
await governance.update( | ||
registry.address, | ||
registry.contract.methods.mapToken( | ||
contractAddresses.root.tokens.TestToken, | ||
contractAddresses.child.tokens.TestToken, | ||
false /* isERC721 */ | ||
).encodeABI() | ||
) | ||
|
||
await governance.update( | ||
registry.address, | ||
registry.contract.methods.mapToken( | ||
contractAddresses.root.tokens.RootERC721, | ||
contractAddresses.child.tokens.RootERC721, | ||
true /* isERC721 */ | ||
).encodeABI() | ||
) | ||
|
||
await governance.update( | ||
registry.address, | ||
registry.contract.methods.updateContractMap( | ||
ethUtils.keccak256('childChain'), | ||
contractAddresses.child.ChildChain | ||
).encodeABI() | ||
) | ||
|
||
const stateSenderContract = await StateSender.at(contractAddresses.root.StateSender) | ||
await stateSenderContract.register(contractAddresses.root.DepositManagerProxy, contractAddresses.child.ChildChain) | ||
let depositManager = await DepositManager.at(contractAddresses.root.DepositManagerProxy) | ||
await depositManager.updateChildChainAndStateSender() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = require('fs') | ||
|
||
export function getContractAddresses() { | ||
return JSON.parse(fs.readFileSync(`${process.cwd()}/contractAddresses.json`).toString()) | ||
} | ||
|
||
export function writeContractAddresses(contractAddresses) { | ||
fs.writeFileSync( | ||
`${process.cwd()}/contractAddresses.json`, | ||
JSON.stringify(contractAddresses, null, 2) // Indent 2 spaces | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
start_testrpc() { | ||
npm run testrpc | ||
} | ||
|
||
start_blockchain() { | ||
cd $PWD/test-blockchain | ||
bash run-docker.sh | ||
cd .. | ||
} | ||
|
||
echo "Starting our own geth instance" | ||
start_blockchain | ||
|
||
echo "Starting our own testrpc instance" | ||
start_testrpc | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
npm run truffle:compile | ||
npm run truffle:migrate:dev -- --reset --to 4 | ||
npm run truffle:migrate:dev:bor -- --reset -f 5 --to 5 | ||
npm run truffle:migrate:dev -- -f 6 --to 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters