Files
r4bbit 3ba39777d9 refactor(twap-oracle): take a price (not a tick) in current-tick instructions
A tick is the TWAP's internal representation, so price sources should not have to
compute it — just as consumers never deal with ticks. CreateCurrentTickAccount and
UpdateCurrentTick now take a Q64.64 spot price (for an AMM, reserve_b/reserve_a) and
the oracle converts it to a tick internally. This keeps producers tick-agnostic,
mirrors the consumer side, and centralises all tick knowledge in the oracle.

  CreateCurrentTickAccount { initial_tick: i32 } -> { initial_price: u128 }
  UpdateCurrentTick        { tick: i32 }         -> { price: u128 }

Add price_to_tick(price: u128) -> i32 to twap_oracle_core, the inverse of
tick_to_oracle_price: isqrt(price << 128) -> sqrtPriceX96 -> get_tick_at_sqrt_ratio.
The sqrtPriceX96 is clamped to >= MIN_SQRT_RATIO so a zero/dust price maps to
MIN_TICK rather than erroring.

Add a pure-integer integer_sqrt(U256) (bit-by-bit, no floating point): ruint's root
is gated behind its std feature and seeds with f64, neither available in the guest.
Uses wrapping_shr for the digit loop (checked_shr rejects the intended lossy shifts).

CurrentTickAccount (still stores a tick) and record_tick are unchanged.
2026-06-04 13:13:08 +02:00
..