Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-books-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Auto resolve zksync bytecode
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
} from "thirdweb/deploys";
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
import { upload } from "thirdweb/storage";
import { isZkSyncChain } from "thirdweb/utils";
import { FormHelperText, FormLabel, Heading, Text } from "tw-components";
import { useCustomFactoryAbi, useFunctionParamsFromABI } from "../hooks";
import { addContractToMultiChainRegistry } from "../utils";
Expand Down Expand Up @@ -386,10 +385,6 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
throw new Error("no chain");
}

const compilerType = (await isZkSyncChain(walletChain))
? "zksolc"
: "solc";

let _contractURI = "";

if (hasContractURI && params.contractMetadata) {
Expand Down Expand Up @@ -454,7 +449,6 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
deployMetadata: m,
initializeParams: params.moduleData[m.name],
})),
compilerType,
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export function ContractPublishForm(props: {
customFactoryAddresses:
props.publishMetadata.factoryDeploymentData?.customFactoryInput
?.customFactoryAddresses || {},
params: props.publishMetadata.customFactoryInput?.params || [],
params:
props.publishMetadata.factoryDeploymentData?.customFactoryInput
?.params || [],
},
},
constructorParams: props.publishMetadata.constructorParams || {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const ContractDescriptionCell: React.FC<
}
>
<Text size="body.md" noOfLines={1}>
{deployMetadataResultQuery.data?.latestPublishedContractMetadata
?.publishedMetadata.description ||
{deployMetadataResultQuery.data?.description ||
(!deployMetadataResultQuery.isFetching ? "First Version" : "None")}
</Text>
</Skeleton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export const ContractIdImage: React.FC<ContractIdImageProps> = ({
}) => {
const deployMetadataResultQuery = useFetchDeployMetadata(contractId);

const logo =
deployMetadataResultQuery.data?.latestPublishedContractMetadata
?.publishedMetadata.logo;
const logo = deployMetadataResultQuery.data?.logo;

const img =
deployMetadataResultQuery.data?.image !== "custom"
Expand Down
5 changes: 2 additions & 3 deletions packages/thirdweb/src/contract/actions/compiler-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
export function formatCompilerMetadata(
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix later
metadata: any,
compilerType?: "solc" | "zksolc",
): CompilerMetadata {
let meta = metadata;
if (compilerType === "zksolc") {
meta = metadata.source_metadata || meta;
if ("source_metadata" in metadata) {
meta = metadata.source_metadata;

Check warning on line 36 in packages/thirdweb/src/contract/actions/compiler-metadata.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/contract/actions/compiler-metadata.ts#L36

Added line #L36 was not covered by tests
}
const compilationTarget = meta.settings.compilationTarget;
const targets = Object.keys(compilationTarget);
Expand Down
4 changes: 0 additions & 4 deletions packages/thirdweb/src/contract/deployment/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export async function fetchPublishedContractMetadata(options: {
contractId: string;
publisher?: string;
version?: string;
compilerType?: "solc" | "zksolc";
}): Promise<FetchDeployMetadataResult> {
const cacheKey = `${options.contractId}-${options.publisher}-${options.version}`;
return withCache(
Expand All @@ -34,7 +33,6 @@ export async function fetchPublishedContractMetadata(options: {
publisherAddress: options.publisher || THIRDWEB_DEPLOYER,
contractId: options.contractId,
version: options.version,
compilerType: options.compilerType,
});
if (!publishedContract.publishMetadataUri) {
throw new Error(
Expand All @@ -44,7 +42,6 @@ export async function fetchPublishedContractMetadata(options: {
const data = await fetchDeployMetadata({
client: options.client,
uri: publishedContract.publishMetadataUri,
compilerType: options.compilerType,
});
return data;
},
Expand Down Expand Up @@ -214,7 +211,6 @@ type FetchPublishedContractOptions = {
contractId: string;
version?: string;
client: ThirdwebClient;
compilerType?: "solc" | "zksolc";
};

/**
Expand Down
14 changes: 9 additions & 5 deletions packages/thirdweb/src/contract/deployment/utils/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
import type { FetchDeployMetadataResult } from "../../../utils/any-evm/deploy-metadata.js";
import {
type FetchDeployMetadataResult,
fetchBytecodeFromCompilerMetadata,
} from "../../../utils/any-evm/deploy-metadata.js";
import { isZkSyncChain } from "../../../utils/any-evm/zksync/isZkSyncChain.js";
import type { ClientAndChainAndAccount } from "../../../utils/types.js";
import { type ThirdwebContract, getContract } from "../../contract.js";
Expand Down Expand Up @@ -27,7 +30,6 @@
constructorParams?: Record<string, unknown>;
publisher?: string;
version?: string;
compilerType?: "solc" | "zksolc";
},
): Promise<{
cloneFactoryContract: ThirdwebContract;
Expand All @@ -41,7 +43,6 @@
constructorParams,
publisher,
version,
compilerType,
} = args;

if (await isZkSyncChain(chain)) {
Expand All @@ -55,14 +56,17 @@
contractId,
publisher,
version,
compilerType,
});
const implementationContract = await zkDeployContractDeterministic({
chain,
client,
account,
abi: compilerMetadata.abi,
bytecode: compilerMetadata.bytecode,
bytecode: await fetchBytecodeFromCompilerMetadata({
compilerMetadata,
client,
chain,
}),

Check warning on line 69 in packages/thirdweb/src/contract/deployment/utils/bootstrap.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/contract/deployment/utils/bootstrap.ts#L65-L69

Added lines #L65 - L69 were not covered by tests
params: constructorParams,
});
return {
Expand Down
24 changes: 14 additions & 10 deletions packages/thirdweb/src/extensions/prebuilts/deploy-published.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
import { normalizeFunctionParams } from "../../utils/abi/normalizeFunctionParams.js";
import { getAddress } from "../../utils/address.js";
import type { CompilerMetadata } from "../../utils/any-evm/deploy-metadata.js";
import {
type CompilerMetadata,
fetchBytecodeFromCompilerMetadata,
} from "../../utils/any-evm/deploy-metadata.js";
import type { FetchDeployMetadataResult } from "../../utils/any-evm/deploy-metadata.js";
import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js";
import type { Hex } from "../../utils/encoding/hex.js";
Expand All @@ -33,7 +36,6 @@
version?: string;
implementationConstructorParams?: Record<string, unknown>;
salt?: string;
compilerType?: "solc" | "zksolc";
};

/**
Expand Down Expand Up @@ -93,14 +95,12 @@
version,
implementationConstructorParams,
salt,
compilerType,
} = options;
const deployMetadata = await fetchPublishedContractMetadata({
client,
contractId,
publisher,
version,
compilerType,
});

return deployContractfromDeployMetadata({
Expand All @@ -111,7 +111,6 @@
initializeParams: contractParams,
implementationConstructorParams,
salt,
compilerType,
});
}

Expand All @@ -130,7 +129,6 @@
initializeParams?: Record<string, unknown>;
}[];
salt?: string;
compilerType?: "solc" | "zksolc";
};

/**
Expand All @@ -148,7 +146,6 @@
implementationConstructorParams,
modules,
salt,
compilerType,
} = options;
switch (deployMetadata?.deployType) {
case "standard": {
Expand Down Expand Up @@ -182,7 +179,6 @@
client,
})),
publisher: deployMetadata.publisher,
compilerType,
});

const initializeTransaction = await getInitializeTransaction({
Expand Down Expand Up @@ -272,7 +268,11 @@
account,
client,
chain,
bytecode: compilerMetadata.bytecode,
bytecode: await fetchBytecodeFromCompilerMetadata({
compilerMetadata,
client,
chain,
}),

Check warning on line 275 in packages/thirdweb/src/extensions/prebuilts/deploy-published.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/prebuilts/deploy-published.ts#L271-L275

Added lines #L271 - L275 were not covered by tests
abi: compilerMetadata.abi,
params: contractParams,
salt,
Expand All @@ -286,7 +286,11 @@
account,
client,
chain,
bytecode: compilerMetadata.bytecode,
bytecode: await fetchBytecodeFromCompilerMetadata({
compilerMetadata,
client,
chain,
}),
abi: compilerMetadata.abi,
constructorParams: contractParams,
salt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("publishContract", () => {
uri: logs?.[0]?.args.publishedContract.publishMetadataUri ?? "",
});
expect(publishedData.abi).toBeDefined();
expect(publishedData.bytecode).toBeDefined();
expect(publishedData.version).toBe("0.0.1");
expect(publishedData.changelog).toBe("Initial release");
expect(publishedData.name).toBe("CatAttackNFT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { encodeAbiParameters } from "../abi/encodeAbiParameters.js";
import { normalizeFunctionParams } from "../abi/normalizeFunctionParams.js";
import { ensureBytecodePrefix } from "../bytecode/prefix.js";
import type { Hex } from "../encoding/hex.js";
import type { FetchDeployMetadataResult } from "./deploy-metadata.js";
import {
type FetchDeployMetadataResult,
fetchBytecodeFromCompilerMetadata,
} from "./deploy-metadata.js";
import { getInitBytecodeWithSalt } from "./get-init-bytecode-with-salt.js";

/**
Expand Down Expand Up @@ -52,7 +55,11 @@ export async function computeDeploymentInfoFromMetadata(args: {
client: args.client,
chain: args.chain,
abi: args.contractMetadata.abi,
bytecode: args.contractMetadata.bytecode,
bytecode: await fetchBytecodeFromCompilerMetadata({
compilerMetadata: args.contractMetadata,
client: args.client,
chain: args.chain,
}),
constructorParams: args.constructorParams,
salt: args.salt,
});
Expand Down
Loading
Loading