Skip to content

Commit

Permalink
GMS-1104: Update bulkMintThreshold func name (#101)
Browse files Browse the repository at this point in the history
- Make the name more consistent
  • Loading branch information
ipekt authored Sep 28, 2023
1 parent 22ff3e0 commit e84dd98
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
32 changes: 16 additions & 16 deletions contracts/token/erc721/abstract/ERC721Hybrid.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -192,22 +192,22 @@ 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);
}
}

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);
Expand All @@ -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--;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions test/allowlist/HybridApproval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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))
Expand Down
16 changes: 8 additions & 8 deletions test/token/erc721/ImmutableERC721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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")
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});
});
Expand All @@ -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] },
Expand Down
6 changes: 3 additions & 3 deletions test/token/erc721/ImmutableERC721HybridPermit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e84dd98

Please sign in to comment.