Contract 9f94c577ea24c2f71cbb0c964c9c9d321e02448d1fe946020afb18974b1c2602

← Back to Index 📥 Download WASM

Meta

binver 0.0.1
rssdkver 23.0.2#a97daf8b07cdf24e9bd45e344db51a21b9ea77d3
rsver 1.89.0

Instances

  • CD3KRKGDRVWPXVB3VXLUMQKMX6XZ6Q2H334IVZD4XXNAMKSRVQL5GLYF

Interface

Initializes the factory with an administrator and pool WASM hash.

Sets up the factory with default fee tiers matching Uniswap V3:

  • 0.05% (500 bps) with tick spacing 10 (for stablecoin pairs)
  • 0.3% (3000 bps) with tick spacing 60 (for most pairs)
  • 1% (10000 bps) with tick spacing 200 (for exotic pairs)

Initializes protocol fees to 0.

Arguments

  • env - The contract environment
  • admin - Address of the factory owner
  • wasm_hash - WASM hash of the pool contract to deploy
  • flash_executor - Address of the FlashExecutor contract (immutable)

Flash Executor

The flash_executor is set once at initialization and cannot be changed. This immutability provides:

  • Decentralization: No admin can update the executor
  • Security: Flash loan behavior is predictable and unchangeable
  • Trust: Users know the executor contract will never change
fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    wasm_hash: soroban_sdk::BytesN<32>,
    flash_executor: soroban_sdk::Address,
)

Transfers factory ownership to a new administrator.

Arguments

  • e - The contract environment
  • new_admin - Address of the new owner (requires current owner authorization)
fn set_owner(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)

Returns the current factory owner address.

Arguments

  • e - The contract environment

Returns

  • Address - Current factory owner
fn get_owner(env: soroban_sdk::Env) -> soroban_sdk::Address

Returns the flash executor address configured at initialization.

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

Arguments

  • env - The contract environment

Returns

  • Address - Address of the FlashExecutor contract
fn get_flash_executor(env: soroban_sdk::Env) -> soroban_sdk::Address

Sets the default pool wasm hash used for newly created pools.

Owner only.

fn set_pool_wasm_hash(env: soroban_sdk::Env, new_wasm_hash: soroban_sdk::BytesN<32>)

Returns the default pool wasm hash used for new pool deployments.

fn get_pool_wasm_hash(env: soroban_sdk::Env) -> soroban_sdk::BytesN<32>

Approves a pool wasm hash for in-place pool upgrades.

Owner only.

fn approve_pool_wasm_hash(env: soroban_sdk::Env, wasm_hash: soroban_sdk::BytesN<32>)

Revokes a previously approved pool wasm hash.

Owner only.

fn revoke_pool_wasm_hash(env: soroban_sdk::Env, wasm_hash: soroban_sdk::BytesN<32>)

Returns whether a pool wasm hash is approved for upgrades.

fn is_pool_wasm_hash_approved(
    env: soroban_sdk::Env,
    wasm_hash: soroban_sdk::BytesN<32>,
) -> bool

Sets whether pool upgrades are frozen.

Owner only.

fn set_upgrade_frozen(
    env: soroban_sdk::Env,
    frozen: bool,
) -> Result<(), soroban_sdk::Error>

Returns true when pool upgrades are currently frozen.

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

Permanently disables pool upgrades (one-way switch).

Owner only.

fn disable_upgrades_permanently(env: soroban_sdk::Env)

Returns true if upgrades were permanently disabled.

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

Upgrades a specific pool to a new approved wasm hash.

Owner only. Allowed only when !frozen && !permanently_disabled.

fn upgrade_pool(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
    new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), soroban_sdk::Error>

Calls pool.migrate(factory) on behalf of the factory.

Owner only. Must be called after upgrade_pool when the new pool code requires post-upgrade migration.

fn migrate_pool(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>

Sets the global protocol fee denominators for all pools.

Arguments

  • env - The contract environment
  • fee_protocol0 - Protocol fee denominator for token0 (0 or 4-10)
  • fee_protocol1 - Protocol fee denominator for token1 (0 or 4-10)

Returns

  • Ok(()) on success
  • Err(InvalidFeeProtocol) if either fee is not 0 or in range 4-10
fn set_protocol_fee(
    env: soroban_sdk::Env,
    fee_protocol0: u32,
    fee_protocol1: u32,
) -> Result<(), soroban_sdk::Error>

Returns the protocol fee denominator for token0.

Arguments

  • env - The contract environment

Returns

  • u32 - Protocol fee denominator for token0 (0 if disabled, or 4-10)
fn get_protocol_fee_0(env: soroban_sdk::Env) -> u32

Returns the protocol fee denominator for token1.

Arguments

  • env - The contract environment

Returns

  • u32 - Protocol fee denominator for token1 (0 if disabled, or 4-10)
fn get_protocol_fee_1(env: soroban_sdk::Env) -> u32

Creates a new pool for the given token pair and fee tier.

Arguments

  • e - The contract environment
  • token_a - First token address
  • token_b - Second token address
  • fee - Fee tier in basis points

Returns

  • Ok(Address) - Address of the newly created pool
  • Err(Error) - If validation fails (see pool::create_pool for error codes)
fn create_pool(
    env: soroban_sdk::Env,
    token_a: soroban_sdk::Address,
    token_b: soroban_sdk::Address,
    fee: u32,
) -> Result

Creates a pool if it doesn't exist and initializes it atomically.

This mirrors Uniswap V3's createAndInitializePoolIfNecessary behavior:

  • If the pool for (tokenA, tokenB, fee) does not exist, it is deployed via the factory.
  • The pool's initialize(sqrt_price_x96) is then invoked in the same Soroban call.

The entire operation is atomic: if initialization fails (e.g., invalid price or pool already initialized), the transaction reverts and the pool creation is rolled back.

Arguments

  • e - The contract environment
  • token_a - First token address
  • token_b - Second token address
  • fee - Fee tier in basis points
  • sqrt_price_x96 - Initial sqrt price in Q64.96 format

Returns

  • Ok(Address) - Address of the pool (created or existing)
  • Err(Error) - If creation or initialization fails

Notes

  • If the pool already exists and is initialized, this call no-ops and returns the address.
  • If the pool already exists but is not initialized, it will be initialized.
fn create_and_initialize_pool(
    env: soroban_sdk::Env,
    token_a: soroban_sdk::Address,
    token_b: soroban_sdk::Address,
    fee: u32,
    sqrt_price_x96: soroban_sdk::U256,
) -> Result

Returns the pool address for a given token pair and fee tier.

Arguments

  • env - The contract environment
  • token_a - First token address
  • token_b - Second token address
  • fee - Fee tier in basis points

Returns

  • Some(Address) - Pool address if it exists
  • None - If no pool exists for this token pair and fee
fn get_pool(
    env: soroban_sdk::Env,
    token_a: soroban_sdk::Address,
    token_b: soroban_sdk::Address,
    fee: u32,
) -> Option

Sets a default router to be auto-authorized on new pools.

Arguments

  • env - The contract environment
  • router - Router address to auto-authorize on new pools
fn set_default_router(env: soroban_sdk::Env, router: soroban_sdk::Address)

Clears the default router setting.

Arguments

  • env - The contract environment
fn clear_default_router(env: soroban_sdk::Env)

Authorizes or revokes a router for a specific pool.

Arguments

  • env - The contract environment
  • pool - Pool address to configure
  • router - Router address to authorize/revoke
  • allowed - True to grant authorization, false to revoke
fn set_pool_router_authorized(
    env: soroban_sdk::Env,
    pool: soroban_sdk::Address,
    router: soroban_sdk::Address,
    allowed: bool,
)

Enables a new fee tier with associated tick spacing.

Arguments

  • env - The contract environment
  • fee - Fee tier in basis points (must be < 1,000,000)
  • tick_spacing - Tick spacing for this fee tier (must be > 0 and < 16,384)

Returns

  • Ok(()) on success
  • Err(Error) - If validation fails (see fees::enable_fee_amount for error codes)
fn e_fee_amt(
    env: soroban_sdk::Env,
    fee: u32,
    tick_spacing: i32,
) -> Result<(), soroban_sdk::Error>

Imports

WebAssembly Text (WAT) ▶