Skip to content

Commit 92df743

Browse files
committed
test
1 parent 968a532 commit 92df743

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
6464
expect(results.length).toBe(7);
6565
});
6666

67+
it("should count transactions for a dynamic contract", async () => {
68+
const deployMetadata = await fetchPublishedContractMetadata({
69+
client: TEST_CLIENT,
70+
contractId: "EvolvingNFT",
71+
});
72+
const results = await getRequiredTransactions({
73+
client: TEST_CLIENT,
74+
chain: CLEAN_ANVIL_CHAIN,
75+
deployMetadata,
76+
});
77+
78+
expect(results.length).toBe(8);
79+
});
80+
6781
it("should return default constructor params for zksync chains", async () => {
6882
const params = await getAllDefaultConstructorParamsForImplementation({
6983
chain: defineChain(300),

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ async function getTransactionsForImplementation(options: {
143143
return getTransactionsForMaketplaceV3(options);
144144
}
145145

146+
if (deployMetadata.routerType === "dynamic") {
147+
return getTransactionsForDynamicContract(options);
148+
}
149+
146150
const constructorParams =
147151
implementationConstructorParams ??
148152
(await getAllDefaultConstructorParamsForImplementation({
@@ -223,6 +227,55 @@ async function getTransactionsForMaketplaceV3(options: {
223227
return transactions;
224228
}
225229

230+
async function getTransactionsForDynamicContract(options: {
231+
chain: Chain;
232+
client: ThirdwebClient;
233+
deployMetadata: FetchDeployMetadataResult;
234+
}): Promise<DeployTransactionResult[]> {
235+
const { chain, client } = options;
236+
const WETHAdress = await computePublishedContractAddress({
237+
chain,
238+
client,
239+
contractId: "WETH9",
240+
});
241+
const wethTx = await getDeployedInfraContract({
242+
chain,
243+
client,
244+
contractId: "WETH9",
245+
}).then((c) =>
246+
c ? null : ({ type: "infra", contractId: "WETH9" } as const),
247+
);
248+
console.log(options.deployMetadata.defaultExtensions);
249+
const extensions: (DeployTransactionResult | null)[] = options.deployMetadata
250+
.defaultExtensions
251+
? await Promise.all(
252+
options.deployMetadata.defaultExtensions.map((e) => {
253+
return getDeployedInfraContract({
254+
chain,
255+
client,
256+
contractId: e.extensionName,
257+
publisher: e.publisherAddress,
258+
version: e.extensionVersion || "latest",
259+
constructorParams: { _nativeTokenWrapper: WETHAdress },
260+
}).then((c) =>
261+
c
262+
? null
263+
: ({ type: "extension", contractId: e.extensionName } as const),
264+
);
265+
}),
266+
)
267+
: [];
268+
// hacky assumption: if we need to deploy any of the extensions, we also need to deploy the implementation
269+
const transactions = [...extensions, wethTx].filter((e) => e !== null);
270+
if (transactions.length) {
271+
transactions.push({
272+
type: "implementation",
273+
contractId: options.deployMetadata.name,
274+
});
275+
}
276+
return transactions;
277+
}
278+
226279
/**
227280
* Gets the default constructor parameters required for contract implementation deployment
228281
* @param args - The arguments object

0 commit comments

Comments
 (0)