{
    "Function": "_batchBuy",
    "File": "contracts/routers/FullRouter.sol",
    "Parent Contracts": [
        "contracts/routers/StrategyRouter.sol",
        "contracts/helpers/StrategyTypes.sol",
        "contracts/interfaces/IStrategyRouter.sol"
    ],
    "High-Level Calls": [
        "IStrategy",
        "IERC20",
        "SafeMath",
        "StrategyLibrary",
        "IERC20",
        "SafeERC20",
        "IERC20",
        "SafeMath",
        "SafeMath",
        "StrategyLibrary",
        "IStrategy",
        "SafeERC20"
    ],
    "Internal Calls": [
        "_buyToken",
        "_batchBuySynths",
        "_buyToken",
        "_borrowToken"
    ],
    "Library Calls": [
        "getExpectedTokenValue",
        "sub",
        "div",
        "safeTransfer",
        "getExpectedTokenValue",
        "safeTransferFrom",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function _batchBuy(\n        address strategy,\n        address from,\n        uint256 total,\n        int256[] memory estimates,\n        address[] memory strategyItems,\n        address[] memory strategyDebt\n    ) internal {\n        for (uint256 i = 0; i < strategyItems.length; i++) {\n            address strategyItem = strategyItems[i];\n            _buyToken(\n                strategy,\n                from,\n                strategyItem,\n                estimates[i],\n                StrategyLibrary.getExpectedTokenValue(total, strategy, strategyItem)\n            );\n        }\n        if (IStrategy(strategy).supportsSynths()) {\n            // Purchase SUSD\n            uint256 susdBalanceBefore = from == strategy ? 0 : IERC20(susd).balanceOf(strategy); // If from strategy it is rebalance or restructure, we want to use all SUSD\n            _buyToken(\n                strategy,\n                from,\n                susd,\n                estimates[estimates.length - 1],\n                StrategyLibrary.getExpectedTokenValue(total, strategy, address(-1))\n            );\n            uint256 susdBalanceAfter = IERC20(susd).balanceOf(strategy);\n            _batchBuySynths(strategy, susdBalanceAfter.sub(susdBalanceBefore));\n        }\n        for (uint256 i = 0; i < strategyDebt.length; i++) {\n            _borrowToken(\n                strategy,\n                strategyDebt[i],\n                total,\n                estimates[strategyItems.length + i]\n            );\n        }\n        int256 percentage = IStrategy(strategy).getPercentage(weth);\n        if (percentage > 0 && from != strategy) {\n            if (from == address(this)) {\n              // Send all WETH\n              IERC20(weth).safeTransfer(strategy, IERC20(weth).balanceOf(from));\n            } else {\n              // Calculate remaining WETH\n              // Since from is not address(this), we know this is a deposit, so estimated value not relevant\n              uint256 amount =\n                  total.mul(uint256(percentage))\n                       .div(DIVISOR);\n              IERC20(weth).safeTransferFrom(\n                  from,\n                  strategy,\n                  amount\n              );\n            }\n        }\n    }"
}