diff --git a/.gas-snapshot b/.gas-snapshot index f069fad0d..b2dafc174 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -6,15 +6,15 @@ ClaimsTest:testCatchesUnderflowOnBurn(uint256) (runs: 100, μ: 39932, ~: 40927) ClaimsTest:testCatchesUnderflowOnTransfer(uint256) (runs: 100, μ: 40057, ~: 41052) ClaimsTest:testTransferToClaimsContractFails() (gas: 36413) FeesTest:testCollectFees() (gas: 622560) -FeesTest:testHookWithdrawFeeProtocolWithdrawFee(uint16,uint16) (runs: 100, μ: 491589, ~: 495940) -FeesTest:testInitializeAllFees(uint16,uint16,uint16,uint16) (runs: 100, μ: 164500, ~: 161247) -FeesTest:testInitializeBothHookFee(uint16,uint16) (runs: 100, μ: 86164, ~: 93440) +FeesTest:testHookWithdrawFeeProtocolWithdrawFee(uint16,uint16) (runs: 100, μ: 489854, ~: 495940) +FeesTest:testInitializeAllFees(uint16,uint16,uint16,uint16) (runs: 100, μ: 164080, ~: 161213) +FeesTest:testInitializeBothHookFee(uint16,uint16) (runs: 100, μ: 85965, ~: 93440) FeesTest:testInitializeFailsNoHook() (gas: 20233) -FeesTest:testInitializeHookProtocolSwapFee(uint16,uint16) (runs: 100, μ: 127817, ~: 133651) +FeesTest:testInitializeHookProtocolSwapFee(uint16,uint16) (runs: 100, μ: 126882, ~: 133651) FeesTest:testInitializeHookSwapFee(uint16) (runs: 100, μ: 68614, ~: 70884) -FeesTest:testInitializeHookWithdrawFee(uint16) (runs: 100, μ: 68427, ~: 70924) +FeesTest:testInitializeHookWithdrawFee(uint16) (runs: 100, μ: 68200, ~: 70924) FeesTest:testInitializeWithSwapProtocolFeeAndHookFeeDifferentDirections() (gas: 584240) -FeesTest:testNoHookProtocolFee(uint16,uint16) (runs: 100, μ: 759115, ~: 765926) +FeesTest:testNoHookProtocolFee(uint16,uint16) (runs: 100, μ: 758142, ~: 765926) FeesTest:testProtocolFeeOnWithdrawalRemainsZeroIfNoHookWithdrawalFeeSet(uint16,uint16) (runs: 100, μ: 470360, ~: 472269) FeesTest:testProtocolSwapFeeAndHookSwapFeeSameDirection() (gas: 604631) FeesTest:testSwapWithProtocolFeeAllAndHookFeeAllButOnlySwapFlag() (gas: 643655) @@ -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, μ: 4783, ~: 4729) -HooksTest:testValidateHookAddressFailsNoHooks(uint152,uint8) (runs: 100, μ: 4808, ~: 4776) +HooksTest:testValidateHookAddressFailsAllHooks(uint152,uint8) (runs: 100, μ: 4787, ~: 4729) +HooksTest:testValidateHookAddressFailsNoHooks(uint152,uint8) (runs: 100, μ: 4805, ~: 4729) 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, μ: 121857, ~: 45987) +LockersLibrary:test_decrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 121371, ~: 45330) LockersLibrary:test_getCurrentLocker_multipleAddressesFuzz(address[]) (runs: 100, μ: 273024, ~: 265967) LockersLibrary:test_incrementNonzeroDeltaCount() (gas: 807) -LockersLibrary:test_incrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 72656, ~: 27388) +LockersLibrary:test_incrementNonzeroDeltaCountFuzz(uint8) (runs: 100, μ: 72366, ~: 26996) LockersLibrary:test_pop() (gas: 1770) LockersLibrary:test_pop_multipleAddressesFuzz(address[]) (runs: 100, μ: 240601, ~: 234397) LockersLibrary:test_push() (gas: 1421) @@ -97,38 +97,38 @@ PoolManagerTest:test_collectProtocolFees_initializesWithProtocolFeeIfCalled() (g PoolManagerTest:test_collectProtocolFees_nativeToken_allowsOwnerToAccumulateFees_gas() (gas: 575330) PoolManagerTest:test_collectProtocolFees_nativeToken_returnsAllFeesIf0IsProvidedAsParameter() (gas: 542397) PoolManagerTest:test_donate_OneToken_gas() (gas: 452140) -PoolManagerTest:test_donate_failsIfNoLiquidity(uint160) (runs: 100, μ: 64520, ~: 64652) +PoolManagerTest:test_donate_failsIfNoLiquidity(uint160) (runs: 100, μ: 64518, ~: 64651) PoolManagerTest:test_donate_failsIfNotInitialized() (gas: 28042) PoolManagerTest:test_donate_failsWithIncorrectSelectors() (gas: 1420105) PoolManagerTest:test_donate_succeedsForNativeTokensWhenPoolHasLiquidity() (gas: 440700) PoolManagerTest:test_donate_succeedsWhenPoolHasLiquidity() (gas: 493156) PoolManagerTest:test_donate_succeedsWithCorrectSelectors() (gas: 1393184) PoolManagerTest:test_feeControllerSet() (gas: 39595) -PoolManagerTest:test_fetchFeeWhenController(uint160) (runs: 100, μ: 112676, ~: 112808) +PoolManagerTest:test_fetchFeeWhenController(uint160) (runs: 100, μ: 112707, ~: 112809) PoolManagerTest:test_getPosition() (gas: 366837) -PoolManagerTest:test_initialize((address,address,uint24,int24,address),uint160) (runs: 100, μ: 18620, ~: 13942) +PoolManagerTest:test_initialize((address,address,uint24,int24,address),uint160) (runs: 100, μ: 18626, ~: 13942) PoolManagerTest:test_initialize_failsIfTickSpaceNeg(uint160) (runs: 100, μ: 15866, ~: 15866) PoolManagerTest:test_initialize_failsIfTickSpaceTooLarge(uint160) (runs: 100, μ: 16790, ~: 16790) PoolManagerTest:test_initialize_failsIfTickSpaceZero(uint160) (runs: 100, μ: 15888, ~: 15888) PoolManagerTest:test_initialize_failsWithIncorrectSelectors() (gas: 984435) -PoolManagerTest:test_initialize_forNativeTokens(uint160) (runs: 100, μ: 59161, ~: 59445) +PoolManagerTest:test_initialize_forNativeTokens(uint160) (runs: 100, μ: 59139, ~: 59421) PoolManagerTest:test_initialize_gas() (gas: 73772) -PoolManagerTest:test_initialize_revertsWhenPoolAlreadyInitialized(uint160) (runs: 100, μ: 50375, ~: 50478) +PoolManagerTest:test_initialize_revertsWhenPoolAlreadyInitialized(uint160) (runs: 100, μ: 50365, ~: 50478) PoolManagerTest:test_initialize_revertsWithIdenticalTokens(uint160) (runs: 100, μ: 13399, ~: 13399) -PoolManagerTest:test_initialize_revertsWithSameTokenCombo(uint160) (runs: 100, μ: 49238, ~: 49341) +PoolManagerTest:test_initialize_revertsWithSameTokenCombo(uint160) (runs: 100, μ: 49228, ~: 49341) PoolManagerTest:test_initialize_succeedsWithCorrectSelectors() (gas: 980799) -PoolManagerTest:test_initialize_succeedsWithEmptyHooks(uint160) (runs: 100, μ: 946584, ~: 946697) -PoolManagerTest:test_initialize_succeedsWithHooks(uint160) (runs: 100, μ: 8937393460516837947, ~: 8937393460516838057) -PoolManagerTest:test_initialize_succeedsWithMaxTickSpacing(uint160) (runs: 100, μ: 50738, ~: 50841) +PoolManagerTest:test_initialize_succeedsWithEmptyHooks(uint160) (runs: 100, μ: 946581, ~: 946697) +PoolManagerTest:test_initialize_succeedsWithHooks(uint160) (runs: 100, μ: 8937393460516837929, ~: 8937393460516838058) +PoolManagerTest:test_initialize_succeedsWithMaxTickSpacing(uint160) (runs: 100, μ: 50708, ~: 50840) PoolManagerTest:test_lock_EmitsCorrectId() (gas: 18848) PoolManagerTest:test_lock_NoOpIsOk() (gas: 50372) PoolManagerTest:test_mint_failsIfNotInitialized() (gas: 29346) PoolManagerTest:test_mint_failsWithIncorrectSelectors() (gas: 1176562) PoolManagerTest:test_mint_gas() (gas: 304522) -PoolManagerTest:test_mint_succeedsForNativeTokensIfInitialized(uint160) (runs: 100, μ: 250174, ~: 267847) -PoolManagerTest:test_mint_succeedsIfInitialized(uint160) (runs: 100, μ: 254591, ~: 256272) +PoolManagerTest:test_mint_succeedsForNativeTokensIfInitialized(uint160) (runs: 100, μ: 250535, ~: 267847) +PoolManagerTest:test_mint_succeedsIfInitialized(uint160) (runs: 100, μ: 254269, ~: 251775) PoolManagerTest:test_mint_succeedsWithCorrectSelectors() (gas: 1211340) -PoolManagerTest:test_mint_succeedsWithHooksIfInitialized(uint160) (runs: 100, μ: 8937393460517082568, ~: 8937393460517084221) +PoolManagerTest:test_mint_succeedsWithHooksIfInitialized(uint160) (runs: 100, μ: 8937393460517082508, ~: 8937393460517084221) PoolManagerTest:test_mint_withHooks_gas() (gas: 1209319) PoolManagerTest:test_mint_withNative_gas() (gas: 285824) PoolManagerTest:test_setProtocolFee_updatesProtocolFeeForInitializedPool() (gas: 118065) @@ -149,9 +149,9 @@ PoolManagerTest:test_take_failsWithInvalidTokensThatDoNotReturnTrueOnTransfer() PoolManagerTest:test_take_failsWithNoLiquidity() (gas: 53518) PoolManagerTest:test_take_succeedsWithPoolWithLiquidity() (gas: 469168) PoolManagerTest:test_take_succeedsWithPoolWithLiquidityWithNativeToken() (gas: 438960) -PoolTest:testModifyPosition(uint160,(address,int24,int24,int128,int24)) (runs: 100, μ: 19911, ~: 7536) -PoolTest:testPoolInitialize(uint160,uint16,uint16,uint24) (runs: 100, μ: 15442, ~: 6475) -PoolTest:testSwap(uint160,uint24,(int24,bool,int256,uint160)) (runs: 100, μ: 212145, ~: 7846) +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, μ: 212151, ~: 7852) SafeCastTest:testToInt128(int256) (runs: 100, μ: 1533, ~: 511) SafeCastTest:testToInt128(uint256) (runs: 100, μ: 1167, ~: 390) SafeCastTest:testToInt256(uint256) (runs: 100, μ: 784, ~: 450) @@ -198,7 +198,7 @@ SqrtPriceMathTestTest:test_getNextSqrtPriceFromOutput_zeroForOneEqualsFalseGas() SqrtPriceMathTestTest:test_getNextSqrtPriceFromOutput_zeroForOneEqualsTrueGas() (gas: 78570) SqrtPriceMathTestTest:test_swapComputation_sqrtPTimessqrtQOverflows() (gas: 2375) SwapMathTest:test_amountOut_isCappedAtTheDesiredAmountOut() (gas: 3414) -SwapMathTest:test_computeSwapStep_Invariants(uint160,uint160,uint128,int256,uint24) (runs: 100, μ: 7950, ~: 7733) +SwapMathTest:test_computeSwapStep_Invariants(uint160,uint160,uint128,int256,uint24) (runs: 100, μ: 7968, ~: 7751) SwapMathTest:test_entireInputAmountTakenAsFee() (gas: 3490) SwapMathTest:test_exactAmountIn_oneForZero_thatGetsCappedAtPriceTargetIn() (gas: 3451) SwapMathTest:test_exactAmountIn_oneForZero_thatIsFullySpentIn() (gas: 4384) @@ -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; }