diff --git a/.gas-snapshot b/.gas-snapshot index 8ac48b9b9..272890086 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,21 +1,21 @@ -ClaimsTest:testCanBurn(uint256) (runs: 100, μ: 32978, ~: 33309) -ClaimsTest:testCanTransfer(uint256) (runs: 100, μ: 50744, ~: 51836) +ClaimsTest:testCanBurn(uint256) (runs: 100, μ: 32978, ~: 33307) +ClaimsTest:testCanTransfer(uint256) (runs: 100, μ: 50745, ~: 51838) ClaimsTest:testCanTransferToZeroAddress() (gas: 51088) ClaimsTest:testCatchesOverflowOnTransfer() (gas: 45550) ClaimsTest:testCatchesUnderflowOnBurn(uint256) (runs: 100, μ: 39917, ~: 40912) ClaimsTest:testCatchesUnderflowOnTransfer(uint256) (runs: 100, μ: 40054, ~: 41049) ClaimsTest:testTransferToClaimsContractFails() (gas: 36392) FeesTest:testCollectFees() (gas: 609252) -FeesTest:testHookWithdrawFeeProtocolWithdrawFee(uint16,uint16) (runs: 100, μ: 484402, ~: 490490) -FeesTest:testInitializeAllFees(uint16,uint16,uint16,uint16) (runs: 100, μ: 140840, ~: 136939) +FeesTest:testHookWithdrawFeeProtocolWithdrawFee(uint16,uint16) (runs: 100, μ: 483318, ~: 490490) +FeesTest:testInitializeAllFees(uint16,uint16,uint16,uint16) (runs: 100, μ: 140779, ~: 136939) FeesTest:testInitializeBothHookFee(uint16,uint16) (runs: 100, μ: 86363, ~: 93440) FeesTest:testInitializeFailsNoHook() (gas: 20233) -FeesTest:testInitializeHookProtocolSwapFee(uint16,uint16) (runs: 100, μ: 103488, ~: 109343) -FeesTest:testInitializeHookSwapFee(uint16) (runs: 100, μ: 68387, ~: 70884) -FeesTest:testInitializeHookWithdrawFee(uint16) (runs: 100, μ: 68200, ~: 70924) +FeesTest:testInitializeHookProtocolSwapFee(uint16,uint16) (runs: 100, μ: 103151, ~: 109343) +FeesTest:testInitializeHookSwapFee(uint16) (runs: 100, μ: 68841, ~: 70884) +FeesTest:testInitializeHookWithdrawFee(uint16) (runs: 100, μ: 68881, ~: 70924) FeesTest:testInitializeWithSwapProtocolFeeAndHookFeeDifferentDirections() (gas: 568917) -FeesTest:testNoHookProtocolFee(uint16,uint16) (runs: 100, μ: 760034, ~: 767656) -FeesTest:testProtocolFeeOnWithdrawalRemainsZeroIfNoHookWithdrawalFeeSet(uint16,uint16) (runs: 100, μ: 465157, ~: 466748) +FeesTest:testNoHookProtocolFee(uint16,uint16) (runs: 100, μ: 759548, ~: 759548) +FeesTest:testProtocolFeeOnWithdrawalRemainsZeroIfNoHookWithdrawalFeeSet(uint16,uint16) (runs: 100, μ: 464998, ~: 466748) FeesTest:testProtocolSwapFeeAndHookSwapFeeSameDirection() (gas: 589308) FeesTest:testSwapWithProtocolFeeAllAndHookFeeAllButOnlySwapFlag() (gas: 638435) FullMathTest:testResultOverflowsHelper() (gas: 3964) @@ -69,16 +69,16 @@ HooksTest:testValidateHookAddressBeforeInitialize(uint152) (runs: 100, μ: 1837, HooksTest:testValidateHookAddressBeforeInitializeAfterModify(uint152) (runs: 100, μ: 1784, ~: 1784) HooksTest:testValidateHookAddressBeforeModify(uint152) (runs: 100, μ: 1863, ~: 1863) HooksTest:testValidateHookAddressBeforeSwap(uint152) (runs: 100, μ: 1856, ~: 1856) -HooksTest:testValidateHookAddressFailsAllHooks(uint152,uint8) (runs: 100, μ: 4798, ~: 4729) -HooksTest:testValidateHookAddressFailsNoHooks(uint152,uint8) (runs: 100, μ: 4797, ~: 4729) +HooksTest:testValidateHookAddressFailsAllHooks(uint152,uint8) (runs: 100, μ: 4786, ~: 4729) +HooksTest:testValidateHookAddressFailsNoHooks(uint152,uint8) (runs: 100, μ: 4807, ~: 4776) HooksTest:testValidateHookAddressNoHooks(uint152) (runs: 100, μ: 1845, ~: 1845) LockersLibrary:testLockerLengthAndNonzeroDeltaCount() (gas: 52392) LockersLibrary:test_clear(address[]) (runs: 100, μ: 114024, ~: 111101) LockersLibrary:test_decrementNonzeroDeltaCount() (gas: 1157) -LockersLibrary:test_decrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 119938, ~: 68325) +LockersLibrary:test_decrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 111910, ~: 52557) LockersLibrary:test_getCurrentLocker_multipleAddressesFuzz(address[]) (runs: 100, μ: 273024, ~: 265967) LockersLibrary:test_incrementNonzeroDeltaCount() (gas: 807) -LockersLibrary:test_incrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 71511, ~: 40716) +LockersLibrary:test_incrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 66721, ~: 31308) LockersLibrary:test_pop() (gas: 1770) LockersLibrary:test_pop_multipleAddressesFuzz(address[]) (runs: 100, μ: 240601, ~: 234397) LockersLibrary:test_push() (gas: 1421) @@ -86,21 +86,21 @@ LockersLibrary:test_push_multipleAddressesFuzz(address[]) (runs: 100, μ: 250569 OwnedTest:testConstructor(address) (runs: 100, μ: 166413, ~: 166413) OwnedTest:testSetOwnerFromNonOwner(address,address) (runs: 100, μ: 167372, ~: 167571) OwnedTest:testSetOwnerFromOwner(address,address) (runs: 100, μ: 169642, ~: 169642) -PoolManagerInitializeTest:test_initialize((address,address,uint24,int24,address),uint160) (runs: 100, μ: 21815, ~: 15963) +PoolManagerInitializeTest:test_initialize((address,address,uint24,int24,address),uint160) (runs: 100, μ: 21805, ~: 15963) PoolManagerInitializeTest:test_initialize_failsIfTickSpaceNeg(uint160) (runs: 100, μ: 20764, ~: 20764) PoolManagerInitializeTest:test_initialize_failsIfTickSpaceTooLarge(uint160) (runs: 100, μ: 21747, ~: 21747) PoolManagerInitializeTest:test_initialize_failsIfTickSpaceZero(uint160) (runs: 100, μ: 20801, ~: 20801) PoolManagerInitializeTest:test_initialize_failsWithIncorrectSelectors() (gas: 1016152) -PoolManagerInitializeTest:test_initialize_fetchFeeWhenController(uint160) (runs: 100, μ: 95665, ~: 95796) -PoolManagerInitializeTest:test_initialize_forNativeTokens(uint160) (runs: 100, μ: 72019, ~: 72279) +PoolManagerInitializeTest:test_initialize_fetchFeeWhenController(uint160) (runs: 100, μ: 95676, ~: 95797) +PoolManagerInitializeTest:test_initialize_forNativeTokens(uint160) (runs: 100, μ: 72068, ~: 72288) PoolManagerInitializeTest:test_initialize_gas() (gas: 87067) -PoolManagerInitializeTest:test_initialize_revertsWhenPoolAlreadyInitialized(uint160) (runs: 100, μ: 65010, ~: 65132) +PoolManagerInitializeTest:test_initialize_revertsWhenPoolAlreadyInitialized(uint160) (runs: 100, μ: 65018, ~: 65132) PoolManagerInitializeTest:test_initialize_revertsWithIdenticalTokens(uint160) (runs: 100, μ: 22624, ~: 22624) PoolManagerInitializeTest:test_initialize_revertsWithSameTokenCombo(uint160) (runs: 100, μ: 27702, ~: 27702) PoolManagerInitializeTest:test_initialize_succeedsWithCorrectSelectors() (gas: 1012968) -PoolManagerInitializeTest:test_initialize_succeedsWithEmptyHooks(uint160) (runs: 100, μ: 978652, ~: 978756) -PoolManagerInitializeTest:test_initialize_succeedsWithHooks(uint160) (runs: 100, μ: 8937393460516839801, ~: 8937393460516839937) -PoolManagerInitializeTest:test_initialize_succeedsWithMaxTickSpacing(uint160) (runs: 100, μ: 65814, ~: 65919) +PoolManagerInitializeTest:test_initialize_succeedsWithEmptyHooks(uint160) (runs: 100, μ: 978640, ~: 978753) +PoolManagerInitializeTest:test_initialize_succeedsWithHooks(uint160) (runs: 100, μ: 8937393460516839770, ~: 8937393460516839937) +PoolManagerInitializeTest:test_initialize_succeedsWithMaxTickSpacing(uint160) (runs: 100, μ: 65814, ~: 65916) PoolManagerReentrancyTest:testParallelLocker() (gas: 1928644) PoolManagerReentrancyTest:testSimpleLinearLocker() (gas: 390198) PoolManagerReentrancyTest:testTokenLocker() (gas: 566947) @@ -112,7 +112,7 @@ PoolManagerTest:test_collectProtocolFees_initializesWithProtocolFeeIfCalled() (g PoolManagerTest:test_collectProtocolFees_nativeToken_allowsOwnerToAccumulateFees_gas() (gas: 284374) PoolManagerTest:test_collectProtocolFees_nativeToken_returnsAllFeesIf0IsProvidedAsParameter() (gas: 248182) PoolManagerTest:test_donate_OneToken_gas() (gas: 148007) -PoolManagerTest:test_donate_failsIfNoLiquidity(uint160) (runs: 100, μ: 114640, ~: 114762) +PoolManagerTest:test_donate_failsIfNoLiquidity(uint160) (runs: 100, μ: 114638, ~: 114761) PoolManagerTest:test_donate_failsIfNotInitialized() (gas: 59654) PoolManagerTest:test_donate_failsWithIncorrectSelectors() (gas: 1426774) PoolManagerTest:test_donate_succeedsForNativeTokensWhenPoolHasLiquidity() (gas: 160719) @@ -128,7 +128,7 @@ PoolManagerTest:test_mint_gas() (gas: 199973) PoolManagerTest:test_mint_succeedsForNativeTokensIfInitialized(uint160) (runs: 100, μ: 166868, ~: 166868) PoolManagerTest:test_mint_succeedsIfInitialized(uint160) (runs: 100, μ: 169963, ~: 169963) PoolManagerTest:test_mint_succeedsWithCorrectSelectors() (gas: 1287264) -PoolManagerTest:test_mint_succeedsWithHooksIfInitialized(uint160) (runs: 100, μ: 8937393460517122544, ~: 8937393460517123618) +PoolManagerTest:test_mint_succeedsWithHooksIfInitialized(uint160) (runs: 100, μ: 8937393460517121897, ~: 8937393460517123606) PoolManagerTest:test_mint_withHooks_gas() (gas: 1283808) PoolManagerTest:test_mint_withNative_gas() (gas: 197549) PoolManagerTest:test_setProtocolFee_updatesProtocolFeeForInitializedPool() (gas: 70461) @@ -149,9 +149,9 @@ PoolManagerTest:test_take_failsWithInvalidTokensThatDoNotReturnTrueOnTransfer() PoolManagerTest:test_take_failsWithNoLiquidity() (gas: 8887503) PoolManagerTest:test_take_succeedsWithPoolWithLiquidity() (gas: 124018) PoolManagerTest:test_take_succeedsWithPoolWithLiquidityWithNativeToken() (gas: 117635) -PoolTest:testModifyPosition(uint160,(address,int24,int24,int128,int24)) (runs: 100, μ: 19911, ~: 7536) +PoolTest:testModifyPosition(uint160,(address,int24,int24,int128,int24)) (runs: 100, μ: 19917, ~: 7542) PoolTest:testPoolInitialize(uint160,uint16,uint16,uint24) (runs: 100, μ: 16461, ~: 6475) -PoolTest:testSwap(uint160,uint24,(int24,bool,int256,uint160)) (runs: 100, μ: 212314, ~: 7846) +PoolTest:testSwap(uint160,uint24,(int24,bool,int256,uint160)) (runs: 100, μ: 212320, ~: 7852) SafeCastTest:testToInt128(int256) (runs: 100, μ: 1575, ~: 511) SafeCastTest:testToInt128(uint256) (runs: 100, μ: 1150, ~: 390) SafeCastTest:testToInt256(uint256) (runs: 100, μ: 760, ~: 450) @@ -301,46 +301,47 @@ TickMathTestTest:test_getSqrtRatioAtTick_isValidMaxTick() (gas: 9795) TickMathTestTest:test_getSqrtRatioAtTick_isValidMaxTickSubOne() (gas: 6967) TickMathTestTest:test_getSqrtRatioAtTick_isValidMinTick() (gas: 9494) TickMathTestTest:test_getSqrtRatioAtTick_isValidMinTickAddOne() (gas: 6819) -TickMathTestTest:test_getSqrtRatioAtTick_matchesJavaScriptImplByOneHundrethOfABip() (gas: 864508) +TickMathTestTest:test_getSqrtRatioAtTick_matchesJavaScriptImplByOneHundrethOfABip() (gas: 865500) TickMathTestTest:test_getSqrtRatioAtTick_throwsForTooHigh() (gas: 8800) TickMathTestTest:test_getSqrtRatioAtTick_throwsForTooLow() (gas: 8736) TickMathTestTest:test_getTickAtSqrtRatio_isValidMaxSqrtRatioMinusOne() (gas: 8287) TickMathTestTest:test_getTickAtSqrtRatio_isValidMinSqrtRatio() (gas: 8008) TickMathTestTest:test_getTickAtSqrtRatio_isValidMinSqrtRatioPlusOne() (gas: 8173) TickMathTestTest:test_getTickAtSqrtRatio_isValidRatioClosestToMaxTick() (gas: 8462) -TickMathTestTest:test_getTickAtSqrtRatio_matchesJavascriptImplWithin1() (gas: 374880) +TickMathTestTest:test_getTickAtSqrtRatio_matchesJavascriptImplWithin1() (gas: 376378) TickMathTestTest:test_getTickAtSqrtRatio_throwsForTooHigh() (gas: 8681) TickMathTestTest:test_getTickAtSqrtRatio_throwsForTooLow() (gas: 8692) TickTest:testTick_clear_deletesAllTheDataInTheTick() (gas: 8080) TickTest:testTick_cross_flipsTheGrowthVariables() (gas: 68414) -TickTest:testTick_cross_twoFlipsAreNoOp() (gas: 69074) -TickTest:testTick_getFeeGrowthInside_returns0ForTwoUninitializedTicksIfTickIsAbove() (gas: 75714) -TickTest:testTick_getFeeGrowthInside_returns0ForTwoUninitializedTicksIfTickIsBelow() (gas: 75677) -TickTest:testTick_getFeeGrowthInside_returnsAllForTwoUninitializedTicksIfTickIsInside() (gas: 56050) -TickTest:testTick_getFeeGrowthInside_subtractsLowerTickIfAbove() (gas: 98630) -TickTest:testTick_getFeeGrowthInside_subtractsUpperAndLowerTickIfInside() (gas: 141314) +TickTest:testTick_cross_twoFlipsAreNoOp() (gas: 69119) +TickTest:testTick_getFeeGrowthInside_returns0ForTwoUninitializedTicksIfTickIsAbove() (gas: 75692) +TickTest:testTick_getFeeGrowthInside_returns0ForTwoUninitializedTicksIfTickIsBelow() (gas: 75655) +TickTest:testTick_getFeeGrowthInside_returnsAllForTwoUninitializedTicksIfTickIsInside() (gas: 56028) +TickTest:testTick_getFeeGrowthInside_subtractsLowerTickIfAbove() (gas: 98673) +TickTest:testTick_getFeeGrowthInside_subtractsUpperAndLowerTickIfInside() (gas: 141292) TickTest:testTick_getFeeGrowthInside_subtractsUpperTickIfBelow() (gas: 98732) -TickTest:testTick_getFeeGrowthInside_worksCorrectlyWithOverflowOnInsideTick() (gas: 141531) +TickTest:testTick_getFeeGrowthInside_worksCorrectlyWithOverflowOnInsideTick() (gas: 141509) TickTest:testTick_tickSpacingToMaxLiquidityPerTick_gasCost60TickSpacing() (gas: 78180) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_gasCostMaxTickSpacing() (gas: 78238) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_gasCostMinTickSpacing() (gas: 78224) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor1() (gas: 1634) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor2302() (gas: 1657) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForEntireRange() (gas: 1750) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForHighFee() (gas: 1635) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForLowFee() (gas: 1614) -TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMediumFee() (gas: 1612) -TickTest:testTick_tickSpacingToParametersInvariants_fuzz(int24) (runs: 100, μ: 5435, ~: 5435) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_gasCostMaxTickSpacing() (gas: 78203) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_gasCostMinTickSpacing() (gas: 78202) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor2302() (gas: 1724) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForEntireRange() (gas: 2049) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForHighFee() (gas: 1702) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForLowFee() (gas: 1745) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMaxTickSpacing() (gas: 1746) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMediumFee() (gas: 1746) +TickTest:testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMinTickSpacing() (gas: 1745) +TickTest:testTick_tickSpacingToParametersInvariants_fuzz(int24) (runs: 100, μ: 5304, ~: 5304) TickTest:testTick_update_assumesAllGrowthHappensBelowTicksLteCurrentTick() (gas: 134932) -TickTest:testTick_update_doesNotFlipFromNonzeroToGreaterNonzero() (gas: 36014) -TickTest:testTick_update_doesNotFlipFromNonzeroToLesserZero() (gas: 36068) +TickTest:testTick_update_doesNotFlipFromNonzeroToGreaterNonzero() (gas: 35992) +TickTest:testTick_update_doesNotFlipFromNonzeroToLesserZero() (gas: 36113) TickTest:testTick_update_doesNotSetAnyGrowthFieldsForTicksGtCurrentTick() (gas: 94471) -TickTest:testTick_update_doesNotSetAnyGrowthFieldsIfTickIsAlreadyInitialized() (gas: 136290) -TickTest:testTick_update_flipsFromNonzeroToZero() (gas: 24676) +TickTest:testTick_update_doesNotSetAnyGrowthFieldsIfTickIsAlreadyInitialized() (gas: 136268) +TickTest:testTick_update_flipsFromNonzeroToZero() (gas: 24659) TickTest:testTick_update_flipsFromZeroToNonzero() (gas: 34678) -TickTest:testTick_update_liquidityParsing_parsesMaxInt128StoredLiquidityGrossAfterUpdate() (gas: 95683) -TickTest:testTick_update_liquidityParsing_parsesMaxInt128StoredLiquidityGrossBeforeUpdate() (gas: 95639) -TickTest:testTick_update_liquidityParsing_parsesMaxUint128StoredLiquidityGrossAfterUpdate() (gas: 95679) -TickTest:testTick_update_liquidityParsing_parsesMaxUint128StoredLiquidityGrossBeforeUpdate() (gas: 95383) -TickTest:testTick_update_netsTheLiquidityBasedOnUpperFlag() (gas: 39534) +TickTest:testTick_update_liquidityParsing_parsesMaxInt128StoredLiquidityGrossAfterUpdate() (gas: 95728) +TickTest:testTick_update_liquidityParsing_parsesMaxInt128StoredLiquidityGrossBeforeUpdate() (gas: 95617) +TickTest:testTick_update_liquidityParsing_parsesMaxUint128StoredLiquidityGrossAfterUpdate() (gas: 95657) +TickTest:testTick_update_liquidityParsing_parsesMaxUint128StoredLiquidityGrossBeforeUpdate() (gas: 95361) +TickTest:testTick_update_netsTheLiquidityBasedOnUpperFlag() (gas: 39512) TickTest:testTick_update_revertsOnOverflowLiquidityGross() (gas: 38987) \ No newline at end of file diff --git a/src/PoolManager.sol b/src/PoolManager.sol index 71870dafc..97a9e144d 100644 --- a/src/PoolManager.sol +++ b/src/PoolManager.sol @@ -8,6 +8,7 @@ import {Position} from "./libraries/Position.sol"; import {FeeLibrary} from "./libraries/FeeLibrary.sol"; import {Currency, CurrencyLibrary} from "./types/Currency.sol"; import {PoolKey} from "./types/PoolKey.sol"; +import {TickMath} from "./libraries/TickMath.sol"; import {NoDelegateCall} from "./NoDelegateCall.sol"; import {Owned} from "./Owned.sol"; import {IHooks} from "./interfaces/IHooks.sol"; @@ -32,10 +33,10 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { using FeeLibrary for uint24; /// @inheritdoc IPoolManager - int24 public constant override MAX_TICK_SPACING = type(int16).max; + int24 public constant MAX_TICK_SPACING = TickMath.MAX_TICK_SPACING; /// @inheritdoc IPoolManager - int24 public constant override MIN_TICK_SPACING = 1; + int24 public constant MIN_TICK_SPACING = TickMath.MIN_TICK_SPACING; /// @dev Represents the currencies due/owed to each locker. /// Must all net to zero when the last lock is released. diff --git a/src/libraries/TickMath.sol b/src/libraries/TickMath.sol index e716524ff..cd8e5cf01 100644 --- a/src/libraries/TickMath.sol +++ b/src/libraries/TickMath.sol @@ -15,6 +15,11 @@ library TickMath { /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; + /// @dev The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767] + int24 internal constant MIN_TICK_SPACING = 1; + /// @dev The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767] + int24 internal constant MAX_TICK_SPACING = type(int16).max; + /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) diff --git a/test/Pool.t.sol b/test/Pool.t.sol index ed57050c2..76179b089 100644 --- a/test/Pool.t.sol +++ b/test/Pool.t.sol @@ -42,8 +42,8 @@ contract PoolTest is Test { function testModifyPosition(uint160 sqrtPriceX96, Pool.ModifyPositionParams memory params) public { // Assumptions tested in PoolManager.t.sol - vm.assume(params.tickSpacing > 0); - vm.assume(params.tickSpacing < 32768); + vm.assume(params.tickSpacing >= TickMath.MIN_TICK_SPACING); + vm.assume(params.tickSpacing <= TickMath.MAX_TICK_SPACING); testPoolInitialize(sqrtPriceX96, 0, 0, 0); @@ -75,8 +75,8 @@ contract PoolTest is Test { function testSwap(uint160 sqrtPriceX96, uint24 swapFee, Pool.SwapParams memory params) public { // Assumptions tested in PoolManager.t.sol - vm.assume(params.tickSpacing > 0); - vm.assume(params.tickSpacing < 32768); + vm.assume(params.tickSpacing >= TickMath.MIN_TICK_SPACING); + vm.assume(params.tickSpacing <= TickMath.MAX_TICK_SPACING); vm.assume(swapFee < 1000000); testPoolInitialize(sqrtPriceX96, 0, 0, 0); diff --git a/test/Tick.t.sol b/test/Tick.t.sol index 94f2b62dd..76d8192be 100644 --- a/test/Tick.t.sol +++ b/test/Tick.t.sol @@ -67,11 +67,11 @@ contract TickTest is Test, GasSnapshot { } function getMinTick(int24 tickSpacing) internal pure returns (int256) { - return (Constants.MIN_TICK / tickSpacing) * tickSpacing; + return (TickMath.MIN_TICK / tickSpacing) * tickSpacing; } function getMaxTick(int24 tickSpacing) internal pure returns (int256) { - return (Constants.MAX_TICK / tickSpacing) * tickSpacing; + return (TickMath.MAX_TICK / tickSpacing) * tickSpacing; } function checkCantOverflow(int24 tickSpacing, uint128 maxLiquidityPerTick) internal { @@ -105,18 +105,25 @@ contract TickTest is Test, GasSnapshot { checkCantOverflow(HIGH_TICK_SPACING, maxLiquidityPerTick); } - function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor1() public { - uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(1); + function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMinTickSpacing() public { + uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(TickMath.MIN_TICK_SPACING); assertEq(maxLiquidityPerTick, 191757530477355301479181766273477); // 126 bits - checkCantOverflow(1, maxLiquidityPerTick); + checkCantOverflow(TickMath.MIN_TICK_SPACING, maxLiquidityPerTick); + } + + function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMaxTickSpacing() public { + uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(TickMath.MAX_TICK_SPACING); + + assertEq(maxLiquidityPerTick, 6169404334338910476561253576012511949); + checkCantOverflow(TickMath.MAX_TICK_SPACING, maxLiquidityPerTick); } function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForEntireRange() public { - uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(887272); + uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(TickMath.MAX_TICK); - assertEq(maxLiquidityPerTick, Constants.MAX_UINT128 / 3); // 126 bits - checkCantOverflow(887272, maxLiquidityPerTick); + assertEq(maxLiquidityPerTick, type(uint128).max / 3); + checkCantOverflow(TickMath.MAX_TICK, maxLiquidityPerTick); } function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor2302() public { @@ -128,7 +135,7 @@ contract TickTest is Test, GasSnapshot { function testTick_tickSpacingToMaxLiquidityPerTick_gasCostMinTickSpacing() public { snapStart("tickSpacingToMaxLiquidityPerTick_gasCostMinTickSpacing"); - tickSpacingToMaxLiquidityPerTick(1); + tickSpacingToMaxLiquidityPerTick(TickMath.MIN_TICK_SPACING); snapEnd(); } @@ -139,10 +146,8 @@ contract TickTest is Test, GasSnapshot { } function testTick_tickSpacingToMaxLiquidityPerTick_gasCostMaxTickSpacing() public { - int24 MAX_TICK_SPACING = 32767; - snapStart("tickSpacingToMaxLiquidityPerTick_gasCostMaxTickSpacing"); - tickSpacingToMaxLiquidityPerTick(MAX_TICK_SPACING); + tickSpacingToMaxLiquidityPerTick(TickMath.MAX_TICK_SPACING); snapEnd(); } @@ -455,8 +460,8 @@ contract TickTest is Test, GasSnapshot { } function testTick_tickSpacingToParametersInvariants_fuzz(int24 tickSpacing) public { - vm.assume(tickSpacing <= TickMath.MAX_TICK); - vm.assume(tickSpacing > 0); + vm.assume(tickSpacing <= TickMath.MAX_TICK_SPACING); + vm.assume(tickSpacing >= TickMath.MIN_TICK_SPACING); int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing; int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing; diff --git a/test/utils/Constants.sol b/test/utils/Constants.sol index afe95ac45..42694631c 100644 --- a/test/utils/Constants.sol +++ b/test/utils/Constants.sol @@ -13,9 +13,6 @@ library Constants { uint128 constant MAX_UINT128 = type(uint128).max; uint160 constant MAX_UINT160 = type(uint160).max; - int24 constant MIN_TICK = -887272; - int24 constant MAX_TICK = 887272; - uint256 constant POOL_SLOT = 10; uint256 constant TICKS_OFFSET = 4; }