You need to enable JavaScript to run this app.
Bankless Academy

DEX Aggregators

Dive into DEX Aggregators, liquidity, and the DeFi exchange landscape.
Start Lesson

Introduction

Decentralized Exchanges (DEXs) eliminate the costs of intermediaries and save Explorers money when trading assets.

But did you know, Explorer, that there’s more ways to save with DeFi technology? Using DEX aggregators, you can scan all possible trades on various DEX platforms simultaneously and execute the best trade route, all in one action. They help you get the best deal when doing a token swap. Just like airline flight aggregators help you find the cheapest flight, DEX aggregators help you maximize the value of your trade.

This lesson will show:

  1. How DEXs split liquidity and how that can result in reduced trading rates.
  2. How DEX aggregators enable users to view and use multiple DEXs through one interface.
  3. Multiple ways a single aggregator interface can save Explorers time and money.

How Liquidity Affects Prices

The amount of any token that is available to trade on a single market is called a token’s liquidity. The amount of liquidity available strongly influences the price impact when making trades in DeFi; a large price impact means the trade will cost more, and a low price impact will cost less. Most people prefer to trade in markets with higher liquidity to reduce their price impact.

You can think of it like a swimming pool; the more water (liquidity) there is, the smaller the change in the water level (price impact) when someone jumps in or leaves. The size of that ‘someone’ (the trade) also affects the change in the water level (price impact).

An Example of How Liquidity Impacts Prices

Let’s look at an example.

Imagine a token that trades on several DEXs at once. One DEX holds a deep pool with most of the token’s liquidity, while another holds a shallow pool with only a small fraction of it.

If an Explorer buys the same amount of the token from each pool, the price impact will be higher in the shallow pool. The same trade pulls a much larger percentage of that pool’s total liquidity, so it moves the price more and costs the buyer more.

Knowledge Check 1

Fill in the blanks: To find the best price, people will want to trade in markets with ________ liquidity to have ________ price impact on their trades.

  • [ ] good, maximum

  • [ ] high, low

  • [ ] low, good

  • [ ] thin, large

Shortcomings of Traditional DEXs: Thin Liquidity

DeFi continues to grow, but a problem is emerging for users: As more DEXs launch, the total amount of any individual token gets spread out. This is known as thin liquidity.

Remember the swimming pool: if the available water (liquidity) is split between multiple pools, the amount of water will be “thinner” in each pool compared to the total in the single original pool.

In DeFi’s early days, one or two DEXs held most of the liquidity. In 2020, new DEXs began competing for it; one rival pulled over $1B of liquidity away from Uniswap within weeks of launching. Today, liquidity is spread across hundreds of DEXs on many blockchains and Layer 2 networks, thinning each individual pool.

Thus, any trade has a larger price impact than when a single DEX held most of the ecosystem’s liquidity. Without new innovations, it costs Explorers more to trade on any single DEX.

Knowledge Check 2

Which two factors determine the price impact of a DEX trade?

  • [ ] The choice of DEX used to make the trade and size of the trade

  • [ ] Which token is chosen to trade and which DEX is used to make the trade

  • [ ] The size of the trade and amount of liquidity available

  • [ ] The amount of liquidity available and which token is chosen to trade

Recombining Liquidity With DEX Aggregators

Large amounts of liquidity are needed to reduce price impact and save you money. DEX aggregators allow users to run trades through multiple DEXs at once and reduce the price impact; a big trade from an Explorer’s wallet gets broken down into multiple small trades across multiple DEXs.

DEX aggregators can even route trades through an intermediary token , or more than one, if that gets a better result for users, like the way a flight aggregator might suggest an extra stop at another airport if it’s cheaper for the passenger. This discovery of the optimal trade route is done by sophisticated algorithms searching through all possible paths to find the cheapest trade route at that moment.

Knowledge Check 3

Trade routing in DEX aggregators means:

  • [ ] Trades are routed via special arrangements with specific DEXs

  • [ ] Trades are always routed through multiple DEXs

  • [ ] Trades are routed through a user’s favorite DEX only

  • [ ] Trades can be routed through multiple DEXs and intermediary tokens

How Gas Cost Is Calculated on Ethereum

Let’s refresh how gas is calculated before seeing how DEX aggregators reduce network fees. These savings matter most on Ethereum Mainnet, where fees can be high; on Layer 2 networks, fees are usually just cents.

Just like gas for a car, gas is the fuel for running blockchain code on Ethereum. The more computations you do, the more gas your code requires. Gas price is measured in very small amounts of Ether called gwei, like cents to a dollar. 1 gwei is 1 billionth of an ether (1 gwei = 0.000000001 ETH).

Total gas cost is based on how much gas your transaction uses and the unit price of gas at the time of use. The formula for calculating the price of a transaction is as follows: Amount of gas used * Gas price = Total gas cost

As an example, let’s say gas costs are at 22 gwei per gas unit and the transaction uses 120-thousand units: 120,000 * 22 gwei = 2,640,000 gwei or 0.00264 ETH

How Aggregators Reduce Gas Costs for Users

Trade splitting would result in more transaction fees from the extra on-chain activity, except that advanced aggregators plan for transaction fees and include them in their calculations of the trade route. They simulate trades off chain, including gas costs, to find trade routes that leave Explorers with the most value at the end of the interaction.

Some aggregators go even further. 1inch, which pioneered DEX aggregation, now also lets professional fillers compete to execute your trade and pay the gas themselves (a system called Fusion). The user often pays no gas at all.

Knowledge Check 4

Which of the following is NOT a way DEX aggregators try to reduce transaction costs for users?

  • [ ] Simulate transactions off-chain prior to trade execution

  • [ ] Ask DEXs to lower network fees for their users

  • [ ] Account for gas cost in trade routing

  • [ ] Let professional fillers execute trades and pay the gas

Meta-Aggregators

There are even meta-aggregators of DEX aggregators! These platforms search through competing DEX aggregators and serve the best price quotes to users. For example, the built-in swap feature in wallets like MetaMask gathers quotes from multiple providers, including DEX aggregators like 1inch, and adds its own service fee on top.

Note: While convenient, meta-aggregator services can add extra costs on top of network transaction fees, increasing the overall cost for users. Explorers: make sure that your trades don’t end up more expensive than you intended.

Knowledge Check 5

Meta-aggregators cross-reference multiple DEX aggregators to find the best prices for their users.

  • [ ] True

  • [ ] False

Avoiding Sandwich Attacks

Users swapping directly through DEXs can lose value up to the limit of their slippage tolerance when bots place trades right before and after theirs to move the price. These losses are called sandwich attacks; in 2021 alone, they cost users around $235,000,000. Today, protections like private transaction routing and intent-based trading shield most everyday trades, but it still pays to keep a low slippage tolerance when swapping tokens.

Fortunately, because of the recombined liquidity offered by DEX aggregators, the price impact of a trade is reduced. Explorers can keep their slippage tolerance low while saving more with DEX aggregators, as opposed to trading directly on a DEX.

Knowledge Check 6

To protect yourself, you should keep your slippage tolerance:

  • [ ] low

  • [ ] high

More Protection From Sandwiches: OTC Trades

Some aggregators like 1inch even offer specialized OTC (Over The Counter) services that provide total protection against sandwich attacks. These optional services enable direct trading with other users, rather than routing through DeFi liquidity pools, giving Explorers another great way to save.

CoW Swap takes a different approach: users sign a trade request (an intent), and professional solvers compete in batch auctions to fill it at the best price. Solvers can even match two users directly, so trades are protected from sandwich attacks by default.

Knowledge Check 7

Many DEX aggregators offer which tool(s) to save their users money?

  • [ ] Routing trades through liquidity from multiple DEXs.

  • [ ] OTC trades that fully protect against sandwich attacks.

  • [ ] Account for gas cost when building the best trade routes.

  • [ ] All of the above