{
    "Function": "withdrawBorrowedAmount",
    "File": "contracts/Pool/Pool.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/utils/ReentrancyGuard.sol",
        "contracts/interfaces/IPool.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/ERC20PausableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"
    ],
    "High-Level Calls": [
        "SafeMathUpgradeable",
        "IRepayment",
        "IExtension",
        "IPoolFactory",
        "SafeMathUpgradeable",
        "IPoolFactory",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "IPoolFactory",
        "SavingsAccountUtil",
        "IPoolFactory",
        "SavingsAccountUtil"
    ],
    "Internal Calls": [
        "onlyBorrower",
        "totalSupply",
        "require(bool,string)",
        "nonReentrant",
        "getCurrentCollateralRatio",
        "require(bool,string)",
        "require(bool,string)"
    ],
    "Library Calls": [
        "div",
        "mul",
        "sub",
        "transferTokens",
        "transferTokens",
        "div",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function withdrawBorrowedAmount() external override onlyBorrower(msg.sender) nonReentrant {\n        LoanStatus _poolStatus = poolVariables.loanStatus;\n        uint256 _tokensLent = totalSupply();\n        require(\n            _poolStatus == LoanStatus.COLLECTION &&\n                poolConstants.loanStartTime < block.timestamp &&\n                block.timestamp < poolConstants.loanWithdrawalDeadline,\n            'WBA1'\n        );\n        IPoolFactory _poolFactory = IPoolFactory(poolFactory);\n        require(_tokensLent >= _poolFactory.minBorrowFraction().mul(poolConstants.borrowAmountRequested).div(10**30), 'WBA2');\n\n        poolVariables.loanStatus = LoanStatus.ACTIVE;\n        uint256 _currentCollateralRatio = getCurrentCollateralRatio();\n        require(_currentCollateralRatio >= poolConstants.idealCollateralRatio, 'WBA3');\n\n        uint256 _noOfRepaymentIntervals = poolConstants.noOfRepaymentIntervals;\n        uint256 _repaymentInterval = poolConstants.repaymentInterval;\n        IRepayment(_poolFactory.repaymentImpl()).initializeRepayment(\n            _noOfRepaymentIntervals,\n            _repaymentInterval,\n            poolConstants.borrowRate,\n            poolConstants.loanStartTime,\n            poolConstants.borrowAsset\n        );\n        IExtension(_poolFactory.extension()).initializePoolExtension(_repaymentInterval);\n\n        address _borrowAsset = poolConstants.borrowAsset;\n        (uint256 _protocolFeeFraction, address _collector) = _poolFactory.getProtocolFeeData();\n        uint256 _protocolFee = _tokensLent.mul(_protocolFeeFraction).div(10**30);\n        delete poolConstants.loanWithdrawalDeadline;\n\n        uint256 _feeAdjustedWithdrawalAmount = _tokensLent.sub(_protocolFee);\n\n        SavingsAccountUtil.transferTokens(_borrowAsset, _protocolFee, address(this), _collector);\n        SavingsAccountUtil.transferTokens(_borrowAsset, _feeAdjustedWithdrawalAmount, address(this), msg.sender);\n\n        emit AmountBorrowed(_feeAdjustedWithdrawalAmount, _protocolFee);\n    }"
}