{
    "Function": "verifyBalance",
    "File": "contracts/libraries/StrategyLibrary.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "IStrategy",
        "IOracle",
        "IStrategy",
        "SignedSafeMath",
        "SignedSafeMath",
        "IStrategy",
        "SignedSafeMath",
        "SignedSafeMath"
    ],
    "Internal Calls": [
        "getRange",
        "getExpectedTokenValue",
        "getRange",
        "getRange",
        "getExpectedTokenValue"
    ],
    "Library Calls": [
        "add",
        "add",
        "sub",
        "sub"
    ],
    "Low-Level Calls": [],
    "Code": "function verifyBalance(address strategy, address oracle) public view returns (bool, uint256, int256[] memory) {\n        (uint256 total, int256[] memory estimates) =\n            IOracle(oracle).estimateStrategy(IStrategy(strategy));\n        uint256 threshold = IStrategy(strategy).rebalanceThreshold();\n\n        bool balanced = true;\n        address[] memory strategyItems = IStrategy(strategy).items();\n        for (uint256 i = 0; i < strategyItems.length; i++) {\n            int256 expectedValue = getExpectedTokenValue(total, strategy, strategyItems[i]);\n            if (expectedValue > 0) {\n                int256 rebalanceRange = 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] > getRange(int256(total), 1)) {\n                    balanced = false;\n                    break;\n                }\n            }\n        }\n        if (balanced) {\n            address[] memory strategyDebt = IStrategy(strategy).debt();\n            for (uint256 i = 0; i < strategyDebt.length; i++) {\n              int256 expectedValue = getExpectedTokenValue(total, strategy, strategyDebt[i]);\n              int256 rebalanceRange = 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, total, estimates);\n    }"
}