// SPDX-License-Identifier: MIT // Klaytn Contract Library v1.0.0 (KIP/token/KIP17/presets/KIP17PresetMinterPauserAutoId.sol) // Based on OpenZeppelin Contracts v4.5.0 (token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol) // https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v4.5.0 pragma solidity ^0.8.0; import "../../../../utils/Context.sol"; import "../../../../access/AccessControlEnumerable.sol"; import "../extensions/KIP17Enumerable.sol"; import "../extensions/KIP17Mintable.sol"; import "../extensions/KIP17Burnable.sol"; import "../extensions/KIP17Pausable.sol"; import "../../../../utils/Counters.sol"; /** * @dev {KIP17} token, including: * * - ability for holders to burn (destroy) their tokens * - a minter role that allows for token minting (creation) * - a pauser role that allows to stop all token transfers * - token ID and URI autogeneration * * This contract uses {AccessControl} to lock permissioned functions using the * different roles - head to its documentation for details. * * The account that deploys the contract will be granted the minter and pauser * roles, as well as the default admin role, which will let it grant both minter * and pauser roles to other accounts. */ contract KIP17PresetMinterPauserAutoId is Context, AccessControlEnumerable, KIP17Enumerable, KIP17Mintable, KIP17Burnable, KIP17Pausable { using Counters for Counters.Counter; Counters.Counter private _tokenIdTracker; string private _baseTokenURI; /** * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the * account that deploys the contract. * * Token URIs will be autogenerated based on `baseURI` and their token IDs. * See {ERC721-tokenURI}. */ constructor( string memory name, string memory symbol, string memory baseTokenURI ) KIP17(name, symbol) { _baseTokenURI = baseTokenURI; _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _setupRole(MINTER_ROLE, _msgSender()); _setupRole(PAUSER_ROLE, _msgSender()); } function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } /** * @dev Creates a new token for `to`. Its token ID will be automatically * assigned (and available on the emitted {IERC721-Transfer} event), and the token * URI autogenerated based on the base URI passed at construction. * * See {KIP17Mintable-mint}. * * Requirements: * * - the caller must have the `MINTER_ROLE`. */ function mint(address to) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), "KIP17PresetMinterPauserAutoId: must have minter role to mint"); // We cannot just use balanceOf to create the new tokenId because tokens // can be burned (destroyed), so we need a separate counter. super.mint(to, _tokenIdTracker.current()); _tokenIdTracker.increment(); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControlEnumerable, KIP17Burnable, KIP17Mintable, KIP17Pausable, KIP17Enumerable) returns (bool) { return AccessControlEnumerable.supportsInterface(interfaceId) || KIP17Burnable.supportsInterface(interfaceId) || KIP17Mintable.supportsInterface(interfaceId) || KIP17Pausable.supportsInterface(interfaceId) || KIP17Enumerable.supportsInterface(interfaceId); } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(KIP17, KIP17Enumerable, KIP17Pausable) { super._beforeTokenTransfer(from, to, tokenId); } }