Skip to content

Commit

Permalink
Spearbit Gas-02: Optimize tickSpacingToMaxLiquidityPerTick (#823)
Browse files Browse the repository at this point in the history
Spearbit Gas-02
  • Loading branch information
hensha256 authored Aug 27, 2024
1 parent 9325e94 commit 0fc5a0b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144677
144656
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170867
170846
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 @@
274028
274007
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 @@
135144
135123
Original file line number Diff line number Diff line change
@@ -1 +1 @@
292854
292833
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24273
24268
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98882
98861
2 changes: 1 addition & 1 deletion .forge-snapshots/simple addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
161406
161385
12 changes: 6 additions & 6 deletions src/libraries/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,18 @@ library Pool {
/// @return result The max liquidity per tick
function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128 result) {
// Equivalent to:
// int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing;
// int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;
// uint24 numTicks = uint24((maxTick - minTick) / tickSpacing) + 1;
// int24 minTick = (TickMath.MIN_TICK / tickSpacing);
// int24 maxTick = (TickMath.MAX_TICK / tickSpacing);
// uint24 numTicks = maxTick - minTick + 1;
// return type(uint128).max / numTicks;
int24 MAX_TICK = TickMath.MAX_TICK;
int24 MIN_TICK = TickMath.MIN_TICK;
// tick spacing will never be 0 since TickMath.MIN_TICK_SPACING is 1
assembly ("memory-safe") {
tickSpacing := signextend(2, tickSpacing)
let minTick := mul(sdiv(MIN_TICK, tickSpacing), tickSpacing)
let maxTick := mul(sdiv(MAX_TICK, tickSpacing), tickSpacing)
let numTicks := add(sdiv(sub(maxTick, minTick), tickSpacing), 1)
let minTick := sdiv(MIN_TICK, tickSpacing)
let maxTick := sdiv(MAX_TICK, tickSpacing)
let numTicks := add(sub(maxTick, minTick), 1)
result := div(sub(shl(128, 1), 1), numTicks)
}
}
Expand Down

0 comments on commit 0fc5a0b

Please sign in to comment.