-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeploy.js
More file actions
701 lines (608 loc) · 23.1 KB
/
Copy pathdeploy.js
File metadata and controls
701 lines (608 loc) · 23.1 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
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/* global ethers */
/* eslint prefer-const: "off" */
// const { ethers } = require("hardhat");
const fs = require("fs").promises;
const { arrayCompare } = require("arweave/node/lib/merkle.js");
// const { ethers } = require("hardhat");
const path = require("node:path");
var _ = require("underscore");
// import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
// const { program } = require('commander');
// program
// .name('devopsdao-contract-deploy')
// .description('CLI to deploy devopsdao contract')
// .version('0.0.1');
// program.command('deploy')
// .description('Deploy smart contract to the chain')
// .argument('<chain>', 'chain name')
// .option('-d, --diamond', 'deploy diamond completely')
// .option('-c, --facet-cut <facet>', 'upgrade facet')
// .action((str, options) => {
// // const limit = options.first ? 1 : undefined;
// // console.log(str.split(options.separator, limit));
// run();
// });
// program.command('upgrade')
// .description('Upgrade diamond facet')
// .argument('<chain>', 'chain name')
// .option('-c, --facet <facet>', 'upgrade facet')
// .action((str, options) => {
// // const limit = options.first ? 1 : undefined;
// // console.log(str.split(options.separator, limit));
// upgradeDiamond();
// });
// program.parse();
// const args = program.commands
// const options = program.opts();
// const { getSelectors, FacetCutAction } = require('./libraries/diamond.js')
const libraries = [
{
name: "LibUtils",
},
{
name: "LibAddress",
},
{
name: "LibTasks",
},
{
name: "LibTasksAudit",
},
{
name: "LibChat",
},
{
name: "LibWithdraw",
libraries: ["LibUtils"],
},
{
name: "LibTokens",
},
{
name: "LibTokenData",
},
{
name: "LibInterchain",
},
{
name: "LibWitnetFacet",
},
];
const diamondFacets = [
{
name: "DiamondCutFacet",
},
{
name: "DiamondLoupeFacet",
},
{
name: "OwnershipFacet",
},
];
const witnetSLA = {
numWitnesses: 9,
minConsensusPercentage: 66, // %
witnessReward: 1000000000, // 1.0 WIT
witnessCollateral: 15000000000, // 15.0 WIT
minerCommitRevealFee: 100000000, // 0.1 WIT
};
// console.log(Object.values(witnetSLA));
const dodaoFacets = [
{
name: "TaskCreateFacet",
libraries: ["LibTasks", "LibTasksAudit", "LibChat", "LibWithdraw"],
},
{
name: "TaskDataFacet",
},
{
name: "TaskStatsFacet",
},
{
name: "AccountFacet",
},
{
name: 'AccountDataFacet',
},
{
name: "TokenFacet",
libraries: ["LibTokens", "LibTokenData"],
},
{
name: "TokenDataFacet",
libraries: ["LibTokenData"],
},
{
name: 'QuestboardFacet',
},
{
name: 'InterchainFacet',
// libraries: ["LibInterchain", "LibTasks"],
},
{
name: 'AxelarFacet',
},
{
name: 'HyperlaneFacet',
},
{
name: 'LayerzeroFacet',
},
{
name: 'WormholeFacet',
},
];
const {
getSelectors,
FacetCutAction,
removeSelectors,
findAddressPositionInFacets,
} = require("../scripts/libraries/diamond.js");
let witnetAddresses;
let requestHashes;
async function configureWitnet(){
console.log('loading witnet contract addresses')
let ecosystem;
let network
if(hre.network.config.witnet){
if (hre.network.config.chainId === 31337) {
ecosystem = "hardhat";
network = "hardhat.localhost";
} else if (hre.network.config.chainId === 1287) {
ecosystem = "moonbeam";
network = "moonbeam.moonbase";
} else if (hre.network.config.chainId === 4002) {
ecosystem = "fantom";
network = "fantom.goerli";
} else if (hre.network.config.chainId === 80001) {
ecosystem = "polygon";
network = "polygon.goerli";
} else if (hre.network.config.chainId === 280) {
ecosystem = "zksync";
network = "zksync.goerli";
}
witnetAddresses = require("witnet-solidity-bridge/migrations/witnet.addresses")[ecosystem][network];
requestHashes = require(`../abi/witnet-requesthashes.json`)["hashes"][hre.network.config.chainId];
// console.log(requestHashes)
dodaoFacets.push(
{
name: "WitnetFacet",
arguments: [witnetAddresses.WitnetRequestBoard, requestHashes.WitnetRequestTemplate, Object.values(witnetSLA)],
libraries: [
'LibUtils',
]
}
);
console.log(dodaoFacets)
}
}
let deployedContracts;
async function deployDiamond(mode = 'deploy') {
console.log('Deploying diamond...');
await configureWitnet();
const accounts = await ethers.getSigners();
// console.log(accounts);
const contractOwner = accounts[0];
console.log(`using wallet: ${contractOwner.address}`);
try{
const existingDeployedContracts = await fs.readFile(path.join(__dirname, `../abi/deployed-contracts.json`));
deployedContracts = JSON.parse(existingDeployedContracts);
}
catch{
console.log(`existing ../abi/deployed-contracts.json not found, will create new`);
deployedContracts = {
deployArgs: {},
};
}
deployedContracts.deployArgs[hre.network.config.chainId] = {};
// Deploy DiamondInit
// DiamondInit provides a function that is called when the diamond is upgraded or deployed to initialize state variables
// Read about how the diamondCut function works in the EIP2535 Diamonds standard
const DiamondInit = await ethers.getContractFactory("DiamondInit");
let feeData = await ethers.provider.getFeeData();
// const diamondInit = await DiamondInit.deploy({ type: 2, gasPrice: feeData.gasPrice });
const diamondInit = await DiamondInit.deploy({ type: 2, maxFeePerGas: feeData.maxFeePerGas, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas });
await diamondInit.deployed();
console.log("DiamondInit deployed:", diamondInit.address);
await new Promise(resolve => setTimeout(resolve, 600));
deployedContracts.deployArgs[hre.network.config.chainId]["DiamondInit"] = {};
deployedContracts.deployArgs[hre.network.config.chainId]["DiamondInit"]['address'] = diamondInit.address;
const libAddresses = await deployLibs(libraries);
// Deploy facets and set the `facetCuts` variable
console.log("");
console.log("Deploying facets");
const facets = diamondFacets.concat(dodaoFacets);
// The `facetCuts` variable is the FacetCut[] that contains the functions to add during diamond deployment
const { facetCuts, facetAddresses } = await deployFacets(facets, libAddresses);
console.log("Facets deployed")
// Creating a function call
// This call gets executed during deployment and can also be executed in upgrades
// It is `executed` with delegatecall on the DiamondInit address.
let functionCall = diamondInit.interface.encodeFunctionData("init");
// Setting arguments that will be used in the diamond constructor
const diamondArgs = {
owner: contractOwner.address,
init: diamondInit.address,
initCalldata: functionCall,
};
// console.log(diamondArgs)
// console.log(facetCuts)
// deploy Diamond
feeData = await ethers.provider.getFeeData();
const Diamond = await ethers.getContractFactory("Diamond");
// console.log(facetCuts);
// const diamond = await Diamond.deploy(facetCuts, diamondArgs, { type: 2, gasPrice: feeData.gasPrice });
const diamond = await Diamond.deploy(facetCuts, diamondArgs, { type: 2, maxFeePerGas: feeData.maxFeePerGas, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas });
await diamond.deployed();
console.log("");
console.log("Diamond deployed:", diamond.address);
let contractAddresses;
try{
const existingAddresses = await fs.readFile(path.join(__dirname, `../abi/addresses.json`));
contractAddresses = JSON.parse(existingAddresses);
}
catch{
console.log(`existing ../abi/addresses.json not found, will create new`);
contractAddresses = {
contracts: {},
};
}
contractAddresses.contracts[hre.network.config.chainId] = {};
contractAddresses.contracts[hre.network.config.chainId]["Diamond"] = diamond.address;
if(mode == 'deploy'){
await fs.writeFile(path.join(__dirname, `../abi/addresses.json`), JSON.stringify(contractAddresses, null, 2));
await fs.writeFile(`${hre.config.abiExporter[0].path}/addresses.json`, JSON.stringify(contractAddresses, null, 2));
}
deployedContracts.deployArgs[hre.network.config.chainId]["Diamond"] = {};
deployedContracts.deployArgs[hre.network.config.chainId]["Diamond"]['address'] = diamond.address;
deployedContracts.deployArgs[hre.network.config.chainId]["Diamond"]["deployArgs"] = [facetCuts, diamondArgs];
// await hre.run("verify:verify", {
// address: diamond.address,
// constructorArguments: [facetCuts, diamondArgs],
// });
// for(const contractName of Object.keys(deployedContracts.deployArgs[hre.network.config.chainId])){
// console.log(`verifying contract ${contractName}`)
// const contractAddress = deployedContracts.deployArgs[hre.network.config.chainId][contractName]['address'];
// const deployArgs = deployedContracts.deployArgs[hre.network.config.chainId][contractName]['deployArgs'];
// if (typeof deployArgs != "undefined") {
// deployedContracts.deployArgs[hre.network.config.chainId][FacetInit.name]["deployArgs"] = FacetInit.arguments;
// // await hre.run("verify:verify", {
// // address: contractAddress,
// // constructorArguments: deployArgs,
// // });
// }
// // else{
// // await hre.run("verify:verify", {
// // address: contractAddress
// // });
// // }
// console.log(`${contractName} verified: ${contractAddress}`);
// }
if(mode == 'deploy'){
await fs.writeFile(path.join(__dirname, `../abi/deployed-contracts.json`), JSON.stringify(deployedContracts, null, 2));
}
// returning the address of the diamond
console.log('Diamond deployed at:', diamond.address);
return { diamondAddress: diamond.address, facetCount: facetCuts.length };
}
async function upgradeDiamondFacets(facets, libraries) {
const existingAddresses = await fs.readFile(path.join(__dirname, `../abi/addresses.json`));
let contractAddresses;
if (typeof existingAddresses !== "undefined") {
contractAddresses = JSON.parse(existingAddresses);
} else {
return false;
}
const diamondAddress = contractAddresses.contracts[hre.network.config.chainId]["Diamond"];
console.log(`upgrading Diamond: ${diamondAddress}`);
try{
const existingDeployedContracts = await fs.readFile(path.join(__dirname, `../abi/deployed-contracts.json`));
deployedContracts = JSON.parse(existingDeployedContracts);
}
catch{
console.log(`existing ../abi/deployed-contracts.json not found, will create new`);
deployedContracts = {
deployArgs: {},
};
deployedContracts.deployArgs[hre.network.config.chainId] = {};
}
if(typeof deployedContracts.deployArgs[hre.network.config.chainId] === 'undefined'){
deployedContracts.deployArgs[hre.network.config.chainId] = {};
}
const diamondLoupeFacet = await ethers.getContractAt("DiamondLoupeFacet", diamondAddress);
const diamondCutFacet = await ethers.getContractAt("DiamondCutFacet", diamondAddress);
console.log("getting existing facets and its libs from diamond");
let facetsDeployedByName = {};
let facetsCompiled = {};
let facetsCompiledSelectors = {};
let facetsDeployedSelectors = {};
let libNames = [];
const facetsDeployed = await diamondLoupeFacet.facets();
for (const facet of facets) {
const facetNameKeccak = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('contract'+facet.name+'()')).substr(0, 10);
const facetCompiled = await ethers.getContractAt(facet.name, diamondAddress);
if (typeof facetCompiled != "undefined") {
let equal;
for (facetDeployed of facetsDeployed) {
// console.log(`checking ${facet.name}`)
//equal = _.isEqual(facetDeployed.functionSelectors, getSelectors(facetCompiled));
found = _.contains(facetDeployed.functionSelectors, facetNameKeccak);
if (found) {
break;
}
}
if (found) {
console.log(`found ${facet.name}`);
facetsDeployedSelectors[facet.name] = facetDeployed.functionSelectors;
// facetsCompiled[facet.name] = facetCompiled;
// facetsCompiledSelectors[facet.name] = getSelectors(facetCompiled);
} else {
console.log(`not found ${facet.name}`);
}
if (typeof facet.libraries != "undefined") {
libNames = libNames.concat(facet.libraries);
}
}
}
//make uniq
libNames = [...new Set(libNames)];
console.log("deploying libraries");
let libs = [];
for (const libName of libNames) {
const lib = libraries.find((library) => library.name === libName);
libs.push(lib);
}
for (const lib of libs) {
if (typeof lib.libraries != "undefined") {
for (const libLibrary of lib.libraries) {
const libDep = libraries.find((library) => library.name === libLibrary);
libs.push(libDep);
}
}
}
//sort first libraries which have no dependencies
libs.sort(function (left, right) {
return left.hasOwnProperty("libraries") ? 1 : right.hasOwnProperty("libraries") ? -1 : 0;
});
const libAddresses = await deployLibs(libs);
console.log("removing facetsCompiledSelectors");
for (const facet of facets) {
if (typeof facetsDeployedSelectors[facet.name] != "undefined") {
tx = await diamondCutFacet.diamondCut(
[
{
facetAddress: ethers.constants.AddressZero,
action: FacetCutAction.Remove,
functionSelectors: facetsDeployedSelectors[facet.name],
},
],
ethers.constants.AddressZero,
"0x",
{ type: 2 }
);
receipt = await tx.wait();
console.log(`${facet.name} removed`);
await new Promise(resolve => setTimeout(resolve, 600));
} else {
console.log(`facet ${facet.name} was not present in diamond`);
}
}
console.log("deploying new facets");
const { facetCuts, facetAddresses } = await deployFacets(facets, libAddresses);
console.log("upgrading diamond with a new facets");
// Any number of functions from any number of facets can be added/replaced/removed in a
tx = await diamondCutFacet.diamondCut(facetCuts, ethers.constants.AddressZero, "0x", { type: 2 });
receipt = await tx.wait();
await new Promise(resolve => setTimeout(resolve, 600));
if (!receipt.status) {
throw Error(`Diamond upgrade failed: ${tx.hash}`);
}
// console.log(`Diamond cut:`, tx)
console.log(`Diamond cut.`);
// const facetsDeployed = await diamondLoupeFacet.facets()
// for(const id of facets.keys()){
// console.log(facetsDeployed[findAddressPositionInFacets(facetAddresses[facets[id].name], facets)])
// // console.log(getSelectors(TasksFacet))
// // assert.sameMembers(facets[findAddressPositionInFacets(tasksFacet.address, facets)][1], getSelectors(TasksFacet))
// }
// const facetAddresses = await diamondLoupeFacet.facetAddresses()
}
async function deployLibs(libraries) {
let libAddresses = {};
for (const library of libraries) {
let Lib;
if (typeof library.name === "undefined") {
continue;
} else if (typeof library.name !== "undefined" && typeof library.libraries === "undefined") {
Lib = await ethers.getContractFactory(library.name);
} else if (typeof library.name !== "undefined" && typeof library.libraries !== "undefined") {
let Libs = {};
for (const LibName of library.libraries) {
Libs[LibName] = libAddresses[LibName];
}
console.log(`${library.name} libraries: ${JSON.stringify(Libs)}`);
Lib = await ethers.getContractFactory(library.name, { libraries: Libs });
}
const feeData = await ethers.provider.getFeeData();
// const lib = await Lib.deploy({ type: 2, gasPrice: feeData.gasPrice });
const lib = await Lib.deploy({ type: 2, maxFeePerGas: feeData.maxFeePerGas*2, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas});
// const lib = await Lib.deploy({ type: 2, gasLimit: 20000, maxFeePerGas: feeData.maxFeePerGas, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas});
await lib.deployed();
libAddresses[library.name] = lib.address;
console.log(`${library.name} deployed:`, lib.address);
await new Promise(resolve => setTimeout(resolve, 600));
deployedContracts.deployArgs[hre.network.config.chainId][library.name] = {};
deployedContracts.deployArgs[hre.network.config.chainId][library.name]['address'] = lib.address;
}
return libAddresses;
}
async function deployFacets(FacetInits, libAddresses) {
const facetCuts = [];
const facetAddresses = {};
for (const FacetInit of FacetInits) {
let Facet;
if (typeof FacetInit.name === "undefined") {
continue;
} else if (typeof FacetInit.name !== "undefined" && typeof FacetInit.libraries === "undefined") {
Facet = await ethers.getContractFactory(FacetInit.name);
} else if (typeof FacetInit.name !== "undefined" && typeof FacetInit.libraries !== "undefined") {
let Libs = {};
for (const LibName of FacetInit.libraries) {
Libs[LibName] = libAddresses[LibName];
}
console.log(`${FacetInit.name} libraries: ${JSON.stringify(Libs)}`);
Facet = await ethers.getContractFactory(FacetInit.name, { libraries: Libs });
}
const feeData = await ethers.provider.getFeeData();
let facet;
if (typeof FacetInit.arguments != "undefined") {
console.log('deploying facet');
// facet = await Facet.deploy(...FacetInit.arguments, { type: 2, gasPrice: feeData.gasPrice });
facet = await Facet.deploy(...FacetInit.arguments, { type: 2, maxFeePerGas: feeData.maxFeePerGas*2, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas });
} else {
console.log('deploying facet');
// facet = await Facet.deploy({ type: 2, gasPrice: feeData.gasPrice });
facet = await Facet.deploy({ type: 2, maxFeePerGas: feeData.maxFeePerGas*2, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas });
}
const tx = await facet.deployed();
// const raw = hre.ethers.getRawTransaction(tx);
console.log(`${FacetInit.name} deployed: ${facet.address}`);
await new Promise(resolve => setTimeout(resolve, 600));
facetCuts.push({
facetAddress: facet.address,
action: FacetCutAction.Add,
functionSelectors: getSelectors(facet),
});
facetAddresses[facet.name] = facet.address;
// console.log('verifying contract')
deployedContracts.deployArgs[hre.network.config.chainId][FacetInit.name] = {};
deployedContracts.deployArgs[hre.network.config.chainId][FacetInit.name]['address'] = facet.address;
if (typeof FacetInit.arguments != "undefined") {
deployedContracts.deployArgs[hre.network.config.chainId][FacetInit.name]["deployArgs"] = FacetInit.arguments;
}
// if (typeof FacetInit.arguments != "undefined") {
// deployedContracts.deployArgs[hre.network.config.chainId][FacetInit.name]["deployArgs"] = FacetInit.arguments;
// await hre.run("verify:verify", {
// address: facet.address,
// constructorArguments: FacetInit.arguments,
// });
// }
// else{
// await hre.run("verify:verify", {
// address: facet.address
// });
// }
// console.log(`${FacetInit.name} verified: ${facet.address}`);
}
return { facetCuts, facetAddresses };
}
async function verifyContracts(){
const mode = 'verify';
// let deployedContracts;
try{
const existingDeployedContracts = await fs.readFile(path.join(__dirname, `../abi/deployed-contracts.json`));
deployedContracts = JSON.parse(existingDeployedContracts);
}
catch{
console.log(`existing ../abi/deployed-contracts.json not found, will create new`);
deployedContracts = {
deployArgs: {},
};
}
for(const contractName of Object.keys(deployedContracts.deployArgs[hre.network.config.chainId])){
if(typeof deployedContracts.deployArgs[hre.network.config.chainId][contractName]['verified'] == 'undefined' ||
deployedContracts.deployArgs[hre.network.config.chainId][contractName]['verified'] != true){
const contractAddress = deployedContracts.deployArgs[hre.network.config.chainId][contractName]['address'];
const deployArgs = deployedContracts.deployArgs[hre.network.config.chainId][contractName]['deployArgs'];
console.log(`verifying contract ${contractName} ${contractAddress}`)
if (typeof deployArgs != "undefined") {
console.log(`${deployArgs}`)
await hre.run("verify:verify", {
address: contractAddress,
constructorArguments: deployArgs,
});
deployedContracts.deployArgs[hre.network.config.chainId][contractName]['verified'] = true;
}
else{
await hre.run("verify:verify", {
address: contractAddress
});
deployedContracts.deployArgs[hre.network.config.chainId][contractName]['verified'] = true;
}
if(mode == 'verify'){
await fs.writeFile(path.join(__dirname, `../abi/deployed-contracts.json`), JSON.stringify(deployedContracts, null, 2));
}
console.log(`${contractName} verified: ${contractAddress}`);
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
function run() {
if (require.main === module) {
deployDiamond('deploy')
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
}
}
if (require.main === module) {
deployDiamond('deploy')
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
}
task("diamondDeploy", "deploys Diamond'", async function (taskArguments, hre, runSuper) {
console.log("deploying Diamond");
console.log("");
// console.log('Deploying facets')
await deployDiamond('deploy');
});
task("diamondUpgrade", "upgrades Diamond'")
.addParam("facets", "facets to add or upgrade")
.setAction(async function (taskArguments, hre, runSuper) {
console.log(taskArguments);
console.log("upgrading Diamond");
await configureWitnet();
console.log("");
let upgradeFacets = [];
let facetNames = [];
if (taskArguments.facets === "all") {
upgradeFacets = dodaoFacets;
} else {
if (taskArguments.facets.indexOf(",") != -1) {
facetNames = taskArguments.facets.split(",");
} else {
facetNames.push(taskArguments.facets);
}
console.log(dodaoFacets);
for (const facetName of facetNames) {
const facet = dodaoFacets.find((facet) => facet.name === facetName);
if (typeof facet != "undefined") {
upgradeFacets.push(facet);
} else {
console.log(`facet contract "${facetName}" is not found`);
}
}
}
if (taskArguments.facets === "all" || upgradeFacets.length === facetNames.length) {
console.log("going to deploy the following facets:");
console.log(upgradeFacets);
await upgradeDiamondFacets(upgradeFacets, libraries);
} else {
console.log("please specify only existing facet contracts");
}
});
task("diamondVerify", "verifies Diamond contracts", async function (taskArguments, hre, runSuper) {
console.log("verifying Diamond contracts");
console.log("");
// console.log('Deploying facets')
await verifyContracts();
});
exports.deployDiamond = deployDiamond;
exports.upgradeDiamondFacets = upgradeDiamondFacets;