@rocketh/verifier 0.10.9 → 0.10.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/esm/blockscout.d.ts +11 -0
  3. package/dist/esm/blockscout.d.ts.map +1 -0
  4. package/dist/esm/blockscout.js +121 -0
  5. package/dist/esm/blockscout.js.map +1 -0
  6. package/dist/esm/cli.d.ts +3 -0
  7. package/dist/esm/cli.d.ts.map +1 -0
  8. package/dist/esm/cli.js +65 -0
  9. package/dist/esm/cli.js.map +1 -0
  10. package/dist/esm/etherscan.d.ts +11 -0
  11. package/dist/esm/etherscan.d.ts.map +1 -0
  12. package/dist/esm/etherscan.js +360 -0
  13. package/dist/esm/etherscan.js.map +1 -0
  14. package/dist/{index.d.ts → esm/index.d.ts} +6 -8
  15. package/dist/esm/index.d.ts.map +1 -0
  16. package/dist/esm/index.js +46 -0
  17. package/dist/esm/index.js.map +1 -0
  18. package/dist/esm/metadata.d.ts +5 -0
  19. package/dist/esm/metadata.d.ts.map +1 -0
  20. package/dist/esm/metadata.js +24 -0
  21. package/dist/esm/metadata.js.map +1 -0
  22. package/dist/esm/sourcify.d.ts +11 -0
  23. package/dist/esm/sourcify.d.ts.map +1 -0
  24. package/dist/esm/sourcify.js +84 -0
  25. package/dist/esm/sourcify.js.map +1 -0
  26. package/dist/esm/utils/match-all.d.ts +42 -0
  27. package/dist/esm/utils/match-all.d.ts.map +1 -0
  28. package/dist/esm/utils/match-all.js +66 -0
  29. package/dist/esm/utils/match-all.js.map +1 -0
  30. package/package.json +10 -15
  31. package/src/blockscout.ts +1 -1
  32. package/src/cli.ts +3 -3
  33. package/src/etherscan.ts +2 -2
  34. package/src/index.ts +3 -3
  35. package/src/sourcify.ts +1 -1
  36. package/tsconfig.json +13 -10
  37. package/dist/cli.cjs +0 -129
  38. package/dist/cli.cjs.map +0 -1
  39. package/dist/cli.mjs +0 -126
  40. package/dist/cli.mjs.map +0 -1
  41. package/dist/index.cjs +0 -671
  42. package/dist/index.cjs.map +0 -1
  43. package/dist/index.mjs +0 -669
  44. package/dist/index.mjs.map +0 -1
package/dist/index.cjs DELETED
@@ -1,671 +0,0 @@
1
- 'use strict';
2
-
3
- var rocketh = require('rocketh');
4
- var fs = require('fs');
5
- var qs = require('qs');
6
- var chalk = require('chalk');
7
- var fs$1 = require('fs-extra');
8
- var path = require('path');
9
-
10
- function matchAll(s, r) {
11
- return {
12
- input: s,
13
- regex: r,
14
- /**
15
- * next
16
- * Get the next match in single group match.
17
- *
18
- * @name next
19
- * @function
20
- * @return {String|null} The matched snippet.
21
- */
22
- next() {
23
- let c = this.nextRaw();
24
- if (c) {
25
- for (let i = 1; i < c.length; i++) {
26
- if (c[i]) {
27
- return c[i];
28
- }
29
- }
30
- }
31
- return null;
32
- },
33
- /**
34
- * nextRaw
35
- * Get the next match in raw regex output. Usefull to get another group match.
36
- *
37
- * @name nextRaw
38
- * @function
39
- * @returns {Array|null} The matched snippet
40
- */
41
- nextRaw() {
42
- let c = this.regex.exec(this.input);
43
- return c;
44
- },
45
- /**
46
- * toArray
47
- * Get all the matches.
48
- *
49
- * @name toArray
50
- * @function
51
- * @return {Array} The matched snippets.
52
- */
53
- toArray() {
54
- let res = [], c = null;
55
- while (c = this.next()) {
56
- res.push(c);
57
- }
58
- return res;
59
- },
60
- /**
61
- * reset
62
- * Reset the index.
63
- *
64
- * @name reset
65
- * @function
66
- * @param {Number} i The new index (default: `0`).
67
- * @return {Number} The new index.
68
- */
69
- reset(i = 0) {
70
- return this.regex.lastIndex = i;
71
- }
72
- };
73
- }
74
-
75
- const defaultEndpoints$1 = {
76
- "1": "https://api.etherscan.io/api",
77
- "3": "https://api-ropsten.etherscan.io/api",
78
- "4": "https://api-rinkeby.etherscan.io/api",
79
- "5": "https://api-goerli.etherscan.io/api",
80
- "10": "https://api-optimistic.etherscan.io/api",
81
- "42": "https://api-kovan.etherscan.io/api",
82
- "97": "https://api-testnet.bscscan.com/api",
83
- "56": "https://api.bscscan.com/api",
84
- "69": "https://api-kovan-optimistic.etherscan.io/api",
85
- "70": "https://api.hooscan.com/api",
86
- "77": "https://blockscout.com/poa/sokol/api",
87
- "128": "https://api.hecoinfo.com/api",
88
- "137": "https://api.polygonscan.com/api",
89
- "250": "https://api.ftmscan.com/api",
90
- "256": "https://api-testnet.hecoinfo.com/api",
91
- "420": "https://api-goerli-optimism.etherscan.io/api",
92
- "588": "https://stardust-explorer.metis.io/api",
93
- "1088": "https://andromeda-explorer.metis.io/api",
94
- "1285": "https://api-moonriver.moonscan.io/api",
95
- "80001": "https://api-testnet.polygonscan.com/api",
96
- "4002": "https://api-testnet.ftmscan.com/api",
97
- "42161": "https://api.arbiscan.io/api",
98
- "421611": "https://api-testnet.arbiscan.io/api",
99
- "421613": "https://api-goerli.arbiscan.io/api",
100
- "43113": "https://api-testnet.snowtrace.io/api",
101
- "43114": "https://api.snowtrace.io/api",
102
- "11155111": "https://api-sepolia.etherscan.io/api"
103
- };
104
- function log$2(...args) {
105
- console.log(...args);
106
- }
107
- function logError$2(...args) {
108
- console.log(chalk.red(...args));
109
- }
110
- function logInfo$2(...args) {
111
- console.log(chalk.yellow(...args));
112
- }
113
- function logSuccess$2(...args) {
114
- console.log(chalk.green(...args));
115
- }
116
- function sleep$2(ms) {
117
- return new Promise((resolve) => setTimeout(resolve, ms));
118
- }
119
- function writeRequestIfRequested(write, networkName, name, request, postData) {
120
- if (write) {
121
- try {
122
- fs.mkdirSync("etherscan_requests");
123
- } catch (e) {
124
- }
125
- const folder = `etherscan_requests/${networkName}`;
126
- try {
127
- fs.mkdirSync(folder);
128
- } catch (e) {
129
- }
130
- fs.writeFileSync(`${folder}/${name}.formdata`, request);
131
- fs.writeFileSync(`${folder}/${name}.json`, JSON.stringify(postData));
132
- fs.writeFileSync(`${folder}/${name}_multi-source.json`, postData.sourceCode);
133
- }
134
- }
135
- function extractOneLicenseFromSourceFile(source) {
136
- const licenses = extractLicenseFromSources(source);
137
- if (licenses.length === 0) {
138
- return void 0;
139
- }
140
- return licenses[0];
141
- }
142
- function extractLicenseFromSources(metadata) {
143
- const regex = /\/\/\s*\t*SPDX-License-Identifier:\s*\t*(.*?)[\s\\]/g;
144
- const matches = matchAll(metadata, regex).toArray();
145
- const licensesFound = {};
146
- const licenses = [];
147
- if (matches) {
148
- for (const match of matches) {
149
- if (!licensesFound[match]) {
150
- licensesFound[match] = true;
151
- licenses.push(match);
152
- }
153
- }
154
- }
155
- return licenses;
156
- }
157
- function getLicenseType(license) {
158
- const licenseType = (() => {
159
- if (license === "None") {
160
- return 1;
161
- }
162
- if (license === "UNLICENSED") {
163
- return 2;
164
- }
165
- if (license === "MIT") {
166
- return 3;
167
- }
168
- if (license === "GPL-2.0") {
169
- return 4;
170
- }
171
- if (license === "GPL-3.0") {
172
- return 5;
173
- }
174
- if (license === "LGPL-2.1") {
175
- return 6;
176
- }
177
- if (license === "LGPL-3.0") {
178
- return 7;
179
- }
180
- if (license === "BSD-2-Clause") {
181
- return 8;
182
- }
183
- if (license === "BSD-3-Clause") {
184
- return 9;
185
- }
186
- if (license === "MPL-2.0") {
187
- return 10;
188
- }
189
- if (license === "OSL-3.0") {
190
- return 11;
191
- }
192
- if (license === "Apache-2.0") {
193
- return 12;
194
- }
195
- if (license === "AGPL-3.0") {
196
- return 13;
197
- }
198
- if (license === "BUSL-1.1") {
199
- return 14;
200
- }
201
- })();
202
- return licenseType;
203
- }
204
- async function submitSourcesToEtherscan(env, config) {
205
- config = config || { type: "etherscan" };
206
- const licenseOption = config.license;
207
- const forceLicense = config.forceLicense;
208
- const etherscanApiKey = config.apiKey;
209
- const all = env.deployments;
210
- const networkName = env.networkName;
211
- let endpoint = config.endpoint;
212
- if (!endpoint) {
213
- endpoint = defaultEndpoints$1[env.chainId];
214
- if (!endpoint) {
215
- return logError$2(`Network with chainId: ${env.chainId} not supported. Please specify the endpoint manually.`);
216
- }
217
- }
218
- async function submit(name) {
219
- const deployment = all[name];
220
- const { address, metadata: metadataString } = deployment;
221
- const abiResponse = await fetch(
222
- `${endpoint}?module=contract&action=getabi&address=${address}&apikey=${etherscanApiKey}`
223
- );
224
- const json = await abiResponse.json();
225
- let contractABI;
226
- if (json.status !== "0") {
227
- try {
228
- contractABI = JSON.parse(json.result);
229
- } catch (e) {
230
- logError$2(e);
231
- return;
232
- }
233
- }
234
- if (contractABI && contractABI !== "") {
235
- log$2(`already verified: ${name} (${address}), skipping.`);
236
- return;
237
- }
238
- if (!metadataString) {
239
- logError$2(`Contract ${name} was deployed without saving metadata. Cannot submit to etherscan, skipping.`);
240
- return;
241
- }
242
- const metadata = JSON.parse(metadataString);
243
- const compilationTarget = metadata.settings?.compilationTarget;
244
- let contractFilepath;
245
- let contractName;
246
- if (compilationTarget) {
247
- contractFilepath = Object.keys(compilationTarget)[0];
248
- contractName = compilationTarget[contractFilepath];
249
- }
250
- if (!contractFilepath || !contractName) {
251
- return logError$2(
252
- `Failed to extract contract fully qualified name from metadata.settings.compilationTarget for ${name}. Skipping.`
253
- );
254
- }
255
- const contractNamePath = `${contractFilepath}:${contractName}`;
256
- const contractSourceFile = metadata.sources[contractFilepath].content;
257
- const sourceLicenseType = extractOneLicenseFromSourceFile(contractSourceFile);
258
- let license = licenseOption;
259
- if (!sourceLicenseType) {
260
- if (!license) {
261
- return logError$2(
262
- `no license speccified in the source code for ${name} (${contractNamePath}), Please use option --license <SPDX>`
263
- );
264
- }
265
- } else {
266
- if (license && license !== sourceLicenseType) {
267
- if (!forceLicense) {
268
- return logError$2(
269
- `mismatch for --license option (${licenseOption}) and the one specified in the source code for ${name}.
270
- Licenses found in source : ${sourceLicenseType}
271
- You can use option --force-license to force option --license`
272
- );
273
- }
274
- } else {
275
- license = sourceLicenseType;
276
- if (!getLicenseType(license)) {
277
- return logError$2(
278
- `license :"${license}" found in source code for ${name} (${contractNamePath}) but this license is not supported by etherscan, list of supported license can be found here : https://etherscan.io/contract-license-types . This tool expect the SPDX id, except for "None" and "UNLICENSED"`
279
- );
280
- }
281
- }
282
- }
283
- const licenseType = getLicenseType(license);
284
- if (!licenseType) {
285
- return logError$2(
286
- `license :"${license}" not supported by etherscan, list of supported license can be found here : https://etherscan.io/contract-license-types . This tool expect the SPDX id, except for "None" and "UNLICENSED"`
287
- );
288
- }
289
- let solcInput;
290
- const settings = { ...metadata.settings };
291
- delete settings.compilationTarget;
292
- solcInput = {
293
- language: metadata.language,
294
- settings,
295
- sources: {}
296
- };
297
- for (const sourcePath of Object.keys(metadata.sources)) {
298
- const source = metadata.sources[sourcePath];
299
- solcInput.sources[sourcePath] = {
300
- content: source.content
301
- };
302
- }
303
- if (deployment.libraries) {
304
- const settings2 = solcInput.settings;
305
- settings2.libraries = settings2.libraries || {};
306
- for (const libraryName of Object.keys(deployment.libraries)) {
307
- if (!settings2.libraries[contractNamePath]) {
308
- settings2.libraries[contractNamePath] = {};
309
- }
310
- settings2.libraries[contractNamePath][libraryName] = deployment.libraries[libraryName];
311
- }
312
- }
313
- const solcInputString = JSON.stringify(solcInput);
314
- logInfo$2(`verifying ${name} (${address}) ...`);
315
- let constructorArguments;
316
- if (deployment.argsData) {
317
- constructorArguments = deployment.argsData.slice(2);
318
- } else {
319
- logInfo$2(`no args found, assuming empty constructor...`);
320
- }
321
- const postData = {
322
- apikey: etherscanApiKey,
323
- module: "contract",
324
- action: "verifysourcecode",
325
- contractaddress: address,
326
- sourceCode: solcInputString,
327
- codeformat: "solidity-standard-json-input",
328
- contractname: contractNamePath,
329
- compilerversion: `v${metadata.compiler.version}`,
330
- // see http://etherscan.io/solcversions for list of support versions
331
- constructorArguements: constructorArguments,
332
- // note the spelling mistake by etherscan
333
- licenseType
334
- };
335
- const formDataAsString = qs.stringify(postData);
336
- const data = new URLSearchParams();
337
- for (const entry of Object.entries(postData)) {
338
- if (entry[1]) {
339
- if (typeof entry[1] === "number") {
340
- data.append(entry[0], entry[1].toString());
341
- } else {
342
- data.append(entry[0], entry[1]);
343
- }
344
- }
345
- }
346
- const submissionResponse = await fetch(`${endpoint}`, {
347
- method: "POST",
348
- headers: { "content-type": "application/x-www-form-urlencoded" },
349
- body: data
350
- });
351
- const submissionJson = await submissionResponse.json();
352
- let guid;
353
- if (submissionJson.status === "1") {
354
- guid = submissionJson.result;
355
- } else {
356
- logError$2(
357
- `contract ${name} failed to submit : "${submissionJson.message}" : "${submissionJson.result}"`,
358
- submissionJson
359
- );
360
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
361
- return;
362
- }
363
- if (!guid) {
364
- logError$2(`contract submission for ${name} failed to return a guid`);
365
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
366
- return;
367
- }
368
- async function checkStatus() {
369
- const statusResponse = await fetch(
370
- `${endpoint}?apikey=${etherscanApiKey}&guid=${guid}&module=contract&action=checkverifystatus`
371
- );
372
- const json2 = await statusResponse.json();
373
- if (json2.result === "Pending in queue") {
374
- return void 0;
375
- }
376
- if (json2.result !== "Fail - Unable to verify") {
377
- if (json2.status === "1") {
378
- return "success";
379
- }
380
- }
381
- logError$2(`Failed to verify contract ${name}: ${json2.message}, ${json2.result}`);
382
- logError$2(
383
- JSON.stringify(
384
- {
385
- apikey: "XXXXXX",
386
- module: "contract",
387
- action: "verifysourcecode",
388
- contractaddress: address,
389
- sourceCode: "...",
390
- codeformat: "solidity-standard-json-input",
391
- contractname: contractNamePath,
392
- compilerversion: `v${metadata.compiler.version}`,
393
- // see http://etherscan.io/solcversions for list of support versions
394
- constructorArguements: constructorArguments,
395
- // note the spelling mistake by etherscan
396
- licenseType
397
- },
398
- null,
399
- " "
400
- )
401
- );
402
- return "failure";
403
- }
404
- logInfo$2("waiting for result...");
405
- let result;
406
- while (!result) {
407
- await new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
408
- result = await checkStatus();
409
- }
410
- if (result === "success") {
411
- logSuccess$2(` => contract ${name} is now verified`);
412
- }
413
- if (result === "failure") {
414
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
415
- logInfo$2("Etherscan failed to verify the source provided");
416
- } else {
417
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
418
- }
419
- }
420
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
421
- await submit(name);
422
- if (env.minInterval) {
423
- await sleep$2(env.minInterval);
424
- }
425
- }
426
- }
427
-
428
- function sleep$1(ms) {
429
- return new Promise((resolve) => setTimeout(resolve, ms));
430
- }
431
- function log$1(...args) {
432
- console.log(...args);
433
- }
434
- function logError$1(...args) {
435
- console.log(chalk.red(...args));
436
- }
437
- function logInfo$1(...args) {
438
- console.log(chalk.yellow(...args));
439
- }
440
- function logSuccess$1(...args) {
441
- console.log(chalk.green(...args));
442
- }
443
- function ensureTrailingSlash$1(s) {
444
- const lastChar = s.substr(-1);
445
- if (lastChar != "/") {
446
- s = s + "/";
447
- }
448
- return s;
449
- }
450
- const defaultEndpoint = "https://sourcify.dev/server/";
451
- async function submitSourcesToSourcify(env, config) {
452
- config = config || { type: "sourcify" };
453
- const all = env.deployments;
454
- const url = config.endpoint ? ensureTrailingSlash$1(config.endpoint) : defaultEndpoint;
455
- async function submit(name) {
456
- const deployment = all[name];
457
- const { address, metadata: metadataString } = deployment;
458
- try {
459
- const checkResponse = await fetch(
460
- `${url}checkByAddresses?addresses=${address.toLowerCase()}&chainIds=${env.chainId}`
461
- );
462
- const json = await checkResponse.json();
463
- if (json[0].status === "perfect") {
464
- log$1(`already verified: ${name} (${address}), skipping.`);
465
- return;
466
- }
467
- } catch (e) {
468
- logError$1(e.response && JSON.stringify(e.response.data) || e);
469
- }
470
- if (!metadataString) {
471
- logError$1(`Contract ${name} was deployed without saving metadata. Cannot submit to sourcify, skipping.`);
472
- return;
473
- }
474
- logInfo$1(`verifying ${name} (${address} on chain ${env.chainId}) ...`);
475
- const formData = new FormData();
476
- formData.append("address", address);
477
- formData.append("chain", env.chainId);
478
- const metadataBlob = new Blob([metadataString], {
479
- type: "application/json"
480
- });
481
- formData.append("files", metadataBlob, "metadata.json");
482
- try {
483
- const submissionResponse = await fetch(url, { body: formData, method: "POST" });
484
- const json = await submissionResponse.json();
485
- if (json.result[0].status === "perfect") {
486
- logSuccess$1(` => contract ${name} is now verified`);
487
- } else {
488
- logError$1(` => contract ${name} is not verified`);
489
- }
490
- } catch (e) {
491
- if (env?.logErrorOnFailure) {
492
- const failingMetadataFolder = path.join("failing_metadata", env.chainId);
493
- fs$1.ensureDirSync(failingMetadataFolder);
494
- fs$1.writeFileSync(path.join(failingMetadataFolder, `${name}_at_${address}.json`), metadataString);
495
- }
496
- logError$1(e.response && JSON.stringify(e.response.data) || e);
497
- }
498
- }
499
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
500
- await submit(name);
501
- if (env.minInterval) {
502
- await sleep$1(env.minInterval);
503
- }
504
- }
505
- }
506
-
507
- const defaultEndpoints = {
508
- "1": "https://eth.blockscout.com/api/v2",
509
- "11155111": "https://eth-sepolia.blockscout.com/api/v2",
510
- "5": "https://eth-goerli.blockscout.com/api/v2",
511
- "10": "https://optimism.blockscout.com/api/v2",
512
- "11155420": "https://optimism-sepolia.blockscout.com/api/v2",
513
- "61": "https://etc.blockscout.com/api/v2",
514
- "324": "https://zksync.blockscout.com/api/v2",
515
- "8453": "https://base.blockscout.com/api/v2",
516
- "84532": "https://base-sepolia.blockscout.com/api/v2",
517
- "100": "https://gnosis.blockscout.com/api/v2",
518
- "10200": "https://gnosis-chiado.blockscout.com/api/v2",
519
- "17001": "https://17001-explorer-api.quarry.linfra.xyz/api/v2"
520
- // probably temporary
521
- };
522
- function sleep(ms) {
523
- return new Promise((resolve) => setTimeout(resolve, ms));
524
- }
525
- function log(...args) {
526
- console.log(...args);
527
- }
528
- function logError(...args) {
529
- console.log(chalk.red(...args));
530
- }
531
- function logInfo(...args) {
532
- console.log(chalk.yellow(...args));
533
- }
534
- function logSuccess(...args) {
535
- console.log(chalk.green(...args));
536
- }
537
- function ensureTrailingSlash(s) {
538
- if (!s.endsWith("/")) {
539
- s = s + "/";
540
- }
541
- return s;
542
- }
543
- async function submitSourcesToBlockscout(env, config) {
544
- config = config || { type: "blockscout" };
545
- const all = env.deployments;
546
- const url = config.endpoint ? ensureTrailingSlash(config.endpoint) : ensureTrailingSlash(defaultEndpoints[env.chainId]);
547
- if (!url) {
548
- logError(`no endpoint provided and no default known for chainId ${env.chainId}`);
549
- return;
550
- }
551
- async function submit(name, deployment) {
552
- const { address, metadata } = deployment;
553
- try {
554
- const checkResponse = await fetch(`${url}smart-contracts/${address.toLowerCase()}`);
555
- const json = await checkResponse.json();
556
- if (json.is_verified) {
557
- log(`already verified: ${name} (${address}), skipping.`);
558
- return;
559
- }
560
- } catch (e) {
561
- logError(e.response && JSON.stringify(e.response.data) || e);
562
- }
563
- const metadataObj = JSON.parse(metadata);
564
- const compilationTarget = metadataObj.settings?.compilationTarget;
565
- let contractFilepath;
566
- let contractName;
567
- if (compilationTarget) {
568
- contractFilepath = Object.keys(compilationTarget)[0];
569
- contractName = compilationTarget[contractFilepath];
570
- }
571
- if (!contractFilepath || !contractName) {
572
- return logError(
573
- `Failed to extract contract fully qualified name from metadata.settings.compilationTarget for ${name}. Skipping.`
574
- );
575
- }
576
- const contractNamePath = `${contractFilepath}:${contractName}`;
577
- const formData = new FormData();
578
- formData.append("address_hash", address);
579
- formData.append("compiler_version", JSON.parse(metadata).compiler.version);
580
- formData.append("constructor_args", deployment.argsData);
581
- formData.append("autodetect_constructor_args", "false");
582
- formData.append("contract_name", contractNamePath);
583
- const metadataBlob = new Blob([metadata], {
584
- type: "application/json"
585
- });
586
- formData.append("files[0]", metadataBlob, "metadata.json");
587
- try {
588
- const submissionResponse = await fetch(
589
- `${url}smart-contracts/${address.toLowerCase()}/verification/via/standard-input`,
590
- { body: formData, method: "POST" }
591
- );
592
- const json = await submissionResponse.json();
593
- if (json.message === "Smart-contract verification started") {
594
- logSuccess(` => contract ${name} verification has started`);
595
- } else {
596
- logError(` => contract ${name} might not have gone throyugh`, json);
597
- }
598
- } catch (e) {
599
- if (env?.logErrorOnFailure) {
600
- const failingMetadataFolder = path.join("failing_metadata", env.chainId);
601
- fs$1.ensureDirSync(failingMetadataFolder);
602
- fs$1.writeFileSync(path.join(failingMetadataFolder, `${name}_at_${address}.json`), metadata);
603
- }
604
- logError(e.response && JSON.stringify(e.response.data) || e);
605
- }
606
- }
607
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
608
- const deployment = all[name];
609
- if (!deployment.metadata) {
610
- logError(`Contract ${name} was deployed without saving metadata. Cannot submit to sourcify, skipping.`);
611
- return;
612
- }
613
- logInfo(`verifying ${name} (${deployment.address} on chain ${env.chainId}) ...`);
614
- await submit(name, deployment);
615
- if (env.minInterval) {
616
- await sleep(env.minInterval);
617
- }
618
- }
619
- }
620
-
621
- async function run(config, options) {
622
- const { deployments, chainId } = rocketh.loadDeployments(config.deployments, config.network.name, false);
623
- if (Object.keys(deployments).length === 0) {
624
- console.log(`the network ${config.network.name} has zero deployments`);
625
- process.exit();
626
- }
627
- if (!chainId) {
628
- console.error(`the network ${config.network.name} has no chainId recorded`);
629
- process.exit(1);
630
- }
631
- if (options.verifier.type === "etherscan") {
632
- await submitSourcesToEtherscan(
633
- {
634
- chainId,
635
- deployments,
636
- networkName: config.network.name,
637
- deploymentNames: options.deploymentNames,
638
- minInterval: options.minInterval,
639
- logErrorOnFailure: options.logErrorOnFailure
640
- },
641
- options.verifier
642
- );
643
- } else if (options.verifier.type === "sourcify") {
644
- await submitSourcesToSourcify(
645
- {
646
- chainId,
647
- deployments,
648
- networkName: config.network.name,
649
- deploymentNames: options.deploymentNames,
650
- minInterval: options.minInterval,
651
- logErrorOnFailure: options.logErrorOnFailure
652
- },
653
- options.verifier
654
- );
655
- } else if (options.verifier.type === "blockscout") {
656
- await submitSourcesToBlockscout(
657
- {
658
- chainId,
659
- deployments,
660
- networkName: config.network.name,
661
- deploymentNames: options.deploymentNames,
662
- minInterval: options.minInterval,
663
- logErrorOnFailure: options.logErrorOnFailure
664
- },
665
- options.verifier
666
- );
667
- }
668
- }
669
-
670
- exports.run = run;
671
- //# sourceMappingURL=index.cjs.map