@metamask-previews/transaction-controller 55.0.2-preview-780c8df → 55.0.2-preview-698a7cc
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 +7 -1
- package/dist/TransactionController.cjs +14 -26
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts +9 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts +9 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +15 -27
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/api/accounts-api.cjs +3 -2
- package/dist/api/accounts-api.cjs.map +1 -1
- package/dist/api/accounts-api.d.cts +1 -0
- package/dist/api/accounts-api.d.cts.map +1 -1
- package/dist/api/accounts-api.d.mts +1 -0
- package/dist/api/accounts-api.d.mts.map +1 -1
- package/dist/api/accounts-api.mjs +3 -2
- package/dist/api/accounts-api.mjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +2 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +4 -50
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +3 -16
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +3 -16
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +2 -47
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs +32 -8
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.cts +7 -2
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.mts +7 -2
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +32 -8
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +16 -1
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +14 -0
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +14 -0
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +14 -0
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,6 @@ import type { Hex } from "@metamask/utils";
|
|
|
5
5
|
import EventEmitter from "events";
|
|
6
6
|
import type { TransactionControllerMessenger } from "../TransactionController.cjs";
|
|
7
7
|
import type { GasFeeEstimates, GasFeeFlow, Layer1GasFeeFlow, TransactionMeta } from "../types.cjs";
|
|
8
|
-
import { GasFeeEstimateLevel } from "../types.cjs";
|
|
9
8
|
/**
|
|
10
9
|
* Automatically polls and updates suggested gas fees on unapproved transactions.
|
|
11
10
|
*/
|
|
@@ -37,8 +36,7 @@ export declare class GasFeePoller {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
* and sets all gas related properties.
|
|
39
|
+
* Update the gas fees for a transaction.
|
|
42
40
|
*
|
|
43
41
|
* @param args - Argument bag.
|
|
44
42
|
* @param args.txMeta - The transaction meta.
|
|
@@ -47,22 +45,11 @@ export declare class GasFeePoller {
|
|
|
47
45
|
* @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
|
|
48
46
|
* @param args.layer1GasFee - The layer 1 gas fee.
|
|
49
47
|
*/
|
|
50
|
-
export declare function
|
|
48
|
+
export declare function updateTransactionGasFees({ txMeta, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }: {
|
|
49
|
+
txMeta: TransactionMeta;
|
|
51
50
|
gasFeeEstimates?: GasFeeEstimates;
|
|
52
51
|
gasFeeEstimatesLoaded?: boolean;
|
|
53
52
|
isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;
|
|
54
53
|
layer1GasFee?: Hex;
|
|
55
|
-
txMeta: TransactionMeta;
|
|
56
|
-
}): void;
|
|
57
|
-
/**
|
|
58
|
-
* Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.
|
|
59
|
-
*
|
|
60
|
-
* @param args - Argument bag.
|
|
61
|
-
* @param args.txMeta - The transaction meta.
|
|
62
|
-
* @param args.userFeeLevel - The user fee level.
|
|
63
|
-
*/
|
|
64
|
-
export declare function applyTransactionGasEstimatesToTransaction({ txMeta, userFeeLevel, }: {
|
|
65
|
-
txMeta: TransactionMeta;
|
|
66
|
-
userFeeLevel: GasFeeEstimateLevel;
|
|
67
54
|
}): void;
|
|
68
55
|
//# sourceMappingURL=GasFeePoller.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GasFeePoller.d.cts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC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EACf,qBAAqB,EACrB,8BAA8B,EAC9B,YAAY,GACb,EAAE;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8BAA8B,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC;IAC9E,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB,GAAG,IAAI,CA8EP"}
|
|
@@ -5,7 +5,6 @@ import type { Hex } from "@metamask/utils";
|
|
|
5
5
|
import EventEmitter from "events";
|
|
6
6
|
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
7
7
|
import type { GasFeeEstimates, GasFeeFlow, Layer1GasFeeFlow, TransactionMeta } from "../types.mjs";
|
|
8
|
-
import { GasFeeEstimateLevel } from "../types.mjs";
|
|
9
8
|
/**
|
|
10
9
|
* Automatically polls and updates suggested gas fees on unapproved transactions.
|
|
11
10
|
*/
|
|
@@ -37,8 +36,7 @@ export declare class GasFeePoller {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
* and sets all gas related properties.
|
|
39
|
+
* Update the gas fees for a transaction.
|
|
42
40
|
*
|
|
43
41
|
* @param args - Argument bag.
|
|
44
42
|
* @param args.txMeta - The transaction meta.
|
|
@@ -47,22 +45,11 @@ export declare class GasFeePoller {
|
|
|
47
45
|
* @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
|
|
48
46
|
* @param args.layer1GasFee - The layer 1 gas fee.
|
|
49
47
|
*/
|
|
50
|
-
export declare function
|
|
48
|
+
export declare function updateTransactionGasFees({ txMeta, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }: {
|
|
49
|
+
txMeta: TransactionMeta;
|
|
51
50
|
gasFeeEstimates?: GasFeeEstimates;
|
|
52
51
|
gasFeeEstimatesLoaded?: boolean;
|
|
53
52
|
isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;
|
|
54
53
|
layer1GasFee?: Hex;
|
|
55
|
-
txMeta: TransactionMeta;
|
|
56
|
-
}): void;
|
|
57
|
-
/**
|
|
58
|
-
* Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.
|
|
59
|
-
*
|
|
60
|
-
* @param args - Argument bag.
|
|
61
|
-
* @param args.txMeta - The transaction meta.
|
|
62
|
-
* @param args.userFeeLevel - The user fee level.
|
|
63
|
-
*/
|
|
64
|
-
export declare function applyTransactionGasEstimatesToTransaction({ txMeta, userFeeLevel, }: {
|
|
65
|
-
txMeta: TransactionMeta;
|
|
66
|
-
userFeeLevel: GasFeeEstimateLevel;
|
|
67
54
|
}): void;
|
|
68
55
|
//# sourceMappingURL=GasFeePoller.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GasFeePoller.d.mts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAIV,gBAAgB,EAEhB,eAAe,EAChB,qBAAiB;
|
|
1
|
+
{"version":3,"file":"GasFeePoller.d.mts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAA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ePoller_gasFee
|
|
|
191
191
|
return new Map(await Promise.all(entryPromises));
|
|
192
192
|
};
|
|
193
193
|
/**
|
|
194
|
-
*
|
|
195
|
-
* and sets all gas related properties.
|
|
194
|
+
* Update the gas fees for a transaction.
|
|
196
195
|
*
|
|
197
196
|
* @param args - Argument bag.
|
|
198
197
|
* @param args.txMeta - The transaction meta.
|
|
@@ -201,7 +200,7 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
|
|
|
201
200
|
* @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
|
|
202
201
|
* @param args.layer1GasFee - The layer 1 gas fee.
|
|
203
202
|
*/
|
|
204
|
-
export function
|
|
203
|
+
export function updateTransactionGasFees({ txMeta, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }) {
|
|
205
204
|
const userFeeLevel = txMeta.userFeeLevel;
|
|
206
205
|
const isUsingGasFeeEstimateLevel = Object.values(GasFeeEstimateLevel).includes(userFeeLevel);
|
|
207
206
|
const { type: gasEstimateType } = gasFeeEstimates ?? {};
|
|
@@ -261,48 +260,4 @@ export function applyGasFeeEstimatesToTransaction({ gasFeeEstimates, gasFeeEstim
|
|
|
261
260
|
txMeta.layer1GasFee = layer1GasFee;
|
|
262
261
|
}
|
|
263
262
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.
|
|
266
|
-
*
|
|
267
|
-
* @param args - Argument bag.
|
|
268
|
-
* @param args.txMeta - The transaction meta.
|
|
269
|
-
* @param args.userFeeLevel - The user fee level.
|
|
270
|
-
*/
|
|
271
|
-
export function applyTransactionGasEstimatesToTransaction({ txMeta, userFeeLevel, }) {
|
|
272
|
-
const { txParams, gasFeeEstimates } = txMeta;
|
|
273
|
-
if (!gasFeeEstimates) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const isEIP1559Compatible = txMeta.txParams.type !== TransactionEnvelopeType.legacy;
|
|
277
|
-
const transactionGasFeeEstimates = gasFeeEstimates;
|
|
278
|
-
const transactionGasFeeEstimateType = transactionGasFeeEstimates.type;
|
|
279
|
-
if (isEIP1559Compatible) {
|
|
280
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.FeeMarket) {
|
|
281
|
-
txParams.maxFeePerGas =
|
|
282
|
-
transactionGasFeeEstimates[userFeeLevel]?.maxFeePerGas;
|
|
283
|
-
txParams.maxPriorityFeePerGas =
|
|
284
|
-
transactionGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;
|
|
285
|
-
}
|
|
286
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.Legacy) {
|
|
287
|
-
txParams.maxFeePerGas = transactionGasFeeEstimates[userFeeLevel];
|
|
288
|
-
txParams.maxPriorityFeePerGas = transactionGasFeeEstimates[userFeeLevel];
|
|
289
|
-
}
|
|
290
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.GasPrice) {
|
|
291
|
-
txParams.maxFeePerGas = transactionGasFeeEstimates.gasPrice;
|
|
292
|
-
txParams.maxPriorityFeePerGas = transactionGasFeeEstimates.gasPrice;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.FeeMarket) {
|
|
297
|
-
txParams.gasPrice =
|
|
298
|
-
transactionGasFeeEstimates[userFeeLevel]?.maxFeePerGas;
|
|
299
|
-
}
|
|
300
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.Legacy) {
|
|
301
|
-
txParams.gasPrice = transactionGasFeeEstimates[userFeeLevel];
|
|
302
|
-
}
|
|
303
|
-
if (transactionGasFeeEstimateType === GasFeeEstimateType.GasPrice) {
|
|
304
|
-
txParams.gasPrice = transactionGasFeeEstimates.gasPrice;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
263
|
//# sourceMappingURL=Gas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;QACD,IAAI,6BAA6B,KAAK,kBAAkB,CAAC,QAAQ,EAAE;YACjE,QAAQ,CAAC,QAAQ,GAAG,0BAA0B,CAAC,QAAQ,CAAC;SACzD;KACF;AACH,CAAC","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasPriceGasFeeEstimates,\n FeeMarketGasFeeEstimates,\n Layer1GasFeeFlow,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop() {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(networkClientId));\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { networkClientId } = transactionMeta;\n const provider = this.#getProvider(networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Updates gas properties for a transaction given `gasFeeEstimates` from the gas fee controller\n * and sets all gas related properties.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function applyGasFeeEstimatesToTransaction({\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n txMeta,\n}: {\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n txMeta: TransactionMeta;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const { type: gasEstimateType } = gasFeeEstimates ?? {};\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (shouldUpdateTxParamsGasFees && isUsingGasFeeEstimateLevel) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n txMeta.txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n\n txMeta.txParams.maxFeePerGas = gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txMeta.txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n txMeta.txParams.gasPrice =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n txMeta.txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n txMeta.txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.userFeeLevel - The user fee level.\n */\nexport function applyTransactionGasEstimatesToTransaction({\n txMeta,\n userFeeLevel,\n}: {\n txMeta: TransactionMeta;\n userFeeLevel: GasFeeEstimateLevel;\n}): void {\n const { txParams, gasFeeEstimates } = txMeta;\n\n if (!gasFeeEstimates) {\n return;\n }\n\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n const transactionGasFeeEstimates = gasFeeEstimates as GasFeeEstimates;\n const transactionGasFeeEstimateType = transactionGasFeeEstimates.type;\n\n if (isEIP1559Compatible) {\n if (transactionGasFeeEstimateType === GasFeeEstimateType.FeeMarket) {\n txParams.maxFeePerGas =\n transactionGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n txParams.maxPriorityFeePerGas =\n transactionGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;\n }\n if (transactionGasFeeEstimateType === GasFeeEstimateType.Legacy) {\n txParams.maxFeePerGas = transactionGasFeeEstimates[userFeeLevel];\n txParams.maxPriorityFeePerGas = transactionGasFeeEstimates[userFeeLevel];\n }\n if (transactionGasFeeEstimateType === GasFeeEstimateType.GasPrice) {\n txParams.maxFeePerGas = transactionGasFeeEstimates.gasPrice;\n txParams.maxPriorityFeePerGas = transactionGasFeeEstimates.gasPrice;\n }\n } else {\n if (transactionGasFeeEstimateType === GasFeeEstimateType.FeeMarket) {\n txParams.gasPrice =\n transactionGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n }\n if (transactionGasFeeEstimateType === GasFeeEstimateType.Legacy) {\n txParams.gasPrice = transactionGasFeeEstimates[userFeeLevel];\n }\n if (transactionGasFeeEstimateType === GasFeeEstimateType.GasPrice) {\n txParams.gasPrice = transactionGasFeeEstimates.gasPrice;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GasFeePoller.mjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAQ,4BAA4B;;AAO3C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAY1C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,8BAA0B;AAClD,OAAO,EAAE,0BAA0B,EAAE,yCAAqC;AAE1E,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IAyBvB;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,aAAa,GAYd;;QAzDD,QAAG,GAAiB,IAAI,YAAY,EAAE,CAAC;QAE9B,6DAEwB;QAExB,4CAA2B;QAE3B,6DAEiB;QAEjB,4CAA6D;QAE7D,gDAA0C;QAE1C,kDAAuC;QAEvC,0CAA2C;QAEpD,wCAAoD;QAEpD,gCAAW,KAAK,EAAC;QAoCf,uBAAA,IAAI,8CAAiC,4BAA4B,MAAA,CAAC;QAClE,uBAAA,IAAI,6BAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,mCAAsB,iBAAiB,MAAA,CAAC;QAC5C,uBAAA,IAAI,8CAAiC,4BAA4B,MAAA,CAAC;QAClE,uBAAA,IAAI,6BAAgB,WAAW,MAAA,CAAC;QAChC,uBA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":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasPriceGasFeeEstimates,\n FeeMarketGasFeeEstimates,\n Layer1GasFeeFlow,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop() {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(networkClientId));\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { networkClientId } = transactionMeta;\n const provider = this.#getProvider(networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Update the gas fees for a transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function updateTransactionGasFees({\n txMeta,\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n}: {\n txMeta: TransactionMeta;\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const { type: gasEstimateType } = gasFeeEstimates ?? {};\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (shouldUpdateTxParamsGasFees && isUsingGasFeeEstimateLevel) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n txMeta.txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n\n txMeta.txParams.maxFeePerGas = gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txMeta.txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n txMeta.txParams.gasPrice =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n txMeta.txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n txMeta.txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n"]}
|
|
@@ -13,23 +13,26 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_getCache, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_queryEntireHistory, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_updateCache, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart;
|
|
16
|
+
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_client, _IncomingTransactionHelper_getCache, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_includeTokenTransfers, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_messenger, _IncomingTransactionHelper_queryEntireHistory, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_timeoutId, _IncomingTransactionHelper_trimTransactions, _IncomingTransactionHelper_updateCache, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_onInterval, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_canStart, _IncomingTransactionHelper_getInterval, _IncomingTransactionHelper_getTags;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.IncomingTransactionHelper = void 0;
|
|
19
19
|
// This package purposefully relies on Node's EventEmitter module.
|
|
20
20
|
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
21
21
|
const events_1 = __importDefault(require("events"));
|
|
22
22
|
const logger_1 = require("../logger.cjs");
|
|
23
|
-
const
|
|
23
|
+
const feature_flags_1 = require("../utils/feature-flags.cjs");
|
|
24
|
+
const TAG_POLLING = 'automatic-polling';
|
|
24
25
|
class IncomingTransactionHelper {
|
|
25
|
-
constructor({ getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }) {
|
|
26
|
+
constructor({ client, getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, messenger, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }) {
|
|
26
27
|
_IncomingTransactionHelper_instances.add(this);
|
|
28
|
+
_IncomingTransactionHelper_client.set(this, void 0);
|
|
27
29
|
_IncomingTransactionHelper_getCache.set(this, void 0);
|
|
28
30
|
_IncomingTransactionHelper_getCurrentAccount.set(this, void 0);
|
|
29
31
|
_IncomingTransactionHelper_getLocalTransactions.set(this, void 0);
|
|
30
32
|
_IncomingTransactionHelper_includeTokenTransfers.set(this, void 0);
|
|
31
33
|
_IncomingTransactionHelper_isEnabled.set(this, void 0);
|
|
32
34
|
_IncomingTransactionHelper_isRunning.set(this, void 0);
|
|
35
|
+
_IncomingTransactionHelper_messenger.set(this, void 0);
|
|
33
36
|
_IncomingTransactionHelper_queryEntireHistory.set(this, void 0);
|
|
34
37
|
_IncomingTransactionHelper_remoteTransactionSource.set(this, void 0);
|
|
35
38
|
_IncomingTransactionHelper_timeoutId.set(this, void 0);
|
|
@@ -37,12 +40,14 @@ class IncomingTransactionHelper {
|
|
|
37
40
|
_IncomingTransactionHelper_updateCache.set(this, void 0);
|
|
38
41
|
_IncomingTransactionHelper_updateTransactions.set(this, void 0);
|
|
39
42
|
this.hub = new events_1.default();
|
|
43
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_client, client, "f");
|
|
40
44
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_getCache, getCache, "f");
|
|
41
45
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_getCurrentAccount, getCurrentAccount, "f");
|
|
42
46
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_getLocalTransactions, getLocalTransactions, "f");
|
|
43
47
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_includeTokenTransfers, includeTokenTransfers, "f");
|
|
44
48
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_isEnabled, isEnabled ?? (() => true), "f");
|
|
45
49
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, false, "f");
|
|
50
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_messenger, messenger, "f");
|
|
46
51
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_queryEntireHistory, queryEntireHistory, "f");
|
|
47
52
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_remoteTransactionSource, remoteTransactionSource, "f");
|
|
48
53
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_trimTransactions, trimTransactions, "f");
|
|
@@ -56,9 +61,10 @@ class IncomingTransactionHelper {
|
|
|
56
61
|
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
57
62
|
return;
|
|
58
63
|
}
|
|
59
|
-
(
|
|
64
|
+
const interval = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getInterval).call(this);
|
|
65
|
+
(0, logger_1.incomingTransactionsLogger)('Starting polling', { interval });
|
|
60
66
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
61
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_timeoutId, setTimeout(() => __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_onInterval).call(this),
|
|
67
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_timeoutId, setTimeout(() => __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_onInterval).call(this), interval), "f");
|
|
62
68
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, true, "f");
|
|
63
69
|
(0, logger_1.incomingTransactionsLogger)('Started polling');
|
|
64
70
|
}
|
|
@@ -72,9 +78,11 @@ class IncomingTransactionHelper {
|
|
|
72
78
|
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, false, "f");
|
|
73
79
|
(0, logger_1.incomingTransactionsLogger)('Stopped polling');
|
|
74
80
|
}
|
|
75
|
-
async update({ isInterval } = {}) {
|
|
81
|
+
async update({ isInterval, tags, } = {}) {
|
|
82
|
+
const finalTags = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getTags).call(this, tags, isInterval);
|
|
76
83
|
(0, logger_1.incomingTransactionsLogger)('Checking for incoming transactions', {
|
|
77
84
|
isInterval: Boolean(isInterval),
|
|
85
|
+
tags: finalTags,
|
|
78
86
|
});
|
|
79
87
|
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
80
88
|
return;
|
|
@@ -92,6 +100,7 @@ class IncomingTransactionHelper {
|
|
|
92
100
|
cache,
|
|
93
101
|
includeTokenTransfers,
|
|
94
102
|
queryEntireHistory,
|
|
103
|
+
tags: finalTags,
|
|
95
104
|
updateCache: __classPrivateFieldGet(this, _IncomingTransactionHelper_updateCache, "f"),
|
|
96
105
|
updateTransactions,
|
|
97
106
|
});
|
|
@@ -130,7 +139,7 @@ class IncomingTransactionHelper {
|
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
exports.IncomingTransactionHelper = IncomingTransactionHelper;
|
|
133
|
-
_IncomingTransactionHelper_getCache = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_queryEntireHistory = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_updateCache = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_onInterval = async function _IncomingTransactionHelper_onInterval() {
|
|
142
|
+
_IncomingTransactionHelper_client = new WeakMap(), _IncomingTransactionHelper_getCache = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_includeTokenTransfers = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_messenger = new WeakMap(), _IncomingTransactionHelper_queryEntireHistory = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_timeoutId = new WeakMap(), _IncomingTransactionHelper_trimTransactions = new WeakMap(), _IncomingTransactionHelper_updateCache = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_onInterval = async function _IncomingTransactionHelper_onInterval() {
|
|
134
143
|
try {
|
|
135
144
|
await this.update({ isInterval: true });
|
|
136
145
|
}
|
|
@@ -138,12 +147,27 @@ _IncomingTransactionHelper_getCache = new WeakMap(), _IncomingTransactionHelper_
|
|
|
138
147
|
console.error('Error while checking incoming transactions', error);
|
|
139
148
|
}
|
|
140
149
|
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isRunning, "f")) {
|
|
150
|
+
__classPrivateFieldSet(this, _IncomingTransactionHelper_timeoutId, setTimeout(
|
|
141
151
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
142
|
-
|
|
152
|
+
() => __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_onInterval).call(this), __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getInterval).call(this)), "f");
|
|
143
153
|
}
|
|
144
154
|
}, _IncomingTransactionHelper_sortTransactionsByTime = function _IncomingTransactionHelper_sortTransactionsByTime(transactions) {
|
|
145
155
|
transactions.sort((a, b) => (a.time < b.time ? -1 : 1));
|
|
146
156
|
}, _IncomingTransactionHelper_canStart = function _IncomingTransactionHelper_canStart() {
|
|
147
157
|
return __classPrivateFieldGet(this, _IncomingTransactionHelper_isEnabled, "f").call(this);
|
|
158
|
+
}, _IncomingTransactionHelper_getInterval = function _IncomingTransactionHelper_getInterval() {
|
|
159
|
+
return (0, feature_flags_1.getIncomingTransactionsPollingInterval)(__classPrivateFieldGet(this, _IncomingTransactionHelper_messenger, "f"));
|
|
160
|
+
}, _IncomingTransactionHelper_getTags = function _IncomingTransactionHelper_getTags(requestTags, isInterval) {
|
|
161
|
+
const tags = [];
|
|
162
|
+
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_client, "f")) {
|
|
163
|
+
tags.push(__classPrivateFieldGet(this, _IncomingTransactionHelper_client, "f"));
|
|
164
|
+
}
|
|
165
|
+
if (requestTags?.length) {
|
|
166
|
+
tags.push(...requestTags);
|
|
167
|
+
}
|
|
168
|
+
else if (isInterval) {
|
|
169
|
+
tags.push(TAG_POLLING);
|
|
170
|
+
}
|
|
171
|
+
return tags?.length ? tags : undefined;
|
|
148
172
|
};
|
|
149
173
|
//# sourceMappingURL=IncomingTransactionHelper.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.cjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA8D;AAU9D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,aAAa;AAEzC,MAAa,yBAAyB;IA+BpC,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAA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M,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CACxD,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CACrC,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;YAC3B,IAAA,mCAAG,EAAC,gDAAgD,CAAC,CAAC;YACtD,OAAO;SACR;QAED,IAAA,mCAAG,EAAC,yBAAyB,EAAE,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QAExE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;CASF;AApND,8DAoNC;6yBA7GC,KAAK;IACH,IAAI;QACF,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,IAAI,uBAAA,IAAI,4CAAW,EAAE;QACnB,kEAAkE;QAClE,uBAAA,IAAI,wCAAc,UAAU,CAAC,GAAG,EAAE,CAAC,uBAAA,IAAI,mFAAY,MAAhB,IAAI,CAAc,EAAE,QAAQ,CAAC,MAAA,CAAC;KAClE;AACH,CAAC,iHA2FuB,YAA+B;IACrD,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;IAGC,OAAO,uBAAA,IAAI,4CAAW,MAAf,IAAI,CAAa,CAAC;AAC3B,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\n\nexport type IncomingTransactionOptions = {\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n queryEntireHistory?: boolean;\n updateTransactions?: boolean;\n};\n\nconst INTERVAL = 1000 * 30; // 30 Seconds\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #getCache: () => Record<string, unknown>;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n readonly #queryEntireHistory?: boolean;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n readonly #updateCache: (fn: (cache: Record<string, unknown>) => void) => void;\n\n readonly #updateTransactions?: boolean;\n\n constructor({\n getCache,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n queryEntireHistory,\n remoteTransactionSource,\n trimTransactions,\n updateCache,\n updateTransactions,\n }: {\n getCache: () => Record<string, unknown>;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n queryEntireHistory?: boolean;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateCache: (fn: (cache: Record<string, unknown>) => void) => void;\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#getCache = getCache;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? (() => true);\n this.#isRunning = false;\n this.#queryEntireHistory = queryEntireHistory;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateCache = updateCache;\n this.#updateTransactions = updateTransactions;\n }\n\n start() {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n log('Starting polling');\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeoutId = setTimeout(() => this.#onInterval(), INTERVAL);\n this.#isRunning = true;\n\n log('Started polling');\n }\n\n stop() {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n async #onInterval() {\n try {\n await this.update({ isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n if (this.#isRunning) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeoutId = setTimeout(() => this.#onInterval(), INTERVAL);\n }\n }\n\n async update({ isInterval }: { isInterval?: boolean } = {}): Promise<void> {\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const cache = this.#getCache();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const queryEntireHistory = this.#queryEntireHistory ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n cache,\n includeTokenTransfers,\n queryEntireHistory,\n updateCache: this.#updateCache,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]) {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.cjs","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAGlC,0CAA8D;AAE9D,8DAAgF;AAUhF,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAa,yBAAyB;IAmCpC,YAAY,EACV,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,GAgBnB;;QA5DQ,oDAAiB;QAEjB,sDAAyC;QAEzC,+DAEP;QAEO,kEAA+C;QAE/C,mEAAiC;QAEjC,uDAA0B;QAEnC,uDAAoB;QAEX,uDAA2C;QAE3C,gEAA8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,CAAC;IAGC,OAAO,uBAAA,IAAI,4CAAW,MAAf,IAAI,CAAa,CAAC;AAC3B,CAAC;IAGC,OAAO,IAAA,sDAAsC,EAAC,uBAAA,IAAI,4CAAW,CAAC,CAAC;AACjE,CAAC,mFAGC,WAAiC,EACjC,UAA+B;IAE/B,MAAM,IAAI,GAAG,EAAE,CAAC;IAEhB,IAAI,uBAAA,IAAI,yCAAQ,EAAE;QAChB,IAAI,CAAC,IAAI,CAAC,uBAAA,IAAI,yCAAQ,CAAC,CAAC;KACzB;IAED,IAAI,WAAW,EAAE,MAAM,EAAE;QACvB,IAAI,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;KAC3B;SAAM,IAAI,UAAU,EAAE;QACrB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KACxB;IAED,OAAO,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport type { TransactionControllerMessenger } from '..';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type { RemoteTransactionSource, TransactionMeta } from '../types';\nimport { getIncomingTransactionsPollingInterval } from '../utils/feature-flags';\n\nexport type IncomingTransactionOptions = {\n client?: string;\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n queryEntireHistory?: boolean;\n updateTransactions?: boolean;\n};\n\nconst TAG_POLLING = 'automatic-polling';\n\nexport class IncomingTransactionHelper {\n hub: EventEmitter;\n\n readonly #client?: string;\n\n readonly #getCache: () => Record<string, unknown>;\n\n readonly #getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n\n readonly #getLocalTransactions: () => TransactionMeta[];\n\n readonly #includeTokenTransfers?: boolean;\n\n readonly #isEnabled: () => boolean;\n\n #isRunning: boolean;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #queryEntireHistory?: boolean;\n\n readonly #remoteTransactionSource: RemoteTransactionSource;\n\n #timeoutId?: unknown;\n\n readonly #trimTransactions: (\n transactions: TransactionMeta[],\n ) => TransactionMeta[];\n\n readonly #updateCache: (fn: (cache: Record<string, unknown>) => void) => void;\n\n readonly #updateTransactions?: boolean;\n\n constructor({\n client,\n getCache,\n getCurrentAccount,\n getLocalTransactions,\n includeTokenTransfers,\n isEnabled,\n messenger,\n queryEntireHistory,\n remoteTransactionSource,\n trimTransactions,\n updateCache,\n updateTransactions,\n }: {\n client?: string;\n getCache: () => Record<string, unknown>;\n getCurrentAccount: () => ReturnType<\n AccountsController['getSelectedAccount']\n >;\n getLocalTransactions: () => TransactionMeta[];\n includeTokenTransfers?: boolean;\n isEnabled?: () => boolean;\n messenger: TransactionControllerMessenger;\n queryEntireHistory?: boolean;\n remoteTransactionSource: RemoteTransactionSource;\n trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];\n updateCache: (fn: (cache: Record<string, unknown>) => void) => void;\n updateTransactions?: boolean;\n }) {\n this.hub = new EventEmitter();\n\n this.#client = client;\n this.#getCache = getCache;\n this.#getCurrentAccount = getCurrentAccount;\n this.#getLocalTransactions = getLocalTransactions;\n this.#includeTokenTransfers = includeTokenTransfers;\n this.#isEnabled = isEnabled ?? (() => true);\n this.#isRunning = false;\n this.#messenger = messenger;\n this.#queryEntireHistory = queryEntireHistory;\n this.#remoteTransactionSource = remoteTransactionSource;\n this.#trimTransactions = trimTransactions;\n this.#updateCache = updateCache;\n this.#updateTransactions = updateTransactions;\n }\n\n start() {\n if (this.#isRunning) {\n return;\n }\n\n if (!this.#canStart()) {\n return;\n }\n\n const interval = this.#getInterval();\n\n log('Starting polling', { interval });\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeoutId = setTimeout(() => this.#onInterval(), interval);\n this.#isRunning = true;\n\n log('Started polling');\n }\n\n stop() {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId as number);\n }\n\n if (!this.#isRunning) {\n return;\n }\n\n this.#isRunning = false;\n\n log('Stopped polling');\n }\n\n async #onInterval() {\n try {\n await this.update({ isInterval: true });\n } catch (error) {\n console.error('Error while checking incoming transactions', error);\n }\n\n if (this.#isRunning) {\n this.#timeoutId = setTimeout(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n () => this.#onInterval(),\n this.#getInterval(),\n );\n }\n }\n\n async update({\n isInterval,\n tags,\n }: { isInterval?: boolean; tags?: string[] } = {}): Promise<void> {\n const finalTags = this.#getTags(tags, isInterval);\n\n log('Checking for incoming transactions', {\n isInterval: Boolean(isInterval),\n tags: finalTags,\n });\n\n if (!this.#canStart()) {\n return;\n }\n\n const account = this.#getCurrentAccount();\n const cache = this.#getCache();\n const includeTokenTransfers = this.#includeTokenTransfers ?? true;\n const queryEntireHistory = this.#queryEntireHistory ?? true;\n const updateTransactions = this.#updateTransactions ?? false;\n\n let remoteTransactions: TransactionMeta[] = [];\n\n try {\n remoteTransactions =\n await this.#remoteTransactionSource.fetchTransactions({\n address: account.address as Hex,\n cache,\n includeTokenTransfers,\n queryEntireHistory,\n tags: finalTags,\n updateCache: this.#updateCache,\n updateTransactions,\n });\n } catch (error: unknown) {\n log('Error while fetching remote transactions', error);\n return;\n }\n\n if (!remoteTransactions.length) {\n return;\n }\n\n this.#sortTransactionsByTime(remoteTransactions);\n\n log(\n 'Found potential transactions',\n remoteTransactions.length,\n remoteTransactions,\n );\n\n const localTransactions = this.#getLocalTransactions();\n\n const uniqueTransactions = remoteTransactions.filter(\n (tx) =>\n !localTransactions.some(\n (currentTx) =>\n currentTx.hash?.toLowerCase() === tx.hash?.toLowerCase() &&\n currentTx.txParams.from?.toLowerCase() ===\n tx.txParams.from?.toLowerCase() &&\n currentTx.type === tx.type,\n ),\n );\n\n if (!uniqueTransactions.length) {\n log('All transactions are already known');\n return;\n }\n\n log(\n 'Found unique transactions',\n uniqueTransactions.length,\n uniqueTransactions,\n );\n\n const trimmedTransactions = this.#trimTransactions([\n ...uniqueTransactions,\n ...localTransactions,\n ]);\n\n const uniqueTransactionIds = uniqueTransactions.map((tx) => tx.id);\n\n const newTransactions = trimmedTransactions.filter((tx) =>\n uniqueTransactionIds.includes(tx.id),\n );\n\n if (!newTransactions.length) {\n log('All unique transactions truncated due to limit');\n return;\n }\n\n log('Adding new transactions', newTransactions.length, newTransactions);\n\n this.hub.emit('transactions', newTransactions);\n }\n\n #sortTransactionsByTime(transactions: TransactionMeta[]) {\n transactions.sort((a, b) => (a.time < b.time ? -1 : 1));\n }\n\n #canStart(): boolean {\n return this.#isEnabled();\n }\n\n #getInterval(): number {\n return getIncomingTransactionsPollingInterval(this.#messenger);\n }\n\n #getTags(\n requestTags: string[] | undefined,\n isInterval: boolean | undefined,\n ): string[] | undefined {\n const tags = [];\n\n if (this.#client) {\n tags.push(this.#client);\n }\n\n if (requestTags?.length) {\n tags.push(...requestTags);\n } else if (isInterval) {\n tags.push(TAG_POLLING);\n }\n\n return tags?.length ? tags : undefined;\n }\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AccountsController } from "@metamask/accounts-controller";
|
|
3
3
|
import EventEmitter from "events";
|
|
4
|
+
import type { TransactionControllerMessenger } from "../index.cjs";
|
|
4
5
|
import type { RemoteTransactionSource, TransactionMeta } from "../types.cjs";
|
|
5
6
|
export type IncomingTransactionOptions = {
|
|
7
|
+
client?: string;
|
|
6
8
|
includeTokenTransfers?: boolean;
|
|
7
9
|
isEnabled?: () => boolean;
|
|
8
10
|
queryEntireHistory?: boolean;
|
|
@@ -11,12 +13,14 @@ export type IncomingTransactionOptions = {
|
|
|
11
13
|
export declare class IncomingTransactionHelper {
|
|
12
14
|
#private;
|
|
13
15
|
hub: EventEmitter;
|
|
14
|
-
constructor({ getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }: {
|
|
16
|
+
constructor({ client, getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, messenger, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }: {
|
|
17
|
+
client?: string;
|
|
15
18
|
getCache: () => Record<string, unknown>;
|
|
16
19
|
getCurrentAccount: () => ReturnType<AccountsController['getSelectedAccount']>;
|
|
17
20
|
getLocalTransactions: () => TransactionMeta[];
|
|
18
21
|
includeTokenTransfers?: boolean;
|
|
19
22
|
isEnabled?: () => boolean;
|
|
23
|
+
messenger: TransactionControllerMessenger;
|
|
20
24
|
queryEntireHistory?: boolean;
|
|
21
25
|
remoteTransactionSource: RemoteTransactionSource;
|
|
22
26
|
trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];
|
|
@@ -25,8 +29,9 @@ export declare class IncomingTransactionHelper {
|
|
|
25
29
|
});
|
|
26
30
|
start(): void;
|
|
27
31
|
stop(): void;
|
|
28
|
-
update({ isInterval }?: {
|
|
32
|
+
update({ isInterval, tags, }?: {
|
|
29
33
|
isInterval?: boolean;
|
|
34
|
+
tags?: string[];
|
|
30
35
|
}): Promise<void>;
|
|
31
36
|
}
|
|
32
37
|
//# sourceMappingURL=IncomingTransactionHelper.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAIxE,OAAO,YAAY,eAAe;
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAIxE,OAAO,YAAY,eAAe;AAElC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qBAAW;AA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EACX,UAAU,EACV,IAAI,GACL,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA2HlE"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AccountsController } from "@metamask/accounts-controller";
|
|
3
3
|
import EventEmitter from "events";
|
|
4
|
+
import type { TransactionControllerMessenger } from "../index.mjs";
|
|
4
5
|
import type { RemoteTransactionSource, TransactionMeta } from "../types.mjs";
|
|
5
6
|
export type IncomingTransactionOptions = {
|
|
7
|
+
client?: string;
|
|
6
8
|
includeTokenTransfers?: boolean;
|
|
7
9
|
isEnabled?: () => boolean;
|
|
8
10
|
queryEntireHistory?: boolean;
|
|
@@ -11,12 +13,14 @@ export type IncomingTransactionOptions = {
|
|
|
11
13
|
export declare class IncomingTransactionHelper {
|
|
12
14
|
#private;
|
|
13
15
|
hub: EventEmitter;
|
|
14
|
-
constructor({ getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }: {
|
|
16
|
+
constructor({ client, getCache, getCurrentAccount, getLocalTransactions, includeTokenTransfers, isEnabled, messenger, queryEntireHistory, remoteTransactionSource, trimTransactions, updateCache, updateTransactions, }: {
|
|
17
|
+
client?: string;
|
|
15
18
|
getCache: () => Record<string, unknown>;
|
|
16
19
|
getCurrentAccount: () => ReturnType<AccountsController['getSelectedAccount']>;
|
|
17
20
|
getLocalTransactions: () => TransactionMeta[];
|
|
18
21
|
includeTokenTransfers?: boolean;
|
|
19
22
|
isEnabled?: () => boolean;
|
|
23
|
+
messenger: TransactionControllerMessenger;
|
|
20
24
|
queryEntireHistory?: boolean;
|
|
21
25
|
remoteTransactionSource: RemoteTransactionSource;
|
|
22
26
|
trimTransactions: (transactions: TransactionMeta[]) => TransactionMeta[];
|
|
@@ -25,8 +29,9 @@ export declare class IncomingTransactionHelper {
|
|
|
25
29
|
});
|
|
26
30
|
start(): void;
|
|
27
31
|
stop(): void;
|
|
28
|
-
update({ isInterval }?: {
|
|
32
|
+
update({ isInterval, tags, }?: {
|
|
29
33
|
isInterval?: boolean;
|
|
34
|
+
tags?: string[];
|
|
30
35
|
}): Promise<void>;
|
|
31
36
|
}
|
|
32
37
|
//# sourceMappingURL=IncomingTransactionHelper.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncomingTransactionHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAIxE,OAAO,YAAY,eAAe;
|
|
1
|
+
{"version":3,"file":"IncomingTransactionHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/IncomingTransactionHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAIxE,OAAO,YAAY,eAAe;AAElC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qBAAW;AAEzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAGzE,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,qBAAa,yBAAyB;;IACpC,GAAG,EAAE,YAAY,CAAC;gBAkCN,EACV,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,GACnB,EAAE;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