D-05 · Routing and quotes
[D-05]Layers
Routing and quotes
One route across every pool. Each route is simulated at the latest block, so what you see is what the chain would pay.
The terminal#
One token at a time: its pool, a day of swaps, the pool's depth, the seven checks and a ticket that simulates a trade.
| Part | From the chain |
|---|---|
| Price | The pool's price right after each swap: V2 Sync reserves, v4 sqrtPriceX96. Not the trade's average, so one big swap does not draw a false wick. |
| Pool | The busiest of the deepest V2 pair and the newest unhooked v4 pool against ETH, WETH or USDG. |
| Liquidity events | V2 Mint and Burn, v4 ModifyLiquidity: marked on the chart as added or taken out. |
| Depth | V2 only: how much buying or selling moves the price by each step, from x·y=k. |
| Pool maker | The wallet that created the pool and how many of its pools were drained, from Corbel's index. |
The exit plan takes your bag and what you paid. It simulates a full sale now and a sale in parts, says how far the price must rise to break even, how much buying the pool must see to get there, and a pace that sells no faster than buyers arrive.
How a quote is made#
- 01CollectDirect V2 and v4 pools, and two-hop paths through ETH or USDG.
- 02SimulateEvery route runs as a swap inside an eth_call at the latest block.
- 03RankRoutes are ordered by what they pay out. The best one is marked.
- 04ShowMinimum received at your slippage, price impact against a tiny trade, and gas.
curl "https://corbel.finance/api/quote?from=ETH&to=USDG&amount=1"
{
"from": "ETH", "to": "USDG", "amountIn": "1",
"block": "114498094",
"best": 0,
"impact": 0.0107,
"routes": [
{
"hops": [{ "venue": "v2", "fee": 3000, "hooked": false, "pool": "0x8803…1C4d" }],
"amountOut": "1739243284",
"gas": 66191,
"ok": true,
"reason": null
},
{
"hops": [{ "venue": "v4", "fee": null, "hooked": true }],
"amountOut": null,
"ok": false,
"reason": "The pool's hook refused the swap."
}
]
}Why a route says no fill#
| Reason | Means |
|---|---|
| The pool's hook refused the swap. | A v4 hook runs code on every swap, and this one reverted. |
| No liquidity on this side of the price. | The pool would pay nothing for this trade. |
