Skip to content

Commit 25cb9a6

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
Merge branch 'main' of https://github.com/nftlabs/nftlabs-protocols into multiwrap
2 parents 08fc02a + 6b6aea6 commit 25cb9a6

File tree

19 files changed

+521
-160
lines changed

19 files changed

+521
-160
lines changed

contracts/drop/DropERC1155.sol

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ contract DropERC1155 is
4242
//////////////////////////////////////////////////////////////*/
4343

4444
bytes32 private constant MODULE_TYPE = bytes32("DropERC1155");
45-
uint256 private constant VERSION = 1;
45+
uint256 private constant VERSION = 2;
4646

4747
// Token name
4848
string public name;
@@ -73,14 +73,14 @@ contract DropERC1155 is
7373
/// @dev The address that receives all platform fees from all sales.
7474
address private platformFeeRecipient;
7575

76+
/// @dev The % of primary sales collected as platform fees.
77+
uint16 private platformFeeBps;
78+
7679
/// @dev The recipient of who gets the royalty.
7780
address private royaltyRecipient;
7881

7982
/// @dev The (default) address that receives all royalty value.
80-
uint128 private royaltyBps;
81-
82-
/// @dev The % of primary sales collected as platform fees.
83-
uint128 private platformFeeBps;
83+
uint16 private royaltyBps;
8484

8585
/// @dev Contract level metadata.
8686
string public contractURI;
@@ -149,11 +149,11 @@ contract DropERC1155 is
149149
name = _name;
150150
symbol = _symbol;
151151
royaltyRecipient = _royaltyRecipient;
152-
royaltyBps = _royaltyBps;
152+
royaltyBps = uint16(_royaltyBps);
153153
platformFeeRecipient = _platformFeeRecipient;
154154
primarySaleRecipient = _saleRecipient;
155155
contractURI = _contractURI;
156-
platformFeeBps = _platformFeeBps;
156+
platformFeeBps = uint16(_platformFeeBps);
157157
_owner = _defaultAdmin;
158158

159159
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
@@ -257,10 +257,14 @@ contract DropERC1155 is
257257
// Get the active claim condition index.
258258
uint256 activeConditionId = getActiveClaimConditionId(_tokenId);
259259

260-
// Verify claim validity. If not valid, revert.
261-
verifyClaim(activeConditionId, _msgSender(), _tokenId, _quantity, _currency, _pricePerToken);
260+
/**
261+
* We make allowlist checks (i.e. verifyClaimMerkleProof) before verifying the claim's general
262+
* validity (i.e. verifyClaim) because we give precedence to the check of allow list quantity
263+
* restriction over the check of the general claim condition's quantityLimitPerTransaction
264+
* restriction.
265+
*/
262266

263-
// Verify inclusion in allowlist
267+
// Verify inclusion in allowlist.
264268
(bool validMerkleProof, uint256 merkleProofIndex) = verifyClaimMerkleProof(
265269
activeConditionId,
266270
_msgSender(),
@@ -270,8 +274,23 @@ contract DropERC1155 is
270274
_proofMaxQuantityPerTransaction
271275
);
272276

277+
// Verify claim validity. If not valid, revert.
278+
bool toVerifyMaxQuantityPerTransaction = _proofMaxQuantityPerTransaction == 0;
279+
verifyClaim(
280+
activeConditionId,
281+
_msgSender(),
282+
_tokenId,
283+
_quantity,
284+
_currency,
285+
_pricePerToken,
286+
toVerifyMaxQuantityPerTransaction
287+
);
288+
273289
if (validMerkleProof && _proofMaxQuantityPerTransaction > 0) {
274-
// Mark the claimer's use of their position in the allowlist.
290+
/**
291+
* Mark the claimer's use of their position in the allowlist. A spot in an allowlist
292+
* can be used only once.
293+
*/
275294
claimCondition[_tokenId].limitMerkleProofClaim[activeConditionId].set(merkleProofIndex);
276295
}
277296

@@ -317,8 +336,11 @@ contract DropERC1155 is
317336
"startTimestamp must be in ascending order."
318337
);
319338

339+
uint256 supplyClaimedAlready = condition.phases[newStartIndex + i].supplyClaimed;
340+
require(supplyClaimedAlready < _phases[i].maxClaimableSupply, "max supply claimed already");
341+
320342
condition.phases[newStartIndex + i] = _phases[i];
321-
condition.phases[newStartIndex + i].supplyClaimed = 0;
343+
condition.phases[newStartIndex + i].supplyClaimed = supplyClaimedAlready;
322344

323345
lastConditionStartTimestamp = _phases[i].startTimestamp;
324346
}
@@ -402,16 +424,19 @@ contract DropERC1155 is
402424
uint256 _tokenId,
403425
uint256 _quantity,
404426
address _currency,
405-
uint256 _pricePerToken
427+
uint256 _pricePerToken,
428+
bool verifyMaxQuantityPerTransaction
406429
) public view {
407430
ClaimCondition memory currentClaimPhase = claimCondition[_tokenId].phases[_conditionId];
408431

409432
require(
410433
_currency == currentClaimPhase.currency && _pricePerToken == currentClaimPhase.pricePerToken,
411434
"invalid currency or price specified."
412435
);
436+
// If we're checking for an allowlist quantity restriction, ignore the general quantity restriction.
413437
require(
414-
_quantity > 0 && _quantity <= currentClaimPhase.quantityLimitPerTransaction,
438+
_quantity > 0 &&
439+
(!verifyMaxQuantityPerTransaction || _quantity <= currentClaimPhase.quantityLimitPerTransaction),
415440
"invalid quantity claimed."
416441
);
417442
require(
@@ -569,7 +594,7 @@ contract DropERC1155 is
569594
require(_royaltyBps <= MAX_BPS, "exceed royalty bps");
570595

571596
royaltyRecipient = _royaltyRecipient;
572-
royaltyBps = uint128(_royaltyBps);
597+
royaltyBps = uint16(_royaltyBps);
573598

574599
emit DefaultRoyalty(_royaltyRecipient, _royaltyBps);
575600
}
@@ -594,7 +619,7 @@ contract DropERC1155 is
594619
{
595620
require(_platformFeeBps <= MAX_BPS, "bps <= 10000.");
596621

597-
platformFeeBps = uint64(_platformFeeBps);
622+
platformFeeBps = uint16(_platformFeeBps);
598623
platformFeeRecipient = _platformFeeRecipient;
599624

600625
emit PlatformFeeInfoUpdated(_platformFeeRecipient, _platformFeeBps);

contracts/drop/DropERC20.sol

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ contract DropERC20 is
9696
string memory _contractURI,
9797
address[] memory _trustedForwarders,
9898
address _primarySaleRecipient,
99-
uint256 _platformFeeBps,
100-
address _platformFeeRecipient
99+
address _platformFeeRecipient,
100+
uint256 _platformFeeBps
101101
) external initializer {
102102
// Initialize inherited contracts, most base-like -> most derived.
103103
__ERC2771Context_init_unchained(_trustedForwarders);
@@ -181,10 +181,14 @@ contract DropERC20 is
181181
// Get the claim conditions.
182182
uint256 activeConditionId = getActiveClaimConditionId();
183183

184-
// Verify claim validity. If not valid, revert.
185-
verifyClaim(activeConditionId, _msgSender(), _quantity, _currency, _pricePerToken);
184+
/**
185+
* We make allowlist checks (i.e. verifyClaimMerkleProof) before verifying the claim's general
186+
* validity (i.e. verifyClaim) because we give precedence to the check of allow list quantity
187+
* restriction over the check of the general claim condition's quantityLimitPerTransaction
188+
* restriction.
189+
*/
186190

187-
// Verify inclusion in allowlist
191+
// Verify inclusion in allowlist.
188192
(bool validMerkleProof, uint256 merkleProofIndex) = verifyClaimMerkleProof(
189193
activeConditionId,
190194
_msgSender(),
@@ -193,8 +197,22 @@ contract DropERC20 is
193197
_proofMaxQuantityPerTransaction
194198
);
195199

200+
// Verify claim validity. If not valid, revert.
201+
bool toVerifyMaxQuantityPerTransaction = _proofMaxQuantityPerTransaction == 0;
202+
verifyClaim(
203+
activeConditionId,
204+
_msgSender(),
205+
_quantity,
206+
_currency,
207+
_pricePerToken,
208+
toVerifyMaxQuantityPerTransaction
209+
);
210+
196211
if (validMerkleProof && _proofMaxQuantityPerTransaction > 0) {
197-
// Mark the claimer's use of their position in the allowlist.
212+
/**
213+
* Mark the claimer's use of their position in the allowlist. A spot in an allowlist
214+
* can be used only once.
215+
*/
198216
claimCondition.limitMerkleProofClaim[activeConditionId].set(merkleProofIndex);
199217
}
200218

@@ -238,8 +256,11 @@ contract DropERC20 is
238256
"startTimestamp must be in ascending order."
239257
);
240258

259+
uint256 supplyClaimedAlready = claimCondition.phases[newStartIndex + i].supplyClaimed;
260+
require(supplyClaimedAlready < _phases[i].maxClaimableSupply, "max supply claimed already");
261+
241262
claimCondition.phases[newStartIndex + i] = _phases[i];
242-
claimCondition.phases[newStartIndex + i].supplyClaimed = 0;
263+
claimCondition.phases[newStartIndex + i].supplyClaimed = supplyClaimedAlready;
243264

244265
lastConditionStartTimestamp = _phases[i].startTimestamp;
245266
}
@@ -324,16 +345,19 @@ contract DropERC20 is
324345
address _claimer,
325346
uint256 _quantity,
326347
address _currency,
327-
uint256 _pricePerToken
348+
uint256 _pricePerToken,
349+
bool verifyMaxQuantityPerTransaction
328350
) public view {
329351
ClaimCondition memory currentClaimPhase = claimCondition.phases[_conditionId];
330352

331353
require(
332354
_currency == currentClaimPhase.currency && _pricePerToken == currentClaimPhase.pricePerToken,
333355
"invalid currency or price specified."
334356
);
357+
// If we're checking for an allowlist quantity restriction, ignore the general quantity restriction.
335358
require(
336-
_quantity > 0 && _quantity <= currentClaimPhase.quantityLimitPerTransaction,
359+
_quantity > 0 &&
360+
(!verifyMaxQuantityPerTransaction || _quantity <= currentClaimPhase.quantityLimitPerTransaction),
337361
"invalid quantity claimed."
338362
);
339363
require(

0 commit comments

Comments
 (0)