{
    "Function": "getBestStrategyWithdraw",
    "File": "contracts/v3/controllers/Controller.sol",
    "Parent Contracts": [
        "contracts/v3/interfaces/IController.sol"
    ],
    "High-Level Calls": [
        "SafeMath"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "sub"
    ],
    "Low-Level Calls": [],
    "Code": "function getBestStrategyWithdraw(\n        address _vault,\n        uint256 _amount\n    )\n        internal\n        view\n        returns (\n            address[] memory _strategies,\n            uint256[] memory _amounts\n        )\n    {\n        // get the length of strategies for a single token\n        uint256 k = _vaultDetails[_vault].strategies.length;\n        // initialize fixed-length memory arrays\n        _strategies = new address[](k);\n        _amounts = new uint256[](k);\n        address _strategy;\n        uint256 _balance;\n        // scan forward from the the beginning of strategies\n        for (uint i = 0; i < k; i++) {\n            _strategy = _vaultDetails[_vault].strategies[i];\n            _strategies[i] = _strategy;\n            // get the balance of the strategy\n            _balance = _vaultDetails[_vault].balances[_strategy];\n            // if the strategy doesn't have the balance to cover the withdraw\n            if (_balance < _amount) {\n                // withdraw what we can and add to the _amounts\n                _amounts[i] = _balance;\n                _amount = _amount.sub(_balance);\n            } else {\n                // stop scanning if the balance is more than the withdraw amount\n                _amounts[i] = _amount;\n                break;\n            }\n        }\n    }"
}