Skip to content
docs

RouterSwap2Protocol

Defined in: protocol-swap2-router/src/swap2/router.ts:77

A swap2 protocol that asks every installed provider in parallel, checks each quote the same way, and executes the chosen route. Pass exactly one of providers or router.

const swap2 = new RouterSwap2Protocol(account, {
fromChain: 'eip155:1',
providers: [lifiProvider(), nearIntentsProvider(), cctpProvider()],
})
const quote = await swap2.quoteSwap2({ fromToken: 'USDC', toToken: 'USDC', toChain: 'eip155:8453', fromTokenAmount: 100_000_000n })
  • BaseSwap2Protocol

new RouterSwap2Protocol(account, config): RouterSwap2Protocol

Defined in: protocol-swap2-router/src/swap2/router.ts:82

unknown

RouterSwap2Config

RouterSwap2Protocol

BaseSwap2Protocol.constructor

protected readonly _account: IWalletAccountReadOnly | IWalletAccount

Defined in: core/dist/index-QWdcwE6y.d.ts:309

BaseSwap2Protocol._account


protected readonly _config: Swap2ProtocolConfig

Defined in: core/dist/index-QWdcwE6y.d.ts:310

BaseSwap2Protocol._config


protected readonly fromChain: string

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:215

BaseSwap2Protocol.fromChain

protected assertFeeCaps(fees, sourceAmount, sourceToken, config?): void

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:247

readonly Swap2Fee[] | undefined

bigint

string

Swap2ProtocolConfig

void

BaseSwap2Protocol.assertFeeCaps


protected assertFeeConfig(config?): void

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:246

Swap2ProtocolConfig

void

BaseSwap2Protocol.assertFeeConfig


protected assertQuoteFeeCaps(q, options, config?): void

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:248

Quote

Swap2Options

Swap2ProtocolConfig

void

BaseSwap2Protocol.assertQuoteFeeCaps


bridge(options): Promise<BridgeResult>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:302

The inherited bridge() has no floor field: quote first, then bind execution to that quote’s minimum so the inherited convenience API stays safe.

BridgeOptions

Promise<BridgeResult>

BaseSwap2Protocol.bridge


protected chainSupported(caip2): boolean

Defined in: protocol-swap2-router/src/swap2/router.ts:142

Whether this protocol can route a chain at all (for support discovery).

string

boolean

BaseSwap2Protocol.chainSupported


claimSwap2(id, account): Promise<{ chain: string; hash: string; id: string; }>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:295

Two-phase routes (CCTP-style burn-and-mint): once getSwap2Status reports “action-required”, the delivery needs a second transaction on the DESTINATION chain, signed there and paid in that chain’s gas. account is the destination-chain account (the bound source account is not reused: the chains differ). The provider builds the claim from the attestation; it is refused when not ready, when it names another chain than the account, or when it is anything but plain EVM calldata. Returns the claim hash and the status id to keep polling with.

string

unknown

Promise<{ chain: string; hash: string; id: string; }>

BaseSwap2Protocol.claimSwap2


close(): void

Defined in: protocol-swap2-router/src/swap2/router.ts:151

Release the providers’ resources (timers, sockets).

void


describeActivity(tx, ctx): ActivityItem | null

Defined in: protocol-swap2-router/src/swap2/router.ts:138

Delegates to every provider the router holds (first match wins); null with no providers.

ChainTx

DescribeActivityContext

ActivityItem | null

BaseSwap2Protocol.describeActivity


protected emitPhase(phase, detail?): void

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:228

Report an execution phase; an observer that throws is ignored.

Swap2ExecutionPhase

Swap2ExecutionPhaseDetail

void

BaseSwap2Protocol.emitPhase


getSupportedChains(): Promise<Swap2SupportedChain[]>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:306

Source chains this protocol can swap from.

Promise<Swap2SupportedChain[]>

BaseSwap2Protocol.getSupportedChains


getSupportedTokens(options?): Promise<Swap2SupportedToken[]>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:308

Tokens of the asset catalog on the supported chains, optionally narrowed.

Swap2SupportedTokensOptions

Promise<Swap2SupportedToken[]>

BaseSwap2Protocol.getSupportedTokens


getSwap2Status(id, _options?): Promise<Swap2StatusResult>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:284

Status of a swap by the id swap2() returned, asked from the provider that executed it.

string

Swap2StatusOptions

Promise<Swap2StatusResult>

BaseSwap2Protocol.getSwap2Status


protected noRouteDetail(): string

Defined in: protocol-swap2-router/src/swap2/router.ts:129

Why the last resolveQuote came back empty (venue names + reasons), or “”. Rides inside the no-route error so execution failures are diagnosable from the surface that shows them.

string

BaseSwap2Protocol.noRouteDetail


protected pairSupported(fromChain, toChain): boolean

Defined in: protocol-swap2-router/src/swap2/router.ts:146

Pair-level capability used when discovery specifies both endpoints.

string

string

boolean

BaseSwap2Protocol.pairSupported


protected prepareOptions(options): Promise<Swap2Options>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:242

Options ready to quote: with allowUnlistedTokens, an unlisted source token gets its decimals, read from the chain through the account (cached per token) — a caller’s fromTokenDecimals that disagrees is refused. Listed tokens and every option otherwise pass through unchanged.

Swap2Options

Promise<Swap2Options>

BaseSwap2Protocol.prepareOptions


protected protocolEnabled(): boolean

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:230

Runtime availability used by the public discovery methods.

boolean

BaseSwap2Protocol.protocolEnabled


protected providerFor(name): CrossChainProvider | undefined

Defined in: protocol-swap2-router/src/swap2/router.ts:133

Look up a provider by name to resume/track an in-flight swap2.

string

CrossChainProvider | undefined

BaseSwap2Protocol.providerFor


quoteBridge(options): Promise<BridgeQuote>

Defined in: core/dist/index-QWdcwE6y.d.ts:609

The older quoteBridge, run through quoteSwap2.

BridgeOptions

Promise<BridgeQuote>

BaseSwap2Protocol.quoteBridge


quoteSwap(options): Promise<SwapQuote>

Defined in: core/dist/index-QWdcwE6y.d.ts:605

The older quoteSwap, run through quoteSwap2.

SwapOptions

Promise<SwapQuote>

BaseSwap2Protocol.quoteSwap


quoteSwap2(options): Promise<Swap2Quote>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:261

Ask for a quote and check it against the request (amounts, slippage floor, fee ceilings in the protocol config). Works on a read-only account.

Swap2Options

Promise<Swap2Quote>

Swap2QuoteError when no route answers, with the provider’s own reason when it gave one.

BaseSwap2Protocol.quoteSwap2


quoteSwap2Routes(options, opts?): Promise<Swap2Route[]>

Defined in: protocol-swap2-router/src/swap2/router.ts:110

Every route for a picker, ranked, with the best and the fastest tagged. onUpdate gets the ranked list each time another provider answers, so a UI shows the first price as soon as the fastest venue replies. Routes the caller’s floor or fee caps refuse are left out. Execute the one the user picks with using(route.provider).swap2(...).

Swap2Options

(routes, pending) => void

Promise<Swap2Route[]>


protected requireSigningAccount(methodName): IWalletAccount

Defined in: core/dist/index-QWdcwE6y.d.ts:322

The account, narrowed to a signing one, or a ReadOnlyAccountError naming the caller.

string

IWalletAccount

BaseSwap2Protocol.requireSigningAccount


protected resolveQuote(params): Promise<Quote | null>

Defined in: protocol-swap2-router/src/swap2/router.ts:99

Quote the route (single provider, or best across the router).

QuoteParams

Promise<Quote | null>

BaseSwap2Protocol.resolveQuote


protected routeQuote(q, options): Swap2Quote | null

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:253

A dry route the auction already validated → the public quote, or null when the caller’s floor / fee caps refuse it.

Quote

Swap2Options

Swap2Quote | null

BaseSwap2Protocol.routeQuote


protected snapshotOf(options): Swap2Options

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:251

A frozen, validated copy of caller options (what every engine path works from).

Swap2Options

Swap2Options

BaseSwap2Protocol.snapshotOf


protected sourceAsset(options): CcAsset | undefined

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:235

The source asset the options name: the catalog’s, or (allowUnlistedTokens) an unlisted one with its decimals.

Swap2Options

CcAsset | undefined

BaseSwap2Protocol.sourceAsset


swap(options): Promise<SwapResult>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:304

Same protection for legacy exact-in swap() calls whose min is optional.

SwapOptions

Promise<SwapResult>

BaseSwap2Protocol.swap


swap2(options, config?): Promise<Swap2Result>

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:271

Re-quote, check the quote, show it to reviewExecution when configured, send any approvals, then sign and broadcast the source leg. An identical call already in flight on the same account is refused.

Swap2Options

Swap2ProtocolConfig

Promise<Swap2Result>

Swap2ExecutionError for a read-only account, Swap2InFlightError for a double tap, Swap2MaybeSentError when the broadcast outcome is unknown (do not retry; track hash).

BaseSwap2Protocol.swap2


protected toParams(given, dry): QuoteParams

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:244

Swap2Options → the engine’s QuoteParams (exact-in only).

Swap2Options

boolean

QuoteParams

BaseSwap2Protocol.toParams


protected toQuote(q, options): Swap2Quote

Defined in: protocol-swap2-core/dist/swap2/base.d.ts:249

Quote

Swap2Options

Swap2Quote

BaseSwap2Protocol.toQuote


using(provider): RouterSwap2Protocol

Defined in: protocol-swap2-router/src/swap2/router.ts:124

This protocol pinned to one provider — the route a user picked from quoteSwap2Routes.

string

RouterSwap2Protocol