This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
/
3_core.js
339 lines (300 loc) Β· 11.5 KB
/
3_core.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
const ConstantAuctionPriceCurve = artifacts.require('ConstantAuctionPriceCurve');
const Core = artifacts.require("Core");
const ERC20Wrapper = artifacts.require('ERC20Wrapper');
const ExchangeIssueLibrary = artifacts.require('ExchangeIssueLibrary');
const ExchangeIssueModule = artifacts.require('ExchangeIssueModule');
const IssuanceLibrary = artifacts.require('IssuanceLibrary');
const KyberNetworkWrapper = artifacts.require('KyberNetworkWrapper');
const LinearAuctionPriceCurve = artifacts.require('LinearAuctionPriceCurve');
const PayableExchangeIssue = artifacts.require("PayableExchangeIssue");
const RebalanceAuctionModule = artifacts.require("RebalanceAuctionModule");
const RebalancingHelperLibrary = artifacts.require('RebalancingHelperLibrary');
const RebalancingSetToken = artifacts.require('RebalancingSetToken');
const RebalancingSetTokenFactory = artifacts.require('RebalancingSetTokenFactory');
const RebalancingTokenIssuanceModule = artifacts.require('RebalancingTokenIssuanceModule');
const SetTokenFactory = artifacts.require("SetTokenFactory");
const StandardFailAuctionLibrary = artifacts.require('StandardFailAuctionLibrary');
const StandardPlaceBidLibrary = artifacts.require('StandardPlaceBidLibrary');
const StandardProposeLibrary = artifacts.require('StandardProposeLibrary');
const StandardSettleRebalanceLibrary = artifacts.require('StandardSettleRebalanceLibrary');
const StandardStartRebalanceLibrary = artifacts.require('StandardStartRebalanceLibrary');
const TransferProxy = artifacts.require("TransferProxy");
const Vault = artifacts.require("Vault");
const WethMock = artifacts.require("WethMock");
const WhiteList = artifacts.require("WhiteList");
const ZeroExExchangeWrapper = artifacts.require("ZeroExExchangeWrapper");
const ZERO_EX_EXCHANGE_ADDRESS_KOVAN = '0x35dd2932454449b14cee11a94d3674a936d5d7b2';
const ZERO_EX_ERC20_PROXY_ADDRESS_KOVAN = '0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e';
const ZERO_EX_ZRX_ADDRESS_KOVAN = '0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa';
const ZERO_EX_EXCHANGE_ADDRESS_TESTRPC = '0x48bacb9266a570d521063ef5dd96e61686dbe788';
const ZERO_EX_ERC20_PROXY_ADDRESS_TESTRPC = '0x1dc4c1cefef38a777b15aa20260a54e584b16c48';
const ZERO_EX_ZRX_ADDRESS_TESTRPC = '0x871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c';
const ZERO_EX_EXCHANGE_ADDRESS_MAINNET = '0x4f833a24e1f95d70f028921e27040ca56e09ab0b';
const ZERO_EX_ERC20_PROXY_ADDRESS_MAINNET = '0x2240dab907db71e64d3e0dba4800c83b5c502d4e';
const ZERO_EX_ZRX_ADDRESS_MAINNET = '0xe41d2489571d322189246dafa5ebde1f4699f498';
const KYBER_NETWORK_PROXY_ADDRESS_KOVAN = '0x7e6b8b9510d71bf8ef0f893902ebb9c865eef4df';
const KYBER_NETWORK_PROXY_ADDRESS_ROPSTEN = '0x818e6fecd516ecc3849daf6845e3ec868087b755';
const KYBER_NETWORK_PROXY_ADDRESS_TESTRPC = '0x371b13d97f4bf77d724e78c16b7dc74099f40e84';
const KYBER_NETWORK_PROXY_ADDRESS_MAINNET = '0x818E6FECD516Ecc3849DAf6845e3EC868087B755';
const WETH_ADDRESS_KOVAN = '0x4C5E0CAbAA6B376D565cF2be865a03F43E361770';
const WETH_ADDRESS_MAINNET = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const DEFAULT_AUCTION_PRICE_NUMERATOR = 1374;
const DEFAULT_AUCTION_PRICE_DENOMINATOR = 1000;
const ONE_DAY_IN_SECONDS = 86400;
const ONE_MINUTE_IN_SECONDS = 60;
const MINIMUM_REBALANCING_NATURAL_UNIT = 10000;
const MAXIMUM_REBALANCING_NATURAL_UNIT = 100000000000000;
module.exports = function(deployer, network, accounts) {
if (network == "development" || network == "coverage") {
console.log("Exiting - Network is development");
return;
}
deployer.then(() => deployContracts(deployer, network));
};
async function deployContracts(deployer, network) {
// Link external libraries that are dependencies of our contracts
await deployAndLinkLibraries(deployer, network);
// Deploy Core contracts and its authorized dependents
await deployCoreContracts(deployer, network);
};
async function deployAndLinkLibraries(deployer, network) {
await deployer.deploy(ERC20Wrapper);
await Vault.link('ERC20Wrapper', ERC20Wrapper.address);
await TransferProxy.link('ERC20Wrapper', ERC20Wrapper.address);
await KyberNetworkWrapper.link('ERC20Wrapper', ERC20Wrapper.address);
await ZeroExExchangeWrapper.link('ERC20Wrapper', ERC20Wrapper.address);
await PayableExchangeIssue.link('ERC20Wrapper', ERC20Wrapper.address);
await deployer.deploy(IssuanceLibrary);
await Core.link('IssuanceLibrary', IssuanceLibrary.address);
await deployer.deploy(ExchangeIssueLibrary);
await PayableExchangeIssue.link('ExchangeIssueLibrary', ExchangeIssueLibrary.address);
await deployRebalancingLibrariesAsync(deployer, network);
await linkRebalancingLibrariesAsync(deployer, network, RebalancingSetTokenFactory);
await linkRebalancingLibrariesAsync(deployer, network, RebalancingSetToken);
};
async function deployRebalancingLibrariesAsync(deployer, network) {
await deployer.deploy(RebalancingHelperLibrary);
await StandardProposeLibrary.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await StandardStartRebalanceLibrary.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await StandardPlaceBidLibrary.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await StandardSettleRebalanceLibrary.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await StandardFailAuctionLibrary.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await deployer.deploy(StandardProposeLibrary);
await deployer.deploy(StandardStartRebalanceLibrary);
await deployer.deploy(StandardPlaceBidLibrary);
await deployer.deploy(StandardSettleRebalanceLibrary);
await deployer.deploy(StandardFailAuctionLibrary);
}
async function linkRebalancingLibrariesAsync(deployer, network, contract) {
await contract.link(
'RebalancingHelperLibrary',
RebalancingHelperLibrary.address
);
await contract.link(
'StandardProposeLibrary',
StandardProposeLibrary.address
);
await contract.link(
'StandardStartRebalanceLibrary',
StandardStartRebalanceLibrary.address
);
await contract.link(
'StandardPlaceBidLibrary',
StandardPlaceBidLibrary.address
);
await contract.link(
'StandardSettleRebalanceLibrary',
StandardSettleRebalanceLibrary.address
);
await contract.link(
'StandardFailAuctionLibrary',
StandardFailAuctionLibrary.address
);
}
async function deployCoreContracts(deployer, network) {
// Deploy Vault and TransferProxy
await deployer.deploy(Vault);
await deployer.deploy(TransferProxy);
// Deploy Core
await deployer.deploy(
Core,
TransferProxy.address,
Vault.address
);
// Deploy SetToken Factory
await deployer.deploy(
SetTokenFactory,
Core.address
);
// Deploy RebalancingSetToken Factory
let minimumRebalanceInterval;
let minimumProposalPeriod;
let minimumTimeToPivot;
let maximumTimeToPivot;
let minimumNaturalUnit;
let maximumNaturalUnit;
switch(network) {
case 'main':
minimumRebalanceInterval = ONE_DAY_IN_SECONDS;
minimumProposalPeriod = ONE_DAY_IN_SECONDS;
minimumTimeToPivot = (ONE_DAY_IN_SECONDS / 4);
maximumTimeToPivot = (ONE_DAY_IN_SECONDS * 3);
minimumNaturalUnit = MINIMUM_REBALANCING_NATURAL_UNIT;
maximumNaturalUnit = MAXIMUM_REBALANCING_NATURAL_UNIT;
break;
case 'kovan':
case 'kovan-fork':
minimumRebalanceInterval = ONE_MINUTE_IN_SECONDS;
minimumProposalPeriod = ONE_MINUTE_IN_SECONDS;
minimumTimeToPivot = 0;
maximumTimeToPivot = (ONE_DAY_IN_SECONDS * 3);
minimumNaturalUnit = MINIMUM_REBALANCING_NATURAL_UNIT;
maximumNaturalUnit = MAXIMUM_REBALANCING_NATURAL_UNIT;
break
case 'ropsten':
case 'ropsten-fork':
case 'development':
minimumRebalanceInterval = ONE_MINUTE_IN_SECONDS;
minimumProposalPeriod = ONE_MINUTE_IN_SECONDS;
minimumTimeToPivot = 0;
maximumTimeToPivot = (ONE_DAY_IN_SECONDS * 3);
minimumNaturalUnit = MINIMUM_REBALANCING_NATURAL_UNIT;
maximumNaturalUnit = MAXIMUM_REBALANCING_NATURAL_UNIT;
break;
}
await deployer.deploy(
RebalancingSetTokenFactory,
Core.address,
WhiteList.address,
minimumRebalanceInterval,
minimumProposalPeriod,
minimumTimeToPivot,
maximumTimeToPivot,
minimumNaturalUnit,
maximumNaturalUnit
);
// Deploy Exchange Wrappers
let zeroExExchangeAddress;
let zeroExERC20ProxyAddress;
let zeroExZRXAddress;
let kyberNetworkProxyAddress;
switch(network) {
case 'main':
zeroExExchangeAddress = ZERO_EX_EXCHANGE_ADDRESS_MAINNET;
zeroExERC20ProxyAddress = ZERO_EX_ERC20_PROXY_ADDRESS_MAINNET;
zeroExZRXAddress = ZERO_EX_ZRX_ADDRESS_MAINNET;
kyberNetworkProxyAddress = KYBER_NETWORK_PROXY_ADDRESS_MAINNET;
break;
case 'kovan':
case 'kovan-fork':
zeroExExchangeAddress = ZERO_EX_EXCHANGE_ADDRESS_KOVAN;
zeroExERC20ProxyAddress = ZERO_EX_ERC20_PROXY_ADDRESS_KOVAN;
zeroExZRXAddress = ZERO_EX_ZRX_ADDRESS_KOVAN;
kyberNetworkProxyAddress = KYBER_NETWORK_PROXY_ADDRESS_KOVAN;
break;
case 'ropsten':
case 'ropsten-fork':
kyberNetworkProxyAddress = KYBER_NETWORK_PROXY_ADDRESS_ROPSTEN;
break;
case 'development':
zeroExExchangeAddress = ZERO_EX_EXCHANGE_ADDRESS_TESTRPC;
zeroExERC20ProxyAddress = ZERO_EX_ERC20_PROXY_ADDRESS_TESTRPC;
zeroExZRXAddress = ZERO_EX_ZRX_ADDRESS_TESTRPC;
kyberNetworkProxyAddress = KYBER_NETWORK_PROXY_ADDRESS_TESTRPC;
break;
}
// Deploy Exchange Issue Module
await deployer.deploy(
ExchangeIssueModule,
Core.address,
TransferProxy.address,
Vault.address
);
// Deploy Rebalancing Auction Module
await deployer.deploy(
RebalanceAuctionModule,
Core.address,
Vault.address
);
// Deploy Rebalancing Token Issuance Module
await deployer.deploy(
RebalancingTokenIssuanceModule,
Core.address,
TransferProxy.address,
Vault.address
);
// Kyber Wrapper
if (kyberNetworkProxyAddress) {
await deployer.deploy(
KyberNetworkWrapper,
Core.address,
kyberNetworkProxyAddress,
TransferProxy.address
);
}
// 0x V2 Wrapper
if (zeroExExchangeAddress && zeroExERC20ProxyAddress && zeroExZRXAddress) {
await deployer.deploy(
ZeroExExchangeWrapper,
Core.address,
zeroExExchangeAddress,
zeroExERC20ProxyAddress,
zeroExZRXAddress,
TransferProxy.address
);
}
// Deploy PayabaleExchangeIssue
switch(network) {
case 'main':
wethAddress = WETH_ADDRESS_MAINNET;
break
case 'kovan':
case 'kovan-fork':
wethAddress = WETH_ADDRESS_KOVAN;
break
case 'ropsten':
case 'ropsten-fork':
case 'development':
wethAddress = WethMock.address;
break;
}
await deployer.deploy(
PayableExchangeIssue,
Core.address,
TransferProxy.address,
ExchangeIssueModule.address,
wethAddress
);
// Deploy Rebalancing Price Auction Libraries
switch(network) {
case 'main':
await deployer.deploy(LinearAuctionPriceCurve, DEFAULT_AUCTION_PRICE_DENOMINATOR, true);
break;
case 'kovan':
case 'kovan-fork':
await deployer.deploy(LinearAuctionPriceCurve, DEFAULT_AUCTION_PRICE_DENOMINATOR, true);
await deployer.deploy(ConstantAuctionPriceCurve, DEFAULT_AUCTION_PRICE_NUMERATOR, DEFAULT_AUCTION_PRICE_DENOMINATOR);
break;
case 'ropsten':
case 'ropsten-fork':
case 'development':
await deployer.deploy(LinearAuctionPriceCurve, DEFAULT_AUCTION_PRICE_DENOMINATOR, true);
await deployer.deploy(ConstantAuctionPriceCurve, DEFAULT_AUCTION_PRICE_NUMERATOR, DEFAULT_AUCTION_PRICE_DENOMINATOR);
break;
}
};