{
    "Function": "_buyToken",
    "File": "contracts/routers/LoopRouter.sol",
    "Parent Contracts": [
        "contracts/routers/StrategyRouter.sol",
        "contracts/helpers/StrategyTypes.sol",
        "contracts/interfaces/IStrategyRouter.sol"
    ],
    "High-Level Calls": [
        "SignedSafeMath",
        "IERC20",
        "IStrategy",
        "StrategyLibrary",
        "IStrategy",
        "SignedSafeMath",
        "IStrategy"
    ],
    "Internal Calls": [
        "_buyPath",
        "_buyPath"
    ],
    "Library Calls": [
        "sub",
        "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        if (estimatedValue == 0) {\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            uint256 balance = IERC20(weth).balanceOf(from);\n            _buyPath(\n                IStrategy(strategy).getTradeData(token),\n                uint256(amount) > balance ? balance : uint256(amount),\n                token,\n                strategy,\n                from\n            );\n        }\n    }"
}