testnet-tokens.sol 2.52 KB
Newer Older
XFT-dev's avatar
XFT-dev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
// contracts/zkAsset.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "../localhost/@openzeppelin/contracts/access/AccessControl.sol";
import "../localhost/@openzeppelin/contracts/GSN/Context.sol";
import "../localhost/@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../localhost/@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "../localhost/@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";

contract zkAsset is ERC20, AccessControl, ERC20Burnable, ERC20Pausable {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

    constructor() public ERC20("zkTEST-Asset", "zkA") {

        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MINTER_ROLE, msg.sender);
        _setupRole(BURNER_ROLE, msg.sender);
        _setupRole(PAUSER_ROLE, msg.sender);
    }

    /**
    * @dev Destroys `amount` tokens for `from`.
    *
    * See {ERC20-_burn}.
    *
    * Requirements:
    *
    * - the caller must have the `BURNER_ROLE`.
    */
    function burn(address from, uint256 amount) public {
        require(hasRole(BURNER_ROLE, msg.sender), "zkAsset: must have burner role to burn");
        _burn(from, amount);
    }

    /**
     * @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 {
        require(hasRole(MINTER_ROLE, _msgSender()), "zkAsset: 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 {
        require(hasRole(PAUSER_ROLE, _msgSender()), "zkAsset: 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 {
        require(hasRole(PAUSER_ROLE, _msgSender()), "zkAsset: must have pauser role to unpause");
        _unpause();
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Pausable) {
        super._beforeTokenTransfer(from, to, amount);
    }
}