|
@@ -2,6 +2,7 @@ pragma solidity ^0.6.0;
|
|
|
|
|
|
import "../access/AccessControl.sol";
|
|
|
import "../GSN/Context.sol";
|
|
|
+import "../utils/Counters.sol";
|
|
|
import "../token/ERC721/ERC721.sol";
|
|
|
import "../token/ERC721/ERC721Burnable.sol";
|
|
|
import "../token/ERC721/ERC721Pausable.sol";
|
|
@@ -12,33 +13,43 @@ import "../token/ERC721/ERC721Pausable.sol";
|
|
|
* - 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 role, the
|
|
|
- * pauser role, and the default admin role, meaning it will be able to grant
|
|
|
- * both the minter and pauser roles.
|
|
|
+ * 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 aother accounts
|
|
|
*/
|
|
|
-contract ERC721MinterPauser is Context, AccessControl, ERC721Burnable, ERC721Pausable {
|
|
|
+contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnable, ERC721Pausable {
|
|
|
+ using Counters for Counters.Counter;
|
|
|
+
|
|
|
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
|
|
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
|
|
|
|
|
|
+ Counters.Counter private _tokenIdTracker;
|
|
|
+
|
|
|
/**
|
|
|
- * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
|
|
|
- * account that deploys the contract.
|
|
|
+ * @dev Grants `DEFAULT_ADMIN_ROLE` and `MINTER_ROLE`to the account that
|
|
|
+ * deploys the contract.
|
|
|
*
|
|
|
- * See {ERC721-constructor}.
|
|
|
+ * Token URIs will be autogenerated based on `baseURI` and their token IDs.
|
|
|
+ * See {ERC721-tokenURI}.
|
|
|
*/
|
|
|
- constructor(string memory name, string memory symbol) public ERC721(name, symbol) {
|
|
|
+ constructor(string memory name, string memory symbol, string memory baseURI) public ERC721(name, symbol) {
|
|
|
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
|
|
|
|
|
_setupRole(MINTER_ROLE, _msgSender());
|
|
|
_setupRole(PAUSER_ROLE, _msgSender());
|
|
|
+
|
|
|
+ _setBaseURI(baseURI);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @dev Creates the `tokenId` tokens for `to`.
|
|
|
+ * @dev Creates a new token for `to`. Its token ID will be automatically
|
|
|
+ * assigned (and available on the emitted {Transfer} event), and the token
|
|
|
+ * URI autogenerated based on the base URI passed at construction.
|
|
|
*
|
|
|
* See {ERC721-_mint}.
|
|
|
*
|
|
@@ -46,9 +57,13 @@ contract ERC721MinterPauser is Context, AccessControl, ERC721Burnable, ERC721Pau
|
|
|
*
|
|
|
* - the caller must have the `MINTER_ROLE`.
|
|
|
*/
|
|
|
- function mint(address to, uint256 tokenId) public {
|
|
|
- require(hasRole(MINTER_ROLE, _msgSender()), "ERC721MinterPauser: must have minter role to mint");
|
|
|
- _mint(to, tokenId);
|
|
|
+ function mint(address to) public {
|
|
|
+ require(hasRole(MINTER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have minter role to mint");
|
|
|
+
|
|
|
+ // We can just use balanceOf to create the new tokenId because tokens
|
|
|
+ // can be burned (destroyed), so we need a separate counter.
|
|
|
+ _mint(to, _tokenIdTracker.current());
|
|
|
+ _tokenIdTracker.increment();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -61,21 +76,21 @@ contract ERC721MinterPauser is Context, AccessControl, ERC721Burnable, ERC721Pau
|
|
|
* - the caller must have the `PAUSER_ROLE`.
|
|
|
*/
|
|
|
function pause() public {
|
|
|
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721MinterPauser: must have pauser role to pause");
|
|
|
+ require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to pause");
|
|
|
_pause();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @dev Unpauses all token transfers.
|
|
|
*
|
|
|
- * See {ERC20Pausable} and {Pausable-_unpause}.
|
|
|
+ * See {ERC721Pausable} and {Pausable-_unpause}.
|
|
|
*
|
|
|
* Requirements:
|
|
|
*
|
|
|
* - the caller must have the `PAUSER_ROLE`.
|
|
|
*/
|
|
|
function unpause() public {
|
|
|
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721MinterPauser: must have pauser role to unpause");
|
|
|
+ require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to unpause");
|
|
|
_unpause();
|
|
|
}
|
|
|
|