1
+ import { THIRDWEB_DEPLOYER_ADDRESS } from "constants/addresses" ;
1
2
import type { ThirdwebClient , ThirdwebContract } from "thirdweb" ;
3
+ import { fetchPublishedContract } from "thirdweb/contract" ;
2
4
import {
3
5
getContractPublisher ,
4
6
getPublishedUriFromCompilerUri ,
5
7
} from "thirdweb/extensions/thirdweb" ;
6
- import { extractIPFSUri , resolveImplementation } from "thirdweb/utils" ;
8
+ import { download } from "thirdweb/storage" ;
9
+ import {
10
+ extractIPFSUri ,
11
+ isZkSyncChain ,
12
+ resolveImplementation ,
13
+ } from "thirdweb/utils" ;
7
14
import { fetchDeployMetadata } from "./fetchDeployMetadata" ;
8
15
9
16
export async function fetchPublishedContractsFromDeploy ( options : {
@@ -17,11 +24,36 @@ export async function fetchPublishedContractsFromDeploy(options: {
17
24
throw new Error ( "No IPFS URI found in bytecode" ) ;
18
25
}
19
26
20
- const publishURIs = await getPublishedUriFromCompilerUri ( {
27
+ let publishURIs = await getPublishedUriFromCompilerUri ( {
21
28
contract : getContractPublisher ( client ) ,
22
29
compilerMetadataUri : contractUri ,
23
30
} ) ;
24
31
32
+ // Try fetching using contract name from compiler metadata for zksolc variants
33
+ // TODO: ContractPublisher should handle multiple metadata uri for a published version
34
+ if ( publishURIs . length === 0 && ( await isZkSyncChain ( contract . chain ) ) ) {
35
+ const deployMetadata = await download ( {
36
+ uri : contractUri ,
37
+ client,
38
+ } )
39
+ // biome-ignore lint/suspicious/noExplicitAny:
40
+ . then ( ( res ) => res . json ( ) as any )
41
+ . catch ( ) ;
42
+ const contractId = Object . values (
43
+ deployMetadata ?. source_metadata . settings ?. compilationTarget ,
44
+ ) ;
45
+
46
+ await fetchPublishedContract ( {
47
+ client,
48
+ contractId : contractId [ 0 ] as string ,
49
+ publisherAddress : THIRDWEB_DEPLOYER_ADDRESS ,
50
+ } )
51
+ . then ( ( published ) => {
52
+ publishURIs = [ published . publishMetadataUri ] ;
53
+ } )
54
+ . catch ( ) ;
55
+ }
56
+
25
57
return await Promise . all (
26
58
publishURIs . map ( ( uri ) => fetchDeployMetadata ( uri , client ) ) ,
27
59
) ;
0 commit comments