diff --git a/.changeset/rich-steaks-guess.md b/.changeset/rich-steaks-guess.md new file mode 100644 index 00000000000..d96b6a76ce2 --- /dev/null +++ b/.changeset/rich-steaks-guess.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Handle zk sync direct deploys in `deployContract` diff --git a/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC1155.json b/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC1155.json index 042b58609cb..ade3f552396 100644 --- a/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC1155.json +++ b/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC1155.json @@ -1,6 +1,10 @@ [ "function encodeBytesOnInstall() pure returns (bytes)", "function getAllMetadataBatches() view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI)[])", + "function getBatchIndex(uint256 _tokenId) view returns (uint256)", + "function getMetadataBatch(uint256 _batchIndex) view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI))", + "function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)", + "function setBaseURI(uint256 _batchIndex, string _baseURI)", "function uploadMetadata(uint256 _amount, string _baseURI)", - "event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)" + "event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)" ] \ No newline at end of file diff --git a/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC721.json b/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC721.json index 042b58609cb..ade3f552396 100644 --- a/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC721.json +++ b/packages/thirdweb/scripts/generate/abis/modules/BatchMetadataERC721.json @@ -1,6 +1,10 @@ [ "function encodeBytesOnInstall() pure returns (bytes)", "function getAllMetadataBatches() view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI)[])", + "function getBatchIndex(uint256 _tokenId) view returns (uint256)", + "function getMetadataBatch(uint256 _batchIndex) view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI))", + "function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)", + "function setBaseURI(uint256 _batchIndex, string _baseURI)", "function uploadMetadata(uint256 _amount, string _baseURI)", - "event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)" + "event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)" ] \ No newline at end of file diff --git a/packages/thirdweb/scripts/generate/abis/modules/SequentialTokenIdERC1155.json b/packages/thirdweb/scripts/generate/abis/modules/SequentialTokenIdERC1155.json index 926ce7e3355..1ae4c38ca8d 100644 --- a/packages/thirdweb/scripts/generate/abis/modules/SequentialTokenIdERC1155.json +++ b/packages/thirdweb/scripts/generate/abis/modules/SequentialTokenIdERC1155.json @@ -1,6 +1,6 @@ [ - "function encodeBytesOnInstall() pure returns (bytes)", + "function encodeBytesOnInstall(uint256 startTokenId) pure returns (bytes)", + "function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)", "function getNextTokenId() view returns (uint256)", - "error SequentialTokenIdInvalidTokenId()", - "error UpdateTokenIdCallbackERC1155NotImplemented()" + "function updateTokenIdERC1155(uint256 _tokenId) payable returns (uint256)" ] \ No newline at end of file diff --git a/packages/thirdweb/src/contract/deployment/deploy-with-abi.ts b/packages/thirdweb/src/contract/deployment/deploy-with-abi.ts index 061a13baa0e..c9d6a890d81 100644 --- a/packages/thirdweb/src/contract/deployment/deploy-with-abi.ts +++ b/packages/thirdweb/src/contract/deployment/deploy-with-abi.ts @@ -5,6 +5,7 @@ import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js"; import { normalizeFunctionParams } from "../../utils/abi/normalizeFunctionParams.js"; import { computeDeploymentAddress } from "../../utils/any-evm/compute-deployment-address.js"; import { computeDeploymentInfoFromBytecode } from "../../utils/any-evm/compute-published-contract-deploy-info.js"; +import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js"; import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js"; import { ensureBytecodePrefix } from "../../utils/bytecode/prefix.js"; import { concatHex } from "../../utils/encoding/helpers/concat-hex.js"; @@ -13,6 +14,7 @@ import type { Prettify } from "../../utils/type-utils.js"; import type { ClientAndChain } from "../../utils/types.js"; import type { Account } from "../../wallets/interfaces/wallet.js"; import { getContract } from "../contract.js"; +import { zkDeployContract } from "./zksync/zkDeployContract.js"; /** * @extension DEPLOY @@ -121,6 +123,18 @@ export async function deployContract( salt?: string; }, ) { + if (await isZkSyncChain(options.chain)) { + return zkDeployContract({ + account: options.account, + client: options.client, + chain: options.chain, + bytecode: options.bytecode, + abi: options.abi, + params: options.constructorParams, + salt: options.salt, + }); + } + if (options.salt !== undefined) { // Deploy with CREATE2 if salt is provided const info = await computeDeploymentInfoFromBytecode(options); diff --git a/packages/thirdweb/src/extensions/ens/resolve-avatar.test.ts b/packages/thirdweb/src/extensions/ens/resolve-avatar.test.ts index 6f31758eea3..7d1944c8a1e 100644 --- a/packages/thirdweb/src/extensions/ens/resolve-avatar.test.ts +++ b/packages/thirdweb/src/extensions/ens/resolve-avatar.test.ts @@ -1,5 +1,4 @@ import { describe, expect, it } from "vitest"; - import { TEST_CLIENT } from "../../../test/src/test-clients.js"; import { resolveAvatar } from "./resolve-avatar.js"; @@ -22,9 +21,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("ENS:resolve-avatar", () => { client: TEST_CLIENT, name: "vitalik.eth", }); - expect(avatarUri?.split("/ipfs/")[1]).toMatchInlineSnapshot( - `"QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif"`, - ); + expect(avatarUri).toMatchInlineSnapshot(`"https://euc.li/vitalik.eth"`); }); it("resolves name without avatar record to null", async () => { diff --git a/packages/thirdweb/src/extensions/modules/MintableERC1155/mintableERC1155.test.ts b/packages/thirdweb/src/extensions/modules/MintableERC1155/mintableERC1155.test.ts index 97f626e10c0..e49c6d978ee 100644 --- a/packages/thirdweb/src/extensions/modules/MintableERC1155/mintableERC1155.test.ts +++ b/packages/thirdweb/src/extensions/modules/MintableERC1155/mintableERC1155.test.ts @@ -40,7 +40,9 @@ describe.runIf(process.env.TW_SECRET_KEY)("ModularTokenERC1155", () => { primarySaleRecipient: TEST_ACCOUNT_A.address, }), BatchMetadataERC1155.module(), - SequentialTokenIdERC1155.module(), + SequentialTokenIdERC1155.module({ + startTokenId: 0n, + }), ], }); contract = getContract({ diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/events/BatchMetadataUpdate.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/events/BatchMetadataUpdate.ts index 81611b6fadb..f21472a187f 100644 --- a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/events/BatchMetadataUpdate.ts +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/events/BatchMetadataUpdate.ts @@ -20,6 +20,6 @@ import { prepareEvent } from "../../../../../event/prepare-event.js"; export function batchMetadataUpdateEvent() { return prepareEvent({ signature: - "event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)", + "event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)", }); } diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getBatchIndex.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getBatchIndex.ts new file mode 100644 index 00000000000..5a193fd2cb0 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getBatchIndex.ts @@ -0,0 +1,125 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "getBatchIndex" function. + */ +export type GetBatchIndexParams = { + tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_tokenId" }>; +}; + +export const FN_SELECTOR = "0x44ec3c07" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_tokenId", + }, +] as const; +const FN_OUTPUTS = [ + { + type: "uint256", + }, +] as const; + +/** + * Checks if the `getBatchIndex` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getBatchIndex` method is supported. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const supported = BatchMetadataERC1155.isGetBatchIndexSupported(["0x..."]); + * ``` + */ +export function isGetBatchIndexSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "getBatchIndex" function. + * @param options - The options for the getBatchIndex function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeGetBatchIndexParams({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeGetBatchIndexParams(options: GetBatchIndexParams) { + return encodeAbiParameters(FN_INPUTS, [options.tokenId]); +} + +/** + * Encodes the "getBatchIndex" function into a Hex string with its parameters. + * @param options - The options for the getBatchIndex function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeGetBatchIndex({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeGetBatchIndex(options: GetBatchIndexParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeGetBatchIndexParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Decodes the result of the getBatchIndex function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.decodeGetBatchIndexResultResult("..."); + * ``` + */ +export function decodeGetBatchIndexResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getBatchIndex" function on the contract. + * @param options - The options for the getBatchIndex function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC1155.getBatchIndex({ + * contract, + * tokenId: ..., + * }); + * + * ``` + */ +export async function getBatchIndex( + options: BaseTransactionOptions, +) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [options.tokenId], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getMetadataBatch.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getMetadataBatch.ts new file mode 100644 index 00000000000..ca806668ee7 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getMetadataBatch.ts @@ -0,0 +1,142 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "getMetadataBatch" function. + */ +export type GetMetadataBatchParams = { + batchIndex: AbiParameterToPrimitiveType<{ + type: "uint256"; + name: "_batchIndex"; + }>; +}; + +export const FN_SELECTOR = "0xe034558b" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_batchIndex", + }, +] as const; +const FN_OUTPUTS = [ + { + type: "tuple", + components: [ + { + type: "uint256", + name: "startTokenIdInclusive", + }, + { + type: "uint256", + name: "endTokenIdInclusive", + }, + { + type: "string", + name: "baseURI", + }, + ], + }, +] as const; + +/** + * Checks if the `getMetadataBatch` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getMetadataBatch` method is supported. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const supported = BatchMetadataERC1155.isGetMetadataBatchSupported(["0x..."]); + * ``` + */ +export function isGetMetadataBatchSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "getMetadataBatch" function. + * @param options - The options for the getMetadataBatch function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeGetMetadataBatchParams({ + * batchIndex: ..., + * }); + * ``` + */ +export function encodeGetMetadataBatchParams(options: GetMetadataBatchParams) { + return encodeAbiParameters(FN_INPUTS, [options.batchIndex]); +} + +/** + * Encodes the "getMetadataBatch" function into a Hex string with its parameters. + * @param options - The options for the getMetadataBatch function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeGetMetadataBatch({ + * batchIndex: ..., + * }); + * ``` + */ +export function encodeGetMetadataBatch(options: GetMetadataBatchParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeGetMetadataBatchParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Decodes the result of the getMetadataBatch function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.decodeGetMetadataBatchResultResult("..."); + * ``` + */ +export function decodeGetMetadataBatchResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getMetadataBatch" function on the contract. + * @param options - The options for the getMetadataBatch function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC1155.getMetadataBatch({ + * contract, + * batchIndex: ..., + * }); + * + * ``` + */ +export async function getMetadataBatch( + options: BaseTransactionOptions, +) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [options.batchIndex], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getModuleConfig.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getModuleConfig.ts new file mode 100644 index 00000000000..cf036b86757 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/read/getModuleConfig.ts @@ -0,0 +1,109 @@ +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; + +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +export const FN_SELECTOR = "0x89e04e0e" as const; +const FN_INPUTS = [] as const; +const FN_OUTPUTS = [ + { + type: "tuple", + name: "config", + components: [ + { + type: "bool", + name: "registerInstallationCallback", + }, + { + type: "bytes4[]", + name: "requiredInterfaces", + }, + { + type: "bytes4[]", + name: "supportedInterfaces", + }, + { + type: "tuple[]", + name: "callbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + ], + }, + { + type: "tuple[]", + name: "fallbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + { + type: "uint256", + name: "permissionBits", + }, + ], + }, + ], + }, +] as const; + +/** + * Checks if the `getModuleConfig` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getModuleConfig` method is supported. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const supported = BatchMetadataERC1155.isGetModuleConfigSupported(["0x..."]); + * ``` + */ +export function isGetModuleConfigSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Decodes the result of the getModuleConfig function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.decodeGetModuleConfigResultResult("..."); + * ``` + */ +export function decodeGetModuleConfigResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getModuleConfig" function on the contract. + * @param options - The options for the getModuleConfig function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC1155.getModuleConfig({ + * contract, + * }); + * + * ``` + */ +export async function getModuleConfig(options: BaseTransactionOptions) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/write/setBaseURI.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/write/setBaseURI.ts new file mode 100644 index 00000000000..5e7b19ccf68 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC1155/write/setBaseURI.ts @@ -0,0 +1,148 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import type { + BaseTransactionOptions, + WithOverrides, +} from "../../../../../transaction/types.js"; +import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { once } from "../../../../../utils/promise/once.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "setBaseURI" function. + */ +export type SetBaseURIParams = WithOverrides<{ + batchIndex: AbiParameterToPrimitiveType<{ + type: "uint256"; + name: "_batchIndex"; + }>; + baseURI: AbiParameterToPrimitiveType<{ type: "string"; name: "_baseURI" }>; +}>; + +export const FN_SELECTOR = "0x33cfcb9f" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_batchIndex", + }, + { + type: "string", + name: "_baseURI", + }, +] as const; +const FN_OUTPUTS = [] as const; + +/** + * Checks if the `setBaseURI` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `setBaseURI` method is supported. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * + * const supported = BatchMetadataERC1155.isSetBaseURISupported(["0x..."]); + * ``` + */ +export function isSetBaseURISupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "setBaseURI" function. + * @param options - The options for the setBaseURI function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeSetBaseURIParams({ + * batchIndex: ..., + * baseURI: ..., + * }); + * ``` + */ +export function encodeSetBaseURIParams(options: SetBaseURIParams) { + return encodeAbiParameters(FN_INPUTS, [options.batchIndex, options.baseURI]); +} + +/** + * Encodes the "setBaseURI" function into a Hex string with its parameters. + * @param options - The options for the setBaseURI function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * const result = BatchMetadataERC1155.encodeSetBaseURI({ + * batchIndex: ..., + * baseURI: ..., + * }); + * ``` + */ +export function encodeSetBaseURI(options: SetBaseURIParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeSetBaseURIParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Prepares a transaction to call the "setBaseURI" function on the contract. + * @param options - The options for the "setBaseURI" function. + * @returns A prepared transaction object. + * @modules BatchMetadataERC1155 + * @example + * ```ts + * import { sendTransaction } from "thirdweb"; + * import { BatchMetadataERC1155 } from "thirdweb/modules"; + * + * const transaction = BatchMetadataERC1155.setBaseURI({ + * contract, + * batchIndex: ..., + * baseURI: ..., + * overrides: { + * ... + * } + * }); + * + * // Send the transaction + * await sendTransaction({ transaction, account }); + * ``` + */ +export function setBaseURI( + options: BaseTransactionOptions< + | SetBaseURIParams + | { + asyncParams: () => Promise; + } + >, +) { + const asyncOptions = once(async () => { + return "asyncParams" in options ? await options.asyncParams() : options; + }); + + return prepareContractCall({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: async () => { + const resolvedOptions = await asyncOptions(); + return [resolvedOptions.batchIndex, resolvedOptions.baseURI] as const; + }, + value: async () => (await asyncOptions()).overrides?.value, + accessList: async () => (await asyncOptions()).overrides?.accessList, + gas: async () => (await asyncOptions()).overrides?.gas, + gasPrice: async () => (await asyncOptions()).overrides?.gasPrice, + maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas, + maxPriorityFeePerGas: async () => + (await asyncOptions()).overrides?.maxPriorityFeePerGas, + nonce: async () => (await asyncOptions()).overrides?.nonce, + extraGas: async () => (await asyncOptions()).overrides?.extraGas, + erc20Value: async () => (await asyncOptions()).overrides?.erc20Value, + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/events/BatchMetadataUpdate.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/events/BatchMetadataUpdate.ts index 6552d84690f..0dd4850bbaa 100644 --- a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/events/BatchMetadataUpdate.ts +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/events/BatchMetadataUpdate.ts @@ -20,6 +20,6 @@ import { prepareEvent } from "../../../../../event/prepare-event.js"; export function batchMetadataUpdateEvent() { return prepareEvent({ signature: - "event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)", + "event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)", }); } diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getBatchIndex.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getBatchIndex.ts new file mode 100644 index 00000000000..f6004039b01 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getBatchIndex.ts @@ -0,0 +1,125 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "getBatchIndex" function. + */ +export type GetBatchIndexParams = { + tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_tokenId" }>; +}; + +export const FN_SELECTOR = "0x44ec3c07" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_tokenId", + }, +] as const; +const FN_OUTPUTS = [ + { + type: "uint256", + }, +] as const; + +/** + * Checks if the `getBatchIndex` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getBatchIndex` method is supported. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const supported = BatchMetadataERC721.isGetBatchIndexSupported(["0x..."]); + * ``` + */ +export function isGetBatchIndexSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "getBatchIndex" function. + * @param options - The options for the getBatchIndex function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeGetBatchIndexParams({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeGetBatchIndexParams(options: GetBatchIndexParams) { + return encodeAbiParameters(FN_INPUTS, [options.tokenId]); +} + +/** + * Encodes the "getBatchIndex" function into a Hex string with its parameters. + * @param options - The options for the getBatchIndex function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeGetBatchIndex({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeGetBatchIndex(options: GetBatchIndexParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeGetBatchIndexParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Decodes the result of the getBatchIndex function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.decodeGetBatchIndexResultResult("..."); + * ``` + */ +export function decodeGetBatchIndexResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getBatchIndex" function on the contract. + * @param options - The options for the getBatchIndex function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC721.getBatchIndex({ + * contract, + * tokenId: ..., + * }); + * + * ``` + */ +export async function getBatchIndex( + options: BaseTransactionOptions, +) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [options.tokenId], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getMetadataBatch.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getMetadataBatch.ts new file mode 100644 index 00000000000..89701986e36 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getMetadataBatch.ts @@ -0,0 +1,142 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "getMetadataBatch" function. + */ +export type GetMetadataBatchParams = { + batchIndex: AbiParameterToPrimitiveType<{ + type: "uint256"; + name: "_batchIndex"; + }>; +}; + +export const FN_SELECTOR = "0xe034558b" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_batchIndex", + }, +] as const; +const FN_OUTPUTS = [ + { + type: "tuple", + components: [ + { + type: "uint256", + name: "startTokenIdInclusive", + }, + { + type: "uint256", + name: "endTokenIdInclusive", + }, + { + type: "string", + name: "baseURI", + }, + ], + }, +] as const; + +/** + * Checks if the `getMetadataBatch` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getMetadataBatch` method is supported. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const supported = BatchMetadataERC721.isGetMetadataBatchSupported(["0x..."]); + * ``` + */ +export function isGetMetadataBatchSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "getMetadataBatch" function. + * @param options - The options for the getMetadataBatch function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeGetMetadataBatchParams({ + * batchIndex: ..., + * }); + * ``` + */ +export function encodeGetMetadataBatchParams(options: GetMetadataBatchParams) { + return encodeAbiParameters(FN_INPUTS, [options.batchIndex]); +} + +/** + * Encodes the "getMetadataBatch" function into a Hex string with its parameters. + * @param options - The options for the getMetadataBatch function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeGetMetadataBatch({ + * batchIndex: ..., + * }); + * ``` + */ +export function encodeGetMetadataBatch(options: GetMetadataBatchParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeGetMetadataBatchParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Decodes the result of the getMetadataBatch function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.decodeGetMetadataBatchResultResult("..."); + * ``` + */ +export function decodeGetMetadataBatchResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getMetadataBatch" function on the contract. + * @param options - The options for the getMetadataBatch function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC721.getMetadataBatch({ + * contract, + * batchIndex: ..., + * }); + * + * ``` + */ +export async function getMetadataBatch( + options: BaseTransactionOptions, +) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [options.batchIndex], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getModuleConfig.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getModuleConfig.ts new file mode 100644 index 00000000000..315f110f39a --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/read/getModuleConfig.ts @@ -0,0 +1,109 @@ +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; + +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +export const FN_SELECTOR = "0x89e04e0e" as const; +const FN_INPUTS = [] as const; +const FN_OUTPUTS = [ + { + type: "tuple", + name: "config", + components: [ + { + type: "bool", + name: "registerInstallationCallback", + }, + { + type: "bytes4[]", + name: "requiredInterfaces", + }, + { + type: "bytes4[]", + name: "supportedInterfaces", + }, + { + type: "tuple[]", + name: "callbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + ], + }, + { + type: "tuple[]", + name: "fallbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + { + type: "uint256", + name: "permissionBits", + }, + ], + }, + ], + }, +] as const; + +/** + * Checks if the `getModuleConfig` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getModuleConfig` method is supported. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const supported = BatchMetadataERC721.isGetModuleConfigSupported(["0x..."]); + * ``` + */ +export function isGetModuleConfigSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Decodes the result of the getModuleConfig function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.decodeGetModuleConfigResultResult("..."); + * ``` + */ +export function decodeGetModuleConfigResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getModuleConfig" function on the contract. + * @param options - The options for the getModuleConfig function. + * @returns The parsed result of the function call. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * + * const result = await BatchMetadataERC721.getModuleConfig({ + * contract, + * }); + * + * ``` + */ +export async function getModuleConfig(options: BaseTransactionOptions) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/write/setBaseURI.ts b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/write/setBaseURI.ts new file mode 100644 index 00000000000..70a888f31e1 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/BatchMetadataERC721/write/setBaseURI.ts @@ -0,0 +1,148 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import type { + BaseTransactionOptions, + WithOverrides, +} from "../../../../../transaction/types.js"; +import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { once } from "../../../../../utils/promise/once.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "setBaseURI" function. + */ +export type SetBaseURIParams = WithOverrides<{ + batchIndex: AbiParameterToPrimitiveType<{ + type: "uint256"; + name: "_batchIndex"; + }>; + baseURI: AbiParameterToPrimitiveType<{ type: "string"; name: "_baseURI" }>; +}>; + +export const FN_SELECTOR = "0x33cfcb9f" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_batchIndex", + }, + { + type: "string", + name: "_baseURI", + }, +] as const; +const FN_OUTPUTS = [] as const; + +/** + * Checks if the `setBaseURI` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `setBaseURI` method is supported. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * + * const supported = BatchMetadataERC721.isSetBaseURISupported(["0x..."]); + * ``` + */ +export function isSetBaseURISupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "setBaseURI" function. + * @param options - The options for the setBaseURI function. + * @returns The encoded ABI parameters. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeSetBaseURIParams({ + * batchIndex: ..., + * baseURI: ..., + * }); + * ``` + */ +export function encodeSetBaseURIParams(options: SetBaseURIParams) { + return encodeAbiParameters(FN_INPUTS, [options.batchIndex, options.baseURI]); +} + +/** + * Encodes the "setBaseURI" function into a Hex string with its parameters. + * @param options - The options for the setBaseURI function. + * @returns The encoded hexadecimal string. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * const result = BatchMetadataERC721.encodeSetBaseURI({ + * batchIndex: ..., + * baseURI: ..., + * }); + * ``` + */ +export function encodeSetBaseURI(options: SetBaseURIParams) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeSetBaseURIParams(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Prepares a transaction to call the "setBaseURI" function on the contract. + * @param options - The options for the "setBaseURI" function. + * @returns A prepared transaction object. + * @modules BatchMetadataERC721 + * @example + * ```ts + * import { sendTransaction } from "thirdweb"; + * import { BatchMetadataERC721 } from "thirdweb/modules"; + * + * const transaction = BatchMetadataERC721.setBaseURI({ + * contract, + * batchIndex: ..., + * baseURI: ..., + * overrides: { + * ... + * } + * }); + * + * // Send the transaction + * await sendTransaction({ transaction, account }); + * ``` + */ +export function setBaseURI( + options: BaseTransactionOptions< + | SetBaseURIParams + | { + asyncParams: () => Promise; + } + >, +) { + const asyncOptions = once(async () => { + return "asyncParams" in options ? await options.asyncParams() : options; + }); + + return prepareContractCall({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: async () => { + const resolvedOptions = await asyncOptions(); + return [resolvedOptions.batchIndex, resolvedOptions.baseURI] as const; + }, + value: async () => (await asyncOptions()).overrides?.value, + accessList: async () => (await asyncOptions()).overrides?.accessList, + gas: async () => (await asyncOptions()).overrides?.gas, + gasPrice: async () => (await asyncOptions()).overrides?.gasPrice, + maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas, + maxPriorityFeePerGas: async () => + (await asyncOptions()).overrides?.maxPriorityFeePerGas, + nonce: async () => (await asyncOptions()).overrides?.nonce, + extraGas: async () => (await asyncOptions()).overrides?.extraGas, + erc20Value: async () => (await asyncOptions()).overrides?.erc20Value, + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/encode/encodeBytesOnInstall.ts b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/encode/encodeBytesOnInstall.ts new file mode 100644 index 00000000000..308f4bc860a --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/encode/encodeBytesOnInstall.ts @@ -0,0 +1,40 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; + +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; + +/** + * Represents the parameters for the "encodeBytesOnInstall" function. + */ +export type EncodeBytesOnInstallParams = { + startTokenId: AbiParameterToPrimitiveType<{ + type: "uint256"; + name: "startTokenId"; + }>; +}; + +export const FN_SELECTOR = "0x579a6021" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "startTokenId", + }, +] as const; + +/** + * Encodes the parameters for the "encodeBytesOnInstall" function. + * @param options - The options for the encodeBytesOnInstall function. + * @returns The encoded ABI parameters. + * @extension MODULES + * @example + * ```ts + * import { encodeEncodeBytesOnInstallParams } "thirdweb/extensions/modules"; + * const result = encodeEncodeBytesOnInstallParams({ + * startTokenId: ..., + * }); + * ``` + */ +export function encodeBytesOnInstallParams( + options: EncodeBytesOnInstallParams, +) { + return encodeAbiParameters(FN_INPUTS, [options.startTokenId]); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/module/install.ts b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/module/install.ts index 22a917574bf..ce28b48f975 100644 --- a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/module/install.ts +++ b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/module/install.ts @@ -4,7 +4,10 @@ import type { ThirdwebContract } from "../../../../../contract/contract.js"; import type { PreparedTransaction } from "../../../../../transaction/prepare-transaction.js"; import type { Address } from "../../../../../utils/address.js"; import type { Account } from "../../../../../wallets/interfaces/wallet.js"; - +import { + type EncodeBytesOnInstallParams, + encodeBytesOnInstallParams, +} from "../encode/encodeBytesOnInstall.js"; import { getOrDeployModule } from "../../../common/getOrDeployModule.js"; import { installPublishedModule } from "../../../common/installPublishedModule.js"; @@ -27,13 +30,17 @@ const contractId = "SequentialTokenIdERC1155"; * name: "My Modular Contract", * }, * modules: [ - * SequentialTokenIdERC1155.module(), + * SequentialTokenIdERC1155.module({ + * startTokenId: ..., + * }), * ], * }); * ``` * @modules SequentialTokenIdERC1155 */ -export function module(params?: { publisher?: string }) { +export function module( + params: EncodeBytesOnInstallParams & { publisher?: string }, +) { return async (args: { client: ThirdwebClient; chain: Chain; @@ -49,7 +56,7 @@ export function module(params?: { publisher?: string }) { }); return { module: moduleContract.address as Address, - data: "0x" as const, + data: encodeInstall(params), }; }; } @@ -65,7 +72,9 @@ export function module(params?: { publisher?: string }) { * const transaction = SequentialTokenIdERC1155.install({ * contract: coreContract, * account: account, - + * params: { + * startTokenId: ..., + * }, * }); * * await sendTransaction({ @@ -78,13 +87,13 @@ export function module(params?: { publisher?: string }) { export function install(options: { contract: ThirdwebContract; account: Account; - params?: { publisher?: string }; + params: EncodeBytesOnInstallParams & { publisher?: string }; }): PreparedTransaction { return installPublishedModule({ account: options.account, contract: options.contract, moduleName: contractId, - moduleData: "0x" as const, + moduleData: encodeInstall(options.params), publisher: options.params?.publisher, }); } @@ -95,6 +104,6 @@ export function install(options: { * @returns - The encoded data. * @modules SequentialTokenIdERC1155 */ -export function encodeInstall() { - return "0x"; +export function encodeInstall(params: EncodeBytesOnInstallParams) { + return encodeBytesOnInstallParams(params); } diff --git a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/encodeBytesOnInstall.ts b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/encodeBytesOnInstall.ts deleted file mode 100644 index fa97f67c090..00000000000 --- a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/encodeBytesOnInstall.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { readContract } from "../../../../../transaction/read-contract.js"; -import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; - -import { decodeAbiParameters } from "viem"; -import type { Hex } from "../../../../../utils/encoding/hex.js"; -import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; - -export const FN_SELECTOR = "0xfec7ff72" as const; -const FN_INPUTS = [] as const; -const FN_OUTPUTS = [ - { - type: "bytes", - }, -] as const; - -/** - * Checks if the `encodeBytesOnInstall` method is supported by the given contract. - * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. - * @returns A boolean indicating if the `encodeBytesOnInstall` method is supported. - * @modules SequentialTokenIdERC1155 - * @example - * ```ts - * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; - * const supported = SequentialTokenIdERC1155.isEncodeBytesOnInstallSupported(["0x..."]); - * ``` - */ -export function isEncodeBytesOnInstallSupported(availableSelectors: string[]) { - return detectMethod({ - availableSelectors, - method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, - }); -} - -/** - * Decodes the result of the encodeBytesOnInstall function call. - * @param result - The hexadecimal result to decode. - * @returns The decoded result as per the FN_OUTPUTS definition. - * @modules SequentialTokenIdERC1155 - * @example - * ```ts - * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; - * const result = SequentialTokenIdERC1155.decodeEncodeBytesOnInstallResultResult("..."); - * ``` - */ -export function decodeEncodeBytesOnInstallResult(result: Hex) { - return decodeAbiParameters(FN_OUTPUTS, result)[0]; -} - -/** - * Calls the "encodeBytesOnInstall" function on the contract. - * @param options - The options for the encodeBytesOnInstall function. - * @returns The parsed result of the function call. - * @modules SequentialTokenIdERC1155 - * @example - * ```ts - * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; - * - * const result = await SequentialTokenIdERC1155.encodeBytesOnInstall({ - * contract, - * }); - * - * ``` - */ -export async function encodeBytesOnInstall(options: BaseTransactionOptions) { - return readContract({ - contract: options.contract, - method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, - params: [], - }); -} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/getModuleConfig.ts b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/getModuleConfig.ts new file mode 100644 index 00000000000..4750da4f484 --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/read/getModuleConfig.ts @@ -0,0 +1,109 @@ +import { readContract } from "../../../../../transaction/read-contract.js"; +import type { BaseTransactionOptions } from "../../../../../transaction/types.js"; + +import { decodeAbiParameters } from "viem"; +import type { Hex } from "../../../../../utils/encoding/hex.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +export const FN_SELECTOR = "0x89e04e0e" as const; +const FN_INPUTS = [] as const; +const FN_OUTPUTS = [ + { + type: "tuple", + name: "config", + components: [ + { + type: "bool", + name: "registerInstallationCallback", + }, + { + type: "bytes4[]", + name: "requiredInterfaces", + }, + { + type: "bytes4[]", + name: "supportedInterfaces", + }, + { + type: "tuple[]", + name: "callbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + ], + }, + { + type: "tuple[]", + name: "fallbackFunctions", + components: [ + { + type: "bytes4", + name: "selector", + }, + { + type: "uint256", + name: "permissionBits", + }, + ], + }, + ], + }, +] as const; + +/** + * Checks if the `getModuleConfig` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `getModuleConfig` method is supported. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * const supported = SequentialTokenIdERC1155.isGetModuleConfigSupported(["0x..."]); + * ``` + */ +export function isGetModuleConfigSupported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Decodes the result of the getModuleConfig function call. + * @param result - The hexadecimal result to decode. + * @returns The decoded result as per the FN_OUTPUTS definition. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * const result = SequentialTokenIdERC1155.decodeGetModuleConfigResultResult("..."); + * ``` + */ +export function decodeGetModuleConfigResult(result: Hex) { + return decodeAbiParameters(FN_OUTPUTS, result)[0]; +} + +/** + * Calls the "getModuleConfig" function on the contract. + * @param options - The options for the getModuleConfig function. + * @returns The parsed result of the function call. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * + * const result = await SequentialTokenIdERC1155.getModuleConfig({ + * contract, + * }); + * + * ``` + */ +export async function getModuleConfig(options: BaseTransactionOptions) { + return readContract({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: [], + }); +} diff --git a/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/write/updateTokenIdERC1155.ts b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/write/updateTokenIdERC1155.ts new file mode 100644 index 00000000000..fc93662b2fc --- /dev/null +++ b/packages/thirdweb/src/extensions/modules/__generated__/SequentialTokenIdERC1155/write/updateTokenIdERC1155.ts @@ -0,0 +1,145 @@ +import type { AbiParameterToPrimitiveType } from "abitype"; +import type { + BaseTransactionOptions, + WithOverrides, +} from "../../../../../transaction/types.js"; +import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js"; +import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js"; +import { once } from "../../../../../utils/promise/once.js"; +import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js"; + +/** + * Represents the parameters for the "updateTokenIdERC1155" function. + */ +export type UpdateTokenIdERC1155Params = WithOverrides<{ + tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_tokenId" }>; +}>; + +export const FN_SELECTOR = "0x034eb4dd" as const; +const FN_INPUTS = [ + { + type: "uint256", + name: "_tokenId", + }, +] as const; +const FN_OUTPUTS = [ + { + type: "uint256", + }, +] as const; + +/** + * Checks if the `updateTokenIdERC1155` method is supported by the given contract. + * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors. + * @returns A boolean indicating if the `updateTokenIdERC1155` method is supported. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * + * const supported = SequentialTokenIdERC1155.isUpdateTokenIdERC1155Supported(["0x..."]); + * ``` + */ +export function isUpdateTokenIdERC1155Supported(availableSelectors: string[]) { + return detectMethod({ + availableSelectors, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + }); +} + +/** + * Encodes the parameters for the "updateTokenIdERC1155" function. + * @param options - The options for the updateTokenIdERC1155 function. + * @returns The encoded ABI parameters. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * const result = SequentialTokenIdERC1155.encodeUpdateTokenIdERC1155Params({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeUpdateTokenIdERC1155Params( + options: UpdateTokenIdERC1155Params, +) { + return encodeAbiParameters(FN_INPUTS, [options.tokenId]); +} + +/** + * Encodes the "updateTokenIdERC1155" function into a Hex string with its parameters. + * @param options - The options for the updateTokenIdERC1155 function. + * @returns The encoded hexadecimal string. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * const result = SequentialTokenIdERC1155.encodeUpdateTokenIdERC1155({ + * tokenId: ..., + * }); + * ``` + */ +export function encodeUpdateTokenIdERC1155( + options: UpdateTokenIdERC1155Params, +) { + // we do a "manual" concat here to avoid the overhead of the "concatHex" function + // we can do this because we know the specific formats of the values + return (FN_SELECTOR + + encodeUpdateTokenIdERC1155Params(options).slice( + 2, + )) as `${typeof FN_SELECTOR}${string}`; +} + +/** + * Prepares a transaction to call the "updateTokenIdERC1155" function on the contract. + * @param options - The options for the "updateTokenIdERC1155" function. + * @returns A prepared transaction object. + * @modules SequentialTokenIdERC1155 + * @example + * ```ts + * import { sendTransaction } from "thirdweb"; + * import { SequentialTokenIdERC1155 } from "thirdweb/modules"; + * + * const transaction = SequentialTokenIdERC1155.updateTokenIdERC1155({ + * contract, + * tokenId: ..., + * overrides: { + * ... + * } + * }); + * + * // Send the transaction + * await sendTransaction({ transaction, account }); + * ``` + */ +export function updateTokenIdERC1155( + options: BaseTransactionOptions< + | UpdateTokenIdERC1155Params + | { + asyncParams: () => Promise; + } + >, +) { + const asyncOptions = once(async () => { + return "asyncParams" in options ? await options.asyncParams() : options; + }); + + return prepareContractCall({ + contract: options.contract, + method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const, + params: async () => { + const resolvedOptions = await asyncOptions(); + return [resolvedOptions.tokenId] as const; + }, + value: async () => (await asyncOptions()).overrides?.value, + accessList: async () => (await asyncOptions()).overrides?.accessList, + gas: async () => (await asyncOptions()).overrides?.gas, + gasPrice: async () => (await asyncOptions()).overrides?.gasPrice, + maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas, + maxPriorityFeePerGas: async () => + (await asyncOptions()).overrides?.maxPriorityFeePerGas, + nonce: async () => (await asyncOptions()).overrides?.nonce, + extraGas: async () => (await asyncOptions()).overrides?.extraGas, + erc20Value: async () => (await asyncOptions()).overrides?.erc20Value, + }); +} diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts index 9b20921068c..d6df91acef1 100644 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts +++ b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts @@ -4,8 +4,6 @@ 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 {} from "../../contract/deployment/utils/infra.js"; -import { zkDeployContract } from "../../contract/deployment/zksync/zkDeployContract.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"; @@ -18,7 +16,6 @@ import { fetchBytecodeFromCompilerMetadata, } from "../../utils/any-evm/deploy-metadata.js"; import type { FetchDeployMetadataResult } from "../../utils/any-evm/deploy-metadata.js"; -import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js"; import type { Hex } from "../../utils/encoding/hex.js"; import type { Account } from "../../wallets/interfaces/wallet.js"; import { getAllDefaultConstructorParamsForImplementation } from "./get-required-transactions.js"; @@ -263,22 +260,6 @@ async function directDeploy(options: { const { account, client, chain, compilerMetadata, contractParams, salt } = options; - if (await isZkSyncChain(chain)) { - return zkDeployContract({ - account, - client, - chain, - bytecode: await fetchBytecodeFromCompilerMetadata({ - compilerMetadata, - client, - chain, - }), - abi: compilerMetadata.abi, - params: contractParams, - salt, - }); - } - const { deployContract } = await import( "../../contract/deployment/deploy-with-abi.js" ); diff --git a/packages/thirdweb/test/vitest.config.ts b/packages/thirdweb/test/vitest.config.ts index 8bc39cabaf8..88039e97328 100644 --- a/packages/thirdweb/test/vitest.config.ts +++ b/packages/thirdweb/test/vitest.config.ts @@ -37,7 +37,8 @@ export default defineConfig({ setupFiles: [join(__dirname, "./reactSetup.ts")], globalSetup: [join(__dirname, "./globalSetup.ts")], testTimeout: 90_000, - retry: 0, + retry: 3, + maxConcurrency: 3, bail: 1, // clear any mocks between any tests clearMocks: true,