{
    "Function": "withdraw",
    "File": "contracts/routers/LoopRouter.sol",
    "Parent Contracts": [
        "contracts/routers/StrategyRouter.sol",
        "contracts/helpers/StrategyTypes.sol",
        "contracts/interfaces/IStrategyRouter.sol"
    ],
    "High-Level Calls": [
        "SafeMath",
        "IStrategy",
        "SignedSafeMath",
        "SafeMath",
        "IStrategy",
        "StrategyLibrary",
        "SafeMath"
    ],
    "Internal Calls": [
        "_sellPath",
        "abi.decode()",
        "onlyController",
        "_estimateSellAmount"
    ],
    "Library Calls": [
        "sub",
        "getExpectedTokenValue",
        "div",
        "sub",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function withdraw(address strategy, bytes calldata data)\n        external\n        override\n        onlyController\n    {\n        (uint256 percentage, uint256 total, int256[] memory estimates) =\n            abi.decode(data, (uint256, uint256, int256[]));\n\n        uint256 expectedWeth = total.mul(percentage).div(10**18);\n        total = total.sub(expectedWeth);\n\n        // Sell loop\n        address[] memory strategyItems = IStrategy(strategy).items();\n        for (uint256 i = 0; i < strategyItems.length; i++) {\n            int256 estimatedValue = estimates[i];\n            int256 expectedValue = StrategyLibrary.getExpectedTokenValue(total, strategy, strategyItems[i]);\n            if (estimatedValue > expectedValue) {\n                TradeData memory tradeData = IStrategy(strategy).getTradeData(strategyItems[i]);\n                _sellPath(\n                    tradeData,\n                    _estimateSellAmount(strategy, strategyItems[i], uint256(estimatedValue.sub(expectedValue)), uint256(estimatedValue)),\n                    strategyItems[i],\n                    strategy\n                );\n            }\n        }\n    }"
}