Skip to content

Handle default extensions #6497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
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 @@ -473,9 +473,7 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
name: params.contractMetadata?.name || "",
contractURI: _contractURI,
defaultAdmin: params.deployParams._defaultAdmin as string,
platformFeeBps: hasInbuiltDefaultFeeConfig
? DEFAULT_FEE_BPS_NEW
: DEFAULT_FEE_BPS,
platformFeeBps: DEFAULT_FEE_BPS_NEW,
platformFeeRecipient: DEFAULT_FEE_RECIPIENT,
trustedForwarders: params.deployParams._trustedForwarders
? JSON.parse(params.deployParams._trustedForwarders as string)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readContract } from "src/transaction/read-contract.js";
import { resolveMethod } from "src/transaction/resolve-method.js";
import { describe, expect, it } from "vitest";
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
import { deployPublishedContract } from "../../extensions/prebuilts/deploy-published.js";
import { getContract } from "../contract.js";
import { deployCloneFactory } from "./utils/bootstrap.js";

describe.runIf(process.env.TW_SECRET_KEY)("deploy dynamic", () => {
it.sequential("should deploy dynamic contract with extensions", async () => {
await deployCloneFactory({
chain: ANVIL_CHAIN,
client: TEST_CLIENT,
account: TEST_ACCOUNT_A,
});

const deployed = await deployPublishedContract({
chain: ANVIL_CHAIN,
client: TEST_CLIENT,
account: TEST_ACCOUNT_A,
contractId: "EvolvingNFT",
contractParams: {
name: "Evolving nft",
symbol: "ENFT",
defaultAdmin: TEST_ACCOUNT_A.address,
royaltyBps: 0n,
royaltyRecipient: TEST_ACCOUNT_A.address,
saleRecipient: TEST_ACCOUNT_A.address,
trustedForwarders: [],
contractURI: "",
},
});

expect(deployed).toBeDefined();

const contract = getContract({
client: TEST_CLIENT,
address: deployed,
chain: ANVIL_CHAIN,
});

const extensions = await readContract({
contract,
method: resolveMethod("getAllExtensions"),
params: [],
});

expect(extensions.length).toEqual(3);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export async function getOrDeployInfraForPublishedContract(
version,
});
}
return { cloneFactoryContract, implementationContract };

return {
cloneFactoryContract,
implementationContract,
};
}

/**
Expand Down
159 changes: 78 additions & 81 deletions packages/thirdweb/src/extensions/prebuilts/deploy-marketplace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type {
Abi,
AbiFunction,
AbiParametersToPrimitiveTypes,
Address,
} from "abitype";
import { toFunctionSelector, toFunctionSignature } from "viem";
import type { AbiParametersToPrimitiveTypes, Address } from "abitype";
import type { ThirdwebClient } from "../../client/client.js";
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
import type { ThirdwebContract } from "../../contract/contract.js";
Expand All @@ -19,6 +13,19 @@ import { getRoyaltyEngineV1ByChainId } from "../../utils/royalty-engine.js";
import type { Prettify } from "../../utils/type-utils.js";
import type { ClientAndChainAndAccount } from "../../utils/types.js";
import { initialize as initMarketplace } from "./__generated__/Marketplace/write/initialize.js";
import { generateExtensionFunctionsFromAbi } from "./get-required-transactions.js";

type Extension = {
metadata: {
name: string;
metadataURI: string;
implementation: `0x${string}`;
};
functions: {
functionSelector: string;
functionSignature: string;
}[];
};

export type MarketplaceContractParams = {
name: string;
Expand Down Expand Up @@ -74,41 +81,72 @@ export async function deployMarketplaceContract(
account,
contractId: "WETH9",
});
const direct = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "DirectListingsLogic",
constructorParams: { _nativeTokenWrapper: WETH.address },
});

const english = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "EnglishAuctionsLogic",
constructorParams: { _nativeTokenWrapper: WETH.address },
});
let extensions: Extension[] = [];

const offers = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "OffersLogic",
});
if (options.version !== "6.0.0") {
const direct = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "DirectListingsLogic",
constructorParams: { _nativeTokenWrapper: WETH.address },
});

const [directFunctions, englishFunctions, offersFunctions] =
await Promise.all([
resolveContractAbi(direct.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
resolveContractAbi(english.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
resolveContractAbi(offers.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
]);
const english = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "EnglishAuctionsLogic",
constructorParams: { _nativeTokenWrapper: WETH.address },
});

const offers = await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: "OffersLogic",
});

const [directFunctions, englishFunctions, offersFunctions] =
await Promise.all([
resolveContractAbi(direct.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
resolveContractAbi(english.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
resolveContractAbi(offers.implementationContract).then(
generateExtensionFunctionsFromAbi,
),
]);
extensions = [
{
metadata: {
name: "Direct Listings",
metadataURI: "",
implementation: direct.implementationContract.address,
},
functions: directFunctions,
},
{
metadata: {
name: "English Auctions",
metadataURI: "",
implementation: english.implementationContract.address,
},
functions: englishFunctions,
},
{
metadata: {
name: "Offers",
metadataURI: "",
implementation: offers.implementationContract.address,
},
functions: offersFunctions,
},
];
}

const { cloneFactoryContract, implementationContract } =
await getOrDeployInfraForPublishedContract({
Expand All @@ -118,32 +156,7 @@ export async function deployMarketplaceContract(
contractId: "MarketplaceV3",
constructorParams: {
_marketplaceV3Params: {
extensions: [
{
metadata: {
name: "Direct Listings",
metadataURI: "",
implementation: direct.implementationContract.address,
},
functions: directFunctions,
},
{
metadata: {
name: "English Auctions",
metadataURI: "",
implementation: english.implementationContract.address,
},
functions: englishFunctions,
},
{
metadata: {
name: "Offers",
metadataURI: "",
implementation: offers.implementationContract.address,
},
functions: offersFunctions,
},
],
extensions,
royaltyEngineAddress: getRoyaltyEngineV1ByChainId(chain.id),
nativeTokenWrapper: WETH.address,
} as MarketplaceConstructorParams[number],
Expand Down Expand Up @@ -199,22 +212,6 @@ async function getInitializeTransaction(options: {
});
}

// helperFns

function generateExtensionFunctionsFromAbi(abi: Abi): Array<{
functionSelector: string;
functionSignature: string;
}> {
const functions = abi.filter(
(item) => item.type === "function" && !item.name.startsWith("_"),
) as AbiFunction[];

return functions.map((fn) => ({
functionSelector: toFunctionSelector(fn),
functionSignature: toFunctionSignature(fn),
}));
}

// let's just ... put this down here
type MarketplaceConstructorParams = AbiParametersToPrimitiveTypes<
[
Expand Down
24 changes: 24 additions & 0 deletions packages/thirdweb/src/extensions/prebuilts/deploy-published.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ export async function deployContractfromDeployMetadata(
import("../../contract/deployment/deploy-via-autofactory.js"),
import("../../contract/deployment/utils/bootstrap.js"),
]);

if (
deployMetadata.routerType === "dynamic" &&
deployMetadata.defaultExtensions
) {
for (const e of deployMetadata.defaultExtensions) {
await getOrDeployInfraForPublishedContract({
chain,
client,
account,
contractId: e.extensionName,
version: e.extensionVersion || "latest",
publisher: e.publisherAddress,
constructorParams:
await getAllDefaultConstructorParamsForImplementation({
chain,
client,
contractId: e.extensionName,
}),
});
}
}

const { cloneFactoryContract, implementationContract } =
await getOrDeployInfraForPublishedContract({
chain,
Expand All @@ -216,6 +239,7 @@ export async function deployContractfromDeployMetadata(
chain,
client,
contractId: deployMetadata.name,
defaultExtensions: deployMetadata.defaultExtensions,
})),
publisher: deployMetadata.publisher,
version: deployMetadata.version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
expect(results.length).toBe(7);
});

it("should count transactions for a dynamic contract", async () => {
const deployMetadata = await fetchPublishedContractMetadata({
client: TEST_CLIENT,
contractId: "EvolvingNFT",
});
const results = await getRequiredTransactions({
client: TEST_CLIENT,
chain: CLEAN_ANVIL_CHAIN,
deployMetadata,
});

expect(results.length).toBe(8);
});

it("should return default constructor params for zksync chains", async () => {
const params = await getAllDefaultConstructorParamsForImplementation({
chain: defineChain(300),
Expand Down
Loading
Loading