File size: 26,747 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
43
44
45
46
47
48
49
50
51
52
53
54
{
  "language": "Solidity",
  "sources": {
    "contracts/S3ETHAaveVesperFinanceDAI.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IWETH.sol\";\nimport \"./interfaces/IUniswapConnector.sol\";\nimport \"./interfaces/IAave.sol\";\nimport \"./interfaces/IS3Proxy.sol\";\nimport \"./interfaces/IS3Admin.sol\";\nimport \"./proxies/S3ETHAaveVesperFinanceDAIProxy.sol\";\n\n\ninterface IFees {\n    function feeCollector(uint256 _index) external view returns (address);\n    function depositStatus(uint256 _index) external view returns (bool);\n    function calcFee(\n        uint256 _strategyId,\n        address _user,\n        address _feeToken\n    ) external view returns (uint256);\n}\n\n\ncontract S3ETHAaveVesperFinanceDAI {\n    uint8 public constant strategyIndex = 11;\n    address public s3Admin;\n    address public feesAddress;\n    address public uniswapConnector;\n    address public wethAddress;\n    address public daiAddress;\n    \n    // protocols\n    address public vPoolDAI;\n    address public vPoolRewardsDAI;\n    address public vspToken;\n    mapping(address => address) public depositors; \n\n    constructor(\n        address _s3Admin,\n        address _feesAddress,\n        address _uniswapConnector,\n        address _wethAddress,\n        address _daiAddress,\n        address _vPoolDAI,\n        address _vPoolRewardsDAI,\n        address _vspToken\n    ) {\n        s3Admin = _s3Admin;\n        feesAddress = _feesAddress;\n        uniswapConnector = _uniswapConnector;\n        wethAddress = _wethAddress;\n        daiAddress = _daiAddress;\n        vPoolDAI = _vPoolDAI;\n        vPoolRewardsDAI = _vPoolRewardsDAI;\n        vspToken = _vspToken;\n\n        IERC20(daiAddress).approve(uniswapConnector, 2**256 - 1);\n        IERC20(vspToken).approve(uniswapConnector, 2**256 - 1);\n    }\n\n    event Deposit(address indexed _depositor, address indexed _token, uint256 _amountIn);\n\n    event Withdraw(address indexed _depositor, uint8 _percentage, uint256 _amount, uint256 _fee);\n\n    event WithdrawCollateral(address indexed _depositor, uint8 _percentage, uint256 _amount, uint256 _fee);\n\n    event ClaimAdditionalTokens(address indexed _depositor, uint256 _amount0, uint256 _amount1, address indexed _swappedTo);\n\n    // Get the current unclaimed VSP tokens amount\n    function getPendingAdditionalTokenClaims(address _address) external view returns(address[] memory _rewardTokens, uint256[] memory _claimableAmounts) {\n        return IVPoolRewards(vPoolRewardsDAI).claimable(depositors[_address]);\n    }   \n    \n    // Get the current Vesper Finance deposit\n    function getCurrentDeposit(address _address) external view returns(uint256, uint256) {\n        uint256 vaDAIShare = IERC20(vPoolDAI).balanceOf(depositors[_address]);\n        uint256 daiEquivalent;\n        if (vaDAIShare > 0) {\n            uint256 pricePerShare = IVPoolDAI(vPoolDAI).pricePerShare();\n            daiEquivalent = (pricePerShare * vaDAIShare) / 10 ** 18;\n        }\n        \n        return (vaDAIShare, daiEquivalent);\n    }\n\n    function getCurrentDebt(address _address) external view returns(uint256) {\n        return IERC20(IS3Admin(s3Admin).interestTokens(strategyIndex)).balanceOf(depositors[_address]);\n    }\n\n    function getMaxUnlockedCollateral(address _address) external view returns(uint256) {\n        (, uint256 totalDebtETH, , uint256 currentLiquidationThreshold, , ) = IAave(IS3Admin(s3Admin).aave()).getUserAccountData(depositors[_address]);\n        uint256 maxAmountToBeWithdrawn;\n        if (totalDebtETH > 0) {\n            maxAmountToBeWithdrawn = (10100 * totalDebtETH) / currentLiquidationThreshold;\n            maxAmountToBeWithdrawn = IERC20(IS3Admin(s3Admin).aWETH()).balanceOf(depositors[_address]) - maxAmountToBeWithdrawn;\n        } else {\n            maxAmountToBeWithdrawn = IERC20(IS3Admin(s3Admin).aWETH()).balanceOf(depositors[_address]); \n        }\n        return maxAmountToBeWithdrawn;\n    }\n\n    // Get the current Aave status\n    function getAaveStatus(address _address) external view returns(uint256, uint256, uint256, uint256, uint256, uint256) {\n        return IAave(IS3Admin(s3Admin).aave()).getUserAccountData(depositors[_address]); \n    }\n\n    function depositETH(uint8 _borrowPercentage, bool _borrowAndDeposit) public payable {\n        require(IFees(feesAddress).depositStatus(strategyIndex), \"ERR: DEPOSITS_STOPPED\");\n        if (_borrowAndDeposit) {\n            require(IS3Admin(s3Admin).whitelistedAaveBorrowPercAmounts(_borrowPercentage), \"ERROR: INVALID_BORROW_PERC\");\n        }\n\n        if (depositors[msg.sender] == address(0)) { \n            // deploy new proxy contract\n            S3ETHAaveVesperFinanceDAIProxy s3proxy = new S3ETHAaveVesperFinanceDAIProxy(\n                address(this),\n                uniswapConnector,\n                wethAddress,\n                daiAddress,\n                vPoolDAI, \n                vPoolRewardsDAI,\n                vspToken,\n                IS3Admin(s3Admin).aave(),\n                IS3Admin(s3Admin).aaveEth(),\n                IS3Admin(s3Admin).aWETH()\n            );\n            s3proxy.setupAddresses(\n                IS3Admin(s3Admin).aavePriceOracle(),\n                IS3Admin(s3Admin).interestTokens(strategyIndex),\n                s3Admin\n            );\n            depositors[msg.sender] = address(s3proxy);\n            s3proxy.depositETH{value: msg.value}(_borrowPercentage, _borrowAndDeposit);\n        } else {\n            // send the deposit to the existing proxy contract\n            IS3Proxy(depositors[msg.sender]).depositETH{value: msg.value}(_borrowPercentage, _borrowAndDeposit); \n        }\n\n        emit Deposit(msg.sender, wethAddress, msg.value);\n    }\n\n    // claim VSP tokens and withdraw them\n    function claimRaw() external {\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\");\n        uint256 truTokens = IS3Proxy(depositors[msg.sender]).claimToDepositor(msg.sender); \n\n        emit ClaimAdditionalTokens(msg.sender, truTokens, 0, address(0));\n    }\n\n    // claim VSP tokens, swap them for ETH and withdraw\n    function claimInETH(uint256 _amountOutMin) external {\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\");\n        uint256 vspTokens = IS3Proxy(depositors[msg.sender]).claimToDeployer();\n\n        uint256 wethAmount = IUniswapConnector(uniswapConnector).swapTokenForToken(\n            vspToken,\n            wethAddress,\n            vspTokens,\n            _amountOutMin,\n            address(this)\n        );\n\n        // swap WETH for ETH\n        IWETH(wethAddress).withdraw(wethAmount);\n        // withdraw ETH\n        (bool success, ) = payable(msg.sender).call{value: wethAmount}(\"\");\n        require(success, \"ERR: FAIL_SENDING_ETH\");\n\n        emit ClaimAdditionalTokens(msg.sender, vspTokens, wethAmount, wethAddress);\n    }\n\n    // claim VSP tokens, swap them for _token and withdraw\n    function claimInToken(address _token, uint256 _amountOutMin) external {\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\"); \n\n        uint256 vspTokens = IS3Proxy(depositors[msg.sender]).claimToDeployer();\n        uint256 tokenAmount = IUniswapConnector(uniswapConnector).swapTokenForToken(\n            vspToken, \n            _token,\n            vspTokens, \n            _amountOutMin, \n            msg.sender\n        );\n\n        emit ClaimAdditionalTokens(msg.sender, vspTokens, tokenAmount, _token);\n    } \n\n    function withdraw(uint8 _percentage, address _feeToken) external {\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\"); \n\n        (uint256 ethAmountToBeWithdrawn, uint256 amountOut) = IS3Proxy(depositors[msg.sender]).withdraw(_percentage); \n        if (amountOut > 0) {\n            ethAmountToBeWithdrawn += _swapYieldProfitTo(depositors[msg.sender], amountOut);\n        }\n        \n        uint256 fee = (ethAmountToBeWithdrawn * IFees(feesAddress).calcFee(strategyIndex, msg.sender, _feeToken)) / 1000;\n        if (fee > 0) {\n            (bool success0, ) = payable(IFees(feesAddress).feeCollector(strategyIndex)).call{value: fee}(\"\");\n            require(success0, \"ERR: FAIL_SENDING_FEE_ETH\");\n        }\n        (bool success1, ) = payable(msg.sender).call{value: ethAmountToBeWithdrawn - fee}(\"\");\n        require(success1, \"ERR: FAIL_SENDING_FEE_ETH\");\n\n        emit Withdraw(msg.sender, _percentage, ethAmountToBeWithdrawn, fee);\n    }\n\n    function withdrawCollateral(uint8 _percentage, address _feeToken) external {\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\");\n\n        (uint256 ethAmountToBeWithdrawn, ) = IS3Proxy(depositors[msg.sender]).withdrawCollateral(_percentage);\n        uint256 fee = (ethAmountToBeWithdrawn * IFees(feesAddress).calcFee(strategyIndex, msg.sender, _feeToken)) / 1000;\n        if (fee > 0) {\n            (bool success0, ) = payable(IFees(feesAddress).feeCollector(strategyIndex)).call{value: fee}(\"\");\n            require(success0, \"ERR: FAIL_SENDING_FEE_ETH\");\n        }\n        (bool success1, ) = payable(msg.sender).call{value: ethAmountToBeWithdrawn - fee}(\"\");\n        require(success1, \"ERR: FAIL_SENDING_ETH\");\n\n        emit WithdrawCollateral(msg.sender, _percentage, ethAmountToBeWithdrawn, fee);\n    }\n\n    function emergencyWithdraw(address _token) external {\n        require(!IFees(feesAddress).depositStatus(strategyIndex), \"ERR: DEPOSITS_ARE_ON\");\n        require(depositors[msg.sender] != address(0), \"ERR: INVALID_DEPOSITOR\");\n\n        IS3Proxy(depositors[msg.sender]).emergencyWithdraw(_token, msg.sender);\n    }\n\n    function _swapYieldProfitTo(address _proxy, uint256 _amountOutMin) private returns(uint256) {\n        if (IERC20(daiAddress).balanceOf(_proxy) > 0) {\n            IERC20(daiAddress).transferFrom(_proxy, address(this), IERC20(daiAddress).balanceOf(_proxy));\n\n            uint256 wethAmount = IUniswapConnector(uniswapConnector).swapTokenForToken(\n                daiAddress, \n                wethAddress,\n                IERC20(daiAddress).balanceOf(address(this)), \n                _amountOutMin, \n                address(this)\n            );\n\n            // swap WETH for ETH\n            IWETH(wethAddress).withdraw(wethAmount);\n\n            return wethAmount;\n        } else {\n            return 0;\n        } \n    }\n\n    receive() external payable {} \n}\n\n// MN bby ¯\\_(ツ)_/¯"
    },
    "contracts/interfaces/IERC20.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IERC20 {\n    function decimals() external view returns (uint8);\n\n    function balanceOf(address _owner) external view returns (uint256);\n\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    function approve(address spender, uint256 amount) external;\n\n    function transfer(address recipient, uint256 amount) external;\n\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) external;\n}"
    },
    "contracts/interfaces/IWETH.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IWETH {\n    function withdraw(uint wad) external;\n}"
    },
    "contracts/interfaces/IUniswapConnector.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IUniswapConnector {\n    function getTokenFee(address _token) external view returns(uint24);\n\n    function uniswapV3Router02() external view returns (address);\n\n    function swapTokenForToken(address _tokenIn, address _tokenOut, uint256 _amount, uint256 _amountOutMin, address _to) external returns(uint256);\n\n    function swapTokenForTokenV3ExactOutput(address _tokenIn, address _tokenOut, uint256 _amount, uint256 _amountInMaximum, address _to) external payable returns(uint256);\n    \n    function swapETHForToken(address _tokenOut, uint256 _amount, uint256 _amountOutMin, address _to) external payable returns(uint256);\n}"
    },
    "contracts/interfaces/IAave.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IAave {\n    function deposit(\n        address asset, \n        uint256 amount, \n        address onBehalfOf, \n        uint16 referralCode\n    ) external;\n\n    function withdraw(\n        address asset,\n        uint256 amount, \n        address to\n    ) external returns (uint256);\n\n    function borrow(\n        address asset,\n        uint256 amount,\n        uint256 interestRateMode,\n        uint16 referralCode,\n        address onBehalfOf\n    ) external;\n\n    function swapBorrowRateMode(address asset, uint256 rateMode) external;\n\n    function repay(\n        address asset,\n        uint256 amount,\n        uint256 rateMode,\n        address onBehalfOf\n    ) external returns (uint256);\n\n    function getUserAccountData(address user) external view returns (\n        uint256 totalCollateralETH,\n        uint256 totalDebtETH,\n        uint256 availableBorrowsETH,\n        uint256 currentLiquidationThreshold,\n        uint256 ltv,\n        uint256 healthFactor\n    );\n}\n\ninterface IAaveETH {\n    function depositETH(\n        address lendingPool,\n        address onBehalfOf,\n        uint16 referralCode\n    ) external payable;\n\n    function withdrawETH(\n        address lendingPool,\n        uint256 amount,\n        address to\n    ) external;\n}\n\ninterface IPriceOracleGetter {\n    function getAssetPrice(address asset) external view returns (uint256);\n}"
    },
    "contracts/interfaces/IS3Proxy.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IS3Proxy {\n    function depositETH(uint8 _borrowPercentage, bool _borrowAndDeposit) external payable;\n\n    function deposit(address _token, uint256 _amount, uint8 _borrowPercentage, bool _borrowAndDeposit) external;\n\n    function withdraw(uint8 _percentage) external returns(uint256, uint256);\n\n    function withdrawCollateral(uint8 _percentage) external returns(uint256, uint256);\n\n    function emergencyWithdraw(address _token, address _depositor) external;\n\n    function claimToDepositor(address _depositor) external returns(uint256);\n\n    function claimToDeployer() external returns(uint256);\n\n    function setupAddresses(\n        address _aavePriceOracle,\n        address _aaveInterestDAI,\n        address _s3Admin\n    ) external;\n}"
    },
    "contracts/proxies/S3ETHAaveVesperFinanceDAIProxy.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\nimport \"../interfaces/IS3Admin.sol\";\nimport \"../interfaces/IERC20.sol\";\nimport \"../interfaces/IAave.sol\";\nimport \"../interfaces/IVesperFinance.sol\";\nimport \"../interfaces/IQuoter.sol\";\nimport \"../interfaces/IUniswapConnector.sol\";\n\n\ncontract S3ETHAaveVesperFinanceDAIProxy {\n    uint8 private constant defaultInterestRate = 2;\n    address private quoterAddress = 0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6;\n    address private deployer;\n    address private uniswapConnector;\n    address private wethAddress;\n    address private daiAddress;\n    address private vPoolDAI;\n    address private vPoolRewardsDAI;\n    address private vspToken;\n    address private aave;\n    address private aaveEth;\n    address private aavePriceOracle;\n    address private aWETH;\n    address private aaveInterestDAI;\n    address private s3Admin;\n\n    constructor(\n        address _deployer,\n        address _uniswapConnector,\n        address _wethAddress,\n        address _daiAddress,\n        address _vPoolDAI,\n        address _vPoolRewardsDAI,\n        address _vspToken,\n        address _aave,\n        address _aaveEth,\n        address _aWETH\n    ) {\n        deployer = _deployer;\n        uniswapConnector = _uniswapConnector;\n        wethAddress = _wethAddress;\n        daiAddress = _daiAddress;\n        vPoolDAI = _vPoolDAI;\n        vPoolRewardsDAI = _vPoolRewardsDAI;\n        vspToken = _vspToken;\n        aave = _aave;\n        aaveEth = _aaveEth;\n        aWETH = _aWETH;\n\n        // Allow for ETH collateral withdrawals\n        IERC20(aWETH).approve(aaveEth, 2**256 - 1);\n        // Give Aave lending protocol approval - needed when repaying the DAI loan\n        IERC20(daiAddress).approve(aave, 2**256 - 1);\n        // Give S3AaveVesperFinanceDAI DAI approval - needed when sending the DAI rewards to the depositor\n        IERC20(daiAddress).approve(deployer, 2**256 - 1);\n        // Allow Vesper Finance protocol to take DAI from the proxy\n        IERC20(daiAddress).approve(vPoolDAI, 2**256 - 1);\n    }\n\n    modifier onlyDeployer() {\n        require(msg.sender == deployer, \"ERR: WRONG_DEPLOYER\");\n        _;\n    }\n\n    function setupAddresses(\n        address _aavePriceOracle,\n        address _aaveInterestDAI,\n        address _s3Admin\n    ) external onlyDeployer {\n        aavePriceOracle = _aavePriceOracle;\n        aaveInterestDAI = _aaveInterestDAI;\n        s3Admin = _s3Admin;\n    }\n\n    function depositETH(uint8 _borrowPercentage, bool _borrowAndDeposit) external payable onlyDeployer {\n        (, , uint256 availableBorrowsETH, , ,) = IAave(aave).getUserAccountData(address(this));\n\n        // supply to Aave protocol\n        IAaveETH(aaveEth).depositETH{value: msg.value}(aave, address(this), 0); \n\n        // Aave borrow & TrueFi deposit\n        if (_borrowAndDeposit) {\n            (, , uint256 availableBorrowsETHAfterDeposit, , ,) = IAave(aave).getUserAccountData(address(this));\n            // borrow DAI from Aave protocol\n            uint256 maxAmountToBeBorrowedForThisDeposit = ((availableBorrowsETHAfterDeposit - availableBorrowsETH) * 10 ** IERC20(daiAddress).decimals()) / IPriceOracleGetter(aavePriceOracle).getAssetPrice(daiAddress); \n            IAave(aave).borrow(\n                daiAddress,\n                (maxAmountToBeBorrowedForThisDeposit * _borrowPercentage) / 100,\n                defaultInterestRate,\n                0,\n                address(this)\n            );\n\n            // Vesper Finance deposit\n            IVPoolDAI(vPoolDAI).deposit(IERC20(daiAddress).balanceOf(address(this)));\n        }\n    }\n\n    function withdraw(uint8 _percentage) external onlyDeployer returns(uint256, uint256) {\n        IVPoolDAI(vPoolDAI).withdraw((IERC20(vPoolDAI).balanceOf(address(this)) * _percentage) / 100);\n\n        // repay the DAI loan to Aave protocol\n        uint256 currentDebt = IERC20(aaveInterestDAI).balanceOf(address(this));\n        uint256 borrowAssetBalance = IERC20(daiAddress).balanceOf(address(this));\n        uint256 currentDebtAfterRepaying;\n        if (borrowAssetBalance > (currentDebt * _percentage) / 100) {\n            // full repay\n            _aaveRepay((currentDebt * _percentage) / 100, address(this));\n        } else {\n            // partly repay\n            _aaveRepay(borrowAssetBalance, address(this));\n            currentDebtAfterRepaying = (currentDebt * _percentage) / 100 - borrowAssetBalance;\n        }\n\n        return _withdrawCollateral(\n            _percentage,\n            currentDebtAfterRepaying\n        );\n    }\n\n    function withdrawCollateral(uint8 _percentage) external onlyDeployer returns(uint256, uint256) {\n        return _withdrawCollateral(_percentage, 0);\n    }\n\n    function _withdrawCollateral(uint8 _percentage, uint256 _currentDebtAfterRepaying) private returns(uint256, uint256) {\n        uint256 maxAmountToBeWithdrawn = _calculateMaxAmountToBeWithdrawn();\n        if (_percentage != 100) {\n            maxAmountToBeWithdrawn = (maxAmountToBeWithdrawn * _percentage) / 100;\n        }\n\n        // if there is debt sell part of the collateral to cover it\n        if (_currentDebtAfterRepaying > 0) {\n            _aaveWithdraw(maxAmountToBeWithdrawn, address(this));\n\n            uint256 amountIn = IQuoter(quoterAddress).quoteExactOutput(\n                abi.encodePacked(daiAddress, IUniswapConnector(uniswapConnector).getTokenFee(daiAddress), wethAddress), \n                _currentDebtAfterRepaying\n            );\n            amountIn = (amountIn * (100 + IS3Admin(s3Admin).slippage())) / 100;\n            \n            IUniswapConnector(uniswapConnector).swapTokenForTokenV3ExactOutput{value: amountIn}(\n                wethAddress, \n                daiAddress,\n                _currentDebtAfterRepaying,\n                amountIn,\n                address(this)\n            );\n\n            uint256 maxAmountToBeWithdrawnBeforeRepay = _calculateMaxAmountToBeWithdrawn();\n            _aaveRepay(IERC20(daiAddress).balanceOf(address(this)), address(this));\n            uint256 maxAmountToBeWithdrawnAfterRepay = _calculateMaxAmountToBeWithdrawn();\n\n            // withdraw rest of the unlocked collateral after repaying the loan\n            _aaveWithdraw(maxAmountToBeWithdrawnAfterRepay - maxAmountToBeWithdrawnBeforeRepay, address(this));\n            uint256 currentEthBalance = address(this).balance;\n            payable(deployer).transfer(currentEthBalance);\n\n            return (currentEthBalance, 0);\n        } else {\n            uint256 amountOut;\n            uint256 currentDAIBalance = IERC20(daiAddress).balanceOf(address(this));\n            if (currentDAIBalance > 0) {\n                amountOut = IQuoter(quoterAddress).quoteExactInput(\n                    abi.encodePacked(daiAddress, IUniswapConnector(uniswapConnector).getTokenFee(daiAddress), wethAddress), \n                    currentDAIBalance\n                );\n                amountOut = (amountOut * (100 - IS3Admin(s3Admin).slippage())) / 100;\n            }\n                \n            _aaveWithdraw(maxAmountToBeWithdrawn, deployer);\n            return (maxAmountToBeWithdrawn, amountOut);\n        }\n    }\n\n    function emergencyWithdraw(address _token, address _depositor) external onlyDeployer {\n        IERC20(_token).transfer(_depositor, IERC20(_token).balanceOf(address(this)));\n    }\n\n    function _calculateMaxAmountToBeWithdrawn() private view returns(uint256) {\n        (, uint256 totalDebtETH, , uint256 currentLiquidationThreshold, , ) = IAave(aave).getUserAccountData(address(this));\n        uint256 maxAmountToBeWithdrawn;\n        if (totalDebtETH > 0) {\n            maxAmountToBeWithdrawn = (10100 * totalDebtETH) / currentLiquidationThreshold;\n            maxAmountToBeWithdrawn = IERC20(aWETH).balanceOf(address(this)) - maxAmountToBeWithdrawn;\n        } else {\n            maxAmountToBeWithdrawn = IERC20(aWETH).balanceOf(address(this)); \n        }\n\n        return maxAmountToBeWithdrawn;\n    }\n\n    function _aaveRepay(uint256 _amount, address _to) private {\n        IAave(aave).repay(\n            daiAddress, \n            _amount,\n            defaultInterestRate, \n            _to\n        );\n    }\n\n    function _aaveWithdraw(uint256 _amount, address _to) private {\n        IAaveETH(aaveEth).withdrawETH(\n            aave,\n            _amount, \n            _to\n        );\n    }\n\n    function claimToDepositor(address _depositor) external onlyDeployer returns(uint256) {\n        return _claim(_depositor);\n    }\n\n    function claimToDeployer() external onlyDeployer returns(uint256) {\n        return _claim(deployer);\n    }\n\n    function _claim(address _address) private returns(uint256) {\n        // VSP tokens\n        IVPoolRewards(vPoolRewardsDAI).claimReward(address(this));\n\n        uint256 vspBalance = IERC20(vspToken).balanceOf(address(this));\n        IERC20(vspToken).transfer(\n            _address,\n            vspBalance\n        );\n\n        return vspBalance;\n    }\n\n    receive() external payable {} \n    fallback() external payable {}\n}\n\n// MN bby ¯\\_(ツ)_/¯ "
    },
    "contracts/interfaces/IS3Admin.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\n\ninterface IS3Admin {\n    function interestTokens(uint8 _strategyIndex) external view returns (address);\n    function whitelistedAaveBorrowPercAmounts(uint8 _amount) external view returns (bool);\n    function aave() external view returns (address);\n    function aaveEth() external view returns (address);\n    function aavePriceOracle() external view returns (address);\n    function aWETH() external view returns (address);\n    function slippage() external view returns (uint8);\n}"
    },
    "contracts/interfaces/IQuoter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IQuoter {\n    function quoteExactInputSingle(\n        address tokenIn,\n        address tokenOut,\n        uint24 fee,\n        uint256 amountIn,\n        uint160 sqrtPriceLimitX96\n    ) external returns (uint256 amountOut);\n\n    function quoteExactOutputSingle(\n        address tokenIn,\n        address tokenOut,\n        uint24 fee,\n        uint256 amountOut,\n        uint160 sqrtPriceLimitX96\n    ) external returns (uint256 amountIn);\n\n    function quoteExactInput(\n        bytes memory path,\n        uint256 amountIn\n    ) external returns (uint256 amountOut);\n\n    function quoteExactOutput(\n        bytes memory path,\n        uint256 amountOut\n    ) external returns (uint256 amountIn);\n}"
    },
    "contracts/interfaces/IVesperFinance.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.17;\n\ninterface IVPoolDAI {\n    function deposit(uint256 _amount) external;\n\n    function withdraw(uint256 _shares) external;\n\n    function pricePerShare() external view returns (uint256);\n}\n\n\ninterface IVPoolETH {\n    function deposit() external payable;\n\n    function withdrawETH(uint256 _shares) external;\n\n    function pricePerShare() external view returns (uint256);\n}\n\n\ninterface IVPoolRewards {\n    function claimable(address _account) external view returns (\n        address[] memory _rewardTokens,\n        uint256[] memory _claimableAmounts\n    );\n\n    function claimReward(address _account) external;\n}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}