Router
Smart routing for optimal swap execution across multiple pools, including multi-hop swaps
Table of Contents
Overview
// Quick example: find best route for SUI -> USDC
const sdk = initFerraSDK({ network: 'mainnet', fullNodeUrl: '...', wallet: '0x...' })
await sdk.Router.loadGraphData()
const result = await sdk.Router.getBestInternalRouter(
'0x2::sui::SUI', // fromCoin
'0x...::usdc::USDC', // toCoin
new BN('1000000000'), // 1 SUI
true, // isFixedInput
100, // slippage (basis points, 100 = 1%)
'' // partner object ID (empty if none)
)
if (result) {
console.log('Best route found:')
result.paths.forEach((path, i) => {
console.log(` Path ${i}: ${path.poolAddress.join(' -> ')}`)
console.log(` Amount out: ${path.amountOut.toString()}`)
})
}Load Graph
From Remote API
Custom Graph Data
Find Best Route
Basic Usage
Parameters
Parameter
Type
Description
Result Structure
With Partner Fee
With Multi-Pool Fallback
Complete Example
Pool TVL
Utility Methods
Get Pool Address and Direction
Get Token Info
Get Fee Rate
Important Notes
Last updated