{
    "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": [
        "SafeCast",
        "SafeCast"
    ],
    "Internal Calls": [
        "_liquidateExactSeize",
        "_liquidateExactRepay",
        "_seizeToRepay",
        "_getLiquidationInfo",
        "whenNotPaused"
    ],
    "Library Calls": [
        "toUint256",
        "toUint256"
    ],
    "Low-Level Calls": [],
    "Code": "function _liquidateFlexible(address trader, uint maxRepay, uint idx) internal whenNotPaused returns(uint /* repayed */) {\n        LiquidationBuffer memory buffer = _getLiquidationInfo(trader, idx);\n\n        // Q. Can user's margin cover the entire debt?\n        uint repay = _seizeToRepay(buffer, margin[idx][trader].toUint256());\n\n        // A.1 Yes, it can cover the entire debt. Settle repayAble\n        if (repay >= buffer.repayAble) {\n            _liquidateExactRepay(\n                buffer,\n                trader,\n                buffer.repayAble, // exact repay amount\n                idx,\n                0 // minSeizeAmount=0 implies accept whatever the oracle price is\n            );\n            return buffer.repayAble; // repayed exactly repayAble and 0 is left to repay now\n        }\n\n        // A.2 No, collateral can not cover the entire debt. Seize all of it.\n        return _liquidateExactSeize(\n            buffer,\n            trader,\n            maxRepay,\n            idx,\n            margin[idx][trader].toUint256()\n        );\n    }"
}