-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.ts
518 lines (481 loc) · 16.6 KB
/
utils.ts
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
import { Contract } from 'ethers'
import { readFileSync, writeFileSync } from 'fs'
import config, { NetworkConfig } from '../config'
import boxContract from '../artifacts/contracts/token/RarePizzasBox.sol/RarePizzasBox.json'
import boxContractV2 from '../artifacts/contracts/token/RarePizzasBoxV2.sol/RarePizzasBoxV2.json'
import randomConsumer from '../artifacts/contracts/random/RandomConsumer.sol/RandomConsumer.json'
import seedStorage from '../artifacts/contracts/data/RarePizzasSeedStorage.sol/RarePizzasSeedStorage.json'
const getAlchemyAPIKey = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.ALCHEMY_MAINNET_KEY
case 'rinkeby':
return config.ALCHEMY_RINKEBY_KEY
case 'matic':
return config.ALCHEMY_MATIC_KEY
case 'maticmum':
return config.ALCHEMY_MUMBAI_KEY
}
return 'VALUE NOT FOUND'
}
const getDeploymentKey = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.MAINNET_PRIVATE_KEY
case 'rinkeby':
return config.RINKEBY_PRIVATE_KEY
case 'matic':
return config.MATIC_PRIVATE_KEY
case 'maticmum':
return config.MATIC_MUMBAI_PRIVATE_KEY
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of the chainlink price feed oracle
*/
const getChainlinkOracle = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.CHAINLINK_MAINNET_PRICE_FEED
case 'rinkeby':
return config.CHAINLINK_RINKEBY_PRICE_FEED
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of the chainlink token
*/
const getChainlinkToken = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.CHAINLINK_MAINNET_TOKEN
case 'rinkeby':
return config.CHAINLINK_RINKEBY_TOKEN
case 'matic':
return config.CHAINLINK_MATIC_TOKEN
case 'maticmum':
return config.CHAINLINK_MATIC_MUMBAI_TOKEN
}
return 'VALUE NOT FOUND'
}
/**
* Get the Address of the Chainlink VRF coordinator
*/
const getChainlinkVRFCoordinator = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.CHAINLINK_MAINNET_VRF_COORD
case 'rinkeby':
return config.CHAINLINK_RINKEBY_VRF_COORD
case 'matic':
return config.CHAINLINK_MATIC_VRF_COORD
case 'maticmum':
return config.CHAINLINK_MATIC_MUMBAI_VRF_COORD
}
return 'VALUE NOT FOUND'
}
/**
* Get the key hash of the chainlink vrf coordinator
*/
const getChainlinkVRFKeyHash = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.CHAINLINK_MAINNET_VRF_KEY_HASH
case 'rinkeby':
return config.CHAINLINK_RINKEBY_VRF_KEY_HASH
case 'matic':
return config.CHAINLINK_MATIC_VRF_KEY_HASH
case 'maticmum':
return config.CHAINLINK_MATIC_MUMBAI_VRF_KEY_HASH
}
return 'VALUE NOT FOUND'
}
/**
* Get the fee for the chainlink VRF coordinator calls
*/
const getChainlinkVRFFee = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.CHAINLINK_MAINNET_VRF_FEE
case 'rinkeby':
return config.CHAINLINK_RINKEBY_VRF_FEE
case 'matic':
return config.CHAINLINK_MATIC_VRF_FEE
case 'maticmum':
return config.CHAINLINK_MATIC_MUMBAI_VRF_FEE
}
return 'VALUE NOT FOUND'
}
/**
* Get the contract address of the OrderAPI Oracle
*/
const getOrderAPIOracleContractAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_ORDER_API_MAINNET_ORACLE_CONTRACT_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_ORDER_API_RINKEBY_ORACLE_CONTRACT_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the EOA address that is loaded into the chainlink oracle node
*/
const getOrderAPIOracleNodeAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_ORDER_API_MAINNET_ORACLE_NODE_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_ORDER_API_RINKEBY_ORACLE_NODE_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the contract address of the contact that will consume the OrderAPI result
*/
const getOrderAPIConsumerContractAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_ORDER_API_CONSUMER_MAINNET_CONTRACT_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_ORDER_API_CONSUMER_RINKEBY_CONTRACT_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the jobId associated with the OrderAPI oracle
*/
const getOrderAPIJobId = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_ORDER_API_MAINNET_JOB_ID
case 'rinkeby':
return config.RAREPIZZAS_ORDER_API_RINKEBY_JOB_ID
}
return 'VALUE NOT FOUND'
}
/**
* Get the job fee of the OrderAPI Oracle
*/
const getOrderAPIJobFee = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_ORDER_API_MAINNET_JOB_FEE
case 'rinkeby':
return config.RAREPIZZAS_ORDER_API_RINKEBY_JOB_FEE
}
return 'VALUE NOT FOUND'
}
/**
* Get the proxy address of the Box contract
*/
const getBoxProxyAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_BOX_MAINNET_PROXY_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_BOX_RINKEBY_PROXY_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of the administrator of the box contract (usually a multi-sig)
*/
const getBoxProxyAdminAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_BOX_MAINNET_PROXY_ADMIN_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_BOX_RINKEBY_PROXY_ADMIN_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the contract address of the VRF random consumer.
*
* Note: this contract is deployed on both ethereum and polygon networks
*/
const getRandomConsumerAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_BOX_MAINNET_RANDOM_CONSUMER_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_BOX_RINKEBY_RANDOM_CONSUMER_ADDRESS
case 'matic':
return config.RAREPIZZAS_MATIC_RANDOM_CONSUMER_ADDRESS
case 'maticmum':
return config.RAREPIZZAS_MUMBAI_RANDOM_CONSUMER_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the proxy address of the Rare Pizzas contract
*/
const getRarePizzasProxyAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_MAINNET_PROXY_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_RINKEBY_PROXY_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of the administrator of the Rare Pizzas contract (usually a multi-sig)
*/
const getRarePizzasProxyAdminAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'mainnet':
return config.RAREPIZZAS_MAINNET_PROXY_ADMIN_ADDRESS
case 'rinkeby':
return config.RAREPIZZAS_RINKEBY_PROXY_ADMIN_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the proxy address of the seed storage contract
*
* note: this contract is deployed on polygon
*/
const getStorageProxyAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'matic':
return config.RAREPIZZAS_SEEDSTORAGE_MATIC_PROXY_ADDRESS
case 'maticmum':
return config.RAREPIZZAS_SEEDSTORAGE_MUMBAI_PROXY_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of the administrator of the Seed Storage contract (usually a multi-sig)
*/
const getStorageProxyAdminAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'matic':
return config.RAREPIZZAS_MATIC_PROXY_ADMIN_ADDRESS
case 'maticmum':
return config.RAREPIZZAS_MUMBAI_PROXY_ADMIN_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Get the address of an EOA that is authorized to make requests to the seed storage contract
*/
const getStorageProxyAuthorizedRequestorAddress = (config: NetworkConfig) => {
const networkName = config.NETWORK.toLowerCase()
switch (networkName) {
case 'matic':
return config.RAREPIZZAS_SEEDSTORAGE_AUTHORIZED_REQUESTOR_MATIC_ADDRESS
case 'maticmum':
return config.RAREPIZZAS_SEEDSTORAGE_AUTHORIZED_REQUESTOR_MUMBAI_ADDRESS
}
return 'VALUE NOT FOUND'
}
/**
* Publish a truncated version of the Box Web3 ABI
*/
const publishBoxWeb3Abi = () => {
const boxWeb3interface = {
contractName: boxContract.contractName,
sourceName: boxContract.sourceName,
abi: [
boxContract.abi.find((i) => i.name === 'BTCETHPriceUpdated'),
boxContract.abi.find((i) => i.name === 'OwnershipTransferred'),
boxContract.abi.find((i) => i.name === 'Transfer'),
boxContract.abi.find((i) => i.name === 'balanceOf'),
boxContract.abi.find((i) => i.name === 'BTCETHPriceUpdated'),
boxContract.abi.find((i) => i.name === 'getBitcoinPriceInWei'),
boxContract.abi.find((i) => i.name === 'getPrice'),
boxContract.abi.find((i) => i.name === 'getPriceInWei'),
boxContract.abi.find((i) => i.name === 'maxSupply'),
boxContract.abi.find((i) => i.name === 'publicSaleStart_timestampInS'),
boxContract.abi.find((i) => i.name === 'purchase'),
// TODO: later ...boxContract.abi.filter((i) => i.name === 'safeTransferFrom'),
boxContract.abi.find((i) => i.name === 'tokenURI'),
boxContract.abi.find((i) => i.name === 'totalSupply'),
],
}
const json = JSON.stringify(boxWeb3interface)
console.log(json)
writeFileSync('./dist/boxWeb3Interface.json', json)
}
/**
* Publish a truncated version of the Box Web3 Admin ABI
*/
const publishBoxWeb3AdminAbi = () => {
const boxWeb3interface = {
contractName: boxContract.contractName,
sourceName: boxContract.sourceName,
abi: [
boxContract.abi.find((i) => i.name === 'mint'),
boxContract.abi.find((i) => i.name === 'purchaseTo'),
boxContract.abi.find((i) => i.name === 'setPresaleAllowed'),
boxContract.abi.find((i) => i.name === 'setSaleStartTimestamp'),
boxContract.abi.find((i) => i.name === 'updateBitcoinPriceInWei'),
boxContract.abi.find((i) => i.name === 'withdraw'),
],
}
const json = JSON.stringify(boxWeb3interface)
console.log(json)
writeFileSync('./dist/boxWeb3AdminInterface.json', json)
}
/**
* Publish a truncated version of the Box V2 Web3 Admin ABI
*/
const publishBoxWeb3V2AdminAbi = () => {
const boxWeb3interface = {
contractName: boxContractV2.contractName,
sourceName: boxContractV2.sourceName,
abi: [
boxContractV2.abi.find((i) => i.name === 'mint'),
boxContractV2.abi.find((i) => i.name === 'purchaseTo'),
boxContractV2.abi.find((i) => i.name === 'setPresaleAllowed'),
boxContractV2.abi.find((i) => i.name === 'setSaleStartTimestamp'),
boxContractV2.abi.find((i) => i.name === 'updateBitcoinPriceInWei'),
boxContractV2.abi.find((i) => i.name === 'withdraw'),
boxContractV2.abi.find(i => i.name === 'setVRFConsumer')
],
}
const json = JSON.stringify(boxWeb3interface)
console.log(json)
writeFileSync('./dist/boxWeb3AdminInterface-v2.json', json)
}
/**
* Publish a truncated version of the RarePizzasSeedStorage ABI
*/
const publishRarePizzasSeedStorageAbi = (proxy: Contract) => {
const contractInterface = {
contractName: seedStorage.contractName,
sourceName: seedStorage.sourceName,
proxy: proxy,
abi: [
seedStorage.abi.find((i) => i.name === 'fulfillRandomness'),
seedStorage.abi.find((i) => i.name === 'getPizzaSeed'),
seedStorage.abi.find((i) => i.name === 'getRandomNumber'),
seedStorage.abi.find((i) => i.name === 'pizzaSeeds')
],
}
const json = JSON.stringify(contractInterface)
console.log(json)
writeFileSync('./dist/rarePizzasSeedStorageAbiInterface.json', json)
}
/**
* Publish a truncated version of the Random Conusmer Web3 Admin ABI
*/
const publishRandomConsumerWeb3AdminAbi = () => {
const contractInterface = {
contractName: randomConsumer.contractName,
sourceName: randomConsumer.sourceName,
abi: [
randomConsumer.abi.find((i) => i.name === 'setCallbackContract'),
randomConsumer.abi.find((i) => i.name === 'setFee'),
randomConsumer.abi.find((i) => i.name === 'setKeyHash'),
randomConsumer.abi.find((i) => i.name === 'withdrawLink'),
randomConsumer.abi.find((i) => i.name === 'withdraw')
],
}
const json = JSON.stringify(contractInterface)
console.log(json)
writeFileSync('./dist/randomConsumerWeb3AdminInterface.json', json)
}
/**
* Publish some deployment data.
*
* This function should be called for all contract deployments
*/
const publishDeploymentData = (name: string, proxy: Contract) => {
const deploymentData = {
network: config.NETWORK,
name: name,
proxy: proxy.address,
transaction: proxy.deployTransaction,
}
const json = JSON.stringify(deploymentData)
console.log(deploymentData)
writeFileSync(`./dist/deployment-${config.NETWORK}-${name}-latest.json`, json)
writeFileSync(`./dist/deployment-${config.NETWORK}-${name}-${Date.now()}.json`, json)
}
const publishRandomConsumerDeploymentData = (name: string, proxy: string, randomConsumer: Contract) => {
const deploymentData = {
network: config.NETWORK,
name: name,
proxy: proxy,
randomConsumer: {
address: randomConsumer.address,
transaction: randomConsumer.deployTransaction
}
}
const json = JSON.stringify(deploymentData)
console.log(deploymentData)
writeFileSync(`./dist/deployment-${config.NETWORK}-${name}-latest.json`, json)
writeFileSync(`./dist/deployment-${config.NETWORK}-${name}-${Date.now()}.json`, json)
}
const publishUpgradeData = (name: string, proxy: string, implementation: string,) => {
const deploymentData = {
network: config.NETWORK,
name: name,
proxy: proxy,
implementation: implementation,
}
const json = JSON.stringify(deploymentData)
console.log(deploymentData)
writeFileSync('./dist/deployment-upgrade-latest.json', json)
writeFileSync(`./dist/deployment-upgrade-${Date.now()}.json`, json)
}
const parseBoxUris = () => {
var text = readFileSync("./data/box_resources", "utf-8");
var textByLine = text.split("\n")
console.log(JSON.stringify(textByLine));
}
const utils = {
getAlchemyAPIKey: getAlchemyAPIKey,
getDeploymentKey: getDeploymentKey,
getChainlinkOracle: getChainlinkOracle,
getChainlinkToken: getChainlinkToken,
getChainlinkVRFCoordinator: getChainlinkVRFCoordinator,
getChainlinkVRFKeyHash: getChainlinkVRFKeyHash,
getChainlinkVRFFee: getChainlinkVRFFee,
getOrderAPIOracleContractAddress: getOrderAPIOracleContractAddress,
getOrderAPIOracleNodeAddress: getOrderAPIOracleNodeAddress,
getOrderAPIConsumerContractAddress: getOrderAPIConsumerContractAddress,
getOrderAPIJobId: getOrderAPIJobId,
getOrderAPIJobFee: getOrderAPIJobFee,
getBoxProxyAddress: getBoxProxyAddress,
getBoxProxyAdminAddress: getBoxProxyAdminAddress,
getRandomConsumerAddress: getRandomConsumerAddress,
getRarePizzasProxyAddress: getRarePizzasProxyAddress,
getRarePizzasProxyAdminAddress: getRarePizzasProxyAdminAddress,
getStorageProxyAddress: getStorageProxyAddress,
getStorageProxyAdminAddress: getStorageProxyAdminAddress,
getStorageProxyAuthorizedRequestorAddress:getStorageProxyAuthorizedRequestorAddress,
parseBoxUris: parseBoxUris,
publishBoxWeb3Abi: publishBoxWeb3Abi,
publishBoxWeb3AdminAbi: publishBoxWeb3AdminAbi,
publishBoxWeb3V2AdminAbi: publishBoxWeb3V2AdminAbi,
publishRarePizzasSeedStorageAbi: publishRarePizzasSeedStorageAbi,
publishRandomConsumerWeb3AdminAbi: publishRandomConsumerWeb3AdminAbi,
publishDeploymentData: publishDeploymentData,
publishRandomConsumerDeploymentData: publishRandomConsumerDeploymentData,
publishUpgradeData: publishUpgradeData
}
export default utils