@metamask/smart-transactions-controller 6.2.2 → 8.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 +68 -1
- package/README.md +2 -2
- package/dist/SmartTransactionsController.d.ts +57 -23
- package/dist/SmartTransactionsController.js +255 -140
- package/dist/SmartTransactionsController.js.map +1 -1
- package/dist/constants.d.ts +12 -3
- package/dist/constants.js +12 -1
- package/dist/constants.js.map +1 -1
- package/dist/test-helpers.d.ts +24 -0
- package/dist/test-helpers.js +34 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/types.d.ts +11 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +18 -5
- package/dist/utils.js.map +1 -1
- package/package.json +24 -16
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,71 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [8.0.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING:** The constructor now requires a `getTransactions` option, which can be used to get a list of existing transactions ([#301](https://github.com/MetaMask/smart-transactions-controller/pull/301))
|
|
12
|
+
- Ensure that a transaction does not get re-confirmed if it is already confirmed or submitted. MetaMask Swaps are confirmed from this controller, other transaction types are most of the time confirmed from the TransactionController. ([#301](https://github.com/MetaMask/smart-transactions-controller/pull/301))
|
|
13
|
+
|
|
14
|
+
## [7.0.0]
|
|
15
|
+
### Added
|
|
16
|
+
- **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))
|
|
17
|
+
- In particular, clients should prefer accessing `feesByChainId` and `livenessByChainId` instead of `fees` and `liveness`, which will be removed in a future major version.
|
|
18
|
+
- `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))
|
|
19
|
+
- 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:
|
|
20
|
+
- `setIntervalLength`
|
|
21
|
+
- `getIntervalLength`
|
|
22
|
+
- `startPollingByNetworkClientId`
|
|
23
|
+
- `stopAllPolling`
|
|
24
|
+
- `stopPollingByPollingToken`
|
|
25
|
+
- `onPollingCompleteByNetworkClientId`
|
|
26
|
+
- Validation can be now be circumvented by passing the `skipConfirm` option ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
|
|
27
|
+
- 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))
|
|
28
|
+
- `updateSmartTransaction`
|
|
29
|
+
- `fetchSmartTransactionsStatus`
|
|
30
|
+
- `getFees`
|
|
31
|
+
- `submitSignedTransactions`
|
|
32
|
+
- `cancelSmartTransaction`
|
|
33
|
+
- `fetchLiveness`
|
|
34
|
+
- Expose `eventEmitter` as a public property ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
|
|
35
|
+
- `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))
|
|
36
|
+
- `submitSignedTransactions` now sets `uuid` and `txHash` on the submitted smart transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
|
|
37
|
+
- `submitSignedTransactions` now returns metadata about the submitted transaction ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
|
|
38
|
+
- 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))
|
|
39
|
+
- `<transaction-uuid>:smartTransaction` is now emitted whenever a smart transaction is updated ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
|
|
40
|
+
- This occurs after transactions are submitted, after they are confirmed, after statuses are updated, and also explicitly via `updateSmartTransaction`.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
- **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))
|
|
44
|
+
- 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.
|
|
45
|
+
- **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))
|
|
46
|
+
- **BREAKING**: Minimum Node.js version is now 18.18 ([#270](https://github.com/MetaMask/smart-transactions-controller/pull/270))
|
|
47
|
+
- **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))
|
|
48
|
+
- **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))
|
|
49
|
+
- **BREAKING:** `fetchSmartTransactionsStatus` now emits `<transaction-uuid>:smartTransaction` instead of `<transaction-uuid>:transaction-hash` ([#279](https://github.com/MetaMask/smart-transactions-controller/pull/279))
|
|
50
|
+
- This event contains more information than just the transaction hash.
|
|
51
|
+
- This event is also always emitted even if there is no transaction hash.
|
|
52
|
+
- **BREAKING:** Use a category of "Transactions" for MetaMetrics events rather than "swaps" ([#282](https://github.com/MetaMask/smart-transactions-controller/pull/282))
|
|
53
|
+
- Bump `@metamask/base-controller` from `^3.2.1` to `^4.0.0` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
|
|
54
|
+
- 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))
|
|
55
|
+
- 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))
|
|
56
|
+
- Bump `@metamask/polling-controller` from `^2.0.0` to `^5.0.0` ([#265](https://github.com/MetaMask/smart-transactions-controller/pull/265))
|
|
57
|
+
- 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))
|
|
58
|
+
- Add `events@^3.3.0` as a dependency ([#271](https://github.com/MetaMask/smart-transactions-controller/pull/271))
|
|
59
|
+
- Deprecate `time` property on `SmartTransaction` type in favor of `creationTime` ([#298](https://github.com/MetaMask/smart-transactions-controller/pull/298))
|
|
60
|
+
|
|
61
|
+
### Removed
|
|
62
|
+
- **BREAKING:** Remove property `ethersProvider` from `SmartTransactionsController` ([#237](https://github.com/MetaMask/smart-transactions-controller/pull/237))
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
- 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))
|
|
66
|
+
- 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))
|
|
67
|
+
- 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))
|
|
68
|
+
- Properly override controller name to `SmartTransactionController` ([#273](https://github.com/MetaMask/smart-transactions-controller/pull/273))
|
|
69
|
+
- 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))
|
|
70
|
+
- 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))
|
|
71
|
+
- This change was made because in the future, the `provider` may no longer be defined initially.
|
|
72
|
+
- This change may cause errors to be thrown immediately following a network switch until a future NetworkController state update or polling iteration.
|
|
73
|
+
|
|
9
74
|
## [6.2.2]
|
|
10
75
|
### Fixed
|
|
11
76
|
- Revert "Parameterize SmartTransactionsController state by ChainId for MultiChain + Integrate PollingController Mixin ([#235](https://github.com/MetaMask/smart-transactions-controller/pull/235))
|
|
@@ -183,7 +248,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
183
248
|
- Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
|
|
184
249
|
- Initial commit
|
|
185
250
|
|
|
186
|
-
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/
|
|
251
|
+
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v8.0.0...HEAD
|
|
252
|
+
[8.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v7.0.0...v8.0.0
|
|
253
|
+
[7.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.2...v7.0.0
|
|
187
254
|
[6.2.2]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.1...v6.2.2
|
|
188
255
|
[6.2.1]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.2.0...v6.2.1
|
|
189
256
|
[6.2.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.1.0...v6.2.0
|
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ or
|
|
|
14
14
|
|
|
15
15
|
### Setup
|
|
16
16
|
|
|
17
|
-
- Install [Node.js](https://nodejs.org)
|
|
18
|
-
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
|
|
17
|
+
- Install the current LTS version of [Node.js](https://nodejs.org)
|
|
18
|
+
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm install` will install the latest suitable version and running `nvm use` will automatically choose the right node version for you.
|
|
19
19
|
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
|
|
20
20
|
- Run `yarn install` to install dependencies and run any required post-install scripts
|
|
21
21
|
|
|
@@ -1,40 +1,60 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 type { TransactionMeta } from '@metamask/transaction-controller';
|
|
8
|
+
import EventEmitter from 'events';
|
|
9
|
+
import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, GetTransactionsOptions } from './types';
|
|
10
|
+
import { SmartTransactionStatuses } from './types';
|
|
5
11
|
export declare const DEFAULT_INTERVAL: number;
|
|
6
12
|
export declare type SmartTransactionsControllerConfig = BaseConfig & {
|
|
7
13
|
interval: number;
|
|
8
14
|
clientId: string;
|
|
9
|
-
chainId:
|
|
15
|
+
chainId: Hex;
|
|
10
16
|
supportedChainIds: string[];
|
|
11
17
|
};
|
|
18
|
+
declare type FeeEstimates = {
|
|
19
|
+
approvalTxFees: IndividualTxFees | undefined;
|
|
20
|
+
tradeTxFees: IndividualTxFees | undefined;
|
|
21
|
+
};
|
|
12
22
|
export declare type SmartTransactionsControllerState = BaseState & {
|
|
13
23
|
smartTransactionsState: {
|
|
14
|
-
smartTransactions: Record<
|
|
24
|
+
smartTransactions: Record<Hex, SmartTransaction[]>;
|
|
15
25
|
userOptIn: boolean | undefined;
|
|
16
26
|
userOptInV2: boolean | undefined;
|
|
17
27
|
liveness: boolean | undefined;
|
|
18
|
-
fees:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
28
|
+
fees: FeeEstimates;
|
|
29
|
+
feesByChainId: Record<Hex, FeeEstimates>;
|
|
30
|
+
livenessByChainId: Record<Hex, boolean>;
|
|
22
31
|
};
|
|
23
32
|
};
|
|
24
|
-
export default class SmartTransactionsController extends
|
|
33
|
+
export default class SmartTransactionsController extends StaticIntervalPollingControllerV1<SmartTransactionsControllerConfig, SmartTransactionsControllerState> {
|
|
34
|
+
#private;
|
|
35
|
+
/**
|
|
36
|
+
* Name of this controller used during composition
|
|
37
|
+
*/
|
|
38
|
+
name: string;
|
|
25
39
|
timeoutHandle?: NodeJS.Timeout;
|
|
26
|
-
private getNonceLock;
|
|
27
|
-
|
|
40
|
+
private readonly getNonceLock;
|
|
41
|
+
private ethQuery;
|
|
28
42
|
confirmExternalTransaction: any;
|
|
29
|
-
|
|
43
|
+
getRegularTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
|
|
44
|
+
private readonly trackMetaMetricsEvent;
|
|
45
|
+
eventEmitter: EventEmitter;
|
|
46
|
+
private readonly getNetworkClientById;
|
|
30
47
|
private fetch;
|
|
31
|
-
constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, trackMetaMetricsEvent, }: {
|
|
48
|
+
constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, getTransactions, trackMetaMetricsEvent, getNetworkClientById, }: {
|
|
32
49
|
onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
|
|
33
50
|
getNonceLock: any;
|
|
34
|
-
provider:
|
|
51
|
+
provider: Provider;
|
|
35
52
|
confirmExternalTransaction: any;
|
|
53
|
+
getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
|
|
36
54
|
trackMetaMetricsEvent: any;
|
|
55
|
+
getNetworkClientById: NetworkController['getNetworkClientById'];
|
|
37
56
|
}, config?: Partial<SmartTransactionsControllerConfig>, state?: Partial<SmartTransactionsControllerState>);
|
|
57
|
+
_executePoll(networkClientId: string): Promise<void>;
|
|
38
58
|
checkPoll(state: any): void;
|
|
39
59
|
initializeSmartTransactionsForChainId(): void;
|
|
40
60
|
poll(interval?: number): Promise<void>;
|
|
@@ -42,23 +62,37 @@ export default class SmartTransactionsController extends BaseController<SmartTra
|
|
|
42
62
|
setOptInState(state: boolean | undefined): void;
|
|
43
63
|
trackStxStatusChange(smartTransaction: SmartTransaction, prevSmartTransaction?: SmartTransaction): void;
|
|
44
64
|
isNewSmartTransaction(smartTransactionUuid: string): boolean;
|
|
45
|
-
updateSmartTransaction(smartTransaction: SmartTransaction
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
updateSmartTransaction(smartTransaction: SmartTransaction, { networkClientId }?: {
|
|
66
|
+
networkClientId?: NetworkClientId;
|
|
67
|
+
}): void;
|
|
68
|
+
updateSmartTransactions({ networkClientId, }?: {
|
|
69
|
+
networkClientId?: NetworkClientId;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
fetchSmartTransactionsStatus(uuids: string[], { networkClientId }?: {
|
|
72
|
+
networkClientId?: NetworkClientId;
|
|
73
|
+
}): Promise<Record<string, SmartTransactionsStatus>>;
|
|
49
74
|
addNonceToTransaction(transaction: UnsignedTransaction): Promise<UnsignedTransaction>;
|
|
50
75
|
clearFees(): Fees;
|
|
51
|
-
getFees(tradeTx: UnsignedTransaction, approvalTx
|
|
52
|
-
|
|
76
|
+
getFees(tradeTx: UnsignedTransaction, approvalTx?: UnsignedTransaction, { networkClientId }?: {
|
|
77
|
+
networkClientId?: NetworkClientId;
|
|
78
|
+
}): Promise<Fees>;
|
|
79
|
+
submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions, networkClientId, }: {
|
|
53
80
|
signedTransactions: SignedTransaction[];
|
|
54
81
|
signedCanceledTransactions: SignedCanceledTransaction[];
|
|
82
|
+
transactionMeta?: any;
|
|
55
83
|
txParams?: any;
|
|
84
|
+
networkClientId?: NetworkClientId;
|
|
56
85
|
}): Promise<any>;
|
|
57
|
-
cancelSmartTransaction(uuid: string
|
|
58
|
-
|
|
86
|
+
cancelSmartTransaction(uuid: string, { networkClientId, }?: {
|
|
87
|
+
networkClientId?: NetworkClientId;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
fetchLiveness({ networkClientId, }?: {
|
|
90
|
+
networkClientId?: NetworkClientId;
|
|
91
|
+
}): Promise<boolean>;
|
|
59
92
|
setStatusRefreshInterval(interval: number): Promise<void>;
|
|
60
93
|
getTransactions({ addressFrom, status, }: {
|
|
61
94
|
addressFrom: string;
|
|
62
95
|
status: SmartTransactionStatuses;
|
|
63
96
|
}): SmartTransaction[];
|
|
64
97
|
}
|
|
98
|
+
export {};
|