1
- import type { DeploymentState } from "./internal/execution/types/deployment-state.js" ;
2
1
import type { DeploymentExecutionState } from "./internal/execution/types/execution-state.js" ;
3
- import type { Artifact , BuildInfo , CompilerInput } from "./types/artifact.js" ;
4
- import type {
5
- ChainConfig ,
6
- SourceToLibraryToAddress ,
7
- VerifyInfo ,
8
- VerifyResult ,
9
- } from "./types/verify.js" ;
10
-
11
- import path from "node:path" ;
2
+ import type { Artifact } from "./types/artifact.js" ;
3
+ import type { VerifyInfo , VerifyResult } from "./types/verify.js" ;
12
4
13
5
import { HardhatError } from "@nomicfoundation/hardhat-errors" ;
14
6
import { FileNotFoundError } from "@nomicfoundation/hardhat-utils/fs" ;
15
- import { analyze } from "@nomicfoundation/solidity-analyzer" ;
16
7
17
- import { builtinChains } from "./internal/chain-config.js" ;
18
8
import { FileDeploymentLoader } from "./internal/deployment-loader/file-deployment-loader.js" ;
19
- import { encodeDeploymentArguments } from "./internal/execution/abi.js" ;
20
9
import { loadDeploymentState } from "./internal/execution/deployment-state-helpers.js" ;
21
10
import { ExecutionResultType } from "./internal/execution/types/execution-result.js" ;
22
11
import {
@@ -30,14 +19,11 @@ import { findExecutionStatesByType } from "./internal/views/find-execution-state
30
19
* Retrieve the information required to verify all contracts from a deployment on Etherscan.
31
20
*
32
21
* @param deploymentDir - the file directory of the deployment
33
- * @param customChains - an array of custom chain configurations
34
22
*
35
23
* @beta
36
24
*/
37
25
export async function * getVerificationInformation (
38
26
deploymentDir : string ,
39
- customChains : ChainConfig [ ] = [ ] ,
40
- includeUnrelatedContracts = false ,
41
27
) : AsyncGenerator < VerifyResult > {
42
28
const deploymentLoader = new FileDeploymentLoader ( deploymentDir ) ;
43
29
@@ -52,8 +38,6 @@ export async function* getVerificationInformation(
52
38
) ;
53
39
}
54
40
55
- const chainConfig = resolveChainConfig ( deploymentState , customChains ) ;
56
-
57
41
const deploymentExStates = findExecutionStatesByType (
58
42
ExecutionSateType . DEPLOYMENT_EXECUTION_STATE ,
59
43
deploymentState ,
@@ -72,85 +56,25 @@ export async function* getVerificationInformation(
72
56
const verifyInfo = await convertExStateToVerifyInfo (
73
57
exState ,
74
58
deploymentLoader ,
75
- includeUnrelatedContracts ,
76
59
) ;
77
60
78
61
if ( typeof verifyInfo === "string" ) {
79
- yield [ null , verifyInfo ] ;
62
+ yield verifyInfo ;
80
63
continue ;
81
64
}
82
65
83
- const verifyResult : VerifyResult = [ chainConfig , verifyInfo ] ;
84
-
85
- yield verifyResult ;
86
- }
87
- }
88
-
89
- function resolveChainConfig (
90
- deploymentState : DeploymentState ,
91
- customChains : ChainConfig [ ] ,
92
- ) {
93
- // implementation note:
94
- // if a user has set a custom chain with the same chainId as a builtin chain,
95
- // the custom chain will be used instead of the builtin chain
96
- const chainConfig = [ ...customChains , ...builtinChains ] . find (
97
- ( c ) => c . chainId === deploymentState . chainId ,
98
- ) ;
99
-
100
- if ( chainConfig === undefined ) {
101
- throw new HardhatError (
102
- HardhatError . ERRORS . IGNITION . VERIFY . UNSUPPORTED_CHAIN ,
103
- {
104
- chainId : deploymentState . chainId ,
105
- } ,
106
- ) ;
107
- }
108
-
109
- return chainConfig ;
110
- }
111
-
112
- export function getImportSourceNames (
113
- sourceName : string ,
114
- buildInfo : BuildInfo ,
115
- visited : Record < string , boolean > = { } ,
116
- ) : string [ ] {
117
- if ( visited [ sourceName ] ) {
118
- return [ ] ;
66
+ yield verifyInfo ;
119
67
}
120
-
121
- visited [ sourceName ] = true ;
122
-
123
- const contractSource = buildInfo . input . sources [ sourceName ] . content ;
124
- const { imports } = analyze ( contractSource ) ;
125
-
126
- const importSources = imports . map ( ( i ) => {
127
- if ( / ^ \. \. ? [ \/ | \\ ] / . test ( i ) ) {
128
- return path . join ( path . dirname ( sourceName ) , i ) . replaceAll ( "\\" , "/" ) ;
129
- }
130
-
131
- return i ;
132
- } ) ;
133
-
134
- return [
135
- ...importSources ,
136
- ...importSources . flatMap ( ( i ) =>
137
- getImportSourceNames ( i , buildInfo , visited ) ,
138
- ) ,
139
- ] ;
140
68
}
141
69
142
70
async function convertExStateToVerifyInfo (
143
71
exState : DeploymentExecutionState ,
144
72
deploymentLoader : FileDeploymentLoader ,
145
- includeUnrelatedContracts : boolean = false ,
146
73
) : Promise < VerifyInfo | string > {
147
- let result : [ BuildInfo , Artifact ] ;
74
+ let artifact : Artifact ;
148
75
149
76
try {
150
- result = await Promise . all ( [
151
- deploymentLoader . readBuildInfo ( exState . artifactId ) ,
152
- deploymentLoader . loadArtifact ( exState . artifactId ) ,
153
- ] ) ;
77
+ artifact = await deploymentLoader . loadArtifact ( exState . artifactId ) ;
154
78
} catch ( e ) {
155
79
assertIgnitionInvariant (
156
80
e instanceof FileNotFoundError ,
@@ -164,8 +88,6 @@ async function convertExStateToVerifyInfo(
164
88
return exState . artifactId ;
165
89
}
166
90
167
- const [ buildInfo , artifact ] = result ;
168
-
169
91
const { contractName, constructorArgs, libraries } = exState ;
170
92
171
93
assertIgnitionInvariant (
@@ -174,78 +96,12 @@ async function convertExStateToVerifyInfo(
174
96
`Deployment execution state ${ exState . id } should have a successful result to retrieve address` ,
175
97
) ;
176
98
177
- const sourceCode = prepareInputBasedOn ( buildInfo , artifact , libraries ) ;
178
-
179
- if ( ! includeUnrelatedContracts ) {
180
- const sourceNames = [
181
- artifact . sourceName ,
182
- ...getImportSourceNames ( artifact . sourceName , buildInfo ) ,
183
- ] ;
184
-
185
- for ( const source of Object . keys ( sourceCode . sources ) ) {
186
- if ( ! sourceNames . includes ( source ) ) {
187
- delete sourceCode . sources [ source ] ;
188
- }
189
- }
190
- }
191
-
192
- const verifyInfo = {
99
+ const verifyInfo : VerifyInfo = {
100
+ constructorArgs,
101
+ libraries,
193
102
address : exState . result . address ,
194
- compilerVersion : buildInfo . solcLongVersion . startsWith ( "v" )
195
- ? buildInfo . solcLongVersion
196
- : `v${ buildInfo . solcLongVersion } ` ,
197
- sourceCode : JSON . stringify ( sourceCode ) ,
198
- name : `${ artifact . sourceName } :${ contractName } ` ,
199
- args : encodeDeploymentArguments ( artifact , constructorArgs ) ,
103
+ contract : `${ artifact . sourceName } :${ contractName } ` ,
200
104
} ;
201
105
202
106
return verifyInfo ;
203
107
}
204
-
205
- function prepareInputBasedOn (
206
- buildInfo : BuildInfo ,
207
- artifact : Artifact ,
208
- libraries : Record < string , string > ,
209
- ) : CompilerInput {
210
- const sourceToLibraryAddresses = resolveLibraryInfoForArtifact (
211
- artifact ,
212
- libraries ,
213
- ) ;
214
-
215
- if ( sourceToLibraryAddresses === null ) {
216
- return buildInfo . input ;
217
- }
218
-
219
- const { input } = buildInfo ;
220
- input . settings . libraries = sourceToLibraryAddresses ;
221
-
222
- return input ;
223
- }
224
-
225
- function resolveLibraryInfoForArtifact (
226
- artifact : Artifact ,
227
- libraries : Record < string , string > ,
228
- ) : SourceToLibraryToAddress | null {
229
- const sourceToLibraryToAddress : SourceToLibraryToAddress = { } ;
230
-
231
- for ( const [ sourceName , refObj ] of Object . entries ( artifact . linkReferences ) ) {
232
- for ( const [ libName ] of Object . entries ( refObj ) ) {
233
- sourceToLibraryToAddress [ sourceName ] ??= { } ;
234
-
235
- const libraryAddress = libraries [ libName ] ;
236
-
237
- assertIgnitionInvariant (
238
- libraryAddress !== undefined ,
239
- `Could not find address for library ${ libName } ` ,
240
- ) ;
241
-
242
- sourceToLibraryToAddress [ sourceName ] [ libName ] = libraryAddress ;
243
- }
244
- }
245
-
246
- if ( Object . entries ( sourceToLibraryToAddress ) . length === 0 ) {
247
- return null ;
248
- }
249
-
250
- return sourceToLibraryToAddress ;
251
- }
0 commit comments