{
    "Function": "_getOffsetAndRedistributionVals",
    "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": [
        "LiquityMath"
    ],
    "Internal Calls": [
        "_getCollPenaltyAndSurplus",
        "_getCollPenaltyAndSurplus"
    ],
    "Library Calls": [
        "_min"
    ],
    "Low-Level Calls": [],
    "Code": "function _getOffsetAndRedistributionVals(\n        uint256 _entireTroveDebt,\n        uint256 _collToLiquidate, // gas compensation is already subtracted\n        uint256 _boldInSPForOffsets,\n        uint256 _price\n    )\n        internal\n        view\n        returns (\n            uint256 debtToOffset,\n            uint256 collToSendToSP,\n            uint256 debtToRedistribute,\n            uint256 collToRedistribute,\n            uint256 collSurplus\n        )\n    {\n        uint256 collSPPortion;\n        /*\n         * Offset as much debt & collateral as possible against the Stability Pool, and redistribute the remainder\n         * between all active troves.\n         *\n         *  If the trove's debt is larger than the deposited Bold in the Stability Pool:\n         *\n         *  - Offset an amount of the trove's debt equal to the Bold in the Stability Pool\n         *  - Send a fraction of the trove's collateral to the Stability Pool, equal to the fraction of its offset debt\n         *\n         */\n        if (_boldInSPForOffsets > 0) {\n            debtToOffset = LiquityMath._min(_entireTroveDebt, _boldInSPForOffsets);\n            collSPPortion = (_collToLiquidate * debtToOffset) / _entireTroveDebt;\n            (collToSendToSP, collSurplus) = _getCollPenaltyAndSurplus(\n                collSPPortion,\n                debtToOffset,\n                LIQUIDATION_PENALTY_SP,\n                _price\n            );\n        }\n\n        // Redistribution\n        debtToRedistribute = _entireTroveDebt - debtToOffset;\n        if (debtToRedistribute > 0) {\n            uint256 collRedistributionPortion = _collToLiquidate - collSPPortion;\n            if (collRedistributionPortion > 0) {\n                (collToRedistribute, collSurplus) = _getCollPenaltyAndSurplus(\n                    collRedistributionPortion + collSurplus, // Coll surplus from offset can be eaten up by red. penalty\n                    debtToRedistribute,\n                    LIQUIDATION_PENALTY_REDISTRIBUTION, // _penaltyRatio\n                    _price\n                );\n            }\n        }\n        // assert(_collToLiquidate == collToSendToSP + collToRedistribute + collSurplus);\n    }"
}