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