-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
109 lines (86 loc) · 3.87 KB
/
build.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
const Web3 = require('web3');
const Proxy = artifacts.require('./Proxy.sol');
const HybridExchange = artifacts.require('./HybridExchange.sol');
const TestToken = artifacts.require('./helper/TestToken.sol');
const WethToken = artifacts.require('./helper/WethToken.sol');
const BigNumber = require('bignumber.js');
BigNumber.config({ EXPONENTIAL_AT: 1000 });
const getWeb3 = () => {
const myWeb3 = new Web3(web3.currentProvider);
return myWeb3;
};
const newContract = async (contract, ...args) => {
const c = await contract.new(...args);
const w = getWeb3();
const instance = new w.eth.Contract(contract.abi, c.address);
return instance;
};
const newContractAt = (contract, address) => {
const w = getWeb3();
const instance = new w.eth.Contract(contract.abi, address);
return instance;
};
module.exports = async () => {
let hot, exchange, proxy;
try {
const testAddresses = web3.eth.accounts.slice(1, 6);
const owner = web3.eth.accounts[0];
const relayer = web3.eth.accounts[9];
const maker = web3.eth.accounts[8];
console.log('owner', owner);
console.log('relayer', relayer);
console.log('maker', maker);
console.log('testAddresses', testAddresses);
const bigAllowance = '0xf000000000000000000000000000000000000000000000000000000000000000';
hot = await newContract(TestToken, 'HydroToken', 'Hot', 18);
console.log('Hydro Token address', web3.toChecksumAddress(hot._address));
proxy = await newContract(Proxy);
console.log('Proxy address', web3.toChecksumAddress(proxy._address));
exchange = await newContract(HybridExchange, proxy._address, hot._address);
console.log('HybridExchange address', web3.toChecksumAddress(exchange._address));
await Proxy.at(proxy._address).addAddress(exchange._address);
console.log('Proxy add exchange into whitelist');
usd = await newContract(TestToken, 'USD TOKEN', 'USD', 18);
console.log('USD TOKEN address', web3.toChecksumAddress(usd._address));
weth = await newContract(WethToken, 'Wrapped Ethereum', 'WETH', 18);
console.log('Wrapped Ethereum TOKEN address', web3.toChecksumAddress(weth._address));
const approveAllToken = async address => {
await usd.methods.approve(proxy._address, bigAllowance).send({ from: address });
console.log(address, 'USD approved');
await hot.methods.approve(proxy._address, bigAllowance).send({ from: address });
console.log(address, 'HOT approved');
await weth.methods.approve(proxy._address, bigAllowance).send({ from: address });
console.log(address, 'WETH approved');
};
const giveCoinsTo = async (address, amount) => {
await hot.methods
.transfer(address, `${amount}000000000000000000`)
.send({ from: owner });
console.log(address, `${amount} HOT received`);
await usd.methods
.transfer(address, `${amount}000000000000000000`)
.send({ from: owner });
console.log(address, `${amount} USD TOKEN received`);
};
const wrapETH = async (address, amount) => {
await weth.methods
.deposit()
.send({ from: address, value: `${amount}000000000000000000` });
console.log(address, `${amount} WETH deposited`);
};
await Promise.all(
testAddresses.map(async u => {
await approveAllToken(u);
await giveCoinsTo(u, '100000');
await wrapETH(u, '1000');
})
);
await approveAllToken(maker);
await giveCoinsTo(maker, '100000');
await wrapETH(maker, '1000');
await approveAllToken(relayer);
process.exit(0);
} catch (e) {
console.log(e);
}
};