diff --git a/.changeset/long-queens-draw.md b/.changeset/long-queens-draw.md new file mode 100644 index 00000000000..2853f28dc5d --- /dev/null +++ b/.changeset/long-queens-draw.md @@ -0,0 +1,37 @@ +--- +"thirdweb": minor +--- + +Added new deployment utility functions to help manage infrastructure contracts and initialization: + +- `getInitializeTransaction`: Prepare initialization transaction for contract deployment +- `getOrDeployInfraForPublishedContract`: Get or deploy required infrastructure for published contracts + +```typescript +import { + getInitializeTransaction, + getOrDeployInfraForPublishedContract +} from "thirdweb"; + +// Get initialization transaction +const initTx = await getInitializeTransaction({ + client, + chain, + account, + implementationContract, + deployMetadata, + initializeParams: { + name: "My Contract", + symbol: "CNTRCT" + } +}); + +// Get or deploy infrastructure +const infra = await getOrDeployInfraForPublishedContract({ + chain, + client, + account, + contractId: "MyContract", + constructorParams: params +}); +``` diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index 3f8e48a8b7d..0c91c50181c 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -22,7 +22,19 @@ import { } from "./infra.js"; /** - * @internal + * Gets or deploys the infrastructure contracts needed for a published contract deployment + * @param args - The arguments object + * @param args.chain - The blockchain network configuration + * @param args.client - The ThirdwebClient instance + * @param args.account - The account performing the deployment + * @param args.contractId - The ID of the contract to deploy + * @param args.constructorParams - Optional constructor parameters for the implementation contract + * @param args.publisher - Optional publisher address, defaults to thirdweb + * @param args.version - Optional version of the contract to deploy + * @returns An object containing: + * - cloneFactoryContract: The factory contract used for creating clones + * - implementationContract: The deployed implementation contract + * @contract */ export async function getOrDeployInfraForPublishedContract( args: ClientAndChainAndAccount & { diff --git a/packages/thirdweb/src/contract/deployment/utils/clone-factory.ts b/packages/thirdweb/src/contract/deployment/utils/clone-factory.ts index 606c91d3b88..48410da5505 100644 --- a/packages/thirdweb/src/contract/deployment/utils/clone-factory.ts +++ b/packages/thirdweb/src/contract/deployment/utils/clone-factory.ts @@ -2,6 +2,10 @@ import type { ClientAndChain } from "../../../utils/types.js"; import { getDeployedInfraContract } from "./infra.js"; /** + * Retrieves the deployed clone factory contract instance if available + * @param args - Client and chain information required to locate the contract + * @returns Promise that resolves to the clone factory contract instance if deployed, null otherwise + * * @internal */ export async function getDeployedCloneFactoryContract(args: ClientAndChain) { diff --git a/packages/thirdweb/src/contract/deployment/utils/infra.ts b/packages/thirdweb/src/contract/deployment/utils/infra.ts index 91aafa811ce..b2f2a5c59e9 100644 --- a/packages/thirdweb/src/contract/deployment/utils/infra.ts +++ b/packages/thirdweb/src/contract/deployment/utils/infra.ts @@ -28,6 +28,16 @@ type GetDeployedInfraParams = Prettify< >; /** + * Retrieves a deployed infrastructure contract instance for the specified contract ID + * @param options - Configuration options for locating the infrastructure contract + * @param options.client - ThirdwebClient instance + * @param options.chain - Target blockchain network + * @param options.contractId - Identifier for the infrastructure contract (e.g. "WETH9", "Forwarder") + * @param options.constructorParams - Optional constructor parameters for contract initialization + * @param options.publisher - Optional custom publisher address + * @param options.version - Optional specific contract version to retrieve + * @returns Promise that resolves to the contract instance if deployed, null otherwise + * * @internal */ export async function getDeployedInfraContract( diff --git a/packages/thirdweb/src/exports/deploys.ts b/packages/thirdweb/src/exports/deploys.ts index 96c8e402445..b5d2a2019e4 100644 --- a/packages/thirdweb/src/exports/deploys.ts +++ b/packages/thirdweb/src/exports/deploys.ts @@ -54,3 +54,6 @@ export { type DeployPackContractOptions, deployPackContract, } from "../extensions/prebuilts/deploy-pack.js"; + +export { getInitializeTransaction } from "../extensions/prebuilts/deploy-published.js"; +export { getOrDeployInfraForPublishedContract } from "../contract/deployment/utils/bootstrap.js"; diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts index d6df91acef1..1d72dab99fd 100644 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts +++ b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts @@ -278,7 +278,22 @@ async function directDeploy(options: { }); } -async function getInitializeTransaction(options: { +/** + * Prepares the initialization transaction for a contract deployment + * @param options - The options for generating the initialize transaction + * @param options.client - The ThirdwebClient instance + * @param options.chain - The blockchain network configuration + * @param options.account - The account performing the initialization + * @param options.implementationContract - The contract implementation to initialize + * @param options.deployMetadata - The metadata for the contract deployment + * @param options.initializeParams - Optional parameters to pass to the initialize function + * @param options.modules - Optional array of modules to install during initialization + * @param options.modules[].deployMetadata - The metadata for the module contract + * @param options.modules[].initializeParams - Optional parameters for module initialization + * @returns The prepared transaction for contract initialization + * @contract + */ +export async function getInitializeTransaction(options: { client: ThirdwebClient; chain: Chain; account: Account; diff --git a/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts b/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts index ea748c5b7ee..585d3d4cfe4 100644 --- a/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts +++ b/packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts @@ -209,6 +209,17 @@ async function getTransactionsForMaketplaceV3(options: { return transactions; } +/** + * Gets the default constructor parameters required for contract implementation deployment + * @param args - The arguments object + * @param args.chain - The blockchain network configuration + * @param args.client - The ThirdwebClient instance + * @returns An object containing default constructor parameters: + * - On zkSync chains: returns an empty object since no parameters are needed + * - On other chains: returns `trustedForwarder` and `nativeTokenWrapper` addresses + * + * @internal + */ export async function getAllDefaultConstructorParamsForImplementation(args: { chain: Chain; client: ThirdwebClient;