{
    "Function": "withdrawFromSP",
    "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": [
        "IActivePool",
        "LiquityMath"
    ],
    "Internal Calls": [
        "_getYieldToKeepOrSend",
        "getDepositorCollGain",
        "_updateDepositAndSnapshots",
        "_sendBoldtoDepositor",
        "getDepositorYieldGain",
        "_getNewStashedCollAndCollToSend",
        "_requireUserHasDeposit",
        "getCompoundedBoldDeposit",
        "_updateTotalBoldDeposits",
        "_sendCollGainToDepositor",
        "require(bool,string)",
        "_decreaseYieldGainsOwed"
    ],
    "Library Calls": [
        "_min"
    ],
    "Low-Level Calls": [],
    "Code": "function withdrawFromSP(uint256 _amount, bool _doClaim) external override {\n        uint256 initialDeposit = deposits[msg.sender].initialValue;\n        _requireUserHasDeposit(initialDeposit);\n\n        activePool.mintAggInterest();\n\n        uint256 currentCollGain = getDepositorCollGain(msg.sender);\n        uint256 currentYieldGain = getDepositorYieldGain(msg.sender);\n        uint256 compoundedBoldDeposit = getCompoundedBoldDeposit(msg.sender);\n        uint256 boldToWithdraw = LiquityMath._min(_amount, compoundedBoldDeposit);\n        (uint256 keptYieldGain, uint256 yieldGainToSend) = _getYieldToKeepOrSend(currentYieldGain, _doClaim);\n        uint256 newDeposit = compoundedBoldDeposit - boldToWithdraw + keptYieldGain;\n        (uint256 newStashedColl, uint256 collToSend) = _getNewStashedCollAndCollToSend(\n            msg.sender,\n            currentCollGain,\n            _doClaim\n        );\n\n        emit DepositOperation(\n            msg.sender,\n            Operation.withdrawFromSP,\n            initialDeposit - compoundedBoldDeposit,\n            -int256(boldToWithdraw),\n            currentYieldGain,\n            yieldGainToSend,\n            currentCollGain,\n            collToSend\n        );\n\n        _updateDepositAndSnapshots(msg.sender, newDeposit, newStashedColl);\n        _decreaseYieldGainsOwed(currentYieldGain);\n        uint256 newTotalBoldDeposits = _updateTotalBoldDeposits(keptYieldGain, boldToWithdraw);\n        _sendBoldtoDepositor(msg.sender, boldToWithdraw + yieldGainToSend);\n        _sendCollGainToDepositor(collToSend);\n\n        require(newTotalBoldDeposits >= MIN_BOLD_IN_SP, \"Withdrawal must leave totalBoldDeposits >= MIN_BOLD_IN_SP\");\n    }"
}