-
Notifications
You must be signed in to change notification settings - Fork 4
/
4_new_bridge.js
131 lines (106 loc) · 4.32 KB
/
4_new_bridge.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict';
/*global artifacts*/
const BridgeFactory = artifacts.require('BridgeFactory');
const cosmos = require('cosmos-lib');
const {getHDProvider} = require('../provider');
const MNEMONIC = process.env.MNEMONIC;
const ROPSTEN = 'ropsten';
module.exports = (deployer) => {
if (process.env.CONTRACT != 'NewBridge') {
return;
}
return deployer.then(async () => {
if (!process.env.ACCOUNT) {
throw new Error('Provide \'ACCOUNT\' option via environment, ' +
'e.g. ACCOUNT=0x2f39...');
}
if (!process.env.BRIDGE_FACTORY) {
throw new Error('Provide \'BRIDGE_FACTORY\' option via environment, ' +
'like BRIDGE_FACTORY=0x4579...');
}
if (!process.env.ETH_ADDRESSES) {
throw new Error('Provide \'ETH_ADDRESSES\' option via environment, ' +
'like ETH_ADDRESSES=0x4579...,0x2f39...(comma seperated addresses)');
}
if (!process.env.WB_ADDRESSES) {
throw new Error('Provide \'WB_ADDRESSES\' option via environment, ' +
'like WB_ADDRESSES=wallets1avmaz...,' +
'wallets1ghaamx..., (comma seperated addresses)');
}
if (!process.env.ETH_CAPACITY) {
throw new Error('Provide \'ETH_CAPACITY\' parameter via environment, ' +
'like ETH_CAPACITY=1000 (in wei)');
}
if (!process.env.ETH_MIN_EXCHANGE) {
throw new Error('Provide \'ETH_MIN_EXCHANGE\' parameter via environment, ' +
'like ETH_MIN_EXCHANGE=1000000000000000000000 (in wei)');
}
if (!process.env.ETH_FEE_PERCENTAGE) {
throw new Error('Provide \'ETH_FEE_PERCENTAGE\' parameter via environment, ' +
'like ETH_FEE_PERCENTAGE=10 (maximum 10000)');
}
if (deployer.network === ROPSTEN) {
BridgeFactory.setProvider(getHDProvider());
}
const account = process.env.ACCOUNT;
const ethAddresses = process.env.ETH_ADDRESSES.split(',');
let wbAddresses = process.env.WB_ADDRESSES.split(',');
const ethCapacity = process.env.ETH_CAPACITY;
const ethMinExchange = process.env.ETH_MIN_EXCHANGE;
const ethFeePercentage = process.env.ETH_FEE_PERCENTAGE;
if (ethAddresses.length != wbAddresses.length) {
throw new Error('Eth addresses amount should be ' +
'equal WB addresses amount');
}
const bridgeFactory = await BridgeFactory.at(process.env.BRIDGE_FACTORY);
console.log('\tCreating new Bridge contract...\n');
console.log('\t1. Creating BankStorage contract');
let tx = await bridgeFactory.createBankStorage(
{
from: account,
gas: process.env.GAS_LIMIT,
gasPrice: process.env.GAS_PRICE
}
);
const index = tx.logs[1].args[1];
console.log('\t2. Creating Bridge contract');
await bridgeFactory.createBridge(
ethCapacity,
ethMinExchange,
ethFeePercentage,
index,
{
from: account,
gas: process.env.GAS_LIMIT,
gasPrice: process.env.GAS_PRICE
}
);
console.log('\t3. Creating PoAGovernment contract');
await bridgeFactory.createPoA(
index,
{
from: account,
gas: process.env.GAS_LIMIT,
gasPrice: process.env.GAS_PRICE
}
);
wbAddresses = wbAddresses.map(a => cosmos.address.getBytes32(a));
console.log('\t4. Connecting contracts...');
tx = await bridgeFactory.build(
ethAddresses,
wbAddresses,
index,
{
from: account,
gas: process.env.GAS_LIMIT,
gasPrice: process.env.GAS_PRICE
}
);
const bridgeAddress = tx.logs[0].args[0];
const args = await bridgeFactory.getInstance(account, index);
console.log('\tDone.\n');
console.log(`\tBridge address: ${bridgeAddress}`);
console.log(`\tBankStorage address: ${args[1]}`);
console.log(`\tPoA address: ${args[2]}`);
});
};