Skip to main content

compute_swap_step

Function compute_swap_step 

Source
pub fn compute_swap_step(
    sqrt_ratio_current_x96: U160,
    sqrt_ratio_target_x96: U160,
    liquidity: u128,
    amount_remaining: I256,
    fee_pips: u32,
) -> Result<SwapStepResult>
Expand description

Computes the result of swapping some amount in, or amount out, given the parameters of the swap.

§Arguments

  • sqrt_ratio_current_x96 - The current sqrt price of the pool
  • sqrt_ratio_target_x96 - The price that cannot be exceeded, from which the direction of the swap is inferred
  • liquidity - The usable liquidity
  • amount_remaining - How much input or output amount is remaining to be swapped in/out
  • fee_pips - The fee taken from the input amount, expressed in hundredths of a bip

§Errors

This function returns an error if:

  • Fee adjustment calculations overflow or encounter division by zero.
  • Amount or price delta calculations overflow the supported numeric range.