Improve gas estimates on all-Dai carts and specific tokens #6918
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has two changes in regards to gas estimates
Changes for Carts with ANT, aDAI, or cDAI
The current default estimate for token donations is 100k per donation, but this is insufficient for some tokens:
Changes for Carts that Only Use DAI
If a cart is all Dai (which is about 75% of checkouts), we use a linear regression to estimate the gas price based on actual transaction data.
The raw data was obtained using the script located at this repo: https://github.com/mds1/Gitcoin-Checkout-Gas-Analysis
That script does the following:
We then used the Plotly Chart Studio to generate a linear best fit line, then tweak the result so the results are more conservative than a typical best fit line (because we'd rather overestimate gas costs than underestimate). This chart can be found in Plotly Chart Studio here: https://plotly.com/~mds1/7/number-of-donations-vs-gas-used-all/
This gave us a new curve of
gasLimit = 25000 * n + 125000;
wheren
is number of donations in a transaction. For 1 donation we use a special case and set the estimate to 80k to avoid overestimating too much (in practice this will not really be seen since the default contribution to Gitcoin means there's two donations when you choose one grant).Some comparisons are shown below:
cc @owocki @apbendi