Skip to content

Commit

Permalink
Replace modulo with bit operations (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
unsortedhashsets authored Apr 8, 2024
1 parent c5a23f0 commit 9f50d5d
Show file tree
Hide file tree
Showing 32 changed files with 32 additions and 32 deletions.
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 @@
264723
264715
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 @@
139579
139575
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144896
144892
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5409
5407
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22506
22504
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5515
5513
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51268
51266
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2592
2578
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2592
2578
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2592
2578
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2591
2556
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2900
2865
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2591
2556
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22844
22769
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55383
55375
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
147569
147561
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149033
149025
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap with native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132802
132600
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146678
146476
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72297
72132
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60300
60135
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
80330
80312
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn native 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76327
76162
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint native output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138678
138660
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
155493
155291
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156090
155723
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with dynamic fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89568
89366
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60278
60113
2 changes: 1 addition & 1 deletion .forge-snapshots/update dynamic fee in before swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140194
139992
2 changes: 1 addition & 1 deletion src/libraries/ProtocolFeeLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library ProtocolFeeLibrary {
uint16 internal constant BIPS_DENOMINATOR = 10_000;

function getZeroForOneFee(uint24 self) internal pure returns (uint16) {
return uint16(self % 4096);
return uint16(self & (4096 - 1));
}

function getOneForZeroFee(uint24 self) internal pure returns (uint16) {
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/TickBitmap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library TickBitmap {
function position(int24 tick) internal pure returns (int16 wordPos, uint8 bitPos) {
unchecked {
wordPos = int16(tick >> 8);
bitPos = uint8(int8(tick % 256));
bitPos = uint8(int8(tick & (256 - 1)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/TickMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ library TickMath {
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
sqrtPriceX96 = uint160((ratio >> 32) + (ratio & ((1 << 32) - 1) == 0 ? 0 : 1));
}
}

Expand Down

0 comments on commit 9f50d5d

Please sign in to comment.