Submitted by rvierdiiev.
Position._borrowLimit doesnt use exisiting collateral in case if user doesnt have any _bathToken.
Position._borrowLimit function is used to calculate how many times user needs to make borrow loop and how many percent of maximum allowed amount to borrow. https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L526-L583
Inside the while loop there is one interesting thing: if (_minted != 0).
If this true, that means that the user currently has some amount of _bathToken, which means that they already have some collateral that can be used to borrow on it. The _maxBorrow(_bathToken) function is called in order to know how many collateral user has and what is the max amount they can borrow using that collateral.
But in this case, if this if (_minted != 0) is not true, it means that the user currently doesnt have any _bathToken, then _maxBorrow(_bathToken) will not be called. However, the user still can have collateral other than _bathToken token.
In this case, that collateral also should be used to borrow on it, but its ignored.
Scenario:
1.The user opened position using bathUSDC and they currently have some amount as collateral inside bathUSDC.
2.Then they open positions using bathETH and in this case their bathUSDC collateral is not used.
VsCode
You should check if the user has liquidity
(uint256 _err, uint256 _liq, uint256 _shortfall) = comptroller.getAccountLiquidity(address(this));
In this case if _liq is not 0, then you should call _maxBorrow(_bathToken) and use that collateral.
daoio (Rubicon) confirmed
