Skip to content

Commit f9afb21

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
SignatureDrop inherits ERC721A
1 parent af3de9d commit f9afb21

File tree

4 files changed

+661
-113
lines changed

4 files changed

+661
-113
lines changed

contracts/drop/SignatureDrop.sol

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ pragma solidity ^0.8.11;
33

44
// ========== External imports ==========
55

6-
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
7-
86
import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
97
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
108
import "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
119
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
1210

1311
// ========== Internal imports ==========
1412

13+
import "../eip/ERC721AUpgradeable.sol";
14+
1515
import "../interfaces/ITWFee.sol";
1616
import "../interfaces/IThirdwebContract.sol";
1717
import "../interfaces/drop/IDropClaimCondition.sol";
1818

19+
import "../openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol";
20+
import "@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol";
21+
22+
import "../lib/CurrencyTransferLib.sol";
23+
import "../lib/FeeType.sol";
24+
1925
// ========== Features ==========
2026

2127
import "../feature/interface/IThirdwebPlatformFee.sol";
@@ -26,13 +32,7 @@ import "../feature/DelayedReveal.sol";
2632
import "../feature/LazyMint.sol";
2733
import "../feature/SignatureMintERC721Upgradeable.sol";
2834

29-
import "../openzeppelin-presets/metatx/ERC2771ContextUpgradeable.sol";
30-
import "@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol";
31-
32-
import "../lib/CurrencyTransferLib.sol";
33-
import "../lib/FeeType.sol";
34-
35-
contract SignatureDropEnumerable is
35+
contract SignatureDrop is
3636
Initializable,
3737
IThirdwebContract,
3838
IThirdwebOwnable,
@@ -47,7 +47,7 @@ contract SignatureDropEnumerable is
4747
DelayedReveal,
4848
LazyMint,
4949
SignatureMintERC721Upgradeable,
50-
ERC721EnumerableUpgradeable
50+
ERC721AUpgradeable
5151
{
5252
using StringsUpgradeable for uint256;
5353

@@ -93,9 +93,6 @@ contract SignatureDropEnumerable is
9393
/// @dev The tokenId of the next NFT that will be minted / lazy minted.
9494
uint256 public nextTokenIdToMint;
9595

96-
/// @dev The tokenId of the next lazy minted NFT that will be claimed.
97-
uint256 public nextTokenIdToClaim;
98-
9996
/// @dev The active conditions for claiming lazy minted tokens.
10097
ClaimCondition public claimCondition;
10198

@@ -155,7 +152,7 @@ contract SignatureDropEnumerable is
155152
// Initialize inherited contracts, most base-like -> most derived.
156153
__ReentrancyGuard_init();
157154
__ERC2771Context_init(_trustedForwarders);
158-
__ERC721_init(_name, _symbol);
155+
__ERC721A_init(_name, _symbol);
159156
__SignatureMintERC721_init();
160157

161158
// Initialize this contract's state.
@@ -212,7 +209,7 @@ contract SignatureDropEnumerable is
212209
public
213210
view
214211
virtual
215-
override(ERC721EnumerableUpgradeable, AccessControlEnumerableUpgradeable)
212+
override(ERC721AUpgradeable, AccessControlEnumerableUpgradeable)
216213
returns (bool)
217214
{
218215
return super.supportsInterface(interfaceId) || type(IERC2981Upgradeable).interfaceId == interfaceId;
@@ -279,7 +276,9 @@ contract SignatureDropEnumerable is
279276
/// @dev Claim lazy minted tokens via signature.
280277
function mintWithSignature(MintRequest calldata _req, bytes calldata _signature) external payable nonReentrant {
281278
require(_req.quantity > 0, "minting zero tokens");
282-
require(nextTokenIdToClaim + _req.quantity <= nextTokenIdToMint, "not enough minted tokens.");
279+
280+
uint256 tokenIdToMint = _currentIndex;
281+
require(tokenIdToMint + _req.quantity <= nextTokenIdToMint, "not enough minted tokens.");
283282

284283
// Verify and process payload.
285284
_processRequest(_req, _signature);
@@ -290,13 +289,8 @@ contract SignatureDropEnumerable is
290289
// Collect price
291290
collectPrice(_req.quantity, _req.currency, _req.pricePerToken);
292291

293-
// Mint tokens. `type(uint256).max` is reserved.
294-
uint256 tokenIdToMint = nextTokenIdToClaim;
295-
nextTokenIdToClaim += _req.quantity;
296-
297-
for (uint256 i = tokenIdToMint; i < tokenIdToMint + _req.quantity; i += 1) {
298-
_mint(receiver, i);
299-
}
292+
// Mint tokens.
293+
_mint(receiver, _req.quantity);
300294

301295
emit TokensMinted(_msgSender(), _req.to, tokenIdToMint, _req.quantity, _req.pricePerToken, _req.currency);
302296
}
@@ -317,7 +311,9 @@ contract SignatureDropEnumerable is
317311
);
318312
require(_quantity > 0 && _quantity <= condition.quantityLimitPerTransaction, "invalid quantity.");
319313
require(condition.supplyClaimed + _quantity <= condition.maxClaimableSupply, "exceed max claimable supply.");
320-
require(nextTokenIdToClaim + _quantity <= nextTokenIdToMint, "not enough minted tokens.");
314+
315+
uint256 tokenIdToClaim = _currentIndex;
316+
require(tokenIdToClaim + _quantity <= nextTokenIdToMint, "not enough minted tokens.");
321317

322318
uint256 lastClaimTimestampForClaimer = lastClaimTimestamp[msg.sender][conditionId];
323319
require(
@@ -334,13 +330,7 @@ contract SignatureDropEnumerable is
334330
claimCondition.supplyClaimed += _quantity;
335331

336332
// Transfer tokens being claimed.
337-
uint256 tokenIdToClaim = nextTokenIdToClaim;
338-
339-
for (uint256 i = tokenIdToClaim; i < tokenIdToClaim + _quantity; i += 1) {
340-
_mint(_receiver, i);
341-
}
342-
343-
nextTokenIdToClaim = tokenIdToClaim + _quantity;
333+
_mint(_receiver, _quantity);
344334

345335
emit TokensMinted(_msgSender(), _receiver, tokenIdToClaim, _quantity, _pricePerToken, _currency);
346336
}
@@ -500,18 +490,25 @@ contract SignatureDropEnumerable is
500490

501491
/// @dev Burns `tokenId`. See {ERC721-_burn}.
502492
function burn(uint256 tokenId) public virtual {
493+
address ownerOfToken = ownerOf(tokenId);
503494
//solhint-disable-next-line max-line-length
504-
require(_isApprovedOrOwner(_msgSender(), tokenId), "caller not owner nor approved");
495+
require(
496+
_msgSender() == ownerOfToken
497+
|| isApprovedForAll(ownerOfToken, _msgSender())
498+
|| getApproved(tokenId) == _msgSender(),
499+
"caller not owner nor approved"
500+
);
505501
_burn(tokenId);
506502
}
507503

508504
/// @dev See {ERC721-_beforeTokenTransfer}.
509-
function _beforeTokenTransfer(
505+
function _beforeTokenTransfers(
510506
address from,
511507
address to,
512-
uint256 tokenId
513-
) internal virtual override(ERC721EnumerableUpgradeable) {
514-
super._beforeTokenTransfer(from, to, tokenId);
508+
uint256 startTokenId,
509+
uint256 quantity
510+
) internal virtual override {
511+
super._beforeTokenTransfers(from, to, startTokenId, quantity);
515512

516513
// if transfer is restricted on the contract, we still want to allow burning and minting
517514
if (!hasRole(TRANSFER_ROLE, address(0)) && from != address(0) && to != address(0)) {

contracts/eip/ERC721AUpgradeable.sol

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ contract ERC721AUpgradeable is Initializable, ContextUpgradeable, ERC165Upgradea
4949
// Mapping from owner to operator approvals
5050
mapping(address => mapping(address => bool)) private _operatorApprovals;
5151

52-
constructor(string memory name_, string memory symbol_) {
53-
_name = name_;
54-
_symbol = symbol_;
55-
_currentIndex = _startTokenId();
56-
}
57-
5852
/**
5953
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
6054
*/
@@ -65,6 +59,7 @@ contract ERC721AUpgradeable is Initializable, ContextUpgradeable, ERC165Upgradea
6559
function __ERC721A_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
6660
_name = name_;
6761
_symbol = symbol_;
62+
_currentIndex = _startTokenId();
6863
}
6964

7065
/**
@@ -218,7 +213,7 @@ contract ERC721AUpgradeable is Initializable, ContextUpgradeable, ERC165Upgradea
218213
* @dev See {IERC721-approve}.
219214
*/
220215
function approve(address to, uint256 tokenId) public override {
221-
address owner = ERC721A.ownerOf(tokenId);
216+
address owner = ERC721AUpgradeable.ownerOf(tokenId);
222217
if (to == owner) revert ApprovalToCurrentOwner();
223218

224219
if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) {

0 commit comments

Comments
 (0)