thirdweb 5.64.4-nightly-c2a90542d7f870c799c297c59cd2b468816f7939-20241031000332 → 5.64.5

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 (143) hide show
  1. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js +31 -0
  2. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js.map +1 -0
  3. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js +33 -0
  4. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js.map +1 -0
  5. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js +149 -0
  6. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js.map +1 -0
  7. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js +193 -0
  8. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js.map +1 -0
  9. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js +173 -0
  10. package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js.map +1 -0
  11. package/dist/cjs/extensions/erc1155/drops/write/claimTo.js +5 -2
  12. package/dist/cjs/extensions/erc1155/drops/write/claimTo.js.map +1 -1
  13. package/dist/cjs/extensions/erc1155/drops/write/setClaimConditions.js +4 -1
  14. package/dist/cjs/extensions/erc1155/drops/write/setClaimConditions.js.map +1 -1
  15. package/dist/cjs/extensions/erc20/drops/write/claimTo.js +1 -0
  16. package/dist/cjs/extensions/erc20/drops/write/claimTo.js.map +1 -1
  17. package/dist/cjs/extensions/erc20/drops/write/setClaimConditions.js +1 -0
  18. package/dist/cjs/extensions/erc20/drops/write/setClaimConditions.js.map +1 -1
  19. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js +27 -0
  20. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js.map +1 -0
  21. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js +33 -0
  22. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js.map +1 -0
  23. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js +105 -0
  24. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js.map +1 -0
  25. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js +184 -0
  26. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js.map +1 -0
  27. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js +164 -0
  28. package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js.map +1 -0
  29. package/dist/cjs/extensions/erc721/drops/write/claimTo.js +6 -3
  30. package/dist/cjs/extensions/erc721/drops/write/claimTo.js.map +1 -1
  31. package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js +4 -1
  32. package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
  33. package/dist/cjs/utils/extensions/drops/get-claim-params.js +20 -0
  34. package/dist/cjs/utils/extensions/drops/get-claim-params.js.map +1 -1
  35. package/dist/cjs/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js +39 -12
  36. package/dist/cjs/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js.map +1 -1
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/cjs/version.js.map +1 -1
  39. package/dist/cjs/wallets/smart/index.js +3 -0
  40. package/dist/cjs/wallets/smart/index.js.map +1 -1
  41. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js +28 -0
  42. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js.map +1 -0
  43. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js +30 -0
  44. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js.map +1 -0
  45. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js +141 -0
  46. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js.map +1 -0
  47. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js +186 -0
  48. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js.map +1 -0
  49. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js +166 -0
  50. package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js.map +1 -0
  51. package/dist/esm/extensions/erc1155/drops/write/claimTo.js +5 -2
  52. package/dist/esm/extensions/erc1155/drops/write/claimTo.js.map +1 -1
  53. package/dist/esm/extensions/erc1155/drops/write/setClaimConditions.js +4 -1
  54. package/dist/esm/extensions/erc1155/drops/write/setClaimConditions.js.map +1 -1
  55. package/dist/esm/extensions/erc20/drops/write/claimTo.js +1 -0
  56. package/dist/esm/extensions/erc20/drops/write/claimTo.js.map +1 -1
  57. package/dist/esm/extensions/erc20/drops/write/setClaimConditions.js +1 -0
  58. package/dist/esm/extensions/erc20/drops/write/setClaimConditions.js.map +1 -1
  59. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js +24 -0
  60. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js.map +1 -0
  61. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js +30 -0
  62. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js.map +1 -0
  63. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js +99 -0
  64. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js.map +1 -0
  65. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js +177 -0
  66. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js.map +1 -0
  67. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js +157 -0
  68. package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js.map +1 -0
  69. package/dist/esm/extensions/erc721/drops/write/claimTo.js +6 -3
  70. package/dist/esm/extensions/erc721/drops/write/claimTo.js.map +1 -1
  71. package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js +4 -1
  72. package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
  73. package/dist/esm/utils/extensions/drops/get-claim-params.js +20 -0
  74. package/dist/esm/utils/extensions/drops/get-claim-params.js.map +1 -1
  75. package/dist/esm/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js +39 -12
  76. package/dist/esm/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js.map +1 -1
  77. package/dist/esm/version.js +1 -1
  78. package/dist/esm/version.js.map +1 -1
  79. package/dist/esm/wallets/smart/index.js +3 -0
  80. package/dist/esm/wallets/smart/index.js.map +1 -1
  81. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.d.ts +72 -0
  82. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.d.ts.map +1 -0
  83. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.d.ts +64 -0
  84. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.d.ts.map +1 -0
  85. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.d.ts +101 -0
  86. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.d.ts.map +1 -0
  87. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.d.ts +139 -0
  88. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.d.ts.map +1 -0
  89. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.d.ts +127 -0
  90. package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.d.ts.map +1 -0
  91. package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts +1 -0
  92. package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts.map +1 -1
  93. package/dist/types/extensions/erc1155/drops/write/setClaimConditions.d.ts +1 -0
  94. package/dist/types/extensions/erc1155/drops/write/setClaimConditions.d.ts.map +1 -1
  95. package/dist/types/extensions/erc20/drops/write/claimTo.d.ts +1 -0
  96. package/dist/types/extensions/erc20/drops/write/claimTo.d.ts.map +1 -1
  97. package/dist/types/extensions/erc20/drops/write/setClaimConditions.d.ts +1 -0
  98. package/dist/types/extensions/erc20/drops/write/setClaimConditions.d.ts.map +1 -1
  99. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.d.ts +54 -0
  100. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.d.ts.map +1 -0
  101. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.d.ts +64 -0
  102. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.d.ts.map +1 -0
  103. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.d.ts +62 -0
  104. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.d.ts.map +1 -0
  105. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/claim.d.ts +132 -0
  106. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/claim.d.ts.map +1 -0
  107. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.d.ts +120 -0
  108. package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.d.ts.map +1 -0
  109. package/dist/types/extensions/erc721/drops/write/claimTo.d.ts +1 -0
  110. package/dist/types/extensions/erc721/drops/write/claimTo.d.ts.map +1 -1
  111. package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts +1 -0
  112. package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts.map +1 -1
  113. package/dist/types/utils/extensions/drops/get-claim-params.d.ts +1 -0
  114. package/dist/types/utils/extensions/drops/get-claim-params.d.ts.map +1 -1
  115. package/dist/types/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.d.ts +1 -0
  116. package/dist/types/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.d.ts.map +1 -1
  117. package/dist/types/version.d.ts +1 -1
  118. package/dist/types/version.d.ts.map +1 -1
  119. package/package.json +1 -1
  120. package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.ts +43 -0
  121. package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.ts +53 -0
  122. package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.ts +160 -0
  123. package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.ts +229 -0
  124. package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.ts +213 -0
  125. package/src/extensions/erc1155/customDrop1155.test.ts +181 -0
  126. package/src/extensions/erc1155/drops/write/claimTo.ts +6 -2
  127. package/src/extensions/erc1155/drops/write/setClaimConditions.ts +5 -1
  128. package/src/extensions/erc20/customDrop20.test.ts +80 -0
  129. package/src/extensions/erc20/drops/write/claimTo.ts +2 -0
  130. package/src/extensions/erc20/drops/write/setClaimConditions.ts +2 -0
  131. package/src/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.ts +25 -0
  132. package/src/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.ts +53 -0
  133. package/src/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.ts +105 -0
  134. package/src/extensions/erc721/__generated__/IDropSinglePhase/write/claim.ts +219 -0
  135. package/src/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.ts +203 -0
  136. package/src/extensions/erc721/customDrop721.test.ts +115 -0
  137. package/src/extensions/erc721/drops/write/claimTo.ts +7 -3
  138. package/src/extensions/erc721/drops/write/setClaimConditions.ts +5 -1
  139. package/src/utils/extensions/drops/get-claim-params.ts +29 -2
  140. package/src/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.ts +46 -16
  141. package/src/version.ts +1 -1
  142. package/src/wallets/smart/index.ts +2 -0
  143. package/src/wallets/smart/smart-wallet-integration.test.ts +33 -0
@@ -0,0 +1,229 @@
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 "claim" function.
13
+ */
14
+ export type ClaimParams = WithOverrides<{
15
+ receiver: AbiParameterToPrimitiveType<{ type: "address"; name: "receiver" }>;
16
+ tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
17
+ quantity: AbiParameterToPrimitiveType<{ type: "uint256"; name: "quantity" }>;
18
+ currency: AbiParameterToPrimitiveType<{ type: "address"; name: "currency" }>;
19
+ pricePerToken: AbiParameterToPrimitiveType<{
20
+ type: "uint256";
21
+ name: "pricePerToken";
22
+ }>;
23
+ allowlistProof: AbiParameterToPrimitiveType<{
24
+ type: "tuple";
25
+ name: "allowlistProof";
26
+ components: [
27
+ { type: "bytes32[]"; name: "proof" },
28
+ { type: "uint256"; name: "quantityLimitPerWallet" },
29
+ { type: "uint256"; name: "pricePerToken" },
30
+ { type: "address"; name: "currency" },
31
+ ];
32
+ }>;
33
+ data: AbiParameterToPrimitiveType<{ type: "bytes"; name: "data" }>;
34
+ }>;
35
+
36
+ export const FN_SELECTOR = "0x57bc3d78" as const;
37
+ const FN_INPUTS = [
38
+ {
39
+ type: "address",
40
+ name: "receiver",
41
+ },
42
+ {
43
+ type: "uint256",
44
+ name: "tokenId",
45
+ },
46
+ {
47
+ type: "uint256",
48
+ name: "quantity",
49
+ },
50
+ {
51
+ type: "address",
52
+ name: "currency",
53
+ },
54
+ {
55
+ type: "uint256",
56
+ name: "pricePerToken",
57
+ },
58
+ {
59
+ type: "tuple",
60
+ name: "allowlistProof",
61
+ components: [
62
+ {
63
+ type: "bytes32[]",
64
+ name: "proof",
65
+ },
66
+ {
67
+ type: "uint256",
68
+ name: "quantityLimitPerWallet",
69
+ },
70
+ {
71
+ type: "uint256",
72
+ name: "pricePerToken",
73
+ },
74
+ {
75
+ type: "address",
76
+ name: "currency",
77
+ },
78
+ ],
79
+ },
80
+ {
81
+ type: "bytes",
82
+ name: "data",
83
+ },
84
+ ] as const;
85
+ const FN_OUTPUTS = [] as const;
86
+
87
+ /**
88
+ * Checks if the `claim` method is supported by the given contract.
89
+ * @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.
90
+ * @returns A boolean indicating if the `claim` method is supported.
91
+ * @extension ERC1155
92
+ * @example
93
+ * ```ts
94
+ * import { isClaimSupported } from "thirdweb/extensions/erc1155";
95
+ *
96
+ * const supported = isClaimSupported(["0x..."]);
97
+ * ```
98
+ */
99
+ export function isClaimSupported(availableSelectors: string[]) {
100
+ return detectMethod({
101
+ availableSelectors,
102
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Encodes the parameters for the "claim" function.
108
+ * @param options - The options for the claim function.
109
+ * @returns The encoded ABI parameters.
110
+ * @extension ERC1155
111
+ * @example
112
+ * ```ts
113
+ * import { encodeClaimParams } from "thirdweb/extensions/erc1155";
114
+ * const result = encodeClaimParams({
115
+ * receiver: ...,
116
+ * tokenId: ...,
117
+ * quantity: ...,
118
+ * currency: ...,
119
+ * pricePerToken: ...,
120
+ * allowlistProof: ...,
121
+ * data: ...,
122
+ * });
123
+ * ```
124
+ */
125
+ export function encodeClaimParams(options: ClaimParams) {
126
+ return encodeAbiParameters(FN_INPUTS, [
127
+ options.receiver,
128
+ options.tokenId,
129
+ options.quantity,
130
+ options.currency,
131
+ options.pricePerToken,
132
+ options.allowlistProof,
133
+ options.data,
134
+ ]);
135
+ }
136
+
137
+ /**
138
+ * Encodes the "claim" function into a Hex string with its parameters.
139
+ * @param options - The options for the claim function.
140
+ * @returns The encoded hexadecimal string.
141
+ * @extension ERC1155
142
+ * @example
143
+ * ```ts
144
+ * import { encodeClaim } from "thirdweb/extensions/erc1155";
145
+ * const result = encodeClaim({
146
+ * receiver: ...,
147
+ * tokenId: ...,
148
+ * quantity: ...,
149
+ * currency: ...,
150
+ * pricePerToken: ...,
151
+ * allowlistProof: ...,
152
+ * data: ...,
153
+ * });
154
+ * ```
155
+ */
156
+ export function encodeClaim(options: ClaimParams) {
157
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
158
+ // we can do this because we know the specific formats of the values
159
+ return (FN_SELECTOR +
160
+ encodeClaimParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
161
+ }
162
+
163
+ /**
164
+ * Prepares a transaction to call the "claim" function on the contract.
165
+ * @param options - The options for the "claim" function.
166
+ * @returns A prepared transaction object.
167
+ * @extension ERC1155
168
+ * @example
169
+ * ```ts
170
+ * import { sendTransaction } from "thirdweb";
171
+ * import { claim } from "thirdweb/extensions/erc1155";
172
+ *
173
+ * const transaction = claim({
174
+ * contract,
175
+ * receiver: ...,
176
+ * tokenId: ...,
177
+ * quantity: ...,
178
+ * currency: ...,
179
+ * pricePerToken: ...,
180
+ * allowlistProof: ...,
181
+ * data: ...,
182
+ * overrides: {
183
+ * ...
184
+ * }
185
+ * });
186
+ *
187
+ * // Send the transaction
188
+ * await sendTransaction({ transaction, account });
189
+ * ```
190
+ */
191
+ export function claim(
192
+ options: BaseTransactionOptions<
193
+ | ClaimParams
194
+ | {
195
+ asyncParams: () => Promise<ClaimParams>;
196
+ }
197
+ >,
198
+ ) {
199
+ const asyncOptions = once(async () => {
200
+ return "asyncParams" in options ? await options.asyncParams() : options;
201
+ });
202
+
203
+ return prepareContractCall({
204
+ contract: options.contract,
205
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
206
+ params: async () => {
207
+ const resolvedOptions = await asyncOptions();
208
+ return [
209
+ resolvedOptions.receiver,
210
+ resolvedOptions.tokenId,
211
+ resolvedOptions.quantity,
212
+ resolvedOptions.currency,
213
+ resolvedOptions.pricePerToken,
214
+ resolvedOptions.allowlistProof,
215
+ resolvedOptions.data,
216
+ ] as const;
217
+ },
218
+ value: async () => (await asyncOptions()).overrides?.value,
219
+ accessList: async () => (await asyncOptions()).overrides?.accessList,
220
+ gas: async () => (await asyncOptions()).overrides?.gas,
221
+ gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
222
+ maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
223
+ maxPriorityFeePerGas: async () =>
224
+ (await asyncOptions()).overrides?.maxPriorityFeePerGas,
225
+ nonce: async () => (await asyncOptions()).overrides?.nonce,
226
+ extraGas: async () => (await asyncOptions()).overrides?.extraGas,
227
+ erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
228
+ });
229
+ }
@@ -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 "setClaimConditions" function.
13
+ */
14
+ export type SetClaimConditionsParams = WithOverrides<{
15
+ tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
16
+ phase: AbiParameterToPrimitiveType<{
17
+ type: "tuple";
18
+ name: "phase";
19
+ components: [
20
+ { type: "uint256"; name: "startTimestamp" },
21
+ { type: "uint256"; name: "maxClaimableSupply" },
22
+ { type: "uint256"; name: "supplyClaimed" },
23
+ { type: "uint256"; name: "quantityLimitPerWallet" },
24
+ { type: "bytes32"; name: "merkleRoot" },
25
+ { type: "uint256"; name: "pricePerToken" },
26
+ { type: "address"; name: "currency" },
27
+ { type: "string"; name: "metadata" },
28
+ ];
29
+ }>;
30
+ resetClaimEligibility: AbiParameterToPrimitiveType<{
31
+ type: "bool";
32
+ name: "resetClaimEligibility";
33
+ }>;
34
+ }>;
35
+
36
+ export const FN_SELECTOR = "0x8affb89f" as const;
37
+ const FN_INPUTS = [
38
+ {
39
+ type: "uint256",
40
+ name: "tokenId",
41
+ },
42
+ {
43
+ type: "tuple",
44
+ name: "phase",
45
+ components: [
46
+ {
47
+ type: "uint256",
48
+ name: "startTimestamp",
49
+ },
50
+ {
51
+ type: "uint256",
52
+ name: "maxClaimableSupply",
53
+ },
54
+ {
55
+ type: "uint256",
56
+ name: "supplyClaimed",
57
+ },
58
+ {
59
+ type: "uint256",
60
+ name: "quantityLimitPerWallet",
61
+ },
62
+ {
63
+ type: "bytes32",
64
+ name: "merkleRoot",
65
+ },
66
+ {
67
+ type: "uint256",
68
+ name: "pricePerToken",
69
+ },
70
+ {
71
+ type: "address",
72
+ name: "currency",
73
+ },
74
+ {
75
+ type: "string",
76
+ name: "metadata",
77
+ },
78
+ ],
79
+ },
80
+ {
81
+ type: "bool",
82
+ name: "resetClaimEligibility",
83
+ },
84
+ ] as const;
85
+ const FN_OUTPUTS = [] as const;
86
+
87
+ /**
88
+ * Checks if the `setClaimConditions` method is supported by the given contract.
89
+ * @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.
90
+ * @returns A boolean indicating if the `setClaimConditions` method is supported.
91
+ * @extension ERC1155
92
+ * @example
93
+ * ```ts
94
+ * import { isSetClaimConditionsSupported } from "thirdweb/extensions/erc1155";
95
+ *
96
+ * const supported = isSetClaimConditionsSupported(["0x..."]);
97
+ * ```
98
+ */
99
+ export function isSetClaimConditionsSupported(availableSelectors: string[]) {
100
+ return detectMethod({
101
+ availableSelectors,
102
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Encodes the parameters for the "setClaimConditions" function.
108
+ * @param options - The options for the setClaimConditions function.
109
+ * @returns The encoded ABI parameters.
110
+ * @extension ERC1155
111
+ * @example
112
+ * ```ts
113
+ * import { encodeSetClaimConditionsParams } from "thirdweb/extensions/erc1155";
114
+ * const result = encodeSetClaimConditionsParams({
115
+ * tokenId: ...,
116
+ * phase: ...,
117
+ * resetClaimEligibility: ...,
118
+ * });
119
+ * ```
120
+ */
121
+ export function encodeSetClaimConditionsParams(
122
+ options: SetClaimConditionsParams,
123
+ ) {
124
+ return encodeAbiParameters(FN_INPUTS, [
125
+ options.tokenId,
126
+ options.phase,
127
+ options.resetClaimEligibility,
128
+ ]);
129
+ }
130
+
131
+ /**
132
+ * Encodes the "setClaimConditions" function into a Hex string with its parameters.
133
+ * @param options - The options for the setClaimConditions function.
134
+ * @returns The encoded hexadecimal string.
135
+ * @extension ERC1155
136
+ * @example
137
+ * ```ts
138
+ * import { encodeSetClaimConditions } from "thirdweb/extensions/erc1155";
139
+ * const result = encodeSetClaimConditions({
140
+ * tokenId: ...,
141
+ * phase: ...,
142
+ * resetClaimEligibility: ...,
143
+ * });
144
+ * ```
145
+ */
146
+ export function encodeSetClaimConditions(options: SetClaimConditionsParams) {
147
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
148
+ // we can do this because we know the specific formats of the values
149
+ return (FN_SELECTOR +
150
+ encodeSetClaimConditionsParams(options).slice(
151
+ 2,
152
+ )) as `${typeof FN_SELECTOR}${string}`;
153
+ }
154
+
155
+ /**
156
+ * Prepares a transaction to call the "setClaimConditions" function on the contract.
157
+ * @param options - The options for the "setClaimConditions" function.
158
+ * @returns A prepared transaction object.
159
+ * @extension ERC1155
160
+ * @example
161
+ * ```ts
162
+ * import { sendTransaction } from "thirdweb";
163
+ * import { setClaimConditions } from "thirdweb/extensions/erc1155";
164
+ *
165
+ * const transaction = setClaimConditions({
166
+ * contract,
167
+ * tokenId: ...,
168
+ * phase: ...,
169
+ * resetClaimEligibility: ...,
170
+ * overrides: {
171
+ * ...
172
+ * }
173
+ * });
174
+ *
175
+ * // Send the transaction
176
+ * await sendTransaction({ transaction, account });
177
+ * ```
178
+ */
179
+ export function setClaimConditions(
180
+ options: BaseTransactionOptions<
181
+ | SetClaimConditionsParams
182
+ | {
183
+ asyncParams: () => Promise<SetClaimConditionsParams>;
184
+ }
185
+ >,
186
+ ) {
187
+ const asyncOptions = once(async () => {
188
+ return "asyncParams" in options ? await options.asyncParams() : options;
189
+ });
190
+
191
+ return prepareContractCall({
192
+ contract: options.contract,
193
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
194
+ params: async () => {
195
+ const resolvedOptions = await asyncOptions();
196
+ return [
197
+ resolvedOptions.tokenId,
198
+ resolvedOptions.phase,
199
+ resolvedOptions.resetClaimEligibility,
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,181 @@
1
+ import { fetchDeployMetadata } from "../../utils/any-evm/deploy-metadata.js";
2
+
3
+ import { beforeAll, describe, expect, it } from "vitest";
4
+ import { VITALIK_WALLET } from "../../../test/src/addresses.js";
5
+ import { ANVIL_CHAIN } from "../../../test/src/chains.js";
6
+ import { TEST_CLIENT } from "../../../test/src/test-clients.js";
7
+ import {
8
+ TEST_ACCOUNT_B,
9
+ TEST_ACCOUNT_C,
10
+ } from "../../../test/src/test-wallets.js";
11
+ import { type ThirdwebContract, getContract } from "../../contract/contract.js";
12
+ import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
13
+ import { deployContractfromDeployMetadata } from "../prebuilts/deploy-published.js";
14
+ import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
15
+ import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
16
+ import { claimTo } from "./drops/write/claimTo.js";
17
+ import { setClaimConditions } from "./drops/write/setClaimConditions.js";
18
+ import { getNFT } from "./read/getNFT.js";
19
+ import { lazyMint } from "./write/lazyMint.js";
20
+
21
+ describe.runIf(process.env.TW_SECRET_KEY)(
22
+ "CustomDropERC1155",
23
+ {
24
+ retry: 0,
25
+ },
26
+ () => {
27
+ let contract: ThirdwebContract;
28
+
29
+ beforeAll(async () => {
30
+ const customDropDeployMetadata = await fetchDeployMetadata({
31
+ client: TEST_CLIENT,
32
+ uri: "ipfs://QmaqFExXhU8kWkgAZCqxo8F3GZd8D2NJzCJWerfmFjujo8",
33
+ });
34
+ const contractAddress = await deployContractfromDeployMetadata({
35
+ chain: ANVIL_CHAIN,
36
+ client: TEST_CLIENT,
37
+ account: TEST_ACCOUNT_C,
38
+ deployMetadata: customDropDeployMetadata,
39
+ initializeParams: {
40
+ defaultAdmin: TEST_ACCOUNT_C.address,
41
+ name: "TestCustomDropERC1155",
42
+ symbol: "TT",
43
+ },
44
+ });
45
+
46
+ contract = getContract({
47
+ address: contractAddress,
48
+ chain: ANVIL_CHAIN,
49
+ client: TEST_CLIENT,
50
+ });
51
+ // this deploys a contract, it may take some time
52
+ }, 60_000);
53
+
54
+ it("should allow for lazy minting tokens", async () => {
55
+ const mintTx = lazyMint({
56
+ contract,
57
+ nfts: [
58
+ { name: "Test NFT" },
59
+ { name: "Test NFT 2" },
60
+ { name: "Test NFT 3" },
61
+ { name: "Test NFT 4" },
62
+ { name: "Test NFT 5" },
63
+ { name: "Test NFT 6" },
64
+ ],
65
+ });
66
+ await sendAndConfirmTransaction({
67
+ transaction: mintTx,
68
+ account: TEST_ACCOUNT_C,
69
+ });
70
+
71
+ await expect(nextTokenIdToMint({ contract })).resolves.toBe(6n);
72
+ await expect(
73
+ getNFT({ contract, tokenId: 0n }),
74
+ ).resolves.toMatchInlineSnapshot(`
75
+ {
76
+ "id": 0n,
77
+ "metadata": {
78
+ "name": "Test NFT",
79
+ },
80
+ "owner": null,
81
+ "supply": 0n,
82
+ "tokenURI": "ipfs://QmTo68Dm1ntSp2BHLmE9gesS6ELuXosRz5mAgFCK6tfsRk/0",
83
+ "type": "ERC1155",
84
+ }
85
+ `);
86
+ });
87
+
88
+ it("should allow to claim tokens", async () => {
89
+ await expect(
90
+ balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }),
91
+ ).resolves.toBe(0n);
92
+ await sendAndConfirmTransaction({
93
+ transaction: setClaimConditions({
94
+ contract,
95
+ phases: [
96
+ {
97
+ startTime: new Date(0),
98
+ maxClaimableSupply: 10n,
99
+ },
100
+ ],
101
+ tokenId: 0n,
102
+ singlePhaseDrop: true,
103
+ }),
104
+ account: TEST_ACCOUNT_C,
105
+ });
106
+ const claimTx = claimTo({
107
+ contract,
108
+ to: TEST_ACCOUNT_C.address,
109
+ tokenId: 0n,
110
+ quantity: 1n,
111
+ singlePhaseDrop: true,
112
+ });
113
+ await sendAndConfirmTransaction({
114
+ transaction: claimTx,
115
+ account: TEST_ACCOUNT_C,
116
+ });
117
+ await expect(
118
+ balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }),
119
+ ).resolves.toBe(1n);
120
+ });
121
+
122
+ it("should allow to claim tokens with an allowlist", async () => {
123
+ const tokenId = 1n;
124
+ await sendAndConfirmTransaction({
125
+ transaction: setClaimConditions({
126
+ contract,
127
+ phases: [
128
+ {
129
+ overrideList: [
130
+ { address: TEST_ACCOUNT_C.address, maxClaimable: "100" },
131
+ { address: VITALIK_WALLET, maxClaimable: "100" },
132
+ ],
133
+ maxClaimablePerWallet: 0n,
134
+ },
135
+ ],
136
+ tokenId,
137
+ singlePhaseDrop: true,
138
+ }),
139
+ account: TEST_ACCOUNT_C,
140
+ });
141
+
142
+ await expect(
143
+ balanceOf({ contract, owner: TEST_ACCOUNT_B.address, tokenId }),
144
+ ).resolves.toBe(0n);
145
+
146
+ await sendAndConfirmTransaction({
147
+ account: TEST_ACCOUNT_C,
148
+ transaction: claimTo({
149
+ contract,
150
+ from: TEST_ACCOUNT_C.address,
151
+ to: TEST_ACCOUNT_B.address,
152
+ tokenId,
153
+ quantity: 1n,
154
+ singlePhaseDrop: true,
155
+ }),
156
+ });
157
+
158
+ await expect(
159
+ balanceOf({ contract, owner: TEST_ACCOUNT_B.address, tokenId }),
160
+ ).resolves.toBe(1n);
161
+
162
+ await expect(
163
+ sendAndConfirmTransaction({
164
+ account: TEST_ACCOUNT_B,
165
+ transaction: claimTo({
166
+ contract,
167
+ to: TEST_ACCOUNT_B.address,
168
+ tokenId,
169
+ quantity: 1n,
170
+ singlePhaseDrop: true,
171
+ }),
172
+ }),
173
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
174
+ [TransactionError: Error - !Qty
175
+
176
+ contract: ${contract.address}
177
+ chainId: ${contract.chain.id}]
178
+ `);
179
+ });
180
+ },
181
+ );
@@ -2,6 +2,7 @@ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
2
2
  import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
3
3
  import { isGetContractMetadataSupported } from "../../../common/read/getContractMetadata.js";
4
4
  import * as GeneratedClaim from "../../__generated__/IDrop1155/write/claim.js";
5
+ import { isClaimConditionSupported } from "../../__generated__/IDropSinglePhase1155/read/claimCondition.js";
5
6
  import { isGetActiveClaimConditionSupported } from "../read/getActiveClaimCondition.js";
6
7
 
7
8
  /**
@@ -12,6 +13,7 @@ export type ClaimToParams = {
12
13
  tokenId: bigint;
13
14
  quantity: bigint;
14
15
  from?: string;
16
+ singlePhaseDrop?: boolean;
15
17
  };
16
18
 
17
19
  /**
@@ -59,6 +61,7 @@ export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
59
61
  quantity: options.quantity,
60
62
  from: options.from,
61
63
  tokenId: options.tokenId,
64
+ singlePhaseDrop: options.singlePhaseDrop,
62
65
  });
63
66
 
64
67
  return {
@@ -85,9 +88,10 @@ export function isClaimToSupported(availableSelectors: string[]) {
85
88
  return [
86
89
  // has to support the claim method
87
90
  GeneratedClaim.isClaimSupported(availableSelectors),
88
- // has to support the getActiveClaimCondition method
89
- isGetActiveClaimConditionSupported(availableSelectors),
90
91
  // requires contractMetadata for claimer proofs
91
92
  isGetContractMetadataSupported(availableSelectors),
93
+ // required to check if the contract supports the getActiveClaimCondition method
94
+ isGetActiveClaimConditionSupported(availableSelectors) ||
95
+ isClaimConditionSupported(availableSelectors),
92
96
  ].every(Boolean);
93
97
  }
@@ -8,6 +8,7 @@ import {
8
8
  } from "../../../common/__generated__/IMulticall/write/multicall.js";
9
9
  import { isGetContractMetadataSupported } from "../../../common/read/getContractMetadata.js";
10
10
  import { isSetClaimConditionsSupported as isSetClaimConditionsSupportedGenerated } from "../../__generated__/IDrop1155/write/setClaimConditions.js";
11
+ import { isSetClaimConditionsSupported as isSetClaimConditionsSupportedGeneratedSinglePhase } from "../../__generated__/IDropSinglePhase1155/write/setClaimConditions.js";
11
12
 
12
13
  /**
13
14
  * @extension ERC1155
@@ -16,6 +17,7 @@ export type SetClaimConditionsParams = {
16
17
  tokenId: bigint;
17
18
  phases: ClaimConditionsInput[];
18
19
  resetClaimEligibility?: boolean;
20
+ singlePhaseDrop?: boolean;
19
21
  };
20
22
 
21
23
  /**
@@ -58,6 +60,7 @@ export function setClaimConditions(
58
60
  resetClaimEligibility: options.resetClaimEligibility,
59
61
  tokenId: options.tokenId,
60
62
  tokenDecimals: 0,
63
+ singlePhase: options.singlePhaseDrop,
61
64
  }),
62
65
  };
63
66
  },
@@ -83,6 +86,7 @@ export function isSetClaimConditionsSupported(availableSelectors: string[]) {
83
86
  isGetContractMetadataSupported(availableSelectors) &&
84
87
  isSetContractURISupported(availableSelectors) &&
85
88
  // needs to actually be able to set the claim Conditions
86
- isSetClaimConditionsSupportedGenerated(availableSelectors)
89
+ (isSetClaimConditionsSupportedGenerated(availableSelectors) ||
90
+ isSetClaimConditionsSupportedGeneratedSinglePhase(availableSelectors))
87
91
  );
88
92
  }