Round a negative Uniswap v3 mean tick like OracleLibrary
Solidity signed integer division truncates toward zero. Uniswap’s oracle helper applies a correction when a negative cumulative tick difference is not divisible by the observation interval.
Compute the two observations
Use observe for the chosen lookback and zero seconds ago at the same block. Subtract the older tick cumulative from the newer and divide by the positive window. In the example a truncating host language may first produce minus ten.
tick cumulative change = -101
window = 10 seconds
floor(-101 / 10) = -11
Because the delta is negative with a nonzero remainder, subtract one from the truncated result to match minus eleven. For a delta of minus one hundred over ten seconds the result stays minus ten. Apply a correction only if your division primitive needs it.
Check that the observation window exists
A pool may not retain an observation old enough for the requested lookback. Surface that failure separately from arithmetic. The mean tick describes a time average over the observed range and should not be presented as a guaranteed execution quote. github.com OracleLibrary.sol