thirdweb 5.88.2-nightly-0c1bb6ccaec9dc4edf596dac7f7623d0ad90f757-20250212000327 → 5.88.3
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.
- package/dist/cjs/exports/extensions/erc1155.js +4 -2
- package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
- package/dist/cjs/exports/extensions/erc20.js +3 -1
- package/dist/cjs/exports/extensions/erc20.js.map +1 -1
- package/dist/cjs/exports/extensions/erc721.js +4 -2
- package/dist/cjs/exports/extensions/erc721.js.map +1 -1
- package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.js +191 -0
- package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.js.map +1 -0
- package/dist/cjs/extensions/erc1155/drops/read/canClaim.js +63 -0
- package/dist/cjs/extensions/erc1155/drops/read/canClaim.js.map +1 -0
- package/dist/cjs/extensions/erc20/__generated__/DropERC20/read/verifyClaim.js +182 -0
- package/dist/cjs/extensions/erc20/__generated__/DropERC20/read/verifyClaim.js.map +1 -0
- package/dist/cjs/extensions/erc20/drops/read/canClaim.js +68 -0
- package/dist/cjs/extensions/erc20/drops/read/canClaim.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/read/verifyClaim.js +182 -0
- package/dist/cjs/extensions/erc721/__generated__/DropERC721/read/verifyClaim.js.map +1 -0
- package/dist/cjs/extensions/erc721/drops/read/canClaim.js +59 -0
- package/dist/cjs/extensions/erc721/drops/read/canClaim.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +12 -5
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js +9 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.js +3 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.js +1 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.js +7 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.js.map +1 -1
- package/dist/cjs/react/web/utils/errors.js +6 -1
- package/dist/cjs/react/web/utils/errors.js.map +1 -1
- package/dist/cjs/transaction/extract-error.js +11 -4
- package/dist/cjs/transaction/extract-error.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/exports/extensions/erc1155.js +1 -0
- package/dist/esm/exports/extensions/erc1155.js.map +1 -1
- package/dist/esm/exports/extensions/erc20.js +1 -0
- package/dist/esm/exports/extensions/erc20.js.map +1 -1
- package/dist/esm/exports/extensions/erc721.js +1 -0
- package/dist/esm/exports/extensions/erc721.js.map +1 -1
- package/dist/esm/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.js +183 -0
- package/dist/esm/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.js.map +1 -0
- package/dist/esm/extensions/erc1155/drops/read/canClaim.js +60 -0
- package/dist/esm/extensions/erc1155/drops/read/canClaim.js.map +1 -0
- package/dist/esm/extensions/erc20/__generated__/DropERC20/read/verifyClaim.js +174 -0
- package/dist/esm/extensions/erc20/__generated__/DropERC20/read/verifyClaim.js.map +1 -0
- package/dist/esm/extensions/erc20/drops/read/canClaim.js +65 -0
- package/dist/esm/extensions/erc20/drops/read/canClaim.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/read/verifyClaim.js +174 -0
- package/dist/esm/extensions/erc721/__generated__/DropERC721/read/verifyClaim.js.map +1 -0
- package/dist/esm/extensions/erc721/drops/read/canClaim.js +56 -0
- package/dist/esm/extensions/erc721/drops/read/canClaim.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +12 -5
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js +9 -4
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.js +3 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.js +2 -4
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.js +7 -3
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.js.map +1 -1
- package/dist/esm/react/web/utils/errors.js +6 -1
- package/dist/esm/react/web/utils/errors.js.map +1 -1
- package/dist/esm/transaction/extract-error.js +11 -5
- package/dist/esm/transaction/extract-error.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/exports/extensions/erc1155.d.ts +1 -0
- package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc20.d.ts +1 -0
- package/dist/types/exports/extensions/erc20.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc721.d.ts +1 -0
- package/dist/types/exports/extensions/erc721.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.d.ts +143 -0
- package/dist/types/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/drops/read/canClaim.d.ts +31 -0
- package/dist/types/extensions/erc1155/drops/read/canClaim.d.ts.map +1 -0
- package/dist/types/extensions/erc20/__generated__/DropERC20/read/verifyClaim.d.ts +136 -0
- package/dist/types/extensions/erc20/__generated__/DropERC20/read/verifyClaim.d.ts.map +1 -0
- package/dist/types/extensions/erc20/drops/read/canClaim.d.ts +32 -0
- package/dist/types/extensions/erc20/drops/read/canClaim.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/read/verifyClaim.d.ts +136 -0
- package/dist/types/extensions/erc721/__generated__/DropERC721/read/verifyClaim.d.ts.map +1 -0
- package/dist/types/extensions/erc721/drops/read/canClaim.d.ts +29 -0
- package/dist/types/extensions/erc721/drops/read/canClaim.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.d.ts.map +1 -1
- package/dist/types/react/web/utils/errors.d.ts.map +1 -1
- package/dist/types/transaction/extract-error.d.ts +4 -0
- package/dist/types/transaction/extract-error.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/extensions/erc1155.ts +5 -0
- package/src/exports/extensions/erc20.ts +5 -0
- package/src/exports/extensions/erc721.ts +5 -0
- package/src/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.ts +223 -0
- package/src/extensions/erc1155/drop1155.test.ts +42 -0
- package/src/extensions/erc1155/drops/read/canClaim.ts +75 -0
- package/src/extensions/erc20/__generated__/DropERC20/read/verifyClaim.ts +213 -0
- package/src/extensions/erc20/drop20.test.ts +38 -0
- package/src/extensions/erc20/drops/read/canClaim.ts +82 -0
- package/src/extensions/erc721/__generated__/DropERC721/read/verifyClaim.ts +213 -0
- package/src/extensions/erc721/drop721.test.ts +39 -0
- package/src/extensions/erc721/drops/read/canClaim.ts +70 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +16 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.tsx +40 -19
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx +1 -2
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.tsx +7 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.tsx +3 -7
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/PaymentSelectionScreen.tsx +28 -16
- package/src/react/web/utils/errors.ts +6 -1
- package/src/transaction/actions/gasless/providers/engine.test.ts +1 -1
- package/src/transaction/actions/gasless/providers/openzeppelin.test.ts +1 -1
- package/src/transaction/extract-error.ts +15 -13
- package/src/version.ts +1 -1
@@ -0,0 +1,223 @@
|
|
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 "verifyClaim" function.
|
11
|
+
*/
|
12
|
+
export type VerifyClaimParams = {
|
13
|
+
conditionId: AbiParameterToPrimitiveType<{
|
14
|
+
type: "uint256";
|
15
|
+
name: "_conditionId";
|
16
|
+
}>;
|
17
|
+
claimer: AbiParameterToPrimitiveType<{ type: "address"; name: "_claimer" }>;
|
18
|
+
tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_tokenId" }>;
|
19
|
+
quantity: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_quantity" }>;
|
20
|
+
currency: AbiParameterToPrimitiveType<{ type: "address"; name: "_currency" }>;
|
21
|
+
pricePerToken: AbiParameterToPrimitiveType<{
|
22
|
+
type: "uint256";
|
23
|
+
name: "_pricePerToken";
|
24
|
+
}>;
|
25
|
+
allowlistProof: AbiParameterToPrimitiveType<{
|
26
|
+
type: "tuple";
|
27
|
+
name: "_allowlistProof";
|
28
|
+
components: [
|
29
|
+
{ type: "bytes32[]"; name: "proof" },
|
30
|
+
{ type: "uint256"; name: "quantityLimitPerWallet" },
|
31
|
+
{ type: "uint256"; name: "pricePerToken" },
|
32
|
+
{ type: "address"; name: "currency" },
|
33
|
+
];
|
34
|
+
}>;
|
35
|
+
};
|
36
|
+
|
37
|
+
export const FN_SELECTOR = "0xea1def9c" as const;
|
38
|
+
const FN_INPUTS = [
|
39
|
+
{
|
40
|
+
type: "uint256",
|
41
|
+
name: "_conditionId",
|
42
|
+
},
|
43
|
+
{
|
44
|
+
type: "address",
|
45
|
+
name: "_claimer",
|
46
|
+
},
|
47
|
+
{
|
48
|
+
type: "uint256",
|
49
|
+
name: "_tokenId",
|
50
|
+
},
|
51
|
+
{
|
52
|
+
type: "uint256",
|
53
|
+
name: "_quantity",
|
54
|
+
},
|
55
|
+
{
|
56
|
+
type: "address",
|
57
|
+
name: "_currency",
|
58
|
+
},
|
59
|
+
{
|
60
|
+
type: "uint256",
|
61
|
+
name: "_pricePerToken",
|
62
|
+
},
|
63
|
+
{
|
64
|
+
type: "tuple",
|
65
|
+
name: "_allowlistProof",
|
66
|
+
components: [
|
67
|
+
{
|
68
|
+
type: "bytes32[]",
|
69
|
+
name: "proof",
|
70
|
+
},
|
71
|
+
{
|
72
|
+
type: "uint256",
|
73
|
+
name: "quantityLimitPerWallet",
|
74
|
+
},
|
75
|
+
{
|
76
|
+
type: "uint256",
|
77
|
+
name: "pricePerToken",
|
78
|
+
},
|
79
|
+
{
|
80
|
+
type: "address",
|
81
|
+
name: "currency",
|
82
|
+
},
|
83
|
+
],
|
84
|
+
},
|
85
|
+
] as const;
|
86
|
+
const FN_OUTPUTS = [
|
87
|
+
{
|
88
|
+
type: "bool",
|
89
|
+
name: "isOverride",
|
90
|
+
},
|
91
|
+
] as const;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Checks if the `verifyClaim` method is supported by the given contract.
|
95
|
+
* @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.
|
96
|
+
* @returns A boolean indicating if the `verifyClaim` method is supported.
|
97
|
+
* @extension ERC1155
|
98
|
+
* @example
|
99
|
+
* ```ts
|
100
|
+
* import { isVerifyClaimSupported } from "thirdweb/extensions/erc1155";
|
101
|
+
* const supported = isVerifyClaimSupported(["0x..."]);
|
102
|
+
* ```
|
103
|
+
*/
|
104
|
+
export function isVerifyClaimSupported(availableSelectors: string[]) {
|
105
|
+
return detectMethod({
|
106
|
+
availableSelectors,
|
107
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
108
|
+
});
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Encodes the parameters for the "verifyClaim" function.
|
113
|
+
* @param options - The options for the verifyClaim function.
|
114
|
+
* @returns The encoded ABI parameters.
|
115
|
+
* @extension ERC1155
|
116
|
+
* @example
|
117
|
+
* ```ts
|
118
|
+
* import { encodeVerifyClaimParams } from "thirdweb/extensions/erc1155";
|
119
|
+
* const result = encodeVerifyClaimParams({
|
120
|
+
* conditionId: ...,
|
121
|
+
* claimer: ...,
|
122
|
+
* tokenId: ...,
|
123
|
+
* quantity: ...,
|
124
|
+
* currency: ...,
|
125
|
+
* pricePerToken: ...,
|
126
|
+
* allowlistProof: ...,
|
127
|
+
* });
|
128
|
+
* ```
|
129
|
+
*/
|
130
|
+
export function encodeVerifyClaimParams(options: VerifyClaimParams) {
|
131
|
+
return encodeAbiParameters(FN_INPUTS, [
|
132
|
+
options.conditionId,
|
133
|
+
options.claimer,
|
134
|
+
options.tokenId,
|
135
|
+
options.quantity,
|
136
|
+
options.currency,
|
137
|
+
options.pricePerToken,
|
138
|
+
options.allowlistProof,
|
139
|
+
]);
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Encodes the "verifyClaim" function into a Hex string with its parameters.
|
144
|
+
* @param options - The options for the verifyClaim function.
|
145
|
+
* @returns The encoded hexadecimal string.
|
146
|
+
* @extension ERC1155
|
147
|
+
* @example
|
148
|
+
* ```ts
|
149
|
+
* import { encodeVerifyClaim } from "thirdweb/extensions/erc1155";
|
150
|
+
* const result = encodeVerifyClaim({
|
151
|
+
* conditionId: ...,
|
152
|
+
* claimer: ...,
|
153
|
+
* tokenId: ...,
|
154
|
+
* quantity: ...,
|
155
|
+
* currency: ...,
|
156
|
+
* pricePerToken: ...,
|
157
|
+
* allowlistProof: ...,
|
158
|
+
* });
|
159
|
+
* ```
|
160
|
+
*/
|
161
|
+
export function encodeVerifyClaim(options: VerifyClaimParams) {
|
162
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
163
|
+
// we can do this because we know the specific formats of the values
|
164
|
+
return (FN_SELECTOR +
|
165
|
+
encodeVerifyClaimParams(options).slice(
|
166
|
+
2,
|
167
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Decodes the result of the verifyClaim function call.
|
172
|
+
* @param result - The hexadecimal result to decode.
|
173
|
+
* @returns The decoded result as per the FN_OUTPUTS definition.
|
174
|
+
* @extension ERC1155
|
175
|
+
* @example
|
176
|
+
* ```ts
|
177
|
+
* import { decodeVerifyClaimResult } from "thirdweb/extensions/erc1155";
|
178
|
+
* const result = decodeVerifyClaimResultResult("...");
|
179
|
+
* ```
|
180
|
+
*/
|
181
|
+
export function decodeVerifyClaimResult(result: Hex) {
|
182
|
+
return decodeAbiParameters(FN_OUTPUTS, result)[0];
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Calls the "verifyClaim" function on the contract.
|
187
|
+
* @param options - The options for the verifyClaim function.
|
188
|
+
* @returns The parsed result of the function call.
|
189
|
+
* @extension ERC1155
|
190
|
+
* @example
|
191
|
+
* ```ts
|
192
|
+
* import { verifyClaim } from "thirdweb/extensions/erc1155";
|
193
|
+
*
|
194
|
+
* const result = await verifyClaim({
|
195
|
+
* contract,
|
196
|
+
* conditionId: ...,
|
197
|
+
* claimer: ...,
|
198
|
+
* tokenId: ...,
|
199
|
+
* quantity: ...,
|
200
|
+
* currency: ...,
|
201
|
+
* pricePerToken: ...,
|
202
|
+
* allowlistProof: ...,
|
203
|
+
* });
|
204
|
+
*
|
205
|
+
* ```
|
206
|
+
*/
|
207
|
+
export async function verifyClaim(
|
208
|
+
options: BaseTransactionOptions<VerifyClaimParams>,
|
209
|
+
) {
|
210
|
+
return readContract({
|
211
|
+
contract: options.contract,
|
212
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
213
|
+
params: [
|
214
|
+
options.conditionId,
|
215
|
+
options.claimer,
|
216
|
+
options.tokenId,
|
217
|
+
options.quantity,
|
218
|
+
options.currency,
|
219
|
+
options.pricePerToken,
|
220
|
+
options.allowlistProof,
|
221
|
+
],
|
222
|
+
});
|
223
|
+
}
|
@@ -22,6 +22,7 @@ import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
|
|
22
22
|
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
|
23
23
|
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
|
24
24
|
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
|
25
|
+
import { canClaim } from "./drops/read/canClaim.js";
|
25
26
|
import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js";
|
26
27
|
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
|
27
28
|
import { claimTo } from "./drops/write/claimTo.js";
|
@@ -130,6 +131,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
|
|
130
131
|
}),
|
131
132
|
account: TEST_ACCOUNT_C,
|
132
133
|
});
|
134
|
+
|
135
|
+
expect(
|
136
|
+
await canClaim({
|
137
|
+
contract,
|
138
|
+
claimer: TEST_ACCOUNT_C.address,
|
139
|
+
quantity: 1n,
|
140
|
+
tokenId: 0n,
|
141
|
+
}),
|
142
|
+
).toMatchInlineSnapshot(`
|
143
|
+
{
|
144
|
+
"result": true,
|
145
|
+
}
|
146
|
+
`);
|
147
|
+
|
133
148
|
const claimTx = claimTo({
|
134
149
|
contract,
|
135
150
|
to: TEST_ACCOUNT_C.address,
|
@@ -205,6 +220,33 @@ describe.runIf(process.env.TW_SECRET_KEY)(
|
|
205
220
|
balanceOf({ contract, owner: TEST_ACCOUNT_B.address, tokenId }),
|
206
221
|
).resolves.toBe(0n);
|
207
222
|
|
223
|
+
expect(
|
224
|
+
await canClaim({
|
225
|
+
contract,
|
226
|
+
claimer: TEST_ACCOUNT_C.address,
|
227
|
+
quantity: 1n,
|
228
|
+
tokenId,
|
229
|
+
}),
|
230
|
+
).toMatchInlineSnapshot(`
|
231
|
+
{
|
232
|
+
"result": true,
|
233
|
+
}
|
234
|
+
`);
|
235
|
+
|
236
|
+
expect(
|
237
|
+
await canClaim({
|
238
|
+
contract,
|
239
|
+
claimer: TEST_ACCOUNT_B.address,
|
240
|
+
quantity: 1n,
|
241
|
+
tokenId,
|
242
|
+
}),
|
243
|
+
).toMatchInlineSnapshot(`
|
244
|
+
{
|
245
|
+
"reason": "DropClaimExceedLimit - 0,1",
|
246
|
+
"result": false,
|
247
|
+
}
|
248
|
+
`);
|
249
|
+
|
208
250
|
await sendAndConfirmTransaction({
|
209
251
|
account: TEST_ACCOUNT_C,
|
210
252
|
transaction: claimTo({
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { extractErrorResult } from "../../../../transaction/extract-error.js";
|
2
|
+
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
|
3
|
+
import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
|
4
|
+
import { verifyClaim } from "../../__generated__/DropERC1155/read/verifyClaim.js";
|
5
|
+
import { getActiveClaimConditionId } from "../../__generated__/IDrop1155/read/getActiveClaimConditionId.js";
|
6
|
+
|
7
|
+
export type CanClaimParams = {
|
8
|
+
claimer: string;
|
9
|
+
quantity: bigint;
|
10
|
+
tokenId: bigint;
|
11
|
+
from?: string;
|
12
|
+
};
|
13
|
+
|
14
|
+
export type CanClaimResult = {
|
15
|
+
result: boolean;
|
16
|
+
reason?: string;
|
17
|
+
};
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Check if a user can claim a drop.
|
21
|
+
*
|
22
|
+
* @param options - The options for the transaction.
|
23
|
+
* @returns Whether the user can claim the drop.
|
24
|
+
*
|
25
|
+
* @example
|
26
|
+
* ```ts
|
27
|
+
* const claimResult = await canClaim({
|
28
|
+
* contract: contract,
|
29
|
+
* claimer: "0x1234567890123456789012345678901234567890",
|
30
|
+
* quantity: "1",
|
31
|
+
* tokenId: 0n,
|
32
|
+
* });
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* @extension ERC1155
|
36
|
+
*/
|
37
|
+
export async function canClaim(
|
38
|
+
options: BaseTransactionOptions<CanClaimParams>,
|
39
|
+
): Promise<CanClaimResult> {
|
40
|
+
const [conditionId, { quantity, currency, pricePerToken, allowlistProof }] =
|
41
|
+
await Promise.all([
|
42
|
+
getActiveClaimConditionId({
|
43
|
+
contract: options.contract,
|
44
|
+
tokenId: options.tokenId,
|
45
|
+
}),
|
46
|
+
getClaimParams({
|
47
|
+
contract: options.contract,
|
48
|
+
quantity: options.quantity,
|
49
|
+
to: options.claimer,
|
50
|
+
type: "erc1155",
|
51
|
+
tokenId: options.tokenId,
|
52
|
+
from: options.from,
|
53
|
+
}),
|
54
|
+
]);
|
55
|
+
try {
|
56
|
+
await verifyClaim({
|
57
|
+
contract: options.contract,
|
58
|
+
claimer: options.claimer,
|
59
|
+
quantity,
|
60
|
+
currency,
|
61
|
+
pricePerToken,
|
62
|
+
allowlistProof,
|
63
|
+
conditionId,
|
64
|
+
tokenId: options.tokenId,
|
65
|
+
});
|
66
|
+
return {
|
67
|
+
result: true,
|
68
|
+
};
|
69
|
+
} catch (error) {
|
70
|
+
return {
|
71
|
+
result: false,
|
72
|
+
reason: await extractErrorResult({ error, contract: options.contract }),
|
73
|
+
};
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,213 @@
|
|
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 "verifyClaim" function.
|
11
|
+
*/
|
12
|
+
export type VerifyClaimParams = {
|
13
|
+
conditionId: AbiParameterToPrimitiveType<{
|
14
|
+
type: "uint256";
|
15
|
+
name: "_conditionId";
|
16
|
+
}>;
|
17
|
+
claimer: AbiParameterToPrimitiveType<{ type: "address"; name: "_claimer" }>;
|
18
|
+
quantity: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_quantity" }>;
|
19
|
+
currency: AbiParameterToPrimitiveType<{ type: "address"; name: "_currency" }>;
|
20
|
+
pricePerToken: AbiParameterToPrimitiveType<{
|
21
|
+
type: "uint256";
|
22
|
+
name: "_pricePerToken";
|
23
|
+
}>;
|
24
|
+
allowlistProof: AbiParameterToPrimitiveType<{
|
25
|
+
type: "tuple";
|
26
|
+
name: "_allowlistProof";
|
27
|
+
components: [
|
28
|
+
{ type: "bytes32[]"; name: "proof" },
|
29
|
+
{ type: "uint256"; name: "quantityLimitPerWallet" },
|
30
|
+
{ type: "uint256"; name: "pricePerToken" },
|
31
|
+
{ type: "address"; name: "currency" },
|
32
|
+
];
|
33
|
+
}>;
|
34
|
+
};
|
35
|
+
|
36
|
+
export const FN_SELECTOR = "0x23a2902b" as const;
|
37
|
+
const FN_INPUTS = [
|
38
|
+
{
|
39
|
+
type: "uint256",
|
40
|
+
name: "_conditionId",
|
41
|
+
},
|
42
|
+
{
|
43
|
+
type: "address",
|
44
|
+
name: "_claimer",
|
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
|
+
] as const;
|
81
|
+
const FN_OUTPUTS = [
|
82
|
+
{
|
83
|
+
type: "bool",
|
84
|
+
name: "isOverride",
|
85
|
+
},
|
86
|
+
] as const;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Checks if the `verifyClaim` method is supported by the given contract.
|
90
|
+
* @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.
|
91
|
+
* @returns A boolean indicating if the `verifyClaim` method is supported.
|
92
|
+
* @extension ERC20
|
93
|
+
* @example
|
94
|
+
* ```ts
|
95
|
+
* import { isVerifyClaimSupported } from "thirdweb/extensions/erc20";
|
96
|
+
* const supported = isVerifyClaimSupported(["0x..."]);
|
97
|
+
* ```
|
98
|
+
*/
|
99
|
+
export function isVerifyClaimSupported(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 "verifyClaim" function.
|
108
|
+
* @param options - The options for the verifyClaim function.
|
109
|
+
* @returns The encoded ABI parameters.
|
110
|
+
* @extension ERC20
|
111
|
+
* @example
|
112
|
+
* ```ts
|
113
|
+
* import { encodeVerifyClaimParams } from "thirdweb/extensions/erc20";
|
114
|
+
* const result = encodeVerifyClaimParams({
|
115
|
+
* conditionId: ...,
|
116
|
+
* claimer: ...,
|
117
|
+
* quantity: ...,
|
118
|
+
* currency: ...,
|
119
|
+
* pricePerToken: ...,
|
120
|
+
* allowlistProof: ...,
|
121
|
+
* });
|
122
|
+
* ```
|
123
|
+
*/
|
124
|
+
export function encodeVerifyClaimParams(options: VerifyClaimParams) {
|
125
|
+
return encodeAbiParameters(FN_INPUTS, [
|
126
|
+
options.conditionId,
|
127
|
+
options.claimer,
|
128
|
+
options.quantity,
|
129
|
+
options.currency,
|
130
|
+
options.pricePerToken,
|
131
|
+
options.allowlistProof,
|
132
|
+
]);
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Encodes the "verifyClaim" function into a Hex string with its parameters.
|
137
|
+
* @param options - The options for the verifyClaim function.
|
138
|
+
* @returns The encoded hexadecimal string.
|
139
|
+
* @extension ERC20
|
140
|
+
* @example
|
141
|
+
* ```ts
|
142
|
+
* import { encodeVerifyClaim } from "thirdweb/extensions/erc20";
|
143
|
+
* const result = encodeVerifyClaim({
|
144
|
+
* conditionId: ...,
|
145
|
+
* claimer: ...,
|
146
|
+
* quantity: ...,
|
147
|
+
* currency: ...,
|
148
|
+
* pricePerToken: ...,
|
149
|
+
* allowlistProof: ...,
|
150
|
+
* });
|
151
|
+
* ```
|
152
|
+
*/
|
153
|
+
export function encodeVerifyClaim(options: VerifyClaimParams) {
|
154
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
155
|
+
// we can do this because we know the specific formats of the values
|
156
|
+
return (FN_SELECTOR +
|
157
|
+
encodeVerifyClaimParams(options).slice(
|
158
|
+
2,
|
159
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Decodes the result of the verifyClaim function call.
|
164
|
+
* @param result - The hexadecimal result to decode.
|
165
|
+
* @returns The decoded result as per the FN_OUTPUTS definition.
|
166
|
+
* @extension ERC20
|
167
|
+
* @example
|
168
|
+
* ```ts
|
169
|
+
* import { decodeVerifyClaimResult } from "thirdweb/extensions/erc20";
|
170
|
+
* const result = decodeVerifyClaimResultResult("...");
|
171
|
+
* ```
|
172
|
+
*/
|
173
|
+
export function decodeVerifyClaimResult(result: Hex) {
|
174
|
+
return decodeAbiParameters(FN_OUTPUTS, result)[0];
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Calls the "verifyClaim" function on the contract.
|
179
|
+
* @param options - The options for the verifyClaim function.
|
180
|
+
* @returns The parsed result of the function call.
|
181
|
+
* @extension ERC20
|
182
|
+
* @example
|
183
|
+
* ```ts
|
184
|
+
* import { verifyClaim } from "thirdweb/extensions/erc20";
|
185
|
+
*
|
186
|
+
* const result = await verifyClaim({
|
187
|
+
* contract,
|
188
|
+
* conditionId: ...,
|
189
|
+
* claimer: ...,
|
190
|
+
* quantity: ...,
|
191
|
+
* currency: ...,
|
192
|
+
* pricePerToken: ...,
|
193
|
+
* allowlistProof: ...,
|
194
|
+
* });
|
195
|
+
*
|
196
|
+
* ```
|
197
|
+
*/
|
198
|
+
export async function verifyClaim(
|
199
|
+
options: BaseTransactionOptions<VerifyClaimParams>,
|
200
|
+
) {
|
201
|
+
return readContract({
|
202
|
+
contract: options.contract,
|
203
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
204
|
+
params: [
|
205
|
+
options.conditionId,
|
206
|
+
options.claimer,
|
207
|
+
options.quantity,
|
208
|
+
options.currency,
|
209
|
+
options.pricePerToken,
|
210
|
+
options.allowlistProof,
|
211
|
+
],
|
212
|
+
});
|
213
|
+
}
|
@@ -14,6 +14,7 @@ import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value
|
|
14
14
|
import { toEther } from "../../utils/units.js";
|
15
15
|
import { name } from "../common/read/name.js";
|
16
16
|
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
|
17
|
+
import { canClaim } from "./drops/read/canClaim.js";
|
17
18
|
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
|
18
19
|
import { claimTo } from "./drops/write/claimTo.js";
|
19
20
|
import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
|
@@ -76,6 +77,18 @@ describe.runIf(process.env.TW_SECRET_KEY)(
|
|
76
77
|
}),
|
77
78
|
account: TEST_ACCOUNT_A,
|
78
79
|
});
|
80
|
+
|
81
|
+
expect(
|
82
|
+
await canClaim({
|
83
|
+
contract,
|
84
|
+
claimer: TEST_ACCOUNT_A.address,
|
85
|
+
quantity: "1",
|
86
|
+
}),
|
87
|
+
).toMatchInlineSnapshot(`
|
88
|
+
{
|
89
|
+
"result": true,
|
90
|
+
}
|
91
|
+
`);
|
79
92
|
const claimTx = claimTo({
|
80
93
|
contract,
|
81
94
|
to: TEST_ACCOUNT_A.address,
|
@@ -180,6 +193,31 @@ describe.runIf(process.env.TW_SECRET_KEY)(
|
|
180
193
|
}
|
181
194
|
`);
|
182
195
|
|
196
|
+
expect(
|
197
|
+
await canClaim({
|
198
|
+
contract,
|
199
|
+
claimer: TEST_ACCOUNT_A.address,
|
200
|
+
quantity: "1",
|
201
|
+
}),
|
202
|
+
).toMatchInlineSnapshot(`
|
203
|
+
{
|
204
|
+
"result": true,
|
205
|
+
}
|
206
|
+
`);
|
207
|
+
|
208
|
+
expect(
|
209
|
+
await canClaim({
|
210
|
+
contract,
|
211
|
+
claimer: TEST_ACCOUNT_B.address,
|
212
|
+
quantity: "1",
|
213
|
+
}),
|
214
|
+
).toMatchInlineSnapshot(`
|
215
|
+
{
|
216
|
+
"reason": "DropClaimExceedLimit - 0,1000000000000000000",
|
217
|
+
"result": false,
|
218
|
+
}
|
219
|
+
`);
|
220
|
+
|
183
221
|
await sendAndConfirmTransaction({
|
184
222
|
account: TEST_ACCOUNT_A,
|
185
223
|
transaction: claimTo({
|