File tree Expand file tree Collapse file tree
spot-vaults/contracts/_utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,15 +34,18 @@ library UniswapV3PoolHelpers {
3434 /// @notice Retrieves the Time-Weighted Average Price (TWAP) tick from a Uniswap V3 pool over a given duration.
3535 /// @param pool The Uniswap V3 pool.
3636 /// @param twapDuration The TWAP duration.
37- /// @return The TWAP tick.
37+ /// @return twapTick The TWAP tick.
3838 function getTwapTick (
3939 IUniswapV3Pool pool ,
4040 uint32 twapDuration
41- ) internal view returns (int24 ) {
41+ ) internal view returns (int24 twapTick ) {
4242 uint32 [] memory secondsAgo = new uint32 [](2 );
4343 secondsAgo[0 ] = twapDuration;
4444 secondsAgo[1 ] = 0 ;
4545 (int56 [] memory tickCumulatives , ) = pool.observe (secondsAgo);
46- return int24 ((tickCumulatives[1 ] - tickCumulatives[0 ]) / twapDuration);
46+ int56 tickCumulativesDelta = tickCumulatives[1 ] - tickCumulatives[0 ];
47+ twapTick = int24 (tickCumulativesDelta / twapDuration);
48+ if (tickCumulativesDelta < 0 && (tickCumulativesDelta % twapDuration != 0 ))
49+ twapTick-- ;
4750 }
4851}
You can’t perform that action at this time.
0 commit comments