Skip to content

Commit 3718020

Browse files
committed
Marketplace implementation addresses (#5822)
TOOL-2814 ## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces support for `ZkSync` chains by adding implementations for contracts and adjusting methods to handle `ZkSync` specific logic, including fetching default constructor parameters and deploying contracts. ### Detailed summary - Added `ZKSYNC_IMPLEMENTATIONS` and `ZKSYNC_WETH` records for various `ZkSync` chains. - Updated `CustomContractForm` to handle `MarketplaceV3` differently for `ZkSync` chains. - Introduced a test for retrieving default constructor parameters for `ZkSync`. - Modified `getAllDefaultConstructorParamsForImplementation` to return `nativeTokenWrapper` for `ZkSync`. - Updated contract deployment logic in `bootstrap.ts` to use `ZkSync` implementations. - Added a test case for saving implementations for `ZkSync` chains. - Enhanced contract fetching logic in `getOrDeployInfraContract` for `WETH9` on `ZkSync`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 243c497 commit 3718020

File tree

6 files changed

+127
-16
lines changed

6 files changed

+127
-16
lines changed

apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from "thirdweb/deploys";
3535
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
3636
import { upload } from "thirdweb/storage";
37+
import { isZkSyncChain } from "thirdweb/utils";
3738
import { FormHelperText, FormLabel, Heading, Text } from "tw-components";
3839
import { useCustomFactoryAbi, useFunctionParamsFromABI } from "../hooks";
3940
import { addContractToMultiChainRegistry } from "../utils";
@@ -426,7 +427,10 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
426427
}
427428
}
428429

429-
if (metadata.name === "MarketplaceV3") {
430+
if (
431+
metadata.name === "MarketplaceV3" &&
432+
!(await isZkSyncChain(walletChain))
433+
) {
430434
// special case for marketplace
431435
return await deployMarketplaceContract({
432436
account: activeAccount,

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { describe, expect, it } from "vitest";
33
import { ANVIL_CHAIN } from "../../../../test/src/chains.js";
44
import { TEST_CLIENT } from "../../../../test/src/test-clients.js";
55
import { TEST_ACCOUNT_A } from "../../../../test/src/test-wallets.js";
6-
import { deployCloneFactory } from "./bootstrap.js";
6+
import { defineChain } from "../../../chains/utils.js";
7+
import {
8+
deployCloneFactory,
9+
getOrDeployInfraContract,
10+
getOrDeployInfraForPublishedContract,
11+
} from "./bootstrap.js";
712
import { getDeployedCreate2Factory } from "./create-2-factory.js";
813
import { getDeployedInfraContract } from "./infra.js";
914

@@ -42,4 +47,42 @@ describe.runIf(process.env.TW_SECRET_KEY)("bootstrap", () => {
4247
});
4348
expect(cloneFactory).not.toBeNull();
4449
});
50+
51+
it("should return saved implementations for zksync chains", async () => {
52+
let infra = await getOrDeployInfraForPublishedContract({
53+
client: TEST_CLIENT,
54+
chain: defineChain(300),
55+
account: TEST_ACCOUNT_A,
56+
contractId: "MarketplaceV3",
57+
});
58+
59+
expect(infra.cloneFactoryContract.address).to.eq(
60+
"0xa51baf6a9c0ef5Db8C1898d5aDD92Bf3227d6088",
61+
);
62+
expect(infra.implementationContract.address).to.eq(
63+
"0x58e0F289C7dD2025eBd0696d913ECC0fdc1CC8bc",
64+
);
65+
66+
infra = await getOrDeployInfraForPublishedContract({
67+
client: TEST_CLIENT,
68+
chain: defineChain(300),
69+
account: TEST_ACCOUNT_A,
70+
contractId: "DropERC721",
71+
version: "5.0.4",
72+
});
73+
74+
expect(infra.cloneFactoryContract.address).to.eq(
75+
"0xa51baf6a9c0ef5Db8C1898d5aDD92Bf3227d6088",
76+
);
77+
expect(infra.implementationContract.address).toBeDefined();
78+
79+
const weth = await getOrDeployInfraContract({
80+
client: TEST_CLIENT,
81+
chain: defineChain(300),
82+
account: TEST_ACCOUNT_A,
83+
contractId: "WETH9",
84+
});
85+
86+
expect(weth.address).to.eq("0x0462C05457Fed440740Ff3696bDd2D0577411e34");
87+
});
4588
});

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { isZkSyncChain } from "../../../utils/any-evm/zksync/isZkSyncChain.js";
77
import type { ClientAndChainAndAccount } from "../../../utils/types.js";
88
import { type ThirdwebContract, getContract } from "../../contract.js";
99
import { fetchPublishedContractMetadata } from "../publisher.js";
10+
import {
11+
ZKSYNC_IMPLEMENTATIONS,
12+
ZKSYNC_WETH,
13+
} from "../zksync/implementations.js";
1014
import { zkDeployCreate2Factory } from "../zksync/zkDeployCreate2Factory.js";
1115
import { zkDeployContractDeterministic } from "../zksync/zkDeployDeterministic.js";
1216
import { getDeployedCloneFactoryContract } from "./clone-factory.js";
@@ -69,18 +73,29 @@ export async function getOrDeployInfraForPublishedContract(
6973
publisher,
7074
version,
7175
});
72-
const implementationContract = await zkDeployContractDeterministic({
73-
chain,
74-
client,
75-
account,
76-
abi: compilerMetadata.abi,
77-
bytecode: await fetchBytecodeFromCompilerMetadata({
78-
compilerMetadata,
79-
client,
76+
77+
const zksyncImplementations = ZKSYNC_IMPLEMENTATIONS[chain.id];
78+
let implementationContract: string | undefined;
79+
80+
if (zksyncImplementations) {
81+
implementationContract = zksyncImplementations[contractId];
82+
}
83+
84+
if (!implementationContract) {
85+
implementationContract = await zkDeployContractDeterministic({
8086
chain,
81-
}),
82-
params: constructorParams,
83-
});
87+
client,
88+
account,
89+
abi: compilerMetadata.abi,
90+
bytecode: await fetchBytecodeFromCompilerMetadata({
91+
compilerMetadata,
92+
client,
93+
chain,
94+
}),
95+
params: constructorParams,
96+
});
97+
}
98+
8499
return {
85100
cloneFactoryContract: getContract({
86101
address: cloneFactoryContract,
@@ -188,6 +203,18 @@ export async function getOrDeployInfraContract(
188203
version?: string;
189204
},
190205
) {
206+
if (options.contractId === "WETH9" && (await isZkSyncChain(options.chain))) {
207+
const weth = ZKSYNC_WETH[options.chain.id];
208+
209+
if (weth) {
210+
return getContract({
211+
client: options.client,
212+
chain: options.chain,
213+
address: weth,
214+
});
215+
}
216+
}
217+
191218
const contractMetadata = await fetchPublishedContractMetadata({
192219
client: options.client,
193220
contractId: options.contractId,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const ZKSYNC_IMPLEMENTATIONS: Record<number, Record<string, string>> = {
2+
[300]: {
3+
MarketplaceV3: "0x58e0F289C7dD2025eBd0696d913ECC0fdc1CC8bc",
4+
},
5+
[302]: {
6+
MarketplaceV3: "0x8b0DBCf5b7D01eBB0F24525CE8AB72F16CE4F8C8",
7+
},
8+
[324]: {
9+
MarketplaceV3: "0xBc02441a36Bb4029Cd191b20243c2e41B862F118",
10+
},
11+
[11124]: {
12+
MarketplaceV3: "0x2dA4Dd326A6482679547071be21f74685d730504",
13+
},
14+
};
15+
16+
export const ZKSYNC_WETH: Record<number, string> = {
17+
[300]: "0x0462C05457Fed440740Ff3696bDd2D0577411e34",
18+
[324]: "0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91",
19+
[11124]: "0x9EDCde0257F2386Ce177C3a7FCdd97787F0D841d",
20+
};

packages/thirdweb/src/extensions/prebuilts/get-required-transactions.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { describe, expect, it } from "vitest";
22
import { CLEAN_ANVIL_CHAIN } from "../../../test/src/chains.js";
33
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
4+
import { defineChain } from "../../chains/utils.js";
45
import { fetchPublishedContractMetadata } from "../../contract/deployment/publisher.js";
5-
import { getRequiredTransactions } from "./get-required-transactions.js";
6+
import {
7+
getAllDefaultConstructorParamsForImplementation,
8+
getRequiredTransactions,
9+
} from "./get-required-transactions.js";
610

711
describe.runIf(process.env.TW_SECRET_KEY)(
812
"getRequiredTransactions",
@@ -59,5 +63,14 @@ describe.runIf(process.env.TW_SECRET_KEY)(
5963
});
6064
expect(results.length).toBe(7);
6165
});
66+
67+
it("should return default constructor params for zksync chains", async () => {
68+
const params = await getAllDefaultConstructorParamsForImplementation({
69+
chain: defineChain(300),
70+
client: TEST_CLIENT,
71+
});
72+
73+
expect(params.nativeTokenWrapper).toBeDefined();
74+
});
6275
},
6376
);

packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../client/client.js";
33
import { getDeployedCreate2Factory } from "../../contract/deployment/utils/create-2-factory.js";
44
import { getDeployedInfraContract } from "../../contract/deployment/utils/infra.js";
55
import { getDeployedInfraContractFromMetadata } from "../../contract/deployment/utils/infra.js";
6+
import { ZKSYNC_WETH } from "../../contract/deployment/zksync/implementations.js";
67
import { computePublishedContractAddress } from "../../utils/any-evm/compute-published-contract-address.js";
78
import type { FetchDeployMetadataResult } from "../../utils/any-evm/deploy-metadata.js";
89
import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js";
@@ -227,8 +228,11 @@ export async function getAllDefaultConstructorParamsForImplementation(args: {
227228
const { chain, client } = args;
228229
const isZkSync = await isZkSyncChain(chain);
229230
if (isZkSync) {
230-
// zksync contracts dont need these implementation constructor params
231-
return {};
231+
const weth = ZKSYNC_WETH[chain.id];
232+
233+
return {
234+
nativeTokenWrapper: weth,
235+
};
232236
}
233237
const [forwarder, weth] = await Promise.all([
234238
computePublishedContractAddress({

0 commit comments

Comments
 (0)