From b63bd8cbd3d8f5988ac4d5730d4a0700aa08174d Mon Sep 17 00:00:00 2001 From: 7400 <7400> Date: Wed, 1 Nov 2023 18:57:59 -0700 Subject: [PATCH] unchecked on TickMath to ensure compatibility --- lib_sol8/v3-core/contracts/libraries/TickMath.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_sol8/v3-core/contracts/libraries/TickMath.sol b/lib_sol8/v3-core/contracts/libraries/TickMath.sol index 1024980..e3b4180 100644 --- a/lib_sol8/v3-core/contracts/libraries/TickMath.sol +++ b/lib_sol8/v3-core/contracts/libraries/TickMath.sol @@ -20,7 +20,7 @@ library TickMath { /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick - function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { + function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {unchecked{ uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(int256(MAX_TICK)), 'T'); @@ -51,14 +51,14 @@ library TickMath { // 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)); - } + }} /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio - function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { + function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {unchecked{ // second inequality must be < because the price can never reach the price at the max tick require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R'); uint256 ratio = uint256(sqrtPriceX96) << 32; @@ -202,4 +202,4 @@ library TickMath { tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } -} +}}