@metamask/smart-transactions-controller 19.2.1 → 20.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 +14 -1
- package/README.md +39 -4
- package/dist/SmartTransactionsController.cjs +19 -21
- package/dist/SmartTransactionsController.cjs.map +1 -1
- package/dist/SmartTransactionsController.d.cts +3 -2
- package/dist/SmartTransactionsController.d.cts.map +1 -1
- package/dist/SmartTransactionsController.d.mts +3 -2
- package/dist/SmartTransactionsController.d.mts.map +1 -1
- package/dist/SmartTransactionsController.mjs +19 -21
- package/dist/SmartTransactionsController.mjs.map +1 -1
- package/dist/constants.mjs +3 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/types.mjs +5 -5
- package/dist/types.mjs.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [20.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Migrate `SmartTransactionsController` to new `Messenger` from `@metamask/messenger` ([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
15
|
+
- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
16
|
+
- **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^24.0.O` to `^25.0.0` ([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
17
|
+
- **BREAKING:** Bump `@metamask/transaction-controller` peer dependency from `^60.4.0` to `^61.0.0` ([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
18
|
+
- Bump `@metamask/base-controller` from `^8.3.0` to `^9.0.0`([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
19
|
+
- Bump `@metamask/polling-controller` from `^14.0.0` to `^15.0.0`([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
20
|
+
- Set `moduleResolution` option to `Node16` ([#543](https://github.com/MetaMask/smart-transactions-controller/pull/543))
|
|
21
|
+
|
|
10
22
|
## [19.2.1]
|
|
11
23
|
|
|
12
24
|
### Fixed
|
|
@@ -646,7 +658,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
646
658
|
- Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
|
|
647
659
|
- Initial commit
|
|
648
660
|
|
|
649
|
-
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/
|
|
661
|
+
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v20.0.0...HEAD
|
|
662
|
+
[20.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v19.2.1...v20.0.0
|
|
650
663
|
[19.2.1]: https://github.com/MetaMask/smart-transactions-controller/compare/v19.2.0...v19.2.1
|
|
651
664
|
[19.2.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v19.1.0...v19.2.0
|
|
652
665
|
[19.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v19.0.0...v19.1.0
|
package/README.md
CHANGED
|
@@ -25,10 +25,6 @@ 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
|
-
### Linking
|
|
29
|
-
|
|
30
|
-
First, `yarn build:link` in this repository, then link it by running `yarn link` in the consumer repository.
|
|
31
|
-
|
|
32
28
|
### Release & Publishing
|
|
33
29
|
|
|
34
30
|
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.
|
|
@@ -66,3 +62,42 @@ The project follows the same release process as the other libraries in the MetaM
|
|
|
66
62
|
- Wait for the `publish-release` GitHub Action workflow to finish. This should trigger a second job (`publish-npm`), which will wait for a run approval by the [`npm publishers`](https://github.com/orgs/MetaMask/teams/npm-publishers) team.
|
|
67
63
|
- Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
|
|
68
64
|
- Once the `publish-npm` job has finished, check npm to verify that it has been published.
|
|
65
|
+
|
|
66
|
+
### Testing changes in other projects using preview builds
|
|
67
|
+
|
|
68
|
+
If you are working on a pull request and want to test changes in another project before you publish them, you can create a _preview build_ and then configure your project to use it.
|
|
69
|
+
|
|
70
|
+
#### Creating a preview build
|
|
71
|
+
|
|
72
|
+
1. Within your pull request, post a comment with the text `@metamaskbot publish-preview`. This starts the `publish-preview` GitHub action, which will create a preview build and publish it to NPM.
|
|
73
|
+
2. After a few minutes, the action should complete and you will see a new comment. Note two things:
|
|
74
|
+
- The name is scoped to `@metamask-previews` instead of `@metamask`.
|
|
75
|
+
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.
|
|
76
|
+
|
|
77
|
+
#### Using a preview build
|
|
78
|
+
|
|
79
|
+
To use a preview build within a project, you need to override the resolution logic for your package manager so that the "production" version of that package is replaced with the preview version. Here's how you do that:
|
|
80
|
+
|
|
81
|
+
1. Open `package.json` in the project and locate the entry for this package in `dependencies`.
|
|
82
|
+
2. Locate the section responsible for resolution overrides (or create it if it doesn't exist). If you're using Yarn, this is `resolutions`; if you're using NPM or any other package manager, this is `overrides`.
|
|
83
|
+
3. Add a line to this section that mirrors the dependency entry on the left-hand side and points to the preview version on the right-hand side. Note the exact format of the left-hand side will differ based on which version of Yarn or NPM you are using. For example:
|
|
84
|
+
- For Yarn Modern, you will add something like this to `resolutions`:
|
|
85
|
+
```
|
|
86
|
+
"@metamask/smart-transactions-controller@^1.2.3": "npm:@metamask-previews/smart-transactions-controller@1.2.3-preview-abcdefg"
|
|
87
|
+
```
|
|
88
|
+
- For Yarn Classic, you will add something like this to `resolutions`:
|
|
89
|
+
```
|
|
90
|
+
"@metamask/smart-transactions-controller": "npm:@metamask-previews/smart-transactions-controller@1.2.3-preview-abcdefg"
|
|
91
|
+
```
|
|
92
|
+
- For NPM, you will add something like this to `overrides`:
|
|
93
|
+
```
|
|
94
|
+
"@metamask/smart-transactions-controller": "npm:@metamask-previews/smart-transactions-controller@1.2.3-preview-abcdefg"
|
|
95
|
+
```
|
|
96
|
+
4. Run `yarn install`.
|
|
97
|
+
|
|
98
|
+
#### Updating a preview build
|
|
99
|
+
|
|
100
|
+
If you make more changes to your pull request and want to create a new preview build:
|
|
101
|
+
|
|
102
|
+
1. Post another `@metamaskbot` comment on the pull request and wait for the response.
|
|
103
|
+
2. Update the version of the preview build in your project's `package.json`. Make sure to re-run `yarn install`!
|
|
@@ -37,7 +37,7 @@ const controllerMetadata = {
|
|
|
37
37
|
smartTransactionsState: {
|
|
38
38
|
includeInStateLogs: true,
|
|
39
39
|
persist: false,
|
|
40
|
-
|
|
40
|
+
includeInDebugSnapshot: true,
|
|
41
41
|
usedInUi: true,
|
|
42
42
|
},
|
|
43
43
|
};
|
|
@@ -104,14 +104,14 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
104
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
|
-
this.
|
|
108
|
-
const { configuration: { chainId }, provider, } = this.
|
|
107
|
+
this.messenger.subscribe('NetworkController:stateChange', ({ selectedNetworkClientId }) => {
|
|
108
|
+
const { configuration: { chainId }, provider, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
109
109
|
__classPrivateFieldSet(this, _SmartTransactionsController_chainId, chainId, "f");
|
|
110
110
|
__classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, new eth_query_1.default(provider), "f");
|
|
111
111
|
this.initializeSmartTransactionsForChainId();
|
|
112
112
|
this.checkPoll(this.state);
|
|
113
113
|
});
|
|
114
|
-
this.
|
|
114
|
+
this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState));
|
|
115
115
|
}
|
|
116
116
|
async _executePoll({ chainIds, }) {
|
|
117
117
|
// if this is going to be truly UI driven polling we shouldn't really reach here
|
|
@@ -188,7 +188,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
188
188
|
let ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f");
|
|
189
189
|
let chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
|
|
190
190
|
if (networkClientId) {
|
|
191
|
-
const { configuration, provider } = this.
|
|
191
|
+
const { configuration, provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
192
192
|
chainId = configuration.chainId;
|
|
193
193
|
ethQuery = new eth_query_1.default(provider);
|
|
194
194
|
}
|
|
@@ -272,8 +272,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
272
272
|
return fees;
|
|
273
273
|
}
|
|
274
274
|
async getFees(tradeTx, approvalTx, { networkClientId } = {}) {
|
|
275
|
-
const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.
|
|
276
|
-
.selectedNetworkClientId;
|
|
275
|
+
const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.messenger.call('NetworkController:getState').selectedNetworkClientId;
|
|
277
276
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
|
|
278
277
|
networkClientId: selectedNetworkClientId,
|
|
279
278
|
});
|
|
@@ -330,8 +329,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
330
329
|
// * transaction controller external transactions list
|
|
331
330
|
async submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions = [], networkClientId, }) {
|
|
332
331
|
var _a, _b;
|
|
333
|
-
const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.
|
|
334
|
-
.selectedNetworkClientId;
|
|
332
|
+
const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.messenger.call('NetworkController:getState').selectedNetworkClientId;
|
|
335
333
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
|
|
336
334
|
networkClientId: selectedNetworkClientId,
|
|
337
335
|
});
|
|
@@ -365,7 +363,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
365
363
|
// This should only happen for Swaps. Non-swaps transactions should already have a nonce
|
|
366
364
|
if (requiresNonce) {
|
|
367
365
|
try {
|
|
368
|
-
nonceLock = await this.
|
|
366
|
+
nonceLock = await this.messenger.call('TransactionController:getNonceLock', txParams.from, selectedNetworkClientId);
|
|
369
367
|
nonce = (0, bytes_1.hexlify)(nonceLock.nextNonce);
|
|
370
368
|
nonceDetails = nonceLock.nonceDetails;
|
|
371
369
|
(_a = txParams.nonce) !== null && _a !== void 0 ? _a : (txParams.nonce = nonce);
|
|
@@ -552,7 +550,7 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
552
550
|
const nextSmartTransaction = Object.assign(Object.assign({}, currentSmartTransaction), smartTransaction);
|
|
553
551
|
// We have to emit this event here, because then a txHash is returned to the TransactionController once it's available
|
|
554
552
|
// and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.
|
|
555
|
-
this.
|
|
553
|
+
this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction);
|
|
556
554
|
if ((0, utils_1.shouldMarkRegularTransactionAsFailed)({
|
|
557
555
|
smartTransaction: nextSmartTransaction,
|
|
558
556
|
clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"),
|
|
@@ -560,8 +558,8 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
560
558
|
})) {
|
|
561
559
|
(0, utils_1.markRegularTransactionAsFailed)({
|
|
562
560
|
smartTransaction: nextSmartTransaction,
|
|
563
|
-
getRegularTransactions: () => this.
|
|
564
|
-
updateTransaction: (transactionMeta, note) => this.
|
|
561
|
+
getRegularTransactions: () => this.messenger.call('TransactionController:getTransactions'),
|
|
562
|
+
updateTransaction: (transactionMeta, note) => this.messenger.call('TransactionController:updateTransaction', transactionMeta, note),
|
|
565
563
|
});
|
|
566
564
|
}
|
|
567
565
|
if ((smartTransaction.status === types_1.SmartTransactionStatuses.SUCCESS ||
|
|
@@ -581,7 +579,7 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
581
579
|
if (!txHash) {
|
|
582
580
|
return true;
|
|
583
581
|
}
|
|
584
|
-
const transactions = this.
|
|
582
|
+
const transactions = this.messenger.call('TransactionController:getTransactions');
|
|
585
583
|
const foundTransaction = transactions === null || transactions === void 0 ? void 0 : transactions.find((tx) => {
|
|
586
584
|
var _a;
|
|
587
585
|
return ((_a = tx.hash) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === txHash.toLowerCase();
|
|
@@ -620,7 +618,7 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
620
618
|
const txMeta = entry.length > 0
|
|
621
619
|
? Object.assign(Object.assign({}, originalTxMeta), { history: originalTxMeta.history.concat(entry) }) : originalTxMeta;
|
|
622
620
|
if (__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_doesTransactionNeedConfirmation).call(this, txHash)) {
|
|
623
|
-
this.
|
|
621
|
+
this.messenger.call('TransactionController:confirmExternalTransaction',
|
|
624
622
|
// TODO: Replace 'as' assertion with correct typing for `txMeta`
|
|
625
623
|
txMeta, transactionReceipt,
|
|
626
624
|
// TODO: Replace 'as' assertion with correct typing for `baseFeePerGas`
|
|
@@ -645,27 +643,27 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
645
643
|
console.error('confirm error', error);
|
|
646
644
|
}
|
|
647
645
|
finally {
|
|
648
|
-
this.
|
|
646
|
+
this.messenger.publish(`SmartTransactionsController:smartTransactionConfirmationDone`, smartTransaction);
|
|
649
647
|
}
|
|
650
648
|
}, _SmartTransactionsController_addNonceToTransaction = async function _SmartTransactionsController_addNonceToTransaction(transaction, networkClientId) {
|
|
651
|
-
const nonceLock = await this.
|
|
649
|
+
const nonceLock = await this.messenger.call('TransactionController:getNonceLock', transaction.from, networkClientId);
|
|
652
650
|
const nonce = nonceLock.nextNonce;
|
|
653
651
|
nonceLock.releaseLock();
|
|
654
652
|
return Object.assign(Object.assign({}, transaction), { nonce: `0x${nonce.toString(16)}` });
|
|
655
653
|
}, _SmartTransactionsController_getChainId = function _SmartTransactionsController_getChainId({ networkClientId, } = {}) {
|
|
656
654
|
if (networkClientId) {
|
|
657
|
-
return this.
|
|
655
|
+
return this.messenger.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
658
656
|
}
|
|
659
657
|
return __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
|
|
660
658
|
}, _SmartTransactionsController_getChainIds = function _SmartTransactionsController_getChainIds() {
|
|
661
|
-
const { networkConfigurationsByChainId } = this.
|
|
659
|
+
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
662
660
|
return Object.keys(networkConfigurationsByChainId).filter((chainId) => __classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(chainId));
|
|
663
661
|
}, _SmartTransactionsController_getNetworkClientId = function _SmartTransactionsController_getNetworkClientId({ chainId }) {
|
|
664
|
-
const { networkConfigurationsByChainId } = this.
|
|
662
|
+
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
665
663
|
return networkConfigurationsByChainId[chainId].rpcEndpoints[networkConfigurationsByChainId[chainId].defaultRpcEndpointIndex].networkClientId;
|
|
666
664
|
}, _SmartTransactionsController_getEthQuery = function _SmartTransactionsController_getEthQuery({ networkClientId, } = {}) {
|
|
667
665
|
if (networkClientId) {
|
|
668
|
-
const { provider } = this.
|
|
666
|
+
const { provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
669
667
|
return new eth_query_1.default(provider);
|
|
670
668
|
}
|
|
671
669
|
if (__classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f") === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.cjs","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAA+C;AAO/C,iEAMoC;AACpC,oEAA2C;AAO3C,qEAA+E;AAS/E,6EAAqE;AACrE,+CAAyC;AACzC,oEAAyC;AAEzC,+CAIqB;AAcrB,uCAA4D;AAC5D,uCAeiB;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,SAAS,EAAE,IAAI;QACf,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;YACD,QAAQ,EAAE,IAAI;YACd,iBAAiB,EAAE;gBACjB,CAAC,0BAAO,CAAC,OAAO,CAAC,EAA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,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 RestrictedMessenger,\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 {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n TransactionControllerConfirmExternalTransactionAction,\n TransactionControllerGetNonceLockAction,\n TransactionControllerGetTransactionsAction,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport { TransactionStatus } 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 generateHistoryEntry,\n getAPIRequestURL,\n handleFetch,\n incrementNonceInHex,\n isSmartTransactionCancellable,\n isSmartTransactionPending,\n replayHistory,\n snapshotFromTxMeta,\n getTxHash,\n getSmartTransactionMetricsProperties,\n getSmartTransactionMetricsSensitiveProperties,\n shouldMarkRegularTransactionAsFailed,\n markRegularTransactionAsFailed,\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 anonymous: 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 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 | TransactionControllerConfirmExternalTransactionAction\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 = RestrictedMessenger<\n typeof controllerName,\n SmartTransactionsControllerActions | AllowedActions,\n SmartTransactionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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.messagingSystem.subscribe(\n 'NetworkController:stateChange',\n ({ selectedNetworkClientId }) => {\n const {\n configuration: { chainId },\n provider,\n } = this.messagingSystem.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.messagingSystem.subscribe(\n `${controllerName}:stateChange`,\n (currentState) => 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.messagingSystem.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, because then a txHash is returned to the TransactionController once it's available\n // and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.\n this.messagingSystem.publish(\n `SmartTransactionsController:smartTransaction`,\n nextSmartTransaction,\n );\n\n if (\n shouldMarkRegularTransactionAsFailed({\n smartTransaction: nextSmartTransaction,\n clientId: this.#clientId,\n getFeatureFlags: this.#getFeatureFlags,\n })\n ) {\n markRegularTransactionAsFailed({\n smartTransaction: nextSmartTransaction,\n getRegularTransactions: () =>\n this.messagingSystem.call('TransactionController:getTransactions'),\n updateTransaction: (transactionMeta: TransactionMeta, note: string) =>\n this.messagingSystem.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 #doesTransactionNeedConfirmation(txHash: string | undefined): boolean {\n if (!txHash) {\n return true;\n }\n const transactions = this.messagingSystem.call(\n 'TransactionController:getTransactions',\n );\n const foundTransaction = transactions?.find((tx) => {\n return tx.hash?.toLowerCase() === txHash.toLowerCase();\n });\n if (!foundTransaction) {\n return true;\n }\n // If a found transaction is either confirmed or submitted, it doesn't need confirmation from the STX controller.\n // When it's in the submitted state, the TransactionController checks its status and confirms it,\n // so no need to confirm it again here.\n return ![TransactionStatus.confirmed, TransactionStatus.submitted].includes(\n foundTransaction.status,\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 maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n blockNumber: string;\n } | null = await query(ethQuery, 'getTransactionReceipt', [txHash]);\n const transaction: {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n } | null = await query(ethQuery, 'getTransactionByHash', [txHash]);\n\n const maxFeePerGas = transaction?.maxFeePerGas;\n const maxPriorityFeePerGas = transaction?.maxPriorityFeePerGas;\n if (transactionReceipt?.blockNumber) {\n const blockData: { baseFeePerGas?: Hex } | null = await query(\n ethQuery,\n 'getBlockByNumber',\n [transactionReceipt?.blockNumber, false],\n );\n const baseFeePerGas = blockData?.baseFeePerGas;\n const updatedTxParams = {\n ...smartTransaction.txParams,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n // call confirmExternalTransaction\n const originalTxMeta = {\n ...smartTransaction,\n id: smartTransaction.uuid,\n status: TransactionStatus.confirmed,\n hash: txHash,\n txParams: updatedTxParams,\n };\n // create txMeta snapshot for history\n const snapshot = snapshotFromTxMeta(originalTxMeta);\n // recover previous tx state obj\n const previousState = replayHistory(originalTxMeta.history);\n // generate history entry and add to history\n const entry = generateHistoryEntry(\n previousState,\n snapshot,\n 'txStateManager: setting status to confirmed',\n );\n const txMeta =\n entry.length > 0\n ? {\n ...originalTxMeta,\n history: originalTxMeta.history.concat(entry),\n }\n : originalTxMeta;\n\n if (this.#doesTransactionNeedConfirmation(txHash)) {\n this.messagingSystem.call(\n 'TransactionController:confirmExternalTransaction',\n // TODO: Replace 'as' assertion with correct typing for `txMeta`\n txMeta as TransactionMeta,\n transactionReceipt,\n // TODO: Replace 'as' assertion with correct typing for `baseFeePerGas`\n baseFeePerGas as Hex,\n );\n }\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.messagingSystem.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.messagingSystem.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.messagingSystem.call('NetworkController:getState')\n .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.messagingSystem.call('NetworkController:getState')\n .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.messagingSystem.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.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration.chainId;\n }\n\n return this.#chainId;\n }\n\n #getChainIds(): Hex[] {\n const { networkConfigurationsByChainId } = this.messagingSystem.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.messagingSystem.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.messagingSystem.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 async fetchLiveness({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): Promise<boolean> {\n const chainId = 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;AACpC,oEAA2C;AAQ3C,qEAA+E;AAS/E,6EAAqE;AACrE,+CAAyC;AACzC,oEAAyC;AAEzC,+CAIqB;AAcrB,uCAA4D;AAC5D,uCAeiB;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;C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AC9C,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 TransactionControllerConfirmExternalTransactionAction,\n TransactionControllerGetNonceLockAction,\n TransactionControllerGetTransactionsAction,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport { TransactionStatus } 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 generateHistoryEntry,\n getAPIRequestURL,\n handleFetch,\n incrementNonceInHex,\n isSmartTransactionCancellable,\n isSmartTransactionPending,\n replayHistory,\n snapshotFromTxMeta,\n getTxHash,\n getSmartTransactionMetricsProperties,\n getSmartTransactionMetricsSensitiveProperties,\n shouldMarkRegularTransactionAsFailed,\n markRegularTransactionAsFailed,\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 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 | TransactionControllerConfirmExternalTransactionAction\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, because then a txHash is returned to the TransactionController once it's available\n // and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.\n this.messenger.publish(\n `SmartTransactionsController:smartTransaction`,\n nextSmartTransaction,\n );\n\n if (\n shouldMarkRegularTransactionAsFailed({\n smartTransaction: nextSmartTransaction,\n clientId: this.#clientId,\n getFeatureFlags: this.#getFeatureFlags,\n })\n ) {\n markRegularTransactionAsFailed({\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 #doesTransactionNeedConfirmation(txHash: string | undefined): boolean {\n if (!txHash) {\n return true;\n }\n const transactions = this.messenger.call(\n 'TransactionController:getTransactions',\n );\n const foundTransaction = transactions?.find((tx) => {\n return tx.hash?.toLowerCase() === txHash.toLowerCase();\n });\n if (!foundTransaction) {\n return true;\n }\n // If a found transaction is either confirmed or submitted, it doesn't need confirmation from the STX controller.\n // When it's in the submitted state, the TransactionController checks its status and confirms it,\n // so no need to confirm it again here.\n return ![TransactionStatus.confirmed, TransactionStatus.submitted].includes(\n foundTransaction.status,\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 maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n blockNumber: string;\n } | null = await query(ethQuery, 'getTransactionReceipt', [txHash]);\n const transaction: {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n } | null = await query(ethQuery, 'getTransactionByHash', [txHash]);\n\n const maxFeePerGas = transaction?.maxFeePerGas;\n const maxPriorityFeePerGas = transaction?.maxPriorityFeePerGas;\n if (transactionReceipt?.blockNumber) {\n const blockData: { baseFeePerGas?: Hex } | null = await query(\n ethQuery,\n 'getBlockByNumber',\n [transactionReceipt?.blockNumber, false],\n );\n const baseFeePerGas = blockData?.baseFeePerGas;\n const updatedTxParams = {\n ...smartTransaction.txParams,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n // call confirmExternalTransaction\n const originalTxMeta = {\n ...smartTransaction,\n id: smartTransaction.uuid,\n status: TransactionStatus.confirmed,\n hash: txHash,\n txParams: updatedTxParams,\n };\n // create txMeta snapshot for history\n const snapshot = snapshotFromTxMeta(originalTxMeta);\n // recover previous tx state obj\n const previousState = replayHistory(originalTxMeta.history);\n // generate history entry and add to history\n const entry = generateHistoryEntry(\n previousState,\n snapshot,\n 'txStateManager: setting status to confirmed',\n );\n const txMeta =\n entry.length > 0\n ? {\n ...originalTxMeta,\n history: originalTxMeta.history.concat(entry),\n }\n : originalTxMeta;\n\n if (this.#doesTransactionNeedConfirmation(txHash)) {\n this.messenger.call(\n 'TransactionController:confirmExternalTransaction',\n // TODO: Replace 'as' assertion with correct typing for `txMeta`\n txMeta as TransactionMeta,\n transactionReceipt,\n // TODO: Replace 'as' assertion with correct typing for `baseFeePerGas`\n baseFeePerGas as Hex,\n );\n }\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 async fetchLiveness({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): Promise<boolean> {\n const chainId = 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,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import { type TraceCallback } from "@metamask/controller-utils";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
5
|
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
5
6
|
import type { TransactionControllerConfirmExternalTransactionAction, TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
6
7
|
import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.cjs";
|
|
@@ -56,7 +57,7 @@ declare type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
|
56
57
|
/**
|
|
57
58
|
* The messenger of the {@link SmartTransactionsController}.
|
|
58
59
|
*/
|
|
59
|
-
export declare type SmartTransactionsControllerMessenger =
|
|
60
|
+
export declare type SmartTransactionsControllerMessenger = Messenger<typeof controllerName, SmartTransactionsControllerActions | AllowedActions, SmartTransactionsControllerEvents | AllowedEvents>;
|
|
60
61
|
declare type SmartTransactionsControllerOptions = {
|
|
61
62
|
interval?: number;
|
|
62
63
|
clientId: ClientId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.d.cts","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,
|
|
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;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC3C,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;AAEtC,OAAO,KAAK,EACV,qDAAqD,EACrD,uCAAuC,EACvC,0CAA0C,EAC1C,4CAA4C,EAC5C,eAAe,EACf,iBAAiB,EAClB,yCAAyC;AAK1C,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EAErB,wBAAoB;AACrB,OAAO,KAAK,EACV,IAAI,EACJ,GAAG,EACH,gBAAgB,EAChB,yBAAyB,EAC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Aa,GACd,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,GAAG,IAAI;CAmDT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import { type TraceCallback } from "@metamask/controller-utils";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
5
|
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
5
6
|
import type { TransactionControllerConfirmExternalTransactionAction, TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
6
7
|
import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.mjs";
|
|
@@ -56,7 +57,7 @@ declare type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
|
56
57
|
/**
|
|
57
58
|
* The messenger of the {@link SmartTransactionsController}.
|
|
58
59
|
*/
|
|
59
|
-
export declare type SmartTransactionsControllerMessenger =
|
|
60
|
+
export declare type SmartTransactionsControllerMessenger = Messenger<typeof controllerName, SmartTransactionsControllerActions | AllowedActions, SmartTransactionsControllerEvents | AllowedEvents>;
|
|
60
61
|
declare type SmartTransactionsControllerOptions = {
|
|
61
62
|
interval?: number;
|
|
62
63
|
clientId: ClientId;
|