// Vulnerability label: DC1
{"GDAODelegate.sol":{"content":"pragma solidity 0.5.17;\n\n\ncontract GDAOGovernanceStorage {\n    /// @notice A record of each accounts delegate\n    mapping (address =\u003e address) internal _delegates;\n\n    /// @notice A checkpoint for marking number of votes from a given block\n    struct Checkpoint {\n        uint32 fromBlock;\n        uint256 votes;\n    }\n\n    /// @notice A record of votes checkpoints for each account, by index\n    mapping (address =\u003e mapping (uint32 =\u003e Checkpoint)) public checkpoints;\n\n    /// @notice The number of checkpoints for each account\n    mapping (address =\u003e uint32) public numCheckpoints;\n\n    /// @notice The EIP-712 typehash for the contract\u0027s domain\n    bytes32 public constant DOMAIN_TYPEHASH = keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n    /// @notice The EIP-712 typehash for the delegation struct used by the contract\n    bytes32 public constant DELEGATION_TYPEHASH = keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n    /// @notice A record of states for signing / validating signatures\n    mapping (address =\u003e uint) public nonces;\n}\n\n// SPDX-License-Identifier: MIT\n/**\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it\u0027s recommended to use it always.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c \u003e= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity\u0027s `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return sub(a, b, \"SafeMath: subtraction overflow\");\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity\u0027s `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b \u003c= a, errorMessage);\n        uint256 c = a - b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\n        // benefit is lost if \u0027b\u0027 is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return div(a, b, \"SafeMath: division by zero\");\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b \u003e 0, errorMessage);\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return mod(a, b, \"SafeMath: modulo by zero\");\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts with custom message when dividing by zero.\n     *\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b != 0, errorMessage);\n        return a % b;\n    }\n}\n\n// Storage for a GDAO token\ncontract GDAOTokenStorage {\n\n    using SafeMath for uint256;\n\n    /**\n     * @dev Guard variable for re-entrancy checks. Not currently used\n     */\n    bool internal _notEntered;\n\n    /**\n     * @notice EIP-20 token name for this token\n     */\n    string public name;\n\n    /**\n     * @notice EIP-20 token symbol for this token\n     */\n    string public symbol;\n\n    /**\n     * @notice EIP-20 token decimals for this token\n     */\n    uint8 public decimals;\n\n    /**\n     * @notice Governor for this contract\n     */\n    address public gov;\n\n    /**\n     * @notice Pending governance for this contract\n     */\n    address public pendingGov;\n\n    /**\n     * @notice Total supply of GDAOs\n     */\n    uint256 internal _totalSupply;\n\n    uint256 internal _cap;\n\n    address[] internal _minters;\n    \n    mapping (address =\u003e uint256) internal _minterIndex;\n\n    mapping (address =\u003e uint256) internal _gdaoBalances;\n\n    mapping (address =\u003e mapping (address =\u003e uint256)) internal _allowedFragments;\n\n}\n\ncontract GDAOTokenInterface is GDAOTokenStorage, GDAOGovernanceStorage {\n\n    /// @notice An event thats emitted when an account changes its delegate\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\n\n    /*** Gov Events ***/\n\n    /**\n     * @notice Event emitted when pendingGov is changed\n     */\n    event NewPendingGov(address oldPendingGov, address newPendingGov);\n\n    /**\n     * @notice Event emitted when gov is changed\n     */\n    event NewGov(address oldGov, address newGov);\n\n    /* - ERC20 Events - */\n\n    /**\n     * @notice EIP20 Transfer event\n     */\n    event Transfer(address indexed from, address indexed to, uint amount);\n\n    /**\n     * @notice EIP20 Approval event\n     */\n    event Approval(address indexed owner, address indexed spender, uint amount);\n\n    /* - Extra Events - */\n    /**\n     * @notice Tokens minted event\n     */\n    event Mint(address to, uint256 amount);\n\n    event AddMinter(address minter);\n\n    event RemoveMinter(address minter);\n\n    /**\n     * @notice Tokens burned event\n     */\n    event Burn(address who, uint256 amount);\n\n    event NewCap(uint256 oldCap, uint256 newCap);\n\n    // Public functions\n    function totalSupply() external view returns (uint256);\n    function transfer(address to, uint256 value) external returns(bool);\n    function transferFrom(address from, address to, uint256 value) external returns(bool);\n    function balanceOf(address who) external view returns(uint256);\n    function allowance(address owner_, address spender) external view returns(uint256);\n    function approve(address spender, uint256 value) external returns (bool);\n    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);\n    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);\n    function burn(uint256 amount) external returns (bool);\n    function cap() external view returns (uint256);\n    function minterCount() external view returns (uint256);\n    function getMinter(uint256 idx) external view returns (address);\n\n    /* - Governance Functions - */\n    function getPriorVotes(address account, uint blockNumber) external view returns (uint256);\n    function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external;\n    function delegate(address delegatee) external;\n    function delegates(address delegator) external view returns (address);\n    function getCurrentVotes(address account) external view returns (uint256);\n\n    /* - Permissioned/Governance functions - */\n    function mint(address to, uint256 amount) external returns (bool);\n    function _setPendingGov(address pendingGov_) external;\n    function _acceptGov() external;\n    function setCap(uint256 ncap) external returns (bool);\n    function addMinter(address minter) external returns (bool);\n    function removeMinter(address minter) external returns (bool);\n\n}\n\ncontract GDAOGovernanceToken is GDAOTokenInterface {\n\n      /// @notice An event thats emitted when an account changes its delegate\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\n\n    /**\n     * @notice Delegate votes from `msg.sender` to `delegatee`\n     * @param delegator The address to get delegatee for\n     */\n    function delegates(address delegator)\n        external\n        view\n        returns (address)\n    {\n        return _delegates[delegator];\n    }\n\n   /**\n    * @notice Delegate votes from `msg.sender` to `delegatee`\n    * @param delegatee The address to delegate votes to\n    */\n    function delegate(address delegatee) external {\n        return _delegate(msg.sender, delegatee);\n    }\n\n    /**\n     * @notice Delegates votes from signatory to `delegatee`\n     * @param delegatee The address to delegate votes to\n     * @param nonce The contract state required to match the signature\n     * @param expiry The time at which to expire the signature\n     * @param v The recovery byte of the signature\n     * @param r Half of the ECDSA signature pair\n     * @param s Half of the ECDSA signature pair\n     */\n    function delegateBySig(\n        address delegatee,\n        uint nonce,\n        uint expiry,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    )\n        external\n    {\n        bytes32 domainSeparator = keccak256(\n            abi.encode(\n                DOMAIN_TYPEHASH,\n                keccak256(bytes(name)),\n                getChainId(),\n                address(this)\n            )\n        );\n\n        bytes32 structHash = keccak256(\n            abi.encode(\n                DELEGATION_TYPEHASH,\n                delegatee,\n                nonce,\n                expiry\n            )\n        );\n\n        bytes32 digest = keccak256(\n            abi.encodePacked(\n                \"\\x19\\x01\",\n                domainSeparator,\n                structHash\n            )\n        );\n\n        address signatory = ecrecover(digest, v, r, s);\n        require(signatory != address(0), \"GDAO::delegateBySig: invalid signature\");\n        require(nonce == nonces[signatory]++, \"GDAO::delegateBySig: invalid nonce\");\n        require(now \u003c= expiry, \"GDAO::delegateBySig: signature expired\");\n        return _delegate(signatory, delegatee);\n    }\n\n    /**\n     * @notice Gets the current votes balance for `account`\n     * @param account The address to get votes balance\n     * @return The number of current votes for `account`\n     */\n    function getCurrentVotes(address account)\n        external\n        view\n        returns (uint256)\n    {\n        uint32 nCheckpoints = numCheckpoints[account];\n        return nCheckpoints \u003e 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\n    }\n\n    /**\n     * @notice Determine the prior number of votes for an account as of a block number\n     * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n     * @param account The address of the account to check\n     * @param blockNumber The block number to get the vote balance at\n     * @return The number of votes the account had as of the given block\n     */\n    function getPriorVotes(address account, uint blockNumber)\n        external\n        view\n        returns (uint256)\n    {\n        require(blockNumber \u003c block.number, \"GDAO::getPriorVotes: not yet determined\");\n\n        uint32 nCheckpoints = numCheckpoints[account];\n        if (nCheckpoints == 0) {\n            return 0;\n        }\n\n        // First check most recent balance\n        if (checkpoints[account][nCheckpoints - 1].fromBlock \u003c= blockNumber) {\n            return checkpoints[account][nCheckpoints - 1].votes;\n        }\n\n        // Next check implicit zero balance\n        if (checkpoints[account][0].fromBlock \u003e blockNumber) {\n            return 0;\n        }\n\n        uint32 lower = 0;\n        uint32 upper = nCheckpoints - 1;\n        while (upper \u003e lower) {\n            uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n            Checkpoint memory cp = checkpoints[account][center];\n            if (cp.fromBlock == blockNumber) {\n                return cp.votes;\n            } else if (cp.fromBlock \u003c blockNumber) {\n                lower = center;\n            } else {\n                upper = center - 1;\n            }\n        }\n        return checkpoints[account][lower].votes;\n    }\n\n    function _delegate(address delegator, address delegatee)\n        internal\n    {\n        address currentDelegate = _delegates[delegator];\n        uint256 delegatorBalance = _gdaoBalances[delegator]; // balance of underlying GDAOs;\n        _delegates[delegator] = delegatee;\n\n        emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n        _moveDelegates(currentDelegate, delegatee, delegatorBalance);\n    }\n\n    function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {\n        if (srcRep != dstRep \u0026\u0026 amount \u003e 0) {\n            if (srcRep != address(0)) {\n                // decrease old representative\n                uint32 srcRepNum = numCheckpoints[srcRep];\n                uint256 srcRepOld = srcRepNum \u003e 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\n                uint256 srcRepNew = srcRepOld.sub(amount);\n                _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\n            }\n\n            if (dstRep != address(0)) {\n                // increase new representative\n                uint32 dstRepNum = numCheckpoints[dstRep];\n                uint256 dstRepOld = dstRepNum \u003e 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\n                uint256 dstRepNew = dstRepOld.add(amount);\n                _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\n            }\n        }\n    }\n\n    function _writeCheckpoint(\n        address delegatee,\n        uint32 nCheckpoints,\n        uint256 oldVotes,\n        uint256 newVotes\n    )\n        internal\n    {\n        uint32 blockNumber = safe32(block.number, \"GDAO::_writeCheckpoint: block number exceeds 32 bits\");\n\n        if (nCheckpoints \u003e 0 \u0026\u0026 checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\n            checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\n        } else {\n            checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\n            numCheckpoints[delegatee] = nCheckpoints + 1;\n        }\n\n        emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\n    }\n\n    function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {\n        require(n \u003c 2**32, errorMessage);\n        return uint32(n);\n    }\n\n    function getChainId() internal pure returns (uint) {\n        uint256 chainId;\n        assembly { chainId := chainid() }\n        return chainId;\n    }\n}\n\ncontract GDAOToken is GDAOGovernanceToken {\n    // Modifiers\n    modifier onlyGov() {\n        require(msg.sender == gov);\n        _;\n    }\n\n    modifier onlyMinter() {\n        require(_minterIndex[msg.sender] != 0 || msg.sender == gov, \"not minter\");\n        _;\n    }\n\n    modifier validRecipient(address to) {\n        require(to != address(0x0));\n        require(to != address(this));\n        _;\n    }\n\n    function initialize(\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_\n    )\n        public\n    {\n        name = name_;\n        symbol = symbol_;\n        decimals = decimals_;\n        _cap = 10000000 * 10 ** uint256(decimals_);\n    }\n\n    /**\n    * @notice Computes the current totalSupply\n    */\n    function totalSupply()\n        external\n        view\n        returns (uint256)\n    {\n        return _totalSupply;\n    }\n\n    function cap()\n        external\n        view\n        returns (uint256)\n    {\n        return _cap;\n    }\n\n    function setCap(uint256 ncap)\n        external\n        onlyGov\n        returns (bool)\n    {\n        require(ncap \u003e= _totalSupply, \"Invalid cap\");\n        uint256 oldCap = _cap;\n        _cap = ncap;\n        emit NewCap(oldCap, ncap);\n\n        return true;\n    }\n\n    /** \n     * Add minter\n     * @param minter minter\n     */\n    function addMinter(address minter) \n        external \n        onlyGov \n        returns (bool)\n    {\n        if (_minterIndex[minter] != 0) {\n            return false;\n        } else {\n            _minters.push(minter);\n            _minterIndex[minter] = _minters.length;\n            emit AddMinter(minter);\n\n            return true;\n        }\n    }\n    \n    /** \n     * Remove minter\n     * @param minter minter\n     */\n    function removeMinter(address minter) \n        external \n        onlyGov \n        returns (bool)\n    {\n        uint256 minterIdx = _minterIndex[minter];\n        if (minterIdx != 0) {\n            uint256 toDelIdx = minterIdx - 1;\n            uint256 lastIdx = _minters.length - 1;\n            address lastMinter = _minters[lastIdx];\n\n            _minters[toDelIdx] = lastMinter;\n            _minterIndex[lastMinter] = toDelIdx + 1;\n            _minters.pop();\n            delete _minterIndex[minter];\n\n            emit RemoveMinter(minter);\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    function minterCount() \n        external \n        view \n        returns (uint256) \n    {\n        return _minters.length;\n    }\n    \n    function getMinter(uint256 idx) \n        external \n        view \n        returns (address) \n    {\n        return _minters[idx];\n    }\n\n    /**\n    * @notice Mints new tokens, increasing totalSupply, and a users balance.\n    * @dev Limited to onlyMinter modifier\n    */\n    function mint(address to, uint256 amount)\n        external\n        onlyMinter\n        returns (bool)\n    {\n        _mint(to, amount);\n        return true;\n    }\n\n    function _mint(address to, uint256 amount)\n        internal\n    {\n      require(to != address(0), \"Mint to the zero address\");\n      // increase totalSupply\n      _totalSupply = _totalSupply.add(amount);\n\n      require(_totalSupply \u003c= _cap, \"Cap exceeded\");\n\n      // add balance\n      _gdaoBalances[to] = _gdaoBalances[to].add(amount);\n      emit Transfer(address(0), to, amount);\n    \n      // add delegates to the minter\n      _moveDelegates(address(0), _delegates[to], amount);\n      emit Mint(to, amount);\n    }\n\n    /**\n    * @notice Burns tokens, decreasing totalSupply, and a users balance.\n    */\n    function burn(uint256 amount)\n        external\n        returns (bool)\n    {\n        _burn(msg.sender, amount);\n        return true;\n    }\n\n    function _burn(address who, uint256 amount)\n        internal\n    {\n      // decrease totalSupply\n      _totalSupply = _totalSupply.sub(amount);\n\n      // decrease cap\n      _cap = _cap.sub(amount);\n\n      // sub balance\n      _gdaoBalances[who] = _gdaoBalances[who].sub(amount);\n      emit Transfer(who, address(0), amount);\n    \n      // sub delegates\n      _moveDelegates(_delegates[who], address(0), amount);\n      emit Burn(who, amount);\n    }\n\n    /* - ERC20 functionality - */\n\n    /**\n    * @dev Transfer tokens to a specified address.\n    * @param to The address to transfer to.\n    * @param value The amount to be transferred.\n    * @return True on success, false otherwise.\n    */\n    function transfer(address to, uint256 value)\n        external\n        validRecipient(to)\n        returns (bool)\n    {\n\n        // sub from balance of sender\n        _gdaoBalances[msg.sender] = _gdaoBalances[msg.sender].sub(value);\n\n        // add to balance of receiver\n        _gdaoBalances[to] = _gdaoBalances[to].add(value);\n        emit Transfer(msg.sender, to, value);\n\n        _moveDelegates(_delegates[msg.sender], _delegates[to], value);\n        return true;\n    }\n\n    /**\n    * @dev Transfer tokens from one address to another.\n    * @param from The address you want to send tokens from.\n    * @param to The address you want to transfer to.\n    * @param value The amount of tokens to be transferred.\n    */\n    function transferFrom(address from, address to, uint256 value)\n        external\n        validRecipient(to)\n        returns (bool)\n    {\n        // decrease allowance\n        _allowedFragments[from][msg.sender] = _allowedFragments[from][msg.sender].sub(value);\n\n        // sub from from\n        _gdaoBalances[from] = _gdaoBalances[from].sub(value);\n        _gdaoBalances[to] = _gdaoBalances[to].add(value);\n        emit Transfer(from, to, value);\n\n        _moveDelegates(_delegates[from], _delegates[to], value);\n        return true;\n    }\n\n    /**\n    * @param who The address to query.\n    * @return The balance of the specified address.\n    */\n    function balanceOf(address who)\n      external\n      view\n      returns (uint256)\n    {\n      return _gdaoBalances[who];\n    }\n\n    /**\n     * @dev Function to check the amount of tokens that an owner has allowed to a spender.\n     * @param owner_ The address which owns the funds.\n     * @param spender The address which will spend the funds.\n     * @return The number of tokens still available for the spender.\n     */\n    function allowance(address owner_, address spender)\n        external\n        view\n        returns (uint256)\n    {\n        return _allowedFragments[owner_][spender];\n    }\n\n    /**\n     * @dev Approve the passed address to spend the specified amount of tokens on behalf of\n     * msg.sender. This method is included for ERC20 compatibility.\n     * increaseAllowance and decreaseAllowance should be used instead.\n     * Changing an allowance with this method brings the risk that someone may transfer both\n     * the old and the new allowance - if they are both greater than zero - if a transfer\n     * transaction is mined before the later approve() call is mined.\n     *\n     * @param spender The address which will spend the funds.\n     * @param value The amount of tokens to be spent.\n     */\n    function approve(address spender, uint256 value)\n        external\n        returns (bool)\n    {\n        _allowedFragments[msg.sender][spender] = value;\n        emit Approval(msg.sender, spender, value);\n        return true;\n    }\n\n    /**\n     * @dev Increase the amount of tokens that an owner has allowed to a spender.\n     * This method should be used instead of approve() to avoid the double approval vulnerability\n     * described above.\n     * @param spender The address which will spend the funds.\n     * @param addedValue The amount of tokens to increase the allowance by.\n     */\n    function increaseAllowance(address spender, uint256 addedValue)\n        external\n        returns (bool)\n    {\n        _allowedFragments[msg.sender][spender] =\n            _allowedFragments[msg.sender][spender].add(addedValue);\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\n        return true;\n    }\n\n    /**\n     * @dev Decrease the amount of tokens that an owner has allowed to a spender.\n     *\n     * @param spender The address which will spend the funds.\n     * @param subtractedValue The amount of tokens to decrease the allowance by.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue)\n        external\n        returns (bool)\n    {\n        uint256 oldValue = _allowedFragments[msg.sender][spender];\n        if (subtractedValue \u003e= oldValue) {\n            _allowedFragments[msg.sender][spender] = 0;\n        } else {\n            _allowedFragments[msg.sender][spender] = oldValue.sub(subtractedValue);\n        }\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\n        return true;\n    }\n\n    /* - Governance Functions - */\n    /** @notice sets the pendingGov\n     * @param pendingGov_ The address of the governor to use for authentication.\n     */\n    function _setPendingGov(address pendingGov_)\n        external\n        onlyGov\n    {\n        address oldPendingGov = pendingGov;\n        pendingGov = pendingGov_;\n        emit NewPendingGov(oldPendingGov, pendingGov_);\n    }\n\n    /** @notice lets msg.sender accept governance\n     *\n     */\n    function _acceptGov()\n        external\n    {\n        require(msg.sender == pendingGov, \"!pending\");\n        address oldGov = gov;\n        gov = pendingGov;\n        pendingGov = address(0);\n        emit NewGov(oldGov, gov);\n    }\n\n}\n\ncontract GDAO is GDAOToken {\n    /**\n     * @notice Initialize the new money market\n     * @param name_ ERC-20 name of this token\n     * @param symbol_ ERC-20 symbol of this token\n     * @param decimals_ ERC-20 decimal precision of this token\n     */\n    function initialize(\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_,\n        address initial_owner,\n        uint256 initSupply_\n    )\n        public\n    {\n        require(initSupply_ \u003e= 0, \"0 init supply\");\n\n        super.initialize(name_, symbol_, decimals_);\n\n        _mint(initial_owner, initSupply_);\n\n    }\n}\n\ncontract GDAODelegationStorage {\n    /**\n     * @notice Implementation address for this contract\n     */\n    address public implementation;\n}\n\ncontract GDAODelegatorInterface is GDAODelegationStorage {\n    /**\n     * @notice Emitted when implementation is changed\n     */\n    event NewImplementation(address oldImplementation, address newImplementation);\n\n    /**\n     * @notice Called by the gov to update the implementation of the delegator\n     * @param implementation_ The address of the new implementation for delegation\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\n     */\n    function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public;\n}\n\ncontract GDAODelegateInterface is GDAODelegationStorage {\n    /**\n     * @notice Called by the delegator on a delegate to initialize it for duty\n     * @dev Should revert if any issues arise which make it unfit for delegation\n     * @param data The encoded bytes data for any initialization\n     */\n    function _becomeImplementation(bytes memory data) public;\n\n    /**\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\n     */\n    function _resignImplementation() public;\n}\n\ncontract GDAODelegate is GDAO, GDAODelegateInterface {\n    /**\n     * @notice Construct an empty delegate\n     */\n    constructor() public {}\n\n    /**\n     * @notice Called by the delegator on a delegate to initialize it for duty\n     * @param data The encoded bytes data for any initialization\n     */\n    function _becomeImplementation(bytes memory data) public {\n        // Shh -- currently unused\n        data;\n\n        // Shh -- we don\u0027t ever want this hook to be marked pure\n        if (false) {\n            implementation = address(0);\n        }\n\n        require(msg.sender == gov, \"only the gov may call _becomeImplementation\");\n    }\n\n    /**\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\n     */\n    function _resignImplementation() public {\n        // Shh -- we don\u0027t ever want this hook to be marked pure\n        if (false) {\n            implementation = address(0);\n        }\n\n        require(msg.sender == gov, \"only the gov may call _resignImplementation\");\n    }\n}"},"GDAODelegator.sol":{"content":"pragma solidity 0.5.17;\n\nimport \"./GDAODelegate.sol\";\n\ncontract GDAODelegator is GDAOTokenInterface, GDAODelegatorInterface {\n    /**\n     * @notice Construct a new GDAO\n     * @param name_ ERC-20 name of this token\n     * @param symbol_ ERC-20 symbol of this token\n     * @param decimals_ ERC-20 decimal precision of this token\n     * @param initSupply_ Initial token amount\n     * @param implementation_ The address of the implementation the contract delegates to\n     * @param becomeImplementationData The encoded args for becomeImplementation\n     */\n    constructor(\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_,\n        uint256 initSupply_,\n        address implementation_,\n        bytes memory becomeImplementationData\n    )\n        public\n    {\n\n\n        // Creator of the contract is gov during initialization\n        gov = msg.sender;\n\n        // First delegate gets to initialize the delegator (i.e. storage contract)\n        delegateTo(\n            implementation_,\n            abi.encodeWithSignature(\n                \"initialize(string,string,uint8,address,uint256)\",\n                name_,\n                symbol_,\n                decimals_,\n                msg.sender,\n                initSupply_\n            )\n        );\n\n        // New implementations always get set via the settor (post-initialize)\n        _setImplementation(implementation_, false, becomeImplementationData);\n\n    }\n\n    /**\n     * @notice Called by the gov to update the implementation of the delegator\n     * @param implementation_ The address of the new implementation for delegation\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\n     */\n    function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public {\n        require(msg.sender == gov, \"GDAODelegator::_setImplementation: Caller must be gov\");\n\n        if (allowResign) {\n            delegateToImplementation(abi.encodeWithSignature(\"_resignImplementation()\"));\n        }\n\n        address oldImplementation = implementation;\n        implementation = implementation_;\n\n        delegateToImplementation(abi.encodeWithSignature(\"_becomeImplementation(bytes)\", becomeImplementationData));\n\n        emit NewImplementation(oldImplementation, implementation);\n    }\n\n    /**\n     * @notice Sender supplies assets into the market and receives cTokens in exchange\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param mintAmount The amount of the underlying asset to supply\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function mint(address to, uint256 mintAmount)\n        external\n        returns (bool)\n    {\n        to; mintAmount; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n    * @notice Burns tokens, decreasing totalSupply, and a users balance.\n    */\n    function burn(uint256 amount)\n        external\n        returns (bool)\n    {\n        amount;\n        delegateAndReturn();\n    }\n\n    /**\n     * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transfer(address dst, uint256 amount)\n        external\n        returns (bool)\n    {\n        dst; amount; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n     * @notice Transfer `amount` tokens from `src` to `dst`\n     * @param src The address of the source account\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transferFrom(\n        address src,\n        address dst,\n        uint256 amount\n    )\n        external\n        returns (bool)\n    {\n        src; dst; amount; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n     * @notice Approve `spender` to transfer up to `amount` from `src`\n     * @dev This will overwrite the approval amount for `spender`\n     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n     * @param spender The address of the account which may transfer tokens\n     * @param amount The number of tokens that are approved (-1 means infinite)\n     * @return Whether or not the approval succeeded\n     */\n    function approve(\n        address spender,\n        uint256 amount\n    )\n        external\n        returns (bool)\n    {\n        spender; amount; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n     * @dev Increase the amount of tokens that an owner has allowed to a spender.\n     * This method should be used instead of approve() to avoid the double approval vulnerability\n     * described above.\n     * @param spender The address which will spend the funds.\n     * @param addedValue The amount of tokens to increase the allowance by.\n     */\n    function increaseAllowance(\n        address spender,\n        uint256 addedValue\n    )\n        external\n        returns (bool)\n    {\n        spender; addedValue; // Shh\n        delegateAndReturn();\n    }\n\n    function totalSupply()\n        external\n        view\n        returns (uint256)\n    {\n        delegateToViewAndReturn();\n    }\n\n     function cap()\n        external\n        view\n        returns (uint256)\n    {\n        delegateToViewAndReturn();\n    }\n\n    function setCap(uint256 ncap)\n        external\n        returns (bool)\n    {\n        ncap;\n        delegateAndReturn();\n    }\n\n    /** \n     * Add minter\n     * @param minter minter\n     */\n    function addMinter(address minter) \n        external  \n        returns (bool)\n    {\n        minter;\n        delegateAndReturn();\n    }\n    \n    /** \n     * Remove minter\n     * @param minter minter\n     */\n    function removeMinter(address minter) \n        external  \n        returns (bool)\n    {\n        minter;\n        delegateAndReturn();\n    }\n\n    function minterCount() \n        external \n        view \n        returns (uint256) \n    {\n        delegateToViewAndReturn();\n    }\n    \n    function getMinter(uint256 idx) \n        external \n        view \n        returns (address) \n    {\n        idx;\n        delegateToViewAndReturn();\n    }\n  \n\n    /**\n     * @dev Decrease the amount of tokens that an owner has allowed to a spender.\n     *\n     * @param spender The address which will spend the funds.\n     * @param subtractedValue The amount of tokens to decrease the allowance by.\n     */\n    function decreaseAllowance(\n        address spender,\n        uint256 subtractedValue\n    )\n        external\n        returns (bool)\n    {\n        spender; subtractedValue; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n     * @notice Get the current allowance from `owner` for `spender`\n     * @param owner The address of the account which owns the tokens to be spent\n     * @param spender The address of the account which may transfer tokens\n     * @return The number of tokens allowed to be spent (-1 means infinite)\n     */\n    function allowance(\n        address owner,\n        address spender\n    )\n        external\n        view\n        returns (uint256)\n    {\n        owner; spender; // Shh\n        delegateToViewAndReturn();\n    }\n\n    /**\n     * @notice Get the current allowance from `owner` for `spender`\n     * @param delegator The address of the account which has designated a delegate\n     * @return Address of delegatee\n     */\n    function delegates(\n        address delegator\n    )\n        external\n        view\n        returns (address)\n    {\n        delegator; // Shh\n        delegateToViewAndReturn();\n    }\n\n    /**\n     * @notice Get the token balance of the `owner`\n     * @param owner The address of the account to query\n     * @return The number of tokens owned by `owner`\n     */\n    function balanceOf(address owner)\n        external\n        view\n        returns (uint256)\n    {\n        owner; // Shh\n        delegateToViewAndReturn();\n    }\n\n    /*** Gov Functions ***/\n\n    /**\n      * @notice Begins transfer of gov rights. The newPendingGov must call `_acceptGov` to finalize the transfer.\n      * @dev Gov function to begin change of gov. The newPendingGov must call `_acceptGov` to finalize the transfer.\n      * @param newPendingGov New pending gov.\n      */\n    function _setPendingGov(address newPendingGov)\n        external\n    {\n        newPendingGov; // Shh\n        delegateAndReturn();\n    }\n\n    /**\n      * @notice Accepts transfer of gov rights. msg.sender must be pendingGov\n      * @dev Gov function for pending gov to accept role and update gov\n      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n      */\n    function _acceptGov()\n        external\n    {\n        delegateAndReturn();\n    }\n\n\n    function getPriorVotes(address account, uint blockNumber)\n        external\n        view\n        returns (uint256)\n    {\n        account; blockNumber;\n        delegateToViewAndReturn();\n    }\n\n    function delegateBySig(\n        address delegatee,\n        uint nonce,\n        uint expiry,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    )\n        external\n    {\n        delegatee; nonce; expiry; v; r; s;\n        delegateAndReturn();\n    }\n\n    function delegate(address delegatee)\n        external\n    {\n        delegatee;\n        delegateAndReturn();\n    }\n\n    function getCurrentVotes(address account)\n        external\n        view\n        returns (uint256)\n    {\n        account;\n        delegateToViewAndReturn();\n    }\n\n    /**\n     * @notice Internal method to delegate execution to another contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     * @param callee The contract to delegatecall\n     * @param data The raw data to delegatecall\n     * @return The returned bytes from the delegatecall\n     */\n    function delegateTo(address callee, bytes memory data) internal returns (bytes memory) {\n        (bool success, bytes memory returnData) = callee.delegatecall(data);\n        assembly {\n            if eq(success, 0) {\n                revert(add(returnData, 0x20), returndatasize)\n            }\n        }\n        return returnData;\n    }\n\n    /**\n     * @notice Delegates execution to the implementation contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     * @param data The raw data to delegatecall\n     * @return The returned bytes from the delegatecall\n     */\n    function delegateToImplementation(bytes memory data) public returns (bytes memory) {\n        return delegateTo(implementation, data);\n    }\n\n    /**\n     * @notice Delegates execution to an implementation contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     *  There are an additional 2 prefix uints from the wrapper returndata, which we ignore since we make an extra hop.\n     * @param data The raw data to delegatecall\n     * @return The returned bytes from the delegatecall\n     */\n    function delegateToViewImplementation(bytes memory data) public view returns (bytes memory) {\n        (bool success, bytes memory returnData) = address(this).staticcall(abi.encodeWithSignature(\"delegateToImplementation(bytes)\", data));\n        assembly {\n            if eq(success, 0) {\n                revert(add(returnData, 0x20), returndatasize)\n            }\n        }\n        return abi.decode(returnData, (bytes));\n    }\n\n    function delegateToViewAndReturn() private view returns (bytes memory) {\n        (bool success, ) = address(this).staticcall(abi.encodeWithSignature(\"delegateToImplementation(bytes)\", msg.data));\n\n        assembly {\n            let free_mem_ptr := mload(0x40)\n            returndatacopy(free_mem_ptr, 0, returndatasize)\n\n            switch success\n            case 0 { revert(free_mem_ptr, returndatasize) }\n            default { return(add(free_mem_ptr, 0x40), returndatasize) }\n        }\n    }\n\n    function delegateAndReturn() private returns (bytes memory) {\n        (bool success, ) = implementation.delegatecall(msg.data);\n\n        assembly {\n            let free_mem_ptr := mload(0x40)\n            returndatacopy(free_mem_ptr, 0, returndatasize)\n\n            switch success\n            case 0 { revert(free_mem_ptr, returndatasize) }\n            default { return(free_mem_ptr, returndatasize) }\n        }\n    }\n\n    /**\n     * @notice Delegates execution to an implementation contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     */\n    function () external payable {\n        require(msg.value == 0,\"GDAODelegator:fallback: cannot send value to fallback\");\n\n        // delegate all other functions to current implementation\n        delegateAndReturn();\n    }\n}"}}