@metamask/transaction-controller 45.1.0 → 47.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -1
- package/dist/TransactionController.cjs +152 -43
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts +88 -72
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts +88 -72
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +151 -42
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/api/accounts-api.cjs +2 -0
- package/dist/api/accounts-api.cjs.map +1 -1
- package/dist/api/accounts-api.d.cts +2 -0
- package/dist/api/accounts-api.d.cts.map +1 -1
- package/dist/api/accounts-api.d.mts +2 -0
- package/dist/api/accounts-api.d.mts.map +1 -1
- package/dist/api/accounts-api.mjs +2 -0
- package/dist/api/accounts-api.mjs.map +1 -1
- package/dist/constants.cjs +20 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +15 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +15 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +19 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +1 -0
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +1 -0
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +1 -0
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +1 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/dist/helpers/MethodDataHelper.cjs.map +1 -1
- package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
- package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
- package/dist/helpers/MethodDataHelper.mjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.cjs +1 -21
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +1 -21
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/{utils/resimulate.cjs → helpers/ResimulateHelper.cjs} +93 -4
- package/dist/helpers/ResimulateHelper.cjs.map +1 -0
- package/dist/{utils/resimulate.d.cts → helpers/ResimulateHelper.d.cts} +13 -1
- package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
- package/dist/{utils/resimulate.d.mts → helpers/ResimulateHelper.d.mts} +13 -1
- package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
- package/dist/{utils/resimulate.mjs → helpers/ResimulateHelper.mjs} +93 -5
- package/dist/helpers/ResimulateHelper.mjs.map +1 -0
- package/dist/helpers/TransactionPoller.cjs +2 -0
- package/dist/helpers/TransactionPoller.cjs.map +1 -1
- package/dist/helpers/TransactionPoller.d.cts +2 -0
- package/dist/helpers/TransactionPoller.d.cts.map +1 -1
- package/dist/helpers/TransactionPoller.d.mts +2 -0
- package/dist/helpers/TransactionPoller.d.mts.map +1 -1
- package/dist/helpers/TransactionPoller.mjs +2 -0
- package/dist/helpers/TransactionPoller.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +5 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +55 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +55 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +5 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/batch.cjs +89 -0
- package/dist/utils/batch.cjs.map +1 -0
- package/dist/utils/batch.d.cts +33 -0
- package/dist/utils/batch.d.cts.map +1 -0
- package/dist/utils/batch.d.mts +33 -0
- package/dist/utils/batch.d.mts.map +1 -0
- package/dist/utils/batch.mjs +84 -0
- package/dist/utils/batch.mjs.map +1 -0
- package/dist/utils/eip7702.cjs +84 -2
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts +35 -10
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts +35 -10
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs +82 -3
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +53 -0
- package/dist/utils/feature-flags.cjs.map +1 -0
- package/dist/utils/feature-flags.d.cts +39 -0
- package/dist/utils/feature-flags.d.cts.map +1 -0
- package/dist/utils/feature-flags.d.mts +39 -0
- package/dist/utils/feature-flags.d.mts.map +1 -0
- package/dist/utils/feature-flags.mjs +47 -0
- package/dist/utils/feature-flags.mjs.map +1 -0
- package/dist/utils/gas-fees.cjs +48 -3
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts +11 -0
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts +11 -0
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +48 -3
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas-flow.cjs +4 -0
- package/dist/utils/gas-flow.cjs.map +1 -1
- package/dist/utils/gas-flow.d.cts +1 -0
- package/dist/utils/gas-flow.d.cts.map +1 -1
- package/dist/utils/gas-flow.d.mts +1 -0
- package/dist/utils/gas-flow.d.mts.map +1 -1
- package/dist/utils/gas-flow.mjs +4 -0
- package/dist/utils/gas-flow.mjs.map +1 -1
- package/dist/utils/gas.cjs +50 -1
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +22 -0
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +22 -0
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +50 -1
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +5 -1
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts +4 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts +4 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.mjs +5 -1
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/retry.cjs +4 -0
- package/dist/utils/retry.cjs.map +1 -1
- package/dist/utils/retry.d.cts +1 -0
- package/dist/utils/retry.d.cts.map +1 -1
- package/dist/utils/retry.d.mts +1 -0
- package/dist/utils/retry.d.mts.map +1 -1
- package/dist/utils/retry.mjs +4 -0
- package/dist/utils/retry.mjs.map +1 -1
- package/dist/utils/simulation-api.cjs +6 -0
- package/dist/utils/simulation-api.cjs.map +1 -1
- package/dist/utils/simulation-api.d.cts +2 -0
- package/dist/utils/simulation-api.d.cts.map +1 -1
- package/dist/utils/simulation-api.d.mts +2 -0
- package/dist/utils/simulation-api.d.mts.map +1 -1
- package/dist/utils/simulation-api.mjs +6 -0
- package/dist/utils/simulation-api.mjs.map +1 -1
- package/dist/utils/simulation.cjs +19 -5
- package/dist/utils/simulation.cjs.map +1 -1
- package/dist/utils/simulation.d.cts +3 -1
- package/dist/utils/simulation.d.cts.map +1 -1
- package/dist/utils/simulation.d.mts +3 -1
- package/dist/utils/simulation.d.mts.map +1 -1
- package/dist/utils/simulation.mjs +19 -5
- package/dist/utils/simulation.mjs.map +1 -1
- package/dist/utils/swaps.cjs +2 -1
- package/dist/utils/swaps.cjs.map +1 -1
- package/dist/utils/swaps.d.cts +1 -0
- package/dist/utils/swaps.d.cts.map +1 -1
- package/dist/utils/swaps.d.mts +1 -0
- package/dist/utils/swaps.d.mts.map +1 -1
- package/dist/utils/swaps.mjs +2 -1
- package/dist/utils/swaps.mjs.map +1 -1
- package/dist/utils/transaction-type.cjs +3 -1
- package/dist/utils/transaction-type.cjs.map +1 -1
- package/dist/utils/transaction-type.mjs +3 -1
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/dist/utils/validation.cjs +34 -5
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.cts +19 -3
- package/dist/utils/validation.d.cts.map +1 -1
- package/dist/utils/validation.d.mts +19 -3
- package/dist/utils/validation.d.mts.map +1 -1
- package/dist/utils/validation.mjs +33 -5
- package/dist/utils/validation.mjs.map +1 -1
- package/package.json +7 -5
- package/dist/utils/resimulate.cjs.map +0 -1
- package/dist/utils/resimulate.d.cts.map +0 -1
- package/dist/utils/resimulate.d.mts.map +0 -1
- package/dist/utils/resimulate.mjs.map +0 -1
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionChainIds, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_updateSubmitHistory;
|
|
12
|
+
var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionChainIds, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_getInternalAccounts, _TransactionController_updateSubmitHistory, _TransactionController_updateGasEstimate;
|
|
13
13
|
function $importDefault(module) {
|
|
14
14
|
if (module?.__esModule) {
|
|
15
15
|
return module.default;
|
|
@@ -43,9 +43,11 @@ import { IncomingTransactionHelper } from "./helpers/IncomingTransactionHelper.m
|
|
|
43
43
|
import { MethodDataHelper } from "./helpers/MethodDataHelper.mjs";
|
|
44
44
|
import { MultichainTrackingHelper } from "./helpers/MultichainTrackingHelper.mjs";
|
|
45
45
|
import { PendingTransactionTracker } from "./helpers/PendingTransactionTracker.mjs";
|
|
46
|
+
import { ResimulateHelper, hasSimulationDataChanged, shouldResimulate } from "./helpers/ResimulateHelper.mjs";
|
|
46
47
|
import { projectLogger as log } from "./logger.mjs";
|
|
47
48
|
import { TransactionEnvelopeType, TransactionType, TransactionStatus, SimulationErrorCode } from "./types.mjs";
|
|
48
|
-
import {
|
|
49
|
+
import { addTransactionBatch, isAtomicBatchSupported } from "./utils/batch.mjs";
|
|
50
|
+
import { generateEIP7702BatchTransaction, signAuthorizationList } from "./utils/eip7702.mjs";
|
|
49
51
|
import { validateConfirmedExternalTransaction } from "./utils/external-transactions.mjs";
|
|
50
52
|
import { addGasBuffer, estimateGas, updateGas } from "./utils/gas.mjs";
|
|
51
53
|
import { updateGasFees } from "./utils/gas-fees.mjs";
|
|
@@ -54,7 +56,6 @@ import { addInitialHistorySnapshot, updateTransactionHistory } from "./utils/his
|
|
|
54
56
|
import { getTransactionLayer1GasFee, updateTransactionLayer1GasFee } from "./utils/layer1-gas-fee-flow.mjs";
|
|
55
57
|
import { getAndFormatTransactionsForNonceTracker, getNextNonce } from "./utils/nonce.mjs";
|
|
56
58
|
import { prepareTransaction, serializeTransaction } from "./utils/prepare.mjs";
|
|
57
|
-
import { hasSimulationDataChanged, shouldResimulate } from "./utils/resimulate.mjs";
|
|
58
59
|
import { getTransactionParamsWithIncreasedGasFee } from "./utils/retry.mjs";
|
|
59
60
|
import { getSimulationData } from "./utils/simulation.mjs";
|
|
60
61
|
import { updatePostTransactionBalance, updateSwapsTransaction } from "./utils/swaps.mjs";
|
|
@@ -155,31 +156,9 @@ export class TransactionController extends BaseController {
|
|
|
155
156
|
* Constructs a TransactionController.
|
|
156
157
|
*
|
|
157
158
|
* @param options - The controller options.
|
|
158
|
-
* @param options.disableHistory - Whether to disable storing history in transaction metadata.
|
|
159
|
-
* @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
|
|
160
|
-
* @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
|
|
161
|
-
* @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
|
|
162
|
-
* @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
|
|
163
|
-
* @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
|
|
164
|
-
* @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
|
|
165
|
-
* @param options.getNetworkClientRegistry - Gets the network client registry.
|
|
166
|
-
* @param options.getNetworkState - Gets the state of the network controller.
|
|
167
|
-
* @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
|
|
168
|
-
* @param options.getSavedGasFees - Gets the saved gas fee config.
|
|
169
|
-
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
170
|
-
* @param options.isFirstTimeInteractionEnabled - Whether first time interaction checks are enabled.
|
|
171
|
-
* @param options.isSimulationEnabled - Whether new transactions will be automatically simulated.
|
|
172
|
-
* @param options.messenger - The controller messenger.
|
|
173
|
-
* @param options.pendingTransactions - Configuration options for pending transaction support.
|
|
174
|
-
* @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
|
|
175
|
-
* @param options.sign - Function used to sign transactions.
|
|
176
|
-
* @param options.state - Initial state to set on this controller.
|
|
177
|
-
* @param options.testGasFeeFlows - Whether to use the test gas fee flow.
|
|
178
|
-
* @param options.trace - Callback to generate trace information.
|
|
179
|
-
* @param options.transactionHistoryLimit - Transaction history limit.
|
|
180
|
-
* @param options.hooks - The controller hooks.
|
|
181
159
|
*/
|
|
182
|
-
constructor(
|
|
160
|
+
constructor(options) {
|
|
161
|
+
const { disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, } = options;
|
|
183
162
|
super({
|
|
184
163
|
name: controllerName,
|
|
185
164
|
metadata,
|
|
@@ -304,6 +283,13 @@ export class TransactionController extends BaseController {
|
|
|
304
283
|
// when transactionsController state changes
|
|
305
284
|
// check for pending transactions and start polling if there are any
|
|
306
285
|
this.messagingSystem.subscribe('TransactionController:stateChange', __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
|
|
286
|
+
new ResimulateHelper({
|
|
287
|
+
simulateTransaction: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateSimulationData).bind(this),
|
|
288
|
+
onTransactionsUpdate: (listener) => {
|
|
289
|
+
this.messagingSystem.subscribe('TransactionController:stateChange', listener, (controllerState) => controllerState.transactions);
|
|
290
|
+
},
|
|
291
|
+
getTransactions: () => this.state.transactions,
|
|
292
|
+
});
|
|
307
293
|
this.onBootCleanup();
|
|
308
294
|
__classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f").call(this);
|
|
309
295
|
}
|
|
@@ -323,6 +309,35 @@ export class TransactionController extends BaseController {
|
|
|
323
309
|
async handleMethodData(fourBytePrefix, networkClientId) {
|
|
324
310
|
return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
|
|
325
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Add a batch of transactions to be submitted after approval.
|
|
314
|
+
*
|
|
315
|
+
* @param request - Request object containing the transactions to add.
|
|
316
|
+
* @returns Result object containing the generated batch ID.
|
|
317
|
+
*/
|
|
318
|
+
async addTransactionBatch(request) {
|
|
319
|
+
return await addTransactionBatch({
|
|
320
|
+
addTransaction: this.addTransaction.bind(this),
|
|
321
|
+
getChainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).bind(this),
|
|
322
|
+
getEthQuery: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId }),
|
|
323
|
+
getInternalAccounts: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).bind(this),
|
|
324
|
+
messenger: this.messagingSystem,
|
|
325
|
+
request,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Determine which chains support atomic batch transactions with the given account address.
|
|
330
|
+
*
|
|
331
|
+
* @param address - The address of the account to check.
|
|
332
|
+
* @returns The supported chain IDs.
|
|
333
|
+
*/
|
|
334
|
+
async isAtomicBatchSupported(address) {
|
|
335
|
+
return isAtomicBatchSupported({
|
|
336
|
+
address,
|
|
337
|
+
getEthQuery: (chainId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { chainId }),
|
|
338
|
+
messenger: this.messagingSystem,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
326
341
|
/**
|
|
327
342
|
* Add a new unapproved transaction to state. Parameters will be validated, a
|
|
328
343
|
* unique transaction id will be generated, and gas and gasPrice will be calculated
|
|
@@ -333,6 +348,7 @@ export class TransactionController extends BaseController {
|
|
|
333
348
|
* @param options.actionId - Unique ID to prevent duplicate requests.
|
|
334
349
|
* @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
335
350
|
* @param options.method - RPC method that requested the transaction.
|
|
351
|
+
* @param options.nestedTransactions - Params for any nested transactions encoded in the data.
|
|
336
352
|
* @param options.origin - The origin of the transaction request, such as a dApp hostname.
|
|
337
353
|
* @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
338
354
|
* @param options.securityAlertResponse - Response from security validator.
|
|
@@ -347,7 +363,7 @@ export class TransactionController extends BaseController {
|
|
|
347
363
|
*/
|
|
348
364
|
async addTransaction(txParams, options) {
|
|
349
365
|
log('Adding transaction', txParams, options);
|
|
350
|
-
const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
|
|
366
|
+
const { actionId, deviceConfirmedOn, method, nestedTransactions, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
|
|
351
367
|
txParams = normalizeTransactionParams(txParams);
|
|
352
368
|
if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
|
|
353
369
|
throw new Error(`Network client not found - ${networkClientId}`);
|
|
@@ -356,12 +372,15 @@ export class TransactionController extends BaseController {
|
|
|
356
372
|
? undefined
|
|
357
373
|
: await this.getPermittedAccounts?.(origin);
|
|
358
374
|
const selectedAddress = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address;
|
|
375
|
+
const internalAccounts = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).call(this);
|
|
359
376
|
await validateTransactionOrigin({
|
|
360
377
|
from: txParams.from,
|
|
378
|
+
internalAccounts,
|
|
361
379
|
origin,
|
|
362
380
|
permittedAddresses,
|
|
363
381
|
selectedAddress,
|
|
364
382
|
txParams,
|
|
383
|
+
type,
|
|
365
384
|
});
|
|
366
385
|
const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
|
|
367
386
|
validateTxParams(txParams, isEIP1559Compatible);
|
|
@@ -383,6 +402,7 @@ export class TransactionController extends BaseController {
|
|
|
383
402
|
deviceConfirmedOn,
|
|
384
403
|
id: random(),
|
|
385
404
|
isFirstTimeInteraction: undefined,
|
|
405
|
+
nestedTransactions,
|
|
386
406
|
networkClientId,
|
|
387
407
|
origin,
|
|
388
408
|
securityAlertResponse,
|
|
@@ -473,7 +493,7 @@ export class TransactionController extends BaseController {
|
|
|
473
493
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
474
494
|
*/
|
|
475
495
|
async stopTransaction(transactionId, gasValues, { estimatedBaseFee, actionId, } = {}) {
|
|
476
|
-
|
|
496
|
+
await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
|
|
477
497
|
actionId,
|
|
478
498
|
estimatedBaseFee,
|
|
479
499
|
gasValues,
|
|
@@ -502,7 +522,7 @@ export class TransactionController extends BaseController {
|
|
|
502
522
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
503
523
|
*/
|
|
504
524
|
async speedUpTransaction(transactionId, gasValues, { actionId, estimatedBaseFee, } = {}) {
|
|
505
|
-
|
|
525
|
+
await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
|
|
506
526
|
actionId,
|
|
507
527
|
estimatedBaseFee,
|
|
508
528
|
gasValues,
|
|
@@ -535,6 +555,7 @@ export class TransactionController extends BaseController {
|
|
|
535
555
|
* @param transaction - The transaction params to estimate gas for.
|
|
536
556
|
* @param multiplier - The multiplier to use for the gas buffer.
|
|
537
557
|
* @param networkClientId - The network client id to use for the estimate.
|
|
558
|
+
* @returns The buffered estimated gas and whether the estimation failed.
|
|
538
559
|
*/
|
|
539
560
|
async estimateGasBuffered(transaction, multiplier, networkClientId) {
|
|
540
561
|
const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
|
|
@@ -797,6 +818,27 @@ export class TransactionController extends BaseController {
|
|
|
797
818
|
this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
|
|
798
819
|
return this.getTransaction(txId);
|
|
799
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Update the isActive state of a transaction.
|
|
823
|
+
*
|
|
824
|
+
* @param transactionId - The ID of the transaction to update.
|
|
825
|
+
* @param isActive - The active state.
|
|
826
|
+
*/
|
|
827
|
+
setTransactionActive(transactionId, isActive) {
|
|
828
|
+
const transactionMeta = this.getTransaction(transactionId);
|
|
829
|
+
if (!transactionMeta) {
|
|
830
|
+
throw new Error(`Transaction with id ${transactionId} not found`);
|
|
831
|
+
}
|
|
832
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
|
|
833
|
+
transactionId,
|
|
834
|
+
note: 'TransactionController#setTransactionActive - Transaction isActive updated',
|
|
835
|
+
skipHistory: true,
|
|
836
|
+
skipValidation: true,
|
|
837
|
+
skipResimulateCheck: true,
|
|
838
|
+
}, (updatedTransactionMeta) => {
|
|
839
|
+
updatedTransactionMeta.isActive = isActive;
|
|
840
|
+
});
|
|
841
|
+
}
|
|
800
842
|
/**
|
|
801
843
|
* Signs and returns the raw transaction data for provided transaction params list.
|
|
802
844
|
*
|
|
@@ -1000,6 +1042,7 @@ export class TransactionController extends BaseController {
|
|
|
1000
1042
|
* @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.
|
|
1001
1043
|
* @param request.chainId - The ID of the chain where the transaction will be executed.
|
|
1002
1044
|
* @param request.networkClientId - The ID of a specific network client to process the transaction.
|
|
1045
|
+
* @returns The layer 1 gas fee.
|
|
1003
1046
|
*/
|
|
1004
1047
|
async getLayer1GasFee({ transactionParams, chainId, networkClientId, }) {
|
|
1005
1048
|
const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, {
|
|
@@ -1062,6 +1105,54 @@ export class TransactionController extends BaseController {
|
|
|
1062
1105
|
abortCallback();
|
|
1063
1106
|
this.signAbortCallbacks.delete(transactionId);
|
|
1064
1107
|
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Update the transaction data of a single nested transaction within an atomic batch transaction.
|
|
1110
|
+
*
|
|
1111
|
+
* @param options - The options bag.
|
|
1112
|
+
* @param options.transactionId - ID of the atomic batch transaction.
|
|
1113
|
+
* @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.
|
|
1114
|
+
* @param options.transactionData - New data to set for the nested transaction.
|
|
1115
|
+
* @returns The updated data for the atomic batch transaction.
|
|
1116
|
+
*/
|
|
1117
|
+
async updateAtomicBatchData({ transactionId, transactionIndex, transactionData, }) {
|
|
1118
|
+
log('Updating atomic batch data', {
|
|
1119
|
+
transactionId,
|
|
1120
|
+
transactionIndex,
|
|
1121
|
+
transactionData,
|
|
1122
|
+
});
|
|
1123
|
+
const updatedTransactionMeta = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
|
|
1124
|
+
transactionId,
|
|
1125
|
+
note: 'TransactionController#updateAtomicBatchData - Atomic batch data updated',
|
|
1126
|
+
}, (transactionMeta) => {
|
|
1127
|
+
const { nestedTransactions, txParams } = transactionMeta;
|
|
1128
|
+
const from = txParams.from;
|
|
1129
|
+
const nestedTransaction = nestedTransactions?.[transactionIndex];
|
|
1130
|
+
if (!nestedTransaction) {
|
|
1131
|
+
throw new Error(`Nested transaction not found with index - ${transactionIndex}`);
|
|
1132
|
+
}
|
|
1133
|
+
nestedTransaction.data = transactionData;
|
|
1134
|
+
const batchTransaction = generateEIP7702BatchTransaction(from, nestedTransactions);
|
|
1135
|
+
transactionMeta.txParams.data = batchTransaction.data;
|
|
1136
|
+
});
|
|
1137
|
+
const draftTransaction = cloneDeep({
|
|
1138
|
+
...updatedTransactionMeta,
|
|
1139
|
+
txParams: {
|
|
1140
|
+
...updatedTransactionMeta.txParams,
|
|
1141
|
+
// Clear existing gas to force estimation
|
|
1142
|
+
gas: undefined,
|
|
1143
|
+
},
|
|
1144
|
+
});
|
|
1145
|
+
await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateGasEstimate).call(this, draftTransaction);
|
|
1146
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
|
|
1147
|
+
transactionId,
|
|
1148
|
+
note: 'TransactionController#updateAtomicBatchData - Gas estimate updated',
|
|
1149
|
+
}, (transactionMeta) => {
|
|
1150
|
+
transactionMeta.txParams.gas = draftTransaction.txParams.gas;
|
|
1151
|
+
transactionMeta.simulationFails = draftTransaction.simulationFails;
|
|
1152
|
+
transactionMeta.gasLimitNoBuffer = draftTransaction.gasLimitNoBuffer;
|
|
1153
|
+
});
|
|
1154
|
+
return updatedTransactionMeta.txParams.data;
|
|
1155
|
+
}
|
|
1065
1156
|
addMetadata(transactionMeta) {
|
|
1066
1157
|
validateTxParams(transactionMeta.txParams);
|
|
1067
1158
|
this.update((state) => {
|
|
@@ -1074,18 +1165,11 @@ export class TransactionController extends BaseController {
|
|
|
1074
1165
|
async updateGasProperties(transactionMeta, { traceContext } = {}) {
|
|
1075
1166
|
const isEIP1559Compatible = transactionMeta.txParams.type !== TransactionEnvelopeType.legacy &&
|
|
1076
1167
|
(await this.getEIP1559Compatibility(transactionMeta.networkClientId));
|
|
1077
|
-
const { networkClientId
|
|
1078
|
-
const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
|
|
1079
|
-
.configuration.type === NetworkClientType.Custom;
|
|
1168
|
+
const { networkClientId } = transactionMeta;
|
|
1080
1169
|
const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
|
|
1081
1170
|
const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId });
|
|
1082
1171
|
await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Update Gas', parentContext: traceContext }, async () => {
|
|
1083
|
-
await
|
|
1084
|
-
ethQuery,
|
|
1085
|
-
chainId,
|
|
1086
|
-
isCustomNetwork,
|
|
1087
|
-
txMeta: transactionMeta,
|
|
1088
|
-
});
|
|
1172
|
+
await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateGasEstimate).call(this, transactionMeta);
|
|
1089
1173
|
});
|
|
1090
1174
|
await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Update Gas Fees', parentContext: traceContext }, async () => await updateGasFees({
|
|
1091
1175
|
eip1559: isEIP1559Compatible,
|
|
@@ -1157,7 +1241,10 @@ export class TransactionController extends BaseController {
|
|
|
1157
1241
|
if (!isTxCompleted) {
|
|
1158
1242
|
if (error?.code === errorCodes.provider.userRejectedRequest) {
|
|
1159
1243
|
this.cancelTransaction(transactionId, actionId);
|
|
1160
|
-
throw providerErrors.userRejectedRequest(
|
|
1244
|
+
throw providerErrors.userRejectedRequest({
|
|
1245
|
+
message: 'MetaMask Tx Signature: User denied transaction signature.',
|
|
1246
|
+
data: error?.data,
|
|
1247
|
+
});
|
|
1161
1248
|
}
|
|
1162
1249
|
else {
|
|
1163
1250
|
this.failTransaction(meta, error, actionId);
|
|
@@ -1187,6 +1274,7 @@ export class TransactionController extends BaseController {
|
|
|
1187
1274
|
*
|
|
1188
1275
|
* @param transactionId - The ID of the transaction to approve.
|
|
1189
1276
|
* @param traceContext - The parent context for any new traces.
|
|
1277
|
+
* @returns The state of the approval.
|
|
1190
1278
|
*/
|
|
1191
1279
|
async approveTransaction(transactionId, traceContext) {
|
|
1192
1280
|
const cleanupTasks = new Array();
|
|
@@ -1225,7 +1313,7 @@ export class TransactionController extends BaseController {
|
|
|
1225
1313
|
}
|
|
1226
1314
|
});
|
|
1227
1315
|
this.onTransactionStatusChange(transactionMeta);
|
|
1228
|
-
const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta
|
|
1316
|
+
const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
|
|
1229
1317
|
if (!this.beforePublish(transactionMeta)) {
|
|
1230
1318
|
log('Skipping publishing transaction based on hook');
|
|
1231
1319
|
this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
|
|
@@ -1592,7 +1680,8 @@ export class TransactionController extends BaseController {
|
|
|
1592
1680
|
const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
|
|
1593
1681
|
return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
|
|
1594
1682
|
}
|
|
1595
|
-
async signTransaction(transactionMeta
|
|
1683
|
+
async signTransaction(transactionMeta) {
|
|
1684
|
+
const { txParams } = transactionMeta;
|
|
1596
1685
|
log('Signing transaction', txParams);
|
|
1597
1686
|
const { authorizationList, from } = txParams;
|
|
1598
1687
|
const finalTxParams = { ...txParams };
|
|
@@ -1621,6 +1710,7 @@ export class TransactionController extends BaseController {
|
|
|
1621
1710
|
const transactionMetaWithRsv = {
|
|
1622
1711
|
...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
|
|
1623
1712
|
status: TransactionStatus.signed,
|
|
1713
|
+
txParams: finalTxParams,
|
|
1624
1714
|
};
|
|
1625
1715
|
this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
|
|
1626
1716
|
this.onTransactionStatusChange(transactionMetaWithRsv);
|
|
@@ -1840,6 +1930,9 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
|
|
|
1840
1930
|
let resimulateResponse;
|
|
1841
1931
|
this.update((state) => {
|
|
1842
1932
|
const index = state.transactions.findIndex(({ id }) => id === transactionId);
|
|
1933
|
+
if (index === -1) {
|
|
1934
|
+
throw new Error(`Cannot update transaction as ID not found - ${transactionId}`);
|
|
1935
|
+
}
|
|
1843
1936
|
let transactionMeta = state.transactions[index];
|
|
1844
1937
|
const originalTransactionMeta = cloneDeep(transactionMeta);
|
|
1845
1938
|
transactionMeta = callback(transactionMeta) ?? transactionMeta;
|
|
@@ -1965,6 +2058,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
|
|
|
1965
2058
|
});
|
|
1966
2059
|
}, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
|
|
1967
2060
|
return this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
2061
|
+
}, _TransactionController_getInternalAccounts = function _TransactionController_getInternalAccounts() {
|
|
2062
|
+
const state = this.messagingSystem.call('AccountsController:getState');
|
|
2063
|
+
return Object.values(state.internalAccounts?.accounts ?? {})
|
|
2064
|
+
.filter((account) => account.type === 'eip155:eoa')
|
|
2065
|
+
.map((account) => account.address);
|
|
1968
2066
|
}, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
|
|
1969
2067
|
const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
|
|
1970
2068
|
const { networkConfigurationsByChainId } = this.getNetworkState();
|
|
@@ -1990,5 +2088,16 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
|
|
|
1990
2088
|
}
|
|
1991
2089
|
submitHistory.unshift(submitHistoryEntry);
|
|
1992
2090
|
});
|
|
2091
|
+
}, _TransactionController_updateGasEstimate = async function _TransactionController_updateGasEstimate(transactionMeta) {
|
|
2092
|
+
const { chainId, networkClientId } = transactionMeta;
|
|
2093
|
+
const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
|
|
2094
|
+
.configuration.type === NetworkClientType.Custom;
|
|
2095
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
|
|
2096
|
+
await updateGas({
|
|
2097
|
+
chainId,
|
|
2098
|
+
ethQuery,
|
|
2099
|
+
isCustomNetwork,
|
|
2100
|
+
txMeta: transactionMeta,
|
|
2101
|
+
});
|
|
1993
2102
|
};
|
|
1994
2103
|
//# sourceMappingURL=TransactionController.mjs.map
|