Users might immediately be liquidated after position opening leading to a loss of CVA and Liquidation fee
The insolvency check (isSolventAfterOpenPosition) within the `openPosition` function does not consider the locked balance adjustment, causing the user account to become insolvent immediately after the position is opened. As a result, the affected users will lose their CVA and liquidation fee locked in their accounts.\\n```\\nFile: PartyBFacetImpl.sol\\n    function openPosition(\\n        uint256 quoteId,\\n        uint256 filledAmount,\\n        uint256 openedPrice,\\n        PairUpnlAndPriceSig memory upnlSig\\n    ) internal returns (uint256 currentId) {\\n..SNIP..\\n        LibSolvency.isSolventAfterOpenPosition(quoteId, filledAmount, upnlSig);\\n\\n        accountLayout.partyANonces[quote.partyA] += 1;\\n        accountLayout.partyBNonces[quote.partyB][quote.partyA] += 1;\\n        quote.modifyTimestamp = block.timestamp;\\n\\n        LibQuote.removeFromPendingQuotes(quote);\\n\\n        if (quote.quantity == filledAmount) {\\n            accountLayout.pendingLockedBalances[quote.partyA].subQuote(quote);\\n            accountLayout.partyBPendingLockedBalances[quote.partyB][quote.partyA].subQuote(quote);\\n\\n            if (quote.orderType == OrderType.LIMIT) {\\n                quote.lockedValues.mul(openedPrice).div(quote.requestedOpenPrice);\\n            }\\n            accountLayout.lockedBalances[quote.partyA].addQuote(quote);\\n            accountLayout.partyBLockedBalances[quote.partyB][quote.partyA].addQuote(quote);\\n        }\\n```\\n\\nThe leverage of a position is computed based on the following formula.\\n$leverage = \\frac{price \\times quantity}{lockedValues.total()}$\\nWhen opening a position, there is a possibility that the leverage might change because the locked values and quantity are fixed, but it could get filled with a different market price compared to the one at the moment the user requested. Thus, the purpose of Line 163 above is to adjust the locked values to maintain a fixed leverage. After the adjustment, the locked value might be higher or lower.\\nThe issue is that the insolvency check at Line 150 is performed before the adjustment is made.\\nAssume that the adjustment in Line 163 cause the locked values to increase. The insolvency check (isSolventAfterOpenPosition) at Line 150 will be performed with old or unadjusted locked values that are smaller than expected. Since smaller locked values mean that there will be more available balance, this might cause the system to miscalculate that an account is not liquidatable, but in fact, it is actually liquidatable once the adjusted increased locked value is taken into consideration.\\nIn this case, once the position is opened, the user account is immediately underwater and can be liquidated.\\nThe issue will occur in the "complete fill" path and "partial fill" path since both paths adjust the locked values to maintain a fixed leverage. The "complete fill" path adjusts the locked values at Line 185
Consider performing the insolvency check with the updated adjusted locked values.
Users might become liquidatable immediately after opening a position due to an incorrect insolvency check within the `openPosition`, which erroneously reports that the account will still be healthy after opening the position, while in reality, it is not. As a result, the affected users will lose their CVA and liquidation fee locked in their accounts.
```\\nFile: PartyBFacetImpl.sol\\n    function openPosition(\\n        uint256 quoteId,\\n        uint256 filledAmount,\\n        uint256 openedPrice,\\n        PairUpnlAndPriceSig memory upnlSig\\n    ) internal returns (uint256 currentId) {\\n..SNIP..\\n        LibSolvency.isSolventAfterOpenPosition(quoteId, filledAmount, upnlSig);\\n\\n        accountLayout.partyANonces[quote.partyA] += 1;\\n        accountLayout.partyBNonces[quote.partyB][quote.partyA] += 1;\\n        quote.modifyTimestamp = block.timestamp;\\n\\n        LibQuote.removeFromPendingQuotes(quote);\\n\\n        if (quote.quantity == filledAmount) {\\n            accountLayout.pendingLockedBalances[quote.partyA].subQuote(quote);\\n            accountLayout.partyBPendingLockedBalances[quote.partyB][quote.partyA].subQuote(quote);\\n\\n            if (quote.orderType == OrderType.LIMIT) {\\n                quote.lockedValues.mul(openedPrice).div(quote.requestedOpenPrice);\\n            }\\n            accountLayout.lockedBalances[quote.partyA].addQuote(quote);\\n            accountLayout.partyBLockedBalances[quote.partyB][quote.partyA].addQuote(quote);\\n        }\\n```\\n