Contract c1aa54e88e5af6f82a2be5c8ebd033565a5c58af35cd71496199aa541166291f

← Back to Index 📥 Download WASM

Meta

rssdkver 23.0.2#a97daf8b07cdf24e9bd45e344db51a21b9ea77d3
rsver 1.89.0

Instances

  • CBYRPHV6PZZIJTH3QUUAE3SLNYRJ2Q6BUUONEV6GI2KJJPUJQAZE3AIG
  • CC2J4J2CIOILIM2FJ3FCSPS5IHUOBL7MXFZ6MZATSPZAOFVM2MHQME4X
  • CCNVOJGNCPZEI5MMSE6NDSX3NAEZVYKRA4M3QIXBZNH2QVBVSR6ELJ72
  • CCRVQM46MREI7D5SALRQSIX37A6YJSU6MPIT5ESKCCGLQDMKLROXSFUL
  • CD6HH5YD3G7TUS6KGFWIMNPX2SP2KR5KWKYNVTIMRJ4LX2OBNUKKHBYI
  • CDNKCL6E5KRTLV3GX3T5KNL664ICIWCD3FMYPP6TVG3UU4Q2SAHKFQ4H

Interface

Constructor called by the factory when deploying a new pool.

Arguments

  • env - The contract environment
  • factory - Address of the factory contract that created this pool
  • token0 - Address of the first token in the pair
  • token1 - Address of the second token in the pair
  • fee - Fee tier for this pool (in basis points)
  • tick_spacing - Minimum tick spacing for this pool
  • flash_executor - Address of the authorized FlashExecutor contract (immutable)
fn __constructor(
    env: soroban_sdk::Env,
    factory: soroban_sdk::Address,
    token0: soroban_sdk::Address,
    token1: soroban_sdk::Address,
    fee: u32,
    tick_spacing: i32,
    flash_executor: soroban_sdk::Address,
)

Validates that tick range is properly ordered and within bounds.

Arguments

  • env - The contract environment
  • tick_lower - Lower tick of the range
  • tick_upper - Upper tick of the range

Returns

  • Ok(()) if ticks are valid
  • Err if ticks are invalid (wrong order, out of bounds, or misaligned with tick_spacing)
fn check_ticks(
    env: soroban_sdk::Env,
    tick_lower: i32,
    tick_upper: i32,
) -> Result<(), soroban_sdk::Error>

Returns the current ledger timestamp.

Arguments

  • env - The contract environment

Returns

Current timestamp in seconds

fn block_timestamp(env: soroban_sdk::Env) -> u64

Initializes the pool with a starting price.

Must be called before any liquidity operations. Can only be called once.

Arguments

  • env - The contract environment
  • sqrt_price_x96 - Initial sqrt price in Q64.96 format

Returns

  • Ok(()) on success
  • Err(AlreadyInitialized) if pool is already initialized
fn initialize(
    env: soroban_sdk::Env,
    sqrt_price_x96: soroban_sdk::U256,
) -> Result<(), soroban_sdk::Error>

Swaps tokens in the pool.

Transfers tokens from sender and sends output tokens to recipient.

Arguments

  • env - The contract environment
  • sender - Address providing input tokens (requires auth)
  • recipient - Address receiving output tokens
  • zero_for_one - True if swapping token0 for token1, false otherwise
  • amount_specified - Amount to swap (positive for exact input, negative for exact output)
  • sqrt_price_limit_x96 - Price limit for the swap in Q64.96 format

Returns

  • Ok(SwapResult) containing amounts swapped and final price
  • Err if swap fails (locked, invalid price limit, etc.)
fn swap(
    env: soroban_sdk::Env,
    sender: soroban_sdk::Address,
    recipient: soroban_sdk::Address,
    zero_for_one: bool,
    amount_specified: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
    hints: OracleHints,
) -> Result

Swaps tokens using prefunded input already held by the pool.

Assumes input tokens have been transferred to the pool before calling. Only authorized routers can call this function. Verifies available delta via baseline accounting system before executing the swap.

Arguments

  • env - The contract environment
  • router - Address of the authorized router (requires auth)
  • recipient - Address receiving output tokens
  • zero_for_one - True if swapping token0 for token1, false otherwise
  • amount_specified - Amount to swap (positive for exact input, negative for exact output)
  • sqrt_price_limit_x96 - Price limit for the swap in Q64.96 format

Returns

  • Ok(SwapResult) containing amounts swapped and final price
  • Err(Unauthorized) if router is not authorized
  • Err on other failures (locked, invalid price limit, insufficient balance)
fn swap_prefunded(
    env: soroban_sdk::Env,
    router: soroban_sdk::Address,
    recipient: soroban_sdk::Address,
    zero_for_one: bool,
    amount_specified: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
    hints: OracleHints,
) -> Result

Manages authorization for routers allowed to call swap_prefunded.

Only the pool's factory can call this function.

Arguments

  • env - The contract environment
  • factory - Address of the factory (requires auth, must match pool's factory)
  • router - Address of the router to authorize/unauthorize
  • allowed - True to authorize, false to remove authorization

Returns

  • Ok(()) on success
  • Err(Unauthorized) if caller is not the pool's factory
fn set_router_authorized(
    env: soroban_sdk::Env,
    factory: soroban_sdk::Address,
    router: soroban_sdk::Address,
    allowed: bool,
) -> Result<(), soroban_sdk::Error>

Burns liquidity from a position.

Removes liquidity from the specified tick range and credits the owed tokens to the position. Tokens must be collected separately via collect.

Arguments

  • env - The contract environment
  • owner - Address owning the position (requires auth)
  • tick_lower - Lower tick of the position range
  • tick_upper - Upper tick of the position range
  • amount - Amount of liquidity to burn

Returns

  • Ok((amount0, amount1)) - Amounts of token0 and token1 owed to the position
  • Err(Locked) if pool is currently locked
  • Err on other failures (invalid ticks, position not found)
fn burn(
    env: soroban_sdk::Env,
    owner: soroban_sdk::Address,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    hints: OracleHints,
) -> Result<(u128, u128), soroban_sdk::Error>

Collects fees accumulated by a liquidity position.

Transfers owed tokens to the recipient. Fees are computed when liquidity is added or removed via mint/burn, not when collecting.

Arguments

  • env - The contract environment
  • recipient - Address receiving the fees (requires auth, must be position owner)
  • tick_lower - Lower tick of the position range
  • tick_upper - Upper tick of the position range
  • amount0_requested - Maximum amount of token0 to collect
  • amount1_requested - Maximum amount of token1 to collect

Returns

  • Ok((amount0, amount1)) - Actual amounts collected (min of requested vs owed)
  • Err(Error) if position fee update fails
fn collect(
    env: soroban_sdk::Env,
    owner: soroban_sdk::Address,
    recipient: soroban_sdk::Address,
    tick_lower: i32,
    tick_upper: i32,
    amount0_requested: u128,
    amount1_requested: u128,
) -> Result<(u128, u128), soroban_sdk::Error>

Collects protocol fees accumulated by the pool.

Only the factory owner can call this function. Keeps a minimum of 1 token in the slot to save on storage gas costs.

Arguments

  • env - The contract environment
  • recipient - Address receiving the protocol fees (requires factory owner auth)
  • amount0_requested - Maximum amount of token0 to collect
  • amount1_requested - Maximum amount of token1 to collect

Returns

  • Ok((amount0, amount1)) - Actual amounts collected
  • Err(Error) if pool is not initialized or params are missing
fn collect_protocol(
    env: soroban_sdk::Env,
    recipient: soroban_sdk::Address,
    amount0_requested: u128,
    amount1_requested: u128,
) -> Result<(u128, u128), soroban_sdk::Error>

Begin a flash loan

Only the authorized FlashExecutor can call this. Must be followed by flash_end() in the same transaction.

Arguments

  • recipient - Address to receive borrowed tokens
  • amount0 - Amount of token0 to borrow
  • amount1 - Amount of token1 to borrow
  • initiator - Address of the flash loan initiator (must be FlashExecutor)

Returns

  • Ok((fee0, fee1, oracle_hints)) - Fees that must be repaid and oracle hints for swaps
fn flash_begin(
    env: soroban_sdk::Env,
    recipient: soroban_sdk::Address,
    amount0: u128,
    amount1: u128,
    initiator: soroban_sdk::Address,
) -> Result<(u128, u128, OracleHints), soroban_sdk::Error>

End a flash loan

Must be called by the same initiator that called flash_begin(). Verifies repayment and clears the flash lock.

Returns

  • Ok(()) if repayment is sufficient
  • Err(InsufficientRepayment0/1) if repayment is insufficient
fn flash_end(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>

Returns the current pool state.

Arguments

  • env - The contract environment

Returns

Slot0 containing current sqrt price, tick, and lock status

fn slot0(env: soroban_sdk::Env) -> Slot0

Returns whether the pool has been initialized.

Arguments

  • env - The contract environment

Returns

true if initialized, false otherwise

fn is_initialized(env: soroban_sdk::Env) -> bool

Returns the factory address that created this pool.

Arguments

  • env - The contract environment

Returns

Address of the factory contract

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

Returns the address of token0 in the pair.

Arguments

  • env - The contract environment

Returns

Address of token0

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

Returns the address of token1 in the pair.

Arguments

  • env - The contract environment

Returns

Address of token1

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

Returns the pool's fee tier.

Arguments

  • env - The contract environment

Returns

Fee in basis points (e.g., 3000 = 0.3%)

fn fee(env: soroban_sdk::Env) -> u32

Returns the pool's tick spacing.

Arguments

  • env - The contract environment

Returns

Tick spacing (e.g., 60 means positions must be on multiples of 60)

fn tick_spacing(env: soroban_sdk::Env) -> i32

Returns the flash executor address for this pool.

The flash executor is immutable and set once during pool deployment. This is the only authorized contract that can initiate flash loans on this pool.

Arguments

  • env - The contract environment

Returns

Address of the FlashExecutor contract

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

Returns the protocol fee for zero_for_one swaps from the factory.

Arguments

  • env - The contract environment

Returns

Protocol fee in basis points

fn get_protocol_fee_0(env: soroban_sdk::Env) -> u32

Returns the protocol fee for one_for_zero swaps from the factory.

Arguments

  • env - The contract environment

Returns

Protocol fee in basis points

fn get_protocol_fee_1(env: soroban_sdk::Env) -> u32

Returns a tick bitmap word for off-chain quoters and lens contracts.

Arguments

  • env - The contract environment
  • word_pos - The word position in the bitmap

Returns

256-bit word from the tick bitmap

fn get_tick_bitmap(env: soroban_sdk::Env, word_pos: i32) -> soroban_sdk::U256

Returns the current active liquidity.

Arguments

  • env - The contract environment

Returns

Total liquidity currently active at the current tick

fn liquidity(env: soroban_sdk::Env) -> u128

Returns the global fee growth for token0.

Arguments

  • env - The contract environment

Returns

Fee growth in Q128.128 format

fn fee_growth_global_0_x128(env: soroban_sdk::Env) -> FixedPoint128

Returns the global fee growth for token1.

Arguments

  • env - The contract environment

Returns

Fee growth in Q128.128 format

fn fee_growth_global_1_x128(env: soroban_sdk::Env) -> FixedPoint128

Returns the accumulated protocol fees.

Arguments

  • env - The contract environment

Returns

ProtocolFees struct containing amounts for both tokens

fn protocol_fees(env: soroban_sdk::Env) -> ProtocolFees

Returns information about a specific tick.

Arguments

  • env - The contract environment
  • tick - The tick index to query

Returns

TickInfo struct, or default (uninitialized) if tick hasn't been used

fn ticks(env: soroban_sdk::Env, tick: i32) -> TickInfo

Returns all data needed for position fee calculations in a single call.

Arguments

  • env - The contract environment
  • tick_lower - The lower tick of the position
  • tick_upper - The upper tick of the position

Returns

PositionFeeData struct containing slot0, global fee growth, and tick info

fn get_position_fee_data(
    env: soroban_sdk::Env,
    tick_lower: i32,
    tick_upper: i32,
) -> PositionFeeData

Returns complete pool state in a single call for efficient batch queries.

This function is designed for the PoolLens contract to minimize cross-contract call overhead. Returns None if the pool is not initialized, eliminating the need for a separate is_initialized check.

Arguments

  • env - The contract environment

Returns

  • Some(PoolState) if pool is initialized with all config and trading state
  • None if pool is not initialized
fn get_full_pool_state(env: soroban_sdk::Env) -> Option

Returns complete pool state with token balances (reserves) in a single call.

Similar to get_full_pool_state but also fetches the token balances held by the pool. This requires two additional cross-contract calls to the token contracts, adding ~1M CPU instructions per pool.

Arguments

  • env - The contract environment

Returns

  • Some(PoolStateWithBalances) if pool is initialized with state and reserves
  • None if pool is not initialized

Note

Use this when you need TVL/reserve information. If you don't need balances, prefer get_full_pool_state.

fn get_pool_state_with_balances(env: soroban_sdk::Env) -> Option

Returns cumulative values inside a tick range for a given position.

Used to compute time-weighted averages and liquidity-weighted time within a price range for liquidity mining and other analytics.

Arguments

  • env - The contract environment
  • tick_lower - Lower tick of the range
  • tick_upper - Upper tick of the range

Returns

  • Ok((tick_cumulative, seconds_per_liquidity_cumulative, seconds_inside))
  • Err(TickNotInitialized) if either tick hasn't been initialized
fn snapshot_cumulatives_inside(
    env: soroban_sdk::Env,
    tick_lower: i32,
    tick_upper: i32,
    hints: OracleHints,
) -> Result<(i64, FixedPoint128, u32), soroban_sdk::Error>

Observes oracle data for a single time point.

Returns tick cumulative and seconds per liquidity cumulative values for computing time-weighted averages.

Arguments

  • env - The contract environment
  • seconds_ago - How many seconds in the past to observe (0 = current)

Returns

  • Ok((tick_cumulative, seconds_per_liquidity_cumulative_x128))
  • Err if observation doesn't exist or is too old
fn observe_single(
    env: soroban_sdk::Env,
    seconds_ago: u32,
    hints: OracleHints,
) -> Result<(i64, FixedPoint128), soroban_sdk::Error>

Observes oracle data for multiple time points.

Returns tick cumulative and seconds per liquidity cumulative values for each requested time point, for computing time-weighted averages.

Arguments

  • env - The contract environment
  • seconds_agos - Vector of seconds in the past to observe (0 = current)

Returns

  • Ok((tick_cumulatives, seconds_per_liquidity_cumulatives_x128))
  • Err if any observation doesn't exist or is too old
fn observe(
    env: soroban_sdk::Env,
    seconds_agos: soroban_sdk::Vec,
    hints: OracleHints,
) -> Result<
    (soroban_sdk::Vec, soroban_sdk::Vec),
    soroban_sdk::Error,
>

Permissionless oracle poke to record a fresh observation.

Writes a new oracle observation using the current pool tick and liquidity. If called within MIN_OBSERVATION_INTERVAL of the last write, this is a no-op.

Returns a tuple (updated, last_timestamp) where:

  • updated is true if a new observation was recorded
  • last_timestamp is the timestamp of the latest observation after this call
fn poke_oracle(
    env: soroban_sdk::Env,
    oracle_slot_hint: u128,
) -> Result<(bool, u64), soroban_sdk::Error>

Returns oracle hints for deterministic queries.

Convenience function that returns both slot and checkpoint hints in a single call, ready to pass to swap/mint/burn/observe functions.

Works both before and after pool initialization:

  • Before init: returns { slot: computed, checkpoint: 0 }
  • After init: returns { slot: computed, checkpoint: actual_count }
fn get_oracle_hints(env: soroban_sdk::Env) -> OracleHints

Get oracle status for UI decisions.

Returns information about the oracle's current state to help the frontend decide when to show/enable the "Refresh price" button.

Returns

A tuple (last_timestamp, age_seconds, can_poke) where:

  • last_timestamp: Unix timestamp of the most recent observation
  • age_seconds: How many seconds have elapsed since the last observation
  • can_poke: Whether calling poke_oracle would update the oracle (respects MIN_OBSERVATION_INTERVAL - at least 1 ledger ≈ 5 seconds)
fn get_oracle_status(
    env: soroban_sdk::Env,
) -> Result<(u64, u64, bool), soroban_sdk::Error>

Mints liquidity to a position.

Creates or adds to a liquidity position in the specified tick range. Transfers the required amounts of both tokens from the sender.

Arguments

  • env - The contract environment
  • sender - Address initiating the mint and providing tokens (requires auth)
  • recipient - Address receiving the liquidity position (position owner)
  • tick_lower - Lower tick of the position range
  • tick_upper - Upper tick of the position range
  • amount - Amount of liquidity to mint

Returns

  • Ok((amount0, amount1)) - Amounts of tokens deposited
  • Err(AmountShouldBeGreaterThanZero) if amount is zero
  • Err(Locked) if pool is currently locked
  • Err(InsufficientToken0/Token1) if token transfer fails
fn mint(
    env: soroban_sdk::Env,
    sender: soroban_sdk::Address,
    recipient: soroban_sdk::Address,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    hints: OracleHints,
) -> Result<(u128, u128), soroban_sdk::Error>

Returns a tick bitmap word (public variant).

Arguments

  • env - The contract environment
  • word_pos - The word position in the bitmap

Returns

256-bit word from the tick bitmap, or zero if uninitialized

fn get_tick_bitmap_public(env: soroban_sdk::Env, word_pos: i32) -> soroban_sdk::U256

Quotes an exact input swap without executing it.

Simulates a swap to determine output amount and final price without transferring tokens or modifying state.

Arguments

  • env - The contract environment
  • zero_for_one - True if swapping token0 for token1, false otherwise
  • amount_in - Exact amount of input tokens
  • sqrt_price_limit_x96 - Price limit for the swap in Q64.96 format

Returns

  • Ok(SwapResult) containing output amount and final sqrt price
  • Err if swap would fail (invalid price limit, etc.)
fn quote_exact_input(
    env: soroban_sdk::Env,
    zero_for_one: bool,
    amount_in: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
) -> Result

Quotes an exact output swap without executing it.

Simulates a swap to determine input amount required for a desired output without transferring tokens or modifying state.

Arguments

  • env - The contract environment
  • zero_for_one - True if swapping token0 for token1, false otherwise
  • amount_out - Exact amount of output tokens desired
  • sqrt_price_limit_x96 - Price limit for the swap in Q64.96 format

Returns

  • Ok(SwapResult) containing required input amount and final sqrt price
  • Err if swap would fail (invalid price limit, insufficient liquidity)
fn quote_exact_output(
    env: soroban_sdk::Env,
    zero_for_one: bool,
    amount_out: i128,
    sqrt_price_limit_x96: soroban_sdk::U256,
) -> Result

Returns position data for a specific owner and tick range.

Arguments

  • env - The contract environment
  • recipient - Address of the position owner
  • tick_lower - Lower tick of the position range
  • tick_upper - Upper tick of the position range

Returns

PositionData containing liquidity, fee growth, and tokens owed

Panics

Panics if position doesn't exist

fn positions(
    env: soroban_sdk::Env,
    recipient: soroban_sdk::Address,
    tick_lower: i32,
    tick_upper: i32,
) -> PositionData

Imports

WebAssembly Text (WAT) ▶