{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/v3/Harvester.sol",
    "Parent Contracts": [
        "contracts/v3/interfaces/IHarvester.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract Harvester is IHarvester {\n    using SafeMath for uint256;\n\n    uint256 public constant ONE_HUNDRED_PERCENT = 10000;\n\n    IManager public immutable override manager;\n    IController public immutable controller;\n    ILegacyController public immutable legacyController;\n\n    uint256 public slippage;\n\n    struct Strategy {\n        uint256 timeout;\n        uint256 lastCalled;\n        address[] addresses;\n    }\n\n    mapping(address => Strategy) public strategies;\n    mapping(address => bool) public isHarvester;\n\n    /**\n     * @notice Logged when harvest is called for a strategy\n     */\n    event Harvest(\n        address indexed controller,\n        address indexed strategy\n    );\n\n    /**\n     * @notice Logged when a harvester is set\n     */\n    event HarvesterSet(address indexed harvester, bool status);\n\n    /**\n     * @notice Logged when a strategy is added for a vault\n     */\n    event StrategyAdded(address indexed vault, address indexed strategy, uint256 timeout);\n\n    /**\n     * @notice Logged when a strategy is removed for a vault\n     */\n    event StrategyRemoved(address indexed vault, address indexed strategy, uint256 timeout);\n\n    /**\n     * @param _manager The address of the yAxisMetaVaultManager contract\n     * @param _controller The address of the controller\n     */\n    constructor(\n        address _manager,\n        address _controller,\n        address _legacyController\n    )\n        public\n    {\n        manager = IManager(_manager);\n        controller = IController(_controller);\n        legacyController = ILegacyController(_legacyController);\n    }\n\n    /**\n     * (GOVERNANCE|STRATEGIST)-ONLY FUNCTIONS\n     */\n\n    /**\n     * @notice Adds a strategy to the rotation for a given vault and sets a timeout\n     * @param _vault The address of the vault\n     * @param _strategy The address of the strategy\n     * @param _timeout The timeout between harvests\n     */\n    function addStrategy(\n        address _vault,\n        address _strategy,\n        uint256 _timeout\n    )\n        external\n        override\n        onlyController\n    {\n        strategies[_vault].addresses.push(_strategy);\n        strategies[_vault].timeout = _timeout;\n        emit StrategyAdded(_vault, _strategy, _timeout);\n    }\n\n    /**\n     * @notice Removes a strategy from the rotation for a given vault and sets a timeout\n     * @param _vault The address of the vault\n     * @param _strategy The address of the strategy\n     * @param _timeout The timeout between harvests\n     */\n    function removeStrategy(\n        address _vault,\n        address _strategy,\n        uint256 _timeout\n    )\n        external\n        override\n        onlyController\n    {\n        uint256 tail = strategies[_vault].addresses.length;\n        uint256 index;\n        bool found;\n        for (uint i; i < tail; i++) {\n            if (strategies[_vault].addresses[i] == _strategy) {\n                index = i;\n                found = true;\n                break;\n            }\n        }\n\n        if (found) {\n            strategies[_vault].addresses[index] = strategies[_vault].addresses[tail.sub(1)];\n            strategies[_vault].addresses.pop();\n            strategies[_vault].timeout = _timeout;\n            emit StrategyRemoved(_vault, _strategy, _timeout);\n        }\n    }\n\n    /**\n     * @notice Sets the status of a harvester address to be able to call harvest functions\n     * @param _harvester The address of the harvester\n     * @param _status The status to allow the harvester to harvest\n     */\n    function setHarvester(\n        address _harvester,\n        bool _status\n    )\n        external\n        onlyStrategist\n    {\n        isHarvester[_harvester] = _status;\n        emit HarvesterSet(_harvester, _status);\n    }\n\n    function setSlippage(\n        uint256 _slippage\n    )\n        external\n        onlyStrategist\n    {\n        require(_slippage < ONE_HUNDRED_PERCENT, \"!_slippage\");\n        slippage = _slippage;\n    }\n\n    /**\n     * HARVESTER-ONLY FUNCTIONS\n     */\n\n    function earn(\n        address _strategy,\n        address _vault\n    )\n        external\n        onlyHarvester\n    {\n        IVault(_vault).earn(_strategy);\n    }\n\n    /**\n     * @notice Harvests a given strategy on the provided controller\n     * @dev This function ignores the timeout\n     * @param _controller The address of the controller\n     * @param _strategy The address of the strategy\n     */\n    function harvest(\n        IController _controller,\n        address _strategy,\n        uint256 _estimatedWETH,\n        uint256 _estimatedYAXIS\n    )\n        public\n        onlyHarvester\n    {\n        _controller.harvestStrategy(_strategy, _estimatedWETH, _estimatedYAXIS);\n        emit Harvest(address(_controller), _strategy);\n    }\n\n    /**\n     * @notice Harvests the next available strategy for a given vault and\n     * rotates the strategies\n     * @param _vault The address of the vault\n     */\n    function harvestNextStrategy(\n        address _vault,\n        uint256 _estimatedWETH,\n        uint256 _estimatedYAXIS\n    )\n        external\n    {\n        require(canHarvest(_vault), \"!canHarvest\");\n        address strategy = strategies[_vault].addresses[0];\n        harvest(controller, strategy, _estimatedWETH, _estimatedYAXIS);\n        uint256 k = strategies[_vault].addresses.length;\n        if (k > 1) {\n            address[] memory _strategies = new address[](k);\n            for (uint i; i < k-1; i++) {\n                _strategies[i] = strategies[_vault].addresses[i+1];\n            }\n            _strategies[k-1] = strategy;\n            strategies[_vault].addresses = _strategies;\n        }\n        // solhint-disable-next-line not-rely-on-time\n        strategies[_vault].lastCalled = block.timestamp;\n    }\n\n    /**\n     * @notice Earns tokens in the LegacyController to the v3 vault\n     * @param _expected The expected amount to deposit after conversion\n     */\n    function legacyEarn(\n        uint256 _expected\n    )\n        external\n        onlyHarvester\n    {\n        legacyController.legacyDeposit(_expected);\n    }\n\n    /**\n     * EXTERNAL VIEW FUNCTIONS\n     */\n\n    /**\n     * @notice Returns the addresses of the strategies for a given vault\n     * @param _vault The address of the vault\n     */\n    function strategyAddresses(\n        address _vault\n    )\n        external\n        view\n        returns (address[] memory)\n    {\n        return strategies[_vault].addresses;\n    }\n\n    /**\n     * PUBLIC VIEW FUNCTIONS\n     */\n\n    /**\n     * @notice Returns the availability of a vault's strategy to be harvested\n     * @param _vault The address of the vault\n     */\n    function canHarvest(\n        address _vault\n    )\n        public\n        view\n        returns (bool)\n    {\n        Strategy storage strategy = strategies[_vault];\n        // only can harvest if there are strategies, and when sufficient time has elapsed\n        // solhint-disable-next-line not-rely-on-time\n        return (strategy.addresses.length > 0 && strategy.lastCalled <= block.timestamp.sub(strategy.timeout));\n    }\n\n    /**\n     * @notice Returns the estimated amount of WETH and YAXIS for the given strategy\n     * @param _strategy The address of the strategy\n     */\n    function getEstimates(\n        address _strategy\n    )\n        public\n        view\n        returns (uint256 _estimatedWETH, uint256 _estimatedYAXIS)\n    {\n        ISwap _router = IStrategy(_strategy).router();\n        address[] memory _path;\n        _path[0] = IStrategy(_strategy).want();\n        _path[1] = IStrategy(_strategy).weth();\n        uint256[] memory _amounts = _router.getAmountsOut(\n            IStrategy(_strategy).balanceOfPool(),\n            _path\n        );\n        _estimatedWETH = _amounts[1];\n        uint256 _slippage = slippage;\n        if (_slippage > 0) {\n            _estimatedWETH = _estimatedWETH.mul(_slippage).div(ONE_HUNDRED_PERCENT);\n        }\n        _path[0] = manager.yaxis();\n        uint256 _fee = _estimatedWETH.mul(manager.treasuryFee()).div(ONE_HUNDRED_PERCENT);\n        _amounts = _router.getAmountsOut(_fee, _path);\n        _estimatedYAXIS = _amounts[1];\n        if (_slippage > 0) {\n            _estimatedYAXIS = _estimatedYAXIS.mul(_slippage).div(ONE_HUNDRED_PERCENT);\n        }\n    }\n\n    /**\n     * MODIFIERS\n     */\n\n    modifier onlyController() {\n        require(manager.allowedControllers(msg.sender), \"!controller\");\n        _;\n    }\n\n    modifier onlyHarvester() {\n        require(isHarvester[msg.sender], \"!harvester\");\n        _;\n    }\n\n    modifier onlyStrategist() {\n        require(msg.sender == manager.strategist(), \"!strategist\");\n        _;\n    }\n}"
}