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

Reads STX feature flags from RemoteFeatureFlagController, validates on state changes with Sentry reporting, adds selectors/utilities, and deprecates getFeatureFlags.

  • BREAKING:
    • Controller reads flags from RemoteFeatureFlagController:getState; getFeatureFlags constructor option deprecated/ignored.
    • Clients must allow actions RemoteFeatureFlagController:getState, ErrorReportingService:captureException and event RemoteFeatureFlagController:stateChange.
  • Controller (src/SmartTransactionsController.ts):
    • Subscribes to RemoteFeatureFlagController:stateChange, validates flags, reports errors via ErrorReportingService:captureException.
    • Uses getSmartTransactionsFeatureFlags/getSmartTransactionsFeatureFlagsForChain to drive behavior (e.g., marking regular tx failed).
  • Feature Flags Module (src/featureFlags/*):
    • Add validators (Superstruct) and processing for smartTransactionsNetworks; supports hex and CAIP-2 IDs.
    • Provide utilities: normalizeChainId, per-chain merge with default, and hardcoded disabled defaults for unknown chains.
  • Selectors (src/selectors.ts):
    • Export selectSmartTransactionsFeatureFlags and selectSmartTransactionsFeatureFlagsForChain.
  • Utils (src/utils.ts):
    • Switch getReturnTxHashAsap/shouldMarkRegularTransactionAsFailed to use network config flags.
  • Tests:
    • Extensive unit tests for validators, feature flag processing/selectors, controller error reporting and behavior.
  • Docs:
    • README adds feature-flag usage/migration guidance; CHANGELOG notes breaking changes.
  • Deps/Peers:
    • Add @metamask/superstruct, @metamask/utils, reselect; peer deps @metamask/remote-feature-flag-controller, @metamask/error-reporting-service.

Written by Cursor Bugbot for commit eb0e310. 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
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.

2 participants