Contract 48ed6b333d1b757c133579d5a0e2eef31da8c76e2d87656c003afb191730b0df

← Back to Index 📥 Download WASM

Meta

rssdkver 27.0.5#ea54f95d3f2f49e0487b29fd1a9f469638f09aba
rsver 1.95.0

Instances

  • CCT3IA6HKUA5GCAR7XLSNR4N5V2WEKDM6G4OSZ4EDXNS56CLDFBT2BDO

Interface

Simple single-venue swap. Backend picks the best venue.

fn swap(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    token_in: soroban_sdk::Address,
    token_out: soroban_sdk::Address,
    amount_in: i128,
    min_amount_out: i128,
    venue_id: u32,
) -> Result

Current protocol fee as (numerator, denominator).

fn get_fee(env: soroban_sdk::Env) -> (i128, i128)

Set the protocol fee (per 100,000 of total output). Admin only, hard-capped at MAX_FEE_PER_100K (0.5 bps); 0 is valid (fee holiday).

fn set_fee(env: soroban_sdk::Env, fee_per_100k: i128) -> Result<(), RouterError>

Get the contract address for a venue.

fn get_venue(
    env: soroban_sdk::Env,
    venue_id: u32,
) -> Result

Get all registered venue IDs.

fn get_venues(env: soroban_sdk::Env) -> soroban_sdk::Vec

Complete an admin rotation — callable only by the proposed admin, proving the new key is live before it holds power.

fn accept_admin(env: soroban_sdk::Env) -> Result<(), RouterError>

ATOMIC MULTI-HOP: execute a whole path (up to MAX_PATH_HOPS swaps, venues mixed freely per hop) in ONE invocation. One signature; if any hop disappoints, the entire path reverts and the user keeps exactly what they started with. Funds never rest in a wallet between hops, and each hop swaps the previous hop's ACTUAL output (no conservative min-out chaining as with multi-transaction plans).

The protocol fee applies once, on the FINAL output, and min_final_out protects the user net of it. estimated_out: the GROSS final output the caller was quoted — execution above it splits the surplus per get_surplus_share (0 disables capture for this call). Rejected below min_final_out so a lowballed estimate can't reclassify honest output as surplus.

fn execute_path(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    token_in: soroban_sdk::Address,
    total_amount_in: i128,
    min_final_out: i128,
    hops: soroban_sdk::Vec,
    estimated_out: i128,
) -> Result

Remove a venue. Admin only.

fn remove_venue(env: soroban_sdk::Env, venue_id: u32) -> Result<(), RouterError>

Deploy-time constructor — atomic with deployment, cannot be front-run.

fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    fee_vault: soroban_sdk::Address,
    swap_book: soroban_sdk::Address,
)

Execute a multi-venue routed swap for user.

Verifies: segments are positive and sum to total_amount_in; every venue exists; net output (after the 0.5 bps protocol fee on the TOTAL output) meets min_total_out — otherwise the whole tx reverts.

estimated_out: the GROSS output the caller was quoted. When execution beats it, the protocol keeps get_surplus_share of the surplus (the user still receives at least the estimate net of the flat fee). 0 disables surplus capture for this call.

fn execute_route(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    token_in: soroban_sdk::Address,
    token_out: soroban_sdk::Address,
    total_amount_in: i128,
    min_total_out: i128,
    segments: soroban_sdk::Vec,
    estimated_out: i128,
) -> Result

Register a new DEX venue adapter. Admin only.

fn register_venue(
    env: soroban_sdk::Env,
    venue_id: u32,
    contract_address: soroban_sdk::Address,
) -> Result<(), RouterError>

Propose a new admin (two-step rotation). Admin only. The proposed address must call accept_admin to take over, so a mistyped transfer is recoverable until accepted.

fn transfer_admin(
    env: soroban_sdk::Env,
    new_admin: soroban_sdk::Address,
) -> Result<(), RouterError>

Current positive-slippage share as (numerator, denominator).

fn get_surplus_share(env: soroban_sdk::Env) -> (i128, i128)

Set the protocol's share of positive slippage (bps of the surplus above the caller-supplied estimate). Admin only, hard-capped at MAX_SURPLUS_SHARE_BPS (50%); 0 disables capture entirely.

fn set_surplus_share(env: soroban_sdk::Env, share_bps: i128) -> Result<(), RouterError>

PERMISSIONLESS keeper entry point: route a timer-expired SwapBook order through DEX venues and settle the maker — all in one invocation.

  1. Claims the order from SwapBook (escrow moves to this contract; SwapBook authorizes us via invoker auth and returns the maker's on-chain price floor min_out).
  2. Executes the provided route segments.
  3. Deducts the protocol fee, enforces net proceeds >= min_out, and pays the maker.

Anyone may call this — a caller gains nothing (proceeds always go to the maker) and a bad route simply reverts, leaving the order claimable again... (revert restores the order's Open state too).

fn route_expired_order(
    env: soroban_sdk::Env,
    order_id: u64,
    segments: soroban_sdk::Vec,
) -> Result

execute_route with an integrator partner fee carved from the output ON TOP of the protocol fee — the partner's cut never comes out of protocol revenue, and min_total_out protects the user net of BOTH fees. partner_fee_per_100k is capped at 100 bps.

fn execute_route_partner(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    token_in: soroban_sdk::Address,
    token_out: soroban_sdk::Address,
    total_amount_in: i128,
    min_total_out: i128,
    segments: soroban_sdk::Vec,
    partner: soroban_sdk::Address,
    partner_fee_per_100k: i128,
    estimated_out: i128,
) -> Result

Imports

WebAssembly Text (WAT) ▶