One of the main use cases users find in the Ethereum blockchain is the ability to exchange between encrypted assets without an intermediary. A decentralized exchange or DEX is the platform used for this activity. They can be summarized as a class of applications that allow you to use the liquidity available in their pool to exchange ETH or any token for other tokens.
DEX represents the most extensive gas consumption application on Ethereum. According to The Block’s statistics, the contract related to token exchange is one of the contracts that consumes the most blockchain resources.
Although these systems have permissionless nature, amazing numbers, and undisputed success, operating on the chain is costly and a burden for some users. The exchange cost can be broken down into several different cost elements:
Liquidity provider fees
Transaction fees of the underlying blockchain
Understanding these costs is critical to capital efficiency, and if the right choice is made, users may save thousands of dollars.
There are several protocol applications for users to choose from in DEX, and they provide the same core service of token exchange. This article aims to compare them based on experience, that is, the cost of transaction fees when using different DEXs available on the market.
Why is the gas cost different between transaction and DEX?
Any on-chain operation needs to be priced according to the amount of computing resources it consumes. In the Ethereum network, gas is a unit used to measure the computational workload used to perform each specific operation, and directly affects transaction costs. Since each protocol adopts different methods and needs to perform different functions to exchange, the consumption 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 details of two different transactions using the tools provided by Tenderly. As you can see, the second transaction ended up costing 70% more gas than the first transaction.
Details of gas consumption for two general exchange exchanges
Each DEX has its own method of performing exchanges, but some modes can be determined between them. In order to compare the cost of gas exchanged between different DEXs, a representative of each was selected. Uniswap V2 represents the traditional constant product pool, and Uniswap V3 introduces a centralized liquidity pool. Curve uses a hybrid and custom curve pool; Balancer V2 uses a weighted pool. For each of them, a Dune dashboard is set up:
- Uniswap V2：https://duneanalytics.com/yulesa/Uniswap-V2-Gas-Usage
- Uniswap V3：https://duneanalytics.com/yulesa/Uniswap-V3-Gas-Usage
The dashboard allows to check each pool individually by entering the pool address in the selection box. It also has a transaction table to filter outliers for more detailed investigation.
DEX gas comparison dashboard
When analyzing multiple pools of a protocol, only pools with more than 100 transactions that meet the above criteria will be plotted to obtain more relevant results. When analyzing transactions that interact with a single pool, the transactions are grouped by the number of jumps involved in the exchange.
Transactions involving multiple exchanges (in this example, 2)
The redemption execution can be wrapped in a transaction that also executes other codes. In order to eliminate this influence, only the transactions that directly call the protocol vault/router contract are analyzed. This filter is used to exclude exchange transactions routed by DEX aggregators and contracts, which are bundled with multiple functions that increase transaction costs but are not related to the DEX protocol itself.
Balancer pool distribution
Most of Balancer’s transactions come from DEX aggregator applications, such as 1inch, Metamask, etc. Since these transactions are excluded from analysis, this naturally reduces the amount of data available. Despite this, there are still 14 pools that meet the criteria for at least 100 direct call transactions. As expected, when evaluating each pool individually, you can see a significant difference between single-hop exchanges and multi-hop exchanges. Another finding is that the number of tokens in the pool does not change the gas expenditure of transactions using it. It is important to remember that the 2 token pool in Balancer may or may not act as an oracle-if they do, the gas cost will be higher when the memory slot that stores the price data is initialized. This can be viewed on the moving average chart of these pools. Note how the average value suddenly drops once all the memory slots have been initialized.
Distribution of LINK/WET, USDC/WETH and WBTC/WETH mining pools
Curve pool distribution
From the DEX studied in this article, Curve has a unique mechanism, which makes this contrast sometimes unbalanced. Each Curve pool (except metapool) is customized for its assets.
Curve shows the most significant difference in gas consumption between the analyzed DEXs. This is partially explained because Curve allows the exchange of unencapsulated tokens, such as DAI or USDC, and this pool is designed to not rely on other protocol IOUs, such as cDAI or yUSDC, and the encapsulation and unpacking process is part of the transaction. As a result, although the assets in the pool accumulate the benefits of these agreements, it makes the exchange more expensive.
Respectively 3pool, renBTC and Tricrypto pool distribution
Uniswap V2 pool distribution
In addition to being the oldest protocol on this list, Uniswap V2 is also widely adopted. More than 2500 pools have been created in the agreement to serve the long tail of assets. Some restrictions were imposed when drawing the above figure, but they can depict the gas cost in the protocol. Some of the most popular tokens, such as stablecoins and BTC, are widely used in multi-hop exchanges in transactions such as ABC <-> ETH <-> WBTC. Sometimes ABC transfers are gas intensive, which increases the average gas used in transactions involving these popular tokens. Once again, when investigating each pool, the most significant difference between transaction gas usage can be allocated to the number of hops performed by each transaction.
Respectively LINK/WET, USDC/WETH and WBTC/WETH pool distribution
Uniswap V3 pool distribution
One of the biggest concerns of Uniswap Protocol V3 is that exchange transactions may cost more gas. Uniswap V3 exchange is affected by the price caused by it. The higher the order relative to the available liquidity, the more it can push the price across the scale. The discrete price range represents a 0.0001% price increase or decrease, in which liquidity needs to be adjusted. Since most transactions have a relatively small impact on prices, the median transaction cost is consistent with the previous version. However, when dealing with a moderate liquidity pool, users need to pay attention to the impact of orders on prices.
Respectively LINK/WET, USDC/WETH and WBTC/WETH pool distribution
Gas cost per protocol
Three peer pools shared by Balancer V2 and Uniswap V2 and V3 were selected for detailed comparison-USDC/WETH, WBTC/WETH and LINK/WETH. Because Curve’s method is different, some of its pools are chosen to integrate into the picture, but they will not participate in the comparison.
It can be observed that there is no significant difference in the gas consumed between the 3 DEXs. The observed difference may be related to the imprecision of the method chosen for the study. For 2 jump exchanges, the difference can be attributed to the second-order effect of the transfer function in one of the token contracts involved in the transaction.
In addition, here is a table that calculates the cost (in U.S. dollars), the current ETH price and the approximate difference observed between DEX. From one perspective, in the $2,000 ETH scenario, the gas is 50 gWei, and the difference between choosing Uniswap V2 instead of V3 for the WBTC/WETH 2-hop exchange will save $3.12. For orders greater than $1040, the typical 0.3% LP fee is greater than this difference.
Gas cost in different scenarios
The study shows that there are no significant differences between the analyzed DEXs. The biggest impact on the gas used by the transaction is the number of hops that must be performed to execute the exchange. The difference between 1-hop and 2-hop exchanges is more meaningful than the difference between DEX. In addition, depending on the size of the transaction, other factors of exchange costs, such as LP fees or slippage, may have a more significant impact on the total cost.
Although Curve has some very competitive pools in terms of gas spending, some of its mining pools are designed with the underlying protocol IOU, and the packaging and unpacking process will significantly affect their swaps
Author of this article: Yule Souza Andrade
Posted by:CoinYuppie，Reprinted with attribution to:https://coinyuppie.com/compare-the-gas-cost-difference-of-the-three-dexs-of-balancer-curve-and-uniswap/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.