-
Notifications
You must be signed in to change notification settings - Fork 15
docs(drift): draft from internal source #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pedromcunha
wants to merge
1
commit into
main
Choose a base branch
from
docs-drift/src-49ad972807-d08bc9a
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --- | ||
| title: "Route Racing" | ||
| description: "Opt into on-chain multi-route execution that picks the best swap output at fill time." | ||
| --- | ||
|
|
||
| Route Racing is a feature that trials multiple candidate swap routes on-chain in a single transaction and executes the one producing the best output. Instead of committing the fill to a single provider quote picked at solve time, Relay submits a bundle of routes through a periphery contract that isolates each route in a reverting subcall, measures the actual output, and settles the winner — turning provider-selection risk into a deterministic on-chain comparison. | ||
|
|
||
| ## Requirements | ||
|
|
||
| Before you can start route racing, you need: | ||
|
|
||
| 1. **An API key** — Required to authenticate your quote requests. Create one in the [Relay Dashboard](https://dashboard.relay.link); see [API keys and Rate Limits](/references/api/api-keys) for details. | ||
| 2. **Route racing enabled on your API key** — Route racing is gated per API key. Contact Relay to have the feature enabled on the key you plan to use. | ||
|
|
||
| Once your key is enabled, opt into racing on individual quote requests. | ||
|
|
||
| --- | ||
|
|
||
| ## How to use it? | ||
|
|
||
| To route race a fill, call [`POST /quote/v2`](/references/api/get-quote-v2) with **`useRouteRacing`** set to `true`. Racing only activates when every eligibility condition is met — otherwise the fill falls back to the single-quote path with no error. | ||
|
|
||
| ### Eligibility | ||
|
|
||
| Route racing applies to a fill only when **all** of the following are true: | ||
|
|
||
| 1. **Your API key is authorized** — the **`useRouteRacing: true`** request field takes effect only when the key has the grant. Requests from unauthorized keys are accepted but not raced. | ||
| 2. **Trade type is `EXACT_INPUT`** — racing picks the winner by maximum output, which matches the exact-input objective. Expected-output quotes do not race. | ||
| 3. **Destination chain is EVM and route-racing-enabled** — the chain must have the RouteRacer periphery contract deployed. Non-EVM chains (Solana, Bitcoin, etc.) never race. | ||
| 4. **Fill size is above the minimum** — the input amount's USD value must exceed **`routeRacingMinUsdSize`** (default `100`). There is no upper bound. | ||
| 5. **At least two viable candidate routes are returned** — if fewer than two competitive routes are available at fill time, the fill takes the single-quote path. | ||
|
|
||
| When any condition fails, the fill silently falls back to the standard single-quote execution path, so opting in is safe on every request. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeGroup> | ||
| ```typescript API | ||
| const API_KEY = "YOUR_API_KEY"; | ||
|
|
||
| const quoteResponse = await fetch("https://api.relay.link/quote/v2", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "Authorization": `Bearer ${API_KEY}`, | ||
| }, | ||
| body: JSON.stringify({ | ||
| user: "WALLET_ADDRESS", | ||
| originChainId: 1, | ||
| destinationChainId: 8453, | ||
| originCurrency: "0x0000000000000000000000000000000000000000", | ||
| destinationCurrency: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", // USDC on Base | ||
| amount: "1000000000000000000", | ||
| tradeType: "EXACT_INPUT", | ||
| // Opt into route racing for this quote | ||
| useRouteRacing: true, | ||
| // Optional: only race when the fill is above $250 (default is $100) | ||
| routeRacingMinUsdSize: 250, | ||
| }), | ||
| }); | ||
|
|
||
| const quote = await quoteResponse.json(); | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| <Info> | ||
| The **`routeRacingMinUsdSize`** parameter is a floor, not a target. Fills at or below the threshold — or whose input cannot be priced — take the single-quote path. Racing has no maximum fill size. | ||
| </Info> | ||
|
|
||
| --- | ||
|
|
||
| ## Caveats | ||
|
|
||
| - Route racing runs at fill time on the destination chain — the initial quote returned to the user does not reflect the raced execution, and the improved output surfaces only after settlement. | ||
| - The reported **`minimumAmountOut`** is the smallest guaranteed minimum across candidates, because any candidate may end up winning. The realized output will meet or exceed the best candidate's expected output on success. | ||
| - Racing is EVM-only and EXACT_INPUT-only today. | ||
| - The API-key grant is re-checked at fill time. If the grant is removed between quote and fill, subsequent regenerations stop racing and fall back to the single-quote path. | ||
| - We recommend protecting your API key on the backend by not exposing it to the client. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example uses
Authorization: Bearer ${API_KEY}, but Relay API keys are supplied throughx-api-key. The quote endpoint accepts the copied request as an unauthenticated public quote, which masks the issue; however, it cannot identify the key whose Route Racing grant should be applied. Use"x-api-key": API_KEYso copied integrations can opt into the key-scoped feature.Artifacts
Route Racing API-key header validation source
Before response using the copied Authorization Bearer header
After response using the documented x-api-key header