Raum NetworkDeveloper Docs
RaumFi v2

RaumFi v2 Reference

Reference documentation for RaumFi v2 public contract functions, error codes, events, and integration surfaces across factory, pair, and router.

Factory (raumfi-factory)

FunctionDescription
initialize(setter, pair_wasm_hash)One-time setup. Sets fee_to_setter and fee_to to setter, and stores the pair contract's WASM hash for future deployments.
create_pair(token_a, token_b) -> AddressSorts the two tokens, deploys a new pair contract from the stored WASM hash at a deterministic address, and calls initialize on it. Fails if a pair already exists for that combination.
get_pair(token_a, token_b) -> AddressLooks up an existing pair's address. Errors with PairDoesNotExist if none exists.
pair_exists(token_a, token_b) -> boolChecks whether a pair has been created for the given tokens.
all_pairs(n) -> AddressReturns the n-th pair created (0-indexed).
all_pairs_length() -> u32Total number of pairs created.
fee_to() / fee_to_setter()Reads the current protocol fee recipient and the address allowed to change it.
fees_enabled() -> boolWhether the protocol fee is currently switched on. Read by every pair on deposit / withdraw.
set_fee_to(to) / set_fee_to_setter(new_setter)fee_to_setter-gated. Change the fee recipient, or hand off the setter role.
set_fees_enabled(is_enabled)fee_to_setter-gated. Toggles whether pairs mint the protocol's share of growth.

Errors (FactoryError): NotInitialized (201), CreatePairIdenticalTokens (202), CreatePairAlreadyExists (203), InitializeAlreadyInitialized (204), PairDoesNotExist (205), IndexDoesNotExist (206).

Events: initialize_factory_contract (on init), new_pair_created (token_0, token_1, pair, new_pairs_length).

Pair (raumfi-pair)

FunctionDescription
initialize(factory, token_0, token_1)Called once by the factory right after deployment. Requires token_0 < token_1. Derives the LP token's name/symbol from each underlying token's SEP-41 symbol().
deposit(to) -> i128Mints LP tokens for whatever excess token_0/token_1 balance the caller has already transferred in over the tracked reserves. Returns liquidity minted.
swap(amount_0_out, amount_1_out, to)Sends the requested output amounts to to, then verifies the constant-product invariant holds against whatever input tokens were sent in beforehand.
withdraw(to) -> (i128, i128)Burns whatever LP token balance the pair currently holds on its own address (sent there by the caller beforehand) and returns the pro-rata token_0/token_1 amounts to to.
skim(to)Sends any balance in excess of tracked reserves to to - recovers tokens sent directly to the pair outside the deposit/swap flow.
sync()Forces the tracked reserves to match actual token balances.
get_reserves() -> (i128, i128)Current reserve_0 / reserve_1.
k_multiplier() -> i128The reserve_0 * reserve_1 value recorded at the last protocol-fee mint (used internally by mint_fee).
token_0() / token_1() / factory()Stored addresses.

The pair also implements the full SEP-41 token::Interface (transfer, transfer_from, approve, allowance, balance, burn, burn_from, decimals, name, symbol) for its own LP token - the pair's contract address is the LP token's address.

Errors (PairError, selected): NotInitialized (102), DepositInsufficientFirstLiquidity (106), DepositInsufficientLiquidityMinted (107), SwapInsufficientLiquidity (110), SwapInvalidTo (111), SwapConstantNotMet (114), WithdrawInsufficientSentShares (116).

Events: deposit_pair_event, swap_pair_event, withdraw_pair_event, sync_pair_event.

Router (raumfi-router)

FunctionDescription
initialize(factory)One-time setup, stores the factory address.
add_liquidity(token_a, token_b, amount_a_desired, amount_b_desired, amount_a_min, amount_b_min, to, deadline) -> (i128, i128, i128)Creates the pair via the factory if it doesn't exist, computes the optimal deposit amounts given current reserves, transfers tokens in, and calls pair.deposit. Returns (amount_a, amount_b, liquidity).
remove_liquidity(token_a, token_b, liquidity, amount_a_min, amount_b_min, to, deadline) -> (i128, i128)Transfers LP tokens to the pair and calls pair.withdraw, enforcing the caller's minimum-amount bounds.
swap_exact_tokens_for_tokens(amount_in, amount_out_min, path, to, deadline) -> Vec<i128>Fixed input, minimum output. Chains swaps across every pair implied by path.
swap_tokens_for_exact_tokens(amount_out, amount_in_max, path, to, deadline) -> Vec<i128>Fixed output, maximum input.
router_pair_for(token_a, token_b) -> AddressComputes a pair's deterministic address locally, without a call to the factory.
router_quote(amount_a, reserve_a, reserve_b) -> i128Equivalent-value quote between two tokens, no fee applied.
router_get_amount_out(amount_in, reserve_in, reserve_out)Swap output after the 0.3% fee, given reserves directly.
router_get_amount_in(amount_out, reserve_in, reserve_out)Required input for a desired output.
router_get_amounts_out(amount_in, path) / router_get_amounts_in(amount_out, path)Chains the above across a multi-hop path, reading live reserves for each pair in path.
get_factory() -> AddressReturns the stored factory address.

Errors (RaumFiRouterError and RaumFiLibraryError, merged into RouterErrorsForLibrary): RouterDeadlineExpired, RouterInsufficientAAmount / RouterInsufficientBAmount, RouterInsufficientOutputAmount, RouterExcessiveInputAmount, RouterPairDoesNotExist, LibraryInsufficientLiquidity, LibraryInvalidPath, LibrarySortIdenticalTokens.

Events: initialized_router_contract, add_liquidity_event, remove_liquidity_event, swap_tokens_event.

Deployed contract addresses

Stellar Testnet, from the Audit_Inital_A2_Fix branch:

ContractAddress
RouterCCBKDA7BGP7RZW27LWAMZXXB6FN26JE6YWYLGFZXLGOKQUM2UPAVENWK
FactoryCCLJULBOBZDJN3ZFO3VXXBAIUP5IVYJSNXSGYS2PW5D26ATKJTEEOWHW

Individual pair addresses aren't listed here since they're deterministic and derived on demand - see Architecture for how the router resolves them locally without a factory call.