Skip to content

Commit

Permalink
add error NewMaxSupplyCannotBeLessThenTotalSupply
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Apr 4, 2024
1 parent f8b8f16 commit fe0d47a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/clones/ERC1155ContractMetadataCloneable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,19 @@ contract ERC1155ContractMetadataCloneable is
_onlyOwnerOrConfigurer();

// Ensure the max supply does not exceed the maximum value of uint64,
// a limit due to the storage of bit-packed variables in TokenSupply,
// a limit due to the storage of bit-packed variables in TokenSupply.
if (newMaxSupply > 2 ** 64 - 1) {
revert CannotExceedMaxSupplyOfUint64(newMaxSupply);
}

// Ensure the max supply does not exceed the total supply.
if (newMaxSupply < _tokenSupply[tokenId].totalSupply) {
revert NewMaxSupplyCannotBeLessThenTotalSupply(
newMaxSupply,
_tokenSupply[tokenId].totalSupply
);
}

// Set the new max supply.
_tokenSupply[tokenId].maxSupply = uint64(newMaxSupply);

Expand Down Expand Up @@ -337,7 +345,13 @@ contract ERC1155ContractMetadataCloneable is
}

/// @dev Override this function to return true if `_beforeTokenTransfer` is used.
function _useBeforeTokenTransfer() internal view virtual override returns (bool) {
function _useBeforeTokenTransfer()
internal
view
virtual
override
returns (bool)
{
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/ISeaDropTokenContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ interface ISeaDropTokenContractMetadata {
*/
error CannotExceedMaxSupplyOfUint64(uint256 got);

/**
* @notice Throw if the max supply exceeds the total supply.
*/
error NewMaxSupplyCannotBeLessThenTotalSupply(
uint256 got,
uint256 totalSupply
);

/**
* @dev Revert with an error when attempting to set the provenance
* hash after the mint has started.
Expand Down
18 changes: 16 additions & 2 deletions src/lib/ERC1155ContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,19 @@ contract ERC1155ContractMetadata is
_onlyOwnerOrConfigurer();

// Ensure the max supply does not exceed the maximum value of uint64,
// a limit due to the storage of bit-packed variables in TokenSupply,
// a limit due to the storage of bit-packed variables in TokenSupply.
if (newMaxSupply > 2 ** 64 - 1) {
revert CannotExceedMaxSupplyOfUint64(newMaxSupply);
}

// Ensure the max supply does not exceed the total supply.
if (newMaxSupply < _tokenSupply[tokenId].totalSupply) {
revert NewMaxSupplyCannotBeLessThenTotalSupply(
newMaxSupply,
_tokenSupply[tokenId].totalSupply
);
}

// Set the new max supply.
_tokenSupply[tokenId].maxSupply = uint64(newMaxSupply);

Expand Down Expand Up @@ -335,7 +343,13 @@ contract ERC1155ContractMetadata is
}

/// @dev Override this function to return true if `_beforeTokenTransfer` is used.
function _useBeforeTokenTransfer() internal view virtual override returns (bool) {
function _useBeforeTokenTransfer()
internal
view
virtual
override
returns (bool)
{
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib/ERC721ContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ contract ERC721ContractMetadata is
revert CannotExceedMaxSupplyOfUint64(newMaxSupply);
}

// Ensure the max supply does not exceed the total minted.
if (newMaxSupply < totalSupply()) {
revert NewMaxSupplyCannotBeLessThenTotalSupply(
newMaxSupply,
totalSupply()
);
}

// Set the new max supply.
_maxSupply = newMaxSupply;

Expand Down
20 changes: 20 additions & 0 deletions test/ERC1155ContractMetadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ describe(`ERC1155ContractMetadata (v${VERSION})`, function () {
.withArgs(BigNumber.from(2).pow(70));
});

it("Should not let the owner set the max supply over the totalSupply", async () => {
await token.setMaxSupply(1, 3);
await mintTokens({
marketplaceContract,
token,
tokenSeaDropInterface,
minter: owner,
tokenId: 1,
quantity: 3,
});
expect(await token.totalSupply(1)).to.equal(3);

await expect(token.setMaxSupply(1, 2))
.to.be.revertedWithCustomError(
token,
"NewMaxSupplyCannotBeLessThenTotalSupply"
)
.withArgs(2, 3);
});

it("Should only let the owner notify update of batch token URIs", async () => {
await expect(
token.connect(bob).emitBatchMetadataUpdate(5, 10)
Expand Down
19 changes: 19 additions & 0 deletions test/ERC721ContractMetadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ describe(`ERC721ContractMetadata (v${VERSION})`, function () {
.withArgs(BigNumber.from(2).pow(70));
});

it("Should not let the owner set the max supply over the totalSupply", async () => {
await token.setMaxSupply(3);
await mintTokens({
marketplaceContract,
token,
tokenSeaDropInterface,
minter: owner,
quantity: 3,
});
expect(await token.totalSupply()).to.equal(3);

await expect(token.setMaxSupply(2))
.to.be.revertedWithCustomError(
token,
"NewMaxSupplyCannotBeLessThenTotalSupply"
)
.withArgs(2, 3);
});

it("Should only let the owner notify update of batch token URIs", async () => {
await expect(
token.connect(bob).emitBatchMetadataUpdate(5, 10)
Expand Down

0 comments on commit fe0d47a

Please sign in to comment.