@metamask/smart-transactions-controller 21.1.0 → 22.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/README.md +47 -0
- package/dist/SmartTransactionsController.cjs +20 -6
- package/dist/SmartTransactionsController.cjs.map +1 -1
- package/dist/SmartTransactionsController.d.cts +13 -5
- package/dist/SmartTransactionsController.d.cts.map +1 -1
- package/dist/SmartTransactionsController.d.mts +13 -5
- package/dist/SmartTransactionsController.d.mts.map +1 -1
- package/dist/SmartTransactionsController.mjs +21 -7
- package/dist/SmartTransactionsController.mjs.map +1 -1
- package/dist/constants.cjs +21 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +20 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +20 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +20 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/featureFlags/feature-flags.cjs +119 -0
- package/dist/featureFlags/feature-flags.cjs.map +1 -0
- package/dist/featureFlags/feature-flags.d.cts +76 -0
- package/dist/featureFlags/feature-flags.d.cts.map +1 -0
- package/dist/featureFlags/feature-flags.d.mts +76 -0
- package/dist/featureFlags/feature-flags.d.mts.map +1 -0
- package/dist/featureFlags/feature-flags.mjs +112 -0
- package/dist/featureFlags/feature-flags.mjs.map +1 -0
- package/dist/featureFlags/index.cjs +14 -0
- package/dist/featureFlags/index.cjs.map +1 -0
- package/dist/featureFlags/index.d.cts +3 -0
- package/dist/featureFlags/index.d.cts.map +1 -0
- package/dist/featureFlags/index.d.mts +3 -0
- package/dist/featureFlags/index.d.mts.map +1 -0
- package/dist/featureFlags/index.mjs +3 -0
- package/dist/featureFlags/index.mjs.map +1 -0
- package/dist/featureFlags/validators.cjs +126 -0
- package/dist/featureFlags/validators.cjs.map +1 -0
- package/dist/featureFlags/validators.d.cts +141 -0
- package/dist/featureFlags/validators.d.cts.map +1 -0
- package/dist/featureFlags/validators.d.mts +141 -0
- package/dist/featureFlags/validators.d.mts.map +1 -0
- package/dist/featureFlags/validators.mjs +121 -0
- package/dist/featureFlags/validators.mjs.map +1 -0
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +66 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/selectors.d.cts +177 -0
- package/dist/selectors.d.cts.map +1 -0
- package/dist/selectors.d.mts +177 -0
- package/dist/selectors.d.mts.map +1 -0
- package/dist/selectors.mjs +63 -0
- package/dist/selectors.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +24 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +24 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +5 -7
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -7
- package/dist/utils.mjs.map +1 -1
- package/package.json +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [22.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING**: The controller now reads feature flags directly from `RemoteFeatureFlagController` via the messenger instead of using the `getFeatureFlags` callback ([#550](https://github.com/MetaMask/smart-transactions-controller/pull/550))
|
|
15
|
+
- Clients must configure the following as allowed actions in the controller messenger:
|
|
16
|
+
- `RemoteFeatureFlagController:getState`
|
|
17
|
+
- `ErrorReportingService:captureException` (for reporting validation errors to Sentry)
|
|
18
|
+
- Clients must configure `RemoteFeatureFlagController:stateChange` as an allowed event
|
|
19
|
+
- The `getFeatureFlags` constructor option is now deprecated and ignored
|
|
20
|
+
|
|
10
21
|
## [21.1.0]
|
|
11
22
|
|
|
12
23
|
### Added
|
|
@@ -681,7 +692,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
681
692
|
- Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
|
|
682
693
|
- Initial commit
|
|
683
694
|
|
|
684
|
-
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/
|
|
695
|
+
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v22.0.0...HEAD
|
|
696
|
+
[22.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v21.1.0...v22.0.0
|
|
685
697
|
[21.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v21.0.0...v21.1.0
|
|
686
698
|
[21.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v20.1.0...v21.0.0
|
|
687
699
|
[20.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v20.0.0...v20.1.0
|
package/README.md
CHANGED
|
@@ -25,6 +25,53 @@ Run `yarn test` to run the tests once. To run tests on file changes, run `yarn t
|
|
|
25
25
|
|
|
26
26
|
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
|
|
27
27
|
|
|
28
|
+
### Feature Flags
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
The flag in LaunchDarkly is named `smartTransactionsNetworks`.
|
|
33
|
+
|
|
34
|
+
#### Adding a New Flag
|
|
35
|
+
|
|
36
|
+
1. **Add the field to the schema** in `src/utils/validators.ts`:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
export const SmartTransactionsNetworkConfigSchema = type({
|
|
40
|
+
// ... existing fields
|
|
41
|
+
myNewFlag: optional(boolean()),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The `SmartTransactionsNetworkConfig` type is automatically inferred from this schema.
|
|
46
|
+
|
|
47
|
+
2. **Add default value** in `src/constants.ts` under `DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS`:
|
|
48
|
+
|
|
49
|
+
These values should be defensive. They are applied when the remote config is invalid or does not exist for a network.
|
|
50
|
+
It disables smart transaction.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = {
|
|
54
|
+
default: {
|
|
55
|
+
// ... existing defaults
|
|
56
|
+
myNewFlag: false,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
3. **Use in clients** via the exported selectors:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller';
|
|
65
|
+
|
|
66
|
+
const chainConfig = selectSmartTransactionsFeatureFlagsForChain(
|
|
67
|
+
state,
|
|
68
|
+
'0x1',
|
|
69
|
+
);
|
|
70
|
+
if (chainConfig.myNewFlag) {
|
|
71
|
+
// Feature is enabled
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
28
75
|
### Release & Publishing
|
|
29
76
|
|
|
30
77
|
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps,
|
|
16
|
+
var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_trace, _SmartTransactionsController_validateAndReportFeatureFlags, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SmartTransactionsController = exports.getDefaultSmartTransactionsControllerState = exports.DEFAULT_INTERVAL = void 0;
|
|
19
19
|
const bytes_1 = require("@ethersproject/bytes");
|
|
@@ -23,6 +23,8 @@ const polling_controller_1 = require("@metamask/polling-controller");
|
|
|
23
23
|
const bignumber_js_1 = require("bignumber.js");
|
|
24
24
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep.js"));
|
|
25
25
|
const constants_1 = require("./constants.cjs");
|
|
26
|
+
const feature_flags_1 = require("./featureFlags/feature-flags.cjs");
|
|
27
|
+
const validators_1 = require("./featureFlags/validators.cjs");
|
|
26
28
|
const types_1 = require("./types.cjs");
|
|
27
29
|
const utils_1 = require("./utils.cjs");
|
|
28
30
|
const SECOND = 1000;
|
|
@@ -76,7 +78,7 @@ function getDefaultSmartTransactionsControllerState() {
|
|
|
76
78
|
}
|
|
77
79
|
exports.getDefaultSmartTransactionsControllerState = getDefaultSmartTransactionsControllerState;
|
|
78
80
|
class SmartTransactionsController extends (0, polling_controller_1.StaticIntervalPollingController)() {
|
|
79
|
-
constructor({ interval = exports.DEFAULT_INTERVAL, clientId, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps,
|
|
81
|
+
constructor({ interval = exports.DEFAULT_INTERVAL, clientId, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, trace, }) {
|
|
80
82
|
super({
|
|
81
83
|
name: controllerName,
|
|
82
84
|
metadata: controllerMetadata,
|
|
@@ -91,7 +93,6 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
91
93
|
_SmartTransactionsController_ethQuery.set(this, void 0);
|
|
92
94
|
_SmartTransactionsController_trackMetaMetricsEvent.set(this, void 0);
|
|
93
95
|
_SmartTransactionsController_getMetaMetricsProps.set(this, void 0);
|
|
94
|
-
_SmartTransactionsController_getFeatureFlags.set(this, void 0);
|
|
95
96
|
_SmartTransactionsController_trace.set(this, void 0);
|
|
96
97
|
__classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
|
|
97
98
|
__classPrivateFieldSet(this, _SmartTransactionsController_clientId, clientId, "f");
|
|
@@ -101,7 +102,6 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
101
102
|
__classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, undefined, "f");
|
|
102
103
|
__classPrivateFieldSet(this, _SmartTransactionsController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
|
|
103
104
|
__classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f");
|
|
104
|
-
__classPrivateFieldSet(this, _SmartTransactionsController_getFeatureFlags, getFeatureFlags, "f");
|
|
105
105
|
__classPrivateFieldSet(this, _SmartTransactionsController_trace, trace !== null && trace !== void 0 ? trace : ((_request, fn) => fn === null || fn === void 0 ? void 0 : fn()), "f");
|
|
106
106
|
this.initializeSmartTransactionsForChainId();
|
|
107
107
|
this.messenger.subscribe('NetworkController:stateChange', ({ selectedNetworkClientId }) => {
|
|
@@ -112,6 +112,10 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
112
112
|
this.checkPoll(this.state);
|
|
113
113
|
});
|
|
114
114
|
this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState));
|
|
115
|
+
// Validate feature flags on changes
|
|
116
|
+
this.messenger.subscribe('RemoteFeatureFlagController:stateChange', () => {
|
|
117
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_validateAndReportFeatureFlags).call(this);
|
|
118
|
+
});
|
|
115
119
|
}
|
|
116
120
|
async _executePoll({ chainIds, }) {
|
|
117
121
|
// if this is going to be truly UI driven polling we shouldn't really reach here
|
|
@@ -487,7 +491,16 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
487
491
|
}
|
|
488
492
|
}
|
|
489
493
|
exports.SmartTransactionsController = SmartTransactionsController;
|
|
490
|
-
_SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(),
|
|
494
|
+
_SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_validateAndReportFeatureFlags = function _SmartTransactionsController_validateAndReportFeatureFlags() {
|
|
495
|
+
var _a;
|
|
496
|
+
const remoteFeatureFlagControllerState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
497
|
+
const rawFlags = (_a = remoteFeatureFlagControllerState === null || remoteFeatureFlagControllerState === void 0 ? void 0 : remoteFeatureFlagControllerState.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks;
|
|
498
|
+
const { errors } = (0, validators_1.validateSmartTransactionsFeatureFlags)(rawFlags);
|
|
499
|
+
// Report each validation error to Sentry
|
|
500
|
+
for (const error of errors) {
|
|
501
|
+
this.messenger.call('ErrorReportingService:captureException', new Error(`[SmartTransactionsController] Feature flag validation failed: ${error.message}. Please check the SmartTransactionNetworks feature flag in Remote Config. Smart transactions are disabled for this network. Default disabled config: ${JSON.stringify(constants_1.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default)}`));
|
|
502
|
+
}
|
|
503
|
+
}, _SmartTransactionsController_fetch =
|
|
491
504
|
/* istanbul ignore next */
|
|
492
505
|
async function _SmartTransactionsController_fetch(request, options) {
|
|
493
506
|
const fetchOptions = Object.assign(Object.assign({}, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, (__classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") && { 'X-Client-Id': __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") })) });
|
|
@@ -559,10 +572,11 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
559
572
|
const nextSmartTransaction = Object.assign(Object.assign({}, currentSmartTransaction), smartTransaction);
|
|
560
573
|
// We have to emit this event here, so a txHash is returned to the TransactionController once it's available.
|
|
561
574
|
this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction);
|
|
575
|
+
const featureFlags = (0, feature_flags_1.getSmartTransactionsFeatureFlagsForChain)((0, feature_flags_1.getSmartTransactionsFeatureFlags)(this.messenger), chainId);
|
|
562
576
|
if ((0, utils_1.shouldMarkRegularTransactionsAsFailed)({
|
|
563
577
|
smartTransaction: nextSmartTransaction,
|
|
564
578
|
clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"),
|
|
565
|
-
|
|
579
|
+
featureFlags,
|
|
566
580
|
})) {
|
|
567
581
|
(0, utils_1.markRegularTransactionsAsFailed)({
|
|
568
582
|
smartTransaction: nextSmartTransaction,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.cjs","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAA+C;AAM/C,iEAMoC;AACpC,oEAA2C;AAQ3C,qEAA+E;AAQ/E,+CAAyC;AACzC,oEAAyC;AAEzC,+CAIqB;AAcrB,uCAA4D;AAC5D,uCAYiB;AAEjB,MAAM,MAAM,GAAG,IAAI,CAAC;AACP,QAAA,gBAAgB,GAAG,MAAM,GAAG,CAAC,CAAC;AAC3C,MAAM,mBAAmB,GACvB,0DAA0D,CAAC;AAE7D;;GAEG;AACH,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,kBAAkB,GAAoD;IAC1E,sBAAsB,EAAE;QACtB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAmBF;;;;GAIG;AACH,SAAgB,0CAA0C;IACxD,OAAO;QACL,sBAAsB,EAAE;YACtB,iBAAiB,EAA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EC,MAAM,EACJ,sBAAsB,EAAE,EAAE,iBAAiB,EAAE,GAC9C,GAAG,IAAI,CAAC,KAAK,CAAC;IACf,MAAM,6BAA6B,GACjC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IACE,CAAC,6BAA6B;QAC9B,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAC1C;QACA,OAAO,EAAE,CAAC;KACX;IACD,OAAO,6BAA6B,CAAC;AACvC,CAAC,uIA2DgC,EAC/B,OAAO,EACP,gBAAgB,GAIjB;IACC,MAAM,EACJ,sBAAsB,EAAE,EAAE,iBAAiB,EAAE,GAC9C,GAAG,IAAI,CAAC,KAAK,CAAC;IACf,MAAM,iCAAiC,GACrC,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,OAAO,CAAC,CAAC;IAC/B,IACE,CAAC,iCAAiC;QAClC,iCAAiC,CAAC,MAAM,KAAK,CAAC,EAC9C;QACA,OAAO;KACR;IACD,MAAM,oCAAoC,GACxC,iCAAiC,CAAC,MAAM,CACtC,CAAC,gBAAkC,EAAE,EAAE,WACrC,OAAA,CAAA,MAAA,gBAAgB,CAAC,QAAQ,0CAAE,IAAI,MAAK,gBAAgB,CAAA,EAAA,CACvD,CAAC;IACJ,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,OAAO,CAAC;YACrD,oCAAoC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { hexlify } from '@ethersproject/bytes';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n query,\n safelyExecute,\n ChainId,\n isSafeDynamicKey,\n type TraceCallback,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n TransactionControllerGetNonceLockAction,\n TransactionControllerGetTransactionsAction,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport {\n MetaMetricsEventCategory,\n MetaMetricsEventName,\n SmartTransactionsTraceName,\n} from './constants';\nimport type {\n Fees,\n Hex,\n IndividualTxFees,\n SignedCanceledTransaction,\n SignedTransaction,\n SmartTransaction,\n SmartTransactionsStatus,\n UnsignedTransaction,\n MetaMetricsProps,\n FeatureFlags,\n ClientId,\n} from './types';\nimport { APIType, SmartTransactionStatuses } from './types';\nimport {\n calculateStatus,\n getAPIRequestURL,\n handleFetch,\n incrementNonceInHex,\n isSmartTransactionCancellable,\n isSmartTransactionPending,\n getTxHash,\n getSmartTransactionMetricsProperties,\n getSmartTransactionMetricsSensitiveProperties,\n shouldMarkRegularTransactionsAsFailed,\n markRegularTransactionsAsFailed,\n} from './utils';\n\nconst SECOND = 1000;\nexport const DEFAULT_INTERVAL = SECOND * 5;\nconst ETH_QUERY_ERROR_MSG =\n '`ethQuery` is not defined on SmartTransactionsController';\n\n/**\n * The name of the {@link SmartTransactionsController}\n */\nconst controllerName = 'SmartTransactionsController';\n\nconst controllerMetadata: StateMetadata<SmartTransactionsControllerState> = {\n smartTransactionsState: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\ntype FeeEstimates = {\n approvalTxFees: IndividualTxFees | null;\n tradeTxFees: IndividualTxFees | null;\n};\n\nexport type SmartTransactionsControllerState = {\n smartTransactionsState: {\n smartTransactions: Record<Hex, SmartTransaction[]>;\n userOptIn: boolean | null;\n userOptInV2: boolean | null;\n liveness: boolean | null;\n fees: FeeEstimates;\n feesByChainId: Record<Hex, FeeEstimates>;\n livenessByChainId: Record<Hex, boolean>;\n };\n};\n\n/**\n * Get the default {@link SmartTransactionsController} state.\n *\n * @returns The default {@link SmartTransactionsController} state.\n */\nexport function getDefaultSmartTransactionsControllerState(): SmartTransactionsControllerState {\n return {\n smartTransactionsState: {\n smartTransactions: {},\n userOptIn: null,\n userOptInV2: null,\n fees: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n\n // TODO: set this to false once the clients are all refreshing the liveness state.\n liveness: true,\n livenessByChainId: {\n [ChainId.mainnet]: true,\n [ChainId.sepolia]: true,\n },\n feesByChainId: {\n [ChainId.mainnet]: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n [ChainId.sepolia]: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n },\n },\n };\n}\n\nexport type SmartTransactionsControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n SmartTransactionsControllerState\n >;\n\n/**\n * The actions that can be performed using the {@link SmartTransactionsController}.\n */\nexport type SmartTransactionsControllerActions =\n SmartTransactionsControllerGetStateAction;\n\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetStateAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerUpdateTransactionAction;\n\nexport type SmartTransactionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SmartTransactionsControllerState\n >;\n\nexport type SmartTransactionsControllerSmartTransactionEvent = {\n type: 'SmartTransactionsController:smartTransaction';\n payload: [SmartTransaction];\n};\n\nexport type SmartTransactionsControllerSmartTransactionConfirmationDoneEvent = {\n type: 'SmartTransactionsController:smartTransactionConfirmationDone';\n payload: [SmartTransaction];\n};\n\n/**\n * The events that {@link SmartTransactionsController} can emit.\n */\nexport type SmartTransactionsControllerEvents =\n | SmartTransactionsControllerStateChangeEvent\n | SmartTransactionsControllerSmartTransactionEvent\n | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent;\n\ntype AllowedEvents = NetworkControllerStateChangeEvent;\n\n/**\n * The messenger of the {@link SmartTransactionsController}.\n */\nexport type SmartTransactionsControllerMessenger = Messenger<\n typeof controllerName,\n SmartTransactionsControllerActions | AllowedActions,\n SmartTransactionsControllerEvents | AllowedEvents\n>;\n\ntype SmartTransactionsControllerOptions = {\n interval?: number;\n clientId: ClientId;\n chainId?: Hex;\n supportedChainIds?: Hex[];\n trackMetaMetricsEvent: (\n event: {\n event: MetaMetricsEventName;\n category: MetaMetricsEventCategory;\n properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;\n sensitiveProperties?: ReturnType<\n typeof getSmartTransactionMetricsSensitiveProperties\n >;\n },\n options?: { metaMetricsId?: string } & Record<string, boolean>,\n ) => void;\n state?: Partial<SmartTransactionsControllerState>;\n messenger: SmartTransactionsControllerMessenger;\n getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n getFeatureFlags: () => FeatureFlags;\n trace?: TraceCallback;\n};\n\nexport type SmartTransactionsControllerPollingInput = {\n chainIds: Hex[];\n};\n\nexport class SmartTransactionsController extends StaticIntervalPollingController<SmartTransactionsControllerPollingInput>()<\n typeof controllerName,\n SmartTransactionsControllerState,\n SmartTransactionsControllerMessenger\n> {\n #interval: number;\n\n #clientId: ClientId;\n\n #chainId: Hex;\n\n #supportedChainIds: Hex[];\n\n timeoutHandle?: NodeJS.Timeout;\n\n #ethQuery: EthQuery | undefined;\n\n readonly #trackMetaMetricsEvent: SmartTransactionsControllerOptions['trackMetaMetricsEvent'];\n\n readonly #getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n\n #getFeatureFlags: SmartTransactionsControllerOptions['getFeatureFlags'];\n\n #trace: TraceCallback;\n\n /* istanbul ignore next */\n async #fetch(request: string, options?: RequestInit) {\n const fetchOptions = {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.#clientId && { 'X-Client-Id': this.#clientId }),\n },\n };\n\n return handleFetch(request, fetchOptions);\n }\n\n constructor({\n interval = DEFAULT_INTERVAL,\n clientId,\n chainId: InitialChainId = ChainId.mainnet,\n supportedChainIds = [ChainId.mainnet, ChainId.sepolia],\n trackMetaMetricsEvent,\n state = {},\n messenger,\n getMetaMetricsProps,\n getFeatureFlags,\n trace,\n }: SmartTransactionsControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: {\n ...getDefaultSmartTransactionsControllerState(),\n ...state,\n },\n });\n this.#interval = interval;\n this.#clientId = clientId;\n this.#chainId = InitialChainId;\n this.#supportedChainIds = supportedChainIds;\n this.setIntervalLength(interval);\n this.#ethQuery = undefined;\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.#getMetaMetricsProps = getMetaMetricsProps;\n this.#getFeatureFlags = getFeatureFlags;\n this.#trace = trace ?? (((_request, fn) => fn?.()) as TraceCallback);\n\n this.initializeSmartTransactionsForChainId();\n\n this.messenger.subscribe(\n 'NetworkController:stateChange',\n ({ selectedNetworkClientId }) => {\n const {\n configuration: { chainId },\n provider,\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n this.#chainId = chainId;\n this.#ethQuery = new EthQuery(provider);\n this.initializeSmartTransactionsForChainId();\n this.checkPoll(this.state);\n },\n );\n\n this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) =>\n this.checkPoll(currentState),\n );\n }\n\n async _executePoll({\n chainIds,\n }: SmartTransactionsControllerPollingInput): Promise<void> {\n // if this is going to be truly UI driven polling we shouldn't really reach here\n // with a networkClientId that is not supported, but for now I'll add a check in case\n // wondering if we should add some kind of predicate to the polling controller to check whether\n // we should poll or not\n const filteredChainIds = (chainIds ?? []).filter((chainId) =>\n this.#supportedChainIds.includes(chainId),\n );\n\n if (filteredChainIds.length === 0) {\n return Promise.resolve();\n }\n return this.updateSmartTransactions({ chainIds: filteredChainIds });\n }\n\n checkPoll({\n smartTransactionsState: { smartTransactions },\n }: SmartTransactionsControllerState) {\n const smartTransactionsForAllChains =\n Object.values(smartTransactions).flat();\n\n const pendingTransactions = smartTransactionsForAllChains?.filter(\n isSmartTransactionPending,\n );\n if (!this.timeoutHandle && pendingTransactions?.length > 0) {\n this.poll();\n } else if (this.timeoutHandle && pendingTransactions?.length === 0) {\n this.stop();\n }\n }\n\n initializeSmartTransactionsForChainId() {\n if (this.#supportedChainIds.includes(this.#chainId)) {\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[this.#chainId] =\n state.smartTransactionsState.smartTransactions[this.#chainId] ?? [];\n });\n }\n }\n\n async poll(interval?: number): Promise<void> {\n if (interval) {\n this.#interval = interval;\n }\n\n this.timeoutHandle && clearInterval(this.timeoutHandle);\n\n if (!this.#supportedChainIds.includes(this.#chainId)) {\n return;\n }\n\n this.timeoutHandle = setInterval(() => {\n safelyExecute(async () => this.updateSmartTransactions());\n }, this.#interval);\n await safelyExecute(async () => this.updateSmartTransactions());\n }\n\n async stop() {\n this.timeoutHandle && clearInterval(this.timeoutHandle);\n this.timeoutHandle = undefined;\n }\n\n setOptInState(optInState: boolean | null): void {\n this.update((state) => {\n state.smartTransactionsState.userOptInV2 = optInState;\n });\n }\n\n trackStxStatusChange(\n smartTransaction: SmartTransaction,\n prevSmartTransaction?: SmartTransaction,\n ) {\n let updatedSmartTransaction = cloneDeep(smartTransaction);\n updatedSmartTransaction = {\n ...cloneDeep(prevSmartTransaction),\n ...updatedSmartTransaction,\n };\n\n if (updatedSmartTransaction.status === prevSmartTransaction?.status) {\n return; // If status hasn't changed, don't track it again.\n }\n\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxStatusUpdated,\n category: MetaMetricsEventCategory.Transactions,\n properties: getSmartTransactionMetricsProperties(updatedSmartTransaction),\n sensitiveProperties: getSmartTransactionMetricsSensitiveProperties(\n updatedSmartTransaction,\n ),\n });\n }\n\n isNewSmartTransaction(smartTransactionUuid: string, chainId?: Hex): boolean {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions =\n smartTransactions[chainId ?? this.#chainId];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransactionUuid,\n );\n return currentIndex === -1 || currentIndex === undefined;\n }\n\n updateSmartTransaction(\n smartTransaction: SmartTransaction,\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ) {\n let ethQuery = this.#ethQuery;\n let chainId = this.#chainId;\n if (networkClientId) {\n const { configuration, provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n chainId = configuration.chainId;\n ethQuery = new EthQuery(provider);\n }\n\n this.#createOrUpdateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n #updateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n }: {\n chainId: Hex;\n },\n ) {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions = smartTransactions[chainId] ?? [];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransaction.uuid,\n );\n\n if (currentIndex === -1) {\n return; // Smart transaction not found, don't update anything.\n }\n\n if (!isSafeDynamicKey(chainId)) {\n return;\n }\n\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId][currentIndex] = {\n ...state.smartTransactionsState.smartTransactions[chainId][\n currentIndex\n ],\n ...smartTransaction,\n };\n });\n }\n\n async #addMetaMetricsPropsToNewSmartTransaction(\n smartTransaction: SmartTransaction,\n ) {\n const metaMetricsProps = await this.#getMetaMetricsProps();\n smartTransaction.accountHardwareType =\n metaMetricsProps?.accountHardwareType;\n smartTransaction.accountType = metaMetricsProps?.accountType;\n smartTransaction.deviceModel = metaMetricsProps?.deviceModel;\n }\n\n async #createOrUpdateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n ethQuery = this.#ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery | undefined;\n },\n ): Promise<void> {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions = smartTransactions[chainId] ?? [];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransaction.uuid,\n );\n const isNewSmartTransaction = this.isNewSmartTransaction(\n smartTransaction.uuid,\n chainId,\n );\n if (ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n if (isNewSmartTransaction) {\n try {\n await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);\n } catch (error) {\n console.error(\n 'Failed to add metrics props to smart transaction:',\n error,\n );\n // Continue without metrics props\n }\n }\n\n this.trackStxStatusChange(\n smartTransaction,\n isNewSmartTransaction\n ? undefined\n : currentSmartTransactions[currentIndex],\n );\n\n if (isNewSmartTransaction) {\n // add smart transaction\n const cancelledNonceIndex = currentSmartTransactions?.findIndex(\n (stx: SmartTransaction) =>\n stx.txParams?.nonce === smartTransaction.txParams?.nonce &&\n stx.status?.startsWith('cancelled'),\n );\n const snapshot = cloneDeep(smartTransaction);\n const history = [snapshot];\n const historifiedSmartTransaction = { ...smartTransaction, history };\n const nextSmartTransactions =\n cancelledNonceIndex > -1\n ? currentSmartTransactions\n .slice(0, cancelledNonceIndex)\n .concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))\n .concat(historifiedSmartTransaction)\n : currentSmartTransactions.concat(historifiedSmartTransaction);\n\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId] =\n nextSmartTransactions;\n });\n return;\n }\n\n const currentSmartTransaction = currentSmartTransactions[currentIndex];\n const nextSmartTransaction = {\n ...currentSmartTransaction,\n ...smartTransaction,\n };\n\n // We have to emit this event here, so a txHash is returned to the TransactionController once it's available.\n this.messenger.publish(\n `SmartTransactionsController:smartTransaction`,\n nextSmartTransaction,\n );\n\n if (\n shouldMarkRegularTransactionsAsFailed({\n smartTransaction: nextSmartTransaction,\n clientId: this.#clientId,\n getFeatureFlags: this.#getFeatureFlags,\n })\n ) {\n markRegularTransactionsAsFailed({\n smartTransaction: nextSmartTransaction,\n getRegularTransactions: () =>\n this.messenger.call('TransactionController:getTransactions'),\n updateTransaction: (transactionMeta: TransactionMeta, note: string) =>\n this.messenger.call(\n 'TransactionController:updateTransaction',\n transactionMeta,\n note,\n ),\n });\n }\n\n if (\n (smartTransaction.status === SmartTransactionStatuses.SUCCESS ||\n smartTransaction.status === SmartTransactionStatuses.REVERTED) &&\n !smartTransaction.confirmed\n ) {\n await this.#confirmSmartTransaction(nextSmartTransaction, {\n chainId,\n ethQuery,\n });\n } else {\n this.#updateSmartTransaction(smartTransaction, {\n chainId,\n });\n }\n }\n\n async updateSmartTransactions(\n {\n chainIds,\n }: {\n chainIds: Hex[];\n } = {\n chainIds: this.#getChainIds(),\n },\n ): Promise<void> {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n\n // Iterate over each chain group directly\n for (const [chainId, transactions] of Object.entries(smartTransactions)) {\n if (chainIds && !chainIds.includes(chainId as Hex)) {\n continue;\n }\n // Filter pending transactions and map them to the desired shape\n const pendingTransactions = transactions\n .filter(isSmartTransactionPending)\n .map((pendingSmartTransaction) => {\n // Use the transaction's chainId (from the key) to derive a networkClientId\n const networkClientIdToUse = this.#getNetworkClientId({\n chainId: chainId as Hex,\n });\n return {\n uuid: pendingSmartTransaction.uuid,\n networkClientId: networkClientIdToUse,\n chainId: pendingSmartTransaction.chainId as Hex, // same as the key, but explicit on the transaction\n };\n });\n\n if (pendingTransactions.length > 0) {\n // Since each group is per chain, all transactions share the same chainId.\n await this.fetchSmartTransactionsStatus(pendingTransactions);\n }\n }\n }\n\n async #confirmSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n ethQuery = this.#ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery | undefined;\n },\n ) {\n if (ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n const txHash = smartTransaction.statusMetadata?.minedHash;\n try {\n const transactionReceipt: {\n blockNumber: string;\n } | null = await query(ethQuery, 'getTransactionReceipt', [txHash]);\n\n if (transactionReceipt?.blockNumber) {\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxConfirmed,\n category: MetaMetricsEventCategory.Transactions,\n properties: getSmartTransactionMetricsProperties(smartTransaction),\n sensitiveProperties:\n getSmartTransactionMetricsSensitiveProperties(smartTransaction),\n });\n this.#updateSmartTransaction(\n { ...smartTransaction, confirmed: true },\n {\n chainId,\n },\n );\n }\n } catch (error) {\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxConfirmationFailed,\n category: MetaMetricsEventCategory.Transactions,\n });\n console.error('confirm error', error);\n } finally {\n this.messenger.publish(\n `SmartTransactionsController:smartTransactionConfirmationDone`,\n smartTransaction,\n );\n }\n }\n\n // ! Ask backend API to accept list of uuids as params\n async fetchSmartTransactionsStatus(\n transactions: {\n uuid: string;\n networkClientId?: NetworkClientId;\n chainId: Hex;\n }[],\n ): Promise<Record<string, SmartTransactionsStatus>> {\n // Since transactions come from the same chain group, take the chainId from the first one.\n const { chainId } = transactions[0];\n\n // Build query parameters with all UUIDs\n const uuids = transactions.map((tx) => tx.uuid);\n const params = new URLSearchParams({ uuids: uuids.join(',') });\n\n // Get the ethQuery for the first transaction's networkClientId\n const ethQuery = this.#getEthQuery({\n networkClientId: transactions[0].networkClientId,\n });\n\n // Construct the URL and fetch the data\n const url = `${getAPIRequestURL(\n APIType.BATCH_STATUS,\n chainId,\n )}?${params.toString()}`;\n const data = (await this.#fetch(url)) as Record<\n string,\n SmartTransactionsStatus\n >;\n\n // Process each returned status\n for (const [uuid, stxStatus] of Object.entries(data)) {\n const matchingTx = transactions.find((tx) => tx.uuid === uuid);\n if (!matchingTx) {\n console.error(`No matching transaction found for uuid: ${uuid}`);\n continue;\n }\n\n const smartTransaction: SmartTransaction = {\n statusMetadata: stxStatus,\n status: calculateStatus(stxStatus),\n cancellable: isSmartTransactionCancellable(stxStatus),\n uuid,\n networkClientId: matchingTx.networkClientId,\n };\n\n await this.#createOrUpdateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n return data;\n }\n\n async #addNonceToTransaction(\n transaction: UnsignedTransaction,\n networkClientId: NetworkClientId,\n ): Promise<UnsignedTransaction> {\n const nonceLock = await this.messenger.call(\n 'TransactionController:getNonceLock',\n transaction.from,\n networkClientId,\n );\n const nonce = nonceLock.nextNonce;\n nonceLock.releaseLock();\n return {\n ...transaction,\n nonce: `0x${nonce.toString(16)}`,\n };\n }\n\n clearFees(): Fees {\n const fees = {\n approvalTxFees: null,\n tradeTxFees: null,\n };\n this.update((state) => {\n state.smartTransactionsState.fees = fees;\n });\n\n return fees;\n }\n\n async getFees(\n tradeTx: UnsignedTransaction,\n approvalTx?: UnsignedTransaction,\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ): Promise<Fees> {\n const selectedNetworkClientId =\n networkClientId ??\n this.messenger.call('NetworkController:getState').selectedNetworkClientId;\n const chainId = this.#getChainId({\n networkClientId: selectedNetworkClientId,\n });\n const transactions: UnsignedTransaction[] = [];\n let unsignedTradeTransactionWithNonce;\n if (approvalTx) {\n const unsignedApprovalTransactionWithNonce =\n await this.#addNonceToTransaction(approvalTx, selectedNetworkClientId);\n transactions.push(unsignedApprovalTransactionWithNonce);\n unsignedTradeTransactionWithNonce = {\n ...tradeTx,\n // If there is an approval tx, the trade tx's nonce is increased by 1.\n nonce: incrementNonceInHex(unsignedApprovalTransactionWithNonce.nonce),\n };\n } else if (tradeTx.nonce) {\n unsignedTradeTransactionWithNonce = tradeTx;\n } else {\n unsignedTradeTransactionWithNonce = await this.#addNonceToTransaction(\n tradeTx,\n selectedNetworkClientId,\n );\n }\n transactions.push(unsignedTradeTransactionWithNonce);\n const data = await this.#trace(\n { name: SmartTransactionsTraceName.GetFees },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.GET_FEES, chainId), {\n method: 'POST',\n body: JSON.stringify({\n txs: transactions,\n }),\n }),\n );\n let approvalTxFees: IndividualTxFees | null;\n let tradeTxFees: IndividualTxFees | null;\n if (approvalTx) {\n approvalTxFees = data?.txs[0];\n tradeTxFees = data?.txs[1];\n } else {\n approvalTxFees = null;\n tradeTxFees = data?.txs[0];\n }\n\n this.update((state) => {\n if (chainId === this.#chainId) {\n state.smartTransactionsState.fees = {\n approvalTxFees,\n tradeTxFees,\n };\n }\n state.smartTransactionsState.feesByChainId[chainId] = {\n approvalTxFees,\n tradeTxFees,\n };\n });\n\n return {\n approvalTxFees,\n tradeTxFees,\n };\n }\n\n // * After this successful call client must add a nonce representative to\n // * transaction controller external transactions list\n async submitSignedTransactions({\n transactionMeta,\n txParams,\n signedTransactions,\n signedCanceledTransactions = [],\n networkClientId,\n }: {\n signedTransactions: SignedTransaction[];\n signedCanceledTransactions?: SignedCanceledTransaction[];\n transactionMeta?: TransactionMeta;\n txParams?: TransactionParams;\n networkClientId?: NetworkClientId;\n }) {\n const selectedNetworkClientId =\n networkClientId ??\n this.messenger.call('NetworkController:getState').selectedNetworkClientId;\n const chainId = this.#getChainId({\n networkClientId: selectedNetworkClientId,\n });\n const ethQuery = this.#getEthQuery({\n networkClientId: selectedNetworkClientId,\n });\n const data = await this.#trace(\n { name: SmartTransactionsTraceName.SubmitTransactions },\n async () =>\n await this.#fetch(\n getAPIRequestURL(APIType.SUBMIT_TRANSACTIONS, chainId),\n {\n method: 'POST',\n body: JSON.stringify({\n rawTxs: signedTransactions,\n rawCancelTxs: signedCanceledTransactions,\n }),\n },\n ),\n );\n const time = Date.now();\n let preTxBalance;\n try {\n if (txParams?.from) {\n const preTxBalanceBN = await query(ethQuery, 'getBalance', [\n txParams.from,\n ]);\n preTxBalance = new BigNumber(preTxBalanceBN).toString(16);\n }\n } catch (error) {\n console.error('ethQuery.getBalance error:', error);\n }\n\n const requiresNonce = txParams && !txParams.nonce;\n let nonce;\n let nonceLock;\n let nonceDetails = {};\n\n // This should only happen for Swaps. Non-swaps transactions should already have a nonce\n if (requiresNonce) {\n try {\n nonceLock = await this.messenger.call(\n 'TransactionController:getNonceLock',\n txParams.from,\n selectedNetworkClientId,\n );\n nonce = hexlify(nonceLock.nextNonce);\n nonceDetails = nonceLock.nonceDetails;\n txParams.nonce ??= nonce;\n } catch (error) {\n console.error('Failed to acquire nonce lock:', error);\n throw error;\n }\n }\n\n const txHashes = signedTransactions.map((tx) => getTxHash(tx));\n const submitTransactionResponse = {\n ...data,\n txHash: txHashes[txHashes.length - 1], // For backward compatibility - use the last tx hash\n txHashes,\n };\n\n try {\n await this.#createOrUpdateSmartTransaction(\n {\n chainId,\n nonceDetails,\n preTxBalance,\n status: SmartTransactionStatuses.PENDING,\n time,\n txParams,\n uuid: submitTransactionResponse.uuid,\n txHash: submitTransactionResponse.txHash,\n cancellable: true,\n type: transactionMeta?.type ?? 'swap',\n transactionId: transactionMeta?.id,\n networkClientId: selectedNetworkClientId,\n txHashes, // Add support for multiple transaction hashes\n },\n { chainId, ethQuery },\n );\n } catch (error) {\n console.error('Failed to create a smart transaction:', error);\n throw error;\n } finally {\n if (nonceLock) {\n nonceLock.releaseLock();\n }\n }\n\n return submitTransactionResponse;\n }\n\n #getChainId({\n networkClientId,\n }: { networkClientId?: NetworkClientId } = {}): Hex {\n if (networkClientId) {\n return this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration.chainId;\n }\n\n return this.#chainId;\n }\n\n #getChainIds(): Hex[] {\n const { networkConfigurationsByChainId } = this.messenger.call(\n 'NetworkController:getState',\n );\n return Object.keys(networkConfigurationsByChainId).filter(\n (chainId): chainId is Hex =>\n this.#supportedChainIds.includes(chainId as Hex),\n );\n }\n\n #getNetworkClientId({ chainId }: { chainId: string }): string {\n const { networkConfigurationsByChainId } = this.messenger.call(\n 'NetworkController:getState',\n );\n return networkConfigurationsByChainId[chainId as Hex].rpcEndpoints[\n networkConfigurationsByChainId[chainId as Hex].defaultRpcEndpointIndex\n ].networkClientId;\n }\n\n #getEthQuery({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): EthQuery {\n if (networkClientId) {\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return new EthQuery(provider);\n }\n\n if (this.#ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n return this.#ethQuery;\n }\n\n // TODO: This should return if the cancellation was on chain or not (for nonce management)\n // After this successful call client must update nonce representative\n // in transaction controller external transactions list\n async cancelSmartTransaction(\n uuid: string,\n {\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {},\n ): Promise<void> {\n const chainId = this.#getChainId({ networkClientId });\n await this.#trace(\n { name: SmartTransactionsTraceName.CancelTransaction },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.CANCEL, chainId), {\n method: 'POST',\n body: JSON.stringify({ uuid }),\n }),\n );\n }\n\n /**\n * Fetches the liveness status of Smart Transactions for a given chain.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID to fetch liveness for. Preferred over networkClientId.\n * @param options.networkClientId - The network client ID to derive chain ID from.\n * @returns A promise that resolves to the liveness status.\n */\n async fetchLiveness({\n networkClientId,\n chainId: chainIdArg,\n }: {\n /** @deprecated Use `chainId` instead. */\n networkClientId?: NetworkClientId;\n chainId?: Hex;\n } = {}): Promise<boolean> {\n // Use chainId directly if provided, otherwise derive from networkClientId\n const chainId = chainIdArg ?? this.#getChainId({ networkClientId });\n let liveness = false;\n try {\n const response = await this.#trace(\n { name: SmartTransactionsTraceName.FetchLiveness },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.LIVENESS, chainId)),\n );\n liveness = Boolean(response.smartTransactions);\n } catch (error) {\n console.log('\"fetchLiveness\" API call failed');\n }\n\n this.update((state) => {\n if (chainId === this.#chainId) {\n state.smartTransactionsState.liveness = liveness;\n }\n state.smartTransactionsState.livenessByChainId[chainId] = liveness;\n });\n\n return liveness;\n }\n\n async setStatusRefreshInterval(interval: number): Promise<void> {\n if (interval !== this.#interval) {\n this.#interval = interval;\n }\n }\n\n #getCurrentSmartTransactions(): SmartTransaction[] {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const smartTransactionsForAllChains =\n Object.values(smartTransactions).flat();\n if (\n !smartTransactionsForAllChains ||\n smartTransactionsForAllChains.length === 0\n ) {\n return [];\n }\n return smartTransactionsForAllChains;\n }\n\n getTransactions({\n addressFrom,\n status,\n }: {\n addressFrom: string;\n status: SmartTransactionStatuses;\n }): SmartTransaction[] {\n const currentSmartTransactions = this.#getCurrentSmartTransactions();\n return currentSmartTransactions.filter((stx) => {\n return stx.status === status && stx.txParams?.from === addressFrom;\n });\n }\n\n getSmartTransactionByMinedTxHash(\n txHash: string | undefined,\n ): SmartTransaction | undefined {\n if (!txHash) {\n return undefined;\n }\n const currentSmartTransactions = this.#getCurrentSmartTransactions();\n return currentSmartTransactions.find((smartTransaction) => {\n return (\n smartTransaction.statusMetadata?.minedHash?.toLowerCase() ===\n txHash.toLowerCase()\n );\n });\n }\n\n wipeSmartTransactions({\n address,\n ignoreNetwork,\n }: {\n address: string;\n ignoreNetwork?: boolean;\n }): void {\n if (!address) {\n return;\n }\n const addressLowerCase = address.toLowerCase();\n if (ignoreNetwork) {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n (Object.keys(smartTransactions) as Hex[]).forEach((chainId) => {\n this.#wipeSmartTransactionsPerChainId({\n chainId,\n addressLowerCase,\n });\n });\n } else {\n this.#wipeSmartTransactionsPerChainId({\n chainId: this.#chainId,\n addressLowerCase,\n });\n }\n }\n\n #wipeSmartTransactionsPerChainId({\n chainId,\n addressLowerCase,\n }: {\n chainId: Hex;\n addressLowerCase: string;\n }): void {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const smartTransactionsForSelectedChain: SmartTransaction[] =\n smartTransactions?.[chainId];\n if (\n !smartTransactionsForSelectedChain ||\n smartTransactionsForSelectedChain.length === 0\n ) {\n return;\n }\n const newSmartTransactionsForSelectedChain =\n smartTransactionsForSelectedChain.filter(\n (smartTransaction: SmartTransaction) =>\n smartTransaction.txParams?.from !== addressLowerCase,\n );\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId] =\n newSmartTransactionsForSelectedChain;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SmartTransactionsController.cjs","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAA+C;AAM/C,iEAMoC;AAEpC,oEAA2C;AAQ3C,qEAA+E;AAa/E,+CAAyC;AACzC,oEAAyC;AAEzC,+CAKqB;AACrB,oEAGsC;AACtC,8DAAkF;AAalF,uCAA4D;AAC5D,uCAYiB;AAEjB,MAAM,MAAM,GAAG,IAAI,CAAC;AACP,QAAA,gBAAgB,GAAG,MAAM,GAAG,CAAC,CAAC;AAC3C,MAAM,mBAAmB,GACvB,0DAA0D,CAAC;AAE7D;;GAEG;AACH,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,kBAAkB,GAAoD;IAC1E,sBAAsB,EAAE;QACtB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAmBF;;;;GAIG;AACH,SAAgB,0CAA0C;IACxD,OAAO;QACL,sBAAsB,EAAE;YACtB,iBAAiB,EAAE,EAAE;YACrB,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE;gBACJ,cAAc,EAAE,IAAI;gBACpB,WAAW,EAAE,IAAI;aAClB;YAED,kFAAkF;YAClF,QAAQ,EAAE,IAAI;YACd,iBAAiB,EAAE;gBACjB,CAAC,0BAAO,CAAC,OAAO,CAAC,EAAE,IAAI;gBACvB,CAAC,0BAAO,CAAC,OAAO,CAAC,EAAE,IAAI;aACxB;YACD,aAAa,EAAE;gBACb,CAAC,0BAAO,CAAC,OAAO,CAAC,EAAE;oBACjB,cAAc,EAAE,IAAI;oBACpB,WAAW,EAAE,IAAI;iBAClB;gBACD,CAAC,0BAAO,CAAC,OAAO,CAAC,EAAE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from '@ethersproject/bytes';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n query,\n safelyExecute,\n ChainId,\n isSafeDynamicKey,\n type TraceCallback,\n} from '@metamask/controller-utils';\nimport type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\nimport EthQuery from '@metamask/eth-query';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n RemoteFeatureFlagControllerGetStateAction,\n RemoteFeatureFlagControllerStateChangeEvent,\n} from '@metamask/remote-feature-flag-controller';\nimport type {\n TransactionControllerGetNonceLockAction,\n TransactionControllerGetTransactionsAction,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport {\n DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS,\n MetaMetricsEventCategory,\n MetaMetricsEventName,\n SmartTransactionsTraceName,\n} from './constants';\nimport {\n getSmartTransactionsFeatureFlags,\n getSmartTransactionsFeatureFlagsForChain,\n} from './featureFlags/feature-flags';\nimport { validateSmartTransactionsFeatureFlags } from './featureFlags/validators';\nimport type {\n Fees,\n IndividualTxFees,\n SignedCanceledTransaction,\n SignedTransaction,\n SmartTransaction,\n SmartTransactionsStatus,\n UnsignedTransaction,\n MetaMetricsProps,\n FeatureFlags,\n ClientId,\n} from './types';\nimport { APIType, SmartTransactionStatuses } from './types';\nimport {\n calculateStatus,\n getAPIRequestURL,\n handleFetch,\n incrementNonceInHex,\n isSmartTransactionCancellable,\n isSmartTransactionPending,\n getTxHash,\n getSmartTransactionMetricsProperties,\n getSmartTransactionMetricsSensitiveProperties,\n shouldMarkRegularTransactionsAsFailed,\n markRegularTransactionsAsFailed,\n} from './utils';\n\nconst SECOND = 1000;\nexport const DEFAULT_INTERVAL = SECOND * 5;\nconst ETH_QUERY_ERROR_MSG =\n '`ethQuery` is not defined on SmartTransactionsController';\n\n/**\n * The name of the {@link SmartTransactionsController}\n */\nconst controllerName = 'SmartTransactionsController';\n\nconst controllerMetadata: StateMetadata<SmartTransactionsControllerState> = {\n smartTransactionsState: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\ntype FeeEstimates = {\n approvalTxFees: IndividualTxFees | null;\n tradeTxFees: IndividualTxFees | null;\n};\n\nexport type SmartTransactionsControllerState = {\n smartTransactionsState: {\n smartTransactions: Record<Hex, SmartTransaction[]>;\n userOptIn: boolean | null;\n userOptInV2: boolean | null;\n liveness: boolean | null;\n fees: FeeEstimates;\n feesByChainId: Record<Hex, FeeEstimates>;\n livenessByChainId: Record<Hex, boolean>;\n };\n};\n\n/**\n * Get the default {@link SmartTransactionsController} state.\n *\n * @returns The default {@link SmartTransactionsController} state.\n */\nexport function getDefaultSmartTransactionsControllerState(): SmartTransactionsControllerState {\n return {\n smartTransactionsState: {\n smartTransactions: {},\n userOptIn: null,\n userOptInV2: null,\n fees: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n\n // TODO: set this to false once the clients are all refreshing the liveness state.\n liveness: true,\n livenessByChainId: {\n [ChainId.mainnet]: true,\n [ChainId.sepolia]: true,\n },\n feesByChainId: {\n [ChainId.mainnet]: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n [ChainId.sepolia]: {\n approvalTxFees: null,\n tradeTxFees: null,\n },\n },\n },\n };\n}\n\nexport type SmartTransactionsControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n SmartTransactionsControllerState\n >;\n\n/**\n * The actions that can be performed using the {@link SmartTransactionsController}.\n */\nexport type SmartTransactionsControllerActions =\n SmartTransactionsControllerGetStateAction;\n\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetStateAction\n | RemoteFeatureFlagControllerGetStateAction\n | TransactionControllerGetNonceLockAction\n | TransactionControllerGetTransactionsAction\n | TransactionControllerUpdateTransactionAction\n | ErrorReportingServiceCaptureExceptionAction;\n\nexport type SmartTransactionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SmartTransactionsControllerState\n >;\n\nexport type SmartTransactionsControllerSmartTransactionEvent = {\n type: 'SmartTransactionsController:smartTransaction';\n payload: [SmartTransaction];\n};\n\nexport type SmartTransactionsControllerSmartTransactionConfirmationDoneEvent = {\n type: 'SmartTransactionsController:smartTransactionConfirmationDone';\n payload: [SmartTransaction];\n};\n\n/**\n * The events that {@link SmartTransactionsController} can emit.\n */\nexport type SmartTransactionsControllerEvents =\n | SmartTransactionsControllerStateChangeEvent\n | SmartTransactionsControllerSmartTransactionEvent\n | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent;\n\ntype AllowedEvents =\n | NetworkControllerStateChangeEvent\n | RemoteFeatureFlagControllerStateChangeEvent;\n\n/**\n * The messenger of the {@link SmartTransactionsController}.\n */\nexport type SmartTransactionsControllerMessenger = Messenger<\n typeof controllerName,\n SmartTransactionsControllerActions | AllowedActions,\n SmartTransactionsControllerEvents | AllowedEvents\n>;\n\ntype SmartTransactionsControllerOptions = {\n interval?: number;\n clientId: ClientId;\n chainId?: Hex;\n supportedChainIds?: Hex[];\n trackMetaMetricsEvent: (\n event: {\n event: MetaMetricsEventName;\n category: MetaMetricsEventCategory;\n properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;\n sensitiveProperties?: ReturnType<\n typeof getSmartTransactionMetricsSensitiveProperties\n >;\n },\n options?: { metaMetricsId?: string } & Record<string, boolean>,\n ) => void;\n state?: Partial<SmartTransactionsControllerState>;\n messenger: SmartTransactionsControllerMessenger;\n getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n /**\n * @deprecated This option is ignored. Feature flags are now read directly\n * from RemoteFeatureFlagController via the messenger. This option will be\n * removed in a future version.\n */\n getFeatureFlags?: () => FeatureFlags;\n trace?: TraceCallback;\n};\n\nexport type SmartTransactionsControllerPollingInput = {\n chainIds: Hex[];\n};\n\nexport class SmartTransactionsController extends StaticIntervalPollingController<SmartTransactionsControllerPollingInput>()<\n typeof controllerName,\n SmartTransactionsControllerState,\n SmartTransactionsControllerMessenger\n> {\n #interval: number;\n\n #clientId: ClientId;\n\n #chainId: Hex;\n\n #supportedChainIds: Hex[];\n\n timeoutHandle?: NodeJS.Timeout;\n\n #ethQuery: EthQuery | undefined;\n\n readonly #trackMetaMetricsEvent: SmartTransactionsControllerOptions['trackMetaMetricsEvent'];\n\n readonly #getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n\n #trace: TraceCallback;\n\n /**\n * Validates the smart transactions feature flags from the remote feature flag controller\n * and reports any validation errors to Sentry via ErrorReportingService.\n * Does not report errors when flags are undefined (not yet fetched).\n */\n #validateAndReportFeatureFlags(): void {\n const remoteFeatureFlagControllerState = this.messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n const rawFlags =\n remoteFeatureFlagControllerState?.remoteFeatureFlags\n ?.smartTransactionsNetworks;\n\n const { errors } = validateSmartTransactionsFeatureFlags(rawFlags);\n\n // Report each validation error to Sentry\n for (const error of errors) {\n this.messenger.call(\n 'ErrorReportingService:captureException',\n new Error(\n `[SmartTransactionsController] Feature flag validation failed: ${\n error.message\n }. Please check the SmartTransactionNetworks feature flag in Remote Config. Smart transactions are disabled for this network. Default disabled config: ${JSON.stringify(\n DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default,\n )}`,\n ),\n );\n }\n }\n\n /* istanbul ignore next */\n async #fetch(request: string, options?: RequestInit) {\n const fetchOptions = {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.#clientId && { 'X-Client-Id': this.#clientId }),\n },\n };\n\n return handleFetch(request, fetchOptions);\n }\n\n constructor({\n interval = DEFAULT_INTERVAL,\n clientId,\n chainId: InitialChainId = ChainId.mainnet,\n supportedChainIds = [ChainId.mainnet, ChainId.sepolia],\n trackMetaMetricsEvent,\n state = {},\n messenger,\n getMetaMetricsProps,\n trace,\n }: SmartTransactionsControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: {\n ...getDefaultSmartTransactionsControllerState(),\n ...state,\n },\n });\n this.#interval = interval;\n this.#clientId = clientId;\n this.#chainId = InitialChainId;\n this.#supportedChainIds = supportedChainIds;\n this.setIntervalLength(interval);\n this.#ethQuery = undefined;\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.#getMetaMetricsProps = getMetaMetricsProps;\n this.#trace = trace ?? (((_request, fn) => fn?.()) as TraceCallback);\n\n this.initializeSmartTransactionsForChainId();\n\n this.messenger.subscribe(\n 'NetworkController:stateChange',\n ({ selectedNetworkClientId }) => {\n const {\n configuration: { chainId },\n provider,\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n this.#chainId = chainId;\n this.#ethQuery = new EthQuery(provider);\n this.initializeSmartTransactionsForChainId();\n this.checkPoll(this.state);\n },\n );\n\n this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) =>\n this.checkPoll(currentState),\n );\n\n // Validate feature flags on changes\n this.messenger.subscribe('RemoteFeatureFlagController:stateChange', () => {\n this.#validateAndReportFeatureFlags();\n });\n }\n\n async _executePoll({\n chainIds,\n }: SmartTransactionsControllerPollingInput): Promise<void> {\n // if this is going to be truly UI driven polling we shouldn't really reach here\n // with a networkClientId that is not supported, but for now I'll add a check in case\n // wondering if we should add some kind of predicate to the polling controller to check whether\n // we should poll or not\n const filteredChainIds = (chainIds ?? []).filter((chainId) =>\n this.#supportedChainIds.includes(chainId),\n );\n\n if (filteredChainIds.length === 0) {\n return Promise.resolve();\n }\n return this.updateSmartTransactions({ chainIds: filteredChainIds });\n }\n\n checkPoll({\n smartTransactionsState: { smartTransactions },\n }: SmartTransactionsControllerState) {\n const smartTransactionsForAllChains =\n Object.values(smartTransactions).flat();\n\n const pendingTransactions = smartTransactionsForAllChains?.filter(\n isSmartTransactionPending,\n );\n if (!this.timeoutHandle && pendingTransactions?.length > 0) {\n this.poll();\n } else if (this.timeoutHandle && pendingTransactions?.length === 0) {\n this.stop();\n }\n }\n\n initializeSmartTransactionsForChainId() {\n if (this.#supportedChainIds.includes(this.#chainId)) {\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[this.#chainId] =\n state.smartTransactionsState.smartTransactions[this.#chainId] ?? [];\n });\n }\n }\n\n async poll(interval?: number): Promise<void> {\n if (interval) {\n this.#interval = interval;\n }\n\n this.timeoutHandle && clearInterval(this.timeoutHandle);\n\n if (!this.#supportedChainIds.includes(this.#chainId)) {\n return;\n }\n\n this.timeoutHandle = setInterval(() => {\n safelyExecute(async () => this.updateSmartTransactions());\n }, this.#interval);\n await safelyExecute(async () => this.updateSmartTransactions());\n }\n\n async stop() {\n this.timeoutHandle && clearInterval(this.timeoutHandle);\n this.timeoutHandle = undefined;\n }\n\n setOptInState(optInState: boolean | null): void {\n this.update((state) => {\n state.smartTransactionsState.userOptInV2 = optInState;\n });\n }\n\n trackStxStatusChange(\n smartTransaction: SmartTransaction,\n prevSmartTransaction?: SmartTransaction,\n ) {\n let updatedSmartTransaction = cloneDeep(smartTransaction);\n updatedSmartTransaction = {\n ...cloneDeep(prevSmartTransaction),\n ...updatedSmartTransaction,\n };\n\n if (updatedSmartTransaction.status === prevSmartTransaction?.status) {\n return; // If status hasn't changed, don't track it again.\n }\n\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxStatusUpdated,\n category: MetaMetricsEventCategory.Transactions,\n properties: getSmartTransactionMetricsProperties(updatedSmartTransaction),\n sensitiveProperties: getSmartTransactionMetricsSensitiveProperties(\n updatedSmartTransaction,\n ),\n });\n }\n\n isNewSmartTransaction(smartTransactionUuid: string, chainId?: Hex): boolean {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions =\n smartTransactions[chainId ?? this.#chainId];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransactionUuid,\n );\n return currentIndex === -1 || currentIndex === undefined;\n }\n\n updateSmartTransaction(\n smartTransaction: SmartTransaction,\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ) {\n let ethQuery = this.#ethQuery;\n let chainId = this.#chainId;\n if (networkClientId) {\n const { configuration, provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n chainId = configuration.chainId;\n ethQuery = new EthQuery(provider);\n }\n\n this.#createOrUpdateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n #updateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n }: {\n chainId: Hex;\n },\n ) {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions = smartTransactions[chainId] ?? [];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransaction.uuid,\n );\n\n if (currentIndex === -1) {\n return; // Smart transaction not found, don't update anything.\n }\n\n if (!isSafeDynamicKey(chainId)) {\n return;\n }\n\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId][currentIndex] = {\n ...state.smartTransactionsState.smartTransactions[chainId][\n currentIndex\n ],\n ...smartTransaction,\n };\n });\n }\n\n async #addMetaMetricsPropsToNewSmartTransaction(\n smartTransaction: SmartTransaction,\n ) {\n const metaMetricsProps = await this.#getMetaMetricsProps();\n smartTransaction.accountHardwareType =\n metaMetricsProps?.accountHardwareType;\n smartTransaction.accountType = metaMetricsProps?.accountType;\n smartTransaction.deviceModel = metaMetricsProps?.deviceModel;\n }\n\n async #createOrUpdateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n ethQuery = this.#ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery | undefined;\n },\n ): Promise<void> {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions = smartTransactions[chainId] ?? [];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransaction.uuid,\n );\n const isNewSmartTransaction = this.isNewSmartTransaction(\n smartTransaction.uuid,\n chainId,\n );\n if (ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n if (isNewSmartTransaction) {\n try {\n await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);\n } catch (error) {\n console.error(\n 'Failed to add metrics props to smart transaction:',\n error,\n );\n // Continue without metrics props\n }\n }\n\n this.trackStxStatusChange(\n smartTransaction,\n isNewSmartTransaction\n ? undefined\n : currentSmartTransactions[currentIndex],\n );\n\n if (isNewSmartTransaction) {\n // add smart transaction\n const cancelledNonceIndex = currentSmartTransactions?.findIndex(\n (stx: SmartTransaction) =>\n stx.txParams?.nonce === smartTransaction.txParams?.nonce &&\n stx.status?.startsWith('cancelled'),\n );\n const snapshot = cloneDeep(smartTransaction);\n const history = [snapshot];\n const historifiedSmartTransaction = { ...smartTransaction, history };\n const nextSmartTransactions =\n cancelledNonceIndex > -1\n ? currentSmartTransactions\n .slice(0, cancelledNonceIndex)\n .concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))\n .concat(historifiedSmartTransaction)\n : currentSmartTransactions.concat(historifiedSmartTransaction);\n\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId] =\n nextSmartTransactions;\n });\n return;\n }\n\n const currentSmartTransaction = currentSmartTransactions[currentIndex];\n const nextSmartTransaction = {\n ...currentSmartTransaction,\n ...smartTransaction,\n };\n\n // We have to emit this event here, so a txHash is returned to the TransactionController once it's available.\n this.messenger.publish(\n `SmartTransactionsController:smartTransaction`,\n nextSmartTransaction,\n );\n\n const featureFlags = getSmartTransactionsFeatureFlagsForChain(\n getSmartTransactionsFeatureFlags(this.messenger),\n chainId,\n );\n\n if (\n shouldMarkRegularTransactionsAsFailed({\n smartTransaction: nextSmartTransaction,\n clientId: this.#clientId,\n featureFlags,\n })\n ) {\n markRegularTransactionsAsFailed({\n smartTransaction: nextSmartTransaction,\n getRegularTransactions: () =>\n this.messenger.call('TransactionController:getTransactions'),\n updateTransaction: (transactionMeta: TransactionMeta, note: string) =>\n this.messenger.call(\n 'TransactionController:updateTransaction',\n transactionMeta,\n note,\n ),\n });\n }\n\n if (\n (smartTransaction.status === SmartTransactionStatuses.SUCCESS ||\n smartTransaction.status === SmartTransactionStatuses.REVERTED) &&\n !smartTransaction.confirmed\n ) {\n await this.#confirmSmartTransaction(nextSmartTransaction, {\n chainId,\n ethQuery,\n });\n } else {\n this.#updateSmartTransaction(smartTransaction, {\n chainId,\n });\n }\n }\n\n async updateSmartTransactions(\n {\n chainIds,\n }: {\n chainIds: Hex[];\n } = {\n chainIds: this.#getChainIds(),\n },\n ): Promise<void> {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n\n // Iterate over each chain group directly\n for (const [chainId, transactions] of Object.entries(smartTransactions)) {\n if (chainIds && !chainIds.includes(chainId as Hex)) {\n continue;\n }\n // Filter pending transactions and map them to the desired shape\n const pendingTransactions = transactions\n .filter(isSmartTransactionPending)\n .map((pendingSmartTransaction) => {\n // Use the transaction's chainId (from the key) to derive a networkClientId\n const networkClientIdToUse = this.#getNetworkClientId({\n chainId: chainId as Hex,\n });\n return {\n uuid: pendingSmartTransaction.uuid,\n networkClientId: networkClientIdToUse,\n chainId: pendingSmartTransaction.chainId as Hex, // same as the key, but explicit on the transaction\n };\n });\n\n if (pendingTransactions.length > 0) {\n // Since each group is per chain, all transactions share the same chainId.\n await this.fetchSmartTransactionsStatus(pendingTransactions);\n }\n }\n }\n\n async #confirmSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.#chainId,\n ethQuery = this.#ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery | undefined;\n },\n ) {\n if (ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n const txHash = smartTransaction.statusMetadata?.minedHash;\n try {\n const transactionReceipt: {\n blockNumber: string;\n } | null = await query(ethQuery, 'getTransactionReceipt', [txHash]);\n\n if (transactionReceipt?.blockNumber) {\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxConfirmed,\n category: MetaMetricsEventCategory.Transactions,\n properties: getSmartTransactionMetricsProperties(smartTransaction),\n sensitiveProperties:\n getSmartTransactionMetricsSensitiveProperties(smartTransaction),\n });\n this.#updateSmartTransaction(\n { ...smartTransaction, confirmed: true },\n {\n chainId,\n },\n );\n }\n } catch (error) {\n this.#trackMetaMetricsEvent({\n event: MetaMetricsEventName.StxConfirmationFailed,\n category: MetaMetricsEventCategory.Transactions,\n });\n console.error('confirm error', error);\n } finally {\n this.messenger.publish(\n `SmartTransactionsController:smartTransactionConfirmationDone`,\n smartTransaction,\n );\n }\n }\n\n // ! Ask backend API to accept list of uuids as params\n async fetchSmartTransactionsStatus(\n transactions: {\n uuid: string;\n networkClientId?: NetworkClientId;\n chainId: Hex;\n }[],\n ): Promise<Record<string, SmartTransactionsStatus>> {\n // Since transactions come from the same chain group, take the chainId from the first one.\n const { chainId } = transactions[0];\n\n // Build query parameters with all UUIDs\n const uuids = transactions.map((tx) => tx.uuid);\n const params = new URLSearchParams({ uuids: uuids.join(',') });\n\n // Get the ethQuery for the first transaction's networkClientId\n const ethQuery = this.#getEthQuery({\n networkClientId: transactions[0].networkClientId,\n });\n\n // Construct the URL and fetch the data\n const url = `${getAPIRequestURL(\n APIType.BATCH_STATUS,\n chainId,\n )}?${params.toString()}`;\n const data = (await this.#fetch(url)) as Record<\n string,\n SmartTransactionsStatus\n >;\n\n // Process each returned status\n for (const [uuid, stxStatus] of Object.entries(data)) {\n const matchingTx = transactions.find((tx) => tx.uuid === uuid);\n if (!matchingTx) {\n console.error(`No matching transaction found for uuid: ${uuid}`);\n continue;\n }\n\n const smartTransaction: SmartTransaction = {\n statusMetadata: stxStatus,\n status: calculateStatus(stxStatus),\n cancellable: isSmartTransactionCancellable(stxStatus),\n uuid,\n networkClientId: matchingTx.networkClientId,\n };\n\n await this.#createOrUpdateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n return data;\n }\n\n async #addNonceToTransaction(\n transaction: UnsignedTransaction,\n networkClientId: NetworkClientId,\n ): Promise<UnsignedTransaction> {\n const nonceLock = await this.messenger.call(\n 'TransactionController:getNonceLock',\n transaction.from,\n networkClientId,\n );\n const nonce = nonceLock.nextNonce;\n nonceLock.releaseLock();\n return {\n ...transaction,\n nonce: `0x${nonce.toString(16)}`,\n };\n }\n\n clearFees(): Fees {\n const fees = {\n approvalTxFees: null,\n tradeTxFees: null,\n };\n this.update((state) => {\n state.smartTransactionsState.fees = fees;\n });\n\n return fees;\n }\n\n async getFees(\n tradeTx: UnsignedTransaction,\n approvalTx?: UnsignedTransaction,\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ): Promise<Fees> {\n const selectedNetworkClientId =\n networkClientId ??\n this.messenger.call('NetworkController:getState').selectedNetworkClientId;\n const chainId = this.#getChainId({\n networkClientId: selectedNetworkClientId,\n });\n const transactions: UnsignedTransaction[] = [];\n let unsignedTradeTransactionWithNonce;\n if (approvalTx) {\n const unsignedApprovalTransactionWithNonce =\n await this.#addNonceToTransaction(approvalTx, selectedNetworkClientId);\n transactions.push(unsignedApprovalTransactionWithNonce);\n unsignedTradeTransactionWithNonce = {\n ...tradeTx,\n // If there is an approval tx, the trade tx's nonce is increased by 1.\n nonce: incrementNonceInHex(unsignedApprovalTransactionWithNonce.nonce),\n };\n } else if (tradeTx.nonce) {\n unsignedTradeTransactionWithNonce = tradeTx;\n } else {\n unsignedTradeTransactionWithNonce = await this.#addNonceToTransaction(\n tradeTx,\n selectedNetworkClientId,\n );\n }\n transactions.push(unsignedTradeTransactionWithNonce);\n const data = await this.#trace(\n { name: SmartTransactionsTraceName.GetFees },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.GET_FEES, chainId), {\n method: 'POST',\n body: JSON.stringify({\n txs: transactions,\n }),\n }),\n );\n let approvalTxFees: IndividualTxFees | null;\n let tradeTxFees: IndividualTxFees | null;\n if (approvalTx) {\n approvalTxFees = data?.txs[0];\n tradeTxFees = data?.txs[1];\n } else {\n approvalTxFees = null;\n tradeTxFees = data?.txs[0];\n }\n\n this.update((state) => {\n if (chainId === this.#chainId) {\n state.smartTransactionsState.fees = {\n approvalTxFees,\n tradeTxFees,\n };\n }\n state.smartTransactionsState.feesByChainId[chainId] = {\n approvalTxFees,\n tradeTxFees,\n };\n });\n\n return {\n approvalTxFees,\n tradeTxFees,\n };\n }\n\n // * After this successful call client must add a nonce representative to\n // * transaction controller external transactions list\n async submitSignedTransactions({\n transactionMeta,\n txParams,\n signedTransactions,\n signedCanceledTransactions = [],\n networkClientId,\n }: {\n signedTransactions: SignedTransaction[];\n signedCanceledTransactions?: SignedCanceledTransaction[];\n transactionMeta?: TransactionMeta;\n txParams?: TransactionParams;\n networkClientId?: NetworkClientId;\n }) {\n const selectedNetworkClientId =\n networkClientId ??\n this.messenger.call('NetworkController:getState').selectedNetworkClientId;\n const chainId = this.#getChainId({\n networkClientId: selectedNetworkClientId,\n });\n const ethQuery = this.#getEthQuery({\n networkClientId: selectedNetworkClientId,\n });\n const data = await this.#trace(\n { name: SmartTransactionsTraceName.SubmitTransactions },\n async () =>\n await this.#fetch(\n getAPIRequestURL(APIType.SUBMIT_TRANSACTIONS, chainId),\n {\n method: 'POST',\n body: JSON.stringify({\n rawTxs: signedTransactions,\n rawCancelTxs: signedCanceledTransactions,\n }),\n },\n ),\n );\n const time = Date.now();\n let preTxBalance;\n try {\n if (txParams?.from) {\n const preTxBalanceBN = await query(ethQuery, 'getBalance', [\n txParams.from,\n ]);\n preTxBalance = new BigNumber(preTxBalanceBN).toString(16);\n }\n } catch (error) {\n console.error('ethQuery.getBalance error:', error);\n }\n\n const requiresNonce = txParams && !txParams.nonce;\n let nonce;\n let nonceLock;\n let nonceDetails = {};\n\n // This should only happen for Swaps. Non-swaps transactions should already have a nonce\n if (requiresNonce) {\n try {\n nonceLock = await this.messenger.call(\n 'TransactionController:getNonceLock',\n txParams.from,\n selectedNetworkClientId,\n );\n nonce = hexlify(nonceLock.nextNonce);\n nonceDetails = nonceLock.nonceDetails;\n txParams.nonce ??= nonce;\n } catch (error) {\n console.error('Failed to acquire nonce lock:', error);\n throw error;\n }\n }\n\n const txHashes = signedTransactions.map((tx) => getTxHash(tx));\n const submitTransactionResponse = {\n ...data,\n txHash: txHashes[txHashes.length - 1], // For backward compatibility - use the last tx hash\n txHashes,\n };\n\n try {\n await this.#createOrUpdateSmartTransaction(\n {\n chainId,\n nonceDetails,\n preTxBalance,\n status: SmartTransactionStatuses.PENDING,\n time,\n txParams,\n uuid: submitTransactionResponse.uuid,\n txHash: submitTransactionResponse.txHash,\n cancellable: true,\n type: transactionMeta?.type ?? 'swap',\n transactionId: transactionMeta?.id,\n networkClientId: selectedNetworkClientId,\n txHashes, // Add support for multiple transaction hashes\n },\n { chainId, ethQuery },\n );\n } catch (error) {\n console.error('Failed to create a smart transaction:', error);\n throw error;\n } finally {\n if (nonceLock) {\n nonceLock.releaseLock();\n }\n }\n\n return submitTransactionResponse;\n }\n\n #getChainId({\n networkClientId,\n }: { networkClientId?: NetworkClientId } = {}): Hex {\n if (networkClientId) {\n return this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration.chainId;\n }\n\n return this.#chainId;\n }\n\n #getChainIds(): Hex[] {\n const { networkConfigurationsByChainId } = this.messenger.call(\n 'NetworkController:getState',\n );\n return Object.keys(networkConfigurationsByChainId).filter(\n (chainId): chainId is Hex =>\n this.#supportedChainIds.includes(chainId as Hex),\n );\n }\n\n #getNetworkClientId({ chainId }: { chainId: string }): string {\n const { networkConfigurationsByChainId } = this.messenger.call(\n 'NetworkController:getState',\n );\n return networkConfigurationsByChainId[chainId as Hex].rpcEndpoints[\n networkConfigurationsByChainId[chainId as Hex].defaultRpcEndpointIndex\n ].networkClientId;\n }\n\n #getEthQuery({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): EthQuery {\n if (networkClientId) {\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return new EthQuery(provider);\n }\n\n if (this.#ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n return this.#ethQuery;\n }\n\n // TODO: This should return if the cancellation was on chain or not (for nonce management)\n // After this successful call client must update nonce representative\n // in transaction controller external transactions list\n async cancelSmartTransaction(\n uuid: string,\n {\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {},\n ): Promise<void> {\n const chainId = this.#getChainId({ networkClientId });\n await this.#trace(\n { name: SmartTransactionsTraceName.CancelTransaction },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.CANCEL, chainId), {\n method: 'POST',\n body: JSON.stringify({ uuid }),\n }),\n );\n }\n\n /**\n * Fetches the liveness status of Smart Transactions for a given chain.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID to fetch liveness for. Preferred over networkClientId.\n * @param options.networkClientId - The network client ID to derive chain ID from.\n * @returns A promise that resolves to the liveness status.\n */\n async fetchLiveness({\n networkClientId,\n chainId: chainIdArg,\n }: {\n /** @deprecated Use `chainId` instead. */\n networkClientId?: NetworkClientId;\n chainId?: Hex;\n } = {}): Promise<boolean> {\n // Use chainId directly if provided, otherwise derive from networkClientId\n const chainId = chainIdArg ?? this.#getChainId({ networkClientId });\n let liveness = false;\n try {\n const response = await this.#trace(\n { name: SmartTransactionsTraceName.FetchLiveness },\n async () =>\n await this.#fetch(getAPIRequestURL(APIType.LIVENESS, chainId)),\n );\n liveness = Boolean(response.smartTransactions);\n } catch (error) {\n console.log('\"fetchLiveness\" API call failed');\n }\n\n this.update((state) => {\n if (chainId === this.#chainId) {\n state.smartTransactionsState.liveness = liveness;\n }\n state.smartTransactionsState.livenessByChainId[chainId] = liveness;\n });\n\n return liveness;\n }\n\n async setStatusRefreshInterval(interval: number): Promise<void> {\n if (interval !== this.#interval) {\n this.#interval = interval;\n }\n }\n\n #getCurrentSmartTransactions(): SmartTransaction[] {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const smartTransactionsForAllChains =\n Object.values(smartTransactions).flat();\n if (\n !smartTransactionsForAllChains ||\n smartTransactionsForAllChains.length === 0\n ) {\n return [];\n }\n return smartTransactionsForAllChains;\n }\n\n getTransactions({\n addressFrom,\n status,\n }: {\n addressFrom: string;\n status: SmartTransactionStatuses;\n }): SmartTransaction[] {\n const currentSmartTransactions = this.#getCurrentSmartTransactions();\n return currentSmartTransactions.filter((stx) => {\n return stx.status === status && stx.txParams?.from === addressFrom;\n });\n }\n\n getSmartTransactionByMinedTxHash(\n txHash: string | undefined,\n ): SmartTransaction | undefined {\n if (!txHash) {\n return undefined;\n }\n const currentSmartTransactions = this.#getCurrentSmartTransactions();\n return currentSmartTransactions.find((smartTransaction) => {\n return (\n smartTransaction.statusMetadata?.minedHash?.toLowerCase() ===\n txHash.toLowerCase()\n );\n });\n }\n\n wipeSmartTransactions({\n address,\n ignoreNetwork,\n }: {\n address: string;\n ignoreNetwork?: boolean;\n }): void {\n if (!address) {\n return;\n }\n const addressLowerCase = address.toLowerCase();\n if (ignoreNetwork) {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n (Object.keys(smartTransactions) as Hex[]).forEach((chainId) => {\n this.#wipeSmartTransactionsPerChainId({\n chainId,\n addressLowerCase,\n });\n });\n } else {\n this.#wipeSmartTransactionsPerChainId({\n chainId: this.#chainId,\n addressLowerCase,\n });\n }\n }\n\n #wipeSmartTransactionsPerChainId({\n chainId,\n addressLowerCase,\n }: {\n chainId: Hex;\n addressLowerCase: string;\n }): void {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const smartTransactionsForSelectedChain: SmartTransaction[] =\n smartTransactions?.[chainId];\n if (\n !smartTransactionsForSelectedChain ||\n smartTransactionsForSelectedChain.length === 0\n ) {\n return;\n }\n const newSmartTransactionsForSelectedChain =\n smartTransactionsForSelectedChain.filter(\n (smartTransaction: SmartTransaction) =>\n smartTransaction.txParams?.from !== addressLowerCase,\n );\n this.update((state) => {\n state.smartTransactionsState.smartTransactions[chainId] =\n newSmartTransactionsForSelectedChain;\n });\n }\n}\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import { type TraceCallback } from "@metamask/controller-utils";
|
|
4
|
+
import type { ErrorReportingServiceCaptureExceptionAction } from "@metamask/error-reporting-service";
|
|
4
5
|
import type { Messenger } from "@metamask/messenger";
|
|
5
6
|
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
7
|
+
import type { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller";
|
|
6
8
|
import type { TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
9
|
+
import type { Hex } from "@metamask/utils";
|
|
7
10
|
import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.cjs";
|
|
8
|
-
import type { Fees,
|
|
11
|
+
import type { Fees, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.cjs";
|
|
9
12
|
import { SmartTransactionStatuses } from "./types.cjs";
|
|
10
13
|
import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from "./utils.cjs";
|
|
11
14
|
export declare const DEFAULT_INTERVAL: number;
|
|
@@ -39,7 +42,7 @@ export declare type SmartTransactionsControllerGetStateAction = ControllerGetSta
|
|
|
39
42
|
* The actions that can be performed using the {@link SmartTransactionsController}.
|
|
40
43
|
*/
|
|
41
44
|
export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction;
|
|
42
|
-
declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction;
|
|
45
|
+
declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction | ErrorReportingServiceCaptureExceptionAction;
|
|
43
46
|
export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>;
|
|
44
47
|
export declare type SmartTransactionsControllerSmartTransactionEvent = {
|
|
45
48
|
type: 'SmartTransactionsController:smartTransaction';
|
|
@@ -53,7 +56,7 @@ export declare type SmartTransactionsControllerSmartTransactionConfirmationDoneE
|
|
|
53
56
|
* The events that {@link SmartTransactionsController} can emit.
|
|
54
57
|
*/
|
|
55
58
|
export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent;
|
|
56
|
-
declare type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
59
|
+
declare type AllowedEvents = NetworkControllerStateChangeEvent | RemoteFeatureFlagControllerStateChangeEvent;
|
|
57
60
|
/**
|
|
58
61
|
* The messenger of the {@link SmartTransactionsController}.
|
|
59
62
|
*/
|
|
@@ -74,7 +77,12 @@ declare type SmartTransactionsControllerOptions = {
|
|
|
74
77
|
state?: Partial<SmartTransactionsControllerState>;
|
|
75
78
|
messenger: SmartTransactionsControllerMessenger;
|
|
76
79
|
getMetaMetricsProps: () => Promise<MetaMetricsProps>;
|
|
77
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated This option is ignored. Feature flags are now read directly
|
|
82
|
+
* from RemoteFeatureFlagController via the messenger. This option will be
|
|
83
|
+
* removed in a future version.
|
|
84
|
+
*/
|
|
85
|
+
getFeatureFlags?: () => FeatureFlags;
|
|
78
86
|
trace?: TraceCallback;
|
|
79
87
|
};
|
|
80
88
|
export declare type SmartTransactionsControllerPollingInput = {
|
|
@@ -98,7 +106,7 @@ declare const SmartTransactionsController_base: (abstract new (...args: any[]) =
|
|
|
98
106
|
export declare class SmartTransactionsController extends SmartTransactionsController_base<typeof controllerName, SmartTransactionsControllerState, SmartTransactionsControllerMessenger> {
|
|
99
107
|
#private;
|
|
100
108
|
timeoutHandle?: NodeJS.Timeout;
|
|
101
|
-
constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps,
|
|
109
|
+
constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, trace, }: SmartTransactionsControllerOptions);
|
|
102
110
|
_executePoll({ chainIds, }: SmartTransactionsControllerPollingInput): Promise<void>;
|
|
103
111
|
checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void;
|
|
104
112
|
initializeSmartTransactionsForChainId(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.d.cts","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAKL,KAAK,aAAa,EACnB,mCAAmC;
|
|
1
|
+
{"version":3,"file":"SmartTransactionsController.d.cts","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAKL,KAAK,aAAa,EACnB,mCAAmC;AACpC,OAAO,KAAK,EAAE,2CAA2C,EAAE,0CAA0C;AAErG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AAe,CAAC;KAC9B,GACL,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACG,aAAa,CAAC,EAClB,eAAe,EACf,OAAO,EAAE,UAAU,GACpB,GAAE;QACD,yCAAyC;QACzC,eAAe,CAAC,EAAE,eAAe,CAAC;QAClC,OAAO,CAAC,EAAE,GAAG,CAAC;KACV,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBnB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB/D,eAAe,CAAC,EACd,WAAW,EACX,MAAM,GACP,EAAE;QACD,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,wBAAwB,CAAC;KAClC,GAAG,gBAAgB,EAAE;IAOtB,gCAAgC,CAC9B,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,gBAAgB,GAAG,SAAS;IAa/B,qBAAqB,CAAC,EACpB,OAAO,EACP,aAAa,GACd,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,GAAG,IAAI;CAmDT"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import { type TraceCallback } from "@metamask/controller-utils";
|
|
4
|
+
import type { ErrorReportingServiceCaptureExceptionAction } from "@metamask/error-reporting-service";
|
|
4
5
|
import type { Messenger } from "@metamask/messenger";
|
|
5
6
|
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
7
|
+
import type { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller";
|
|
6
8
|
import type { TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
9
|
+
import type { Hex } from "@metamask/utils";
|
|
7
10
|
import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.mjs";
|
|
8
|
-
import type { Fees,
|
|
11
|
+
import type { Fees, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.mjs";
|
|
9
12
|
import { SmartTransactionStatuses } from "./types.mjs";
|
|
10
13
|
import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from "./utils.mjs";
|
|
11
14
|
export declare const DEFAULT_INTERVAL: number;
|
|
@@ -39,7 +42,7 @@ export declare type SmartTransactionsControllerGetStateAction = ControllerGetSta
|
|
|
39
42
|
* The actions that can be performed using the {@link SmartTransactionsController}.
|
|
40
43
|
*/
|
|
41
44
|
export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction;
|
|
42
|
-
declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction;
|
|
45
|
+
declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction | ErrorReportingServiceCaptureExceptionAction;
|
|
43
46
|
export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>;
|
|
44
47
|
export declare type SmartTransactionsControllerSmartTransactionEvent = {
|
|
45
48
|
type: 'SmartTransactionsController:smartTransaction';
|
|
@@ -53,7 +56,7 @@ export declare type SmartTransactionsControllerSmartTransactionConfirmationDoneE
|
|
|
53
56
|
* The events that {@link SmartTransactionsController} can emit.
|
|
54
57
|
*/
|
|
55
58
|
export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent;
|
|
56
|
-
declare type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
59
|
+
declare type AllowedEvents = NetworkControllerStateChangeEvent | RemoteFeatureFlagControllerStateChangeEvent;
|
|
57
60
|
/**
|
|
58
61
|
* The messenger of the {@link SmartTransactionsController}.
|
|
59
62
|
*/
|
|
@@ -74,7 +77,12 @@ declare type SmartTransactionsControllerOptions = {
|
|
|
74
77
|
state?: Partial<SmartTransactionsControllerState>;
|
|
75
78
|
messenger: SmartTransactionsControllerMessenger;
|
|
76
79
|
getMetaMetricsProps: () => Promise<MetaMetricsProps>;
|
|
77
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated This option is ignored. Feature flags are now read directly
|
|
82
|
+
* from RemoteFeatureFlagController via the messenger. This option will be
|
|
83
|
+
* removed in a future version.
|
|
84
|
+
*/
|
|
85
|
+
getFeatureFlags?: () => FeatureFlags;
|
|
78
86
|
trace?: TraceCallback;
|
|
79
87
|
};
|
|
80
88
|
export declare type SmartTransactionsControllerPollingInput = {
|
|
@@ -98,7 +106,7 @@ declare const SmartTransactionsController_base: (abstract new (...args: any[]) =
|
|
|
98
106
|
export declare class SmartTransactionsController extends SmartTransactionsController_base<typeof controllerName, SmartTransactionsControllerState, SmartTransactionsControllerMessenger> {
|
|
99
107
|
#private;
|
|
100
108
|
timeoutHandle?: NodeJS.Timeout;
|
|
101
|
-
constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps,
|
|
109
|
+
constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, trace, }: SmartTransactionsControllerOptions);
|
|
102
110
|
_executePoll({ chainIds, }: SmartTransactionsControllerPollingInput): Promise<void>;
|
|
103
111
|
checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void;
|
|
104
112
|
initializeSmartTransactionsForChainId(): void;
|