diff --git a/contracts/libraries/Position.sol b/contracts/libraries/Position.sol index 22f500a7..945d9eba 100644 --- a/contracts/libraries/Position.sol +++ b/contracts/libraries/Position.sol @@ -83,7 +83,7 @@ library Position { /// @notice Whether the position exists /// @dev Is false if position has been liquidated or fraction remaining == 0 function exists(Info memory self) internal pure returns (bool exists_) { - return (!self.liquidated && self.fractionRemaining > 0); + return (self.fractionRemaining > 0); } /*/////////////////////////////////////////////////////////////// @@ -102,7 +102,6 @@ library Position { pure returns (uint16) { - require(fractionRemoved <= ONE, "OVV1:fraction>max"); uint256 fractionRemaining = _fractionRemaining(self).mulDown(ONE - fractionRemoved); return fractionRemaining.toUint16Fixed(); } @@ -163,8 +162,7 @@ library Position { /// @notice accounting for amount of position remaining /// @dev use mulUp to avoid rounding leftovers on unwind function notionalInitial(Info memory self, uint256 fraction) internal pure returns (uint256) { - uint256 fractionRemaining = _fractionRemaining(self); - uint256 notionalForRemaining = _notionalInitial(self).mulUp(fractionRemaining); + uint256 notionalForRemaining = _notionalInitial(self).mulUp(_fractionRemaining(self)); return notionalForRemaining.mulUp(fraction); } @@ -172,8 +170,7 @@ library Position { /// @notice accounting for amount of position remaining /// @dev use mulUp to avoid rounding leftovers on unwind function oiInitial(Info memory self, uint256 fraction) internal pure returns (uint256) { - uint256 fractionRemaining = _fractionRemaining(self); - uint256 oiInitialForRemaining = _oiInitial(self).mulUp(fractionRemaining); + uint256 oiInitialForRemaining = _oiInitial(self).mulUp(_fractionRemaining(self)); return oiInitialForRemaining.mulUp(fraction); } @@ -190,8 +187,7 @@ library Position { /// @notice for amount of position remaining /// @dev use mulUp to avoid rounding leftovers on unwind function debtInitial(Info memory self, uint256 fraction) internal pure returns (uint256) { - uint256 fractionRemaining = _fractionRemaining(self); - uint256 debtForRemaining = _debtInitial(self).mulUp(fractionRemaining); + uint256 debtForRemaining = _debtInitial(self).mulUp(_fractionRemaining(self)); return debtForRemaining.mulUp(fraction); } @@ -317,7 +313,7 @@ library Position { uint256 fraction = ONE; uint256 posNotionalInitial = notionalInitial(self, fraction); - if (self.liquidated || self.fractionRemaining == 0) { + if (self.fractionRemaining == 0) { // already been liquidated or doesn't exist // latter covers edge case of val == 0 and MM + liq fee == 0 return false; diff --git a/tests/libraries/position/test_fraction.py b/tests/libraries/position/test_fraction.py index 2ced02ed..77707cf2 100644 --- a/tests/libraries/position/test_fraction.py +++ b/tests/libraries/position/test_fraction.py @@ -1,4 +1,3 @@ -from brownie import reverts from brownie.test import given, strategy from decimal import Decimal @@ -69,36 +68,3 @@ def test_updated_fraction_remaining(position, fraction_remaining, expect = updated_fraction_remaining actual = position.updatedFractionRemaining(pos, fraction_removed_256) assert expect == actual - - -def test_updated_fraction_remaining_reverts_when_gt_max(position): - notional = 10000000000000000000 # 10 - debt = 2000000000000000000 # 2 - is_long = True - liquidated = False - fraction_remaining = 9000 # 0.9 - - mid_price = 100000000000000000000 # 100 - entry_price = 101000000000000000000 # 101 - - mid_tick = price_to_tick(mid_price) - entry_tick = price_to_tick(entry_price) - - oi = int((notional / mid_price) * 1000000000000000000) # 0.1 - shares_to_oi_ratio = 800000000000000000 # 0.8 - oi_shares = int(Decimal(oi) * Decimal(shares_to_oi_ratio) - / Decimal(1e18)) # 0.08 - - pos = (notional, debt, mid_tick, entry_tick, is_long, - liquidated, oi_shares, fraction_remaining) - - # check fails when greater than ONE - fraction_removed = 1000000000000000001 # 1 greater than ONE (18 decimals) - with reverts("OVV1:fraction>max"): - position.updatedFractionRemaining(pos, fraction_removed) - - # check succeeds when equal to ONE - fraction_removed = 1000000000000000000 - expect = 0 - actual = position.updatedFractionRemaining(pos, fraction_removed) - assert expect == actual