From ce82aa59baf58c07dd1d4a05c9f9e02c6fad6fab Mon Sep 17 00:00:00 2001 From: Alice <34962750+hensha256@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:52:15 -0400 Subject: [PATCH] Spearbit 105 (#870) --- ...quidity to already existing position with salt.snap | 2 +- .forge-snapshots/addLiquidity CA fee.snap | 2 +- .forge-snapshots/addLiquidity with empty hook.snap | 2 +- .forge-snapshots/addLiquidity with native token.snap | 2 +- .../create new liquidity to a position with salt.snap | 2 +- .forge-snapshots/poolManager bytecode size.snap | 2 +- ...simple addLiquidity second addition same range.snap | 2 +- .forge-snapshots/simple addLiquidity.snap | 2 +- src/libraries/Pool.sol | 2 +- test/Tick.t.sol | 10 +++++----- test/libraries/Pool.t.sol | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.forge-snapshots/add liquidity to already existing position with salt.snap b/.forge-snapshots/add liquidity to already existing position with salt.snap index 7931cc0d3..0cc62a123 100644 --- a/.forge-snapshots/add liquidity to already existing position with salt.snap +++ b/.forge-snapshots/add liquidity to already existing position with salt.snap @@ -1 +1 @@ -144608 \ No newline at end of file +144627 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity CA fee.snap b/.forge-snapshots/addLiquidity CA fee.snap index 329e55959..51059b6ad 100644 --- a/.forge-snapshots/addLiquidity CA fee.snap +++ b/.forge-snapshots/addLiquidity CA fee.snap @@ -1 +1 @@ -170897 \ No newline at end of file +170916 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with empty hook.snap b/.forge-snapshots/addLiquidity with empty hook.snap index cb223237c..30bdfbe46 100644 --- a/.forge-snapshots/addLiquidity with empty hook.snap +++ b/.forge-snapshots/addLiquidity with empty hook.snap @@ -1 +1 @@ -274175 \ No newline at end of file +274194 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with native token.snap b/.forge-snapshots/addLiquidity with native token.snap index 3ec6fa53a..cd7fd0616 100644 --- a/.forge-snapshots/addLiquidity with native token.snap +++ b/.forge-snapshots/addLiquidity with native token.snap @@ -1 +1 @@ -135101 \ No newline at end of file +135120 \ No newline at end of file diff --git a/.forge-snapshots/create new liquidity to a position with salt.snap b/.forge-snapshots/create new liquidity to a position with salt.snap index ebcbdf72c..34d77f4b0 100644 --- a/.forge-snapshots/create new liquidity to a position with salt.snap +++ b/.forge-snapshots/create new liquidity to a position with salt.snap @@ -1 +1 @@ -292800 \ No newline at end of file +292819 \ No newline at end of file diff --git a/.forge-snapshots/poolManager bytecode size.snap b/.forge-snapshots/poolManager bytecode size.snap index 991b253d9..c5436b36d 100644 --- a/.forge-snapshots/poolManager bytecode size.snap +++ b/.forge-snapshots/poolManager bytecode size.snap @@ -1 +1 @@ -24006 \ No newline at end of file +24044 \ No newline at end of file diff --git a/.forge-snapshots/simple addLiquidity second addition same range.snap b/.forge-snapshots/simple addLiquidity second addition same range.snap index 513cda23b..8d0e2523f 100644 --- a/.forge-snapshots/simple addLiquidity second addition same range.snap +++ b/.forge-snapshots/simple addLiquidity second addition same range.snap @@ -1 +1 @@ -98819 \ No newline at end of file +98838 \ No newline at end of file diff --git a/.forge-snapshots/simple addLiquidity.snap b/.forge-snapshots/simple addLiquidity.snap index 0d3371c3f..2ac3df3f0 100644 --- a/.forge-snapshots/simple addLiquidity.snap +++ b/.forge-snapshots/simple addLiquidity.snap @@ -1 +1 @@ -161364 \ No newline at end of file +161383 \ No newline at end of file diff --git a/src/libraries/Pool.sol b/src/libraries/Pool.sol index d58e316ef..4a1e93d28 100644 --- a/src/libraries/Pool.sol +++ b/src/libraries/Pool.sol @@ -567,7 +567,7 @@ library Pool { // tick spacing will never be 0 since TickMath.MIN_TICK_SPACING is 1 assembly ("memory-safe") { tickSpacing := signextend(2, tickSpacing) - let minTick := sdiv(MIN_TICK, tickSpacing) + let minTick := sub(sdiv(MIN_TICK, tickSpacing), slt(smod(MIN_TICK, tickSpacing), 0)) let maxTick := sdiv(MAX_TICK, tickSpacing) let numTicks := add(sub(maxTick, minTick), 1) result := div(sub(shl(128, 1), 1), numTicks) diff --git a/test/Tick.t.sol b/test/Tick.t.sol index e31faca21..44c2ba57b 100644 --- a/test/Tick.t.sol +++ b/test/Tick.t.sol @@ -116,21 +116,21 @@ contract TickTest is Test, GasSnapshot { function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForLowFee() public pure { uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(LOW_TICK_SPACING); - assertEq(maxLiquidityPerTick, 1917569901783203986719870431555990); + assertEq(maxLiquidityPerTick, 1917559095893846719543856547154045); checkCantOverflow(LOW_TICK_SPACING, maxLiquidityPerTick); } function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMediumFee() public pure { uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(MEDIUM_TICK_SPACING); - assertEq(maxLiquidityPerTick, 11505743598341114571880798222544994); + assertEq(maxLiquidityPerTick, 11505354575363080317263139282924270); checkCantOverflow(MEDIUM_TICK_SPACING, maxLiquidityPerTick); } function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForHighFee() public pure { uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(HIGH_TICK_SPACING); - assertEq(maxLiquidityPerTick, 38350317471085141830651933667504588); + assertEq(maxLiquidityPerTick, 38345995821606768476828330790147420); checkCantOverflow(HIGH_TICK_SPACING, maxLiquidityPerTick); } @@ -144,7 +144,7 @@ contract TickTest is Test, GasSnapshot { function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMaxTickSpacing() public pure { uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(TickMath.MAX_TICK_SPACING); - assertEq(maxLiquidityPerTick, 6186952125835244790243174680577603844); + assertEq(maxLiquidityPerTick, 6076470837873901133274546561281575204); checkCantOverflow(TickMath.MAX_TICK_SPACING, maxLiquidityPerTick); } @@ -158,7 +158,7 @@ contract TickTest is Test, GasSnapshot { function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueFor2302() public pure { uint128 maxLiquidityPerTick = tickSpacingToMaxLiquidityPerTick(2302); - assertEq(maxLiquidityPerTick, 441351967472034323558203122479595605); + assertEq(maxLiquidityPerTick, 440780268032303709149448973357212709); checkCantOverflow(2302, maxLiquidityPerTick); } diff --git a/test/libraries/Pool.t.sol b/test/libraries/Pool.t.sol index af060031a..4b8ec1e56 100644 --- a/test/libraries/Pool.t.sol +++ b/test/libraries/Pool.t.sol @@ -174,7 +174,7 @@ contract PoolTest is Test, GasSnapshot { int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing; int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing; uint24 numTicks = uint24((maxTick - minTick) / tickSpacing) + 1; - // assert that the result is the same as the v3 math - assertEq(type(uint128).max / numTicks, Pool.tickSpacingToMaxLiquidityPerTick(tickSpacing)); + // assert that the result is the same as the v3 math or lower + assertGe(type(uint128).max / numTicks, Pool.tickSpacingToMaxLiquidityPerTick(tickSpacing)); } }