Router Swap
Execute optimized swaps through Ferra's smart router for best rates.
Overview
The Router module automatically finds the optimal path for your swap by:
Path Discovery: Finds all possible routes between tokens
TVL Optimization: Prioritizes pools with higher liquidity
Multi-hop Support: Routes through intermediate tokens when beneficial
Best Rate Selection: Compares all paths to find optimal execution
Quick Start
// 1. Find best route
const bestRoute = await sdk.Router.getBestInternalRouter(
'0x2::sui::SUI', // From token
'0x...::usdc::USDC', // To token
new BN('1000000000'), // Amount (1 SUI)
true, // Fix input amount
0.01, // 1% slippage
'' // No partner
)
// 2. Create swap transaction
if (bestRoute && !bestRoute.isExceed) {
const tx = await TransactionUtil.buildRouterSwapTransaction(
sdk,
bestRoute.createTxParams,
true, // byAmountIn
allCoinAssets
)
const result = await sdk.fullClient.signAndExecuteTransaction({
transaction: tx,
signer: keypair
})
}Find Optimal Route
Basic Route Finding
With Fallback Options
Route Types
Single-Hop Route
Direct swap in one pool:
Multi-Hop Route
Through intermediate token:
Complete Swap Flow
Load Graph Data
Router needs graph data to find paths:
Advanced Features
TVL-Based Routing
Router prioritizes high-TVL pools:
Custom Path Preferences
Fix Output Amount
Error Handling
Route Information
Important Notes
Router automatically loads graph data on first use
Multi-hop limited to 2 pools (3 tokens max)
TVL-based routing improves execution quality
Partner fees not supported with split paths
Always check
isExceedbefore executingGraph data cached for performance
Last updated