{
    "Function": "removeLiquidity",
    "File": "contracts/hyphen/LiquidityProviders.sol",
    "Parent Contracts": [
        "contracts/security/Pausable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol",
        "contracts/hyphen/metatx/ERC2771ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"
    ],
    "High-Level Calls": [
        "IWhiteListPeriodManager",
        "ILPToken"
    ],
    "Internal Calls": [
        "getTokenPriceInLPShares",
        "_msgSender",
        "_msgSender",
        "_msgSender",
        "onlyValidLpToken",
        "sharesToTokenAmount",
        "require(bool,string)",
        "_msgSender",
        "require(bool,string)",
        "_burnSharesFromNft",
        "require(bool,string)",
        "_decreaseCurrentLiquidity",
        "whenNotPaused",
        "_msgSender",
        "nonReentrant",
        "onlyValidLpToken",
        "_isSupportedToken",
        "_transferFromLiquidityPool",
        "getTokenPriceInLPShares"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function removeLiquidity(uint256 _nftId, uint256 _amount)\n        external\n        nonReentrant\n        onlyValidLpToken(_nftId, _msgSender())\n        whenNotPaused\n    {\n        (address _tokenAddress, uint256 nftSuppliedLiquidity, uint256 totalNFTShares) = lpToken.tokenMetadata(_nftId);\n        require(_isSupportedToken(_tokenAddress), \"ERR__TOKEN_NOT_SUPPORTED\");\n\n        require(_amount != 0, \"ERR__INVALID_AMOUNT\");\n        require(nftSuppliedLiquidity >= _amount, \"ERR__INSUFFICIENT_LIQUIDITY\");\n        whiteListPeriodManager.beforeLiquidityRemoval(_msgSender(), _tokenAddress, _amount);\n        // Claculate how much shares represent input amount\n        uint256 lpSharesForInputAmount = _amount * getTokenPriceInLPShares(_tokenAddress);\n\n        // Calculate rewards accumulated\n        uint256 eligibleLiquidity = sharesToTokenAmount(totalNFTShares, _tokenAddress);\n        \n        uint256 lpFeeAccumulated;\n\n        // Handle edge cases where eligibleLiquidity is less than what was supplied by very small amount \n        if(nftSuppliedLiquidity > eligibleLiquidity) {\n            lpFeeAccumulated = 0;\n        } else {\n            unchecked {\n                lpFeeAccumulated = eligibleLiquidity - nftSuppliedLiquidity;\n            }\n        }\n        // Calculate amount of lp shares that represent accumulated Fee\n        uint256 lpSharesRepresentingFee = lpFeeAccumulated * getTokenPriceInLPShares(_tokenAddress);\n\n        totalLPFees[_tokenAddress] -= lpFeeAccumulated;\n        uint256 amountToWithdraw = _amount + lpFeeAccumulated;\n        uint256 lpSharesToBurn = lpSharesForInputAmount + lpSharesRepresentingFee;\n\n        // Handle round off errors to avoid dust lp token in contract\n        if (totalNFTShares - lpSharesToBurn < BASE_DIVISOR) {\n            lpSharesToBurn = totalNFTShares;\n        }\n        totalReserve[_tokenAddress] -= amountToWithdraw;\n        totalLiquidity[_tokenAddress] -= _amount;\n        totalSharesMinted[_tokenAddress] -= lpSharesToBurn;\n\n        _decreaseCurrentLiquidity(_tokenAddress, _amount);\n\n        _burnSharesFromNft(_nftId, lpSharesToBurn, _amount, _tokenAddress);\n\n        _transferFromLiquidityPool(_tokenAddress, _msgSender(), amountToWithdraw);\n\n        emit LiquidityRemoved(_tokenAddress, amountToWithdraw, _msgSender());\n    }"
}