StarkFiStarkFi

Fibrous DEX Aggregator

Optimal swap routing, batch routing, and USD pricing

Overview

Fibrous is a DEX aggregator on Starknet that finds optimal swap routes across multiple liquidity sources. StarkFi uses Fibrous for all swap operations — single trades, multi-swaps, and batch operations.

How StarkFi Uses Fibrous

FeatureFibrous APIStarkFi Command
Single SwapgetRoute()getCalldata()trade
Multi-SwapgetRouteBatch()getCalldataBatch()multi-swap
Batch SwapgetRoute() per pairbatch --swap
USD PricinggetRoute() price fieldbalance, portfolio
Health CheckcheckFibrousHealth()status

API Endpoints

EndpointFunctionPurpose
GET /routegetRoute()Get swap route + expected output for a single pair
GET /calldatagetCalldata()Get executable calldata with slippage protection
GET /routeBatchgetRouteBatch()Batch routing for up to 3 pairs (same destination token)
GET /healthCheckcheckFibrousHealth()API health and availability status

Base URL: https://api.fibrous.finance/starknet

Configuration

SettingValue
Base URLhttps://api.fibrous.finance/starknet
Router Contract0x00f6f4CF62E...FDf5a
Default Slippage1%
Max Batch Pairs3

How Routing Works

Single Swap

1. getRoute(tokenIn, tokenOut, amount)    →  Find optimal route + expected output
2. getCalldata(tokenIn, tokenOut, amount) →  Generate executable calldata with slippage
3. Execute via TxBuilder:  approve → swap

Multi-Swap (Batch)

When all pairs share the same output token, Fibrous uses the native routeBatch endpoint for more efficient routing. Otherwise, StarkFi falls back to parallel individual getRoute() calls:

1. getRouteBatch(pairs)       →  Get routes for 2-3 pairs simultaneously
2. getCalldataBatch(pairs)    →  Generate calldata for each pair
3. Execute via TxBuilder:  approve₁ → swap₁ → approve₂ → swap₂ → ...

USD Pricing

StarkFi uses Fibrous route data for real-time USD price estimation. This powers the balance, portfolio, and lend-status commands:

  1. Route 1 unit of the target token → USDC
  2. Read the inputToken.price from the route response
  3. USDC and USDT short-circuit to $1.00 (no API call needed)

Error Handling

ErrorCauseResolution
NO_ROUTE_FOUNDNo liquidity path existsTry a different token pair or smaller amount
BATCH_LIMIT_EXCEEDEDMore than 3 pairs in multi-swapSplit into multiple transactions
NETWORK_ERRORFibrous API unreachableCheck status with starkfi status, retry later

All requests use automatic retry with exponential backoff for transient network errors.

Edit on GitHub

Last updated on

On this page