Skip to content

feat(transaction-pay): add ordered strategy fallback orchestration#7868

Open
pedronfigueiredo wants to merge 2 commits intomainfrom
cor-6992-extract-fallback-mechanism
Open

feat(transaction-pay): add ordered strategy fallback orchestration#7868
pedronfigueiredo wants to merge 2 commits intomainfrom
cor-6992-extract-fallback-mechanism

Conversation

@pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Feb 9, 2026

Explanation

As per preemptive validation on #7806

  • Adds ordered strategy retrieval via TransactionPayController:getStrategies while preserving existing getStrategy behavior.
  • Adds compatibility filtering (supports(...)) during strategy selection.
  • Implements quote fallback orchestration:
    • try next strategy when quote retrieval fails
    • try next strategy when quote list is empty
    • skip unsupported strategies
  • Implements publish-hook fallback orchestration:
    • execute primary strategy from existing quote strategy
    • on execution failure, rebuild quote requests and try next compatible strategy
    • throw original primary error if all fallback attempts fail

References

Addresses https://github.com/MetaMask/MetaMask-planning/issues/6992

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 core quote-selection and refresh logic and changes which strategy is executed at publish time; ordering/fallback mistakes could cause missing quotes or incorrect submission paths, though changes are well covered by unit tests.

Overview
TransactionPayController now supports an ordered getStrategies callback (with fallback to the legacy getStrategy and to a feature-flag-driven default order) and passes this ordered list through quote refresh/update flows.

Quote retrieval (updateQuotes/getQuotes) has been reworked to iterate strategies in order, optionally apply per-strategy supports(...) filtering, skip unknown strategies, and fall back on errors/empty quotes (including batch-transaction failures). The publish hook now executes using the strategy encoded in the stored quote instead of re-resolving it from controller state.

Adds a new remote feature flag confirmations_pay.strategyOrder (with validation/deduping) and updates tests/docs/changelog accordingly.

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

@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch 6 times, most recently from 23573ac to 55549a1 Compare February 9, 2026 11:34
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from 55549a1 to e2818b3 Compare February 9, 2026 13:32
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from e2818b3 to 5158351 Compare February 9, 2026 13:48
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch 3 times, most recently from c450bc6 to 782bc16 Compare February 9, 2026 14:27
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from 9b2de51 to 44ee983 Compare February 12, 2026 11:02
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.

@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from 44ee983 to eeca0ed Compare February 12, 2026 13:47
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from eeca0ed to 9cd0f37 Compare February 13, 2026 10:43
@pedronfigueiredo pedronfigueiredo force-pushed the cor-6992-extract-fallback-mechanism branch from 9cd0f37 to a6c9af9 Compare February 13, 2026 10:47
(transaction: TransactionMeta): TransactionPayStrategy => {
const fallbackStrategy = getStrategyOrder(this.messenger)[0];
return (
this.#getStrategiesWithFallback(transaction)[0] ?? fallbackStrategy
Copy link
Member

Choose a reason for hiding this comment

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

Minor, as I assume this isn't used anymore, but do we need the ternary here since the fallback strategies are retrieved within getStrategiesWithFallback?

max?: number;
};
relayQuoteUrl?: string;
strategyOrder?: unknown[];
Copy link
Member

Choose a reason for hiding this comment

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

Is this not a string[]?

export const DEFAULT_SLIPPAGE = 0.005;
export const DEFAULT_STRATEGY_ORDER: [
TransactionPayStrategy,
...TransactionPayStrategy[],
Copy link
Member

Choose a reason for hiding this comment

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

As this is a constant, do we need a type, and why is it [X, ...X[]]?

max?: number;
};
relayQuoteUrl?: string;
strategyOrder?: unknown[];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe strategyPriority?

.filter((strategy): strategy is TransactionPayStrategy =>
VALID_STRATEGIES.has(strategy as TransactionPayStrategy),
)
.filter(
Copy link
Member

Choose a reason for hiding this comment

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

uniq from lodash?

name: strategyName,
strategy: getStrategyByName(strategyName),
};
} catch {
Copy link
Member

Choose a reason for hiding this comment

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

Minor, maybe a getStrategiesByName util?

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