File size: 61,946 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../../../utils/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 Address for address;\n\n    function safeTransfer(\n        IERC20 token,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 value\n    ) 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(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) 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        require(\n            (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(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        uint256 newAllowance = token.allowance(address(this), spender) + value;\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            uint256 newAllowance = oldAllowance - value;\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n        }\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) {\n            // Return data is optional\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\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     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\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        (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(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) 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(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) 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(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\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                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/math/SafeMath.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            uint256 c = a + b;\n            if (c < a) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b > a) return (false, 0);\n            return (true, a - b);\n        }\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\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) return (true, 0);\n            uint256 c = a * b;\n            if (c / a != b) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a / b);\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a % b);\n        }\n    }\n\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        return a + b;\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 a - b;\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        return a * b;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator.\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting 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 a % b;\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     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {trySub}.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b <= a, errorMessage);\n            return a - b;\n        }\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting 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(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a / b;\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting with custom message when dividing by zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryMod}.\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(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a % b;\n        }\n    }\n}\n"
    },
    "contracts/strategy/BaseStrategy.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.8.0 <0.9.0;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {SafeERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {SafeMath} from \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\n\nimport {VaultAPI} from \"../../interfaces/vault/VaultAPI.sol\";\n\nlibrary StrategyLib {\n    using SafeMath for uint256;\n\n    function internalHarvestTrigger(\n        address vault,\n        address strategy,\n        uint256 callCost,\n        uint256 minReportDelay,\n        uint256 maxReportDelay,\n        uint256 debtThreshold,\n        uint256 profitFactor\n    ) public view returns (bool) {\n        StrategyParams memory params = VaultAPI(vault).strategies(strategy);\n        // Should not trigger if Strategy is not activated\n        if (params.activation == 0) {\n            return false;\n        }\n\n        // Should not trigger if we haven't waited long enough since previous harvest\n        if (block.timestamp.sub(params.lastReport) < minReportDelay) return false;\n\n        // Should trigger if hasn't been called in a while\n        if (block.timestamp.sub(params.lastReport) >= maxReportDelay) return true;\n\n        // If some amount is owed, pay it back\n        // NOTE: Since debt is based on deposits, it makes sense to guard against large\n        //       changes to the value from triggering a harvest directly through user\n        //       behavior. This should ensure reasonable resistance to manipulation\n        //       from user-initiated withdrawals as the outstanding debt fluctuates.\n        uint256 outstanding = VaultAPI(vault).debtOutstanding();\n\n        if (outstanding > debtThreshold) return true;\n\n        // Check for profits and losses\n        uint256 total = StrategyAPI(strategy).estimatedTotalAssets();\n\n        // Trigger if we have a loss to report\n        if (total.add(debtThreshold) < params.totalDebt) return true;\n\n        uint256 profit = 0;\n        if (total > params.totalDebt) profit = total.sub(params.totalDebt);\n        // We've earned a profit!\n\n        // Otherwise, only trigger if it \"makes sense\" economically (gas cost\n        // is <N% of value moved)\n        uint256 credit = VaultAPI(vault).creditAvailable();\n        return (profitFactor.mul(callCost) < credit.add(profit));\n    }\n\n    function internalSetRewards(\n        address oldRewards,\n        address newRewards,\n        address vault\n    ) public {\n        require(newRewards != address(0));\n        VaultAPI(vault).approve(oldRewards, 0);\n        VaultAPI(vault).approve(newRewards, type(uint256).max);\n    }\n}\n\n// File: StrategyLib.sol\n\nstruct StrategyParams {\n    uint256 performanceFee;\n    uint256 activation;\n    uint256 debtRatio;\n    uint256 minDebtPerHarvest;\n    uint256 maxDebtPerHarvest;\n    uint256 lastReport;\n    uint256 totalDebt;\n    uint256 totalGain;\n    uint256 totalLoss;\n}\n\n/**\n * This interface is here for the keeper bot to use.\n */\ninterface StrategyAPI {\n    function name() external view returns (string memory);\n\n    function vault() external view returns (address);\n\n    function want() external view returns (address);\n\n    function apiVersion() external pure returns (string memory);\n\n    function keeper() external view returns (address);\n\n    function isActive() external view returns (bool);\n\n    function delegatedAssets() external view returns (uint256);\n\n    function estimatedTotalAssets() external view returns (uint256);\n\n    function tendTrigger(uint256 callCost) external view returns (bool);\n\n    function tend() external;\n\n    function harvestTrigger(uint256 callCost) external view returns (bool);\n\n    function harvest() external;\n\n    event Harvested(uint256 profit, uint256 loss, uint256 debtPayment, uint256 debtOutstanding);\n}\n\n/**\n * @title Base Strategy\n * @author Everbloom\n * @notice\n *  BaseStrategy implements all of the required functionality to interoperate\n *  closely with the Vault contract. This contract should be inherited and the\n *  abstract methods implemented to adapt the Strategy to the particular needs\n *  it has to create a return.\n *\n *  Of special interest is the relationship between `harvest()` and\n *  `vault.report()'. `harvest()` may be called simply because enough time has\n *  elapsed since the last report, and not because any funds need to be moved\n *  or positions adjusted. This is critical so that the Vault may maintain an\n *  accurate picture of the Strategy's performance. See  `vault.report()`,\n *  `harvest()`, and `harvestTrigger()` for further details.\n */\n\nabstract contract BaseStrategy {\n    using SafeMath for uint256;\n    string public metadataURI;\n\n    /**\n     * @notice\n     *  Used to track which version of `StrategyAPI` this Strategy\n     *  implements.\n     * @dev The Strategy's version must match the Vault's `API_VERSION`.\n     * @return A string which holds the current API version of this contract.\n     */\n    function apiVersion() public pure returns (string memory) {\n        return \"0.4.3\";\n    }\n\n    /**\n     * @notice This Strategy's name.\n     * @dev\n     *  You can use this field to manage the \"version\" of this Strategy, e.g.\n     *  `StrategySomethingOrOtherV1`. However, \"API Version\" is managed by\n     *  `apiVersion()` function above.\n     * @return This Strategy's name.\n     */\n    function name() external view virtual returns (string memory);\n\n    /**\n     * @notice\n     *  The amount (priced in want) of the total assets managed by this strategy should not count\n     *  towards TVL calculations.\n     * @dev\n     *  You can override this field to set it to a non-zero value if some of the assets of this\n     *  Strategy is somehow delegated inside another part of the ecosystem e.g. another Vault.\n     *  Note that this value must be strictly less than or equal to the amount provided by\n     *  `estimatedTotalAssets()` below, as the TVL calc will be total assets minus delegated assets.\n     *  Also note that this value is used to determine the total assets under management by this\n     *  strategy, for the purposes of computing the management fee in `Vault`\n     * @return\n     *  The amount of assets this strategy manages that should not be included in Total Value\n     *  Locked (TVL) calculation across it's ecosystem.\n     */\n    function delegatedAssets() external view virtual returns (uint256) {\n        return 0;\n    }\n\n    VaultAPI public vault;\n    address public strategist;\n    address public rewards;\n    address public keeper;\n\n    IERC20 public want;\n\n    // So indexers can keep track of this\n    event Harvested(uint256 profit, uint256 loss, uint256 debtPayment, uint256 debtOutstanding);\n\n    event UpdatedStrategist(address newStrategist);\n\n    event UpdatedKeeper(address newKeeper);\n\n    event UpdatedRewards(address rewards);\n\n    event UpdatedMinReportDelay(uint256 delay);\n\n    event UpdatedMaxReportDelay(uint256 delay);\n\n    event UpdatedProfitFactor(uint256 profitFactor);\n\n    event UpdatedDebtThreshold(uint256 debtThreshold);\n\n    event EmergencyExitEnabled();\n\n    event UpdatedMetadataURI(string metadataURI);\n\n    // The minimum number of seconds between harvest calls. See\n    // `setMinReportDelay()` for more details.\n    uint256 public minReportDelay;\n\n    // The maximum number of seconds between harvest calls. See\n    // `setMaxReportDelay()` for more details.\n    uint256 public maxReportDelay;\n\n    // The minimum multiple that `callCost` must be above the credit/profit to\n    // be \"justifiable\". See `setProfitFactor()` for more details.\n    uint256 public profitFactor;\n\n    // Use this to adjust the threshold at which running a debt causes a\n    // harvest trigger. See `setDebtThreshold()` for more details.\n    uint256 public debtThreshold;\n\n    // See note on `setEmergencyExit()`.\n    bool public emergencyExit;\n\n    // modifiers\n    modifier onlyAuthorized() {\n        _onlyAuthorized();\n        _;\n    }\n\n    modifier onlyEmergencyAuthorized() {\n        _onlyEmergencyAuthorized();\n        _;\n    }\n\n    modifier onlyStrategist() {\n        _onlyStrategist();\n        _;\n    }\n\n    modifier onlyGovernance() {\n        _onlyGovernance();\n        _;\n    }\n\n    modifier onlyRewarder() {\n        _onlyRewarder();\n        _;\n    }\n\n    modifier onlyKeepers() {\n        _onlyKeepers();\n        _;\n    }\n\n    function _onlyAuthorized() internal view {\n        require(msg.sender == strategist || msg.sender == _governance());\n    }\n\n    function _onlyEmergencyAuthorized() internal view {\n        require(\n            msg.sender == strategist ||\n                msg.sender == _governance() ||\n                msg.sender == vault.guardian() ||\n                msg.sender == vault.management()\n        );\n    }\n\n    function _onlyStrategist() internal view {\n        require(msg.sender == strategist);\n    }\n\n    function _onlyGovernance() internal view {\n        require(msg.sender == _governance());\n    }\n\n    function _onlyRewarder() internal view {\n        require(msg.sender == _governance() || msg.sender == strategist);\n    }\n\n    function _onlyKeepers() internal view {\n        require(\n            msg.sender == keeper ||\n                msg.sender == strategist ||\n                msg.sender == _governance() ||\n                msg.sender == vault.guardian() ||\n                msg.sender == vault.management()\n        );\n    }\n\n    constructor(address _vault) {\n        _initialize(_vault, msg.sender, msg.sender, msg.sender);\n    }\n\n    /**\n     * @notice\n     *  Initializes the Strategy, this is called only once, when the\n     *  contract is deployed.\n     * @dev `_vault` should implement `VaultAPI`.\n     * @param _vault The address of the Vault responsible for this Strategy.\n     * @param _strategist The address to assign as `strategist`.\n     * The strategist is able to change the reward address\n     * @param _rewards  The address to use for pulling rewards.\n     * @param _keeper The adddress of the _keeper. _keeper\n     * can harvest and tend a strategy.\n     */\n    function _initialize(\n        address _vault,\n        address _strategist,\n        address _rewards,\n        address _keeper\n    ) internal {\n        require(address(want) == address(0), \"Strategy already initialized\");\n\n        vault = VaultAPI(_vault);\n        want = IERC20(vault.token());\n        SafeERC20.safeApprove(want, _vault, type(uint256).max);\n        // Give Vault unlimited access (might save gas)\n        strategist = _strategist;\n        rewards = _rewards;\n        keeper = _keeper;\n\n        // initialize variables\n        minReportDelay = 0;\n        maxReportDelay = 86400;\n        profitFactor = 100;\n        debtThreshold = 0;\n\n        vault.approve(rewards, type(uint256).max);\n        // Allow rewards to be pulled\n    }\n\n    /**\n     * @notice\n     *  Used to change `strategist`.\n     *\n     *  This may only be called by governance or the existing strategist.\n     * @param _strategist The new address to assign as `strategist`.\n     */\n    function setStrategist(address _strategist) external onlyAuthorized {\n        require(_strategist != address(0));\n        strategist = _strategist;\n        emit UpdatedStrategist(_strategist);\n    }\n\n    /**\n     * @notice\n     *  Used to change `keeper`.\n     *\n     *  `keeper` is the only address that may call `tend()` or `harvest()`,\n     *  other than `governance()` or `strategist`. However, unlike\n     *  `governance()` or `strategist`, `keeper` may *only* call `tend()`\n     *  and `harvest()`, and no other authorized functions, following the\n     *  principle of least privilege.\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _keeper The new address to assign as `keeper`.\n     */\n    function setKeeper(address _keeper) external onlyAuthorized {\n        require(_keeper != address(0));\n        keeper = _keeper;\n        emit UpdatedKeeper(_keeper);\n    }\n\n    /**\n     * @notice\n     *  Used to change `rewards`. EOA or smart contract which has the permission\n     *  to pull rewards from the vault.\n     *\n     *  This may only be called by the strategist.\n     * @param _rewards The address to use for pulling rewards.\n     */\n    function setRewards(address _rewards) external onlyRewarder {\n        address oldRewards = rewards;\n        rewards = _rewards;\n        StrategyLib.internalSetRewards(oldRewards, _rewards, address(vault));\n        emit UpdatedRewards(_rewards);\n    }\n\n    /**\n     * @notice\n     *  Used to change `minReportDelay`. `minReportDelay` is the minimum number\n     *  of blocks that should pass for `harvest()` to be called.\n     *\n     *  For external keepers (such as the Keep3r network), this is the minimum\n     *  time between jobs to wait. (see `harvestTrigger()`\n     *  for more details.)\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _delay The minimum number of seconds to wait between harvests.\n     */\n    function setMinReportDelay(uint256 _delay) external onlyAuthorized {\n        minReportDelay = _delay;\n        emit UpdatedMinReportDelay(_delay);\n    }\n\n    /**\n     * @notice\n     *  Used to change `maxReportDelay`. `maxReportDelay` is the maximum number\n     *  of blocks that should pass for `harvest()` to be called.\n     *\n     *  For external keepers (such as the Keep3r network), this is the maximum\n     *  time between jobs to wait. (see `harvestTrigger()`\n     *  for more details.)\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _delay The maximum number of seconds to wait between harvests.\n     */\n    function setMaxReportDelay(uint256 _delay) external onlyAuthorized {\n        maxReportDelay = _delay;\n        emit UpdatedMaxReportDelay(_delay);\n    }\n\n    /**\n     * @notice\n     *  Used to change `profitFactor`. `profitFactor` is used to determine\n     *  if it's worthwhile to harvest, given gas costs. (See `harvestTrigger()`\n     *  for more details.)\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _profitFactor A ratio to multiply anticipated\n     * `harvest()` gas cost against.\n     */\n    function setProfitFactor(uint256 _profitFactor) external onlyAuthorized {\n        profitFactor = _profitFactor;\n        emit UpdatedProfitFactor(_profitFactor);\n    }\n\n    /**\n     * @notice\n     *  Sets how far the Strategy can go into loss without a harvest and report\n     *  being required.\n     *\n     *  By default this is 0, meaning any losses would cause a harvest which\n     *  will subsequently report the loss to the Vault for tracking. (See\n     *  `harvestTrigger()` for more details.)\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _debtThreshold How big of a loss this Strategy may carry without\n     * being required to report to the Vault.\n     */\n    function setDebtThreshold(uint256 _debtThreshold) external onlyAuthorized {\n        debtThreshold = _debtThreshold;\n        emit UpdatedDebtThreshold(_debtThreshold);\n    }\n\n    /**\n     * @notice\n     *  Used to change `metadataURI`. `metadataURI` is used to store the URI\n     * of the file describing the strategy.\n     *\n     *  This may only be called by governance or the strategist.\n     * @param _metadataURI The URI that describe the strategy.\n     */\n    function setMetadataURI(string calldata _metadataURI) external onlyAuthorized {\n        metadataURI = _metadataURI;\n        emit UpdatedMetadataURI(_metadataURI);\n    }\n\n    /**\n     * Resolve governance address from Vault contract, used to make assertions\n     * on protected functions in the Strategy.\n     */\n    function _governance() internal view returns (address) {\n        return vault.governance();\n    }\n\n    /**\n     * @notice\n     *  Provide an accurate conversion from `_amtInWei` (denominated in wei)\n     *  to `want` (using the native decimal characteristics of `want`).\n     * @dev\n     *  Care must be taken when working with decimals to assure that the conversion\n     *  is compatible. As an example:\n     *\n     *      given 1e17 wei (0.1 ETH) as input, and want is USDC (6 decimals),\n     *      with USDC/ETH = 1800, this should give back 180000000 (180 USDC)\n     *\n     * @param _amtInWei The amount (in wei/1e-18 ETH) to convert to `want`\n     * @return The amount in `want` of `_amtInEth` converted to `want`\n     **/\n    function ethToWant(uint256 _amtInWei) public view virtual returns (uint256);\n\n    /**\n     * @notice\n     *  Provide an accurate estimate for the total amount of assets\n     *  (principle + return) that this Strategy is currently managing,\n     *  denominated in terms of `want` tokens.\n     *\n     *  This total should be \"realizable\" e.g. the total value that could\n     *  *actually* be obtained from this Strategy if it were to divest its\n     *  entire position based on current on-chain conditions.\n     * @dev\n     *  Care must be taken in using this function, since it relies on external\n     *  systems, which could be manipulated by the attacker to give an inflated\n     *  (or reduced) value produced by this function, based on current on-chain\n     *  conditions (e.g. this function is possible to influence through\n     *  flashloan attacks, oracle manipulations, or other DeFi attack\n     *  mechanisms).\n     *\n     *  It is up to governance to use this function to correctly order this\n     *  Strategy relative to its peers in the withdrawal queue to minimize\n     *  losses for the Vault based on sudden withdrawals. This value should be\n     *  higher than the total debt of the Strategy and higher than its expected\n     *  value to be \"safe\".\n     * @return The estimated total assets in this Strategy.\n     */\n    function estimatedTotalAssets() public view virtual returns (uint256);\n\n    /*\n     * @notice\n     *  Provide an indication of whether this strategy is currently \"active\"\n     *  in that it is managing an active position, or will manage a position in\n     *  the future. This should correlate to `harvest()` activity, so that Harvest\n     *  events can be tracked externally by indexing agents.\n     * @return True if the strategy is actively managing a position.\n     */\n    function isActive() public view returns (bool) {\n        return vault.strategies(address(this)).debtRatio > 0 || estimatedTotalAssets() > 0;\n    }\n\n    /**\n     * Perform any Strategy unwinding or other calls necessary to capture the\n     * \"free return\" this Strategy has generated since the last time its core\n     * position(s) were adjusted. Examples include unwrapping extra rewards.\n     * This call is only used during \"normal operation\" of a Strategy, and\n     * should be optimized to minimize losses as much as possible.\n     *\n     * This method returns any realized profits and/or realized losses\n     * incurred, and should return the total amounts of profits/losses/debt\n     * payments (in `want` tokens) for the Vault's accounting (e.g.\n     * `want.balanceOf(this) >= _debtPayment + _profit`).\n     *\n     * `_debtOutstanding` will be 0 if the Strategy is not past the configured\n     * debt limit, otherwise its value will be how far past the debt limit\n     * the Strategy is. The Strategy's debt limit is configured in the Vault.\n     *\n     * NOTE: `_debtPayment` should be less than or equal to `_debtOutstanding`.\n     *       It is okay for it to be less than `_debtOutstanding`, as that\n     *       should only used as a guide for how much is left to pay back.\n     *       Payments should be made to minimize loss from slippage, debt,\n     *       withdrawal fees, etc.\n     *\n     * See `vault.debtOutstanding()`.\n     */\n    function _prepareReturn(uint256 _debtOutstanding)\n        internal\n        virtual\n        returns (\n            uint256 _profit,\n            uint256 _loss,\n            uint256 _debtPayment\n        );\n\n    /**\n     * Perform any adjustments to the core position(s) of this Strategy given\n     * what change the Vault made in the \"investable capital\" available to the\n     * Strategy. Note that all \"free capital\" in the Strategy after the report\n     * was made is available for reinvestment. Also note that this number\n     * could be 0, and you should handle that scenario accordingly.\n     *\n     * See comments regarding `_debtOutstanding` on `prepareReturn()`.\n     */\n    function _adjustPosition(uint256 _debtOutstanding) internal virtual;\n\n    /**\n     * Liquidate up to `_amountNeeded` of `want` of this strategy's positions,\n     * irregardless of slippage. Any excess will be re-invested with `adjustPosition()`.\n     * This function should return the amount of `want` tokens made available by the\n     * liquidation. If there is a difference between them, `_loss` indicates whether the\n     * difference is due to a realized loss, or if there is some other sitution at play\n     * (e.g. locked funds) where the amount made available is less than what is needed.\n     *\n     * NOTE: The invariant `_liquidatedAmount + _loss <= _amountNeeded` should always be maintained\n     */\n    function _liquidatePosition(uint256 _amountNeeded)\n        internal\n        virtual\n        returns (uint256 _liquidatedAmount, uint256 _loss);\n\n    /**\n     * Liquidate everything and returns the amount that got freed.\n     * This function is used during emergency exit instead of `prepareReturn()` to\n     * liquidate all of the Strategy's positions back to the Vault.\n     */\n\n    function _liquidateAllPositions() internal virtual returns (uint256 _amountFreed);\n\n    /**\n     * @notice\n     *  Provide a signal to the keeper that `tend()` should be called. The\n     *  keeper will provide the estimated gas cost that they would pay to call\n     *  `tend()`, and this function should use that estimate to make a\n     *  determination if calling it is \"worth it\" for the keeper. This is not\n     *  the only consideration into issuing this trigger, for example if the\n     *  position would be negatively affected if `tend()` is not called\n     *  shortly, then this can return `true` even if the keeper might be\n     *  \"at a loss\".\n     * @dev\n     *  `callCostInWei` must be priced in terms of `wei` (1e-18 ETH).\n     *\n     *  This call and `harvestTrigger()` should never return `true` at the same\n     *  time.\n     * @param callCostInWei The keeper's estimated gas cost to call `tend()` (in wei).\n     * @return `true` if `tend()` should be called, `false` otherwise.\n     */\n    // solhint-disable-next-line no-unused-vars\n    function tendTrigger(uint256 callCostInWei) public view virtual returns (bool) {\n        // We usually don't need tend, but if there are positions that need\n        // active maintainence, overriding this function is how you would\n        // signal for that.\n        // If your implementation uses the cost of the call in want, you can\n        // use uint256 callCost = ethToWant(callCostInWei);\n\n        return false;\n    }\n\n    /**\n     * @notice\n     *  Adjust the Strategy's position. The purpose of tending isn't to\n     *  realize gains, but to maximize yield by reinvesting any returns.\n     *\n     *  See comments on `adjustPosition()`.\n     *\n     *  This may only be called by governance, the strategist, or the keeper.\n     */\n    function tend() external onlyKeepers {\n        // Don't take profits with this call, but adjust for better gains\n        _adjustPosition(vault.debtOutstanding());\n    }\n\n    /**\n     * @notice\n     *  Provide a signal to the keeper that `harvest()` should be called. The\n     *  keeper will provide the estimated gas cost that they would pay to call\n     *  `harvest()`, and this function should use that estimate to make a\n     *  determination if calling it is \"worth it\" for the keeper. This is not\n     *  the only consideration into issuing this trigger, for example if the\n     *  position would be negatively affected if `harvest()` is not called\n     *  shortly, then this can return `true` even if the keeper might be \"at a\n     *  loss\".\n     * @dev\n     *  `callCostInWei` must be priced in terms of `wei` (1e-18 ETH).\n     *\n     *  This call and `tendTrigger` should never return `true` at the\n     *  same time.\n     *\n     *  See `min/maxReportDelay`, `profitFactor`, `debtThreshold` to adjust the\n     *  strategist-controlled parameters that will influence whether this call\n     *  returns `true` or not. These parameters will be used in conjunction\n     *  with the parameters reported to the Vault (see `params`) to determine\n     *  if calling `harvest()` is merited.\n     *\n     *  It is expected that an external system will check `harvestTrigger()`.\n     *  This could be a script run off a desktop or cloud bot (e.g.\n     *  or via an integration with the Keep3r network (e.g.\n     *  https://github.com/Macarse/GenericKeep3rV2/blob/master/contracts/keep3r/GenericKeep3rV2.sol).\n     * @param callCostInWei The keeper's estimated gas cost to call `harvest()` (in wei).\n     * @return `true` if `harvest()` should be called, `false` otherwise.\n     */\n    function harvestTrigger(uint256 callCostInWei) public view virtual returns (bool) {\n        return\n            StrategyLib.internalHarvestTrigger(\n                address(vault),\n                address(this),\n                ethToWant(callCostInWei),\n                minReportDelay,\n                maxReportDelay,\n                debtThreshold,\n                profitFactor\n            );\n    }\n\n    /**\n     * @notice\n     *  Harvests the Strategy, recognizing any profits or losses and adjusting\n     *  the Strategy's position.\n     *\n     *  In the rare case the Strategy is in emergency shutdown, this will exit\n     *  the Strategy's position.\n     *\n     *  This may only be called by governance, the strategist, or the keeper.\n     * @dev\n     *  When `harvest()` is called, the Strategy reports to the Vault (via\n     *  `vault.report()`), so in some cases `harvest()` must be called in order\n     *  to take in profits, to borrow newly available funds from the Vault, or\n     *  otherwise adjust its position. In other cases `harvest()` must be\n     *  called to report to the Vault on the Strategy's position, especially if\n     *  any losses have occurred.\n     */\n    function harvest() external onlyKeepers {\n        uint256 profit = 0;\n        uint256 loss = 0;\n        uint256 debtOutstanding = vault.debtOutstanding();\n        uint256 debtPayment = 0;\n        if (emergencyExit) {\n            // Free up as much capital as possible\n            uint256 amountFreed = _liquidateAllPositions();\n            if (amountFreed < debtOutstanding) {\n                loss = debtOutstanding.sub(amountFreed);\n            } else if (amountFreed > debtOutstanding) {\n                profit = amountFreed.sub(debtOutstanding);\n            }\n            debtPayment = debtOutstanding.sub(loss);\n        } else {\n            // Free up returns for Vault to pull\n            (profit, loss, debtPayment) = _prepareReturn(debtOutstanding);\n        }\n\n        // Allow Vault to take up to the \"harvested\" balance of this contract,\n        // which is the amount it has earned since the last time it reported to\n        // the Vault.\n        debtOutstanding = vault.report(profit, loss, debtPayment);\n\n        // Check if free returns are left, and re-invest them\n        _adjustPosition(debtOutstanding);\n\n        emit Harvested(profit, loss, debtPayment, debtOutstanding);\n    }\n\n    /**\n     * @notice\n     *  Withdraws `_amountNeeded` to `vault`.\n     *\n     *  This may only be called by the Vault.\n     * @param _amountNeeded How much `want` to withdraw.\n     * @return _loss Any realized losses\n     */\n    function withdraw(uint256 _amountNeeded) external returns (uint256 _loss) {\n        require(msg.sender == address(vault), \"!vault\");\n        // Liquidate as much as possible to `want`, up to `_amountNeeded`\n        uint256 amountFreed;\n        (amountFreed, _loss) = _liquidatePosition(_amountNeeded);\n        // Send it directly back (NOTE: Using `msg.sender` saves some gas here)\n        SafeERC20.safeTransfer(want, msg.sender, amountFreed);\n        // NOTE: Reinvest anything leftover on next `tend`/`harvest`\n    }\n\n    /**\n     * Do anything necessary to prepare this Strategy for migration, such as\n     * transferring any reserve or LP tokens, CDPs, or other tokens or stores of\n     * value.\n     */\n    function _prepareMigration(address _newStrategy) internal virtual;\n\n    /**\n     * @notice\n     *  Transfers all `want` from this Strategy to `_newStrategy`.\n     *\n     *  This may only be called by the Vault.\n     * @dev\n     * The new Strategy's Vault must be the same as this Strategy's Vault.\n     *  The migration process should be carefully performed to make sure all\n     * the assets are migrated to the new address, which should have never\n     * interacted with the vault before.\n     * @param _newStrategy The Strategy to migrate to.\n     */\n    function migrate(address _newStrategy) external {\n        require(msg.sender == address(vault));\n        require(BaseStrategy(_newStrategy).vault() == vault);\n        _prepareMigration(_newStrategy);\n        SafeERC20.safeTransfer(want, _newStrategy, want.balanceOf(address(this)));\n    }\n\n    /**\n     * @notice\n     *  Activates emergency exit. Once activated, the Strategy will exit its\n     *  position upon the next harvest, depositing all funds into the Vault as\n     *  quickly as is reasonable given on-chain conditions.\n     *\n     *  This may only be called by governance or the strategist.\n     * @dev\n     *  See `vault.setEmergencyShutdown()` and `harvest()` for further details.\n     */\n    function setEmergencyExit() external onlyEmergencyAuthorized {\n        emergencyExit = true;\n        vault.revokeStrategy();\n\n        emit EmergencyExitEnabled();\n    }\n\n    /**\n     * Override this to add all tokens/tokenized positions this contract\n     * manages on a *persistent* basis (e.g. not just for swapping back to\n     * want ephemerally).\n     *\n     * NOTE: Do *not* include `want`, already included in `sweep` below.\n     *\n     * Example:\n     * ```\n     *    function protectedTokens() internal override view returns (address[] memory) {\n     *      address[] memory protected = new address[](3);\n     *      protected[0] = tokenA;\n     *      protected[1] = tokenB;\n     *      protected[2] = tokenC;\n     *      return protected;\n     *    }\n     * ```\n     */\n    function _protectedTokens() internal view virtual returns (address[] memory);\n\n    /**\n     * @notice\n     *  Removes tokens from this Strategy that are not the type of tokens\n     *  managed by this Strategy. This may be used in case of accidentally\n     *  sending the wrong kind of token to this Strategy.\n     *\n     *  Tokens will be sent to `governance()`.\n     *\n     *  This will fail if an attempt is made to sweep `want`, or any tokens\n     *  that are protected by this Strategy.\n     *\n     *  This may only be called by governance.\n     * @dev\n     *  Implement `protectedTokens()` to specify any additional tokens that\n     *  should be protected from sweeping in addition to `want`.\n     * @param _token The token to transfer out of this vault.\n     */\n    function sweep(address _token) external onlyGovernance {\n        require(_token != address(want), \"!want\");\n        require(_token != address(vault), \"!shares\");\n\n        address[] memory protectedTokens = _protectedTokens();\n        for (uint256 i; i < protectedTokens.length; i++) require(_token != protectedTokens[i], \"!protected\");\n\n        SafeERC20.safeTransfer(IERC20(_token), _governance(), IERC20(_token).balanceOf(address(this)));\n    }\n}\n\nabstract contract BaseStrategyInitializable is BaseStrategy {\n    bool public isOriginal = true;\n\n    event Cloned(address indexed clone);\n\n    constructor(address _vault) BaseStrategy(_vault) {}\n\n    function initialize(\n        address _vault,\n        address _strategist,\n        address _rewards,\n        address _keeper\n    ) external virtual {\n        _initialize(_vault, _strategist, _rewards, _keeper);\n    }\n\n    function clone(address _vault) external returns (address) {\n        return this.clone(_vault, msg.sender, msg.sender, msg.sender);\n    }\n\n    function clone(\n        address _vault,\n        address _strategist,\n        address _rewards,\n        address _keeper\n    ) external returns (address newStrategy) {\n        require(isOriginal, \"!clone\");\n        // Copied from https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol\n        bytes20 addressBytes = bytes20(address(this));\n\n        assembly {\n            // EIP-1167 bytecode\n            let clone_code := mload(0x40)\n            mstore(clone_code, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n            mstore(add(clone_code, 0x14), addressBytes)\n            mstore(add(clone_code, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n            newStrategy := create(0, clone_code, 0x37)\n        }\n\n        BaseStrategyInitializable(newStrategy).initialize(_vault, _strategist, _rewards, _keeper);\n\n        emit Cloned(newStrategy);\n    }\n}\n"
    },
    "interfaces/vault/VaultAPI.sol": {
      "content": "// SPDX-License-Identifier: AGPL-3.0\n\npragma solidity >=0.8.0 <0.9.0;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {StrategyParams} from \"../../contracts/strategy/BaseStrategy.sol\";\n\ninterface VaultAPI is IERC20 {\n    function name() external view returns (string calldata);\n\n    function symbol() external view returns (string calldata);\n\n    function decimals() external view returns (uint256);\n\n    function apiVersion() external pure returns (string memory);\n\n    function permit(\n        address owner,\n        address spender,\n        uint256 amount,\n        uint256 expiry,\n        bytes calldata signature\n    ) external returns (bool);\n\n    // NOTE: Vyper produces multiple signatures for a given function with \"default\" args\n    function deposit() external returns (uint256);\n\n    function deposit(uint256 amount) external returns (uint256);\n\n    function deposit(uint256 amount, address recipient) external returns (uint256);\n\n    // NOTE: Vyper produces multiple signatures for a given function with \"default\" args\n    function withdraw() external returns (uint256);\n\n    function withdraw(uint256 maxShares) external returns (uint256);\n\n    function withdraw(uint256 maxShares, address recipient) external returns (uint256);\n\n    function withdraw(\n        uint256 maxShares,\n        address recipient,\n        uint256 maxLoss\n    ) external returns (uint256);\n\n    function token() external view returns (address);\n\n    function strategies(address _strategy) external view returns (StrategyParams memory);\n\n    function pricePerShare() external view returns (uint256);\n\n    function totalAssets() external view returns (uint256);\n\n    function depositLimit() external view returns (uint256);\n\n    function maxAvailableShares() external view returns (uint256);\n\n    /**\n     * View how much the Vault would increase this Strategy's borrow limit,\n     * based on its present performance (since its last report). Can be used to\n     * determine expectedReturn in your Strategy.\n     */\n    function creditAvailable() external view returns (uint256);\n\n    /**\n     * View how much the Vault would like to pull back from the Strategy,\n     * based on its present performance (since its last report). Can be used to\n     * determine expectedReturn in your Strategy.\n     */\n    function debtOutstanding() external view returns (uint256);\n\n    /**\n     * View how much the Vault expect this Strategy to return at the current\n     * block, based on its present performance (since its last report). Can be\n     * used to determine expectedReturn in your Strategy.\n     */\n    function expectedReturn() external view returns (uint256);\n\n    /**\n     * This is the main contact point where the Strategy interacts with the\n     * Vault. It is critical that this call is handled as intended by the\n     * Strategy. Therefore, this function will be called by BaseStrategy to\n     * make sure the integration is correct.\n     */\n    function report(\n        uint256 _gain,\n        uint256 _loss,\n        uint256 _debtPayment\n    ) external returns (uint256);\n\n    /**\n     * This function should only be used in the scenario where the Strategy is\n     * being retired but no migration of the positions are possible, or in the\n     * extreme scenario that the Strategy needs to be put into \"Emergency Exit\"\n     * mode in order for it to exit as quickly as possible. The latter scenario\n     * could be for any reason that is considered \"critical\" that the Strategy\n     * exits its position as fast as possible, such as a sudden change in\n     * market conditions leading to losses, or an imminent failure in an\n     * external dependency.\n     */\n    function revokeStrategy() external;\n\n    /**\n     * View the governance address of the Vault to assert privileged functions\n     * can only be called by governance. The Strategy serves the Vault, so it\n     * is subject to governance defined by the Vault.\n     */\n    function governance() external view returns (address);\n\n    /**\n     * View the management address of the Vault to assert privileged functions\n     * can only be called by management. The Strategy serves the Vault, so it\n     * is subject to management defined by the Vault.\n     */\n    function management() external view returns (address);\n\n    /**\n     * View the guardian address of the Vault to assert privileged functions\n     * can only be called by guardian. The Strategy serves the Vault, so it\n     * is subject to guardian defined by the Vault.\n     */\n    function guardian() external view returns (address);\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}