Initializes the factory with an administrator and pool WASM hash.
Sets up the factory with default fee tiers matching Uniswap V3:
Initializes protocol fees to 0.
env - The contract environmentadmin - Address of the factory ownerwasm_hash - WASM hash of the pool contract to deployflash_executor - Address of the FlashExecutor contract (immutable)The flash_executor is set once at initialization and cannot be changed. This immutability provides:
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.
e - The contract environmentnew_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.
e - The contract environmentAddress - Current factory ownerfn 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.
env - The contract environmentAddress - Address of the FlashExecutor contractfn get_flash_executor(env: soroban_sdk::Env) -> soroban_sdk::Address
Sets the global protocol fee denominators for all pools.
env - The contract environmentfee_protocol0 - Protocol fee denominator for token0 (0 or 4-10)fee_protocol1 - Protocol fee denominator for token1 (0 or 4-10)Ok(()) on successErr(InvalidFeeProtocol) if either fee is not 0 or in range 4-10fn set_protocol_fee(
env: soroban_sdk::Env,
fee_protocol0: u32,
fee_protocol1: u32,
) -> Result<(), soroban_sdk::Error>
Returns the protocol fee denominator for token0.
env - The contract environmentu32 - 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.
env - The contract environmentu32 - 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.
e - The contract environmenttoken_a - First token addresstoken_b - Second token addressfee - Fee tier in basis pointsOk(Address) - Address of the newly created poolErr(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:
(tokenA, tokenB, fee) does not exist, it is deployed via the factory.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.
e - The contract environmenttoken_a - First token addresstoken_b - Second token addressfee - Fee tier in basis pointssqrt_price_x96 - Initial sqrt price in Q64.96 formatOk(Address) - Address of the pool (created or existing)Err(Error) - If creation or initialization failsfn 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.
env - The contract environmenttoken_a - First token addresstoken_b - Second token addressfee - Fee tier in basis pointsSome(Address) - Pool address if it existsNone - If no pool exists for this token pair and feefn 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.
env - The contract environmentrouter - Router address to auto-authorize on new poolsfn set_default_router(env: soroban_sdk::Env, router: soroban_sdk::Address)
Clears the default router setting.
env - The contract environmentfn clear_default_router(env: soroban_sdk::Env)
Authorizes or revokes a router for a specific pool.
env - The contract environmentpool - Pool address to configurerouter - Router address to authorize/revokeallowed - True to grant authorization, false to revokefn 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.
env - The contract environmentfee - Fee tier in basis points (must be < 1,000,000)tick_spacing - Tick spacing for this fee tier (must be > 0 and < 16,384)Ok(()) on successErr(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>