{
    "Function": "_applyUpfrontFee",
    "File": "contracts/src/BorrowerOperations.sol",
    "Parent Contracts": [
        "contracts/src/Interfaces/IBorrowerOperations.sol",
        "contracts/src/Dependencies/AddRemoveManagers.sol",
        "contracts/src/Interfaces/IAddRemoveManagers.sol",
        "contracts/src/Dependencies/LiquityBase.sol",
        "contracts/src/Interfaces/ILiquityBase.sol"
    ],
    "High-Level Calls": [
        "IActivePool",
        "LiquityMath"
    ],
    "Internal Calls": [
        "_requireUserAcceptsUpfrontFee",
        "_getNewTCRFromTroveChange",
        "_requireNewTCRisAboveCCR",
        "_requireOraclesLive",
        "_calcUpfrontFee",
        "_requireICRisAboveMCR",
        "_requireICRisAboveMCRPlusBCR"
    ],
    "Library Calls": [
        "_computeCR"
    ],
    "Low-Level Calls": [],
    "Code": "function _applyUpfrontFee(\n        uint256 _troveEntireColl,\n        uint256 _troveEntireDebt,\n        TroveChange memory _troveChange,\n        uint256 _maxUpfrontFee,\n        bool _isTroveInBatch\n    ) internal returns (uint256) {\n        uint256 price = _requireOraclesLive();\n\n        uint256 avgInterestRate = activePool.getNewApproxAvgInterestRateFromTroveChange(_troveChange);\n        _troveChange.upfrontFee = _calcUpfrontFee(_troveEntireDebt, avgInterestRate);\n        _requireUserAcceptsUpfrontFee(_troveChange.upfrontFee, _maxUpfrontFee);\n\n        _troveEntireDebt += _troveChange.upfrontFee;\n\n        // ICR is based on the requested Bold amount + upfront fee.\n        uint256 newICR = LiquityMath._computeCR(_troveEntireColl, _troveEntireDebt, price);\n        if (_isTroveInBatch) {\n            _requireICRisAboveMCRPlusBCR(newICR);\n        } else {\n            _requireICRisAboveMCR(newICR);\n        }\n\n        // Disallow a premature adjustment if it would result in TCR < CCR\n        // (which includes the case when TCR is already below CCR before the adjustment).\n        uint256 newTCR = _getNewTCRFromTroveChange(_troveChange, price);\n        _requireNewTCRisAboveCCR(newTCR);\n\n        return _troveEntireDebt;\n    }"
}