{
    "Function": "calculatePurchaseReturn",
    "File": "contracts/bancor/BancorFormula.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "SafeMath",
        "SafeMath",
        "SafeMath"
    ],
    "Internal Calls": [
        "power",
        "require(bool,string)"
    ],
    "Library Calls": [
        "mul",
        "mul",
        "add"
    ],
    "Low-Level Calls": [],
    "Code": "function calculatePurchaseReturn(\n        uint256 _supply,\n        uint256 _reserveBalance,\n        uint32 _reserveRatio,\n        uint256 _depositAmount\n    ) public view returns (uint256) {\n        // validate input\n        require(\n            _supply > 0 && _reserveBalance > 0 && _reserveRatio > 0 && _reserveRatio <= MAX_RATIO,\n            \"invalid parameters\"\n        );\n\n        // special case for 0 deposit amount\n        if (_depositAmount == 0) return 0;\n\n        // special case if the ratio = 100%\n        if (_reserveRatio == MAX_RATIO) return _supply.mul(_depositAmount) / _reserveBalance;\n\n        uint256 result;\n        uint8 precision;\n        uint256 baseN = _depositAmount.add(_reserveBalance);\n        (result, precision) = power(baseN, _reserveBalance, _reserveRatio, MAX_RATIO);\n        uint256 temp = _supply.mul(result) >> precision;\n        return temp - _supply;\n    }"
}