-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDex_Build.js
More file actions
116 lines (95 loc) · 3.6 KB
/
Copy pathDex_Build.js
File metadata and controls
116 lines (95 loc) · 3.6 KB
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
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, tokens) => {
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
const tokenName = await token.methods.name().call();
await token.methods
.approve(proxy._address, bigAllowance)
.send({ from: address });
console.log(address, `${tokenName} approved`);
}
};
const giveCoinsTo = async (address, amount, tokens) => {
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
const tokenName = await token.methods.name().call();
await token.methods
.transfer(address, `${amount}000000000000000000`)
.send({ from: owner });
console.log(address, `${amount} ${tokenName} 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, [usd, hot, weth]);
await giveCoinsTo(u, "100000", [hot, usd]);
await wrapETH(u, "1000");
})
);
await approveAllToken(maker, [usd, hot, weth]);
await giveCoinsTo(maker, "100000", [hot, usd]);
await wrapETH(maker, "1000");
await approveAllToken(relayer, [usd, hot, weth]);
process.exit(0);
} catch (e) {
console.log(e);
}
};