Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spearbit 105 #870

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144608
144627
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170897
170916
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
274175
274194
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135101
135120
Original file line number Diff line number Diff line change
@@ -1 +1 @@
292800
292819
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24006
24044
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98819
98838
2 changes: 1 addition & 1 deletion .forge-snapshots/simple addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
161364
161383
2 changes: 1 addition & 1 deletion src/libraries/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions test/Tick.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ contract TickTest is Test, GasSnapshot {
function testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForLowFee() public pure {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should add a test for when the min tick % tick spacing is 0 cause the number then shouldn't change from impl to impl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are 2 such tests already
testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMinTickSpacing
testTick_tickSpacingToMaxLiquidityPerTick_returnsTheCorrectValueForMaxTickSpacing

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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions test/libraries/Pool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Loading