Skip to content

Commit 54f0294

Browse files
committed
[Update] Enhance ERC1155 and ERC20 claim condition handling and detection (#4397)
<!-- start pr-codex --> ## PR-Codex overview This PR enhances ERC1155 Drop ClaimCondition functionality. ### Detailed summary - Added `isGetActiveClaimConditionSupported` function - Updated `getActiveClaimCondition` and `claimTo` methods - Added `isClaimToSupported` function - Updated `lazyMint` method and added `isLazyMintSupported` function > The following files were skipped due to too many changes: `packages/thirdweb/src/extensions/erc1155/drops/write/setClaimConditions.ts`, `packages/thirdweb/src/extensions/erc20/drops/write/setClaimConditions.ts`, `packages/thirdweb/src/extensions/erc20/drops/write/claimTo.ts`, `packages/thirdweb/src/extensions/erc1155/drops/read/getClaimConditions.ts`, `packages/thirdweb/src/extensions/erc1155/drops/write/resetClaimEligibility.ts`, `packages/thirdweb/src/extensions/erc1155/__generated__/IDrop1155/read/claimCondition.ts`, `packages/thirdweb/src/extensions/erc1155/drop1155.test.ts` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 52c931a commit 54f0294

File tree

18 files changed

+584
-33
lines changed

18 files changed

+584
-33
lines changed

.changeset/little-shrimps-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
[Extensions] Erc1155 Drop ClaimCondition enhancements

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"function claim(address receiver, uint256 tokenId, uint256 quantity, address currency, uint256 pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) allowlistProof, bytes data) payable",
55
"function setClaimConditions(uint256 tokenId, (uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata)[] phases, bool resetClaimEligibility)",
66
"function getActiveClaimConditionId(uint256 _tokenId) view returns (uint256)",
7-
"function getClaimConditionById(uint256 _tokenId, uint256 _conditionId) view returns ((uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) condition)"
7+
"function getClaimConditionById(uint256 _tokenId, uint256 _conditionId) view returns ((uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) condition)",
8+
"function claimCondition(uint256 _tokenId) view returns (uint256 currentStartId, uint256 count)"
89
]

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,53 @@ export { freezeMetadata } from "../../extensions/erc1155/__generated__/INFTMetad
7979
* DROPS extension for ERC1155
8080
*/
8181
// READ
82-
export { getActiveClaimCondition } from "../../extensions/erc1155/drops/read/getActiveClaimCondition.js";
82+
export {
83+
getActiveClaimCondition,
84+
isGetActiveClaimConditionSupported,
85+
} from "../../extensions/erc1155/drops/read/getActiveClaimCondition.js";
86+
export {
87+
getClaimConditionById,
88+
type GetClaimConditionByIdParams,
89+
isGetClaimConditionByIdSupported,
90+
} from "../../extensions/erc1155/__generated__/IDrop1155/read/getClaimConditionById.js";
91+
export {
92+
getClaimConditions,
93+
type GetClaimConditionsParams,
94+
isGetClaimConditionsSupported,
95+
} from "../../extensions/erc1155/drops/read/getClaimConditions.js";
96+
97+
// WRITE
8398
export {
8499
claimTo,
85100
type ClaimToParams,
101+
isClaimToSupported,
86102
} from "../../extensions/erc1155/drops/write/claimTo.js";
87-
88-
// WRITE
89103
export {
90104
lazyMint,
91105
type LazyMintParams,
106+
isLazyMintSupported,
92107
} from "../../extensions/erc1155/write/lazyMint.js";
93108
export {
94109
setClaimConditions,
95110
type SetClaimConditionsParams,
111+
isSetClaimConditionsSupported,
96112
} from "../../extensions/erc1155/drops/write/setClaimConditions.js";
113+
export {
114+
resetClaimEligibility,
115+
type ResetClaimEligibilityParams,
116+
isResetClaimEligibilitySupported,
117+
} from "../../extensions/erc1155/drops/write/resetClaimEligibility.js";
118+
119+
// METADATA
97120
export {
98121
updateMetadata,
99122
type UpdateMetadataParams,
100123
} from "../../extensions/erc1155/drops/write/updateMetadata.js";
101-
102124
export {
103125
updateTokenURI,
104126
type UpdateTokenURIParams,
105127
} from "../../extensions/erc1155/write/updateTokenURI.js";
106128

107-
export {
108-
getClaimConditionById,
109-
type GetClaimConditionByIdParams,
110-
} from "../../extensions/erc1155/__generated__/IDrop1155/read/getClaimConditionById.js";
111-
112129
/**
113130
* SIGNATURE extension for ERC1155
114131
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export {
8585
export {
8686
setClaimConditions,
8787
type SetClaimConditionsParams,
88+
isSetClaimConditionsSupported,
8889
} from "../../extensions/erc20/drops/write/setClaimConditions.js";
8990
export {
9091
resetClaimEligibility,

packages/thirdweb/src/extensions/erc1155/__generated__/IDrop1155/read/claimCondition.ts

Lines changed: 131 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: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TEST_CLIENT } from "../../../test/src/test-clients.js";
55
import {
66
TEST_ACCOUNT_A,
77
TEST_ACCOUNT_B,
8+
TEST_ACCOUNT_D,
89
} from "../../../test/src/test-wallets.js";
910
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1011
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
@@ -14,7 +15,9 @@ import { getContractMetadata } from "../common/read/getContractMetadata.js";
1415
import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
1516
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
1617
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
18+
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
1719
import { claimTo } from "./drops/write/claimTo.js";
20+
import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
1821
import { setClaimConditions } from "./drops/write/setClaimConditions.js";
1922
import { getNFT } from "./read/getNFT.js";
2023
import { lazyMint } from "./write/lazyMint.js";
@@ -64,14 +67,16 @@ describe.runIf(process.env.TW_SECRET_KEY)(
6467
{ name: "Test NFT 2" },
6568
{ name: "Test NFT 3" },
6669
{ name: "Test NFT 4" },
70+
{ name: "Test NFT 5" },
71+
{ name: "Test NFT 6" },
6772
],
6873
});
6974
await sendAndConfirmTransaction({
7075
transaction: mintTx,
7176
account: TEST_ACCOUNT_A,
7277
});
7378

74-
await expect(nextTokenIdToMint({ contract })).resolves.toBe(4n);
79+
await expect(nextTokenIdToMint({ contract })).resolves.toBe(6n);
7580
await expect(
7681
getNFT({ contract, tokenId: 0n }),
7782
).resolves.toMatchInlineSnapshot(`
@@ -82,7 +87,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
8287
},
8388
"owner": null,
8489
"supply": 0n,
85-
"tokenURI": "ipfs://QmUfspS2uU9roYLJveebbY5geYaNR4KkZAsMkb5pPRtc7a/0",
90+
"tokenURI": "ipfs://QmTo68Dm1ntSp2BHLmE9gesS6ELuXosRz5mAgFCK6tfsRk/0",
8691
"type": "ERC1155",
8792
}
8893
`);
@@ -245,7 +250,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
245250
[TransactionError: Error - !Qty
246251
247252
contract: ${contract.address}
248-
chainId: 31337]
253+
chainId: ${contract.chain.id}]
249254
`);
250255

251256
await sendAndConfirmTransaction({
@@ -305,5 +310,102 @@ describe.runIf(process.env.TW_SECRET_KEY)(
305310
balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId }),
306311
).resolves.toBe(1n);
307312
});
313+
314+
it("should be able to retrieve multiple phases", async () => {
315+
await sendAndConfirmTransaction({
316+
transaction: setClaimConditions({
317+
contract,
318+
tokenId: 5n,
319+
phases: [
320+
{
321+
maxClaimablePerWallet: 1n,
322+
startTime: new Date(0),
323+
},
324+
{
325+
maxClaimablePerWallet: 2n,
326+
startTime: new Date(),
327+
},
328+
],
329+
}),
330+
account: TEST_ACCOUNT_A,
331+
});
332+
333+
const phases = await getClaimConditions({ contract, tokenId: 5n });
334+
expect(phases).toHaveLength(2);
335+
expect(phases[0]?.quantityLimitPerWallet).toBe(1n);
336+
expect(phases[1]?.quantityLimitPerWallet).toBe(2n);
337+
});
338+
339+
it("should be able to reset claim eligibility", async () => {
340+
// set claim conditions to only allow one claim
341+
await sendAndConfirmTransaction({
342+
transaction: setClaimConditions({
343+
contract,
344+
tokenId: 6n,
345+
phases: [
346+
{
347+
maxClaimablePerWallet: 1n,
348+
},
349+
],
350+
}),
351+
account: TEST_ACCOUNT_A,
352+
});
353+
// claim one token
354+
await sendAndConfirmTransaction({
355+
transaction: claimTo({
356+
tokenId: 6n,
357+
contract,
358+
// fresh account to avoid any previous claims
359+
to: TEST_ACCOUNT_D.address,
360+
quantity: 1n,
361+
}),
362+
// fresh account to avoid any previous claims
363+
account: TEST_ACCOUNT_D,
364+
});
365+
// check that the account has claimed one token
366+
await expect(
367+
balanceOf({ tokenId: 6n, contract, owner: TEST_ACCOUNT_D.address }),
368+
).resolves.toBe(1n);
369+
// attempt to claim another token (this should fail)
370+
await expect(
371+
sendAndConfirmTransaction({
372+
transaction: claimTo({
373+
tokenId: 6n,
374+
contract,
375+
to: TEST_ACCOUNT_D.address,
376+
quantity: 1n,
377+
}),
378+
account: TEST_ACCOUNT_D,
379+
}),
380+
).rejects.toThrowErrorMatchingInlineSnapshot(`
381+
[TransactionError: Error - !Qty
382+
383+
contract: ${contract.address}
384+
chainId: ${contract.chain.id}]
385+
`);
386+
387+
// reset claim eligibility
388+
await sendAndConfirmTransaction({
389+
transaction: resetClaimEligibility({
390+
tokenId: 6n,
391+
contract,
392+
}),
393+
account: TEST_ACCOUNT_A,
394+
});
395+
// attempt to claim another token (this should succeed)
396+
await sendAndConfirmTransaction({
397+
transaction: claimTo({
398+
tokenId: 6n,
399+
contract,
400+
to: TEST_ACCOUNT_D.address,
401+
quantity: 1n,
402+
}),
403+
account: TEST_ACCOUNT_D,
404+
});
405+
// check that the account has claimed two tokens
406+
await expect(
407+
balanceOf({ tokenId: 6n, contract, owner: TEST_ACCOUNT_D.address }),
408+
).resolves.toBe(2n);
409+
});
308410
},
309411
);

0 commit comments

Comments
 (0)