Fundamentals: What is a DEX aggregator?
A quick explanation of how DEX aggregators help traders get the best prices.
Since liquidity in DeFi is fragmented across dozens of different sources, ensuring you’re getting the best price means having to check out multiple trading venues. Some exchanges will offer better prices, but have high slippage, while others offer worse rates for lower slippage. Aggregators are a user-friendly way to bring all of this information and liquidity together to get users the best prices.
How does a DEX aggregator work?
There are a number of different types of DeFi aggregators – you can aggregate token prices on exchanges, or rates from lending services, and yield farming protocols. But they all work in a similar way: data is pulled from a variety of sources and is shown to the user to allow them to optimize their trades. It’s similar to how a website like Expedia pulls together all of the flight price data from various airlines.
Let’s take Matcha, the DEX aggregator built by 0x Labs, as an example. Matcha aggregates liquidity for user trades from dozens of sources, including Uniswap, Aave, and Sushiswap, across eight blockchains, such as Ethereum, Polygon and Binance Smart Chain. Matcha also taps into liquidity provided by professional market makers, and once the best price is identified, uses “smart order routing” to maximize the overall return on your trade.
What is smart order routing?
A typical aggregator will scan across multiple DEXes and present someone with the best overall exchange or liquidity source to make a trade with. But Matcha, using smart order routing, goes one step further by also splitting your trade up across different DEXes and liquidity sources. This ensures that you’re able to maximize the overall value of your trade.
For example, maybe the best price to trade 1,000 DAI for 1 ETH is 50% through Bancor, 25% through Uniswap, and 25% through Uniswap. 0x Swap API's smart order routing logic automatically calculates this and packages it into a single quote that's ready to be executed.
What is slippage protection?
0x's Swap API also has a pair of features that differentiate it from all other DEX aggregators. One of those is called slippage protection. When trading on DEXes, a variety of external market factors could cause the price of your trade to shift between you placing your trade, and your trade actually executing. This is referred to as slippage, and it’s something you wouldn't notice until the trade is settled.
Swap API's slippage protection works with the API’s smart order routing to forecast the amount of slippage a trade might incur, allowing the algorithm to deliver the optimal trade route. The slippage protection forecasts incorporate factors including trading pairs, liquidity and the size of your trade.
What is price impact protection?
Another key feature offered by Swap API is price impact protection. Similar to slippage, price impact occurs in between a trader placing a trade, and its actual execution.
Price impact isn’t caused by external factors, however, but instead by the influence that your trade itself has over the market price of a trading pair. This makes price impact directly related to the amount of liquidity in a trading pair, and price impact will be higher when placing large trades on illiquid assets.
Price impact protection is an optional feature of the API. But when enabled, it allows users to avoid getting rekt by trading illiquid tokens. When using the API, users will be notified when their trade faces a price impact over a certain threshold. The API will return an error of insufficient liquidity due to the price impact being higher than the defined limit, which is easily customizable.
Enable crypto trading in your app with Swap API
Swap API aggregates liquidity from 100+ AMMs and professional market makers on the most popular blockchains. With Swap API, you can easily power crypto trading in your application with a single integration that unlocks thousands of tokens. Learn how you can leverage Swap API to access deep liquidity without the infrastructure overhead.