Uniswap Labs Blog

Auto Router V2
December 16, 2021

Today, we’re releasing a series of features to improve pricing and optimize gas cost of swaps:

  • An updated Auto Router that finds the best price across Uniswap v2 + v3 while optimizing for gas prices
  • Auto Router support for Uniswap Protocol on Layer 2 Networks
  • Real-time gas estimates on your swap
  • Smarter auto slippage

We’re also releasing the full Auto Router to the community as a convenient npm package and sharing new developer tools:

  • Auto Router npm package
  • Atomic swap + add liquidity
  • Oracle-based slippage

The updated Auto Router improves trade prices even further by routing trades across both Uniswap v2 and v3 pools. It also finds the best price across all Uniswap protocols, and optimizes gas costs in the process, so you never have to worry about which version you’re using.

In addition, starting today the Auto Router supports all of the Uniswap Protocol’s Layer 2 networks: Optimistic Ethereum and Arbitrum. The combination of highly efficient trade pricing of the Auto Router with the low gas costs of a Layer 2 network, delivers a cheaper trading experience than ever before.

To help you make informed decisions about gas costs, we’re also excited to announce gas cost estimates in the Uniswap App. You will now see a USD estimate of the gas fee before submitting a swap, so you can wait for the right moment to trade.

Finally, we’re releasing two new capabilities for Uniswap developers. The first is called ‘Swap-and-add liquidity’ which allows you to provide liquidity with one asset instead of two by automatically swapping to the right ratio. The second is slippage limits relative to v3’s time-weighted-average-price feeds.

Gas Aware Route Splitting Across v2 and v3

In September, we launched the Auto Router, a smart order routing algorithm that splits trades across multiple Uniswap v3 pools while accounting for gas costs.

The Auto Router has been a major win for Uniswap v3 users: our analysis shows that the Auto Router improves pricing for 13.97% of all trades and 36.84% of trades between the Top 10 tokens by TVL.

While Uniswap v3 has grown to over $3b in daily trade, Uniswap v2 remains a large liquidity venue on Ethereum, with over $700m in volume.

The Auto Router now splits trades across both v2 and v3 liquidity pools to find the best price across both these industry-leading protocols. Additionally, trades on v2 can be split across up to seven paths to take advantage of liquidity depth in different pools. The Auto Router is also gas-aware and will only take an extra hop or split if it results in a better net rate for you.

In the example below, the new Auto Router finds a +0.64% better price quote by splitting the trade across both Uniswap v2 and v3 liquidity.


These improvements are made possible by a new SwapRouter contract which will require new ERC-20 token approvals. In order to save gas fees, the app will compare the older router price to the new router price, and only use the new router if it offers a better price.

By default, the App uses a Uniswap Labs hosted instance of the Auto Router to efficiently compute your route with low latency. For those who wish to remove this dependency, you can disable the Auto Router API in settings to compute your route locally in the browser, with slightly higher latency.

Layer 2 Network Support

The Auto Router is now available on all networks where Uniswap Protocol is deployed: Optimistic Ethereum and Arbitrum. This makes trading on these networks even more efficient than before.

Real Time Gas Estimates

Gas prices have increased over the past few months and knowing the right time to submit a transaction can be difficult. We’re excited to launch an estimated gas cost feature, allowing you to monitor the true cost of a swap in real time directly from the App interface.


Smarter Auto Slippage

We’re using these gas estimates to get smarter about slippage, too. Historically, the App has defaulted to 0.5% slippage because in many cases you’re better off re-submitting a transaction that fails due to high slippage. But if you’re trading smaller amounts, high gas fees often make resubmission too costly.

The Uniswap App will now automatically set slippage based on your expected gas cost and trade size. For smaller trades, the App will adjust slippage tolerance to improve the chance of the transaction succeeding. As always, you can manually set your slippage limits in the App settings.

For Developers

Auto Router npm Package

The above improvements are made possible by the open-source Auto Router. In order to help more developers take advantage of these capabilities, we are today launching an npm package to quickly import the Auto Router in your project. Read this developer guide to get started with the @uniswap/smart-order-router package.

SwapRouter02.sol Contract

The new SwapRouter02.sol contract has been deployed and is fully open source. Check out the code on GitHub.

Swap and Add

The new router contract now offers an atomic ‘swap-and-add’ function that makes it possible to provide liquidity with only one of the asset’s in the pool, or any ratio of the two assets.

In order to add liquidity to a Uniswap v3 pool, the user or contract must provide two assets in a particular ratio. In many cases, the user only holds a single asset or an arbitrary ratio of the two assets. This means you often have some tokens left over after adding liquidity. A simple approach is to submit a swap transaction to reach the optimal ratio and then submit an add liquidity transaction -- but your swap (and other transactions in between) will have changed the optimal ratio!

The new SwapRouter makes it possible to swap and then add liquidity in a single atomic transaction. The smart-order-router npm package even includes a function to compute the optimal ratio and transaction calldata. Check out this new developer guide to learn how to swap-and-add in your project today.

This is available to developers today and coming soon to the Uniswap App.

Oracle Slippage

The new router also allows you to limit the relative price impact of trades as measured against v3 oracles, not just the current state of on-chain liquidity. For example, a user swapping ETH for USDC could specify that their swap can only execute within one percentage point of the five minute ETH/USDC time-weighted average price. This mitigates MEV and sandwich attacks for safe, automated, permissionless trading. Check out the OracleSlippage.sol contract for more detail.

We’re excited for you to enjoy smarter swaps in the Uniswap App and to hear about your experience using the new features.

To get involved and stay up to date:

  • Join the Uniswap community discord
  • Follow Uniswap Labs on Twitter
  • Subscribe to the Uniswap Labs blog
  • Register as a delegate on Sybil
  • Participate in Uniswap governance

Uniswap Team 🦄

Related posts