{
    "Function": "liquidateFlexible",
    "File": "contracts/MarginAccount.sol",
    "Parent Contracts": [
        "contracts/legos/HubbleBase.sol",
        "node_modules/@openzeppelin/contracts/metatx/ERC2771Context.sol",
        "node_modules/@openzeppelin/contracts/security/Pausable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "contracts/legos/Governable.sol",
        "node_modules/@openzeppelin/contracts/proxy/utils/Initializable.sol",
        "contracts/legos/Governable.sol",
        "contracts/Interfaces.sol"
    ],
    "High-Level Calls": [
        "IClearingHouse"
    ],
    "Internal Calls": [
        "revert NOT_LIQUIDATABLE(IMarginAccount.LiquidationStatus)",
        "_getLiquidationInfo",
        "whenNotPaused",
        "_liquidateFlexible"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function liquidateFlexible(address trader, uint maxRepay, uint[] calldata idxs) external whenNotPaused {\n        clearingHouse.updatePositions(trader); // credits/debits funding\n        uint repayed;\n        for (uint i = 0; i < idxs.length; i++) {\n            LiquidationBuffer memory buffer = _getLiquidationInfo(trader, idxs[i]);\n            // revert only if trader has open positions, otherwise fail silently\n            if (buffer.status == IMarginAccount.LiquidationStatus.OPEN_POSITIONS) {\n                revert NOT_LIQUIDATABLE(buffer.status);\n            }\n            if (buffer.status != IMarginAccount.LiquidationStatus.IS_LIQUIDATABLE) {\n                break;\n            }\n            repayed = _liquidateFlexible(trader, maxRepay, idxs[i]);\n            maxRepay -= repayed;\n        }\n    }"
}