-
Notifications
You must be signed in to change notification settings - Fork 122
Transaction gas costs
This Dune query can be used to collect block stats: https://explore.duneanalytics.com/queries/19430/source
This query returns stats for all blocks of block size 386 in the last 7 days, containing 262 blocks when I executed the query.
Data can be pasted in a worksheet and saved as block_stats.csv
. My data can be downloaded here: https://drive.google.com/file/d/1QRjag7wwgNlzRWYVh14H_1EXXOhwcbdp/view?usp=sharing
The python scripts in packages/loopring_v3/fee-regression
can be used to run over a bunch of parameters to find the closest fit. An extra penalty can be given to predictions that are lower than the actual gas used by the block.
The error rate can be visualised on Dune: https://explore.duneanalytics.com/queries/19403/source#39659
A positive error means the predicted gas usage is higher than the actual gas used. A negative error means the prediction gas usage is lower than the actual gas used.
Total gas delta
is the difference between the sum of all gas usage predictions minus the sum of all gas used. So it can be seen as the "gas surplus" if positive, or "gas deficit" if negative.
Best total error: 7377650
Total gas delta: -413108
- noop_cost: 0
- deposit_cost: -1000
- withdrawal_cost: 45000
- transfer_cost: 1300
- trade_cost: 1350
- account_update_cost: 17500
- amm_update_cost: 46000
- signature_cost: 6000
Best total error: 10388670
Total gas delta: 2698842
- noop_cost: 0
- deposit_cost: 0
- withdrawal_cost: 46000
- transfer_cost: 1350
- trade_cost: 1350
- account_update_cost: 17500
- amm_update_cost: 46000
- signature_cost: 6500
Best total error: 14554087
Total gas delta: 6162342
- noop_cost: 0
- deposit_cost: 0
- withdrawal_cost: 47500
- transfer_cost: 1350
- trade_cost: 1350
- account_update_cost: 18000
- amm_update_cost: 47000
- signature_cost: 6000
The average gas costs provide a very good fit to the actual gas used, mostly within 5%. All 3 cases have a gas surplus.
Good average gas costs for operations are:
- Withdrawal: 46,000-47,500 gas
- Transfer: 1,300 - 1,350 gas
- Trade: 1,350 gas
- Account Update: 17,500-18,000 gas
- AMM join/AMM exit: 102,000 - 104,000 gas
An AMM join/exit is: 2x AMM updates + 3x transfers + 1x signature verification
Once compression is enabled gas costs for noops/trades/transfers should go down. Submitting multiple blocks at once when we have enough throughput will also lower gas costs.
This Dune query can be used to find the min, max and average gas used for fast withdrawals per token: https://explore.duneanalytics.com/queries/19463
The query uses all transactions and will automatically add tokens to the table as fast withdrawals for the token are done.
I think the average gas used + some small extra buffer would be a fair cost to charge users.
Because it's a stand-alone tx it's also possible to use the web3 function to estimate the gas used. But remember that that gas estimation does not estimate the actual gas used, only the min gas needed not to have out of gas errors, so it could estimate a higher gas value than actually used.
Loopring Foundation
nothing here