feat(transaction-pay): add Across strategy support#7886
feat(transaction-pay): add Across strategy support#7886pedronfigueiredo wants to merge 1 commit intomainfrom
Conversation
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/types.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Outdated
Show resolved
Hide resolved
665488f to
8be8f8c
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Outdated
Show resolved
Hide resolved
8be8f8c to
3f52702
Compare
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Show resolved
Hide resolved
3f52702 to
789a704
Compare
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Outdated
Show resolved
Hide resolved
789a704 to
6953629
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Outdated
Show resolved
Hide resolved
6953629 to
8c1c7e5
Compare
9cd0f37 to
a6c9af9
Compare
| return getFeatureFlags(messenger).relayFallbackGas; | ||
| } | ||
|
|
||
| export async function estimateGasWithBufferOrFallback({ |
| }; | ||
| } | ||
|
|
||
| export function getFallbackGas(messenger: TransactionPayControllerMessenger): { |
There was a problem hiding this comment.
Should this be in feature-flags.ts?
| error = caughtError; | ||
| } | ||
|
|
||
| const fallbackGas = getFallbackGas(messenger); |
There was a problem hiding this comment.
Debatable whether we should have fallback gas or throw as it implies the transaction would revert?
There was a problem hiding this comment.
fallback is now option but off by default
| across?: PayStrategyConfigRaw; | ||
| relay?: { | ||
| enabled?: boolean; | ||
| relayQuoteUrl?: string; |
There was a problem hiding this comment.
Is this redundant as we already have the top level value?
| slippage: number; | ||
| }; | ||
|
|
||
| export type PayStrategyConfigRaw = { |
There was a problem hiding this comment.
Should this be AcrossConfig?
| messenger, | ||
| }); | ||
|
|
||
| const max = calculateGasCost({ |
There was a problem hiding this comment.
We also need gas station support here, but can do that in a future PR and re-use the Relay logic.
There was a problem hiding this comment.
added a ticket for this
| request: QuoteRequest, | ||
| ): Promise<TransactionPayQuote<AcrossQuote>['fees']['sourceNetwork']> { | ||
| const { from } = request; | ||
| const { swapTx } = quote; |
There was a problem hiding this comment.
Do we also need to include gas cost of approvalTxns?
| const chainId = toHex(params.chainId); | ||
| const value = toHex(params.value ?? '0x0'); | ||
|
|
||
| const gas = await estimateGasWithBuffer( |
There was a problem hiding this comment.
We don't want to duplicate the gas logic again, but store the gas limits in the quote to use during submit, so we know the network fees will match.
| data: params.data, | ||
| from, | ||
| gas: toHex(gas), | ||
| maxFeePerGas: normalizeOptionalHex(params.maxFeePerGas), |
There was a problem hiding this comment.
Can they not return gas fee properties?
There was a problem hiding this comment.
not sure I understand the question here, it's simply normalising to hex if needed.
| } | ||
|
|
||
| await Promise.all( | ||
| transactionIds.map((txId) => waitForTransactionConfirmed(txId, messenger)), |
There was a problem hiding this comment.
We're waiting for the deposit transactions to succeed, but we also need to poll the Across API to verify the status of their transactions on the target chain.
Looks like /deposit/status?
08bac6a to
26c090a
Compare
8c1c7e5 to
68679f6
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
0df61f2 to
43816bc
Compare
packages/transaction-pay-controller/src/strategy/across/types.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Outdated
Show resolved
Hide resolved
e9f21d7 to
bc1b4fe
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
bc1b4fe to
a2cec3d
Compare
packages/transaction-pay-controller/src/strategy/across/across-submit.ts
Outdated
Show resolved
Hide resolved
a2cec3d to
4e7659a
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/AcrossStrategy.ts
Show resolved
Hide resolved
4e7659a to
3c6deb7
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
3c6deb7 to
d514937
Compare
packages/transaction-pay-controller/src/strategy/across/types.ts
Outdated
Show resolved
Hide resolved
d514937 to
b78255e
Compare
packages/transaction-pay-controller/src/strategy/across/types.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Outdated
Show resolved
Hide resolved
b78255e to
bbcb0e4
Compare
packages/transaction-pay-controller/src/strategy/across/across-quotes.ts
Show resolved
Hide resolved
bbcb0e4 to
9d2e07b
Compare
packages/transaction-pay-controller/src/strategy/across/AcrossStrategy.ts
Show resolved
Hide resolved
303f7d7 to
d1799f1
Compare
packages/transaction-pay-controller/src/strategy/across/AcrossStrategy.ts
Show resolved
Hide resolved
d1799f1 to
239eab7
Compare
|
|
||
| if (request.transaction?.type === TransactionType.perpsAcrossDeposit) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Missing predictAcrossDeposit guard causes potential recursion
High Severity
The supports() guard only rejects TransactionType.perpsAcrossDeposit but not TransactionType.predictAcrossDeposit. Since getAcrossDepositType maps predictDeposit → predictAcrossDeposit, the Across strategy will incorrectly consider its own predict-type deposit transactions as eligible, potentially causing recursive re-processing.
Additional Locations (1)
78893dc to
0680f84
Compare
packages/transaction-pay-controller/src/strategy/across/AcrossStrategy.ts
Show resolved
Hide resolved
0680f84 to
5fd161f
Compare
packages/transaction-pay-controller/src/strategy/across/AcrossStrategy.ts
Show resolved
Hide resolved
5fd161f to
3c7fd02
Compare


Explanation
This PR extracts the Across strategy work on top of the provider-fallback baseline.
It adds:
acrossstrategy type + registration)transaction-controllerandtransaction-pay-controllerReferences
Addresses: https://github.com/MetaMask/MetaMask-planning/issues/6997
Checklist
Note
Medium Risk
Adds a new on-chain submission path that builds/sends approval and deposit transactions and introduces external API polling, so failures could impact transaction execution and fee/gas calculations. Feature-flag gating and extensive tests reduce but don’t eliminate integration risk.
Overview
Adds a new
Acrosstransaction-pay strategy and makes it part of the default strategy order/selection, with feature-flagged enablement and strategy-specific config (apiBase,integratorId,allowSameChain,postActionsEnabled).Implements Across quote retrieval/normalization and submission: calls Across
/swap/approvalwith optional MetaMask app-fee params and optional post-actions, estimates gas with buffering and fallbacks, submits approval+deposit as a batch (or a single deposit), marks intents complete, tracks required transaction IDs, and optionally polls Across/deposit/statusto return the destination/fill hash.Extends shared types/utilities to support this flow (new
TransactionPayActionstructure,getPayStrategiesConfig, sharedsumAmounts/getFiatValueFromUsd, and a reusableestimateGasLimitWithBufferOrFallback), updates Relay’ssupportsgating, and introduces newTransactionTypes (perpsAcrossDeposit,predictAcrossDeposit) with changelog entries.Written by Cursor Bugbot for commit 3c7fd02. This will update automatically on new commits. Configure here.