Skip to content

Commit 3a0568e

Browse files
authored
fix setClaimCondition for DropSinglePhase1155 (#353)
* fix setClaimCondition for DropSinglePhase1155: generate unique conditionId for every tokenId * remove unused imports
1 parent c2aa16c commit 3a0568e

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

contracts/extension/DropSinglePhase1155.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ abstract contract DropSinglePhase1155 is IDropSinglePhase1155 {
7474

7575
uint256 supplyClaimedAlready = condition.supplyClaimed;
7676

77-
if (_resetClaimEligibility) {
77+
if (targetConditionId == bytes32(0) || _resetClaimEligibility) {
7878
supplyClaimedAlready = 0;
79-
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number));
79+
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number, _tokenId));
8080
}
8181

8282
if (supplyClaimedAlready > _condition.maxClaimableSupply) {

contracts/legacy-contracts/extension/DropSinglePhase1155_V1.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ abstract contract DropSinglePhase1155_V1 is IDropSinglePhase1155_V1 {
115115

116116
uint256 supplyClaimedAlready = condition.supplyClaimed;
117117

118-
if (_resetClaimEligibility) {
118+
if (targetConditionId == bytes32(0) || _resetClaimEligibility) {
119119
supplyClaimedAlready = 0;
120-
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number));
120+
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number, _tokenId));
121121
}
122122

123123
if (supplyClaimedAlready > _condition.maxClaimableSupply) {

src/test/sdk/extension/DropSinglePhase1155.t.sol

+32
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,43 @@ contract ExtensionDropSinglePhase1155 is DSTest, Test {
192192
ext.claim(receiver, 0, 10, address(0), 0, alp, "");
193193
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 10);
194194

195+
vm.roll(100);
195196
ext.setClaimConditions(0, conditions[0], true);
196197
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 0);
197198

198199
vm.prank(receiver, receiver);
199200
ext.claim(receiver, 0, 10, address(0), 0, alp, "");
200201
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 10);
201202
}
203+
204+
/**
205+
* note: Testing state; unique condition Id for every token.
206+
*/
207+
function test_state_claimCondition_uniqueConditionId() public {
208+
ext.setCondition(true);
209+
vm.warp(1);
210+
211+
address receiver = address(0x123);
212+
address claimer1 = address(0x345);
213+
bytes32[] memory proofs = new bytes32[](0);
214+
uint256 _tokenId = 0;
215+
216+
MyDropSinglePhase1155.AllowlistProof memory alp;
217+
alp.proof = proofs;
218+
219+
MyDropSinglePhase1155.ClaimCondition[] memory conditions = new MyDropSinglePhase1155.ClaimCondition[](1);
220+
conditions[0].maxClaimableSupply = 100;
221+
conditions[0].quantityLimitPerWallet = 100;
222+
223+
ext.setClaimConditions(_tokenId, conditions[0], false);
224+
225+
vm.prank(claimer1, claimer1);
226+
ext.claim(receiver, _tokenId, 100, address(0), 0, alp, "");
227+
228+
assertEq(ext.getSupplyClaimedByWallet(_tokenId, claimer1), 100);
229+
230+
// supply claimed for other tokenIds should be 0
231+
assertEq(ext.getSupplyClaimedByWallet(1, claimer1), 0);
232+
assertEq(ext.getSupplyClaimedByWallet(2, claimer1), 0);
233+
}
202234
}

0 commit comments

Comments
 (0)