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
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
throw new Error("no chain");
}

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

let _contractURI = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function deployViaAutoFactory(
salt,
} = options;

if (isZkSyncChain(chain)) {
if (await isZkSyncChain(chain)) {
return zkDeployProxy({
chain,
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function getOrDeployInfraForPublishedContract(
compilerType,
} = args;

if (isZkSyncChain(chain)) {
if (await isZkSyncChain(chain)) {
const cloneFactoryContract = await zkDeployCreate2Factory({
chain,
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export async function getRequiredTransactions(
modules = [],
} = options;

const isZkSync = await isZkSyncChain(chain);

if (deployMetadata?.deployType === "autoFactory") {
const results: (
| DeployTransactionResult
Expand All @@ -53,7 +55,7 @@ export async function getRequiredTransactions(
chain,
client,
}).then((c) =>
c || isZkSyncChain(chain)
c || isZkSync
? null
: ({ type: "infra", contractId: "Create2Factory" } as const),
),
Expand All @@ -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),
),
Expand All @@ -78,7 +80,7 @@ export async function getRequiredTransactions(
}),
},
}).then((c) =>
c || isZkSyncChain(chain)
c || isZkSync
? null
: ({ type: "infra", contractId: "TWCloneFactory" } as const),
),
Expand Down
48 changes: 40 additions & 8 deletions packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts
Original file line number Diff line number Diff line change
@@ -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";
}

Check warning on line 20 in packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts#L19-L20

Added lines #L19 - L20 were not covered by tests

return "";
});

return stack === "zksync-stack";
}

async function getChainStack(chainId: number): Promise<string> {
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 },
);
}
2 changes: 1 addition & 1 deletion packages/thirdweb/src/wallets/smart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading