@metamask/smart-transactions-controller 4.0.0 → 6.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 +26 -1
- package/dist/SmartTransactionsController.d.ts +48 -22
- package/dist/SmartTransactionsController.js +183 -125
- package/dist/SmartTransactionsController.js.map +1 -1
- package/dist/constants.d.ts +4 -3
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [6.0.0]
|
|
10
|
+
### Added
|
|
11
|
+
- **BREAKING:** `getNetworkClientById` is now required argument in constructor options object ([#210](https://github.com/MetaMask/smart-transactions-controller/pull/210))
|
|
12
|
+
- Integrate `PollingController` mixin and `_executePoll` method used for concurrent multichain polling ([#210](https://github.com/MetaMask/smart-transactions-controller/pull/210))
|
|
13
|
+
- Consumers can now call `startPollingByNetworkClientId` with a networkClientId to start polling for a specific chain and `stopPollingByPollingToken` with the returned pollingToken to stop polling for that chain.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **BREAKING**: Bump `@metamask/network-controller` from ^13.0.1 to ^15.0.0 ([#211](https://github.com/MetaMask/smart-transactions-controller/pull/211))
|
|
17
|
+
- **BREAKING**: Replace `@ethersproject/providers` with `@metamask/eth-query` ([#210](https://github.com/MetaMask/smart-transactions-controller/pull/210))
|
|
18
|
+
- Remove `@ethersproject/bignumber` ([#210](https://github.com/MetaMask/smart-transactions-controller/pull/210))
|
|
19
|
+
- Add optional options object containing a `networkClientId` argument to the `updateSmartTransaction` method ([#210](https://github.com/MetaMask/smart-transactions-controller/pull/210))
|
|
20
|
+
|
|
21
|
+
## [5.0.0]
|
|
22
|
+
### Changed
|
|
23
|
+
- Bump dependency on `@metamask/network-controller` to ^13.0.0 ([#191](https://github.com/MetaMask/smart-transactions-controller/pull/191))
|
|
24
|
+
- Bump dependency on `@metamask/base-controller` to ^3.2.1 ([#191](https://github.com/MetaMask/smart-transactions-controller/pull/191))
|
|
25
|
+
- Bump dependency on `@metamask/controller-utils` to ^5.0.0 ([#191](https://github.com/MetaMask/smart-transactions-controller/pull/191))
|
|
26
|
+
|
|
27
|
+
### Removed
|
|
28
|
+
- **BREAKING:** Remove `metamaskNetworkId` from smart transaction state ([#191](https://github.com/MetaMask/smart-transactions-controller/pull/191))
|
|
29
|
+
- To migrate, remove references to `TransactionMeta.metamaskNetworkId` and `TransactionMeta.history.metamaskNetworkId`
|
|
30
|
+
- Remove `getNetwork` from constructor options ([#191](https://github.com/MetaMask/smart-transactions-controller/pull/191))
|
|
31
|
+
|
|
9
32
|
## [4.0.0]
|
|
10
33
|
### Changed
|
|
11
34
|
- **BREAKING**: Bump minimum Node.js version to v16 ([#161](https://github.com/MetaMask/smart-transactions-controller/pull/161))
|
|
@@ -141,7 +164,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
141
164
|
- Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
|
|
142
165
|
- Initial commit
|
|
143
166
|
|
|
144
|
-
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/
|
|
167
|
+
[Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v6.0.0...HEAD
|
|
168
|
+
[6.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v5.0.0...v6.0.0
|
|
169
|
+
[5.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v4.0.0...v5.0.0
|
|
145
170
|
[4.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v3.1.0...v4.0.0
|
|
146
171
|
[3.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v3.0.0...v3.1.0
|
|
147
172
|
[3.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v2.3.2...v3.0.0
|
|
@@ -1,41 +1,48 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { BaseConfig,
|
|
3
|
-
import { NetworkState } from '@metamask/network-controller';
|
|
4
|
-
import {
|
|
2
|
+
import { BaseConfig, BaseState } from '@metamask/base-controller';
|
|
3
|
+
import { NetworkState, NetworkController, NetworkClientId } from '@metamask/network-controller';
|
|
4
|
+
import { PollingControllerV1 } from '@metamask/polling-controller';
|
|
5
|
+
import EthQuery from '@metamask/eth-query';
|
|
6
|
+
import { SmartTransaction, SignedTransaction, SignedCanceledTransaction, UnsignedTransaction, SmartTransactionStatuses, Fees, IndividualTxFees, Hex } from './types';
|
|
5
7
|
export declare const DEFAULT_INTERVAL: number;
|
|
6
8
|
export declare type SmartTransactionsControllerConfig = BaseConfig & {
|
|
7
9
|
interval: number;
|
|
8
10
|
clientId: string;
|
|
9
|
-
chainId:
|
|
11
|
+
chainId: Hex;
|
|
10
12
|
supportedChainIds: string[];
|
|
11
13
|
};
|
|
14
|
+
declare type FeeEstimates = {
|
|
15
|
+
approvalTxFees: IndividualTxFees | undefined;
|
|
16
|
+
tradeTxFees: IndividualTxFees | undefined;
|
|
17
|
+
};
|
|
12
18
|
export declare type SmartTransactionsControllerState = BaseState & {
|
|
13
19
|
smartTransactionsState: {
|
|
14
|
-
smartTransactions: Record<
|
|
20
|
+
smartTransactions: Record<Hex, SmartTransaction[]>;
|
|
15
21
|
userOptIn: boolean | undefined;
|
|
16
22
|
liveness: boolean | undefined;
|
|
17
|
-
fees:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
23
|
+
fees: FeeEstimates;
|
|
24
|
+
feesByChainId: Record<Hex, FeeEstimates>;
|
|
25
|
+
livenessByChainId: Record<Hex, boolean>;
|
|
21
26
|
};
|
|
22
27
|
};
|
|
23
|
-
export default class SmartTransactionsController extends
|
|
28
|
+
export default class SmartTransactionsController extends PollingControllerV1<SmartTransactionsControllerConfig, SmartTransactionsControllerState> {
|
|
29
|
+
#private;
|
|
24
30
|
timeoutHandle?: NodeJS.Timeout;
|
|
25
31
|
private getNonceLock;
|
|
26
|
-
|
|
27
|
-
ethersProvider: any;
|
|
32
|
+
ethQuery: EthQuery;
|
|
28
33
|
confirmExternalTransaction: any;
|
|
29
34
|
private trackMetaMetricsEvent;
|
|
35
|
+
private getNetworkClientById;
|
|
30
36
|
private fetch;
|
|
31
|
-
constructor({ onNetworkStateChange, getNonceLock,
|
|
37
|
+
constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, }: {
|
|
32
38
|
onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
|
|
33
39
|
getNonceLock: any;
|
|
34
|
-
getNetwork: any;
|
|
35
40
|
provider: any;
|
|
36
41
|
confirmExternalTransaction: any;
|
|
37
42
|
trackMetaMetricsEvent: any;
|
|
43
|
+
getNetworkClientById: NetworkController['getNetworkClientById'];
|
|
38
44
|
}, config?: Partial<SmartTransactionsControllerConfig>, state?: Partial<SmartTransactionsControllerState>);
|
|
45
|
+
_executePoll(networkClientId: string): Promise<void>;
|
|
39
46
|
checkPoll(state: any): void;
|
|
40
47
|
initializeSmartTransactionsForChainId(): void;
|
|
41
48
|
poll(interval?: number): Promise<void>;
|
|
@@ -43,23 +50,42 @@ export default class SmartTransactionsController extends BaseController<SmartTra
|
|
|
43
50
|
setOptInState(state: boolean | undefined): void;
|
|
44
51
|
trackStxStatusChange(smartTransaction: SmartTransaction, prevSmartTransaction?: SmartTransaction): void;
|
|
45
52
|
isNewSmartTransaction(smartTransactionUuid: string): boolean;
|
|
46
|
-
updateSmartTransaction(smartTransaction: SmartTransaction
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
updateSmartTransaction(smartTransaction: SmartTransaction, { networkClientId }?: {
|
|
54
|
+
networkClientId?: NetworkClientId;
|
|
55
|
+
}): void;
|
|
56
|
+
updateSmartTransactions({ networkClientId, }?: {
|
|
57
|
+
networkClientId?: NetworkClientId;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
fetchSmartTransactionsStatus(uuids: string[], { networkClientId }?: {
|
|
60
|
+
networkClientId?: NetworkClientId;
|
|
61
|
+
}): Promise<SmartTransaction[]>;
|
|
50
62
|
addNonceToTransaction(transaction: UnsignedTransaction): Promise<UnsignedTransaction>;
|
|
51
63
|
clearFees(): Fees;
|
|
52
|
-
getFees(tradeTx: UnsignedTransaction, approvalTx: UnsignedTransaction
|
|
53
|
-
|
|
64
|
+
getFees(tradeTx: UnsignedTransaction, approvalTx: UnsignedTransaction, { networkClientId }?: {
|
|
65
|
+
networkClientId?: NetworkClientId;
|
|
66
|
+
}): Promise<Fees>;
|
|
67
|
+
submitSignedTransactions({ txParams, signedTransactions, signedCanceledTransactions, networkClientId, }: {
|
|
54
68
|
signedTransactions: SignedTransaction[];
|
|
55
69
|
signedCanceledTransactions: SignedCanceledTransaction[];
|
|
56
70
|
txParams?: any;
|
|
71
|
+
networkClientId?: NetworkClientId;
|
|
57
72
|
}): Promise<any>;
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
getChainId({ networkClientId, }?: {
|
|
74
|
+
networkClientId?: NetworkClientId;
|
|
75
|
+
}): Hex;
|
|
76
|
+
getEthQuery({ networkClientId, }: {
|
|
77
|
+
networkClientId?: NetworkClientId;
|
|
78
|
+
}): EthQuery;
|
|
79
|
+
cancelSmartTransaction(uuid: string, { networkClientId, }?: {
|
|
80
|
+
networkClientId?: NetworkClientId;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
fetchLiveness({ networkClientId, }?: {
|
|
83
|
+
networkClientId?: NetworkClientId;
|
|
84
|
+
}): Promise<boolean>;
|
|
60
85
|
setStatusRefreshInterval(interval: number): Promise<void>;
|
|
61
86
|
getTransactions({ addressFrom, status, }: {
|
|
62
87
|
addressFrom: string;
|
|
63
88
|
status: SmartTransactionStatuses;
|
|
64
89
|
}): SmartTransaction[];
|
|
65
90
|
}
|
|
91
|
+
export {};
|
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
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");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
2
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
9
|
};
|
|
10
|
+
var _SmartTransactionsController_instances, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction;
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
12
|
exports.DEFAULT_INTERVAL = void 0;
|
|
7
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
8
13
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
14
|
+
const polling_controller_1 = require("@metamask/polling-controller");
|
|
9
15
|
const bignumber_js_1 = require("bignumber.js");
|
|
10
|
-
const
|
|
11
|
-
const providers_1 = require("@ethersproject/providers");
|
|
16
|
+
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
12
17
|
const bytes_1 = require("@ethersproject/bytes");
|
|
13
|
-
const mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
14
18
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
15
19
|
const types_1 = require("./types");
|
|
16
20
|
const utils_1 = require("./utils");
|
|
17
21
|
const constants_1 = require("./constants");
|
|
18
22
|
const SECOND = 1000;
|
|
19
23
|
exports.DEFAULT_INTERVAL = SECOND * 5;
|
|
20
|
-
class SmartTransactionsController extends
|
|
21
|
-
constructor({ onNetworkStateChange, getNonceLock,
|
|
24
|
+
class SmartTransactionsController extends polling_controller_1.PollingControllerV1 {
|
|
25
|
+
constructor({ onNetworkStateChange, getNonceLock, provider, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, }, config, state) {
|
|
22
26
|
super(config, state);
|
|
27
|
+
_SmartTransactionsController_instances.add(this);
|
|
23
28
|
this.defaultConfig = {
|
|
24
29
|
interval: exports.DEFAULT_INTERVAL,
|
|
25
|
-
chainId:
|
|
30
|
+
chainId: controller_utils_1.ChainId.mainnet,
|
|
26
31
|
clientId: 'default',
|
|
27
|
-
supportedChainIds: [constants_1.CHAIN_IDS.ETHEREUM, constants_1.CHAIN_IDS.
|
|
32
|
+
supportedChainIds: [constants_1.CHAIN_IDS.ETHEREUM, constants_1.CHAIN_IDS.GOERLI],
|
|
28
33
|
};
|
|
29
34
|
this.defaultState = {
|
|
30
35
|
smartTransactionsState: {
|
|
@@ -35,13 +40,28 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
35
40
|
tradeTxFees: undefined,
|
|
36
41
|
},
|
|
37
42
|
liveness: true,
|
|
43
|
+
livenessByChainId: {
|
|
44
|
+
[constants_1.CHAIN_IDS.ETHEREUM]: true,
|
|
45
|
+
[constants_1.CHAIN_IDS.GOERLI]: true,
|
|
46
|
+
},
|
|
47
|
+
feesByChainId: {
|
|
48
|
+
[constants_1.CHAIN_IDS.ETHEREUM]: {
|
|
49
|
+
approvalTxFees: undefined,
|
|
50
|
+
tradeTxFees: undefined,
|
|
51
|
+
},
|
|
52
|
+
[constants_1.CHAIN_IDS.GOERLI]: {
|
|
53
|
+
approvalTxFees: undefined,
|
|
54
|
+
tradeTxFees: undefined,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
38
57
|
},
|
|
39
58
|
};
|
|
59
|
+
this.setIntervalLength(this.config.interval || exports.DEFAULT_INTERVAL);
|
|
40
60
|
this.getNonceLock = getNonceLock;
|
|
41
|
-
this.
|
|
42
|
-
this.ethersProvider = new providers_1.Web3Provider(provider);
|
|
61
|
+
this.ethQuery = new eth_query_1.default(provider);
|
|
43
62
|
this.confirmExternalTransaction = confirmExternalTransaction;
|
|
44
63
|
this.trackMetaMetricsEvent = trackMetaMetricsEvent;
|
|
64
|
+
this.getNetworkClientById = getNetworkClientById;
|
|
45
65
|
this.initialize();
|
|
46
66
|
this.initializeSmartTransactionsForChainId();
|
|
47
67
|
onNetworkStateChange(({ providerConfig: newProvider }) => {
|
|
@@ -49,7 +69,7 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
49
69
|
this.configure({ chainId });
|
|
50
70
|
this.initializeSmartTransactionsForChainId();
|
|
51
71
|
this.checkPoll(this.state);
|
|
52
|
-
this.
|
|
72
|
+
this.ethQuery = new eth_query_1.default(provider);
|
|
53
73
|
});
|
|
54
74
|
this.subscribe((currentState) => this.checkPoll(currentState));
|
|
55
75
|
}
|
|
@@ -59,6 +79,17 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
59
79
|
const fetchOptions = Object.assign(Object.assign({}, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, (clientId && { 'X-Client-Id': clientId })) });
|
|
60
80
|
return (0, utils_1.handleFetch)(request, fetchOptions);
|
|
61
81
|
}
|
|
82
|
+
_executePoll(networkClientId) {
|
|
83
|
+
// if this is going to be truly UI driven polling we shouldn't really reach here
|
|
84
|
+
// with a networkClientId that is not supported, but for now I'll add a check in case
|
|
85
|
+
// wondering if we should add some kind of predicate to the polling controller to check whether
|
|
86
|
+
// we should poll or not
|
|
87
|
+
const chainId = this.getChainId({ networkClientId });
|
|
88
|
+
if (!this.config.supportedChainIds.includes(chainId)) {
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
return this.updateSmartTransactions({ networkClientId });
|
|
92
|
+
}
|
|
62
93
|
checkPoll(state) {
|
|
63
94
|
const { smartTransactions } = state.smartTransactionsState;
|
|
64
95
|
const currentSmartTransactions = smartTransactions[this.config.chainId];
|
|
@@ -134,123 +165,49 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
134
165
|
const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransactionUuid);
|
|
135
166
|
return currentIndex === -1 || currentIndex === undefined;
|
|
136
167
|
}
|
|
137
|
-
updateSmartTransaction(smartTransaction) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
? undefined
|
|
146
|
-
: currentSmartTransactions[currentIndex]);
|
|
147
|
-
if (isNewSmartTransaction) {
|
|
148
|
-
// add smart transaction
|
|
149
|
-
const cancelledNonceIndex = currentSmartTransactions.findIndex((stx) => {
|
|
150
|
-
var _a, _b, _c;
|
|
151
|
-
return ((_a = stx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === ((_b = smartTransaction.txParams) === null || _b === void 0 ? void 0 : _b.nonce) &&
|
|
152
|
-
((_c = stx.status) === null || _c === void 0 ? void 0 : _c.startsWith('cancelled'));
|
|
153
|
-
});
|
|
154
|
-
const snapshot = (0, cloneDeep_1.default)(smartTransaction);
|
|
155
|
-
const history = [snapshot];
|
|
156
|
-
const historifiedSmartTransaction = Object.assign(Object.assign({}, smartTransaction), { history });
|
|
157
|
-
const nextSmartTransactions = cancelledNonceIndex > -1
|
|
158
|
-
? currentSmartTransactions
|
|
159
|
-
.slice(0, cancelledNonceIndex)
|
|
160
|
-
.concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))
|
|
161
|
-
.concat(historifiedSmartTransaction)
|
|
162
|
-
: currentSmartTransactions.concat(historifiedSmartTransaction);
|
|
163
|
-
this.update({
|
|
164
|
-
smartTransactionsState: Object.assign(Object.assign({}, smartTransactionsState), { smartTransactions: Object.assign(Object.assign({}, smartTransactionsState.smartTransactions), { [chainId]: nextSmartTransactions }) }),
|
|
165
|
-
});
|
|
166
|
-
return;
|
|
168
|
+
updateSmartTransaction(smartTransaction, { networkClientId } = {}) {
|
|
169
|
+
let { chainId } = this.config;
|
|
170
|
+
let { ethQuery } = this;
|
|
171
|
+
if (networkClientId) {
|
|
172
|
+
const networkClient = this.getNetworkClientById(networkClientId);
|
|
173
|
+
chainId = networkClient.configuration.chainId;
|
|
174
|
+
// @ts-expect-error TODO: Provider type alignment
|
|
175
|
+
ethQuery = new eth_query_1.default(networkClient.provider);
|
|
167
176
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// confirm smart transaction
|
|
172
|
-
const currentSmartTransaction = currentSmartTransactions[currentIndex];
|
|
173
|
-
const nextSmartTransaction = Object.assign(Object.assign({}, currentSmartTransaction), smartTransaction);
|
|
174
|
-
this.confirmSmartTransaction(nextSmartTransaction);
|
|
175
|
-
}
|
|
176
|
-
this.update({
|
|
177
|
-
smartTransactionsState: Object.assign(Object.assign({}, smartTransactionsState), { smartTransactions: Object.assign(Object.assign({}, smartTransactionsState.smartTransactions), { [chainId]: smartTransactionsState.smartTransactions[chainId].map((item, index) => {
|
|
178
|
-
return index === currentIndex
|
|
179
|
-
? Object.assign(Object.assign({}, item), smartTransaction) : item;
|
|
180
|
-
}) }) }),
|
|
177
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, smartTransaction, {
|
|
178
|
+
chainId,
|
|
179
|
+
ethQuery,
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
|
-
async updateSmartTransactions() {
|
|
182
|
+
async updateSmartTransactions({ networkClientId, } = {}) {
|
|
184
183
|
const { smartTransactions } = this.state.smartTransactionsState;
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const transactionsToUpdate =
|
|
184
|
+
const chainId = this.getChainId({ networkClientId });
|
|
185
|
+
const smartTransactionsForChainId = smartTransactions === null || smartTransactions === void 0 ? void 0 : smartTransactions[chainId];
|
|
186
|
+
const transactionsToUpdate = smartTransactionsForChainId
|
|
188
187
|
.filter(utils_1.isSmartTransactionPending)
|
|
189
188
|
.map((smartTransaction) => smartTransaction.uuid);
|
|
190
189
|
if (transactionsToUpdate.length > 0) {
|
|
191
|
-
this.fetchSmartTransactionsStatus(transactionsToUpdate
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
async confirmSmartTransaction(smartTransaction) {
|
|
195
|
-
var _a, _b, _c;
|
|
196
|
-
const txHash = (_a = smartTransaction.statusMetadata) === null || _a === void 0 ? void 0 : _a.minedHash;
|
|
197
|
-
try {
|
|
198
|
-
const transactionReceipt = await this.ethersProvider.getTransactionReceipt(txHash);
|
|
199
|
-
const transaction = await this.ethersProvider.getTransaction(txHash);
|
|
200
|
-
const maxFeePerGas = (_b = transaction.maxFeePerGas) === null || _b === void 0 ? void 0 : _b.toHexString();
|
|
201
|
-
const maxPriorityFeePerGas = (_c = transaction.maxPriorityFeePerGas) === null || _c === void 0 ? void 0 : _c.toHexString();
|
|
202
|
-
if (transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber) {
|
|
203
|
-
const blockData = await this.ethersProvider.getBlock(transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber, false);
|
|
204
|
-
const baseFeePerGas = blockData === null || blockData === void 0 ? void 0 : blockData.baseFeePerGas.toHexString();
|
|
205
|
-
const txReceipt = (0, mapValues_1.default)(transactionReceipt, (value) => {
|
|
206
|
-
if (value instanceof bignumber_1.BigNumber) {
|
|
207
|
-
return value.toHexString();
|
|
208
|
-
}
|
|
209
|
-
return value;
|
|
210
|
-
});
|
|
211
|
-
const updatedTxParams = Object.assign(Object.assign({}, smartTransaction.txParams), { maxFeePerGas,
|
|
212
|
-
maxPriorityFeePerGas });
|
|
213
|
-
// call confirmExternalTransaction
|
|
214
|
-
const originalTxMeta = Object.assign(Object.assign({}, smartTransaction), { id: smartTransaction.uuid, status: 'confirmed', hash: txHash, txParams: updatedTxParams });
|
|
215
|
-
// create txMeta snapshot for history
|
|
216
|
-
const snapshot = (0, utils_1.snapshotFromTxMeta)(originalTxMeta);
|
|
217
|
-
// recover previous tx state obj
|
|
218
|
-
const previousState = (0, utils_1.replayHistory)(originalTxMeta.history);
|
|
219
|
-
// generate history entry and add to history
|
|
220
|
-
const entry = (0, utils_1.generateHistoryEntry)(previousState, snapshot, 'txStateManager: setting status to confirmed');
|
|
221
|
-
const txMeta = entry.length > 0
|
|
222
|
-
? Object.assign(Object.assign({}, originalTxMeta), { history: originalTxMeta.history.concat(entry) }) : originalTxMeta;
|
|
223
|
-
this.confirmExternalTransaction(txMeta, txReceipt, baseFeePerGas);
|
|
224
|
-
this.trackMetaMetricsEvent({
|
|
225
|
-
event: 'STX Confirmed',
|
|
226
|
-
category: 'swaps',
|
|
227
|
-
});
|
|
228
|
-
this.updateSmartTransaction(Object.assign(Object.assign({}, smartTransaction), { confirmed: true }));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (e) {
|
|
232
|
-
this.trackMetaMetricsEvent({
|
|
233
|
-
event: 'STX Confirmation Failed',
|
|
234
|
-
category: 'swaps',
|
|
190
|
+
this.fetchSmartTransactionsStatus(transactionsToUpdate, {
|
|
191
|
+
networkClientId,
|
|
235
192
|
});
|
|
236
|
-
console.error('confirm error', e);
|
|
237
193
|
}
|
|
238
194
|
}
|
|
239
195
|
// ! Ask backend API to accept list of uuids as params
|
|
240
|
-
async fetchSmartTransactionsStatus(uuids) {
|
|
241
|
-
const { chainId } = this.config;
|
|
196
|
+
async fetchSmartTransactionsStatus(uuids, { networkClientId } = {}) {
|
|
242
197
|
const params = new URLSearchParams({
|
|
243
198
|
uuids: uuids.join(','),
|
|
244
199
|
});
|
|
200
|
+
const chainId = this.getChainId({ networkClientId });
|
|
201
|
+
const ethQuery = this.getEthQuery({ networkClientId });
|
|
245
202
|
const url = `${(0, utils_1.getAPIRequestURL)(types_1.APIType.BATCH_STATUS, chainId)}?${params.toString()}`;
|
|
246
203
|
const data = await this.fetch(url);
|
|
247
204
|
Object.entries(data).forEach(([uuid, stxStatus]) => {
|
|
248
|
-
this.
|
|
205
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, {
|
|
249
206
|
statusMetadata: stxStatus,
|
|
250
207
|
status: (0, utils_1.calculateStatus)(stxStatus),
|
|
251
208
|
cancellable: (0, utils_1.isSmartTransactionCancellable)(stxStatus),
|
|
252
209
|
uuid,
|
|
253
|
-
});
|
|
210
|
+
}, { chainId, ethQuery });
|
|
254
211
|
});
|
|
255
212
|
return data;
|
|
256
213
|
}
|
|
@@ -270,8 +227,8 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
270
227
|
});
|
|
271
228
|
return fees;
|
|
272
229
|
}
|
|
273
|
-
async getFees(tradeTx, approvalTx) {
|
|
274
|
-
const
|
|
230
|
+
async getFees(tradeTx, approvalTx, { networkClientId } = {}) {
|
|
231
|
+
const chainId = this.getChainId({ networkClientId });
|
|
275
232
|
const transactions = [];
|
|
276
233
|
let unsignedTradeTransactionWithNonce;
|
|
277
234
|
if (approvalTx) {
|
|
@@ -304,7 +261,10 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
304
261
|
smartTransactionsState: Object.assign(Object.assign({}, this.state.smartTransactionsState), { fees: {
|
|
305
262
|
approvalTxFees,
|
|
306
263
|
tradeTxFees,
|
|
307
|
-
} }),
|
|
264
|
+
}, feesByChainId: Object.assign(Object.assign({}, this.state.smartTransactionsState.feesByChainId), { [chainId]: {
|
|
265
|
+
approvalTxFees,
|
|
266
|
+
tradeTxFees,
|
|
267
|
+
} }) }),
|
|
308
268
|
});
|
|
309
269
|
return {
|
|
310
270
|
approvalTxFees,
|
|
@@ -313,8 +273,9 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
313
273
|
}
|
|
314
274
|
// * After this successful call client must add a nonce representative to
|
|
315
275
|
// * transaction controller external transactions list
|
|
316
|
-
async submitSignedTransactions({ txParams, signedTransactions, signedCanceledTransactions, }) {
|
|
317
|
-
const
|
|
276
|
+
async submitSignedTransactions({ txParams, signedTransactions, signedCanceledTransactions, networkClientId, }) {
|
|
277
|
+
const chainId = this.getChainId({ networkClientId });
|
|
278
|
+
const ethQuery = this.getEthQuery({ networkClientId });
|
|
318
279
|
const data = await this.fetch((0, utils_1.getAPIRequestURL)(types_1.APIType.SUBMIT_TRANSACTIONS, chainId), {
|
|
319
280
|
method: 'POST',
|
|
320
281
|
body: JSON.stringify({
|
|
@@ -323,14 +284,15 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
323
284
|
}),
|
|
324
285
|
});
|
|
325
286
|
const time = Date.now();
|
|
326
|
-
const metamaskNetworkId = this.getNetwork();
|
|
327
287
|
let preTxBalance;
|
|
328
288
|
try {
|
|
329
|
-
const preTxBalanceBN = await
|
|
330
|
-
|
|
289
|
+
const preTxBalanceBN = await (0, controller_utils_1.query)(ethQuery, 'getBalance', [
|
|
290
|
+
txParams === null || txParams === void 0 ? void 0 : txParams.from,
|
|
291
|
+
]);
|
|
292
|
+
preTxBalance = new bignumber_js_1.BigNumber(preTxBalanceBN).toString(16);
|
|
331
293
|
}
|
|
332
294
|
catch (e) {
|
|
333
|
-
console.error('
|
|
295
|
+
console.error('provider error', e);
|
|
334
296
|
}
|
|
335
297
|
const nonceLock = await this.getNonceLock(txParams === null || txParams === void 0 ? void 0 : txParams.from);
|
|
336
298
|
try {
|
|
@@ -339,35 +301,44 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
339
301
|
txParams.nonce = nonce;
|
|
340
302
|
}
|
|
341
303
|
const { nonceDetails } = nonceLock;
|
|
342
|
-
this.
|
|
343
|
-
chainId,
|
|
304
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, {
|
|
344
305
|
nonceDetails,
|
|
345
|
-
metamaskNetworkId,
|
|
346
306
|
preTxBalance,
|
|
347
307
|
status: types_1.SmartTransactionStatuses.PENDING,
|
|
348
308
|
time,
|
|
349
309
|
txParams,
|
|
350
310
|
uuid: data.uuid,
|
|
351
311
|
cancellable: true,
|
|
352
|
-
});
|
|
312
|
+
}, { chainId, ethQuery });
|
|
353
313
|
}
|
|
354
314
|
finally {
|
|
355
315
|
nonceLock.releaseLock();
|
|
356
316
|
}
|
|
357
317
|
return data;
|
|
358
318
|
}
|
|
319
|
+
getChainId({ networkClientId, } = {}) {
|
|
320
|
+
return networkClientId
|
|
321
|
+
? this.getNetworkClientById(networkClientId).configuration.chainId
|
|
322
|
+
: this.config.chainId;
|
|
323
|
+
}
|
|
324
|
+
getEthQuery({ networkClientId, }) {
|
|
325
|
+
return networkClientId
|
|
326
|
+
? // @ts-expect-error TODO: Provider type alignment
|
|
327
|
+
new eth_query_1.default(this.getNetworkClientById(networkClientId).provider)
|
|
328
|
+
: this.ethQuery;
|
|
329
|
+
}
|
|
359
330
|
// TODO: This should return if the cancellation was on chain or not (for nonce management)
|
|
360
331
|
// After this successful call client must update nonce representative
|
|
361
332
|
// in transaction controller external transactions list
|
|
362
|
-
async cancelSmartTransaction(uuid) {
|
|
363
|
-
const
|
|
333
|
+
async cancelSmartTransaction(uuid, { networkClientId, } = {}) {
|
|
334
|
+
const chainId = this.getChainId({ networkClientId });
|
|
364
335
|
await this.fetch((0, utils_1.getAPIRequestURL)(types_1.APIType.CANCEL, chainId), {
|
|
365
336
|
method: 'POST',
|
|
366
337
|
body: JSON.stringify({ uuid }),
|
|
367
338
|
});
|
|
368
339
|
}
|
|
369
|
-
async fetchLiveness() {
|
|
370
|
-
const
|
|
340
|
+
async fetchLiveness({ networkClientId, } = {}) {
|
|
341
|
+
const chainId = this.getChainId({ networkClientId });
|
|
371
342
|
let liveness = false;
|
|
372
343
|
try {
|
|
373
344
|
const response = await this.fetch((0, utils_1.getAPIRequestURL)(types_1.APIType.LIVENESS, chainId));
|
|
@@ -377,7 +348,7 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
377
348
|
console.log('"fetchLiveness" API call failed');
|
|
378
349
|
}
|
|
379
350
|
this.update({
|
|
380
|
-
smartTransactionsState: Object.assign(Object.assign({}, this.state.smartTransactionsState), { liveness }),
|
|
351
|
+
smartTransactionsState: Object.assign(Object.assign({}, this.state.smartTransactionsState), { liveness, livenessByChainId: Object.assign(Object.assign({}, this.state.smartTransactionsState.livenessByChainId), { [chainId]: liveness }) }),
|
|
381
352
|
});
|
|
382
353
|
return liveness;
|
|
383
354
|
}
|
|
@@ -400,4 +371,91 @@ class SmartTransactionsController extends base_controller_1.BaseController {
|
|
|
400
371
|
}
|
|
401
372
|
}
|
|
402
373
|
exports.default = SmartTransactionsController;
|
|
374
|
+
_SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_updateSmartTransaction = function _SmartTransactionsController_updateSmartTransaction(smartTransaction, { chainId = this.config.chainId, ethQuery = this.ethQuery, }) {
|
|
375
|
+
const { smartTransactionsState } = this.state;
|
|
376
|
+
const { smartTransactions } = smartTransactionsState;
|
|
377
|
+
const currentSmartTransactions = smartTransactions[chainId];
|
|
378
|
+
const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransaction.uuid);
|
|
379
|
+
const isNewSmartTransaction = this.isNewSmartTransaction(smartTransaction.uuid);
|
|
380
|
+
this.trackStxStatusChange(smartTransaction, isNewSmartTransaction
|
|
381
|
+
? undefined
|
|
382
|
+
: currentSmartTransactions[currentIndex]);
|
|
383
|
+
if (isNewSmartTransaction) {
|
|
384
|
+
// add smart transaction
|
|
385
|
+
const cancelledNonceIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => {
|
|
386
|
+
var _a, _b, _c;
|
|
387
|
+
return ((_a = stx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === ((_b = smartTransaction.txParams) === null || _b === void 0 ? void 0 : _b.nonce) &&
|
|
388
|
+
((_c = stx.status) === null || _c === void 0 ? void 0 : _c.startsWith('cancelled'));
|
|
389
|
+
});
|
|
390
|
+
const snapshot = (0, cloneDeep_1.default)(smartTransaction);
|
|
391
|
+
const history = [snapshot];
|
|
392
|
+
const historifiedSmartTransaction = Object.assign(Object.assign({}, smartTransaction), { history });
|
|
393
|
+
const nextSmartTransactions = cancelledNonceIndex > -1
|
|
394
|
+
? currentSmartTransactions
|
|
395
|
+
.slice(0, cancelledNonceIndex)
|
|
396
|
+
.concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))
|
|
397
|
+
.concat(historifiedSmartTransaction)
|
|
398
|
+
: currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.concat(historifiedSmartTransaction);
|
|
399
|
+
this.update({
|
|
400
|
+
smartTransactionsState: Object.assign(Object.assign({}, smartTransactionsState), { smartTransactions: Object.assign(Object.assign({}, smartTransactionsState.smartTransactions), { [chainId]: nextSmartTransactions }) }),
|
|
401
|
+
});
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if ((smartTransaction.status === types_1.SmartTransactionStatuses.SUCCESS ||
|
|
405
|
+
smartTransaction.status === types_1.SmartTransactionStatuses.REVERTED) &&
|
|
406
|
+
!smartTransaction.confirmed) {
|
|
407
|
+
// confirm smart transaction
|
|
408
|
+
const currentSmartTransaction = currentSmartTransactions[currentIndex];
|
|
409
|
+
const nextSmartTransaction = Object.assign(Object.assign({}, currentSmartTransaction), smartTransaction);
|
|
410
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_confirmSmartTransaction).call(this, nextSmartTransaction, {
|
|
411
|
+
chainId,
|
|
412
|
+
ethQuery,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
this.update({
|
|
416
|
+
smartTransactionsState: Object.assign(Object.assign({}, smartTransactionsState), { smartTransactions: Object.assign(Object.assign({}, smartTransactionsState.smartTransactions), { [chainId]: smartTransactionsState.smartTransactions[chainId].map((item, index) => {
|
|
417
|
+
return index === currentIndex
|
|
418
|
+
? Object.assign(Object.assign({}, item), smartTransaction) : item;
|
|
419
|
+
}) }) }),
|
|
420
|
+
});
|
|
421
|
+
}, _SmartTransactionsController_confirmSmartTransaction = async function _SmartTransactionsController_confirmSmartTransaction(smartTransaction, { chainId, ethQuery, }) {
|
|
422
|
+
var _a;
|
|
423
|
+
const txHash = (_a = smartTransaction.statusMetadata) === null || _a === void 0 ? void 0 : _a.minedHash;
|
|
424
|
+
try {
|
|
425
|
+
const transactionReceipt = await (0, controller_utils_1.query)(ethQuery, 'getTransactionReceipt', [txHash]);
|
|
426
|
+
const transaction = await (0, controller_utils_1.query)(ethQuery, 'getTransactionByHash', [txHash]);
|
|
427
|
+
const maxFeePerGas = transaction === null || transaction === void 0 ? void 0 : transaction.maxFeePerGas;
|
|
428
|
+
const maxPriorityFeePerGas = transaction === null || transaction === void 0 ? void 0 : transaction.maxPriorityFeePerGas;
|
|
429
|
+
if (transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber) {
|
|
430
|
+
const blockData = await (0, controller_utils_1.query)(ethQuery, 'getBlockByNumber', [transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber, false]);
|
|
431
|
+
const baseFeePerGas = blockData === null || blockData === void 0 ? void 0 : blockData.baseFeePerGas;
|
|
432
|
+
const txReceipt = Object.values(transactionReceipt);
|
|
433
|
+
const updatedTxParams = Object.assign(Object.assign({}, smartTransaction.txParams), { maxFeePerGas,
|
|
434
|
+
maxPriorityFeePerGas });
|
|
435
|
+
// call confirmExternalTransaction
|
|
436
|
+
const originalTxMeta = Object.assign(Object.assign({}, smartTransaction), { id: smartTransaction.uuid, status: 'confirmed', hash: txHash, txParams: updatedTxParams });
|
|
437
|
+
// create txMeta snapshot for history
|
|
438
|
+
const snapshot = (0, utils_1.snapshotFromTxMeta)(originalTxMeta);
|
|
439
|
+
// recover previous tx state obj
|
|
440
|
+
const previousState = (0, utils_1.replayHistory)(originalTxMeta.history);
|
|
441
|
+
// generate history entry and add to history
|
|
442
|
+
const entry = (0, utils_1.generateHistoryEntry)(previousState, snapshot, 'txStateManager: setting status to confirmed');
|
|
443
|
+
const txMeta = entry.length > 0
|
|
444
|
+
? Object.assign(Object.assign({}, originalTxMeta), { history: originalTxMeta.history.concat(entry) }) : originalTxMeta;
|
|
445
|
+
this.confirmExternalTransaction(txMeta, txReceipt, baseFeePerGas);
|
|
446
|
+
this.trackMetaMetricsEvent({
|
|
447
|
+
event: 'STX Confirmed',
|
|
448
|
+
category: 'swaps',
|
|
449
|
+
});
|
|
450
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, Object.assign(Object.assign({}, smartTransaction), { confirmed: true }), { chainId, ethQuery });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
catch (e) {
|
|
454
|
+
this.trackMetaMetricsEvent({
|
|
455
|
+
event: 'STX Confirmation Failed',
|
|
456
|
+
category: 'swaps',
|
|
457
|
+
});
|
|
458
|
+
console.error('confirm error', e);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
403
461
|
//# sourceMappingURL=SmartTransactionsController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTransactionsController.js","sourceRoot":"","sources":["../src/SmartTransactionsController.ts"],"names":[],"mappings":";;;;;;AAAA,+DAImC;AACnC,iEAA2D;AAE3D,+CAAyC;AACzC,wDAAwE;AACxE,wDAAwD;AACxD,gDAA+C;AAC/C,iEAAyC;AACzC,iEAAyC;AACzC,mCAUiB;AACjB,mCAWiB;AACjB,2CAAwC;AAExC,MAAM,MAAM,GAAG,IAAI,CAAC;AACP,QAAA,gBAAgB,GAAG,MAAM,GAAG,CAAC,CAAC;AAqB3C,MAAqB,2BAA4B,SAAQ,gCAGxD;IA2BC,YACE,EACE,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,0BAA0B,EAC1B,qBAAqB,GAUtB,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SACX;QAED,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;;YAC7C,OAAO,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,CAAA,MAAA,GAAG,CAAC,QAAQ,0CAAE,IAAI,MAAK,WAAW,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5kBD,8CA4kBC","sourcesContent":["import {\n BaseConfig,\n BaseController,\n BaseState,\n} from '@metamask/base-controller';\nimport { safelyExecute } from '@metamask/controller-utils';\nimport { NetworkState } from '@metamask/network-controller';\nimport { BigNumber } from 'bignumber.js';\nimport { BigNumber as ethersBigNumber } from '@ethersproject/bignumber';\nimport { Web3Provider } from '@ethersproject/providers';\nimport { hexlify } from '@ethersproject/bytes';\nimport mapValues from 'lodash/mapValues';\nimport cloneDeep from 'lodash/cloneDeep';\nimport {\n APIType,\n SmartTransaction,\n SignedTransaction,\n SignedCanceledTransaction,\n UnsignedTransaction,\n SmartTransactionsStatus,\n SmartTransactionStatuses,\n Fees,\n IndividualTxFees,\n} from './types';\nimport {\n getAPIRequestURL,\n isSmartTransactionPending,\n calculateStatus,\n snapshotFromTxMeta,\n replayHistory,\n generateHistoryEntry,\n getStxProcessingTime,\n handleFetch,\n isSmartTransactionCancellable,\n incrementNonceInHex,\n} from './utils';\nimport { CHAIN_IDS } from './constants';\n\nconst SECOND = 1000;\nexport const DEFAULT_INTERVAL = SECOND * 5;\n\nexport type SmartTransactionsControllerConfig = BaseConfig & {\n interval: number;\n clientId: string;\n chainId: string;\n supportedChainIds: string[];\n};\n\nexport type SmartTransactionsControllerState = BaseState & {\n smartTransactionsState: {\n smartTransactions: Record<string, SmartTransaction[]>;\n userOptIn: boolean | undefined;\n liveness: boolean | undefined;\n fees: {\n approvalTxFees: IndividualTxFees | undefined;\n tradeTxFees: IndividualTxFees | undefined;\n };\n };\n};\n\nexport default class SmartTransactionsController extends BaseController<\n SmartTransactionsControllerConfig,\n SmartTransactionsControllerState\n> {\n public timeoutHandle?: NodeJS.Timeout;\n\n private getNonceLock: any;\n\n private getNetwork: any;\n\n public ethersProvider: any;\n\n public confirmExternalTransaction: any;\n\n private trackMetaMetricsEvent: any;\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 getNetwork,\n provider,\n confirmExternalTransaction,\n trackMetaMetricsEvent,\n }: {\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n getNonceLock: any;\n getNetwork: any;\n provider: any;\n confirmExternalTransaction: any;\n trackMetaMetricsEvent: any;\n },\n config?: Partial<SmartTransactionsControllerConfig>,\n state?: Partial<SmartTransactionsControllerState>,\n ) {\n super(config, state);\n\n this.defaultConfig = {\n interval: DEFAULT_INTERVAL,\n chainId: CHAIN_IDS.ETHEREUM,\n clientId: 'default',\n supportedChainIds: [CHAIN_IDS.ETHEREUM, CHAIN_IDS.RINKEBY],\n };\n\n this.defaultState = {\n smartTransactionsState: {\n smartTransactions: {},\n userOptIn: undefined,\n fees: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n liveness: true,\n },\n };\n\n this.getNonceLock = getNonceLock;\n this.getNetwork = getNetwork;\n this.ethersProvider = new Web3Provider(provider);\n this.confirmExternalTransaction = confirmExternalTransaction;\n this.trackMetaMetricsEvent = trackMetaMetricsEvent;\n\n this.initialize();\n this.initializeSmartTransactionsForChainId();\n\n onNetworkStateChange(({ providerConfig: newProvider }) => {\n const { chainId } = newProvider;\n this.configure({ chainId });\n this.initializeSmartTransactionsForChainId();\n this.checkPoll(this.state);\n this.ethersProvider = new Web3Provider(provider);\n });\n\n this.subscribe((currentState: any) => this.checkPoll(currentState));\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 await safelyExecute(() => this.updateSmartTransactions());\n this.timeoutHandle = setInterval(() => {\n safelyExecute(() => this.updateSmartTransactions());\n }, this.config.interval);\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 userOptIn: state,\n },\n });\n }\n\n trackStxStatusChange(\n smartTransaction: SmartTransaction,\n prevSmartTransaction?: SmartTransaction,\n ) {\n if (!prevSmartTransaction) {\n return; // Don't track the first STX, because it doesn't have all necessary params.\n }\n\n let updatedSmartTransaction = cloneDeep(smartTransaction);\n updatedSmartTransaction = {\n ...cloneDeep(prevSmartTransaction),\n ...updatedSmartTransaction,\n };\n\n if (\n !updatedSmartTransaction.swapMetaData ||\n (updatedSmartTransaction.status === prevSmartTransaction.status &&\n prevSmartTransaction.swapMetaData)\n ) {\n return; // If status hasn't changed, don't track it again.\n }\n\n const sensitiveProperties = {\n stx_status: updatedSmartTransaction.status,\n token_from_symbol: updatedSmartTransaction.sourceTokenSymbol,\n token_to_symbol: updatedSmartTransaction.destinationTokenSymbol,\n processing_time: getStxProcessingTime(updatedSmartTransaction.time),\n stx_enabled: true,\n current_stx_enabled: true,\n stx_user_opt_in: true,\n };\n\n this.trackMetaMetricsEvent({\n event: 'STX Status Updated',\n category: 'swaps',\n sensitiveProperties,\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(smartTransaction: SmartTransaction): void {\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 === smartTransaction.uuid,\n );\n const isNewSmartTransaction = this.isNewSmartTransaction(\n smartTransaction.uuid,\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 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 this.confirmSmartTransaction(nextSmartTransaction);\n }\n\n this.update({\n smartTransactionsState: {\n ...smartTransactionsState,\n smartTransactions: {\n ...smartTransactionsState.smartTransactions,\n [chainId]: smartTransactionsState.smartTransactions[chainId].map(\n (item, index) => {\n return index === currentIndex\n ? { ...item, ...smartTransaction }\n : item;\n },\n ),\n },\n },\n });\n }\n\n async updateSmartTransactions() {\n const { smartTransactions } = this.state.smartTransactionsState;\n const { chainId } = this.config;\n\n const currentSmartTransactions = smartTransactions?.[chainId];\n\n const transactionsToUpdate: string[] = currentSmartTransactions\n .filter(isSmartTransactionPending)\n .map((smartTransaction) => smartTransaction.uuid);\n\n if (transactionsToUpdate.length > 0) {\n this.fetchSmartTransactionsStatus(transactionsToUpdate);\n }\n }\n\n async confirmSmartTransaction(smartTransaction: SmartTransaction) {\n const txHash = smartTransaction.statusMetadata?.minedHash;\n try {\n const transactionReceipt =\n await this.ethersProvider.getTransactionReceipt(txHash);\n const transaction = await this.ethersProvider.getTransaction(txHash);\n const maxFeePerGas = transaction.maxFeePerGas?.toHexString();\n const maxPriorityFeePerGas =\n transaction.maxPriorityFeePerGas?.toHexString();\n if (transactionReceipt?.blockNumber) {\n const blockData = await this.ethersProvider.getBlock(\n transactionReceipt?.blockNumber,\n false,\n );\n const baseFeePerGas = blockData?.baseFeePerGas.toHexString();\n const txReceipt = mapValues(transactionReceipt, (value) => {\n if (value instanceof ethersBigNumber) {\n return value.toHexString();\n }\n return value;\n });\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: '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 this.confirmExternalTransaction(txMeta, txReceipt, baseFeePerGas);\n\n this.trackMetaMetricsEvent({\n event: 'STX Confirmed',\n category: 'swaps',\n });\n\n this.updateSmartTransaction({\n ...smartTransaction,\n confirmed: true,\n });\n }\n } catch (e) {\n this.trackMetaMetricsEvent({\n event: 'STX Confirmation Failed',\n category: 'swaps',\n });\n console.error('confirm error', e);\n }\n }\n\n // ! Ask backend API to accept list of uuids as params\n async fetchSmartTransactionsStatus(\n uuids: string[],\n ): Promise<SmartTransaction[]> {\n const { chainId } = this.config;\n\n const params = new URLSearchParams({\n uuids: uuids.join(','),\n });\n\n const url = `${getAPIRequestURL(\n APIType.BATCH_STATUS,\n chainId,\n )}?${params.toString()}`;\n\n const data = await this.fetch(url);\n\n Object.entries(data).forEach(([uuid, stxStatus]) => {\n this.updateSmartTransaction({\n statusMetadata: stxStatus as SmartTransactionsStatus,\n status: calculateStatus(stxStatus as SmartTransactionsStatus),\n cancellable: isSmartTransactionCancellable(\n stxStatus as SmartTransactionsStatus,\n ),\n uuid,\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 ): Promise<Fees> {\n const { chainId } = this.config;\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 {\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 fees: {\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 txParams,\n signedTransactions,\n signedCanceledTransactions,\n }: {\n signedTransactions: SignedTransaction[];\n signedCanceledTransactions: SignedCanceledTransaction[];\n txParams?: any;\n }) {\n const { chainId } = this.config;\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 const metamaskNetworkId = this.getNetwork();\n let preTxBalance;\n try {\n const preTxBalanceBN = await this.ethersProvider.getBalance(\n txParams?.from,\n );\n preTxBalance = new BigNumber(preTxBalanceBN.toHexString()).toString(16);\n } catch (e) {\n console.error('ethers error', e);\n }\n const nonceLock = await this.getNonceLock(txParams?.from);\n try {\n const nonce = hexlify(nonceLock.nextNonce);\n if (txParams && !txParams?.nonce) {\n txParams.nonce = nonce;\n }\n const { nonceDetails } = nonceLock;\n\n this.updateSmartTransaction({\n chainId,\n nonceDetails,\n metamaskNetworkId,\n preTxBalance,\n status: SmartTransactionStatuses.PENDING,\n time,\n txParams,\n uuid: data.uuid,\n cancellable: true,\n });\n } finally {\n nonceLock.releaseLock();\n }\n\n return data;\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(uuid: string): Promise<void> {\n const { chainId } = this.config;\n await this.fetch(getAPIRequestURL(APIType.CANCEL, chainId), {\n method: 'POST',\n body: JSON.stringify({ uuid }),\n });\n }\n\n async fetchLiveness(): Promise<boolean> {\n const { chainId } = this.config;\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 (e) {\n console.log('\"fetchLiveness\" API call failed');\n }\n\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n liveness,\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 getTransactions({\n addressFrom,\n status,\n }: {\n addressFrom: string;\n status: SmartTransactionStatuses;\n }): 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\n return currentSmartTransactions.filter((stx) => {\n return stx.status === status && stx.txParams?.from === addressFrom;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SmartTransactionsController.js","sourceR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C,MAAM,KAAK,GAAG,IAAA,4BAAoB,EAChC,aAAa,EACb,QAAQ,EACR,6CAA6C,CAC9C,CAAC;YACF,MAAM,MAAM,GACV,KAAK,CAAC,MAAM,GAAG,CAAC;gBACd,CAAC,iCACM,cAAc,KACjB,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAEjD,CAAC,CAAC,cAAc,CAAC;YAErB,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;YAElE,IAAI,CAAC,qBAAqB,CAAC;gBACzB,KAAK,EAAE,eAAe;gBACtB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC;YAEH,uBAAA,IAAI,mGAAwB,MAA5B,IAAI,kCAEG,gBAAgB,KACnB,SAAS,EAAE,IAAI,KAEjB,EAAE,OAAO,EAAE,QAAQ,EAAE,CACtB,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,qBAAqB,CAAC;YACzB,KAAK,EAAE,yBAAyB;YAChC,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;KACnC;AACH,CAAC","sourcesContent":["import { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { ChainId, safelyExecute, query } from '@metamask/controller-utils';\nimport {\n NetworkState,\n NetworkController,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport { PollingControllerV1 } from '@metamask/polling-controller';\nimport { BigNumber } from 'bignumber.js';\nimport EthQuery from '@metamask/eth-query';\nimport { hexlify } from '@ethersproject/bytes';\nimport cloneDeep from 'lodash/cloneDeep';\nimport {\n APIType,\n SmartTransaction,\n SignedTransaction,\n SignedCanceledTransaction,\n UnsignedTransaction,\n SmartTransactionsStatus,\n SmartTransactionStatuses,\n Fees,\n IndividualTxFees,\n Hex,\n} from './types';\nimport {\n getAPIRequestURL,\n isSmartTransactionPending,\n calculateStatus,\n snapshotFromTxMeta,\n replayHistory,\n generateHistoryEntry,\n getStxProcessingTime,\n handleFetch,\n isSmartTransactionCancellable,\n incrementNonceInHex,\n} from './utils';\nimport { CHAIN_IDS } from './constants';\n\nconst SECOND = 1000;\nexport const DEFAULT_INTERVAL = SECOND * 5;\n\nexport type SmartTransactionsControllerConfig = BaseConfig & {\n interval: number;\n clientId: string;\n chainId: Hex;\n supportedChainIds: string[];\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 liveness: boolean | undefined;\n fees: FeeEstimates;\n feesByChainId: Record<Hex, FeeEstimates>;\n livenessByChainId: Record<Hex, boolean>;\n };\n};\n\nexport default class SmartTransactionsController extends PollingControllerV1<\n SmartTransactionsControllerConfig,\n SmartTransactionsControllerState\n> {\n public timeoutHandle?: NodeJS.Timeout;\n\n private getNonceLock: any;\n\n public ethQuery: EthQuery;\n\n public confirmExternalTransaction: any;\n\n private trackMetaMetricsEvent: any;\n\n private getNetworkClientById: NetworkController['getNetworkClientById'];\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 provider,\n confirmExternalTransaction,\n trackMetaMetricsEvent,\n getNetworkClientById,\n }: {\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n getNonceLock: any;\n provider: any;\n confirmExternalTransaction: any;\n trackMetaMetricsEvent: any;\n getNetworkClientById: NetworkController['getNetworkClientById'];\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: [CHAIN_IDS.ETHEREUM, CHAIN_IDS.GOERLI],\n };\n\n this.defaultState = {\n smartTransactionsState: {\n smartTransactions: {},\n userOptIn: undefined,\n fees: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n liveness: true,\n livenessByChainId: {\n [CHAIN_IDS.ETHEREUM]: true,\n [CHAIN_IDS.GOERLI]: true,\n },\n feesByChainId: {\n [CHAIN_IDS.ETHEREUM]: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n [CHAIN_IDS.GOERLI]: {\n approvalTxFees: undefined,\n tradeTxFees: undefined,\n },\n },\n },\n };\n this.setIntervalLength(this.config.interval || DEFAULT_INTERVAL);\n this.getNonceLock = getNonceLock;\n this.ethQuery = new EthQuery(provider);\n this.confirmExternalTransaction = confirmExternalTransaction;\n this.trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.getNetworkClientById = getNetworkClientById;\n\n this.initialize();\n this.initializeSmartTransactionsForChainId();\n\n onNetworkStateChange(({ providerConfig: newProvider }) => {\n const { chainId } = newProvider;\n this.configure({ chainId });\n this.initializeSmartTransactionsForChainId();\n this.checkPoll(this.state);\n this.ethQuery = new EthQuery(provider);\n });\n\n this.subscribe((currentState: any) => this.checkPoll(currentState));\n }\n\n _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 await safelyExecute(() => this.updateSmartTransactions());\n this.timeoutHandle = setInterval(() => {\n safelyExecute(() => this.updateSmartTransactions());\n }, this.config.interval);\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 userOptIn: state,\n },\n });\n }\n\n trackStxStatusChange(\n smartTransaction: SmartTransaction,\n prevSmartTransaction?: SmartTransaction,\n ) {\n if (!prevSmartTransaction) {\n return; // Don't track the first STX, because it doesn't have all necessary params.\n }\n\n let updatedSmartTransaction = cloneDeep(smartTransaction);\n updatedSmartTransaction = {\n ...cloneDeep(prevSmartTransaction),\n ...updatedSmartTransaction,\n };\n\n if (\n !updatedSmartTransaction.swapMetaData ||\n (updatedSmartTransaction.status === prevSmartTransaction.status &&\n prevSmartTransaction.swapMetaData)\n ) {\n return; // If status hasn't changed, don't track it again.\n }\n\n const sensitiveProperties = {\n stx_status: updatedSmartTransaction.status,\n token_from_symbol: updatedSmartTransaction.sourceTokenSymbol,\n token_to_symbol: updatedSmartTransaction.destinationTokenSymbol,\n processing_time: getStxProcessingTime(updatedSmartTransaction.time),\n stx_enabled: true,\n current_stx_enabled: true,\n stx_user_opt_in: true,\n };\n\n this.trackMetaMetricsEvent({\n event: 'STX Status Updated',\n category: 'swaps',\n sensitiveProperties,\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 { chainId } = this.config;\n let { ethQuery } = this;\n if (networkClientId) {\n const networkClient = this.getNetworkClientById(networkClientId);\n chainId = networkClient.configuration.chainId;\n // @ts-expect-error TODO: Provider type alignment\n ethQuery = new EthQuery(networkClient.provider);\n }\n\n this.#updateSmartTransaction(smartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n #updateSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId = this.config.chainId,\n ethQuery = this.ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery;\n },\n ): 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\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 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 this.#confirmSmartTransaction(nextSmartTransaction, {\n chainId,\n ethQuery,\n });\n }\n\n this.update({\n smartTransactionsState: {\n ...smartTransactionsState,\n smartTransactions: {\n ...smartTransactionsState.smartTransactions,\n [chainId]: smartTransactionsState.smartTransactions[chainId].map(\n (item, index) => {\n return index === currentIndex\n ? { ...item, ...smartTransaction }\n : item;\n },\n ),\n },\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 async #confirmSmartTransaction(\n smartTransaction: SmartTransaction,\n {\n chainId,\n ethQuery,\n }: {\n chainId: Hex;\n ethQuery: EthQuery;\n },\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\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 txReceipt = Object.values(transactionReceipt);\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: '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 this.confirmExternalTransaction(txMeta, txReceipt, baseFeePerGas);\n\n this.trackMetaMetricsEvent({\n event: 'STX Confirmed',\n category: 'swaps',\n });\n\n this.#updateSmartTransaction(\n {\n ...smartTransaction,\n confirmed: true,\n },\n { chainId, ethQuery },\n );\n }\n } catch (e) {\n this.trackMetaMetricsEvent({\n event: 'STX Confirmation Failed',\n category: 'swaps',\n });\n console.error('confirm error', e);\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<SmartTransaction[]> {\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);\n Object.entries(data).forEach(([uuid, stxStatus]) => {\n this.#updateSmartTransaction(\n {\n statusMetadata: stxStatus as SmartTransactionsStatus,\n status: calculateStatus(stxStatus as SmartTransactionsStatus),\n cancellable: isSmartTransactionCancellable(\n stxStatus as SmartTransactionsStatus,\n ),\n uuid,\n },\n { chainId, 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 {\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 fees: {\n approvalTxFees,\n tradeTxFees,\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 txParams,\n signedTransactions,\n signedCanceledTransactions,\n networkClientId,\n }: {\n signedTransactions: SignedTransaction[];\n signedCanceledTransactions: SignedCanceledTransaction[];\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 (e) {\n console.error('provider error', e);\n }\n const nonceLock = await this.getNonceLock(txParams?.from);\n try {\n const nonce = hexlify(nonceLock.nextNonce);\n if (txParams && !txParams?.nonce) {\n txParams.nonce = nonce;\n }\n const { nonceDetails } = nonceLock;\n\n this.#updateSmartTransaction(\n {\n nonceDetails,\n preTxBalance,\n status: SmartTransactionStatuses.PENDING,\n time,\n txParams,\n uuid: data.uuid,\n cancellable: true,\n },\n { chainId, ethQuery },\n );\n } finally {\n nonceLock.releaseLock();\n }\n\n return data;\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 return networkClientId\n ? // @ts-expect-error TODO: Provider type alignment\n new EthQuery(this.getNetworkClientById(networkClientId).provider)\n : 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 (e) {\n console.log('\"fetchLiveness\" API call failed');\n }\n\n this.update({\n smartTransactionsState: {\n ...this.state.smartTransactionsState,\n 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 getTransactions({\n addressFrom,\n status,\n }: {\n addressFrom: string;\n status: SmartTransactionStatuses;\n }): 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\n return currentSmartTransactions.filter((stx) => {\n return stx.status === status && stx.txParams?.from === addressFrom;\n });\n }\n}\n"]}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const API_BASE_URL = "https://transaction.metaswap.codefi.network";
|
|
2
2
|
export declare const CHAIN_IDS: {
|
|
3
|
-
ETHEREUM:
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
readonly ETHEREUM: "0x1";
|
|
4
|
+
readonly GOERLI: "0x5";
|
|
5
|
+
readonly RINKEBY: "0x4";
|
|
6
|
+
readonly BSC: "0x38";
|
|
6
7
|
};
|
package/dist/constants.js
CHANGED
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,6CAA6C,CAAC;AAC7D,QAAA,SAAS,GAAG;IACvB,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;IACd,GAAG,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,6CAA6C,CAAC;AAC7D,QAAA,SAAS,GAAG;IACvB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,KAAK;IACd,GAAG,EAAE,MAAM;CACH,CAAC","sourcesContent":["export const API_BASE_URL = 'https://transaction.metaswap.codefi.network';\nexport const CHAIN_IDS = {\n ETHEREUM: '0x1',\n GOERLI: '0x5',\n RINKEBY: '0x4',\n BSC: '0x38',\n} as const;\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -62,7 +62,6 @@ export declare type SmartTransaction = {
|
|
|
62
62
|
destinationTokenDecimals?: string;
|
|
63
63
|
destinationTokenSymbol?: string;
|
|
64
64
|
history?: any;
|
|
65
|
-
metamaskNetworkId?: string;
|
|
66
65
|
nonceDetails?: any;
|
|
67
66
|
origin?: string;
|
|
68
67
|
preTxBalance?: string;
|
|
@@ -95,3 +94,4 @@ export declare type Fees = {
|
|
|
95
94
|
export declare type UnsignedTransaction = any;
|
|
96
95
|
export declare type SignedTransaction = any;
|
|
97
96
|
export declare type SignedCanceledTransaction = any;
|
|
97
|
+
export declare type Hex = `0x${string}`;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,UAAU;;;AAEV,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;AAExB,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":["/** API */\n\nexport enum APIType {\n 'GET_FEES',\n 'ESTIMATE_GAS',\n 'SUBMIT_TRANSACTIONS',\n 'CANCEL',\n 'BATCH_STATUS',\n 'LIVENESS',\n}\n\n/** SmartTransactions */\n\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 | undefined;\n minedTx: SmartTransactionMinedTx;\n isSettled: boolean;\n};\n\nexport type SmartTransaction = {\n uuid: string;\n chainId?: string;\n destinationTokenAddress?: string;\n destinationTokenDecimals?: string;\n destinationTokenSymbol?: string;\n history?: any;\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,UAAU;;;AAEV,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;AAExB,IAAY,uBAMX;AAND,WAAY,uBAAuB;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n\nexport enum APIType {\n 'GET_FEES',\n 'ESTIMATE_GAS',\n 'SUBMIT_TRANSACTIONS',\n 'CANCEL',\n 'BATCH_STATUS',\n 'LIVENESS',\n}\n\n/** SmartTransactions */\n\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 | undefined;\n minedTx: SmartTransactionMinedTx;\n isSettled: boolean;\n};\n\nexport type SmartTransaction = {\n uuid: 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;\n txParams?: any;\n type?: string;\n confirmed?: boolean;\n cancellable?: boolean;\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 | undefined;\n tradeTxFees: IndividualTxFees | undefined;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/smart-transactions-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Improves success rates for swaps by trialing transactions privately and finding minimum fees",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"test:watch": "jest --watchAll"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
29
28
|
"@ethersproject/bytes": "^5.7.0",
|
|
30
|
-
"@
|
|
31
|
-
"@metamask/
|
|
32
|
-
"@metamask/
|
|
33
|
-
"@metamask/network-controller": "^
|
|
29
|
+
"@metamask/base-controller": "^3.2.1",
|
|
30
|
+
"@metamask/controller-utils": "^5.0.0",
|
|
31
|
+
"@metamask/eth-query": "^3.0.1",
|
|
32
|
+
"@metamask/network-controller": "^15.0.0",
|
|
33
|
+
"@metamask/polling-controller": "^0.2.0",
|
|
34
34
|
"bignumber.js": "^9.0.1",
|
|
35
35
|
"fast-json-patch": "^3.1.0",
|
|
36
36
|
"lodash": "^4.17.21"
|