Skip to content

refactor(transaction-pay-controller): extract post-quote gas helpers from the Relay strategy - #10805

Merged
matthewwalsh0 merged 2 commits into
mainfrom
refactor/transaction-pay-post-quote
Oct 16, 2026
Merged

matthewwalsh0 merged 2 commits into
mainfrom
refactor/transaction-pay-post-quote

Conversation

@matthewwalsh0

@matthewwalsh0 matthewwalsh0 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Explanation

Post-quote gas handling lives inside the Relay strategy, but the server strategy needs the same logic to support Predict withdraws. This moves it into shared helpers with no change in behaviour.

  • estimateSourceGas estimates source-chain gas for a quote's transactions, including the original transaction prepended in post-quote flows, the fixed allowances when it cannot be estimated, and an optional from override.
  • reservePostQuoteGas re-quotes with the gas cost reserved from the source amount, using a strategy-provided re-quote callback.
  • The Relay strategy calls both helpers in place of its inline logic. The existing Relay quote tests pass unchanged, and the helpers have their own unit tests.

References

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
Touches quote amounts and gas limits for post-quote and EIP-7702 batch paths; behavior is intended to be unchanged but mistakes could affect funding and gas-fee-token eligibility.

Overview
Refactors post-quote gas logic out of the Relay strategy into shared utilities so other pay strategies (e.g. server/Predict withdraw) can reuse the same behavior without duplicating it.

reservePostQuoteGas centralizes the two-phase post-quote flow: when gas must be paid from the committed source balance (gas fee token or native source), it buffers the estimated gas cost, subtracts it from sourceTokenAmount when needed, and re-quotes via a callback—with the same fallbacks (sufficient headroom, insufficient amount after subtraction, lost gas-fee-token eligibility, re-quote errors).

estimateSourceGas centralizes source-chain gas estimation for quote steps plus transactions prepended at submit time: batch-estimating the original transaction with relay steps for post-quote EIP-7702 detection, optional fromOverride for Safe-style flows, and fixed allowances when the original tx cannot be included (payment override, account override, missing to/gas).

The Relay strategy now delegates to these helpers instead of large inline blocks in relay-quotes.ts; dedicated unit tests cover the extracted logic.

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

Base automatically changed from refactor/transaction-pay-polymarket-utils to main October 13, 2026 16:07
@matthewwalsh0
matthewwalsh0 force-pushed the refactor/transaction-pay-post-quote branch from f35a6de to ea9634a Compare October 14, 2026 13:29
@matthewwalsh0
matthewwalsh0 force-pushed the refactor/transaction-pay-post-quote branch from 3ed4f55 to f5b1abf Compare October 14, 2026 13:49
@matthewwalsh0
matthewwalsh0 marked this pull request as ready for review October 14, 2026 16:30
@matthewwalsh0
matthewwalsh0 requested a review from a team as a code owner October 14, 2026 16:30
@matthewwalsh0

Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@matthewwalsh0
matthewwalsh0 deployed to default-branch October 14, 2026 16:30 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@11.0.1-preview-f5b1abf78
@metamask-previews/accounts-controller@40.0.0-preview-f5b1abf78
@metamask-previews/address-book-controller@8.0.0-preview-f5b1abf78
@metamask-previews/advanced-chart-core@1.0.0-preview-f5b1abf78
@metamask-previews/ai-controllers@2.0.0-preview-f5b1abf78
@metamask-previews/analytics-controller@4.0.0-preview-f5b1abf78
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-f5b1abf78
@metamask-previews/announcement-controller@9.0.0-preview-f5b1abf78
@metamask-previews/app-metadata-controller@3.0.0-preview-f5b1abf78
@metamask-previews/approval-controller@10.0.0-preview-f5b1abf78
@metamask-previews/assets-controller@19.0.0-preview-f5b1abf78
@metamask-previews/assets-controllers@112.1.2-preview-f5b1abf78
@metamask-previews/authenticated-user-storage@4.1.0-preview-f5b1abf78
@metamask-previews/base-controller@10.0.0-preview-f5b1abf78
@metamask-previews/base-data-service@2.1.0-preview-f5b1abf78
@metamask-previews/bitcoin-regtest-up@2.0.0-preview-f5b1abf78
@metamask-previews/bridge-controller@82.0.3-preview-f5b1abf78
@metamask-previews/bridge-status-controller@76.3.5-preview-f5b1abf78
@metamask-previews/build-utils@4.0.0-preview-f5b1abf78
@metamask-previews/chain-agnostic-permission@2.0.0-preview-f5b1abf78
@metamask-previews/chomp-api-service@6.0.1-preview-f5b1abf78
@metamask-previews/claims-controller@1.0.3-preview-f5b1abf78
@metamask-previews/client-controller@2.0.0-preview-f5b1abf78
@metamask-previews/client-utils@3.0.4-preview-f5b1abf78
@metamask-previews/compliance-controller@3.0.0-preview-f5b1abf78
@metamask-previews/composable-controller@13.0.0-preview-f5b1abf78
@metamask-previews/config-registry-controller@5.0.0-preview-f5b1abf78
@metamask-previews/connectivity-controller@1.0.0-preview-f5b1abf78
@metamask-previews/controller-utils@13.0.0-preview-f5b1abf78
@metamask-previews/core-backend@12.1.0-preview-f5b1abf78
@metamask-previews/cryptography@1.1.2-preview-f5b1abf78
@metamask-previews/delegation-controller@4.0.0-preview-f5b1abf78
@metamask-previews/earn-controller@13.0.2-preview-f5b1abf78
@metamask-previews/eip-5792-middleware@4.0.1-preview-f5b1abf78
@metamask-previews/eip-7702-internal-rpc-middleware@1.0.0-preview-f5b1abf78
@metamask-previews/eip1193-permission-middleware@3.0.0-preview-f5b1abf78
@metamask-previews/eth-block-tracker@16.0.0-preview-f5b1abf78
@metamask-previews/eth-json-rpc-middleware@25.0.0-preview-f5b1abf78
@metamask-previews/eth-json-rpc-provider@7.0.0-preview-f5b1abf78
@metamask-previews/foundryup@2.0.0-preview-f5b1abf78
@metamask-previews/gas-fee-controller@27.0.0-preview-f5b1abf78
@metamask-previews/gator-permissions-controller@6.0.1-preview-f5b1abf78
@metamask-previews/geolocation-controller@2.0.0-preview-f5b1abf78
@metamask-previews/java-tron-up@2.0.0-preview-f5b1abf78
@metamask-previews/json-rpc-engine@11.0.0-preview-f5b1abf78
@metamask-previews/json-rpc-middleware-stream@9.0.0-preview-f5b1abf78
@metamask-previews/keyring-controller@28.1.0-preview-f5b1abf78
@metamask-previews/kyc-controller@0.9.0-preview-f5b1abf78
@metamask-previews/local-node-utils@2.0.0-preview-f5b1abf78
@metamask-previews/logging-controller@10.0.0-preview-f5b1abf78
@metamask-previews/message-manager@15.0.0-preview-f5b1abf78
@metamask-previews/messenger@3.0.0-preview-f5b1abf78
@metamask-previews/messenger-cli@1.0.0-preview-f5b1abf78
@metamask-previews/money-account-api-data-service@2.1.0-preview-f5b1abf78
@metamask-previews/money-account-balance-service@3.1.2-preview-f5b1abf78
@metamask-previews/money-account-controller@2.0.0-preview-f5b1abf78
@metamask-previews/money-account-upgrade-controller@5.1.0-preview-f5b1abf78
@metamask-previews/money-account-utils@2.1.0-preview-f5b1abf78
@metamask-previews/multichain-account-service@14.1.0-preview-f5b1abf78
@metamask-previews/multichain-api-middleware@5.0.0-preview-f5b1abf78
@metamask-previews/multichain-network-controller@4.0.0-preview-f5b1abf78
@metamask-previews/multichain-transactions-controller@8.0.0-preview-f5b1abf78
@metamask-previews/name-controller@10.0.0-preview-f5b1abf78
@metamask-previews/network-connection-banner-controller@1.0.0-preview-f5b1abf78
@metamask-previews/network-controller@37.0.1-preview-f5b1abf78
@metamask-previews/network-enablement-controller@7.0.2-preview-f5b1abf78
@metamask-previews/notification-services-controller@29.0.3-preview-f5b1abf78
@metamask-previews/passkey-controller@4.1.0-preview-f5b1abf78
@metamask-previews/permission-controller@14.0.0-preview-f5b1abf78
@metamask-previews/permission-log-controller@6.0.0-preview-f5b1abf78
@metamask-previews/perps-controller@20.1.0-preview-f5b1abf78
@metamask-previews/phishing-controller@18.2.1-preview-f5b1abf78
@metamask-previews/platform-api-docs@0.2.1-preview-f5b1abf78
@metamask-previews/polling-controller@17.0.0-preview-f5b1abf78
@metamask-previews/preferences-controller@24.0.0-preview-f5b1abf78
@metamask-previews/profile-controller@1.1.0-preview-f5b1abf78
@metamask-previews/profile-metrics-controller@5.1.3-preview-f5b1abf78
@metamask-previews/profile-sync-controller@34.0.3-preview-f5b1abf78
@metamask-previews/ramps-controller@27.0.1-preview-f5b1abf78
@metamask-previews/rate-limit-controller@8.0.0-preview-f5b1abf78
@metamask-previews/react-data-query@2.0.0-preview-f5b1abf78
@metamask-previews/remote-feature-flag-controller@7.0.0-preview-f5b1abf78
@metamask-previews/sample-controllers@6.0.0-preview-f5b1abf78
@metamask-previews/seedless-onboarding-controller@12.0.0-preview-f5b1abf78
@metamask-previews/selected-network-controller@27.0.0-preview-f5b1abf78
@metamask-previews/sentinel-api-service@2.1.0-preview-f5b1abf78
@metamask-previews/shield-controller@7.0.4-preview-f5b1abf78
@metamask-previews/signature-controller@40.0.0-preview-f5b1abf78
@metamask-previews/smart-transactions-controller@27.1.0-preview-f5b1abf78
@metamask-previews/snap-account-service@4.0.0-preview-f5b1abf78
@metamask-previews/social-controllers@3.7.0-preview-f5b1abf78
@metamask-previews/solana-test-validator-up@2.0.0-preview-f5b1abf78
@metamask-previews/stellar-quickstart-up@0.0.0-preview-f5b1abf78
@metamask-previews/storage-service@2.0.0-preview-f5b1abf78
@metamask-previews/subscription-controller@14.0.0-preview-f5b1abf78
@metamask-previews/transaction-controller@72.2.1-preview-f5b1abf78
@metamask-previews/transaction-pay-controller@30.1.0-preview-f5b1abf78
@metamask-previews/user-operation-controller@42.0.1-preview-f5b1abf78
@metamask-previews/utils@12.0.0-preview-f5b1abf78
@metamask-previews/wallet@17.1.0-preview-f5b1abf78
@metamask-previews/wallet-cli@0.0.0-preview-f5b1abf78

@matthewwalsh0
matthewwalsh0 added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit af7a3d2 Oct 16, 2026
49 checks passed
@matthewwalsh0
matthewwalsh0 deleted the refactor/transaction-pay-post-quote branch October 16, 2026 05:27

This branch was successfully deployed

1 active deployment
default-branch — f5b1abf7 Deployed Oct 14, 2026 by matthewwalsh0 via Determine whether this PR is a release PR #5523
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants