SmartRouter
SIP Protocol API Reference v0.7.4
SIP Protocol API Reference / SmartRouter
Class: SmartRouter
Section titled “Class: SmartRouter”Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7927
Smart Router for finding optimal settlement routes
Queries all compatible backends in parallel and ranks routes by:
- Total cost (network + protocol fees)
- Execution speed (estimated time)
- Privacy support (shielded vs transparent)
Features:
- Quote caching with configurable TTL (default: 30s)
- Per-backend timeouts (default: 5s)
- Circuit breaker for failing backends
- Error isolation with Promise.allSettled
Example
Section titled “Example”const registry = new SettlementRegistry()registry.register(nearIntentsBackend)registry.register(zcashBackend)
const router = new SmartRouter(registry, { cacheTtlMs: 30_000, backendTimeoutMs: 5_000,})
const routes = await router.findBestRoute({ from: { chain: 'ethereum', token: 'USDC' }, to: { chain: 'solana', token: 'SOL' }, amount: 100_000000n, privacyLevel: PrivacyLevel.SHIELDED, preferLowFees: true})
// Get best routeconst best = routes[0]console.log(`Best backend: ${best.backend}`)console.log(`Cost: ${best.quote.fees.totalFeeUSD} USD`)console.log(`Time: ${best.quote.estimatedTime}s`)Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SmartRouter(
registry,options?):SmartRouter$1
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7933
Parameters
Section titled “Parameters”registry
Section titled “registry”options?
Section titled “options?”SmartRouterOptions
Returns
Section titled “Returns”SmartRouter$1
Methods
Section titled “Methods”clearCache()
Section titled “clearCache()”clearCache():
void
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7937
Clear the quote cache
Returns
Section titled “Returns”void
getCacheStats()
Section titled “getCacheStats()”getCacheStats():
object
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7941
Get cache statistics
Returns
Section titled “Returns”object
size:
number
maxSize
Section titled “maxSize”maxSize:
number
getBackendStatuses()
Section titled “getBackendStatuses()”getBackendStatuses():
Map<string,CircuitBreakerStatus>
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7948
Get backend health statuses
Returns
Section titled “Returns”Map<string, CircuitBreakerStatus>
findBestRoute()
Section titled “findBestRoute()”findBestRoute(
params):Promise<RouteWithQuote[]>
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7959
Find best routes for a swap
Queries all compatible backends in parallel and returns sorted routes. Uses caching, per-backend timeouts, and circuit breaker for reliability.
Parameters
Section titled “Parameters”params
Section titled “params”Route finding parameters
Returns
Section titled “Returns”Promise<RouteWithQuote[]>
Sorted routes (best first)
Throws
Section titled “Throws”If no backends support the route
compareQuotes()
Section titled “compareQuotes()”compareQuotes(
routes):QuoteComparison
Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7976
Compare quotes from multiple routes side-by-side
Parameters
Section titled “Parameters”routes
Section titled “routes”Routes to compare (from findBestRoute)
Returns
Section titled “Returns”Comparison with best routes by different criteria