-
Notifications
You must be signed in to change notification settings - Fork 227
/
migrateToMCD.js
56 lines (48 loc) · 1.86 KB
/
migrateToMCD.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require('dotenv').config()
const Web3 = require('web3')
const multiSigWalletAbi = require('../abi/multiSigwallet')
const proxyAbi = require('../../build/contracts/EternalStorageProxy').abi
const foreignBridgeAbi = require('../../build/contracts/ForeignBridgeErcToNative').abi
const confirmTransaction = require('./confirmTransaction')
const validatorState = require('./validatorState')
const {
FOREIGN_PRIVKEY,
FOREIGN_RPC_URL,
FOREING_BRIDGE_ADDRESS,
ROLE,
FOREIGN_START_BLOCK,
FOREIGN_GAS_PRICE
} = process.env
const web3 = new Web3(new Web3.providers.HttpProvider(FOREIGN_RPC_URL))
const { address } = web3.eth.accounts.wallet.add(FOREIGN_PRIVKEY)
const migrateToMCD = async () => {
try {
const proxy = new web3.eth.Contract(proxyAbi, FOREING_BRIDGE_ADDRESS)
const bridge = new web3.eth.Contract(foreignBridgeAbi, FOREING_BRIDGE_ADDRESS)
const ownerAddress = await proxy.methods.upgradeabilityOwner().call()
const multiSigWallet = new web3.eth.Contract(multiSigWalletAbi, ownerAddress)
await validatorState(web3, address, multiSigWallet)
const data = bridge.methods.migrateToMCD().encodeABI()
if (ROLE === 'leader') {
const gas = await multiSigWallet.methods
.submitTransaction(FOREING_BRIDGE_ADDRESS, 0, data)
.estimateGas({ from: address })
const receipt = await multiSigWallet.methods
.submitTransaction(FOREING_BRIDGE_ADDRESS, 0, data)
.send({ from: address, gas, gasPrice: FOREIGN_GAS_PRICE })
console.log(`Submission status: ${receipt.status} - Tx Hash: ${receipt.transactionHash}`)
} else {
await confirmTransaction({
fromBlock: FOREIGN_START_BLOCK,
contract: multiSigWallet,
destination: FOREING_BRIDGE_ADDRESS,
data,
address,
gasPrice: FOREIGN_GAS_PRICE
})
}
} catch (e) {
console.log(e.message)
}
}
migrateToMCD()