Skip to content

Commit

Permalink
Merge pull request #6 from davisshaver/feat-add-public-mint-toggle
Browse files Browse the repository at this point in the history
✨ Add public mint toggle
  • Loading branch information
davisshaver authored Sep 21, 2024
2 parents a9ca45a + 6529e8c commit acdd757
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/ProtoGravaNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ library Events {
/// @notice Emitted after default format is changed
/// @param newDefaultFormat for all tokens
event DefaultFormatChanged(string newDefaultFormat);

/// @notice Emitted after public minting is toggled
/// @param isPublicMintEnabled for all tokens
event PublicMintToggled(bool isPublicMintEnabled);
}

/// @title ProtoGravaNFT
Expand Down Expand Up @@ -72,6 +76,8 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
/// @notice Description
string public description;

bool public isPublicMintEnabled;

/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
Expand All @@ -89,6 +95,13 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
_;
}

/// @notice Throws if called when public minting is disabled
modifier onlyWhenPublicMintEnabled() {
if (!isPublicMintEnabled && msg.sender != _owner)
revert PublicMintDisabled();
_;
}

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand All @@ -111,6 +124,9 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
/// @notice Thrown if user attempts to mint more than one token
error OnePerUser();

/// @notice Thrown if public minting is disabled
error PublicMintDisabled();

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
Expand All @@ -124,6 +140,7 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
) ERC721(_name, _symbol) {
defaultFormat = Defaults.DEFAULT_FOR_DEFAULT_IMAGE;
description = Defaults.DEFAULT_DESCRIPTION;
isPublicMintEnabled = true;
}

/// @notice Get total non-burned supply of token
Expand Down Expand Up @@ -304,7 +321,7 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
/* solhint-enable quotes */

/// @notice Mint a token
function mint() external {
function mint() external onlyWhenPublicMintEnabled {
if (totalMinted + 1 >= MAX_TOTAL_MINTED) revert NoTokensLeft();

if (balanceOf(msg.sender) > 0) revert OnePerUser();
Expand Down Expand Up @@ -358,6 +375,12 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {
return formattedTokenURI;
}

/// @notice Toggle public minting
function ownerTogglePublicMint() public onlyContractOwner {
isPublicMintEnabled = !isPublicMintEnabled;
emit Events.PublicMintToggled(isPublicMintEnabled);
}

/// @notice Update default Gravatar image format for future tokens
/// @param newDefaultFormat for Gravatar image API
function ownerSetDefaultFormat(
Expand Down
15 changes: 15 additions & 0 deletions src/test/ProtoGravaNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ contract ProtoGravNFTTestContract is ProtoGravaNFTTest {
assertEq(charlie.getAddress(), charlieAddress);
}

/// @notice Test that public minting is enabled by default
function testPublicMintDisabled() public view {
assertTrue(protogravanft.isPublicMintEnabled());
}

/// @notice Test that public minting can be disabled
function testPublicMintToggle() public {
protogravanft.ownerTogglePublicMint();
assertTrue(!protogravanft.isPublicMintEnabled());
vm.expectRevert(abi.encodeWithSignature("PublicMintDisabled()"));
alice.mint();
protogravanft.mint();
assertEq(protogravanft.balanceOf(address(this)), 1);
}

/// @notice Allow Alice to mint a token for approved hash
function testAliceMint() public {
// Collect Alice balance of tokens before mint
Expand Down

0 comments on commit acdd757

Please sign in to comment.