Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions contracts/src/TNT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ contract TNT is ERC721, AccessControl {
error NotOwner();
error InvalidIndex();
error NonTransferable();
error MaxSupplyReached();
error MaxSupplyTooLow(uint256 requested, uint256 alreadyMinted);
event MaxSupplyUpdated(uint256 previous, uint256 next);

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant REVOKER_ROLE = keccak256("REVOKER_ROLE");
Expand All @@ -28,6 +31,7 @@ contract TNT is ERC721, AccessControl {
bool public immutable revokable;
address public factoryContract;
string public imageURL;
uint256 public maxSupply;

struct TokenMetadata {
uint256 issuedAt;
Expand All @@ -54,8 +58,18 @@ contract TNT is ERC721, AccessControl {
imageURL = _imageURL;
}

function setMaxSupply(uint256 _maxSupply) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_maxSupply != 0 && _maxSupply < _nextTokenId) {
revert MaxSupplyTooLow(_maxSupply, _nextTokenId);
}
emit MaxSupplyUpdated(maxSupply, _maxSupply);
maxSupply = _maxSupply;
}

function issueToken(address user) public onlyRole(MINTER_ROLE) {
if (user == address(0)) revert InvalidUser();

if (maxSupply > 0 && _nextTokenId >= maxSupply) revert MaxSupplyReached();

uint256 tokenId = _nextTokenId++;
_safeMint(user, tokenId);
Expand Down