diff --git a/src/libraries/SqrtPriceMath.sol b/src/libraries/SqrtPriceMath.sol index 24b2fa7f3..659b750e1 100644 --- a/src/libraries/SqrtPriceMath.sol +++ b/src/libraries/SqrtPriceMath.sol @@ -238,11 +238,8 @@ library SqrtPriceMath { { uint256 numerator = absDiff(sqrtPriceAX96, sqrtPriceBX96); uint256 denominator = FixedPoint96.Q96; - uint256 _liquidity; - assembly ("memory-safe") { - // avoid implicit upcasting - _liquidity := and(liquidity, 0xffffffffffffffffffffffffffffffff) - } + uint256 _liquidity = uint256(liquidity); + /** * Equivalent to: * amount1 = roundUp diff --git a/src/libraries/StateLibrary.sol b/src/libraries/StateLibrary.sol index c884a07b0..c1540e2d3 100644 --- a/src/libraries/StateLibrary.sol +++ b/src/libraries/StateLibrary.sol @@ -12,8 +12,8 @@ library StateLibrary { /// @notice index of feeGrowthGlobal0X128 in Pool.State uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1; - /// @notice index of feeGrowthGlobal1X128 in Pool.State - uint256 public constant FEE_GROWTH_GLOBAL1_OFFSET = 2; + + // feeGrowthGlobal1X128 offset in Pool.State = 2 /// @notice index of liquidity in Pool.State uint256 public constant LIQUIDITY_OFFSET = 3; diff --git a/src/libraries/SwapMath.sol b/src/libraries/SwapMath.sol index 63ceaf4e4..2142655a7 100644 --- a/src/libraries/SwapMath.sol +++ b/src/libraries/SwapMath.sol @@ -70,7 +70,7 @@ library SwapMath { // `amountIn` is capped by the target price sqrtPriceNextX96 = sqrtPriceTargetX96; feeAmount = _feePips == MAX_SWAP_FEE - ? amountIn + ? amountIn // amountIn is always 0 here, as amountRemainingLessFee == 0 and amountRemainingLessFee >= amountIn : FullMath.mulDivRoundingUp(amountIn, _feePips, MAX_SWAP_FEE - _feePips); } else { // exhaust the remaining amount diff --git a/src/libraries/UnsafeMath.sol b/src/libraries/UnsafeMath.sol index c1cdf3eb2..c3f23c83c 100644 --- a/src/libraries/UnsafeMath.sol +++ b/src/libraries/UnsafeMath.sol @@ -10,10 +10,8 @@ library UnsafeMath { /// @param y The divisor /// @return z The quotient, ceil(x / y) function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { - unchecked { - assembly ("memory-safe") { - z := add(div(x, y), gt(mod(x, y), 0)) - } + assembly ("memory-safe") { + z := add(div(x, y), gt(mod(x, y), 0)) } } diff --git a/src/types/PoolId.sol b/src/types/PoolId.sol index 740dff007..22a0b4f91 100644 --- a/src/types/PoolId.sol +++ b/src/types/PoolId.sol @@ -10,7 +10,8 @@ library PoolIdLibrary { /// @notice Returns value equal to keccak256(abi.encode(poolKey)) function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) { assembly ("memory-safe") { - poolId := keccak256(poolKey, mul(32, 5)) + // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes) + poolId := keccak256(poolKey, 0xa0) } } }