Module orca_whirlpool.internal.quote.decrease_liquidity

Expand source code
# https://github.com/orca-so/whirlpools/blob/main/sdk/src/quotes/public/decrease-liquidity-quote.ts

import dataclasses
from ..types.percentage import Percentage
from ..invariant import invariant
from ..utils.tick_util import TickUtil
from ..utils.liquidity_math import LiquidityMath
from ..utils.price_math import PriceMath


@dataclasses.dataclass(frozen=True)
class DecreaseLiquidityQuoteParams:
    liquidity: int
    tick_current_index: int
    sqrt_price: int
    tick_lower_index: int
    tick_upper_index: int
    slippage_tolerance: Percentage


@dataclasses.dataclass(frozen=True)
class DecreaseLiquidityQuote:
    liquidity: int
    token_est_a: int
    token_est_b: int
    token_min_a: int
    token_min_b: int


def decrease_liquidity_quote_by_liquidity_with_params(
    params: DecreaseLiquidityQuoteParams
) -> DecreaseLiquidityQuote:
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_lower_index), "tick_lower_index is out of bounds")
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_upper_index), "tick_upper_index is out of bounds")
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_current_index), "tick_current_index is out of bounds")
    invariant(params.tick_lower_index < params.tick_upper_index, "tick_lower_index < tick_upper_index")

    lower = PriceMath.tick_index_to_sqrt_price_x64(params.tick_lower_index)
    upper = PriceMath.tick_index_to_sqrt_price_x64(params.tick_upper_index)
    current = min(max(params.sqrt_price, lower), upper)  # bounded

    estimate_amount = LiquidityMath.get_token_amounts_from_liquidity(
        params.liquidity,
        current,
        lower,
        upper,
        False
    )

    return DecreaseLiquidityQuote(
        liquidity=params.liquidity,
        token_est_a=estimate_amount.token_a,
        token_est_b=estimate_amount.token_b,
        token_min_a=params.slippage_tolerance.adjust_sub(estimate_amount.token_a),
        token_min_b=params.slippage_tolerance.adjust_sub(estimate_amount.token_b),
    )

Functions

def decrease_liquidity_quote_by_liquidity_with_params(params: DecreaseLiquidityQuoteParams) ‑> DecreaseLiquidityQuote
Expand source code
def decrease_liquidity_quote_by_liquidity_with_params(
    params: DecreaseLiquidityQuoteParams
) -> DecreaseLiquidityQuote:
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_lower_index), "tick_lower_index is out of bounds")
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_upper_index), "tick_upper_index is out of bounds")
    invariant(TickUtil.is_tick_index_in_bounds(params.tick_current_index), "tick_current_index is out of bounds")
    invariant(params.tick_lower_index < params.tick_upper_index, "tick_lower_index < tick_upper_index")

    lower = PriceMath.tick_index_to_sqrt_price_x64(params.tick_lower_index)
    upper = PriceMath.tick_index_to_sqrt_price_x64(params.tick_upper_index)
    current = min(max(params.sqrt_price, lower), upper)  # bounded

    estimate_amount = LiquidityMath.get_token_amounts_from_liquidity(
        params.liquidity,
        current,
        lower,
        upper,
        False
    )

    return DecreaseLiquidityQuote(
        liquidity=params.liquidity,
        token_est_a=estimate_amount.token_a,
        token_est_b=estimate_amount.token_b,
        token_min_a=params.slippage_tolerance.adjust_sub(estimate_amount.token_a),
        token_min_b=params.slippage_tolerance.adjust_sub(estimate_amount.token_b),
    )

Classes

class DecreaseLiquidityQuote (liquidity: int, token_est_a: int, token_est_b: int, token_min_a: int, token_min_b: int)

DecreaseLiquidityQuote(liquidity: int, token_est_a: int, token_est_b: int, token_min_a: int, token_min_b: int)

Expand source code
@dataclasses.dataclass(frozen=True)
class DecreaseLiquidityQuote:
    liquidity: int
    token_est_a: int
    token_est_b: int
    token_min_a: int
    token_min_b: int

Class variables

var liquidity : int
var token_est_a : int
var token_est_b : int
var token_min_a : int
var token_min_b : int
class DecreaseLiquidityQuoteParams (liquidity: int, tick_current_index: int, sqrt_price: int, tick_lower_index: int, tick_upper_index: int, slippage_tolerance: Percentage)

DecreaseLiquidityQuoteParams(liquidity: int, tick_current_index: int, sqrt_price: int, tick_lower_index: int, tick_upper_index: int, slippage_tolerance: orca_whirlpool.internal.types.percentage.Percentage)

Expand source code
@dataclasses.dataclass(frozen=True)
class DecreaseLiquidityQuoteParams:
    liquidity: int
    tick_current_index: int
    sqrt_price: int
    tick_lower_index: int
    tick_upper_index: int
    slippage_tolerance: Percentage

Class variables

var liquidity : int
var slippage_tolerancePercentage
var sqrt_price : int
var tick_current_index : int
var tick_lower_index : int
var tick_upper_index : int