Skip to content

Commit 159ffbf

Browse files
[SDK] feat: Add verifyClaim export and canClaim function (#6234)
Fixes TOOL-3381 <!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on exposing the `canClaim` extension function for ERC20, ERC721, and ERC1155 drops, allowing for better claim verification and improving the overall functionality of the drops system. ### Detailed summary - Added `canClaim` function to `erc20`, `erc721`, and `erc1155` extensions. - Updated tests to include `canClaim` functionality. - Modified JSON ABI files to include `verifyClaim` function. - Adjusted gas values in tests. - Enhanced error handling in `extract-error.ts`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 0c1bb6c commit 159ffbf

File tree

20 files changed

+988
-19
lines changed

20 files changed

+988
-19
lines changed

.changeset/orange-ravens-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Expose `canClaim` extension function for erc20/721/1155 drops

packages/thirdweb/scripts/generate/abis/erc1155/DropERC1155.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply)",
33
"function setSaleRecipientForToken(uint256 _tokenId, address _saleRecipient)",
44
"function updateBatchBaseURI(uint256 _index, string calldata _uri)",
5-
"function freezeBatchBaseURI(uint256 _index)"
5+
"function freezeBatchBaseURI(uint256 _index)",
6+
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _tokenId, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
67
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
3+
]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
"function updateBatchBaseURI(uint256 _index, string calldata _uri)",
33
"function freezeBatchBaseURI(uint256 _index)",
4-
"function setMaxTotalSupply(uint256 _maxTotalSupply)"
4+
"function setMaxTotalSupply(uint256 _maxTotalSupply)",
5+
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
56
]

packages/thirdweb/src/exports/extensions/erc1155.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ export {
107107
type GetClaimConditionsParams,
108108
isGetClaimConditionsSupported,
109109
} from "../../extensions/erc1155/drops/read/getClaimConditions.js";
110+
export {
111+
canClaim,
112+
type CanClaimParams,
113+
type CanClaimResult,
114+
} from "../../extensions/erc1155/drops/read/canClaim.js";
110115

111116
// WRITE
112117
export {

packages/thirdweb/src/exports/extensions/erc20.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export {
7575
getActiveClaimCondition,
7676
isGetActiveClaimConditionSupported,
7777
} from "../../extensions/erc20/drops/read/getActiveClaimCondition.js";
78+
export {
79+
canClaim,
80+
type CanClaimParams,
81+
type CanClaimResult,
82+
} from "../../extensions/erc20/drops/read/canClaim.js";
7883

7984
// WRITE
8085
export {

packages/thirdweb/src/exports/extensions/erc721.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export {
109109
getActiveClaimCondition,
110110
isGetActiveClaimConditionSupported,
111111
} from "../../extensions/erc721/drops/read/getActiveClaimCondition.js";
112+
export {
113+
canClaim,
114+
type CanClaimParams,
115+
type CanClaimResult,
116+
} from "../../extensions/erc721/drops/read/canClaim.js";
112117

113118
// WRITE
114119
export {

packages/thirdweb/src/extensions/erc1155/__generated__/DropERC1155/read/verifyClaim.ts

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/thirdweb/src/extensions/erc1155/drop1155.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
2222
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
2323
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
2424
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
25+
import { canClaim } from "./drops/read/canClaim.js";
2526
import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js";
2627
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
2728
import { claimTo } from "./drops/write/claimTo.js";
@@ -130,6 +131,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
130131
}),
131132
account: TEST_ACCOUNT_C,
132133
});
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+
133148
const claimTx = claimTo({
134149
contract,
135150
to: TEST_ACCOUNT_C.address,
@@ -205,6 +220,33 @@ describe.runIf(process.env.TW_SECRET_KEY)(
205220
balanceOf({ contract, owner: TEST_ACCOUNT_B.address, tokenId }),
206221
).resolves.toBe(0n);
207222

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+
208250
await sendAndConfirmTransaction({
209251
account: TEST_ACCOUNT_C,
210252
transaction: claimTo({

0 commit comments

Comments
 (0)