thirdweb 5.59.2 → 5.60.0-nightly-8b681729a105bf0ba13be166937bae7914813a2e-20240930000338

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/cjs/exports/deploys.js +3 -1
  2. package/dist/cjs/exports/deploys.js.map +1 -1
  3. package/dist/cjs/exports/extensions/pack.js +24 -0
  4. package/dist/cjs/exports/extensions/pack.js.map +1 -0
  5. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackCreated.js +31 -0
  6. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackCreated.js.map +1 -0
  7. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackOpened.js +32 -0
  8. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackOpened.js.map +1 -0
  9. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackUpdated.js +31 -0
  10. package/dist/cjs/extensions/pack/__generated__/IPack/events/PackUpdated.js.map +1 -0
  11. package/dist/cjs/extensions/pack/__generated__/IPack/read/canUpdatePack.js +114 -0
  12. package/dist/cjs/extensions/pack/__generated__/IPack/read/canUpdatePack.js.map +1 -0
  13. package/dist/cjs/extensions/pack/__generated__/IPack/read/getPackContents.js +137 -0
  14. package/dist/cjs/extensions/pack/__generated__/IPack/read/getPackContents.js.map +1 -0
  15. package/dist/cjs/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.js +114 -0
  16. package/dist/cjs/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.js.map +1 -0
  17. package/dist/cjs/extensions/pack/__generated__/IPack/read/getTokenOfBundle.js +139 -0
  18. package/dist/cjs/extensions/pack/__generated__/IPack/read/getTokenOfBundle.js.map +1 -0
  19. package/dist/cjs/extensions/pack/__generated__/IPack/read/getUriOfBundle.js +114 -0
  20. package/dist/cjs/extensions/pack/__generated__/IPack/read/getUriOfBundle.js.map +1 -0
  21. package/dist/cjs/extensions/pack/__generated__/IPack/write/addPackContents.js +175 -0
  22. package/dist/cjs/extensions/pack/__generated__/IPack/write/addPackContents.js.map +1 -0
  23. package/dist/cjs/extensions/pack/__generated__/IPack/write/createPack.js +193 -0
  24. package/dist/cjs/extensions/pack/__generated__/IPack/write/createPack.js.map +1 -0
  25. package/dist/cjs/extensions/pack/__generated__/IPack/write/openPack.js +146 -0
  26. package/dist/cjs/extensions/pack/__generated__/IPack/write/openPack.js.map +1 -0
  27. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.js +32 -0
  28. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.js.map +1 -0
  29. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.js +32 -0
  30. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.js.map +1 -0
  31. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.js +114 -0
  32. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.js.map +1 -0
  33. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.js +74 -0
  34. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.js.map +1 -0
  35. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.js +143 -0
  36. package/dist/cjs/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.js.map +1 -0
  37. package/dist/cjs/extensions/pack/createNewPack.js +285 -0
  38. package/dist/cjs/extensions/pack/createNewPack.js.map +1 -0
  39. package/dist/cjs/extensions/prebuilts/__generated__/Pack/write/initialize.js +175 -0
  40. package/dist/cjs/extensions/prebuilts/__generated__/Pack/write/initialize.js.map +1 -0
  41. package/dist/cjs/extensions/prebuilts/deploy-pack.js +115 -0
  42. package/dist/cjs/extensions/prebuilts/deploy-pack.js.map +1 -0
  43. package/dist/cjs/rpc/watchBlockNumber.js +2 -8
  44. package/dist/cjs/rpc/watchBlockNumber.js.map +1 -1
  45. package/dist/cjs/utils/sleep.js +12 -0
  46. package/dist/cjs/utils/sleep.js.map +1 -0
  47. package/dist/cjs/version.js +1 -1
  48. package/dist/cjs/version.js.map +1 -1
  49. package/dist/cjs/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.js +4 -8
  50. package/dist/cjs/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.js.map +1 -1
  51. package/dist/esm/exports/deploys.js +1 -0
  52. package/dist/esm/exports/deploys.js.map +1 -1
  53. package/dist/esm/exports/extensions/pack.js +12 -0
  54. package/dist/esm/exports/extensions/pack.js.map +1 -0
  55. package/dist/esm/extensions/pack/__generated__/IPack/events/PackCreated.js +28 -0
  56. package/dist/esm/extensions/pack/__generated__/IPack/events/PackCreated.js.map +1 -0
  57. package/dist/esm/extensions/pack/__generated__/IPack/events/PackOpened.js +29 -0
  58. package/dist/esm/extensions/pack/__generated__/IPack/events/PackOpened.js.map +1 -0
  59. package/dist/esm/extensions/pack/__generated__/IPack/events/PackUpdated.js +28 -0
  60. package/dist/esm/extensions/pack/__generated__/IPack/events/PackUpdated.js.map +1 -0
  61. package/dist/esm/extensions/pack/__generated__/IPack/read/canUpdatePack.js +106 -0
  62. package/dist/esm/extensions/pack/__generated__/IPack/read/canUpdatePack.js.map +1 -0
  63. package/dist/esm/extensions/pack/__generated__/IPack/read/getPackContents.js +129 -0
  64. package/dist/esm/extensions/pack/__generated__/IPack/read/getPackContents.js.map +1 -0
  65. package/dist/esm/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.js +106 -0
  66. package/dist/esm/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.js.map +1 -0
  67. package/dist/esm/extensions/pack/__generated__/IPack/read/getTokenOfBundle.js +131 -0
  68. package/dist/esm/extensions/pack/__generated__/IPack/read/getTokenOfBundle.js.map +1 -0
  69. package/dist/esm/extensions/pack/__generated__/IPack/read/getUriOfBundle.js +106 -0
  70. package/dist/esm/extensions/pack/__generated__/IPack/read/getUriOfBundle.js.map +1 -0
  71. package/dist/esm/extensions/pack/__generated__/IPack/write/addPackContents.js +168 -0
  72. package/dist/esm/extensions/pack/__generated__/IPack/write/addPackContents.js.map +1 -0
  73. package/dist/esm/extensions/pack/__generated__/IPack/write/createPack.js +186 -0
  74. package/dist/esm/extensions/pack/__generated__/IPack/write/createPack.js.map +1 -0
  75. package/dist/esm/extensions/pack/__generated__/IPack/write/openPack.js +139 -0
  76. package/dist/esm/extensions/pack/__generated__/IPack/write/openPack.js.map +1 -0
  77. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.js +29 -0
  78. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.js.map +1 -0
  79. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.js +29 -0
  80. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.js.map +1 -0
  81. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.js +106 -0
  82. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.js.map +1 -0
  83. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.js +69 -0
  84. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.js.map +1 -0
  85. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.js +136 -0
  86. package/dist/esm/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.js.map +1 -0
  87. package/dist/esm/extensions/pack/createNewPack.js +281 -0
  88. package/dist/esm/extensions/pack/createNewPack.js.map +1 -0
  89. package/dist/esm/extensions/prebuilts/__generated__/Pack/write/initialize.js +168 -0
  90. package/dist/esm/extensions/prebuilts/__generated__/Pack/write/initialize.js.map +1 -0
  91. package/dist/esm/extensions/prebuilts/deploy-pack.js +112 -0
  92. package/dist/esm/extensions/prebuilts/deploy-pack.js.map +1 -0
  93. package/dist/esm/rpc/watchBlockNumber.js +1 -7
  94. package/dist/esm/rpc/watchBlockNumber.js.map +1 -1
  95. package/dist/esm/utils/sleep.js +9 -0
  96. package/dist/esm/utils/sleep.js.map +1 -0
  97. package/dist/esm/version.js +1 -1
  98. package/dist/esm/version.js.map +1 -1
  99. package/dist/esm/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.js +4 -8
  100. package/dist/esm/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.js.map +1 -1
  101. package/dist/types/exports/deploys.d.ts +1 -0
  102. package/dist/types/exports/deploys.d.ts.map +1 -1
  103. package/dist/types/exports/extensions/pack.d.ts +9 -0
  104. package/dist/types/exports/extensions/pack.d.ts.map +1 -0
  105. package/dist/types/extensions/pack/__generated__/IPack/events/PackCreated.d.ts +47 -0
  106. package/dist/types/extensions/pack/__generated__/IPack/events/PackCreated.d.ts.map +1 -0
  107. package/dist/types/extensions/pack/__generated__/IPack/events/PackOpened.d.ts +70 -0
  108. package/dist/types/extensions/pack/__generated__/IPack/events/PackOpened.d.ts.map +1 -0
  109. package/dist/types/extensions/pack/__generated__/IPack/events/PackUpdated.d.ts +47 -0
  110. package/dist/types/extensions/pack/__generated__/IPack/events/PackUpdated.d.ts.map +1 -0
  111. package/dist/types/extensions/pack/__generated__/IPack/read/canUpdatePack.d.ts +83 -0
  112. package/dist/types/extensions/pack/__generated__/IPack/read/canUpdatePack.d.ts.map +1 -0
  113. package/dist/types/extensions/pack/__generated__/IPack/read/getPackContents.d.ts +93 -0
  114. package/dist/types/extensions/pack/__generated__/IPack/read/getPackContents.d.ts.map +1 -0
  115. package/dist/types/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.d.ts +83 -0
  116. package/dist/types/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.d.ts.map +1 -0
  117. package/dist/types/extensions/pack/__generated__/IPack/read/getTokenOfBundle.d.ts +100 -0
  118. package/dist/types/extensions/pack/__generated__/IPack/read/getTokenOfBundle.d.ts.map +1 -0
  119. package/dist/types/extensions/pack/__generated__/IPack/read/getUriOfBundle.d.ts +83 -0
  120. package/dist/types/extensions/pack/__generated__/IPack/read/getUriOfBundle.d.ts.map +1 -0
  121. package/dist/types/extensions/pack/__generated__/IPack/write/addPackContents.d.ts +118 -0
  122. package/dist/types/extensions/pack/__generated__/IPack/write/addPackContents.d.ts.map +1 -0
  123. package/dist/types/extensions/pack/__generated__/IPack/write/createPack.d.ts +132 -0
  124. package/dist/types/extensions/pack/__generated__/IPack/write/createPack.d.ts.map +1 -0
  125. package/dist/types/extensions/pack/__generated__/IPack/write/openPack.d.ts +86 -0
  126. package/dist/types/extensions/pack/__generated__/IPack/write/openPack.d.ts.map +1 -0
  127. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.d.ts +57 -0
  128. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.d.ts.map +1 -0
  129. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.d.ts +51 -0
  130. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.d.ts.map +1 -0
  131. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.d.ts +83 -0
  132. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.d.ts.map +1 -0
  133. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.d.ts +33 -0
  134. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.d.ts.map +1 -0
  135. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.d.ts +93 -0
  136. package/dist/types/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.d.ts.map +1 -0
  137. package/dist/types/extensions/pack/createNewPack.d.ts +104 -0
  138. package/dist/types/extensions/pack/createNewPack.d.ts.map +1 -0
  139. package/dist/types/extensions/prebuilts/__generated__/Pack/write/initialize.d.ts +121 -0
  140. package/dist/types/extensions/prebuilts/__generated__/Pack/write/initialize.d.ts.map +1 -0
  141. package/dist/types/extensions/prebuilts/deploy-pack.d.ts +62 -0
  142. package/dist/types/extensions/prebuilts/deploy-pack.d.ts.map +1 -0
  143. package/dist/types/rpc/watchBlockNumber.d.ts.map +1 -1
  144. package/dist/types/utils/sleep.d.ts +7 -0
  145. package/dist/types/utils/sleep.d.ts.map +1 -0
  146. package/dist/types/version.d.ts +1 -1
  147. package/dist/types/version.d.ts.map +1 -1
  148. package/dist/types/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.d.ts.map +1 -1
  149. package/package.json +1 -1
  150. package/src/exports/deploys.ts +6 -0
  151. package/src/exports/extensions/pack.ts +42 -0
  152. package/src/extensions/erc1155/drops/read/getActiveClaimCondition.test.ts +6 -4
  153. package/src/extensions/erc721/drops/write/updateMetadata.test.ts +2 -2
  154. package/src/extensions/erc721/read/getTotalClaimedSupply.test.ts +2 -2
  155. package/src/extensions/erc721/read/getTotalUnclaimedSupply.test.ts +2 -2
  156. package/src/extensions/erc721/write/updateTokenURI.test.ts +2 -2
  157. package/src/extensions/pack/__generated__/IPack/events/PackCreated.ts +41 -0
  158. package/src/extensions/pack/__generated__/IPack/events/PackOpened.ts +47 -0
  159. package/src/extensions/pack/__generated__/IPack/events/PackUpdated.ts +41 -0
  160. package/src/extensions/pack/__generated__/IPack/read/canUpdatePack.ts +125 -0
  161. package/src/extensions/pack/__generated__/IPack/read/getPackContents.ts +148 -0
  162. package/src/extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.ts +129 -0
  163. package/src/extensions/pack/__generated__/IPack/read/getTokenOfBundle.ts +151 -0
  164. package/src/extensions/pack/__generated__/IPack/read/getUriOfBundle.ts +125 -0
  165. package/src/extensions/pack/__generated__/IPack/write/addPackContents.ts +213 -0
  166. package/src/extensions/pack/__generated__/IPack/write/createPack.ts +239 -0
  167. package/src/extensions/pack/__generated__/IPack/write/openPack.ts +168 -0
  168. package/src/extensions/pack/__generated__/IPackVRFDirect/events/PackOpenRequested.ts +49 -0
  169. package/src/extensions/pack/__generated__/IPackVRFDirect/events/PackRandomnessFulfilled.ts +49 -0
  170. package/src/extensions/pack/__generated__/IPackVRFDirect/read/canClaimRewards.ts +125 -0
  171. package/src/extensions/pack/__generated__/IPackVRFDirect/write/claimRewards.ts +73 -0
  172. package/src/extensions/pack/__generated__/IPackVRFDirect/write/openPackAndClaimRewards.ts +177 -0
  173. package/src/extensions/pack/createNewPack.test.ts +207 -0
  174. package/src/extensions/pack/createNewPack.ts +433 -0
  175. package/src/extensions/prebuilts/__generated__/Pack/write/initialize.ts +216 -0
  176. package/src/extensions/prebuilts/deploy-erc20.test.ts +5 -3
  177. package/src/extensions/prebuilts/deploy-erc721.test.ts +6 -4
  178. package/src/extensions/prebuilts/deploy-pack.test.ts +23 -0
  179. package/src/extensions/prebuilts/deploy-pack.ts +173 -0
  180. package/src/extensions/prebuilts/deploy-split.test.ts +2 -2
  181. package/src/extensions/prebuilts/deploy-vote.test.ts +7 -5
  182. package/src/extensions/split/read/getAllRecipientsAddresses.test.ts +2 -2
  183. package/src/extensions/split/read/getAllRecipientsPercentages.test.ts +2 -2
  184. package/src/extensions/split/read/getRecipientSplitPercentage.test.ts +4 -2
  185. package/src/extensions/vote/read/proposalExists.test.ts +6 -6
  186. package/src/rpc/watchBlockNumber.ts +1 -8
  187. package/src/utils/sleep.ts +8 -0
  188. package/src/version.ts +1 -1
  189. package/src/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.ts +5 -9
  190. package/src/wallets/smart/smart-wallet-integration-v07.test.ts +11 -8
  191. package/src/wallets/utils/getTokenBalance.test.ts +8 -6
@@ -0,0 +1,125 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import { readContract } from "../../../../../transaction/read-contract.js";
3
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
4
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
5
+ import { decodeAbiParameters } from "viem";
6
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
7
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
8
+
9
+ /**
10
+ * Represents the parameters for the "getUriOfBundle" function.
11
+ */
12
+ export type GetUriOfBundleParams = {
13
+ bundleId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_bundleId" }>;
14
+ };
15
+
16
+ export const FN_SELECTOR = "0x61195e94" as const;
17
+ const FN_INPUTS = [
18
+ {
19
+ type: "uint256",
20
+ name: "_bundleId",
21
+ },
22
+ ] as const;
23
+ const FN_OUTPUTS = [
24
+ {
25
+ type: "string",
26
+ },
27
+ ] as const;
28
+
29
+ /**
30
+ * Checks if the `getUriOfBundle` method is supported by the given contract.
31
+ * @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.
32
+ * @returns A boolean indicating if the `getUriOfBundle` method is supported.
33
+ * @extension PACK
34
+ * @example
35
+ * ```ts
36
+ * import { isGetUriOfBundleSupported } from "thirdweb/extensions/pack";
37
+ * const supported = isGetUriOfBundleSupported(["0x..."]);
38
+ * ```
39
+ */
40
+ export function isGetUriOfBundleSupported(availableSelectors: string[]) {
41
+ return detectMethod({
42
+ availableSelectors,
43
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Encodes the parameters for the "getUriOfBundle" function.
49
+ * @param options - The options for the getUriOfBundle function.
50
+ * @returns The encoded ABI parameters.
51
+ * @extension PACK
52
+ * @example
53
+ * ```ts
54
+ * import { encodeGetUriOfBundleParams } from "thirdweb/extensions/pack";
55
+ * const result = encodeGetUriOfBundleParams({
56
+ * bundleId: ...,
57
+ * });
58
+ * ```
59
+ */
60
+ export function encodeGetUriOfBundleParams(options: GetUriOfBundleParams) {
61
+ return encodeAbiParameters(FN_INPUTS, [options.bundleId]);
62
+ }
63
+
64
+ /**
65
+ * Encodes the "getUriOfBundle" function into a Hex string with its parameters.
66
+ * @param options - The options for the getUriOfBundle function.
67
+ * @returns The encoded hexadecimal string.
68
+ * @extension PACK
69
+ * @example
70
+ * ```ts
71
+ * import { encodeGetUriOfBundle } from "thirdweb/extensions/pack";
72
+ * const result = encodeGetUriOfBundle({
73
+ * bundleId: ...,
74
+ * });
75
+ * ```
76
+ */
77
+ export function encodeGetUriOfBundle(options: GetUriOfBundleParams) {
78
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
79
+ // we can do this because we know the specific formats of the values
80
+ return (FN_SELECTOR +
81
+ encodeGetUriOfBundleParams(options).slice(
82
+ 2,
83
+ )) as `${typeof FN_SELECTOR}${string}`;
84
+ }
85
+
86
+ /**
87
+ * Decodes the result of the getUriOfBundle function call.
88
+ * @param result - The hexadecimal result to decode.
89
+ * @returns The decoded result as per the FN_OUTPUTS definition.
90
+ * @extension PACK
91
+ * @example
92
+ * ```ts
93
+ * import { decodeGetUriOfBundleResult } from "thirdweb/extensions/pack";
94
+ * const result = decodeGetUriOfBundleResultResult("...");
95
+ * ```
96
+ */
97
+ export function decodeGetUriOfBundleResult(result: Hex) {
98
+ return decodeAbiParameters(FN_OUTPUTS, result)[0];
99
+ }
100
+
101
+ /**
102
+ * Calls the "getUriOfBundle" function on the contract.
103
+ * @param options - The options for the getUriOfBundle function.
104
+ * @returns The parsed result of the function call.
105
+ * @extension PACK
106
+ * @example
107
+ * ```ts
108
+ * import { getUriOfBundle } from "thirdweb/extensions/pack";
109
+ *
110
+ * const result = await getUriOfBundle({
111
+ * contract,
112
+ * bundleId: ...,
113
+ * });
114
+ *
115
+ * ```
116
+ */
117
+ export async function getUriOfBundle(
118
+ options: BaseTransactionOptions<GetUriOfBundleParams>,
119
+ ) {
120
+ return readContract({
121
+ contract: options.contract,
122
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
123
+ params: [options.bundleId],
124
+ });
125
+ }
@@ -0,0 +1,213 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import type {
3
+ BaseTransactionOptions,
4
+ WithOverrides,
5
+ } from "../../../../../transaction/types.js";
6
+ import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
7
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
8
+ import { once } from "../../../../../utils/promise/once.js";
9
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
10
+
11
+ /**
12
+ * Represents the parameters for the "addPackContents" function.
13
+ */
14
+ export type AddPackContentsParams = WithOverrides<{
15
+ packId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_packId" }>;
16
+ contents: AbiParameterToPrimitiveType<{
17
+ type: "tuple[]";
18
+ name: "_contents";
19
+ components: [
20
+ { type: "address"; name: "assetContract" },
21
+ { type: "uint8"; name: "tokenType" },
22
+ { type: "uint256"; name: "tokenId" },
23
+ { type: "uint256"; name: "totalAmount" },
24
+ ];
25
+ }>;
26
+ numOfRewardUnits: AbiParameterToPrimitiveType<{
27
+ type: "uint256[]";
28
+ name: "_numOfRewardUnits";
29
+ }>;
30
+ recipient: AbiParameterToPrimitiveType<{
31
+ type: "address";
32
+ name: "_recipient";
33
+ }>;
34
+ }>;
35
+
36
+ export const FN_SELECTOR = "0xa96b1438" as const;
37
+ const FN_INPUTS = [
38
+ {
39
+ type: "uint256",
40
+ name: "_packId",
41
+ },
42
+ {
43
+ type: "tuple[]",
44
+ name: "_contents",
45
+ components: [
46
+ {
47
+ type: "address",
48
+ name: "assetContract",
49
+ },
50
+ {
51
+ type: "uint8",
52
+ name: "tokenType",
53
+ },
54
+ {
55
+ type: "uint256",
56
+ name: "tokenId",
57
+ },
58
+ {
59
+ type: "uint256",
60
+ name: "totalAmount",
61
+ },
62
+ ],
63
+ },
64
+ {
65
+ type: "uint256[]",
66
+ name: "_numOfRewardUnits",
67
+ },
68
+ {
69
+ type: "address",
70
+ name: "_recipient",
71
+ },
72
+ ] as const;
73
+ const FN_OUTPUTS = [
74
+ {
75
+ type: "uint256",
76
+ name: "packTotalSupply",
77
+ },
78
+ {
79
+ type: "uint256",
80
+ name: "newSupplyAdded",
81
+ },
82
+ ] as const;
83
+
84
+ /**
85
+ * Checks if the `addPackContents` method is supported by the given contract.
86
+ * @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.
87
+ * @returns A boolean indicating if the `addPackContents` method is supported.
88
+ * @extension PACK
89
+ * @example
90
+ * ```ts
91
+ * import { isAddPackContentsSupported } from "thirdweb/extensions/pack";
92
+ *
93
+ * const supported = isAddPackContentsSupported(["0x..."]);
94
+ * ```
95
+ */
96
+ export function isAddPackContentsSupported(availableSelectors: string[]) {
97
+ return detectMethod({
98
+ availableSelectors,
99
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Encodes the parameters for the "addPackContents" function.
105
+ * @param options - The options for the addPackContents function.
106
+ * @returns The encoded ABI parameters.
107
+ * @extension PACK
108
+ * @example
109
+ * ```ts
110
+ * import { encodeAddPackContentsParams } from "thirdweb/extensions/pack";
111
+ * const result = encodeAddPackContentsParams({
112
+ * packId: ...,
113
+ * contents: ...,
114
+ * numOfRewardUnits: ...,
115
+ * recipient: ...,
116
+ * });
117
+ * ```
118
+ */
119
+ export function encodeAddPackContentsParams(options: AddPackContentsParams) {
120
+ return encodeAbiParameters(FN_INPUTS, [
121
+ options.packId,
122
+ options.contents,
123
+ options.numOfRewardUnits,
124
+ options.recipient,
125
+ ]);
126
+ }
127
+
128
+ /**
129
+ * Encodes the "addPackContents" function into a Hex string with its parameters.
130
+ * @param options - The options for the addPackContents function.
131
+ * @returns The encoded hexadecimal string.
132
+ * @extension PACK
133
+ * @example
134
+ * ```ts
135
+ * import { encodeAddPackContents } from "thirdweb/extensions/pack";
136
+ * const result = encodeAddPackContents({
137
+ * packId: ...,
138
+ * contents: ...,
139
+ * numOfRewardUnits: ...,
140
+ * recipient: ...,
141
+ * });
142
+ * ```
143
+ */
144
+ export function encodeAddPackContents(options: AddPackContentsParams) {
145
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
146
+ // we can do this because we know the specific formats of the values
147
+ return (FN_SELECTOR +
148
+ encodeAddPackContentsParams(options).slice(
149
+ 2,
150
+ )) as `${typeof FN_SELECTOR}${string}`;
151
+ }
152
+
153
+ /**
154
+ * Prepares a transaction to call the "addPackContents" function on the contract.
155
+ * @param options - The options for the "addPackContents" function.
156
+ * @returns A prepared transaction object.
157
+ * @extension PACK
158
+ * @example
159
+ * ```ts
160
+ * import { sendTransaction } from "thirdweb";
161
+ * import { addPackContents } from "thirdweb/extensions/pack";
162
+ *
163
+ * const transaction = addPackContents({
164
+ * contract,
165
+ * packId: ...,
166
+ * contents: ...,
167
+ * numOfRewardUnits: ...,
168
+ * recipient: ...,
169
+ * overrides: {
170
+ * ...
171
+ * }
172
+ * });
173
+ *
174
+ * // Send the transaction
175
+ * await sendTransaction({ transaction, account });
176
+ * ```
177
+ */
178
+ export function addPackContents(
179
+ options: BaseTransactionOptions<
180
+ | AddPackContentsParams
181
+ | {
182
+ asyncParams: () => Promise<AddPackContentsParams>;
183
+ }
184
+ >,
185
+ ) {
186
+ const asyncOptions = once(async () => {
187
+ return "asyncParams" in options ? await options.asyncParams() : options;
188
+ });
189
+
190
+ return prepareContractCall({
191
+ contract: options.contract,
192
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
193
+ params: async () => {
194
+ const resolvedOptions = await asyncOptions();
195
+ return [
196
+ resolvedOptions.packId,
197
+ resolvedOptions.contents,
198
+ resolvedOptions.numOfRewardUnits,
199
+ resolvedOptions.recipient,
200
+ ] as const;
201
+ },
202
+ value: async () => (await asyncOptions()).overrides?.value,
203
+ accessList: async () => (await asyncOptions()).overrides?.accessList,
204
+ gas: async () => (await asyncOptions()).overrides?.gas,
205
+ gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
206
+ maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
207
+ maxPriorityFeePerGas: async () =>
208
+ (await asyncOptions()).overrides?.maxPriorityFeePerGas,
209
+ nonce: async () => (await asyncOptions()).overrides?.nonce,
210
+ extraGas: async () => (await asyncOptions()).overrides?.extraGas,
211
+ erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
212
+ });
213
+ }
@@ -0,0 +1,239 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import type {
3
+ BaseTransactionOptions,
4
+ WithOverrides,
5
+ } from "../../../../../transaction/types.js";
6
+ import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
7
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
8
+ import { once } from "../../../../../utils/promise/once.js";
9
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
10
+
11
+ /**
12
+ * Represents the parameters for the "createPack" function.
13
+ */
14
+ export type CreatePackParams = WithOverrides<{
15
+ contents: AbiParameterToPrimitiveType<{
16
+ type: "tuple[]";
17
+ name: "contents";
18
+ components: [
19
+ { type: "address"; name: "assetContract" },
20
+ { type: "uint8"; name: "tokenType" },
21
+ { type: "uint256"; name: "tokenId" },
22
+ { type: "uint256"; name: "totalAmount" },
23
+ ];
24
+ }>;
25
+ numOfRewardUnits: AbiParameterToPrimitiveType<{
26
+ type: "uint256[]";
27
+ name: "numOfRewardUnits";
28
+ }>;
29
+ packUri: AbiParameterToPrimitiveType<{ type: "string"; name: "packUri" }>;
30
+ openStartTimestamp: AbiParameterToPrimitiveType<{
31
+ type: "uint128";
32
+ name: "openStartTimestamp";
33
+ }>;
34
+ amountDistributedPerOpen: AbiParameterToPrimitiveType<{
35
+ type: "uint128";
36
+ name: "amountDistributedPerOpen";
37
+ }>;
38
+ recipient: AbiParameterToPrimitiveType<{
39
+ type: "address";
40
+ name: "recipient";
41
+ }>;
42
+ }>;
43
+
44
+ export const FN_SELECTOR = "0x092e6075" as const;
45
+ const FN_INPUTS = [
46
+ {
47
+ type: "tuple[]",
48
+ name: "contents",
49
+ components: [
50
+ {
51
+ type: "address",
52
+ name: "assetContract",
53
+ },
54
+ {
55
+ type: "uint8",
56
+ name: "tokenType",
57
+ },
58
+ {
59
+ type: "uint256",
60
+ name: "tokenId",
61
+ },
62
+ {
63
+ type: "uint256",
64
+ name: "totalAmount",
65
+ },
66
+ ],
67
+ },
68
+ {
69
+ type: "uint256[]",
70
+ name: "numOfRewardUnits",
71
+ },
72
+ {
73
+ type: "string",
74
+ name: "packUri",
75
+ },
76
+ {
77
+ type: "uint128",
78
+ name: "openStartTimestamp",
79
+ },
80
+ {
81
+ type: "uint128",
82
+ name: "amountDistributedPerOpen",
83
+ },
84
+ {
85
+ type: "address",
86
+ name: "recipient",
87
+ },
88
+ ] as const;
89
+ const FN_OUTPUTS = [
90
+ {
91
+ type: "uint256",
92
+ name: "packId",
93
+ },
94
+ {
95
+ type: "uint256",
96
+ name: "packTotalSupply",
97
+ },
98
+ ] as const;
99
+
100
+ /**
101
+ * Checks if the `createPack` method is supported by the given contract.
102
+ * @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.
103
+ * @returns A boolean indicating if the `createPack` method is supported.
104
+ * @extension PACK
105
+ * @example
106
+ * ```ts
107
+ * import { isCreatePackSupported } from "thirdweb/extensions/pack";
108
+ *
109
+ * const supported = isCreatePackSupported(["0x..."]);
110
+ * ```
111
+ */
112
+ export function isCreatePackSupported(availableSelectors: string[]) {
113
+ return detectMethod({
114
+ availableSelectors,
115
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
116
+ });
117
+ }
118
+
119
+ /**
120
+ * Encodes the parameters for the "createPack" function.
121
+ * @param options - The options for the createPack function.
122
+ * @returns The encoded ABI parameters.
123
+ * @extension PACK
124
+ * @example
125
+ * ```ts
126
+ * import { encodeCreatePackParams } from "thirdweb/extensions/pack";
127
+ * const result = encodeCreatePackParams({
128
+ * contents: ...,
129
+ * numOfRewardUnits: ...,
130
+ * packUri: ...,
131
+ * openStartTimestamp: ...,
132
+ * amountDistributedPerOpen: ...,
133
+ * recipient: ...,
134
+ * });
135
+ * ```
136
+ */
137
+ export function encodeCreatePackParams(options: CreatePackParams) {
138
+ return encodeAbiParameters(FN_INPUTS, [
139
+ options.contents,
140
+ options.numOfRewardUnits,
141
+ options.packUri,
142
+ options.openStartTimestamp,
143
+ options.amountDistributedPerOpen,
144
+ options.recipient,
145
+ ]);
146
+ }
147
+
148
+ /**
149
+ * Encodes the "createPack" function into a Hex string with its parameters.
150
+ * @param options - The options for the createPack function.
151
+ * @returns The encoded hexadecimal string.
152
+ * @extension PACK
153
+ * @example
154
+ * ```ts
155
+ * import { encodeCreatePack } from "thirdweb/extensions/pack";
156
+ * const result = encodeCreatePack({
157
+ * contents: ...,
158
+ * numOfRewardUnits: ...,
159
+ * packUri: ...,
160
+ * openStartTimestamp: ...,
161
+ * amountDistributedPerOpen: ...,
162
+ * recipient: ...,
163
+ * });
164
+ * ```
165
+ */
166
+ export function encodeCreatePack(options: CreatePackParams) {
167
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
168
+ // we can do this because we know the specific formats of the values
169
+ return (FN_SELECTOR +
170
+ encodeCreatePackParams(options).slice(
171
+ 2,
172
+ )) as `${typeof FN_SELECTOR}${string}`;
173
+ }
174
+
175
+ /**
176
+ * Prepares a transaction to call the "createPack" function on the contract.
177
+ * @param options - The options for the "createPack" function.
178
+ * @returns A prepared transaction object.
179
+ * @extension PACK
180
+ * @example
181
+ * ```ts
182
+ * import { sendTransaction } from "thirdweb";
183
+ * import { createPack } from "thirdweb/extensions/pack";
184
+ *
185
+ * const transaction = createPack({
186
+ * contract,
187
+ * contents: ...,
188
+ * numOfRewardUnits: ...,
189
+ * packUri: ...,
190
+ * openStartTimestamp: ...,
191
+ * amountDistributedPerOpen: ...,
192
+ * recipient: ...,
193
+ * overrides: {
194
+ * ...
195
+ * }
196
+ * });
197
+ *
198
+ * // Send the transaction
199
+ * await sendTransaction({ transaction, account });
200
+ * ```
201
+ */
202
+ export function createPack(
203
+ options: BaseTransactionOptions<
204
+ | CreatePackParams
205
+ | {
206
+ asyncParams: () => Promise<CreatePackParams>;
207
+ }
208
+ >,
209
+ ) {
210
+ const asyncOptions = once(async () => {
211
+ return "asyncParams" in options ? await options.asyncParams() : options;
212
+ });
213
+
214
+ return prepareContractCall({
215
+ contract: options.contract,
216
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
217
+ params: async () => {
218
+ const resolvedOptions = await asyncOptions();
219
+ return [
220
+ resolvedOptions.contents,
221
+ resolvedOptions.numOfRewardUnits,
222
+ resolvedOptions.packUri,
223
+ resolvedOptions.openStartTimestamp,
224
+ resolvedOptions.amountDistributedPerOpen,
225
+ resolvedOptions.recipient,
226
+ ] as const;
227
+ },
228
+ value: async () => (await asyncOptions()).overrides?.value,
229
+ accessList: async () => (await asyncOptions()).overrides?.accessList,
230
+ gas: async () => (await asyncOptions()).overrides?.gas,
231
+ gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
232
+ maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
233
+ maxPriorityFeePerGas: async () =>
234
+ (await asyncOptions()).overrides?.maxPriorityFeePerGas,
235
+ nonce: async () => (await asyncOptions()).overrides?.nonce,
236
+ extraGas: async () => (await asyncOptions()).overrides?.extraGas,
237
+ erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
238
+ });
239
+ }