Skip to content
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

fix: incorrect standard swap gas fee estimation #28127

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

matthewwalsh0
Copy link
Member

@matthewwalsh0 matthewwalsh0 commented Oct 28, 2024

Description

Fix incorrect non-smart gas fee estimations due to the use of an empty estimated base fee.

Open in GitHub Codespaces

Related issues

Fixes: #28088

Manual testing steps

See issue.

Screenshots/Recordings

Before

After

Smart Standard

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@github-actions github-actions bot added the team-confirmations Push issues to confirmations team label Oct 28, 2024
@matthewwalsh0 matthewwalsh0 marked this pull request as ready for review October 28, 2024 15:11
@matthewwalsh0 matthewwalsh0 requested a review from a team as a code owner October 28, 2024 15:11
@martahj
Copy link
Contributor

martahj commented Oct 28, 2024

I'm not sure if this fixes the issue.

I'm using an account with 0.004029351477 ETH.

When I go to make a transaction, the estimated gas fee is 0.00334, but I still see a warning message saying I need an additional 0.0044+ ETH to make the transaction. It says the estimated fee is 0.00334 ETH ($8.40) and the max fee is $10.22, which would mean the max fee in ETH would be 0.004063666667. This is a little over my current ETH balance, so it's correct to show the warning, but the additional ETH needed is too high; it says I need basically the full amount, not the difference between the current balance and the estimated fee.
Screenshot 2024-10-28 at 2 08 27 PM

I then send the account 0.00005 ETH to that account, bringing the total balance to 0.004079351477032958 ETH. At this point, the message should go away because the account is sufficiently funded based on the max fee presented, but when I retry the swap the insufficient funds message persists.

@matthewwalsh0
Copy link
Member Author

matthewwalsh0 commented Oct 28, 2024

I'm not sure if this fixes the issue.

The core problem shown in the issue video is that the estimated gas fee in 12.6 is substantially less than in 12.5, to the point that when we get an insufficient fee response from the smart transaction API, it doesn't make sense since our displayed max fee is less than our total balance. This PR resolves that specific problem.

I think you've also identified a separate pre-existing issue in the ReviewQuote component that was introduced when smart transaction support was added. It's difficult to test, but my theory is:

  1. When smart transactions are enabled, we render the gas fee estimates from the getFees call to the remote API.
  2. If this request fails due an insufficient balance (as shown in this issue also), we render the values from the error response into the warning message, specifically currentBalanceWei and balanceNeededWei - currentBalanceWei.
  3. The problem is that if the API request fails, how can we then locate the smart transaction fees to render?
  4. We instead fallback to the standard gas fee estimation calculation using the gas fee flows and gas API which are slightly different to the smart transaction fees hence the disparity you've noticed in the desired balance in the warning, versus the rendered max fee.
  5. One solution here could be to render the balance needed directly from the error response?

Meaning this PR should fix the regression from version 12.5, though I believe the misleading math you identified is out of scope. We could try verify the above theory by repeating your steps on 12.5?

@metamaskbot
Copy link
Collaborator

Builds ready [899a36f]
Page Load Metrics (1931 ± 91 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint18325411790524252
domContentLoaded17202472189118689
load17732490193118991
domInteractive27144522612
backgroundConnect12109393014
firstReactRender503041035024
getState559272211
initialActions01000
loadScripts12392001139717283
setupStore1191292612
uiStartup193831592165282136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 68 Bytes (0.00%)
  • ui: 28 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@martahj
Copy link
Contributor

martahj commented Oct 29, 2024

Meaning this PR should fix the regression from version 12.5, though I believe the misleading math you identified is out of scope. We could try verify the above theory by repeating your steps on 12.5?

Ok, I was able to repro on 12.5 and made a ticket to tackle the underlying issue. PR lgtm.

@matthewwalsh0 matthewwalsh0 added this pull request to the merge queue Oct 29, 2024
Merged via the queue into develop with commit 54b110a Oct 29, 2024
86 checks passed
@matthewwalsh0 matthewwalsh0 deleted the fix/28088-incorrect-standard-swap-gas-fee branch October 29, 2024 15:06
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2024
@metamaskbot metamaskbot added release-12.7.0 Issue or pull request that will be included in release 12.7.0 release-12.6.0 Issue or pull request that will be included in release 12.6.0 and removed release-12.7.0 Issue or pull request that will be included in release 12.7.0 labels Oct 29, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-12.6.0 on PR. Adding release label release-12.6.0 on PR and removing other release labels(release-12.7.0), as PR was cherry-picked in branch 12.6.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Swap shows incorrect gas fees
4 participants