Improves success rates for swaps by trialing transactions privately and finding minimum fees.
yarn add @metamask/smart-transactions-controller
or
npm install @metamask/smart-transactions-controller
Smart transactions feature flags are managed via RemoteFeatureFlagController (LaunchDarkly). The configuration uses a default remote object for global settings and chain-specific overrides keyed by hex chain ID.
The flag in LaunchDarkly is named smartTransactionsNetworks.
-
Add the field to the schema in
src/utils/validators.ts:export const SmartTransactionsNetworkConfigSchema = type({ // ... existing fields myNewFlag: optional(boolean()), });
The
SmartTransactionsNetworkConfigtype is automatically inferred from this schema. -
Add default value in
src/constants.tsunderDEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS:These values should be defensive. They are applied when the remote config is invalid or does not exist for a network. It disables smart transaction.
export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = { default: { // ... existing defaults myNewFlag: false, }, };
-
Use in clients via the exported selectors:
import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller'; const chainConfig = selectSmartTransactionsFeatureFlagsForChain( state, '0x1', ); if (chainConfig.myNewFlag) { // Feature is enabled }
This package is part of a monorepo. Instructions for contributing can be found in the monorepo README.