123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.7.0;
- import "../access/AccessControl.sol";
- import "../utils/Context.sol";
- import "../token/ERC1155/ERC1155.sol";
- import "../token/ERC1155/ERC1155Burnable.sol";
- import "../token/ERC1155/ERC1155Pausable.sol";
- /**
- * @dev {ERC1155} 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
- *
- * 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 ERC1155PresetMinterPauser is Context, AccessControl, ERC1155Burnable, ERC1155Pausable {
- bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
- bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
- /**
- * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE`, and `PAUSER_ROLE` to the account that
- * deploys the contract.
- */
- constructor(string memory uri) ERC1155(uri) {
- _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
- _setupRole(MINTER_ROLE, _msgSender());
- _setupRole(PAUSER_ROLE, _msgSender());
- }
- /**
- * @dev Creates `amount` new tokens for `to`, of token type `id`.
- *
- * See {ERC1155-_mint}.
- *
- * Requirements:
- *
- * - the caller must have the `MINTER_ROLE`.
- */
- function mint(address to, uint256 id, uint256 amount, bytes memory data) public virtual {
- require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
- _mint(to, id, amount, data);
- }
- /**
- * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}.
- */
- function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual {
- require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
- _mintBatch(to, ids, amounts, data);
- }
- /**
- * @dev Pauses all token transfers.
- *
- * See {ERC1155Pausable} and {Pausable-_pause}.
- *
- * Requirements:
- *
- * - the caller must have the `PAUSER_ROLE`.
- */
- function pause() public virtual {
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have pauser role to pause");
- _pause();
- }
- /**
- * @dev Unpauses all token transfers.
- *
- * See {ERC1155Pausable} and {Pausable-_unpause}.
- *
- * Requirements:
- *
- * - the caller must have the `PAUSER_ROLE`.
- */
- function unpause() public virtual {
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have pauser role to unpause");
- _unpause();
- }
- function _beforeTokenTransfer(
- address operator,
- address from,
- address to,
- uint256[] memory ids,
- uint256[] memory amounts,
- bytes memory data
- )
- internal virtual override(ERC1155, ERC1155Pausable)
- {
- super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
- }
- }
|