unchecked on TickMath to ensure compatibility
This commit is contained in:
@@ -20,7 +20,7 @@ library TickMath {
|
|||||||
/// @param tick The input tick for the above formula
|
/// @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)
|
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
|
||||||
/// at the given tick
|
/// 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));
|
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
|
||||||
require(absTick <= uint256(int256(MAX_TICK)), 'T');
|
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 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
|
// 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) == 0 ? 0 : 1));
|
||||||
}
|
}}
|
||||||
|
|
||||||
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
|
/// @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
|
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
|
||||||
/// ever return.
|
/// ever return.
|
||||||
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
|
/// @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
|
/// @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
|
// 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');
|
require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
|
||||||
uint256 ratio = uint256(sqrtPriceX96) << 32;
|
uint256 ratio = uint256(sqrtPriceX96) << 32;
|
||||||
@@ -202,4 +202,4 @@ library TickMath {
|
|||||||
|
|
||||||
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
|
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user