// Vulnerability label: DC1
{{
  "language": "Solidity",
  "sources": {
    "contracts/ClaimConfig.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.7.3;\n\nimport \"./utils/SafeMath.sol\";\nimport \"./utils/Ownable.sol\";\nimport \"./interfaces/IClaimConfig.sol\";\nimport \"./interfaces/IProtocol.sol\";\n\n/**\n * @title Config for ClaimManagement contract\n * @author Alan\n */\ncontract ClaimConfig is IClaimConfig, Ownable {\n    using SafeMath for uint256;\n    \n    bool public override allowPartialClaim = true;\n\n    address public override auditor;\n    address public override governance;\n    address public override treasury;\n    address public override protocolFactory;\n    \n    // The max time allowed from filing a claim to a decision made\n    uint256 public override maxClaimDecisionWindow = 7 days;\n    uint256 public override baseClaimFee = 10e18;\n    uint256 public override forceClaimFee = 500e18;\n    uint256 public override feeMultiplier = 2;\n\n    // protocol => claim fee\n    mapping(address => uint256) private protocolClaimFee;\n\n    IERC20 public override feeCurrency = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);\n\n    modifier onlyGovernance() {\n        require(msg.sender == governance, \"COVER_CC: !governance\");\n        _;\n    }\n\n    /**\n     * @notice Set the address of governance\n     * @dev Governance address cannot be set to owner or 0 address\n     */\n    function setGovernance(address _governance) external override onlyGovernance {\n        require(_governance != address(0), \"COVER_CC: governance cannot be 0\");\n        require(_governance != owner(), \"COVER_CC: governance cannot be owner\");\n        governance = _governance;\n    }\n\n    /**\n     * @notice Set the address of treasury\n     */\n    function setTreasury(address _treasury) external override onlyOwner {\n        require(_treasury != address(0), \"COVER_CC: treasury cannot be 0\");\n        treasury = _treasury;\n    }\n\n    /**\n     * @notice Set max time window allowed to decide a claim after filed, requires at least 3 days for voting\n     */\n    function setMaxClaimDecisionWindow(uint256 _newTimeWindow) external override onlyOwner {\n        require(_newTimeWindow < 3 days, \"COVER_CC: window too short\");\n        maxClaimDecisionWindow = _newTimeWindow;\n    }\n\n    /**\n     * @notice Set the status and address of auditor\n     */\n    function setAuditor(address _auditor) external override onlyOwner {\n        auditor = _auditor;\n    }\n\n    /**\n     * @notice Set the status of allowing partial claims\n     */\n    function setPartialClaimStatus(bool _allowPartialClaim) external override onlyOwner {\n        allowPartialClaim = _allowPartialClaim;\n    }\n\n    /**\n     * @notice Set fees and currency of filing a claim\n     * @dev `_forceClaimFee` must be > `_baseClaimFee`\n     */\n    function setFeeAndCurrency(uint256 _baseClaimFee, uint256 _forceClaimFee, address _currency)\n        external \n        override \n        onlyGovernance \n    {\n        require(_baseClaimFee > 0, \"COVER_CC: baseClaimFee <= 0\");\n        require(_forceClaimFee > _baseClaimFee, \"COVER_CC: forceClaimFee <= baseClaimFee\");\n        require(_currency != address(0), \"COVER_CC: feeCurrency cannot be 0\");\n        baseClaimFee = _baseClaimFee;\n        forceClaimFee = _forceClaimFee;\n        feeCurrency = IERC20(_currency);\n    }\n\n    /**\n     * @notice Set the fee multiplier to `_multiplier`\n     * @dev `_multiplier` must be atleast 1\n     */\n    function setFeeMultiplier(uint256 _multiplier) external override onlyGovernance {\n        require(_multiplier >= 1, \"COVER_CC: multiplier < 1\");\n        feeMultiplier = _multiplier;\n    }\n\n    /**\n     * @notice Get status of auditor voting\n     * @dev Returns false if `auditor` is 0\n     * @return status of auditor voting in decideClaim\n     */\n    function isAuditorVoting() public view override returns (bool) {\n        return auditor != address(0);\n    }\n\n    /**\n     * @notice Get the claim fee for protocol `_protocol`\n     * @dev Will return `baseClaimFee` if fee is 0\n     * @return fee for filing a claim for protocol\n     */\n    function getProtocolClaimFee(address _protocol) public view override returns (uint256) {\n        return protocolClaimFee[_protocol] == 0 ? baseClaimFee : protocolClaimFee[_protocol];\n    }\n\n    /**\n     * @notice Get the time window allowed to file after an incident happened\n     * @dev it is calculated based on the noclaimRedeemDelay of the protocol - (maxClaimDecisionWindow) - 1hour\n     * @return time window\n     */\n    function getFileClaimWindow(address _protocol) public view override returns (uint256) {\n        uint256 noclaimRedeemDelay = IProtocol(_protocol).noclaimRedeemDelay();\n        return noclaimRedeemDelay.sub(maxClaimDecisionWindow).sub(1 hours);\n    }\n\n    /**\n     * @notice Updates fee for protocol `_protocol` by multiplying current fee by `feeMultiplier`\n     * @dev protocolClaimFee[protocol] cannot exceed `baseClaimFee`\n     */\n    function _updateProtocolClaimFee(address _protocol) internal {\n        uint256 newFee = getProtocolClaimFee(_protocol).mul(feeMultiplier);\n        if (newFee <= forceClaimFee) {\n            protocolClaimFee[_protocol] = newFee;\n        }\n    }\n\n    /**\n     * @notice Resets fee for protocol `_protocol` to `baseClaimFee`\n     */\n    function _resetProtocolClaimFee(address _protocol) internal {\n        protocolClaimFee[_protocol] = baseClaimFee;\n    }\n}"
    },
    "contracts/utils/SafeMath.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\n/**\n * @dev Wrappers over Solidity's 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's 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's `+` 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 >= 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's `-` 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's `-` 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 <= 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's `*` 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 'a' not being zero, but the\n        // benefit is lost if 'b' 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's `/` 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's `/` 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 > 0, errorMessage);\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn't 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's `%` 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's `%` 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}"
    },
    "contracts/utils/Ownable.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"../interfaces/IOwnable.sol\";\nimport \"./Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n * @author crypto-pumpkin@github\n *\n * By initialization, the owner account will be the one that called initializeOwner. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\ncontract Ownable is Initializable {\n    address private _owner;\n    address private _newOwner;\n\n    event OwnershipTransferInitiated(address indexed previousOwner, address indexed newOwner);\n    event OwnershipTransferCompleted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev COVER: Initializes the contract setting the deployer as the initial owner.\n     */\n    function initializeOwner() internal initializer {\n        _owner = msg.sender;\n        emit OwnershipTransferCompleted(address(0), _owner);\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(_owner == msg.sender, \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        emit OwnershipTransferInitiated(_owner, newOwner);\n        _newOwner = newOwner;\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function claimOwnership() public virtual {\n        require(_newOwner == msg.sender, \"Ownable: caller is not the owner\");\n        emit OwnershipTransferCompleted(_owner, _newOwner);\n        _owner = _newOwner;\n    }\n}"
    },
    "contracts/interfaces/IClaimConfig.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\nimport \"./IERC20.sol\";\n\n/**\n * @dev ClaimConfg contract interface. See {ClaimConfig}.\n * @author Alan\n */\ninterface IClaimConfig {\n    function allowPartialClaim() external view returns (bool);\n    function auditor() external view returns (address);\n    function governance() external view returns (address);\n    function treasury() external view returns (address);\n    function protocolFactory() external view returns (address);\n    function maxClaimDecisionWindow() external view returns (uint256);\n    function baseClaimFee() external view returns (uint256);\n    function forceClaimFee() external view returns (uint256);\n    function feeMultiplier() external view returns (uint256);\n    function feeCurrency() external view returns (IERC20);\n    function getFileClaimWindow(address _protocol) external view returns (uint256);\n    function isAuditorVoting() external view returns (bool);\n    function getProtocolClaimFee(address _protocol) external view returns (uint256);\n    \n    // @notice only dev\n    function setMaxClaimDecisionWindow(uint256 _newTimeWindow) external;\n    function setTreasury(address _treasury) external;\n    function setAuditor(address _auditor) external;\n    function setPartialClaimStatus(bool _allowPartialClaim) external;\n\n    // @dev Only callable by governance\n    function setGovernance(address _governance) external;\n    function setFeeAndCurrency(uint256 _baseClaimFee, uint256 _forceClaimFee, address _currency) external;\n    function setFeeMultiplier(uint256 _multiplier) external;\n}"
    },
    "contracts/interfaces/IProtocol.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\n/**\n * @dev Protocol contract interface. See {Protocol}.\n * @author crypto-pumpkin@github\n */\ninterface IProtocol {\n  /// @notice emit when a claim against the protocol is accepted\n  event ClaimAccepted(uint256 newClaimNonce);\n\n  function getProtocolDetails()\n    external view returns (\n      bytes32 _name,\n      bool _active,\n      uint256 _claimNonce,\n      uint256 _claimRedeemDelay,\n      uint256 _noclaimRedeemDelay,\n      address[] memory _collaterals,\n      uint48[] memory _expirationTimestamps,\n      address[] memory _allCovers,\n      address[] memory _allActiveCovers\n    );\n  function active() external view returns (bool);\n  function name() external view returns (bytes32);\n  function claimNonce() external view returns (uint256);\n  /// @notice delay # of seconds for redeem with accepted claim, redeemCollateral is not affected\n  function claimRedeemDelay() external view returns (uint256);\n  /// @notice delay # of seconds for redeem without accepted claim, redeemCollateral is not affected\n  function noclaimRedeemDelay() external view returns (uint256);\n  function activeCovers(uint256 _index) external view returns (address);\n  function claimDetails(uint256 _claimNonce) external view returns (uint16 _payoutNumerator, uint16 _payoutDenominator, uint48 _incidentTimestamp, uint48 _timestamp);\n  function collateralStatusMap(address _collateral) external view returns (uint8 _status);\n  function expirationTimestampMap(uint48 _expirationTimestamp) external view returns (bytes32 _name, uint8 _status);\n  function coverMap(address _collateral, uint48 _expirationTimestamp) external view returns (address);\n\n  function collaterals(uint256 _index) external view returns (address);\n  function collateralsLength() external view returns (uint256);\n  function expirationTimestamps(uint256 _index) external view returns (uint48);\n  function expirationTimestampsLength() external view returns (uint256);\n  function activeCoversLength() external view returns (uint256);\n  function claimsLength() external view returns (uint256);\n  function addCover(address _collateral, uint48 _timestamp, uint256 _amount)\n    external returns (bool);\n\n  /// @notice access restriction - claimManager\n  function enactClaim(uint16 _payoutNumerator, uint16 _payoutDenominator, uint48 _incidentTimestamp, uint256 _protocolNonce) external returns (bool);\n\n  /// @notice access restriction - dev\n  function setActive(bool _active) external returns (bool);\n  function updateExpirationTimestamp(uint48 _expirationTimestamp, bytes32 _expirationTimestampName, uint8 _status) external returns (bool);\n  function updateCollateral(address _collateral, uint8 _status) external returns (bool);\n\n  /// @notice access restriction - governance\n  function updateClaimRedeemDelay(uint256 _claimRedeemDelay) external returns (bool);\n  function updateNoclaimRedeemDelay(uint256 _noclaimRedeemDelay) external returns (bool);\n}"
    },
    "contracts/interfaces/IOwnable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\n/**\n * @title Interface of Ownable\n */\ninterface IOwnable {\n    function owner() external view returns (address);\n}\n"
    },
    "contracts/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\n// solhint-disable-next-line compiler-version\npragma solidity >=0.4.24 <0.8.0;\n\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n * \n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.\n * \n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n\n    /**\n     * @dev Indicates that the contract has been initialized.\n     */\n    bool private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Modifier to protect an initializer function from being invoked twice.\n     */\n    modifier initializer() {\n        require(_initializing || _isConstructor() || !_initialized, \"Initializable: contract is already initialized\");\n\n        bool isTopLevelCall = !_initializing;\n        if (isTopLevelCall) {\n            _initializing = true;\n            _initialized = true;\n        }\n\n        _;\n\n        if (isTopLevelCall) {\n            _initializing = false;\n        }\n    }\n\n    /// @dev Returns true if and only if the function is running in the constructor\n    function _isConstructor() private view returns (bool) {\n        // extcodesize checks the size of the code stored in an address, and\n        // address returns the current address. Since the code is still not\n        // deployed when running a constructor, any checks on its code size will\n        // yield zero, making it an effective way to detect if a contract is\n        // under construction or not.\n        address self = address(this);\n        uint256 cs;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { cs := extcodesize(self) }\n        return cs == 0;\n    }\n}"
    },
    "contracts/interfaces/IERC20.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\n/**\n * @title Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    event Transfer(address indexed from, address indexed to, uint256 value);\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    function symbol() external view returns (string memory);\n    function balanceOf(address account) external view returns (uint256);\n    function transfer(address recipient, uint256 amount) external returns (bool);\n    function approve(address spender, uint256 amount) external returns (bool);\n    function allowance(address owner, address spender) external view returns (uint256);\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n    function totalSupply() external view returns (uint256);\n\n    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);\n    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);\n}"
    },
    "contracts/ClaimManagement.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.7.3;\npragma experimental ABIEncoderV2;\n\nimport \"./ClaimConfig.sol\";\nimport \"./interfaces/IProtocol.sol\";\nimport \"./interfaces/IProtocolFactory.sol\";\nimport \"./interfaces/IClaimManagement.sol\";\nimport \"./utils/SafeERC20.sol\";\n\n/**\n * @title Claim Management for claims filed for a COVER supported protocol\n * @author Alan\n */\ncontract ClaimManagement is IClaimManagement, ClaimConfig {\n    using SafeERC20 for IERC20;\n    using SafeMath for uint256;\n\n    // protocol => nonce => Claim[]\n    mapping(address => mapping(uint256 => Claim[])) public override protocolClaims;\n\n    modifier onlyApprovedDecider() {\n        if (isAuditorVoting()) {\n            require(msg.sender == auditor, \"COVER_CM: !auditor\");\n        } else {\n            require(msg.sender == governance, \"COVER_CM: !governance\");\n        }\n        _;\n    }\n\n    modifier onlyWhenAuditorVoting() {\n        require(isAuditorVoting(), \"COVER_CM: !isAuditorVoting\");\n        _;\n    }\n\n    /**\n     * @notice Initialize governance and treasury addresses\n     * @dev Governance address cannot be set to owner address; `_auditor` can be 0.\n     * @param _governance address: address of the governance account\n     * @param _auditor address: address of the auditor account\n     * @param _treasury address: address of the treasury account\n     * @param _protocolFactory address: address of the protocol factory\n     */\n    constructor(address _governance, address _auditor, address _treasury, address _protocolFactory) {\n        require(\n            _governance != msg.sender && _governance != address(0), \n            \"COVER_CC: governance cannot be owner or 0\"\n        );\n        require(_treasury != address(0), \"COVER_CM: treasury cannot be 0\");\n        require(_protocolFactory != address(0), \"COVER_CM: protocol factory cannot be 0\");\n        governance = _governance;\n        auditor = _auditor;\n        treasury = _treasury;\n        protocolFactory = _protocolFactory;\n\n        initializeOwner();\n    }\n\n    /**\n     * @notice File a claim for a COVER-supported contract `_protocol` \n     * by paying the `protocolClaimFee[_protocol]` fee\n     * @dev `_incidentTimestamp` must be within the past 14 days\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _protocolName bytes32: protocol name for `_protocol`\n     * @param _incidentTimestamp uint48: timestamp of the claim incident\n     * \n     * Emits ClaimFiled\n     */ \n    function fileClaim(address _protocol, bytes32 _protocolName, uint48 _incidentTimestamp) \n        external \n        override \n    {\n        require(_protocol != address(0), \"COVER_CM: protocol cannot be 0\");\n        require(\n            _protocol == getAddressFromFactory(_protocolName), \n            \"COVER_CM: invalid protocol address\"\n        );\n        require(\n            block.timestamp.sub(_incidentTimestamp) <= getFileClaimWindow(_protocol),\n            \"COVER_CM: block.timestamp - incidentTimestamp > fileClaimWindow\"\n        );\n        uint256 nonce = getProtocolNonce(_protocol);\n        uint256 claimFee = getProtocolClaimFee(_protocol);\n        protocolClaims[_protocol][nonce].push(Claim({\n            state: ClaimState.Filed,\n            filedBy: msg.sender,\n            payoutNumerator: 0,\n            payoutDenominator: 1,\n            filedTimestamp: uint48(block.timestamp),\n            incidentTimestamp: _incidentTimestamp,\n            decidedTimestamp: 0,\n            feePaid: claimFee\n        }));\n        feeCurrency.safeTransferFrom(msg.sender, address(this), claimFee);\n        _updateProtocolClaimFee(_protocol);\n        emit ClaimFiled({\n            isForced: false,\n            filedBy: msg.sender,\n            protocol: _protocol,\n            incidentTimestamp: _incidentTimestamp,\n            nonce: nonce,\n            index: protocolClaims[_protocol][nonce].length - 1,\n            feePaid: claimFee\n        });\n    }\n\n    /**\n     * @notice Force file a claim for a COVER-supported contract `_protocol`\n     * that bypasses validateClaim by paying the `forceClaimFee` fee\n     * @dev `_incidentTimestamp` must be within the past 14 days. \n     * Only callable when isAuditorVoting is true\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _protocolName bytes32: protocol name for `_protocol`\n     * @param _incidentTimestamp uint48: timestamp of the claim incident\n     * \n     * Emits ClaimFiled\n     */\n    function forceFileClaim(address _protocol, bytes32 _protocolName, uint48 _incidentTimestamp)\n        external \n        override \n        onlyWhenAuditorVoting \n    {\n        require(_protocol != address(0), \"COVER_CM: protocol cannot be 0\");\n        require(\n            _protocol == getAddressFromFactory(_protocolName), \n            \"COVER_CM: invalid protocol address\"\n        );  \n        require(\n            block.timestamp.sub(_incidentTimestamp) <= getFileClaimWindow(_protocol),\n            \"COVER_CM: block.timestamp - incidentTimestamp > fileClaimWindow\"\n        );\n        uint256 nonce = getProtocolNonce(_protocol);\n        protocolClaims[_protocol][nonce].push(Claim({\n            state: ClaimState.ForceFiled,\n            filedBy: msg.sender,\n            payoutNumerator: 0,\n            payoutDenominator: 1,\n            filedTimestamp: uint48(block.timestamp),\n            incidentTimestamp: _incidentTimestamp,\n            decidedTimestamp: 0,\n            feePaid: forceClaimFee\n        }));\n        feeCurrency.safeTransferFrom(msg.sender, address(this), forceClaimFee);\n        emit ClaimFiled({\n            isForced: true,\n            filedBy: msg.sender,\n            protocol: _protocol,\n            incidentTimestamp: _incidentTimestamp,\n            nonce: nonce,\n            index: protocolClaims[_protocol][nonce].length - 1,\n            feePaid: forceClaimFee\n        });\n    }\n\n    /**\n     * @notice Validates whether claim will be passed to approvedDecider to decideClaim\n     * @dev Only callable if isAuditorVoting is true\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _nonce uint256: nonce of the protocol\n     * @param _index uint256: index of the claim\n     * @param _claimIsValid bool: true if claim is valid and passed to auditor, false otherwise\n     *     \n     * Emits ClaimValidated\n     */\n    function validateClaim(address _protocol, uint256 _nonce, uint256 _index, bool _claimIsValid)\n        external \n        override \n        onlyGovernance\n        onlyWhenAuditorVoting \n    {\n        Claim storage claim = protocolClaims[_protocol][_nonce][_index];\n        require(\n            _nonce == getProtocolNonce(_protocol), \n            \"COVER_CM: input nonce != protocol nonce\"\n            );\n        require(claim.state == ClaimState.Filed, \"COVER_CM: claim not filed\");\n        if (_claimIsValid) {\n            claim.state = ClaimState.Validated;\n            _resetProtocolClaimFee(_protocol);\n        } else {\n            claim.state = ClaimState.Invalidated;\n            claim.decidedTimestamp = uint48(block.timestamp);\n            feeCurrency.safeTransfer(treasury, claim.feePaid);\n        }\n        emit ClaimValidated({\n            claimIsValid: _claimIsValid,\n            protocol: _protocol,\n            nonce: _nonce,\n            index: _index\n        });\n    }\n\n    /**\n     * @notice Decide whether claim for a protocol should be accepted(will payout) or denied\n     * @dev Only callable by approvedDecider\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _nonce uint256: nonce of the protocol\n     * @param _index uint256: index of the claim\n     * @param _claimIsAccepted bool: true if claim is accepted and will payout, otherwise false\n     * @param _payoutNumerator uint256: numerator of percent payout, 0 if _claimIsAccepted = false\n     * @param _payoutDenominator uint256: denominator of percent payout\n     *\n     * Emits ClaimDecided\n     */\n    function decideClaim(\n        address _protocol, \n        uint256 _nonce, \n        uint256 _index, \n        bool _claimIsAccepted, \n        uint16 _payoutNumerator, \n        uint16 _payoutDenominator\n    )   \n        external\n        override \n        onlyApprovedDecider\n    {\n        require(\n            _nonce == getProtocolNonce(_protocol), \n            \"COVER_CM: input nonce != protocol nonce\"\n        );\n        Claim storage claim = protocolClaims[_protocol][_nonce][_index];\n        if (isAuditorVoting()) {\n            require(\n                claim.state == ClaimState.Validated || \n                claim.state == ClaimState.ForceFiled, \n                \"COVER_CM: claim not validated or forceFiled\"\n            );\n        } else {\n            require(claim.state == ClaimState.Filed, \"COVER_CM: claim not filed\");\n        }\n\n        if (_isDecisionWindowPassed(claim)) {\n            // Max decision claim window passed, claim is default to Denied\n            _claimIsAccepted = false;\n        }\n        if (_claimIsAccepted) {\n            require(_payoutNumerator > 0, \"COVER_CM: claim accepted, but payoutNumerator == 0\");\n            if (allowPartialClaim) {\n                require(\n                    _payoutNumerator <= _payoutDenominator, \n                    \"COVER_CM: payoutNumerator > payoutDenominator\"\n                );\n            } else {\n                require(\n                    _payoutNumerator == _payoutDenominator, \n                    \"COVER_CM: payoutNumerator != payoutDenominator\"\n                );\n            }\n            claim.state = ClaimState.Accepted;\n            claim.payoutNumerator = _payoutNumerator;\n            claim.payoutDenominator = _payoutDenominator;\n            feeCurrency.safeTransfer(claim.filedBy, claim.feePaid);\n            _resetProtocolClaimFee(_protocol);\n            IProtocol(_protocol).enactClaim(_payoutNumerator, _payoutDenominator, claim.incidentTimestamp, _nonce);\n        } else {\n            require(_payoutNumerator == 0, \"COVER_CM: claim denied (default if passed window), but payoutNumerator != 0\");\n            claim.state = ClaimState.Denied;\n            feeCurrency.safeTransfer(treasury, claim.feePaid);\n        }\n        claim.decidedTimestamp = uint48(block.timestamp);\n        emit ClaimDecided({\n            claimIsAccepted: _claimIsAccepted, \n            protocol: _protocol, \n            nonce: _nonce, \n            index: _index, \n            payoutNumerator: _payoutNumerator, \n            payoutDenominator: _payoutDenominator\n        });\n    }\n\n    /**\n     * @notice Get all claims for protocol `_protocol` and nonce `_nonce` in state `_state`\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _nonce uint256: nonce of the protocol\n     * @param _state ClaimState: state of claim\n     * @return all claims for protocol and nonce in given state\n     */\n    function getAllClaimsByState(address _protocol, uint256 _nonce, ClaimState _state)\n        external \n        view \n        override \n        returns (Claim[] memory) \n    {\n        Claim[] memory allClaims = protocolClaims[_protocol][_nonce];\n        uint256 count;\n        Claim[] memory temp = new Claim[](allClaims.length);\n        for (uint i = 0; i < allClaims.length; i++) {\n            if (allClaims[i].state == _state) {\n                temp[count] = allClaims[i];\n                count++;\n            }\n        }\n        Claim[] memory claimsByState = new Claim[](count);\n        for (uint i = 0; i < count; i++) {\n            claimsByState[i] = temp[i];\n        }\n        return claimsByState;\n    }\n\n    /**\n     * @notice Get all claims for protocol `_protocol` and nonce `_nonce`\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @param _nonce uint256: nonce of the protocol\n     * @return all claims for protocol and nonce\n     */\n    function getAllClaimsByNonce(address _protocol, uint256 _nonce) \n        external \n        view \n        override \n        returns (Claim[] memory) \n    {\n        return protocolClaims[_protocol][_nonce];\n    }\n\n    /**\n     * @notice Get the protocol address from the protocol factory\n     * @param _protocolName bytes32: protocol name\n     * @return address corresponding to the protocol name `_protocolName`\n     */\n    function getAddressFromFactory(bytes32 _protocolName) public view override returns (address) {\n        return IProtocolFactory(protocolFactory).protocols(_protocolName);\n    }\n\n    /**\n     * @notice Get the current nonce for protocol `_protocol`\n     * @param _protocol address: contract address of the protocol that COVER supports\n     * @return the current nonce for protocol `_protocol`\n     */\n    function getProtocolNonce(address _protocol) public view override returns (uint256) {\n        return IProtocol(_protocol).claimNonce();\n    }\n\n    /**\n     * The times passed since the claim was filed has to be less than the max claim decision window\n     */\n    function _isDecisionWindowPassed(Claim memory claim) private view returns (bool) {\n        return block.timestamp.sub(claim.filedTimestamp) > maxClaimDecisionWindow.sub(1 hours);\n    }\n} "
    },
    "contracts/interfaces/IProtocolFactory.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\n/**\n * @dev ProtocolFactory contract interface. See {ProtocolFactory}.\n * @author crypto-pumpkin@github\n */\ninterface IProtocolFactory {\n  /// @notice emit when a new protocol is supported in COVER\n  event ProtocolInitiation(address protocolAddress);\n\n  function getAllProtocolAddresses() external view returns (address[] memory);\n  function getRedeemFees() external view returns (uint16 _numerator, uint16 _denominator);\n  function redeemFeeNumerator() external view returns (uint16);\n  function redeemFeeDenominator() external view returns (uint16);\n  function protocolImplementation() external view returns (address);\n  function coverImplementation() external view returns (address);\n  function coverERC20Implementation() external view returns (address);\n  function treasury() external view returns (address);\n  function governance() external view returns (address);\n  function claimManager() external view returns (address);\n  function protocols(bytes32 _protocolName) external view returns (address);\n\n  function getProtocolsLength() external view returns (uint256);\n  function getProtocolNameAndAddress(uint256 _index) external view returns (bytes32, address);\n  /// @notice return contract address, the contract may not be deployed yet\n  function getProtocolAddress(bytes32 _name) external view returns (address);\n  /// @notice return contract address, the contract may not be deployed yet\n  function getCoverAddress(bytes32 _protocolName, uint48 _timestamp, address _collateral, uint256 _claimNonce) external view returns (address);\n  /// @notice return contract address, the contract may not be deployed yet\n  function getCovTokenAddress(bytes32 _protocolName, uint48 _timestamp, address _collateral, uint256 _claimNonce, bool _isClaimCovToken) external view returns (address);\n\n  /// @notice access restriction - owner (dev)\n  /// @dev update this will only affect contracts deployed after\n  function updateProtocolImplementation(address _newImplementation) external returns (bool);\n  /// @dev update this will only affect contracts deployed after\n  function updateCoverImplementation(address _newImplementation) external returns (bool);\n  /// @dev update this will only affect contracts deployed after\n  function updateCoverERC20Implementation(address _newImplementation) external returns (bool);\n  function addProtocol(\n    bytes32 _name,\n    bool _active,\n    address _collateral,\n    uint48[] calldata _timestamps,\n    bytes32[] calldata _timestampNames\n  ) external returns (address);\n  function updateTreasury(address _address) external returns (bool);\n  function updateClaimManager(address _address) external returns (bool);\n\n  /// @notice access restriction - governance\n  function updateFees(uint16 _redeemFeeNumerator, uint16 _redeemFeeDenominator) external returns (bool);\n  function updateGovernance(address _address) external returns (bool);\n}  "
    },
    "contracts/interfaces/IClaimManagement.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\npragma experimental ABIEncoderV2;\n\n/**\n * @dev ClaimManagement contract interface. See {ClaimManagement}.\n * @author Alan\n */\n interface IClaimManagement {\n    enum ClaimState { Filed, ForceFiled, Validated, Invalidated, Accepted, Denied }\n    struct Claim {\n        ClaimState state; // Current state of claim\n        address filedBy; // Address of user who filed claim\n        uint16 payoutNumerator; // Numerator of percent to payout\n        uint16 payoutDenominator; // Denominator of percent to payout\n        uint48 filedTimestamp; // Timestamp of submitted claim\n        uint48 incidentTimestamp; // Timestamp of the incident the claim is filed for\n        uint48 decidedTimestamp; // Timestamp when claim outcome is decided\n        uint256 feePaid; // Fee paid to file the claim\n    }\n\n    function protocolClaims(address _protocol, uint256 _nonce, uint256 _index) external view returns (        \n        ClaimState state,\n        address filedBy,\n        uint16 payoutNumerator,\n        uint16 payoutDenominator,\n        uint48 filedTimestamp,\n        uint48 incidentTimestamp,\n        uint48 decidedTimestamp,\n        uint256 feePaid\n    );\n    \n    function fileClaim(address _protocol, bytes32 _protocolName, uint48 _incidentTimestamp) external;\n    function forceFileClaim(address _protocol, bytes32 _protocolName, uint48 _incidentTimestamp) external;\n    \n    // @dev Only callable by owner when auditor is voting\n    function validateClaim(address _protocol, uint256 _nonce, uint256 _index, bool _claimIsValid) external;\n\n    // @dev Only callable by approved decider, governance or auditor (isAuditorVoting == true)\n    function decideClaim(address _protocol, uint256 _nonce, uint256 _index, bool _claimIsAccepted, uint16 _payoutNumerator, uint16 _payoutDenominator) external;\n\n    function getAllClaimsByState(address _protocol, uint256 _nonce, ClaimState _state) external view returns (Claim[] memory);\n    function getAllClaimsByNonce(address _protocol, uint256 _nonce) external view returns (Claim[] memory);\n    function getAddressFromFactory(bytes32 _protocolName) external view returns (address);\n    function getProtocolNonce(address _protocol) external view returns (uint256);\n    \n    event ClaimFiled(\n        bool indexed isForced,\n        address indexed filedBy, \n        address indexed protocol, \n        uint48 incidentTimestamp,\n        uint256 nonce, \n        uint256 index, \n        uint256 feePaid\n    );\n    event ClaimValidated(\n        bool indexed claimIsValid,\n        address indexed protocol, \n        uint256 nonce, \n        uint256 index\n    );\n    event ClaimDecided(\n        bool indexed claimIsAccepted,\n        address indexed protocol, \n        uint256 nonce, \n        uint256 index, \n        uint16 payoutNumerator, \n        uint16 payoutDenominator\n    );\n }"
    },
    "contracts/utils/SafeERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\nimport \"../interfaces/IERC20.sol\";\nimport \"./SafeMath.sol\";\nimport \"./Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using SafeMath for uint256;\n    using Address for address;\n\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20 token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        // solhint-disable-next-line max-line-length\n        require((value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).add(value);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) { // Return data is optional\n            // solhint-disable-next-line max-line-length\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}"
    },
    "contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n        // for accounts without code, i.e. `keccak256('')`\n        bytes32 codehash;\n        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { codehash := extcodehash(account) }\n        return (codehash != accountHash && codehash != 0x0);\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n        (bool success, ) = recipient.call{ value: amount }(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain`call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n      return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        return _functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        return _functionCallWithValue(target, data, value, errorMessage);\n    }\n\n    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}"
    },
    "contracts/Protocol.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./proxy/InitializableAdminUpgradeabilityProxy.sol\";\nimport \"./utils/Create2.sol\";\nimport \"./utils/Initializable.sol\";\nimport \"./utils/Ownable.sol\";\nimport \"./utils/SafeMath.sol\";\nimport \"./utils/SafeERC20.sol\";\nimport \"./utils/ReentrancyGuard.sol\";\nimport \"./interfaces/ICover.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IOwnable.sol\";\nimport \"./interfaces/IProtocol.sol\";\nimport \"./interfaces/IProtocolFactory.sol\";\n\n/**\n * @title Protocol contract\n * @author crypto-pumpkin@github\n */\ncontract Protocol is IProtocol, Initializable, ReentrancyGuard, Ownable {\n  using SafeMath for uint256;\n  using SafeERC20 for IERC20;\n\n  struct ClaimDetails {\n    uint16 payoutNumerator; // 0 to 65,535\n    uint16 payoutDenominator; // 0 to 65,535\n    uint48 incidentTimestamp;\n    uint48 claimEnactedTimestamp;\n  }\n\n  struct ExpirationTimestampInfo {\n    bytes32 name;\n    uint8 status; // 0 never set; 1 active, 2 inactive\n  }\n\n  bytes4 private constant COVER_INIT_SIGNITURE = bytes4(keccak256(\"initialize(string,uint48,address,uint256)\"));\n\n  /// @notice only active (true) protocol allows adding more covers\n  bool public override active;\n\n  bytes32 public override name;\n\n  // nonce of for the protocol's claim status, it also indicates count of accepted claim in the past\n  uint256 public override claimNonce;\n\n  // delay # of seconds for redeem with accepted claim, redeemCollateral is not affected\n  uint256 public override claimRedeemDelay;\n  // delay # of seconds for redeem without accepted claim, redeemCollateral is not affected\n  uint256 public override noclaimRedeemDelay;\n\n  // only active covers, once there is an accepted claim (enactClaim called successfully), this sets to [].\n  address[] public override activeCovers;\n  address[] private allCovers;\n\n  /// @notice list of every supported expirationTimestamp, all may not be active.\n  uint48[] public override expirationTimestamps;\n\n  /// @notice list of every supported collateral, all may not be active.\n  address[] public override collaterals;\n\n  // [claimNonce] => accepted ClaimDetails\n  ClaimDetails[] public override claimDetails;\n\n  // @notice collateral => status. 0 never set; 1 active, 2 inactive\n  mapping(address => uint8) public override collateralStatusMap;\n\n  mapping(uint48 => ExpirationTimestampInfo) public override expirationTimestampMap;\n\n  // collateral => timestamp => coverAddress, most recent cover created for the collateral and timestamp combination\n  mapping(address => mapping(uint48 => address)) public override coverMap;\n\n  modifier onlyActive() {\n    require(active, \"COVER: protocol not active\");\n    _;\n  }\n\n  modifier onlyDev() {\n    require(msg.sender == _dev(), \"COVER: caller not dev\");\n    _;\n  }\n\n  modifier onlyGovernance() {\n    require(msg.sender == IProtocolFactory(owner()).governance(), \"COVER: caller not governance\");\n    _;\n  }\n\n  /// @dev Initialize, called once\n  function initialize (\n    bytes32 _protocolName,\n    bool _active,\n    address _collateral,\n    uint48[] calldata _expirationTimestamps,\n    bytes32[] calldata _expirationTimestampNames\n  )\n    external initializer\n  {\n    name = _protocolName;\n    collaterals.push(_collateral);\n    active = _active;\n    expirationTimestamps = _expirationTimestamps;\n\n    collateralStatusMap[_collateral] = 1;\n\n    for (uint i = 0; i < _expirationTimestamps.length; i++) {\n      if (block.timestamp < _expirationTimestamps[i]) {\n        expirationTimestampMap[_expirationTimestamps[i]] = ExpirationTimestampInfo(\n          _expirationTimestampNames[i],\n          1\n        );\n      }\n    }\n\n    // set default delay for redeem\n    claimRedeemDelay = 2 days;\n    noclaimRedeemDelay = 10 days;\n\n    initializeOwner();\n  }\n\n  function getProtocolDetails()\n    external view override returns (\n      bytes32 _name,\n      bool _active,\n      uint256 _claimNonce,\n      uint256 _claimRedeemDelay,\n      uint256 _noclaimRedeemDelay,\n      address[] memory _collaterals,\n      uint48[] memory _expirationTimestamps,\n      address[] memory _allCovers,\n      address[] memory _allActiveCovers\n    )\n  {\n    return (\n      name,\n      active,\n      claimNonce,\n      claimRedeemDelay,\n      noclaimRedeemDelay,\n      getCollaterals(),\n      getExpirationTimestamps(),\n      getAllCovers(),\n      getAllActiveCovers()\n    );\n  }\n\n  function collateralsLength() external view override returns (uint256) {\n    return collaterals.length;\n  }\n\n  function expirationTimestampsLength() external view override returns (uint256) {\n    return expirationTimestamps.length;\n  }\n\n  function activeCoversLength() external view override returns (uint256) {\n    return activeCovers.length;\n  }\n\n  function claimsLength() external view override returns (uint256) {\n    return claimDetails.length;\n  }\n\n  /**\n   * @notice add cover for sender\n   *  - transfer collateral from sender to cover contract\n   *  - mint the same amount CLAIM covToken to sender\n   *  - mint the same amount NOCLAIM covToken to sender\n   */\n  function addCover(address _collateral, uint48 _timestamp, uint256 _amount)\n    external override onlyActive nonReentrant returns (bool)\n  {\n    require(_amount > 0, \"COVER: amount <= 0\");\n    require(collateralStatusMap[_collateral] == 1, \"COVER: invalid collateral\");\n    require(block.timestamp < _timestamp && expirationTimestampMap[_timestamp].status == 1, \"COVER: invalid expiration date\");\n\n    // Validate sender collateral balance is > amount\n    IERC20 collateral = IERC20(_collateral);\n    require(collateral.balanceOf(msg.sender) >= _amount, \"COVER: amount > collateral balance\");\n\n    address addr = coverMap[_collateral][_timestamp];\n\n    // Deploy new cover contract if not exist or if claim accepted\n    if (addr == address(0) || ICover(addr).claimNonce() != claimNonce) {\n      string memory coverName = _generateCoverName(_timestamp, collateral.symbol());\n\n      bytes memory bytecode = type(InitializableAdminUpgradeabilityProxy).creationCode;\n      bytes32 salt = keccak256(abi.encodePacked(name, _timestamp, _collateral, claimNonce));\n      addr = Create2.deploy(0, salt, bytecode);\n\n      bytes memory initData = abi.encodeWithSelector(COVER_INIT_SIGNITURE, coverName, _timestamp, _collateral, claimNonce);\n      address coverImplementation = IProtocolFactory(owner()).coverImplementation();\n      InitializableAdminUpgradeabilityProxy(payable(addr)).initialize(\n        coverImplementation,\n        IOwnable(owner()).owner(),\n        initData\n      );\n\n      activeCovers.push(addr);\n      allCovers.push(addr);\n      coverMap[_collateral][_timestamp] = addr;\n    }\n\n    // move collateral to the cover contract and mint CovTokens to sender\n    uint256 coverBalanceBefore = collateral.balanceOf(addr);\n    collateral.safeTransferFrom(msg.sender, addr, _amount);\n    uint256 coverBalanceAfter = collateral.balanceOf(addr);\n    require(coverBalanceAfter > coverBalanceBefore, \"COVER: collateral transfer failed\");\n    ICover(addr).mint(coverBalanceAfter.sub(coverBalanceBefore), msg.sender);\n    return true;\n  }\n\n  /// @notice update status or add new expiration timestamp\n  function updateExpirationTimestamp(uint48 _expirationTimestamp, bytes32 _expirationTimestampName, uint8 _status) external override onlyDev returns (bool) {\n    require(block.timestamp < _expirationTimestamp, \"COVER: invalid expiration date\");\n    require(_status > 0 && _status < 3, \"COVER: status not in (0, 2]\");\n\n    if (expirationTimestampMap[_expirationTimestamp].status == 0) {\n      expirationTimestamps.push(_expirationTimestamp);\n    }\n    expirationTimestampMap[_expirationTimestamp] = ExpirationTimestampInfo(\n      _expirationTimestampName,\n      _status\n    );\n    return true;\n  }\n\n  /// @notice update status or add new collateral\n  function updateCollateral(address _collateral, uint8 _status) external override onlyDev returns (bool) {\n    require(_collateral != address(0), \"COVER: address cannot be 0\");\n    require(_status > 0 && _status < 3, \"COVER: status not in (0, 2]\");\n\n    if (collateralStatusMap[_collateral] == 0) {\n      collaterals.push(_collateral);\n    }\n    collateralStatusMap[_collateral] = _status;\n    return true;\n  }\n\n  /**\n   * @dev enact accepted claim, all covers are to be paid out\n   *  - increment claimNonce\n   *  - delete activeCovers list\n   *  - only COVER claim manager can call this function\n   *\n   * Emit ClaimAccepted\n   */\n  function enactClaim(\n    uint16 _payoutNumerator,\n    uint16 _payoutDenominator,\n    uint48 _incidentTimestamp,\n    uint256 _protocolNonce\n  )\n   external override returns (bool)\n  {\n    require(_protocolNonce == claimNonce, \"COVER: nonces do not match\");\n    require(_payoutNumerator <= _payoutDenominator && _payoutNumerator > 0, \"COVER: payout % is not in (0%, 100%]\");\n    require(msg.sender == IProtocolFactory(owner()).claimManager(), \"COVER: caller not claimManager\");\n\n    claimNonce = claimNonce.add(1);\n    delete activeCovers;\n    claimDetails.push(ClaimDetails(\n      _payoutNumerator,\n      _payoutDenominator,\n      _incidentTimestamp,\n      uint48(block.timestamp)\n    ));\n    emit ClaimAccepted(_protocolNonce);\n    return true;\n  }\n\n  // update status of protocol, if false, will pause new cover creation\n  function setActive(bool _active) external override onlyDev returns (bool) {\n    active = _active;\n    return true;\n  }\n\n  function updateClaimRedeemDelay(uint256 _claimRedeemDelay)\n   external override onlyGovernance returns (bool)\n  {\n    claimRedeemDelay = _claimRedeemDelay;\n    return true;\n  }\n\n  function updateNoclaimRedeemDelay(uint256 _noclaimRedeemDelay)\n   external override onlyGovernance returns (bool)\n  {\n    noclaimRedeemDelay = _noclaimRedeemDelay;\n    return true;\n  }\n\n  function getAllCovers() private view returns (address[] memory) {\n    return allCovers;\n  }\n\n  function getAllActiveCovers() private view returns (address[] memory) {\n    return activeCovers;\n  }\n\n  function getCollaterals() private view returns (address[] memory) {\n    return collaterals;\n  }\n\n  function getExpirationTimestamps() private view returns (uint48[] memory) {\n    return expirationTimestamps;\n  }\n\n  /// @dev the owner of this contract is ProtocolFactory contract. The owner of ProtocolFactory is dev\n  function _dev() private view returns (address) {\n    return IOwnable(owner()).owner();\n  }\n\n  /// @dev generate the cover name. Example: COVER_CURVE_2020_12_31_DAI_0\n  function _generateCoverName(uint48 _expirationTimestamp, string memory _collateralSymbol)\n   internal view returns (string memory) \n  {\n    return string(abi.encodePacked(\n      \"COVER\",\n      \"_\",\n      bytes32ToString(name),\n      \"_\",\n      bytes32ToString(expirationTimestampMap[_expirationTimestamp].name),\n      \"_\",\n      _collateralSymbol,\n      \"_\",\n      uintToString(claimNonce)\n    ));\n  }\n\n  // string helper\n  function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {\n    uint8 i = 0;\n    while(i < 32 && _bytes32[i] != 0) {\n        i++;\n    }\n    bytes memory bytesArray = new bytes(i);\n    for (i = 0; i < 32 && _bytes32[i] != 0; i++) {\n        bytesArray[i] = _bytes32[i];\n    }\n    return string(bytesArray);\n  }\n\n  // string helper\n  function uintToString(uint256 _i) internal pure returns (string memory _uintAsString) {\n    if (_i == 0) {\n      return \"0\";\n    }\n    uint256 j = _i;\n    uint256 len;\n    while (j != 0) {\n      len++;\n      j /= 10;\n    }\n    bytes memory bstr = new bytes(len);\n    uint256 k = len - 1;\n    while (_i != 0) {\n      bstr[k--] = byte(uint8(48 + _i % 10));\n      _i /= 10;\n    }\n    return string(bstr);\n  }\n}\n"
    },
    "contracts/proxy/InitializableAdminUpgradeabilityProxy.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport './BaseAdminUpgradeabilityProxy.sol';\n\n/**\n * @title InitializableAdminUpgradeabilityProxy\n * @dev Extends from BaseAdminUpgradeabilityProxy with an initializer for \n * initializing the implementation, admin, and init data.\n */\ncontract InitializableAdminUpgradeabilityProxy is BaseAdminUpgradeabilityProxy {\n  /**\n   * Contract initializer.\n   * @param _logic address of the initial implementation.\n   * @param _admin Address of the proxy administrator.\n   * @param _data Data to send as msg.data to the implementation to initialize the proxied contract.\n   * It should include the signature and the parameters of the function to be called, as described in\n   * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.\n   * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped.\n   */\n  function initialize(address _logic, address _admin, bytes memory _data) public payable {\n    require(_implementation() == address(0));\n\n    assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1));\n    _setImplementation(_logic);\n    if(_data.length > 0) {\n      (bool success,) = _logic.delegatecall(_data);\n      require(success);\n    }\n\n    assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1));\n    _setAdmin(_admin);\n  }\n}"
    },
    "contracts/utils/Create2.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\n/**\n * @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.\n * `CREATE2` can be used to compute in advance the address where a smart\n * contract will be deployed, which allows for interesting new mechanisms known\n * as 'counterfactual interactions'.\n *\n * See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more\n * information.\n */\nlibrary Create2 {\n    /**\n     * @dev Deploys a contract using `CREATE2`. The address where the contract\n     * will be deployed can be known in advance via {computeAddress}.\n     *\n     * The bytecode for a contract can be obtained from Solidity with\n     * `type(contractName).creationCode`.\n     *\n     * Requirements:\n     *\n     * - `bytecode` must not be empty.\n     * - `salt` must have not been used for `bytecode` already.\n     * - the factory must have a balance of at least `amount`.\n     * - if `amount` is non-zero, `bytecode` must have a `payable` constructor.\n     */\n    function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address payable) {\n        address payable addr;\n        require(address(this).balance >= amount, \"Create2: insufficient balance\");\n        require(bytecode.length != 0, \"Create2: bytecode length is zero\");\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)\n        }\n        require(addr != address(0), \"Create2: Failed on deploy\");\n        return addr;\n    }\n\n    /**\n     * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the\n     * `bytecodeHash` or `salt` will result in a new destination address.\n     */\n    function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {\n        return computeAddress(salt, bytecodeHash, address(this));\n    }\n\n    /**\n     * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at\n     * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.\n     */\n    function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address) {\n        bytes32 _data = keccak256(\n            abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)\n        );\n        return address(uint256(_data));\n    }\n}"
    },
    "contracts/utils/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor () {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and make it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}\n"
    },
    "contracts/interfaces/ICover.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./ICoverERC20.sol\";\n\n/**\n * @title Cover contract interface. See {Cover}.\n * @author crypto-pumpkin@github\n */\ninterface ICover {\n  event NewCoverERC20(address);\n\n  function getCoverDetails()\n    external view returns (string memory _name, uint48 _expirationTimestamp, address _collateral, uint256 _claimNonce, ICoverERC20 _claimCovToken, ICoverERC20 _noclaimCovToken);\n  function expirationTimestamp() external view returns (uint48);\n  function collateral() external view returns (address);\n  function claimCovToken() external view returns (ICoverERC20);\n  function noclaimCovToken() external view returns (ICoverERC20);\n  function name() external view returns (string memory);\n  function claimNonce() external view returns (uint256);\n\n  function redeemClaim() external;\n  function redeemNoclaim() external;\n  function redeemCollateral(uint256 _amount) external;\n\n  /// @notice access restriction - owner (Protocol)\n  function mint(uint256 _amount, address _receiver) external;\n\n  /// @notice access restriction - dev\n  function setCovTokenSymbol(string calldata _name) external;\n}"
    },
    "contracts/proxy/BaseAdminUpgradeabilityProxy.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\nimport './BaseUpgradeabilityProxy.sol';\n\n/**\n * @title BaseAdminUpgradeabilityProxy\n * @dev This contract combines an upgradeability proxy with an authorization\n * mechanism for administrative tasks.\n * All external functions in this contract must be guarded by the\n * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity\n * feature proposal that would enable this to be done automatically.\n */\ncontract BaseAdminUpgradeabilityProxy is BaseUpgradeabilityProxy {\n  /**\n   * @dev Emitted when the administration has been transferred.\n   * @param previousAdmin Address of the previous admin.\n   * @param newAdmin Address of the new admin.\n   */\n  event AdminChanged(address previousAdmin, address newAdmin);\n\n  /**\n   * @dev Storage slot with the admin of the contract.\n   * This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n   * validated in the constructor.\n   */\n\n  bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n  /**\n   * @dev Modifier to check whether the `msg.sender` is the admin.\n   * If it is, it will run the function. Otherwise, it will delegate the call\n   * to the implementation.\n   */\n  modifier ifAdmin() {\n    if (msg.sender == _admin()) {\n      _;\n    } else {\n      _fallback();\n    }\n  }\n\n  /**\n   * @return The address of the proxy admin.\n   */\n  function admin() external ifAdmin returns (address) {\n    return _admin();\n  }\n\n  /**\n   * @return The address of the implementation.\n   */\n  function implementation() external ifAdmin returns (address) {\n    return _implementation();\n  }\n\n  /**\n   * @dev Changes the admin of the proxy.\n   * Only the current admin can call this function.\n   * @param newAdmin Address to transfer proxy administration to.\n   */\n  function changeAdmin(address newAdmin) external ifAdmin {\n    require(newAdmin != address(0), \"Cannot change the admin of a proxy to the zero address\");\n    emit AdminChanged(_admin(), newAdmin);\n    _setAdmin(newAdmin);\n  }\n\n  /**\n   * @dev Upgrade the backing implementation of the proxy.\n   * Only the admin can call this function.\n   * @param newImplementation Address of the new implementation.\n   */\n  function upgradeTo(address newImplementation) external ifAdmin {\n    _upgradeTo(newImplementation);\n  }\n\n  /**\n   * @dev Upgrade the backing implementation of the proxy and call a function\n   * on the new implementation.\n   * This is useful to initialize the proxied contract.\n   * @param newImplementation Address of the new implementation.\n   * @param data Data to send as msg.data in the low level call.\n   * It should include the signature and the parameters of the function to be called, as described in\n   * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.\n   */\n  function upgradeToAndCall(address newImplementation, bytes calldata data) payable external ifAdmin {\n    _upgradeTo(newImplementation);\n    (bool success,) = newImplementation.delegatecall(data);\n    require(success);\n  }\n\n  /**\n   * @return adm The admin slot.\n   */\n  function _admin() internal view returns (address adm) {\n    bytes32 slot = ADMIN_SLOT;\n    assembly {\n      adm := sload(slot)\n    }\n  }\n\n  /**\n   * @dev Sets the address of the proxy admin.\n   * @param newAdmin Address of the new proxy admin.\n   */\n  function _setAdmin(address newAdmin) internal {\n    bytes32 slot = ADMIN_SLOT;\n\n    assembly {\n      sstore(slot, newAdmin)\n    }\n  }\n} "
    },
    "contracts/proxy/BaseUpgradeabilityProxy.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\nimport \"../utils/Address.sol\";\nimport \"./Proxy.sol\";\n\n/**\n * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an\n * implementation address that can be changed. This address is stored in storage in the location specified by\n * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the\n * implementation behind the proxy.\n * \n * Upgradeability is only provided internally through {_upgradeTo}. For an externally upgradeable proxy see\n * {TransparentUpgradeableProxy}.\n */\ncontract BaseUpgradeabilityProxy is Proxy {\n\n    /**\n     * @dev Storage slot with the address of the current implementation.\n     * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n     * validated in the constructor.\n     */\n    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n    event Upgraded(address indexed implementation);\n\n    /**\n     * @dev Returns the current implementation address.\n     */\n    function _implementation() internal override view returns (address impl) {\n        bytes32 slot = IMPLEMENTATION_SLOT;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            impl := sload(slot)\n        }\n    }\n\n    /**\n     * @dev Upgrades the proxy to a new implementation.\n     * \n     * Emits an {Upgraded} event.\n     */\n    function _upgradeTo(address newImplementation) internal {\n        _setImplementation(newImplementation);\n        emit Upgraded(newImplementation);\n    }\n\n    /**\n     * @dev Stores a new address in the EIP1967 implementation slot.\n     */\n    function _setImplementation(address newImplementation) internal {\n        require(Address.isContract(newImplementation), \"UpgradeableProxy: new implementation is not a contract\");\n\n        bytes32 slot = IMPLEMENTATION_SLOT;\n\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            sstore(slot, newImplementation)\n        }\n    }\n}"
    },
    "contracts/proxy/Proxy.sol": {
      "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.3;\n\n/**\n * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM\n * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to\n * be specified by overriding the virtual {_implementation} function.\n * \n * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a\n * different contract through the {_delegate} function.\n * \n * The success and return data of the delegated call will be returned back to the caller of the proxy.\n */\nabstract contract Proxy {\n    /**\n     * @dev Delegates the current call to `implementation`.\n     * \n     * This function does not return to its internall call site, it will return directly to the external caller.\n     */\n    function _delegate(address implementation) internal {\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Copy msg.data. We take full control of memory in this inline assembly\n            // block because it will not return to Solidity code. We overwrite the\n            // Solidity scratch pad at memory position 0.\n            calldatacopy(0, 0, calldatasize())\n\n            // Call the implementation.\n            // out and outsize are 0 because we don't know the size yet.\n            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n\n            // Copy the returned data.\n            returndatacopy(0, 0, returndatasize())\n\n            switch result\n            // delegatecall returns 0 on error.\n            case 0 { revert(0, returndatasize()) }\n            default { return(0, returndatasize()) }\n        }\n    }\n\n    /**\n     * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function\n     * and {_fallback} should delegate.\n     */\n    function _implementation() internal virtual view returns (address);\n\n    /**\n     * @dev Delegates the current call to the address returned by `_implementation()`.\n     * \n     * This function does not return to its internall call site, it will return directly to the external caller.\n     */\n    function _fallback() internal {\n        _beforeFallback();\n        _delegate(_implementation());\n    }\n\n    /**\n     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other\n     * function in the contract matches the call data.\n     */\n    fallback () payable external {\n        _fallback();\n    }\n\n    /**\n     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data\n     * is empty.\n     */\n    receive () payable external {\n        _fallback();\n    }\n\n    /**\n     * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`\n     * call, or as part of the Solidity `fallback` or `receive` functions.\n     * \n     * If overriden should call `super._beforeFallback()`.\n     */\n    function _beforeFallback() internal virtual {\n    }\n}"
    },
    "contracts/interfaces/ICoverERC20.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./IERC20.sol\";\n\n/**\n * @title CoverERC20 contract interface, implements {IERC20}. See {CoverERC20}.\n * @author crypto-pumpkin@github\n */\ninterface ICoverERC20 is IERC20 {\n    function burn(uint256 _amount) external returns (bool);\n\n    /// @notice access restriction - owner (Cover)\n    function mint(address _account, uint256 _amount) external returns (bool);\n    function setSymbol(string calldata _symbol) external returns (bool);\n    function burnByCover(address _account, uint256 _amount) external returns (bool);\n}"
    },
    "contracts/ProtocolFactory.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./proxy/InitializableAdminUpgradeabilityProxy.sol\";\nimport \"./utils/Address.sol\";\nimport \"./utils/Create2.sol\";\nimport \"./utils/Ownable.sol\";\nimport \"./interfaces/IProtocolFactory.sol\";\n\n/**\n * @title ProtocolFactory contract\n * @author crypto-pumpkin@github\n */\ncontract ProtocolFactory is IProtocolFactory, Ownable {\n\n  bytes4 private constant PROTOCOL_INIT_SIGNITURE = bytes4(keccak256(\"initialize(bytes32,bool,address,uint48[],bytes32[])\"));\n\n  uint16 public override redeemFeeNumerator = 10; // 0 to 65,535\n  uint16 public override redeemFeeDenominator = 10000; // 0 to 65,535\n\n  address public override protocolImplementation;\n  address public override coverImplementation;\n  address public override coverERC20Implementation;\n\n  address public override treasury;\n  address public override governance;\n  address public override claimManager;\n\n  // not all protocols are active\n  bytes32[] private protocolNames;\n\n  mapping(bytes32 => address) public override protocols;\n\n  modifier onlyGovernance() {\n    require(msg.sender == governance, \"COVER: caller not governance\");\n    _;\n  }\n\n  constructor (\n    address _protocolImplementation,\n    address _coverImplementation,\n    address _coverERC20Implementation,\n    address _governance,\n    address _treasury\n  ) {\n    protocolImplementation = _protocolImplementation;\n    coverImplementation = _coverImplementation;\n    coverERC20Implementation = _coverERC20Implementation;\n    governance = _governance;\n    treasury = _treasury;\n\n    initializeOwner();\n  }\n\n  function getAllProtocolAddresses() external view override returns (address[] memory) {\n    bytes32[] memory protocolNamesCopy = protocolNames;\n    address[] memory protocolAddresses = new address[](protocolNamesCopy.length);\n    for (uint i = 0; i < protocolNamesCopy.length; i++) {\n      protocolAddresses[i] = protocols[protocolNamesCopy[i]];\n    }\n    return protocolAddresses;\n  }\n\n  function getRedeemFees() external view override returns (uint16 _numerator, uint16 _denominator) {\n    return (redeemFeeNumerator, redeemFeeDenominator);\n  }\n\n  function getProtocolsLength() external view override returns (uint256) {\n    return protocolNames.length;\n  }\n\n  function getProtocolNameAndAddress(uint256 _index)\n   external view override returns (bytes32, address)\n  {\n    bytes32 name = protocolNames[_index];\n    return (name, protocols[name]);\n  }\n\n  /// @notice return protocol contract address, the contract may not be deployed yet\n  function getProtocolAddress(bytes32 _name) public view override returns (address) {\n    return _computeAddress(keccak256(abi.encodePacked(_name)), address(this));\n  }\n\n  /// @notice return cover contract address, the contract may not be deployed yet\n  function getCoverAddress(\n    bytes32 _protocolName,\n    uint48 _timestamp,\n    address _collateral,\n    uint256 _claimNonce\n  )\n   public view override returns (address)\n  {\n    return _computeAddress(\n      keccak256(abi.encodePacked(_protocolName, _timestamp, _collateral, _claimNonce)),\n      getProtocolAddress(_protocolName)\n    );\n  }\n\n  /// @notice return covToken contract address, the contract may not be deployed yet\n  function getCovTokenAddress(\n    bytes32 _protocolName,\n    uint48 _timestamp,\n    address _collateral,\n    uint256 _claimNonce,\n    bool _isClaimCovToken\n  )\n   external view override returns (address) \n  {\n    return _computeAddress(\n      keccak256(abi.encodePacked(\n        _protocolName,\n        _timestamp,\n        _collateral,\n        _claimNonce,\n        _isClaimCovToken ? \"CLAIM\" : \"NOCLAIM\")\n      ),\n      getCoverAddress(_protocolName, _timestamp, _collateral, _claimNonce)\n    );\n  }\n\n  /// @dev Emits ProtocolInitiation, add a supported protocol in COVER\n  function addProtocol(\n    bytes32 _name,\n    bool _active,\n    address _collateral,\n    uint48[] calldata _timestamps,\n    bytes32[] calldata _timestampNames\n  )\n    external override onlyOwner returns (address)\n  {\n    require(protocols[_name] == address(0), \"COVER: protocol exists\");\n    require(_timestamps.length == _timestampNames.length, \"COVER: timestamp lengths don't match\");\n    protocolNames.push(_name);\n\n    bytes memory bytecode = type(InitializableAdminUpgradeabilityProxy).creationCode;\n    // unique salt required for each protocol, salt + deployer decides contract address\n    bytes32 salt = keccak256(abi.encodePacked(_name));\n    address payable proxyAddr = Create2.deploy(0, salt, bytecode);\n    emit ProtocolInitiation(proxyAddr);\n\n    bytes memory initData = abi.encodeWithSelector(PROTOCOL_INIT_SIGNITURE, _name, _active, _collateral, _timestamps, _timestampNames);\n    InitializableAdminUpgradeabilityProxy(proxyAddr).initialize(protocolImplementation, owner(), initData);\n\n    protocols[_name] = proxyAddr;\n\n    return proxyAddr;\n  }\n\n  /// @dev update this will only affect protocols deployed after\n  function updateProtocolImplementation(address _newImplementation)\n   external override onlyOwner returns (bool)\n  {\n    require(Address.isContract(_newImplementation), \"COVER: new implementation is not a contract\");\n    protocolImplementation = _newImplementation;\n    return true;\n  }\n\n  /// @dev update this will only affect covers of protocols deployed after\n  function updateCoverImplementation(address _newImplementation)\n   external override onlyOwner returns (bool)\n  {\n    require(Address.isContract(_newImplementation), \"COVER: new implementation is not a contract\");\n    coverImplementation = _newImplementation;\n    return true;\n  }\n\n  /// @dev update this will only affect covTokens of covers of protocols deployed after\n  function updateCoverERC20Implementation(address _newImplementation)\n   external override onlyOwner returns (bool)\n  {\n    require(Address.isContract(_newImplementation), \"COVER: new implementation is not a contract\");\n    coverERC20Implementation = _newImplementation;\n    return true;\n  }\n\n  function updateFees(\n    uint16 _redeemFeeNumerator,\n    uint16 _redeemFeeDenominator\n  )\n    external override onlyGovernance returns (bool)\n  {\n    require(_redeemFeeDenominator > 0, \"COVER: denominator cannot be 0\");\n    redeemFeeNumerator = _redeemFeeNumerator;\n    redeemFeeDenominator = _redeemFeeDenominator;\n    return true;\n  }\n\n  function updateClaimManager(address _address)\n   external override onlyOwner returns (bool)\n  {\n    require(_address != address(0), \"COVER: address cannot be 0\");\n    claimManager = _address;\n    return true;\n  }\n\n  function updateGovernance(address _address)\n   external override onlyGovernance returns (bool)\n  {\n    require(_address != address(0), \"COVER: address cannot be 0\");\n    require(_address != owner(), \"COVER: governance cannot be owner\");\n    governance = _address;\n    return true;\n  }\n\n  function updateTreasury(address _address)\n   external override onlyOwner returns (bool)\n  {\n    require(_address != address(0), \"COVER: address cannot be 0\");\n    treasury = _address;\n    return true;\n  }\n\n  function _computeAddress(bytes32 salt, address deployer) private pure returns (address) {\n    bytes memory bytecode = type(InitializableAdminUpgradeabilityProxy).creationCode;\n    return Create2.computeAddress(salt, keccak256(bytecode), deployer);\n  }\n}"
    },
    "contracts/CoverERC20.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./utils/Initializable.sol\";\nimport \"./utils/Ownable.sol\";\nimport \"./utils/SafeMath.sol\";\nimport \"./interfaces/ICoverERC20.sol\";\n\n/**\n * @title CoverERC20 implements {ERC20} standards with expended features for COVER\n * @author crypto-pumpkin@github\n *\n * COVER's covToken Features:\n *  - Has mint and burn by owner (Cover contract) only feature.\n *  - No limit on the totalSupply.\n *  - Should only be created from Cover contract. See {Cover}\n */\ncontract CoverERC20 is ICoverERC20, Initializable, Ownable {\n  using SafeMath for uint256;\n\n  uint8 public constant decimals = 18;\n  string public constant name = \"covToken\";\n\n  // The symbol of  the contract\n  string public override symbol;\n  uint256 private _totalSupply;\n\n  mapping(address => uint256) private balances;\n  mapping(address => mapping (address => uint256)) private allowances;\n\n  /// @notice Initialize, called once\n  function initialize (string calldata _symbol) external initializer {\n    symbol = _symbol;\n    initializeOwner();\n  }\n\n  /// @notice Standard ERC20 function\n  function balanceOf(address account) external view override returns (uint256) {\n    return balances[account];\n  }\n\n  /// @notice Standard ERC20 function\n  function totalSupply() external view override returns (uint256) {\n    return _totalSupply;\n  }\n\n  /// @notice Standard ERC20 function\n  function transfer(address recipient, uint256 amount) external virtual override returns (bool) {\n    _transfer(msg.sender, recipient, amount);\n    return true;\n  }\n\n  /// @notice Standard ERC20 function\n  function allowance(address owner, address spender) external view virtual override returns (uint256) {\n    return allowances[owner][spender];\n  }\n\n  /// @notice Standard ERC20 function\n  function approve(address spender, uint256 amount) external virtual override returns (bool) {\n    _approve(msg.sender, spender, amount);\n    return true;\n  }\n\n  /// @notice Standard ERC20 function\n  function transferFrom(address sender, address recipient, uint256 amount)\n    external virtual override returns (bool)\n  {\n    _transfer(sender, recipient, amount);\n    _approve(sender, msg.sender, allowances[sender][msg.sender].sub(amount, \"CoverERC20: transfer amount exceeds allowance\"));\n    return true;\n  }\n\n  /// @notice New ERC20 function\n  function increaseAllowance(address spender, uint256 addedValue) public virtual override returns (bool) {\n    _approve(msg.sender, spender, allowances[msg.sender][spender].add(addedValue));\n    return true;\n  }\n\n  /// @notice New ERC20 function\n  function decreaseAllowance(address spender, uint256 subtractedValue) public virtual override returns (bool) {\n    _approve(msg.sender, spender, allowances[msg.sender][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n    return true;\n  }\n\n  /// @notice COVER specific function\n  function mint(address _account, uint256 _amount)\n    external override onlyOwner returns (bool)\n  {\n    require(_account != address(0), \"CoverERC20: mint to the zero address\");\n\n    _totalSupply = _totalSupply.add(_amount);\n    balances[_account] = balances[_account].add(_amount);\n    emit Transfer(address(0), _account, _amount);\n    return true;\n  }\n\n  /// @notice COVER specific function\n  function setSymbol(string calldata _symbol)\n    external override onlyOwner returns (bool)\n  {\n    symbol = _symbol;\n    return true;\n  }\n\n  /// @notice COVER specific function\n  function burnByCover(address _account, uint256 _amount) external override onlyOwner returns (bool) {\n    _burn(_account, _amount);\n    return true;\n  }\n\n  /// @notice COVER specific function\n  function burn(uint256 _amount) external override returns (bool) {\n    _burn(msg.sender, _amount);\n    return true;\n  }\n\n  function _transfer(address sender, address recipient, uint256 amount) internal {\n    require(sender != address(0), \"CoverERC20: transfer from the zero address\");\n    require(recipient != address(0), \"CoverERC20: transfer to the zero address\");\n\n    balances[sender] = balances[sender].sub(amount, \"CoverERC20: transfer amount exceeds balance\");\n    balances[recipient] = balances[recipient].add(amount);\n    emit Transfer(sender, recipient, amount);\n  }\n\n  function _burn(address account, uint256 amount) internal {\n    require(account != address(0), \"CoverERC20: burn from the zero address\");\n\n    balances[account] = balances[account].sub(amount, \"CoverERC20: burn amount exceeds balance\");\n    _totalSupply = _totalSupply.sub(amount);\n    emit Transfer(account, address(0), amount);\n  }\n\n  function _approve(address owner, address spender, uint256 amount) internal {\n    require(owner != address(0), \"CoverERC20: approve from the zero address\");\n    require(spender != address(0), \"CoverERC20: approve to the zero address\");\n\n    allowances[owner][spender] = amount;\n    emit Approval(owner, spender, amount);\n  }\n}\n"
    },
    "contracts/Cover.sol": {
      "content": "// SPDX-License-Identifier: No License\n\npragma solidity ^0.7.3;\n\nimport \"./proxy/InitializableAdminUpgradeabilityProxy.sol\";\nimport \"./utils/Create2.sol\";\nimport \"./utils/Initializable.sol\";\nimport \"./utils/Ownable.sol\";\nimport \"./utils/ReentrancyGuard.sol\";\nimport \"./utils/SafeMath.sol\";\nimport \"./utils/SafeERC20.sol\";\nimport \"./interfaces/ICover.sol\";\nimport \"./interfaces/ICoverERC20.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IOwnable.sol\";\nimport \"./interfaces/IProtocol.sol\";\nimport \"./interfaces/IProtocolFactory.sol\";\n\n/**\n * @title Cover contract\n * @author crypto-pumpkin@github\n *\n * The contract\n *  - Holds collateral funds\n *  - Mints and burns CovTokens (CoverERC20)\n *  - Allows redeem from collateral pool with or without an accepted claim\n */\ncontract Cover is ICover, Initializable, Ownable, ReentrancyGuard {\n  using SafeMath for uint256;\n  using SafeERC20 for IERC20;\n\n  bytes4 private constant COVERERC20_INIT_SIGNITURE = bytes4(keccak256(\"initialize(string)\"));\n  uint48 public override expirationTimestamp;\n  address public override collateral;\n  ICoverERC20 public override claimCovToken;\n  ICoverERC20 public override noclaimCovToken;\n  string public override name;\n  uint256 public override claimNonce;\n\n  modifier onlyNotExpired() {\n    require(block.timestamp < expirationTimestamp, \"COVER: cover expired\");\n    _;\n  }\n\n  /// @dev Initialize, called once\n  function initialize (\n    string calldata _name,\n    uint48 _timestamp,\n    address _collateral,\n    uint256 _claimNonce\n  ) public initializer {\n    name = _name;\n    expirationTimestamp = _timestamp;\n    collateral = _collateral;\n    claimNonce = _claimNonce;\n\n    initializeOwner();\n\n    claimCovToken = _createCovToken(\"CLAIM\");\n    noclaimCovToken = _createCovToken(\"NOCLAIM\");\n  }\n\n  function getCoverDetails()\n    external view override returns (string memory _name, uint48 _expirationTimestamp, address _collateral, uint256 _claimNonce, ICoverERC20 _claimCovToken, ICoverERC20 _noclaimCovToken)\n  {\n    return (name, expirationTimestamp, collateral, claimNonce, claimCovToken, noclaimCovToken);\n  }\n\n  /// @notice only owner (covered protocol) can mint, collateral is transfered in Protocol\n  function mint(uint256 _amount, address _receiver) external override onlyOwner onlyNotExpired {\n    _noClaimAcceptedCheck(); // save gas than modifier\n\n    claimCovToken.mint(_receiver, _amount);\n    noclaimCovToken.mint(_receiver, _amount);\n  }\n\n  /// @notice redeem CLAIM covToken, only if there is a claim accepted and delayWithClaim period passed\n  function redeemClaim() external override {\n    IProtocol protocol = IProtocol(owner());\n    require(protocol.claimNonce() > claimNonce, \"COVER: no claim accepted\");\n\n    (uint16 _payoutNumerator, uint16 _payoutDenominator, uint48 _incidentTimestamp, uint48 _claimEnactedTimestamp) = _claimDetails();\n    require(_incidentTimestamp <= expirationTimestamp, \"COVER: cover expired before incident\");\n    require(block.timestamp >= uint256(_claimEnactedTimestamp) + protocol.claimRedeemDelay(), \"COVER: not ready\");\n\n    _paySender(\n      claimCovToken,\n      uint256(_payoutNumerator),\n      uint256(_payoutDenominator)\n    );\n  }\n\n  /**\n   * @notice redeem NOCLAIM covToken, accept\n   * - if no claim accepted, cover is expired, and delayWithoutClaim period passed\n   * - if claim accepted, but payout % < 1, and delayWithClaim period passed\n   */\n  function redeemNoclaim() external override {\n    IProtocol protocol = IProtocol(owner());\n    if (protocol.claimNonce() > claimNonce) {\n      // protocol has an accepted claim\n\n      (uint16 _payoutNumerator, uint16 _payoutDenominator, uint48 _incidentTimestamp, uint48 _claimEnactedTimestamp) = _claimDetails();\n\n      if (_incidentTimestamp > expirationTimestamp) {\n        // incident happened after expiration date, redeem back full collateral\n\n        require(block.timestamp >= uint256(expirationTimestamp) + protocol.noclaimRedeemDelay(), \"COVER: not ready\");\n        _paySender(noclaimCovToken, 1, 1);\n      } else {\n        // incident happened before expiration date, pay 1 - payout%\n\n        // If claim payout is 100%, nothing is left for NOCLAIM covToken holders\n        require(_payoutNumerator < _payoutDenominator, \"COVER: claim payout 100%\");\n\n        require(block.timestamp >= uint256(_claimEnactedTimestamp) + protocol.claimRedeemDelay(), \"COVER: not ready\");\n        _paySender(\n          noclaimCovToken,\n          uint256(_payoutDenominator).sub(uint256(_payoutNumerator)),\n          uint256(_payoutDenominator)\n        );\n      }\n    } else {\n      // protocol has no accepted claim\n\n      require(block.timestamp >= uint256(expirationTimestamp) + protocol.noclaimRedeemDelay(), \"COVER: not ready\");\n      _paySender(noclaimCovToken, 1, 1);\n    }\n  }\n\n  /// @notice redeem collateral, only when no claim accepted and not expired\n  function redeemCollateral(uint256 _amount) external override onlyNotExpired {\n    require(_amount > 0, \"COVER: amount is 0\");\n    _noClaimAcceptedCheck(); // save gas than modifier\n\n    ICoverERC20 _claimCovToken = claimCovToken; // save gas\n    ICoverERC20 _noclaimCovToken = noclaimCovToken; // save gas\n\n    require(_amount <= _claimCovToken.balanceOf(msg.sender), \"COVER: low CLAIM balance\");\n    require(_amount <= _noclaimCovToken.balanceOf(msg.sender), \"COVER: low NOCLAIM balance\");\n\n    _claimCovToken.burnByCover(msg.sender, _amount);\n    _noclaimCovToken.burnByCover(msg.sender, _amount);\n    _payCollateral(msg.sender, _amount);\n  }\n\n  /**\n   * @notice set CovTokenSymbol, will update symbols for both covTokens, only dev account (factory owner)\n   * For example:\n   *  - COVER_CURVE_2020_12_31_DAI_0\n   */\n  function setCovTokenSymbol(string calldata _name) external override {\n    require(_dev() == msg.sender, \"COVER: not dev\");\n\n    claimCovToken.setSymbol(string(abi.encodePacked(_name, \"_CLAIM\")));\n    noclaimCovToken.setSymbol(string(abi.encodePacked(_name, \"_NOCLAIM\")));\n  }\n\n  /// @notice the owner of this contract is Protocol contract, the owner of Protocol is ProtocolFactory contract\n  function _factory() private view returns (address) {\n    return IOwnable(owner()).owner();\n  }\n\n  // get the claim details for the corresponding nonce from protocol contract\n  function _claimDetails() private view returns (uint16 _payoutNumerator, uint16 _payoutDenominator, uint48 _incidentTimestamp, uint48 _claimEnactedTimestamp) {\n    return IProtocol(owner()).claimDetails(claimNonce);\n  }\n\n  /// @notice the owner of ProtocolFactory contract is dev, also see {_factory}\n  function _dev() private view returns (address) {\n    return IOwnable(_factory()).owner();\n  }\n\n  /// @notice make sure no claim is accepted\n  function _noClaimAcceptedCheck() private view {\n    require(IProtocol(owner()).claimNonce() == claimNonce, \"COVER: claim accepted\");\n  }\n\n  /// @notice transfer collateral (amount - fee) from this contract to recevier, transfer fee to COVER treasury\n  function _payCollateral(address _receiver, uint256 _amount) private nonReentrant {\n    IProtocolFactory factory = IProtocolFactory(_factory());\n    uint256 redeemFeeNumerator = factory.redeemFeeNumerator();\n    uint256 redeemFeeDenominator = factory.redeemFeeDenominator();\n    uint256 fee = _amount.mul(redeemFeeNumerator).div(redeemFeeDenominator);\n    address treasury = factory.treasury();\n    IERC20 collateralToken = IERC20(collateral);\n\n    collateralToken.safeTransfer(_receiver, _amount.sub(fee));\n    collateralToken.safeTransfer(treasury, fee);\n  }\n\n  /// @notice burn covToken and pay sender\n  function _paySender(\n    ICoverERC20 _covToken,\n    uint256 _payoutNumerator,\n    uint256 _payoutDenominator\n  ) private {\n    require(_payoutNumerator <= _payoutDenominator, \"COVER: payout % is > 100%\");\n    require(_payoutNumerator > 0, \"COVER: payout % < 0%\");\n\n    uint256 amount = _covToken.balanceOf(msg.sender);\n    require(amount > 0, \"COVER: low covToken balance\");\n\n    _covToken.burnByCover(msg.sender, amount);\n\n    uint256 payoutAmount = amount.mul(_payoutNumerator).div(_payoutDenominator);\n    _payCollateral(msg.sender, payoutAmount);\n  }\n\n  /// @dev Emits NewCoverERC20\n  function _createCovToken(string memory _suffix) private returns (ICoverERC20) {\n    bytes memory bytecode = type(InitializableAdminUpgradeabilityProxy).creationCode;\n    bytes32 salt = keccak256(abi.encodePacked(IProtocol(owner()).name(), expirationTimestamp, collateral, claimNonce, _suffix));\n    address payable proxyAddr = Create2.deploy(0, salt, bytecode);\n\n    bytes memory initData = abi.encodeWithSelector(COVERERC20_INIT_SIGNITURE, string(abi.encodePacked(name, \"_\", _suffix)));\n    address coverERC20Implementation = IProtocolFactory(_factory()).coverERC20Implementation();\n    InitializableAdminUpgradeabilityProxy(proxyAddr).initialize(\n      coverERC20Implementation,\n      IOwnable(_factory()).owner(),\n      initData\n    );\n\n    emit NewCoverERC20(proxyAddr);\n    return ICoverERC20(proxyAddr);\n  }\n}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}}