Is there still room for improvement in the Gas consumption of Ethereum DeFi?
This article was published on DODOZoo, author: Leimingda, founder of DODO.
I will systematically introduce the Gas issue here.
The Mechanism of Gas Usage
First, Ethereum's Gas is a prepayment mechanism. During the use of DEX, you will see three Gas values:
A. Gas displayed on the DEX frontend
B. Gas limit seen when signing in the wallet
C. Actual Gas consumption seen on Etherscan
For example, when you go to stay at a hotel:
A. Estimated hotel price seen on Ctrip is 1000
B. The hotel charges you a prepayment of 3000
C. At checkout, the actual cost for accommodation and drinks is 1200
Next, we will focus on discussing actual consumption, and then discuss how to present this number as accurately as possible to users.
What Does It Mean for Gas to Be Expensive?
When we say a transaction used 100 dollars of Gas, we mean:
"Gas * GasPrice * ethPrice"
Here, GasPrice is determined by the user; if you want to complete the transaction quickly, spend more, if not in a hurry, spend less. ethPrice is determined by the market.
What is truly affected by the product is the Gas consumption itself. Therefore, to really understand Gas, we need to shift our discussion from dollars to the quantity of Gas.
Concept of Magnitude
So where is Gas mainly consumed?
In two major parts: 1. Data writing 2. External calls
Gas optimization refers to using as little data writing and external calls as possible to complete business logic.
Writing data costs about 20,000~5,000 Gas, and contract calls cost about 3,000 Gas. This is the largest portion, and due to the complexity of the execution environment, all Gas consumption mentioned below will fluctuate within a small range in a production environment.
An ERC 20 transfer involves two writes, costing about 60,000 Gas.
An ERC 20 Approve involves one write, costing about 45,000 Gas.
A Uniswap single-hop transaction costs about 110,000 Gas (e.g., USDT→ETH).
A Uniswap two-hop transaction costs about 170,000 Gas (e.g., USDT→ETH→UNI).
A Uniswap three-hop transaction costs about 230,000 Gas (e.g., USDT→ETH→WBTC→LINK).
As can be seen, even within Uniswap, a single Swap can have a significant difference in Gas consumption!
This is still under very simple routing strategies. If the routing strategy becomes complex, such as with 1inch or Matcha, the Gas for a transaction can fluctuate between 150,000 and 1,000,000.
Therefore, we cannot simply say that Gas is expensive on a certain platform.
Does It Mean We Should Abandon Aggregators Because Their Gas Is Much More Expensive Than Uniswap?
Not necessarily.
Although aggregators have expensive Gas, it is not blindly expensive. The cost is high because there is additional logic to execute, and this extra logic can bring significant profits. If the profits can cover the extra Gas expenses, then using an aggregator is justified.
In the past, aggregators may not have paid much attention to Gas, but now the increase in Gas price and Ethereum price has caused the dollar cost of Gas to grow by 100 times. Therefore, in DODOV2, we will comprehensively compare Gas and quotes to provide the solution with the lowest average cost.
Is DODO Expensive?
It is both expensive and not expensive.
When executing routing, DODO will outsource a layer of function calls beyond the original liquidity, which will cost about 40,000 Gas more than the liquidity source.
However:
- After gas subsidies, DODO's Gas consumption can be made the same as or even cheaper than the liquidity source.
- Considering the advantages of quotes, although the Gas expenses are high, the average cost is the lowest on DODO.
How to Reasonably Display Gas
Recall the previous hotel example.
If you are Ctrip, your goal is to present the user's actual expenses as accurately as possible.
Ordinary users have already been educated that when staying at a hotel, the pre-authorization charged is definitely more than the actual consumption, and they won't mind too much.
A. Gas displayed on the DEX frontend
B. Gas limit seen when signing in the wallet
C. Actual Gas consumption seen on Etherscan
However, Ethereum users are still far from understanding these mechanisms; they do not know that the wallet pop-up is a pre-authorization. If you directly display number C on the webpage, but the number B that pops up in the wallet is very large, users will feel very confused.
Therefore, on DODO's webpage, number B will be displayed first to ensure consistency with the wallet. Then number C will be shown to ensure that users are not deterred.
Here, 0.084 is number A, i.e., the wallet pre-authorization. 0.084-0.042 is number C, i.e., DODO estimates your actual expenses. In this scenario, your actual expenses are similar to a Uniswap single-hop transaction.
Is There Room for Improvement in DODO's Gas?
Yes, in DODOV2, it is mainly reflected in the following aspects:
• Comprehensive comparison of Gas and quotes to avoid situations where quote advantages are negated by excessively high Gas costs that harm user interests;
• Improvements in routing to reduce upper-layer computational overhead;
• Gas optimization in V2 pools to reduce lower-layer computational overhead;
• More accurate Gas Price estimation, allowing users to accurately jump the queue (thanks to the Gasnow service from Spark Pool);
• Support for BSC and L2 parallel migration.
Conclusion
Gas is an unavoidable pain for all projects; it is a happy trouble. I have experienced the bleak times of Ethereum with 1 gwei transaction packing, when on-chain transactions seemed almost free, but life was very difficult.
Now that the value of DeFi has been discovered, people's trading activity has greatly increased, and Gas prices have also risen sharply. Every project has the obligation to complete business with the least read and write operations, saving precious block space for the Ethereum ecosystem.
Additionally, every project also has the obligation to find a cheap and safe L2 solution for users.
DODO has always treated the Gas issue as a research project and is at the forefront of research. We look forward to users experiencing the Gas optimization brought by V2 as soon as possible and welcome any suggestions regarding Gas optimization.