123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.6.0;
- import "../access/AccessControl.sol";
- import "../GSN/Context.sol";
- import "../token/ERC20/ERC20.sol";
- import "../token/ERC20/ERC20Burnable.sol";
- import "../token/ERC20/ERC20Pausable.sol";
- /**
- * @dev {ERC20} 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 ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20Pausable {
- 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.
- *
- * See {ERC20-constructor}.
- */
- constructor(string memory name, string memory symbol) public ERC20(name, symbol) {
- _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
- _setupRole(MINTER_ROLE, _msgSender());
- _setupRole(PAUSER_ROLE, _msgSender());
- }
- /**
- * @dev Creates `amount` new tokens for `to`.
- *
- * See {ERC20-_mint}.
- *
- * Requirements:
- *
- * - the caller must have the `MINTER_ROLE`.
- */
- function mint(address to, uint256 amount) public virtual {
- require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint");
- _mint(to, amount);
- }
- /**
- * @dev Pauses all token transfers.
- *
- * See {ERC20Pausable} and {Pausable-_pause}.
- *
- * Requirements:
- *
- * - the caller must have the `PAUSER_ROLE`.
- */
- function pause() public virtual {
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to pause");
- _pause();
- }
- /**
- * @dev Unpauses all token transfers.
- *
- * See {ERC20Pausable} and {Pausable-_unpause}.
- *
- * Requirements:
- *
- * - the caller must have the `PAUSER_ROLE`.
- */
- function unpause() public virtual {
- require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to unpause");
- _unpause();
- }
- function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) {
- super._beforeTokenTransfer(from, to, amount);
- }
- }
|