{
    "Function": "_openTrove",
    "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": [
        "IBoldToken",
        "IActivePool",
        "IActivePool",
        "LiquityMath",
        "IWETH"
    ],
    "Internal Calls": [
        "_calcUpfrontFee",
        "_getNewTCRFromTroveChange",
        "_pullCollAndSendToActivePool",
        "abi.encode()",
        "_setAddManager",
        "_requireIsNotShutDown",
        "_requireUserAcceptsUpfrontFee",
        "_requireICRisAboveMCRPlusBCR",
        "_requireICRisAboveMCR",
        "_requireOraclesLive",
        "_requireAtLeastMinDebt",
        "_requireNewTCRisAboveCCR",
        "_setRemoveManagerAndReceiver",
        "_requireTroveDoesNotExists",
        "keccak256(bytes)"
    ],
    "Library Calls": [
        "_computeCR"
    ],
    "Low-Level Calls": [],
    "Code": "function _openTrove(\n        address _owner,\n        uint256 _ownerIndex,\n        uint256 _collAmount,\n        uint256 _boldAmount,\n        uint256 _annualInterestRate,\n        address _interestBatchManager,\n        uint256 _batchEntireDebt,\n        uint256 _batchManagementAnnualFee,\n        uint256 _maxUpfrontFee,\n        address _addManager,\n        address _removeManager,\n        address _receiver,\n        TroveChange memory _change\n    ) internal returns (uint256) {\n        _requireIsNotShutDown();\n\n        LocalVariables_openTrove memory vars;\n\n        // stack too deep not allowing to reuse troveManager from outer functions\n        vars.troveManager = troveManager;\n        vars.activePool = activePool;\n        vars.boldToken = boldToken;\n\n        vars.price = _requireOraclesLive();\n\n        // --- Checks ---\n\n        vars.troveId = uint256(keccak256(abi.encode(_owner, _ownerIndex)));\n        _requireTroveDoesNotExists(vars.troveManager, vars.troveId);\n\n        _change.collIncrease = _collAmount;\n        _change.debtIncrease = _boldAmount;\n\n        // For simplicity, we ignore the fee when calculating the approx. interest rate\n        _change.newWeightedRecordedDebt = (_batchEntireDebt + _change.debtIncrease) * _annualInterestRate;\n\n        vars.avgInterestRate = vars.activePool.getNewApproxAvgInterestRateFromTroveChange(_change);\n        _change.upfrontFee = _calcUpfrontFee(_change.debtIncrease, vars.avgInterestRate);\n        _requireUserAcceptsUpfrontFee(_change.upfrontFee, _maxUpfrontFee);\n\n        vars.entireDebt = _change.debtIncrease + _change.upfrontFee;\n        _requireAtLeastMinDebt(vars.entireDebt);\n\n        vars.ICR = LiquityMath._computeCR(_collAmount, vars.entireDebt, vars.price);\n\n        // Recalculate newWeightedRecordedDebt, now taking into account the upfront fee, and the batch fee if needed\n        if (_interestBatchManager == address(0)) {\n            _change.newWeightedRecordedDebt = vars.entireDebt * _annualInterestRate;\n\n            // ICR is based on the requested Bold amount + upfront fee.\n            _requireICRisAboveMCR(vars.ICR);\n        } else {\n            // old values have been set outside, before calling this function\n            _change.newWeightedRecordedDebt = (_batchEntireDebt + vars.entireDebt) * _annualInterestRate;\n            _change.newWeightedRecordedBatchManagementFee =\n                (_batchEntireDebt + vars.entireDebt) *\n                _batchManagementAnnualFee;\n\n            // ICR is based on the requested Bold amount + upfront fee.\n            // Troves in a batch have a stronger requirement (MCR+BCR)\n            _requireICRisAboveMCRPlusBCR(vars.ICR);\n        }\n\n        vars.newTCR = _getNewTCRFromTroveChange(_change, vars.price);\n        _requireNewTCRisAboveCCR(vars.newTCR);\n\n        // --- Effects & interactions ---\n\n        // Set add/remove managers\n        _setAddManager(vars.troveId, _addManager);\n        _setRemoveManagerAndReceiver(vars.troveId, _removeManager, _receiver);\n\n        vars.activePool.mintAggInterestAndAccountForTroveChange(_change, _interestBatchManager);\n\n        // Pull coll tokens from sender and move them to the Active Pool\n        _pullCollAndSendToActivePool(vars.activePool, _collAmount);\n\n        // Mint the requested _boldAmount to the borrower and mint the gas comp to the GasPool\n        vars.boldToken.mint(msg.sender, _boldAmount);\n        WETH.transferFrom(msg.sender, gasPoolAddress, ETH_GAS_COMPENSATION);\n\n        return vars.troveId;\n    }"
}