{
    "Function": "_buyToken",
    "File": "contracts/routers/FullRouter.sol",
    "Parent Contracts": [
        "contracts/routers/StrategyRouter.sol",
        "contracts/helpers/StrategyTypes.sol",
        "contracts/interfaces/IStrategyRouter.sol"
    ],
    "High-Level Calls": [
        "SignedSafeMath",
        "IERC20",
        "SignedSafeMath",
        "IStrategy",
        "StrategyLibrary",
        "SignedSafeMath",
        "IStrategy",
        "SignedSafeMath"
    ],
    "Internal Calls": [
        "_buyPath",
        "_buyPath",
        "abi.decode()"
    ],
    "Library Calls": [
        "sub",
        "mul",
        "div",
        "getRange",
        "sub"
    ],
    "Low-Level Calls": [],
    "Code": "function _buyToken(\n        address strategy,\n        address from,\n        address token,\n        int256 estimatedValue,\n        int256 expectedValue\n    ) internal {\n        int256 amount;\n        // Note: it is possible for a restructure to have an estimated value of zero,\n        // but only if it's expected value is also zero, in which case this function\n        // will end without making a purchase. So it is safe to set `isDeposit` this way\n        bool isDeposit = estimatedValue == 0;\n        if (isDeposit) {\n            amount = expectedValue;\n        } else {\n            int256 rebalanceRange =\n                StrategyLibrary.getRange(\n                    expectedValue,\n                    IStrategy(strategy).rebalanceThreshold()\n                );\n            if (estimatedValue < expectedValue.sub(rebalanceRange)) {\n                amount = expectedValue.sub(estimatedValue);\n            }\n        }\n        if (amount > 0) {\n            TradeData memory tradeData = IStrategy(strategy).getTradeData(token);\n            if (tradeData.cache.length > 0) {\n                //Apply multiplier\n                uint16 multiplier = abi.decode(tradeData.cache, (uint16));\n                amount = amount.mul(int256(multiplier)).div(int256(DIVISOR));\n            }\n            uint256 balance = IERC20(weth).balanceOf(from);\n            _buyPath(\n                tradeData,\n                uint256(amount) > balance ? balance : uint256(amount),\n                token,\n                strategy,\n                from\n            );\n        }\n    }"
}