1
1
#!/usr/bin/env node
2
2
import {
3
+ ChainFolder ,
4
+ parseObjFromFile ,
3
5
parseVerifyArgsFromCLI ,
4
6
readFromDeploymentFile ,
5
7
readMetadata ,
6
8
} from "../utils/io" ;
7
9
import { $ , cd } from "zx" ;
8
10
import { MODULE_ROOT_PATH } from "../utils/constants" ;
9
- /**
10
- * Take a deployment name, and verify the result to blockscout api
11
- */
12
- async function main ( ) {
13
- const { deploymentName, verifierUrl, chainFolder, etherscanApiKey } =
14
- await parseVerifyArgsFromCLI ( ) ;
11
+ import { Logger } from "winston" ;
12
+ import { getMainLogger } from "../utils/cli" ;
13
+ import { ContractItemSchema } from "../evm/schemas/contract" ;
14
+ import { loadContractUpdateRegistry } from "../evm/schemas/contractUpdate" ;
15
15
16
+ const verifyContract = async (
17
+ deploymentName : string ,
18
+ chainFolder : ChainFolder ,
19
+ etherscanApiKey : string ,
20
+ verifierUrl : string ,
21
+ logger : Logger
22
+ ) => {
16
23
// Read deployment file, so that we can find path to artifact
17
24
const deployment = await readFromDeploymentFile ( deploymentName , chainFolder ) ;
18
25
const metadata = await readMetadata ( deployment . factory ) ;
@@ -27,7 +34,6 @@ async function main() {
27
34
`${ etherscanApiKey } ` ,
28
35
`--verifier-url=${ verifierUrl } ` ,
29
36
] ;
30
-
31
37
// Find libraries into string that foundry verification expects if there are any
32
38
let libraries : Record < string , string > | null = null ;
33
39
if ( deployment . libraries && deployment . libraries . length > 0 ) {
@@ -37,7 +43,7 @@ async function main() {
37
43
} ) ;
38
44
}
39
45
40
- console . log (
46
+ logger . info (
41
47
`verifying ${ deploymentName } 's deployment with ${ deployment . factory } ${
42
48
libraries ? `and libraries ${ libraries } ` : ``
43
49
} `
@@ -49,10 +55,44 @@ async function main() {
49
55
try {
50
56
command = await $ `forge verify-contract ${ args } 2>&1 | tee verify-out.txt` ; // command = await $`cd ${MODULE_ROOT_PATH} && forge verify-contract ${
51
57
} catch ( e ) {
52
- console . log ( "error " , e ) ;
58
+ logger . error ( "error " , e ) ;
53
59
}
54
60
55
- console . log ( "verification result " , command ) ;
61
+ logger . info ( "verification result " , command ) ;
62
+ } ;
63
+ /**
64
+ * Take a deployment name, and verify the result to blockscout api
65
+ */
66
+ async function main ( ) {
67
+ const { verifierUrl, chainFolder, etherscanApiKey, updateSpecs } =
68
+ await parseVerifyArgsFromCLI ( ) ;
69
+
70
+ // Fetch spec from contract
71
+
72
+ const contractUpdates = loadContractUpdateRegistry (
73
+ parseObjFromFile ( updateSpecs )
74
+ ) ;
75
+
76
+ const logger = getMainLogger ( ) ;
77
+ for ( const contractUpdate of contractUpdates . values ( ) ) {
78
+ const parsed = ContractItemSchema . safeParse ( contractUpdate ) ;
79
+ if ( parsed . success ) {
80
+ // Only try to verify contractName if it matches the deploymentName
81
+ try {
82
+ await verifyContract (
83
+ parsed . data . name ,
84
+ chainFolder ,
85
+ etherscanApiKey ,
86
+ verifierUrl ,
87
+ logger
88
+ ) ;
89
+ } catch ( e ) {
90
+ logger . error (
91
+ `Failed to verify contract ${ parsed . data . name } with error: ${ e } `
92
+ ) ;
93
+ }
94
+ }
95
+ }
56
96
}
57
97
58
98
main ( ) ;
0 commit comments