contract MuseToken is ERC20PresetMinterPauser {
    // Cap at 1 million
    uint256 internal _cap = 1000000 * 10**18;

    constructor() public ERC20PresetMinterPauser("Muse", "MUSE") {}

    /**
     * @dev Returns the cap on the token's total supply.
     */
    function cap() public view returns (uint256) {
        return _cap;
    }

    // change cap in case of decided by the community
    function changeCap(uint256 _newCap) external {
        require(
            hasRole(MINTER_ROLE, _msgSender()),
            "ERC20PresetMinterPauser: must have minter role to mint"
        );
        _cap = _newCap;
    }

    /**
     * @dev See {ERC20-_beforeTokenTransfer}.
     *
     * Requirements:
     *
     * - minted tokens must not cause the total supply to go over the cap.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override(ERC20PresetMinterPauser) {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) {
            // When minting tokens
            require(
                totalSupply().add(amount) <= _cap,
                "ERC20Capped: cap exceeded"
            );
        }
    }
}
function changeCap(uint256 _newCap) external {
    require(
        hasRole(MINTER_ROLE, _msgSender()),
        "ERC20PresetMinterPauser: must have minter role to mint"
    );
    _cap = _newCap;
}

// change cap in case of decided by the community