Best Execution
BestExecutionRouter ranks candidate routes across providers and returns a best route plus alternatives.
Enable it
Section titled “Enable it”const runtime = new DeFiRuntime({ chains, providers, wallet, bestExecution: { timeoutMs: 10_000, minProviders: 1, scoringWeights: { netOutput: 0.7, gasCost: 0.15, priceImpact: 0.15, }, crossChain: { enabled: true, maxPaths: 3, bridgeTimeWeight: 0.1, }, },});Query route rankings
Section titled “Query route rankings”const route = await runtime.getBestRoute({ inputToken: 'USDC', outputToken: 'WETH', amount: 1_000_000n, chain: 'ethereum-mainnet', destinationChain: 'arbitrum-one', slippageBps: 100, preferSpeed: true, preferMEVProtection: true, excludeProviders: ['provider-id-to-skip'], maxSlippageBps: 250,});
console.log(route.bestRoute.provider, route.bestRoute.score);console.log(route.routes.length);route.alternatives remains available as a backward-compat alias for route.routes.
Scoring signals
Section titled “Scoring signals”- estimated net output (dominant signal)
- fee and gas cost penalties
- price impact penalty
- optional bridge time penalty (for cross-chain paths)
- preference boosts for speed and MEV protection
Use this with Runtime lifecycle and provider-specific quote/route inspection.