@@ -52,6 +52,7 @@ export interface EtherscanResult {
52
52
Proxy : string ;
53
53
Implementation : string ;
54
54
SwarmSource : string ;
55
+ ContractFileName ?: string ;
55
56
}
56
57
57
58
export interface ProcessedEtherscanResult {
@@ -89,7 +90,7 @@ export const isVyperResult = (etherscanResult: EtherscanResult): boolean => {
89
90
return etherscanResult . CompilerVersion . startsWith ( "vyper" ) ;
90
91
} ;
91
92
92
- export const getContractPathFromSources = ( contractName : string , sources : any ) : string | undefined => {
93
+ export const getContractPathFromSoliditySources = ( contractName : string , sources : any ) : string | undefined => {
93
94
// Look for a file that contains the contract definition
94
95
for ( const [ filePath , source ] of Object . entries ( sources ) ) {
95
96
const content = typeof source === "string" ? source : ( source as any ) . content ;
@@ -180,12 +181,16 @@ export const processEtherscanResult = async (
180
181
verificationMethod = "std-json" ;
181
182
const jsonInput = parseEtherscanJsonInput ( sourceCodeObject ) ;
182
183
183
- // Find contract path from sources
184
- const foundPath = getContractPathFromSources ( contractName , jsonInput . sources ) ;
185
- if ( ! foundPath ) {
186
- throw new Error ( "Could not find contract path in sources" ) ;
184
+ // Use ContractFileName if available, otherwise search in sources
185
+ if ( etherscanResult . ContractFileName ) {
186
+ contractPath = etherscanResult . ContractFileName ;
187
+ } else {
188
+ const foundPath = getContractPathFromSoliditySources ( contractName , jsonInput . sources ) ;
189
+ if ( ! foundPath ) {
190
+ throw new Error ( "Could not find contract path in sources" ) ;
191
+ }
192
+ contractPath = foundPath ;
187
193
}
188
- contractPath = foundPath ;
189
194
190
195
// Create a single JSON file
191
196
const jsonContent = JSON . stringify ( jsonInput , null , 2 ) ;
@@ -199,12 +204,16 @@ export const processEtherscanResult = async (
199
204
verificationMethod = "multiple-files" ;
200
205
const sourcesObject = JSON . parse ( sourceCodeObject ) as { [ key : string ] : { content : string } } ;
201
206
202
- // Find contract path from sources
203
- const foundPath = getContractPathFromSources ( contractName , sourcesObject ) ;
204
- if ( ! foundPath ) {
205
- throw new Error ( "Could not find contract path in sources" ) ;
207
+ // Use ContractFileName if available, otherwise search in sources
208
+ if ( etherscanResult . ContractFileName ) {
209
+ contractPath = etherscanResult . ContractFileName ;
210
+ } else {
211
+ const foundPath = getContractPathFromSoliditySources ( contractName , sourcesObject ) ;
212
+ if ( ! foundPath ) {
213
+ throw new Error ( "Could not find contract path in sources" ) ;
214
+ }
215
+ contractPath = foundPath ;
206
216
}
207
- contractPath = foundPath ;
208
217
209
218
// Create files from sources object
210
219
files = Object . entries ( sourcesObject ) . map ( ( [ filename , object ] ) => {
@@ -217,10 +226,15 @@ export const processEtherscanResult = async (
217
226
// single-file method
218
227
verificationMethod = "single-file" ;
219
228
const extension = language === "vyper" ? "vy" : "sol" ;
220
- const filename = `${ contractName } .${ extension } ` ;
221
- contractPath = filename ;
229
+
230
+ // Use ContractFileName if available, otherwise construct filename
231
+ if ( etherscanResult . ContractFileName ) {
232
+ contractPath = etherscanResult . ContractFileName ;
233
+ } else {
234
+ contractPath = `${ contractName } .${ extension } ` ;
235
+ }
222
236
223
- const sourceFile = new File ( [ sourceCodeObject ] , filename , { type : "text/plain" } ) ;
237
+ const sourceFile = new File ( [ sourceCodeObject ] , contractPath , { type : "text/plain" } ) ;
224
238
files = [ sourceFile ] ;
225
239
226
240
// Generate compiler settings for single-file method
0 commit comments