{
    "Function": "_getLiquidationPrice",
    "File": "contracts/HubbleViewer.sol",
    "Parent Contracts": [
        "contracts/Interfaces.sol"
    ],
    "High-Level Calls": [
        "SafeCast",
        "IAMM",
        "SafeCast",
        "IAMM",
        "SafeCast",
        "IAMM",
        "SafeCast",
        "IClearingHouse"
    ],
    "Internal Calls": [
        "_abs",
        "_abs"
    ],
    "Library Calls": [
        "toUint256",
        "toInt256",
        "toInt256",
        "toInt256"
    ],
    "Low-Level Calls": [],
    "Code": "function _getLiquidationPrice(\n            address trader,\n            IAMM amm,\n            uint256 notionalPosition,\n            int256 margin,\n            int256 baseAssetQuantity,\n            uint quoteAssetQuantity\n        )\n        internal\n        view\n        returns(uint256 liquidationPrice)\n    {\n        if (notionalPosition == 0) {\n            return 0;\n        }\n\n        (, int256 unrealizedPnl, int256 totalPosSize, uint256 openNotional) = amm.getNotionalPositionAndUnrealizedPnl(trader);\n\n        if (baseAssetQuantity != 0) {\n            // Calculate effective position and openNotional\n            if (baseAssetQuantity * totalPosSize >= 0) { // increasingPosition i.e. same direction trade\n                openNotional += quoteAssetQuantity;\n            } else { // open reverse position\n                uint totalPosNotional = amm.getCloseQuote(totalPosSize + baseAssetQuantity);\n                if (_abs(totalPosSize) >= _abs(baseAssetQuantity)) { // position side remains same after the trade\n                    (openNotional,) = amm.getOpenNotionalWhileReducingPosition(\n                        totalPosSize,\n                        totalPosNotional,\n                        unrealizedPnl,\n                        baseAssetQuantity\n                    );\n                } else { // position side changes after the trade\n                    openNotional = totalPosNotional;\n                }\n            }\n            totalPosSize += baseAssetQuantity;\n        }\n\n        int256 pnlForLiquidation = clearingHouse.maintenanceMargin() * notionalPosition.toInt256() / PRECISION_INT - margin;\n        int256 _liquidationPrice;\n        if (totalPosSize > 0) {\n            _liquidationPrice = (openNotional.toInt256() + pnlForLiquidation) * 1e18 / totalPosSize;\n        } else if (totalPosSize < 0) {\n            _liquidationPrice = (openNotional.toInt256() - pnlForLiquidation) * 1e18 / (-totalPosSize);\n        }\n\n        if (_liquidationPrice < 0) { // is this possible?\n            _liquidationPrice = 0;\n        }\n        return _liquidationPrice.toUint256();\n    }"
}