Contract 148ca1a98456b2b2cabff5b846de9a27690fcabc76c6a7081fdf9535d6773018

← Back to Index 📥 Download WASM

Meta

rssdkver 23.0.2#a97daf8b07cdf24e9bd45e344db51a21b9ea77d3
rsver 1.88.0

Instances

  • CASKWJSINHFW7BF7RUOA4E2FP6B2TYRKFX2UOPWLCPOOPUR6UU3G2RWC

Interface

Initialize the PoolLens with the factory address

Arguments

  • env - The Soroban environment
  • factory - The DEX factory contract address
fn __constructor(env: soroban_sdk::Env, factory: soroban_sdk::Address)

Get the stored factory address

Returns

The factory contract address

fn get_factory(env: soroban_sdk::Env) -> soroban_sdk::Address

Fetch pool data for multiple pools by their addresses

This is the most efficient method when you already know the pool addresses. Uses a single cross-contract call per pool.

Arguments

  • env - The Soroban environment
  • pools - Vector of pool contract addresses to query

Returns

Vector of PoolData structs in the same order as input. Each PoolData contains result: Found(state) if initialized, NotFound otherwise.

fn get_pools_data(
    env: soroban_sdk::Env,
    pools: soroban_sdk::Vec,
) -> soroban_sdk::Vec

Fetch pool data for multiple pools by token pairs

Looks up pool addresses from the factory, then fetches their data. Useful when you have token pairs but not pool addresses.

Arguments

  • env - The Soroban environment
  • pairs - Vector of token pair queries (token_a, token_b, fee)

Returns

Vector of PoolData structs in the same order as input. Each PoolData contains result: Found(state) if initialized, NotFound otherwise. Token order in the query doesn't matter - tokens are sorted internally.

fn get_pools_by_pairs(
    env: soroban_sdk::Env,
    pairs: soroban_sdk::Vec,
) -> soroban_sdk::Vec

Fetch data for a single pool

Arguments

  • env - The Soroban environment
  • pool - The pool contract address

Returns

PoolData struct with all pool information

fn get_pool_data(env: soroban_sdk::Env, pool: soroban_sdk::Address) -> PoolData

Fetch pool data with balances for multiple pools by their addresses.

Same as get_pools_data but includes token reserves (balances). Costs ~1M extra CPU per pool due to balance lookups.

Arguments

  • env - The Soroban environment
  • pools - Vector of pool contract addresses to query

Returns

Vector of PoolDataWithBalances structs in the same order as input.

fn get_pools_data_with_bal(
    env: soroban_sdk::Env,
    pools: soroban_sdk::Vec,
) -> soroban_sdk::Vec

Fetch data with balances for a single pool

Arguments

  • env - The Soroban environment
  • pool - The pool contract address

Returns

PoolDataWithBalances struct with pool state and reserves

fn get_pool_data_with_bal(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
) -> PoolDataWithBalances

Initialize the quoter with factory and WETH9 addresses @param factory The address of the pool factory contract @param xlm The address of the wrapped XLM token

Note: Panics on initialization failure (e.g., if already initialized). This is intentional - a contract that fails to initialize should not be usable.

fn init(
    env: soroban_sdk::Env,
    factory: soroban_sdk::Address,
    xlm: soroban_sdk::Address,
)

Returns the amount out received for a given exact input swap without executing the swap @param token_in The token being swapped in @param token_out The token being swapped out @param fee The fee tier of the pool @param amount_in The amount of input tokens @param sqrt_price_limit_x96 The price limit; 0 for no limit @return amount_out The amount of output tokens that would be received

fn quote_exact_input_single(
    env: soroban_sdk::Env,
    token_in: soroban_sdk::Address,
    token_out: soroban_sdk::Address,
    fee: u32,
    amount_in: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
) -> Result

Returns the amount out received for a given exact input swap without executing the swap @param path The path of tokens to swap through, encoded as (token0, fee, token1, fee, token2, ...) @param amount_in The amount of the first token to swap @return amount_out The amount of the last token that would be received

fn quote_exact_input(
    env: soroban_sdk::Env,
    path: soroban_sdk::Bytes,
    amount_in: i128,
) -> Result

Returns the amount in required for a given exact output swap without executing the swap @param token_in The token being swapped in @param token_out The token being swapped out @param fee The fee tier of the pool @param amount_out The amount of output tokens desired @param sqrt_price_limit_x96 The price limit; 0 for no limit @return amount_in The amount of input tokens required

fn quote_exact_output_single(
    env: soroban_sdk::Env,
    token_in: soroban_sdk::Address,
    token_out: soroban_sdk::Address,
    fee: u32,
    amount_out: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
) -> Result

Returns the amount in required to receive the given exact output amount but for a swap of multiple pools @param path The path of tokens to swap through, encoded in REVERSE order (tokenOut, fee, tokenIn, ...) Note: For exact output, the path must be reversed from exact input @param amount_out The amount of the last token to receive @return amount_in The amount of the first token required

fn quote_exact_output(
    env: soroban_sdk::Env,
    path: soroban_sdk::Bytes,
    amount_out: i128,
) -> Result

Initialize the quoter with factory and XLM addresses

Note: Panics on initialization failure (e.g., if already initialized). This is intentional - a contract that fails to initialize should not be usable.

fn init_v2(
    env: soroban_sdk::Env,
    factory: soroban_sdk::Address,
    xlm: soroban_sdk::Address,
)
fn quote_exact_input_v2(
    env: soroban_sdk::Env,
    path: soroban_sdk::Bytes,
    amount_in: i128,
) -> Result
fn quote_exact_output_v2(
    env: soroban_sdk::Env,
    path: soroban_sdk::Bytes,
    amount_out: i128,
) -> Result
fn quote_exact_input_single_v2(
    env: soroban_sdk::Env,
    params: QuoteExactInputSingleParams,
) -> Result
fn quote_exact_output_single_v2(
    env: soroban_sdk::Env,
    params: QuoteExactOutputSingleParams,
) -> Result

Gets all populated ticks in a specific word of the tick bitmap

Arguments

  • env - The Soroban environment
  • pool - The address of the pool contract
  • tick_bitmap_index - The index of the tick bitmap word to query (i32)

Returns

A vector of PopulatedTick structs containing tick index, liquidity_net, and liquidity_gross

Note

This function mirrors the behavior of Uniswap V3's TickLens.getPopulatedTicksInWord:

  1. Fetches the bitmap for the specified word (256 bits)
  2. Counts populated ticks (bits set to 1)
  3. For each populated bit, calculates the actual tick and fetches its data
  4. Returns results in reverse order (matching Solidity's behavior)
fn get_populated_ticks_in_word(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
    tick_bitmap_index: i32,
) -> soroban_sdk::Vec

Gets all populated ticks across a range of bitmap words.

This function batches multiple bitmap word queries into a single call, reducing cross-contract call overhead for operations like liquidity charts.

Arguments

  • env - The Soroban environment
  • pool - The address of the pool contract
  • start_word - The first bitmap word index (can be negative)
  • count - Number of consecutive words to scan (capped at MAX_RANGE_COUNT)

Returns

A PopulatedTicksResult containing:

  • ticks: Vector of PopulatedTick structs in ascending order by tick index
  • truncated: True if results are incomplete for any reason

Ordering

NOTE: This function returns ticks in ASCENDING order (lowest tick first), which differs from get_populated_ticks_in_word that returns REVERSE order (matching Uniswap V3 Solidity behavior).

Limits & Truncation

The truncated flag is set to true if:

  • count exceeded MAX_RANGE_COUNT (256 words)
  • start_word was near i32::MAX causing range reduction
  • More than MAX_TICKS_BATCH (2
fn get_populated_ticks_in_range(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
    start_word: i32,
    count: u32,
) -> PopulatedTicksResult

Imports

WebAssembly Text (WAT) ▶