Skip to content

feat(transaction-pay-controller): add route-based strategy resolution#8282

Open
pedronfigueiredo wants to merge 4 commits intomainfrom
codex/transaction-pay-route-feature-flags
Open

feat(transaction-pay-controller): add route-based strategy resolution#8282
pedronfigueiredo wants to merge 4 commits intomainfrom
codex/transaction-pay-route-feature-flags

Conversation

@pedronfigueiredo
Copy link
Copy Markdown
Contributor

@pedronfigueiredo pedronfigueiredo commented Mar 24, 2026

Explanation

This change moves the generic confirmations_pay strategy-order routing logic into @metamask/transaction-pay-controller so clients no longer need to own the raw feature-flag parsing and ordered strategy resolution themselves.

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
Changes how TransactionPayController chooses fallback pay strategies by adding route-aware feature-flag parsing (chain/token/transactionType overrides) and enabled-strategy filtering, which can alter quote/submit behavior across transactions. Risk is mitigated by extensive unit tests but impacts core payment routing.

Overview
Adds route-aware pay-strategy resolution inside @metamask/transaction-pay-controller. When custom getStrategy/getStrategies callbacks don’t return a valid strategy, the controller now resolves an ordered strategy list from confirmations_pay using route context (payment token chainId/address + transaction.type).

getStrategyOrder is expanded to normalize and validate override configs, apply a clear precedence (transaction-type + token/chain overrides down to global defaults), and filter out disabled strategies; a new getStrategy helper returns the first applicable strategy. Tests are updated/expanded to cover routing precedence, case normalization, disabled-strategy behavior, and to assert internal raw-flag helpers are not exposed, and the changelog notes the new route-based resolution.

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

@pedronfigueiredo pedronfigueiredo self-assigned this Mar 24, 2026
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch 3 times, most recently from 5a81abc to b59a521 Compare March 24, 2026 14:53
@pedronfigueiredo pedronfigueiredo marked this pull request as ready for review March 24, 2026 15:04
@pedronfigueiredo pedronfigueiredo requested review from a team as code owners March 24, 2026 15:04
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch 2 times, most recently from 5a2400d to 3d3dc21 Compare March 24, 2026 17:27
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from 3d3dc21 to 85b9724 Compare March 24, 2026 17:45
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from 85b9724 to de66381 Compare March 25, 2026 14:31
* @returns Raw confirmations_pay feature flags.
*/
function getFeatureFlagsRaw(
export function getConfirmationsPayFeatureFlags(
Copy link
Copy Markdown
Member

@matthewwalsh0 matthewwalsh0 Mar 25, 2026

Choose a reason for hiding this comment

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

As in the transaction controller, the intent of these utils is to abstract the feature flag schema to retrieve values based on relevant args.

So we don't want to expose the raw values, but instead return the relevant data, so we could just have getStrategy(chainId, tokenAddress, transactionType) for example?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the suggested util getStrategy and getStrategyOrder

@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from 0abc1de to daaa4ad Compare March 26, 2026 14:00
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from daaa4ad to 8c8c8b0 Compare March 26, 2026 16:54
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the purpose of this file? Are we just trying to accomodate the localOverrides?

Do they even function for JSON flags?

Could this just go inside feature-flags.ts?

return validStrategies;
}

return getStrategyOrder(this.messenger);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we not still need to call our new routing if neither of these is defined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, getStrategy and getStrategies come from the client overrides, but we still want to fallback to the feature flag configured values in the client. I added the missing arguments

export { TransactionPayPublishHook } from './helpers/TransactionPayPublishHook';
export type { TransactionPayBridgeQuote } from './strategy/bridge/types';
export type { TransactionPayRouteContext } from './utils/strategy-routing';
export { getStrategiesForRoute } from './utils/strategy-routing';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can still be done internally, but as a fallback if the client hasn't explicitly provided their own strategy logic via one of the two callbacks?

* @returns Raw confirmations_pay feature flags.
*/
function getFeatureFlagsRaw(
export function getConfirmationsPayFeatureFlags(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No change?

@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from 8c8c8b0 to 649a57c Compare March 27, 2026 14:39
Copy link
Copy Markdown

@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 2 potential issues.

Fix All in Cursor

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

@pedronfigueiredo pedronfigueiredo requested a review from a team as a code owner March 27, 2026 16:23
@pedronfigueiredo pedronfigueiredo force-pushed the codex/transaction-pay-route-feature-flags branch from cd877d4 to 190d2ce Compare March 27, 2026 16:29
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.

3 participants