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-transaction feature flags to RemoteFeatureFlagController with per-chain validation, selectors, and Sentry error reporting; deprecates getFeatureFlags.

  • BREAKING:
    • Controller now reads flags via RemoteFeatureFlagController:getState and listens to RemoteFeatureFlagController:stateChange; getFeatureFlags option deprecated/ignored.
    • Requires messenger allowlist updates for actions RemoteFeatureFlagController:getState, ErrorReportingService:captureException and event RemoteFeatureFlagController:stateChange.
  • Controller (src/SmartTransactionsController.ts):
    • Integrates remote flags; validates on state changes and reports errors via ErrorReportingService:captureException.
    • Uses chain-specific flags when marking regular txs failed and for return-tx-hash-asap behavior.
  • Feature flags module:
    • Adds src/featureFlags/* with validators (superstruct), processing, normalizeChainId, and chain-level merging; introduces DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS fallback.
  • Selectors/Exports:
    • Adds src/selectors.ts with selectSmartTransactionsFeatureFlags and selectSmartTransactionsFeatureFlagsForChain; exports from src/index.ts.
  • Utils (src/utils.ts):
    • Switches helpers to accept SmartTransactionsNetworkConfig instead of legacy flags.
  • Tests: Extensive new tests for controller validation, feature-flag processing, selectors, and utils updates.
  • Docs (README.md, CHANGELOG.md):
    • Documents remote flag usage, schema extension, defaults, and migration notes.
  • Dependencies (package.json):
    • Adds @metamask/superstruct, @metamask/utils, reselect; dev/peer deps for @metamask/remote-feature-flag-controller and @metamask/error-reporting-service.

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