{
    "Function": "_openReversePosition",
    "File": "contracts/AMM.sol",
    "Parent Contracts": [
        "contracts/legos/Governable.sol",
        "node_modules/@openzeppelin/contracts/proxy/utils/Initializable.sol",
        "contracts/legos/Governable.sol",
        "contracts/Interfaces.sol"
    ],
    "High-Level Calls": [
        "SafeCast",
        "SafeCast"
    ],
    "Internal Calls": [
        "_reducePosition",
        "abs",
        "abs",
        "abs",
        "_increasePosition",
        "abs",
        "_reducePosition"
    ],
    "Library Calls": [
        "toUint256",
        "toUint256"
    ],
    "Low-Level Calls": [],
    "Code": "function _openReversePosition(address trader, int256 baseAssetQuantity, uint quoteAssetLimit)\n        internal\n        returns (int realizedPnl, uint quoteAsset, bool isPositionIncreased)\n    {\n        Position memory position = positions[trader];\n        if (abs(position.size) >= abs(baseAssetQuantity)) {\n            (realizedPnl, quoteAsset) = _reducePosition(trader, baseAssetQuantity, quoteAssetLimit);\n        } else {\n            uint closedRatio = (quoteAssetLimit * abs(position.size).toUint256()) / abs(baseAssetQuantity).toUint256();\n            (realizedPnl, quoteAsset) = _reducePosition(trader, -position.size, closedRatio);\n\n            // this is required because the user might pass a very less value (slippage-prone) while shorting\n            if (quoteAssetLimit >= quoteAsset) {\n                quoteAssetLimit -= quoteAsset;\n            }\n            quoteAsset += _increasePosition(trader, baseAssetQuantity + position.size, quoteAssetLimit);\n            isPositionIncreased = true;\n        }\n    }"
}