diff --git a/contracts/OverlayV1Market.sol b/contracts/OverlayV1Market.sol index 6da34c96..f76f0afa 100644 --- a/contracts/OverlayV1Market.sol +++ b/contracts/OverlayV1Market.sol @@ -342,18 +342,7 @@ contract OverlayV1Market is IOverlayV1Market { // subtract unwound open interest from the side's aggregate oi value // and decrease number of oi shares issued - // NOTE: use subFloor to avoid reverts with oi rounding issues - if (pos.isLong) { - oiLong = oiLong.subFloor( - pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) - ); - oiLongShares -= pos.oiSharesCurrent(fraction); - } else { - oiShort = oiShort.subFloor( - pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) - ); - oiShortShares -= pos.oiSharesCurrent(fraction); - } + _reduceOIAndOIShares(pos, fraction); // register the amount to be minted/burned // capPayoff prevents overflow reverts with int256 cast @@ -444,18 +433,7 @@ contract OverlayV1Market is IOverlayV1Market { // subtract liquidated open interest from the side's aggregate oi value // and decrease number of oi shares issued - // NOTE: use subFloor to avoid reverts with oi rounding issues - if (pos.isLong) { - oiLong = oiLong.subFloor( - pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) - ); - oiLongShares -= pos.oiSharesCurrent(fraction); - } else { - oiShort = oiShort.subFloor( - pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) - ); - oiShortShares -= pos.oiSharesCurrent(fraction); - } + _reduceOIAndOIShares(pos, fraction); // register the amount to be burned _registerMintOrBurn(int256(value) - int256(cost) - int256(marginToBurn)); @@ -748,6 +726,23 @@ contract OverlayV1Market is IOverlayV1Market { return minted; } + /// @notice subtract open interest from the side's aggregate oi value + /// @notice and decrease number of oi shares issued + function _reduceOIAndOIShares(Position.Info memory pos, uint256 fraction) internal { + // NOTE: use subFloor to avoid reverts with oi rounding issues + if (pos.isLong) { + oiLong = oiLong.subFloor( + pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) + ); + oiLongShares -= pos.oiSharesCurrent(fraction); + } else { + oiShort = oiShort.subFloor( + pos.oiCurrent(fraction, oiTotalOnSide, oiTotalSharesOnSide) + ); + oiShortShares -= pos.oiSharesCurrent(fraction); + } + } + /// @notice Updates the market for funding changes to open interest /// @notice since last time market was interacted with function _payFunding() private {