{
    "Function": "calculateLiquidateReturn",
    "File": "contracts/bancor/BancorFormula.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "SafeMath",
        "SafeMath"
    ],
    "Internal Calls": [
        "power",
        "require(bool)"
    ],
    "Library Calls": [
        "mul",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function calculateLiquidateReturn(\n        uint256 _supply,\n        uint256 _reserveBalance,\n        uint32 _totalRatio,\n        uint256 _amount\n    ) public view returns (uint256) {\n        // validate input\n        require(\n            _supply > 0 &&\n                _reserveBalance > 0 &&\n                _totalRatio > 1 &&\n                _totalRatio <= MAX_RATIO * 2 &&\n                _amount <= _supply\n        );\n\n        // special case for 0 amount\n        if (_amount == 0) return 0;\n\n        // special case for liquidating the entire supply\n        if (_amount == _supply) return _reserveBalance;\n\n        // special case if the total ratio = 100%\n        if (_totalRatio == MAX_RATIO) return _amount.mul(_reserveBalance) / _supply;\n\n        uint256 result;\n        uint8 precision;\n        uint256 baseD = _supply - _amount;\n        (result, precision) = power(_supply, baseD, MAX_RATIO, _totalRatio);\n        uint256 temp1 = _reserveBalance.mul(result);\n        uint256 temp2 = _reserveBalance << precision;\n        return (temp1 - temp2) / result;\n    }"
}