@rocketh/verifier 0.10.11 → 0.10.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocketh/verifier",
3
- "version": "0.10.11",
3
+ "version": "0.10.12",
4
4
  "description": "submit verification proof to verifier services (blockchain explorer, sourcify...",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,6 +17,9 @@
17
17
  "bin": {
18
18
  "rocketh-verify": "dist/cli.js"
19
19
  },
20
+ "files": [
21
+ "dist"
22
+ ],
20
23
  "devDependencies": {
21
24
  "@types/node": "^20.14.8",
22
25
  "as-soon": "^0.0.11",
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- dist/
2
- node_modules/
3
- package.json
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "useTabs": true,
3
- "singleQuote": true,
4
-
5
- "printWidth": 120,
6
- "bracketSpacing": false
7
- }
package/CHANGELOG.md DELETED
@@ -1,78 +0,0 @@
1
- # @rocketh/verifier
2
-
3
- ## 0.10.11
4
-
5
- ### Patch Changes
6
-
7
- - use tsx
8
- - Updated dependencies
9
- - rocketh@0.10.16
10
-
11
- ## 0.10.10
12
-
13
- ### Patch Changes
14
-
15
- - Updated dependencies
16
- - rocketh@0.10.15
17
-
18
- ## 0.10.9
19
-
20
- ### Patch Changes
21
-
22
- - latest dependencies
23
- - Updated dependencies
24
- - rocketh@0.10.14
25
-
26
- ## 0.10.8
27
-
28
- ### Patch Changes
29
-
30
- - fix type + allow license specification for etherscan
31
-
32
- ## 0.10.7
33
-
34
- ### Patch Changes
35
-
36
- - Updated dependencies
37
- - rocketh@0.10.13
38
-
39
- ## 0.10.6
40
-
41
- ### Patch Changes
42
-
43
- - Updated dependencies
44
- - rocketh@0.10.12
45
-
46
- ## 0.10.5
47
-
48
- ### Patch Changes
49
-
50
- - forgot to build
51
-
52
- ## 0.10.4
53
-
54
- ### Patch Changes
55
-
56
- - chalk do not support cjs
57
-
58
- ## 0.10.3
59
-
60
- ### Patch Changes
61
-
62
- - Updated dependencies
63
- - rocketh@0.10.11
64
-
65
- ## 0.10.2
66
-
67
- ### Patch Changes
68
-
69
- - Updated dependencies
70
- - rocketh@0.10.10
71
-
72
- ## 0.10.1
73
-
74
- ### Patch Changes
75
-
76
- - use pkgroll and @rocketh namespace
77
- - Updated dependencies
78
- - rocketh@0.10.9
package/src/blockscout.ts DELETED
@@ -1,157 +0,0 @@
1
- import chalk from 'chalk';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import {Abi, Deployment, UnknownDeployments} from 'rocketh';
5
- import {BlockscoutOptions} from './index.js';
6
-
7
- //https://eth.blockscout.com/api/v2/search?q=WETH
8
- const defaultEndpoints: {[chainId: string]: string} = {
9
- '1': 'https://eth.blockscout.com/api/v2',
10
- '11155111': 'https://eth-sepolia.blockscout.com/api/v2',
11
- '5': 'https://eth-goerli.blockscout.com/api/v2',
12
- '10': 'https://optimism.blockscout.com/api/v2',
13
- '11155420': 'https://optimism-sepolia.blockscout.com/api/v2',
14
- '61': 'https://etc.blockscout.com/api/v2',
15
- '324': 'https://zksync.blockscout.com/api/v2',
16
- '8453': 'https://base.blockscout.com/api/v2',
17
- '84532': 'https://base-sepolia.blockscout.com/api/v2',
18
- '100': 'https://gnosis.blockscout.com/api/v2',
19
- '10200': 'https://gnosis-chiado.blockscout.com/api/v2',
20
- '17001': 'https://17001-explorer-api.quarry.linfra.xyz/api/v2', // probably temporary
21
- };
22
-
23
- function sleep(ms: number) {
24
- return new Promise((resolve) => setTimeout(resolve, ms));
25
- }
26
-
27
- function log(...args: any[]) {
28
- console.log(...args);
29
- }
30
-
31
- function logError(...args: any[]) {
32
- console.log(chalk.red(...args));
33
- }
34
-
35
- function logInfo(...args: any[]) {
36
- console.log(chalk.yellow(...args));
37
- }
38
-
39
- function logSuccess(...args: any[]) {
40
- console.log(chalk.green(...args));
41
- }
42
-
43
- function ensureTrailingSlash(s: string): string {
44
- if (!s.endsWith('/')) {
45
- s = s + '/';
46
- }
47
- return s;
48
- }
49
-
50
- export async function submitSourcesToBlockscout(
51
- env: {
52
- deployments: UnknownDeployments;
53
- networkName: string;
54
- chainId: string;
55
- deploymentNames?: string[];
56
- minInterval?: number;
57
- logErrorOnFailure?: boolean;
58
- },
59
- config?: BlockscoutOptions
60
- ): Promise<void> {
61
- config = config || {type: 'blockscout'};
62
- const all = env.deployments;
63
- const url = config.endpoint
64
- ? ensureTrailingSlash(config.endpoint)
65
- : ensureTrailingSlash(defaultEndpoints[env.chainId]);
66
-
67
- if (!url) {
68
- logError(`no endpoint provided and no default known for chainId ${env.chainId}`);
69
- return;
70
- }
71
-
72
- async function submit(name: string, deployment: Deployment<Abi>) {
73
- const {address, metadata} = deployment;
74
-
75
- try {
76
- const checkResponse = await fetch(`${url}smart-contracts/${address.toLowerCase()}`);
77
- const json = await checkResponse.json();
78
- if (json.is_verified) {
79
- log(`already verified: ${name} (${address}), skipping.`);
80
- return;
81
- }
82
- } catch (e) {
83
- logError(((e as any).response && JSON.stringify((e as any).response.data)) || e);
84
- }
85
-
86
- const metadataObj = JSON.parse(metadata);
87
- const compilationTarget = metadataObj.settings?.compilationTarget;
88
-
89
- let contractFilepath;
90
- let contractName;
91
- if (compilationTarget) {
92
- contractFilepath = Object.keys(compilationTarget)[0];
93
- contractName = compilationTarget[contractFilepath];
94
- }
95
-
96
- if (!contractFilepath || !contractName) {
97
- return logError(
98
- `Failed to extract contract fully qualified name from metadata.settings.compilationTarget for ${name}. Skipping.`
99
- );
100
- }
101
-
102
- const contractNamePath = `${contractFilepath}:${contractName}`;
103
-
104
- const formData = new FormData();
105
- formData.append('address_hash', address);
106
- formData.append('compiler_version', JSON.parse(metadata).compiler.version);
107
- formData.append('constructor_args', deployment.argsData);
108
- formData.append('autodetect_constructor_args', 'false');
109
- formData.append('contract_name', contractNamePath);
110
-
111
- const metadataBlob = new Blob([metadata], {
112
- type: 'application/json',
113
- });
114
- formData.append('files[0]', metadataBlob, 'metadata.json');
115
-
116
- try {
117
- const submissionResponse = await fetch(
118
- `${url}smart-contracts/${address.toLowerCase()}/verification/via/standard-input`,
119
- {body: formData, method: 'POST'}
120
- );
121
- const json = await submissionResponse.json();
122
- if (json.message === 'Smart-contract verification started') {
123
- logSuccess(` => contract ${name} verification has started`);
124
- } else {
125
- logError(` => contract ${name} might not have gone throyugh`, json);
126
- }
127
- } catch (e) {
128
- if (env?.logErrorOnFailure) {
129
- const failingMetadataFolder = path.join('failing_metadata', env.chainId);
130
- fs.ensureDirSync(failingMetadataFolder);
131
- fs.writeFileSync(path.join(failingMetadataFolder, `${name}_at_${address}.json`), metadata);
132
- }
133
- logError(((e as any).response && JSON.stringify((e as any).response.data)) || e);
134
- }
135
- }
136
-
137
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
138
- const deployment = all[name];
139
-
140
- if (!deployment.metadata) {
141
- logError(`Contract ${name} was deployed without saving metadata. Cannot submit to sourcify, skipping.`);
142
- return;
143
- }
144
-
145
- logInfo(`verifying ${name} (${deployment.address} on chain ${env.chainId}) ...`);
146
-
147
- // if (config?.version === 'v1') {
148
- // await submitV1(name, deployment);
149
- // } else {
150
- await submit(name, deployment);
151
- // }
152
-
153
- if (env.minInterval) {
154
- await sleep(env.minInterval);
155
- }
156
- }
157
- }
package/src/cli.ts DELETED
@@ -1,73 +0,0 @@
1
- #! /usr/bin/env node
2
- import {loadEnv} from 'ldenv';
3
- import {readAndResolveConfig} from 'rocketh';
4
- import {run} from './index.js';
5
- import {Command, Option} from 'commander';
6
- import pkg from '../package.json' with {type: 'json'};
7
- import {ConfigOptions} from 'rocketh';
8
- import {exportMetadata} from './metadata.js';
9
- loadEnv();
10
-
11
- const commandName = `rocketh-verify`;
12
-
13
- const program = new Command();
14
- program
15
- .name(commandName)
16
- .description('submit contract for verification')
17
- .version(pkg.version)
18
-
19
- .option('-d, --deployments <value>', 'folder where deployments are saved')
20
- .requiredOption('-n, --network <value>', 'network context to use');
21
-
22
- program
23
- .command('etherscan')
24
- .description('submit contract for verification to etherscan')
25
- .option('--endpoint <value>', 'endpoint to connect to')
26
- .option('--license <value>', 'source code license')
27
- .option('--force-license', 'force the use of the license provided')
28
- .action((options: {endpoint?: string; forceLicense: boolean; license: string}) => {
29
- const programOptions = program.opts() as ConfigOptions;
30
- const resolvedConfig = readAndResolveConfig({...programOptions, ignoreMissingRPC: true});
31
- run(resolvedConfig, {
32
- verifier: {
33
- type: 'etherscan',
34
- apiKey: process.env['ETHERSCAN_API_KEY'],
35
- endpoint: options.endpoint,
36
- forceLicense: options.forceLicense,
37
- license: options.license,
38
- },
39
- });
40
- });
41
-
42
- program
43
- .command('sourcify')
44
- .description('submit contract for verification to sourcify')
45
- .option('--endpoint <value>', 'endpoint to connect to')
46
- .action((options: {endpoint?: string}) => {
47
- const programOptions = program.opts() as ConfigOptions;
48
- const resolvedConfig = readAndResolveConfig({...programOptions, ignoreMissingRPC: true});
49
- run(resolvedConfig, {verifier: {type: 'sourcify', endpoint: options.endpoint}});
50
- });
51
-
52
- program
53
- .command('blockscout')
54
- .description('submit contract for verification to blockscout')
55
- .option('--endpoint <value>', 'endpoint to connect to')
56
- // .option('--api <value>', 'api version (default to v2)')
57
- .action((options: {endpoint?: string}) => {
58
- const programOptions = program.opts() as ConfigOptions;
59
- const resolvedConfig = readAndResolveConfig({...programOptions, ignoreMissingRPC: true});
60
- run(resolvedConfig, {verifier: {type: 'blockscout', endpoint: options.endpoint}});
61
- });
62
-
63
- program
64
- .command('metadata')
65
- .description('export metadata')
66
- .option('--out <value>', 'folder to write metadata into')
67
- .action((options: {out?: string}) => {
68
- const programOptions = program.opts() as ConfigOptions;
69
- const resolvedConfig = readAndResolveConfig({...programOptions, ignoreMissingRPC: true});
70
- exportMetadata(resolvedConfig, {out: options.out || '_metadata'});
71
- });
72
-
73
- program.parse(process.argv);
package/src/etherscan.ts DELETED
@@ -1,431 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import fs from 'fs';
3
- import qs from 'qs';
4
- import chalk from 'chalk';
5
- import {matchAll} from './utils/match-all.js';
6
- import {Environment, UnknownDeployments} from 'rocketh';
7
- import {EtherscanOptions} from './index.js';
8
-
9
- const defaultEndpoints: {[chainId: string]: string} = {
10
- '1': 'https://api.etherscan.io/api',
11
- '3': 'https://api-ropsten.etherscan.io/api',
12
- '4': 'https://api-rinkeby.etherscan.io/api',
13
- '5': 'https://api-goerli.etherscan.io/api',
14
- '10': 'https://api-optimistic.etherscan.io/api',
15
- '42': 'https://api-kovan.etherscan.io/api',
16
- '97': 'https://api-testnet.bscscan.com/api',
17
- '56': 'https://api.bscscan.com/api',
18
- '69': 'https://api-kovan-optimistic.etherscan.io/api',
19
- '70': 'https://api.hooscan.com/api',
20
- '77': 'https://blockscout.com/poa/sokol/api',
21
- '128': 'https://api.hecoinfo.com/api',
22
- '137': 'https://api.polygonscan.com/api',
23
- '250': 'https://api.ftmscan.com/api',
24
- '256': 'https://api-testnet.hecoinfo.com/api',
25
- '420': 'https://api-goerli-optimism.etherscan.io/api',
26
- '588': 'https://stardust-explorer.metis.io/api',
27
- '1088': 'https://andromeda-explorer.metis.io/api',
28
- '1285': 'https://api-moonriver.moonscan.io/api',
29
- '80001': 'https://api-testnet.polygonscan.com/api',
30
- '4002': 'https://api-testnet.ftmscan.com/api',
31
- '42161': 'https://api.arbiscan.io/api',
32
- '421611': 'https://api-testnet.arbiscan.io/api',
33
- '421613': 'https://api-goerli.arbiscan.io/api',
34
- '43113': 'https://api-testnet.snowtrace.io/api',
35
- '43114': 'https://api.snowtrace.io/api',
36
- '11155111': 'https://api-sepolia.etherscan.io/api',
37
- };
38
-
39
- function log(...args: any[]) {
40
- console.log(...args);
41
- }
42
-
43
- function logError(...args: any[]) {
44
- console.log(chalk.red(...args));
45
- }
46
-
47
- function logInfo(...args: any[]) {
48
- console.log(chalk.yellow(...args));
49
- }
50
-
51
- function logSuccess(...args: any[]) {
52
- console.log(chalk.green(...args));
53
- }
54
-
55
- function sleep(ms: number) {
56
- return new Promise((resolve) => setTimeout(resolve, ms));
57
- }
58
-
59
- function writeRequestIfRequested(
60
- write: boolean,
61
- networkName: string,
62
- name: string,
63
- request: string,
64
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
65
- postData: any
66
- ) {
67
- if (write) {
68
- try {
69
- fs.mkdirSync('etherscan_requests');
70
- } catch (e) {}
71
- const folder = `etherscan_requests/${networkName}`;
72
- try {
73
- fs.mkdirSync(folder);
74
- } catch (e) {}
75
- fs.writeFileSync(`${folder}/${name}.formdata`, request);
76
- fs.writeFileSync(`${folder}/${name}.json`, JSON.stringify(postData));
77
- fs.writeFileSync(`${folder}/${name}_multi-source.json`, postData.sourceCode);
78
- }
79
- }
80
-
81
- function extractOneLicenseFromSourceFile(source: string): string | undefined {
82
- const licenses = extractLicenseFromSources(source);
83
- if (licenses.length === 0) {
84
- return undefined;
85
- }
86
- return licenses[0]; // TODO error out on multiple SPDX ?
87
- }
88
-
89
- function extractLicenseFromSources(metadata: string): string[] {
90
- const regex = /\/\/\s*\t*SPDX-License-Identifier:\s*\t*(.*?)[\s\\]/g;
91
- const matches = matchAll(metadata, regex).toArray();
92
- const licensesFound: {[license: string]: boolean} = {};
93
- const licenses = [];
94
- if (matches) {
95
- for (const match of matches) {
96
- if (!licensesFound[match]) {
97
- licensesFound[match] = true;
98
- licenses.push(match);
99
- }
100
- }
101
- }
102
- return licenses;
103
- }
104
-
105
- function getLicenseType(license: string): undefined | number {
106
- const licenseType = (() => {
107
- if (license === 'None') {
108
- return 1;
109
- }
110
- if (license === 'UNLICENSED') {
111
- return 2;
112
- }
113
- if (license === 'MIT') {
114
- return 3;
115
- }
116
- if (license === 'GPL-2.0') {
117
- return 4;
118
- }
119
- if (license === 'GPL-3.0') {
120
- return 5;
121
- }
122
- if (license === 'LGPL-2.1') {
123
- return 6;
124
- }
125
- if (license === 'LGPL-3.0') {
126
- return 7;
127
- }
128
- if (license === 'BSD-2-Clause') {
129
- return 8;
130
- }
131
- if (license === 'BSD-3-Clause') {
132
- return 9;
133
- }
134
- if (license === 'MPL-2.0') {
135
- return 10;
136
- }
137
- if (license === 'OSL-3.0') {
138
- return 11;
139
- }
140
- if (license === 'Apache-2.0') {
141
- return 12;
142
- }
143
- if (license === 'AGPL-3.0') {
144
- return 13;
145
- }
146
- if (license === 'BUSL-1.1') {
147
- return 14;
148
- }
149
- })();
150
- return licenseType;
151
- }
152
-
153
- export async function submitSourcesToEtherscan(
154
- env: {
155
- deployments: UnknownDeployments;
156
- networkName: string;
157
- chainId: string;
158
- deploymentNames?: string[];
159
- minInterval?: number;
160
- logErrorOnFailure?: boolean;
161
- },
162
- config?: EtherscanOptions
163
- ): Promise<void> {
164
- config = config || {type: 'etherscan'};
165
- const licenseOption = config.license;
166
- const forceLicense = config.forceLicense;
167
- const etherscanApiKey = config.apiKey;
168
- const all = env.deployments;
169
- const networkName = env.networkName;
170
- let endpoint = config.endpoint;
171
- if (!endpoint) {
172
- endpoint = defaultEndpoints[env.chainId];
173
- if (!endpoint) {
174
- return logError(`Network with chainId: ${env.chainId} not supported. Please specify the endpoint manually.`);
175
- }
176
- }
177
-
178
- async function submit(name: string) {
179
- const deployment = all[name];
180
- const {address, metadata: metadataString} = deployment;
181
- const abiResponse = await fetch(
182
- `${endpoint}?module=contract&action=getabi&address=${address}&apikey=${etherscanApiKey}`
183
- );
184
- const json = await abiResponse.json();
185
- let contractABI;
186
- if (json.status !== '0') {
187
- try {
188
- contractABI = JSON.parse(json.result);
189
- } catch (e) {
190
- logError(e);
191
- return;
192
- }
193
- }
194
- if (contractABI && contractABI !== '') {
195
- log(`already verified: ${name} (${address}), skipping.`);
196
- return;
197
- }
198
-
199
- if (!metadataString) {
200
- logError(`Contract ${name} was deployed without saving metadata. Cannot submit to etherscan, skipping.`);
201
- return;
202
- }
203
- const metadata = JSON.parse(metadataString);
204
- const compilationTarget = metadata.settings?.compilationTarget;
205
-
206
- let contractFilepath;
207
- let contractName;
208
- if (compilationTarget) {
209
- contractFilepath = Object.keys(compilationTarget)[0];
210
- contractName = compilationTarget[contractFilepath];
211
- }
212
-
213
- if (!contractFilepath || !contractName) {
214
- return logError(
215
- `Failed to extract contract fully qualified name from metadata.settings.compilationTarget for ${name}. Skipping.`
216
- );
217
- }
218
-
219
- const contractNamePath = `${contractFilepath}:${contractName}`;
220
-
221
- const contractSourceFile = metadata.sources[contractFilepath].content;
222
- const sourceLicenseType = extractOneLicenseFromSourceFile(contractSourceFile);
223
-
224
- let license = licenseOption;
225
- if (!sourceLicenseType) {
226
- if (!license) {
227
- return logError(
228
- `no license speccified in the source code for ${name} (${contractNamePath}), Please use option --license <SPDX>`
229
- );
230
- }
231
- } else {
232
- if (license && license !== sourceLicenseType) {
233
- if (!forceLicense) {
234
- return logError(
235
- `mismatch for --license option (${licenseOption}) and the one specified in the source code for ${name}.\nLicenses found in source : ${sourceLicenseType}\nYou can use option --force-license to force option --license`
236
- );
237
- }
238
- } else {
239
- license = sourceLicenseType;
240
- if (!getLicenseType(license)) {
241
- return logError(
242
- `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"`
243
- );
244
- }
245
- }
246
- }
247
-
248
- const licenseType = getLicenseType(license);
249
-
250
- if (!licenseType) {
251
- return logError(
252
- `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"`
253
- );
254
- }
255
-
256
- let solcInput: {
257
- language: string;
258
- settings: any;
259
- sources: Record<string, {content: string}>;
260
- };
261
-
262
- const settings = {...metadata.settings};
263
- delete settings.compilationTarget;
264
- solcInput = {
265
- language: metadata.language,
266
- settings,
267
- sources: {},
268
- };
269
- for (const sourcePath of Object.keys(metadata.sources)) {
270
- const source = metadata.sources[sourcePath];
271
- // only content as this fails otherwise
272
- solcInput.sources[sourcePath] = {
273
- content: source.content,
274
- };
275
- }
276
-
277
- // Adding Libraries ....
278
- if (deployment.libraries) {
279
- const settings = solcInput.settings;
280
- settings.libraries = settings.libraries || {};
281
- for (const libraryName of Object.keys(deployment.libraries)) {
282
- if (!settings.libraries[contractNamePath]) {
283
- settings.libraries[contractNamePath] = {};
284
- }
285
- settings.libraries[contractNamePath][libraryName] = deployment.libraries[libraryName];
286
- }
287
- }
288
- const solcInputString = JSON.stringify(solcInput);
289
-
290
- logInfo(`verifying ${name} (${address}) ...`);
291
-
292
- let constructorArguments: string | undefined;
293
- if (deployment.argsData) {
294
- constructorArguments = deployment.argsData.slice(2);
295
- } else {
296
- // TODO ?
297
- // logInfo(`no argsData found, falling back on args (hardhat-deploy v1)`);
298
- // if ((deployment as any).args) {
299
- // const constructorABI: {inputs: any[]} = deployment.abi.find(
300
- // (v) => v.type === 'constructor'
301
- // );
302
- // if (constructorABI) {
303
- // constructorArguements = encode
304
- // .encode(constructor.inputs, deployment.args)
305
- // .slice(2);
306
- // }
307
- // } else {
308
- // logInfo(`no args found, assuming empty constructor...`);
309
- // }
310
- logInfo(`no args found, assuming empty constructor...`);
311
- }
312
-
313
- const postData: {
314
- [fieldName: string]: string | number | void | undefined; // TODO type
315
- } = {
316
- apikey: etherscanApiKey,
317
- module: 'contract',
318
- action: 'verifysourcecode',
319
- contractaddress: address,
320
- sourceCode: solcInputString,
321
- codeformat: 'solidity-standard-json-input',
322
- contractname: contractNamePath,
323
- compilerversion: `v${metadata.compiler.version}`, // see http://etherscan.io/solcversions for list of support versions
324
- constructorArguements: constructorArguments, // note the spelling mistake by etherscan
325
- licenseType,
326
- };
327
-
328
- const formDataAsString = qs.stringify(postData);
329
- const data = new URLSearchParams();
330
- for (const entry of Object.entries(postData)) {
331
- if (entry[1]) {
332
- if (typeof entry[1] === 'number') {
333
- data.append(entry[0], entry[1].toString());
334
- } else {
335
- data.append(entry[0], entry[1]);
336
- }
337
- }
338
- }
339
- const submissionResponse = await fetch(`${endpoint}`, {
340
- method: 'POST',
341
- headers: {'content-type': 'application/x-www-form-urlencoded'},
342
- body: data,
343
- });
344
- const submissionJson = await submissionResponse.json();
345
-
346
- let guid: string;
347
- if (submissionJson.status === '1') {
348
- guid = submissionJson.result;
349
- } else {
350
- logError(
351
- `contract ${name} failed to submit : "${submissionJson.message}" : "${submissionJson.result}"`,
352
- submissionJson
353
- );
354
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
355
- return;
356
- }
357
- if (!guid) {
358
- logError(`contract submission for ${name} failed to return a guid`);
359
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
360
- return;
361
- }
362
-
363
- async function checkStatus(): Promise<string | undefined> {
364
- // TODO while loop and delay :
365
- const statusResponse = await fetch(
366
- `${endpoint}?apikey=${etherscanApiKey}&guid=${guid}&module=contract&action=checkverifystatus`
367
- );
368
- const json = await statusResponse.json();
369
-
370
- // blockscout seems to return status == 1 in case of failure
371
- // so we check string first
372
- if (json.result === 'Pending in queue') {
373
- return undefined;
374
- }
375
- if (json.result !== 'Fail - Unable to verify') {
376
- if (json.status === '1') {
377
- // console.log(statusData);
378
- return 'success';
379
- }
380
- }
381
- logError(`Failed to verify contract ${name}: ${json.message}, ${json.result}`);
382
-
383
- logError(
384
- JSON.stringify(
385
- {
386
- apikey: 'XXXXXX',
387
- module: 'contract',
388
- action: 'verifysourcecode',
389
- contractaddress: address,
390
- sourceCode: '...',
391
- codeformat: 'solidity-standard-json-input',
392
- contractname: contractNamePath,
393
- compilerversion: `v${metadata.compiler.version}`, // see http://etherscan.io/solcversions for list of support versions
394
- constructorArguements: constructorArguments, // note the spelling mistake by etherscan
395
- licenseType,
396
- },
397
- null,
398
- ' '
399
- )
400
- );
401
- // logError(JSON.stringify(postData, null, " "));
402
- // logInfo(postData.sourceCode);
403
- return 'failure';
404
- }
405
-
406
- logInfo('waiting for result...');
407
- let result;
408
- while (!result) {
409
- await new Promise((resolve) => setTimeout(resolve, 10 * 1000));
410
- result = await checkStatus();
411
- }
412
-
413
- if (result === 'success') {
414
- logSuccess(` => contract ${name} is now verified`);
415
- }
416
-
417
- if (result === 'failure') {
418
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
419
- logInfo('Etherscan failed to verify the source provided');
420
- } else {
421
- writeRequestIfRequested(env?.logErrorOnFailure || false, networkName, name, formDataAsString, postData);
422
- }
423
- }
424
-
425
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
426
- await submit(name);
427
- if (env.minInterval) {
428
- await sleep(env.minInterval);
429
- }
430
- }
431
- }
package/src/index.ts DELETED
@@ -1,82 +0,0 @@
1
- import {ResolvedConfig, loadDeployments} from 'rocketh';
2
- import {submitSourcesToEtherscan} from './etherscan.js';
3
- import {submitSourcesToSourcify} from './sourcify.js';
4
- import {submitSourcesToBlockscout} from './blockscout.js';
5
-
6
- export type EtherscanOptions = {
7
- type: 'etherscan';
8
- endpoint?: string;
9
- apiKey?: string;
10
- license?: string;
11
- forceLicense?: boolean;
12
- };
13
-
14
- export type SourcifyOptions = {
15
- type: 'sourcify';
16
- endpoint?: string;
17
- };
18
-
19
- export type BlockscoutOptions = {
20
- type: 'blockscout';
21
- endpoint?: string;
22
- // version?: string;
23
- };
24
-
25
- export type VerificationOptions = {
26
- verifier: EtherscanOptions | SourcifyOptions | BlockscoutOptions;
27
- deploymentNames?: string[];
28
- minInterval?: number;
29
- logErrorOnFailure?: boolean;
30
- };
31
-
32
- export async function run(config: ResolvedConfig, options: VerificationOptions) {
33
- const {deployments, chainId} = loadDeployments(config.deployments, config.network.name, false);
34
-
35
- if (Object.keys(deployments).length === 0) {
36
- console.log(`the network ${config.network.name} has zero deployments`);
37
- process.exit();
38
- }
39
-
40
- if (!chainId) {
41
- console.error(`the network ${config.network.name} has no chainId recorded`);
42
- process.exit(1);
43
- }
44
-
45
- if (options.verifier.type === 'etherscan') {
46
- await submitSourcesToEtherscan(
47
- {
48
- chainId,
49
- deployments,
50
- networkName: config.network.name,
51
- deploymentNames: options.deploymentNames,
52
- minInterval: options.minInterval,
53
- logErrorOnFailure: options.logErrorOnFailure,
54
- },
55
- options.verifier
56
- );
57
- } else if (options.verifier.type === 'sourcify') {
58
- await submitSourcesToSourcify(
59
- {
60
- chainId,
61
- deployments,
62
- networkName: config.network.name,
63
- deploymentNames: options.deploymentNames,
64
- minInterval: options.minInterval,
65
- logErrorOnFailure: options.logErrorOnFailure,
66
- },
67
- options.verifier
68
- );
69
- } else if (options.verifier.type === 'blockscout') {
70
- await submitSourcesToBlockscout(
71
- {
72
- chainId,
73
- deployments,
74
- networkName: config.network.name,
75
- deploymentNames: options.deploymentNames,
76
- minInterval: options.minInterval,
77
- logErrorOnFailure: options.logErrorOnFailure,
78
- },
79
- options.verifier
80
- );
81
- }
82
- }
package/src/metadata.ts DELETED
@@ -1,30 +0,0 @@
1
- import {ResolvedConfig, loadDeployments} from 'rocketh';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
-
5
- export function exportMetadata(config: ResolvedConfig, {out}: {out: string}) {
6
- const {deployments, chainId} = loadDeployments(config.deployments, config.network.name, false);
7
-
8
- if (Object.keys(deployments).length === 0) {
9
- console.log(`the network ${config.network.name} has zero deployments`);
10
- process.exit();
11
- }
12
-
13
- if (!chainId) {
14
- console.error(`the network ${config.network.name} has no chainId recorded`);
15
- process.exit(1);
16
- }
17
-
18
- const folder = path.join(out, config.network.name);
19
- fs.emptyDirSync(folder);
20
- const deploymentNames = Object.keys(deployments);
21
- for (const deploymentName of deploymentNames) {
22
- const deployment = deployments[deploymentName];
23
- if (deployment.metadata) {
24
- fs.writeFileSync(
25
- path.join(folder, `${deploymentName}_at_${deployment.address}.metadata.json`),
26
- deployment.metadata
27
- );
28
- }
29
- }
30
- }
package/src/sourcify.ts DELETED
@@ -1,109 +0,0 @@
1
- import chalk from 'chalk';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import {UnknownDeployments} from 'rocketh';
5
- import {SourcifyOptions} from './index.js';
6
-
7
- function sleep(ms: number) {
8
- return new Promise((resolve) => setTimeout(resolve, ms));
9
- }
10
-
11
- function log(...args: any[]) {
12
- console.log(...args);
13
- }
14
-
15
- function logError(...args: any[]) {
16
- console.log(chalk.red(...args));
17
- }
18
-
19
- function logInfo(...args: any[]) {
20
- console.log(chalk.yellow(...args));
21
- }
22
-
23
- function logSuccess(...args: any[]) {
24
- console.log(chalk.green(...args));
25
- }
26
-
27
- function ensureTrailingSlash(s: string): string {
28
- const lastChar = s.substr(-1);
29
- if (lastChar != '/') {
30
- s = s + '/';
31
- }
32
- return s;
33
- }
34
-
35
- // const defaultEndpoint = 'https://server.verificationstaging.shardlabs.io/';
36
- const defaultEndpoint = 'https://sourcify.dev/server/';
37
-
38
- export async function submitSourcesToSourcify(
39
- env: {
40
- deployments: UnknownDeployments;
41
- networkName: string;
42
- chainId: string;
43
- deploymentNames?: string[];
44
- minInterval?: number;
45
- logErrorOnFailure?: boolean;
46
- },
47
- config?: SourcifyOptions
48
- ): Promise<void> {
49
- config = config || {type: 'sourcify'};
50
- const all = env.deployments;
51
- const url = config.endpoint ? ensureTrailingSlash(config.endpoint) : defaultEndpoint;
52
-
53
- async function submit(name: string) {
54
- const deployment = all[name];
55
- const {address, metadata: metadataString} = deployment;
56
-
57
- try {
58
- const checkResponse = await fetch(
59
- `${url}checkByAddresses?addresses=${address.toLowerCase()}&chainIds=${env.chainId}`
60
- );
61
- const json = await checkResponse.json();
62
- if (json[0].status === 'perfect') {
63
- log(`already verified: ${name} (${address}), skipping.`);
64
- return;
65
- }
66
- } catch (e) {
67
- logError(((e as any).response && JSON.stringify((e as any).response.data)) || e);
68
- }
69
-
70
- if (!metadataString) {
71
- logError(`Contract ${name} was deployed without saving metadata. Cannot submit to sourcify, skipping.`);
72
- return;
73
- }
74
-
75
- logInfo(`verifying ${name} (${address} on chain ${env.chainId}) ...`);
76
-
77
- const formData = new FormData();
78
- formData.append('address', address);
79
- formData.append('chain', env.chainId);
80
- const metadataBlob = new Blob([metadataString], {
81
- type: 'application/json',
82
- });
83
- formData.append('files', metadataBlob, 'metadata.json');
84
-
85
- try {
86
- const submissionResponse = await fetch(url, {body: formData, method: 'POST'});
87
- const json = await submissionResponse.json();
88
- if (json.result[0].status === 'perfect') {
89
- logSuccess(` => contract ${name} is now verified`);
90
- } else {
91
- logError(` => contract ${name} is not verified`);
92
- }
93
- } catch (e) {
94
- if (env?.logErrorOnFailure) {
95
- const failingMetadataFolder = path.join('failing_metadata', env.chainId);
96
- fs.ensureDirSync(failingMetadataFolder);
97
- fs.writeFileSync(path.join(failingMetadataFolder, `${name}_at_${address}.json`), metadataString);
98
- }
99
- logError(((e as any).response && JSON.stringify((e as any).response.data)) || e);
100
- }
101
- }
102
-
103
- for (const name of env.deploymentNames ? env.deploymentNames : Object.keys(all)) {
104
- await submit(name);
105
- if (env.minInterval) {
106
- await sleep(env.minInterval);
107
- }
108
- }
109
- }
@@ -1,72 +0,0 @@
1
- // taken from package match-all
2
- export function matchAll(s: string, r: RegExp) {
3
- return {
4
- input: s,
5
- regex: r,
6
-
7
- /**
8
- * next
9
- * Get the next match in single group match.
10
- *
11
- * @name next
12
- * @function
13
- * @return {String|null} The matched snippet.
14
- */
15
- next() {
16
- let c = this.nextRaw();
17
- if (c) {
18
- for (let i = 1; i < c.length; i++) {
19
- if (c[i]) {
20
- return c[i];
21
- }
22
- }
23
- }
24
- return null;
25
- },
26
-
27
- /**
28
- * nextRaw
29
- * Get the next match in raw regex output. Usefull to get another group match.
30
- *
31
- * @name nextRaw
32
- * @function
33
- * @returns {Array|null} The matched snippet
34
- */
35
- nextRaw() {
36
- let c = this.regex.exec(this.input);
37
- return c;
38
- },
39
-
40
- /**
41
- * toArray
42
- * Get all the matches.
43
- *
44
- * @name toArray
45
- * @function
46
- * @return {Array} The matched snippets.
47
- */
48
- toArray() {
49
- let res = [],
50
- c = null;
51
-
52
- while ((c = this.next())) {
53
- res.push(c);
54
- }
55
-
56
- return res;
57
- },
58
-
59
- /**
60
- * reset
61
- * Reset the index.
62
- *
63
- * @name reset
64
- * @function
65
- * @param {Number} i The new index (default: `0`).
66
- * @return {Number} The new index.
67
- */
68
- reset(i: number = 0) {
69
- return (this.regex.lastIndex = i);
70
- },
71
- };
72
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "strictNullChecks": true,
5
- "target": "ESNext",
6
- "module": "NodeNext",
7
- "lib": ["ESNext", "dom"],
8
- "moduleResolution": "NodeNext",
9
- "resolveJsonModule": true,
10
- "skipLibCheck": true,
11
- "sourceMap": true,
12
- "declaration": true,
13
- "declarationMap": true,
14
- "rootDir": "./src",
15
- "outDir": "./dist/esm"
16
- },
17
- "include": ["src/**/*.ts"]
18
- }