Skip to content

Conversation

@rarquevaux
Copy link
Contributor

@rarquevaux rarquevaux commented Dec 5, 2025

RemoteFeatureFlagController Integration in SmartTransactionController

This PR refactors how Smart Transactions feature flags are validated and made available to clients. This will allow clients to move away from the smart transactions properties of the swaps feature flags which are deprecated.

Key Changes:

  • Flag Source: Feature flags are now read directly from RemoteFeatureFlagController:getState instead of a getFeatureFlags callback.
  • Validation Timing: Flags are validated when RemoteFeatureFlagController:stateChange fires
  • Per-Chain Validation: Invalid chain configs are removed individually without affecting valid chains; errors are reported to Sentry via ErrorReportingService:captureException
  • Unknown Chain Safety: Chains without explicit config return hardcoded disabled defaults (all flags false)
  • Messenger Requirements: Clients must configure RemoteFeatureFlagController:getState, ErrorReportingService:captureException as allowed actions, and RemoteFeatureFlagController:stateChange as allowed event
  • The getFeatureFlags constructor option is deprecated and ignored.

Links to draft migration PRs:


Note

Migrates smart-transactions feature flags to RemoteFeatureFlagController with per-chain validation, Sentry error reporting, new selectors, and controller changes that deprecate the getFeatureFlags option.

  • Breaking:
    • Controller now reads flags via RemoteFeatureFlagController:getState and listens to RemoteFeatureFlagController:stateChange.
    • Requires allowing actions RemoteFeatureFlagController:getState, ErrorReportingService:captureException and event RemoteFeatureFlagController:stateChange in the messenger.
    • Deprecates and ignores getFeatureFlags constructor option.
  • Feature Flags:
    • Add featureFlags module with validators (superstruct) and helpers to process flags, normalize chain IDs (hex/CAIP-2), and merge per-chain configs.
    • Introduce hardcoded DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS fallback.
    • Export selectors selectSmartTransactionsFeatureFlags and selectSmartTransactionsFeatureFlagsForChain.
  • Controller (src/SmartTransactionsController.ts):
    • Validates flags on feature-flag state changes and reports errors via ErrorReportingService:captureException.
    • Uses per-chain flags when deciding to mark regular transactions as failed; removes use of getFeatureFlags.
  • Types & Exports:
    • Add and export SmartTransactionsNetworkConfig, SmartTransactionsFeatureFlagsConfig; update public index exports.
  • Tests:
    • Add comprehensive tests for validators, feature-flag processing/selection, and controller error reporting and behavior.
  • Docs:
    • README: document feature-flag management and how to add new flags.
  • Dependencies:
    • Add @metamask/superstruct, @metamask/utils, reselect; add peer deps @metamask/remote-feature-flag-controller, @metamask/error-reporting-service.

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

@socket-security
Copy link

socket-security bot commented Dec 5, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​remote-feature-flag-controller@​2.0.11001007596100
Added@​metamask/​error-reporting-service@​3.0.010010010094100

View full report

@rarquevaux rarquevaux force-pushed the feat/STX-331-stx-flags-v2 branch 4 times, most recently from b4c03a2 to 3176b2a Compare December 6, 2025 00:02
@rarquevaux rarquevaux marked this pull request as ready for review December 6, 2025 00:02
@rarquevaux rarquevaux requested a review from a team as a code owner December 6, 2025 00:02
@rarquevaux rarquevaux changed the title fix(STX-331): migrate STX flags to smart-transactions-controller feat(STX-331): migrate STX flags to smart-transactions-controller Dec 6, 2025
@rarquevaux rarquevaux force-pushed the feat/STX-331-stx-flags-v2 branch from 3176b2a to eb0e310 Compare December 6, 2025 00:40
@rarquevaux rarquevaux force-pushed the feat/STX-331-stx-flags-v2 branch from eb0e310 to 2c07ca5 Compare December 8, 2025 18:01
dan437
dan437 previously approved these changes Dec 9, 2025
@rarquevaux rarquevaux force-pushed the feat/STX-331-stx-flags-v2 branch from 27e2f33 to f0ffe63 Compare December 17, 2025 18:47
@rarquevaux rarquevaux merged commit 26cfef4 into main Dec 17, 2025
18 checks passed
@rarquevaux rarquevaux deleted the feat/STX-331-stx-flags-v2 branch December 17, 2025 19:40
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