contract ERC20AccessList is ERC20Pausable, ERC20CapEnabler, ERC20Operator {

    TokenAccessList public accessList;
    bool public checkingAccessList;

    /**
     * Admin events
     */

    event AccessListSet(address accessList);
    event AccessListUnset();

    /**
    * Admin functions
    */

    /**
    * @dev Sets up the centralized accessList contract
    * @param _accessList the address of accessList contract.
    * @return A boolean that indicates if the operation was successful.
    */
    function setupAccessList(address _accessList)
        public
        onlyCreator {
            if (_accessList == address(0)) revert("Invalid access list address");
            accessList = TokenAccessList(_accessList);
            checkingAccessList = true;
            emit AccessListSet(_accessList);
    }

    /**
    * @dev Removes the accessList
    * @return A boolean that indicates if the operation was successful.
    */
    function removeAccessList()
        public
        onlyCreator {
            checkingAccessList = false;
            accessList = TokenAccessList(0x0);
            emit AccessListUnset();
    }

    /**
    * @dev Overrides MintableToken mint() adding the accessList validation
    * @param _to The address that will receive the minted tokens.
    * @param _amount The amount of tokens to mint.
    * @return A boolean that indicates if the operation was successful.
    */
    function mint(address _to, uint256 _amount)
        public
        onlyMinter
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(_to), "AccessList: address not authorized");
            }
            return super.mint(_to, _amount);
    }

    /**
    * User functions
    */

    /**
    * @dev Overrides BasicToken transfer() adding the accessList validation
    * @param _to The address to transfer to.
    * @param _value The amount to be transferred.
    * @return A boolean that indicates if the operation was successful.
    */
    function transfer(address _to, uint256 _value)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(msg.sender, _to), "AccessList: address not authorized");
            }
            return super.transfer(_to, _value);
    }

    /**
    * @dev Overrides BasicToken transfer() adding the accessList validation
    * @param _to The address to transfer from.
    * @param _to The address to transfer to.
    * @param _value The amount to be transferred.
    * @return A boolean that indicates if the operation was successful.
    */
    function forcedTransfer(address _from, address _to, uint256 _value)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(_from, _to), "AccessList: address not authorized");
            }
            return super.forcedTransfer(_from, _to, _value);
    }

    /**
     * @dev Overrides StandardToken transferFrom() adding the accessList validation
     * @param _from address The address which you want to send tokens from
     * @param _to address The address which you want to transfer to
     * @param _value uint256 the amount of tokens to be transferred
     */
    function transferFrom(address _from, address _to, uint256 _value)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(msg.sender, _from, _to), "AccessList: address not authorized");
            }
            return super.transferFrom(_from, _to, _value);
    }

    /**
     * @dev Overrides StandardToken approve() adding the accessList validation
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     * @return A boolean that indicates if the operation was successful.
     */
    function approve(address _spender, uint256 _value)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(msg.sender, _spender), "AccessList: address not authorized");
            }
            return super.approve(_spender, _value);
    }

    /**
     * @dev Overrides StandardToken increaseApproval() adding the accessList validation
     * @param _spender The address which will spend the funds.
     * @param _addedValue The amount of tokens to increase the allowance by.
     * @return A boolean that indicates if the operation was successful.
     */
    function increaseAllowance(address _spender, uint _addedValue)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(msg.sender, _spender), "AccessList: address not authorized");
            }
            return super.increaseAllowance(_spender, _addedValue);
    }

    /**
     * @dev Overrides StandardToken decreaseApproval() adding the accessList validation
     * @param _spender The address which will spend the funds.
     * @param _subtractedValue The amount of tokens to decrease the allowance by.
     * @return A boolean that indicates if the operation was successful.
     */
    function decreaseAllowance(address _spender, uint _subtractedValue)
        public
        whenNotPaused
        returns (bool) {
            if (checkingAccessList) {
                require(accessList.checkEnabled(msg.sender, _spender), "AccessList: address not authorized");
            }
            return super.decreaseAllowance(_spender, _subtractedValue);
    }

}
/**
 * ERC20 implementation that optionally allows the setup of a access list,
 * which may or may not be required by regulators. If a access list is
 * configured, then the contract starts validating parties.
 * Only the token creator, represented by the CreatorRole, is allowed
 * to add and remove the access list
 */
function mint(address _to, uint256 _amount)
    public
    onlyMinter
    returns (bool) {
        if (checkingAccessList) {
            require(accessList.checkEnabled(_to), "AccessList: address not authorized");
        }
        return super.mint(_to, _amount);
}

/**
 * @dev Overrides MintableToken mint() adding the accessList validation
 * @param _to The address that will receive the minted tokens.
 * @param _amount The amount of tokens to mint.
 * @return A boolean that indicates if the operation was successful.
 */