-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update gas model #171
Update gas model #171
Conversation
Very nice PR!
The issue with using the minimum is that this includes optimal gas cases instead of the "usual". For example, specifically with WETH unwrapping, this represents the gas cost of unwrapping exactly all your WETH and not the general case of unwrapping some of it. The reason for the difference is setting some storage to 0 (so, in this case setting your WETH balance to 0) gives you a gas refund that you don't get in the general case (setting your WETH balance from some non-zero The same can be said for the other interactions - it is likely to represent the gas cost of trading exactly all your tokens and not just trading some of your tokens (and I assume the latter is much more likely for settlements because of non-zero buffers held by the settlement contract). |
@nlordell can this be merged? |
Yes. For some reason I had misread:
as
🙈 I think a median would be slightly more correct - but I'm not sure how easy it is to do. |
Extra word snuck in my sentence which made it confusing. 😅 (removed it). |
Updated PR and its description to reference median gas used. |
You can take a look at @vkgnosis's fee analysis tool. You can see fee coverage over the past month and compare to how it changes after implementing this change. |
@MartinquaXD The query you use is similar to the one you were showing me the other day right? If so, I can confirm that the values match what I get by querying dex trades on dune. |
Looking into simulations of settlements with
ZeroExInteraction
s revealed that the gas model for those is way too high. Since the approach to estimate those interactions was based off of existing estimation methods for other AMM interactions I estimated them all again with the same (hopefully more accurate) approach.AFAIK the previous approach for gas cost estimation was to find a transactions which only had a single interaction of the type we are interested in and use that. For some interactions the min over a long period of time was used for some only a few samples were looked at. Also note that the
UnwrapWethInteraction
used the median value whereas every other interaction used the minimum.The new approach is to use the
ethereum.traces
table which contains tracksgas_used
for each function call. This is better for our purposes since it gives us more data to look at (transaction only containing the interaction vs. every transaction containing such interaction) and also discounts any gas overhead a transaction might additionally have.The used queries are all in the form of:
I decided to NOT use the lower bound anymore and instead used the median amount for our gas cost model since that seemed more appropriate.
The changes will cause our overall gas cost estimations to decrease and will make 0x and Balancer way more competitive against UniswapV2.
Test Plan
Manual tests simulating transactions with tenderly and using the gas profiler to compare those values against values returned by each dune query.