Skip to content

Commit

Permalink
Use maxSupply = 0 for unlimited supply
Browse files Browse the repository at this point in the history
  • Loading branch information
TomiOhl committed May 2, 2024
1 parent ca96021 commit 53c9c2a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 24 deletions.
6 changes: 2 additions & 4 deletions contracts/ConfigurableGuildRewardNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ contract ConfigurableGuildRewardNFT is
IGuildRewardNFTFactory.ConfigurableNFTConfig memory nftConfig,
address factoryProxyAddress
) public initializer {
if (nftConfig.maxSupply <= 0) revert MaxSupplyZero();

cid = nftConfig.cid;
maxSupply = nftConfig.maxSupply;
mintableAmountPerUser = nftConfig.mintableAmountPerUser;
Expand Down Expand Up @@ -72,7 +70,8 @@ contract ConfigurableGuildRewardNFT is
uint256 firstTokenId = totalSupply();
uint256 lastTokenId = firstTokenId + amount - 1;

if (lastTokenId >= maxSupply) revert MaxSupplyReached(maxSupply);
uint256 tokenIdCap = maxSupply;
if (tokenIdCap > 0 && lastTokenId >= tokenIdCap) revert MaxSupplyReached(tokenIdCap);

for (uint256 tokenId = firstTokenId; tokenId <= lastTokenId; ) {
_safeMint(receiver, tokenId);
Expand Down Expand Up @@ -122,7 +121,6 @@ contract ConfigurableGuildRewardNFT is
}

function setMaxSupply(uint256 newMaxSupply) external onlyOwner {
if (newMaxSupply <= 0) revert MaxSupplyZero();
maxSupply = newMaxSupply;
emit MaxSupplyChanged(newMaxSupply);
}
Expand Down
7 changes: 2 additions & 5 deletions contracts/interfaces/IMaxSupply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ pragma solidity ^0.8.0;

interface IMaxSupply {
/// @notice The maximum number of tokens that can ever be minted.
/// @return count The number of tokens.
/// @return count The number of tokens. Unlimited if zero.
function maxSupply() external view returns (uint256 count);

/// @notice Sets the maximum number of tokens that can ever be minted.
/// @dev Only callable by the owner.
/// @param newMaxSupply The number of tokens.
/// @param newMaxSupply The number of tokens. Unlimited if zero.
function setMaxSupply(uint256 newMaxSupply) external;

/// @notice Event emitted when the maxSupply is changed.
/// @param newMaxSupply The number of tokens.
event MaxSupplyChanged(uint256 newMaxSupply);

/// @notice Error thrown when the maximum supply attempted to be set is zero.
error MaxSupplyZero();

/// @notice Error thrown when the tokenId is higher than the maximum supply.
/// @param maxSupply The maximum supply of the token.
error MaxSupplyReached(uint256 maxSupply);
Expand Down
2 changes: 1 addition & 1 deletion docs/contracts/ConfigurableGuildRewardNFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Only callable by the owner.

| Name | Type | Description |
| :--- | :--- | :---------- |
| `newMaxSupply` | uint256 | The number of tokens. |
| `newMaxSupply` | uint256 | The number of tokens. Unlimited if zero. |

### setMintableAmountPerUser

Expand Down
12 changes: 2 additions & 10 deletions docs/contracts/interfaces/IMaxSupply.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The maximum number of tokens that can ever be minted.

| Name | Type | Description |
| :--- | :--- | :---------- |
| `count` | uint256 | The number of tokens. |
| `count` | uint256 | The number of tokens. Unlimited if zero. |
### setMaxSupply

```solidity
Expand All @@ -31,7 +31,7 @@ Only callable by the owner.

| Name | Type | Description |
| :--- | :--- | :---------- |
| `newMaxSupply` | uint256 | The number of tokens. |
| `newMaxSupply` | uint256 | The number of tokens. Unlimited if zero. |

## Events

Expand All @@ -53,14 +53,6 @@ Event emitted when the maxSupply is changed.

## Custom errors

### MaxSupplyZero

```solidity
error MaxSupplyZero()
```

Error thrown when the maximum supply attempted to be set is zero.

### MaxSupplyReached

```solidity
Expand Down
4 changes: 0 additions & 4 deletions test/ConfigurableGuildRewardNFT.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,6 @@ describe("ConfigurableGuildRewardNFT", () => {
);
});

it("should revert if maxSupply is attempted to be set to 0", async () => {
await expect(nft.setMaxSupply(0)).to.be.revertedWithCustomError(nft, "MaxSupplyZero");
});

it("should update maxSupply", async () => {
const maxSupply = 5;
await nft.setMaxSupply(maxSupply);
Expand Down

0 comments on commit 53c9c2a

Please sign in to comment.