Skip to content

Commit b2d6ba4

Browse files
committed
fetch published contract using zksolc compiler metadata
1 parent b4229a6 commit b2d6ba4

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

apps/dashboard/src/components/contract-components/fetchPublishedContractsFromDeploy.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { THIRDWEB_DEPLOYER_ADDRESS } from "constants/addresses";
12
import type { ThirdwebClient, ThirdwebContract } from "thirdweb";
3+
import { fetchPublishedContract } from "thirdweb/contract";
24
import {
35
getContractPublisher,
46
getPublishedUriFromCompilerUri,
57
} 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";
714
import { fetchDeployMetadata } from "./fetchDeployMetadata";
815

916
export async function fetchPublishedContractsFromDeploy(options: {
@@ -17,11 +24,36 @@ export async function fetchPublishedContractsFromDeploy(options: {
1724
throw new Error("No IPFS URI found in bytecode");
1825
}
1926

20-
const publishURIs = await getPublishedUriFromCompilerUri({
27+
let publishURIs = await getPublishedUriFromCompilerUri({
2128
contract: getContractPublisher(client),
2229
compilerMetadataUri: contractUri,
2330
});
2431

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+
2557
return await Promise.all(
2658
publishURIs.map((uri) => fetchDeployMetadata(uri, client)),
2759
);

packages/thirdweb/src/contract/deployment/utils/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export async function getOrDeployInfraContract(
236236
});
237237
}
238238

239-
export async function getOrDeployInfraContractFromMetadata(
239+
async function getOrDeployInfraContractFromMetadata(
240240
options: ClientAndChainAndAccount & {
241241
contractMetadata: FetchDeployMetadataResult;
242242
constructorParams?: Record<string, unknown>;

0 commit comments

Comments
 (0)