{
    "Function": "offset",
    "File": "contracts/src/StabilityPool.sol",
    "Parent Contracts": [
        "contracts/src/Interfaces/IStabilityPoolEvents.sol",
        "contracts/src/Interfaces/IStabilityPool.sol",
        "contracts/src/Interfaces/IBoldRewardsReceiver.sol",
        "contracts/src/Dependencies/LiquityBase.sol",
        "contracts/src/Interfaces/ILiquityBase.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "require(bool,string)",
        "_moveOffsetCollAndDebt",
        "_requireCallerIsTroveManager"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function offset(uint256 _debtToOffset, uint256 _collToAdd) external override {\n        _requireCallerIsTroveManager();\n\n        scaleToS[currentScale] += (P * _collToAdd) / totalBoldDeposits;\n        emit S_Updated(scaleToS[currentScale], currentScale);\n\n        uint256 numerator = P * (totalBoldDeposits - _debtToOffset);\n        uint256 newP = numerator / totalBoldDeposits;\n\n        // For `P` to turn zero, `totalBoldDeposits` has to be greater than `P * (totalBoldDeposits - _debtToOffset)`.\n        // - As the offset must leave at least 1 BOLD in the SP (MIN_BOLD_IN_SP),\n        //   the minimum value of `totalBoldDeposits - _debtToOffset` is `1e18`\n        // - It can be shown that `P` is always in range (1e27, 1e36].\n        // Thus, to turn `P` zero, `totalBoldDeposits` has to be greater than `(1e27 + 1) * 1e18`,\n        // and the offset has to be (near) maximal.\n        // In other words, there needs to be octillions of BOLD in the SP, which is unlikely to happen in practice.\n        require(newP > 0, \"P must never decrease to 0\");\n\n        // Overflow analyisis of scaling up P:\n        // We know that the resulting P is <= 1e36, and it's the result of dividing numerator by totalBoldDeposits.\n        // Thus, numerator <= 1e36 * totalBoldDeposits, so unless totalBoldDeposits is septillions of BOLD, it won\u2019t overflow.\n        // That holds on every iteration as an upper bound. We multiply numerator by SCALE_FACTOR,\n        // but numerator is by definition smaller than 1e36 * totalBoldDeposits / SCALE_FACTOR.\n        while (newP < P_PRECISION / SCALE_FACTOR) {\n            numerator *= SCALE_FACTOR;\n            newP = numerator / totalBoldDeposits;\n            currentScale += 1;\n            emit ScaleUpdated(currentScale);\n        }\n\n        emit P_Updated(newP);\n        P = newP;\n\n        _moveOffsetCollAndDebt(_collToAdd, _debtToOffset);\n    }"
}