Submitted by bin2chen
s_grossPremiumLast[] definitions are as follows:
A critical rule: if there is a change in totalLiquidity, we must recalculate this value.
When Pool.mintOptions(), s_grossPremiumLast[chunkKey] will increase.
Step: mintOptions()->_mintInSFPMAndUpdateCollateral()->_updateSettlementPostMint()
When Pool.burnOptions()s_grossPremiumLast[chunkKey] will decrease
burnOptions()->_burnAndHandleExercise()->_updateSettlementPostBurn()
The issue lies within _updateSettlementPostBurn(), where it adds a condition that if (LeftRightSigned.unwrap(legPremia) != 0) must be met for s_grossPremiumLast[chunkKey] to decrease.
This results in not recalculating s_grossPremiumLast[chunkKey] even when totalLiquidity changes.
For example, in the same block, if a user executes mintOptions(), s_grossPremiumLast[chunkKey] increases by 50. Immediately after, executing burnOptions() doesnt decrease s_grossPremiumLast[chunkKey] by 50 because legPremia == 0.
The following code demonstrates this scenario, where s_grossPremiumLast[chunkKey] keeps increasing, so last gross accumulated keeps decreasing.
Due to the incorrect accounting of s_grossPremiumLast[chunkKey], the calculation in _getAvailablePremium() is also incorrect. This results in inaccuracies in the amount of premium received by the seller when closing their position.
Regardless of the value of legPremia, it should recalculate s_grossPremiumLast[chunkKey] when long == 0.
Context
dyedm1 (Panoptic) confirmed
