@metamask/transaction-controller 6.1.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [7.1.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Expose `HARDFORK` constant ([#1423](https://github.com/MetaMask/core/pull/1423))
|
|
12
|
+
- Add support for transactions on Linea networks ([#1423](https://github.com/MetaMask/core/pull/1423))
|
|
13
|
+
|
|
14
|
+
## [7.0.0]
|
|
15
|
+
### Changed
|
|
16
|
+
- **BREAKING**: Change the approveTransaction and cancelTransaction methods to private ([#1435](https://github.com/MetaMask/core/pull/1435))
|
|
17
|
+
- Consumers should migrate from use of these methods to use of `processApproval`.
|
|
18
|
+
- Update the TransactionController to await the approval request promise before automatically performing the relevant logic, either signing and submitting the transaction, or cancelling it ([#1435](https://github.com/MetaMask/core/pull/1435))
|
|
19
|
+
|
|
9
20
|
## [6.1.0]
|
|
10
21
|
### Changed
|
|
11
22
|
- Relax types of `provider` and `blockTracker` options ([#1443](https://github.com/MetaMask/core/pull/1443))
|
|
@@ -78,7 +89,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
78
89
|
|
|
79
90
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
80
91
|
|
|
81
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@
|
|
92
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@7.1.0...HEAD
|
|
93
|
+
[7.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@7.0.0...@metamask/transaction-controller@7.1.0
|
|
94
|
+
[7.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@6.1.0...@metamask/transaction-controller@7.0.0
|
|
82
95
|
[6.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@6.0.0...@metamask/transaction-controller@6.1.0
|
|
83
96
|
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@5.0.0...@metamask/transaction-controller@6.0.0
|
|
84
97
|
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@4.0.1...@metamask/transaction-controller@5.0.0
|
|
@@ -5,7 +5,8 @@ import { TypedTransaction } from '@ethereumjs/tx';
|
|
|
5
5
|
import type { Hex } from '@metamask/utils';
|
|
6
6
|
import { BaseController, BaseConfig, BaseState, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
7
7
|
import type { BlockTracker, NetworkState, Provider } from '@metamask/network-controller';
|
|
8
|
-
import {
|
|
8
|
+
import { AddApprovalRequest } from '@metamask/approval-controller';
|
|
9
|
+
export declare const HARDFORK = "london";
|
|
9
10
|
/**
|
|
10
11
|
* @type Result
|
|
11
12
|
* @property result - Promise resolving to a new transaction hash
|
|
@@ -221,7 +222,7 @@ declare const controllerName = "TransactionController";
|
|
|
221
222
|
/**
|
|
222
223
|
* The external actions available to the {@link TransactionController}.
|
|
223
224
|
*/
|
|
224
|
-
declare type AllowedActions = AddApprovalRequest
|
|
225
|
+
declare type AllowedActions = AddApprovalRequest;
|
|
225
226
|
/**
|
|
226
227
|
* The messenger of the {@link TransactionController}.
|
|
227
228
|
*/
|
|
@@ -317,22 +318,6 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
317
318
|
* @returns {Common} common configuration object
|
|
318
319
|
*/
|
|
319
320
|
getCommonConfiguration(): Common;
|
|
320
|
-
/**
|
|
321
|
-
* Approves a transaction and updates it's status in state. If this is not a
|
|
322
|
-
* retry transaction, a nonce will be generated. The transaction is signed
|
|
323
|
-
* using the sign configuration property, then published to the blockchain.
|
|
324
|
-
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
325
|
-
*
|
|
326
|
-
* @param transactionID - The ID of the transaction to approve.
|
|
327
|
-
*/
|
|
328
|
-
approveTransaction(transactionID: string): Promise<void>;
|
|
329
|
-
/**
|
|
330
|
-
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
331
|
-
* and emitting a `<tx.id>:finished` hub event.
|
|
332
|
-
*
|
|
333
|
-
* @param transactionID - The ID of the transaction to cancel.
|
|
334
|
-
*/
|
|
335
|
-
cancelTransaction(transactionID: string): void;
|
|
336
321
|
/**
|
|
337
322
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
338
323
|
* and emitting a `<tx.id>:finished` hub event.
|
|
@@ -391,6 +376,23 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
391
376
|
* @returns The block number of the latest incoming transaction.
|
|
392
377
|
*/
|
|
393
378
|
fetchAll(address: string, opt?: FetchAllOptions): Promise<string | void>;
|
|
379
|
+
private processApproval;
|
|
380
|
+
/**
|
|
381
|
+
* Approves a transaction and updates it's status in state. If this is not a
|
|
382
|
+
* retry transaction, a nonce will be generated. The transaction is signed
|
|
383
|
+
* using the sign configuration property, then published to the blockchain.
|
|
384
|
+
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
385
|
+
*
|
|
386
|
+
* @param transactionID - The ID of the transaction to approve.
|
|
387
|
+
*/
|
|
388
|
+
private approveTransaction;
|
|
389
|
+
/**
|
|
390
|
+
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
391
|
+
* and emitting a `<tx.id>:finished` hub event.
|
|
392
|
+
*
|
|
393
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
394
|
+
*/
|
|
395
|
+
private cancelTransaction;
|
|
394
396
|
/**
|
|
395
397
|
* Trim the amount of transactions that are set on the state. Checks
|
|
396
398
|
* if the length of the tx history is longer then desired persistence
|
|
@@ -413,6 +415,13 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
413
415
|
* @returns Whether the transaction is in a final state.
|
|
414
416
|
*/
|
|
415
417
|
private isFinalState;
|
|
418
|
+
/**
|
|
419
|
+
* Whether the transaction has at least completed all local processing.
|
|
420
|
+
*
|
|
421
|
+
* @param status - The transaction status.
|
|
422
|
+
* @returns Whether the transaction is in a final state.
|
|
423
|
+
*/
|
|
424
|
+
private isLocalFinalState;
|
|
416
425
|
/**
|
|
417
426
|
* Method to verify the state of a transaction using the Blockchain as a source of truth.
|
|
418
427
|
*
|
|
@@ -484,9 +493,9 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
484
493
|
*/
|
|
485
494
|
private isGasDataOutdated;
|
|
486
495
|
private requestApproval;
|
|
487
|
-
private
|
|
488
|
-
private rejectApproval;
|
|
496
|
+
private getTransaction;
|
|
489
497
|
private getApprovalId;
|
|
498
|
+
private isTransactionCompleted;
|
|
490
499
|
}
|
|
491
500
|
export default TransactionController;
|
|
492
501
|
//# sourceMappingURL=TransactionController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGtE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AActC,OAAO,
|
|
1
|
+
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;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iBAAiB;IAezB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,wBAAwB;IA0BhC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;YACW,oCAAoC;IA4DlD;;;;;;;;OAQG;YACW,4BAA4B;IAa1C;;;;;;OAMG;IACH,OAAO,CAAC,mCAAmC;IA0B3C;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;IAiB7B;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;YAOX,eAAe;IAmB7B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,sBAAsB;CAc/B;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.TransactionController = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.WalletDevice = exports.TransactionStatus = void 0;
|
|
15
|
+
exports.TransactionController = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.WalletDevice = exports.TransactionStatus = exports.HARDFORK = void 0;
|
|
16
16
|
const events_1 = require("events");
|
|
17
17
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
18
18
|
const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
@@ -26,7 +26,7 @@ const base_controller_1 = require("@metamask/base-controller");
|
|
|
26
26
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
27
27
|
const nonce_tracker_1 = __importDefault(require("nonce-tracker"));
|
|
28
28
|
const utils_1 = require("./utils");
|
|
29
|
-
|
|
29
|
+
exports.HARDFORK = 'london';
|
|
30
30
|
/**
|
|
31
31
|
* The status of the transaction. Each status represents the state of the transaction internally
|
|
32
32
|
* in the wallet. Some of these correspond with the state of the transaction on the network, but
|
|
@@ -271,28 +271,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
271
271
|
this.failTransaction(transactionMeta, error);
|
|
272
272
|
return Promise.reject(error);
|
|
273
273
|
}
|
|
274
|
-
const result = new Promise((resolve, reject) => {
|
|
275
|
-
this.hub.once(`${transactionMeta.id}:finished`, (meta) => {
|
|
276
|
-
switch (meta.status) {
|
|
277
|
-
case TransactionStatus.submitted:
|
|
278
|
-
return resolve(meta.transactionHash);
|
|
279
|
-
case TransactionStatus.rejected:
|
|
280
|
-
return reject(eth_rpc_errors_1.ethErrors.provider.userRejectedRequest('User rejected the transaction'));
|
|
281
|
-
case TransactionStatus.cancelled:
|
|
282
|
-
return reject(eth_rpc_errors_1.ethErrors.rpc.internal('User cancelled the transaction'));
|
|
283
|
-
case TransactionStatus.failed:
|
|
284
|
-
return reject(eth_rpc_errors_1.ethErrors.rpc.internal(meta.error.message));
|
|
285
|
-
/* istanbul ignore next */
|
|
286
|
-
default:
|
|
287
|
-
return reject(eth_rpc_errors_1.ethErrors.rpc.internal(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(meta)}`));
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
274
|
transactions.push(transactionMeta);
|
|
292
275
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
293
276
|
this.hub.emit(`unapprovedTransaction`, transactionMeta);
|
|
294
|
-
|
|
295
|
-
|
|
277
|
+
return {
|
|
278
|
+
result: this.processApproval(transactionMeta),
|
|
279
|
+
transactionMeta,
|
|
280
|
+
};
|
|
296
281
|
});
|
|
297
282
|
}
|
|
298
283
|
prepareUnsignedEthTx(txParams) {
|
|
@@ -312,113 +297,17 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
312
297
|
*/
|
|
313
298
|
getCommonConfiguration() {
|
|
314
299
|
const { networkId, providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
|
|
315
|
-
if (chain !== controller_utils_1.RPC
|
|
316
|
-
|
|
300
|
+
if (chain !== controller_utils_1.RPC &&
|
|
301
|
+
chain !== controller_utils_1.NetworkType['linea-goerli'] &&
|
|
302
|
+
chain !== controller_utils_1.NetworkType['linea-mainnet']) {
|
|
303
|
+
return new common_1.default({ chain, hardfork: exports.HARDFORK });
|
|
317
304
|
}
|
|
318
305
|
const customChainParams = {
|
|
319
306
|
name,
|
|
320
307
|
chainId: parseInt(chainId, 16),
|
|
321
308
|
networkId: networkId === null ? NaN : parseInt(networkId, undefined),
|
|
322
309
|
};
|
|
323
|
-
return common_1.default.forCustomChain(controller_utils_1.NetworkType.mainnet, customChainParams, HARDFORK);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Approves a transaction and updates it's status in state. If this is not a
|
|
327
|
-
* retry transaction, a nonce will be generated. The transaction is signed
|
|
328
|
-
* using the sign configuration property, then published to the blockchain.
|
|
329
|
-
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
330
|
-
*
|
|
331
|
-
* @param transactionID - The ID of the transaction to approve.
|
|
332
|
-
*/
|
|
333
|
-
approveTransaction(transactionID) {
|
|
334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
const { transactions } = this.state;
|
|
336
|
-
const releaseLock = yield this.mutex.acquire();
|
|
337
|
-
const { providerConfig } = this.getNetworkState();
|
|
338
|
-
const { chainId } = providerConfig;
|
|
339
|
-
const index = transactions.findIndex(({ id }) => transactionID === id);
|
|
340
|
-
const transactionMeta = transactions[index];
|
|
341
|
-
const { transaction: { nonce, from }, } = transactionMeta;
|
|
342
|
-
let nonceLock;
|
|
343
|
-
try {
|
|
344
|
-
if (!this.sign) {
|
|
345
|
-
releaseLock();
|
|
346
|
-
this.failTransaction(transactionMeta, new Error('No sign method defined.'));
|
|
347
|
-
this.rejectApproval(transactionMeta);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
else if (!chainId) {
|
|
351
|
-
releaseLock();
|
|
352
|
-
this.failTransaction(transactionMeta, new Error('No chainId defined.'));
|
|
353
|
-
this.rejectApproval(transactionMeta);
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
const { approved: status } = TransactionStatus;
|
|
357
|
-
let nonceToUse = nonce;
|
|
358
|
-
// if a nonce already exists on the transactionMeta it means this is a speedup or cancel transaction
|
|
359
|
-
// so we want to reuse that nonce and hope that it beats the previous attempt to chain. Otherwise use a new locked nonce
|
|
360
|
-
if (!nonceToUse) {
|
|
361
|
-
nonceLock = yield this.nonceTracker.getNonceLock(from);
|
|
362
|
-
nonceToUse = (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16));
|
|
363
|
-
}
|
|
364
|
-
transactionMeta.status = status;
|
|
365
|
-
transactionMeta.transaction.nonce = nonceToUse;
|
|
366
|
-
transactionMeta.transaction.chainId = chainId;
|
|
367
|
-
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.transaction), { gasLimit: transactionMeta.transaction.gas });
|
|
368
|
-
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.transaction);
|
|
369
|
-
const txParams = isEIP1559
|
|
370
|
-
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.transaction.maxFeePerGas, maxPriorityFeePerGas: transactionMeta.transaction.maxPriorityFeePerGas, estimatedBaseFee: transactionMeta.transaction.estimatedBaseFee,
|
|
371
|
-
// specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set
|
|
372
|
-
type: 2 }) : baseTxParams;
|
|
373
|
-
// delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set
|
|
374
|
-
if (isEIP1559) {
|
|
375
|
-
delete txParams.gasPrice;
|
|
376
|
-
}
|
|
377
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
378
|
-
const signedTx = yield this.sign(unsignedEthTx, from);
|
|
379
|
-
transactionMeta.status = TransactionStatus.signed;
|
|
380
|
-
this.updateTransaction(transactionMeta);
|
|
381
|
-
const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
382
|
-
transactionMeta.rawTransaction = rawTransaction;
|
|
383
|
-
this.updateTransaction(transactionMeta);
|
|
384
|
-
const transactionHash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [
|
|
385
|
-
rawTransaction,
|
|
386
|
-
]);
|
|
387
|
-
transactionMeta.transactionHash = transactionHash;
|
|
388
|
-
transactionMeta.status = TransactionStatus.submitted;
|
|
389
|
-
this.updateTransaction(transactionMeta);
|
|
390
|
-
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
391
|
-
this.acceptApproval(transactionMeta);
|
|
392
|
-
}
|
|
393
|
-
catch (error) {
|
|
394
|
-
this.failTransaction(transactionMeta, error);
|
|
395
|
-
this.rejectApproval(transactionMeta);
|
|
396
|
-
}
|
|
397
|
-
finally {
|
|
398
|
-
// must set transaction to submitted/failed before releasing lock
|
|
399
|
-
if (nonceLock) {
|
|
400
|
-
nonceLock.releaseLock();
|
|
401
|
-
}
|
|
402
|
-
releaseLock();
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
408
|
-
* and emitting a `<tx.id>:finished` hub event.
|
|
409
|
-
*
|
|
410
|
-
* @param transactionID - The ID of the transaction to cancel.
|
|
411
|
-
*/
|
|
412
|
-
cancelTransaction(transactionID) {
|
|
413
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionID);
|
|
414
|
-
if (!transactionMeta) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
transactionMeta.status = TransactionStatus.rejected;
|
|
418
|
-
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
419
|
-
const transactions = this.state.transactions.filter(({ id }) => id !== transactionID);
|
|
420
|
-
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
421
|
-
this.rejectApproval(transactionMeta);
|
|
310
|
+
return common_1.default.forCustomChain(controller_utils_1.NetworkType.mainnet, customChainParams, exports.HARDFORK);
|
|
422
311
|
}
|
|
423
312
|
/**
|
|
424
313
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
@@ -485,7 +374,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
485
374
|
yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTransaction]);
|
|
486
375
|
transactionMeta.status = TransactionStatus.cancelled;
|
|
487
376
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
488
|
-
this.rejectApproval(transactionMeta);
|
|
489
377
|
});
|
|
490
378
|
}
|
|
491
379
|
/**
|
|
@@ -614,7 +502,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
614
502
|
estimateGasError,
|
|
615
503
|
};
|
|
616
504
|
}
|
|
617
|
-
return { gas: (0, ethereumjs_util_1.addHexPrefix)((0, controller_utils_1.BNToHex)(maxGasBN)), gasPrice };
|
|
505
|
+
return { gas: (0, ethereumjs_util_1.addHexPrefix)((0, controller_utils_1.BNToHex)(maxGasBN)), gasPrice, estimateGasError };
|
|
618
506
|
});
|
|
619
507
|
}
|
|
620
508
|
/**
|
|
@@ -749,6 +637,142 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
749
637
|
return latestIncomingTxBlockNumber;
|
|
750
638
|
});
|
|
751
639
|
}
|
|
640
|
+
processApproval(transactionMeta) {
|
|
641
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
642
|
+
const transactionId = transactionMeta.id;
|
|
643
|
+
let resultCallbacks;
|
|
644
|
+
try {
|
|
645
|
+
const acceptResult = yield this.requestApproval(transactionMeta);
|
|
646
|
+
resultCallbacks = acceptResult.resultCallbacks;
|
|
647
|
+
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
648
|
+
if (meta && !isCompleted) {
|
|
649
|
+
yield this.approveTransaction(transactionId);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
654
|
+
if (meta && !isCompleted) {
|
|
655
|
+
if (error.code === eth_rpc_errors_1.errorCodes.provider.userRejectedRequest) {
|
|
656
|
+
this.cancelTransaction(transactionId);
|
|
657
|
+
throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest('User rejected the transaction');
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
this.failTransaction(meta, error);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const finalMeta = this.getTransaction(transactionId);
|
|
665
|
+
switch (finalMeta === null || finalMeta === void 0 ? void 0 : finalMeta.status) {
|
|
666
|
+
case TransactionStatus.failed:
|
|
667
|
+
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(finalMeta.error);
|
|
668
|
+
throw eth_rpc_errors_1.ethErrors.rpc.internal(finalMeta.error.message);
|
|
669
|
+
case TransactionStatus.cancelled:
|
|
670
|
+
const cancelError = eth_rpc_errors_1.ethErrors.rpc.internal('User cancelled the transaction');
|
|
671
|
+
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(cancelError);
|
|
672
|
+
throw cancelError;
|
|
673
|
+
case TransactionStatus.submitted:
|
|
674
|
+
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.success();
|
|
675
|
+
return finalMeta.transactionHash;
|
|
676
|
+
default:
|
|
677
|
+
const internalError = eth_rpc_errors_1.ethErrors.rpc.internal(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finalMeta || transactionId)}`);
|
|
678
|
+
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(internalError);
|
|
679
|
+
throw internalError;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Approves a transaction and updates it's status in state. If this is not a
|
|
685
|
+
* retry transaction, a nonce will be generated. The transaction is signed
|
|
686
|
+
* using the sign configuration property, then published to the blockchain.
|
|
687
|
+
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
688
|
+
*
|
|
689
|
+
* @param transactionID - The ID of the transaction to approve.
|
|
690
|
+
*/
|
|
691
|
+
approveTransaction(transactionID) {
|
|
692
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
693
|
+
const { transactions } = this.state;
|
|
694
|
+
const releaseLock = yield this.mutex.acquire();
|
|
695
|
+
const { providerConfig } = this.getNetworkState();
|
|
696
|
+
const { chainId } = providerConfig;
|
|
697
|
+
const index = transactions.findIndex(({ id }) => transactionID === id);
|
|
698
|
+
const transactionMeta = transactions[index];
|
|
699
|
+
const { transaction: { nonce, from }, } = transactionMeta;
|
|
700
|
+
let nonceLock;
|
|
701
|
+
try {
|
|
702
|
+
if (!this.sign) {
|
|
703
|
+
releaseLock();
|
|
704
|
+
this.failTransaction(transactionMeta, new Error('No sign method defined.'));
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
else if (!chainId) {
|
|
708
|
+
releaseLock();
|
|
709
|
+
this.failTransaction(transactionMeta, new Error('No chainId defined.'));
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const { approved: status } = TransactionStatus;
|
|
713
|
+
let nonceToUse = nonce;
|
|
714
|
+
// if a nonce already exists on the transactionMeta it means this is a speedup or cancel transaction
|
|
715
|
+
// so we want to reuse that nonce and hope that it beats the previous attempt to chain. Otherwise use a new locked nonce
|
|
716
|
+
if (!nonceToUse) {
|
|
717
|
+
nonceLock = yield this.nonceTracker.getNonceLock(from);
|
|
718
|
+
nonceToUse = (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16));
|
|
719
|
+
}
|
|
720
|
+
transactionMeta.status = status;
|
|
721
|
+
transactionMeta.transaction.nonce = nonceToUse;
|
|
722
|
+
transactionMeta.transaction.chainId = chainId;
|
|
723
|
+
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.transaction), { gasLimit: transactionMeta.transaction.gas });
|
|
724
|
+
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.transaction);
|
|
725
|
+
const txParams = isEIP1559
|
|
726
|
+
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.transaction.maxFeePerGas, maxPriorityFeePerGas: transactionMeta.transaction.maxPriorityFeePerGas, estimatedBaseFee: transactionMeta.transaction.estimatedBaseFee,
|
|
727
|
+
// specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set
|
|
728
|
+
type: 2 }) : baseTxParams;
|
|
729
|
+
// delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set
|
|
730
|
+
if (isEIP1559) {
|
|
731
|
+
delete txParams.gasPrice;
|
|
732
|
+
}
|
|
733
|
+
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
734
|
+
const signedTx = yield this.sign(unsignedEthTx, from);
|
|
735
|
+
transactionMeta.status = TransactionStatus.signed;
|
|
736
|
+
this.updateTransaction(transactionMeta);
|
|
737
|
+
const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
738
|
+
transactionMeta.rawTransaction = rawTransaction;
|
|
739
|
+
this.updateTransaction(transactionMeta);
|
|
740
|
+
const transactionHash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [
|
|
741
|
+
rawTransaction,
|
|
742
|
+
]);
|
|
743
|
+
transactionMeta.transactionHash = transactionHash;
|
|
744
|
+
transactionMeta.status = TransactionStatus.submitted;
|
|
745
|
+
this.updateTransaction(transactionMeta);
|
|
746
|
+
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
this.failTransaction(transactionMeta, error);
|
|
750
|
+
}
|
|
751
|
+
finally {
|
|
752
|
+
// must set transaction to submitted/failed before releasing lock
|
|
753
|
+
if (nonceLock) {
|
|
754
|
+
nonceLock.releaseLock();
|
|
755
|
+
}
|
|
756
|
+
releaseLock();
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
762
|
+
* and emitting a `<tx.id>:finished` hub event.
|
|
763
|
+
*
|
|
764
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
765
|
+
*/
|
|
766
|
+
cancelTransaction(transactionID) {
|
|
767
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionID);
|
|
768
|
+
if (!transactionMeta) {
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
transactionMeta.status = TransactionStatus.rejected;
|
|
772
|
+
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
773
|
+
const transactions = this.state.transactions.filter(({ id }) => id !== transactionID);
|
|
774
|
+
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
775
|
+
}
|
|
752
776
|
/**
|
|
753
777
|
* Trim the amount of transactions that are set on the state. Checks
|
|
754
778
|
* if the length of the tx history is longer then desired persistence
|
|
@@ -795,6 +819,21 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
795
819
|
status === TransactionStatus.failed ||
|
|
796
820
|
status === TransactionStatus.cancelled);
|
|
797
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Whether the transaction has at least completed all local processing.
|
|
824
|
+
*
|
|
825
|
+
* @param status - The transaction status.
|
|
826
|
+
* @returns Whether the transaction is in a final state.
|
|
827
|
+
*/
|
|
828
|
+
isLocalFinalState(status) {
|
|
829
|
+
return [
|
|
830
|
+
TransactionStatus.cancelled,
|
|
831
|
+
TransactionStatus.confirmed,
|
|
832
|
+
TransactionStatus.failed,
|
|
833
|
+
TransactionStatus.rejected,
|
|
834
|
+
TransactionStatus.submitted,
|
|
835
|
+
].includes(status);
|
|
836
|
+
}
|
|
798
837
|
/**
|
|
799
838
|
* Method to verify the state of a transaction using the Blockchain as a source of truth.
|
|
800
839
|
*
|
|
@@ -951,46 +990,36 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
951
990
|
isGasDataOutdated(remoteGasUsed, localGasUsed) {
|
|
952
991
|
return remoteGasUsed !== localGasUsed;
|
|
953
992
|
}
|
|
954
|
-
requestApproval(txMeta
|
|
993
|
+
requestApproval(txMeta) {
|
|
955
994
|
return __awaiter(this, void 0, void 0, function* () {
|
|
956
995
|
const id = this.getApprovalId(txMeta);
|
|
957
996
|
const { origin } = txMeta;
|
|
958
997
|
const type = controller_utils_1.ApprovalType.Transaction;
|
|
959
998
|
const requestData = { txId: txMeta.id };
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
catch (error) {
|
|
969
|
-
console.info('Failed to request transaction approval', error);
|
|
970
|
-
}
|
|
999
|
+
return (yield this.messagingSystem.call('ApprovalController:addRequest', {
|
|
1000
|
+
id,
|
|
1001
|
+
origin: origin || controller_utils_1.ORIGIN_METAMASK,
|
|
1002
|
+
type,
|
|
1003
|
+
requestData,
|
|
1004
|
+
expectsResult: true,
|
|
1005
|
+
}, true));
|
|
971
1006
|
});
|
|
972
1007
|
}
|
|
973
|
-
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
this.messagingSystem.call('ApprovalController:acceptRequest', id);
|
|
977
|
-
}
|
|
978
|
-
catch (error) {
|
|
979
|
-
console.info('Failed to accept transaction approval request', error);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
rejectApproval(txMeta) {
|
|
983
|
-
const id = this.getApprovalId(txMeta);
|
|
984
|
-
try {
|
|
985
|
-
this.messagingSystem.call('ApprovalController:rejectRequest', id, new Error('Rejected'));
|
|
986
|
-
}
|
|
987
|
-
catch (error) {
|
|
988
|
-
console.info('Failed to reject transaction approval request', error);
|
|
989
|
-
}
|
|
1008
|
+
getTransaction(transactionID) {
|
|
1009
|
+
const { transactions } = this.state;
|
|
1010
|
+
return transactions.find(({ id }) => id === transactionID);
|
|
990
1011
|
}
|
|
991
1012
|
getApprovalId(txMeta) {
|
|
992
1013
|
return String(txMeta.id);
|
|
993
1014
|
}
|
|
1015
|
+
isTransactionCompleted(transactionid) {
|
|
1016
|
+
const transaction = this.getTransaction(transactionid);
|
|
1017
|
+
if (!transaction) {
|
|
1018
|
+
return { meta: undefined, isCompleted: false };
|
|
1019
|
+
}
|
|
1020
|
+
const isCompleted = this.isLocalFinalState(transaction.status);
|
|
1021
|
+
return { meta: transaction, isCompleted };
|
|
1022
|
+
}
|
|
994
1023
|
}
|
|
995
1024
|
exports.TransactionController = TransactionController;
|
|
996
1025
|
exports.default = TransactionController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.js","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,qDAAgE;AAChE,mDAA2C;AAC3C,8EAAiD;AACjD,0DAAiC;AACjC,gEAAwC;AACxC,uCAAsE;AACtE,+BAAoC;AACpC,6CAAoC;AAEpC,+DAKmC;AAMnC,iEAYoC;AAMpC,kEAAyC;AACzC,mCAYiB;AAEjB,MAAM,QAAQ,GAAG,QAAQ,CAAC;AA6D1B;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EATW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAS5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,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C/B;oBACE,EAAE;oBACF,MAAM,EAAE,MAAM,IAAI,kCAAe;oBACjC,IAAI;oBACJ,WAAW;iBACZ,EACD,iBAAiB,CAClB,CAAC;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;aAC/D;QACH,CAAC;KAAA;IAEO,cAAc,CAAC,MAAuB;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAEtC,IAAI;YACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;SACnE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;SACtE;IACH,CAAC;IAEO,cAAc,CAAC,MAAuB;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAEtC,IAAI;YACF,IAAI,CAAC,eAAe,CAAC,IAAI,CACvB,kCAAkC,EAClC,EAAE,EACF,IAAI,KAAK,CAAC,UAAU,CAAC,CACtB,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;SACtE;IACH,CAAC;IAEO,aAAa,CAAC,MAAuB;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;CACF;AAvyCD,sDAuyCC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { addHexPrefix, bufferToHex, BN } from 'ethereumjs-util';\nimport { ethErrors } from 'eth-rpc-errors';\nimport MethodRegistry from 'eth-method-registry';\nimport EthQuery from 'eth-query';\nimport Common from '@ethereumjs/common';\nimport { TransactionFactory, TypedTransaction } from '@ethereumjs/tx';\nimport { v1 as random } from 'uuid';\nimport { Mutex } from 'async-mutex';\nimport type { Hex } from '@metamask/utils';\nimport {\n BaseController,\n BaseConfig,\n BaseState,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport type {\n BlockTracker,\n NetworkState,\n Provider,\n} from '@metamask/network-controller';\nimport {\n BNToHex,\n fractionBN,\n hexToBN,\n safelyExecute,\n isSmartContractCode,\n query,\n NetworkType,\n RPC,\n ApprovalType,\n ORIGIN_METAMASK,\n convertHexToDecimal,\n} from '@metamask/controller-utils';\nimport {\n AcceptRequest as AcceptApprovalRequest,\n AddApprovalRequest,\n RejectRequest as RejectApprovalRequest,\n} from '@metamask/approval-controller';\nimport NonceTracker from 'nonce-tracker';\nimport {\n getAndFormatTransactionsForNonceTracker,\n normalizeTransaction,\n validateTransaction,\n handleTransactionFetch,\n getIncreasedPriceFromExisting,\n isEIP1559Transaction,\n isGasPriceValue,\n isFeeMarketEIP1559Values,\n validateGasValues,\n validateMinimumIncrease,\n ESTIMATE_GAS_ERROR,\n} from './utils';\n\nconst HARDFORK = 'london';\n\n/**\n * @type Result\n * @property result - Promise resolving to a new transaction hash\n * @property transactionMeta - Meta information about this new transaction\n */\nexport interface Result {\n result: Promise<string>;\n transactionMeta: TransactionMeta;\n}\n\n/**\n * @type Fetch All Options\n * @property fromBlock - String containing a specific block decimal number\n * @property etherscanApiKey - API key to be used to fetch token transactions\n */\nexport interface FetchAllOptions {\n fromBlock?: string;\n etherscanApiKey?: string;\n}\n\n/**\n * @type Transaction\n *\n * Transaction representation\n * @property chainId - Network ID as per EIP-155\n * @property data - Data to pass with this transaction\n * @property from - Address to send this transaction from\n * @property gas - Gas to send with this transaction\n * @property gasPrice - Price of gas with this transaction\n * @property gasUsed - Gas used in the transaction\n * @property nonce - Unique number to prevent replay attacks\n * @property to - Address to send this transaction to\n * @property value - Value associated with this transaction\n */\nexport interface Transaction {\n chainId?: Hex;\n data?: string;\n from: string;\n gas?: string;\n gasPrice?: string;\n gasUsed?: string;\n nonce?: string;\n to?: string;\n value?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n estimatedBaseFee?: string;\n estimateGasError?: string;\n}\n\nexport interface GasPriceValue {\n gasPrice: string;\n}\n\nexport interface FeeMarketEIP1559Values {\n maxFeePerGas: string;\n maxPriorityFeePerGas: string;\n}\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\ntype TransactionMetaBase = {\n isTransfer?: boolean;\n transferInformation?: {\n symbol: string;\n contractAddress: string;\n decimals: number;\n };\n id: string;\n networkID?: string;\n chainId?: Hex;\n origin?: string;\n rawTransaction?: string;\n time: number;\n toSmartContract?: boolean;\n transaction: Transaction;\n transactionHash?: string;\n blockNumber?: string;\n deviceConfirmedOn?: WalletDevice;\n verifiedOnBlockchain?: boolean;\n};\n\n/**\n * @type TransactionMeta\n *\n * TransactionMeta representation\n * @property error - Synthesized error information for failed transactions\n * @property id - Generated UUID associated with this transaction\n * @property networkID - Network code as per EIP-155 for this transaction\n * @property origin - Origin this transaction was sent from\n * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed\n * @property rawTransaction - Hex representation of the underlying transaction\n * @property status - String status of this transaction\n * @property time - Timestamp associated with this transaction\n * @property toSmartContract - Whether transaction recipient is a smart contract\n * @property transaction - Underlying Transaction object\n * @property transactionHash - Hash of a successful transaction\n * @property blockNumber - Number of the block where the transaction has been included\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\n/**\n * @type EtherscanTransactionMeta\n *\n * EtherscanTransactionMeta representation\n * @property blockNumber - Number of the block where the transaction has been included\n * @property timeStamp - Timestamp associated with this transaction\n * @property hash - Hash of a successful transaction\n * @property nonce - Nonce of the transaction\n * @property blockHash - Hash of the block where the transaction has been included\n * @property transactionIndex - Etherscan internal index for this transaction\n * @property from - Address to send this transaction from\n * @property to - Address to send this transaction to\n * @property gas - Gas to send with this transaction\n * @property gasPrice - Price of gas with this transaction\n * @property isError - Synthesized error information for failed transactions\n * @property txreceipt_status - Receipt status for this transaction\n * @property input - input of the transaction\n * @property contractAddress - Address of the contract\n * @property cumulativeGasUsed - Amount of gas used\n * @property confirmations - Number of confirmations\n */\nexport interface EtherscanTransactionMeta {\n blockNumber: string;\n timeStamp: string;\n hash: string;\n nonce: string;\n blockHash: string;\n transactionIndex: string;\n from: string;\n to: string;\n value: string;\n gas: string;\n gasPrice: string;\n cumulativeGasUsed: string;\n gasUsed: string;\n isError: string;\n txreceipt_status: string;\n input: string;\n contractAddress: string;\n confirmations: string;\n tokenDecimal: string;\n tokenSymbol: string;\n}\n\n/**\n * @type TransactionConfig\n *\n * Transaction controller configuration\n * @property interval - Polling interval used to fetch new currency rate\n * @property provider - Provider used to create a new underlying EthQuery instance\n * @property sign - Method used to sign transactions\n */\nexport interface TransactionConfig extends BaseConfig {\n interval: number;\n sign?: (transaction: Transaction, from: string) => Promise<any>;\n txHistoryLimit: number;\n}\n\n/**\n * @type MethodData\n *\n * Method data registry object\n * @property registryMethod - Registry method raw string\n * @property parsedRegistryMethod - Registry method object, containing name and method arguments\n */\nexport interface MethodData {\n registryMethod: string;\n parsedRegistryMethod: Record<string, unknown>;\n}\n\n/**\n * @type TransactionState\n *\n * Transaction controller state\n * @property transactions - A list of TransactionMeta objects\n * @property methodData - Object containing all known method data information\n */\nexport interface TransactionState extends BaseState {\n transactions: TransactionMeta[];\n methodData: { [key: string]: MethodData };\n}\n\n/**\n * Multiplier used to determine a transaction's increased gas fee during cancellation\n */\nexport const CANCEL_RATE = 1.5;\n\n/**\n * Multiplier used to determine a transaction's increased gas fee during speed up\n */\nexport const SPEED_UP_RATE = 1.1;\n\n/**\n * The name of the {@link TransactionController}.\n */\nconst controllerName = 'TransactionController';\n\n/**\n * The external actions available to the {@link TransactionController}.\n */\ntype AllowedActions =\n | AddApprovalRequest\n | AcceptApprovalRequest\n | RejectApprovalRequest;\n\n/**\n * The messenger of the {@link TransactionController}.\n */\nexport type TransactionControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Controller responsible for submitting and managing transactions.\n */\nexport class TransactionController extends BaseController<\n TransactionConfig,\n TransactionState\n> {\n private ethQuery: EthQuery;\n\n private nonceTracker: NonceTracker;\n\n private registry: any;\n\n private provider: Provider;\n\n private handle?: ReturnType<typeof setTimeout>;\n\n private mutex = new Mutex();\n\n private getNetworkState: () => NetworkState;\n\n private messagingSystem: TransactionControllerMessenger;\n\n private failTransaction(transactionMeta: TransactionMeta, error: Error) {\n const newTransactionMeta = {\n ...transactionMeta,\n error,\n status: TransactionStatus.failed,\n };\n this.updateTransaction(newTransactionMeta);\n this.hub.emit(`${transactionMeta.id}:finished`, newTransactionMeta);\n }\n\n private async registryLookup(fourBytePrefix: string): Promise<MethodData> {\n const registryMethod = await this.registry.lookup(fourBytePrefix);\n const parsedRegistryMethod = this.registry.parse(registryMethod);\n return { registryMethod, parsedRegistryMethod };\n }\n\n /**\n * Normalizes the transaction information from etherscan\n * to be compatible with the TransactionMeta interface.\n *\n * @param txMeta - The transaction.\n * @param currentNetworkID - The current network ID.\n * @param currentChainId - The current chain ID.\n * @returns The normalized transaction.\n */\n private normalizeTx(\n txMeta: EtherscanTransactionMeta,\n currentNetworkID: string,\n currentChainId: Hex,\n ): TransactionMeta {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n const normalizedTransactionBase = {\n blockNumber: txMeta.blockNumber,\n id: random({ msecs: time }),\n networkID: currentNetworkID,\n chainId: currentChainId,\n time,\n transaction: {\n data: txMeta.input,\n from: txMeta.from,\n gas: BNToHex(new BN(txMeta.gas)),\n gasPrice: BNToHex(new BN(txMeta.gasPrice)),\n gasUsed: BNToHex(new BN(txMeta.gasUsed)),\n nonce: BNToHex(new BN(txMeta.nonce)),\n to: txMeta.to,\n value: BNToHex(new BN(txMeta.value)),\n },\n transactionHash: txMeta.hash,\n verifiedOnBlockchain: false,\n };\n\n /* istanbul ignore else */\n if (txMeta.isError === '0') {\n return {\n ...normalizedTransactionBase,\n status: TransactionStatus.confirmed,\n };\n }\n\n /* istanbul ignore next */\n return {\n ...normalizedTransactionBase,\n error: new Error('Transaction failed'),\n status: TransactionStatus.failed,\n };\n }\n\n private normalizeTokenTx = (\n txMeta: EtherscanTransactionMeta,\n currentNetworkID: string,\n currentChainId: Hex,\n ): TransactionMeta => {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n const {\n to,\n from,\n gas,\n gasPrice,\n gasUsed,\n hash,\n contractAddress,\n tokenDecimal,\n tokenSymbol,\n value,\n } = txMeta;\n return {\n id: random({ msecs: time }),\n isTransfer: true,\n networkID: currentNetworkID,\n chainId: currentChainId,\n status: TransactionStatus.confirmed,\n time,\n transaction: {\n chainId: currentChainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n to,\n value,\n },\n transactionHash: hash,\n transferInformation: {\n contractAddress,\n decimals: Number(tokenDecimal),\n symbol: tokenSymbol,\n },\n verifiedOnBlockchain: false,\n };\n };\n\n /**\n * EventEmitter instance used to listen to specific transactional events\n */\n hub = new EventEmitter();\n\n /**\n * Name of this controller used during composition\n */\n override name = 'TransactionController';\n\n /**\n * Method used to sign transactions\n */\n sign?: (\n transaction: TypedTransaction,\n from: string,\n ) => Promise<TypedTransaction>;\n\n /**\n * Creates a TransactionController instance.\n *\n * @param options - The controller options.\n * @param options.getNetworkState - Gets the state of the network controller.\n * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.\n * @param options.provider - The provider used to create the underlying EthQuery instance.\n * @param options.blockTracker - The block tracker used to poll for new blocks data.\n * @param options.messenger - The controller messenger.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n getNetworkState,\n onNetworkStateChange,\n provider,\n blockTracker,\n messenger,\n }: {\n getNetworkState: () => NetworkState;\n onNetworkStateChange: (listener: (state: NetworkState) => void) => void;\n provider: Provider;\n blockTracker: BlockTracker;\n messenger: TransactionControllerMessenger;\n },\n config?: Partial<TransactionConfig>,\n state?: Partial<TransactionState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n interval: 15000,\n txHistoryLimit: 40,\n };\n\n this.defaultState = {\n methodData: {},\n transactions: [],\n };\n this.initialize();\n this.provider = provider;\n this.messagingSystem = messenger;\n this.getNetworkState = getNetworkState;\n this.ethQuery = new EthQuery(provider);\n this.registry = new MethodRegistry({ provider });\n this.nonceTracker = new NonceTracker({\n provider,\n blockTracker,\n getPendingTransactions: (address) =>\n getAndFormatTransactionsForNonceTracker(\n address,\n TransactionStatus.submitted,\n this.state.transactions,\n ),\n getConfirmedTransactions: (address) =>\n getAndFormatTransactionsForNonceTracker(\n address,\n TransactionStatus.confirmed,\n this.state.transactions,\n ),\n });\n\n onNetworkStateChange(() => {\n this.ethQuery = new EthQuery(this.provider);\n this.registry = new MethodRegistry({ provider: this.provider });\n });\n this.poll();\n }\n\n /**\n * Starts a new polling interval.\n *\n * @param interval - The polling interval used to fetch new transaction statuses.\n */\n async poll(interval?: number): Promise<void> {\n interval && this.configure({ interval }, false, false);\n this.handle && clearTimeout(this.handle);\n await safelyExecute(() => this.queryTransactionStatuses());\n this.handle = setTimeout(() => {\n this.poll(this.config.interval);\n }, this.config.interval);\n }\n\n /**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @returns The method data object corresponding to the given signature prefix.\n */\n async handleMethodData(fourBytePrefix: string): Promise<MethodData> {\n const releaseLock = await this.mutex.acquire();\n try {\n const { methodData } = this.state;\n const knownMethod = Object.keys(methodData).find(\n (knownFourBytePrefix) => fourBytePrefix === knownFourBytePrefix,\n );\n if (knownMethod) {\n return methodData[fourBytePrefix];\n }\n const registry = await this.registryLookup(fourBytePrefix);\n this.update({\n methodData: { ...methodData, ...{ [fourBytePrefix]: registry } },\n });\n return registry;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction id will be generated, and gas and gasPrice will be calculated\n * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param transaction - The transaction object to add.\n * @param origin - The domain origin to append to the generated TransactionMeta.\n * @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\n async addTransaction(\n transaction: Transaction,\n origin?: string,\n deviceConfirmedOn?: WalletDevice,\n ): Promise<Result> {\n const { providerConfig, networkId } = this.getNetworkState();\n const { transactions } = this.state;\n transaction = normalizeTransaction(transaction);\n validateTransaction(transaction);\n\n const transactionMeta: TransactionMeta = {\n id: random(),\n networkID: networkId ?? undefined,\n chainId: providerConfig.chainId,\n origin,\n status: TransactionStatus.unapproved as TransactionStatus.unapproved,\n time: Date.now(),\n transaction,\n deviceConfirmedOn,\n verifiedOnBlockchain: false,\n };\n\n try {\n const { gas, estimateGasError } = await this.estimateGas(transaction);\n transaction.gas = gas;\n transaction.estimateGasError = estimateGasError;\n } catch (error: any) {\n this.failTransaction(transactionMeta, error);\n return Promise.reject(error);\n }\n\n const result: Promise<string> = new Promise((resolve, reject) => {\n this.hub.once(\n `${transactionMeta.id}:finished`,\n (meta: TransactionMeta) => {\n switch (meta.status) {\n case TransactionStatus.submitted:\n return resolve(meta.transactionHash as string);\n case TransactionStatus.rejected:\n return reject(\n ethErrors.provider.userRejectedRequest(\n 'User rejected the transaction',\n ),\n );\n case TransactionStatus.cancelled:\n return reject(\n ethErrors.rpc.internal('User cancelled the transaction'),\n );\n case TransactionStatus.failed:\n return reject(ethErrors.rpc.internal(meta.error.message));\n /* istanbul ignore next */\n default:\n return reject(\n ethErrors.rpc.internal(\n `MetaMask Tx Signature: Unknown problem: ${JSON.stringify(\n meta,\n )}`,\n ),\n );\n }\n },\n );\n });\n\n transactions.push(transactionMeta);\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n this.hub.emit(`unapprovedTransaction`, transactionMeta);\n this.requestApproval(transactionMeta);\n return { result, transactionMeta };\n }\n\n prepareUnsignedEthTx(txParams: Record<string, unknown>): TypedTransaction {\n return TransactionFactory.fromTxData(txParams, {\n common: this.getCommonConfiguration(),\n freeze: false,\n });\n }\n\n /**\n * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for\n * specifying which chain, network, hardfork and EIPs to support for\n * a transaction. By referencing this configuration, and analyzing the fields\n * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718\n * transaction type to use.\n *\n * @returns {Common} common configuration object\n */\n\n getCommonConfiguration(): Common {\n const {\n networkId,\n providerConfig: { type: chain, chainId, nickname: name },\n } = this.getNetworkState();\n\n if (chain !== RPC) {\n return new Common({ chain, hardfork: HARDFORK });\n }\n\n const customChainParams = {\n name,\n chainId: parseInt(chainId, 16),\n networkId: networkId === null ? NaN : parseInt(networkId, undefined),\n };\n\n return Common.forCustomChain(\n NetworkType.mainnet,\n customChainParams,\n HARDFORK,\n );\n }\n\n /**\n * Approves a transaction and updates it's status in state. If this is not a\n * retry transaction, a nonce will be generated. The transaction is signed\n * using the sign configuration property, then published to the blockchain.\n * A `<tx.id>:finished` hub event is fired after success or failure.\n *\n * @param transactionID - The ID of the transaction to approve.\n */\n async approveTransaction(transactionID: string) {\n const { transactions } = this.state;\n const releaseLock = await this.mutex.acquire();\n const { providerConfig } = this.getNetworkState();\n const { chainId } = providerConfig;\n const index = transactions.findIndex(({ id }) => transactionID === id);\n const transactionMeta = transactions[index];\n const {\n transaction: { nonce, from },\n } = transactionMeta;\n let nonceLock;\n try {\n if (!this.sign) {\n releaseLock();\n this.failTransaction(\n transactionMeta,\n new Error('No sign method defined.'),\n );\n this.rejectApproval(transactionMeta);\n return;\n } else if (!chainId) {\n releaseLock();\n this.failTransaction(transactionMeta, new Error('No chainId defined.'));\n this.rejectApproval(transactionMeta);\n return;\n }\n\n const { approved: status } = TransactionStatus;\n let nonceToUse = nonce;\n // if a nonce already exists on the transactionMeta it means this is a speedup or cancel transaction\n // so we want to reuse that nonce and hope that it beats the previous attempt to chain. Otherwise use a new locked nonce\n if (!nonceToUse) {\n nonceLock = await this.nonceTracker.getNonceLock(from);\n nonceToUse = addHexPrefix(nonceLock.nextNonce.toString(16));\n }\n\n transactionMeta.status = status;\n transactionMeta.transaction.nonce = nonceToUse;\n transactionMeta.transaction.chainId = chainId;\n\n const baseTxParams = {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n };\n\n const isEIP1559 = isEIP1559Transaction(transactionMeta.transaction);\n\n const txParams = isEIP1559\n ? {\n ...baseTxParams,\n maxFeePerGas: transactionMeta.transaction.maxFeePerGas,\n maxPriorityFeePerGas:\n transactionMeta.transaction.maxPriorityFeePerGas,\n estimatedBaseFee: transactionMeta.transaction.estimatedBaseFee,\n // specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set\n type: 2,\n }\n : baseTxParams;\n\n // delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set\n if (isEIP1559) {\n delete txParams.gasPrice;\n }\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n const signedTx = await this.sign(unsignedEthTx, from);\n transactionMeta.status = TransactionStatus.signed;\n this.updateTransaction(transactionMeta);\n const rawTransaction = bufferToHex(signedTx.serialize());\n\n transactionMeta.rawTransaction = rawTransaction;\n this.updateTransaction(transactionMeta);\n const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [\n rawTransaction,\n ]);\n transactionMeta.transactionHash = transactionHash;\n transactionMeta.status = TransactionStatus.submitted;\n this.updateTransaction(transactionMeta);\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n this.acceptApproval(transactionMeta);\n } catch (error: any) {\n this.failTransaction(transactionMeta, error);\n this.rejectApproval(transactionMeta);\n } finally {\n // must set transaction to submitted/failed before releasing lock\n if (nonceLock) {\n nonceLock.releaseLock();\n }\n releaseLock();\n }\n }\n\n /**\n * Cancels a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionID - The ID of the transaction to cancel.\n */\n cancelTransaction(transactionID: string) {\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n if (!transactionMeta) {\n return;\n }\n transactionMeta.status = TransactionStatus.rejected;\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n const transactions = this.state.transactions.filter(\n ({ id }) => id !== transactionID,\n );\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n this.rejectApproval(transactionMeta);\n }\n\n /**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionID - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n */\n async stopTransaction(\n transactionID: string,\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n ) {\n if (gasValues) {\n validateGasValues(gasValues);\n }\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n if (!transactionMeta) {\n return;\n }\n\n if (!this.sign) {\n throw new Error('No sign method defined.');\n }\n\n // gasPrice (legacy non EIP1559)\n const minGasPrice = getIncreasedPriceFromExisting(\n transactionMeta.transaction.gasPrice,\n CANCEL_RATE,\n );\n\n const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;\n\n const newGasPrice =\n (gasPriceFromValues &&\n validateMinimumIncrease(gasPriceFromValues, minGasPrice)) ||\n minGasPrice;\n\n // maxFeePerGas (EIP1559)\n const existingMaxFeePerGas = transactionMeta.transaction?.maxFeePerGas;\n const minMaxFeePerGas = getIncreasedPriceFromExisting(\n existingMaxFeePerGas,\n CANCEL_RATE,\n );\n const maxFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;\n const newMaxFeePerGas =\n (maxFeePerGasValues &&\n validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas)) ||\n (existingMaxFeePerGas && minMaxFeePerGas);\n\n // maxPriorityFeePerGas (EIP1559)\n const existingMaxPriorityFeePerGas =\n transactionMeta.transaction?.maxPriorityFeePerGas;\n const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(\n existingMaxPriorityFeePerGas,\n CANCEL_RATE,\n );\n const maxPriorityFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;\n const newMaxPriorityFeePerGas =\n (maxPriorityFeePerGasValues &&\n validateMinimumIncrease(\n maxPriorityFeePerGasValues,\n minMaxPriorityFeePerGas,\n )) ||\n (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);\n\n const txParams =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n from: transactionMeta.transaction.from,\n gasLimit: transactionMeta.transaction.gas,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n type: 2,\n nonce: transactionMeta.transaction.nonce,\n to: transactionMeta.transaction.from,\n value: '0x0',\n }\n : {\n from: transactionMeta.transaction.from,\n gasLimit: transactionMeta.transaction.gas,\n gasPrice: newGasPrice,\n nonce: transactionMeta.transaction.nonce,\n to: transactionMeta.transaction.from,\n value: '0x0',\n };\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n\n const signedTx = await this.sign(\n unsignedEthTx,\n transactionMeta.transaction.from,\n );\n const rawTransaction = bufferToHex(signedTx.serialize());\n await query(this.ethQuery, 'sendRawTransaction', [rawTransaction]);\n transactionMeta.status = TransactionStatus.cancelled;\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n this.rejectApproval(transactionMeta);\n }\n\n /**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionID - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transation.\n */\n async speedUpTransaction(\n transactionID: string,\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n ) {\n if (gasValues) {\n validateGasValues(gasValues);\n }\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n /* istanbul ignore next */\n if (!transactionMeta) {\n return;\n }\n\n /* istanbul ignore next */\n if (!this.sign) {\n throw new Error('No sign method defined.');\n }\n\n const { transactions } = this.state;\n\n // gasPrice (legacy non EIP1559)\n const minGasPrice = getIncreasedPriceFromExisting(\n transactionMeta.transaction.gasPrice,\n SPEED_UP_RATE,\n );\n\n const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;\n\n const newGasPrice =\n (gasPriceFromValues &&\n validateMinimumIncrease(gasPriceFromValues, minGasPrice)) ||\n minGasPrice;\n\n // maxFeePerGas (EIP1559)\n const existingMaxFeePerGas = transactionMeta.transaction?.maxFeePerGas;\n const minMaxFeePerGas = getIncreasedPriceFromExisting(\n existingMaxFeePerGas,\n SPEED_UP_RATE,\n );\n const maxFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;\n const newMaxFeePerGas =\n (maxFeePerGasValues &&\n validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas)) ||\n (existingMaxFeePerGas && minMaxFeePerGas);\n\n // maxPriorityFeePerGas (EIP1559)\n const existingMaxPriorityFeePerGas =\n transactionMeta.transaction?.maxPriorityFeePerGas;\n const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(\n existingMaxPriorityFeePerGas,\n SPEED_UP_RATE,\n );\n const maxPriorityFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;\n const newMaxPriorityFeePerGas =\n (maxPriorityFeePerGasValues &&\n validateMinimumIncrease(\n maxPriorityFeePerGasValues,\n minMaxPriorityFeePerGas,\n )) ||\n (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);\n\n const txParams =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n type: 2,\n }\n : {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n gasPrice: newGasPrice,\n };\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n\n const signedTx = await this.sign(\n unsignedEthTx,\n transactionMeta.transaction.from,\n );\n const rawTransaction = bufferToHex(signedTx.serialize());\n const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [\n rawTransaction,\n ]);\n const baseTransactionMeta = {\n ...transactionMeta,\n id: random(),\n time: Date.now(),\n transactionHash,\n };\n const newTransactionMeta =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n ...baseTransactionMeta,\n transaction: {\n ...transactionMeta.transaction,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n },\n }\n : {\n ...baseTransactionMeta,\n transaction: {\n ...transactionMeta.transaction,\n gasPrice: newGasPrice,\n },\n };\n transactions.push(newTransactionMeta);\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n this.hub.emit(`${transactionMeta.id}:speedup`, newTransactionMeta);\n }\n\n /**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @returns The gas and gas price.\n */\n async estimateGas(transaction: Transaction) {\n const estimatedTransaction = { ...transaction };\n const {\n gas,\n gasPrice: providedGasPrice,\n to,\n value,\n data,\n } = estimatedTransaction;\n const gasPrice =\n typeof providedGasPrice === 'undefined'\n ? await query(this.ethQuery, 'gasPrice')\n : providedGasPrice;\n const { providerConfig } = this.getNetworkState();\n const isCustomNetwork = providerConfig.type === NetworkType.rpc;\n // 1. If gas is already defined on the transaction, use it\n if (typeof gas !== 'undefined') {\n return { gas, gasPrice };\n }\n const { gasLimit } = await query(this.ethQuery, 'getBlockByNumber', [\n 'latest',\n false,\n ]);\n\n // 2. If to is not defined or this is not a contract address, and there is no data use 0x5208 / 21000.\n // If the newtwork is a custom network then bypass this check and fetch 'estimateGas'.\n /* istanbul ignore next */\n const code = to ? await query(this.ethQuery, 'getCode', [to]) : undefined;\n /* istanbul ignore next */\n if (\n !isCustomNetwork &&\n (!to || (to && !data && (!code || code === '0x')))\n ) {\n return { gas: '0x5208', gasPrice };\n }\n\n // if data, should be hex string format\n estimatedTransaction.data = !data\n ? data\n : /* istanbul ignore next */ addHexPrefix(data);\n\n // 3. If this is a contract address, safely estimate gas using RPC\n estimatedTransaction.value =\n typeof value === 'undefined' ? '0x0' : /* istanbul ignore next */ value;\n const gasLimitBN = hexToBN(gasLimit);\n estimatedTransaction.gas = BNToHex(fractionBN(gasLimitBN, 19, 20));\n\n let gasHex;\n let estimateGasError;\n try {\n gasHex = await query(this.ethQuery, 'estimateGas', [\n estimatedTransaction,\n ]);\n } catch (error) {\n estimateGasError = ESTIMATE_GAS_ERROR;\n }\n // 4. Pad estimated gas without exceeding the most recent block gasLimit. If the network is a\n // a custom network then return the eth_estimateGas value.\n const gasBN = hexToBN(gasHex);\n const maxGasBN = gasLimitBN.muln(0.9);\n const paddedGasBN = gasBN.muln(1.5);\n /* istanbul ignore next */\n if (gasBN.gt(maxGasBN) || isCustomNetwork) {\n return { gas: addHexPrefix(gasHex), gasPrice, estimateGasError };\n }\n\n /* istanbul ignore next */\n if (paddedGasBN.lt(maxGasBN)) {\n return {\n gas: addHexPrefix(BNToHex(paddedGasBN)),\n gasPrice,\n estimateGasError,\n };\n }\n return { gas: addHexPrefix(BNToHex(maxGasBN)), gasPrice };\n }\n\n /**\n * Check the status of submitted transactions on the network to determine whether they have\n * been included in a block. Any that have been included in a block are marked as confirmed.\n */\n async queryTransactionStatuses() {\n const { transactions } = this.state;\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId } = providerConfig;\n let gotUpdates = false;\n await safelyExecute(() =>\n Promise.all(\n transactions.map(async (meta, index) => {\n // Using fallback to networkID only when there is no chainId present.\n // Should be removed when networkID is completely removed.\n const txBelongsToCurrentChain =\n meta.chainId === currentChainId ||\n (!meta.chainId && meta.networkID === currentNetworkID);\n\n if (!meta.verifiedOnBlockchain && txBelongsToCurrentChain) {\n const [reconciledTx, updateRequired] =\n await this.blockchainTransactionStateReconciler(meta);\n if (updateRequired) {\n transactions[index] = reconciledTx;\n gotUpdates = updateRequired;\n }\n }\n }),\n ),\n );\n\n /* istanbul ignore else */\n if (gotUpdates) {\n this.update({\n transactions: this.trimTransactionsForState(transactions),\n });\n }\n }\n\n /**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n */\n updateTransaction(transactionMeta: TransactionMeta) {\n const { transactions } = this.state;\n transactionMeta.transaction = normalizeTransaction(\n transactionMeta.transaction,\n );\n validateTransaction(transactionMeta.transaction);\n const index = transactions.findIndex(({ id }) => transactionMeta.id === id);\n transactions[index] = transactionMeta;\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n }\n\n /**\n * Removes all transactions from state, optionally based on the current network.\n *\n * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the\n * current network. If `true`, all transactions are wiped.\n */\n wipeTransactions(ignoreNetwork?: boolean) {\n /* istanbul ignore next */\n if (ignoreNetwork) {\n this.update({ transactions: [] });\n return;\n }\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId } = providerConfig;\n const newTransactions = this.state.transactions.filter(\n ({ networkID, chainId }) => {\n // Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.\n const isCurrentNetwork =\n chainId === currentChainId ||\n (!chainId && networkID === currentNetworkID);\n return !isCurrentNetwork;\n },\n );\n\n this.update({\n transactions: this.trimTransactionsForState(newTransactions),\n });\n }\n\n /**\n * Get transactions from Etherscan for the given address. By default all transactions are\n * returned, but the `fromBlock` option can be given to filter just for transactions from a\n * specific block onward.\n *\n * @param address - The address to fetch the transactions for.\n * @param opt - Object containing optional data, fromBlock and Etherscan API key.\n * @returns The block number of the latest incoming transaction.\n */\n async fetchAll(\n address: string,\n opt?: FetchAllOptions,\n ): Promise<string | void> {\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId, type: networkType } = providerConfig;\n const { transactions } = this.state;\n\n const supportedNetworkIds = ['1', '5', '11155111'];\n /* istanbul ignore next */\n if (\n currentNetworkID === null ||\n supportedNetworkIds.indexOf(currentNetworkID) === -1\n ) {\n return undefined;\n }\n\n const [etherscanTxResponse, etherscanTokenResponse] =\n await handleTransactionFetch(\n networkType,\n address,\n this.config.txHistoryLimit,\n opt,\n );\n\n const normalizedTxs = etherscanTxResponse.result.map(\n (tx: EtherscanTransactionMeta) =>\n this.normalizeTx(tx, currentNetworkID, currentChainId),\n );\n const normalizedTokenTxs = etherscanTokenResponse.result.map(\n (tx: EtherscanTransactionMeta) =>\n this.normalizeTokenTx(tx, currentNetworkID, currentChainId),\n );\n\n const [updateRequired, allTxs] = this.etherscanTransactionStateReconciler(\n [...normalizedTxs, ...normalizedTokenTxs],\n transactions,\n );\n\n allTxs.sort((a, b) => (a.time < b.time ? -1 : 1));\n\n let latestIncomingTxBlockNumber: string | undefined;\n allTxs.forEach(async (tx) => {\n /* istanbul ignore next */\n if (\n // Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.\n (tx.chainId === currentChainId ||\n (!tx.chainId && tx.networkID === currentNetworkID)) &&\n tx.transaction.to &&\n tx.transaction.to.toLowerCase() === address.toLowerCase()\n ) {\n if (\n tx.blockNumber &&\n (!latestIncomingTxBlockNumber ||\n parseInt(latestIncomingTxBlockNumber, 10) <\n parseInt(tx.blockNumber, 10))\n ) {\n latestIncomingTxBlockNumber = tx.blockNumber;\n }\n }\n\n /* istanbul ignore else */\n if (tx.toSmartContract === undefined) {\n // If not `to` is a contract deploy, if not `data` is send eth\n if (\n tx.transaction.to &&\n (!tx.transaction.data || tx.transaction.data !== '0x')\n ) {\n const code = await query(this.ethQuery, 'getCode', [\n tx.transaction.to,\n ]);\n tx.toSmartContract = isSmartContractCode(code);\n } else {\n tx.toSmartContract = false;\n }\n }\n });\n\n // Update state only if new transactions were fetched or\n // the status or gas data of a transaction has changed\n if (updateRequired) {\n this.update({ transactions: this.trimTransactionsForState(allTxs) });\n }\n return latestIncomingTxBlockNumber;\n }\n\n /**\n * Trim the amount of transactions that are set on the state. Checks\n * if the length of the tx history is longer then desired persistence\n * limit and then if it is removes the oldest confirmed or rejected tx.\n * Pending or unapproved transactions will not be removed by this\n * operation. For safety of presenting a fully functional transaction UI\n * representation, this function will not break apart transactions with the\n * same nonce, created on the same day, per network. Not accounting for transactions of the same\n * nonce, same day and network combo can result in confusing or broken experiences\n * in the UI. The transactions are then updated using the BaseController update.\n *\n * @param transactions - The transactions to be applied to the state.\n * @returns The trimmed list of transactions.\n */\n private trimTransactionsForState(\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const nonceNetworkSet = new Set();\n const txsToKeep = transactions.reverse().filter((tx) => {\n const { chainId, networkID, status, transaction, time } = tx;\n if (transaction) {\n const key = `${transaction.nonce}-${\n chainId ? convertHexToDecimal(chainId) : networkID\n }-${new Date(time).toDateString()}`;\n if (nonceNetworkSet.has(key)) {\n return true;\n } else if (\n nonceNetworkSet.size < this.config.txHistoryLimit ||\n !this.isFinalState(status)\n ) {\n nonceNetworkSet.add(key);\n return true;\n }\n }\n return false;\n });\n txsToKeep.reverse();\n return txsToKeep;\n }\n\n /**\n * Determines if the transaction is in a final state.\n *\n * @param status - The transaction status.\n * @returns Whether the transaction is in a final state.\n */\n private isFinalState(status: TransactionStatus): boolean {\n return (\n status === TransactionStatus.rejected ||\n status === TransactionStatus.confirmed ||\n status === TransactionStatus.failed ||\n status === TransactionStatus.cancelled\n );\n }\n\n /**\n * Method to verify the state of a transaction using the Blockchain as a source of truth.\n *\n * @param meta - The local transaction to verify on the blockchain.\n * @returns A tuple containing the updated transaction, and whether or not an update was required.\n */\n private async blockchainTransactionStateReconciler(\n meta: TransactionMeta,\n ): Promise<[TransactionMeta, boolean]> {\n const { status, transactionHash } = meta;\n switch (status) {\n case TransactionStatus.confirmed:\n const txReceipt = await query(this.ethQuery, 'getTransactionReceipt', [\n transactionHash,\n ]);\n\n if (!txReceipt) {\n return [meta, false];\n }\n\n meta.verifiedOnBlockchain = true;\n meta.transaction.gasUsed = txReceipt.gasUsed;\n\n // According to the Web3 docs:\n // TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.\n if (Number(txReceipt.status) === 0) {\n const error: Error = new Error(\n 'Transaction failed. The transaction was reversed',\n );\n this.failTransaction(meta, error);\n return [meta, false];\n }\n\n return [meta, true];\n case TransactionStatus.submitted:\n const txObj = await query(this.ethQuery, 'getTransactionByHash', [\n transactionHash,\n ]);\n\n if (!txObj) {\n const receiptShowsFailedStatus =\n await this.checkTxReceiptStatusIsFailed(transactionHash);\n\n // Case the txObj is evaluated as false, a second check will\n // determine if the tx failed or it is pending or confirmed\n if (receiptShowsFailedStatus) {\n const error: Error = new Error(\n 'Transaction failed. The transaction was dropped or replaced by a new one',\n );\n this.failTransaction(meta, error);\n }\n }\n\n /* istanbul ignore next */\n if (txObj?.blockNumber) {\n meta.status = TransactionStatus.confirmed;\n this.hub.emit(`${meta.id}:confirmed`, meta);\n return [meta, true];\n }\n\n return [meta, false];\n default:\n return [meta, false];\n }\n }\n\n /**\n * Method to check if a tx has failed according to their receipt\n * According to the Web3 docs:\n * TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.\n * The receipt is not available for pending transactions and returns null.\n *\n * @param txHash - The transaction hash.\n * @returns Whether the transaction has failed.\n */\n private async checkTxReceiptStatusIsFailed(\n txHash: string | undefined,\n ): Promise<boolean> {\n const txReceipt = await query(this.ethQuery, 'getTransactionReceipt', [\n txHash,\n ]);\n if (!txReceipt) {\n // Transaction is pending\n return false;\n }\n return Number(txReceipt.status) === 0;\n }\n\n /**\n * Method to verify the state of transactions using Etherscan as a source of truth.\n *\n * @param remoteTxs - Transactions to reconcile that are from a remote source.\n * @param localTxs - Transactions to reconcile that are local.\n * @returns A tuple containing a boolean indicating whether or not an update was required, and the updated transaction.\n */\n private etherscanTransactionStateReconciler(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): [boolean, TransactionMeta[]] {\n const updatedTxs: TransactionMeta[] = this.getUpdatedTransactions(\n remoteTxs,\n localTxs,\n );\n\n const newTxs: TransactionMeta[] = this.getNewTransactions(\n remoteTxs,\n localTxs,\n );\n\n const updatedLocalTxs = localTxs.map((tx: TransactionMeta) => {\n const txIdx = updatedTxs.findIndex(\n ({ transactionHash }) => transactionHash === tx.transactionHash,\n );\n return txIdx === -1 ? tx : updatedTxs[txIdx];\n });\n\n const updateRequired = newTxs.length > 0 || updatedLocalTxs.length > 0;\n\n return [updateRequired, [...newTxs, ...updatedLocalTxs]];\n }\n\n /**\n * Get all transactions that are in the remote transactions array\n * but not in the local transactions array.\n *\n * @param remoteTxs - Array of transactions from remote source.\n * @param localTxs - Array of transactions stored locally.\n * @returns The new transactions.\n */\n private getNewTransactions(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): TransactionMeta[] {\n return remoteTxs.filter((tx) => {\n const alreadyInTransactions = localTxs.find(\n ({ transactionHash }) => transactionHash === tx.transactionHash,\n );\n return !alreadyInTransactions;\n });\n }\n\n /**\n * Get all the transactions that are locally outdated with respect\n * to a remote source (etherscan or blockchain). The returned array\n * contains the transactions with the updated data.\n *\n * @param remoteTxs - Array of transactions from remote source.\n * @param localTxs - Array of transactions stored locally.\n * @returns The updated transactions.\n */\n private getUpdatedTransactions(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): TransactionMeta[] {\n return remoteTxs.filter((remoteTx) => {\n const isTxOutdated = localTxs.find((localTx) => {\n return (\n remoteTx.transactionHash === localTx.transactionHash &&\n this.isTransactionOutdated(remoteTx, localTx)\n );\n });\n return isTxOutdated;\n });\n }\n\n /**\n * Verifies if a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteTx - The remote transaction from Etherscan.\n * @param localTx - The local transaction.\n * @returns Whether the transaction is outdated.\n */\n private isTransactionOutdated(\n remoteTx: TransactionMeta,\n localTx: TransactionMeta,\n ): boolean {\n const statusOutdated = this.isStatusOutdated(\n remoteTx.transactionHash,\n localTx.transactionHash,\n remoteTx.status,\n localTx.status,\n );\n const gasDataOutdated = this.isGasDataOutdated(\n remoteTx.transaction.gasUsed,\n localTx.transaction.gasUsed,\n );\n return statusOutdated || gasDataOutdated;\n }\n\n /**\n * Verifies if the status of a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteTxHash - Remote transaction hash.\n * @param localTxHash - Local transaction hash.\n * @param remoteTxStatus - Remote transaction status.\n * @param localTxStatus - Local transaction status.\n * @returns Whether the status is outdated.\n */\n private isStatusOutdated(\n remoteTxHash: string | undefined,\n localTxHash: string | undefined,\n remoteTxStatus: TransactionStatus,\n localTxStatus: TransactionStatus,\n ): boolean {\n return remoteTxHash === localTxHash && remoteTxStatus !== localTxStatus;\n }\n\n /**\n * Verifies if the gas data of a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteGasUsed - Remote gas used in the transaction.\n * @param localGasUsed - Local gas used in the transaction.\n * @returns Whether the gas data is outdated.\n */\n private isGasDataOutdated(\n remoteGasUsed: string | undefined,\n localGasUsed: string | undefined,\n ): boolean {\n return remoteGasUsed !== localGasUsed;\n }\n\n private async requestApproval(\n txMeta: TransactionMeta,\n { shouldShowRequest } = { shouldShowRequest: true },\n ) {\n const id = this.getApprovalId(txMeta);\n const { origin } = txMeta;\n const type = ApprovalType.Transaction;\n const requestData = { txId: txMeta.id };\n\n try {\n await this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin: origin || ORIGIN_METAMASK,\n type,\n requestData,\n },\n shouldShowRequest,\n );\n } catch (error) {\n console.info('Failed to request transaction approval', error);\n }\n }\n\n private acceptApproval(txMeta: TransactionMeta) {\n const id = this.getApprovalId(txMeta);\n\n try {\n this.messagingSystem.call('ApprovalController:acceptRequest', id);\n } catch (error) {\n console.info('Failed to accept transaction approval request', error);\n }\n }\n\n private rejectApproval(txMeta: TransactionMeta) {\n const id = this.getApprovalId(txMeta);\n\n try {\n this.messagingSystem.call(\n 'ApprovalController:rejectRequest',\n id,\n new Error('Rejected'),\n );\n } catch (error) {\n console.info('Failed to reject transaction approval request', error);\n }\n }\n\n private getApprovalId(txMeta: TransactionMeta) {\n return String(txMeta.id);\n }\n}\n\nexport default TransactionController;\n"]}
|
|
1
|
+
{"version":3,"file":"TransactionController.js","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,qDAAgE;AAChE,mDAAuD;AACvD,8EAAiD;AACjD,0DAAiC;AACjC,gEAAwC;AACxC,uCAAsE;AACtE,+BAAoC;AACpC,6CAAoC;AAEpC,+DAKmC;AAMnC,iEAYoC;AAMpC,kEAAyC;AACzC,mCAYiB;AAEJ,QAAA,QAAQ,GAAG,QAAQ,CAAC;AA6DjC;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EATW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAS5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,CAAA;IACnC,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAgID;;GAEG;AACU,QAAA,WAAW,GAAG,GAAG,CAAC;AAE/B;;GAEG;AACU,QAAA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B,CAAC;IAEO,sBAAsB,CAAC,aAAqB;QAIlD,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAEvD,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;SAChD;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE/D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;IAC5C,CAAC;CACF;AA30CD,sDA20CC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { addHexPrefix, bufferToHex, BN } from 'ethereumjs-util';\nimport { errorCodes, ethErrors } from 'eth-rpc-errors';\nimport MethodRegistry from 'eth-method-registry';\nimport EthQuery from 'eth-query';\nimport Common from '@ethereumjs/common';\nimport { TransactionFactory, TypedTransaction } from '@ethereumjs/tx';\nimport { v1 as random } from 'uuid';\nimport { Mutex } from 'async-mutex';\nimport type { Hex } from '@metamask/utils';\nimport {\n BaseController,\n BaseConfig,\n BaseState,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport type {\n BlockTracker,\n NetworkState,\n Provider,\n} from '@metamask/network-controller';\nimport {\n BNToHex,\n fractionBN,\n hexToBN,\n safelyExecute,\n isSmartContractCode,\n query,\n NetworkType,\n RPC,\n ApprovalType,\n ORIGIN_METAMASK,\n convertHexToDecimal,\n} from '@metamask/controller-utils';\nimport {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport NonceTracker from 'nonce-tracker';\nimport {\n getAndFormatTransactionsForNonceTracker,\n normalizeTransaction,\n validateTransaction,\n handleTransactionFetch,\n getIncreasedPriceFromExisting,\n isEIP1559Transaction,\n isGasPriceValue,\n isFeeMarketEIP1559Values,\n validateGasValues,\n validateMinimumIncrease,\n ESTIMATE_GAS_ERROR,\n} from './utils';\n\nexport const HARDFORK = 'london';\n\n/**\n * @type Result\n * @property result - Promise resolving to a new transaction hash\n * @property transactionMeta - Meta information about this new transaction\n */\nexport interface Result {\n result: Promise<string>;\n transactionMeta: TransactionMeta;\n}\n\n/**\n * @type Fetch All Options\n * @property fromBlock - String containing a specific block decimal number\n * @property etherscanApiKey - API key to be used to fetch token transactions\n */\nexport interface FetchAllOptions {\n fromBlock?: string;\n etherscanApiKey?: string;\n}\n\n/**\n * @type Transaction\n *\n * Transaction representation\n * @property chainId - Network ID as per EIP-155\n * @property data - Data to pass with this transaction\n * @property from - Address to send this transaction from\n * @property gas - Gas to send with this transaction\n * @property gasPrice - Price of gas with this transaction\n * @property gasUsed - Gas used in the transaction\n * @property nonce - Unique number to prevent replay attacks\n * @property to - Address to send this transaction to\n * @property value - Value associated with this transaction\n */\nexport interface Transaction {\n chainId?: Hex;\n data?: string;\n from: string;\n gas?: string;\n gasPrice?: string;\n gasUsed?: string;\n nonce?: string;\n to?: string;\n value?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n estimatedBaseFee?: string;\n estimateGasError?: string;\n}\n\nexport interface GasPriceValue {\n gasPrice: string;\n}\n\nexport interface FeeMarketEIP1559Values {\n maxFeePerGas: string;\n maxPriorityFeePerGas: string;\n}\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\ntype TransactionMetaBase = {\n isTransfer?: boolean;\n transferInformation?: {\n symbol: string;\n contractAddress: string;\n decimals: number;\n };\n id: string;\n networkID?: string;\n chainId?: Hex;\n origin?: string;\n rawTransaction?: string;\n time: number;\n toSmartContract?: boolean;\n transaction: Transaction;\n transactionHash?: string;\n blockNumber?: string;\n deviceConfirmedOn?: WalletDevice;\n verifiedOnBlockchain?: boolean;\n};\n\n/**\n * @type TransactionMeta\n *\n * TransactionMeta representation\n * @property error - Synthesized error information for failed transactions\n * @property id - Generated UUID associated with this transaction\n * @property networkID - Network code as per EIP-155 for this transaction\n * @property origin - Origin this transaction was sent from\n * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed\n * @property rawTransaction - Hex representation of the underlying transaction\n * @property status - String status of this transaction\n * @property time - Timestamp associated with this transaction\n * @property toSmartContract - Whether transaction recipient is a smart contract\n * @property transaction - Underlying Transaction object\n * @property transactionHash - Hash of a successful transaction\n * @property blockNumber - Number of the block where the transaction has been included\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\n/**\n * @type EtherscanTransactionMeta\n *\n * EtherscanTransactionMeta representation\n * @property blockNumber - Number of the block where the transaction has been included\n * @property timeStamp - Timestamp associated with this transaction\n * @property hash - Hash of a successful transaction\n * @property nonce - Nonce of the transaction\n * @property blockHash - Hash of the block where the transaction has been included\n * @property transactionIndex - Etherscan internal index for this transaction\n * @property from - Address to send this transaction from\n * @property to - Address to send this transaction to\n * @property gas - Gas to send with this transaction\n * @property gasPrice - Price of gas with this transaction\n * @property isError - Synthesized error information for failed transactions\n * @property txreceipt_status - Receipt status for this transaction\n * @property input - input of the transaction\n * @property contractAddress - Address of the contract\n * @property cumulativeGasUsed - Amount of gas used\n * @property confirmations - Number of confirmations\n */\nexport interface EtherscanTransactionMeta {\n blockNumber: string;\n timeStamp: string;\n hash: string;\n nonce: string;\n blockHash: string;\n transactionIndex: string;\n from: string;\n to: string;\n value: string;\n gas: string;\n gasPrice: string;\n cumulativeGasUsed: string;\n gasUsed: string;\n isError: string;\n txreceipt_status: string;\n input: string;\n contractAddress: string;\n confirmations: string;\n tokenDecimal: string;\n tokenSymbol: string;\n}\n\n/**\n * @type TransactionConfig\n *\n * Transaction controller configuration\n * @property interval - Polling interval used to fetch new currency rate\n * @property provider - Provider used to create a new underlying EthQuery instance\n * @property sign - Method used to sign transactions\n */\nexport interface TransactionConfig extends BaseConfig {\n interval: number;\n sign?: (transaction: Transaction, from: string) => Promise<any>;\n txHistoryLimit: number;\n}\n\n/**\n * @type MethodData\n *\n * Method data registry object\n * @property registryMethod - Registry method raw string\n * @property parsedRegistryMethod - Registry method object, containing name and method arguments\n */\nexport interface MethodData {\n registryMethod: string;\n parsedRegistryMethod: Record<string, unknown>;\n}\n\n/**\n * @type TransactionState\n *\n * Transaction controller state\n * @property transactions - A list of TransactionMeta objects\n * @property methodData - Object containing all known method data information\n */\nexport interface TransactionState extends BaseState {\n transactions: TransactionMeta[];\n methodData: { [key: string]: MethodData };\n}\n\n/**\n * Multiplier used to determine a transaction's increased gas fee during cancellation\n */\nexport const CANCEL_RATE = 1.5;\n\n/**\n * Multiplier used to determine a transaction's increased gas fee during speed up\n */\nexport const SPEED_UP_RATE = 1.1;\n\n/**\n * The name of the {@link TransactionController}.\n */\nconst controllerName = 'TransactionController';\n\n/**\n * The external actions available to the {@link TransactionController}.\n */\ntype AllowedActions = AddApprovalRequest;\n\n/**\n * The messenger of the {@link TransactionController}.\n */\nexport type TransactionControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Controller responsible for submitting and managing transactions.\n */\nexport class TransactionController extends BaseController<\n TransactionConfig,\n TransactionState\n> {\n private ethQuery: EthQuery;\n\n private nonceTracker: NonceTracker;\n\n private registry: any;\n\n private provider: Provider;\n\n private handle?: ReturnType<typeof setTimeout>;\n\n private mutex = new Mutex();\n\n private getNetworkState: () => NetworkState;\n\n private messagingSystem: TransactionControllerMessenger;\n\n private failTransaction(transactionMeta: TransactionMeta, error: Error) {\n const newTransactionMeta = {\n ...transactionMeta,\n error,\n status: TransactionStatus.failed,\n };\n this.updateTransaction(newTransactionMeta);\n this.hub.emit(`${transactionMeta.id}:finished`, newTransactionMeta);\n }\n\n private async registryLookup(fourBytePrefix: string): Promise<MethodData> {\n const registryMethod = await this.registry.lookup(fourBytePrefix);\n const parsedRegistryMethod = this.registry.parse(registryMethod);\n return { registryMethod, parsedRegistryMethod };\n }\n\n /**\n * Normalizes the transaction information from etherscan\n * to be compatible with the TransactionMeta interface.\n *\n * @param txMeta - The transaction.\n * @param currentNetworkID - The current network ID.\n * @param currentChainId - The current chain ID.\n * @returns The normalized transaction.\n */\n private normalizeTx(\n txMeta: EtherscanTransactionMeta,\n currentNetworkID: string,\n currentChainId: Hex,\n ): TransactionMeta {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n const normalizedTransactionBase = {\n blockNumber: txMeta.blockNumber,\n id: random({ msecs: time }),\n networkID: currentNetworkID,\n chainId: currentChainId,\n time,\n transaction: {\n data: txMeta.input,\n from: txMeta.from,\n gas: BNToHex(new BN(txMeta.gas)),\n gasPrice: BNToHex(new BN(txMeta.gasPrice)),\n gasUsed: BNToHex(new BN(txMeta.gasUsed)),\n nonce: BNToHex(new BN(txMeta.nonce)),\n to: txMeta.to,\n value: BNToHex(new BN(txMeta.value)),\n },\n transactionHash: txMeta.hash,\n verifiedOnBlockchain: false,\n };\n\n /* istanbul ignore else */\n if (txMeta.isError === '0') {\n return {\n ...normalizedTransactionBase,\n status: TransactionStatus.confirmed,\n };\n }\n\n /* istanbul ignore next */\n return {\n ...normalizedTransactionBase,\n error: new Error('Transaction failed'),\n status: TransactionStatus.failed,\n };\n }\n\n private normalizeTokenTx = (\n txMeta: EtherscanTransactionMeta,\n currentNetworkID: string,\n currentChainId: Hex,\n ): TransactionMeta => {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n const {\n to,\n from,\n gas,\n gasPrice,\n gasUsed,\n hash,\n contractAddress,\n tokenDecimal,\n tokenSymbol,\n value,\n } = txMeta;\n return {\n id: random({ msecs: time }),\n isTransfer: true,\n networkID: currentNetworkID,\n chainId: currentChainId,\n status: TransactionStatus.confirmed,\n time,\n transaction: {\n chainId: currentChainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n to,\n value,\n },\n transactionHash: hash,\n transferInformation: {\n contractAddress,\n decimals: Number(tokenDecimal),\n symbol: tokenSymbol,\n },\n verifiedOnBlockchain: false,\n };\n };\n\n /**\n * EventEmitter instance used to listen to specific transactional events\n */\n hub = new EventEmitter();\n\n /**\n * Name of this controller used during composition\n */\n override name = 'TransactionController';\n\n /**\n * Method used to sign transactions\n */\n sign?: (\n transaction: TypedTransaction,\n from: string,\n ) => Promise<TypedTransaction>;\n\n /**\n * Creates a TransactionController instance.\n *\n * @param options - The controller options.\n * @param options.getNetworkState - Gets the state of the network controller.\n * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.\n * @param options.provider - The provider used to create the underlying EthQuery instance.\n * @param options.blockTracker - The block tracker used to poll for new blocks data.\n * @param options.messenger - The controller messenger.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n getNetworkState,\n onNetworkStateChange,\n provider,\n blockTracker,\n messenger,\n }: {\n getNetworkState: () => NetworkState;\n onNetworkStateChange: (listener: (state: NetworkState) => void) => void;\n provider: Provider;\n blockTracker: BlockTracker;\n messenger: TransactionControllerMessenger;\n },\n config?: Partial<TransactionConfig>,\n state?: Partial<TransactionState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n interval: 15000,\n txHistoryLimit: 40,\n };\n\n this.defaultState = {\n methodData: {},\n transactions: [],\n };\n this.initialize();\n this.provider = provider;\n this.messagingSystem = messenger;\n this.getNetworkState = getNetworkState;\n this.ethQuery = new EthQuery(provider);\n this.registry = new MethodRegistry({ provider });\n this.nonceTracker = new NonceTracker({\n provider,\n blockTracker,\n getPendingTransactions: (address) =>\n getAndFormatTransactionsForNonceTracker(\n address,\n TransactionStatus.submitted,\n this.state.transactions,\n ),\n getConfirmedTransactions: (address) =>\n getAndFormatTransactionsForNonceTracker(\n address,\n TransactionStatus.confirmed,\n this.state.transactions,\n ),\n });\n\n onNetworkStateChange(() => {\n this.ethQuery = new EthQuery(this.provider);\n this.registry = new MethodRegistry({ provider: this.provider });\n });\n this.poll();\n }\n\n /**\n * Starts a new polling interval.\n *\n * @param interval - The polling interval used to fetch new transaction statuses.\n */\n async poll(interval?: number): Promise<void> {\n interval && this.configure({ interval }, false, false);\n this.handle && clearTimeout(this.handle);\n await safelyExecute(() => this.queryTransactionStatuses());\n this.handle = setTimeout(() => {\n this.poll(this.config.interval);\n }, this.config.interval);\n }\n\n /**\n * Handle new method data request.\n *\n * @param fourBytePrefix - The method prefix.\n * @returns The method data object corresponding to the given signature prefix.\n */\n async handleMethodData(fourBytePrefix: string): Promise<MethodData> {\n const releaseLock = await this.mutex.acquire();\n try {\n const { methodData } = this.state;\n const knownMethod = Object.keys(methodData).find(\n (knownFourBytePrefix) => fourBytePrefix === knownFourBytePrefix,\n );\n if (knownMethod) {\n return methodData[fourBytePrefix];\n }\n const registry = await this.registryLookup(fourBytePrefix);\n this.update({\n methodData: { ...methodData, ...{ [fourBytePrefix]: registry } },\n });\n return registry;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Add a new unapproved transaction to state. Parameters will be validated, a\n * unique transaction id will be generated, and gas and gasPrice will be calculated\n * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.\n *\n * @param transaction - The transaction object to add.\n * @param origin - The domain origin to append to the generated TransactionMeta.\n * @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.\n * @returns Object containing a promise resolving to the transaction hash if approved.\n */\n async addTransaction(\n transaction: Transaction,\n origin?: string,\n deviceConfirmedOn?: WalletDevice,\n ): Promise<Result> {\n const { providerConfig, networkId } = this.getNetworkState();\n const { transactions } = this.state;\n transaction = normalizeTransaction(transaction);\n validateTransaction(transaction);\n\n const transactionMeta: TransactionMeta = {\n id: random(),\n networkID: networkId ?? undefined,\n chainId: providerConfig.chainId,\n origin,\n status: TransactionStatus.unapproved as TransactionStatus.unapproved,\n time: Date.now(),\n transaction,\n deviceConfirmedOn,\n verifiedOnBlockchain: false,\n };\n\n try {\n const { gas, estimateGasError } = await this.estimateGas(transaction);\n transaction.gas = gas;\n transaction.estimateGasError = estimateGasError;\n } catch (error: any) {\n this.failTransaction(transactionMeta, error);\n return Promise.reject(error);\n }\n\n transactions.push(transactionMeta);\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n this.hub.emit(`unapprovedTransaction`, transactionMeta);\n\n return {\n result: this.processApproval(transactionMeta),\n transactionMeta,\n };\n }\n\n prepareUnsignedEthTx(txParams: Record<string, unknown>): TypedTransaction {\n return TransactionFactory.fromTxData(txParams, {\n common: this.getCommonConfiguration(),\n freeze: false,\n });\n }\n\n /**\n * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for\n * specifying which chain, network, hardfork and EIPs to support for\n * a transaction. By referencing this configuration, and analyzing the fields\n * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718\n * transaction type to use.\n *\n * @returns {Common} common configuration object\n */\n\n getCommonConfiguration(): Common {\n const {\n networkId,\n providerConfig: { type: chain, chainId, nickname: name },\n } = this.getNetworkState();\n\n if (\n chain !== RPC &&\n chain !== NetworkType['linea-goerli'] &&\n chain !== NetworkType['linea-mainnet']\n ) {\n return new Common({ chain, hardfork: HARDFORK });\n }\n\n const customChainParams = {\n name,\n chainId: parseInt(chainId, 16),\n networkId: networkId === null ? NaN : parseInt(networkId, undefined),\n };\n\n return Common.forCustomChain(\n NetworkType.mainnet,\n customChainParams,\n HARDFORK,\n );\n }\n\n /**\n * Attempts to cancel a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionID - The ID of the transaction to cancel.\n * @param gasValues - The gas values to use for the cancellation transaction.\n */\n async stopTransaction(\n transactionID: string,\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n ) {\n if (gasValues) {\n validateGasValues(gasValues);\n }\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n if (!transactionMeta) {\n return;\n }\n\n if (!this.sign) {\n throw new Error('No sign method defined.');\n }\n\n // gasPrice (legacy non EIP1559)\n const minGasPrice = getIncreasedPriceFromExisting(\n transactionMeta.transaction.gasPrice,\n CANCEL_RATE,\n );\n\n const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;\n\n const newGasPrice =\n (gasPriceFromValues &&\n validateMinimumIncrease(gasPriceFromValues, minGasPrice)) ||\n minGasPrice;\n\n // maxFeePerGas (EIP1559)\n const existingMaxFeePerGas = transactionMeta.transaction?.maxFeePerGas;\n const minMaxFeePerGas = getIncreasedPriceFromExisting(\n existingMaxFeePerGas,\n CANCEL_RATE,\n );\n const maxFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;\n const newMaxFeePerGas =\n (maxFeePerGasValues &&\n validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas)) ||\n (existingMaxFeePerGas && minMaxFeePerGas);\n\n // maxPriorityFeePerGas (EIP1559)\n const existingMaxPriorityFeePerGas =\n transactionMeta.transaction?.maxPriorityFeePerGas;\n const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(\n existingMaxPriorityFeePerGas,\n CANCEL_RATE,\n );\n const maxPriorityFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;\n const newMaxPriorityFeePerGas =\n (maxPriorityFeePerGasValues &&\n validateMinimumIncrease(\n maxPriorityFeePerGasValues,\n minMaxPriorityFeePerGas,\n )) ||\n (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);\n\n const txParams =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n from: transactionMeta.transaction.from,\n gasLimit: transactionMeta.transaction.gas,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n type: 2,\n nonce: transactionMeta.transaction.nonce,\n to: transactionMeta.transaction.from,\n value: '0x0',\n }\n : {\n from: transactionMeta.transaction.from,\n gasLimit: transactionMeta.transaction.gas,\n gasPrice: newGasPrice,\n nonce: transactionMeta.transaction.nonce,\n to: transactionMeta.transaction.from,\n value: '0x0',\n };\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n\n const signedTx = await this.sign(\n unsignedEthTx,\n transactionMeta.transaction.from,\n );\n const rawTransaction = bufferToHex(signedTx.serialize());\n await query(this.ethQuery, 'sendRawTransaction', [rawTransaction]);\n transactionMeta.status = TransactionStatus.cancelled;\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n }\n\n /**\n * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.\n *\n * @param transactionID - The ID of the transaction to speed up.\n * @param gasValues - The gas values to use for the speed up transation.\n */\n async speedUpTransaction(\n transactionID: string,\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n ) {\n if (gasValues) {\n validateGasValues(gasValues);\n }\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n /* istanbul ignore next */\n if (!transactionMeta) {\n return;\n }\n\n /* istanbul ignore next */\n if (!this.sign) {\n throw new Error('No sign method defined.');\n }\n\n const { transactions } = this.state;\n\n // gasPrice (legacy non EIP1559)\n const minGasPrice = getIncreasedPriceFromExisting(\n transactionMeta.transaction.gasPrice,\n SPEED_UP_RATE,\n );\n\n const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;\n\n const newGasPrice =\n (gasPriceFromValues &&\n validateMinimumIncrease(gasPriceFromValues, minGasPrice)) ||\n minGasPrice;\n\n // maxFeePerGas (EIP1559)\n const existingMaxFeePerGas = transactionMeta.transaction?.maxFeePerGas;\n const minMaxFeePerGas = getIncreasedPriceFromExisting(\n existingMaxFeePerGas,\n SPEED_UP_RATE,\n );\n const maxFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;\n const newMaxFeePerGas =\n (maxFeePerGasValues &&\n validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas)) ||\n (existingMaxFeePerGas && minMaxFeePerGas);\n\n // maxPriorityFeePerGas (EIP1559)\n const existingMaxPriorityFeePerGas =\n transactionMeta.transaction?.maxPriorityFeePerGas;\n const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(\n existingMaxPriorityFeePerGas,\n SPEED_UP_RATE,\n );\n const maxPriorityFeePerGasValues =\n isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;\n const newMaxPriorityFeePerGas =\n (maxPriorityFeePerGasValues &&\n validateMinimumIncrease(\n maxPriorityFeePerGasValues,\n minMaxPriorityFeePerGas,\n )) ||\n (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);\n\n const txParams =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n type: 2,\n }\n : {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n gasPrice: newGasPrice,\n };\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n\n const signedTx = await this.sign(\n unsignedEthTx,\n transactionMeta.transaction.from,\n );\n const rawTransaction = bufferToHex(signedTx.serialize());\n const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [\n rawTransaction,\n ]);\n const baseTransactionMeta = {\n ...transactionMeta,\n id: random(),\n time: Date.now(),\n transactionHash,\n };\n const newTransactionMeta =\n newMaxFeePerGas && newMaxPriorityFeePerGas\n ? {\n ...baseTransactionMeta,\n transaction: {\n ...transactionMeta.transaction,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas: newMaxPriorityFeePerGas,\n },\n }\n : {\n ...baseTransactionMeta,\n transaction: {\n ...transactionMeta.transaction,\n gasPrice: newGasPrice,\n },\n };\n transactions.push(newTransactionMeta);\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n this.hub.emit(`${transactionMeta.id}:speedup`, newTransactionMeta);\n }\n\n /**\n * Estimates required gas for a given transaction.\n *\n * @param transaction - The transaction to estimate gas for.\n * @returns The gas and gas price.\n */\n async estimateGas(transaction: Transaction) {\n const estimatedTransaction = { ...transaction };\n const {\n gas,\n gasPrice: providedGasPrice,\n to,\n value,\n data,\n } = estimatedTransaction;\n const gasPrice =\n typeof providedGasPrice === 'undefined'\n ? await query(this.ethQuery, 'gasPrice')\n : providedGasPrice;\n const { providerConfig } = this.getNetworkState();\n const isCustomNetwork = providerConfig.type === NetworkType.rpc;\n // 1. If gas is already defined on the transaction, use it\n if (typeof gas !== 'undefined') {\n return { gas, gasPrice };\n }\n const { gasLimit } = await query(this.ethQuery, 'getBlockByNumber', [\n 'latest',\n false,\n ]);\n\n // 2. If to is not defined or this is not a contract address, and there is no data use 0x5208 / 21000.\n // If the newtwork is a custom network then bypass this check and fetch 'estimateGas'.\n /* istanbul ignore next */\n const code = to ? await query(this.ethQuery, 'getCode', [to]) : undefined;\n /* istanbul ignore next */\n if (\n !isCustomNetwork &&\n (!to || (to && !data && (!code || code === '0x')))\n ) {\n return { gas: '0x5208', gasPrice };\n }\n\n // if data, should be hex string format\n estimatedTransaction.data = !data\n ? data\n : /* istanbul ignore next */ addHexPrefix(data);\n\n // 3. If this is a contract address, safely estimate gas using RPC\n estimatedTransaction.value =\n typeof value === 'undefined' ? '0x0' : /* istanbul ignore next */ value;\n const gasLimitBN = hexToBN(gasLimit);\n estimatedTransaction.gas = BNToHex(fractionBN(gasLimitBN, 19, 20));\n\n let gasHex;\n let estimateGasError;\n try {\n gasHex = await query(this.ethQuery, 'estimateGas', [\n estimatedTransaction,\n ]);\n } catch (error) {\n estimateGasError = ESTIMATE_GAS_ERROR;\n }\n // 4. Pad estimated gas without exceeding the most recent block gasLimit. If the network is a\n // a custom network then return the eth_estimateGas value.\n const gasBN = hexToBN(gasHex);\n const maxGasBN = gasLimitBN.muln(0.9);\n const paddedGasBN = gasBN.muln(1.5);\n /* istanbul ignore next */\n if (gasBN.gt(maxGasBN) || isCustomNetwork) {\n return { gas: addHexPrefix(gasHex), gasPrice, estimateGasError };\n }\n\n /* istanbul ignore next */\n if (paddedGasBN.lt(maxGasBN)) {\n return {\n gas: addHexPrefix(BNToHex(paddedGasBN)),\n gasPrice,\n estimateGasError,\n };\n }\n return { gas: addHexPrefix(BNToHex(maxGasBN)), gasPrice, estimateGasError };\n }\n\n /**\n * Check the status of submitted transactions on the network to determine whether they have\n * been included in a block. Any that have been included in a block are marked as confirmed.\n */\n async queryTransactionStatuses() {\n const { transactions } = this.state;\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId } = providerConfig;\n let gotUpdates = false;\n await safelyExecute(() =>\n Promise.all(\n transactions.map(async (meta, index) => {\n // Using fallback to networkID only when there is no chainId present.\n // Should be removed when networkID is completely removed.\n const txBelongsToCurrentChain =\n meta.chainId === currentChainId ||\n (!meta.chainId && meta.networkID === currentNetworkID);\n\n if (!meta.verifiedOnBlockchain && txBelongsToCurrentChain) {\n const [reconciledTx, updateRequired] =\n await this.blockchainTransactionStateReconciler(meta);\n if (updateRequired) {\n transactions[index] = reconciledTx;\n gotUpdates = updateRequired;\n }\n }\n }),\n ),\n );\n\n /* istanbul ignore else */\n if (gotUpdates) {\n this.update({\n transactions: this.trimTransactionsForState(transactions),\n });\n }\n }\n\n /**\n * Updates an existing transaction in state.\n *\n * @param transactionMeta - The new transaction to store in state.\n */\n updateTransaction(transactionMeta: TransactionMeta) {\n const { transactions } = this.state;\n transactionMeta.transaction = normalizeTransaction(\n transactionMeta.transaction,\n );\n validateTransaction(transactionMeta.transaction);\n const index = transactions.findIndex(({ id }) => transactionMeta.id === id);\n transactions[index] = transactionMeta;\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n }\n\n /**\n * Removes all transactions from state, optionally based on the current network.\n *\n * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the\n * current network. If `true`, all transactions are wiped.\n */\n wipeTransactions(ignoreNetwork?: boolean) {\n /* istanbul ignore next */\n if (ignoreNetwork) {\n this.update({ transactions: [] });\n return;\n }\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId } = providerConfig;\n const newTransactions = this.state.transactions.filter(\n ({ networkID, chainId }) => {\n // Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.\n const isCurrentNetwork =\n chainId === currentChainId ||\n (!chainId && networkID === currentNetworkID);\n return !isCurrentNetwork;\n },\n );\n\n this.update({\n transactions: this.trimTransactionsForState(newTransactions),\n });\n }\n\n /**\n * Get transactions from Etherscan for the given address. By default all transactions are\n * returned, but the `fromBlock` option can be given to filter just for transactions from a\n * specific block onward.\n *\n * @param address - The address to fetch the transactions for.\n * @param opt - Object containing optional data, fromBlock and Etherscan API key.\n * @returns The block number of the latest incoming transaction.\n */\n async fetchAll(\n address: string,\n opt?: FetchAllOptions,\n ): Promise<string | void> {\n const { providerConfig, networkId: currentNetworkID } =\n this.getNetworkState();\n const { chainId: currentChainId, type: networkType } = providerConfig;\n const { transactions } = this.state;\n\n const supportedNetworkIds = ['1', '5', '11155111'];\n /* istanbul ignore next */\n if (\n currentNetworkID === null ||\n supportedNetworkIds.indexOf(currentNetworkID) === -1\n ) {\n return undefined;\n }\n\n const [etherscanTxResponse, etherscanTokenResponse] =\n await handleTransactionFetch(\n networkType,\n address,\n this.config.txHistoryLimit,\n opt,\n );\n\n const normalizedTxs = etherscanTxResponse.result.map(\n (tx: EtherscanTransactionMeta) =>\n this.normalizeTx(tx, currentNetworkID, currentChainId),\n );\n const normalizedTokenTxs = etherscanTokenResponse.result.map(\n (tx: EtherscanTransactionMeta) =>\n this.normalizeTokenTx(tx, currentNetworkID, currentChainId),\n );\n\n const [updateRequired, allTxs] = this.etherscanTransactionStateReconciler(\n [...normalizedTxs, ...normalizedTokenTxs],\n transactions,\n );\n\n allTxs.sort((a, b) => (a.time < b.time ? -1 : 1));\n\n let latestIncomingTxBlockNumber: string | undefined;\n allTxs.forEach(async (tx) => {\n /* istanbul ignore next */\n if (\n // Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.\n (tx.chainId === currentChainId ||\n (!tx.chainId && tx.networkID === currentNetworkID)) &&\n tx.transaction.to &&\n tx.transaction.to.toLowerCase() === address.toLowerCase()\n ) {\n if (\n tx.blockNumber &&\n (!latestIncomingTxBlockNumber ||\n parseInt(latestIncomingTxBlockNumber, 10) <\n parseInt(tx.blockNumber, 10))\n ) {\n latestIncomingTxBlockNumber = tx.blockNumber;\n }\n }\n\n /* istanbul ignore else */\n if (tx.toSmartContract === undefined) {\n // If not `to` is a contract deploy, if not `data` is send eth\n if (\n tx.transaction.to &&\n (!tx.transaction.data || tx.transaction.data !== '0x')\n ) {\n const code = await query(this.ethQuery, 'getCode', [\n tx.transaction.to,\n ]);\n tx.toSmartContract = isSmartContractCode(code);\n } else {\n tx.toSmartContract = false;\n }\n }\n });\n\n // Update state only if new transactions were fetched or\n // the status or gas data of a transaction has changed\n if (updateRequired) {\n this.update({ transactions: this.trimTransactionsForState(allTxs) });\n }\n return latestIncomingTxBlockNumber;\n }\n\n private async processApproval(\n transactionMeta: TransactionMeta,\n ): Promise<string> {\n const transactionId = transactionMeta.id;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n const acceptResult = await this.requestApproval(transactionMeta);\n resultCallbacks = acceptResult.resultCallbacks;\n\n const { meta, isCompleted } = this.isTransactionCompleted(transactionId);\n\n if (meta && !isCompleted) {\n await this.approveTransaction(transactionId);\n }\n } catch (error: any) {\n const { meta, isCompleted } = this.isTransactionCompleted(transactionId);\n\n if (meta && !isCompleted) {\n if (error.code === errorCodes.provider.userRejectedRequest) {\n this.cancelTransaction(transactionId);\n\n throw ethErrors.provider.userRejectedRequest(\n 'User rejected the transaction',\n );\n } else {\n this.failTransaction(meta, error);\n }\n }\n }\n\n const finalMeta = this.getTransaction(transactionId);\n\n switch (finalMeta?.status) {\n case TransactionStatus.failed:\n resultCallbacks?.error(finalMeta.error);\n throw ethErrors.rpc.internal(finalMeta.error.message);\n\n case TransactionStatus.cancelled:\n const cancelError = ethErrors.rpc.internal(\n 'User cancelled the transaction',\n );\n\n resultCallbacks?.error(cancelError);\n throw cancelError;\n\n case TransactionStatus.submitted:\n resultCallbacks?.success();\n return finalMeta.transactionHash as string;\n\n default:\n const internalError = ethErrors.rpc.internal(\n `MetaMask Tx Signature: Unknown problem: ${JSON.stringify(\n finalMeta || transactionId,\n )}`,\n );\n\n resultCallbacks?.error(internalError);\n throw internalError;\n }\n }\n\n /**\n * Approves a transaction and updates it's status in state. If this is not a\n * retry transaction, a nonce will be generated. The transaction is signed\n * using the sign configuration property, then published to the blockchain.\n * A `<tx.id>:finished` hub event is fired after success or failure.\n *\n * @param transactionID - The ID of the transaction to approve.\n */\n private async approveTransaction(transactionID: string) {\n const { transactions } = this.state;\n const releaseLock = await this.mutex.acquire();\n const { providerConfig } = this.getNetworkState();\n const { chainId } = providerConfig;\n const index = transactions.findIndex(({ id }) => transactionID === id);\n const transactionMeta = transactions[index];\n const {\n transaction: { nonce, from },\n } = transactionMeta;\n let nonceLock;\n try {\n if (!this.sign) {\n releaseLock();\n this.failTransaction(\n transactionMeta,\n new Error('No sign method defined.'),\n );\n return;\n } else if (!chainId) {\n releaseLock();\n this.failTransaction(transactionMeta, new Error('No chainId defined.'));\n return;\n }\n\n const { approved: status } = TransactionStatus;\n let nonceToUse = nonce;\n // if a nonce already exists on the transactionMeta it means this is a speedup or cancel transaction\n // so we want to reuse that nonce and hope that it beats the previous attempt to chain. Otherwise use a new locked nonce\n if (!nonceToUse) {\n nonceLock = await this.nonceTracker.getNonceLock(from);\n nonceToUse = addHexPrefix(nonceLock.nextNonce.toString(16));\n }\n\n transactionMeta.status = status;\n transactionMeta.transaction.nonce = nonceToUse;\n transactionMeta.transaction.chainId = chainId;\n\n const baseTxParams = {\n ...transactionMeta.transaction,\n gasLimit: transactionMeta.transaction.gas,\n };\n\n const isEIP1559 = isEIP1559Transaction(transactionMeta.transaction);\n\n const txParams = isEIP1559\n ? {\n ...baseTxParams,\n maxFeePerGas: transactionMeta.transaction.maxFeePerGas,\n maxPriorityFeePerGas:\n transactionMeta.transaction.maxPriorityFeePerGas,\n estimatedBaseFee: transactionMeta.transaction.estimatedBaseFee,\n // specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set\n type: 2,\n }\n : baseTxParams;\n\n // delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set\n if (isEIP1559) {\n delete txParams.gasPrice;\n }\n\n const unsignedEthTx = this.prepareUnsignedEthTx(txParams);\n const signedTx = await this.sign(unsignedEthTx, from);\n transactionMeta.status = TransactionStatus.signed;\n this.updateTransaction(transactionMeta);\n const rawTransaction = bufferToHex(signedTx.serialize());\n\n transactionMeta.rawTransaction = rawTransaction;\n this.updateTransaction(transactionMeta);\n const transactionHash = await query(this.ethQuery, 'sendRawTransaction', [\n rawTransaction,\n ]);\n transactionMeta.transactionHash = transactionHash;\n transactionMeta.status = TransactionStatus.submitted;\n this.updateTransaction(transactionMeta);\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n } catch (error: any) {\n this.failTransaction(transactionMeta, error);\n } finally {\n // must set transaction to submitted/failed before releasing lock\n if (nonceLock) {\n nonceLock.releaseLock();\n }\n releaseLock();\n }\n }\n\n /**\n * Cancels a transaction based on its ID by setting its status to \"rejected\"\n * and emitting a `<tx.id>:finished` hub event.\n *\n * @param transactionID - The ID of the transaction to cancel.\n */\n private cancelTransaction(transactionID: string) {\n const transactionMeta = this.state.transactions.find(\n ({ id }) => id === transactionID,\n );\n if (!transactionMeta) {\n return;\n }\n transactionMeta.status = TransactionStatus.rejected;\n this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);\n const transactions = this.state.transactions.filter(\n ({ id }) => id !== transactionID,\n );\n this.update({ transactions: this.trimTransactionsForState(transactions) });\n }\n\n /**\n * Trim the amount of transactions that are set on the state. Checks\n * if the length of the tx history is longer then desired persistence\n * limit and then if it is removes the oldest confirmed or rejected tx.\n * Pending or unapproved transactions will not be removed by this\n * operation. For safety of presenting a fully functional transaction UI\n * representation, this function will not break apart transactions with the\n * same nonce, created on the same day, per network. Not accounting for transactions of the same\n * nonce, same day and network combo can result in confusing or broken experiences\n * in the UI. The transactions are then updated using the BaseController update.\n *\n * @param transactions - The transactions to be applied to the state.\n * @returns The trimmed list of transactions.\n */\n private trimTransactionsForState(\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const nonceNetworkSet = new Set();\n const txsToKeep = transactions.reverse().filter((tx) => {\n const { chainId, networkID, status, transaction, time } = tx;\n if (transaction) {\n const key = `${transaction.nonce}-${\n chainId ? convertHexToDecimal(chainId) : networkID\n }-${new Date(time).toDateString()}`;\n if (nonceNetworkSet.has(key)) {\n return true;\n } else if (\n nonceNetworkSet.size < this.config.txHistoryLimit ||\n !this.isFinalState(status)\n ) {\n nonceNetworkSet.add(key);\n return true;\n }\n }\n return false;\n });\n txsToKeep.reverse();\n return txsToKeep;\n }\n\n /**\n * Determines if the transaction is in a final state.\n *\n * @param status - The transaction status.\n * @returns Whether the transaction is in a final state.\n */\n private isFinalState(status: TransactionStatus): boolean {\n return (\n status === TransactionStatus.rejected ||\n status === TransactionStatus.confirmed ||\n status === TransactionStatus.failed ||\n status === TransactionStatus.cancelled\n );\n }\n\n /**\n * Whether the transaction has at least completed all local processing.\n *\n * @param status - The transaction status.\n * @returns Whether the transaction is in a final state.\n */\n private isLocalFinalState(status: TransactionStatus): boolean {\n return [\n TransactionStatus.cancelled,\n TransactionStatus.confirmed,\n TransactionStatus.failed,\n TransactionStatus.rejected,\n TransactionStatus.submitted,\n ].includes(status);\n }\n\n /**\n * Method to verify the state of a transaction using the Blockchain as a source of truth.\n *\n * @param meta - The local transaction to verify on the blockchain.\n * @returns A tuple containing the updated transaction, and whether or not an update was required.\n */\n private async blockchainTransactionStateReconciler(\n meta: TransactionMeta,\n ): Promise<[TransactionMeta, boolean]> {\n const { status, transactionHash } = meta;\n switch (status) {\n case TransactionStatus.confirmed:\n const txReceipt = await query(this.ethQuery, 'getTransactionReceipt', [\n transactionHash,\n ]);\n\n if (!txReceipt) {\n return [meta, false];\n }\n\n meta.verifiedOnBlockchain = true;\n meta.transaction.gasUsed = txReceipt.gasUsed;\n\n // According to the Web3 docs:\n // TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.\n if (Number(txReceipt.status) === 0) {\n const error: Error = new Error(\n 'Transaction failed. The transaction was reversed',\n );\n this.failTransaction(meta, error);\n return [meta, false];\n }\n\n return [meta, true];\n case TransactionStatus.submitted:\n const txObj = await query(this.ethQuery, 'getTransactionByHash', [\n transactionHash,\n ]);\n\n if (!txObj) {\n const receiptShowsFailedStatus =\n await this.checkTxReceiptStatusIsFailed(transactionHash);\n\n // Case the txObj is evaluated as false, a second check will\n // determine if the tx failed or it is pending or confirmed\n if (receiptShowsFailedStatus) {\n const error: Error = new Error(\n 'Transaction failed. The transaction was dropped or replaced by a new one',\n );\n this.failTransaction(meta, error);\n }\n }\n\n /* istanbul ignore next */\n if (txObj?.blockNumber) {\n meta.status = TransactionStatus.confirmed;\n this.hub.emit(`${meta.id}:confirmed`, meta);\n return [meta, true];\n }\n\n return [meta, false];\n default:\n return [meta, false];\n }\n }\n\n /**\n * Method to check if a tx has failed according to their receipt\n * According to the Web3 docs:\n * TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.\n * The receipt is not available for pending transactions and returns null.\n *\n * @param txHash - The transaction hash.\n * @returns Whether the transaction has failed.\n */\n private async checkTxReceiptStatusIsFailed(\n txHash: string | undefined,\n ): Promise<boolean> {\n const txReceipt = await query(this.ethQuery, 'getTransactionReceipt', [\n txHash,\n ]);\n if (!txReceipt) {\n // Transaction is pending\n return false;\n }\n return Number(txReceipt.status) === 0;\n }\n\n /**\n * Method to verify the state of transactions using Etherscan as a source of truth.\n *\n * @param remoteTxs - Transactions to reconcile that are from a remote source.\n * @param localTxs - Transactions to reconcile that are local.\n * @returns A tuple containing a boolean indicating whether or not an update was required, and the updated transaction.\n */\n private etherscanTransactionStateReconciler(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): [boolean, TransactionMeta[]] {\n const updatedTxs: TransactionMeta[] = this.getUpdatedTransactions(\n remoteTxs,\n localTxs,\n );\n\n const newTxs: TransactionMeta[] = this.getNewTransactions(\n remoteTxs,\n localTxs,\n );\n\n const updatedLocalTxs = localTxs.map((tx: TransactionMeta) => {\n const txIdx = updatedTxs.findIndex(\n ({ transactionHash }) => transactionHash === tx.transactionHash,\n );\n return txIdx === -1 ? tx : updatedTxs[txIdx];\n });\n\n const updateRequired = newTxs.length > 0 || updatedLocalTxs.length > 0;\n\n return [updateRequired, [...newTxs, ...updatedLocalTxs]];\n }\n\n /**\n * Get all transactions that are in the remote transactions array\n * but not in the local transactions array.\n *\n * @param remoteTxs - Array of transactions from remote source.\n * @param localTxs - Array of transactions stored locally.\n * @returns The new transactions.\n */\n private getNewTransactions(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): TransactionMeta[] {\n return remoteTxs.filter((tx) => {\n const alreadyInTransactions = localTxs.find(\n ({ transactionHash }) => transactionHash === tx.transactionHash,\n );\n return !alreadyInTransactions;\n });\n }\n\n /**\n * Get all the transactions that are locally outdated with respect\n * to a remote source (etherscan or blockchain). The returned array\n * contains the transactions with the updated data.\n *\n * @param remoteTxs - Array of transactions from remote source.\n * @param localTxs - Array of transactions stored locally.\n * @returns The updated transactions.\n */\n private getUpdatedTransactions(\n remoteTxs: TransactionMeta[],\n localTxs: TransactionMeta[],\n ): TransactionMeta[] {\n return remoteTxs.filter((remoteTx) => {\n const isTxOutdated = localTxs.find((localTx) => {\n return (\n remoteTx.transactionHash === localTx.transactionHash &&\n this.isTransactionOutdated(remoteTx, localTx)\n );\n });\n return isTxOutdated;\n });\n }\n\n /**\n * Verifies if a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteTx - The remote transaction from Etherscan.\n * @param localTx - The local transaction.\n * @returns Whether the transaction is outdated.\n */\n private isTransactionOutdated(\n remoteTx: TransactionMeta,\n localTx: TransactionMeta,\n ): boolean {\n const statusOutdated = this.isStatusOutdated(\n remoteTx.transactionHash,\n localTx.transactionHash,\n remoteTx.status,\n localTx.status,\n );\n const gasDataOutdated = this.isGasDataOutdated(\n remoteTx.transaction.gasUsed,\n localTx.transaction.gasUsed,\n );\n return statusOutdated || gasDataOutdated;\n }\n\n /**\n * Verifies if the status of a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteTxHash - Remote transaction hash.\n * @param localTxHash - Local transaction hash.\n * @param remoteTxStatus - Remote transaction status.\n * @param localTxStatus - Local transaction status.\n * @returns Whether the status is outdated.\n */\n private isStatusOutdated(\n remoteTxHash: string | undefined,\n localTxHash: string | undefined,\n remoteTxStatus: TransactionStatus,\n localTxStatus: TransactionStatus,\n ): boolean {\n return remoteTxHash === localTxHash && remoteTxStatus !== localTxStatus;\n }\n\n /**\n * Verifies if the gas data of a local transaction is outdated with respect to the remote transaction.\n *\n * @param remoteGasUsed - Remote gas used in the transaction.\n * @param localGasUsed - Local gas used in the transaction.\n * @returns Whether the gas data is outdated.\n */\n private isGasDataOutdated(\n remoteGasUsed: string | undefined,\n localGasUsed: string | undefined,\n ): boolean {\n return remoteGasUsed !== localGasUsed;\n }\n\n private async requestApproval(txMeta: TransactionMeta): Promise<AddResult> {\n const id = this.getApprovalId(txMeta);\n const { origin } = txMeta;\n const type = ApprovalType.Transaction;\n const requestData = { txId: txMeta.id };\n\n return (await this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin: origin || ORIGIN_METAMASK,\n type,\n requestData,\n expectsResult: true,\n },\n true,\n )) as Promise<AddResult>;\n }\n\n private getTransaction(transactionID: string): TransactionMeta | undefined {\n const { transactions } = this.state;\n return transactions.find(({ id }) => id === transactionID);\n }\n\n private getApprovalId(txMeta: TransactionMeta) {\n return String(txMeta.id);\n }\n\n private isTransactionCompleted(transactionid: string): {\n meta?: TransactionMeta;\n isCompleted: boolean;\n } {\n const transaction = this.getTransaction(transactionid);\n\n if (!transaction) {\n return { meta: undefined, isCompleted: false };\n }\n\n const isCompleted = this.isLocalFinalState(transaction.status);\n\n return { meta: transaction, isCompleted };\n }\n}\n\nexport default TransactionController;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/transaction-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@ethereumjs/common": "^2.6.1",
|
|
33
33
|
"@ethereumjs/tx": "^3.5.2",
|
|
34
|
-
"@metamask/approval-controller": "^3.
|
|
35
|
-
"@metamask/base-controller": "^3.
|
|
36
|
-
"@metamask/controller-utils": "^4.0
|
|
37
|
-
"@metamask/network-controller": "^10.
|
|
34
|
+
"@metamask/approval-controller": "^3.4.0",
|
|
35
|
+
"@metamask/base-controller": "^3.1.0",
|
|
36
|
+
"@metamask/controller-utils": "^4.2.0",
|
|
37
|
+
"@metamask/network-controller": "^10.3.1",
|
|
38
38
|
"@metamask/utils": "^5.0.2",
|
|
39
39
|
"async-mutex": "^0.2.6",
|
|
40
40
|
"babel-runtime": "^6.26.0",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"typescript": "~4.6.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@metamask/approval-controller": "^3.
|
|
63
|
-
"@metamask/network-controller": "^10.
|
|
62
|
+
"@metamask/approval-controller": "^3.4.0",
|
|
63
|
+
"@metamask/network-controller": "^10.3.1"
|
|
64
64
|
},
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": ">=16.0.0"
|