{
    "Function": "_checkBalance",
    "File": "contracts/test/LibraryWrapper.sol",
    "Parent Contracts": [
        "contracts/helpers/StrategyTypes.sol"
    ],
    "High-Level Calls": [
        "IStrategy",
        "SignedSafeMath",
        "IStrategy",
        "SignedSafeMath",
        "SignedSafeMath",
        "StrategyLibrary",
        "IOracle",
        "StrategyLibrary",
        "StrategyLibrary",
        "SignedSafeMath",
        "StrategyLibrary",
        "StrategyLibrary"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "getExpectedTokenValue",
        "getRange",
        "sub",
        "getExpectedTokenValue",
        "add",
        "getRange",
        "add",
        "sub",
        "getRange"
    ],
    "Low-Level Calls": [],
    "Code": "function _checkBalance(\n        uint256 threshold\n    ) internal view returns (bool) {\n        (uint256 total, int256[] memory estimates) =\n            oracle.estimateStrategy(strategy);\n        bool balanced = true;\n        address[] memory strategyItems = strategy.items();\n        for (uint256 i = 0; i < strategyItems.length; i++) {\n            int256 expectedValue = StrategyLibrary.getExpectedTokenValue(total, address(strategy), strategyItems[i]);\n            if (expectedValue > 0) {\n                int256 rebalanceRange = StrategyLibrary.getRange(expectedValue, threshold);\n                if (estimates[i] > expectedValue.add(rebalanceRange)) {\n                    balanced = false;\n                    break;\n                }\n                if (estimates[i] < expectedValue.sub(rebalanceRange)) {\n                    balanced = false;\n                    break;\n                }\n            } else {\n                // Token has an expected value of 0, so any value can cause the contract\n                // to be 'unbalanced' so we need an alternative way to determine balance.\n                // Min percent = 0.1%. If token value is above, consider it unbalanced\n                if (estimates[i] > StrategyLibrary.getRange(int256(total), 1)) {\n                    balanced = false;\n                    break;\n                }\n            }\n        }\n        if (balanced) {\n            address[] memory strategyDebt = strategy.debt();\n            for (uint256 i = 0; i < strategyDebt.length; i++) {\n              int256 expectedValue = StrategyLibrary.getExpectedTokenValue(total, address(strategy), strategyDebt[i]);\n              int256 rebalanceRange = StrategyLibrary.getRange(expectedValue, threshold);\n              uint256 index = strategyItems.length + i;\n               // Debt\n               if (estimates[index] < expectedValue.add(rebalanceRange)) {\n                   balanced = false;\n                   break;\n               }\n               if (estimates[index] > expectedValue.sub(rebalanceRange)) {\n                   balanced = false;\n                   break;\n               }\n            }\n        }\n        return balanced;\n    }"
}