Skip to content

batch transactions for delegated accounts to avoid in-flight tx limit#8125

Open
cloudonshore wants to merge 11 commits intomainfrom
fix/batch-delegated-accounts
Open

batch transactions for delegated accounts to avoid in-flight tx limit#8125
cloudonshore wants to merge 11 commits intomainfrom
fix/batch-delegated-accounts

Conversation

@cloudonshore
Copy link

@cloudonshore cloudonshore commented Mar 5, 2026

Motivation

Ethereum nodes (reth, geth) enforce a limit of 1 pending transaction for EIP-7702 delegated accounts. When a swap or bridge requires token approval, the bridge-status-controller submits approve and trade as two separate transactions. The second transaction gets rejected by the node with "in-flight transaction limit reached for delegated accounts", causing the swap/bridge to fail.

Related: MetaMask/metamask-mobile#25595

Description

This PR detects EIP-7702 delegated accounts and routes them through the existing batched transaction path (previously only used for smart transactions and gasless 7702 quotes), combining approve + trade into a single atomic transaction.

Changes

@metamask/transaction-controller

  • Expose isAtomicBatchSupported as a messenger action so other controllers can check whether an account is delegated to a supported smart contract
  • Register the action handler and export the type

@metamask/bridge-status-controller

  • Add TransactionControllerIsAtomicBatchSupportedAction to AllowedActions
  • Before transaction submission, call isAtomicBatchSupported to detect delegated accounts
  • Add isDelegatedAccount as a third condition (alongside isStxEnabledOnClient and gasIncluded7702) for entering the batch transaction path
  • Pass isDelegatedAccount through to getAddTransactionBatchParams so that disable7702 is set to false for delegated accounts — enabling 7702 batching with user-paid gas (not just gas-sponsored)
  • Hoist isDelegatedAccount outside the #trace callback so it's accessible in the isNonBatchEvm check, ensuring batch transactions from delegated accounts are properly recorded in bridge status history
  • Extend findAndUpdateTransactionsInBatch to handle TransactionType.bridge and TransactionType.bridgeApproval in the 7702 matching logic (previously only handled swap/swapApproval), fixing transaction lookup for bridge operations from delegated accounts
  • Skip undefined entries in txDataByType iteration to prevent bridge transactions from being incorrectly retyped as swaps

Key design decisions

  • Batching ≠ gas sponsorship: These are orthogonal features. Delegated accounts need batching to avoid the in-flight limit, but can still pay their own gas. The disable7702 flag is now false when either gasIncluded7702 is true OR the account is delegated.
  • Graceful fallback: The delegation check is wrapped in a try/catch that defaults to false, so if isAtomicBatchSupported fails for any reason, the transaction falls back to the standard (non-batch) path.

References

Changelog

@metamask/transaction-controller

  • Added: TransactionControllerIsAtomicBatchSupportedAction type export
  • Added: Messenger action handler for isAtomicBatchSupported

@metamask/bridge-status-controller

  • Fixed: Delegated accounts (EIP-7702) now use batched transactions to avoid in-flight transaction limit
  • Fixed: Bridge transaction types now properly matched in 7702 batch path (findAndUpdateTransactionsInBatch)
  • Fixed: Delegated account batch transactions now recorded in bridge status history
  • Fixed: Undefined tx type entries no longer cause swap/bridge mistyping in batch matching

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 submission and batching behavior for EVM swap/bridge flows, which can affect how approvals/trades are sent and recorded. Risk is moderated by a try/catch fallback when isAtomicBatchSupported fails and by expanded unit test coverage.

Overview
Delegated (EIP-7702) accounts are now detected and forced through the atomic batch path so approval + trade are submitted as a single batch when needed, avoiding node “in-flight tx limit” failures.

This adds a new messenger-exposed action TransactionController:isAtomicBatchSupported (and exported TransactionControllerIsAtomicBatchSupportedAction type), wires Bridge Status Controller permissions for it, and updates batch parameter construction to decouple 7702 batching from gas sponsorship (skip gas fields only when gasIncluded7702 is true, otherwise estimate/include gas for delegated batches).

Also fixes 7702 batch post-signing reconciliation by matching and re-typing bridge/bridgeApproval entries (not just swap), skipping undefined type entries, and ensures delegated-account batch submissions are recorded in bridge history; tests/snapshots are updated and include a failure-case fallback for isAtomicBatchSupported errors.

Written by Cursor Bugbot for commit cc67872. This will update automatically on new commits. Configure here.

…limit

Ethereum nodes only allow 1 pending transaction for EIP-7702 delegated
accounts. When a swap requires token approval, the approve and swap
transactions are submitted separately, causing the second to be rejected.

This fix detects delegated accounts via isAtomicBatchSupported and routes
them through the batched transaction path, combining approve + swap into
a single transaction.

Changes:
- Expose isAtomicBatchSupported as a TransactionController messenger action
- Add delegation check in BridgeStatusController before tx submission
- Allow 7702 batching for delegated accounts without requiring gas sponsorship
@cloudonshore cloudonshore requested review from a team as code owners March 5, 2026 17:40
@cloudonshore cloudonshore changed the title fix: batch transactions for delegated accounts to avoid in-flight tx … batch transactions for delegated accounts to avoid in-flight tx limit Mar 9, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@cloudonshore cloudonshore requested a review from a team as a code owner March 9, 2026 21:52
The new TransactionController:isAtomicBatchSupported messenger call
in submitTx shifts mock queues for all EVM bridge and swap tests.
Add the mock to setupEventTrackingMocks helpers and manual setups,
update call count assertions, refresh snapshots, and add a test
covering the catch fallback path.
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