DEX Gas Comparison

This article compares empirically the cost of transaction fees when using different DEXes using Dune.

Yule Souza Andrade
8 min readJul 23, 2021

The primary use case users have found in the Ethereum blockchain is the ability to swap between crypto-assets without intermediaries. Decentralized exchanges or DEXes are platforms used for this activity. They can be summarized as an app that allows you to swap ETH or any token into other tokens using the liquidity available inside its pools.

Decentralized exchange swaps represent the most extensive consumption of gas on Ethereum. According to statistics from The Block, the contracts (pieces of code) associated with token swap are among the ones that most consume blockchain resources.

Source: The Block https://www.theblockcrypto.com/data/on-chain-metrics/ethereum

Despite these systems’ permissionless nature, stunning volumes and uncontested success, doing operations on-chain are costly, making it burdensome for some users. A swap cost can be broken down into several distinct cost elements:

  • Price impact
  • Liquidity Providers fees
  • Slippage
  • Transaction fees of the underlying blockchain

Understanding these costs are paramount for capital efficiency and can save thousands of dollars from users who make the right choices.

The DEX industry has several alternative protocols apps that users can choose from that offer the same core service of swapping tokens. This article is meant to compare empirically the last item, the cost of transaction fees, when using different DEX available in the market.

Why does gas cost vary between transactions and DEXes?

Any operation on-chain needs to be priced by the amount of computational resources it consumes. In the Ethereum network, gas is the unit used to measure the computational effort used to execute each specific operation and directly impacts the transaction cost. As each protocol takes different approaches and needs to execute different functions to make a swap, the consumption of each transaction/protocol also differs.

A transaction can call any number of functions and interact with many different smart contracts. Below, we can see a breakdown of gas consumption for two different transactions using a tool provided by Tenderly. As you can see, the second transaction ends up spending 70% more gas than the first one.

Gas breakdown of two generic swap transactions. Source: https://tenderly.co/ Dashboard

The comparison method

Each DEX has its methodology to perform swaps, but some patterns can be identified between them. To compare the gas cost of swaps between different DEXes, one of each kind has been selected. Uniswap V2 is representing the traditional constant product pools, Uniswap V3 introduced concentrated liquidity pools, Curve was chosen for its hybrid and custom curve pools, and finally, Balancer V2 with weighted pools. For each one of them, a Dune dashboard has been set up :

The dashboards allow inspecting each pool individually by entering the pool address at the selection box. It also has a transaction table to filter outliers for a more detailed investigation.

DEX Gas Comparison dashboard.

When analyzing the multiple pools of a protocol, only pools with more than 100 transactions matching the criteria above were plotted to make more relevant results. When analyzing transactions interacting with an individual pool, transactions were grouped by the number of hops involved in the swap.

A transaction involving multiple swaps (in this case 2). Source: https://etherscan.io/

A swap execution can be wrapped inside transactions that also execute other code. To exclude this effect, only transactions with a direct call to the protocol vault/router contract have been analyzed. This filter was used to exclude swap transactions routed by DEX aggregators and contracts that bundle multiple functions that would increase the transaction costs but are not associated with the DEX protocol itself.

Balancer

Balancer pools distribution.

Most of the transactions of Balancer come from DEX aggregator apps, such as 1inch, Metamask and others. As these transactions were excluded from the analysis, this naturally reduces the data population available. Nonetheless, 14 pools have matched the criteria to have a least 100 direct call transactions. As expected, when evaluating each pool individually, it is possible to see a notable difference between single-hop swaps and multiple hops swaps. One more finding is that the amount of tokens in the pool doesn’t change the gas spend of trades using it. It’s important to keep in mind that 2-token pools in Balancer may or may not act as an oracle — and in case they do, gas costs are somewhat higher while memory slots that store price data are initialized. This can be viewed on the moving average charts of these pools. Notice how the mean suddenly decreases once all memory slots have been initialized.

LINK/WET, USDC/WETH and WBTC/WETH pools distribution, respectively.

Curve

Curve pools distribution.

From the DEX studied in this article, Curve has a unique mechanism, which makes the comparison sometimes uneven. Each Curve pool, excepting metapools, is custom-made for its assets.

Curve presented the most considerable variance of gas spend between the DEX analyzed. This is partially explained because Curve allows the swap of unwrapped tokens like DAI or USDC while the pool is designed with the unlying being other protocols IOU like cDAI or yUSDC, and the wrapping and unwrapping process is part of the trade. As a result, while the assets in the pool accrue the benefits of those protocols, it makes the swaps considerably more expensive.

3pool, renBTC and Tricrypto pools distribution, respectively.

Uniswap V2

Uniswap V2 pools distribution.

Besides been the oldest protocol on this list, Uniswap V2 has seen a fantastic adoption. More than 2500 pools have been created in the protocol, serving the long tail of assets. Some limitations were imposed when plotting the graph above, but they can paint the picture of the gas costs in the protocol. Some of the most popular tokens, for instance, stable coins and BTC, are popularly used in multi-hop swaps in transactions like ABC <-> ETH <-> WBTC. Sometimes ABC transfers are gas-intensive and increase the average gas used in transactions involving these popular tokens. Once again, when investigating each pool, the most significant variance between transaction gas use can be assigned to how many hops each transaction makes.

LINK/WET, USDC/WETH and WBTC/WETH pools distribution, respectively.

Uniswap V3

Uniswap V3 pools distribution.

One of the biggest concerns about version 3 of the Uniswap protocol was that swapping transactions could cost more gas. Uniswap V3 swaps are affected by the price impact it causes. The higher the order relative to the liquidity available, the more it will push the price across ticks, discrete price intervals representing a 0.0001% increase or decrease in price in which liquidity needs to be adjusted. As most of the transactions have a relatively small price impact, the median transaction costs align with the previous version. However, the price impact of the order is something a user needs to be concerned about when dealing with modest liquidity pools.

LINK/WET, USDC/WETH and WBTC/WETH pools distribution, respectively.

Comparing Protocols

Gas costs for each protocol.

Three equivalent pools that Balancer V2 and Uniswap V2 and V3 have in common have been chosen to make a detailed comparison — USDC/WETH, WBTC/WETH and LINK/WETH. As Curve has a different methodology, some of its pools have been chosen to blend in the picture but won’t enter in the comparison.

It’s possible to observe that there isn’t a significant difference in the gas spent between the 3 DEXs. The observed disparity can be associated with imprecision in the methodology chosen for the study. For 2 hop swaps, the variance can be attributed to second-order effects of transfers function in one of the tokens contracts involved in the trade.

Moreover, here is a table calculating the cost, in dollars, with the current ETH prices and the approximate difference observed between DEXes. As a perspective, in a $2000 ETH scenario with gas at 50 gWei, the difference in choosing Uniswap V2 over V3 for a WBTC/WETH 2 hop swap would save $3.12. A typical 0.3% LP fee is bigger than this difference for orders bigger than $1040.

Gas cost for different scenarios.

Conclusion

The study has demonstrated that there aren’t significant discrepancies between the DEX analyzed. The biggest influence on the gas used by a transaction is the number of hops it has to make to perform the swap. The difference between 1 and 2 hop swaps is more meaningful than the difference found between DEXs. Furthermore, depending on the size of the trade, likely other elements of the swap cost, such as LP fees or slippage, will have a more significant impact on the total cost.

Although Curve has some very competitive pools regarding gas spend, some of its pools are designed with underlying protocols IOU and the wrapping and unwrapping process significantly impacts swaps on them.

Considerations on the analysis

Executing swaps commonly implicates calling the transfer function of the token contract participating — the exception being multihop trades on Balancer due to its single vault model or the use of internal user balance in the Balancer vault. Some tokens can execute more than simple accounting when the transfer function is called, increasing the swap cost of transactions. A practical method to exclude this effect using Dune has not been exhaustively achieved. This behavior is particularly concerning when the transaction executes multiple hops to make a swap and one of the tokens isn’t well behaved. Although, it is believed that this issue affects all protocols systematically and are few to influence the result significantly. Restricting the scope of the analysis to single-hop transactions for each token pool can mitigate this effect.

As some protocols have thousands of transactions since their inception, processing this vast amount of data in Dune/Internet Browser drastically lowers the usability of the dashboard. Thus, in these protocols, a limitation was imposed on the number of transactions analyzed. However, the decreased in the data population does not significantly change the results. For the individual pool views, the dashboard is capped at 1000 transactions. Uniswap V2 is limited to transactions in the last month.

Thanks to Markus Buhatem Koch for the discussions that helped inform this post.

--

--