@metamask/smart-transactions-controller 6.2.2 → 7.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 CHANGED
@@ -6,6 +6,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [7.0.0]
10
+ ### Added
11
+ - **BREAKING:** Track fees and liveness for multiple chains by adding `feesByChainId` and `livenessByChainId` properties to SmartTransactionsControllerState ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
12
+ - In particular, clients should prefer accessing `feesByChainId` and `livenessByChainId` instead of `fees` and `liveness`, which will be removed in a future major version.
13
+ - `SmartTransactionsController` now inherits from `StaticIntervalPollingControllerV1` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237), [#265](https://github.com/MetaMask/smart-transactions-controller/pull/265))
14
+ - This change introduces a set of public methods to the controller which is designed to manage polling on a particular network instead of the globally selected network. Internally, `updateSmartTransactions` will still be called as the legacy polling does. The methods added are:
15
+ - `setIntervalLength`
16
+ - `getIntervalLength`
17
+ - `startPollingByNetworkClientId`
18
+ - `stopAllPolling`
19
+ - `stopPollingByPollingToken`
20
+ - `onPollingCompleteByNetworkClientId`
21
+ - Validation can be now be circumvented by passing the `skipConfirm` option ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
22
+ - Several methods now take a `networkClientId` option within an options object which can be used to operate on smart transactions that live on a particular chain instead of the globally selected one ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
23
+ - `updateSmartTransaction`
24
+ - `fetchSmartTransactionsStatus`
25
+ - `getFees`
26
+ - `submitSignedTransactions`
27
+ - `cancelSmartTransaction`
28
+ - `fetchLiveness`
29
+ - Expose `eventEmitter` as a public property ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
30
+ - `submitSignedTransactions` now takes a `transactionMeta` option which is used to set the `type` of the submitted smart transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
31
+ - `submitSignedTransactions` now sets `uuid` and `txHash` on the submitted smart transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
32
+ - `submitSignedTransactions` now returns metadata about the submitted transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
33
+ - Add `getTxHash` utility function which can be used to get the transaction hash from a signed transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
34
+ - `<transaction-uuid>:smartTransaction` is now emitted whenever a smart transaction is updated ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
35
+ - This occurs after transactions are submitted, after they are confirmed, after statuses are updated, and also explicitly via `updateSmartTransaction`.
36
+
37
+ ### Changed
38
+ - **BREAKING**: Bump `@metamask/network-controller` from `^15.0.0` to `^17.0.0` ([#238](https://github.com/MetaMask/smart-transactions-controller/pull/238) [#241](https://github.com/MetaMask/smart-transactions-controller/pull/241))
39
+ - This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for `@metamask/base-controller@4.0.0` for more.
40
+ - **BREAKING**: The set of supported chains (configurable via `supportedChainIds`) now defaults to including Goerli instead of Rinkeby ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
41
+ - **BREAKING**: Minimum Node.js version is now 18.18 ([#270](https://github.com/MetaMask/smart-transactions-controller/pull/270))
42
+ - **BREAKING:** Constrain the type of the constructor `provider` option to `Provider` from `@metamask/network-controller` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
43
+ - **BREAKING:** The constructor now takes a required argument `getNetworkClientById`, which should be bound from NetworkController's `getNetworkClientById` method ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
44
+ - **BREAKING:** `fetchSmartTransactionsStatus` now emits `<transaction-uuid>:smartTransaction` instead of `<transaction-uuid>:transaction-hash` ([#279](https://github.com/MetaMask/smart-transactions-controller/pull/279))
45
+ - This event contains more information than just the transaction hash.
46
+ - This event is also always emitted even if there is no transaction hash.
47
+ - **BREAKING:** Use a category of "Transactions" for MetaMetrics events rather than "swaps" ([#282](https://github.com/MetaMask/smart-transactions-controller/pull/282))
48
+ - Bump `@metamask/base-controller` from `^3.2.1` to `^4.0.0` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
49
+ - Bump `@metamask/controller-utils` from `^5.0.0` to `^8.0.3` ([#242](https://github.com/MetaMask/smart-transactions-controller/pull/242) [#244](https://github.com/MetaMask/smart-transactions-controller/pull/244))([#242](https://github.com/MetaMask/smart-transactions-controller/pull/242)) ([#244](https://github.com/MetaMask/smart-transactions-controller/pull/244)) ([#267](https://github.com/MetaMask/smart-transactions-controller/pull/267)) ([#272](https://github.com/MetaMask/smart-transactions-controller/pull/272))
50
+ - Bump `@metamask/network-controller` from `^15.2.0` to `^17.2.0` ([#238](https://github.com/MetaMask/smart-transactions-controller/pull/238)) ([#241](https://github.com/MetaMask/smart-transactions-controller/pull/241)) ([#255](https://github.com/MetaMask/smart-transactions-controller/pull/255)) ([#264](https://github.com/MetaMask/smart-transactions-controller/pull/264)) ([#265](https://github.com/MetaMask/smart-transactions-controller/pull/265))
51
+ - Bump `@metamask/polling-controller` from `^2.0.0` to `^5.0.0` ([#265](https://github.com/MetaMask/smart-transactions-controller/pull/265))
52
+ - Remove `@ethersprovider/bignumber` and `@ethersproject/providers` from dependencies; replace with `@metamask/eth-query@^4.0.0` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
53
+ - Add `events@^3.3.0` as a dependency ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
54
+ - Deprecate `time` property on `SmartTransaction` type in favor of `creationTime` ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
55
+
56
+ ### Removed
57
+ - **BREAKING:** Remove property `ethersProvider` from `SmartTransactionsController` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
58
+
59
+ ### Fixed
60
+ - Fix `getFees` so that it does not blow away an existing `nonce` on the trade transaction ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
61
+ - Fix `submitSignedTransactions` so that it sets a `nonce` on the resulting transaction if it doesn't have one ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
62
+ - Fix updating a smart transaction to no longer throw when no smart transactions have been previously saved under the current chain ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
63
+ - Properly override controller name to `SmartTransactionController` ([#273](https://github.com/MetaMask/smart-transactions-controller/pull/273))
64
+ - Properly mark `getFees` as having an optional second argument, since it was being handled that way anyway ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
65
+ - The controller now waits until the first NetworkController update before making use of the `provider` constructor argument to hit the currently selected network ([#274](https://github.com/MetaMask/smart-transactions-controller/pull/274))
66
+ - This change was made because in the future, the `provider` may no longer be defined initially.
67
+ - This change may cause errors to be thrown immediately following a network switch until a future NetworkController state update or polling iteration.
68
+
9
69
  ## [6.2.2]
10
70
  ### Fixed
11
71
  - Revert "Parameterize SmartTransactionsController state by ChainId for MultiChain + Integrate PollingController Mixin ([#235](https://github.com/MetaMask/smart-transactions-controller/pull/235))
@@ -183,7 +243,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
183
243
  - Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
184
244
  - Initial commit
185
245
 
186
- [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.2...HEAD
246
+ [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v7.0.0...HEAD
247
+ [7.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.2...v7.0.0
187
248
  [6.2.2]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.1...v6.2.2
188
249
  [6.2.1]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.0...v6.2.1
189
250
  [6.2.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.1.0...v6.2.0
@@ -1,40 +1,57 @@
1
1
  /// <reference types="node" />
2
- import { BaseConfig, BaseController, BaseState } from '@metamask/base-controller';
3
- import { NetworkState } from '@metamask/network-controller';
4
- import { SmartTransaction, SignedTransaction, SignedCanceledTransaction, UnsignedTransaction, SmartTransactionStatuses, Fees, IndividualTxFees } from './types';
2
+ /// <reference types="node" />
3
+ import type { BaseConfig, BaseState } from '@metamask/base-controller';
4
+ import type { Provider } from '@metamask/eth-query';
5
+ import type { NetworkClientId, NetworkController, NetworkState } from '@metamask/network-controller';
6
+ import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';
7
+ import EventEmitter from 'events';
8
+ import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction } from './types';
9
+ import { SmartTransactionStatuses } from './types';
5
10
  export declare const DEFAULT_INTERVAL: number;
6
11
  export declare type SmartTransactionsControllerConfig = BaseConfig & {
7
12
  interval: number;
8
13
  clientId: string;
9
- chainId: string;
14
+ chainId: Hex;
10
15
  supportedChainIds: string[];
11
16
  };
17
+ declare type FeeEstimates = {
18
+ approvalTxFees: IndividualTxFees | undefined;
19
+ tradeTxFees: IndividualTxFees | undefined;
20
+ };
12
21
  export declare type SmartTransactionsControllerState = BaseState & {
13
22
  smartTransactionsState: {
14
- smartTransactions: Record<string, SmartTransaction[]>;
23
+ smartTransactions: Record<Hex, SmartTransaction[]>;
15
24
  userOptIn: boolean | undefined;
16
25
  userOptInV2: boolean | undefined;
17
26
  liveness: boolean | undefined;
18
- fees: {
19
- approvalTxFees: IndividualTxFees | undefined;
20
- tradeTxFees: IndividualTxFees | undefined;
21
- };
27
+ fees: FeeEstimates;
28
+ feesByChainId: Record<Hex, FeeEstimates>;
29
+ livenessByChainId: Record<Hex, boolean>;
22
30
  };
23
31
  };
24
- export default class SmartTransactionsController extends BaseController<SmartTransactionsControllerConfig, SmartTransactionsControllerState> {
32
+ export default class SmartTransactionsController extends StaticIntervalPollingControllerV1<SmartTransactionsControllerConfig, SmartTransactionsControllerState> {
33
+ #private;
34
+ /**
35
+ * Name of this controller used during composition
36
+ */
37
+ name: string;
25
38
  timeoutHandle?: NodeJS.Timeout;
26
- private getNonceLock;
27
- ethersProvider: any;
39
+ private readonly getNonceLock;
40
+ private ethQuery;
28
41
  confirmExternalTransaction: any;
29
- private trackMetaMetricsEvent;
42
+ private readonly trackMetaMetricsEvent;
43
+ eventEmitter: EventEmitter;
44
+ private readonly getNetworkClientById;
30
45
  private fetch;
31
- constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, trackMetaMetricsEvent, }: {
46
+ constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, }: {
32
47
  onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
33
48
  getNonceLock: any;
34
- provider: any;
49
+ provider: Provider;
35
50
  confirmExternalTransaction: any;
36
51
  trackMetaMetricsEvent: any;
52
+ getNetworkClientById: NetworkController['getNetworkClientById'];
37
53
  }, config?: Partial<SmartTransactionsControllerConfig>, state?: Partial<SmartTransactionsControllerState>);
54
+ _executePoll(networkClientId: string): Promise<void>;
38
55
  checkPoll(state: any): void;
39
56
  initializeSmartTransactionsForChainId(): void;
40
57
  poll(interval?: number): Promise<void>;
@@ -42,23 +59,37 @@ export default class SmartTransactionsController extends BaseController<SmartTra
42
59
  setOptInState(state: boolean | undefined): void;
43
60
  trackStxStatusChange(smartTransaction: SmartTransaction, prevSmartTransaction?: SmartTransaction): void;
44
61
  isNewSmartTransaction(smartTransactionUuid: string): boolean;
45
- updateSmartTransaction(smartTransaction: SmartTransaction): void;
46
- updateSmartTransactions(): Promise<void>;
47
- confirmSmartTransaction(smartTransaction: SmartTransaction): Promise<void>;
48
- fetchSmartTransactionsStatus(uuids: string[]): Promise<SmartTransaction[]>;
62
+ updateSmartTransaction(smartTransaction: SmartTransaction, { networkClientId }?: {
63
+ networkClientId?: NetworkClientId;
64
+ }): void;
65
+ updateSmartTransactions({ networkClientId, }?: {
66
+ networkClientId?: NetworkClientId;
67
+ }): Promise<void>;
68
+ fetchSmartTransactionsStatus(uuids: string[], { networkClientId }?: {
69
+ networkClientId?: NetworkClientId;
70
+ }): Promise<Record<string, SmartTransactionsStatus>>;
49
71
  addNonceToTransaction(transaction: UnsignedTransaction): Promise<UnsignedTransaction>;
50
72
  clearFees(): Fees;
51
- getFees(tradeTx: UnsignedTransaction, approvalTx: UnsignedTransaction): Promise<Fees>;
52
- submitSignedTransactions({ txParams, signedTransactions, signedCanceledTransactions, }: {
73
+ getFees(tradeTx: UnsignedTransaction, approvalTx?: UnsignedTransaction, { networkClientId }?: {
74
+ networkClientId?: NetworkClientId;
75
+ }): Promise<Fees>;
76
+ submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions, networkClientId, }: {
53
77
  signedTransactions: SignedTransaction[];
54
78
  signedCanceledTransactions: SignedCanceledTransaction[];
79
+ transactionMeta?: any;
55
80
  txParams?: any;
81
+ networkClientId?: NetworkClientId;
56
82
  }): Promise<any>;
57
- cancelSmartTransaction(uuid: string): Promise<void>;
58
- fetchLiveness(): Promise<boolean>;
83
+ cancelSmartTransaction(uuid: string, { networkClientId, }?: {
84
+ networkClientId?: NetworkClientId;
85
+ }): Promise<void>;
86
+ fetchLiveness({ networkClientId, }?: {
87
+ networkClientId?: NetworkClientId;
88
+ }): Promise<boolean>;
59
89
  setStatusRefreshInterval(interval: number): Promise<void>;
60
90
  getTransactions({ addressFrom, status, }: {
61
91
  addressFrom: string;
62
92
  status: SmartTransactionStatuses;
63
93
  }): SmartTransaction[];
64
94
  }
95
+ export {};