@metamask-previews/transaction-controller 16.0.0-preview.80566a6 → 17.0.0-preview.eb58a59
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 +42 -1
- package/dist/TransactionController.d.ts +44 -3
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +122 -33
- package/dist/TransactionController.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/types.d.ts +82 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/etherscan.d.ts.map +1 -1
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/gas.d.ts +2 -0
- package/dist/utils/gas.d.ts.map +1 -1
- package/dist/utils/gas.js +26 -17
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/swaps.d.ts.map +1 -1
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/utils.d.ts +11 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +18 -2
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +90 -7
- package/dist/utils/validation.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [17.0.0]
|
|
10
|
+
### Added
|
|
11
|
+
- **BREAKING:** Add additional support swaps support ([#1877](https://github.com/MetaMask/core/pull/1877))
|
|
12
|
+
- Swap transaction updates can be prevented by setting `disableSwaps` as `true`. If not set it will default to `false`.
|
|
13
|
+
- If `disableSwaps` is `false` or not set, then the `createSwapsTransaction` callback MUST be defined.
|
|
14
|
+
- Add optional hooks to support alternate flows ([#1787](https://github.com/MetaMask/core/pull/1787))
|
|
15
|
+
- Add the `getAdditionalSignArguments` hook to provide additional arguments when signing.
|
|
16
|
+
- Add the `beforeApproveOnInit` hook to execute additional logic before starting an approval flow for a transaction during initialization. Return `false` to skip the transaction.
|
|
17
|
+
- Add the `afterSign` hook to execute additional logic after signing a transaction. Return `false` to not change the `status` to `signed`.
|
|
18
|
+
- Add the `beforePublish` hook to execute additional logic before publishing a transaction. Return `false` to prevent the transaction being submitted.
|
|
19
|
+
- Add additional persisted transaction support during initialization and on network change ([#1916](https://github.com/MetaMask/core/pull/1916))
|
|
20
|
+
- Initialise approvals for unapproved transactions on the current network.
|
|
21
|
+
- Add missing gas values for unapproved transactions on the current network.
|
|
22
|
+
- Submit any approved transactions on the current network.
|
|
23
|
+
- Support saved gas fees ([#1966](https://github.com/MetaMask/core/pull/1966))
|
|
24
|
+
- Add optional `getSavedGasFees` callback to constructor.
|
|
25
|
+
- Add `updateCustodialTransaction` method to update custodial transactions ([#2018](https://github.com/MetaMask/core/pull/2018))
|
|
26
|
+
- Add `accessList` to txParam types ([#2016](https://github.com/MetaMask/core/pull/2016))
|
|
27
|
+
- Add `estimateGasBuffered` method to estimate gas and apply a specific buffer multiplier ([#2021](https://github.com/MetaMask/core/pull/2021))
|
|
28
|
+
- Add `updateSecurityAlertResponse` method ([#1985](https://github.com/MetaMask/core/pull/1985))
|
|
29
|
+
- Add gas values validation ([#1978](https://github.com/MetaMask/core/pull/1978))
|
|
30
|
+
- Add `approveTransactionsWithSameNonce` method ([#1961](https://github.com/MetaMask/core/pull/1961))
|
|
31
|
+
- Add `clearUnapprovedTransactions` method ([#1979](https://github.com/MetaMask/core/pull/1979))
|
|
32
|
+
- Add `updatePreviousGasParams` method ([#1943](https://github.com/MetaMask/core/pull/1943))
|
|
33
|
+
- Emit additional events to support metrics in the clients ([#1894](https://github.com/MetaMask/core/pull/1894))
|
|
34
|
+
- Populate the `firstRetryBlockNumber`, `retryCount`, and `warning` properties in the transaction metadata. ([#1896](https://github.com/MetaMask/core/pull/1896))
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- **BREAKING:** Pending transactions are now automatically resubmitted. ([#1896](https://github.com/MetaMask/core/pull/1896))
|
|
38
|
+
- This can be disabled by setting the new `pendingTransactions.isResubmitEnabled` constructor option to `false`.
|
|
39
|
+
- **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^16.0.0
|
|
40
|
+
- Persist specific error properties in core transaction metadata ([#1915](https://github.com/MetaMask/core/pull/1915))
|
|
41
|
+
- Create `TransactionError` type with explicit properties.
|
|
42
|
+
- Align core transaction error messages with extension ([#1980](https://github.com/MetaMask/core/pull/1980))
|
|
43
|
+
- Catch of the `initApprovals` method to skip logging when the error is `userRejectedRequest`.
|
|
44
|
+
- Create an additional transaction metadata entry when calling `stopTransaction` ([#1998](https://github.com/MetaMask/core/pull/1998))
|
|
45
|
+
- Bump dependency `@metamask/eth-query` from ^3.0.1 to ^4.0.0 ([#2028](https://github.com/MetaMask/core/pull/2028))
|
|
46
|
+
- Bump dependency and peer dependency on `@metamask/gas-fee-controller` to ^10.0.1
|
|
47
|
+
- Bump @metamask/utils from 8.1.0 to 8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
|
|
48
|
+
|
|
9
49
|
## [16.0.0]
|
|
10
50
|
### Changed
|
|
11
51
|
- **BREAKING:** Bump dependency and peer dependency on `@metamask/gas-fee-controller` to ^10.0.0
|
|
@@ -248,7 +288,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
248
288
|
|
|
249
289
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
250
290
|
|
|
251
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@
|
|
291
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@17.0.0...HEAD
|
|
292
|
+
[17.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@16.0.0...@metamask/transaction-controller@17.0.0
|
|
252
293
|
[16.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@15.0.0...@metamask/transaction-controller@16.0.0
|
|
253
294
|
[15.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@14.0.0...@metamask/transaction-controller@15.0.0
|
|
254
295
|
[14.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@13.0.0...@metamask/transaction-controller@14.0.0
|
|
@@ -9,8 +9,8 @@ import type { BlockTracker, NetworkState, Provider } from '@metamask/network-con
|
|
|
9
9
|
import type { Hex } from '@metamask/utils';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import type { NonceLock } from 'nonce-tracker/dist/NonceTracker';
|
|
12
|
-
import type { Events, SavedGasFees, SecurityProviderRequest, SendFlowHistoryEntry, TransactionParams, TransactionMeta, TransactionReceipt, WalletDevice } from './types';
|
|
13
|
-
import { TransactionType } from './types';
|
|
12
|
+
import type { Events, SavedGasFees, SecurityProviderRequest, SendFlowHistoryEntry, TransactionParams, TransactionMeta, TransactionReceipt, WalletDevice, SecurityAlertResponse } from './types';
|
|
13
|
+
import { TransactionType, TransactionStatus } from './types';
|
|
14
14
|
export declare const HARDFORK = Hardfork.London;
|
|
15
15
|
/**
|
|
16
16
|
* @type Result
|
|
@@ -234,7 +234,7 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
234
234
|
method?: string;
|
|
235
235
|
origin?: string;
|
|
236
236
|
requireApproval?: boolean | undefined;
|
|
237
|
-
securityAlertResponse?:
|
|
237
|
+
securityAlertResponse?: SecurityAlertResponse;
|
|
238
238
|
sendFlowHistory?: SendFlowHistoryEntry[];
|
|
239
239
|
swaps?: {
|
|
240
240
|
hasApproveTx?: boolean;
|
|
@@ -289,6 +289,23 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
289
289
|
};
|
|
290
290
|
} | undefined;
|
|
291
291
|
}>;
|
|
292
|
+
/**
|
|
293
|
+
* Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.
|
|
294
|
+
*
|
|
295
|
+
* @param transaction - The transaction params to estimate gas for.
|
|
296
|
+
* @param multiplier - The multiplier to use for the gas buffer.
|
|
297
|
+
*/
|
|
298
|
+
estimateGasBuffered(transaction: TransactionParams, multiplier: number): Promise<{
|
|
299
|
+
gas: string;
|
|
300
|
+
simulationFails: {
|
|
301
|
+
reason: any;
|
|
302
|
+
errorKey: any;
|
|
303
|
+
debug: {
|
|
304
|
+
blockNumber: string;
|
|
305
|
+
blockGasLimit: string;
|
|
306
|
+
};
|
|
307
|
+
} | undefined;
|
|
308
|
+
}>;
|
|
292
309
|
/**
|
|
293
310
|
* Updates an existing transaction in state.
|
|
294
311
|
*
|
|
@@ -296,6 +313,13 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
296
313
|
* @param note - A note or update reason to include in the transaction history.
|
|
297
314
|
*/
|
|
298
315
|
updateTransaction(transactionMeta: TransactionMeta, note: string): void;
|
|
316
|
+
/**
|
|
317
|
+
* Update the security alert response for a transaction.
|
|
318
|
+
*
|
|
319
|
+
* @param transactionId - ID of the transaction.
|
|
320
|
+
* @param securityAlertResponse - The new security alert response for the transaction.
|
|
321
|
+
*/
|
|
322
|
+
updateSecurityAlertResponse(transactionId: string, securityAlertResponse: SecurityAlertResponse): void;
|
|
299
323
|
/**
|
|
300
324
|
* Removes all transactions from state, optionally based on the current network.
|
|
301
325
|
*
|
|
@@ -385,11 +409,28 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
385
409
|
* @returns The raw transactions.
|
|
386
410
|
*/
|
|
387
411
|
approveTransactionsWithSameNonce(listOfTxParams?: TransactionParams[]): Promise<string | string[]>;
|
|
412
|
+
/**
|
|
413
|
+
* Update a custodial transaction.
|
|
414
|
+
*
|
|
415
|
+
* @param transactionId - The ID of the transaction to update.
|
|
416
|
+
* @param options - The custodial transaction options to update.
|
|
417
|
+
* @param options.custodyStatus - The new custody status value to be assigned.
|
|
418
|
+
* @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
|
|
419
|
+
* @param options.hash - The new hash value to be assigned.
|
|
420
|
+
* @param options.status - The new status value to be assigned.
|
|
421
|
+
*/
|
|
422
|
+
updateCustodialTransaction(transactionId: string, { custodyStatus, errorMessage, hash, status, }: {
|
|
423
|
+
custodyStatus?: string;
|
|
424
|
+
errorMessage?: string;
|
|
425
|
+
hash?: string;
|
|
426
|
+
status?: TransactionStatus;
|
|
427
|
+
}): void;
|
|
388
428
|
private signExternalTransaction;
|
|
389
429
|
/**
|
|
390
430
|
* Removes unapproved transactions from state.
|
|
391
431
|
*/
|
|
392
432
|
clearUnapprovedTransactions(): void;
|
|
433
|
+
private addMetadata;
|
|
393
434
|
private updateGasProperties;
|
|
394
435
|
private getCurrentChainTransactionsByStatus;
|
|
395
436
|
private onBootCleanup;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAU3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAA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O,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,oBAAoB;IAO5B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAsB9B,OAAO,CAAC,sBAAsB;IAyB9B,OAAO,CAAC,gCAAgC;IAaxC,OAAO,CAAC,4BAA4B;IAsCpC;;;;OAIG;YACW,sBAAsB;IAmCpC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IA8BlC;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAWnC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;YAMpB,0BAA0B;IAUxC;;;;;;OAMG;YACW,wBAAwB;YAiBxB,uBAAuB;IAWrC,OAAO,CAAC,qCAAqC;YAyB/B,eAAe;CAsC9B;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -116,7 +116,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
116
116
|
this.provider = provider;
|
|
117
117
|
this.messagingSystem = messenger;
|
|
118
118
|
this.getNetworkState = getNetworkState;
|
|
119
|
-
// @ts-expect-error TODO: Provider type alignment
|
|
120
119
|
this.ethQuery = new eth_query_1.default(provider);
|
|
121
120
|
this.isSendFlowHistoryDisabled = disableSendFlowHistory !== null && disableSendFlowHistory !== void 0 ? disableSendFlowHistory : false;
|
|
122
121
|
this.isHistoryDisabled = disableHistory !== null && disableHistory !== void 0 ? disableHistory : false;
|
|
@@ -179,7 +178,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
179
178
|
});
|
|
180
179
|
this.addPendingTransactionTrackerListeners();
|
|
181
180
|
onNetworkStateChange(() => {
|
|
182
|
-
// @ts-expect-error TODO: Provider type alignment
|
|
183
181
|
this.ethQuery = new eth_query_1.default(this.provider);
|
|
184
182
|
this.registry = new eth_method_registry_1.default({ provider: this.provider });
|
|
185
183
|
this.onBootCleanup();
|
|
@@ -187,7 +185,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
187
185
|
this.onBootCleanup();
|
|
188
186
|
}
|
|
189
187
|
failTransaction(transactionMeta, error, actionId) {
|
|
190
|
-
const newTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { error, status: types_1.TransactionStatus.failed });
|
|
188
|
+
const newTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { error: (0, utils_1.normalizeTxError)(error), status: types_1.TransactionStatus.failed });
|
|
191
189
|
this.hub.emit('transaction-failed', {
|
|
192
190
|
actionId,
|
|
193
191
|
error: error.message,
|
|
@@ -252,7 +250,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
252
250
|
addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, } = {}) {
|
|
253
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
252
|
const chainId = this.getChainId();
|
|
255
|
-
const { transactions } = this.state;
|
|
256
253
|
txParams = (0, utils_1.normalizeTxParams)(txParams);
|
|
257
254
|
const isEIP1559Compatible = yield this.getEIP1559Compatibility();
|
|
258
255
|
(0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
|
|
@@ -299,10 +296,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
299
296
|
cancelTransaction: this.cancelTransaction.bind(this),
|
|
300
297
|
controllerHubEmitter: this.hub.emit.bind(this.hub),
|
|
301
298
|
});
|
|
302
|
-
|
|
303
|
-
this.update({
|
|
304
|
-
transactions: this.trimTransactionsForState(transactions),
|
|
305
|
-
});
|
|
299
|
+
this.addMetadata(transactionMeta);
|
|
306
300
|
this.hub.emit(`unapprovedTransaction`, transactionMeta);
|
|
307
301
|
}
|
|
308
302
|
return {
|
|
@@ -339,10 +333,14 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
339
333
|
stopTransaction(transactionId, gasValues, { estimatedBaseFee, actionId, } = {}) {
|
|
340
334
|
var _a, _b;
|
|
341
335
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
// If transaction is found for same action id, do not create a cancel transaction.
|
|
337
|
+
if (this.getTransactionWithActionId(actionId)) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
342
340
|
if (gasValues) {
|
|
343
341
|
(0, utils_1.validateGasValues)(gasValues);
|
|
344
342
|
}
|
|
345
|
-
const transactionMeta = this.
|
|
343
|
+
const transactionMeta = this.getTransaction(transactionId);
|
|
346
344
|
if (!transactionMeta) {
|
|
347
345
|
return;
|
|
348
346
|
}
|
|
@@ -369,7 +367,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
369
367
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
370
368
|
(0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
|
|
371
369
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
372
|
-
const
|
|
370
|
+
const newTxParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
373
371
|
? {
|
|
374
372
|
from: transactionMeta.txParams.from,
|
|
375
373
|
gasLimit: transactionMeta.txParams.gas,
|
|
@@ -388,17 +386,33 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
388
386
|
to: transactionMeta.txParams.from,
|
|
389
387
|
value: '0x0',
|
|
390
388
|
};
|
|
391
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(
|
|
389
|
+
const unsignedEthTx = this.prepareUnsignedEthTx(newTxParams);
|
|
392
390
|
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
|
|
393
|
-
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
394
391
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
395
|
-
yield
|
|
396
|
-
|
|
397
|
-
|
|
392
|
+
const hash = yield this.publishTransaction(rawTx);
|
|
393
|
+
const cancelTransactionMeta = {
|
|
394
|
+
actionId,
|
|
395
|
+
chainId: transactionMeta.chainId,
|
|
396
|
+
estimatedBaseFee,
|
|
397
|
+
hash,
|
|
398
|
+
id: (0, uuid_1.v1)(),
|
|
399
|
+
originalGasEstimate: transactionMeta.txParams.gas,
|
|
400
|
+
status: types_1.TransactionStatus.submitted,
|
|
401
|
+
time: Date.now(),
|
|
402
|
+
type: types_1.TransactionType.cancel,
|
|
403
|
+
txParams: newTxParams,
|
|
404
|
+
};
|
|
405
|
+
this.addMetadata(cancelTransactionMeta);
|
|
398
406
|
// stopTransaction has no approval request, so we assume the user has already approved the transaction
|
|
399
|
-
this.hub.emit('transaction-approved', {
|
|
400
|
-
|
|
401
|
-
|
|
407
|
+
this.hub.emit('transaction-approved', {
|
|
408
|
+
transactionMeta: cancelTransactionMeta,
|
|
409
|
+
actionId,
|
|
410
|
+
});
|
|
411
|
+
this.hub.emit('transaction-submitted', {
|
|
412
|
+
transactionMeta: cancelTransactionMeta,
|
|
413
|
+
actionId,
|
|
414
|
+
});
|
|
415
|
+
this.hub.emit(`${cancelTransactionMeta.id}:finished`, cancelTransactionMeta);
|
|
402
416
|
});
|
|
403
417
|
}
|
|
404
418
|
/**
|
|
@@ -429,7 +443,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
429
443
|
if (!this.sign) {
|
|
430
444
|
throw new Error('No sign method defined.');
|
|
431
445
|
}
|
|
432
|
-
const { transactions } = this.state;
|
|
433
446
|
// gasPrice (legacy non EIP1559)
|
|
434
447
|
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.SPEED_UP_RATE);
|
|
435
448
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
@@ -458,11 +471,10 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
458
471
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
459
472
|
const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
460
473
|
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
|
|
461
|
-
actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry });
|
|
474
|
+
actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry, originalType: transactionMeta.type });
|
|
462
475
|
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
463
476
|
? Object.assign(Object.assign({}, baseTransactionMeta), { txParams: Object.assign(Object.assign({}, transactionMeta.txParams), { maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas }) }) : Object.assign(Object.assign({}, baseTransactionMeta), { txParams: Object.assign(Object.assign({}, transactionMeta.txParams), { gasPrice: newGasPrice }) });
|
|
464
|
-
|
|
465
|
-
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
477
|
+
this.addMetadata(newTransactionMeta);
|
|
466
478
|
// speedUpTransaction has no approval request, so we assume the user has already approved the transaction
|
|
467
479
|
this.hub.emit('transaction-approved', {
|
|
468
480
|
transactionMeta: newTransactionMeta,
|
|
@@ -487,6 +499,22 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
487
499
|
return { gas: estimatedGas, simulationFails };
|
|
488
500
|
});
|
|
489
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.
|
|
504
|
+
*
|
|
505
|
+
* @param transaction - The transaction params to estimate gas for.
|
|
506
|
+
* @param multiplier - The multiplier to use for the gas buffer.
|
|
507
|
+
*/
|
|
508
|
+
estimateGasBuffered(transaction, multiplier) {
|
|
509
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
510
|
+
const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
|
|
511
|
+
const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
|
|
512
|
+
return {
|
|
513
|
+
gas,
|
|
514
|
+
simulationFails,
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
}
|
|
490
518
|
/**
|
|
491
519
|
* Updates an existing transaction in state.
|
|
492
520
|
*
|
|
@@ -504,6 +532,23 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
504
532
|
transactions[index] = transactionMeta;
|
|
505
533
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
506
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* Update the security alert response for a transaction.
|
|
537
|
+
*
|
|
538
|
+
* @param transactionId - ID of the transaction.
|
|
539
|
+
* @param securityAlertResponse - The new security alert response for the transaction.
|
|
540
|
+
*/
|
|
541
|
+
updateSecurityAlertResponse(transactionId, securityAlertResponse) {
|
|
542
|
+
if (!securityAlertResponse) {
|
|
543
|
+
throw new Error('updateSecurityAlertResponse: securityAlertResponse should not be null');
|
|
544
|
+
}
|
|
545
|
+
const transactionMeta = this.getTransaction(transactionId);
|
|
546
|
+
if (!transactionMeta) {
|
|
547
|
+
throw new Error(`Cannot update security alert response as no transaction metadata found`);
|
|
548
|
+
}
|
|
549
|
+
const updatedMeta = (0, lodash_1.merge)(transactionMeta, { securityAlertResponse });
|
|
550
|
+
this.updateTransaction(updatedMeta, 'TransactionController:updatesecurityAlertResponse - securityAlertResponse updated');
|
|
551
|
+
}
|
|
507
552
|
/**
|
|
508
553
|
* Removes all transactions from state, optionally based on the current network.
|
|
509
554
|
*
|
|
@@ -751,17 +796,62 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
751
796
|
return rawTransactions;
|
|
752
797
|
});
|
|
753
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Update a custodial transaction.
|
|
801
|
+
*
|
|
802
|
+
* @param transactionId - The ID of the transaction to update.
|
|
803
|
+
* @param options - The custodial transaction options to update.
|
|
804
|
+
* @param options.custodyStatus - The new custody status value to be assigned.
|
|
805
|
+
* @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
|
|
806
|
+
* @param options.hash - The new hash value to be assigned.
|
|
807
|
+
* @param options.status - The new status value to be assigned.
|
|
808
|
+
*/
|
|
809
|
+
updateCustodialTransaction(transactionId, { custodyStatus, errorMessage, hash, status, }) {
|
|
810
|
+
let transactionMeta;
|
|
811
|
+
transactionMeta = this.getTransaction(transactionId);
|
|
812
|
+
if (!transactionMeta) {
|
|
813
|
+
throw new Error(`Cannot update custodial transaction as no transaction metadata found`);
|
|
814
|
+
}
|
|
815
|
+
if (!transactionMeta.custodyId) {
|
|
816
|
+
throw new Error('Transaction must be a custodian transaction');
|
|
817
|
+
}
|
|
818
|
+
if (status &&
|
|
819
|
+
![
|
|
820
|
+
types_1.TransactionStatus.submitted,
|
|
821
|
+
types_1.TransactionStatus.signed,
|
|
822
|
+
types_1.TransactionStatus.failed,
|
|
823
|
+
].includes(status)) {
|
|
824
|
+
throw new Error(`Cannot update custodial transaction with status: ${status}`);
|
|
825
|
+
}
|
|
826
|
+
if (status === types_1.TransactionStatus.signed) {
|
|
827
|
+
transactionMeta.status = status;
|
|
828
|
+
}
|
|
829
|
+
if (status === types_1.TransactionStatus.submitted) {
|
|
830
|
+
transactionMeta.submittedTime = new Date().getTime();
|
|
831
|
+
transactionMeta.status = status;
|
|
832
|
+
}
|
|
833
|
+
if (status === types_1.TransactionStatus.failed) {
|
|
834
|
+
transactionMeta = Object.assign(Object.assign({}, transactionMeta), { error: (0, utils_1.normalizeTxError)(new Error(errorMessage)), status: types_1.TransactionStatus.failed });
|
|
835
|
+
}
|
|
836
|
+
if (custodyStatus) {
|
|
837
|
+
transactionMeta.custodyStatus = custodyStatus;
|
|
838
|
+
}
|
|
839
|
+
if (hash) {
|
|
840
|
+
transactionMeta.hash = hash;
|
|
841
|
+
}
|
|
842
|
+
this.updateTransaction(transactionMeta, `TransactionController:updateCustodialTransaction - Custodial transaction updated`);
|
|
843
|
+
}
|
|
754
844
|
signExternalTransaction(transactionParams) {
|
|
755
845
|
return __awaiter(this, void 0, void 0, function* () {
|
|
756
846
|
if (!this.sign) {
|
|
757
847
|
throw new Error('No sign method defined.');
|
|
758
848
|
}
|
|
759
|
-
const
|
|
849
|
+
const normalizedTransactionParams = (0, utils_1.normalizeTxParams)(transactionParams);
|
|
760
850
|
const chainId = this.getChainId();
|
|
761
|
-
const type = (0, utils_1.isEIP1559Transaction)(
|
|
851
|
+
const type = (0, utils_1.isEIP1559Transaction)(normalizedTransactionParams)
|
|
762
852
|
? types_1.TransactionEnvelopeType.feeMarket
|
|
763
853
|
: types_1.TransactionEnvelopeType.legacy;
|
|
764
|
-
const updatedTransactionParams = Object.assign(Object.assign({},
|
|
854
|
+
const updatedTransactionParams = Object.assign(Object.assign({}, normalizedTransactionParams), { type, gasLimit: normalizedTransactionParams.gas, chainId });
|
|
765
855
|
const { from } = updatedTransactionParams;
|
|
766
856
|
const common = this.getCommonConfiguration();
|
|
767
857
|
const unsignedTransaction = tx_1.TransactionFactory.fromTxData(updatedTransactionParams, { common });
|
|
@@ -777,6 +867,11 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
777
867
|
const transactions = this.state.transactions.filter(({ status }) => status !== types_1.TransactionStatus.unapproved);
|
|
778
868
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
779
869
|
}
|
|
870
|
+
addMetadata(transactionMeta) {
|
|
871
|
+
const { transactions } = this.state;
|
|
872
|
+
transactions.push(transactionMeta);
|
|
873
|
+
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
874
|
+
}
|
|
780
875
|
updateGasProperties(transactionMeta) {
|
|
781
876
|
return __awaiter(this, void 0, void 0, function* () {
|
|
782
877
|
const isEIP1559Compatible = yield this.getEIP1559Compatibility();
|
|
@@ -886,7 +981,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
886
981
|
if (!isTxCompleted) {
|
|
887
982
|
if ((error === null || error === void 0 ? void 0 : error.code) === rpc_errors_1.errorCodes.provider.userRejectedRequest) {
|
|
888
983
|
this.cancelTransaction(transactionId, actionId);
|
|
889
|
-
throw rpc_errors_1.providerErrors.userRejectedRequest('User
|
|
984
|
+
throw rpc_errors_1.providerErrors.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.');
|
|
890
985
|
}
|
|
891
986
|
else {
|
|
892
987
|
this.failTransaction(meta, error, actionId);
|
|
@@ -899,10 +994,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
899
994
|
case types_1.TransactionStatus.failed:
|
|
900
995
|
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(finalMeta.error);
|
|
901
996
|
throw rpc_errors_1.rpcErrors.internal(finalMeta.error.message);
|
|
902
|
-
case types_1.TransactionStatus.cancelled:
|
|
903
|
-
const cancelError = rpc_errors_1.rpcErrors.internal('User cancelled the transaction');
|
|
904
|
-
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(cancelError);
|
|
905
|
-
throw cancelError;
|
|
906
997
|
case types_1.TransactionStatus.submitted:
|
|
907
998
|
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.success();
|
|
908
999
|
return finalMeta.hash;
|
|
@@ -1069,8 +1160,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1069
1160
|
isFinalState(status) {
|
|
1070
1161
|
return (status === types_1.TransactionStatus.rejected ||
|
|
1071
1162
|
status === types_1.TransactionStatus.confirmed ||
|
|
1072
|
-
status === types_1.TransactionStatus.failed
|
|
1073
|
-
status === types_1.TransactionStatus.cancelled);
|
|
1163
|
+
status === types_1.TransactionStatus.failed);
|
|
1074
1164
|
}
|
|
1075
1165
|
/**
|
|
1076
1166
|
* Whether the transaction has at least completed all local processing.
|
|
@@ -1080,7 +1170,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1080
1170
|
*/
|
|
1081
1171
|
isLocalFinalState(status) {
|
|
1082
1172
|
return [
|
|
1083
|
-
types_1.TransactionStatus.cancelled,
|
|
1084
1173
|
types_1.TransactionStatus.confirmed,
|
|
1085
1174
|
types_1.TransactionStatus.failed,
|
|
1086
1175
|
types_1.TransactionStatus.rejected,
|