diff --git a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx index 4d9304048c0..36c1a111eed 100644 --- a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx +++ b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx @@ -386,7 +386,9 @@ export const CustomContractForm: React.FC = ({ throw new Error("no chain"); } - const compilerType = isZkSyncChain(walletChain) ? "zksolc" : "solc"; + const compilerType = (await isZkSyncChain(walletChain)) + ? "zksolc" + : "solc"; let _contractURI = ""; diff --git a/packages/thirdweb/src/contract/deployment/deploy-via-autofactory.ts b/packages/thirdweb/src/contract/deployment/deploy-via-autofactory.ts index cd475d1cb1f..3c4410fe8a9 100644 --- a/packages/thirdweb/src/contract/deployment/deploy-via-autofactory.ts +++ b/packages/thirdweb/src/contract/deployment/deploy-via-autofactory.ts @@ -73,7 +73,7 @@ export async function deployViaAutoFactory( salt, } = options; - if (isZkSyncChain(chain)) { + if (await isZkSyncChain(chain)) { return zkDeployProxy({ chain, client, diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index 2642d8444f5..1da6c8c24b6 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -44,7 +44,7 @@ export async function getOrDeployInfraForPublishedContract( compilerType, } = args; - if (isZkSyncChain(chain)) { + if (await isZkSyncChain(chain)) { const cloneFactoryContract = await zkDeployCreate2Factory({ chain, client, diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts index c78a4f2cc2c..2be090bd2a0 100644 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts +++ b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts @@ -267,7 +267,7 @@ async function directDeploy(options: { const { account, client, chain, compilerMetadata, contractParams, salt } = options; - if (isZkSyncChain(chain)) { + if (await isZkSyncChain(chain)) { return zkDeployContract({ account, client, diff --git a/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts b/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts index c55b69a9203..241926c612d 100644 --- a/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts +++ b/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts @@ -43,6 +43,8 @@ export async function getRequiredTransactions( modules = [], } = options; + const isZkSync = await isZkSyncChain(chain); + if (deployMetadata?.deployType === "autoFactory") { const results: ( | DeployTransactionResult @@ -53,7 +55,7 @@ export async function getRequiredTransactions( chain, client, }).then((c) => - c || isZkSyncChain(chain) + c || isZkSync ? null : ({ type: "infra", contractId: "Create2Factory" } as const), ), @@ -62,7 +64,7 @@ export async function getRequiredTransactions( client, contractId: "Forwarder", }).then((c) => - c || isZkSyncChain(chain) + c || isZkSync ? null : ({ type: "infra", contractId: "Forwarder" } as const), ), @@ -78,7 +80,7 @@ export async function getRequiredTransactions( }), }, }).then((c) => - c || isZkSyncChain(chain) + c || isZkSync ? null : ({ type: "infra", contractId: "TWCloneFactory" } as const), ), diff --git a/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts b/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts index 72b00a252e6..54360eff765 100644 --- a/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts +++ b/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts @@ -1,12 +1,44 @@ import type { Chain } from "../../../chains/types.js"; +import { withCache } from "../../promise/withCache.js"; -export function isZkSyncChain(chain: Chain) { - return ( - chain.id === 324 || - chain.id === 300 || - chain.id === 302 || - chain.id === 11124 || - chain.id === 282 || // cronos zkevm testnet - chain.id === 388 // cronos zkevm mainnet +export async function isZkSyncChain(chain: Chain) { + if (chain.id === 1337 || chain.id === 31337) { + return false; + } + + const stack = await getChainStack(chain.id).catch(() => { + // fall back to checking against these zksync chain-ids + if ( + chain.id === 324 || + chain.id === 300 || + chain.id === 302 || + chain.id === 11124 || + chain.id === 282 || // cronos zkevm testnet + chain.id === 388 // cronos zkevm mainnet + ) { + return "zksync-stack"; + } + + return ""; + }); + + return stack === "zksync-stack"; +} + +async function getChainStack(chainId: number): Promise { + return withCache( + async () => { + const res = await fetch(`https://${chainId}.rpc.thirdweb.com/stack`); + + if (!res.ok) { + res.body?.cancel(); + throw new Error(`Error fetching stack for ${chainId}`); + } + + const data = await res.json(); + + return data.stack; + }, + { cacheKey: `stack:${chainId}`, cacheTime: 24 * 60 * 60 * 1000 }, ); } diff --git a/packages/thirdweb/src/wallets/smart/index.ts b/packages/thirdweb/src/wallets/smart/index.ts index 7ac16fea68c..27c95b84a06 100644 --- a/packages/thirdweb/src/wallets/smart/index.ts +++ b/packages/thirdweb/src/wallets/smart/index.ts @@ -104,7 +104,7 @@ export async function connectSmartWallet( const sponsorGas = "gasless" in options ? options.gasless : options.sponsorGas; - if (isZkSyncChain(chain)) { + if (await isZkSyncChain(chain)) { return [ createZkSyncAccount({ creationOptions,