@metamask/smart-transactions-controller 12.0.1 → 13.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/dist/SmartTransactionsController.d.ts +68 -45
- package/dist/SmartTransactionsController.js +188 -155
- package/dist/SmartTransactionsController.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [13.0.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING:** Updated `SmartTransactionsController` to inherit from `StaticIntervalPollingController` instead of `StaticIntervalPollingControllerV1` ([#397](https://github.com/MetaMask/smart-transactions-controller/pull/397)).
|
|
12
|
+
- The constructor for `SmartTransactionsController` now accepts a single options object instead of three separate arguments, with configuration options merged into this object.
|
|
13
|
+
- `SmartTransactionsController` now requires a `messenger` option (with the corresponding type `SmartTransactionsControllerMessenger` now available).
|
|
14
|
+
- The constructor no longer accepts `onNetworkStateChange`; instead, it subscribes to `NetworkController:stateChange`.
|
|
15
|
+
- The `getNetworkClientById` argument has been removed from the constructor and is now accessed through the messenger.
|
|
16
|
+
- The controller no longer subscribes to its own events; this is now managed via the messenger.
|
|
17
|
+
- Event emission is no longer handled by `EventEmitter`; the messenger is now used for emitting events.
|
|
18
|
+
- The `SmartTransactionsControllerConfig` type has been removed and replaced with `SmartTransactionsControllerOptions`.
|
|
19
|
+
- Added and exported the following types: `SmartTransactionsControllerMessenger`, `SmartTransactionsControllerState`, `SmartTransactionsControllerGetStateAction`, `SmartTransactionsControllerActions`, `SmartTransactionsControllerStateChangeEvent`, `SmartTransactionsControllerSmartTransactionEvent`, and `SmartTransactionsControllerEvents`.
|
|
20
|
+
|
|
9
21
|
## [12.0.1]
|
|
10
22
|
### Fixed
|
|
11
23
|
- Fix issue where this.ethQuery is sometimes unexpectedly undefined ([#405](https://github.com/MetaMask/smart-transactions-controller/pull/405))
|
|
@@ -330,7 +342,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
330
342
|
- Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
|
|
331
343
|
- Initial commit
|
|
332
344
|
|
|
333
|
-
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/
|
|
345
|
+
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v13.0.0...HEAD
|
|
346
|
+
[13.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v12.0.1...v13.0.0
|
|
334
347
|
[12.0.1]: https://github.com/MetaMask/smart-transactions-controller/compare/v12.0.0...v12.0.1
|
|
335
348
|
[12.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v11.0.0...v12.0.0
|
|
336
349
|
[11.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v10.2.0...v11.0.0
|
|
@@ -1,65 +1,88 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import EventEmitter from 'events';
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
3
|
+
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from '@metamask/network-controller';
|
|
4
|
+
import { StaticIntervalPollingController } from '@metamask/polling-controller';
|
|
5
|
+
import type { TransactionController, TransactionMeta, TransactionParams } from '@metamask/transaction-controller';
|
|
6
|
+
import { MetaMetricsEventCategory, MetaMetricsEventName } from './constants';
|
|
8
7
|
import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, GetTransactionsOptions, MetaMetricsProps } from './types';
|
|
9
8
|
import { SmartTransactionStatuses } from './types';
|
|
9
|
+
import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from './utils';
|
|
10
10
|
export declare const DEFAULT_INTERVAL: number;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
supportedChainIds: Hex[];
|
|
16
|
-
};
|
|
11
|
+
/**
|
|
12
|
+
* The name of the {@link SmartTransactionsController}
|
|
13
|
+
*/
|
|
14
|
+
declare const controllerName = "SmartTransactionsController";
|
|
17
15
|
declare type FeeEstimates = {
|
|
18
|
-
approvalTxFees: IndividualTxFees |
|
|
19
|
-
tradeTxFees: IndividualTxFees |
|
|
16
|
+
approvalTxFees: IndividualTxFees | null;
|
|
17
|
+
tradeTxFees: IndividualTxFees | null;
|
|
20
18
|
};
|
|
21
|
-
export declare type SmartTransactionsControllerState =
|
|
19
|
+
export declare type SmartTransactionsControllerState = {
|
|
22
20
|
smartTransactionsState: {
|
|
23
21
|
smartTransactions: Record<Hex, SmartTransaction[]>;
|
|
24
|
-
userOptIn: boolean |
|
|
25
|
-
userOptInV2: boolean |
|
|
26
|
-
liveness: boolean |
|
|
22
|
+
userOptIn: boolean | null;
|
|
23
|
+
userOptInV2: boolean | null;
|
|
24
|
+
liveness: boolean | null;
|
|
27
25
|
fees: FeeEstimates;
|
|
28
26
|
feesByChainId: Record<Hex, FeeEstimates>;
|
|
29
27
|
livenessByChainId: Record<Hex, boolean>;
|
|
30
28
|
};
|
|
31
29
|
};
|
|
32
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Get the default {@link SmartTransactionsController} state.
|
|
32
|
+
*
|
|
33
|
+
* @returns The default {@link SmartTransactionsController} state.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getDefaultSmartTransactionsControllerState(): SmartTransactionsControllerState;
|
|
36
|
+
export declare type SmartTransactionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SmartTransactionsControllerState>;
|
|
37
|
+
/**
|
|
38
|
+
* The actions that can be performed using the {@link SmartTransactionsController}.
|
|
39
|
+
*/
|
|
40
|
+
export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction;
|
|
41
|
+
export declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction;
|
|
42
|
+
export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>;
|
|
43
|
+
export declare type SmartTransactionsControllerSmartTransactionEvent = {
|
|
44
|
+
type: 'SmartTransactionsController:smartTransaction';
|
|
45
|
+
payload: [SmartTransaction];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The events that {@link SmartTransactionsController} can emit.
|
|
49
|
+
*/
|
|
50
|
+
export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent;
|
|
51
|
+
export declare type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
52
|
+
/**
|
|
53
|
+
* The messenger of the {@link SmartTransactionsController}.
|
|
54
|
+
*/
|
|
55
|
+
export declare type SmartTransactionsControllerMessenger = RestrictedControllerMessenger<typeof controllerName, SmartTransactionsControllerActions | AllowedActions, SmartTransactionsControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
56
|
+
declare type SmartTransactionsControllerOptions = {
|
|
57
|
+
interval?: number;
|
|
58
|
+
clientId?: string;
|
|
59
|
+
chainId?: Hex;
|
|
60
|
+
supportedChainIds?: Hex[];
|
|
61
|
+
getNonceLock: TransactionController['getNonceLock'];
|
|
62
|
+
confirmExternalTransaction: TransactionController['confirmExternalTransaction'];
|
|
63
|
+
trackMetaMetricsEvent: (event: {
|
|
64
|
+
event: MetaMetricsEventName;
|
|
65
|
+
category: MetaMetricsEventCategory;
|
|
66
|
+
properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;
|
|
67
|
+
sensitiveProperties?: ReturnType<typeof getSmartTransactionMetricsSensitiveProperties>;
|
|
68
|
+
}, options?: {
|
|
69
|
+
metaMetricsId?: string;
|
|
70
|
+
} & Record<string, boolean>) => void;
|
|
71
|
+
state?: Partial<SmartTransactionsControllerState>;
|
|
72
|
+
messenger: SmartTransactionsControllerMessenger;
|
|
73
|
+
getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
|
|
74
|
+
getMetaMetricsProps: () => Promise<MetaMetricsProps>;
|
|
75
|
+
};
|
|
76
|
+
export default class SmartTransactionsController extends StaticIntervalPollingController<typeof controllerName, SmartTransactionsControllerState, SmartTransactionsControllerMessenger> {
|
|
33
77
|
#private;
|
|
34
|
-
/**
|
|
35
|
-
* Name of this controller used during composition
|
|
36
|
-
*/
|
|
37
|
-
name: string;
|
|
38
78
|
timeoutHandle?: NodeJS.Timeout;
|
|
39
|
-
|
|
40
|
-
private ethQuery;
|
|
41
|
-
confirmExternalTransaction: any;
|
|
42
|
-
getRegularTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
|
|
43
|
-
private readonly trackMetaMetricsEvent;
|
|
44
|
-
eventEmitter: EventEmitter;
|
|
45
|
-
private readonly getNetworkClientById;
|
|
46
|
-
private readonly getMetaMetricsProps;
|
|
47
|
-
private fetch;
|
|
48
|
-
constructor({ onNetworkStateChange, getNonceLock, confirmExternalTransaction, getTransactions, trackMetaMetricsEvent, getNetworkClientById, getMetaMetricsProps, }: {
|
|
49
|
-
onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
|
|
50
|
-
getNonceLock: any;
|
|
51
|
-
confirmExternalTransaction: any;
|
|
52
|
-
getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
|
|
53
|
-
trackMetaMetricsEvent: any;
|
|
54
|
-
getNetworkClientById: NetworkController['getNetworkClientById'];
|
|
55
|
-
getMetaMetricsProps: () => Promise<MetaMetricsProps>;
|
|
56
|
-
}, config?: Partial<SmartTransactionsControllerConfig>, state?: Partial<SmartTransactionsControllerState>);
|
|
79
|
+
constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, getNonceLock, confirmExternalTransaction, trackMetaMetricsEvent, state, messenger, getTransactions, getMetaMetricsProps, }: SmartTransactionsControllerOptions);
|
|
57
80
|
_executePoll(networkClientId: string): Promise<void>;
|
|
58
|
-
checkPoll(
|
|
81
|
+
checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void;
|
|
59
82
|
initializeSmartTransactionsForChainId(): void;
|
|
60
83
|
poll(interval?: number): Promise<void>;
|
|
61
84
|
stop(): Promise<void>;
|
|
62
|
-
setOptInState(
|
|
85
|
+
setOptInState(optInState: boolean | null): void;
|
|
63
86
|
trackStxStatusChange(smartTransaction: SmartTransaction, prevSmartTransaction?: SmartTransaction): void;
|
|
64
87
|
isNewSmartTransaction(smartTransactionUuid: string): boolean;
|
|
65
88
|
updateSmartTransaction(smartTransaction: SmartTransaction, { networkClientId }?: {
|
|
@@ -79,8 +102,8 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
|
|
|
79
102
|
submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions, networkClientId, }: {
|
|
80
103
|
signedTransactions: SignedTransaction[];
|
|
81
104
|
signedCanceledTransactions: SignedCanceledTransaction[];
|
|
82
|
-
transactionMeta?:
|
|
83
|
-
txParams?:
|
|
105
|
+
transactionMeta?: TransactionMeta;
|
|
106
|
+
txParams?: TransactionParams;
|
|
84
107
|
networkClientId?: NetworkClientId;
|
|
85
108
|
}): Promise<any>;
|
|
86
109
|
cancelSmartTransaction(uuid: string, { networkClientId, }?: {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
2
8
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
9
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
@@ -7,90 +13,106 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
15
|
};
|
|
10
|
-
var _SmartTransactionsController_instances, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_doesTransactionNeedConfirmation, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId;
|
|
16
|
+
var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_getNonceLock, _SmartTransactionsController_ethQuery, _SmartTransactionsController_confirmExternalTransaction, _SmartTransactionsController_getRegularTransactions, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_doesTransactionNeedConfirmation, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId;
|
|
11
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DEFAULT_INTERVAL = void 0;
|
|
13
|
-
// eslint-disable-next-line import/no-nodejs-modules
|
|
18
|
+
exports.getDefaultSmartTransactionsControllerState = exports.DEFAULT_INTERVAL = void 0;
|
|
14
19
|
const bytes_1 = require("@ethersproject/bytes");
|
|
15
20
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
16
21
|
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
17
22
|
const polling_controller_1 = require("@metamask/polling-controller");
|
|
18
23
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
19
24
|
const bignumber_js_1 = require("bignumber.js");
|
|
20
|
-
// eslint-disable-next-line import/no-nodejs-modules
|
|
21
|
-
const events_1 = __importDefault(require("events"));
|
|
22
25
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
23
26
|
const constants_1 = require("./constants");
|
|
24
27
|
const types_1 = require("./types");
|
|
25
28
|
const utils_1 = require("./utils");
|
|
26
29
|
const SECOND = 1000;
|
|
27
30
|
exports.DEFAULT_INTERVAL = SECOND * 5;
|
|
31
|
+
const DEFAULT_CLIENT_ID = 'default';
|
|
28
32
|
const ETH_QUERY_ERROR_MSG = '`ethQuery` is not defined on SmartTransactionsController';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
/**
|
|
34
|
+
* The name of the {@link SmartTransactionsController}
|
|
35
|
+
*/
|
|
36
|
+
const controllerName = 'SmartTransactionsController';
|
|
37
|
+
const controllerMetadata = {
|
|
38
|
+
smartTransactionsState: {
|
|
39
|
+
persist: false,
|
|
40
|
+
anonymous: true,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Get the default {@link SmartTransactionsController} state.
|
|
45
|
+
*
|
|
46
|
+
* @returns The default {@link SmartTransactionsController} state.
|
|
47
|
+
*/
|
|
48
|
+
function getDefaultSmartTransactionsControllerState() {
|
|
49
|
+
return {
|
|
50
|
+
smartTransactionsState: {
|
|
51
|
+
smartTransactions: {},
|
|
52
|
+
userOptIn: null,
|
|
53
|
+
userOptInV2: null,
|
|
54
|
+
fees: {
|
|
55
|
+
approvalTxFees: null,
|
|
56
|
+
tradeTxFees: null,
|
|
57
|
+
},
|
|
58
|
+
liveness: true,
|
|
59
|
+
livenessByChainId: {
|
|
60
|
+
[controller_utils_1.ChainId.mainnet]: true,
|
|
61
|
+
[controller_utils_1.ChainId.sepolia]: true,
|
|
62
|
+
},
|
|
63
|
+
feesByChainId: {
|
|
64
|
+
[controller_utils_1.ChainId.mainnet]: {
|
|
65
|
+
approvalTxFees: null,
|
|
66
|
+
tradeTxFees: null,
|
|
56
67
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
tradeTxFees: undefined,
|
|
61
|
-
},
|
|
62
|
-
[controller_utils_1.ChainId.sepolia]: {
|
|
63
|
-
approvalTxFees: undefined,
|
|
64
|
-
tradeTxFees: undefined,
|
|
65
|
-
},
|
|
68
|
+
[controller_utils_1.ChainId.sepolia]: {
|
|
69
|
+
approvalTxFees: null,
|
|
70
|
+
tradeTxFees: null,
|
|
66
71
|
},
|
|
67
72
|
},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.getDefaultSmartTransactionsControllerState = getDefaultSmartTransactionsControllerState;
|
|
77
|
+
class SmartTransactionsController extends polling_controller_1.StaticIntervalPollingController {
|
|
78
|
+
constructor({ interval = exports.DEFAULT_INTERVAL, clientId = DEFAULT_CLIENT_ID, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], getNonceLock, confirmExternalTransaction, trackMetaMetricsEvent, state = {}, messenger, getTransactions, getMetaMetricsProps, }) {
|
|
79
|
+
super({
|
|
80
|
+
name: controllerName,
|
|
81
|
+
metadata: controllerMetadata,
|
|
82
|
+
messenger,
|
|
83
|
+
state: Object.assign(Object.assign({}, getDefaultSmartTransactionsControllerState()), state),
|
|
84
|
+
});
|
|
85
|
+
_SmartTransactionsController_instances.add(this);
|
|
86
|
+
_SmartTransactionsController_interval.set(this, void 0);
|
|
87
|
+
_SmartTransactionsController_clientId.set(this, void 0);
|
|
88
|
+
_SmartTransactionsController_chainId.set(this, void 0);
|
|
89
|
+
_SmartTransactionsController_supportedChainIds.set(this, void 0);
|
|
90
|
+
_SmartTransactionsController_getNonceLock.set(this, void 0);
|
|
91
|
+
_SmartTransactionsController_ethQuery.set(this, void 0);
|
|
92
|
+
_SmartTransactionsController_confirmExternalTransaction.set(this, void 0);
|
|
93
|
+
_SmartTransactionsController_getRegularTransactions.set(this, void 0);
|
|
94
|
+
_SmartTransactionsController_trackMetaMetricsEvent.set(this, void 0);
|
|
95
|
+
_SmartTransactionsController_getMetaMetricsProps.set(this, void 0);
|
|
96
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
|
|
97
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_clientId, clientId, "f");
|
|
98
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_chainId, InitialChainId, "f");
|
|
99
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_supportedChainIds, supportedChainIds, "f");
|
|
100
|
+
this.setIntervalLength(interval);
|
|
101
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_getNonceLock, getNonceLock, "f");
|
|
102
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, undefined, "f");
|
|
103
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_confirmExternalTransaction, confirmExternalTransaction, "f");
|
|
104
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_getRegularTransactions, getTransactions, "f");
|
|
105
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
|
|
106
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f");
|
|
78
107
|
this.initializeSmartTransactionsForChainId();
|
|
79
|
-
|
|
80
|
-
const { configuration: { chainId }, provider, } = this.getNetworkClientById
|
|
81
|
-
this
|
|
82
|
-
this
|
|
108
|
+
this.messagingSystem.subscribe('NetworkController:stateChange', ({ selectedNetworkClientId }) => {
|
|
109
|
+
const { configuration: { chainId }, provider, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
110
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_chainId, chainId, "f");
|
|
111
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, new eth_query_1.default(provider), "f");
|
|
83
112
|
this.initializeSmartTransactionsForChainId();
|
|
84
113
|
this.checkPoll(this.state);
|
|
85
114
|
});
|
|
86
|
-
this.subscribe((currentState) => this.checkPoll(currentState));
|
|
87
|
-
this.eventEmitter = new events_1.default();
|
|
88
|
-
}
|
|
89
|
-
/* istanbul ignore next */
|
|
90
|
-
async fetch(request, options) {
|
|
91
|
-
const { clientId } = this.config;
|
|
92
|
-
const fetchOptions = Object.assign(Object.assign({}, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, (clientId && { 'X-Client-Id': clientId })) });
|
|
93
|
-
return (0, utils_1.handleFetch)(request, fetchOptions);
|
|
115
|
+
this.messagingSystem.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState));
|
|
94
116
|
}
|
|
95
117
|
async _executePoll(networkClientId) {
|
|
96
118
|
// if this is going to be truly UI driven polling we shouldn't really reach here
|
|
@@ -98,14 +120,13 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
98
120
|
// wondering if we should add some kind of predicate to the polling controller to check whether
|
|
99
121
|
// we should poll or not
|
|
100
122
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
101
|
-
if (!this.
|
|
123
|
+
if (!__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(chainId)) {
|
|
102
124
|
return Promise.resolve();
|
|
103
125
|
}
|
|
104
126
|
return this.updateSmartTransactions({ networkClientId });
|
|
105
127
|
}
|
|
106
|
-
checkPoll(
|
|
107
|
-
const
|
|
108
|
-
const currentSmartTransactions = smartTransactions[this.config.chainId];
|
|
128
|
+
checkPoll({ smartTransactionsState: { smartTransactions }, }) {
|
|
129
|
+
const currentSmartTransactions = smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")];
|
|
109
130
|
const pendingTransactions = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.filter(utils_1.isSmartTransactionPending);
|
|
110
131
|
if (!this.timeoutHandle && (pendingTransactions === null || pendingTransactions === void 0 ? void 0 : pendingTransactions.length) > 0) {
|
|
111
132
|
this.poll();
|
|
@@ -115,33 +136,34 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
initializeSmartTransactionsForChainId() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
if (__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"))) {
|
|
140
|
+
this.update((state) => {
|
|
141
|
+
var _a;
|
|
142
|
+
state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")] =
|
|
143
|
+
(_a = state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")]) !== null && _a !== void 0 ? _a : [];
|
|
123
144
|
});
|
|
124
145
|
}
|
|
125
146
|
}
|
|
126
147
|
async poll(interval) {
|
|
127
|
-
|
|
128
|
-
|
|
148
|
+
if (interval) {
|
|
149
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
|
|
150
|
+
}
|
|
129
151
|
this.timeoutHandle && clearInterval(this.timeoutHandle);
|
|
130
|
-
if (!
|
|
152
|
+
if (!__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"))) {
|
|
131
153
|
return;
|
|
132
154
|
}
|
|
133
155
|
this.timeoutHandle = setInterval(() => {
|
|
134
156
|
(0, controller_utils_1.safelyExecute)(async () => this.updateSmartTransactions());
|
|
135
|
-
}, this
|
|
157
|
+
}, __classPrivateFieldGet(this, _SmartTransactionsController_interval, "f"));
|
|
136
158
|
await (0, controller_utils_1.safelyExecute)(async () => this.updateSmartTransactions());
|
|
137
159
|
}
|
|
138
160
|
async stop() {
|
|
139
161
|
this.timeoutHandle && clearInterval(this.timeoutHandle);
|
|
140
162
|
this.timeoutHandle = undefined;
|
|
141
163
|
}
|
|
142
|
-
setOptInState(
|
|
143
|
-
this.update({
|
|
144
|
-
|
|
164
|
+
setOptInState(optInState) {
|
|
165
|
+
this.update((state) => {
|
|
166
|
+
state.smartTransactionsState.userOptInV2 = optInState;
|
|
145
167
|
});
|
|
146
168
|
}
|
|
147
169
|
trackStxStatusChange(smartTransaction, prevSmartTransaction) {
|
|
@@ -150,7 +172,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
150
172
|
if (updatedSmartTransaction.status === (prevSmartTransaction === null || prevSmartTransaction === void 0 ? void 0 : prevSmartTransaction.status)) {
|
|
151
173
|
return; // If status hasn't changed, don't track it again.
|
|
152
174
|
}
|
|
153
|
-
this.
|
|
175
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
|
|
154
176
|
event: constants_1.MetaMetricsEventName.StxStatusUpdated,
|
|
155
177
|
category: constants_1.MetaMetricsEventCategory.Transactions,
|
|
156
178
|
properties: (0, utils_1.getSmartTransactionMetricsProperties)(updatedSmartTransaction),
|
|
@@ -158,19 +180,18 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
158
180
|
});
|
|
159
181
|
}
|
|
160
182
|
isNewSmartTransaction(smartTransactionUuid) {
|
|
161
|
-
const {
|
|
162
|
-
const
|
|
163
|
-
const { smartTransactions } = smartTransactionsState;
|
|
164
|
-
const currentSmartTransactions = smartTransactions[chainId];
|
|
183
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
184
|
+
const currentSmartTransactions = smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")];
|
|
165
185
|
const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransactionUuid);
|
|
166
186
|
return currentIndex === -1 || currentIndex === undefined;
|
|
167
187
|
}
|
|
168
188
|
updateSmartTransaction(smartTransaction, { networkClientId } = {}) {
|
|
169
|
-
let
|
|
189
|
+
let ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f");
|
|
190
|
+
let chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
|
|
170
191
|
if (networkClientId) {
|
|
171
|
-
const
|
|
172
|
-
chainId =
|
|
173
|
-
ethQuery = new eth_query_1.default(
|
|
192
|
+
const { configuration, provider } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
|
193
|
+
chainId = configuration.chainId;
|
|
194
|
+
ethQuery = new eth_query_1.default(provider);
|
|
174
195
|
}
|
|
175
196
|
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_createOrUpdateSmartTransaction).call(this, smartTransaction, {
|
|
176
197
|
chainId,
|
|
@@ -178,7 +199,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
178
199
|
});
|
|
179
200
|
}
|
|
180
201
|
async updateSmartTransactions({ networkClientId, } = {}) {
|
|
181
|
-
const { smartTransactions } = this.state
|
|
202
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
182
203
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
183
204
|
const smartTransactionsForChainId = smartTransactions[chainId];
|
|
184
205
|
const transactionsToUpdate = smartTransactionsForChainId
|
|
@@ -198,7 +219,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
198
219
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
199
220
|
const ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getEthQuery).call(this, { networkClientId });
|
|
200
221
|
const url = `${(0, utils_1.getAPIRequestURL)(types_1.APIType.BATCH_STATUS, chainId)}?${params.toString()}`;
|
|
201
|
-
const data = (await this.
|
|
222
|
+
const data = (await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, url));
|
|
202
223
|
for (const [uuid, stxStatus] of Object.entries(data)) {
|
|
203
224
|
const smartTransaction = {
|
|
204
225
|
statusMetadata: stxStatus,
|
|
@@ -214,18 +235,18 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
214
235
|
return data;
|
|
215
236
|
}
|
|
216
237
|
async addNonceToTransaction(transaction) {
|
|
217
|
-
const nonceLock = await this.
|
|
238
|
+
const nonceLock = await __classPrivateFieldGet(this, _SmartTransactionsController_getNonceLock, "f").call(this, transaction.from);
|
|
218
239
|
const nonce = nonceLock.nextNonce;
|
|
219
240
|
nonceLock.releaseLock();
|
|
220
241
|
return Object.assign(Object.assign({}, transaction), { nonce: `0x${nonce.toString(16)}` });
|
|
221
242
|
}
|
|
222
243
|
clearFees() {
|
|
223
244
|
const fees = {
|
|
224
|
-
approvalTxFees:
|
|
225
|
-
tradeTxFees:
|
|
245
|
+
approvalTxFees: null,
|
|
246
|
+
tradeTxFees: null,
|
|
226
247
|
};
|
|
227
|
-
this.update({
|
|
228
|
-
|
|
248
|
+
this.update((state) => {
|
|
249
|
+
state.smartTransactionsState.fees = fees;
|
|
229
250
|
});
|
|
230
251
|
return fees;
|
|
231
252
|
}
|
|
@@ -247,7 +268,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
247
268
|
unsignedTradeTransactionWithNonce = await this.addNonceToTransaction(tradeTx);
|
|
248
269
|
}
|
|
249
270
|
transactions.push(unsignedTradeTransactionWithNonce);
|
|
250
|
-
const data = await this.
|
|
271
|
+
const data = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.GET_FEES, chainId), {
|
|
251
272
|
method: 'POST',
|
|
252
273
|
body: JSON.stringify({
|
|
253
274
|
txs: transactions,
|
|
@@ -260,18 +281,20 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
260
281
|
tradeTxFees = data === null || data === void 0 ? void 0 : data.txs[1];
|
|
261
282
|
}
|
|
262
283
|
else {
|
|
284
|
+
approvalTxFees = null;
|
|
263
285
|
tradeTxFees = data === null || data === void 0 ? void 0 : data.txs[0];
|
|
264
286
|
}
|
|
265
|
-
this.update({
|
|
266
|
-
|
|
267
|
-
fees
|
|
287
|
+
this.update((state) => {
|
|
288
|
+
if (chainId === __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")) {
|
|
289
|
+
state.smartTransactionsState.fees = {
|
|
268
290
|
approvalTxFees,
|
|
269
291
|
tradeTxFees,
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
state.smartTransactionsState.feesByChainId[chainId] = {
|
|
295
|
+
approvalTxFees,
|
|
296
|
+
tradeTxFees,
|
|
297
|
+
};
|
|
275
298
|
});
|
|
276
299
|
return {
|
|
277
300
|
approvalTxFees,
|
|
@@ -281,10 +304,10 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
281
304
|
// * After this successful call client must add a nonce representative to
|
|
282
305
|
// * transaction controller external transactions list
|
|
283
306
|
async submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions, networkClientId, }) {
|
|
284
|
-
var _a;
|
|
307
|
+
var _a, _b;
|
|
285
308
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
286
309
|
const ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getEthQuery).call(this, { networkClientId });
|
|
287
|
-
const data = await this.
|
|
310
|
+
const data = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.SUBMIT_TRANSACTIONS, chainId), {
|
|
288
311
|
method: 'POST',
|
|
289
312
|
body: JSON.stringify({
|
|
290
313
|
rawTxs: signedTransactions,
|
|
@@ -302,17 +325,15 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
302
325
|
catch (error) {
|
|
303
326
|
console.error('provider error', error);
|
|
304
327
|
}
|
|
305
|
-
const requiresNonce = !txParams.nonce;
|
|
328
|
+
const requiresNonce = txParams && !txParams.nonce;
|
|
306
329
|
let nonce;
|
|
307
330
|
let nonceLock;
|
|
308
331
|
let nonceDetails = {};
|
|
309
332
|
if (requiresNonce) {
|
|
310
|
-
nonceLock = await this.
|
|
333
|
+
nonceLock = await __classPrivateFieldGet(this, _SmartTransactionsController_getNonceLock, "f").call(this, txParams.from);
|
|
311
334
|
nonce = (0, bytes_1.hexlify)(nonceLock.nextNonce);
|
|
312
335
|
nonceDetails = nonceLock.nonceDetails;
|
|
313
|
-
|
|
314
|
-
(_a = txParams.nonce) !== null && _a !== void 0 ? _a : (txParams.nonce = nonce);
|
|
315
|
-
}
|
|
336
|
+
(_a = txParams.nonce) !== null && _a !== void 0 ? _a : (txParams.nonce = nonce);
|
|
316
337
|
}
|
|
317
338
|
const submitTransactionResponse = Object.assign(Object.assign({}, data), { txHash: (0, utils_1.getTxHash)(signedTransactions[0]) });
|
|
318
339
|
try {
|
|
@@ -326,7 +347,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
326
347
|
uuid: submitTransactionResponse.uuid,
|
|
327
348
|
txHash: submitTransactionResponse.txHash,
|
|
328
349
|
cancellable: true,
|
|
329
|
-
type: (transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.type)
|
|
350
|
+
type: (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.type) !== null && _b !== void 0 ? _b : 'swap',
|
|
330
351
|
}, { chainId, ethQuery });
|
|
331
352
|
}
|
|
332
353
|
finally {
|
|
@@ -339,7 +360,7 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
339
360
|
// in transaction controller external transactions list
|
|
340
361
|
async cancelSmartTransaction(uuid, { networkClientId, } = {}) {
|
|
341
362
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
342
|
-
await this.
|
|
363
|
+
await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.CANCEL, chainId), {
|
|
343
364
|
method: 'POST',
|
|
344
365
|
body: JSON.stringify({ uuid }),
|
|
345
366
|
});
|
|
@@ -348,20 +369,23 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
348
369
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
349
370
|
let liveness = false;
|
|
350
371
|
try {
|
|
351
|
-
const response = await this.
|
|
372
|
+
const response = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.LIVENESS, chainId));
|
|
352
373
|
liveness = Boolean(response.lastBlock);
|
|
353
374
|
}
|
|
354
375
|
catch (error) {
|
|
355
376
|
console.log('"fetchLiveness" API call failed');
|
|
356
377
|
}
|
|
357
|
-
this.update({
|
|
358
|
-
|
|
378
|
+
this.update((state) => {
|
|
379
|
+
if (chainId === __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")) {
|
|
380
|
+
state.smartTransactionsState.liveness = liveness;
|
|
381
|
+
}
|
|
382
|
+
state.smartTransactionsState.livenessByChainId[chainId] = liveness;
|
|
359
383
|
});
|
|
360
384
|
return liveness;
|
|
361
385
|
}
|
|
362
386
|
async setStatusRefreshInterval(interval) {
|
|
363
|
-
if (interval !== this
|
|
364
|
-
this
|
|
387
|
+
if (interval !== __classPrivateFieldGet(this, _SmartTransactionsController_interval, "f")) {
|
|
388
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
|
|
365
389
|
}
|
|
366
390
|
}
|
|
367
391
|
getTransactions({ addressFrom, status, }) {
|
|
@@ -388,53 +412,55 @@ class SmartTransactionsController extends polling_controller_1.StaticIntervalPol
|
|
|
388
412
|
}
|
|
389
413
|
const addressLowerCase = address.toLowerCase();
|
|
390
414
|
if (ignoreNetwork) {
|
|
391
|
-
const { smartTransactions } = this.state
|
|
415
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
392
416
|
Object.keys(smartTransactions).forEach((chainId) => {
|
|
393
|
-
const chainIdHex = chainId;
|
|
394
417
|
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_wipeSmartTransactionsPerChainId).call(this, {
|
|
395
|
-
chainId
|
|
418
|
+
chainId,
|
|
396
419
|
addressLowerCase,
|
|
397
420
|
});
|
|
398
421
|
});
|
|
399
422
|
}
|
|
400
423
|
else {
|
|
401
424
|
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_wipeSmartTransactionsPerChainId).call(this, {
|
|
402
|
-
chainId: this
|
|
425
|
+
chainId: __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"),
|
|
403
426
|
addressLowerCase,
|
|
404
427
|
});
|
|
405
428
|
}
|
|
406
429
|
}
|
|
407
430
|
}
|
|
408
431
|
exports.default = SmartTransactionsController;
|
|
409
|
-
|
|
432
|
+
_SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_getNonceLock = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_confirmExternalTransaction = new WeakMap(), _SmartTransactionsController_getRegularTransactions = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_fetch =
|
|
433
|
+
/* istanbul ignore next */
|
|
434
|
+
async function _SmartTransactionsController_fetch(request, options) {
|
|
435
|
+
const fetchOptions = Object.assign(Object.assign({}, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, (__classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") && { 'X-Client-Id': __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") })) });
|
|
436
|
+
return (0, utils_1.handleFetch)(request, fetchOptions);
|
|
437
|
+
}, _SmartTransactionsController_updateSmartTransaction = function _SmartTransactionsController_updateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), }) {
|
|
410
438
|
var _a;
|
|
411
|
-
const { smartTransactionsState } = this.state;
|
|
412
|
-
const { smartTransactions } = smartTransactionsState;
|
|
439
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
413
440
|
const currentSmartTransactions = (_a = smartTransactions[chainId]) !== null && _a !== void 0 ? _a : [];
|
|
414
441
|
const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransaction.uuid);
|
|
415
442
|
if (currentIndex === -1) {
|
|
416
443
|
return; // Smart transaction not found, don't update anything.
|
|
417
444
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
445
|
+
if (!(0, controller_utils_1.isSafeDynamicKey)(chainId)) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
this.update((state) => {
|
|
449
|
+
state.smartTransactionsState.smartTransactions[chainId][currentIndex] = Object.assign(Object.assign({}, state.smartTransactionsState.smartTransactions[chainId][currentIndex]), smartTransaction);
|
|
423
450
|
});
|
|
424
451
|
}, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction = async function _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction(smartTransaction) {
|
|
425
|
-
const metaMetricsProps = await this.
|
|
452
|
+
const metaMetricsProps = await __classPrivateFieldGet(this, _SmartTransactionsController_getMetaMetricsProps, "f").call(this);
|
|
426
453
|
smartTransaction.accountHardwareType =
|
|
427
454
|
metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.accountHardwareType;
|
|
428
455
|
smartTransaction.accountType = metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.accountType;
|
|
429
456
|
smartTransaction.deviceModel = metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.deviceModel;
|
|
430
|
-
}, _SmartTransactionsController_createOrUpdateSmartTransaction = async function _SmartTransactionsController_createOrUpdateSmartTransaction(smartTransaction, { chainId = this
|
|
457
|
+
}, _SmartTransactionsController_createOrUpdateSmartTransaction = async function _SmartTransactionsController_createOrUpdateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
|
|
431
458
|
var _a;
|
|
432
|
-
const { smartTransactionsState } = this.state;
|
|
433
|
-
const { smartTransactions } = smartTransactionsState;
|
|
459
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
434
460
|
const currentSmartTransactions = (_a = smartTransactions[chainId]) !== null && _a !== void 0 ? _a : [];
|
|
435
461
|
const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransaction.uuid);
|
|
436
462
|
const isNewSmartTransaction = this.isNewSmartTransaction(smartTransaction.uuid);
|
|
437
|
-
if (this
|
|
463
|
+
if (__classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f") === undefined) {
|
|
438
464
|
throw new Error(ETH_QUERY_ERROR_MSG);
|
|
439
465
|
}
|
|
440
466
|
if (isNewSmartTransaction) {
|
|
@@ -459,14 +485,15 @@ _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsContro
|
|
|
459
485
|
.concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))
|
|
460
486
|
.concat(historifiedSmartTransaction)
|
|
461
487
|
: currentSmartTransactions.concat(historifiedSmartTransaction);
|
|
462
|
-
this.update({
|
|
463
|
-
smartTransactionsState
|
|
488
|
+
this.update((state) => {
|
|
489
|
+
state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")] =
|
|
490
|
+
nextSmartTransactions;
|
|
464
491
|
});
|
|
465
492
|
return;
|
|
466
493
|
}
|
|
467
494
|
// We have to emit this event here, because then a txHash is returned to the TransactionController once it's available
|
|
468
495
|
// and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.
|
|
469
|
-
this.
|
|
496
|
+
this.messagingSystem.publish(`SmartTransactionsController:smartTransaction`, smartTransaction);
|
|
470
497
|
if ((smartTransaction.status === types_1.SmartTransactionStatuses.SUCCESS ||
|
|
471
498
|
smartTransaction.status === types_1.SmartTransactionStatuses.REVERTED) &&
|
|
472
499
|
!smartTransaction.confirmed) {
|
|
@@ -487,7 +514,7 @@ _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsContro
|
|
|
487
514
|
if (!txHash) {
|
|
488
515
|
return true;
|
|
489
516
|
}
|
|
490
|
-
const transactions = this.
|
|
517
|
+
const transactions = __classPrivateFieldGet(this, _SmartTransactionsController_getRegularTransactions, "f").call(this);
|
|
491
518
|
const foundTransaction = transactions === null || transactions === void 0 ? void 0 : transactions.find((tx) => {
|
|
492
519
|
var _a;
|
|
493
520
|
return ((_a = tx.hash) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === txHash.toLowerCase();
|
|
@@ -499,7 +526,7 @@ _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsContro
|
|
|
499
526
|
// When it's in the submitted state, the TransactionController checks its status and confirms it,
|
|
500
527
|
// so no need to confirm it again here.
|
|
501
528
|
return ![transaction_controller_1.TransactionStatus.confirmed, transaction_controller_1.TransactionStatus.submitted].includes(foundTransaction.status);
|
|
502
|
-
}, _SmartTransactionsController_confirmSmartTransaction = async function _SmartTransactionsController_confirmSmartTransaction(smartTransaction, { chainId = this
|
|
529
|
+
}, _SmartTransactionsController_confirmSmartTransaction = async function _SmartTransactionsController_confirmSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
|
|
503
530
|
var _a;
|
|
504
531
|
if (ethQuery === undefined) {
|
|
505
532
|
throw new Error(ETH_QUERY_ERROR_MSG);
|
|
@@ -526,9 +553,13 @@ _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsContro
|
|
|
526
553
|
const txMeta = entry.length > 0
|
|
527
554
|
? Object.assign(Object.assign({}, originalTxMeta), { history: originalTxMeta.history.concat(entry) }) : originalTxMeta;
|
|
528
555
|
if (__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_doesTransactionNeedConfirmation).call(this, txHash)) {
|
|
529
|
-
this
|
|
556
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_confirmExternalTransaction, "f").call(this,
|
|
557
|
+
// TODO: Replace 'as' assertion with correct typing for `txMeta`
|
|
558
|
+
txMeta, transactionReceipt,
|
|
559
|
+
// TODO: Replace 'as' assertion with correct typing for `baseFeePerGas`
|
|
560
|
+
baseFeePerGas);
|
|
530
561
|
}
|
|
531
|
-
this.
|
|
562
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
|
|
532
563
|
event: constants_1.MetaMetricsEventName.StxConfirmed,
|
|
533
564
|
category: constants_1.MetaMetricsEventCategory.Transactions,
|
|
534
565
|
properties: (0, utils_1.getSmartTransactionMetricsProperties)(smartTransaction),
|
|
@@ -540,42 +571,44 @@ _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsContro
|
|
|
540
571
|
}
|
|
541
572
|
}
|
|
542
573
|
catch (error) {
|
|
543
|
-
this.
|
|
574
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
|
|
544
575
|
event: constants_1.MetaMetricsEventName.StxConfirmationFailed,
|
|
545
576
|
category: constants_1.MetaMetricsEventCategory.Transactions,
|
|
546
577
|
});
|
|
547
578
|
console.error('confirm error', error);
|
|
548
579
|
}
|
|
549
580
|
}, _SmartTransactionsController_getChainId = function _SmartTransactionsController_getChainId({ networkClientId, } = {}) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
581
|
+
if (networkClientId) {
|
|
582
|
+
return this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
583
|
+
}
|
|
584
|
+
return __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
|
|
553
585
|
}, _SmartTransactionsController_getEthQuery = function _SmartTransactionsController_getEthQuery({ networkClientId, } = {}) {
|
|
554
586
|
if (networkClientId) {
|
|
555
|
-
|
|
587
|
+
const { provider } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
|
588
|
+
return new eth_query_1.default(provider);
|
|
556
589
|
}
|
|
557
|
-
if (this
|
|
590
|
+
if (__classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f") === undefined) {
|
|
558
591
|
throw new Error(ETH_QUERY_ERROR_MSG);
|
|
559
592
|
}
|
|
560
|
-
return this
|
|
593
|
+
return __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f");
|
|
561
594
|
}, _SmartTransactionsController_getCurrentSmartTransactions = function _SmartTransactionsController_getCurrentSmartTransactions() {
|
|
562
|
-
const { smartTransactions } = this.state
|
|
563
|
-
const
|
|
564
|
-
const currentSmartTransactions = smartTransactions === null || smartTransactions === void 0 ? void 0 : smartTransactions[chainId];
|
|
595
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
596
|
+
const currentSmartTransactions = smartTransactions === null || smartTransactions === void 0 ? void 0 : smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")];
|
|
565
597
|
if (!currentSmartTransactions || currentSmartTransactions.length === 0) {
|
|
566
598
|
return [];
|
|
567
599
|
}
|
|
568
600
|
return currentSmartTransactions;
|
|
569
601
|
}, _SmartTransactionsController_wipeSmartTransactionsPerChainId = function _SmartTransactionsController_wipeSmartTransactionsPerChainId({ chainId, addressLowerCase, }) {
|
|
570
|
-
const { smartTransactions } = this.state
|
|
602
|
+
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
571
603
|
const smartTransactionsForSelectedChain = smartTransactions === null || smartTransactions === void 0 ? void 0 : smartTransactions[chainId];
|
|
572
604
|
if (!smartTransactionsForSelectedChain ||
|
|
573
605
|
smartTransactionsForSelectedChain.length === 0) {
|
|
574
606
|
return;
|
|
575
607
|
}
|
|
576
608
|
const newSmartTransactionsForSelectedChain = smartTransactionsForSelectedChain.filter((smartTransaction) => { var _a; return ((_a = smartTransaction.txParams) === null || _a === void 0 ? void 0 : _a.from) !== addressLowerCase; });
|
|
577
|
-
this.update({
|
|
578
|
-
|
|
609
|
+
this.update((state) => {
|
|
610
|
+
state.smartTransactionsState.smartTransactions[chainId] =
|
|
611
|
+
newSmartTransactionsForSelectedChain;
|
|
579
612
|
});
|
|
580
613
|
};
|
|
581
614
|
//# sourceMappingURL=SmartTransactionsController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.js","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,gDAA+C;AAE/C,iEAA2E;AAC3E,oEAA2C;AAM3C,qEAAiF;AAEjF,6EAAqE;AACrE,+CAAyC;AACzC,oDAAoD;AACpD,oDAAkC;AAClC,iEAAyC;AAEzC,2CAA6E;AAa7E,mCAA4D;AAC5D,mCAaiB;AAEjB,MAAM,MAAM,GAAG,IAAI,CAAC;AACP,QAAA,gBAAgB,GAAG,MAAM,GAAG,CAAC,CAAC;AAC3C,MAAM,mBAAmB,GACvB,0DAA0D,CAAC;AA0B7D,MAAqB,2BAA4B,SAAQ,sDAGxD;IAwCC,YACE,EACE,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GAWpB,EACD,MAAmD,EACnD,K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ACxC,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;QACV,sBAAsB,kCACjB,IAAI,CAAC,KAAK,CAAC,sBAAsB,KACpC,iBAAiB,kCACZ,iBAAiB,KACpB,CAAC,OAAO,CAAC,EAAE,oCAAoC,MAElD;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["// eslint-disable-next-line import/no-nodejs-modules\nimport { hexlify } from '@ethersproject/bytes';\nimport type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { query, safelyExecute, ChainId } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClientId,\n NetworkController,\n NetworkState,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n// eslint-disable-next-line import/no-nodejs-modules\nimport EventEmitter from 'events';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport { MetaMetricsEventCategory, MetaMetricsEventName } from './constants';\nimport type {\n Fees,\n Hex,\n IndividualTxFees,\n SignedCanceledTransaction,\n SignedTransaction,\n SmartTransaction,\n SmartTransactionsStatus,\n UnsignedTransaction,\n GetTransactionsOptions,\n MetaMetricsProps,\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} 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\nexport type SmartTransactionsControllerConfig = BaseConfig & {\n interval: number;\n clientId: string;\n chainId: Hex;\n supportedChainIds: Hex[];\n};\n\ntype FeeEstimates = {\n approvalTxFees: IndividualTxFees | undefined;\n tradeTxFees: IndividualTxFees | undefined;\n};\n\nexport type SmartTransactionsControllerState = BaseState & {\n smartTransactionsState: {\n smartTransactions: Record<Hex, SmartTransaction[]>;\n userOptIn: boolean | undefined;\n userOptInV2: boolean | undefined;\n liveness: boolean | undefined;\n fees: FeeEstimates;\n feesByChainId: Record<Hex, FeeEstimates>;\n livenessByChainId: Record<Hex, boolean>;\n };\n};\n\nexport default class SmartTransactionsController extends StaticIntervalPollingControllerV1<\n SmartTransactionsControllerConfig,\n SmartTransactionsControllerState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'SmartTransactionsController';\n\n public timeoutHandle?: NodeJS.Timeout;\n\n private readonly getNonceLock: any;\n\n private ethQuery: EthQuery | undefined;\n\n public confirmExternalTransaction: any;\n\n public getRegularTransactions: (\n options?: GetTransactionsOptions,\n ) => TransactionMeta[];\n\n private readonly trackMetaMetricsEvent: any;\n\n public eventEmitter: EventEmitter;\n\n private readonly getNetworkClientById: NetworkController['getNetworkClientById'];\n\n private readonly getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n\n /* istanbul ignore next */\n private async fetch(request: string, options?: RequestInit) {\n const { clientId } = this.config;\n const fetchOptions = {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...(clientId && { 'X-Client-Id': clientId }),\n },\n };\n\n return handleFetch(request, fetchOptions);\n }\n\n constructor(\n {\n onNetworkStateChange,\n getNonceLock,\n confirmExternalTransaction,\n getTransactions,\n trackMetaMetricsEvent,\n getNetworkClientById,\n getMetaMetricsProps,\n }: {\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n getNonceLock: any;\n confirmExternalTransaction: any;\n getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];\n trackMetaMetricsEvent: any;\n getNetworkClientById: NetworkController['getNetworkClientById'];\n getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n },\n config?: Partial<SmartTransactionsControllerConfig>,\n state?: Partial<SmartTransactionsControllerState>,\n ) {\n super(config, state);\n\n this.defaultConfig = {\n interval: DEFAULT_INTERVAL,\n chainId: ChainId.mainnet,\n clientId: 'default',\n supportedChainIds: [ChainId.mainnet, ChainId.sepolia],\n };\n\n this.defaultState = {\n smartTransactionsState: {\n smartTransactions: {},\n userOptIn: undefined,\n userOptInV2: undefined,\n fees: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n liveness: true,\n livenessByChainId: {\n [ChainId.mainnet]: true,\n [ChainId.sepolia]: true,\n },\n feesByChainId: {\n [ChainId.mainnet]: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n [ChainId.sepolia]: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n },\n },\n };\n\n this.initialize();\n this.setIntervalLength(this.config.interval);\n this.getNonceLock = getNonceLock;\n this.ethQuery = undefined;\n this.confirmExternalTransaction = confirmExternalTransaction;\n this.getRegularTransactions = getTransactions;\n this.trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.getNetworkClientById = getNetworkClientById;\n this.getMetaMetricsProps = getMetaMetricsProps;\n\n this.initializeSmartTransactionsForChainId();\n\n onNetworkStateChange(({ selectedNetworkClientId }) => {\n const {\n configuration: { chainId },\n provider,\n } = this.getNetworkClientById(selectedNetworkClientId);\n this.configure({ chainId });\n this.ethQuery = new EthQuery(provider);\n this.initializeSmartTransactionsForChainId();\n this.checkPoll(this.state);\n });\n\n this.subscribe((currentState: any) => this.checkPoll(currentState));\n this.eventEmitter = new EventEmitter();\n }\n\n async _executePoll(networkClientId: string): 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 chainId = this.#getChainId({ networkClientId });\n if (!this.config.supportedChainIds.includes(chainId)) {\n return Promise.resolve();\n }\n return this.updateSmartTransactions({ networkClientId });\n }\n\n checkPoll(state: any) {\n const { smartTransactions } = state.smartTransactionsState;\n const currentSmartTransactions = smartTransactions[this.config.chainId];\n const pendingTransactions = currentSmartTransactions?.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.config.supportedChainIds.includes(this.config.chainId)) {\n const { smartTransactionsState } = this.state;\n this.update({\n smartTransactionsState: {\n ...smartTransactionsState,\n smartTransactions: {\n ...smartTransactionsState.smartTransactions,\n [this.config.chainId]:\n smartTransactionsState.smartTransactions[this.config.chainId] ??\n [],\n },\n },\n });\n }\n }\n\n async poll(interval?: number): Promise<void> {\n const { chainId, supportedChainIds } = this.config;\n interval && this.configure({ interval }, false, false);\n this.timeoutHandle && clearInterval(this.timeoutHandle);\n if (!supportedChainIds.includes(chainId)) {\n return;\n }\n this.timeoutHandle = setInterval(() => {\n safelyExecute(async () => this.updateSmartTransactions());\n }, this.config.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(state: boolean | undefined): void {\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n userOptInV2: state,\n },\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): boolean {\n const { chainId } = this.config;\n const { smartTransactionsState } = this.state;\n const { smartTransactions } = smartTransactionsState;\n const currentSmartTransactions = smartTransactions[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 {\n ethQuery,\n config: { chainId },\n } = this;\n if (networkClientId) {\n const networkClient = this.getNetworkClientById(networkClientId);\n chainId = networkClient.configuration.chainId;\n ethQuery = new EthQuery(networkClient.provider);\n }\n\n this.#createOrUpdateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n #updateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.config.chainId,\n }: {\n chainId: Hex;\n },\n ) {\n const { smartTransactionsState } = this.state;\n const { smartTransactions } = smartTransactionsState;\n const currentSmartTransactions = smartTransactions[chainId] ?? [];\n const currentIndex = currentSmartTransactions?.findIndex(\n (stx) => stx.uuid === smartTransaction.uuid,\n );\n if (currentIndex === -1) {\n return; // Smart transaction not found, don't update anything.\n }\n this.update({\n smartTransactionsState: {\n ...smartTransactionsState,\n smartTransactions: {\n ...smartTransactionsState.smartTransactions,\n [chainId]: smartTransactionsState.smartTransactions[chainId].map(\n (existingSmartTransaction, index) => {\n return index === currentIndex\n ? { ...existingSmartTransaction, ...smartTransaction }\n : existingSmartTransaction;\n },\n ),\n },\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.config.chainId,\n ethQuery = this.ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery | undefined;\n },\n ): Promise<void> {\n const { smartTransactionsState } = this.state;\n const { smartTransactions } = smartTransactionsState;\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 );\n if (this.ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n if (isNewSmartTransaction) {\n await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);\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 this.update({\n smartTransactionsState: {\n ...smartTransactionsState,\n smartTransactions: {\n ...smartTransactionsState.smartTransactions,\n [chainId]: nextSmartTransactions,\n },\n },\n });\n return;\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.eventEmitter.emit(\n `${smartTransaction.uuid}:smartTransaction`,\n smartTransaction,\n );\n\n if (\n (smartTransaction.status === SmartTransactionStatuses.SUCCESS ||\n smartTransaction.status === SmartTransactionStatuses.REVERTED) &&\n !smartTransaction.confirmed\n ) {\n // confirm smart transaction\n const currentSmartTransaction = currentSmartTransactions[currentIndex];\n const nextSmartTransaction = {\n ...currentSmartTransaction,\n ...smartTransaction,\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 networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): Promise<void> {\n const { smartTransactions } = this.state.smartTransactionsState;\n const chainId = this.#getChainId({ networkClientId });\n const smartTransactionsForChainId = smartTransactions[chainId];\n\n const transactionsToUpdate: string[] = smartTransactionsForChainId\n .filter(isSmartTransactionPending)\n .map((smartTransaction) => smartTransaction.uuid);\n\n if (transactionsToUpdate.length > 0) {\n this.fetchSmartTransactionsStatus(transactionsToUpdate, {\n networkClientId,\n });\n }\n }\n\n #doesTransactionNeedConfirmation(txHash: string | undefined): boolean {\n if (!txHash) {\n return true;\n }\n const transactions = this.getRegularTransactions();\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.config.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?: string } | 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.confirmExternalTransaction(\n txMeta,\n transactionReceipt,\n baseFeePerGas,\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 }\n }\n\n // ! Ask backend API to accept list of uuids as params\n async fetchSmartTransactionsStatus(\n uuids: string[],\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ): Promise<Record<string, SmartTransactionsStatus>> {\n const params = new URLSearchParams({\n uuids: uuids.join(','),\n });\n const chainId = this.#getChainId({ networkClientId });\n const ethQuery = this.#getEthQuery({ networkClientId });\n const url = `${getAPIRequestURL(\n APIType.BATCH_STATUS,\n chainId,\n )}?${params.toString()}`;\n\n const data = (await this.fetch(url)) as Record<\n string,\n SmartTransactionsStatus\n >;\n\n for (const [uuid, stxStatus] of Object.entries(data)) {\n const smartTransaction: SmartTransaction = {\n statusMetadata: stxStatus,\n status: calculateStatus(stxStatus),\n cancellable: isSmartTransactionCancellable(stxStatus),\n uuid,\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 ): Promise<UnsignedTransaction> {\n const nonceLock = await this.getNonceLock(transaction.from);\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: undefined,\n tradeTxFees: undefined,\n };\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n 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 chainId = this.#getChainId({ networkClientId });\n const transactions = [];\n let unsignedTradeTransactionWithNonce;\n if (approvalTx) {\n const unsignedApprovalTransactionWithNonce =\n await this.addNonceToTransaction(approvalTx);\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 );\n }\n transactions.push(unsignedTradeTransactionWithNonce);\n const data = await this.fetch(getAPIRequestURL(APIType.GET_FEES, chainId), {\n method: 'POST',\n body: JSON.stringify({\n txs: transactions,\n }),\n });\n let approvalTxFees;\n let tradeTxFees;\n if (approvalTx) {\n approvalTxFees = data?.txs[0];\n tradeTxFees = data?.txs[1];\n } else {\n tradeTxFees = data?.txs[0];\n }\n\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n ...(chainId === this.config.chainId && {\n fees: {\n approvalTxFees,\n tradeTxFees,\n },\n }),\n feesByChainId: {\n ...this.state.smartTransactionsState.feesByChainId,\n [chainId]: {\n approvalTxFees,\n tradeTxFees,\n },\n },\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?: any;\n txParams?: any;\n networkClientId?: NetworkClientId;\n }) {\n const chainId = this.#getChainId({ networkClientId });\n const ethQuery = this.#getEthQuery({ networkClientId });\n const data = 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 const time = Date.now();\n let preTxBalance;\n try {\n const preTxBalanceBN = await query(ethQuery, 'getBalance', [\n txParams?.from,\n ]);\n preTxBalance = new BigNumber(preTxBalanceBN).toString(16);\n } catch (error) {\n console.error('provider error', error);\n }\n\n const requiresNonce = !txParams.nonce;\n let nonce;\n let nonceLock;\n let nonceDetails = {};\n\n if (requiresNonce) {\n nonceLock = await this.getNonceLock(txParams?.from);\n nonce = hexlify(nonceLock.nextNonce);\n nonceDetails = nonceLock.nonceDetails;\n if (txParams) {\n txParams.nonce ??= nonce;\n }\n }\n const submitTransactionResponse = {\n ...data,\n txHash: getTxHash(signedTransactions[0]),\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 },\n { chainId, ethQuery },\n );\n } finally {\n nonceLock?.releaseLock();\n }\n\n return submitTransactionResponse;\n }\n\n #getChainId({\n networkClientId,\n }: { networkClientId?: NetworkClientId } = {}): Hex {\n return networkClientId\n ? this.getNetworkClientById(networkClientId).configuration.chainId\n : this.config.chainId;\n }\n\n #getEthQuery({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): EthQuery {\n if (networkClientId) {\n return new EthQuery(this.getNetworkClientById(networkClientId).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.fetch(getAPIRequestURL(APIType.CANCEL, chainId), {\n method: 'POST',\n body: JSON.stringify({ uuid }),\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.fetch(\n getAPIRequestURL(APIType.LIVENESS, chainId),\n );\n liveness = Boolean(response.lastBlock);\n } catch (error) {\n console.log('\"fetchLiveness\" API call failed');\n }\n\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n ...(chainId === this.config.chainId && { liveness }),\n livenessByChainId: {\n ...this.state.smartTransactionsState.livenessByChainId,\n [chainId]: liveness,\n },\n },\n });\n\n return liveness;\n }\n\n async setStatusRefreshInterval(interval: number): Promise<void> {\n if (interval !== this.config.interval) {\n this.configure({ interval }, false, false);\n }\n }\n\n #getCurrentSmartTransactions(): SmartTransaction[] {\n const { smartTransactions } = this.state.smartTransactionsState;\n const { chainId } = this.config;\n const currentSmartTransactions = smartTransactions?.[chainId];\n if (!currentSmartTransactions || currentSmartTransactions.length === 0) {\n return [];\n }\n return currentSmartTransactions;\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 { smartTransactions } = this.state.smartTransactionsState;\n Object.keys(smartTransactions).forEach((chainId) => {\n const chainIdHex: Hex = chainId as Hex;\n this.#wipeSmartTransactionsPerChainId({\n chainId: chainIdHex,\n addressLowerCase,\n });\n });\n } else {\n this.#wipeSmartTransactionsPerChainId({\n chainId: this.config.chainId,\n addressLowerCase,\n });\n }\n }\n\n #wipeSmartTransactionsPerChainId({\n chainId,\n addressLowerCase,\n }: {\n chainId: Hex;\n addressLowerCase: string;\n }): void {\n const { smartTransactions } = this.state.smartTransactionsState;\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({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n smartTransactions: {\n ...smartTransactions,\n [chainId]: newSmartTransactionsForSelectedChain,\n },\n },\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SmartTransactionsController.js","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAA+C;AAM/C,iEAKoC;AACpC,oEAA2C;AAM3C,qEAA+E;AAM/E,6EAAqE;AACrE,+CAAyC;AACzC,iEAAyC;AAEzC,2CAA6E;AAa7E,mCAA4D;AAC5D,mCAaiB;AAEjB,MAAM,MAAM,GAAG,IAAI,CAAC;AACP,QAAA,gBAAgB,GAAG,MAAM,GAAG,CAAC,CAAC;AAC3C,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,mBAAmB,GACvB,0DAA0D,CAAC;AAE7D;;GAEG;AACH,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,kBAAkB,GAAG;IACzB,sBAAsB,EAAE;QACtB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;KAChB;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,EAA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A,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 RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport {\n query,\n safelyExecute,\n ChainId,\n isSafeDynamicKey,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n TransactionController,\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 { MetaMetricsEventCategory, MetaMetricsEventName } from './constants';\nimport type {\n Fees,\n Hex,\n IndividualTxFees,\n SignedCanceledTransaction,\n SignedTransaction,\n SmartTransaction,\n SmartTransactionsStatus,\n UnsignedTransaction,\n GetTransactionsOptions,\n MetaMetricsProps,\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} from './utils';\n\nconst SECOND = 1000;\nexport const DEFAULT_INTERVAL = SECOND * 5;\nconst DEFAULT_CLIENT_ID = 'default';\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 = {\n smartTransactionsState: {\n persist: false,\n anonymous: 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\nexport type AllowedActions = NetworkControllerGetNetworkClientByIdAction;\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\n/**\n * The events that {@link SmartTransactionsController} can emit.\n */\nexport type SmartTransactionsControllerEvents =\n | SmartTransactionsControllerStateChangeEvent\n | SmartTransactionsControllerSmartTransactionEvent;\n\nexport type AllowedEvents = NetworkControllerStateChangeEvent;\n\n/**\n * The messenger of the {@link SmartTransactionsController}.\n */\nexport type SmartTransactionsControllerMessenger =\n RestrictedControllerMessenger<\n typeof controllerName,\n SmartTransactionsControllerActions | AllowedActions,\n SmartTransactionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n >;\n\ntype SmartTransactionsControllerOptions = {\n interval?: number;\n clientId?: string;\n chainId?: Hex;\n supportedChainIds?: Hex[];\n getNonceLock: TransactionController['getNonceLock'];\n confirmExternalTransaction: TransactionController['confirmExternalTransaction'];\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 getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];\n getMetaMetricsProps: () => Promise<MetaMetricsProps>;\n};\n\nexport default class SmartTransactionsController extends StaticIntervalPollingController<\n typeof controllerName,\n SmartTransactionsControllerState,\n SmartTransactionsControllerMessenger\n> {\n #interval: number;\n\n #clientId: string;\n\n #chainId: Hex;\n\n #supportedChainIds: Hex[];\n\n timeoutHandle?: NodeJS.Timeout;\n\n readonly #getNonceLock: SmartTransactionsControllerOptions['getNonceLock'];\n\n #ethQuery: EthQuery | undefined;\n\n #confirmExternalTransaction: SmartTransactionsControllerOptions['confirmExternalTransaction'];\n\n #getRegularTransactions: (\n options?: GetTransactionsOptions,\n ) => TransactionMeta[];\n\n readonly #trackMetaMetricsEvent: SmartTransactionsControllerOptions['trackMetaMetricsEvent'];\n\n readonly #getMetaMetricsProps: () => Promise<MetaMetricsProps>;\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 = DEFAULT_CLIENT_ID,\n chainId: InitialChainId = ChainId.mainnet,\n supportedChainIds = [ChainId.mainnet, ChainId.sepolia],\n getNonceLock,\n confirmExternalTransaction,\n trackMetaMetricsEvent,\n state = {},\n messenger,\n getTransactions,\n getMetaMetricsProps,\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.#getNonceLock = getNonceLock;\n this.#ethQuery = undefined;\n this.#confirmExternalTransaction = confirmExternalTransaction;\n this.#getRegularTransactions = getTransactions;\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.#getMetaMetricsProps = getMetaMetricsProps;\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(networkClientId: string): 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 chainId = this.#getChainId({ networkClientId });\n if (!this.#supportedChainIds.includes(chainId)) {\n return Promise.resolve();\n }\n return this.updateSmartTransactions({ networkClientId });\n }\n\n checkPoll({\n smartTransactionsState: { smartTransactions },\n }: SmartTransactionsControllerState) {\n const currentSmartTransactions = smartTransactions[this.#chainId];\n const pendingTransactions = currentSmartTransactions?.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): boolean {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const currentSmartTransactions = smartTransactions[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 );\n if (this.#ethQuery === undefined) {\n throw new Error(ETH_QUERY_ERROR_MSG);\n }\n\n if (isNewSmartTransaction) {\n await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);\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[this.#chainId] =\n nextSmartTransactions;\n });\n return;\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 smartTransaction,\n );\n\n if (\n (smartTransaction.status === SmartTransactionStatuses.SUCCESS ||\n smartTransaction.status === SmartTransactionStatuses.REVERTED) &&\n !smartTransaction.confirmed\n ) {\n // confirm smart transaction\n const currentSmartTransaction = currentSmartTransactions[currentIndex];\n const nextSmartTransaction = {\n ...currentSmartTransaction,\n ...smartTransaction,\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 networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {}): Promise<void> {\n const {\n smartTransactionsState: { smartTransactions },\n } = this.state;\n const chainId = this.#getChainId({ networkClientId });\n const smartTransactionsForChainId = smartTransactions[chainId];\n\n const transactionsToUpdate: string[] = smartTransactionsForChainId\n .filter(isSmartTransactionPending)\n .map((smartTransaction) => smartTransaction.uuid);\n\n if (transactionsToUpdate.length > 0) {\n this.fetchSmartTransactionsStatus(transactionsToUpdate, {\n networkClientId,\n });\n }\n }\n\n #doesTransactionNeedConfirmation(txHash: string | undefined): boolean {\n if (!txHash) {\n return true;\n }\n const transactions = this.#getRegularTransactions();\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.#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 }\n }\n\n // ! Ask backend API to accept list of uuids as params\n async fetchSmartTransactionsStatus(\n uuids: string[],\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ): Promise<Record<string, SmartTransactionsStatus>> {\n const params = new URLSearchParams({\n uuids: uuids.join(','),\n });\n const chainId = this.#getChainId({ networkClientId });\n const ethQuery = this.#getEthQuery({ networkClientId });\n const url = `${getAPIRequestURL(\n APIType.BATCH_STATUS,\n chainId,\n )}?${params.toString()}`;\n\n const data = (await this.#fetch(url)) as Record<\n string,\n SmartTransactionsStatus\n >;\n\n for (const [uuid, stxStatus] of Object.entries(data)) {\n const smartTransaction: SmartTransaction = {\n statusMetadata: stxStatus,\n status: calculateStatus(stxStatus),\n cancellable: isSmartTransactionCancellable(stxStatus),\n uuid,\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 ): Promise<UnsignedTransaction> {\n const nonceLock = await this.#getNonceLock(transaction.from);\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 chainId = this.#getChainId({ networkClientId });\n const transactions = [];\n let unsignedTradeTransactionWithNonce;\n if (approvalTx) {\n const unsignedApprovalTransactionWithNonce =\n await this.addNonceToTransaction(approvalTx);\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 );\n }\n transactions.push(unsignedTradeTransactionWithNonce);\n const data = await this.#fetch(\n getAPIRequestURL(APIType.GET_FEES, chainId),\n {\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 chainId = this.#getChainId({ networkClientId });\n const ethQuery = this.#getEthQuery({ networkClientId });\n const data = 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 const time = Date.now();\n let preTxBalance;\n try {\n const preTxBalanceBN = await query(ethQuery, 'getBalance', [\n txParams?.from,\n ]);\n preTxBalance = new BigNumber(preTxBalanceBN).toString(16);\n } catch (error) {\n console.error('provider error', error);\n }\n\n const requiresNonce = txParams && !txParams.nonce;\n let nonce;\n let nonceLock;\n let nonceDetails = {};\n\n if (requiresNonce) {\n nonceLock = await this.#getNonceLock(txParams.from);\n nonce = hexlify(nonceLock.nextNonce);\n nonceDetails = nonceLock.nonceDetails;\n txParams.nonce ??= nonce;\n }\n const submitTransactionResponse = {\n ...data,\n txHash: getTxHash(signedTransactions[0]),\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 },\n { chainId, ethQuery },\n );\n } finally {\n nonceLock?.releaseLock();\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 #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.#fetch(getAPIRequestURL(APIType.CANCEL, chainId), {\n method: 'POST',\n body: JSON.stringify({ uuid }),\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.#fetch(\n getAPIRequestURL(APIType.LIVENESS, chainId),\n );\n liveness = Boolean(response.lastBlock);\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 currentSmartTransactions = smartTransactions?.[this.#chainId];\n if (!currentSmartTransactions || currentSmartTransactions.length === 0) {\n return [];\n }\n return currentSmartTransactions;\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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export { default } from './SmartTransactionsController';
|
|
2
|
+
export type { SmartTransactionsControllerMessenger, SmartTransactionsControllerState, SmartTransactionsControllerGetStateAction, SmartTransactionsControllerActions, SmartTransactionsControllerStateChangeEvent, SmartTransactionsControllerSmartTransactionEvent, SmartTransactionsControllerEvents, } from './SmartTransactionsController';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var SmartTransactionsController_1 = require("./SmartTransactionsController");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(SmartTransactionsController_1).default; } });
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,6EAAwD;AAA/C,uIAAA,OAAO,OAAA","sourcesContent":["export { default } from './SmartTransactionsController';\nexport type {\n SmartTransactionsControllerMessenger,\n SmartTransactionsControllerState,\n SmartTransactionsControllerGetStateAction,\n SmartTransactionsControllerActions,\n SmartTransactionsControllerStateChangeEvent,\n SmartTransactionsControllerSmartTransactionEvent,\n SmartTransactionsControllerEvents,\n} from './SmartTransactionsController';\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -97,8 +97,8 @@ export declare type IndividualTxFees = {
|
|
|
97
97
|
gasUsed: number;
|
|
98
98
|
};
|
|
99
99
|
export declare type Fees = {
|
|
100
|
-
approvalTxFees: IndividualTxFees |
|
|
101
|
-
tradeTxFees: IndividualTxFees |
|
|
100
|
+
approvalTxFees: IndividualTxFees | null;
|
|
101
|
+
tradeTxFees: IndividualTxFees | null;
|
|
102
102
|
};
|
|
103
103
|
export declare type UnsignedTransaction = any;
|
|
104
104
|
export declare type SignedTransaction = any;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,UAAU;AACV,IAAY,OAOX;AAPD,WAAY,OAAO;IACjB,6CAAU,CAAA;IACV,qDAAc,CAAA;IACd,mEAAqB,CAAA;IACrB,yCAAQ,CAAA;IACR,qDAAc,CAAA;IACd,6CAAU,CAAA;AACZ,CAAC,EAPW,OAAO,GAAP,eAAO,KAAP,eAAO,QAOlB;AAED,wBAAwB;AACxB,IAAY,uBAMX;AAND,WAAY,uBAAuB;IACjC,kDAAuB,CAAA;IACvB,8CAAmB,CAAA;IACnB,kDAAuB,CAAA;IACvB,gDAAqB,CAAA;IACrB,8CAAmB,CAAA;AACrB,CAAC,EANW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAMlC;AAED,IAAY,kCAQX;AARD,WAAY,kCAAkC;IAC5C,mEAA6B,CAAA;IAC7B,6DAAuB,CAAA;IACvB,yEAAmC,CAAA;IACnC,qEAA+B,CAAA;IAC/B,uEAAiC,CAAA;IACjC,qEAA+B,CAAA;IAC/B,qFAA+C,CAAA;AACjD,CAAC,EARW,kCAAkC,GAAlC,0CAAkC,KAAlC,0CAAkC,QAQ7C;AAED,IAAY,wBAaX;AAbD,WAAY,wBAAwB;IAClC,+CAAmB,CAAA;IACnB,+CAAmB,CAAA;IACnB,iDAAqB,CAAA;IACrB,+CAAmB,CAAA;IACnB,mDAAuB,CAAA;IACvB,6EAAiD,CAAA;IACjD,uEAA2C,CAAA;IAC3C,mFAAuD,CAAA;IACvD,+EAAmD,CAAA;IACnD,iFAAqD,CAAA;IACrD,+FAAmE,CAAA;IACnE,iDAAqB,CAAA;AACvB,CAAC,EAbW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAanC;AAEY,QAAA,6BAA6B,GAAG;IAC3C,CAAC,kCAAkC,CAAC,YAAY,CAAC,EAC/C,wBAAwB,CAAC,sBAAsB;IACjD,CAAC,kCAAkC,CAAC,SAAS,CAAC,EAC5C,wBAAwB,CAAC,mBAAmB;IAC9C,CAAC,kCAAkC,CAAC,eAAe,CAAC,EAClD,wBAAwB,CAAC,yBAAyB;IACpD,CAAC,kCAAkC,CAAC,aAAa,CAAC,EAChD,wBAAwB,CAAC,uBAAuB;IAClD,CAAC,kCAAkC,CAAC,cAAc,CAAC,EACjD,wBAAwB,CAAC,wBAAwB;IACnD,CAAC,kCAAkC,CAAC,qBAAqB,CAAC,EACxD,wBAAwB,CAAC,+BAA+B;CAC3D,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\n\n/** API */\nexport enum APIType {\n 'GET_FEES',\n 'ESTIMATE_GAS',\n 'SUBMIT_TRANSACTIONS',\n 'CANCEL',\n 'BATCH_STATUS',\n 'LIVENESS',\n}\n\n/** SmartTransactions */\nexport enum SmartTransactionMinedTx {\n NOT_MINED = 'not_mined',\n SUCCESS = 'success',\n CANCELLED = 'cancelled',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n}\n\nexport enum SmartTransactionCancellationReason {\n WOULD_REVERT = 'would_revert',\n TOO_CHEAP = 'too_cheap',\n DEADLINE_MISSED = 'deadline_missed',\n INVALID_NONCE = 'invalid_nonce',\n USER_CANCELLED = 'user_cancelled',\n NOT_CANCELLED = 'not_cancelled',\n PREVIOUS_TX_CANCELLED = 'previous_tx_cancelled',\n}\n\nexport enum SmartTransactionStatuses {\n PENDING = 'pending',\n SUCCESS = 'success',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n CANCELLED = 'cancelled',\n CANCELLED_WOULD_REVERT = 'cancelled_would_revert',\n CANCELLED_TOO_CHEAP = 'cancelled_too_cheap',\n CANCELLED_DEADLINE_MISSED = 'cancelled_deadline_missed',\n CANCELLED_INVALID_NONCE = 'cancelled_invalid_nonce',\n CANCELLED_USER_CANCELLED = 'cancelled_user_cancelled',\n CANCELLED_PREVIOUS_TX_CANCELLED = 'cancelled_previous_tx_cancelled',\n RESOLVED = 'resolved',\n}\n\nexport const cancellationReasonToStatusMap = {\n [SmartTransactionCancellationReason.WOULD_REVERT]:\n SmartTransactionStatuses.CANCELLED_WOULD_REVERT,\n [SmartTransactionCancellationReason.TOO_CHEAP]:\n SmartTransactionStatuses.CANCELLED_TOO_CHEAP,\n [SmartTransactionCancellationReason.DEADLINE_MISSED]:\n SmartTransactionStatuses.CANCELLED_DEADLINE_MISSED,\n [SmartTransactionCancellationReason.INVALID_NONCE]:\n SmartTransactionStatuses.CANCELLED_INVALID_NONCE,\n [SmartTransactionCancellationReason.USER_CANCELLED]:\n SmartTransactionStatuses.CANCELLED_USER_CANCELLED,\n [SmartTransactionCancellationReason.PREVIOUS_TX_CANCELLED]:\n SmartTransactionStatuses.CANCELLED_PREVIOUS_TX_CANCELLED,\n};\n\nexport type SmartTransactionsStatus = {\n error?: string;\n cancellationFeeWei: number;\n cancellationReason?: SmartTransactionCancellationReason;\n deadlineRatio: number;\n minedHash: string;\n minedTx: SmartTransactionMinedTx;\n isSettled: boolean;\n duplicated?: boolean;\n timedOut?: boolean;\n proxied?: boolean;\n};\n\nexport type SmartTransaction = {\n uuid: string;\n txHash?: string;\n chainId?: string;\n destinationTokenAddress?: string;\n destinationTokenDecimals?: string;\n destinationTokenSymbol?: string;\n history?: any;\n nonceDetails?: any;\n origin?: string;\n preTxBalance?: string;\n status?: string;\n statusMetadata?: SmartTransactionsStatus;\n sourceTokenSymbol?: string;\n swapMetaData?: any;\n swapTokenValue?: string;\n time?: number; // @deprecated We should use creationTime instead.\n creationTime?: number;\n txParams?: any;\n type?: string;\n confirmed?: boolean;\n cancellable?: boolean;\n accountHardwareType?: string;\n accountType?: string;\n deviceModel?: string;\n};\n\nexport type Fee = {\n maxFeePerGas: number;\n maxPriorityFeePerGas: number;\n};\n\nexport type IndividualTxFees = {\n fees: Fee[];\n cancelFees: Fee[];\n feeEstimate: number;\n gasLimit: number;\n gasUsed: number;\n};\n\nexport type Fees = {\n approvalTxFees: IndividualTxFees |
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,UAAU;AACV,IAAY,OAOX;AAPD,WAAY,OAAO;IACjB,6CAAU,CAAA;IACV,qDAAc,CAAA;IACd,mEAAqB,CAAA;IACrB,yCAAQ,CAAA;IACR,qDAAc,CAAA;IACd,6CAAU,CAAA;AACZ,CAAC,EAPW,OAAO,GAAP,eAAO,KAAP,eAAO,QAOlB;AAED,wBAAwB;AACxB,IAAY,uBAMX;AAND,WAAY,uBAAuB;IACjC,kDAAuB,CAAA;IACvB,8CAAmB,CAAA;IACnB,kDAAuB,CAAA;IACvB,gDAAqB,CAAA;IACrB,8CAAmB,CAAA;AACrB,CAAC,EANW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAMlC;AAED,IAAY,kCAQX;AARD,WAAY,kCAAkC;IAC5C,mEAA6B,CAAA;IAC7B,6DAAuB,CAAA;IACvB,yEAAmC,CAAA;IACnC,qEAA+B,CAAA;IAC/B,uEAAiC,CAAA;IACjC,qEAA+B,CAAA;IAC/B,qFAA+C,CAAA;AACjD,CAAC,EARW,kCAAkC,GAAlC,0CAAkC,KAAlC,0CAAkC,QAQ7C;AAED,IAAY,wBAaX;AAbD,WAAY,wBAAwB;IAClC,+CAAmB,CAAA;IACnB,+CAAmB,CAAA;IACnB,iDAAqB,CAAA;IACrB,+CAAmB,CAAA;IACnB,mDAAuB,CAAA;IACvB,6EAAiD,CAAA;IACjD,uEAA2C,CAAA;IAC3C,mFAAuD,CAAA;IACvD,+EAAmD,CAAA;IACnD,iFAAqD,CAAA;IACrD,+FAAmE,CAAA;IACnE,iDAAqB,CAAA;AACvB,CAAC,EAbW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAanC;AAEY,QAAA,6BAA6B,GAAG;IAC3C,CAAC,kCAAkC,CAAC,YAAY,CAAC,EAC/C,wBAAwB,CAAC,sBAAsB;IACjD,CAAC,kCAAkC,CAAC,SAAS,CAAC,EAC5C,wBAAwB,CAAC,mBAAmB;IAC9C,CAAC,kCAAkC,CAAC,eAAe,CAAC,EAClD,wBAAwB,CAAC,yBAAyB;IACpD,CAAC,kCAAkC,CAAC,aAAa,CAAC,EAChD,wBAAwB,CAAC,uBAAuB;IAClD,CAAC,kCAAkC,CAAC,cAAc,CAAC,EACjD,wBAAwB,CAAC,wBAAwB;IACnD,CAAC,kCAAkC,CAAC,qBAAqB,CAAC,EACxD,wBAAwB,CAAC,+BAA+B;CAC3D,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\n\n/** API */\nexport enum APIType {\n 'GET_FEES',\n 'ESTIMATE_GAS',\n 'SUBMIT_TRANSACTIONS',\n 'CANCEL',\n 'BATCH_STATUS',\n 'LIVENESS',\n}\n\n/** SmartTransactions */\nexport enum SmartTransactionMinedTx {\n NOT_MINED = 'not_mined',\n SUCCESS = 'success',\n CANCELLED = 'cancelled',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n}\n\nexport enum SmartTransactionCancellationReason {\n WOULD_REVERT = 'would_revert',\n TOO_CHEAP = 'too_cheap',\n DEADLINE_MISSED = 'deadline_missed',\n INVALID_NONCE = 'invalid_nonce',\n USER_CANCELLED = 'user_cancelled',\n NOT_CANCELLED = 'not_cancelled',\n PREVIOUS_TX_CANCELLED = 'previous_tx_cancelled',\n}\n\nexport enum SmartTransactionStatuses {\n PENDING = 'pending',\n SUCCESS = 'success',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n CANCELLED = 'cancelled',\n CANCELLED_WOULD_REVERT = 'cancelled_would_revert',\n CANCELLED_TOO_CHEAP = 'cancelled_too_cheap',\n CANCELLED_DEADLINE_MISSED = 'cancelled_deadline_missed',\n CANCELLED_INVALID_NONCE = 'cancelled_invalid_nonce',\n CANCELLED_USER_CANCELLED = 'cancelled_user_cancelled',\n CANCELLED_PREVIOUS_TX_CANCELLED = 'cancelled_previous_tx_cancelled',\n RESOLVED = 'resolved',\n}\n\nexport const cancellationReasonToStatusMap = {\n [SmartTransactionCancellationReason.WOULD_REVERT]:\n SmartTransactionStatuses.CANCELLED_WOULD_REVERT,\n [SmartTransactionCancellationReason.TOO_CHEAP]:\n SmartTransactionStatuses.CANCELLED_TOO_CHEAP,\n [SmartTransactionCancellationReason.DEADLINE_MISSED]:\n SmartTransactionStatuses.CANCELLED_DEADLINE_MISSED,\n [SmartTransactionCancellationReason.INVALID_NONCE]:\n SmartTransactionStatuses.CANCELLED_INVALID_NONCE,\n [SmartTransactionCancellationReason.USER_CANCELLED]:\n SmartTransactionStatuses.CANCELLED_USER_CANCELLED,\n [SmartTransactionCancellationReason.PREVIOUS_TX_CANCELLED]:\n SmartTransactionStatuses.CANCELLED_PREVIOUS_TX_CANCELLED,\n};\n\nexport type SmartTransactionsStatus = {\n error?: string;\n cancellationFeeWei: number;\n cancellationReason?: SmartTransactionCancellationReason;\n deadlineRatio: number;\n minedHash: string;\n minedTx: SmartTransactionMinedTx;\n isSettled: boolean;\n duplicated?: boolean;\n timedOut?: boolean;\n proxied?: boolean;\n};\n\nexport type SmartTransaction = {\n uuid: string;\n txHash?: string;\n chainId?: string;\n destinationTokenAddress?: string;\n destinationTokenDecimals?: string;\n destinationTokenSymbol?: string;\n history?: any;\n nonceDetails?: any;\n origin?: string;\n preTxBalance?: string;\n status?: string;\n statusMetadata?: SmartTransactionsStatus;\n sourceTokenSymbol?: string;\n swapMetaData?: any;\n swapTokenValue?: string;\n time?: number; // @deprecated We should use creationTime instead.\n creationTime?: number;\n txParams?: any;\n type?: string;\n confirmed?: boolean;\n cancellable?: boolean;\n accountHardwareType?: string;\n accountType?: string;\n deviceModel?: string;\n};\n\nexport type Fee = {\n maxFeePerGas: number;\n maxPriorityFeePerGas: number;\n};\n\nexport type IndividualTxFees = {\n fees: Fee[];\n cancelFees: Fee[];\n feeEstimate: number;\n gasLimit: number;\n gasUsed: number;\n};\n\nexport type Fees = {\n approvalTxFees: IndividualTxFees | null;\n tradeTxFees: IndividualTxFees | null;\n};\n\n// TODO\nexport type UnsignedTransaction = any;\n\n// TODO\nexport type SignedTransaction = any;\n\n// TODO\nexport type SignedCanceledTransaction = any;\n\nexport type Hex = `0x${string}`;\n\nexport type GetTransactionsOptions = {\n searchCriteria?: any;\n initialList?: TransactionMeta[];\n filterToCurrentNetwork?: boolean;\n limit?: number;\n};\n\nexport type MetaMetricsProps = {\n accountHardwareType?: string;\n accountType?: string;\n deviceModel?: string;\n};\n"]}
|
package/package.json
CHANGED