Skip to main content

JIT routing (beta)

Just-in-time (JIT) routing lets the block builder improve the route of a swap at block-building time using the freshest possible information to tighten spreads and mitigate spoofing risk.

JIT routing is triggered by a swap call on the JITSettler contract, which tells a builder to query a DEX routing system for fresh routes. The builder simulates your transaction with and without the new routes injected. If the builder is able to provide a better route, the swap call executes the route. If not, swap reverts. Since delivery of a JIT route cannot be guaranteed, the recommended use is for your transaction to execute a different "default" route if swap reverts. This route provides a baseline against which we measure improvement.

How it works​

  1. You send a transaction that calls the settler, and runs your route if the settler has no route or swap reverts.
  2. The builder simulates your transaction as it arrived. No route is posted yet, so your route runs. The amount your route pays in this simulation is the baseline.
  3. The builder asks the JIT router for a route that beats the baseline. The JIT router is an offchain service that searches the supported venues. The gain must cover the gas to post the route and the extra gas the route uses. Future versions will run an auction between multiple routers.
  4. If the JIT router returns a route, the builder simulates your transaction again with the route posted directly before it. It keeps the route only if your transaction succeeds and gets a better price.
  5. In the block, your swap call fills through the posted route. The settler pays at least your amountOutMin, or it reverts and your route runs.

Guarantees​

The system is built to provide low-risk, high-upside improvement. This is done through guarantees split across onchain and offchain logic. The JITSettler contract enforces these on every call:

  • A fill raises recipient's tokenOut balance by at least your amountOutMin, or swap reverts.
  • In each swap call, the settler makes one transfer of amountIn of tokenIn from your contract. A route cannot spend the rest of your approval.

The builder adds the following guarantees. No contract checks them:

  • It posts a route only when recipient receives more than it would without injection, after the posting charge, the fee and the cost of the extra gas that the route uses.

Anyone can post a route to the settler, but the system provides an easy mechanism to tell which builder posted the route, allowing you to set your own per-builder permissions. Your contract can also require onchain that a fill beats your route. Integrate JIT routing shows an integration with each.

What this version supports​

  • Ethereum mainnet, in BuilderNet blocks only. Future versions will work across multiple builders.
  • Any contract can call the settler. You do not need to register, and the builder tries to route every call it receives. It may skip small swaps, and under heavy load it prioritizes large swaps.
  • The builder takes a posting charge and a fee on the improvement from the route's output. See Fees.
  • Exact-input swaps between supported tokens. The settler takes ERC-20 tokens only, so wrap native ETH first.
  • Routes fill on the venues that the JIT router supports. That list changes as the JIT router adds venues.
  • A swap cannot exclude a venue. If you must avoid certain onchain venues, we do not recommend this feature.

Coming soon: more builders and routers​

Today only BuilderNet posts routes, and it gets them from one JIT router. The settler already lets any builder post a route, and a route can come from any router. Future versions will work across multiple builders and run an auction between multiple routers. The venues a swap can fill on will then depend on the routers that take part.

Keep the list of builders that your contract accepts routes from settable, so that you can add one.

Next steps​