Announcing 0x Swap API v1

Announcing a new version of 0x Swap API’s swap endpoint, the best DEX aggregator.

October 1, 2020

News

TL;DR

  • 7 out of 10 times 0x Swap API offers better adjusted prices than 1inch, Dex Ag, Paraswap and Uniswap. That is, the price after transaction fees are paid.
  • Swap API v1 delivers market-leading gas efficiency. With a custom, highly-optimized architecture, accessing Uniswap’s liquidity through Swap API is now as cheap and often cheaper than going to Uniswap directly.
  • DeFi developers can find the Swap API docs here. Existing integrators can use this guide to migrate to v1.
  • Traders can go to Matcha — which uses Swap API under the hood — to buy and sell assets at the best price possible across all DEX liquidity sources.

In January 2020 we launched v0 of 0x Swap API, a public tool designed to make it simple for DeFi developers to tap into all DEX liquidity in a fast and reliable way. Since launch, Swap API has processed over 29K trades that in total represent ~$550 million in trading volume.

Swap API monthly volume since launch 🏒

The version 0 release represented a solid starting point, but it was clear that there was still plenty of room for improving and pushing the DEX aggregation space forward. So, we spent the last eight months gathering feedback and iterating, and today we are proud to launch a revamped Swap API v1: the highest-performing, professional-grade DEX aggregator in the industry. For 7 out of 10 trades, users get a better adjusted price through Swap API than through 1inch, DexAg, Paraswap and Uniswap.

With a simple http request, developers can fetch the best available price across 13 liquidity sources — including exclusive 0x liquidity from professional liquidity providers and proprietary AMMs, as well as 0x Mesh, Uniswap, Oasis, Kyber, Curve, Balancer, Bancor, mStable, Mooniswap, Sushiswap and Swerve. In addition to fetching prices from these liquidity sources, under the hood the /swap/quote endpoint leverages smart order routing algorithms to split orders across sources to reduce slippage and achieve the best price for a given trade.

Quoted versus Adjusted Prices

We built Swap API v1 with one goal in mind: offering the best prices after accounting for transaction costs.

These days it is not uncommon to see screenshots comparing quotes between DEX aggregators for a given trade on Twitter. The problem with this is that comparing aggregators on quoted prices is a bad business for users as often the best quoted price does not result in the best deal once transaction costs are paid. We believe that using adjusted price is a more objective metric and a better way to measure performance between aggregators as it is what the user ultimately gets in their wallet. Wait, but why?

Adjusted price is what a user receives after a transaction is completed on-chain and transaction costs (gas and fees) are paid. It can be calculated using the following formula:

adjusted_price = sold_amount_usd / ( bought_amount_usd — transaction_costs_usd )

Let’s use an example to illustrate this:

A user wants to trade 100 DAI for USDC. Aggregator #1 quotes 100 USDC with a transaction cost of $5. Using the formula above, we can determine that adjusted price = 100 / ( 100–5 ) = $1.05.

The same user checks out a second aggregator. Aggregator #2 quotes 104 USDC for the same 100 DAI, but with a transaction cost of $10. In this case, adjusted price = 100 / (104–10) = $1.06.

In this example, Aggregator 1 wins as it ultimately finds a cheaper rate for the user to convert 100 DAI to 100 USDC. While aggregator #2 initially quoted a better rate and bought more tokens, you can observe how the transaction cost impacted the adjusted price. In conclusion, spending an additional $5 to only receive an additional 4 USDC resulted in a more expensive deal for the user.

The majority of existing aggregators seem to optimize to win quoted prices and attract users, but we often see them failing at delivering the best adjusted price. By optimizing for adjusted prices and accounting for gas costs in Swap API smart order routing, 0x API offers the best adjusted prices 7 out of 10 times.

Quoted and adjusted prices winning rates for Swap API, 1inch, Dex Ag, Paraswap and Uniswap. 0x API outperforms other exchanges ~72% of the time by offering better prices after accounting for gas.

Reducing Gas Usage

Reducing gas usage has been a focus for our team for the past eight months. Our initial target was to cut down transaction costs by 50%, however, in Swap API v1 we achieved to cut down transaction costs, on average, by ~76% vs v0. Gas usage is currently around 460K gwei for a $50K trade, down from 1.5M gwei for the same trade in v0. These optimizations have turned Swap API into the most efficient aggregator across all trade sizes.

While, on average, Swap API uses more gas than Uniswap, Swap API offers better adjusted prices than Uniswap 7 out of 10 times. How is this possible? At 0x Labs we built a super optimized contract that allows Swap API to source liquidity that is 100% routed through Uniswap in a more gas efficient way than the default Uniswap contracts. This is particularly beneficial for smaller trades (<$5K), which are typically routed to a single source.

To exemplify this, let’s take a look at the following two transactions:

Swap API v1 delivers market-leading gas efficiency. With a custom, highly-optimized architecture, accessing Uniswap’s liquidity through Swap API is now as cheap and often cheaper than going to Uniswap directly.

The first transaction (left) shows an ETH<>UNI trade made by going directly to Uniswap. The second transaction (right) shows an equivalent ETH<>UNI trade being 100% routed to Uniswap via Swap API. As shown in the “gas used by transaction” field, the Uniswap transaction cost ~114K gas and the Swap API transaction cost ~110K gas, that is 3.7% cheaper. Certain on-chain state and conditions can change the results (for example, if the user needs to set new allowances), but in general, using Swap API to trade on Uniswap is now as cheap and often cheaper than going to Uniswap directly.

What’s else is new in v1?

  • Nine new liquidity sources for a total of 13, with new ones being added frequently.
  • Two Swap API exclusive liquidity sources: 0x RFQT and 0x private AMM.
  • The 0x protocol fee is no longer incurred for external liquidity sources, lowering transaction costs further.
  • Last-minute, on-chain routing to adjust (and often improve) quotes for market movements that can occur between submission and on-chain confirmation.
  • A new settlement contract that allows us have more accurate fills and gas usage lower than any other aggregator.
  • Multi-hop, a new piece of logic in our smart order routing that allows us to bridge liquidity to illiquid markets.
  • A super optimized contract that allows Swap API to source Uniswap in a more gas efficient way than the default Uniswap contracts.
  • Support for ERC20>ETH trades.
  • Support for affiliateFee, a percentage based fee integrators can add to monetize their product.
  • excludedSources, a parameter that allows integrators to exclude specific sources from the routing.
  • New /meta_transaction endpoints that allow integrators to remove or defer the requirement that the user must pay for gas and protocol fees with ETH. It provides a superset of the liquidity available via the /swap/quote endpoint.

Contents

Subscribe to newsletter

By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong, but it's not your fault.

Up next

Fundamentals: SocialFi

Nov 26, 2024

Unlock powerful onchain insights with 0x Trade Analytics API

Nov 5, 2024

Fundamentals: Smart Contract Wallets

Oct 15, 2024

Compliance made easy with 0x Address Screening

Sep 26, 2024

0x's next-gen pricing engine is now live

Sep 25, 2024

Introducing state-of-the-art Buy/Sell Tax support

Sep 4, 2024

Take control of your balance sheet with 0x v2

Aug 15, 2024

0x v2 bug bounty program

Jul 30, 2024

What does the "best price" in DeFi really mean?

Jul 23, 2024

Eliminate allowance risk with Permit2

Jul 17, 2024

Introducing 0x's next-gen pricing engine

Jul 15, 2024

0x Dev Digest: May 2024

May 31, 2024

Frame spotlight: Paycaster

May 21, 2024

Frame spotlight: Airstack

May 9, 2024

Power up your Farcaster Frames with 0x swaps

May 2, 2024

0x Dev Digest: April 2024

Apr 30, 2024

Introducing 0x Trade Analytics

Mar 12, 2024

Coinbase Case Study

Jan 30, 2024

Introducing gasless swaps and approvals with Gasless API

Jan 22, 2024

Bitcoin ETFs have arrived

Jan 12, 2024

Building in the open: 0x pricing update

Dec 11, 2023

Matcha leverages Gasless API to bring users the most frictionless trading experience in DeFi

Nov 30, 2023

0x Dev Digest: October 2023

Nov 2, 2023

Monetize crypto trading in your app with Swap API

Oct 26, 2023

0x Dev Digest: September 2023

Oct 3, 2023

A comprehensive analysis of RFQ performance

Sep 26, 2023

Unlock optimal trades in Swap API with 0x RFQ liquidity

Sep 20, 2023

0x Dev Digest: August 2023

Aug 31, 2023

Portal launches swaps in its white label MPC wallet powered by 0x

Aug 16, 2023

0x Swap API is now live on Base

Aug 9, 2023

Introducing paid plans for Swap API

Jul 24, 2023

Decreasing Frictions in DeFi hackathon recap

Jul 12, 2023

0x's pricing principles

Jul 3, 2023

0x Dev Digest: June 2023

Jun 30, 2023

App spotlight: tastycrypto

Jun 27, 2023

App spotlight: 31Third

Jun 22, 2023

0x 101: Intro to gasless API

Jun 13, 2023

Inspiration for building with Swap API

Jun 8, 2023

0x Dev Digest: May 2023

May 31, 2023

Fundamentals: What are gas fees?

May 25, 2023

Decreasing Frictions in DeFi Hackathon

May 12, 2023

Swap API liquidity management

May 18, 2023

0x 101: Getting started with Swap API

May 16, 2023

0x 101: Intro to Swap API

May 9, 2023

0x 101: Intro to 0x Orders

May 4, 2023

0x 101: Intro to 0x Protocol

Apr 27, 2023

A new home for 0x Protocol

Apr 24, 2023

Say hi to the new 0x

Apr 20, 2023

0x Year in Review 2022

Jan 5, 2023

0x Swap API expands to Arbitrum

Sep 22, 2022

Managed liquidity

Apr 23, 2020

0x Smart Order Routing

May 19, 2020

App spotlight: Taho

Mar 8, 2022

Fundamentals: What is a Layer 2 chain?

Apr 19, 2023

Fundamentals: What is the difference between quoted, executed, and adjusted prices?

Apr 19, 2023

Fundamentals: What is price impact?

Apr 19, 2023

Fundamentals: What is slippage?

Apr 19, 2023

Fundamentals: What is an automated market maker (AMM)?

Apr 19, 2023

Fundamentals: What is market making?

Apr 19, 2023

Fundamentals: What is a DEX aggregator?

Apr 19, 2023

Fundamentals: What is liquidity?

Apr 19, 2023

Fundamentals: What is a decentralized exchange (DEX)?

Apr 19, 2023

0x at ETHDenver 2023

Mar 21, 2023

The 0x Mission and Values

Jun 7, 2018

Announcing support for new testnets

Aug 10, 2022

0x Swap API expands to Binance Smart Chain

Mar 17, 2021

Scaling DeFi — Layer One

Sep 1, 2021

Introducing Slippage Protection

Jul 14, 2022

San Francisco Blockchain Week 2022 Recap

Nov 21, 2022

0x Swap API adds new liquidity sources

Jul 11, 2022

Review of slippage performance

Sep 14, 2022

Phuture case study

Oct 20, 2022

Measuring the impact of hidden DEX costs

Apr 14, 2022

Market making in DeFi

Aug 12, 2021

Introducing 0x Labs

Jun 22, 2020

Introducing 0x Explorer

Oct 26, 2022

Growing DeFi with professional market makers

Aug 26, 2020

0x 101: How to Access 0x Data

Apr 25, 2023

GameStop chooses 0x Swap API

Jul 8, 2022

Build on Base with 0x

Feb 23, 2023

A comprehensive analysis on DEX liquidity aggregators’ performance

Oct 1, 2020

Access all DEX liquidity through 0x Swap API

Jan 28, 2020

Announcing the 0xpo Summit 2022

Aug 24, 2022

0x Protocol, a preview of what’s to come

Mar 16, 2023

Update to our Privacy Policy

Mar 14, 2023

Price Impact Protection has arrived

Dec 14, 2022

0x Limit Orders Go Multi-Chain

Dec 23, 2021

0x Labs raises $70M Series B led by Greylock to continue expanding Web3’s core exchange infrastructure

Apr 26, 2022

0x launches Tx Relay API in beta, with Robinhood Wallet as first partner

Mar 1, 2023

0x Labs raises $15M Series A to bring decentralized exchange markets to a global audience

Feb 5, 2021

App spotlight: Zerion

Jun 22, 2022

App spotlight: Matcha

Nov 24, 2021

App spotlight: DexGuru

Jun 17, 2021

App spotlight: DEXTools

Sep 23, 2021

App spotlight: DODO

Aug 10, 2021

App spotlight: DappRadar

Dec 16, 2021

App spotlight: DeFi Saver

Jul 20, 2021

0x + Brave partner to make crypto and DeFi more accessible to everyone

Jul 7, 2021

0x Swap API now supports 0x Protocol v4

Mar 1, 2021

0x Swap API is now available on Fantom

Oct 26, 2021