{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/v3/controllers/LegacyController.sol",
    "Parent Contracts": [
        "contracts/v3/interfaces/ILegacyController.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract LegacyController is ILegacyController {\n    using SafeERC20 for IERC20;\n    using SafeMath for uint256;\n\n    uint256 public constant MAX = 10000;\n\n    IManager public immutable manager;\n    IERC20 public immutable token;\n    address public immutable metavault;\n\n    bool public investEnabled;\n    IVault public vault;\n    IConverter public converter;\n\n    event Earn(uint256 amount);\n    event Withdraw(uint256 amount);\n\n    /**\n     * @param _manager The vault manager contract\n     * @param _metavault The legacy MetaVault contract\n     */\n    constructor(\n        address _manager,\n        address _metavault\n    )\n        public\n    {\n        manager = IManager(_manager);\n        metavault = _metavault;\n        address _token = ILegacyVault(_metavault).want();\n        token = IERC20(_token);\n    }\n\n    /**\n     * @notice Sets the vault address\n     * @param _vault The v3 vault address\n     */\n    function setVault(\n        address _vault\n    )\n        external\n        onlyStrategist\n    {\n        IVault cachedVault = vault;\n        if (address(cachedVault) != address(0)) {\n            cachedVault.withdrawAll(address(token));\n            token.safeTransfer(metavault, token.balanceOf(address(this)));\n        }\n        vault = IVault(_vault);\n    }\n\n    /**\n     * @notice Sets the converter address\n     * @param _converter The address of the converter\n     */\n    function setConverter(\n        address _converter\n    )\n        external\n        onlyStrategist\n    {\n        converter = IConverter(_converter);\n    }\n\n    /**\n     * @notice Sets the investEnabled status flag\n     * @param _investEnabled Bool for enabling investment\n     */\n    function setInvestEnabled(\n        bool _investEnabled\n    )\n        external\n        onlyStrategist\n    {\n        investEnabled = _investEnabled;\n    }\n\n    /**\n     * @notice Recovers stuck tokens sent directly to this contract\n     * @dev This only allows the strategist to recover unsupported tokens\n     * @param _token The address of the token\n     * @param _receiver The address to receive the tokens\n     */\n    function recoverUnsupportedToken(\n        address _token,\n        address _receiver\n    )\n        external\n        onlyStrategist\n    {\n        require(_token != address(token), \"!_token\");\n        IERC20(_token).safeTransfer(_receiver, IERC20(_token).balanceOf(address(this)));\n    }\n\n    /**\n     * @notice Returns the balance of the given token on the vault\n     * @param _token The address of the token\n     */\n    function balanceOf(\n        address _token\n    )\n        external\n        view\n        onlyToken(_token)\n        returns (uint256)\n    {\n        return token.balanceOf(address(this))\n                    .add(IERC20(address(vault)).balanceOf(address(this)));\n    }\n\n    /**\n     * @notice Returns the withdraw fee for withdrawing the given token and amount\n     * @param _token The address of the token\n     * @param _amount The amount to withdraw\n     */\n    function withdrawFee(\n        address _token,\n        uint256 _amount\n    )\n        external\n        view\n        onlyToken(_token)\n        returns (uint256)\n    {\n        return manager.withdrawalProtectionFee().mul(_amount).div(MAX);\n    }\n\n    /**\n     * @notice Withdraws the amount from the v3 vault\n     * @param _amount The amount to withdraw\n     */\n    function withdraw(\n        address,\n        uint256 _amount\n    )\n        external\n        onlyEnabledVault\n        onlyMetaVault\n    {\n        uint256 _balance = token.balanceOf(address(this));\n        // happy path exits without calling back to the vault\n        if (_balance >= _amount) {\n            token.safeTransfer(metavault, _amount);\n            emit Withdraw(_amount);\n        } else {\n            uint256 _toWithdraw = _amount.sub(_balance);\n            IVault cachedVault = vault;\n            // convert to vault shares\n            address[] memory _tokens = cachedVault.getTokens();\n            require(_tokens.length > 0, \"!_tokens\");\n            // get the amount of the token that we would be withdrawing\n            uint256 _expected = converter.expected(address(token), _tokens[0], _toWithdraw);\n            uint256 _shares = _expected.mul(1e18).div(cachedVault.getPricePerFullShare());\n            cachedVault.withdraw(_shares, _tokens[0]);\n            _balance = IERC20(_tokens[0]).balanceOf(address(this));\n            IERC20(_tokens[0]).safeTransfer(address(converter), _balance);\n            // TODO: calculate expected\n            converter.convert(_tokens[0], address(token), _balance, 1);\n            emit Withdraw(token.balanceOf(address(this)));\n            token.safeTransfer(metavault, token.balanceOf(address(this)));\n        }\n    }\n\n    /**\n     * @notice Only emits the Earn event\n     * @dev This is a dummy function to allow the MetaVault to call\n     * @param _amount The amount to earn\n     */\n    function earn(\n        address,\n        uint256 _amount\n    )\n        external\n        onlyMetaVault\n    {\n        emit Earn(_amount);\n    }\n\n    /**\n     * @notice Deposits the given token to the v3 vault\n     * @param _toToken The address to convert to\n     * @param _expected The expected amount to deposit after conversion\n     */\n    function legacyDeposit(\n        address _toToken,\n        uint256 _expected\n    )\n        external\n        override\n        onlyEnabledConverter\n        onlyHarvester\n    {\n        if (_toToken != address(token)) {\n            uint256 _amount = token.balanceOf(address(this));\n            token.safeTransfer(address(converter), _amount);\n            converter.convert(address(token), _toToken, _amount, _expected);\n        }\n        IERC20(_toToken).safeApprove(address(vault), 0);\n        IERC20(_toToken).safeApprove(address(vault), type(uint256).max);\n        vault.deposit(_toToken, IERC20(_toToken).balanceOf(address(this)));\n    }\n\n    /**\n     * @notice Reverts if the converter is not set\n     */\n    modifier onlyEnabledConverter() {\n        require(address(converter) != address(0), \"!converter\");\n        _;\n    }\n\n    /**\n     * @notice Reverts if the vault is not set\n     */\n    modifier onlyEnabledVault() {\n        require(address(vault) != address(0), \"!vault\");\n        _;\n    }\n\n    /**\n     * @notice Reverts if the caller is not the harvester\n     */\n    modifier onlyHarvester() {\n        require(msg.sender == manager.harvester(), \"!harvester\");\n        _;\n    }\n\n    /**\n     * @notice Reverts if the caller is not the MetaVault\n     */\n    modifier onlyMetaVault() {\n        require(msg.sender == metavault, \"!metavault\");\n        _;\n    }\n\n    /**\n     * @notice Reverts if the caller is not the strategist\n     */\n    modifier onlyStrategist() {\n        require(msg.sender == manager.strategist(), \"!strategist\");\n        _;\n    }\n\n    /**\n     * @notice Reverts if the given token is not the stored token\n     */\n    modifier onlyToken(address _token) {\n        require(_token == address(token), \"!_token\");\n        _;\n    }\n}"
}