{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/InvestmentManager.sol",
    "Parent Contracts": [
        "src/util/Auth.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract InvestmentManager is Auth {\n    using MathLib for uint256;\n    using MathLib for uint128;\n\n    /// @dev Prices are fixed-point integers with 18 decimals\n    uint8 public constant PRICE_DECIMALS = 18;\n    EscrowLike public immutable escrow;\n    UserEscrowLike public immutable userEscrow;\n\n    GatewayLike public gateway;\n    PoolManagerLike public poolManager;\n\n    mapping(address => mapping(address => LPValues)) public orderbook;\n\n    // --- Events ---\n    event File(bytes32 indexed what, address data);\n    event DepositProcessed(address indexed liquidityPool, address indexed user, uint128 indexed currencyAmount);\n    event RedemptionProcessed(address indexed liquidityPool, address indexed user, uint128 indexed trancheTokenAmount);\n\n    constructor(address escrow_, address userEscrow_) {\n        escrow = EscrowLike(escrow_);\n        userEscrow = UserEscrowLike(userEscrow_);\n\n        wards[msg.sender] = 1;\n        emit Rely(msg.sender);\n    }\n\n    /// @dev Gateway must be msg.sender for incoming messages\n    modifier onlyGateway() {\n        require(msg.sender == address(gateway), \"InvestmentManager/not-the-gateway\");\n        _;\n    }\n\n    // --- Administration ---\n    function file(bytes32 what, address data) external auth {\n        if (what == \"gateway\") gateway = GatewayLike(data);\n        else if (what == \"poolManager\") poolManager = PoolManagerLike(data);\n        else revert(\"InvestmentManager/file-unrecognized-param\");\n        emit File(what, data);\n    }\n\n    // --- Outgoing message handling ---\n    /// @notice Request deposit. Liquidity pools have to request investments from Centrifuge before actual tranche tokens can be minted.\n    ///         The deposit requests are added to the order book on Centrifuge. Once the next epoch is executed on Centrifuge,\n    ///         liquidity pools can proceed with tranche token payouts in case their orders got fullfilled.\n    ///         If an amount of 0 is passed, this triggers cancelling outstanding deposit orders.\n    /// @dev    The user currency amount required to fullfill the deposit request have to be locked,\n    ///         even though the tranche token payout can only happen after epoch execution.\n    function requestDeposit(uint256 currencyAmount, address user) public auth {\n        address liquidityPool = msg.sender;\n        LiquidityPoolLike lPool = LiquidityPoolLike(liquidityPool);\n        address currency = lPool.asset();\n        uint128 _currencyAmount = _toUint128(currencyAmount);\n\n        // Check if liquidity pool currency is supported by the Centrifuge pool\n        poolManager.isAllowedAsPoolCurrency(lPool.poolId(), currency);\n        // Check if user is allowed to hold the restricted tranche tokens\n        _isAllowedToInvest(lPool.poolId(), lPool.trancheId(), currency, user);\n        if (_currencyAmount == 0) {\n            // Case: outstanding investment orders only needed to be cancelled\n            gateway.cancelInvestOrder(\n                lPool.poolId(), lPool.trancheId(), user, poolManager.currencyAddressToId(lPool.asset())\n            );\n            return;\n        }\n\n        // Transfer the currency amount from user to escrow. (lock currency in escrow).\n        SafeTransferLib.safeTransferFrom(currency, user, address(escrow), _currencyAmount);\n\n        gateway.increaseInvestOrder(\n            lPool.poolId(), lPool.trancheId(), user, poolManager.currencyAddressToId(lPool.asset()), _currencyAmount\n        );\n    }\n\n    /// @notice Request tranche token redemption. Liquidity pools have to request redemptions from Centrifuge before actual currency payouts can be done.\n    ///         The redemption requests are added to the order book on Centrifuge. Once the next epoch is executed on Centrifuge,\n    ///         liquidity pools can proceed with currency payouts in case their orders got fullfilled.\n    ///         If an amount of 0 is passed, this triggers cancelling outstanding redemption orders.\n    /// @dev    The user tranche tokens required to fullfill the redemption request have to be locked, even though the currency payout can only happen after epoch execution.\n    function requestRedeem(uint256 trancheTokenAmount, address user) public auth {\n        address liquidityPool = msg.sender;\n        LiquidityPoolLike lPool = LiquidityPoolLike(liquidityPool);\n        uint128 _trancheTokenAmount = _toUint128(trancheTokenAmount);\n\n        // Check if liquidity pool currency is supported by the Centrifuge pool\n        poolManager.isAllowedAsPoolCurrency(lPool.poolId(), lPool.asset());\n        // Check if user is allowed to hold the restricted tranche tokens\n\n        _isAllowedToInvest(lPool.poolId(), lPool.trancheId(), lPool.asset(), user);\n\n        if (_trancheTokenAmount == 0) {\n            // Case: outstanding redemption orders will be cancelled\n            gateway.cancelRedeemOrder(\n                lPool.poolId(), lPool.trancheId(), user, poolManager.currencyAddressToId(lPool.asset())\n            );\n            return;\n        }\n\n        lPool.transferFrom(user, address(escrow), _trancheTokenAmount);\n\n        gateway.increaseRedeemOrder(\n            lPool.poolId(), lPool.trancheId(), user, poolManager.currencyAddressToId(lPool.asset()), _trancheTokenAmount\n        );\n    }\n\n    function decreaseDepositRequest(uint256 _currencyAmount, address user) public auth {\n        uint128 currencyAmount = _toUint128(_currencyAmount);\n        LiquidityPoolLike liquidityPool = LiquidityPoolLike(msg.sender);\n        require(liquidityPool.checkTransferRestriction(address(0), user, 0), \"InvestmentManager/not-a-member\");\n        gateway.decreaseInvestOrder(\n            liquidityPool.poolId(),\n            liquidityPool.trancheId(),\n            user,\n            poolManager.currencyAddressToId(liquidityPool.asset()),\n            currencyAmount\n        );\n    }\n\n    function decreaseRedeemRequest(uint256 _trancheTokenAmount, address user) public auth {\n        uint128 trancheTokenAmount = _toUint128(_trancheTokenAmount);\n        LiquidityPoolLike liquidityPool = LiquidityPoolLike(msg.sender);\n        require(liquidityPool.checkTransferRestriction(address(0), user, 0), \"InvestmentManager/not-a-member\");\n        gateway.decreaseRedeemOrder(\n            liquidityPool.poolId(),\n            liquidityPool.trancheId(),\n            user,\n            poolManager.currencyAddressToId(liquidityPool.asset()),\n            trancheTokenAmount\n        );\n    }\n\n    function collectDeposit(address user) public auth {\n        LiquidityPoolLike liquidityPool = LiquidityPoolLike(msg.sender);\n        require(liquidityPool.checkTransferRestriction(address(0), user, 0), \"InvestmentManager/not-a-member\");\n        gateway.collectInvest(\n            liquidityPool.poolId(),\n            liquidityPool.trancheId(),\n            user,\n            poolManager.currencyAddressToId(liquidityPool.asset())\n        );\n    }\n\n    function collectRedeem(address user) public auth {\n        LiquidityPoolLike liquidityPool = LiquidityPoolLike(msg.sender);\n        require(liquidityPool.checkTransferRestriction(address(0), user, 0), \"InvestmentManager/not-a-member\");\n        gateway.collectRedeem(\n            liquidityPool.poolId(),\n            liquidityPool.trancheId(),\n            user,\n            poolManager.currencyAddressToId(liquidityPool.asset())\n        );\n    }\n\n    // --- Incoming message handling ---\n    function updateTrancheTokenPrice(uint64 poolId, bytes16 trancheId, uint128 currencyId, uint128 price)\n        public\n        onlyGateway\n    {\n        address currency = poolManager.currencyIdToAddress(currencyId);\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, currency);\n        require(liquidityPool != address(0), \"InvestmentManager/tranche-does-not-exist\");\n\n        LiquidityPoolLike(liquidityPool).updatePrice(price);\n    }\n\n    function handleExecutedCollectInvest(\n        uint64 poolId,\n        bytes16 trancheId,\n        address recipient,\n        uint128 currency,\n        uint128 currencyPayout,\n        uint128 trancheTokensPayout\n    ) public onlyGateway {\n        require(currencyPayout != 0, \"InvestmentManager/zero-invest\");\n        address _currency = poolManager.currencyIdToAddress(currency);\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, _currency);\n        require(liquidityPool != address(0), \"InvestmentManager/tranche-does-not-exist\");\n\n        LPValues storage lpValues = orderbook[recipient][liquidityPool];\n        lpValues.maxDeposit = lpValues.maxDeposit + currencyPayout;\n        lpValues.maxMint = lpValues.maxMint + trancheTokensPayout;\n\n        LiquidityPoolLike(liquidityPool).mint(address(escrow), trancheTokensPayout); // mint to escrow. Recepeint can claim by calling withdraw / redeem\n        _updateLiquidityPoolPrice(liquidityPool, currencyPayout, trancheTokensPayout);\n    }\n\n    function handleExecutedCollectRedeem(\n        uint64 poolId,\n        bytes16 trancheId,\n        address recipient,\n        uint128 currency,\n        uint128 currencyPayout,\n        uint128 trancheTokensPayout\n    ) public onlyGateway {\n        require(trancheTokensPayout != 0, \"InvestmentManager/zero-redeem\");\n        address _currency = poolManager.currencyIdToAddress(currency);\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, _currency);\n        require(liquidityPool != address(0), \"InvestmentManager/tranche-does-not-exist\");\n\n        LPValues storage lpValues = orderbook[recipient][liquidityPool];\n        lpValues.maxWithdraw = lpValues.maxWithdraw + currencyPayout;\n        lpValues.maxRedeem = lpValues.maxRedeem + trancheTokensPayout;\n\n        userEscrow.transferIn(_currency, address(escrow), recipient, currencyPayout);\n        LiquidityPoolLike(liquidityPool).burn(address(escrow), trancheTokensPayout); // burned redeemed tokens from escrow\n        _updateLiquidityPoolPrice(liquidityPool, currencyPayout, trancheTokensPayout);\n    }\n\n    function handleExecutedDecreaseInvestOrder(\n        uint64 poolId,\n        bytes16 trancheId,\n        address user,\n        uint128 currency,\n        uint128 currencyPayout\n    ) public onlyGateway {\n        require(currencyPayout != 0, \"InvestmentManager/zero-payout\");\n\n        address _currency = poolManager.currencyIdToAddress(currency);\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, _currency);\n        require(liquidityPool != address(0), \"InvestmentManager/tranche-does-not-exist\");\n        require(_currency == LiquidityPoolLike(liquidityPool).asset(), \"InvestmentManager/not-tranche-currency\");\n\n        SafeTransferLib.safeTransferFrom(_currency, address(escrow), user, currencyPayout);\n    }\n\n    function handleExecutedDecreaseRedeemOrder(\n        uint64 poolId,\n        bytes16 trancheId,\n        address user,\n        uint128 currency,\n        uint128 trancheTokenPayout\n    ) public onlyGateway {\n        require(trancheTokenPayout != 0, \"InvestmentManager/zero-payout\");\n\n        address _currency = poolManager.currencyIdToAddress(currency);\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, _currency);\n        require(address(liquidityPool) != address(0), \"InvestmentManager/tranche-does-not-exist\");\n\n        require(\n            LiquidityPoolLike(liquidityPool).checkTransferRestriction(address(0), user, 0),\n            \"InvestmentManager/not-a-member\"\n        );\n\n        require(\n            LiquidityPoolLike(liquidityPool).transferFrom(address(escrow), user, trancheTokenPayout),\n            \"InvestmentManager/trancheTokens-transfer-failed\"\n        );\n    }\n\n    // --- View functions ---\n    function totalAssets(uint256 totalSupply, address liquidityPool) public view returns (uint256 _totalAssets) {\n        _totalAssets = convertToAssets(totalSupply, liquidityPool);\n    }\n\n    /// @dev Calculates the amount of shares / tranche tokens that any user would get for the amount of currency / assets provided.\n    ///      The calculation is based on the tranche token price from the most recent epoch retrieved from Centrifuge.\n    function convertToShares(uint256 _assets, address liquidityPool) public view auth returns (uint256 shares) {\n        (uint8 currencyDecimals, uint8 trancheTokenDecimals) = _getPoolDecimals(liquidityPool);\n        uint128 assets = _toUint128(_assets);\n\n        shares = assets.mulDiv(\n            10 ** (PRICE_DECIMALS + trancheTokenDecimals - currencyDecimals),\n            LiquidityPoolLike(liquidityPool).latestPrice(),\n            MathLib.Rounding.Down\n        );\n    }\n\n    /// @dev Calculates the asset value for an amount of shares / tranche tokens provided.\n    ///      The calculation is based on the tranche token price from the most recent epoch retrieved from Centrifuge.\n    function convertToAssets(uint256 _shares, address liquidityPool) public view auth returns (uint256 assets) {\n        (uint8 currencyDecimals, uint8 trancheTokenDecimals) = _getPoolDecimals(liquidityPool);\n        uint128 shares = _toUint128(_shares);\n\n        assets = shares.mulDiv(\n            LiquidityPoolLike(liquidityPool).latestPrice(),\n            10 ** (PRICE_DECIMALS + trancheTokenDecimals - currencyDecimals),\n            MathLib.Rounding.Down\n        );\n    }\n\n    /// @return currencyAmount is type of uin256 to support the EIP4626 Liquidity Pool interface\n    function maxDeposit(address user, address liquidityPool) public view returns (uint256 currencyAmount) {\n        currencyAmount = uint256(orderbook[user][liquidityPool].maxDeposit);\n    }\n\n    /// @return trancheTokenAmount type of uin256 to support the EIP4626 Liquidity Pool interface\n    function maxMint(address user, address liquidityPool) public view returns (uint256 trancheTokenAmount) {\n        trancheTokenAmount = uint256(orderbook[user][liquidityPool].maxMint);\n    }\n\n    /// @return currencyAmount type of uin256 to support the EIP4626 Liquidity Pool interface\n    function maxWithdraw(address user, address liquidityPool) public view returns (uint256 currencyAmount) {\n        currencyAmount = uint256(orderbook[user][liquidityPool].maxWithdraw);\n    }\n\n    /// @return trancheTokenAmount type of uin256 to support the EIP4626 Liquidity Pool interface\n    function maxRedeem(address user, address liquidityPool) public view returns (uint256 trancheTokenAmount) {\n        trancheTokenAmount = uint256(orderbook[user][liquidityPool].maxRedeem);\n    }\n\n    /// @return trancheTokenAmount is type of uin256 to support the EIP4626 Liquidity Pool interface\n    function previewDeposit(address user, address liquidityPool, uint256 _currencyAmount)\n        public\n        view\n        returns (uint256 trancheTokenAmount)\n    {\n        uint128 currencyAmount = _toUint128(_currencyAmount);\n        uint256 depositPrice = calculateDepositPrice(user, liquidityPool);\n        if (depositPrice == 0) return 0;\n\n        trancheTokenAmount = uint256(_calculateTrancheTokenAmount(currencyAmount, liquidityPool, depositPrice));\n    }\n\n    /// @return currencyAmount is type of uin256 to support the EIP4626 Liquidity Pool interface\n    function previewMint(address user, address liquidityPool, uint256 _trancheTokenAmount)\n        public\n        view\n        returns (uint256 currencyAmount)\n    {\n        uint128 trancheTokenAmount = _toUint128(_trancheTokenAmount);\n        uint256 depositPrice = calculateDepositPrice(user, liquidityPool);\n        if (depositPrice == 0) return 0;\n\n        currencyAmount = uint256(_calculateCurrencyAmount(trancheTokenAmount, liquidityPool, depositPrice));\n    }\n\n    /// @return trancheTokenAmount is type of uin256 to support the EIP4626 Liquidity Pool interface\n    function previewWithdraw(address user, address liquidityPool, uint256 _currencyAmount)\n        public\n        view\n        returns (uint256 trancheTokenAmount)\n    {\n        uint128 currencyAmount = _toUint128(_currencyAmount);\n        uint256 redeemPrice = calculateRedeemPrice(user, liquidityPool);\n        if (redeemPrice == 0) return 0;\n\n        trancheTokenAmount = uint256(_calculateTrancheTokenAmount(currencyAmount, liquidityPool, redeemPrice));\n    }\n\n    /// @return currencyAmount is type of uin256 to support the EIP4626 Liquidity Pool interface\n    function previewRedeem(address user, address liquidityPool, uint256 _trancheTokenAmount)\n        public\n        view\n        returns (uint256 currencyAmount)\n    {\n        uint128 trancheTokenAmount = _toUint128(_trancheTokenAmount);\n        uint256 redeemPrice = calculateRedeemPrice(user, liquidityPool);\n        if (redeemPrice == 0) return 0;\n\n        currencyAmount = uint256(_calculateCurrencyAmount(trancheTokenAmount, liquidityPool, redeemPrice));\n    }\n\n    // --- Liquidity Pool processing functions ---\n    /// @notice Processes user's currency deposit / investment after the epoch has been executed on Centrifuge.\n    ///         In case user's invest order was fullfilled (partially or in full) on Centrifuge during epoch execution MaxDeposit and MaxMint are increased and tranche tokens can be transferred to user's wallet on calling processDeposit.\n    ///         Note: The currency required to fullfill the invest order is already locked in escrow upon calling requestDeposit.\n    /// @dev    trancheTokenAmount return value is type of uint256 to be compliant with EIP4626 LiquidityPool interface\n    /// @return trancheTokenAmount the amount of tranche tokens transferred to the user's wallet after successful deposit.\n    function processDeposit(address user, uint256 currencyAmount) public auth returns (uint256 trancheTokenAmount) {\n        address liquidityPool = msg.sender;\n        uint128 _currencyAmount = _toUint128(currencyAmount);\n        require(\n            (_currencyAmount <= orderbook[user][liquidityPool].maxDeposit && _currencyAmount != 0),\n            \"InvestmentManager/amount-exceeds-deposit-limits\"\n        );\n\n        uint256 depositPrice = calculateDepositPrice(user, liquidityPool);\n        require(depositPrice != 0, \"LiquidityPool/deposit-token-price-0\");\n\n        uint128 _trancheTokenAmount = _calculateTrancheTokenAmount(_currencyAmount, liquidityPool, depositPrice);\n        _deposit(_trancheTokenAmount, _currencyAmount, liquidityPool, user);\n        trancheTokenAmount = uint256(_trancheTokenAmount);\n    }\n\n    /// @notice Processes user's currency deposit / investment after the epoch has been executed on Centrifuge.\n    ///         In case user's invest order was fullfilled on Centrifuge during epoch execution MaxDeposit and MaxMint are increased\n    ///         and trancheTokens can be transferred to user's wallet on calling processDeposit or processMint.\n    ///         Note: The currency amount required to fullfill the invest order is already locked in escrow upon calling requestDeposit.\n    ///         Note: The tranche tokens are already minted on collectInvest and are deposited to the escrow account until the users calls mint, or deposit.\n    /// @dev    currencyAmount return value is type of uint256 to be compliant with EIP4626 LiquidityPool interface\n    /// @return currencyAmount the amount of liquidityPool assets invested and locked in escrow in order\n    ///         for the amount of tranche tokens received after successful investment into the pool.\n    function processMint(address user, uint256 trancheTokenAmount) public auth returns (uint256 currencyAmount) {\n        address liquidityPool = msg.sender;\n        uint128 _trancheTokenAmount = _toUint128(trancheTokenAmount);\n        require(\n            (_trancheTokenAmount <= orderbook[user][liquidityPool].maxMint && _trancheTokenAmount != 0),\n            \"InvestmentManager/amount-exceeds-mint-limits\"\n        );\n\n        uint256 depositPrice = calculateDepositPrice(user, liquidityPool);\n        require(depositPrice != 0, \"LiquidityPool/deposit-token-price-0\");\n\n        uint128 _currencyAmount = _calculateCurrencyAmount(_trancheTokenAmount, liquidityPool, depositPrice);\n        _deposit(_trancheTokenAmount, _currencyAmount, liquidityPool, user);\n        currencyAmount = uint256(_currencyAmount);\n    }\n\n    function _deposit(uint128 trancheTokenAmount, uint128 currencyAmount, address liquidityPool, address user)\n        internal\n    {\n        LiquidityPoolLike lPool = LiquidityPoolLike(liquidityPool);\n\n        _decreaseDepositLimits(user, liquidityPool, currencyAmount, trancheTokenAmount); // decrease the possible deposit limits\n        require(lPool.checkTransferRestriction(msg.sender, user, 0), \"InvestmentManager/trancheTokens-not-a-member\");\n        require(\n            lPool.transferFrom(address(escrow), user, trancheTokenAmount),\n            \"InvestmentManager/trancheTokens-transfer-failed\"\n        );\n\n        emit DepositProcessed(liquidityPool, user, currencyAmount);\n    }\n\n    /// @dev    Processes user's tranche Token redemption after the epoch has been executed on Centrifuge.\n    ///         In case user's redempion order was fullfilled on Centrifuge during epoch execution MaxRedeem and MaxWithdraw\n    ///         are increased and LiquidityPool currency can be transferred to user's wallet on calling processRedeem or processWithdraw.\n    ///         Note: The trancheTokenAmount required to fullfill the redemption order was already locked in escrow\n    ///         upon calling requestRedeem and burned upon collectRedeem.\n    /// @notice currencyAmount return value is type of uint256 to be compliant with EIP4626 LiquidityPool interface\n    /// @return currencyAmount the amount of liquidityPool assets received for the amount of redeemed/burned tranche tokens.\n    function processRedeem(uint256 trancheTokenAmount, address receiver, address user)\n        public\n        auth\n        returns (uint256 currencyAmount)\n    {\n        address liquidityPool = msg.sender;\n        uint128 _trancheTokenAmount = _toUint128(trancheTokenAmount);\n        require(\n            (_trancheTokenAmount <= orderbook[user][liquidityPool].maxRedeem && _trancheTokenAmount != 0),\n            \"InvestmentManager/amount-exceeds-redeem-limits\"\n        );\n\n        uint256 redeemPrice = calculateRedeemPrice(user, liquidityPool);\n        require(redeemPrice != 0, \"LiquidityPool/redeem-token-price-0\");\n\n        uint128 _currencyAmount = _calculateCurrencyAmount(_trancheTokenAmount, liquidityPool, redeemPrice);\n        _redeem(_trancheTokenAmount, _currencyAmount, liquidityPool, receiver, user);\n        currencyAmount = uint256(_currencyAmount);\n    }\n\n    /// @dev    Processes user's tranche token redemption after the epoch has been executed on Centrifuge.\n    ///         In case user's redempion order was fullfilled on Centrifuge during epoch execution MaxRedeem and MaxWithdraw\n    ///         are increased and LiquidityPool currency can be transferred to user's wallet on calling processRedeem or processWithdraw.\n    ///         Note: The trancheTokenAmount required to fullfill the redemption order was already locked in escrow upon calling requestRedeem and burned upon collectRedeem.\n    /// @notice trancheTokenAmount return value is type of uint256 to be compliant with EIP4626 LiquidityPool interface\n    /// @return trancheTokenAmount the amount of trancheTokens redeemed/burned required to receive the currencyAmount payout/withdrawel.\n    function processWithdraw(uint256 currencyAmount, address receiver, address user)\n        public\n        auth\n        returns (uint256 trancheTokenAmount)\n    {\n        address liquidityPool = msg.sender;\n        uint128 _currencyAmount = _toUint128(currencyAmount);\n        require(\n            (_currencyAmount <= orderbook[user][liquidityPool].maxWithdraw && _currencyAmount != 0),\n            \"InvestmentManager/amount-exceeds-withdraw-limits\"\n        );\n\n        uint256 redeemPrice = calculateRedeemPrice(user, liquidityPool);\n        require(redeemPrice != 0, \"LiquidityPool/redeem-token-price-0\");\n\n        uint128 _trancheTokenAmount = _calculateTrancheTokenAmount(_currencyAmount, liquidityPool, redeemPrice);\n        _redeem(_trancheTokenAmount, _currencyAmount, liquidityPool, receiver, user);\n        trancheTokenAmount = uint256(_trancheTokenAmount);\n    }\n\n    function _redeem(\n        uint128 trancheTokenAmount,\n        uint128 currencyAmount,\n        address liquidityPool,\n        address receiver,\n        address user\n    ) internal {\n        LiquidityPoolLike lPool = LiquidityPoolLike(liquidityPool);\n\n        _decreaseRedemptionLimits(user, liquidityPool, currencyAmount, trancheTokenAmount); // decrease the possible deposit limits\n        userEscrow.transferOut(lPool.asset(), user, receiver, currencyAmount);\n\n        emit RedemptionProcessed(liquidityPool, user, trancheTokenAmount);\n    }\n\n    // --- Helpers ---\n    function calculateDepositPrice(address user, address liquidityPool) public view returns (uint256 depositPrice) {\n        LPValues storage lpValues = orderbook[user][liquidityPool];\n        if (lpValues.maxMint == 0) {\n            return 0;\n        }\n\n        depositPrice = _calculatePrice(lpValues.maxDeposit, lpValues.maxMint, liquidityPool);\n    }\n\n    function calculateRedeemPrice(address user, address liquidityPool) public view returns (uint256 redeemPrice) {\n        LPValues storage lpValues = orderbook[user][liquidityPool];\n        if (lpValues.maxRedeem == 0) {\n            return 0;\n        }\n\n        redeemPrice = _calculatePrice(lpValues.maxWithdraw, lpValues.maxRedeem, liquidityPool);\n    }\n\n    function _calculatePrice(uint128 currencyAmount, uint128 trancheTokenAmount, address liquidityPool)\n        public\n        view\n        returns (uint256 depositPrice)\n    {\n        (uint8 currencyDecimals, uint8 trancheTokenDecimals) = _getPoolDecimals(liquidityPool);\n        uint256 currencyAmountInPriceDecimals = _toPriceDecimals(currencyAmount, currencyDecimals, liquidityPool);\n        uint256 trancheTokenAmountInPriceDecimals =\n            _toPriceDecimals(trancheTokenAmount, trancheTokenDecimals, liquidityPool);\n\n        depositPrice = currencyAmountInPriceDecimals.mulDiv(\n            10 ** PRICE_DECIMALS, trancheTokenAmountInPriceDecimals, MathLib.Rounding.Down\n        );\n    }\n\n    function _updateLiquidityPoolPrice(address liquidityPool, uint128 currencyPayout, uint128 trancheTokensPayout)\n        internal\n    {\n        uint128 price = _toUint128(_calculatePrice(currencyPayout, trancheTokensPayout, liquidityPool));\n        LiquidityPoolLike(liquidityPool).updatePrice(price);\n    }\n\n    function _calculateTrancheTokenAmount(uint128 currencyAmount, address liquidityPool, uint256 price)\n        internal\n        view\n        returns (uint128 trancheTokenAmount)\n    {\n        (uint8 currencyDecimals, uint8 trancheTokenDecimals) = _getPoolDecimals(liquidityPool);\n\n        uint256 currencyAmountInPriceDecimals = _toPriceDecimals(currencyAmount, currencyDecimals, liquidityPool).mulDiv(\n            10 ** PRICE_DECIMALS, price, MathLib.Rounding.Down\n        );\n\n        trancheTokenAmount = _fromPriceDecimals(currencyAmountInPriceDecimals, trancheTokenDecimals, liquidityPool);\n    }\n\n    function _calculateCurrencyAmount(uint128 trancheTokenAmount, address liquidityPool, uint256 price)\n        internal\n        view\n        returns (uint128 currencyAmount)\n    {\n        (uint8 currencyDecimals, uint8 trancheTokenDecimals) = _getPoolDecimals(liquidityPool);\n\n        uint256 currencyAmountInPriceDecimals = _toPriceDecimals(\n            trancheTokenAmount, trancheTokenDecimals, liquidityPool\n        ).mulDiv(price, 10 ** PRICE_DECIMALS, MathLib.Rounding.Down);\n\n        currencyAmount = _fromPriceDecimals(currencyAmountInPriceDecimals, currencyDecimals, liquidityPool);\n    }\n\n    function _decreaseDepositLimits(address user, address liquidityPool, uint128 _currency, uint128 trancheTokens)\n        internal\n    {\n        LPValues storage lpValues = orderbook[user][liquidityPool];\n        if (lpValues.maxDeposit < _currency) {\n            lpValues.maxDeposit = 0;\n        } else {\n            lpValues.maxDeposit = lpValues.maxDeposit - _currency;\n        }\n        if (lpValues.maxMint < trancheTokens) {\n            lpValues.maxMint = 0;\n        } else {\n            lpValues.maxMint = lpValues.maxMint - trancheTokens;\n        }\n    }\n\n    function _decreaseRedemptionLimits(address user, address liquidityPool, uint128 _currency, uint128 trancheTokens)\n        internal\n    {\n        LPValues storage lpValues = orderbook[user][liquidityPool];\n        if (lpValues.maxWithdraw < _currency) {\n            lpValues.maxWithdraw = 0;\n        } else {\n            lpValues.maxWithdraw = lpValues.maxWithdraw - _currency;\n        }\n        if (lpValues.maxRedeem < trancheTokens) {\n            lpValues.maxRedeem = 0;\n        } else {\n            lpValues.maxRedeem = lpValues.maxRedeem - trancheTokens;\n        }\n    }\n\n    function _isAllowedToInvest(uint64 poolId, bytes16 trancheId, address currency, address user)\n        internal\n        returns (bool)\n    {\n        address liquidityPool = poolManager.getLiquidityPool(poolId, trancheId, currency);\n        require(liquidityPool != address(0), \"InvestmentManager/unknown-liquidity-pool\");\n        require(\n            LiquidityPoolLike(liquidityPool).checkTransferRestriction(address(0), user, 0),\n            \"InvestmentManager/not-a-member\"\n        );\n        return true;\n    }\n\n    /// @dev    Safe type conversion from uint256 to uint128. Revert if value is too big to be stored with uint128. Avoid data loss.\n    /// @return value - safely converted without data loss\n    function _toUint128(uint256 _value) internal pure returns (uint128 value) {\n        if (_value > type(uint128).max) {\n            revert(\"InvestmentManager/uint128-overflow\");\n        } else {\n            value = uint128(_value);\n        }\n    }\n\n    /// @dev    When converting currency to tranche token amounts using the price,\n    ///         all values are normalized to PRICE_DECIMALS\n    function _toPriceDecimals(uint128 _value, uint8 decimals, address liquidityPool)\n        internal\n        view\n        returns (uint256 value)\n    {\n        if (PRICE_DECIMALS == decimals) return uint256(_value);\n        value = uint256(_value) * 10 ** (PRICE_DECIMALS - decimals);\n    }\n\n    /// @dev    Convert decimals of the value from the price decimals back to the intended decimals\n    function _fromPriceDecimals(uint256 _value, uint8 decimals, address liquidityPool)\n        internal\n        view\n        returns (uint128 value)\n    {\n        if (PRICE_DECIMALS == decimals) return _toUint128(_value);\n        value = _toUint128(_value / 10 ** (PRICE_DECIMALS - decimals));\n    }\n\n    /// @dev    Return the currency decimals and the tranche token decimals for a given liquidityPool\n    function _getPoolDecimals(address liquidityPool)\n        internal\n        view\n        returns (uint8 currencyDecimals, uint8 trancheTokenDecimals)\n    {\n        currencyDecimals = ERC20Like(LiquidityPoolLike(liquidityPool).asset()).decimals();\n        trancheTokenDecimals = LiquidityPoolLike(liquidityPool).decimals();\n    }\n}"
}