/** * Cost-Optimal Payment Router for x402 challenges. * * When an x402 challenge includes multiple `accepts[]` options (different * assets, networks, or facilitators), the router picks the cheapest one. * * This is utility-maximising routing: given N payment options, select the * one that minimises total cost to the agent. Total cost = asset amount + * estimated network fee - any discount for faster settlement. * * The router uses a pluggable PriceFeed interface so users can bring * their own pricing data (CoinGecko, Chainlink, custom oracle, or just * hardcoded stablecoin parity). * * Design: * - Stablecoins (USDC, EURC, DAI) are assumed to be ~$1 unless a * PriceFeed says otherwise. * - Network fee estimates are configurable per-network. Defaults * based on typical L2 vs L1 costs. * - Settlement speed is a tiebreaker, not a primary factor. */ /** An x402 payment option from the challenge's accepts[] array. */ export interface PaymentOption { /** Payment scheme (e.g., 'exact') */ scheme: string; /** Blockchain network (e.g., 'base', 'ethereum', 'arbitrum') */ network: string; /** Maximum amount required (as decimal string) */ maxAmountRequired: string; /** Asset to pay with (e.g., 'USDC', 'EURC') */ asset: string; /** Recipient address */ payTo: string; /** Resource URL */ resource: string; /** Description */ description?: string; /** Any extra fields from the challenge */ [key: string]: unknown; } /** Provides asset prices and network fee estimates. */ export interface PriceFeed { /** Get USD price of an asset. Return 1.0 for stablecoins. */ getAssetPriceUsd(asset: string): number | Promise; /** Get estimated network fee in USD for a transaction on this network. */ getNetworkFeeUsd(network: string): number | Promise; } /** Scored payment option with cost breakdown. */ export interface ScoredOption { /** The original payment option */ option: PaymentOption; /** Asset amount in USD */ amountUsd: number; /** Estimated network fee in USD */ networkFeeUsd: number; /** Total estimated cost in USD */ totalCostUsd: number; /** Settlement speed tier (1=fast L2, 2=medium, 3=slow L1) */ speedTier: number; /** Composite score (lower = better) */ score: number; } export interface PaymentRouterConfig { /** Custom price feed. Default: stablecoin parity + typical L2 fees. */ priceFeed?: PriceFeed; /** Weight for network fees in scoring (0-1). Default: 0.3 */ feeWeight?: number; /** Weight for settlement speed in scoring (0-1). Default: 0.1 */ speedWeight?: number; } /** * Routes x402 payments to the cheapest option. * * Usage: * const router = new PaymentRouter(); * const best = await router.select(challenge.accepts); * // best.option is the PaymentOption to use * // best.totalCostUsd is the estimated total cost */ export declare class PaymentRouter { private priceFeed; private feeWeight; private speedWeight; constructor(config?: PaymentRouterConfig); /** * Score and rank all payment options, return the best one. * Returns null if no options provided. */ select(options: PaymentOption[]): Promise; /** * Score all options and return ranked list (cheapest first). */ rank(options: PaymentOption[]): Promise; /** * Score a single payment option. */ private score; } //# sourceMappingURL=router.d.ts.map