feat(transaction-pay-controller): add route-based strategy resolution#8282
feat(transaction-pay-controller): add route-based strategy resolution#8282pedronfigueiredo wants to merge 4 commits intomainfrom
Conversation
5a81abc to
b59a521
Compare
packages/transaction-pay-controller/src/TransactionPayController.ts
Outdated
Show resolved
Hide resolved
5a2400d to
3d3dc21
Compare
packages/transaction-pay-controller/src/TransactionPayController.ts
Outdated
Show resolved
Hide resolved
3d3dc21 to
85b9724
Compare
85b9724 to
de66381
Compare
packages/transaction-pay-controller/src/utils/strategy-routing.ts
Outdated
Show resolved
Hide resolved
| * @returns Raw confirmations_pay feature flags. | ||
| */ | ||
| function getFeatureFlagsRaw( | ||
| export function getConfirmationsPayFeatureFlags( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I added the suggested util getStrategy and getStrategyOrder
packages/transaction-pay-controller/src/utils/strategy-routing.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/utils/strategy-routing.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/TransactionPayController.ts
Outdated
Show resolved
Hide resolved
0abc1de to
daaa4ad
Compare
packages/transaction-pay-controller/src/utils/strategy-routing.ts
Outdated
Show resolved
Hide resolved
daaa4ad to
8c8c8b0
Compare
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Do we not still need to call our new routing if neither of these is defined?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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( |
8c8c8b0 to
649a57c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
cd877d4 to
190d2ce
Compare

Explanation
This change moves the generic
confirmations_paystrategy-order routing logic into@metamask/transaction-pay-controllerso clients no longer need to own the raw feature-flag parsing and ordered strategy resolution themselves.References
pnf/plan-provider-fallback-rolloutChecklist
Note
Medium Risk
Changes how
TransactionPayControllerchooses 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 customgetStrategy/getStrategiescallbacks don’t return a valid strategy, the controller now resolves an ordered strategy list fromconfirmations_payusing route context (payment tokenchainId/address+transaction.type).getStrategyOrderis 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 newgetStrategyhelper 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.