6. Routing & Quote Generation

Quotes are computed from a graph snapshot G_t. The router generates k candidate routes, filters by hard constraints, estimates output ranges, and scores candidates to select an optimal RoutePlan.

Pipeline Stages

#
Stage
Description

1

Input

Receives the swap intent: source asset X, destination asset Y, amount, and any caller constraints.

2

Load Snapshot G_t

Loads the latest graph snapshot of available venues, liquidity, and token pairs at time t.

3

Generate k Candidates

Runs k-best path enumeration over the graph to produce a set of candidate routes.

4

Estimate

For each candidate, computes expected output amount, fees, and checks against venue limits.

5

Score

Ranks candidates using a composite score across cost, execution speed, and success probability.

6

Select Best RoutePlan

Picks the highest-scoring candidate and assembles it into a structured RoutePlan.

7

Return Quote

Returns the quote to the caller with a TTL, after which the RoutePlan is considered stale.


Input / Output

Input

Field
Description

X → Y

Source and destination asset pair (e.g. USDT@ETH → ZEC@ZEC).

amount

The input amount to be swapped.

constraints

Caller-defined constraints: venue whitelist/blacklist, max fees, deadlines, etc.

Output

Field
Description

RoutePlan

The fully resolved execution plan with ordered legs, venues, and adapters.

TTL

Expiry timestamp after which the quote must be re-requested.


Notes

  • The snapshot G_t is immutable per pipeline run — no live data is fetched mid-execution.

  • The scoring function weights cost, speed, and success rate and can be tuned per deployment.

  • If no valid candidate passes the estimation step, the pipeline returns an empty quote with a reason code.

6.1 Fixed-rate vs Floating

Baltex supports standard (floating) quotes and fixed-rate quotes. Fixed-rate quotes reserve inventory for a limited time; for Cross‑Chain fixed-rate execution, the rateId returned by /rate must be supplied to /exchange and is valid for 1 minute.

6.2 Scoring (reference form)

A practical scoring objective is multi-factor and can be expressed as: expected_out − total_fees − slippage_risk − reliability_penalty − time_penalty. Baltex’s quote engine considers network fees, venue depth, and slippage to identify the lowest-cost viable route.

Last updated