diff --git a/contracts/token/erc721/abstract/ERC721Hybrid.sol b/contracts/token/erc721/abstract/ERC721Hybrid.sol index 64818d13..06884705 100644 --- a/contracts/token/erc721/abstract/ERC721Hybrid.sol +++ b/contracts/token/erc721/abstract/ERC721Hybrid.sol @@ -12,7 +12,7 @@ This contract allows for minting with one of two strategies: - ERC721: minting with specified tokenIDs (inefficient) - ERC721Psi: minting in batches with consecutive tokenIDs (efficient) -All other ERC721 functions are supported, with routing logic depending on the tokenId. +All other ERC721 functions are supported, with routing logic depending on the tokenId. */ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Errors { @@ -56,13 +56,13 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err /** @dev returns the threshold that divides tokens that are minted by id and * minted by quantity **/ - function bulkMintThreshold() public pure virtual returns (uint256) { + function mintBatchByQuantityThreshold() public pure virtual returns (uint256) { return 2 ** 128; } /// @dev returns the startTokenID for the minting by quantity section of the contract function _startTokenId() internal pure virtual override(ERC721Psi) returns (uint256) { - return bulkMintThreshold(); + return mintBatchByQuantityThreshold(); } /// @dev mints number of tokens specified to the address given via erc721psi @@ -93,7 +93,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err /// @dev mints by id to a specified address via erc721 function _mintByID(address to, uint256 tokenId) internal { - if (tokenId >= bulkMintThreshold()) { + if (tokenId >= mintBatchByQuantityThreshold()) { revert IImmutableERC721IDAboveThreshold(tokenId); } @@ -106,7 +106,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err /// @dev safe mints by id to a specified address via erc721 function _safeMintByID(address to, uint256 tokenId) internal { - if (tokenId >= bulkMintThreshold()) { + if (tokenId >= mintBatchByQuantityThreshold()) { revert IImmutableERC721IDAboveThreshold(tokenId); } @@ -192,14 +192,14 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err * the erc721psi method is invoked. They then behave like their specified ancestors methods. **/ function _exists(uint256 tokenId) internal view virtual override(ERC721, ERC721PsiBurnable) returns (bool) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721._ownerOf(tokenId) != address(0) && (!_burnedTokens.get(tokenId)); } return ERC721PsiBurnable._exists(tokenId); } function _transfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { ERC721._transfer(from, to, tokenId); } else { ERC721Psi._transfer(from, to, tokenId); @@ -207,7 +207,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err } function ownerOf(uint256 tokenId) public view virtual override(ERC721, ERC721Psi) returns (address) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721.ownerOf(tokenId); } return ERC721Psi.ownerOf(tokenId); @@ -217,7 +217,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err * additional tracking is added for erc721 to prevent re-minting **/ function _burn(uint256 tokenId) internal virtual override(ERC721, ERC721PsiBurnable) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { ERC721._burn(tokenId); _burnedTokens.set(tokenId); _idMintTotalSupply--; @@ -227,7 +227,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err } function _approve(address to, uint256 tokenId) internal virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721._approve(to, tokenId); } return ERC721Psi._approve(to, tokenId); @@ -237,7 +237,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err address spender, uint256 tokenId ) internal view virtual override(ERC721, ERC721Psi) returns (bool) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721._isApprovedOrOwner(spender, tokenId); } return ERC721Psi._isApprovedOrOwner(spender, tokenId); @@ -249,7 +249,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err uint256 tokenId, bytes memory _data ) internal virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721._safeTransfer(from, to, tokenId, _data); } return ERC721Psi._safeTransfer(from, to, tokenId, _data); @@ -261,7 +261,7 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err uint256 tokenId, bytes memory _data ) public virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721.safeTransferFrom(from, to, tokenId, _data); } return ERC721Psi.safeTransferFrom(from, to, tokenId, _data); @@ -275,21 +275,21 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err } function getApproved(uint256 tokenId) public view virtual override(ERC721, ERC721Psi) returns (address) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721.getApproved(tokenId); } return ERC721Psi.getApproved(tokenId); } function approve(address to, uint256 tokenId) public virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721.approve(to, tokenId); } return ERC721Psi.approve(to, tokenId); } function transferFrom(address from, address to, uint256 tokenId) public virtual override(ERC721, ERC721Psi) { - if (tokenId < bulkMintThreshold()) { + if (tokenId < mintBatchByQuantityThreshold()) { return ERC721.transferFrom(from, to, tokenId); } return ERC721Psi.transferFrom(from, to, tokenId); diff --git a/test/allowlist/HybridApproval.test.ts b/test/allowlist/HybridApproval.test.ts index e930eb25..3b870188 100644 --- a/test/allowlist/HybridApproval.test.ts +++ b/test/allowlist/HybridApproval.test.ts @@ -86,7 +86,7 @@ describe("Royalty Checks with Hybrid ERC721", function () { }); it("Should allow EOAs to be approved", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await erc721.connect(minter).mintByQuantity(minter.address, 1); // Approve EOA addr const tokenId = first; @@ -99,7 +99,7 @@ describe("Royalty Checks with Hybrid ERC721", function () { it("Should allow Allowlisted addresses to be approved", async function () { // Add the mock marketplace to registry await operatorAllowlist.connect(registrar).addAddressToAllowlist([marketPlace.address]); - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await erc721.connect(minter).mintByQuantity(minter.address, 1); const tokenId = first; // Approve marketplace on erc721 contract @@ -112,7 +112,7 @@ describe("Royalty Checks with Hybrid ERC721", function () { it("Should allow Allowlisted smart contract wallets to be approved", async function () { // Allowlist the bytecode await operatorAllowlist.connect(registrar).addWalletToAllowlist(deployedAddr); - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await erc721.connect(minter).mintByQuantity(minter.address, 1); const tokenId = first; await erc721.connect(minter).approve(deployedAddr, tokenId); @@ -128,7 +128,7 @@ describe("Royalty Checks with Hybrid ERC721", function () { await erc721.connect(owner).setOperatorAllowlistRegistry(operatorAllowlist.address); }); it("Should freely allow transfers between EOAs", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await erc721.connect(minter).mintByQuantity(accs[0].address, 1); await erc721.connect(minter).mintByQuantity(accs[1].address, 1); const tokenIdOne = first; @@ -152,7 +152,7 @@ describe("Royalty Checks with Hybrid ERC721", function () { }); it("Should block transfers from a not allow listed contracts", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await erc721.connect(minter).mintByQuantity(marketPlace.address, 1); const tokenId = first; await expect(marketPlace.connect(minter).executeTransferFrom(marketPlace.address, minter.address, tokenId)) diff --git a/test/token/erc721/ImmutableERC721.test.ts b/test/token/erc721/ImmutableERC721.test.ts index 43377965..20687310 100644 --- a/test/token/erc721/ImmutableERC721.test.ts +++ b/test/token/erc721/ImmutableERC721.test.ts @@ -105,7 +105,7 @@ describe("ImmutableERC721", function () { it("Should allow batch minting of tokens by quantity", async function () { const qty = 5; const mintRequests = [{ to: user.address, quantity: qty }]; - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); const originalBalance = await erc721.balanceOf(user.address); const originalSupply = await erc721.totalSupply(); await erc721.connect(minter).mintBatchByQuantity(mintRequests); @@ -119,7 +119,7 @@ describe("ImmutableERC721", function () { it("Should allow safe batch minting of tokens by quantity", async function () { const qty = 5; const mintRequests = [{ to: user2.address, quantity: qty }]; - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); const originalBalance = await erc721.balanceOf(user2.address); const originalSupply = await erc721.totalSupply(); await erc721.connect(minter).safeMintBatchByQuantity(mintRequests); @@ -142,7 +142,7 @@ describe("ImmutableERC721", function () { it("Should allow owner or approved to burn a batch of mixed ID/PSI tokens", async function () { const originalBalance = await erc721.balanceOf(user.address); const originalSupply = await erc721.totalSupply(); - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); const batch = [3, 4, first.toString(), first.add(1).toString()]; await erc721.connect(user).burnBatch(batch); expect(await erc721.balanceOf(user.address)).to.equal(originalBalance.sub(batch.length)); @@ -206,7 +206,7 @@ describe("ImmutableERC721", function () { }); it("Should prevent not approved to burn a batch of tokens", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); await expect(erc721.connect(minter).burnBatch([first.add(2), first.add(3)])) .to.be.revertedWith("IImmutableERC721NotOwnerOrOperator") .withArgs(first.add(2)); @@ -221,7 +221,7 @@ describe("ImmutableERC721", function () { }); it("Should revert if minting by id with id above threshold", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); const mintRequests = [{ to: user.address, tokenIds: [first] }]; await expect(erc721.connect(minter).mintBatch(mintRequests)) .to.be.revertedWith("IImmutableERC721IDAboveThreshold") @@ -293,7 +293,7 @@ describe("ImmutableERC721", function () { describe("exists", async function () { it("verifies valid tokens minted by quantity", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); expect(await erc721.exists(first.add(3))).to.equal(true); }); @@ -302,7 +302,7 @@ describe("ImmutableERC721", function () { }); it("verifies invalid tokens", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); expect(await erc721.exists(first.add(10))).to.equal(false); }); }); @@ -321,7 +321,7 @@ describe("ImmutableERC721", function () { describe("Transfers", function () { it("Should allow users to transfer tokens using safeTransferFromBatch", async function () { - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); // Mint tokens for testing transfers const mintRequests = [ { to: minter.address, tokenIds: [51, 52, 53] }, diff --git a/test/token/erc721/ImmutableERC721HybridPermit.test.ts b/test/token/erc721/ImmutableERC721HybridPermit.test.ts index a01bd8d5..0f27e7b6 100644 --- a/test/token/erc721/ImmutableERC721HybridPermit.test.ts +++ b/test/token/erc721/ImmutableERC721HybridPermit.test.ts @@ -96,7 +96,7 @@ describe("ImmutableERC721Permit", function () { it("can use permits to approve spender on token minted by quantity", async function () { await erc721.connect(minter).mintByQuantity(user.address, 1); - const first = await erc721.bulkMintThreshold(); + const first = await erc721.mintBatchByQuantityThreshold(); const deadline = Math.round(Date.now() / 1000 + 24 * 60 * 60); const nonce = await erc721.nonces(first); @@ -200,7 +200,7 @@ describe("ImmutableERC721Permit", function () { await erc721.connect(minter).mintByQuantity(user.address, 1); const deadline = Math.round(Date.now() / 1000 + 24 * 60 * 60); const operatorAddress = await operator.getAddress(); - const tokenId = (await erc721.bulkMintThreshold()).add(1); + const tokenId = (await erc721.mintBatchByQuantityThreshold()).add(1); await erc721 .connect(user) @@ -240,7 +240,7 @@ describe("ImmutableERC721Permit", function () { await erc721.connect(minter).mintByQuantity(user.address, 1); const deadline = Math.round(Date.now() / 1000 + 24 * 60 * 60); - const tokenId = (await erc721.bulkMintThreshold()).add(2); + const tokenId = (await erc721.mintBatchByQuantityThreshold()).add(2); const nonce = await erc721.nonces(tokenId); expect(nonce).to.be.equal(0);