@metamask/transaction-controller 24.0.0 → 25.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -1
- package/dist/TransactionController.js +39 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +40 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2YXA3K67.mjs +62 -0
- package/dist/chunk-2YXA3K67.mjs.map +1 -0
- package/dist/chunk-3D3SA6PY.mjs +211 -0
- package/dist/chunk-3D3SA6PY.mjs.map +1 -0
- package/dist/chunk-4S25HUCL.js +46 -0
- package/dist/chunk-4S25HUCL.js.map +1 -0
- package/dist/chunk-5OQ373JS.js +211 -0
- package/dist/chunk-5OQ373JS.js.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-72OTU5ZW.mjs +2332 -0
- package/dist/chunk-72OTU5ZW.mjs.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7XPI7KU5.mjs +46 -0
- package/dist/chunk-7XPI7KU5.mjs.map +1 -0
- package/dist/chunk-BILEZLAT.js +182 -0
- package/dist/chunk-BILEZLAT.js.map +1 -0
- package/dist/chunk-CQBXHAYR.js +121 -0
- package/dist/chunk-CQBXHAYR.js.map +1 -0
- package/dist/chunk-CXXGL43K.js +85 -0
- package/dist/chunk-CXXGL43K.js.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTONMSFW.mjs +208 -0
- package/dist/chunk-DTONMSFW.mjs.map +1 -0
- package/dist/chunk-EEMJC7S7.mjs +182 -0
- package/dist/chunk-EEMJC7S7.mjs.map +1 -0
- package/dist/chunk-F3CMU2DM.js +170 -0
- package/dist/chunk-F3CMU2DM.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-ITDY6AIZ.js +127 -0
- package/dist/chunk-ITDY6AIZ.js.map +1 -0
- package/dist/chunk-IZI7FQIN.mjs +170 -0
- package/dist/chunk-IZI7FQIN.mjs.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-K26EBMGI.mjs +121 -0
- package/dist/chunk-K26EBMGI.mjs.map +1 -0
- package/dist/chunk-KFL2GGZC.mjs +48 -0
- package/dist/chunk-KFL2GGZC.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM4LTWRU.mjs +76 -0
- package/dist/chunk-NM4LTWRU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NRWEI43Q.js +320 -0
- package/dist/chunk-NRWEI43Q.js.map +1 -0
- package/dist/chunk-O7H2MC7R.js +62 -0
- package/dist/chunk-O7H2MC7R.js.map +1 -0
- package/dist/chunk-OF6NSLXF.mjs +90 -0
- package/dist/chunk-OF6NSLXF.mjs.map +1 -0
- package/dist/chunk-QDIYZX5V.js +2332 -0
- package/dist/chunk-QDIYZX5V.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-QPNEFZB3.js +208 -0
- package/dist/chunk-QPNEFZB3.js.map +1 -0
- package/dist/chunk-QSBIXUMB.mjs +242 -0
- package/dist/chunk-QSBIXUMB.mjs.map +1 -0
- package/dist/chunk-R7NJVDWN.js +48 -0
- package/dist/chunk-R7NJVDWN.js.map +1 -0
- package/dist/chunk-RQKICZYP.js +137 -0
- package/dist/chunk-RQKICZYP.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-TXVH44HM.js +90 -0
- package/dist/chunk-TXVH44HM.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VEREDMI2.mjs +85 -0
- package/dist/chunk-VEREDMI2.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-W3GAOR7Y.js +76 -0
- package/dist/chunk-W3GAOR7Y.js.map +1 -0
- package/dist/chunk-WXQZIUNW.js +242 -0
- package/dist/chunk-WXQZIUNW.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XKNFL657.mjs +137 -0
- package/dist/chunk-XKNFL657.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z3HHSD5I.mjs +127 -0
- package/dist/chunk-Z3HHSD5I.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/chunk-ZQFMTLZJ.mjs +320 -0
- package/dist/chunk-ZQFMTLZJ.mjs.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +11 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +12 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +57 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +236 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +10 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +5 -3
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +94 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts +16 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.js +9 -0
- package/dist/utils/layer1-gas-fee-flow.js.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.mjs +9 -0
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -160
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +22 -10
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/utils.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createModuleLogger,
|
|
3
|
+
projectLogger
|
|
4
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
5
|
+
import {
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet
|
|
10
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
11
|
+
|
|
12
|
+
// src/helpers/PendingTransactionTracker.ts
|
|
13
|
+
import { query } from "@metamask/controller-utils";
|
|
14
|
+
import EventEmitter from "events";
|
|
15
|
+
import { cloneDeep, merge } from "lodash";
|
|
16
|
+
var DROPPED_BLOCK_COUNT = 3;
|
|
17
|
+
var RECEIPT_STATUS_SUCCESS = "0x1";
|
|
18
|
+
var RECEIPT_STATUS_FAILURE = "0x0";
|
|
19
|
+
var MAX_RETRY_BLOCK_DISTANCE = 50;
|
|
20
|
+
var KNOWN_TRANSACTION_ERRORS = [
|
|
21
|
+
"replacement transaction underpriced",
|
|
22
|
+
"known transaction",
|
|
23
|
+
"gas price too low to replace",
|
|
24
|
+
"transaction with the same hash was already imported",
|
|
25
|
+
"gateway timeout",
|
|
26
|
+
"nonce too low"
|
|
27
|
+
];
|
|
28
|
+
var log = createModuleLogger(projectLogger, "pending-transactions");
|
|
29
|
+
var _approveTransaction, _blockTracker, _droppedBlockCountByHash, _getChainId, _getEthQuery, _getTransactions, _isResubmitEnabled, _listener, _getGlobalLock, _publishTransaction, _running, _beforeCheckPendingTransaction, _beforePublish, _start, start_fn, _onLatestBlock, onLatestBlock_fn, _checkTransactions, checkTransactions_fn, _resubmitTransactions, resubmitTransactions_fn, _isKnownTransactionError, isKnownTransactionError_fn, _resubmitTransaction, resubmitTransaction_fn, _isResubmitDue, isResubmitDue_fn, _checkTransaction, checkTransaction_fn, _onTransactionConfirmed, onTransactionConfirmed_fn, _isTransactionDropped, isTransactionDropped_fn, _isNonceTaken, isNonceTaken_fn, _getPendingTransactions, getPendingTransactions_fn, _warnTransaction, warnTransaction_fn, _failTransaction, failTransaction_fn, _dropTransaction, dropTransaction_fn, _updateTransaction, updateTransaction_fn, _getTransactionReceipt, getTransactionReceipt_fn, _getBlockByHash, getBlockByHash_fn, _getNetworkTransactionCount, getNetworkTransactionCount_fn, _getCurrentChainTransactions, getCurrentChainTransactions_fn;
|
|
30
|
+
var PendingTransactionTracker = class {
|
|
31
|
+
constructor({
|
|
32
|
+
approveTransaction,
|
|
33
|
+
blockTracker,
|
|
34
|
+
getChainId,
|
|
35
|
+
getEthQuery,
|
|
36
|
+
getTransactions,
|
|
37
|
+
isResubmitEnabled,
|
|
38
|
+
getGlobalLock,
|
|
39
|
+
publishTransaction,
|
|
40
|
+
hooks
|
|
41
|
+
}) {
|
|
42
|
+
__privateAdd(this, _start);
|
|
43
|
+
__privateAdd(this, _onLatestBlock);
|
|
44
|
+
__privateAdd(this, _checkTransactions);
|
|
45
|
+
__privateAdd(this, _resubmitTransactions);
|
|
46
|
+
__privateAdd(this, _isKnownTransactionError);
|
|
47
|
+
__privateAdd(this, _resubmitTransaction);
|
|
48
|
+
__privateAdd(this, _isResubmitDue);
|
|
49
|
+
__privateAdd(this, _checkTransaction);
|
|
50
|
+
__privateAdd(this, _onTransactionConfirmed);
|
|
51
|
+
__privateAdd(this, _isTransactionDropped);
|
|
52
|
+
__privateAdd(this, _isNonceTaken);
|
|
53
|
+
__privateAdd(this, _getPendingTransactions);
|
|
54
|
+
__privateAdd(this, _warnTransaction);
|
|
55
|
+
__privateAdd(this, _failTransaction);
|
|
56
|
+
__privateAdd(this, _dropTransaction);
|
|
57
|
+
__privateAdd(this, _updateTransaction);
|
|
58
|
+
__privateAdd(this, _getTransactionReceipt);
|
|
59
|
+
__privateAdd(this, _getBlockByHash);
|
|
60
|
+
__privateAdd(this, _getNetworkTransactionCount);
|
|
61
|
+
__privateAdd(this, _getCurrentChainTransactions);
|
|
62
|
+
__privateAdd(this, _approveTransaction, void 0);
|
|
63
|
+
__privateAdd(this, _blockTracker, void 0);
|
|
64
|
+
__privateAdd(this, _droppedBlockCountByHash, void 0);
|
|
65
|
+
__privateAdd(this, _getChainId, void 0);
|
|
66
|
+
__privateAdd(this, _getEthQuery, void 0);
|
|
67
|
+
__privateAdd(this, _getTransactions, void 0);
|
|
68
|
+
__privateAdd(this, _isResubmitEnabled, void 0);
|
|
69
|
+
// TODO: Replace `any` with type
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
__privateAdd(this, _listener, void 0);
|
|
72
|
+
__privateAdd(this, _getGlobalLock, void 0);
|
|
73
|
+
__privateAdd(this, _publishTransaction, void 0);
|
|
74
|
+
__privateAdd(this, _running, void 0);
|
|
75
|
+
__privateAdd(this, _beforeCheckPendingTransaction, void 0);
|
|
76
|
+
__privateAdd(this, _beforePublish, void 0);
|
|
77
|
+
this.startIfPendingTransactions = () => {
|
|
78
|
+
const pendingTransactions = __privateMethod(this, _getPendingTransactions, getPendingTransactions_fn).call(this);
|
|
79
|
+
if (pendingTransactions.length) {
|
|
80
|
+
__privateMethod(this, _start, start_fn).call(this);
|
|
81
|
+
} else {
|
|
82
|
+
this.stop();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
this.hub = new EventEmitter();
|
|
86
|
+
__privateSet(this, _approveTransaction, approveTransaction);
|
|
87
|
+
__privateSet(this, _blockTracker, blockTracker);
|
|
88
|
+
__privateSet(this, _droppedBlockCountByHash, /* @__PURE__ */ new Map());
|
|
89
|
+
__privateSet(this, _getChainId, getChainId);
|
|
90
|
+
__privateSet(this, _getEthQuery, getEthQuery);
|
|
91
|
+
__privateSet(this, _getTransactions, getTransactions);
|
|
92
|
+
__privateSet(this, _isResubmitEnabled, isResubmitEnabled ?? true);
|
|
93
|
+
__privateSet(this, _listener, __privateMethod(this, _onLatestBlock, onLatestBlock_fn).bind(this));
|
|
94
|
+
__privateSet(this, _getGlobalLock, getGlobalLock);
|
|
95
|
+
__privateSet(this, _publishTransaction, publishTransaction);
|
|
96
|
+
__privateSet(this, _running, false);
|
|
97
|
+
__privateSet(this, _beforePublish, hooks?.beforePublish ?? (() => true));
|
|
98
|
+
__privateSet(this, _beforeCheckPendingTransaction, hooks?.beforeCheckPendingTransaction ?? (() => true));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Force checks the network if the given transaction is confirmed and updates it's status.
|
|
102
|
+
*
|
|
103
|
+
* @param txMeta - The transaction to check
|
|
104
|
+
*/
|
|
105
|
+
async forceCheckTransaction(txMeta) {
|
|
106
|
+
const releaseLock = await __privateGet(this, _getGlobalLock).call(this);
|
|
107
|
+
try {
|
|
108
|
+
await __privateMethod(this, _checkTransaction, checkTransaction_fn).call(this, txMeta);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
log("Failed to check transaction", error);
|
|
111
|
+
} finally {
|
|
112
|
+
releaseLock();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
stop() {
|
|
116
|
+
if (!__privateGet(this, _running)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
__privateGet(this, _blockTracker).removeListener("latest", __privateGet(this, _listener));
|
|
120
|
+
__privateSet(this, _running, false);
|
|
121
|
+
log("Stopped polling");
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
_approveTransaction = new WeakMap();
|
|
125
|
+
_blockTracker = new WeakMap();
|
|
126
|
+
_droppedBlockCountByHash = new WeakMap();
|
|
127
|
+
_getChainId = new WeakMap();
|
|
128
|
+
_getEthQuery = new WeakMap();
|
|
129
|
+
_getTransactions = new WeakMap();
|
|
130
|
+
_isResubmitEnabled = new WeakMap();
|
|
131
|
+
_listener = new WeakMap();
|
|
132
|
+
_getGlobalLock = new WeakMap();
|
|
133
|
+
_publishTransaction = new WeakMap();
|
|
134
|
+
_running = new WeakMap();
|
|
135
|
+
_beforeCheckPendingTransaction = new WeakMap();
|
|
136
|
+
_beforePublish = new WeakMap();
|
|
137
|
+
_start = new WeakSet();
|
|
138
|
+
start_fn = function() {
|
|
139
|
+
if (__privateGet(this, _running)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
__privateGet(this, _blockTracker).on("latest", __privateGet(this, _listener));
|
|
143
|
+
__privateSet(this, _running, true);
|
|
144
|
+
log("Started polling");
|
|
145
|
+
};
|
|
146
|
+
_onLatestBlock = new WeakSet();
|
|
147
|
+
onLatestBlock_fn = async function(latestBlockNumber) {
|
|
148
|
+
const releaseLock = await __privateGet(this, _getGlobalLock).call(this);
|
|
149
|
+
try {
|
|
150
|
+
await __privateMethod(this, _checkTransactions, checkTransactions_fn).call(this);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
log("Failed to check transactions", error);
|
|
153
|
+
} finally {
|
|
154
|
+
releaseLock();
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
await __privateMethod(this, _resubmitTransactions, resubmitTransactions_fn).call(this, latestBlockNumber);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
log("Failed to resubmit transactions", error);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
_checkTransactions = new WeakSet();
|
|
163
|
+
checkTransactions_fn = async function() {
|
|
164
|
+
log("Checking transactions");
|
|
165
|
+
const pendingTransactions = __privateMethod(this, _getPendingTransactions, getPendingTransactions_fn).call(this);
|
|
166
|
+
if (!pendingTransactions.length) {
|
|
167
|
+
log("No pending transactions to check");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
log("Found pending transactions to check", {
|
|
171
|
+
count: pendingTransactions.length,
|
|
172
|
+
ids: pendingTransactions.map((tx) => tx.id)
|
|
173
|
+
});
|
|
174
|
+
await Promise.all(
|
|
175
|
+
pendingTransactions.map((tx) => __privateMethod(this, _checkTransaction, checkTransaction_fn).call(this, tx))
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
_resubmitTransactions = new WeakSet();
|
|
179
|
+
resubmitTransactions_fn = async function(latestBlockNumber) {
|
|
180
|
+
if (!__privateGet(this, _isResubmitEnabled) || !__privateGet(this, _running)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
log("Resubmitting transactions");
|
|
184
|
+
const pendingTransactions = __privateMethod(this, _getPendingTransactions, getPendingTransactions_fn).call(this);
|
|
185
|
+
if (!pendingTransactions.length) {
|
|
186
|
+
log("No pending transactions to resubmit");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
log("Found pending transactions to resubmit", {
|
|
190
|
+
count: pendingTransactions.length,
|
|
191
|
+
ids: pendingTransactions.map((tx) => tx.id)
|
|
192
|
+
});
|
|
193
|
+
for (const txMeta of pendingTransactions) {
|
|
194
|
+
try {
|
|
195
|
+
await __privateMethod(this, _resubmitTransaction, resubmitTransaction_fn).call(this, txMeta, latestBlockNumber);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
const errorMessage = error.value?.message?.toLowerCase() || error.message.toLowerCase();
|
|
198
|
+
if (__privateMethod(this, _isKnownTransactionError, isKnownTransactionError_fn).call(this, errorMessage)) {
|
|
199
|
+
log("Ignoring known transaction error", errorMessage);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
__privateMethod(this, _warnTransaction, warnTransaction_fn).call(this, txMeta, error.message, "There was an error when resubmitting this transaction.");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
_isKnownTransactionError = new WeakSet();
|
|
207
|
+
isKnownTransactionError_fn = function(errorMessage) {
|
|
208
|
+
return KNOWN_TRANSACTION_ERRORS.some(
|
|
209
|
+
(knownError) => errorMessage.includes(knownError)
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
_resubmitTransaction = new WeakSet();
|
|
213
|
+
resubmitTransaction_fn = async function(txMeta, latestBlockNumber) {
|
|
214
|
+
if (!__privateMethod(this, _isResubmitDue, isResubmitDue_fn).call(this, txMeta, latestBlockNumber)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const { rawTx } = txMeta;
|
|
218
|
+
if (!__privateGet(this, _beforePublish).call(this, txMeta)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (!rawTx?.length) {
|
|
222
|
+
log("Approving transaction as no raw value");
|
|
223
|
+
await __privateGet(this, _approveTransaction).call(this, txMeta.id);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const ethQuery = __privateGet(this, _getEthQuery).call(this, txMeta.networkClientId);
|
|
227
|
+
await __privateGet(this, _publishTransaction).call(this, ethQuery, rawTx);
|
|
228
|
+
const retryCount = (txMeta.retryCount ?? 0) + 1;
|
|
229
|
+
__privateMethod(this, _updateTransaction, updateTransaction_fn).call(this, merge({}, txMeta, { retryCount }), "PendingTransactionTracker:transaction-retry - Retry count increased");
|
|
230
|
+
};
|
|
231
|
+
_isResubmitDue = new WeakSet();
|
|
232
|
+
isResubmitDue_fn = function(txMeta, latestBlockNumber) {
|
|
233
|
+
const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);
|
|
234
|
+
if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {
|
|
235
|
+
txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;
|
|
236
|
+
__privateMethod(this, _updateTransaction, updateTransaction_fn).call(this, txMetaWithFirstRetryBlockNumber, "PendingTransactionTracker:#isResubmitDue - First retry block number set");
|
|
237
|
+
}
|
|
238
|
+
const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;
|
|
239
|
+
const blocksSinceFirstRetry = Number.parseInt(latestBlockNumber, 16) - Number.parseInt(firstRetryBlockNumber, 16);
|
|
240
|
+
const retryCount = txMeta.retryCount || 0;
|
|
241
|
+
const requiredBlocksSinceFirstRetry = Math.min(
|
|
242
|
+
MAX_RETRY_BLOCK_DISTANCE,
|
|
243
|
+
Math.pow(2, retryCount)
|
|
244
|
+
);
|
|
245
|
+
return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;
|
|
246
|
+
};
|
|
247
|
+
_checkTransaction = new WeakSet();
|
|
248
|
+
checkTransaction_fn = async function(txMeta) {
|
|
249
|
+
const { hash, id } = txMeta;
|
|
250
|
+
if (!hash && __privateGet(this, _beforeCheckPendingTransaction).call(this, txMeta)) {
|
|
251
|
+
const error = new Error(
|
|
252
|
+
"We had an error while submitting this transaction, please try again."
|
|
253
|
+
);
|
|
254
|
+
error.name = "NoTxHashError";
|
|
255
|
+
__privateMethod(this, _failTransaction, failTransaction_fn).call(this, txMeta, error);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (__privateMethod(this, _isNonceTaken, isNonceTaken_fn).call(this, txMeta)) {
|
|
259
|
+
log("Nonce already taken", id);
|
|
260
|
+
__privateMethod(this, _dropTransaction, dropTransaction_fn).call(this, txMeta);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const receipt = await __privateMethod(this, _getTransactionReceipt, getTransactionReceipt_fn).call(this, hash);
|
|
265
|
+
const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;
|
|
266
|
+
const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;
|
|
267
|
+
if (isFailure) {
|
|
268
|
+
log("Transaction receipt has failed status");
|
|
269
|
+
__privateMethod(this, _failTransaction, failTransaction_fn).call(this, txMeta, new Error("Transaction dropped or replaced"));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const { blockNumber, blockHash } = receipt || {};
|
|
273
|
+
if (isSuccess && blockNumber && blockHash) {
|
|
274
|
+
await __privateMethod(this, _onTransactionConfirmed, onTransactionConfirmed_fn).call(this, txMeta, {
|
|
275
|
+
...receipt,
|
|
276
|
+
blockNumber,
|
|
277
|
+
blockHash
|
|
278
|
+
});
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
} catch (error) {
|
|
282
|
+
log("Failed to check transaction", id, error);
|
|
283
|
+
__privateMethod(this, _warnTransaction, warnTransaction_fn).call(this, txMeta, error.message, "There was a problem loading this transaction.");
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (await __privateMethod(this, _isTransactionDropped, isTransactionDropped_fn).call(this, txMeta)) {
|
|
287
|
+
__privateMethod(this, _dropTransaction, dropTransaction_fn).call(this, txMeta);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
_onTransactionConfirmed = new WeakSet();
|
|
291
|
+
onTransactionConfirmed_fn = async function(txMeta, receipt) {
|
|
292
|
+
const { id } = txMeta;
|
|
293
|
+
const { blockHash } = receipt;
|
|
294
|
+
log("Transaction confirmed", id);
|
|
295
|
+
const { baseFeePerGas, timestamp: blockTimestamp } = await __privateMethod(this, _getBlockByHash, getBlockByHash_fn).call(this, blockHash, false);
|
|
296
|
+
const updatedTxMeta = cloneDeep(txMeta);
|
|
297
|
+
updatedTxMeta.baseFeePerGas = baseFeePerGas;
|
|
298
|
+
updatedTxMeta.blockTimestamp = blockTimestamp;
|
|
299
|
+
updatedTxMeta.status = "confirmed" /* confirmed */;
|
|
300
|
+
updatedTxMeta.txParams = {
|
|
301
|
+
...updatedTxMeta.txParams,
|
|
302
|
+
gasUsed: receipt.gasUsed
|
|
303
|
+
};
|
|
304
|
+
updatedTxMeta.txReceipt = receipt;
|
|
305
|
+
updatedTxMeta.verifiedOnBlockchain = true;
|
|
306
|
+
__privateMethod(this, _updateTransaction, updateTransaction_fn).call(this, updatedTxMeta, "PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed");
|
|
307
|
+
this.hub.emit("transaction-confirmed", updatedTxMeta);
|
|
308
|
+
};
|
|
309
|
+
_isTransactionDropped = new WeakSet();
|
|
310
|
+
isTransactionDropped_fn = async function(txMeta) {
|
|
311
|
+
const {
|
|
312
|
+
hash,
|
|
313
|
+
id,
|
|
314
|
+
txParams: { nonce, from }
|
|
315
|
+
} = txMeta;
|
|
316
|
+
if (!nonce || !hash) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
const networkNextNonceHex = await __privateMethod(this, _getNetworkTransactionCount, getNetworkTransactionCount_fn).call(this, from);
|
|
320
|
+
const networkNextNonceNumber = parseInt(networkNextNonceHex, 16);
|
|
321
|
+
const nonceNumber = parseInt(nonce, 16);
|
|
322
|
+
if (nonceNumber >= networkNextNonceNumber) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
let droppedBlockCount = __privateGet(this, _droppedBlockCountByHash).get(hash);
|
|
326
|
+
if (droppedBlockCount === void 0) {
|
|
327
|
+
droppedBlockCount = 0;
|
|
328
|
+
__privateGet(this, _droppedBlockCountByHash).set(hash, droppedBlockCount);
|
|
329
|
+
}
|
|
330
|
+
if (droppedBlockCount < DROPPED_BLOCK_COUNT) {
|
|
331
|
+
log("Incrementing dropped block count", { id, droppedBlockCount });
|
|
332
|
+
__privateGet(this, _droppedBlockCountByHash).set(hash, droppedBlockCount + 1);
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
log("Hit dropped block count", id);
|
|
336
|
+
__privateGet(this, _droppedBlockCountByHash).delete(hash);
|
|
337
|
+
return true;
|
|
338
|
+
};
|
|
339
|
+
_isNonceTaken = new WeakSet();
|
|
340
|
+
isNonceTaken_fn = function(txMeta) {
|
|
341
|
+
const { id, txParams } = txMeta;
|
|
342
|
+
return __privateMethod(this, _getCurrentChainTransactions, getCurrentChainTransactions_fn).call(this).some(
|
|
343
|
+
(tx) => tx.id !== id && tx.txParams.from === txParams.from && tx.status === "confirmed" /* confirmed */ && tx.txParams.nonce === txParams.nonce && tx.type !== "incoming" /* incoming */
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
_getPendingTransactions = new WeakSet();
|
|
347
|
+
getPendingTransactions_fn = function() {
|
|
348
|
+
return __privateMethod(this, _getCurrentChainTransactions, getCurrentChainTransactions_fn).call(this).filter(
|
|
349
|
+
(tx) => tx.status === "submitted" /* submitted */ && !tx.verifiedOnBlockchain && !tx.isUserOperation
|
|
350
|
+
);
|
|
351
|
+
};
|
|
352
|
+
_warnTransaction = new WeakSet();
|
|
353
|
+
warnTransaction_fn = function(txMeta, error, message) {
|
|
354
|
+
__privateMethod(this, _updateTransaction, updateTransaction_fn).call(this, {
|
|
355
|
+
...txMeta,
|
|
356
|
+
warning: { error, message }
|
|
357
|
+
}, "PendingTransactionTracker:#warnTransaction - Warning added");
|
|
358
|
+
};
|
|
359
|
+
_failTransaction = new WeakSet();
|
|
360
|
+
failTransaction_fn = function(txMeta, error) {
|
|
361
|
+
log("Transaction failed", txMeta.id, error);
|
|
362
|
+
this.hub.emit("transaction-failed", txMeta, error);
|
|
363
|
+
};
|
|
364
|
+
_dropTransaction = new WeakSet();
|
|
365
|
+
dropTransaction_fn = function(txMeta) {
|
|
366
|
+
log("Transaction dropped", txMeta.id);
|
|
367
|
+
this.hub.emit("transaction-dropped", txMeta);
|
|
368
|
+
};
|
|
369
|
+
_updateTransaction = new WeakSet();
|
|
370
|
+
updateTransaction_fn = function(txMeta, note) {
|
|
371
|
+
this.hub.emit("transaction-updated", txMeta, note);
|
|
372
|
+
};
|
|
373
|
+
_getTransactionReceipt = new WeakSet();
|
|
374
|
+
getTransactionReceipt_fn = async function(txHash) {
|
|
375
|
+
return await query(__privateGet(this, _getEthQuery).call(this), "getTransactionReceipt", [txHash]);
|
|
376
|
+
};
|
|
377
|
+
_getBlockByHash = new WeakSet();
|
|
378
|
+
getBlockByHash_fn = async function(blockHash, includeTransactionDetails) {
|
|
379
|
+
return await query(__privateGet(this, _getEthQuery).call(this), "getBlockByHash", [
|
|
380
|
+
blockHash,
|
|
381
|
+
includeTransactionDetails
|
|
382
|
+
]);
|
|
383
|
+
};
|
|
384
|
+
_getNetworkTransactionCount = new WeakSet();
|
|
385
|
+
getNetworkTransactionCount_fn = async function(address) {
|
|
386
|
+
return await query(__privateGet(this, _getEthQuery).call(this), "getTransactionCount", [address]);
|
|
387
|
+
};
|
|
388
|
+
_getCurrentChainTransactions = new WeakSet();
|
|
389
|
+
getCurrentChainTransactions_fn = function() {
|
|
390
|
+
const currentChainId = __privateGet(this, _getChainId).call(this);
|
|
391
|
+
return __privateGet(this, _getTransactions).call(this).filter(
|
|
392
|
+
(tx) => tx.chainId === currentChainId
|
|
393
|
+
);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export {
|
|
397
|
+
PendingTransactionTracker
|
|
398
|
+
};
|
|
399
|
+
//# sourceMappingURL=chunk-JRQHIBG5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/PendingTransactionTracker.ts"],"sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n BlockTracker,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport EventEmitter from 'events';\nimport { cloneDeep, merge } from 'lodash';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionReceipt } from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\n\n/**\n * We wait this many blocks before emitting a 'transaction-dropped' event\n * This is because we could be talking to a node that is out of sync\n */\nconst DROPPED_BLOCK_COUNT = 3;\n\nconst RECEIPT_STATUS_SUCCESS = '0x1';\nconst RECEIPT_STATUS_FAILURE = '0x0';\nconst MAX_RETRY_BLOCK_DISTANCE = 50;\n\nconst KNOWN_TRANSACTION_ERRORS = [\n 'replacement transaction underpriced',\n 'known transaction',\n 'gas price too low to replace',\n 'transaction with the same hash was already imported',\n 'gateway timeout',\n 'nonce too low',\n];\n\nconst log = createModuleLogger(projectLogger, 'pending-transactions');\n\ntype SuccessfulTransactionReceipt = TransactionReceipt & {\n blockNumber: string;\n blockHash: string;\n};\n\ntype Events = {\n 'transaction-confirmed': [txMeta: TransactionMeta];\n 'transaction-dropped': [txMeta: TransactionMeta];\n 'transaction-failed': [txMeta: TransactionMeta, error: Error];\n 'transaction-updated': [txMeta: TransactionMeta, note: string];\n};\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PendingTransactionTrackerEventEmitter extends EventEmitter {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): this;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n}\n\nexport class PendingTransactionTracker {\n hub: PendingTransactionTrackerEventEmitter;\n\n #approveTransaction: (transactionId: string) => Promise<void>;\n\n #blockTracker: BlockTracker;\n\n #droppedBlockCountByHash: Map<string, number>;\n\n #getChainId: () => string;\n\n #getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n\n #getTransactions: () => TransactionMeta[];\n\n #isResubmitEnabled: boolean;\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #listener: any;\n\n #getGlobalLock: () => Promise<() => void>;\n\n #publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n\n #running: boolean;\n\n #beforeCheckPendingTransaction: (transactionMeta: TransactionMeta) => boolean;\n\n #beforePublish: (transactionMeta: TransactionMeta) => boolean;\n\n constructor({\n approveTransaction,\n blockTracker,\n getChainId,\n getEthQuery,\n getTransactions,\n isResubmitEnabled,\n getGlobalLock,\n publishTransaction,\n hooks,\n }: {\n approveTransaction: (transactionId: string) => Promise<void>;\n blockTracker: BlockTracker;\n getChainId: () => string;\n getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n getTransactions: () => TransactionMeta[];\n isResubmitEnabled?: boolean;\n getGlobalLock: () => Promise<() => void>;\n publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n hooks?: {\n beforeCheckPendingTransaction?: (\n transactionMeta: TransactionMeta,\n ) => boolean;\n beforePublish?: (transactionMeta: TransactionMeta) => boolean;\n };\n }) {\n this.hub = new EventEmitter() as PendingTransactionTrackerEventEmitter;\n\n this.#approveTransaction = approveTransaction;\n this.#blockTracker = blockTracker;\n this.#droppedBlockCountByHash = new Map();\n this.#getChainId = getChainId;\n this.#getEthQuery = getEthQuery;\n this.#getTransactions = getTransactions;\n this.#isResubmitEnabled = isResubmitEnabled ?? true;\n this.#listener = this.#onLatestBlock.bind(this);\n this.#getGlobalLock = getGlobalLock;\n this.#publishTransaction = publishTransaction;\n this.#running = false;\n this.#beforePublish = hooks?.beforePublish ?? (() => true);\n this.#beforeCheckPendingTransaction =\n hooks?.beforeCheckPendingTransaction ?? (() => true);\n }\n\n startIfPendingTransactions = () => {\n const pendingTransactions = this.#getPendingTransactions();\n\n if (pendingTransactions.length) {\n this.#start();\n } else {\n this.stop();\n }\n };\n\n /**\n * Force checks the network if the given transaction is confirmed and updates it's status.\n *\n * @param txMeta - The transaction to check\n */\n async forceCheckTransaction(txMeta: TransactionMeta) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransaction(txMeta);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transaction', error);\n } finally {\n releaseLock();\n }\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n this.#blockTracker.on('latest', this.#listener);\n this.#running = true;\n\n log('Started polling');\n }\n\n stop() {\n if (!this.#running) {\n return;\n }\n\n this.#blockTracker.removeListener('latest', this.#listener);\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onLatestBlock(latestBlockNumber: string) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransactions();\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transactions', error);\n } finally {\n releaseLock();\n }\n\n try {\n await this.#resubmitTransactions(latestBlockNumber);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to resubmit transactions', error);\n }\n }\n\n async #checkTransactions() {\n log('Checking transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to check');\n return;\n }\n\n log('Found pending transactions to check', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n await Promise.all(\n pendingTransactions.map((tx) => this.#checkTransaction(tx)),\n );\n }\n\n async #resubmitTransactions(latestBlockNumber: string) {\n if (!this.#isResubmitEnabled || !this.#running) {\n return;\n }\n\n log('Resubmitting transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to resubmit');\n return;\n }\n\n log('Found pending transactions to resubmit', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n for (const txMeta of pendingTransactions) {\n try {\n await this.#resubmitTransaction(txMeta, latestBlockNumber);\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n /* istanbul ignore next */\n const errorMessage =\n error.value?.message?.toLowerCase() || error.message.toLowerCase();\n\n if (this.#isKnownTransactionError(errorMessage)) {\n log('Ignoring known transaction error', errorMessage);\n return;\n }\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was an error when resubmitting this transaction.',\n );\n }\n }\n }\n\n #isKnownTransactionError(errorMessage: string) {\n return KNOWN_TRANSACTION_ERRORS.some((knownError) =>\n errorMessage.includes(knownError),\n );\n }\n\n async #resubmitTransaction(\n txMeta: TransactionMeta,\n latestBlockNumber: string,\n ) {\n if (!this.#isResubmitDue(txMeta, latestBlockNumber)) {\n return;\n }\n\n const { rawTx } = txMeta;\n\n if (!this.#beforePublish(txMeta)) {\n return;\n }\n\n if (!rawTx?.length) {\n log('Approving transaction as no raw value');\n await this.#approveTransaction(txMeta.id);\n return;\n }\n\n const ethQuery = this.#getEthQuery(txMeta.networkClientId);\n await this.#publishTransaction(ethQuery, rawTx);\n\n const retryCount = (txMeta.retryCount ?? 0) + 1;\n\n this.#updateTransaction(\n merge({}, txMeta, { retryCount }),\n 'PendingTransactionTracker:transaction-retry - Retry count increased',\n );\n }\n\n #isResubmitDue(txMeta: TransactionMeta, latestBlockNumber: string): boolean {\n const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);\n\n if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {\n txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;\n\n this.#updateTransaction(\n txMetaWithFirstRetryBlockNumber,\n 'PendingTransactionTracker:#isResubmitDue - First retry block number set',\n );\n }\n\n const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;\n\n const blocksSinceFirstRetry =\n Number.parseInt(latestBlockNumber, 16) -\n Number.parseInt(firstRetryBlockNumber, 16);\n\n const retryCount = txMeta.retryCount || 0;\n\n // Exponential backoff to limit retries at publishing\n // Capped at ~15 minutes between retries\n const requiredBlocksSinceFirstRetry = Math.min(\n MAX_RETRY_BLOCK_DISTANCE,\n Math.pow(2, retryCount),\n );\n\n return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;\n }\n\n async #checkTransaction(txMeta: TransactionMeta) {\n const { hash, id } = txMeta;\n\n if (!hash && this.#beforeCheckPendingTransaction(txMeta)) {\n const error = new Error(\n 'We had an error while submitting this transaction, please try again.',\n );\n\n error.name = 'NoTxHashError';\n\n this.#failTransaction(txMeta, error);\n\n return;\n }\n\n if (this.#isNonceTaken(txMeta)) {\n log('Nonce already taken', id);\n this.#dropTransaction(txMeta);\n return;\n }\n\n try {\n const receipt = await this.#getTransactionReceipt(hash);\n const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;\n const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;\n\n if (isFailure) {\n log('Transaction receipt has failed status');\n\n this.#failTransaction(\n txMeta,\n new Error('Transaction dropped or replaced'),\n );\n\n return;\n }\n\n const { blockNumber, blockHash } = receipt || {};\n\n if (isSuccess && blockNumber && blockHash) {\n await this.#onTransactionConfirmed(txMeta, {\n ...receipt,\n blockNumber,\n blockHash,\n });\n\n return;\n }\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n log('Failed to check transaction', id, error);\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was a problem loading this transaction.',\n );\n\n return;\n }\n\n if (await this.#isTransactionDropped(txMeta)) {\n this.#dropTransaction(txMeta);\n }\n }\n\n async #onTransactionConfirmed(\n txMeta: TransactionMeta,\n receipt: SuccessfulTransactionReceipt,\n ) {\n const { id } = txMeta;\n const { blockHash } = receipt;\n\n log('Transaction confirmed', id);\n\n const { baseFeePerGas, timestamp: blockTimestamp } =\n await this.#getBlockByHash(blockHash, false);\n\n const updatedTxMeta = cloneDeep(txMeta);\n updatedTxMeta.baseFeePerGas = baseFeePerGas;\n updatedTxMeta.blockTimestamp = blockTimestamp;\n updatedTxMeta.status = TransactionStatus.confirmed;\n updatedTxMeta.txParams = {\n ...updatedTxMeta.txParams,\n gasUsed: receipt.gasUsed,\n };\n updatedTxMeta.txReceipt = receipt;\n updatedTxMeta.verifiedOnBlockchain = true;\n\n this.#updateTransaction(\n updatedTxMeta,\n 'PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed',\n );\n\n this.hub.emit('transaction-confirmed', updatedTxMeta);\n }\n\n async #isTransactionDropped(txMeta: TransactionMeta) {\n const {\n hash,\n id,\n txParams: { nonce, from },\n } = txMeta;\n\n /* istanbul ignore next */\n if (!nonce || !hash) {\n return false;\n }\n\n const networkNextNonceHex = await this.#getNetworkTransactionCount(from);\n const networkNextNonceNumber = parseInt(networkNextNonceHex, 16);\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber >= networkNextNonceNumber) {\n return false;\n }\n\n let droppedBlockCount = this.#droppedBlockCountByHash.get(hash);\n\n if (droppedBlockCount === undefined) {\n droppedBlockCount = 0;\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount);\n }\n\n if (droppedBlockCount < DROPPED_BLOCK_COUNT) {\n log('Incrementing dropped block count', { id, droppedBlockCount });\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount + 1);\n return false;\n }\n\n log('Hit dropped block count', id);\n\n this.#droppedBlockCountByHash.delete(hash);\n return true;\n }\n\n #isNonceTaken(txMeta: TransactionMeta): boolean {\n const { id, txParams } = txMeta;\n\n return this.#getCurrentChainTransactions().some(\n (tx) =>\n tx.id !== id &&\n tx.txParams.from === txParams.from &&\n tx.status === TransactionStatus.confirmed &&\n tx.txParams.nonce === txParams.nonce &&\n tx.type !== TransactionType.incoming,\n );\n }\n\n #getPendingTransactions(): TransactionMeta[] {\n return this.#getCurrentChainTransactions().filter(\n (tx) =>\n tx.status === TransactionStatus.submitted &&\n !tx.verifiedOnBlockchain &&\n !tx.isUserOperation,\n );\n }\n\n #warnTransaction(txMeta: TransactionMeta, error: string, message: string) {\n this.#updateTransaction(\n {\n ...txMeta,\n warning: { error, message },\n },\n 'PendingTransactionTracker:#warnTransaction - Warning added',\n );\n }\n\n #failTransaction(txMeta: TransactionMeta, error: Error) {\n log('Transaction failed', txMeta.id, error);\n this.hub.emit('transaction-failed', txMeta, error);\n }\n\n #dropTransaction(txMeta: TransactionMeta) {\n log('Transaction dropped', txMeta.id);\n this.hub.emit('transaction-dropped', txMeta);\n }\n\n #updateTransaction(txMeta: TransactionMeta, note: string) {\n this.hub.emit('transaction-updated', txMeta, note);\n }\n\n async #getTransactionReceipt(\n txHash?: string,\n ): Promise<TransactionReceipt | undefined> {\n return await query(this.#getEthQuery(), 'getTransactionReceipt', [txHash]);\n }\n\n async #getBlockByHash(\n blockHash: string,\n includeTransactionDetails: boolean,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n return await query(this.#getEthQuery(), 'getBlockByHash', [\n blockHash,\n includeTransactionDetails,\n ]);\n }\n\n async #getNetworkTransactionCount(address: string): Promise<string> {\n return await query(this.#getEthQuery(), 'getTransactionCount', [address]);\n }\n\n #getCurrentChainTransactions(): TransactionMeta[] {\n const currentChainId = this.#getChainId();\n\n return this.#getTransactions().filter(\n (tx) => tx.chainId === currentChainId,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,aAAa;AAMtB,OAAO,kBAAkB;AACzB,SAAS,WAAW,aAAa;AAUjC,IAAM,sBAAsB;AAE5B,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AAEjC,IAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAhCpE;AA0DO,IAAM,4BAAN,MAAgC;AAAA,EA+BrC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAeG;AA+CH;AAsBA,uBAAM;AAoBN,uBAAM;AAoBN,uBAAM;AA2CN;AAMA,uBAAM;AA+BN;AA8BA,uBAAM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BAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG,YAAY;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultGasFeeFlow
|
|
3
|
+
} from "./chunk-OF6NSLXF.mjs";
|
|
4
|
+
import {
|
|
5
|
+
projectLogger
|
|
6
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
7
|
+
import {
|
|
8
|
+
GasFeeEstimateLevel
|
|
9
|
+
} from "./chunk-NM4LTWRU.mjs";
|
|
10
|
+
import {
|
|
11
|
+
__privateAdd,
|
|
12
|
+
__privateMethod
|
|
13
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
14
|
+
|
|
15
|
+
// src/gas-flows/LineaGasFeeFlow.ts
|
|
16
|
+
import { ChainId, hexToBN, query, toHex } from "@metamask/controller-utils";
|
|
17
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
18
|
+
var log = createModuleLogger(projectLogger, "linea-gas-fee-flow");
|
|
19
|
+
var LINEA_CHAIN_IDS = [
|
|
20
|
+
ChainId["linea-mainnet"],
|
|
21
|
+
ChainId["linea-goerli"],
|
|
22
|
+
ChainId["linea-sepolia"]
|
|
23
|
+
];
|
|
24
|
+
var BASE_FEE_MULTIPLIERS = {
|
|
25
|
+
low: 1,
|
|
26
|
+
medium: 1.35,
|
|
27
|
+
high: 1.7
|
|
28
|
+
};
|
|
29
|
+
var PRIORITY_FEE_MULTIPLIERS = {
|
|
30
|
+
low: 1,
|
|
31
|
+
medium: 1.05,
|
|
32
|
+
high: 1.1
|
|
33
|
+
};
|
|
34
|
+
var _getLineaGasFees, getLineaGasFees_fn, _getLineaResponse, getLineaResponse_fn, _getValuesFromMultipliers, getValuesFromMultipliers_fn, _getMaxFees, getMaxFees_fn, _feesToString, feesToString_fn;
|
|
35
|
+
var LineaGasFeeFlow = class {
|
|
36
|
+
constructor() {
|
|
37
|
+
__privateAdd(this, _getLineaGasFees);
|
|
38
|
+
__privateAdd(this, _getLineaResponse);
|
|
39
|
+
__privateAdd(this, _getValuesFromMultipliers);
|
|
40
|
+
__privateAdd(this, _getMaxFees);
|
|
41
|
+
__privateAdd(this, _feesToString);
|
|
42
|
+
}
|
|
43
|
+
matchesTransaction(transactionMeta) {
|
|
44
|
+
return LINEA_CHAIN_IDS.includes(transactionMeta.chainId);
|
|
45
|
+
}
|
|
46
|
+
async getGasFees(request) {
|
|
47
|
+
try {
|
|
48
|
+
return await __privateMethod(this, _getLineaGasFees, getLineaGasFees_fn).call(this, request);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
log("Using default flow as fallback due to error", error);
|
|
51
|
+
return new DefaultGasFeeFlow().getGasFees(request);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
_getLineaGasFees = new WeakSet();
|
|
56
|
+
getLineaGasFees_fn = async function(request) {
|
|
57
|
+
const { ethQuery, transactionMeta } = request;
|
|
58
|
+
const lineaResponse = await __privateMethod(this, _getLineaResponse, getLineaResponse_fn).call(this, transactionMeta, ethQuery);
|
|
59
|
+
log("Received Linea response", lineaResponse);
|
|
60
|
+
const baseFees = __privateMethod(this, _getValuesFromMultipliers, getValuesFromMultipliers_fn).call(this, lineaResponse.baseFeePerGas, BASE_FEE_MULTIPLIERS);
|
|
61
|
+
log("Generated base fees", __privateMethod(this, _feesToString, feesToString_fn).call(this, baseFees));
|
|
62
|
+
const priorityFees = __privateMethod(this, _getValuesFromMultipliers, getValuesFromMultipliers_fn).call(this, lineaResponse.priorityFeePerGas, PRIORITY_FEE_MULTIPLIERS);
|
|
63
|
+
log("Generated priority fees", __privateMethod(this, _feesToString, feesToString_fn).call(this, priorityFees));
|
|
64
|
+
const maxFees = __privateMethod(this, _getMaxFees, getMaxFees_fn).call(this, baseFees, priorityFees);
|
|
65
|
+
log("Generated max fees", __privateMethod(this, _feesToString, feesToString_fn).call(this, maxFees));
|
|
66
|
+
const estimates = Object.values(GasFeeEstimateLevel).reduce(
|
|
67
|
+
(result, level) => ({
|
|
68
|
+
...result,
|
|
69
|
+
[level]: {
|
|
70
|
+
maxFeePerGas: toHex(maxFees[level]),
|
|
71
|
+
maxPriorityFeePerGas: toHex(priorityFees[level])
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
return { estimates };
|
|
77
|
+
};
|
|
78
|
+
_getLineaResponse = new WeakSet();
|
|
79
|
+
getLineaResponse_fn = function(transactionMeta, ethQuery) {
|
|
80
|
+
return query(ethQuery, "linea_estimateGas", [
|
|
81
|
+
{
|
|
82
|
+
from: transactionMeta.txParams.from,
|
|
83
|
+
to: transactionMeta.txParams.to,
|
|
84
|
+
value: transactionMeta.txParams.value,
|
|
85
|
+
input: transactionMeta.txParams.data,
|
|
86
|
+
// Required in request but no impact on response.
|
|
87
|
+
gasPrice: "0x100000000"
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
};
|
|
91
|
+
_getValuesFromMultipliers = new WeakSet();
|
|
92
|
+
getValuesFromMultipliers_fn = function(value, multipliers) {
|
|
93
|
+
const base = hexToBN(value);
|
|
94
|
+
const low = base.muln(multipliers.low);
|
|
95
|
+
const medium = base.muln(multipliers.medium);
|
|
96
|
+
const high = base.muln(multipliers.high);
|
|
97
|
+
return {
|
|
98
|
+
low,
|
|
99
|
+
medium,
|
|
100
|
+
high
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
_getMaxFees = new WeakSet();
|
|
104
|
+
getMaxFees_fn = function(baseFees, priorityFees) {
|
|
105
|
+
return {
|
|
106
|
+
low: baseFees.low.add(priorityFees.low),
|
|
107
|
+
medium: baseFees.medium.add(priorityFees.medium),
|
|
108
|
+
high: baseFees.high.add(priorityFees.high)
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
_feesToString = new WeakSet();
|
|
112
|
+
feesToString_fn = function(fees) {
|
|
113
|
+
return Object.values(GasFeeEstimateLevel).map(
|
|
114
|
+
(level) => fees[level].toString(10)
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
LineaGasFeeFlow
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=chunk-K26EBMGI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gas-flows/LineaGasFeeFlow.ts"],"sourcesContent":["import { ChainId, hexToBN, query, toHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel } from '../types';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\n\ntype LineaEstimateGasResponse = {\n baseFeePerGas: Hex;\n priorityFeePerGas: Hex;\n};\n\ntype FeesByLevel = {\n [key in GasFeeEstimateLevel]: BN;\n};\n\nconst log = createModuleLogger(projectLogger, 'linea-gas-fee-flow');\n\nconst LINEA_CHAIN_IDS: Hex[] = [\n ChainId['linea-mainnet'],\n ChainId['linea-goerli'],\n ChainId['linea-sepolia'],\n];\n\nconst BASE_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.35,\n high: 1.7,\n};\n\nconst PRIORITY_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.05,\n high: 1.1,\n};\n\n/**\n * Implementation of a gas fee flow specific to Linea networks that obtains gas fee estimates using:\n * - The `linea_estimateGas` RPC method to obtain the base fee and lowest priority fee.\n * - Static multipliers to increase the base and priority fees.\n */\nexport class LineaGasFeeFlow implements GasFeeFlow {\n matchesTransaction(transactionMeta: TransactionMeta): boolean {\n return LINEA_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getLineaGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n }\n\n async #getLineaGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { ethQuery, transactionMeta } = request;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n ethQuery,\n );\n\n log('Received Linea response', lineaResponse);\n\n const baseFees = this.#getValuesFromMultipliers(\n lineaResponse.baseFeePerGas,\n BASE_FEE_MULTIPLIERS,\n );\n\n log('Generated base fees', this.#feesToString(baseFees));\n\n const priorityFees = this.#getValuesFromMultipliers(\n lineaResponse.priorityFeePerGas,\n PRIORITY_FEE_MULTIPLIERS,\n );\n\n log('Generated priority fees', this.#feesToString(priorityFees));\n\n const maxFees = this.#getMaxFees(baseFees, priorityFees);\n\n log('Generated max fees', this.#feesToString(maxFees));\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: {\n maxFeePerGas: toHex(maxFees[level]),\n maxPriorityFeePerGas: toHex(priorityFees[level]),\n },\n }),\n {} as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getLineaResponse(\n transactionMeta: TransactionMeta,\n ethQuery: EthQuery,\n ): Promise<LineaEstimateGasResponse> {\n return query(ethQuery, 'linea_estimateGas', [\n {\n from: transactionMeta.txParams.from,\n to: transactionMeta.txParams.to,\n value: transactionMeta.txParams.value,\n input: transactionMeta.txParams.data,\n // Required in request but no impact on response.\n gasPrice: '0x100000000',\n },\n ]);\n }\n\n #getValuesFromMultipliers(\n value: Hex,\n multipliers: { low: number; medium: number; high: number },\n ): FeesByLevel {\n const base = hexToBN(value);\n const low = base.muln(multipliers.low);\n const medium = base.muln(multipliers.medium);\n const high = base.muln(multipliers.high);\n\n return {\n low,\n medium,\n high,\n };\n }\n\n #getMaxFees(\n baseFees: Record<GasFeeEstimateLevel, BN>,\n priorityFees: Record<GasFeeEstimateLevel, BN>,\n ): FeesByLevel {\n return {\n low: baseFees.low.add(priorityFees.low),\n medium: baseFees.medium.add(priorityFees.medium),\n high: baseFees.high.add(priorityFees.high),\n };\n }\n\n #feesToString(fees: FeesByLevel) {\n return Object.values(GasFeeEstimateLevel).map((level) =>\n fees[level].toString(10),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,SAAS,SAAS,OAAO,aAAa;AAE/C,SAAS,0BAAoC;AAuB7C,IAAM,MAAM,mBAAmB,eAAe,oBAAoB;AAElE,IAAM,kBAAyB;AAAA,EAC7B,QAAQ,eAAe;AAAA,EACvB,QAAQ,cAAc;AAAA,EACtB,QAAQ,eAAe;AACzB;AAEA,IAAM,uBAAuB;AAAA,EAC3B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AACR;AAEA,IAAM,2BAA2B;AAAA,EAC/B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AACR;AA3CA;AAkDO,IAAM,kBAAN,MAA4C;AAAA,EAA5C;AAcL,uBAAM;AA4CN;AAgBA;AAgBA;AAWA;AAAA;AAAA,EApGA,mBAAmB,iBAA2C;AAC5D,WAAO,gBAAgB,SAAS,gBAAgB,OAAO;AAAA,EACzD;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,QAAI;AACF,aAAO,MAAM,sBAAK,sCAAL,WAAsB;AAAA,IACrC,SAAS,OAAO;AACd,UAAI,+CAA+C,KAAK;AACxD,aAAO,IAAI,kBAAkB,EAAE,WAAW,OAAO;AAAA,IACnD;AAAA,EACF;AA8FF;AA5FQ;AAAA,qBAAgB,eACpB,SAC6B;AAC7B,QAAM,EAAE,UAAU,gBAAgB,IAAI;AAEtC,QAAM,gBAAgB,MAAM,sBAAK,wCAAL,WAC1B,iBACA;AAGF,MAAI,2BAA2B,aAAa;AAE5C,QAAM,WAAW,sBAAK,wDAAL,WACf,cAAc,eACd;AAGF,MAAI,uBAAuB,sBAAK,gCAAL,WAAmB,SAAS;AAEvD,QAAM,eAAe,sBAAK,wDAAL,WAC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O,OAAO,OAAO,mBAAmB,EAAE;AAAA,IAAI,CAAC,UAC7C,KAAK,KAAK,EAAE,SAAS,EAAE;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
projectLogger
|
|
3
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/layer1-gas-fee-flow.ts
|
|
6
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
7
|
+
var log = createModuleLogger(projectLogger, "layer-1-gas-fee-flow");
|
|
8
|
+
async function updateTransactionLayer1GasFee(request) {
|
|
9
|
+
const layer1GasFee = await getTransactionLayer1GasFee(request);
|
|
10
|
+
if (layer1GasFee) {
|
|
11
|
+
const { transactionMeta } = request;
|
|
12
|
+
transactionMeta.layer1GasFee = layer1GasFee;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows) {
|
|
16
|
+
return layer1GasFeeFlows.find(
|
|
17
|
+
(layer1GasFeeFlow) => layer1GasFeeFlow.matchesTransaction(transactionMeta)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
async function getTransactionLayer1GasFee({
|
|
21
|
+
ethQuery,
|
|
22
|
+
transactionMeta,
|
|
23
|
+
layer1GasFeeFlows
|
|
24
|
+
}) {
|
|
25
|
+
const layer1GasFeeFlow = getLayer1GasFeeFlow(
|
|
26
|
+
transactionMeta,
|
|
27
|
+
layer1GasFeeFlows
|
|
28
|
+
);
|
|
29
|
+
if (!layer1GasFeeFlow) {
|
|
30
|
+
log("Layer 1 gas fee flow not found", transactionMeta.id);
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
|
|
35
|
+
ethQuery,
|
|
36
|
+
transactionMeta
|
|
37
|
+
});
|
|
38
|
+
return layer1Fee;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
log("Failed to get layer 1 gas fee", transactionMeta.id, error);
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
updateTransactionLayer1GasFee
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-KFL2GGZC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/layer1-gas-fee-flow.ts"],"sourcesContent":["import type EthQuery from '@metamask/eth-query';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n ethQuery: EthQuery;\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (layer1GasFee) {\n const { transactionMeta } = request;\n transactionMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.ethQuery - The EthQuery instance to use to get the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nasync function getTransactionLayer1GasFee({\n ethQuery,\n transactionMeta,\n layer1GasFeeFlows,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n if (!layer1GasFeeFlow) {\n log('Layer 1 gas fee flow not found', transactionMeta.id);\n return undefined;\n }\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n ethQuery,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"],"mappings":";;;;;AACA,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAepE,eAAsB,8BACpB,SACA;AACA,QAAM,eAAe,MAAM,2BAA2B,OAAO;AAE7D,MAAI,cAAc;AAChB,UAAM,EAAE,gBAAgB,IAAI;AAC5B,oBAAgB,eAAe;AAAA,EACjC;AACF;AAQA,SAAS,oBACP,iBACA,mBAC8B;AAC9B,SAAO,kBAAkB;AAAA,IAAK,CAAC,qBAC7B,iBAAiB,mBAAmB,eAAe;AAAA,EACrD;AACF;AASA,eAAe,2BAA2B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB;AACrB,QAAI,kCAAkC,gBAAgB,EAAE;AACxD,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,EAAE,UAAU,IAAI,MAAM,iBAAiB,aAAa;AAAA,MACxD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iCAAiC,gBAAgB,IAAI,KAAK;AAC9D,WAAO;AAAA,EACT;AACF;","names":[]}
|