Skip to main content

encode_sqrt_ratio_x96

Function encode_sqrt_ratio_x96 

Source
pub fn encode_sqrt_ratio_x96(amount0: u128, amount1: u128) -> U160
Expand description

Encodes the sqrt ratio of two token amounts as a Q64.96 fixed point number.

Calculates sqrt(amount0 / amount1) * 2^96 to encode the price ratio between two tokens as a fixed-point number suitable for AMM calculations.

ยงPanics

Panics if:

  • amount1 is zero (division by zero).
  • sqrt(amount1) is zero during overflow handling.
  • Mathematical operations result in overflow during mul_div.