Skip to content

Commit 880650d

Browse files
committed
Fix module deployment (#6869)
- Handle refs and metadata format (solc vs zksolc) for modules <!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on fixing module deployment issues in the `thirdweb` package, particularly with references and zk (zero-knowledge) support. It modifies contract deployment utilities and enhances the fetching of published contracts. ### Detailed summary - Updated the `getOrDeployInfraContractFromMetadata` function to simplify contract retrieval. - Changed the deployment logic to use `deployContractfromDeployMetadata`. - Enhanced `fetchPublishedContractsFromDeploy` to handle zkSync chains and fetch metadata appropriately. - Added new types and improved error handling for contract metadata fetching. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent fd91ee8 commit 880650d

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

.changeset/fruity-suits-relax.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix module deployment with refs and zk

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

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
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

16+
type ZkSolcMetadata = {
17+
source_metadata: { settings: { compilationTarget: Record<string, string> } };
18+
};
19+
920
export async function fetchPublishedContractsFromDeploy(options: {
1021
contract: ThirdwebContract;
1122
client: ThirdwebClient;
@@ -17,11 +28,37 @@ export async function fetchPublishedContractsFromDeploy(options: {
1728
throw new Error("No IPFS URI found in bytecode");
1829
}
1930

20-
const publishURIs = await getPublishedUriFromCompilerUri({
31+
let publishURIs = await getPublishedUriFromCompilerUri({
2132
contract: getContractPublisher(client),
2233
compilerMetadataUri: contractUri,
2334
});
2435

36+
// Try fetching using contract name from compiler metadata for zksolc variants
37+
// TODO: ContractPublisher should handle multiple metadata uri for a published version
38+
if (publishURIs.length === 0 && (await isZkSyncChain(contract.chain))) {
39+
try {
40+
const res = await download({
41+
uri: contractUri,
42+
client,
43+
});
44+
45+
const deployMetadata = (await res.json()) as ZkSolcMetadata;
46+
47+
const contractId = Object.values(
48+
deployMetadata.source_metadata.settings.compilationTarget,
49+
);
50+
51+
if (contractId[0]) {
52+
const published = await fetchPublishedContract({
53+
client,
54+
contractId: contractId[0],
55+
publisherAddress: THIRDWEB_DEPLOYER_ADDRESS,
56+
});
57+
publishURIs = [published.publishMetadataUri];
58+
}
59+
} catch {}
60+
}
61+
2562
return await Promise.all(
2663
publishURIs.map((uri) => fetchDeployMetadata(uri, client)),
2764
);

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

+1-1
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>;

packages/thirdweb/src/extensions/prebuilts/deploy-published.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Chain } from "../../chains/types.js";
33
import type { ThirdwebClient } from "../../client/client.js";
44
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
55
import { fetchPublishedContractMetadata } from "../../contract/deployment/publisher.js";
6-
import { getOrDeployInfraContractFromMetadata } from "../../contract/deployment/utils/bootstrap.js";
76
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
87
import { simulateTransaction } from "../../transaction/actions/simulate.js";
98
import { prepareContractCall } from "../../transaction/prepare-contract-call.js";
@@ -435,18 +434,21 @@ export async function getInitializeTransaction(options: {
435434
const moduleInstallData: Hex[] = [];
436435
for (const module of modules) {
437436
// deploy the module if not already deployed
438-
const contract = await getOrDeployInfraContractFromMetadata({
439-
client,
440-
chain,
437+
const contractAddress = await deployContractfromDeployMetadata({
441438
account,
442-
contractMetadata: module.deployMetadata,
439+
chain,
440+
client,
441+
deployMetadata: module.deployMetadata,
442+
implementationConstructorParams:
443+
module.deployMetadata.implConstructorParams,
444+
salt: "",
443445
});
444446

445447
const installFunction = module.deployMetadata.abi.find(
446448
(i) => i.type === "function" && i.name === "encodeBytesOnInstall",
447449
) as AbiFunction | undefined;
448450

449-
moduleAddresses.push(getAddress(contract.address));
451+
moduleAddresses.push(getAddress(contractAddress));
450452
moduleInstallData.push(
451453
installFunction
452454
? encodeAbiParameters(

0 commit comments

Comments
 (0)