Skip to content

SmartRouter

SIP Protocol API Reference v0.7.4


SIP Protocol API Reference / 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
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 route
const best = routes[0]
console.log(`Best backend: ${best.backend}`)
console.log(`Cost: ${best.quote.fees.totalFeeUSD} USD`)
console.log(`Time: ${best.quote.estimatedTime}s`)

new SmartRouter(registry, options?): SmartRouter$1

Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7933

SettlementRegistry

SmartRouterOptions

SmartRouter$1

clearCache(): void

Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7937

Clear the quote cache

void


getCacheStats(): object

Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7941

Get cache statistics

object

size: number

maxSize: number


getBackendStatuses(): Map<string, CircuitBreakerStatus>

Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7948

Get backend health statuses

Map<string, CircuitBreakerStatus>


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.

FindBestRouteParams

Route finding parameters

Promise<RouteWithQuote[]>

Sorted routes (best first)

If no backends support the route


compareQuotes(routes): QuoteComparison

Defined in: @sip-protocol/sdk/dist/index-DXh2IGkz.d.ts:7976

Compare quotes from multiple routes side-by-side

RouteWithQuote[]

Routes to compare (from findBestRoute)

QuoteComparison

Comparison with best routes by different criteria