{
    "Function": "withdraw",
    "File": "contracts/routers/FullRouter.sol",
    "Parent Contracts": [
        "contracts/routers/StrategyRouter.sol",
        "contracts/helpers/StrategyTypes.sol",
        "contracts/interfaces/IStrategyRouter.sol"
    ],
    "High-Level Calls": [
        "IStrategy",
        "StrategyLibrary",
        "SafeMath",
        "SafeMath",
        "IStrategy",
        "SafeMath",
        "SignedSafeMath"
    ],
    "Internal Calls": [
        "_startTempEstimateSession",
        "_getTempEstimate",
        "abi.decode()",
        "onlyController",
        "_deleverageForWithdraw",
        "_sellPath",
        "_estimateSellAmount",
        "_removeTempEstimate",
        "_getTempEstimate"
    ],
    "Library Calls": [
        "getExpectedTokenValue",
        "div",
        "sub",
        "sub",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function withdraw(address strategy, bytes calldata data)\n        external\n        override\n        onlyController\n    {\n        _startTempEstimateSession(strategy);\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        address[] memory strategyItems = IStrategy(strategy).items();\n        // Deleverage debt\n        _deleverageForWithdraw(strategy, strategyItems, estimates, total);\n        // Sell loop\n        for (uint256 i = 0; i < strategyItems.length; i++) {\n            int256 estimatedValue = estimates[i];\n            if (_getTempEstimate(strategy, strategyItems[i]) > 0) {\n                estimatedValue = _getTempEstimate(strategy, strategyItems[i]);\n                _removeTempEstimate(strategy, strategyItems[i]);\n            }\n            int256 expectedValue = StrategyLibrary.getExpectedTokenValue(total, strategy, strategyItems[i]);\n            if (estimatedValue > expectedValue) {\n                _sellPath(\n                    IStrategy(strategy).getTradeData(strategyItems[i]),\n                    _estimateSellAmount(strategy, strategyItems[i], uint256(estimatedValue.sub(expectedValue)), uint256(estimatedValue)),\n                    strategyItems[i],\n                    strategy\n                );\n            }\n        }\n    }"
}