From 3b550ae3ebb0f7fe3574df268d80087f36dc6277 Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 21 Oct 2024 18:17:24 +0530 Subject: [PATCH 1/6] Infra deployment updated --- .../contract-deploy-form/custom-contract.tsx | 7 +- .../components/contract-components/hooks.ts | 71 ++++++++++++++++++- .../src/lib/deployment/template-values.ts | 22 ++++++ .../contract/deployment/utils/bootstrap.ts | 64 ++++++++++++++++- .../src/contract/deployment/utils/infra.ts | 22 ++++++ .../deployment/utils/mintfee-manager.ts | 69 ++++++++++++++++++ packages/thirdweb/src/exports/deploys.ts | 5 ++ .../extensions/prebuilts/deploy-published.ts | 8 ++- 8 files changed, 262 insertions(+), 6 deletions(-) create mode 100644 packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts diff --git a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx index b545dff7391..9e3183db314 100644 --- a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx +++ b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx @@ -37,7 +37,7 @@ import { import { useActiveAccount, useActiveWalletChain } from "thirdweb/react"; import { upload } from "thirdweb/storage"; import { FormHelperText, FormLabel, Heading, Text } from "tw-components"; -import { useCustomFactoryAbi, useFunctionParamsFromABI } from "../hooks"; +import { useCustomFactoryAbi, useFunctionParamsFromABI, useMintfeeManager, useMultisig } from "../hooks"; import { addContractToMultiChainRegistry } from "../utils"; import { Fieldset } from "./common"; import { ContractMetadataFieldset } from "./contract-metadata-fieldset"; @@ -149,6 +149,9 @@ export const CustomContractForm: React.FC = ({ const isTWPublisher = checkTwPublisher(metadata?.publisher); + const multisig = useMultisig(walletChain?.id); + const mintfeeManager = useMintfeeManager(walletChain?.id); + const initializerParams = useFunctionParamsFromABI( metadata?.deployType === "customFactory" && customFactoryAbi?.data ? customFactoryAbi.data @@ -193,6 +196,8 @@ export const CustomContractForm: React.FC = ({ { connectedWallet: activeAccount?.address, chainId: walletChain?.id, + multisig: multisig.data?.multisig, + mintFeeManager: mintfeeManager.data?.mintfeeManager }, ); diff --git a/apps/dashboard/src/components/contract-components/hooks.ts b/apps/dashboard/src/components/contract-components/hooks.ts index 9d3721856ee..ce0d240f049 100644 --- a/apps/dashboard/src/components/contract-components/hooks.ts +++ b/apps/dashboard/src/components/contract-components/hooks.ts @@ -6,7 +6,7 @@ import type { Abi } from "abitype"; import { isEnsName, resolveEns } from "lib/ens"; import { useV5DashboardChain } from "lib/v5-adapter"; import { useMemo } from "react"; -import { type ThirdwebContract, getContract } from "thirdweb"; +import { type ThirdwebContract, ZERO_ADDRESS, getContract } from "thirdweb"; import { resolveContractAbi } from "thirdweb/contract"; import { isAddress } from "thirdweb/utils"; import { @@ -18,6 +18,7 @@ import { fetchDeployMetadata } from "./fetchDeployMetadata"; import { fetchPublishedContracts } from "./fetchPublishedContracts"; import { fetchPublishedContractsFromDeploy } from "./fetchPublishedContractsFromDeploy"; import type { ContractId } from "./types"; +import { getPredictedMintFeeManagerAddress, getPredictedMultisigAddress } from "thirdweb/deploys"; export function useFetchDeployMetadata(contractId: ContractId) { return useQuery({ @@ -150,6 +151,66 @@ export function usePublishedContractsQuery(address?: string) { }); } +function multisigQuery(chainId: number | undefined) { + if(!chainId) { + chainId = 1; + } + + return queryOptions({ + queryKey: ["multisig", chainId], + queryFn: async() => { + const chain = useV5DashboardChain(chainId); + const client = useThirdwebClient(); + + const multisig = await getPredictedMultisigAddress({client, chain}); + + return { + multisig + } + + }, + enabled: + !!chainId, + // 24h + gcTime: 60 * 60 * 24 * 1000, + // 1h + staleTime: 60 * 60 * 1000, + // default to zero address + placeholderData: { multisig: ZERO_ADDRESS }, + retry: false, + }) +} + +function mintfeeManagerQuery(chainId: number | undefined) { + if(!chainId) { + chainId = 1; + } + + return queryOptions({ + queryKey: ["mintfee-manager", chainId], + queryFn: async() => { + const chain = useV5DashboardChain(chainId); + const client = useThirdwebClient(); + + const mintfeeManager = await getPredictedMintFeeManagerAddress({client, chain}); + + return { + mintfeeManager + } + + }, + enabled: + !!chainId, + // 24h + gcTime: 60 * 60 * 24 * 1000, + // 1h + staleTime: 60 * 60 * 1000, + // default to zero address + placeholderData: { mintfeeManager: ZERO_ADDRESS }, + retry: false, + }) +} + function ensQuery(addressOrEnsName?: string) { // if the address is `thirdweb.eth` we actually want `deployer.thirdweb.eth` here... if (addressOrEnsName === "thirdweb.eth") { @@ -208,6 +269,14 @@ export function useEns(addressOrEnsName?: string) { return useQuery(ensQuery(addressOrEnsName)); } +export function useMultisig(chainId: number | undefined) { + return useQuery(multisigQuery(chainId)); +} + +export function useMintfeeManager(chainId: number | undefined) { + return useQuery(mintfeeManagerQuery(chainId)); +} + export function useContractEvents(abi: Abi) { return abi.filter((a) => a.type === "event"); } diff --git a/apps/dashboard/src/lib/deployment/template-values.ts b/apps/dashboard/src/lib/deployment/template-values.ts index ed36f7b114c..d7ef5e4dafc 100644 --- a/apps/dashboard/src/lib/deployment/template-values.ts +++ b/apps/dashboard/src/lib/deployment/template-values.ts @@ -3,6 +3,8 @@ import type { SolidityType } from "lib/solidity-types"; interface ReplacementProps { connectedWallet?: string; chainId?: number; + mintFeeManager?: string; + multisig?: string; } interface TemplateValue { @@ -25,6 +27,26 @@ const ADDRESS_TEMPLATE_VALUES: TemplateValue[] = [ ); }, }, + { + value: "{{tw_mintfee_manager}}", + helperText: "Replaced with the address of the thirdweb mint fee manager.", + replacerFunction: (searchValue, replacers) => { + return searchValue.replaceAll( + "{{tw_mintfee_manager}}", + replacers.mintFeeManager || "", + ); + }, + }, + { + value: "{{tw_multisig}}", + helperText: "Replaced with the address of the thirdweb multisig.", + replacerFunction: (searchValue, replacers) => { + return searchValue.replaceAll( + "{{tw_multisig}}", + replacers.multisig || "", + ); + }, + }, ]; const ADDRESS_ARRAY_TEMPLATE_VALUES: TemplateValue[] = [ diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index 3f8e48a8b7d..a7cd41614d5 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -1,3 +1,4 @@ +import { ZERO_ADDRESS } from "../../../constants/addresses.js"; import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js"; import { type FetchDeployMetadataResult, @@ -20,6 +21,7 @@ import { getDeployedInfraContractFromMetadata, prepareInfraContractDeployTransactionFromMetadata, } from "./infra.js"; +import { getDeployedMintFeeManagerContract } from "./mintfee-manager.js"; /** * @internal @@ -34,6 +36,7 @@ export async function getOrDeployInfraForPublishedContract( ): Promise<{ cloneFactoryContract: ThirdwebContract; implementationContract: ThirdwebContract; + mintfeeManagerContract?: ThirdwebContract; }> { const { chain, @@ -83,11 +86,15 @@ export async function getOrDeployInfraForPublishedContract( }; } - let [cloneFactoryContract, implementationContract] = await Promise.all([ + let [cloneFactoryContract, mintfeeManagerContract, implementationContract] = await Promise.all([ getDeployedCloneFactoryContract({ chain, client, }), + getDeployedMintFeeManagerContract({ + chain, + client, + }), getDeployedInfraContract({ chain, client, @@ -98,13 +105,18 @@ export async function getOrDeployInfraForPublishedContract( }), ]); - if (!implementationContract || !cloneFactoryContract) { + if (!implementationContract || !cloneFactoryContract || !mintfeeManagerContract) { // deploy the infra and implementation contracts if not found cloneFactoryContract = await deployCloneFactory({ client, chain, account, }); + mintfeeManagerContract = await deployMintFeeManager({ + client, + chain, + account, + }); implementationContract = await deployImplementation({ client, chain, @@ -115,7 +127,7 @@ export async function getOrDeployInfraForPublishedContract( version, }); } - return { cloneFactoryContract, implementationContract }; + return { cloneFactoryContract, mintfeeManagerContract, implementationContract }; } /** @@ -143,6 +155,52 @@ export async function deployCloneFactory(options: ClientAndChainAndAccount) { }); } +/** + * @internal + * @returns the deployed mint fee manager contract + */ +export async function deployMintFeeManager(options: ClientAndChainAndAccount) { + // create2 factory + const create2Factory = await getDeployedCreate2Factory(options); + if (!create2Factory) { + await deployCreate2Factory(options); + } + + // Multisig + const multisig = await deployMultisig(options); + + // clone factory + return getOrDeployInfraContract({ + ...options, + contractId: "MintFeeManagerCore", + constructorParams: { _owner: multisig, _modules: [], _moduleInstallData: [] }, + }); +} + +/** + * @internal + * @returns the deployed multisig contract + */ +export async function deployMultisig(options: ClientAndChainAndAccount) { + // create2 factory + const create2Factory = await getDeployedCreate2Factory(options); + if (!create2Factory) { + await deployCreate2Factory(options); + } + + return getOrDeployInfraContract({ + ...options, + contractId: "Multisig", + constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + }); +} + +export const TW_SIGNER_1 = ZERO_ADDRESS; +export const TW_SIGNER_2 = ZERO_ADDRESS; +export const TW_SIGNER_3 = ZERO_ADDRESS; + +export const MULTISIG_REQUIRED_APPROVALS = 2; + /** * @internal * @returns the deployed infra contract diff --git a/packages/thirdweb/src/contract/deployment/utils/infra.ts b/packages/thirdweb/src/contract/deployment/utils/infra.ts index 91aafa811ce..fcf3722b3c0 100644 --- a/packages/thirdweb/src/contract/deployment/utils/infra.ts +++ b/packages/thirdweb/src/contract/deployment/utils/infra.ts @@ -16,6 +16,8 @@ export type InfraContractId = | "Forwarder" | "ForwarderEOAOnly" | "TWCloneFactory" + | "MintFeeManagerCore" + | "Multisig" | (string & {}); type GetDeployedInfraParams = Prettify< @@ -27,6 +29,26 @@ type GetDeployedInfraParams = Prettify< } >; +/** + * @internal + */ +export async function getPredictedInfraContractAddress( + options: GetDeployedInfraParams, +): Promise { + const contractMetadata = await fetchPublishedContractMetadata({ + client: options.client, + contractId: options.contractId, + publisher: options.publisher, + version: options.version, + }); + return await computeContractAddress({ + client: options.client, + chain: options.chain, + contractMetadata, + constructorParams: options.constructorParams, + }) +} + /** * @internal */ diff --git a/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts new file mode 100644 index 00000000000..587522a58bb --- /dev/null +++ b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts @@ -0,0 +1,69 @@ +import type { ClientAndChain } from "../../../utils/types.js"; +import { TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3, MULTISIG_REQUIRED_APPROVALS } from "./bootstrap.js"; +import { getDeployedInfraContract, getPredictedInfraContractAddress } from "./infra.js"; + +/** + * @internal + */ +export async function getDeployedMintFeeManagerContract(args: ClientAndChain) { + // check if Multisig is deployed + const multisig = await getDeployedInfraContract({ + ...args, + contractId: "Multisig", + constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + if (!multisig) { + return null; + } + + // check if MintFeeManager is deployed + const mintfeeManager = await getDeployedInfraContract({ + ...args, + contractId: "MintFeeManagerCore", + constructorParams: { _owner: multisig, _modules: [], _moduleInstallData: [] }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + if (!mintfeeManager) { + return null; + } + return mintfeeManager; +} + +/** + * @internal + */ +export async function getPredictedMintFeeManagerAddress(args: ClientAndChain) { + // compute multisig address + const multisig = await getPredictedInfraContractAddress({ + ...args, + contractId: "Multisig", + constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + + // compute mintfee manager address + const mintfeeManager = await getPredictedInfraContractAddress({ + ...args, + contractId: "MintFeeManagerCore", + constructorParams: { _owner: multisig, _modules: [], _moduleInstallData: [] }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + + return mintfeeManager; +} + +/** + * @internal + */ +export async function getPredictedMultisigAddress(args: ClientAndChain) { + // compute multisig address + const multisig = await getPredictedInfraContractAddress({ + ...args, + contractId: "Multisig", + constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + + return multisig; +} diff --git a/packages/thirdweb/src/exports/deploys.ts b/packages/thirdweb/src/exports/deploys.ts index 96c8e402445..50617e4a1c9 100644 --- a/packages/thirdweb/src/exports/deploys.ts +++ b/packages/thirdweb/src/exports/deploys.ts @@ -54,3 +54,8 @@ export { type DeployPackContractOptions, deployPackContract, } from "../extensions/prebuilts/deploy-pack.js"; +export { + getDeployedMintFeeManagerContract, + getPredictedMintFeeManagerAddress, + getPredictedMultisigAddress +} from "../contract/deployment/utils/mintfee-manager.js"; diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts index d6df91acef1..36dd7b27d7c 100644 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts +++ b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts @@ -3,7 +3,7 @@ import type { Chain } from "../../chains/types.js"; import type { ThirdwebClient } from "../../client/client.js"; import { type ThirdwebContract, getContract } from "../../contract/contract.js"; import { fetchPublishedContractMetadata } from "../../contract/deployment/publisher.js"; -import { getOrDeployInfraContractFromMetadata } from "../../contract/deployment/utils/bootstrap.js"; +import { deployMintFeeManager, getOrDeployInfraContractFromMetadata } from "../../contract/deployment/utils/bootstrap.js"; import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js"; import { simulateTransaction } from "../../transaction/actions/simulate.js"; import { prepareContractCall } from "../../transaction/prepare-contract-call.js"; @@ -319,9 +319,15 @@ async function getInitializeTransaction(options: { (i) => i.name === "moduleInstallData" || i.name === "_moduleInstallData", ); if (hasModules) { + await deployMintFeeManager({client, chain, account}); + const moduleAddresses: Hex[] = []; const moduleInstallData: Hex[] = []; for (const module of modules) { + // deploy mint fee manager and multisig if not already deployed + + module.deployMetadata.abi + // deploy the module if not already deployed const contract = await getOrDeployInfraContractFromMetadata({ client, From bceccc5b6f75b4b4e3157c710b829542351775dc Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 21 Oct 2024 18:42:08 +0530 Subject: [PATCH 2/6] lint --- .../contract-deploy-form/custom-contract.tsx | 18 +++++- .../components/contract-components/hooks.ts | 57 ++++++++++--------- packages/thirdweb/src/exports/deploys.ts | 1 - 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx index 7896c67abe5..28176570641 100644 --- a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx +++ b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx @@ -37,7 +37,12 @@ import { import { useActiveAccount, useActiveWalletChain } from "thirdweb/react"; import { upload } from "thirdweb/storage"; import { FormHelperText, FormLabel, Heading, Text } from "tw-components"; -import { useCustomFactoryAbi, useFunctionParamsFromABI, useMintfeeManager, useMultisig } from "../hooks"; +import { + useCustomFactoryAbi, + useFunctionParamsFromABI, + useMintfeeManager, + useMultisig, +} from "../hooks"; import { addContractToMultiChainRegistry } from "../utils"; import { Fieldset } from "./common"; import { ContractMetadataFieldset } from "./contract-metadata-fieldset"; @@ -197,7 +202,7 @@ export const CustomContractForm: React.FC = ({ connectedWallet: activeAccount?.address, chainId: walletChain?.id, multisig: multisig.data?.multisig, - mintFeeManager: mintfeeManager.data?.mintfeeManager + mintFeeManager: mintfeeManager.data?.mintfeeManager, }, ); @@ -217,7 +222,14 @@ export const CustomContractForm: React.FC = ({ {} as Record, ), }), - [deployParams, metadata?.constructorParams, activeAccount, walletChain?.id], + [ + deployParams, + metadata?.constructorParams, + activeAccount, + walletChain?.id, + mintfeeManager, + multisig, + ], ); const transformedQueryData = useMemo( diff --git a/apps/dashboard/src/components/contract-components/hooks.ts b/apps/dashboard/src/components/contract-components/hooks.ts index ce0d240f049..04e3ce948f6 100644 --- a/apps/dashboard/src/components/contract-components/hooks.ts +++ b/apps/dashboard/src/components/contract-components/hooks.ts @@ -8,6 +8,10 @@ import { useV5DashboardChain } from "lib/v5-adapter"; import { useMemo } from "react"; import { type ThirdwebContract, ZERO_ADDRESS, getContract } from "thirdweb"; import { resolveContractAbi } from "thirdweb/contract"; +import { + getPredictedMintFeeManagerAddress, + getPredictedMultisigAddress, +} from "thirdweb/deploys"; import { isAddress } from "thirdweb/utils"; import { type PublishedContractWithVersion, @@ -18,7 +22,6 @@ import { fetchDeployMetadata } from "./fetchDeployMetadata"; import { fetchPublishedContracts } from "./fetchPublishedContracts"; import { fetchPublishedContractsFromDeploy } from "./fetchPublishedContractsFromDeploy"; import type { ContractId } from "./types"; -import { getPredictedMintFeeManagerAddress, getPredictedMultisigAddress } from "thirdweb/deploys"; export function useFetchDeployMetadata(contractId: ContractId) { return useQuery({ @@ -152,25 +155,24 @@ export function usePublishedContractsQuery(address?: string) { } function multisigQuery(chainId: number | undefined) { - if(!chainId) { - chainId = 1; + let chainIdFinal = chainId; + if (!chainIdFinal) { + chainIdFinal = 1; } - + return queryOptions({ - queryKey: ["multisig", chainId], - queryFn: async() => { - const chain = useV5DashboardChain(chainId); + queryKey: ["multisig", chainIdFinal], + queryFn: async () => { + const chain = useV5DashboardChain(chainIdFinal); const client = useThirdwebClient(); - const multisig = await getPredictedMultisigAddress({client, chain}); + const multisig = await getPredictedMultisigAddress({ client, chain }); return { - multisig - } - + multisig, + }; }, - enabled: - !!chainId, + enabled: !!chainId, // 24h gcTime: 60 * 60 * 24 * 1000, // 1h @@ -178,29 +180,32 @@ function multisigQuery(chainId: number | undefined) { // default to zero address placeholderData: { multisig: ZERO_ADDRESS }, retry: false, - }) + }); } function mintfeeManagerQuery(chainId: number | undefined) { - if(!chainId) { - chainId = 1; + let chainIdFinal = chainId; + + if (!chainIdFinal) { + chainIdFinal = 1; } return queryOptions({ - queryKey: ["mintfee-manager", chainId], - queryFn: async() => { - const chain = useV5DashboardChain(chainId); + queryKey: ["mintfee-manager", chainIdFinal], + queryFn: async () => { + const chain = useV5DashboardChain(chainIdFinal); const client = useThirdwebClient(); - const mintfeeManager = await getPredictedMintFeeManagerAddress({client, chain}); + const mintfeeManager = await getPredictedMintFeeManagerAddress({ + client, + chain, + }); return { - mintfeeManager - } - + mintfeeManager, + }; }, - enabled: - !!chainId, + enabled: !!chainId, // 24h gcTime: 60 * 60 * 24 * 1000, // 1h @@ -208,7 +213,7 @@ function mintfeeManagerQuery(chainId: number | undefined) { // default to zero address placeholderData: { mintfeeManager: ZERO_ADDRESS }, retry: false, - }) + }); } function ensQuery(addressOrEnsName?: string) { diff --git a/packages/thirdweb/src/exports/deploys.ts b/packages/thirdweb/src/exports/deploys.ts index 50617e4a1c9..dc3f8292f10 100644 --- a/packages/thirdweb/src/exports/deploys.ts +++ b/packages/thirdweb/src/exports/deploys.ts @@ -55,7 +55,6 @@ export { deployPackContract, } from "../extensions/prebuilts/deploy-pack.js"; export { - getDeployedMintFeeManagerContract, getPredictedMintFeeManagerAddress, getPredictedMultisigAddress } from "../contract/deployment/utils/mintfee-manager.js"; From 2f209f8ac79c7801384820a1342ae2d201cc5c81 Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 21 Oct 2024 19:35:14 +0530 Subject: [PATCH 3/6] fix publish form default params --- .../contract-params-fieldset.tsx | 61 +++++++------------ 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/apps/dashboard/src/components/contract-components/contract-publish-form/contract-params-fieldset.tsx b/apps/dashboard/src/components/contract-components/contract-publish-form/contract-params-fieldset.tsx index b9cdbef3c58..b66c5b1af96 100644 --- a/apps/dashboard/src/components/contract-components/contract-publish-form/contract-params-fieldset.tsx +++ b/apps/dashboard/src/components/contract-components/contract-publish-form/contract-params-fieldset.tsx @@ -5,8 +5,8 @@ import { Input, InputGroup, InputRightElement, + Select, Textarea, - Tooltip, useBreakpointValue, } from "@chakra-ui/react"; import type { AbiParameter } from "abitype"; @@ -15,8 +15,6 @@ import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers"; import { getTemplateValuesForType } from "lib/deployment/template-values"; import { useFormContext } from "react-hook-form"; import { - Button, - Card, Checkbox, FormErrorMessage, FormHelperText, @@ -133,44 +131,27 @@ export const ContractParamsFieldset: React.FC = ({ /> {paramTemplateValues.length > 0 && ( - - - - {paramTemplateValues[0]?.helperText} Click to - apply. - - - } + + )} From d87fbf7cefb7405264cc34d2617c0845598a4807 Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 21 Oct 2024 21:25:12 +0530 Subject: [PATCH 4/6] correct contract id --- .../thirdweb/src/contract/deployment/utils/bootstrap.ts | 2 +- packages/thirdweb/src/contract/deployment/utils/infra.ts | 2 +- .../src/contract/deployment/utils/mintfee-manager.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index a7cd41614d5..75d82076cba 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -190,7 +190,7 @@ export async function deployMultisig(options: ClientAndChainAndAccount) { return getOrDeployInfraContract({ ...options, - contractId: "Multisig", + contractId: "MultiSig", constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, }); } diff --git a/packages/thirdweb/src/contract/deployment/utils/infra.ts b/packages/thirdweb/src/contract/deployment/utils/infra.ts index fcf3722b3c0..9c0cecc9150 100644 --- a/packages/thirdweb/src/contract/deployment/utils/infra.ts +++ b/packages/thirdweb/src/contract/deployment/utils/infra.ts @@ -17,7 +17,7 @@ export type InfraContractId = | "ForwarderEOAOnly" | "TWCloneFactory" | "MintFeeManagerCore" - | "Multisig" + | "MultiSig" | (string & {}); type GetDeployedInfraParams = Prettify< diff --git a/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts index 587522a58bb..11685a3614f 100644 --- a/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts +++ b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts @@ -9,7 +9,7 @@ export async function getDeployedMintFeeManagerContract(args: ClientAndChain) { // check if Multisig is deployed const multisig = await getDeployedInfraContract({ ...args, - contractId: "Multisig", + contractId: "MultiSig", constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging }); @@ -37,7 +37,7 @@ export async function getPredictedMintFeeManagerAddress(args: ClientAndChain) { // compute multisig address const multisig = await getPredictedInfraContractAddress({ ...args, - contractId: "Multisig", + contractId: "MultiSig", constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging }); @@ -60,7 +60,7 @@ export async function getPredictedMultisigAddress(args: ClientAndChain) { // compute multisig address const multisig = await getPredictedInfraContractAddress({ ...args, - contractId: "Multisig", + contractId: "MultiSig", constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging }); From ecca6557b49697f29fd47f0f081408e0495567bc Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 21 Oct 2024 23:41:09 +0530 Subject: [PATCH 5/6] fix publisher --- packages/thirdweb/src/contract/deployment/utils/bootstrap.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index 75d82076cba..fd4ec6ae843 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -192,6 +192,7 @@ export async function deployMultisig(options: ClientAndChainAndAccount) { ...options, contractId: "MultiSig", constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging }); } From 44d8d8b16929b6b72353c5e68cf6324f60241c81 Mon Sep 17 00:00:00 2001 From: Yash Date: Tue, 22 Oct 2024 00:53:34 +0530 Subject: [PATCH 6/6] default values for infra --- .../contract/deployment/utils/bootstrap.ts | 28 +++++++++++++++++-- .../src/contract/deployment/utils/infra.ts | 24 +++++++++++++++- .../deployment/utils/mintfee-manager.ts | 17 +++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts index fd4ec6ae843..2946b704114 100644 --- a/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts +++ b/packages/thirdweb/src/contract/deployment/utils/bootstrap.ts @@ -21,7 +21,12 @@ import { getDeployedInfraContractFromMetadata, prepareInfraContractDeployTransactionFromMetadata, } from "./infra.js"; -import { getDeployedMintFeeManagerContract } from "./mintfee-manager.js"; +import { getDeployedMintFeeManagerContract, getDeployedMultisigContract } from "./mintfee-manager.js"; + +export interface ReplacementValues { + mintFeeManager?: string; + multisig?: string; +} /** * @internal @@ -86,11 +91,15 @@ export async function getOrDeployInfraForPublishedContract( }; } - let [cloneFactoryContract, mintfeeManagerContract, implementationContract] = await Promise.all([ + let [cloneFactoryContract, mintfeeManagerContract, multisig, implementationContract] = await Promise.all([ getDeployedCloneFactoryContract({ chain, client, }), + getDeployedMultisigContract({ + chain, + client, + }), getDeployedMintFeeManagerContract({ chain, client, @@ -105,13 +114,18 @@ export async function getOrDeployInfraForPublishedContract( }), ]); - if (!implementationContract || !cloneFactoryContract || !mintfeeManagerContract) { + if (!implementationContract || !cloneFactoryContract || !multisig || !mintfeeManagerContract) { // deploy the infra and implementation contracts if not found cloneFactoryContract = await deployCloneFactory({ client, chain, account, }); + multisig = await deployMultisig({ + client, + chain, + account, + }); mintfeeManagerContract = await deployMintFeeManager({ client, chain, @@ -125,6 +139,10 @@ export async function getOrDeployInfraForPublishedContract( constructorParams, publisher, version, + replacementValues: { + mintFeeManager: mintfeeManagerContract.address, + multisig: multisig.address + } }); } return { cloneFactoryContract, mintfeeManagerContract, implementationContract }; @@ -212,6 +230,7 @@ export async function deployImplementation( constructorParams?: Record; publisher?: string; version?: string; + replacementValues?: ReplacementValues }, ) { return getOrDeployInfraContract({ @@ -220,6 +239,7 @@ export async function deployImplementation( constructorParams: options.constructorParams, publisher: options.publisher, version: options.version, + replacementValues: options.replacementValues }); } @@ -233,6 +253,7 @@ export async function getOrDeployInfraContract( constructorParams?: Record; publisher?: string; version?: string; + replacementValues?: ReplacementValues }, ) { const contractMetadata = await fetchPublishedContractMetadata({ @@ -254,6 +275,7 @@ export async function getOrDeployInfraContractFromMetadata( options: ClientAndChainAndAccount & { contractMetadata: FetchDeployMetadataResult; constructorParams?: Record; + replacementValues?: ReplacementValues }, ) { const infraContract = await getDeployedInfraContractFromMetadata(options); diff --git a/packages/thirdweb/src/contract/deployment/utils/infra.ts b/packages/thirdweb/src/contract/deployment/utils/infra.ts index 9c0cecc9150..bd240ef9411 100644 --- a/packages/thirdweb/src/contract/deployment/utils/infra.ts +++ b/packages/thirdweb/src/contract/deployment/utils/infra.ts @@ -9,6 +9,7 @@ import type { Prettify } from "../../../utils/type-utils.js"; import type { ClientAndChain } from "../../../utils/types.js"; import { type ThirdwebContract, getContract } from "../../contract.js"; import { fetchPublishedContractMetadata } from "../publisher.js"; +import type { ReplacementValues } from "./bootstrap.js"; import { computeCreate2FactoryAddress } from "./create-2-factory.js"; export type InfraContractId = @@ -99,8 +100,26 @@ export function prepareInfraContractDeployTransactionFromMetadata(options: { contractMetadata: FetchDeployMetadataResult; constructorParams?: Record; salt?: string; + replacementValues?: ReplacementValues }) { const { client, chain } = options; + let params: Record; + if(options.contractMetadata.constructorParams) { + if(!options.constructorParams) { + Object.keys(options.contractMetadata.constructorParams).forEach(async (key, index) => { + const param = options.contractMetadata.constructorParams![key]; + + if (param?.defaultValue === "{{tw-mintfee-mmanager}}") { + params[index] = options.replacementValues?.mintFeeManager || ""; + } else if (param?.defaultValue === "{{tw-multisig}}") { + params[index] = options.replacementValues?.multisig || ""; + } else { + params[index] = ""; + } + }); + } + } + return prepareTransaction({ client, chain, @@ -111,7 +130,10 @@ export function prepareInfraContractDeployTransactionFromMetadata(options: { }), data: async () => { const infraContractInfo = - await computeDeploymentInfoFromMetadata(options); + await computeDeploymentInfoFromMetadata({ + ...options, + constructorParams: params + }); return infraContractInfo.initBytecodeWithsalt; }, }); diff --git a/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts index 11685a3614f..9ab9d1ce76a 100644 --- a/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts +++ b/packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts @@ -30,6 +30,23 @@ export async function getDeployedMintFeeManagerContract(args: ClientAndChain) { return mintfeeManager; } +/** + * @internal + */ +export async function getDeployedMultisigContract(args: ClientAndChain) { + const multisig = await getDeployedInfraContract({ + ...args, + contractId: "MultiSig", + constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS }, + publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging + }); + if (!multisig) { + return null; + } + + return multisig; +} + /** * @internal */