{
    "Function": "_liquidate",
    "File": "contracts/src/TroveManager.sol",
    "Parent Contracts": [
        "contracts/src/Interfaces/ITroveEvents.sol",
        "contracts/src/Interfaces/ITroveManager.sol",
        "contracts/src/Dependencies/LiquityBase.sol",
        "contracts/src/Interfaces/ILiquityBase.sol"
    ],
    "High-Level Calls": [
        "IBorrowerOperations",
        "ITroveNFT",
        "ICollSurplusPool",
        "IActivePool"
    ],
    "Internal Calls": [
        "_getLatestBatchData",
        "_getBatchManager",
        "_getOffsetAndRedistributionVals",
        "_closeTrove",
        "_movePendingTroveRewardsToActivePool",
        "_getLatestTroveData",
        "_getCollGasCompensation"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function _liquidate(\n        IDefaultPool _defaultPool,\n        uint256 _troveId,\n        uint256 _boldInSPForOffsets,\n        uint256 _price,\n        LatestTroveData memory trove,\n        LiquidationValues memory singleLiquidation\n    ) internal {\n        address owner = troveNFT.ownerOf(_troveId);\n\n        _getLatestTroveData(_troveId, trove);\n        address batchAddress = _getBatchManager(_troveId);\n        bool isTroveInBatch = batchAddress != address(0);\n        LatestBatchData memory batch;\n        if (isTroveInBatch) _getLatestBatchData(batchAddress, batch);\n\n        _movePendingTroveRewardsToActivePool(_defaultPool, trove.redistBoldDebtGain, trove.redistCollGain);\n\n        singleLiquidation.collGasCompensation = _getCollGasCompensation(trove.entireColl);\n        uint256 collToLiquidate = trove.entireColl - singleLiquidation.collGasCompensation;\n\n        (\n            singleLiquidation.debtToOffset,\n            singleLiquidation.collToSendToSP,\n            singleLiquidation.debtToRedistribute,\n            singleLiquidation.collToRedistribute,\n            singleLiquidation.collSurplus\n        ) = _getOffsetAndRedistributionVals(trove.entireDebt, collToLiquidate, _boldInSPForOffsets, _price);\n\n        TroveChange memory troveChange;\n        troveChange.collDecrease = trove.entireColl;\n        troveChange.debtDecrease = trove.entireDebt;\n        troveChange.appliedRedistCollGain = trove.redistCollGain;\n        troveChange.appliedRedistBoldDebtGain = trove.redistBoldDebtGain;\n        _closeTrove(\n            _troveId,\n            troveChange,\n            batchAddress,\n            batch.entireCollWithoutRedistribution,\n            batch.entireDebtWithoutRedistribution,\n            Status.closedByLiquidation\n        );\n\n        if (isTroveInBatch) {\n            singleLiquidation.oldWeightedRecordedDebt =\n                batch.weightedRecordedDebt +\n                (trove.entireDebt - trove.redistBoldDebtGain) *\n                batch.annualInterestRate;\n            singleLiquidation.newWeightedRecordedDebt =\n                batch.entireDebtWithoutRedistribution *\n                batch.annualInterestRate;\n            // Mint batch management fee\n            troveChange.batchAccruedManagementFee = batch.accruedManagementFee;\n            troveChange.oldWeightedRecordedBatchManagementFee =\n                batch.weightedRecordedBatchManagementFee +\n                (trove.entireDebt - trove.redistBoldDebtGain) *\n                batch.annualManagementFee;\n            troveChange.newWeightedRecordedBatchManagementFee =\n                batch.entireDebtWithoutRedistribution *\n                batch.annualManagementFee;\n            activePool.mintBatchManagementFeeAndAccountForChange(troveChange, batchAddress);\n        } else {\n            singleLiquidation.oldWeightedRecordedDebt = trove.weightedRecordedDebt;\n        }\n\n        // Differencen between liquidation penalty and liquidation threshold\n        if (singleLiquidation.collSurplus > 0) {\n            collSurplusPool.accountSurplus(owner, singleLiquidation.collSurplus);\n        }\n\n        // Wipe out state in BO\n        borrowerOperations.onLiquidateTrove(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: 0,\n            _coll: 0,\n            _stake: 0,\n            _annualInterestRate: 0,\n            _snapshotOfTotalCollRedist: 0,\n            _snapshotOfTotalDebtRedist: 0\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.liquidate,\n            _annualInterestRate: 0,\n            _debtIncreaseFromRedist: trove.redistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: 0,\n            _debtChangeFromOperation: -int256(trove.entireDebt),\n            _collIncreaseFromRedist: trove.redistCollGain,\n            _collChangeFromOperation: -int256(trove.entireColl)\n        });\n\n        if (isTroveInBatch) {\n            emit BatchUpdated({\n                _interestBatchManager: batchAddress,\n                _operation: BatchOperation.exitBatch,\n                _debt: batches[batchAddress].debt,\n                _coll: batches[batchAddress].coll,\n                _annualInterestRate: batch.annualInterestRate,\n                _annualManagementFee: batch.annualManagementFee,\n                _totalDebtShares: batches[batchAddress].totalDebtShares,\n                _debtIncreaseFromUpfrontFee: 0\n            });\n        }\n    }"
}