Skip to content

fix(transaction-controller): harden gas fee token preflight - #10071

Open
jpuri wants to merge 4 commits into
mainfrom
fix/gas-fee-token-preflight-predict-claim
Open

fix(transaction-controller): harden gas fee token preflight#10071
jpuri wants to merge 4 commits into
mainfrom
fix/gas-fee-token-preflight-predict-claim

Conversation

@jpuri

@jpuri jpuri commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Explanation

Predict claim on Mobile (Polygon Safe wallets) can fail during gas-station preflight when a gas fee token (e.g. pUSD) is pre-selected but Sentinel returns an empty gasFeeTokens list and native POL is insufficient.

Two controller bugs contribute to confusing failures and bad publish fallbacks:

  1. isNativeBalanceSufficientForGas treated missing maxFeePerGas/gasPrice as zero, so gas × 0 = 0 made every wallet look able to pay native gas. That could clear selectedGasFeeToken while gas estimates were still in flight (common with skipInitialGasEstimate), leading to publishes with intrinsic gas too low: gas 0.
  2. checkGasFeeTokenBeforePublish set isExternalSign: true and cleared nonce before validating the selected token. When validation failed (Gas fee token not found and insufficient native balance), transaction metadata could remain in external-sign mode even though signing was never completed.

This PR hardens both paths:

  • balance.ts: return insufficient when gas or fee fields are unset, so pre-selected gas fee tokens are not cleared prematurely.
  • gas-fee-tokens.ts: only enable external sign after the selected token is confirmed in freshly fetched gasFeeTokens; on failure, persist refreshed tokens but reset isExternalSign to false before throwing.

No breaking API changes. Scope is limited to @metamask/transaction-controller publish-time gas-fee-token gating.

References

https://consensyssoftware.atlassian.net/browse/CONF-1725

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes transaction publish gating and native-balance checks; behavior shifts from false positives (premature token clearing, stuck external sign) to stricter failures when fees or tokens are unavailable.

Overview
Hardens publish-time gas fee token checks so pending or missing gas estimates no longer look like zero-cost native gas, and failed preflight no longer leaves transactions stuck in external-sign mode.

isNativeBalanceSufficientForGas now returns insufficient when gas or fee fields (maxFeePerGas / gasPrice) are unset, instead of multiplying by zero and incorrectly clearing a pre-selected gas fee token while estimates are still loading.

checkGasFeeTokenBeforePublish now confirms the selected token exists in freshly fetched gasFeeTokens before setting isExternalSign and clearing nonce. On validation failure it persists the refreshed token list, resets isExternalSign to false, then throws—rather than leaving external-sign metadata after an error.

Reviewed by Cursor Bugbot for commit 447935c. Bugbot is set up for automated code reviews on this repo. Configure here.

Avoid treating native balance as sufficient when gas estimates are still
pending, and do not leave isExternalSign enabled when the selected gas fee
token fails preflight validation.
@jpuri
jpuri requested review from a team as code owners September 2, 2026 04:58
@jpuri
jpuri deployed to default-branch September 2, 2026 04:58 — with GitHub Actions Active
@jpuri
jpuri marked this pull request as draft September 2, 2026 04:58
@jpuri
jpuri marked this pull request as ready for review September 2, 2026 05:06
@jpuri
jpuri enabled auto-merge September 2, 2026 05:06
@jpuri
jpuri deployed to default-branch September 2, 2026 05:06 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant