Original Author: Yule Souza Andrade Translation: Block unicorn
The main use case that users find in the Ethereum blockchain is the ability to exchange between crypto assets without an intermediary. Decentralized exchanges or DEXs are platforms used for this activity. They can be summarized as an application that allows you to exchange ETH or any token for other tokens using the liquidity available in their pool.
Decentralized exchanges represent the most widespread fee consumption on Ethereum. According to The Block's statistics, the contract (code segment) related to token exchange is one of the contracts that consume the most blockchain resources.
Despite the permissionless nature of the awesome HESE system, its amazing size and undisputed success, the cost of doing business on the chain makes it a burden for some users. Swap costs can be broken down into several different cost elements:
price impact
Liquidity Provider Fees
slip
Transaction fees on the underlying blockchain
Understanding these costs is critical to capital efficiency and can save thousands of dollars from users who make the right choices.
The DEX industry has several alternative protocol applications that users can choose from that provide the same core service of token exchange. This article aims to empirically compare the last item, the cost of transaction fees when using different DEXs available in the market.
Why do gas costs differ between exchanges and DEXs?
Any on-chain operation needs to be priced according to the amount of computing resources it consumes. In the Ethereum network, gas is the unit used to measure the computational effort used to perform each specific operation and directly affects transaction costs. Since each protocol takes a different approach and needs to perform different functions to make an exchange, the cost of each transaction/protocol is also different.
A transaction can call any number of functions and interact with many different smart contracts. Below, we can see the gas consumption breakdown for two different transactions using the tools provided by Tenderly. As you can see, the second transaction ended up spending 70% more gas than the first transaction.
Fee Comparison
Each DEX has its method of performing the swap, but some patterns can be identified between them. In order to compare the gas cost of swaps between different DEXs, one of each was chosen. Uniswap V2 represents the traditional constant product pool, Uniswap V3 introduced a centralized liquidity pool, chose Curve as its hybrid and custom curve pool, and finally chose Balancer V2 with a weighted pool. For each of them, a Dune dashboard is set:
Balancer: https://duneanalytics.com/yulesa/Balancer-Gas
Curve: https://duneanalytics.com/yulesa/Curve-Gas-Usage
Uniswap V2:https ://duneanalytics.com/yulesa/Uniswap-V2-Gas-Usage
Uniswap V3:https ://duneanalytics.com/yulesa/Uniswap-V3-Gas-Usage
The dashboard allows to inspect each pool individually by entering the pool address in the select box. It also has a transaction table to filter outliers for more detailed investigation.
When analyzing multiple pools for a protocol, only pools with more than 100 transactions meeting the above criteria are plotted for more relevant results. When analyzing transactions that interact with a single pool, transactions are grouped by the number of hops involved in the exchange.
Swap execution can be wrapped in a transaction that also executes other code. To rule out this effect, only transactions that directly invoke protocol vault/router contracts are analyzed. This filter is used to exclude swaps routed by DEX aggregators and contracts that bundle multiple features that increase transaction costs but have nothing to do with the DEX protocol itself.
Balancer
Balancer pool distribution
Most of Balancer's transactions come from DEX aggregator apps such as 1inch, Metamask, etc. As these transactions are excluded from the analysis, this naturally reduces the amount of data available. Still, 14 pools met the criteria of at least 100 direct call transactions. As expected, significant differences between single-hop and multi-hop swaps can be seen when evaluating each pool individually. Another finding is that the amount of tokens in a pool does not change the gas spending of transactions using it. It's important to remember that 2 token pools in Balancer may or may not act as oracles - if they do, the gas cost will be a bit higher when the memory slots storing the price data are initialized. This can be viewed on the moving average charts for these pools.
The above three pictures are the distribution of LINK/WET, USDC/WETH and WBTC/WETH mining pools respectively
Curve(CRV)
Curve pool distribution
From the DEX studied in this paper, Curve has a unique mechanism, which makes the comparison sometimes unbalanced. Every Curve pool (except Metapool) is customized for its assets.
The curves show the most significant differences in gas consumption between the DEXs analyzed. This is partly explained because Curve allows the exchange of unwrapped tokens like DAI or USDC, while the pool is designed not to rely on other protocol IOUs like cDAI or yUSDC, and the wrapping and unwrapping process is part of the transaction. As a result, while the assets in the pool accumulate the benefits of these protocols, it makes the exchange more expensive.
The above 3 pools are respectively Curve 3pool, renBTC and Tricrypto pool distribution
Uniswap V2
In addition to being the oldest protocol on this list, Uniswap V2 is also widely adopted. More than 2,500 mining pools have been created in the protocol to serve the long tail of assets. Some constraints were imposed when drawing the above graphs, but they can depict the gas cost in the protocol. Some of the most popular coins, such as stablecoins and BTC, are widely used in ABC<-> ETH <->Multi-hop swaps in transactions like WBTC. Sometimes ABC transfers are gas intensive, increasing the average gas used in transactions involving these popular coins. Once again, when investigating each pool, the most significant difference between transaction gas usage can be assigned to the number of hops each transaction takes.
Distribution of LINK/WET, USDC/WETH and WBTC/WETH mining pools respectively
Uniswap V3
One of the biggest concerns with version 3 of the Uniswap protocol is that swap transactions could cost more gas. Uniswap V3 swaps are affected by the price they create. The higher the order book relative to the available liquidity, the more it drives price ticks, with discrete price bands representing 0.0001% price increases or decreases where liquidity needs to be adjusted. Since most transactions have relatively little impact on price, the median transaction costs are consistent with previous editions. However, when dealing with moderate liquidity pools, users need to pay attention to the impact of orders on price.
Distribution of LINK/WET, USDC/WETH and WBTC/WETH mining pools respectively
Agreement fee comparison
Fee cost per agreement
Three equivalent pools common to Balancer V2 and Uniswap V2 and V3 were chosen for detailed comparison - USDC/WETH, WBTC/WETH and LINK/WETH. Since Curve has a different approach, some of its pools were chosen to blend in the picture, but will not enter the comparison.
It can be observed that there is no significant difference in gas consumed among the 3 DEXs. The observed differences may be related to the imprecision of the methods chosen for the study. For the 2-hop swap period, the difference can be attributed to second-order effects of the transfer function in one of the token contracts involved in the transaction.
Additionally, here is a table that calculates the cost (in USD), the approximate difference observed between the current ETH price and the DEX. To put it in perspective, in a $2000 ETH scenario with 50 gWei in gas, the difference in choosing Uniswap V2 instead of V3 for a WBTC/WETH 2-hop swap would save $3.12. For orders greater than $1040, the typical 0.3% LP fee is greater than this difference.
in conclusion
in conclusion
The study showed no significant differences among the DEXs analyzed. The biggest impact on the gas used by a transaction is the number of hops that must be made to execute the exchange. The difference between 1-hop and 2-hop exchanges is more meaningful than the difference between DEXs. Additionally, depending on the size of the transaction, other elements of the swap cost, such as LP fees or slippage, may have a more significant impact on the total cost.
While Curve has some very competitive pools in terms of gas payouts, some of its pools are designed with the underlying protocol IOUs, and the wrapping and unwrapping process can significantly affect their swaps.
Analysis Considerations
Performing a swap usually means calling the transfer function of the participating token contracts - exceptions are multi-hop transactions on Balancer due to Balancer's single-vault model or using internal user balances in Balancer vaults. Some tokens can perform more than simple bookkeeping when calling the transfer function, thereby increasing the swap cost of the transaction. A practical way to exclude this effect using Dune has not been fully implemented. This behavior is especially worrisome when a transaction performs multiple hops to exchange and one of the tokens is underperforming. Although, it is believed that this issue affects all protocols systematically and rarely significantly affects the results. Restricting the scope of the analysis to single-hop transactions per token pool mitigates this effect.
Since some protocols have thousands of transactions from the start, processing such a large amount of data in Dune/Internet Browser can greatly reduce the usability of the dashboard. Therefore, in these protocols, a limit is imposed on the number of transactions analyzed. However, a reduction in the data population does not change the results significantly. For a single pool view, the dashboard is capped at 1000 transactions. Uniswap V2 is limited to last month's transactions.
