# 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.

```mermaid
flowchart LR
    I["Input
(X→Y, amount, constraints)"]
    LS["Load Snapshot
G_t"]
    GK["Generate k Candidates"]
    ES["Estimate
(out, fees, limits)"]
    SC["Score
(cost/speed/success)"]
    SB["Select Best
RoutePlan"]
    RQ["Return Quote
(+ TTL)"]

    I --> LS --> GK --> ES --> SC --> SB --> RQ
```

#### Pipeline Stages

<table><thead><tr><th width="78">#</th><th width="211">Stage</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td><strong>Input</strong></td><td>Receives the swap intent: source asset <code>X</code>, destination asset <code>Y</code>, amount, and any caller constraints.</td></tr><tr><td>2</td><td><strong>Load Snapshot G_t</strong></td><td>Loads the latest graph snapshot of available venues, liquidity, and token pairs at time <code>t</code>.</td></tr><tr><td>3</td><td><strong>Generate k Candidates</strong></td><td>Runs k-best path enumeration over the graph to produce a set of candidate routes.</td></tr><tr><td>4</td><td><strong>Estimate</strong></td><td>For each candidate, computes expected output amount, fees, and checks against venue limits.</td></tr><tr><td>5</td><td><strong>Score</strong></td><td>Ranks candidates using a composite score across cost, execution speed, and success probability.</td></tr><tr><td>6</td><td><strong>Select Best RoutePlan</strong></td><td>Picks the highest-scoring candidate and assembles it into a structured <code>RoutePlan</code>.</td></tr><tr><td>7</td><td><strong>Return Quote</strong></td><td>Returns the quote to the caller with a TTL, after which the <code>RoutePlan</code> is considered stale.</td></tr></tbody></table>

***

#### Input / Output

#### Input

<table><thead><tr><th width="156">Field</th><th>Description</th></tr></thead><tbody><tr><td><code>X → Y</code></td><td>Source and destination asset pair (e.g. USDT@ETH → ZEC@ZEC).</td></tr><tr><td><code>amount</code></td><td>The input amount to be swapped.</td></tr><tr><td><code>constraints</code></td><td>Caller-defined constraints: venue whitelist/blacklist, max fees, deadlines, etc.</td></tr></tbody></table>

#### Output

<table><thead><tr><th width="155">Field</th><th>Description</th></tr></thead><tbody><tr><td><code>RoutePlan</code></td><td>The fully resolved execution plan with ordered legs, venues, and adapters.</td></tr><tr><td><code>TTL</code></td><td>Expiry timestamp after which the quote must be re-requested.</td></tr></tbody></table>

***

#### 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.

\ <br>
