fix: transaction parameters for batch swap transactions#8979
Conversation
| skipInitialGasEstimate: quoteResponse.quote.gasIncluded7702 | ||
| ? isDelegatedAccount | ||
| : Boolean(gasFeeToken), | ||
| excludeNativeTokenForFee: !gasFeeToken, |
There was a problem hiding this comment.
Inverted excludeNativeTokenForFee flag
High Severity
Batch submission sets excludeNativeTokenForFee to !gasFeeToken, so when an ERC20 gasFeeToken is provided the flag is false. TransactionController only forces fee payment via gasFeeToken when excludeNativeTokenForFee is true with a token set, so ERC20 gasless swaps can fall back to native balance.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9e44080. Configure here.
There was a problem hiding this comment.
This is intentional. Prevents failures if the user has a native balance but it's not enough to cover network fees
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 402df45. Configure here.
| quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address && | ||
| isNativeAddress(quoteResponse.quote.feeData[FeeType.TX_FEE].asset.address) | ||
| ? undefined | ||
| : (quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address as Hex); |
There was a problem hiding this comment.
Empty native fee sets gasFeeToken
Low Severity
When TX_FEE uses a native asset with an empty-string address (valid per isNativeAddress), the gasFeeToken expression falls through to the else branch and passes an empty hex string instead of undefined, so batch params can carry a bogus gasFeeToken rather than treating the fee as native.
Reviewed by Cursor Bugbot for commit 402df45. Configure here.
There was a problem hiding this comment.
This is not possible, it's either zero address or a hex
## Explanation **Current state:** When submitting batch and batch-sell swap transactions, the gas-related transaction options were not being set correctly in several edge cases: 1. When the bridge fee is paid in an ERC20 token, the `gasFeeToken` field was not being populated, causing the TransactionController to default to native token fee payment. 2. The `excludeNativeTokenForFee` flag was not being set when a `gasFeeToken` was present, meaning the TransactionController might fall back to native assets even when an ERC20 gas fee token was explicitly specified. 3. For `gasIncluded7702` quotes submitted to accounts that haven't yet been upgraded to a smart account, `skipInitialGasEstimate` was incorrectly set, which could cause gas estimation issues. **Solution:** This release fixes all three cases in the gas-related transaction option construction for batch and batch-sell swaps: - `gasFeeToken` is now set from the quote's fee token when fees are paid in ERC20. - `excludeNativeTokenForFee` is set to `true` whenever `gasFeeToken` is populated, ensuring the ERC20 token is always used for fee payment in that scenario. - `skipInitialGasEstimate` is set to `false` when submitting `gasIncluded7702` quotes and the account has not yet been upgraded to a smart account, ensuring correct gas estimation for those transactions. ## References - [MetaMask#8979](MetaMask#8979) ## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > The release carries a targeted fix to how gas/fee options are passed into TransactionController for batch and batch-sell swaps, which can change fee token selection and estimation behavior at submit time. > > **Overview** > **Release `1019.0.0`** bumps the core monorepo and publishes **`@metamask/bridge-status-controller@72.0.1`**, documenting the gas-option fix from [MetaMask#8979](MetaMask#8979) for **batch** and **batch-sell** swaps: ERC20-paid fees set **`gasFeeToken`**, **`excludeNativeTokenForFee=true`** when that token is used, and **`skipInitialGasEstimate=false`** for **`gasIncluded7702`** on accounts not yet upgraded to a smart account. > > **`@metamask/transaction-pay-controller`** is updated to depend on **`@metamask/bridge-status-controller@^72.0.1`** (changelog + `package.json` + `yarn.lock`). No application source changes appear in this diff—only version and release metadata. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ed18202. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>


Explanation
Fixes batch-sell submission edge case which causes tx failure if
gasIncluded7702=trueand STX is enabled. See changelog for exact parameters changedIn addition to these changes, clients need to update the TransactionController
publishHookto prioritize publishing via 7702 ifisGasFeeIncluded=true. The current logic submits using STX although the quote requires 7702 processingExample transaction-controller-init change
References
Checklist
Note
High Risk
Changes how batched swaps choose 7702 vs STX paths and how fees are paid; misconfiguration can cause submission failures, and full behavior depends on a coordinated TransactionController publishHook update in clients.
Overview
Fixes gas and EIP-7702 batch options passed from
BridgeStatusControllerintoTransactionControllerfor batched swaps and batch-sell flows, addressing failures when quotes use gas-included 7702 with STX enabled or ERC-20–denominated fees.Batch swap strategy now derives
gasFeeTokenfrom the quote’sTX_FEEasset (omitted when the fee asset is native), and setsskipInitialGasEstimate/excludeNativeTokenForFeefrom that token and fromgasIncluded7702plus whether the account is already delegated.shouldDisable7702is tightened so delegated accounts only keep 7702 enabled when the quote is not plaingasIncludedSTX gasless.Batch-sell uses the same
skipInitialGasEstimateandexcludeNativeTokenForFeerules.toTransactionParamsaccepts bridge-api fee fields whether they are already hex or numeric strings.Tests and snapshots cover native vs ERC-20 gasless swaps and the updated batch params. Clients still need a separate
publishHookchange soisGasFeeIncludedquotes publish via 7702 instead of STX when required.Reviewed by Cursor Bugbot for commit 402df45. Bugbot is set up for automated code reviews on this repo. Configure here.