feat(transaction-pay-controller): Add shared EIP-7702 quote gas estimation#8145
feat(transaction-pay-controller): Add shared EIP-7702 quote gas estimation#8145pedronfigueiredo merged 3 commits intomainfrom
Conversation
c658ed5 to
7b400b2
Compare
7b400b2 to
49aa199
Compare
cryptotavares
left a comment
There was a problem hiding this comment.
Reviewing as @cryptotavares's AI assistant
Overall this is a clean refactor — the shared estimator logic is well-structured, fallbacks are correctly wired, and the batch/individual split in estimateQuoteGasLimits is sound. A few things worth addressing before merge:
Bug: Missing chainId fallback in getAcrossOrderedTransactions
File: src/strategy/across/transactions.ts + src/strategy/across/across-quotes.ts
getAcrossOrderedTransactions spreads approval transactions directly from the Across API response:
const approvalTransactions = (quote.approvalTxns ?? []).map((approval) => ({
...approval,
kind: 'approval' as const,
type: TransactionType.tokenMethodApprove,
}));If the Across API omits chainId on an approval transaction (which the old code explicitly guarded against with quote.approvalTxns?.[index]?.chainId ?? swapTx.chainId), then transaction.chainId will be undefined at runtime despite the type saying number. The gas estimation call in calculateSourceNetworkCost then does:
chainId: toHex(transaction.chainId), // toHex(undefined) → likely '0x0'This would target the wrong chain for gas estimation. The cost calculation later in calculateSourceNetworkCost still has the correct fallback (quote.approvalTxns?.[index]?.chainId ?? swapTx.chainId), but that doesn't help if estimation ran against chain 0x0.
The old fallback was intentional. Either:
- Add the fallback inside
getAcrossOrderedTransactions(passswapTx.chainIdand useapproval.chainId ?? swapChainId), or - Add it at the call site in
calculateSourceNetworkCostwhen building thetransactionsarray
Logic concern: useBuffer skips buffer when batch API echoes provided gas
File: src/utils/quote-gas.ts (~L105)
const useBuffer =
gasLimits.length === 1 || paramGasLimits[index] !== gasLimit;When estimateGasBatch returns per-transaction results (gasLimits.length === transactions.length), useBuffer is false if the batch API returns exactly the value that was passed in via transaction.gas. The intent seems to be "if the chain just echoed back our provided value, don't add a buffer on top." That's a reasonable interpretation, but paramGasLimits[index] is the parsed input gas; if the batch API happens to estimate the same number that was provided (not just echo it), buffer would also be skipped. Is that intentional? Worth adding a comment to clarify.
Minor: combinePostQuoteGas EIP-7702 detection heuristic
File: src/strategy/relay/relay-quotes.ts (~L480)
// TODO: Test EIP-7702 support on the chain as well before assuming single gas limit.
const isEIP7702 = gasLimits.length === 1;A single-step Relay quote (one transaction, individual estimation) also produces gasLimits.length === 1, so this misidentifies it as a 7702 batch and combines the original tx gas into a single limit. I see this has a TODO already — just flagging it as something that becomes more load-bearing now that the shared estimator is in use for both strategies.
One merge blocker (the chainId fallback regression), one question (buffer logic intent), one pre-existing TODO that's worth tracking. Happy to look at a follow-up once the chainId question is resolved.
0c900ca to
50c912d
Compare
ec0ec98 to
e0c0649
Compare
5317383 to
8a2e24a
Compare
There was a problem hiding this comment.
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.
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
8a2e24a to
33c04a7
Compare
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
c0225fd to
14f1189
Compare
| requiredParams.from === undefined || | ||
| requiredParams.to === undefined | ||
| ) { | ||
| throw new Error( |
There was a problem hiding this comment.
Minor, I meant let it throw naturally rather than explicitly checking each field.
| const gasEstimate = gasEstimates.gasLimits[index]; | ||
|
|
||
| if (!gasEstimate) { | ||
| throw new Error( |
There was a problem hiding this comment.
Minor, is this possible since earlier gas estimation would of thrown?
There was a problem hiding this comment.
good point, removed
| const batchGasLimit = | ||
| is7702 && allParams.length > 1 ? gasLimits[0] : undefined; | ||
|
|
||
| if (is7702 && allParams.length > 1 && batchGasLimit === undefined) { |
There was a problem hiding this comment.
Minor, is this duplication since we already have is7702 set?
Could we enforce in the type that is7702 guarantees one entry?
6228110 to
19e2e26
Compare
19e2e26 to
845e1c3
Compare
Explanation
Add a shared quote gas estimator that switches between per-transaction and EIP-7702 batch estimation, reuses Across’s ordered submission transaction list at quote time, and falls back to the single-transaction path when batch estimation is unsupported or fails.
References
https://github.com/MetaMask/MetaMask-planning/issues/7098
Checklist
Note
Medium Risk
Refactors gas estimation and submission logic for both Relay and Across quotes, including new EIP-7702 batch-handling paths; incorrect limits could impact fee calculation or batch execution behavior.
Overview
Adds a shared
estimateQuoteGasLimitsutility that centralizes quote-time gas estimation across strategies, usingestimateGasBatchfor multi-transaction quotes (including EIP-7702 combined single-limit batches) and falling back to per-transaction estimation when appropriate.Updates Across and Relay quoting to use this shared estimator, introduces a consistent
is7702flag in quote metadata, and reshapes gas limit data (Across now returns an ordered list instead of{ approval, swap }). Submission paths are updated to honoris7702by omitting per-txgaswhen usinggasLimit7702, with stricter erroring when required limits/fields are missing.Adds
getAcrossOrderedTransactionsto reuse the same approval+swap ordering for estimation and submit, and expands test coverage for batch estimation, missing fields, and 7702-specific behaviors.Written by Cursor Bugbot for commit 845e1c3. This will update automatically on new commits. Configure here.