@metamask/transaction-controller 36.1.0 → 37.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -1
- package/dist/TransactionController.cjs +2026 -0
- package/dist/TransactionController.cjs.map +1 -0
- package/dist/{types/TransactionController.d.ts → TransactionController.d.cts} +16 -24
- package/dist/TransactionController.d.cts.map +1 -0
- package/dist/TransactionController.d.mts +827 -0
- package/dist/TransactionController.d.mts.map +1 -0
- package/dist/TransactionController.mjs +2027 -44
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/constants.cjs +170 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +143 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +165 -18
- package/dist/constants.mjs.map +1 -1
- package/dist/errors.cjs +30 -0
- package/dist/{chunk-HMOSP33F.js.map → errors.cjs.map} +1 -1
- package/dist/{types/errors.d.ts → errors.d.cts} +2 -2
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +15 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +22 -14
- package/dist/errors.mjs.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.cjs +87 -0
- package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -0
- package/dist/{types/gas-flows/DefaultGasFeeFlow.d.ts → gas-flows/DefaultGasFeeFlow.d.cts} +2 -2
- package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +81 -13
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +102 -0
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
- package/dist/{types/gas-flows/LineaGasFeeFlow.d.ts → gas-flows/LineaGasFeeFlow.d.cts} +2 -2
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.d.mts +12 -0
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs +96 -14
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +29 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/{types/gas-flows/OptimismLayer1GasFeeFlow.d.ts → gas-flows/OptimismLayer1GasFeeFlow.d.cts} +3 -3
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +10 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +24 -10
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +92 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/{types/gas-flows/OracleLayer1GasFeeFlow.d.ts → gas-flows/OracleLayer1GasFeeFlow.d.cts} +3 -3
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +12 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +88 -7
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +21 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/{types/gas-flows/ScrollLayer1GasFeeFlow.d.ts → gas-flows/ScrollLayer1GasFeeFlow.d.cts} +3 -3
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +10 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +16 -10
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
- package/dist/{chunk-FMRLPVFZ.mjs.map → gas-flows/TestGasFeeFlow.cjs.map} +1 -1
- package/dist/{types/gas-flows/TestGasFeeFlow.d.ts → gas-flows/TestGasFeeFlow.d.cts} +2 -2
- package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
- package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.mjs +67 -7
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.cjs +149 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.cjs.map +1 -0
- package/dist/{types/helpers/EtherscanRemoteTransactionSource.d.ts → helpers/EtherscanRemoteTransactionSource.d.cts} +3 -3
- package/dist/helpers/EtherscanRemoteTransactionSource.d.cts.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.d.mts +15 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.d.mts.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +147 -10
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +185 -0
- package/dist/helpers/GasFeePoller.cjs.map +1 -0
- package/dist/{types/helpers/GasFeePoller.d.ts → helpers/GasFeePoller.d.cts} +7 -7
- package/dist/helpers/GasFeePoller.d.cts.map +1 -0
- package/dist/helpers/GasFeePoller.d.mts +35 -0
- package/dist/helpers/GasFeePoller.d.mts.map +1 -0
- package/dist/helpers/GasFeePoller.mjs +183 -10
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs +199 -0
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -0
- package/dist/{types/helpers/IncomingTransactionHelper.d.ts → helpers/IncomingTransactionHelper.d.cts} +6 -6
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.d.mts +40 -0
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.mjs +190 -7
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.cjs +284 -0
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
- package/dist/{types/helpers/MultichainTrackingHelper.d.ts → helpers/MultichainTrackingHelper.d.cts} +8 -8
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.d.mts +76 -0
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.mjs +282 -11
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +328 -0
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
- package/dist/{types/helpers/PendingTransactionTracker.d.ts → helpers/PendingTransactionTracker.d.cts} +6 -7
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
- package/dist/helpers/PendingTransactionTracker.d.mts +42 -0
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
- package/dist/helpers/PendingTransactionTracker.mjs +320 -8
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +10 -10
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -76
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +9 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +6 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +5 -11
- package/dist/logger.mjs.map +1 -1
- package/dist/types.cjs +308 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types/types.d.ts → types.d.cts} +7 -35
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +999 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +304 -23
- package/dist/types.mjs.map +1 -1
- package/dist/utils/etherscan.cjs +111 -0
- package/dist/utils/etherscan.cjs.map +1 -0
- package/dist/{types/utils/etherscan.d.ts → utils/etherscan.d.cts} +2 -2
- package/dist/utils/etherscan.d.cts.map +1 -0
- package/dist/utils/etherscan.d.mts +71 -0
- package/dist/utils/etherscan.d.mts.map +1 -0
- package/dist/utils/etherscan.mjs +104 -13
- package/dist/utils/etherscan.mjs.map +1 -1
- package/dist/utils/external-transactions.cjs +36 -0
- package/dist/utils/external-transactions.cjs.map +1 -0
- package/dist/{types/utils/external-transactions.d.ts → utils/external-transactions.d.cts} +2 -2
- package/dist/utils/external-transactions.d.cts.map +1 -0
- package/dist/utils/external-transactions.d.mts +10 -0
- package/dist/utils/external-transactions.d.mts.map +1 -0
- package/dist/utils/external-transactions.mjs +31 -8
- package/dist/utils/external-transactions.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +208 -0
- package/dist/utils/gas-fees.cjs.map +1 -0
- package/dist/{types/utils/gas-fees.d.ts → utils/gas-fees.d.cts} +5 -5
- package/dist/utils/gas-fees.d.cts.map +1 -0
- package/dist/utils/gas-fees.d.mts +26 -0
- package/dist/utils/gas-fees.d.mts.map +1 -0
- package/dist/utils/gas-fees.mjs +202 -15
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas-flow.cjs +76 -0
- package/dist/utils/gas-flow.cjs.map +1 -0
- package/dist/{types/utils/gas-flow.d.ts → utils/gas-flow.d.cts} +5 -5
- package/dist/utils/gas-flow.d.cts.map +1 -0
- package/dist/utils/gas-flow.d.mts +26 -0
- package/dist/utils/gas-flow.d.mts.map +1 -0
- package/dist/utils/gas-flow.mjs +70 -10
- package/dist/utils/gas-flow.mjs.map +1 -1
- package/dist/utils/gas.cjs +112 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/{types/utils/gas.d.ts → utils/gas.d.cts} +4 -4
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +28 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/gas.mjs +105 -19
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/history.cjs +164 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/{types/utils/history.d.ts → utils/history.d.cts} +2 -2
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +29 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +163 -13
- package/dist/utils/history.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +59 -0
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
- package/dist/{types/utils/layer1-gas-fee-flow.d.ts → utils/layer1-gas-fee-flow.d.cts} +4 -4
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.d.mts +25 -0
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.mjs +53 -10
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/nonce.cjs +66 -0
- package/dist/utils/nonce.cjs.map +1 -0
- package/dist/{types/utils/nonce.d.ts → utils/nonce.d.cts} +3 -3
- package/dist/utils/nonce.d.cts.map +1 -0
- package/dist/utils/nonce.d.mts +21 -0
- package/dist/utils/nonce.d.mts.map +1 -0
- package/dist/utils/nonce.mjs +60 -10
- package/dist/utils/nonce.mjs.map +1 -1
- package/dist/utils/retry.cjs +89 -0
- package/dist/utils/retry.cjs.map +1 -0
- package/dist/{types/utils/retry.d.ts → utils/retry.d.cts} +3 -3
- package/dist/utils/retry.d.cts.map +1 -0
- package/dist/utils/retry.d.mts +11 -0
- package/dist/utils/retry.d.mts.map +1 -0
- package/dist/utils/retry.mjs +84 -7
- package/dist/utils/retry.mjs.map +1 -1
- package/dist/utils/simulation-api.cjs +72 -0
- package/dist/utils/simulation-api.cjs.map +1 -0
- package/dist/{types/utils/simulation-api.d.ts → utils/simulation-api.d.cts} +2 -2
- package/dist/utils/simulation-api.d.cts.map +1 -0
- package/dist/utils/simulation-api.d.mts +107 -0
- package/dist/utils/simulation-api.d.mts.map +1 -0
- package/dist/utils/simulation-api.mjs +67 -10
- package/dist/utils/simulation-api.mjs.map +1 -1
- package/dist/utils/simulation.cjs +443 -0
- package/dist/utils/simulation.cjs.map +1 -0
- package/dist/{types/utils/simulation.d.ts → utils/simulation.d.cts} +6 -6
- package/dist/utils/simulation.d.cts.map +1 -0
- package/dist/utils/simulation.d.mts +46 -0
- package/dist/utils/simulation.d.mts.map +1 -0
- package/dist/utils/simulation.mjs +436 -15
- package/dist/utils/simulation.mjs.map +1 -1
- package/dist/utils/swaps.cjs +309 -0
- package/dist/utils/swaps.cjs.map +1 -0
- package/dist/{types/utils/swaps.d.ts → utils/swaps.d.cts} +5 -5
- package/dist/utils/swaps.d.cts.map +1 -0
- package/dist/utils/swaps.d.mts +84 -0
- package/dist/utils/swaps.d.mts.map +1 -0
- package/dist/utils/swaps.mjs +303 -22
- package/dist/utils/swaps.mjs.map +1 -1
- package/dist/utils/transaction-type.cjs +115 -0
- package/dist/utils/transaction-type.cjs.map +1 -0
- package/dist/{types/utils/transaction-type.d.ts → utils/transaction-type.d.cts} +3 -3
- package/dist/utils/transaction-type.d.cts.map +1 -0
- package/dist/utils/transaction-type.d.mts +14 -0
- package/dist/utils/transaction-type.d.mts.map +1 -0
- package/dist/utils/transaction-type.mjs +110 -10
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/dist/utils/utils.cjs +151 -0
- package/dist/utils/utils.cjs.map +1 -0
- package/dist/{types/utils/utils.d.ts → utils/utils.d.cts} +2 -2
- package/dist/utils/utils.d.cts.map +1 -0
- package/dist/utils/utils.d.mts +52 -0
- package/dist/utils/utils.d.mts.map +1 -0
- package/dist/utils/utils.mjs +139 -21
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/validation.cjs +267 -0
- package/dist/{chunk-4OYPDGHO.js.map → utils/validation.cjs.map} +1 -1
- package/dist/{types/utils/validation.d.ts → utils/validation.d.cts} +2 -2
- package/dist/utils/validation.d.cts.map +1 -0
- package/dist/utils/validation.d.mts +20 -0
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/validation.mjs +261 -11
- package/dist/utils/validation.mjs.map +1 -1
- package/package.json +19 -14
- package/dist/TransactionController.js +0 -46
- package/dist/TransactionController.js.map +0 -1
- package/dist/chunk-2XKEAKQG.js +0 -55
- package/dist/chunk-2XKEAKQG.js.map +0 -1
- package/dist/chunk-3AVRGHUO.mjs +0 -360
- package/dist/chunk-3AVRGHUO.mjs.map +0 -1
- package/dist/chunk-3ZV5YEUV.mjs +0 -239
- package/dist/chunk-3ZV5YEUV.mjs.map +0 -1
- package/dist/chunk-4OYPDGHO.js +0 -201
- package/dist/chunk-4V4XIPCI.mjs +0 -338
- package/dist/chunk-4V4XIPCI.mjs.map +0 -1
- package/dist/chunk-5G6OHAXI.mjs +0 -137
- package/dist/chunk-5G6OHAXI.mjs.map +0 -1
- package/dist/chunk-5HYWLTVQ.js +0 -228
- package/dist/chunk-5HYWLTVQ.js.map +0 -1
- package/dist/chunk-5QVDIVJH.js +0 -68
- package/dist/chunk-5QVDIVJH.js.map +0 -1
- package/dist/chunk-6B5BEO3R.mjs +0 -399
- package/dist/chunk-6B5BEO3R.mjs.map +0 -1
- package/dist/chunk-6DDVVUJC.mjs +0 -50
- package/dist/chunk-6DDVVUJC.mjs.map +0 -1
- package/dist/chunk-6OLJWLKK.js +0 -338
- package/dist/chunk-6OLJWLKK.js.map +0 -1
- package/dist/chunk-7LXE4KHV.js +0 -40
- package/dist/chunk-7LXE4KHV.js.map +0 -1
- package/dist/chunk-7NMV2NPM.js +0 -172
- package/dist/chunk-7NMV2NPM.js.map +0 -1
- package/dist/chunk-AWIJZAW3.mjs +0 -112
- package/dist/chunk-AWIJZAW3.mjs.map +0 -1
- package/dist/chunk-BZV72SCF.js +0 -226
- package/dist/chunk-BZV72SCF.js.map +0 -1
- package/dist/chunk-EGQCE3FK.mjs +0 -85
- package/dist/chunk-EGQCE3FK.mjs.map +0 -1
- package/dist/chunk-EHWAY6XU.js +0 -112
- package/dist/chunk-EHWAY6XU.js.map +0 -1
- package/dist/chunk-EKJXGERC.mjs +0 -172
- package/dist/chunk-EKJXGERC.mjs.map +0 -1
- package/dist/chunk-FG74Z3F5.mjs +0 -102
- package/dist/chunk-FG74Z3F5.mjs.map +0 -1
- package/dist/chunk-FMRLPVFZ.mjs +0 -66
- package/dist/chunk-FRKQ3Z2L.mjs +0 -40
- package/dist/chunk-FRKQ3Z2L.mjs.map +0 -1
- package/dist/chunk-HMOSP33F.js +0 -36
- package/dist/chunk-HQSNKCXI.mjs +0 -36
- package/dist/chunk-HQSNKCXI.mjs.map +0 -1
- package/dist/chunk-JIFPK37W.mjs +0 -257
- package/dist/chunk-JIFPK37W.mjs.map +0 -1
- package/dist/chunk-JOQK7A5G.mjs +0 -68
- package/dist/chunk-JOQK7A5G.mjs.map +0 -1
- package/dist/chunk-K4KOSAGM.mjs +0 -61
- package/dist/chunk-K4KOSAGM.mjs.map +0 -1
- package/dist/chunk-KG4UW4K4.mjs +0 -88
- package/dist/chunk-KG4UW4K4.mjs.map +0 -1
- package/dist/chunk-KT6UAKBB.js +0 -61
- package/dist/chunk-KT6UAKBB.js.map +0 -1
- package/dist/chunk-KTGMNUTQ.js +0 -106
- package/dist/chunk-KTGMNUTQ.js.map +0 -1
- package/dist/chunk-KYRW4BLA.mjs +0 -121
- package/dist/chunk-KYRW4BLA.mjs.map +0 -1
- package/dist/chunk-LFFYCDHB.mjs +0 -92
- package/dist/chunk-LFFYCDHB.mjs.map +0 -1
- package/dist/chunk-NNCUD3QF.js +0 -360
- package/dist/chunk-NNCUD3QF.js.map +0 -1
- package/dist/chunk-NNHSNPT2.mjs +0 -67
- package/dist/chunk-NNHSNPT2.mjs.map +0 -1
- package/dist/chunk-NOHEXQ7Y.mjs +0 -55
- package/dist/chunk-NOHEXQ7Y.mjs.map +0 -1
- package/dist/chunk-NYKRCWBG.js +0 -31
- package/dist/chunk-NYKRCWBG.js.map +0 -1
- package/dist/chunk-O6ZZVIFH.mjs +0 -176
- package/dist/chunk-O6ZZVIFH.mjs.map +0 -1
- package/dist/chunk-PRUNMTRD.js +0 -50
- package/dist/chunk-PRUNMTRD.js.map +0 -1
- package/dist/chunk-PSZ34BI5.js +0 -92
- package/dist/chunk-PSZ34BI5.js.map +0 -1
- package/dist/chunk-QKV7E5BO.js +0 -257
- package/dist/chunk-QKV7E5BO.js.map +0 -1
- package/dist/chunk-RHDPOIS4.js +0 -239
- package/dist/chunk-RHDPOIS4.js.map +0 -1
- package/dist/chunk-S6VGOPUY.js +0 -14
- package/dist/chunk-S6VGOPUY.js.map +0 -1
- package/dist/chunk-SD6CWFDF.js +0 -88
- package/dist/chunk-SD6CWFDF.js.map +0 -1
- package/dist/chunk-SFFOC25Q.mjs +0 -226
- package/dist/chunk-SFFOC25Q.mjs.map +0 -1
- package/dist/chunk-SMC5Q6ZH.mjs +0 -120
- package/dist/chunk-SMC5Q6ZH.mjs.map +0 -1
- package/dist/chunk-TIE3CPF7.js +0 -120
- package/dist/chunk-TIE3CPF7.js.map +0 -1
- package/dist/chunk-TJMQEH57.js +0 -66
- package/dist/chunk-TJMQEH57.js.map +0 -1
- package/dist/chunk-UGN7PBON.js +0 -176
- package/dist/chunk-UGN7PBON.js.map +0 -1
- package/dist/chunk-UHAFIPSL.js +0 -121
- package/dist/chunk-UHAFIPSL.js.map +0 -1
- package/dist/chunk-UHSRHP55.mjs +0 -106
- package/dist/chunk-UHSRHP55.mjs.map +0 -1
- package/dist/chunk-ULD4JC3Q.js +0 -399
- package/dist/chunk-ULD4JC3Q.js.map +0 -1
- package/dist/chunk-UQQWZT6C.mjs +0 -14
- package/dist/chunk-UQQWZT6C.mjs.map +0 -1
- package/dist/chunk-V72C4MCR.js +0 -137
- package/dist/chunk-V72C4MCR.js.map +0 -1
- package/dist/chunk-VEVVBHP3.mjs +0 -31
- package/dist/chunk-VEVVBHP3.mjs.map +0 -1
- package/dist/chunk-VGFPVAKX.mjs +0 -228
- package/dist/chunk-VGFPVAKX.mjs.map +0 -1
- package/dist/chunk-VKWOHNDO.js +0 -2509
- package/dist/chunk-VKWOHNDO.js.map +0 -1
- package/dist/chunk-WR5F34OW.js +0 -23
- package/dist/chunk-WR5F34OW.js.map +0 -1
- package/dist/chunk-X4XSEYPL.mjs +0 -201
- package/dist/chunk-X4XSEYPL.mjs.map +0 -1
- package/dist/chunk-XTMJ25EF.mjs +0 -2509
- package/dist/chunk-XTMJ25EF.mjs.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-XVYXRCRL.js +0 -85
- package/dist/chunk-XVYXRCRL.js.map +0 -1
- package/dist/chunk-YVCX6Z75.js +0 -102
- package/dist/chunk-YVCX6Z75.js.map +0 -1
- package/dist/chunk-YWLMT7XH.js +0 -67
- package/dist/chunk-YWLMT7XH.js.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/chunk-Z4GV3YQQ.mjs +0 -23
- package/dist/chunk-Z4GV3YQQ.mjs.map +0 -1
- package/dist/constants.js +0 -20
- package/dist/constants.js.map +0 -1
- package/dist/errors.js +0 -15
- package/dist/errors.js.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.js +0 -15
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.js +0 -16
- package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +0 -11
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.js +0 -9
- package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.js +0 -11
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/TestGasFeeFlow.js +0 -9
- package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.js +0 -12
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +0 -1
- package/dist/helpers/GasFeePoller.js +0 -12
- package/dist/helpers/GasFeePoller.js.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.js +0 -9
- package/dist/helpers/IncomingTransactionHelper.js.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.js +0 -13
- package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
- package/dist/helpers/PendingTransactionTracker.js +0 -10
- package/dist/helpers/PendingTransactionTracker.js.map +0 -1
- package/dist/index.js +0 -77
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -12
- package/dist/logger.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/TransactionController.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/errors.d.ts.map +0 -1
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/types/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/types/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/types/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils/etherscan.d.ts.map +0 -1
- package/dist/types/utils/external-transactions.d.ts.map +0 -1
- package/dist/types/utils/gas-fees.d.ts.map +0 -1
- package/dist/types/utils/gas-flow.d.ts.map +0 -1
- package/dist/types/utils/gas.d.ts.map +0 -1
- package/dist/types/utils/history.d.ts.map +0 -1
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +0 -1
- package/dist/types/utils/nonce.d.ts.map +0 -1
- package/dist/types/utils/retry.d.ts.map +0 -1
- package/dist/types/utils/simulation-api.d.ts.map +0 -1
- package/dist/types/utils/simulation.d.ts.map +0 -1
- package/dist/types/utils/swaps.d.ts.map +0 -1
- package/dist/types/utils/transaction-type.d.ts.map +0 -1
- package/dist/types/utils/utils.d.ts.map +0 -1
- package/dist/types/utils/validation.d.ts.map +0 -1
- package/dist/types.js +0 -24
- package/dist/types.js.map +0 -1
- package/dist/utils/etherscan.js +0 -14
- package/dist/utils/etherscan.js.map +0 -1
- package/dist/utils/external-transactions.js +0 -9
- package/dist/utils/external-transactions.js.map +0 -1
- package/dist/utils/gas-fees.js +0 -16
- package/dist/utils/gas-fees.js.map +0 -1
- package/dist/utils/gas-flow.js +0 -11
- package/dist/utils/gas-flow.js.map +0 -1
- package/dist/utils/gas.js +0 -20
- package/dist/utils/gas.js.map +0 -1
- package/dist/utils/history.js +0 -14
- package/dist/utils/history.js.map +0 -1
- package/dist/utils/layer1-gas-fee-flow.js +0 -11
- package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
- package/dist/utils/nonce.js +0 -11
- package/dist/utils/nonce.js.map +0 -1
- package/dist/utils/retry.js +0 -8
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/simulation-api.js +0 -11
- package/dist/utils/simulation-api.js.map +0 -1
- package/dist/utils/simulation.js +0 -17
- package/dist/utils/simulation.js.map +0 -1
- package/dist/utils/swaps.js +0 -24
- package/dist/utils/swaps.js.map +0 -1
- package/dist/utils/transaction-type.js +0 -11
- package/dist/utils/transaction-type.js.map +0 -1
- package/dist/utils/utils.js +0 -23
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/validation.js +0 -12
- package/dist/utils/validation.js.map +0 -1
package/dist/chunk-XTMJ25EF.mjs
DELETED
|
@@ -1,2509 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAndFormatTransactionsForNonceTracker,
|
|
3
|
-
getNextNonce
|
|
4
|
-
} from "./chunk-6DDVVUJC.mjs";
|
|
5
|
-
import {
|
|
6
|
-
getTransactionParamsWithIncreasedGasFee
|
|
7
|
-
} from "./chunk-JOQK7A5G.mjs";
|
|
8
|
-
import {
|
|
9
|
-
getSimulationData
|
|
10
|
-
} from "./chunk-3AVRGHUO.mjs";
|
|
11
|
-
import {
|
|
12
|
-
determineTransactionType
|
|
13
|
-
} from "./chunk-KG4UW4K4.mjs";
|
|
14
|
-
import {
|
|
15
|
-
validateTransactionOrigin,
|
|
16
|
-
validateTxParams
|
|
17
|
-
} from "./chunk-X4XSEYPL.mjs";
|
|
18
|
-
import {
|
|
19
|
-
PendingTransactionTracker
|
|
20
|
-
} from "./chunk-6B5BEO3R.mjs";
|
|
21
|
-
import {
|
|
22
|
-
validateConfirmedExternalTransaction
|
|
23
|
-
} from "./chunk-FRKQ3Z2L.mjs";
|
|
24
|
-
import {
|
|
25
|
-
addGasBuffer,
|
|
26
|
-
estimateGas,
|
|
27
|
-
updateGas
|
|
28
|
-
} from "./chunk-5G6OHAXI.mjs";
|
|
29
|
-
import {
|
|
30
|
-
addInitialHistorySnapshot,
|
|
31
|
-
updateTransactionHistory
|
|
32
|
-
} from "./chunk-SMC5Q6ZH.mjs";
|
|
33
|
-
import {
|
|
34
|
-
OptimismLayer1GasFeeFlow
|
|
35
|
-
} from "./chunk-VEVVBHP3.mjs";
|
|
36
|
-
import {
|
|
37
|
-
ScrollLayer1GasFeeFlow
|
|
38
|
-
} from "./chunk-Z4GV3YQQ.mjs";
|
|
39
|
-
import {
|
|
40
|
-
TestGasFeeFlow
|
|
41
|
-
} from "./chunk-FMRLPVFZ.mjs";
|
|
42
|
-
import {
|
|
43
|
-
GasFeePoller
|
|
44
|
-
} from "./chunk-VGFPVAKX.mjs";
|
|
45
|
-
import {
|
|
46
|
-
getTransactionLayer1GasFee,
|
|
47
|
-
updateTransactionLayer1GasFee
|
|
48
|
-
} from "./chunk-NOHEXQ7Y.mjs";
|
|
49
|
-
import {
|
|
50
|
-
IncomingTransactionHelper
|
|
51
|
-
} from "./chunk-3ZV5YEUV.mjs";
|
|
52
|
-
import {
|
|
53
|
-
MultichainTrackingHelper
|
|
54
|
-
} from "./chunk-4V4XIPCI.mjs";
|
|
55
|
-
import {
|
|
56
|
-
EtherscanRemoteTransactionSource
|
|
57
|
-
} from "./chunk-EKJXGERC.mjs";
|
|
58
|
-
import {
|
|
59
|
-
LineaGasFeeFlow
|
|
60
|
-
} from "./chunk-KYRW4BLA.mjs";
|
|
61
|
-
import {
|
|
62
|
-
DefaultGasFeeFlow
|
|
63
|
-
} from "./chunk-AWIJZAW3.mjs";
|
|
64
|
-
import {
|
|
65
|
-
updateGasFees
|
|
66
|
-
} from "./chunk-SFFOC25Q.mjs";
|
|
67
|
-
import {
|
|
68
|
-
updatePostTransactionBalance,
|
|
69
|
-
updateSwapsTransaction
|
|
70
|
-
} from "./chunk-JIFPK37W.mjs";
|
|
71
|
-
import {
|
|
72
|
-
isEIP1559Transaction,
|
|
73
|
-
normalizeGasFeeValues,
|
|
74
|
-
normalizeTransactionParams,
|
|
75
|
-
normalizeTxError,
|
|
76
|
-
validateGasValues,
|
|
77
|
-
validateIfTransactionUnapproved
|
|
78
|
-
} from "./chunk-UHSRHP55.mjs";
|
|
79
|
-
import {
|
|
80
|
-
getGasFeeFlow
|
|
81
|
-
} from "./chunk-NNHSNPT2.mjs";
|
|
82
|
-
import {
|
|
83
|
-
projectLogger
|
|
84
|
-
} from "./chunk-UQQWZT6C.mjs";
|
|
85
|
-
import {
|
|
86
|
-
__privateAdd,
|
|
87
|
-
__privateGet,
|
|
88
|
-
__privateMethod,
|
|
89
|
-
__privateSet
|
|
90
|
-
} from "./chunk-XUI43LEZ.mjs";
|
|
91
|
-
|
|
92
|
-
// src/TransactionController.ts
|
|
93
|
-
import { Hardfork, Common } from "@ethereumjs/common";
|
|
94
|
-
import { TransactionFactory } from "@ethereumjs/tx";
|
|
95
|
-
import { bufferToHex } from "@ethereumjs/util";
|
|
96
|
-
import { BaseController } from "@metamask/base-controller";
|
|
97
|
-
import {
|
|
98
|
-
query,
|
|
99
|
-
ApprovalType,
|
|
100
|
-
ORIGIN_METAMASK,
|
|
101
|
-
convertHexToDecimal,
|
|
102
|
-
isInfuraNetworkType
|
|
103
|
-
} from "@metamask/controller-utils";
|
|
104
|
-
import EthQuery from "@metamask/eth-query";
|
|
105
|
-
import { NetworkClientType } from "@metamask/network-controller";
|
|
106
|
-
import { NonceTracker } from "@metamask/nonce-tracker";
|
|
107
|
-
import { errorCodes, rpcErrors, providerErrors } from "@metamask/rpc-errors";
|
|
108
|
-
import { add0x } from "@metamask/utils";
|
|
109
|
-
import { Mutex } from "async-mutex";
|
|
110
|
-
import { MethodRegistry } from "eth-method-registry";
|
|
111
|
-
import { EventEmitter } from "events";
|
|
112
|
-
import { cloneDeep, mapValues, merge, pickBy, sortBy, isEqual } from "lodash";
|
|
113
|
-
import { v1 as random } from "uuid";
|
|
114
|
-
var metadata = {
|
|
115
|
-
transactions: {
|
|
116
|
-
persist: true,
|
|
117
|
-
anonymous: false
|
|
118
|
-
},
|
|
119
|
-
methodData: {
|
|
120
|
-
persist: true,
|
|
121
|
-
anonymous: false
|
|
122
|
-
},
|
|
123
|
-
lastFetchedBlockNumbers: {
|
|
124
|
-
persist: true,
|
|
125
|
-
anonymous: false
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var HARDFORK = Hardfork.London;
|
|
129
|
-
var CANCEL_RATE = 1.1;
|
|
130
|
-
var SPEED_UP_RATE = 1.1;
|
|
131
|
-
var controllerName = "TransactionController";
|
|
132
|
-
var ApprovalState = /* @__PURE__ */ ((ApprovalState2) => {
|
|
133
|
-
ApprovalState2["Approved"] = "approved";
|
|
134
|
-
ApprovalState2["NotApproved"] = "not-approved";
|
|
135
|
-
ApprovalState2["SkippedViaBeforePublishHook"] = "skipped-via-before-publish-hook";
|
|
136
|
-
return ApprovalState2;
|
|
137
|
-
})(ApprovalState || {});
|
|
138
|
-
function getDefaultTransactionControllerState() {
|
|
139
|
-
return {
|
|
140
|
-
methodData: {},
|
|
141
|
-
transactions: [],
|
|
142
|
-
lastFetchedBlockNumbers: {}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
var _internalEvents, _incomingTransactionOptions, _pendingTransactionOptions, _trace, _transactionHistoryLimit, _isSimulationEnabled, _testGasFeeFlows, _multichainTrackingHelper, _retryTransaction, retryTransaction_fn, _createNonceTracker, createNonceTracker_fn, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn, _createPendingTransactionTracker, createPendingTransactionTracker_fn, _checkForPendingTransactionAndStartPolling, _stopAllTracking, stopAllTracking_fn, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn, _getGasFeeFlows, getGasFeeFlows_fn, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn, _updateTransactionInternal, updateTransactionInternal_fn, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn, _updateSimulationData, updateSimulationData_fn, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn, _getNetworkClientId, getNetworkClientId_fn, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn, _getGlobalChainId, getGlobalChainId_fn, _isCustomNetwork, isCustomNetwork_fn, _getSelectedAccount, getSelectedAccount_fn;
|
|
146
|
-
var TransactionController = class extends BaseController {
|
|
147
|
-
/**
|
|
148
|
-
* Constructs a TransactionController.
|
|
149
|
-
*
|
|
150
|
-
* @param options - The controller options.
|
|
151
|
-
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
152
|
-
* @param options.disableHistory - Whether to disable storing history in transaction metadata.
|
|
153
|
-
* @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
|
|
154
|
-
* @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
|
|
155
|
-
* @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
|
|
156
|
-
* @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
|
|
157
|
-
* @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
|
|
158
|
-
* @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
|
|
159
|
-
* @param options.getNetworkClientRegistry - Gets the network client registry.
|
|
160
|
-
* @param options.getNetworkState - Gets the state of the network controller.
|
|
161
|
-
* @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
|
|
162
|
-
* @param options.getSavedGasFees - Gets the saved gas fee config.
|
|
163
|
-
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
164
|
-
* @param options.isMultichainEnabled - Enable multichain support.
|
|
165
|
-
* @param options.isSimulationEnabled - Whether new transactions will be automatically simulated.
|
|
166
|
-
* @param options.messenger - The controller messenger.
|
|
167
|
-
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
168
|
-
* @param options.pendingTransactions - Configuration options for pending transaction support.
|
|
169
|
-
* @param options.provider - The provider used to create the underlying EthQuery instance.
|
|
170
|
-
* @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
|
|
171
|
-
* @param options.sign - Function used to sign transactions.
|
|
172
|
-
* @param options.state - Initial state to set on this controller.
|
|
173
|
-
* @param options.testGasFeeFlows - Whether to use the test gas fee flow.
|
|
174
|
-
* @param options.trace - Callback to generate trace information.
|
|
175
|
-
* @param options.transactionHistoryLimit - Transaction history limit.
|
|
176
|
-
* @param options.hooks - The controller hooks.
|
|
177
|
-
*/
|
|
178
|
-
constructor({
|
|
179
|
-
blockTracker,
|
|
180
|
-
disableHistory,
|
|
181
|
-
disableSendFlowHistory,
|
|
182
|
-
disableSwaps,
|
|
183
|
-
getCurrentAccountEIP1559Compatibility,
|
|
184
|
-
getCurrentNetworkEIP1559Compatibility,
|
|
185
|
-
getExternalPendingTransactions,
|
|
186
|
-
getGasFeeEstimates,
|
|
187
|
-
getNetworkClientRegistry,
|
|
188
|
-
getNetworkState,
|
|
189
|
-
getPermittedAccounts,
|
|
190
|
-
getSavedGasFees,
|
|
191
|
-
incomingTransactions = {},
|
|
192
|
-
isMultichainEnabled = false,
|
|
193
|
-
isSimulationEnabled,
|
|
194
|
-
messenger,
|
|
195
|
-
onNetworkStateChange,
|
|
196
|
-
pendingTransactions = {},
|
|
197
|
-
provider,
|
|
198
|
-
securityProviderRequest,
|
|
199
|
-
sign,
|
|
200
|
-
state,
|
|
201
|
-
testGasFeeFlows,
|
|
202
|
-
trace,
|
|
203
|
-
transactionHistoryLimit = 40,
|
|
204
|
-
hooks
|
|
205
|
-
}) {
|
|
206
|
-
super({
|
|
207
|
-
name: controllerName,
|
|
208
|
-
metadata,
|
|
209
|
-
messenger,
|
|
210
|
-
state: {
|
|
211
|
-
...getDefaultTransactionControllerState(),
|
|
212
|
-
...state
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
__privateAdd(this, _retryTransaction);
|
|
216
|
-
__privateAdd(this, _createNonceTracker);
|
|
217
|
-
__privateAdd(this, _createIncomingTransactionHelper);
|
|
218
|
-
__privateAdd(this, _createPendingTransactionTracker);
|
|
219
|
-
__privateAdd(this, _stopAllTracking);
|
|
220
|
-
__privateAdd(this, _removeIncomingTransactionHelperListeners);
|
|
221
|
-
__privateAdd(this, _addIncomingTransactionHelperListeners);
|
|
222
|
-
__privateAdd(this, _removePendingTransactionTrackerListeners);
|
|
223
|
-
__privateAdd(this, _addPendingTransactionTrackerListeners);
|
|
224
|
-
__privateAdd(this, _getNonceTrackerPendingTransactions);
|
|
225
|
-
__privateAdd(this, _getGasFeeFlows);
|
|
226
|
-
__privateAdd(this, _getLayer1GasFeeFlows);
|
|
227
|
-
__privateAdd(this, _updateTransactionInternal);
|
|
228
|
-
__privateAdd(this, _checkIfTransactionParamsUpdated);
|
|
229
|
-
__privateAdd(this, _onTransactionParamsUpdated);
|
|
230
|
-
__privateAdd(this, _updateSimulationData);
|
|
231
|
-
__privateAdd(this, _onGasFeePollerTransactionUpdate);
|
|
232
|
-
__privateAdd(this, _getNetworkClientId);
|
|
233
|
-
__privateAdd(this, _getGlobalNetworkClientId);
|
|
234
|
-
__privateAdd(this, _getGlobalChainId);
|
|
235
|
-
__privateAdd(this, _isCustomNetwork);
|
|
236
|
-
__privateAdd(this, _getSelectedAccount);
|
|
237
|
-
__privateAdd(this, _internalEvents, new EventEmitter());
|
|
238
|
-
this.approvingTransactionIds = /* @__PURE__ */ new Set();
|
|
239
|
-
this.mutex = new Mutex();
|
|
240
|
-
__privateAdd(this, _incomingTransactionOptions, void 0);
|
|
241
|
-
__privateAdd(this, _pendingTransactionOptions, void 0);
|
|
242
|
-
this.signAbortCallbacks = /* @__PURE__ */ new Map();
|
|
243
|
-
__privateAdd(this, _trace, void 0);
|
|
244
|
-
__privateAdd(this, _transactionHistoryLimit, void 0);
|
|
245
|
-
__privateAdd(this, _isSimulationEnabled, void 0);
|
|
246
|
-
__privateAdd(this, _testGasFeeFlows, void 0);
|
|
247
|
-
__privateAdd(this, _multichainTrackingHelper, void 0);
|
|
248
|
-
__privateAdd(this, _checkForPendingTransactionAndStartPolling, () => {
|
|
249
|
-
this.pendingTransactionTracker.startIfPendingTransactions();
|
|
250
|
-
__privateGet(this, _multichainTrackingHelper).checkForPendingTransactionAndStartPolling();
|
|
251
|
-
});
|
|
252
|
-
this.messagingSystem = messenger;
|
|
253
|
-
this.getNetworkState = getNetworkState;
|
|
254
|
-
this.isSendFlowHistoryDisabled = disableSendFlowHistory ?? false;
|
|
255
|
-
this.isHistoryDisabled = disableHistory ?? false;
|
|
256
|
-
this.isSwapsDisabled = disableSwaps ?? false;
|
|
257
|
-
__privateSet(this, _isSimulationEnabled, isSimulationEnabled ?? (() => true));
|
|
258
|
-
this.registry = new MethodRegistry({ provider });
|
|
259
|
-
this.getSavedGasFees = getSavedGasFees ?? ((_chainId) => void 0);
|
|
260
|
-
this.getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility ?? (() => Promise.resolve(true));
|
|
261
|
-
this.getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
|
|
262
|
-
this.getGasFeeEstimates = getGasFeeEstimates || (() => Promise.resolve({}));
|
|
263
|
-
this.getPermittedAccounts = getPermittedAccounts;
|
|
264
|
-
this.getExternalPendingTransactions = getExternalPendingTransactions ?? (() => []);
|
|
265
|
-
this.securityProviderRequest = securityProviderRequest;
|
|
266
|
-
__privateSet(this, _incomingTransactionOptions, incomingTransactions);
|
|
267
|
-
__privateSet(this, _pendingTransactionOptions, pendingTransactions);
|
|
268
|
-
__privateSet(this, _transactionHistoryLimit, transactionHistoryLimit);
|
|
269
|
-
this.sign = sign;
|
|
270
|
-
__privateSet(this, _testGasFeeFlows, testGasFeeFlows === true);
|
|
271
|
-
__privateSet(this, _trace, trace ?? ((_request, fn) => fn?.()));
|
|
272
|
-
this.afterSign = hooks?.afterSign ?? (() => true);
|
|
273
|
-
this.beforeApproveOnInit = hooks?.beforeApproveOnInit ?? (() => true);
|
|
274
|
-
this.beforeCheckPendingTransaction = hooks?.beforeCheckPendingTransaction ?? /* istanbul ignore next */
|
|
275
|
-
(() => true);
|
|
276
|
-
this.beforePublish = hooks?.beforePublish ?? (() => true);
|
|
277
|
-
this.getAdditionalSignArguments = hooks?.getAdditionalSignArguments ?? (() => []);
|
|
278
|
-
this.publish = hooks?.publish ?? (() => Promise.resolve({ transactionHash: void 0 }));
|
|
279
|
-
this.nonceTracker = __privateMethod(this, _createNonceTracker, createNonceTracker_fn).call(this, {
|
|
280
|
-
provider,
|
|
281
|
-
blockTracker
|
|
282
|
-
});
|
|
283
|
-
const findNetworkClientIdByChainId = (chainId) => {
|
|
284
|
-
return this.messagingSystem.call(
|
|
285
|
-
`NetworkController:findNetworkClientIdByChainId`,
|
|
286
|
-
chainId
|
|
287
|
-
);
|
|
288
|
-
};
|
|
289
|
-
__privateSet(this, _multichainTrackingHelper, new MultichainTrackingHelper({
|
|
290
|
-
isMultichainEnabled,
|
|
291
|
-
provider,
|
|
292
|
-
nonceTracker: this.nonceTracker,
|
|
293
|
-
incomingTransactionOptions: incomingTransactions,
|
|
294
|
-
findNetworkClientIdByChainId,
|
|
295
|
-
getNetworkClientById: (networkClientId) => {
|
|
296
|
-
return this.messagingSystem.call(
|
|
297
|
-
`NetworkController:getNetworkClientById`,
|
|
298
|
-
networkClientId
|
|
299
|
-
);
|
|
300
|
-
},
|
|
301
|
-
getNetworkClientRegistry,
|
|
302
|
-
removeIncomingTransactionHelperListeners: __privateMethod(this, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn).bind(this),
|
|
303
|
-
removePendingTransactionTrackerListeners: __privateMethod(this, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn).bind(this),
|
|
304
|
-
createNonceTracker: __privateMethod(this, _createNonceTracker, createNonceTracker_fn).bind(this),
|
|
305
|
-
createIncomingTransactionHelper: __privateMethod(this, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn).bind(this),
|
|
306
|
-
createPendingTransactionTracker: __privateMethod(this, _createPendingTransactionTracker, createPendingTransactionTracker_fn).bind(this),
|
|
307
|
-
onNetworkStateChange: (listener) => {
|
|
308
|
-
this.messagingSystem.subscribe(
|
|
309
|
-
"NetworkController:stateChange",
|
|
310
|
-
listener
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
}));
|
|
314
|
-
__privateGet(this, _multichainTrackingHelper).initialize();
|
|
315
|
-
const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource({
|
|
316
|
-
includeTokenTransfers: incomingTransactions.includeTokenTransfers
|
|
317
|
-
});
|
|
318
|
-
this.incomingTransactionHelper = __privateMethod(this, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn).call(this, {
|
|
319
|
-
blockTracker,
|
|
320
|
-
etherscanRemoteTransactionSource
|
|
321
|
-
});
|
|
322
|
-
this.pendingTransactionTracker = __privateMethod(this, _createPendingTransactionTracker, createPendingTransactionTracker_fn).call(this, {
|
|
323
|
-
provider,
|
|
324
|
-
blockTracker
|
|
325
|
-
});
|
|
326
|
-
this.gasFeeFlows = __privateMethod(this, _getGasFeeFlows, getGasFeeFlows_fn).call(this);
|
|
327
|
-
this.layer1GasFeeFlows = __privateMethod(this, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn).call(this);
|
|
328
|
-
const gasFeePoller = new GasFeePoller({
|
|
329
|
-
findNetworkClientIdByChainId,
|
|
330
|
-
gasFeeFlows: this.gasFeeFlows,
|
|
331
|
-
getGasFeeControllerEstimates: this.getGasFeeEstimates,
|
|
332
|
-
getProvider: (chainId, networkClientId) => __privateGet(this, _multichainTrackingHelper).getProvider({
|
|
333
|
-
networkClientId,
|
|
334
|
-
chainId
|
|
335
|
-
}),
|
|
336
|
-
getTransactions: () => this.state.transactions,
|
|
337
|
-
layer1GasFeeFlows: this.layer1GasFeeFlows,
|
|
338
|
-
onStateChange: (listener) => {
|
|
339
|
-
this.messagingSystem.subscribe(
|
|
340
|
-
"TransactionController:stateChange",
|
|
341
|
-
listener
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
gasFeePoller.hub.on(
|
|
346
|
-
"transaction-updated",
|
|
347
|
-
__privateMethod(this, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn).bind(this)
|
|
348
|
-
);
|
|
349
|
-
this.messagingSystem.subscribe(
|
|
350
|
-
"TransactionController:stateChange",
|
|
351
|
-
__privateGet(this, _checkForPendingTransactionAndStartPolling)
|
|
352
|
-
);
|
|
353
|
-
onNetworkStateChange(() => {
|
|
354
|
-
projectLogger("Detected network change", this.getChainId());
|
|
355
|
-
this.pendingTransactionTracker.startIfPendingTransactions();
|
|
356
|
-
this.onBootCleanup();
|
|
357
|
-
});
|
|
358
|
-
this.onBootCleanup();
|
|
359
|
-
__privateGet(this, _checkForPendingTransactionAndStartPolling).call(this);
|
|
360
|
-
}
|
|
361
|
-
failTransaction(transactionMeta, error, actionId) {
|
|
362
|
-
const newTransactionMeta = merge({}, transactionMeta, {
|
|
363
|
-
error: normalizeTxError(error),
|
|
364
|
-
status: "failed" /* failed */
|
|
365
|
-
});
|
|
366
|
-
this.messagingSystem.publish(`${controllerName}:transactionFailed`, {
|
|
367
|
-
actionId,
|
|
368
|
-
error: error.message,
|
|
369
|
-
transactionMeta: newTransactionMeta
|
|
370
|
-
});
|
|
371
|
-
this.updateTransaction(
|
|
372
|
-
newTransactionMeta,
|
|
373
|
-
"TransactionController#failTransaction - Add error message and set status to failed"
|
|
374
|
-
);
|
|
375
|
-
this.onTransactionStatusChange(newTransactionMeta);
|
|
376
|
-
this.messagingSystem.publish(
|
|
377
|
-
`${controllerName}:transactionFinished`,
|
|
378
|
-
newTransactionMeta
|
|
379
|
-
);
|
|
380
|
-
__privateGet(this, _internalEvents).emit(
|
|
381
|
-
`${transactionMeta.id}:finished`,
|
|
382
|
-
newTransactionMeta
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
async registryLookup(fourBytePrefix) {
|
|
386
|
-
const registryMethod = await this.registry.lookup(fourBytePrefix);
|
|
387
|
-
if (!registryMethod) {
|
|
388
|
-
return {
|
|
389
|
-
registryMethod: "",
|
|
390
|
-
parsedRegistryMethod: { name: void 0, args: void 0 }
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
const parsedRegistryMethod = this.registry.parse(registryMethod);
|
|
394
|
-
return { registryMethod, parsedRegistryMethod };
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Stops polling and removes listeners to prepare the controller for garbage collection.
|
|
398
|
-
*/
|
|
399
|
-
destroy() {
|
|
400
|
-
__privateMethod(this, _stopAllTracking, stopAllTracking_fn).call(this);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Handle new method data request.
|
|
404
|
-
*
|
|
405
|
-
* @param fourBytePrefix - The method prefix.
|
|
406
|
-
* @returns The method data object corresponding to the given signature prefix.
|
|
407
|
-
*/
|
|
408
|
-
async handleMethodData(fourBytePrefix) {
|
|
409
|
-
const releaseLock = await this.mutex.acquire();
|
|
410
|
-
try {
|
|
411
|
-
const { methodData } = this.state;
|
|
412
|
-
const knownMethod = Object.keys(methodData).find(
|
|
413
|
-
(knownFourBytePrefix) => fourBytePrefix === knownFourBytePrefix
|
|
414
|
-
);
|
|
415
|
-
if (knownMethod) {
|
|
416
|
-
return methodData[fourBytePrefix];
|
|
417
|
-
}
|
|
418
|
-
const registry = await this.registryLookup(fourBytePrefix);
|
|
419
|
-
this.update((state) => {
|
|
420
|
-
state.methodData[fourBytePrefix] = registry;
|
|
421
|
-
});
|
|
422
|
-
return registry;
|
|
423
|
-
} finally {
|
|
424
|
-
releaseLock();
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Add a new unapproved transaction to state. Parameters will be validated, a
|
|
429
|
-
* unique transaction id will be generated, and gas and gasPrice will be calculated
|
|
430
|
-
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
431
|
-
*
|
|
432
|
-
* @param txParams - Standard parameters for an Ethereum transaction.
|
|
433
|
-
* @param opts - Additional options to control how the transaction is added.
|
|
434
|
-
* @param opts.actionId - Unique ID to prevent duplicate requests.
|
|
435
|
-
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
436
|
-
* @param opts.method - RPC method that requested the transaction.
|
|
437
|
-
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
438
|
-
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
439
|
-
* @param opts.securityAlertResponse - Response from security validator.
|
|
440
|
-
* @param opts.sendFlowHistory - The sendFlowHistory entries to add.
|
|
441
|
-
* @param opts.type - Type of transaction to add, such as 'cancel' or 'swap'.
|
|
442
|
-
* @param opts.swaps - Options for swaps transactions.
|
|
443
|
-
* @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
|
|
444
|
-
* @param opts.swaps.meta - Metadata for swap transaction.
|
|
445
|
-
* @param opts.networkClientId - The id of the network client for this transaction.
|
|
446
|
-
* @param opts.traceContext - The parent context for any new traces.
|
|
447
|
-
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
448
|
-
*/
|
|
449
|
-
async addTransaction(txParams, {
|
|
450
|
-
actionId,
|
|
451
|
-
deviceConfirmedOn,
|
|
452
|
-
method,
|
|
453
|
-
origin,
|
|
454
|
-
requireApproval,
|
|
455
|
-
securityAlertResponse,
|
|
456
|
-
sendFlowHistory,
|
|
457
|
-
swaps = {},
|
|
458
|
-
traceContext,
|
|
459
|
-
type,
|
|
460
|
-
networkClientId: requestNetworkClientId
|
|
461
|
-
} = {}) {
|
|
462
|
-
projectLogger("Adding transaction", txParams);
|
|
463
|
-
txParams = normalizeTransactionParams(txParams);
|
|
464
|
-
if (requestNetworkClientId && !__privateGet(this, _multichainTrackingHelper).has(requestNetworkClientId)) {
|
|
465
|
-
throw new Error(
|
|
466
|
-
"The networkClientId for this transaction could not be found"
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
const networkClientId = requestNetworkClientId ?? __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
|
|
470
|
-
const isEIP1559Compatible = await this.getEIP1559Compatibility(
|
|
471
|
-
networkClientId
|
|
472
|
-
);
|
|
473
|
-
validateTxParams(txParams, isEIP1559Compatible);
|
|
474
|
-
if (origin) {
|
|
475
|
-
await validateTransactionOrigin(
|
|
476
|
-
await this.getPermittedAccounts(origin),
|
|
477
|
-
__privateMethod(this, _getSelectedAccount, getSelectedAccount_fn).call(this).address,
|
|
478
|
-
txParams.from,
|
|
479
|
-
origin
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(
|
|
483
|
-
txParams,
|
|
484
|
-
origin
|
|
485
|
-
);
|
|
486
|
-
const chainId = this.getChainId(networkClientId);
|
|
487
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
488
|
-
networkClientId,
|
|
489
|
-
chainId
|
|
490
|
-
});
|
|
491
|
-
const transactionType = type ?? (await determineTransactionType(txParams, ethQuery)).type;
|
|
492
|
-
const existingTransactionMeta = this.getTransactionWithActionId(actionId);
|
|
493
|
-
let addedTransactionMeta = existingTransactionMeta ? cloneDeep(existingTransactionMeta) : {
|
|
494
|
-
// Add actionId to txMeta to check if same actionId is seen again
|
|
495
|
-
actionId,
|
|
496
|
-
chainId,
|
|
497
|
-
dappSuggestedGasFees,
|
|
498
|
-
deviceConfirmedOn,
|
|
499
|
-
id: random(),
|
|
500
|
-
origin,
|
|
501
|
-
securityAlertResponse,
|
|
502
|
-
status: "unapproved" /* unapproved */,
|
|
503
|
-
time: Date.now(),
|
|
504
|
-
txParams,
|
|
505
|
-
userEditedGasLimit: false,
|
|
506
|
-
verifiedOnBlockchain: false,
|
|
507
|
-
type: transactionType,
|
|
508
|
-
networkClientId
|
|
509
|
-
};
|
|
510
|
-
await __privateGet(this, _trace).call(this, { name: "Estimate Gas Properties", parentContext: traceContext }, (context) => this.updateGasProperties(addedTransactionMeta, {
|
|
511
|
-
traceContext: context
|
|
512
|
-
}));
|
|
513
|
-
if (!existingTransactionMeta) {
|
|
514
|
-
if (method && this.securityProviderRequest) {
|
|
515
|
-
const securityProviderResponse = await this.securityProviderRequest(
|
|
516
|
-
addedTransactionMeta,
|
|
517
|
-
method
|
|
518
|
-
);
|
|
519
|
-
addedTransactionMeta.securityProviderResponse = securityProviderResponse;
|
|
520
|
-
}
|
|
521
|
-
if (!this.isSendFlowHistoryDisabled) {
|
|
522
|
-
addedTransactionMeta.sendFlowHistory = sendFlowHistory ?? [];
|
|
523
|
-
}
|
|
524
|
-
if (!this.isHistoryDisabled) {
|
|
525
|
-
addedTransactionMeta = addInitialHistorySnapshot(addedTransactionMeta);
|
|
526
|
-
}
|
|
527
|
-
addedTransactionMeta = updateSwapsTransaction(
|
|
528
|
-
addedTransactionMeta,
|
|
529
|
-
transactionType,
|
|
530
|
-
swaps,
|
|
531
|
-
{
|
|
532
|
-
isSwapsDisabled: this.isSwapsDisabled,
|
|
533
|
-
cancelTransaction: this.cancelTransaction.bind(this),
|
|
534
|
-
messenger: this.messagingSystem
|
|
535
|
-
}
|
|
536
|
-
);
|
|
537
|
-
this.addMetadata(addedTransactionMeta);
|
|
538
|
-
if (requireApproval !== false) {
|
|
539
|
-
__privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta, {
|
|
540
|
-
traceContext
|
|
541
|
-
}).catch((error) => {
|
|
542
|
-
projectLogger("Error while updating simulation data", error);
|
|
543
|
-
throw error;
|
|
544
|
-
});
|
|
545
|
-
} else {
|
|
546
|
-
projectLogger("Skipping simulation as approval not required");
|
|
547
|
-
}
|
|
548
|
-
this.messagingSystem.publish(
|
|
549
|
-
`${controllerName}:unapprovedTransactionAdded`,
|
|
550
|
-
addedTransactionMeta
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
return {
|
|
554
|
-
result: this.processApproval(addedTransactionMeta, {
|
|
555
|
-
isExisting: Boolean(existingTransactionMeta),
|
|
556
|
-
requireApproval,
|
|
557
|
-
actionId,
|
|
558
|
-
traceContext
|
|
559
|
-
}),
|
|
560
|
-
transactionMeta: addedTransactionMeta
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
startIncomingTransactionPolling(networkClientIds = []) {
|
|
564
|
-
if (networkClientIds.length === 0) {
|
|
565
|
-
this.incomingTransactionHelper.start();
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
__privateGet(this, _multichainTrackingHelper).startIncomingTransactionPolling(
|
|
569
|
-
networkClientIds
|
|
570
|
-
);
|
|
571
|
-
}
|
|
572
|
-
stopIncomingTransactionPolling(networkClientIds = []) {
|
|
573
|
-
if (networkClientIds.length === 0) {
|
|
574
|
-
this.incomingTransactionHelper.stop();
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
__privateGet(this, _multichainTrackingHelper).stopIncomingTransactionPolling(
|
|
578
|
-
networkClientIds
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
stopAllIncomingTransactionPolling() {
|
|
582
|
-
this.incomingTransactionHelper.stop();
|
|
583
|
-
__privateGet(this, _multichainTrackingHelper).stopAllIncomingTransactionPolling();
|
|
584
|
-
}
|
|
585
|
-
async updateIncomingTransactions(networkClientIds = []) {
|
|
586
|
-
if (networkClientIds.length === 0) {
|
|
587
|
-
await this.incomingTransactionHelper.update();
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
await __privateGet(this, _multichainTrackingHelper).updateIncomingTransactions(
|
|
591
|
-
networkClientIds
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
596
|
-
* and emitting a `<tx.id>:finished` hub event.
|
|
597
|
-
*
|
|
598
|
-
* @param transactionId - The ID of the transaction to cancel.
|
|
599
|
-
* @param gasValues - The gas values to use for the cancellation transaction.
|
|
600
|
-
* @param options - The options for the cancellation transaction.
|
|
601
|
-
* @param options.actionId - Unique ID to prevent duplicate requests.
|
|
602
|
-
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
603
|
-
*/
|
|
604
|
-
async stopTransaction(transactionId, gasValues, {
|
|
605
|
-
estimatedBaseFee,
|
|
606
|
-
actionId
|
|
607
|
-
} = {}) {
|
|
608
|
-
return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
|
|
609
|
-
actionId,
|
|
610
|
-
estimatedBaseFee,
|
|
611
|
-
gasValues,
|
|
612
|
-
label: "cancel",
|
|
613
|
-
rate: CANCEL_RATE,
|
|
614
|
-
transactionId,
|
|
615
|
-
transactionType: "cancel" /* cancel */,
|
|
616
|
-
prepareTransactionParams: (txParams) => {
|
|
617
|
-
delete txParams.data;
|
|
618
|
-
txParams.to = txParams.from;
|
|
619
|
-
txParams.value = "0x0";
|
|
620
|
-
},
|
|
621
|
-
afterSubmit: (newTransactionMeta) => {
|
|
622
|
-
this.messagingSystem.publish(
|
|
623
|
-
`${controllerName}:transactionFinished`,
|
|
624
|
-
newTransactionMeta
|
|
625
|
-
);
|
|
626
|
-
__privateGet(this, _internalEvents).emit(
|
|
627
|
-
`${newTransactionMeta.id}:finished`,
|
|
628
|
-
newTransactionMeta
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
635
|
-
*
|
|
636
|
-
* @param transactionId - The ID of the transaction to speed up.
|
|
637
|
-
* @param gasValues - The gas values to use for the speed up transaction.
|
|
638
|
-
* @param options - The options for the speed up transaction.
|
|
639
|
-
* @param options.actionId - Unique ID to prevent duplicate requests
|
|
640
|
-
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
641
|
-
*/
|
|
642
|
-
async speedUpTransaction(transactionId, gasValues, {
|
|
643
|
-
actionId,
|
|
644
|
-
estimatedBaseFee
|
|
645
|
-
} = {}) {
|
|
646
|
-
return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
|
|
647
|
-
actionId,
|
|
648
|
-
estimatedBaseFee,
|
|
649
|
-
gasValues,
|
|
650
|
-
label: "speed up",
|
|
651
|
-
rate: SPEED_UP_RATE,
|
|
652
|
-
transactionId,
|
|
653
|
-
transactionType: "retry" /* retry */,
|
|
654
|
-
afterSubmit: (newTransactionMeta) => {
|
|
655
|
-
this.messagingSystem.publish(
|
|
656
|
-
`${controllerName}:speedupTransactionAdded`,
|
|
657
|
-
newTransactionMeta
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Estimates required gas for a given transaction.
|
|
664
|
-
*
|
|
665
|
-
* @param transaction - The transaction to estimate gas for.
|
|
666
|
-
* @param networkClientId - The network client id to use for the estimate.
|
|
667
|
-
* @returns The gas and gas price.
|
|
668
|
-
*/
|
|
669
|
-
async estimateGas(transaction, networkClientId) {
|
|
670
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
671
|
-
networkClientId
|
|
672
|
-
});
|
|
673
|
-
const { estimatedGas, simulationFails } = await estimateGas(
|
|
674
|
-
transaction,
|
|
675
|
-
ethQuery
|
|
676
|
-
);
|
|
677
|
-
return { gas: estimatedGas, simulationFails };
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.
|
|
681
|
-
*
|
|
682
|
-
* @param transaction - The transaction params to estimate gas for.
|
|
683
|
-
* @param multiplier - The multiplier to use for the gas buffer.
|
|
684
|
-
* @param networkClientId - The network client id to use for the estimate.
|
|
685
|
-
*/
|
|
686
|
-
async estimateGasBuffered(transaction, multiplier, networkClientId) {
|
|
687
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
688
|
-
networkClientId
|
|
689
|
-
});
|
|
690
|
-
const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(
|
|
691
|
-
transaction,
|
|
692
|
-
ethQuery
|
|
693
|
-
);
|
|
694
|
-
const gas = addGasBuffer(estimatedGas, blockGasLimit, multiplier);
|
|
695
|
-
return {
|
|
696
|
-
gas,
|
|
697
|
-
simulationFails
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Updates an existing transaction in state.
|
|
702
|
-
*
|
|
703
|
-
* @param transactionMeta - The new transaction to store in state.
|
|
704
|
-
* @param note - A note or update reason to include in the transaction history.
|
|
705
|
-
*/
|
|
706
|
-
updateTransaction(transactionMeta, note) {
|
|
707
|
-
const { id: transactionId } = transactionMeta;
|
|
708
|
-
__privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, note }, () => ({
|
|
709
|
-
...transactionMeta
|
|
710
|
-
}));
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Update the security alert response for a transaction.
|
|
714
|
-
*
|
|
715
|
-
* @param transactionId - ID of the transaction.
|
|
716
|
-
* @param securityAlertResponse - The new security alert response for the transaction.
|
|
717
|
-
*/
|
|
718
|
-
updateSecurityAlertResponse(transactionId, securityAlertResponse) {
|
|
719
|
-
if (!securityAlertResponse) {
|
|
720
|
-
throw new Error(
|
|
721
|
-
"updateSecurityAlertResponse: securityAlertResponse should not be null"
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
725
|
-
if (!transactionMeta) {
|
|
726
|
-
throw new Error(
|
|
727
|
-
`Cannot update security alert response as no transaction metadata found`
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
const updatedTransactionMeta = {
|
|
731
|
-
...transactionMeta,
|
|
732
|
-
securityAlertResponse
|
|
733
|
-
};
|
|
734
|
-
this.updateTransaction(
|
|
735
|
-
updatedTransactionMeta,
|
|
736
|
-
`${controllerName}:updatesecurityAlertResponse - securityAlertResponse updated`
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Removes all transactions from state, optionally based on the current network.
|
|
741
|
-
*
|
|
742
|
-
* @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
|
|
743
|
-
* current network. If `true`, all transactions are wiped.
|
|
744
|
-
* @param address - If specified, only transactions originating from this address will be
|
|
745
|
-
* wiped on current network.
|
|
746
|
-
*/
|
|
747
|
-
wipeTransactions(ignoreNetwork, address) {
|
|
748
|
-
if (ignoreNetwork && !address) {
|
|
749
|
-
this.update((state) => {
|
|
750
|
-
state.transactions = [];
|
|
751
|
-
});
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
const currentChainId = this.getChainId();
|
|
755
|
-
const newTransactions = this.state.transactions.filter(
|
|
756
|
-
({ chainId, txParams }) => {
|
|
757
|
-
const isMatchingNetwork = ignoreNetwork || chainId === currentChainId;
|
|
758
|
-
if (!isMatchingNetwork) {
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
const isMatchingAddress = !address || txParams.from?.toLowerCase() === address.toLowerCase();
|
|
762
|
-
return !isMatchingAddress;
|
|
763
|
-
}
|
|
764
|
-
);
|
|
765
|
-
this.update((state) => {
|
|
766
|
-
state.transactions = this.trimTransactionsForState(newTransactions);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Adds external provided transaction to state as confirmed transaction.
|
|
771
|
-
*
|
|
772
|
-
* @param transactionMeta - TransactionMeta to add transactions.
|
|
773
|
-
* @param transactionReceipt - TransactionReceipt of the external transaction.
|
|
774
|
-
* @param baseFeePerGas - Base fee per gas of the external transaction.
|
|
775
|
-
*/
|
|
776
|
-
async confirmExternalTransaction(transactionMeta, transactionReceipt, baseFeePerGas) {
|
|
777
|
-
const newTransactionMeta = this.addExternalTransaction(transactionMeta);
|
|
778
|
-
try {
|
|
779
|
-
const transactionId = newTransactionMeta.id;
|
|
780
|
-
const updatedTransactionMeta = {
|
|
781
|
-
...newTransactionMeta,
|
|
782
|
-
status: "confirmed" /* confirmed */,
|
|
783
|
-
txReceipt: transactionReceipt
|
|
784
|
-
};
|
|
785
|
-
if (baseFeePerGas) {
|
|
786
|
-
updatedTransactionMeta.baseFeePerGas = baseFeePerGas;
|
|
787
|
-
}
|
|
788
|
-
this.markNonceDuplicatesDropped(transactionId);
|
|
789
|
-
this.updateTransaction(
|
|
790
|
-
updatedTransactionMeta,
|
|
791
|
-
`${controllerName}:confirmExternalTransaction - Add external transaction`
|
|
792
|
-
);
|
|
793
|
-
this.onTransactionStatusChange(updatedTransactionMeta);
|
|
794
|
-
this.updatePostBalance(updatedTransactionMeta).catch((error) => {
|
|
795
|
-
projectLogger("Error while updating post balance", error);
|
|
796
|
-
throw error;
|
|
797
|
-
});
|
|
798
|
-
this.messagingSystem.publish(
|
|
799
|
-
`${controllerName}:transactionConfirmed`,
|
|
800
|
-
updatedTransactionMeta
|
|
801
|
-
);
|
|
802
|
-
} catch (error) {
|
|
803
|
-
console.error("Failed to confirm external transaction", error);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* Append new send flow history to a transaction.
|
|
808
|
-
*
|
|
809
|
-
* @param transactionID - The ID of the transaction to update.
|
|
810
|
-
* @param currentSendFlowHistoryLength - The length of the current sendFlowHistory array.
|
|
811
|
-
* @param sendFlowHistoryToAdd - The sendFlowHistory entries to add.
|
|
812
|
-
* @returns The updated transactionMeta.
|
|
813
|
-
*/
|
|
814
|
-
updateTransactionSendFlowHistory(transactionID, currentSendFlowHistoryLength, sendFlowHistoryToAdd) {
|
|
815
|
-
if (this.isSendFlowHistoryDisabled) {
|
|
816
|
-
throw new Error(
|
|
817
|
-
"Send flow history is disabled for the current transaction controller"
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
const transactionMeta = this.getTransaction(transactionID);
|
|
821
|
-
if (!transactionMeta) {
|
|
822
|
-
throw new Error(
|
|
823
|
-
`Cannot update send flow history as no transaction metadata found`
|
|
824
|
-
);
|
|
825
|
-
}
|
|
826
|
-
validateIfTransactionUnapproved(
|
|
827
|
-
transactionMeta,
|
|
828
|
-
"updateTransactionSendFlowHistory"
|
|
829
|
-
);
|
|
830
|
-
const sendFlowHistory = transactionMeta.sendFlowHistory ?? [];
|
|
831
|
-
if (currentSendFlowHistoryLength === sendFlowHistory.length) {
|
|
832
|
-
const updatedTransactionMeta = {
|
|
833
|
-
...transactionMeta,
|
|
834
|
-
sendFlowHistory: [...sendFlowHistory, ...sendFlowHistoryToAdd]
|
|
835
|
-
};
|
|
836
|
-
this.updateTransaction(
|
|
837
|
-
updatedTransactionMeta,
|
|
838
|
-
`${controllerName}:updateTransactionSendFlowHistory - sendFlowHistory updated`
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
return this.getTransaction(transactionID);
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Update the gas values of a transaction.
|
|
845
|
-
*
|
|
846
|
-
* @param transactionId - The ID of the transaction to update.
|
|
847
|
-
* @param gasValues - Gas values to update.
|
|
848
|
-
* @param gasValues.gas - Same as transaction.gasLimit.
|
|
849
|
-
* @param gasValues.gasLimit - Maxmimum number of units of gas to use for this transaction.
|
|
850
|
-
* @param gasValues.gasPrice - Price per gas for legacy transactions.
|
|
851
|
-
* @param gasValues.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.
|
|
852
|
-
* @param gasValues.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.
|
|
853
|
-
* @param gasValues.estimateUsed - Which estimate level was used.
|
|
854
|
-
* @param gasValues.estimateSuggested - Which estimate level that the API suggested.
|
|
855
|
-
* @param gasValues.defaultGasEstimates - The default estimate for gas.
|
|
856
|
-
* @param gasValues.originalGasEstimate - Original estimate for gas.
|
|
857
|
-
* @param gasValues.userEditedGasLimit - The gas limit supplied by user.
|
|
858
|
-
* @param gasValues.userFeeLevel - Estimate level user selected.
|
|
859
|
-
* @returns The updated transactionMeta.
|
|
860
|
-
*/
|
|
861
|
-
updateTransactionGasFees(transactionId, {
|
|
862
|
-
defaultGasEstimates,
|
|
863
|
-
estimateUsed,
|
|
864
|
-
estimateSuggested,
|
|
865
|
-
gas,
|
|
866
|
-
gasLimit,
|
|
867
|
-
gasPrice,
|
|
868
|
-
maxPriorityFeePerGas,
|
|
869
|
-
maxFeePerGas,
|
|
870
|
-
originalGasEstimate,
|
|
871
|
-
userEditedGasLimit,
|
|
872
|
-
userFeeLevel
|
|
873
|
-
}) {
|
|
874
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
875
|
-
if (!transactionMeta) {
|
|
876
|
-
throw new Error(
|
|
877
|
-
`Cannot update transaction as no transaction metadata found`
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
validateIfTransactionUnapproved(
|
|
881
|
-
transactionMeta,
|
|
882
|
-
"updateTransactionGasFees"
|
|
883
|
-
);
|
|
884
|
-
let transactionGasFees = {
|
|
885
|
-
txParams: {
|
|
886
|
-
gas,
|
|
887
|
-
gasLimit,
|
|
888
|
-
gasPrice,
|
|
889
|
-
maxPriorityFeePerGas,
|
|
890
|
-
maxFeePerGas
|
|
891
|
-
},
|
|
892
|
-
defaultGasEstimates,
|
|
893
|
-
estimateUsed,
|
|
894
|
-
estimateSuggested,
|
|
895
|
-
originalGasEstimate,
|
|
896
|
-
userEditedGasLimit,
|
|
897
|
-
userFeeLevel
|
|
898
|
-
// TODO: Replace `any` with type
|
|
899
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
900
|
-
};
|
|
901
|
-
transactionGasFees.txParams = pickBy(transactionGasFees.txParams);
|
|
902
|
-
transactionGasFees = pickBy(transactionGasFees);
|
|
903
|
-
const updatedMeta = merge({}, transactionMeta, transactionGasFees);
|
|
904
|
-
this.updateTransaction(
|
|
905
|
-
updatedMeta,
|
|
906
|
-
`${controllerName}:updateTransactionGasFees - gas values updated`
|
|
907
|
-
);
|
|
908
|
-
return this.getTransaction(transactionId);
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Update the previous gas values of a transaction.
|
|
912
|
-
*
|
|
913
|
-
* @param transactionId - The ID of the transaction to update.
|
|
914
|
-
* @param previousGas - Previous gas values to update.
|
|
915
|
-
* @param previousGas.gasLimit - Maxmimum number of units of gas to use for this transaction.
|
|
916
|
-
* @param previousGas.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.
|
|
917
|
-
* @param previousGas.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.
|
|
918
|
-
* @returns The updated transactionMeta.
|
|
919
|
-
*/
|
|
920
|
-
updatePreviousGasParams(transactionId, {
|
|
921
|
-
gasLimit,
|
|
922
|
-
maxFeePerGas,
|
|
923
|
-
maxPriorityFeePerGas
|
|
924
|
-
}) {
|
|
925
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
926
|
-
if (!transactionMeta) {
|
|
927
|
-
throw new Error(
|
|
928
|
-
`Cannot update transaction as no transaction metadata found`
|
|
929
|
-
);
|
|
930
|
-
}
|
|
931
|
-
validateIfTransactionUnapproved(transactionMeta, "updatePreviousGasParams");
|
|
932
|
-
const transactionPreviousGas = {
|
|
933
|
-
previousGas: {
|
|
934
|
-
gasLimit,
|
|
935
|
-
maxFeePerGas,
|
|
936
|
-
maxPriorityFeePerGas
|
|
937
|
-
}
|
|
938
|
-
// TODO: Replace `any` with type
|
|
939
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
940
|
-
};
|
|
941
|
-
transactionPreviousGas.previousGas = pickBy(
|
|
942
|
-
transactionPreviousGas.previousGas
|
|
943
|
-
);
|
|
944
|
-
const updatedMeta = merge({}, transactionMeta, transactionPreviousGas);
|
|
945
|
-
this.updateTransaction(
|
|
946
|
-
updatedMeta,
|
|
947
|
-
`${controllerName}:updatePreviousGasParams - Previous gas values updated`
|
|
948
|
-
);
|
|
949
|
-
return this.getTransaction(transactionId);
|
|
950
|
-
}
|
|
951
|
-
async getNonceLock(address, networkClientId) {
|
|
952
|
-
return __privateGet(this, _multichainTrackingHelper).getNonceLock(
|
|
953
|
-
address,
|
|
954
|
-
networkClientId
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Updates the editable parameters of a transaction.
|
|
959
|
-
*
|
|
960
|
-
* @param txId - The ID of the transaction to update.
|
|
961
|
-
* @param params - The editable parameters to update.
|
|
962
|
-
* @param params.data - Data to pass with the transaction.
|
|
963
|
-
* @param params.gas - Maximum number of units of gas to use for the transaction.
|
|
964
|
-
* @param params.gasPrice - Price per gas for legacy transactions.
|
|
965
|
-
* @param params.from - Address to send the transaction from.
|
|
966
|
-
* @param params.to - Address to send the transaction to.
|
|
967
|
-
* @param params.value - Value associated with the transaction.
|
|
968
|
-
* @returns The updated transaction metadata.
|
|
969
|
-
*/
|
|
970
|
-
async updateEditableParams(txId, {
|
|
971
|
-
data,
|
|
972
|
-
gas,
|
|
973
|
-
gasPrice,
|
|
974
|
-
from,
|
|
975
|
-
to,
|
|
976
|
-
value
|
|
977
|
-
}) {
|
|
978
|
-
const transactionMeta = this.getTransaction(txId);
|
|
979
|
-
if (!transactionMeta) {
|
|
980
|
-
throw new Error(
|
|
981
|
-
`Cannot update editable params as no transaction metadata found`
|
|
982
|
-
);
|
|
983
|
-
}
|
|
984
|
-
validateIfTransactionUnapproved(transactionMeta, "updateEditableParams");
|
|
985
|
-
const editableParams = {
|
|
986
|
-
txParams: {
|
|
987
|
-
data,
|
|
988
|
-
from,
|
|
989
|
-
to,
|
|
990
|
-
value,
|
|
991
|
-
gas,
|
|
992
|
-
gasPrice
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
editableParams.txParams = pickBy(
|
|
996
|
-
editableParams.txParams
|
|
997
|
-
);
|
|
998
|
-
const updatedTransaction = merge({}, transactionMeta, editableParams);
|
|
999
|
-
const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
|
|
1000
|
-
chainId: transactionMeta.chainId,
|
|
1001
|
-
networkClientId: transactionMeta.networkClientId
|
|
1002
|
-
});
|
|
1003
|
-
const ethQuery = new EthQuery(provider);
|
|
1004
|
-
const { type } = await determineTransactionType(
|
|
1005
|
-
updatedTransaction.txParams,
|
|
1006
|
-
ethQuery
|
|
1007
|
-
);
|
|
1008
|
-
updatedTransaction.type = type;
|
|
1009
|
-
await updateTransactionLayer1GasFee({
|
|
1010
|
-
layer1GasFeeFlows: this.layer1GasFeeFlows,
|
|
1011
|
-
provider,
|
|
1012
|
-
transactionMeta: updatedTransaction
|
|
1013
|
-
});
|
|
1014
|
-
this.updateTransaction(
|
|
1015
|
-
updatedTransaction,
|
|
1016
|
-
`Update Editable Params for ${txId}`
|
|
1017
|
-
);
|
|
1018
|
-
return this.getTransaction(txId);
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Signs and returns the raw transaction data for provided transaction params list.
|
|
1022
|
-
*
|
|
1023
|
-
* @param listOfTxParams - The list of transaction params to approve.
|
|
1024
|
-
* @param opts - Options bag.
|
|
1025
|
-
* @param opts.hasNonce - Whether the transactions already have a nonce.
|
|
1026
|
-
* @returns The raw transactions.
|
|
1027
|
-
*/
|
|
1028
|
-
async approveTransactionsWithSameNonce(listOfTxParams = [], { hasNonce } = {}) {
|
|
1029
|
-
projectLogger("Approving transactions with same nonce", {
|
|
1030
|
-
transactions: listOfTxParams
|
|
1031
|
-
});
|
|
1032
|
-
if (listOfTxParams.length === 0) {
|
|
1033
|
-
return "";
|
|
1034
|
-
}
|
|
1035
|
-
const initialTx = listOfTxParams[0];
|
|
1036
|
-
const common = this.getCommonConfiguration(initialTx.chainId);
|
|
1037
|
-
let networkClientId;
|
|
1038
|
-
try {
|
|
1039
|
-
networkClientId = this.messagingSystem.call(
|
|
1040
|
-
`NetworkController:findNetworkClientIdByChainId`,
|
|
1041
|
-
initialTx.chainId
|
|
1042
|
-
);
|
|
1043
|
-
} catch (err) {
|
|
1044
|
-
projectLogger("failed to find networkClientId from chainId", err);
|
|
1045
|
-
}
|
|
1046
|
-
const initialTxAsEthTx = TransactionFactory.fromTxData(initialTx, {
|
|
1047
|
-
common
|
|
1048
|
-
});
|
|
1049
|
-
const initialTxAsSerializedHex = bufferToHex(initialTxAsEthTx.serialize());
|
|
1050
|
-
if (this.approvingTransactionIds.has(initialTxAsSerializedHex)) {
|
|
1051
|
-
return "";
|
|
1052
|
-
}
|
|
1053
|
-
this.approvingTransactionIds.add(initialTxAsSerializedHex);
|
|
1054
|
-
let rawTransactions, nonceLock;
|
|
1055
|
-
try {
|
|
1056
|
-
const fromAddress = initialTx.from;
|
|
1057
|
-
const requiresNonce = hasNonce !== true;
|
|
1058
|
-
nonceLock = requiresNonce ? await this.getNonceLock(fromAddress, networkClientId) : void 0;
|
|
1059
|
-
const nonce = nonceLock ? add0x(nonceLock.nextNonce.toString(16)) : initialTx.nonce;
|
|
1060
|
-
if (nonceLock) {
|
|
1061
|
-
projectLogger("Using nonce from nonce tracker", nonce, nonceLock.nonceDetails);
|
|
1062
|
-
}
|
|
1063
|
-
rawTransactions = await Promise.all(
|
|
1064
|
-
listOfTxParams.map((txParams) => {
|
|
1065
|
-
txParams.nonce = nonce;
|
|
1066
|
-
return this.signExternalTransaction(txParams.chainId, txParams);
|
|
1067
|
-
})
|
|
1068
|
-
);
|
|
1069
|
-
} catch (err) {
|
|
1070
|
-
projectLogger("Error while signing transactions with same nonce", err);
|
|
1071
|
-
throw err;
|
|
1072
|
-
} finally {
|
|
1073
|
-
nonceLock?.releaseLock();
|
|
1074
|
-
this.approvingTransactionIds.delete(initialTxAsSerializedHex);
|
|
1075
|
-
}
|
|
1076
|
-
return rawTransactions;
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* Update a custodial transaction.
|
|
1080
|
-
*
|
|
1081
|
-
* @param transactionId - The ID of the transaction to update.
|
|
1082
|
-
* @param options - The custodial transaction options to update.
|
|
1083
|
-
* @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
|
|
1084
|
-
* @param options.hash - The new hash value to be assigned.
|
|
1085
|
-
* @param options.status - The new status value to be assigned.
|
|
1086
|
-
*/
|
|
1087
|
-
updateCustodialTransaction(transactionId, {
|
|
1088
|
-
errorMessage,
|
|
1089
|
-
hash,
|
|
1090
|
-
status
|
|
1091
|
-
}) {
|
|
1092
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
1093
|
-
if (!transactionMeta) {
|
|
1094
|
-
throw new Error(
|
|
1095
|
-
`Cannot update custodial transaction as no transaction metadata found`
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
if (!transactionMeta.custodyId) {
|
|
1099
|
-
throw new Error("Transaction must be a custodian transaction");
|
|
1100
|
-
}
|
|
1101
|
-
if (status && ![
|
|
1102
|
-
"submitted" /* submitted */,
|
|
1103
|
-
"signed" /* signed */,
|
|
1104
|
-
"failed" /* failed */
|
|
1105
|
-
].includes(status)) {
|
|
1106
|
-
throw new Error(
|
|
1107
|
-
`Cannot update custodial transaction with status: ${status}`
|
|
1108
|
-
);
|
|
1109
|
-
}
|
|
1110
|
-
const updatedTransactionMeta = merge(
|
|
1111
|
-
{},
|
|
1112
|
-
transactionMeta,
|
|
1113
|
-
pickBy({ hash, status })
|
|
1114
|
-
);
|
|
1115
|
-
if (updatedTransactionMeta.status === "submitted" /* submitted */) {
|
|
1116
|
-
updatedTransactionMeta.submittedTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1117
|
-
}
|
|
1118
|
-
if (updatedTransactionMeta.status === "failed" /* failed */) {
|
|
1119
|
-
updatedTransactionMeta.error = normalizeTxError(new Error(errorMessage));
|
|
1120
|
-
}
|
|
1121
|
-
this.updateTransaction(
|
|
1122
|
-
updatedTransactionMeta,
|
|
1123
|
-
`${controllerName}:updateCustodialTransaction - Custodial transaction updated`
|
|
1124
|
-
);
|
|
1125
|
-
if (["submitted" /* submitted */, "failed" /* failed */].includes(
|
|
1126
|
-
status
|
|
1127
|
-
)) {
|
|
1128
|
-
this.messagingSystem.publish(
|
|
1129
|
-
`${controllerName}:transactionFinished`,
|
|
1130
|
-
updatedTransactionMeta
|
|
1131
|
-
);
|
|
1132
|
-
__privateGet(this, _internalEvents).emit(
|
|
1133
|
-
`${updatedTransactionMeta.id}:finished`,
|
|
1134
|
-
updatedTransactionMeta
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
/**
|
|
1139
|
-
* Creates approvals for all unapproved transactions persisted.
|
|
1140
|
-
*/
|
|
1141
|
-
initApprovals() {
|
|
1142
|
-
const chainId = this.getChainId();
|
|
1143
|
-
const unapprovedTxs = this.state.transactions.filter(
|
|
1144
|
-
(transaction) => transaction.status === "unapproved" /* unapproved */ && transaction.chainId === chainId && !transaction.isUserOperation
|
|
1145
|
-
);
|
|
1146
|
-
for (const txMeta of unapprovedTxs) {
|
|
1147
|
-
this.processApproval(txMeta, {
|
|
1148
|
-
shouldShowRequest: false
|
|
1149
|
-
}).catch((error) => {
|
|
1150
|
-
if (error?.code === errorCodes.provider.userRejectedRequest) {
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
console.error("Error during persisted transaction approval", error);
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Search transaction metadata for matching entries.
|
|
1159
|
-
*
|
|
1160
|
-
* @param opts - Options bag.
|
|
1161
|
-
* @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.
|
|
1162
|
-
* @param opts.initialList - The transactions to search. Defaults to the current state.
|
|
1163
|
-
* @param opts.filterToCurrentNetwork - Whether to filter the results to the current network. Defaults to true.
|
|
1164
|
-
* @param opts.limit - The maximum number of transactions to return. No limit by default.
|
|
1165
|
-
* @returns An array of transactions matching the provided options.
|
|
1166
|
-
*/
|
|
1167
|
-
getTransactions({
|
|
1168
|
-
searchCriteria = {},
|
|
1169
|
-
initialList,
|
|
1170
|
-
filterToCurrentNetwork = true,
|
|
1171
|
-
limit
|
|
1172
|
-
} = {}) {
|
|
1173
|
-
const chainId = this.getChainId();
|
|
1174
|
-
const predicateMethods = mapValues(searchCriteria, (predicate) => {
|
|
1175
|
-
return typeof predicate === "function" ? predicate : (
|
|
1176
|
-
// TODO: Replace `any` with type
|
|
1177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1178
|
-
(v) => v === predicate
|
|
1179
|
-
);
|
|
1180
|
-
});
|
|
1181
|
-
const transactionsToFilter = initialList ?? this.state.transactions;
|
|
1182
|
-
const filteredTransactions = sortBy(
|
|
1183
|
-
pickBy(transactionsToFilter, (transaction) => {
|
|
1184
|
-
if (filterToCurrentNetwork && transaction.chainId !== chainId) {
|
|
1185
|
-
return false;
|
|
1186
|
-
}
|
|
1187
|
-
for (const [key, predicate] of Object.entries(predicateMethods)) {
|
|
1188
|
-
if (key in transaction.txParams) {
|
|
1189
|
-
if (predicate(transaction.txParams[key]) === false) {
|
|
1190
|
-
return false;
|
|
1191
|
-
}
|
|
1192
|
-
} else if (predicate(transaction[key]) === false) {
|
|
1193
|
-
return false;
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
return true;
|
|
1197
|
-
}),
|
|
1198
|
-
"time"
|
|
1199
|
-
);
|
|
1200
|
-
if (limit !== void 0) {
|
|
1201
|
-
const nonces = /* @__PURE__ */ new Set();
|
|
1202
|
-
const txs = [];
|
|
1203
|
-
for (let i = filteredTransactions.length - 1; i > -1; i--) {
|
|
1204
|
-
const txMeta = filteredTransactions[i];
|
|
1205
|
-
const { nonce } = txMeta.txParams;
|
|
1206
|
-
if (!nonces.has(nonce)) {
|
|
1207
|
-
if (nonces.size < limit) {
|
|
1208
|
-
nonces.add(nonce);
|
|
1209
|
-
} else {
|
|
1210
|
-
continue;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
txs.unshift(txMeta);
|
|
1214
|
-
}
|
|
1215
|
-
return txs;
|
|
1216
|
-
}
|
|
1217
|
-
return filteredTransactions;
|
|
1218
|
-
}
|
|
1219
|
-
async estimateGasFee({
|
|
1220
|
-
transactionParams,
|
|
1221
|
-
chainId,
|
|
1222
|
-
networkClientId: requestNetworkClientId
|
|
1223
|
-
}) {
|
|
1224
|
-
const networkClientId = __privateMethod(this, _getNetworkClientId, getNetworkClientId_fn).call(this, {
|
|
1225
|
-
networkClientId: requestNetworkClientId,
|
|
1226
|
-
chainId
|
|
1227
|
-
});
|
|
1228
|
-
const transactionMeta = {
|
|
1229
|
-
txParams: transactionParams,
|
|
1230
|
-
chainId,
|
|
1231
|
-
networkClientId
|
|
1232
|
-
};
|
|
1233
|
-
const gasFeeFlow = getGasFeeFlow(
|
|
1234
|
-
transactionMeta,
|
|
1235
|
-
this.gasFeeFlows
|
|
1236
|
-
);
|
|
1237
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
1238
|
-
networkClientId,
|
|
1239
|
-
chainId
|
|
1240
|
-
});
|
|
1241
|
-
const gasFeeControllerData = await this.getGasFeeEstimates({
|
|
1242
|
-
networkClientId
|
|
1243
|
-
});
|
|
1244
|
-
return gasFeeFlow.getGasFees({
|
|
1245
|
-
ethQuery,
|
|
1246
|
-
gasFeeControllerData,
|
|
1247
|
-
transactionMeta
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Determine the layer 1 gas fee for the given transaction parameters.
|
|
1252
|
-
*
|
|
1253
|
-
* @param request - The request object.
|
|
1254
|
-
* @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.
|
|
1255
|
-
* @param request.chainId - The ID of the chain where the transaction will be executed.
|
|
1256
|
-
* @param request.networkClientId - The ID of a specific network client to process the transaction.
|
|
1257
|
-
*/
|
|
1258
|
-
async getLayer1GasFee({
|
|
1259
|
-
transactionParams,
|
|
1260
|
-
chainId,
|
|
1261
|
-
networkClientId
|
|
1262
|
-
}) {
|
|
1263
|
-
const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
|
|
1264
|
-
networkClientId,
|
|
1265
|
-
chainId
|
|
1266
|
-
});
|
|
1267
|
-
return await getTransactionLayer1GasFee({
|
|
1268
|
-
layer1GasFeeFlows: this.layer1GasFeeFlows,
|
|
1269
|
-
provider,
|
|
1270
|
-
transactionMeta: {
|
|
1271
|
-
txParams: transactionParams,
|
|
1272
|
-
chainId
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
async signExternalTransaction(chainId, transactionParams) {
|
|
1277
|
-
if (!this.sign) {
|
|
1278
|
-
throw new Error("No sign method defined.");
|
|
1279
|
-
}
|
|
1280
|
-
const normalizedTransactionParams = normalizeTransactionParams(transactionParams);
|
|
1281
|
-
const type = isEIP1559Transaction(normalizedTransactionParams) ? "0x2" /* feeMarket */ : "0x0" /* legacy */;
|
|
1282
|
-
const updatedTransactionParams = {
|
|
1283
|
-
...normalizedTransactionParams,
|
|
1284
|
-
type,
|
|
1285
|
-
gasLimit: normalizedTransactionParams.gas,
|
|
1286
|
-
chainId
|
|
1287
|
-
};
|
|
1288
|
-
const { from } = updatedTransactionParams;
|
|
1289
|
-
const common = this.getCommonConfiguration(chainId);
|
|
1290
|
-
const unsignedTransaction = TransactionFactory.fromTxData(
|
|
1291
|
-
updatedTransactionParams,
|
|
1292
|
-
{ common }
|
|
1293
|
-
);
|
|
1294
|
-
const signedTransaction = await this.sign(unsignedTransaction, from);
|
|
1295
|
-
const rawTransaction = bufferToHex(signedTransaction.serialize());
|
|
1296
|
-
return rawTransaction;
|
|
1297
|
-
}
|
|
1298
|
-
/**
|
|
1299
|
-
* Removes unapproved transactions from state.
|
|
1300
|
-
*/
|
|
1301
|
-
clearUnapprovedTransactions() {
|
|
1302
|
-
const transactions = this.state.transactions.filter(
|
|
1303
|
-
({ status }) => status !== "unapproved" /* unapproved */
|
|
1304
|
-
);
|
|
1305
|
-
this.update((state) => {
|
|
1306
|
-
state.transactions = this.trimTransactionsForState(transactions);
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Stop the signing process for a specific transaction.
|
|
1311
|
-
* Throws an error causing the transaction status to be set to failed.
|
|
1312
|
-
* @param transactionId - The ID of the transaction to stop signing.
|
|
1313
|
-
*/
|
|
1314
|
-
abortTransactionSigning(transactionId) {
|
|
1315
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
1316
|
-
if (!transactionMeta) {
|
|
1317
|
-
throw new Error(`Cannot abort signing as no transaction metadata found`);
|
|
1318
|
-
}
|
|
1319
|
-
const abortCallback = this.signAbortCallbacks.get(transactionId);
|
|
1320
|
-
if (!abortCallback) {
|
|
1321
|
-
throw new Error(
|
|
1322
|
-
`Cannot abort signing as transaction is not waiting for signing`
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
1325
|
-
abortCallback();
|
|
1326
|
-
this.signAbortCallbacks.delete(transactionId);
|
|
1327
|
-
}
|
|
1328
|
-
addMetadata(transactionMeta) {
|
|
1329
|
-
validateTxParams(transactionMeta.txParams);
|
|
1330
|
-
this.update((state) => {
|
|
1331
|
-
state.transactions = this.trimTransactionsForState([
|
|
1332
|
-
...state.transactions,
|
|
1333
|
-
transactionMeta
|
|
1334
|
-
]);
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
async updateGasProperties(transactionMeta, { traceContext } = {}) {
|
|
1338
|
-
const isEIP1559Compatible = transactionMeta.txParams.type !== "0x0" /* legacy */ && await this.getEIP1559Compatibility(transactionMeta.networkClientId);
|
|
1339
|
-
const { networkClientId, chainId } = transactionMeta;
|
|
1340
|
-
const isCustomNetwork = __privateMethod(this, _isCustomNetwork, isCustomNetwork_fn).call(this, networkClientId);
|
|
1341
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
1342
|
-
networkClientId,
|
|
1343
|
-
chainId
|
|
1344
|
-
});
|
|
1345
|
-
const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
|
|
1346
|
-
networkClientId,
|
|
1347
|
-
chainId
|
|
1348
|
-
});
|
|
1349
|
-
await __privateGet(this, _trace).call(this, { name: "Update Gas", parentContext: traceContext }, async () => {
|
|
1350
|
-
await updateGas({
|
|
1351
|
-
ethQuery,
|
|
1352
|
-
chainId,
|
|
1353
|
-
isCustomNetwork,
|
|
1354
|
-
txMeta: transactionMeta
|
|
1355
|
-
});
|
|
1356
|
-
});
|
|
1357
|
-
await __privateGet(this, _trace).call(this, { name: "Update Gas Fees", parentContext: traceContext }, async () => await updateGasFees({
|
|
1358
|
-
eip1559: isEIP1559Compatible,
|
|
1359
|
-
ethQuery,
|
|
1360
|
-
gasFeeFlows: this.gasFeeFlows,
|
|
1361
|
-
getGasFeeEstimates: this.getGasFeeEstimates,
|
|
1362
|
-
getSavedGasFees: this.getSavedGasFees.bind(this),
|
|
1363
|
-
txMeta: transactionMeta
|
|
1364
|
-
}));
|
|
1365
|
-
await __privateGet(this, _trace).call(this, { name: "Update Layer 1 Gas Fees", parentContext: traceContext }, async () => await updateTransactionLayer1GasFee({
|
|
1366
|
-
layer1GasFeeFlows: this.layer1GasFeeFlows,
|
|
1367
|
-
provider,
|
|
1368
|
-
transactionMeta
|
|
1369
|
-
}));
|
|
1370
|
-
}
|
|
1371
|
-
onBootCleanup() {
|
|
1372
|
-
this.submitApprovedTransactions();
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Force submit approved transactions for all chains.
|
|
1376
|
-
*/
|
|
1377
|
-
submitApprovedTransactions() {
|
|
1378
|
-
const approvedTransactions = this.state.transactions.filter(
|
|
1379
|
-
(transaction) => transaction.status === "approved" /* approved */
|
|
1380
|
-
);
|
|
1381
|
-
for (const transactionMeta of approvedTransactions) {
|
|
1382
|
-
if (this.beforeApproveOnInit(transactionMeta)) {
|
|
1383
|
-
this.approveTransaction(transactionMeta.id).catch((error) => {
|
|
1384
|
-
console.error("Error while submitting persisted transaction", error);
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
async processApproval(transactionMeta, {
|
|
1390
|
-
isExisting = false,
|
|
1391
|
-
requireApproval,
|
|
1392
|
-
shouldShowRequest = true,
|
|
1393
|
-
actionId,
|
|
1394
|
-
traceContext
|
|
1395
|
-
}) {
|
|
1396
|
-
const transactionId = transactionMeta.id;
|
|
1397
|
-
let resultCallbacks;
|
|
1398
|
-
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
1399
|
-
const finishedPromise = isCompleted ? Promise.resolve(meta) : this.waitForTransactionFinished(transactionId);
|
|
1400
|
-
if (meta && !isExisting && !isCompleted) {
|
|
1401
|
-
try {
|
|
1402
|
-
if (requireApproval !== false) {
|
|
1403
|
-
const acceptResult = await __privateGet(this, _trace).call(this, { name: "Await Approval", parentContext: traceContext }, (context) => this.requestApproval(transactionMeta, {
|
|
1404
|
-
shouldShowRequest,
|
|
1405
|
-
traceContext: context
|
|
1406
|
-
}));
|
|
1407
|
-
resultCallbacks = acceptResult.resultCallbacks;
|
|
1408
|
-
const approvalValue = acceptResult.value;
|
|
1409
|
-
const updatedTransaction = approvalValue?.txMeta;
|
|
1410
|
-
if (updatedTransaction) {
|
|
1411
|
-
projectLogger("Updating transaction with approval data", {
|
|
1412
|
-
customNonce: updatedTransaction.customNonceValue,
|
|
1413
|
-
params: updatedTransaction.txParams
|
|
1414
|
-
});
|
|
1415
|
-
this.updateTransaction(
|
|
1416
|
-
updatedTransaction,
|
|
1417
|
-
"TransactionController#processApproval - Updated with approval data"
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
|
|
1422
|
-
if (!isTxCompleted) {
|
|
1423
|
-
const approvalResult = await this.approveTransaction(
|
|
1424
|
-
transactionId,
|
|
1425
|
-
traceContext
|
|
1426
|
-
);
|
|
1427
|
-
if (approvalResult === "skipped-via-before-publish-hook" /* SkippedViaBeforePublishHook */ && resultCallbacks) {
|
|
1428
|
-
resultCallbacks.success();
|
|
1429
|
-
}
|
|
1430
|
-
const updatedTransactionMeta = this.getTransaction(
|
|
1431
|
-
transactionId
|
|
1432
|
-
);
|
|
1433
|
-
this.messagingSystem.publish(
|
|
1434
|
-
`${controllerName}:transactionApproved`,
|
|
1435
|
-
{
|
|
1436
|
-
transactionMeta: updatedTransactionMeta,
|
|
1437
|
-
actionId
|
|
1438
|
-
}
|
|
1439
|
-
);
|
|
1440
|
-
}
|
|
1441
|
-
} catch (error) {
|
|
1442
|
-
const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
|
|
1443
|
-
if (!isTxCompleted) {
|
|
1444
|
-
if (error?.code === errorCodes.provider.userRejectedRequest) {
|
|
1445
|
-
this.cancelTransaction(transactionId, actionId);
|
|
1446
|
-
throw providerErrors.userRejectedRequest(
|
|
1447
|
-
"MetaMask Tx Signature: User denied transaction signature."
|
|
1448
|
-
);
|
|
1449
|
-
} else {
|
|
1450
|
-
this.failTransaction(meta, error, actionId);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
const finalMeta = await finishedPromise;
|
|
1456
|
-
switch (finalMeta?.status) {
|
|
1457
|
-
case "failed" /* failed */:
|
|
1458
|
-
resultCallbacks?.error(finalMeta.error);
|
|
1459
|
-
throw rpcErrors.internal(finalMeta.error.message);
|
|
1460
|
-
case "submitted" /* submitted */:
|
|
1461
|
-
resultCallbacks?.success();
|
|
1462
|
-
return finalMeta.hash;
|
|
1463
|
-
default:
|
|
1464
|
-
const internalError = rpcErrors.internal(
|
|
1465
|
-
`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(
|
|
1466
|
-
finalMeta || transactionId
|
|
1467
|
-
)}`
|
|
1468
|
-
);
|
|
1469
|
-
resultCallbacks?.error(internalError);
|
|
1470
|
-
throw internalError;
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Approves a transaction and updates it's status in state. If this is not a
|
|
1475
|
-
* retry transaction, a nonce will be generated. The transaction is signed
|
|
1476
|
-
* using the sign configuration property, then published to the blockchain.
|
|
1477
|
-
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
1478
|
-
*
|
|
1479
|
-
* @param transactionId - The ID of the transaction to approve.
|
|
1480
|
-
* @param traceContext - The parent context for any new traces.
|
|
1481
|
-
*/
|
|
1482
|
-
async approveTransaction(transactionId, traceContext) {
|
|
1483
|
-
const cleanupTasks = new Array();
|
|
1484
|
-
cleanupTasks.push(await this.mutex.acquire());
|
|
1485
|
-
let transactionMeta = this.getTransactionOrThrow(transactionId);
|
|
1486
|
-
try {
|
|
1487
|
-
if (!this.sign) {
|
|
1488
|
-
this.failTransaction(
|
|
1489
|
-
transactionMeta,
|
|
1490
|
-
new Error("No sign method defined.")
|
|
1491
|
-
);
|
|
1492
|
-
return "not-approved" /* NotApproved */;
|
|
1493
|
-
} else if (!transactionMeta.chainId) {
|
|
1494
|
-
this.failTransaction(transactionMeta, new Error("No chainId defined."));
|
|
1495
|
-
return "not-approved" /* NotApproved */;
|
|
1496
|
-
}
|
|
1497
|
-
if (this.approvingTransactionIds.has(transactionId)) {
|
|
1498
|
-
projectLogger("Skipping approval as signing in progress", transactionId);
|
|
1499
|
-
return "not-approved" /* NotApproved */;
|
|
1500
|
-
}
|
|
1501
|
-
this.approvingTransactionIds.add(transactionId);
|
|
1502
|
-
cleanupTasks.push(
|
|
1503
|
-
() => this.approvingTransactionIds.delete(transactionId)
|
|
1504
|
-
);
|
|
1505
|
-
const [nonce, releaseNonce] = await getNextNonce(
|
|
1506
|
-
transactionMeta,
|
|
1507
|
-
(address) => __privateGet(this, _multichainTrackingHelper).getNonceLock(
|
|
1508
|
-
address,
|
|
1509
|
-
transactionMeta.networkClientId
|
|
1510
|
-
)
|
|
1511
|
-
);
|
|
1512
|
-
releaseNonce && cleanupTasks.push(releaseNonce);
|
|
1513
|
-
transactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
|
|
1514
|
-
transactionId,
|
|
1515
|
-
note: "TransactionController#approveTransaction - Transaction approved"
|
|
1516
|
-
}, (draftTxMeta) => {
|
|
1517
|
-
const { txParams, chainId } = draftTxMeta;
|
|
1518
|
-
draftTxMeta.status = "approved" /* approved */;
|
|
1519
|
-
draftTxMeta.txParams = {
|
|
1520
|
-
...txParams,
|
|
1521
|
-
nonce,
|
|
1522
|
-
chainId,
|
|
1523
|
-
gasLimit: txParams.gas,
|
|
1524
|
-
...isEIP1559Transaction(txParams) && {
|
|
1525
|
-
type: "0x2" /* feeMarket */
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
});
|
|
1529
|
-
this.onTransactionStatusChange(transactionMeta);
|
|
1530
|
-
const rawTx = await __privateGet(this, _trace).call(this, { name: "Sign", parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
|
|
1531
|
-
if (!this.beforePublish(transactionMeta)) {
|
|
1532
|
-
projectLogger("Skipping publishing transaction based on hook");
|
|
1533
|
-
this.messagingSystem.publish(
|
|
1534
|
-
`${controllerName}:transactionPublishingSkipped`,
|
|
1535
|
-
transactionMeta
|
|
1536
|
-
);
|
|
1537
|
-
return "skipped-via-before-publish-hook" /* SkippedViaBeforePublishHook */;
|
|
1538
|
-
}
|
|
1539
|
-
if (!rawTx) {
|
|
1540
|
-
return "not-approved" /* NotApproved */;
|
|
1541
|
-
}
|
|
1542
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
1543
|
-
networkClientId: transactionMeta.networkClientId,
|
|
1544
|
-
chainId: transactionMeta.chainId
|
|
1545
|
-
});
|
|
1546
|
-
let preTxBalance;
|
|
1547
|
-
const shouldUpdatePreTxBalance = transactionMeta.type === "swap" /* swap */;
|
|
1548
|
-
if (shouldUpdatePreTxBalance) {
|
|
1549
|
-
projectLogger("Determining pre-transaction balance");
|
|
1550
|
-
preTxBalance = await query(ethQuery, "getBalance", [
|
|
1551
|
-
transactionMeta.txParams.from
|
|
1552
|
-
]);
|
|
1553
|
-
}
|
|
1554
|
-
projectLogger("Publishing transaction", transactionMeta.txParams);
|
|
1555
|
-
let hash;
|
|
1556
|
-
await __privateGet(this, _trace).call(this, { name: "Publish", parentContext: traceContext }, async () => {
|
|
1557
|
-
({ transactionHash: hash } = await this.publish(
|
|
1558
|
-
transactionMeta,
|
|
1559
|
-
rawTx
|
|
1560
|
-
));
|
|
1561
|
-
if (hash === void 0) {
|
|
1562
|
-
hash = await this.publishTransaction(ethQuery, rawTx);
|
|
1563
|
-
}
|
|
1564
|
-
});
|
|
1565
|
-
projectLogger("Publish successful", hash);
|
|
1566
|
-
transactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
|
|
1567
|
-
transactionId,
|
|
1568
|
-
note: "TransactionController#approveTransaction - Transaction submitted"
|
|
1569
|
-
}, (draftTxMeta) => {
|
|
1570
|
-
draftTxMeta.hash = hash;
|
|
1571
|
-
draftTxMeta.status = "submitted" /* submitted */;
|
|
1572
|
-
draftTxMeta.submittedTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1573
|
-
if (shouldUpdatePreTxBalance) {
|
|
1574
|
-
draftTxMeta.preTxBalance = preTxBalance;
|
|
1575
|
-
projectLogger("Updated pre-transaction balance", preTxBalance);
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
|
|
1579
|
-
transactionMeta
|
|
1580
|
-
});
|
|
1581
|
-
this.messagingSystem.publish(
|
|
1582
|
-
`${controllerName}:transactionFinished`,
|
|
1583
|
-
transactionMeta
|
|
1584
|
-
);
|
|
1585
|
-
__privateGet(this, _internalEvents).emit(`${transactionId}:finished`, transactionMeta);
|
|
1586
|
-
this.onTransactionStatusChange(transactionMeta);
|
|
1587
|
-
return "approved" /* Approved */;
|
|
1588
|
-
} catch (error) {
|
|
1589
|
-
this.failTransaction(transactionMeta, error);
|
|
1590
|
-
return "not-approved" /* NotApproved */;
|
|
1591
|
-
} finally {
|
|
1592
|
-
cleanupTasks.forEach((task) => task());
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
async publishTransaction(ethQuery, rawTransaction) {
|
|
1596
|
-
return await query(ethQuery, "sendRawTransaction", [rawTransaction]);
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
1600
|
-
* and emitting a `<tx.id>:finished` hub event.
|
|
1601
|
-
*
|
|
1602
|
-
* @param transactionId - The ID of the transaction to cancel.
|
|
1603
|
-
* @param actionId - The actionId passed from UI
|
|
1604
|
-
*/
|
|
1605
|
-
cancelTransaction(transactionId, actionId) {
|
|
1606
|
-
const transactionMeta = this.state.transactions.find(
|
|
1607
|
-
({ id }) => id === transactionId
|
|
1608
|
-
);
|
|
1609
|
-
if (!transactionMeta) {
|
|
1610
|
-
return;
|
|
1611
|
-
}
|
|
1612
|
-
this.update((state) => {
|
|
1613
|
-
const transactions = state.transactions.filter(
|
|
1614
|
-
({ id }) => id !== transactionId
|
|
1615
|
-
);
|
|
1616
|
-
state.transactions = this.trimTransactionsForState(transactions);
|
|
1617
|
-
});
|
|
1618
|
-
const updatedTransactionMeta = {
|
|
1619
|
-
...transactionMeta,
|
|
1620
|
-
status: "rejected" /* rejected */
|
|
1621
|
-
};
|
|
1622
|
-
this.messagingSystem.publish(
|
|
1623
|
-
`${controllerName}:transactionFinished`,
|
|
1624
|
-
updatedTransactionMeta
|
|
1625
|
-
);
|
|
1626
|
-
__privateGet(this, _internalEvents).emit(
|
|
1627
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1628
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1629
|
-
`${transactionMeta.id}:finished`,
|
|
1630
|
-
updatedTransactionMeta
|
|
1631
|
-
);
|
|
1632
|
-
this.messagingSystem.publish(`${controllerName}:transactionRejected`, {
|
|
1633
|
-
transactionMeta: updatedTransactionMeta,
|
|
1634
|
-
actionId
|
|
1635
|
-
});
|
|
1636
|
-
this.onTransactionStatusChange(updatedTransactionMeta);
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Trim the amount of transactions that are set on the state. Checks
|
|
1640
|
-
* if the length of the tx history is longer then desired persistence
|
|
1641
|
-
* limit and then if it is removes the oldest confirmed or rejected tx.
|
|
1642
|
-
* Pending or unapproved transactions will not be removed by this
|
|
1643
|
-
* operation. For safety of presenting a fully functional transaction UI
|
|
1644
|
-
* representation, this function will not break apart transactions with the
|
|
1645
|
-
* same nonce, created on the same day, per network. Not accounting for
|
|
1646
|
-
* transactions of the same nonce, same day and network combo can result in
|
|
1647
|
-
* confusing or broken experiences in the UI.
|
|
1648
|
-
*
|
|
1649
|
-
* @param transactions - The transactions to be applied to the state.
|
|
1650
|
-
* @returns The trimmed list of transactions.
|
|
1651
|
-
*/
|
|
1652
|
-
trimTransactionsForState(transactions) {
|
|
1653
|
-
const nonceNetworkSet = /* @__PURE__ */ new Set();
|
|
1654
|
-
const txsToKeep = [...transactions].sort((a, b) => a.time > b.time ? -1 : 1).filter((tx) => {
|
|
1655
|
-
const { chainId, status, txParams, time } = tx;
|
|
1656
|
-
if (txParams) {
|
|
1657
|
-
const key = `${String(txParams.nonce)}-${convertHexToDecimal(
|
|
1658
|
-
chainId
|
|
1659
|
-
)}-${new Date(time).toDateString()}`;
|
|
1660
|
-
if (nonceNetworkSet.has(key)) {
|
|
1661
|
-
return true;
|
|
1662
|
-
} else if (nonceNetworkSet.size < __privateGet(this, _transactionHistoryLimit) || !this.isFinalState(status)) {
|
|
1663
|
-
nonceNetworkSet.add(key);
|
|
1664
|
-
return true;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
return false;
|
|
1668
|
-
});
|
|
1669
|
-
txsToKeep.reverse();
|
|
1670
|
-
return txsToKeep;
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Determines if the transaction is in a final state.
|
|
1674
|
-
*
|
|
1675
|
-
* @param status - The transaction status.
|
|
1676
|
-
* @returns Whether the transaction is in a final state.
|
|
1677
|
-
*/
|
|
1678
|
-
isFinalState(status) {
|
|
1679
|
-
return status === "rejected" /* rejected */ || status === "confirmed" /* confirmed */ || status === "failed" /* failed */;
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* Whether the transaction has at least completed all local processing.
|
|
1683
|
-
*
|
|
1684
|
-
* @param status - The transaction status.
|
|
1685
|
-
* @returns Whether the transaction is in a final state.
|
|
1686
|
-
*/
|
|
1687
|
-
isLocalFinalState(status) {
|
|
1688
|
-
return [
|
|
1689
|
-
"confirmed" /* confirmed */,
|
|
1690
|
-
"failed" /* failed */,
|
|
1691
|
-
"rejected" /* rejected */,
|
|
1692
|
-
"submitted" /* submitted */
|
|
1693
|
-
].includes(status);
|
|
1694
|
-
}
|
|
1695
|
-
async requestApproval(txMeta, {
|
|
1696
|
-
shouldShowRequest,
|
|
1697
|
-
traceContext
|
|
1698
|
-
}) {
|
|
1699
|
-
const id = this.getApprovalId(txMeta);
|
|
1700
|
-
const { origin } = txMeta;
|
|
1701
|
-
const type = ApprovalType.Transaction;
|
|
1702
|
-
const requestData = { txId: txMeta.id };
|
|
1703
|
-
await __privateGet(this, _trace).call(this, {
|
|
1704
|
-
name: "Notification Display",
|
|
1705
|
-
id,
|
|
1706
|
-
parentContext: traceContext
|
|
1707
|
-
});
|
|
1708
|
-
return await this.messagingSystem.call(
|
|
1709
|
-
"ApprovalController:addRequest",
|
|
1710
|
-
{
|
|
1711
|
-
id,
|
|
1712
|
-
origin: origin || ORIGIN_METAMASK,
|
|
1713
|
-
type,
|
|
1714
|
-
requestData,
|
|
1715
|
-
expectsResult: true
|
|
1716
|
-
},
|
|
1717
|
-
shouldShowRequest
|
|
1718
|
-
);
|
|
1719
|
-
}
|
|
1720
|
-
getTransaction(transactionId) {
|
|
1721
|
-
const { transactions } = this.state;
|
|
1722
|
-
return transactions.find(({ id }) => id === transactionId);
|
|
1723
|
-
}
|
|
1724
|
-
getTransactionOrThrow(transactionId, errorMessagePrefix = "TransactionController") {
|
|
1725
|
-
const txMeta = this.getTransaction(transactionId);
|
|
1726
|
-
if (!txMeta) {
|
|
1727
|
-
throw new Error(
|
|
1728
|
-
`${errorMessagePrefix}: No transaction found with id ${transactionId}`
|
|
1729
|
-
);
|
|
1730
|
-
}
|
|
1731
|
-
return txMeta;
|
|
1732
|
-
}
|
|
1733
|
-
getApprovalId(txMeta) {
|
|
1734
|
-
return String(txMeta.id);
|
|
1735
|
-
}
|
|
1736
|
-
isTransactionCompleted(transactionId) {
|
|
1737
|
-
const transaction = this.getTransaction(transactionId);
|
|
1738
|
-
if (!transaction) {
|
|
1739
|
-
return { meta: void 0, isCompleted: false };
|
|
1740
|
-
}
|
|
1741
|
-
const isCompleted = this.isLocalFinalState(transaction.status);
|
|
1742
|
-
return { meta: transaction, isCompleted };
|
|
1743
|
-
}
|
|
1744
|
-
getChainId(networkClientId) {
|
|
1745
|
-
const globalChainId = __privateMethod(this, _getGlobalChainId, getGlobalChainId_fn).call(this);
|
|
1746
|
-
const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
|
|
1747
|
-
if (!networkClientId || networkClientId === globalNetworkClientId) {
|
|
1748
|
-
return globalChainId;
|
|
1749
|
-
}
|
|
1750
|
-
return this.messagingSystem.call(
|
|
1751
|
-
`NetworkController:getNetworkClientById`,
|
|
1752
|
-
networkClientId
|
|
1753
|
-
).configuration.chainId;
|
|
1754
|
-
}
|
|
1755
|
-
prepareUnsignedEthTx(chainId, txParams) {
|
|
1756
|
-
return TransactionFactory.fromTxData(txParams, {
|
|
1757
|
-
freeze: false,
|
|
1758
|
-
common: this.getCommonConfiguration(chainId)
|
|
1759
|
-
});
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
|
|
1763
|
-
* specifying which chain, network, hardfork and EIPs to support for
|
|
1764
|
-
* a transaction. By referencing this configuration, and analyzing the fields
|
|
1765
|
-
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
1766
|
-
* transaction type to use.
|
|
1767
|
-
*
|
|
1768
|
-
* @param chainId - The chainId to use for the configuration.
|
|
1769
|
-
* @returns common configuration object
|
|
1770
|
-
*/
|
|
1771
|
-
getCommonConfiguration(chainId) {
|
|
1772
|
-
const customChainParams = {
|
|
1773
|
-
chainId: parseInt(chainId, 16),
|
|
1774
|
-
defaultHardfork: HARDFORK
|
|
1775
|
-
};
|
|
1776
|
-
return Common.custom(customChainParams);
|
|
1777
|
-
}
|
|
1778
|
-
onIncomingTransactions({
|
|
1779
|
-
added,
|
|
1780
|
-
updated
|
|
1781
|
-
}) {
|
|
1782
|
-
this.update((state) => {
|
|
1783
|
-
const { transactions: currentTransactions } = state;
|
|
1784
|
-
const updatedTransactions = [
|
|
1785
|
-
...added,
|
|
1786
|
-
...currentTransactions.map((originalTransaction) => {
|
|
1787
|
-
const updatedTransaction = updated.find(
|
|
1788
|
-
({ hash }) => hash === originalTransaction.hash
|
|
1789
|
-
);
|
|
1790
|
-
return updatedTransaction ?? originalTransaction;
|
|
1791
|
-
})
|
|
1792
|
-
];
|
|
1793
|
-
state.transactions = this.trimTransactionsForState(updatedTransactions);
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
onUpdatedLastFetchedBlockNumbers({
|
|
1797
|
-
lastFetchedBlockNumbers,
|
|
1798
|
-
blockNumber
|
|
1799
|
-
}) {
|
|
1800
|
-
this.update((state) => {
|
|
1801
|
-
state.lastFetchedBlockNumbers = lastFetchedBlockNumbers;
|
|
1802
|
-
});
|
|
1803
|
-
this.messagingSystem.publish(
|
|
1804
|
-
`${controllerName}:incomingTransactionBlockReceived`,
|
|
1805
|
-
blockNumber
|
|
1806
|
-
);
|
|
1807
|
-
}
|
|
1808
|
-
generateDappSuggestedGasFees(txParams, origin) {
|
|
1809
|
-
if (!origin || origin === ORIGIN_METAMASK) {
|
|
1810
|
-
return void 0;
|
|
1811
|
-
}
|
|
1812
|
-
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = txParams;
|
|
1813
|
-
if (gasPrice === void 0 && maxFeePerGas === void 0 && maxPriorityFeePerGas === void 0 && gas === void 0) {
|
|
1814
|
-
return void 0;
|
|
1815
|
-
}
|
|
1816
|
-
const dappSuggestedGasFees = {};
|
|
1817
|
-
if (gasPrice !== void 0) {
|
|
1818
|
-
dappSuggestedGasFees.gasPrice = gasPrice;
|
|
1819
|
-
} else if (maxFeePerGas !== void 0 || maxPriorityFeePerGas !== void 0) {
|
|
1820
|
-
dappSuggestedGasFees.maxFeePerGas = maxFeePerGas;
|
|
1821
|
-
dappSuggestedGasFees.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
1822
|
-
}
|
|
1823
|
-
if (gas !== void 0) {
|
|
1824
|
-
dappSuggestedGasFees.gas = gas;
|
|
1825
|
-
}
|
|
1826
|
-
return dappSuggestedGasFees;
|
|
1827
|
-
}
|
|
1828
|
-
/**
|
|
1829
|
-
* Validates and adds external provided transaction to state.
|
|
1830
|
-
*
|
|
1831
|
-
* @param transactionMeta - Nominated external transaction to be added to state.
|
|
1832
|
-
* @returns The new transaction.
|
|
1833
|
-
*/
|
|
1834
|
-
addExternalTransaction(transactionMeta) {
|
|
1835
|
-
const { chainId } = transactionMeta;
|
|
1836
|
-
const { transactions } = this.state;
|
|
1837
|
-
const fromAddress = transactionMeta?.txParams?.from;
|
|
1838
|
-
const sameFromAndNetworkTransactions = transactions.filter(
|
|
1839
|
-
(transaction) => transaction.txParams.from === fromAddress && transaction.chainId === chainId
|
|
1840
|
-
);
|
|
1841
|
-
const confirmedTxs = sameFromAndNetworkTransactions.filter(
|
|
1842
|
-
(transaction) => transaction.status === "confirmed" /* confirmed */
|
|
1843
|
-
);
|
|
1844
|
-
const pendingTxs = sameFromAndNetworkTransactions.filter(
|
|
1845
|
-
(transaction) => transaction.status === "submitted" /* submitted */
|
|
1846
|
-
);
|
|
1847
|
-
validateConfirmedExternalTransaction(
|
|
1848
|
-
transactionMeta,
|
|
1849
|
-
confirmedTxs,
|
|
1850
|
-
pendingTxs
|
|
1851
|
-
);
|
|
1852
|
-
const newTransactionMeta = (transactionMeta.history ?? []).length === 0 && !this.isHistoryDisabled ? addInitialHistorySnapshot(transactionMeta) : transactionMeta;
|
|
1853
|
-
this.update((state) => {
|
|
1854
|
-
state.transactions = this.trimTransactionsForState([
|
|
1855
|
-
...state.transactions,
|
|
1856
|
-
newTransactionMeta
|
|
1857
|
-
]);
|
|
1858
|
-
});
|
|
1859
|
-
return newTransactionMeta;
|
|
1860
|
-
}
|
|
1861
|
-
/**
|
|
1862
|
-
* Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions
|
|
1863
|
-
* in the transactions have the same nonce.
|
|
1864
|
-
*
|
|
1865
|
-
* @param transactionId - Used to identify original transaction.
|
|
1866
|
-
*/
|
|
1867
|
-
markNonceDuplicatesDropped(transactionId) {
|
|
1868
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
1869
|
-
if (!transactionMeta) {
|
|
1870
|
-
return;
|
|
1871
|
-
}
|
|
1872
|
-
const nonce = transactionMeta.txParams?.nonce;
|
|
1873
|
-
const from = transactionMeta.txParams?.from;
|
|
1874
|
-
const { chainId } = transactionMeta;
|
|
1875
|
-
const sameNonceTransactions = this.state.transactions.filter(
|
|
1876
|
-
(transaction) => transaction.id !== transactionId && transaction.txParams.from === from && transaction.txParams.nonce === nonce && transaction.chainId === chainId && transaction.type !== "incoming" /* incoming */
|
|
1877
|
-
);
|
|
1878
|
-
const sameNonceTransactionIds = sameNonceTransactions.map(
|
|
1879
|
-
(transaction) => transaction.id
|
|
1880
|
-
);
|
|
1881
|
-
if (sameNonceTransactions.length === 0) {
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
1884
|
-
this.update((state) => {
|
|
1885
|
-
for (const transaction of state.transactions) {
|
|
1886
|
-
if (sameNonceTransactionIds.includes(transaction.id)) {
|
|
1887
|
-
transaction.replacedBy = transactionMeta?.hash;
|
|
1888
|
-
transaction.replacedById = transactionMeta?.id;
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
});
|
|
1892
|
-
for (const transaction of this.state.transactions) {
|
|
1893
|
-
if (sameNonceTransactionIds.includes(transaction.id) && transaction.status !== "failed" /* failed */) {
|
|
1894
|
-
this.setTransactionStatusDropped(transaction);
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Method to set transaction status to dropped.
|
|
1900
|
-
*
|
|
1901
|
-
* @param transactionMeta - TransactionMeta of transaction to be marked as dropped.
|
|
1902
|
-
*/
|
|
1903
|
-
setTransactionStatusDropped(transactionMeta) {
|
|
1904
|
-
const updatedTransactionMeta = {
|
|
1905
|
-
...transactionMeta,
|
|
1906
|
-
status: "dropped" /* dropped */
|
|
1907
|
-
};
|
|
1908
|
-
this.messagingSystem.publish(`${controllerName}:transactionDropped`, {
|
|
1909
|
-
transactionMeta: updatedTransactionMeta
|
|
1910
|
-
});
|
|
1911
|
-
this.updateTransaction(
|
|
1912
|
-
updatedTransactionMeta,
|
|
1913
|
-
"TransactionController#setTransactionStatusDropped - Transaction dropped"
|
|
1914
|
-
);
|
|
1915
|
-
this.onTransactionStatusChange(updatedTransactionMeta);
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Get transaction with provided actionId.
|
|
1919
|
-
*
|
|
1920
|
-
* @param actionId - Unique ID to prevent duplicate requests
|
|
1921
|
-
* @returns the filtered transaction
|
|
1922
|
-
*/
|
|
1923
|
-
getTransactionWithActionId(actionId) {
|
|
1924
|
-
return this.state.transactions.find(
|
|
1925
|
-
(transaction) => actionId && transaction.actionId === actionId
|
|
1926
|
-
);
|
|
1927
|
-
}
|
|
1928
|
-
async waitForTransactionFinished(transactionId) {
|
|
1929
|
-
return new Promise((resolve) => {
|
|
1930
|
-
__privateGet(this, _internalEvents).once(`${transactionId}:finished`, (txMeta) => {
|
|
1931
|
-
resolve(txMeta);
|
|
1932
|
-
});
|
|
1933
|
-
});
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* Updates the r, s, and v properties of a TransactionMeta object
|
|
1937
|
-
* with values from a signed transaction.
|
|
1938
|
-
*
|
|
1939
|
-
* @param transactionMeta - The TransactionMeta object to update.
|
|
1940
|
-
* @param signedTx - The encompassing type for all transaction types containing r, s, and v values.
|
|
1941
|
-
* @returns The updated TransactionMeta object.
|
|
1942
|
-
*/
|
|
1943
|
-
updateTransactionMetaRSV(transactionMeta, signedTx) {
|
|
1944
|
-
const transactionMetaWithRsv = cloneDeep(transactionMeta);
|
|
1945
|
-
for (const key of ["r", "s", "v"]) {
|
|
1946
|
-
const value = signedTx[key];
|
|
1947
|
-
if (value === void 0 || value === null) {
|
|
1948
|
-
continue;
|
|
1949
|
-
}
|
|
1950
|
-
transactionMetaWithRsv[key] = add0x(value.toString(16));
|
|
1951
|
-
}
|
|
1952
|
-
return transactionMetaWithRsv;
|
|
1953
|
-
}
|
|
1954
|
-
async getEIP1559Compatibility(networkClientId) {
|
|
1955
|
-
const currentNetworkIsEIP1559Compatible = await this.getCurrentNetworkEIP1559Compatibility(networkClientId);
|
|
1956
|
-
const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
|
|
1957
|
-
return currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible;
|
|
1958
|
-
}
|
|
1959
|
-
async signTransaction(transactionMeta, txParams) {
|
|
1960
|
-
projectLogger("Signing transaction", txParams);
|
|
1961
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(
|
|
1962
|
-
transactionMeta.chainId,
|
|
1963
|
-
txParams
|
|
1964
|
-
);
|
|
1965
|
-
this.approvingTransactionIds.add(transactionMeta.id);
|
|
1966
|
-
const signedTx = await new Promise((resolve, reject) => {
|
|
1967
|
-
this.sign?.(
|
|
1968
|
-
unsignedEthTx,
|
|
1969
|
-
txParams.from,
|
|
1970
|
-
...this.getAdditionalSignArguments(transactionMeta)
|
|
1971
|
-
).then(resolve, reject);
|
|
1972
|
-
this.signAbortCallbacks.set(
|
|
1973
|
-
transactionMeta.id,
|
|
1974
|
-
() => reject(new Error("Signing aborted by user"))
|
|
1975
|
-
);
|
|
1976
|
-
});
|
|
1977
|
-
this.signAbortCallbacks.delete(transactionMeta.id);
|
|
1978
|
-
if (!signedTx) {
|
|
1979
|
-
projectLogger("Skipping signed status as no signed transaction");
|
|
1980
|
-
return void 0;
|
|
1981
|
-
}
|
|
1982
|
-
const transactionMetaFromHook = cloneDeep(transactionMeta);
|
|
1983
|
-
if (!this.afterSign(transactionMetaFromHook, signedTx)) {
|
|
1984
|
-
this.updateTransaction(
|
|
1985
|
-
transactionMetaFromHook,
|
|
1986
|
-
"TransactionController#signTransaction - Update after sign"
|
|
1987
|
-
);
|
|
1988
|
-
projectLogger("Skipping signed status based on hook");
|
|
1989
|
-
return void 0;
|
|
1990
|
-
}
|
|
1991
|
-
const transactionMetaWithRsv = {
|
|
1992
|
-
...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
|
|
1993
|
-
status: "signed" /* signed */
|
|
1994
|
-
};
|
|
1995
|
-
this.updateTransaction(
|
|
1996
|
-
transactionMetaWithRsv,
|
|
1997
|
-
"TransactionController#approveTransaction - Transaction signed"
|
|
1998
|
-
);
|
|
1999
|
-
this.onTransactionStatusChange(transactionMetaWithRsv);
|
|
2000
|
-
const rawTx = bufferToHex(signedTx.serialize());
|
|
2001
|
-
const transactionMetaWithRawTx = merge({}, transactionMetaWithRsv, {
|
|
2002
|
-
rawTx
|
|
2003
|
-
});
|
|
2004
|
-
this.updateTransaction(
|
|
2005
|
-
transactionMetaWithRawTx,
|
|
2006
|
-
"TransactionController#approveTransaction - RawTransaction added"
|
|
2007
|
-
);
|
|
2008
|
-
return rawTx;
|
|
2009
|
-
}
|
|
2010
|
-
onTransactionStatusChange(transactionMeta) {
|
|
2011
|
-
this.messagingSystem.publish(`${controllerName}:transactionStatusUpdated`, {
|
|
2012
|
-
transactionMeta
|
|
2013
|
-
});
|
|
2014
|
-
}
|
|
2015
|
-
getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
|
|
2016
|
-
return getAndFormatTransactionsForNonceTracker(
|
|
2017
|
-
chainId,
|
|
2018
|
-
address,
|
|
2019
|
-
status,
|
|
2020
|
-
this.state.transactions
|
|
2021
|
-
);
|
|
2022
|
-
}
|
|
2023
|
-
onConfirmedTransaction(transactionMeta) {
|
|
2024
|
-
projectLogger("Processing confirmed transaction", transactionMeta.id);
|
|
2025
|
-
this.markNonceDuplicatesDropped(transactionMeta.id);
|
|
2026
|
-
this.messagingSystem.publish(
|
|
2027
|
-
`${controllerName}:transactionConfirmed`,
|
|
2028
|
-
transactionMeta
|
|
2029
|
-
);
|
|
2030
|
-
this.onTransactionStatusChange(transactionMeta);
|
|
2031
|
-
this.updatePostBalance(transactionMeta).catch((error) => {
|
|
2032
|
-
projectLogger("Error while updating post balance", error);
|
|
2033
|
-
throw error;
|
|
2034
|
-
});
|
|
2035
|
-
}
|
|
2036
|
-
async updatePostBalance(transactionMeta) {
|
|
2037
|
-
try {
|
|
2038
|
-
if (transactionMeta.type !== "swap" /* swap */) {
|
|
2039
|
-
return;
|
|
2040
|
-
}
|
|
2041
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
2042
|
-
networkClientId: transactionMeta.networkClientId,
|
|
2043
|
-
chainId: transactionMeta.chainId
|
|
2044
|
-
});
|
|
2045
|
-
const { updatedTransactionMeta, approvalTransactionMeta } = await updatePostTransactionBalance(transactionMeta, {
|
|
2046
|
-
ethQuery,
|
|
2047
|
-
getTransaction: this.getTransaction.bind(this),
|
|
2048
|
-
updateTransaction: this.updateTransaction.bind(this)
|
|
2049
|
-
});
|
|
2050
|
-
this.messagingSystem.publish(
|
|
2051
|
-
`${controllerName}:postTransactionBalanceUpdated`,
|
|
2052
|
-
{
|
|
2053
|
-
transactionMeta: updatedTransactionMeta,
|
|
2054
|
-
approvalTransactionMeta
|
|
2055
|
-
}
|
|
2056
|
-
);
|
|
2057
|
-
} catch (error) {
|
|
2058
|
-
projectLogger("Error while updating post transaction balance", error);
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
async publishTransactionForRetry(ethQuery, rawTx, transactionMeta) {
|
|
2062
|
-
try {
|
|
2063
|
-
const hash = await this.publishTransaction(ethQuery, rawTx);
|
|
2064
|
-
return hash;
|
|
2065
|
-
} catch (error) {
|
|
2066
|
-
if (this.isTransactionAlreadyConfirmedError(error)) {
|
|
2067
|
-
await this.pendingTransactionTracker.forceCheckTransaction(
|
|
2068
|
-
transactionMeta
|
|
2069
|
-
);
|
|
2070
|
-
throw new Error("Previous transaction is already confirmed");
|
|
2071
|
-
}
|
|
2072
|
-
throw error;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
/**
|
|
2076
|
-
* Ensures that error is a nonce issue
|
|
2077
|
-
*
|
|
2078
|
-
* @param error - The error to check
|
|
2079
|
-
* @returns Whether or not the error is a nonce issue
|
|
2080
|
-
*/
|
|
2081
|
-
// TODO: Replace `any` with type
|
|
2082
|
-
// Some networks are returning original error in the data field
|
|
2083
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2084
|
-
isTransactionAlreadyConfirmedError(error) {
|
|
2085
|
-
return error?.message?.includes("nonce too low") || error?.data?.message?.includes("nonce too low");
|
|
2086
|
-
}
|
|
2087
|
-
};
|
|
2088
|
-
_internalEvents = new WeakMap();
|
|
2089
|
-
_incomingTransactionOptions = new WeakMap();
|
|
2090
|
-
_pendingTransactionOptions = new WeakMap();
|
|
2091
|
-
_trace = new WeakMap();
|
|
2092
|
-
_transactionHistoryLimit = new WeakMap();
|
|
2093
|
-
_isSimulationEnabled = new WeakMap();
|
|
2094
|
-
_testGasFeeFlows = new WeakMap();
|
|
2095
|
-
_multichainTrackingHelper = new WeakMap();
|
|
2096
|
-
_retryTransaction = new WeakSet();
|
|
2097
|
-
retryTransaction_fn = async function({
|
|
2098
|
-
actionId,
|
|
2099
|
-
afterSubmit,
|
|
2100
|
-
estimatedBaseFee,
|
|
2101
|
-
gasValues,
|
|
2102
|
-
label,
|
|
2103
|
-
prepareTransactionParams,
|
|
2104
|
-
rate,
|
|
2105
|
-
transactionId,
|
|
2106
|
-
transactionType
|
|
2107
|
-
}) {
|
|
2108
|
-
if (this.getTransactionWithActionId(actionId)) {
|
|
2109
|
-
return;
|
|
2110
|
-
}
|
|
2111
|
-
if (gasValues) {
|
|
2112
|
-
gasValues = normalizeGasFeeValues(gasValues);
|
|
2113
|
-
validateGasValues(gasValues);
|
|
2114
|
-
}
|
|
2115
|
-
projectLogger(`Creating ${label} transaction`, transactionId, gasValues);
|
|
2116
|
-
const transactionMeta = this.getTransaction(transactionId);
|
|
2117
|
-
if (!transactionMeta) {
|
|
2118
|
-
return;
|
|
2119
|
-
}
|
|
2120
|
-
if (!this.sign) {
|
|
2121
|
-
throw new Error("No sign method defined.");
|
|
2122
|
-
}
|
|
2123
|
-
const newTxParams = getTransactionParamsWithIncreasedGasFee(
|
|
2124
|
-
transactionMeta.txParams,
|
|
2125
|
-
rate,
|
|
2126
|
-
gasValues
|
|
2127
|
-
);
|
|
2128
|
-
prepareTransactionParams?.(newTxParams);
|
|
2129
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(
|
|
2130
|
-
transactionMeta.chainId,
|
|
2131
|
-
newTxParams
|
|
2132
|
-
);
|
|
2133
|
-
const signedTx = await this.sign(
|
|
2134
|
-
unsignedEthTx,
|
|
2135
|
-
transactionMeta.txParams.from
|
|
2136
|
-
);
|
|
2137
|
-
const transactionMetaWithRsv = this.updateTransactionMetaRSV(
|
|
2138
|
-
transactionMeta,
|
|
2139
|
-
signedTx
|
|
2140
|
-
);
|
|
2141
|
-
const rawTx = bufferToHex(signedTx.serialize());
|
|
2142
|
-
const newFee = newTxParams.maxFeePerGas ?? newTxParams.gasPrice;
|
|
2143
|
-
const oldFee = newTxParams.maxFeePerGas ? transactionMetaWithRsv.txParams.maxFeePerGas : transactionMetaWithRsv.txParams.gasPrice;
|
|
2144
|
-
projectLogger(`Submitting ${label} transaction`, {
|
|
2145
|
-
oldFee,
|
|
2146
|
-
newFee,
|
|
2147
|
-
txParams: newTxParams
|
|
2148
|
-
});
|
|
2149
|
-
const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
|
|
2150
|
-
networkClientId: transactionMeta.networkClientId,
|
|
2151
|
-
chainId: transactionMeta.chainId
|
|
2152
|
-
});
|
|
2153
|
-
const hash = await this.publishTransactionForRetry(
|
|
2154
|
-
ethQuery,
|
|
2155
|
-
rawTx,
|
|
2156
|
-
transactionMeta
|
|
2157
|
-
);
|
|
2158
|
-
const newTransactionMeta = {
|
|
2159
|
-
...transactionMetaWithRsv,
|
|
2160
|
-
estimatedBaseFee,
|
|
2161
|
-
id: random(),
|
|
2162
|
-
time: Date.now(),
|
|
2163
|
-
hash,
|
|
2164
|
-
actionId,
|
|
2165
|
-
originalGasEstimate: transactionMeta.txParams.gas,
|
|
2166
|
-
type: transactionType,
|
|
2167
|
-
txParams: newTxParams,
|
|
2168
|
-
originalType: transactionMeta.type
|
|
2169
|
-
};
|
|
2170
|
-
this.addMetadata(newTransactionMeta);
|
|
2171
|
-
this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
|
|
2172
|
-
transactionMeta: newTransactionMeta,
|
|
2173
|
-
actionId
|
|
2174
|
-
});
|
|
2175
|
-
this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
|
|
2176
|
-
transactionMeta: newTransactionMeta,
|
|
2177
|
-
actionId
|
|
2178
|
-
});
|
|
2179
|
-
afterSubmit?.(newTransactionMeta);
|
|
2180
|
-
};
|
|
2181
|
-
_createNonceTracker = new WeakSet();
|
|
2182
|
-
createNonceTracker_fn = function({
|
|
2183
|
-
provider,
|
|
2184
|
-
blockTracker,
|
|
2185
|
-
chainId
|
|
2186
|
-
}) {
|
|
2187
|
-
return new NonceTracker({
|
|
2188
|
-
// TODO: Fix types
|
|
2189
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2190
|
-
provider,
|
|
2191
|
-
// TODO: Fix types
|
|
2192
|
-
blockTracker,
|
|
2193
|
-
getPendingTransactions: __privateMethod(this, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn).bind(
|
|
2194
|
-
this,
|
|
2195
|
-
chainId
|
|
2196
|
-
),
|
|
2197
|
-
getConfirmedTransactions: this.getNonceTrackerTransactions.bind(
|
|
2198
|
-
this,
|
|
2199
|
-
"confirmed" /* confirmed */
|
|
2200
|
-
)
|
|
2201
|
-
});
|
|
2202
|
-
};
|
|
2203
|
-
_createIncomingTransactionHelper = new WeakSet();
|
|
2204
|
-
createIncomingTransactionHelper_fn = function({
|
|
2205
|
-
blockTracker,
|
|
2206
|
-
etherscanRemoteTransactionSource,
|
|
2207
|
-
chainId
|
|
2208
|
-
}) {
|
|
2209
|
-
const incomingTransactionHelper = new IncomingTransactionHelper({
|
|
2210
|
-
blockTracker,
|
|
2211
|
-
getCurrentAccount: () => __privateMethod(this, _getSelectedAccount, getSelectedAccount_fn).call(this),
|
|
2212
|
-
getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
|
|
2213
|
-
getChainId: chainId ? () => chainId : this.getChainId.bind(this),
|
|
2214
|
-
isEnabled: __privateGet(this, _incomingTransactionOptions).isEnabled,
|
|
2215
|
-
queryEntireHistory: __privateGet(this, _incomingTransactionOptions).queryEntireHistory,
|
|
2216
|
-
remoteTransactionSource: etherscanRemoteTransactionSource,
|
|
2217
|
-
transactionLimit: __privateGet(this, _transactionHistoryLimit),
|
|
2218
|
-
updateTransactions: __privateGet(this, _incomingTransactionOptions).updateTransactions
|
|
2219
|
-
});
|
|
2220
|
-
__privateMethod(this, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn).call(this, incomingTransactionHelper);
|
|
2221
|
-
return incomingTransactionHelper;
|
|
2222
|
-
};
|
|
2223
|
-
_createPendingTransactionTracker = new WeakSet();
|
|
2224
|
-
createPendingTransactionTracker_fn = function({
|
|
2225
|
-
provider,
|
|
2226
|
-
blockTracker,
|
|
2227
|
-
chainId
|
|
2228
|
-
}) {
|
|
2229
|
-
const ethQuery = new EthQuery(provider);
|
|
2230
|
-
const getChainId = chainId ? () => chainId : this.getChainId.bind(this);
|
|
2231
|
-
const pendingTransactionTracker = new PendingTransactionTracker({
|
|
2232
|
-
approveTransaction: async (transactionId) => {
|
|
2233
|
-
await this.approveTransaction(transactionId);
|
|
2234
|
-
},
|
|
2235
|
-
blockTracker,
|
|
2236
|
-
getChainId,
|
|
2237
|
-
getEthQuery: () => ethQuery,
|
|
2238
|
-
getTransactions: () => this.state.transactions,
|
|
2239
|
-
isResubmitEnabled: __privateGet(this, _pendingTransactionOptions).isResubmitEnabled,
|
|
2240
|
-
getGlobalLock: () => __privateGet(this, _multichainTrackingHelper).acquireNonceLockForChainIdKey({
|
|
2241
|
-
chainId: getChainId()
|
|
2242
|
-
}),
|
|
2243
|
-
publishTransaction: this.publishTransaction.bind(this),
|
|
2244
|
-
hooks: {
|
|
2245
|
-
beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
|
|
2246
|
-
beforePublish: this.beforePublish.bind(this)
|
|
2247
|
-
}
|
|
2248
|
-
});
|
|
2249
|
-
__privateMethod(this, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn).call(this, pendingTransactionTracker);
|
|
2250
|
-
return pendingTransactionTracker;
|
|
2251
|
-
};
|
|
2252
|
-
_checkForPendingTransactionAndStartPolling = new WeakMap();
|
|
2253
|
-
_stopAllTracking = new WeakSet();
|
|
2254
|
-
stopAllTracking_fn = function() {
|
|
2255
|
-
this.pendingTransactionTracker.stop();
|
|
2256
|
-
__privateMethod(this, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn).call(this, this.pendingTransactionTracker);
|
|
2257
|
-
this.incomingTransactionHelper.stop();
|
|
2258
|
-
__privateMethod(this, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn).call(this, this.incomingTransactionHelper);
|
|
2259
|
-
__privateGet(this, _multichainTrackingHelper).stopAllTracking();
|
|
2260
|
-
};
|
|
2261
|
-
_removeIncomingTransactionHelperListeners = new WeakSet();
|
|
2262
|
-
removeIncomingTransactionHelperListeners_fn = function(incomingTransactionHelper) {
|
|
2263
|
-
incomingTransactionHelper.hub.removeAllListeners("transactions");
|
|
2264
|
-
incomingTransactionHelper.hub.removeAllListeners(
|
|
2265
|
-
"updatedLastFetchedBlockNumbers"
|
|
2266
|
-
);
|
|
2267
|
-
};
|
|
2268
|
-
_addIncomingTransactionHelperListeners = new WeakSet();
|
|
2269
|
-
addIncomingTransactionHelperListeners_fn = function(incomingTransactionHelper) {
|
|
2270
|
-
incomingTransactionHelper.hub.on(
|
|
2271
|
-
"transactions",
|
|
2272
|
-
this.onIncomingTransactions.bind(this)
|
|
2273
|
-
);
|
|
2274
|
-
incomingTransactionHelper.hub.on(
|
|
2275
|
-
"updatedLastFetchedBlockNumbers",
|
|
2276
|
-
this.onUpdatedLastFetchedBlockNumbers.bind(this)
|
|
2277
|
-
);
|
|
2278
|
-
};
|
|
2279
|
-
_removePendingTransactionTrackerListeners = new WeakSet();
|
|
2280
|
-
removePendingTransactionTrackerListeners_fn = function(pendingTransactionTracker) {
|
|
2281
|
-
pendingTransactionTracker.hub.removeAllListeners("transaction-confirmed");
|
|
2282
|
-
pendingTransactionTracker.hub.removeAllListeners("transaction-dropped");
|
|
2283
|
-
pendingTransactionTracker.hub.removeAllListeners("transaction-failed");
|
|
2284
|
-
pendingTransactionTracker.hub.removeAllListeners("transaction-updated");
|
|
2285
|
-
};
|
|
2286
|
-
_addPendingTransactionTrackerListeners = new WeakSet();
|
|
2287
|
-
addPendingTransactionTrackerListeners_fn = function(pendingTransactionTracker) {
|
|
2288
|
-
pendingTransactionTracker.hub.on(
|
|
2289
|
-
"transaction-confirmed",
|
|
2290
|
-
this.onConfirmedTransaction.bind(this)
|
|
2291
|
-
);
|
|
2292
|
-
pendingTransactionTracker.hub.on(
|
|
2293
|
-
"transaction-dropped",
|
|
2294
|
-
this.setTransactionStatusDropped.bind(this)
|
|
2295
|
-
);
|
|
2296
|
-
pendingTransactionTracker.hub.on(
|
|
2297
|
-
"transaction-failed",
|
|
2298
|
-
this.failTransaction.bind(this)
|
|
2299
|
-
);
|
|
2300
|
-
pendingTransactionTracker.hub.on(
|
|
2301
|
-
"transaction-updated",
|
|
2302
|
-
this.updateTransaction.bind(this)
|
|
2303
|
-
);
|
|
2304
|
-
};
|
|
2305
|
-
_getNonceTrackerPendingTransactions = new WeakSet();
|
|
2306
|
-
getNonceTrackerPendingTransactions_fn = function(chainId, address) {
|
|
2307
|
-
const standardPendingTransactions = this.getNonceTrackerTransactions(
|
|
2308
|
-
"submitted" /* submitted */,
|
|
2309
|
-
address,
|
|
2310
|
-
chainId
|
|
2311
|
-
);
|
|
2312
|
-
const externalPendingTransactions = this.getExternalPendingTransactions(
|
|
2313
|
-
address,
|
|
2314
|
-
chainId
|
|
2315
|
-
);
|
|
2316
|
-
return [...standardPendingTransactions, ...externalPendingTransactions];
|
|
2317
|
-
};
|
|
2318
|
-
_getGasFeeFlows = new WeakSet();
|
|
2319
|
-
getGasFeeFlows_fn = function() {
|
|
2320
|
-
if (__privateGet(this, _testGasFeeFlows)) {
|
|
2321
|
-
return [new TestGasFeeFlow()];
|
|
2322
|
-
}
|
|
2323
|
-
return [new LineaGasFeeFlow(), new DefaultGasFeeFlow()];
|
|
2324
|
-
};
|
|
2325
|
-
_getLayer1GasFeeFlows = new WeakSet();
|
|
2326
|
-
getLayer1GasFeeFlows_fn = function() {
|
|
2327
|
-
return [new OptimismLayer1GasFeeFlow(), new ScrollLayer1GasFeeFlow()];
|
|
2328
|
-
};
|
|
2329
|
-
_updateTransactionInternal = new WeakSet();
|
|
2330
|
-
updateTransactionInternal_fn = function({
|
|
2331
|
-
transactionId,
|
|
2332
|
-
note,
|
|
2333
|
-
skipHistory
|
|
2334
|
-
}, callback) {
|
|
2335
|
-
let updatedTransactionParams = [];
|
|
2336
|
-
this.update((state) => {
|
|
2337
|
-
const index = state.transactions.findIndex(
|
|
2338
|
-
({ id }) => id === transactionId
|
|
2339
|
-
);
|
|
2340
|
-
let transactionMeta2 = state.transactions[index];
|
|
2341
|
-
transactionMeta2 = callback(transactionMeta2) ?? transactionMeta2;
|
|
2342
|
-
transactionMeta2.txParams = normalizeTransactionParams(
|
|
2343
|
-
transactionMeta2.txParams
|
|
2344
|
-
);
|
|
2345
|
-
validateTxParams(transactionMeta2.txParams);
|
|
2346
|
-
updatedTransactionParams = __privateMethod(this, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn).call(this, transactionMeta2);
|
|
2347
|
-
const shouldSkipHistory = this.isHistoryDisabled || skipHistory;
|
|
2348
|
-
if (!shouldSkipHistory) {
|
|
2349
|
-
transactionMeta2 = updateTransactionHistory(
|
|
2350
|
-
transactionMeta2,
|
|
2351
|
-
note ?? "Transaction updated"
|
|
2352
|
-
);
|
|
2353
|
-
}
|
|
2354
|
-
state.transactions[index] = transactionMeta2;
|
|
2355
|
-
});
|
|
2356
|
-
const transactionMeta = this.getTransaction(
|
|
2357
|
-
transactionId
|
|
2358
|
-
);
|
|
2359
|
-
if (updatedTransactionParams.length > 0) {
|
|
2360
|
-
__privateMethod(this, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn).call(this, transactionMeta, updatedTransactionParams);
|
|
2361
|
-
}
|
|
2362
|
-
return transactionMeta;
|
|
2363
|
-
};
|
|
2364
|
-
_checkIfTransactionParamsUpdated = new WeakSet();
|
|
2365
|
-
checkIfTransactionParamsUpdated_fn = function(newTransactionMeta) {
|
|
2366
|
-
const { id: transactionId, txParams: newParams } = newTransactionMeta;
|
|
2367
|
-
const originalParams = this.getTransaction(transactionId)?.txParams;
|
|
2368
|
-
if (!originalParams || isEqual(originalParams, newParams)) {
|
|
2369
|
-
return [];
|
|
2370
|
-
}
|
|
2371
|
-
const params = Object.keys(newParams);
|
|
2372
|
-
const updatedProperties = params.filter(
|
|
2373
|
-
(param) => newParams[param] !== originalParams[param]
|
|
2374
|
-
);
|
|
2375
|
-
projectLogger(
|
|
2376
|
-
"Transaction parameters have been updated",
|
|
2377
|
-
transactionId,
|
|
2378
|
-
updatedProperties,
|
|
2379
|
-
originalParams,
|
|
2380
|
-
newParams
|
|
2381
|
-
);
|
|
2382
|
-
return updatedProperties;
|
|
2383
|
-
};
|
|
2384
|
-
_onTransactionParamsUpdated = new WeakSet();
|
|
2385
|
-
onTransactionParamsUpdated_fn = function(transactionMeta, updatedParams) {
|
|
2386
|
-
if (["to", "value", "data"].some(
|
|
2387
|
-
(param) => updatedParams.includes(param)
|
|
2388
|
-
)) {
|
|
2389
|
-
projectLogger("Updating simulation data due to transaction parameter update");
|
|
2390
|
-
__privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta).catch((error) => {
|
|
2391
|
-
projectLogger("Error updating simulation data", error);
|
|
2392
|
-
throw error;
|
|
2393
|
-
});
|
|
2394
|
-
}
|
|
2395
|
-
};
|
|
2396
|
-
_updateSimulationData = new WeakSet();
|
|
2397
|
-
updateSimulationData_fn = async function(transactionMeta, { traceContext } = {}) {
|
|
2398
|
-
const { id: transactionId, chainId, txParams } = transactionMeta;
|
|
2399
|
-
const { from, to, value, data } = txParams;
|
|
2400
|
-
let simulationData = {
|
|
2401
|
-
error: {
|
|
2402
|
-
code: "disabled" /* Disabled */,
|
|
2403
|
-
message: "Simulation disabled"
|
|
2404
|
-
},
|
|
2405
|
-
tokenBalanceChanges: []
|
|
2406
|
-
};
|
|
2407
|
-
if (__privateGet(this, _isSimulationEnabled).call(this)) {
|
|
2408
|
-
__privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, skipHistory: true }, (txMeta) => {
|
|
2409
|
-
txMeta.simulationData = void 0;
|
|
2410
|
-
});
|
|
2411
|
-
simulationData = await __privateGet(this, _trace).call(this, { name: "Simulate", parentContext: traceContext }, () => getSimulationData({
|
|
2412
|
-
chainId,
|
|
2413
|
-
from,
|
|
2414
|
-
to,
|
|
2415
|
-
value,
|
|
2416
|
-
data
|
|
2417
|
-
}));
|
|
2418
|
-
}
|
|
2419
|
-
const finalTransactionMeta = this.getTransaction(transactionId);
|
|
2420
|
-
if (!finalTransactionMeta) {
|
|
2421
|
-
projectLogger(
|
|
2422
|
-
"Cannot update simulation data as transaction not found",
|
|
2423
|
-
transactionId,
|
|
2424
|
-
simulationData
|
|
2425
|
-
);
|
|
2426
|
-
return;
|
|
2427
|
-
}
|
|
2428
|
-
__privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
|
|
2429
|
-
transactionId,
|
|
2430
|
-
note: "TransactionController#updateSimulationData - Update simulation data"
|
|
2431
|
-
}, (txMeta) => {
|
|
2432
|
-
txMeta.simulationData = simulationData;
|
|
2433
|
-
});
|
|
2434
|
-
projectLogger("Updated simulation data", transactionId, simulationData);
|
|
2435
|
-
};
|
|
2436
|
-
_onGasFeePollerTransactionUpdate = new WeakSet();
|
|
2437
|
-
onGasFeePollerTransactionUpdate_fn = function({
|
|
2438
|
-
transactionId,
|
|
2439
|
-
gasFeeEstimates,
|
|
2440
|
-
gasFeeEstimatesLoaded,
|
|
2441
|
-
layer1GasFee
|
|
2442
|
-
}) {
|
|
2443
|
-
__privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, skipHistory: true }, (txMeta) => {
|
|
2444
|
-
if (gasFeeEstimates) {
|
|
2445
|
-
txMeta.gasFeeEstimates = gasFeeEstimates;
|
|
2446
|
-
}
|
|
2447
|
-
if (gasFeeEstimatesLoaded !== void 0) {
|
|
2448
|
-
txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;
|
|
2449
|
-
}
|
|
2450
|
-
if (layer1GasFee) {
|
|
2451
|
-
txMeta.layer1GasFee = layer1GasFee;
|
|
2452
|
-
}
|
|
2453
|
-
});
|
|
2454
|
-
};
|
|
2455
|
-
_getNetworkClientId = new WeakSet();
|
|
2456
|
-
getNetworkClientId_fn = function({
|
|
2457
|
-
networkClientId: requestNetworkClientId,
|
|
2458
|
-
chainId
|
|
2459
|
-
}) {
|
|
2460
|
-
const globalChainId = __privateMethod(this, _getGlobalChainId, getGlobalChainId_fn).call(this);
|
|
2461
|
-
const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
|
|
2462
|
-
if (requestNetworkClientId) {
|
|
2463
|
-
return requestNetworkClientId;
|
|
2464
|
-
}
|
|
2465
|
-
if (!chainId || chainId === globalChainId) {
|
|
2466
|
-
return globalNetworkClientId;
|
|
2467
|
-
}
|
|
2468
|
-
return this.messagingSystem.call(
|
|
2469
|
-
`NetworkController:findNetworkClientIdByChainId`,
|
|
2470
|
-
chainId
|
|
2471
|
-
);
|
|
2472
|
-
};
|
|
2473
|
-
_getGlobalNetworkClientId = new WeakSet();
|
|
2474
|
-
getGlobalNetworkClientId_fn = function() {
|
|
2475
|
-
return this.getNetworkState().selectedNetworkClientId;
|
|
2476
|
-
};
|
|
2477
|
-
_getGlobalChainId = new WeakSet();
|
|
2478
|
-
getGlobalChainId_fn = function() {
|
|
2479
|
-
return this.messagingSystem.call(
|
|
2480
|
-
`NetworkController:getNetworkClientById`,
|
|
2481
|
-
this.getNetworkState().selectedNetworkClientId
|
|
2482
|
-
).configuration.chainId;
|
|
2483
|
-
};
|
|
2484
|
-
_isCustomNetwork = new WeakSet();
|
|
2485
|
-
isCustomNetwork_fn = function(networkClientId) {
|
|
2486
|
-
const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
|
|
2487
|
-
if (!networkClientId || networkClientId === globalNetworkClientId) {
|
|
2488
|
-
return !isInfuraNetworkType(
|
|
2489
|
-
this.getNetworkState().selectedNetworkClientId
|
|
2490
|
-
);
|
|
2491
|
-
}
|
|
2492
|
-
return this.messagingSystem.call(
|
|
2493
|
-
`NetworkController:getNetworkClientById`,
|
|
2494
|
-
networkClientId
|
|
2495
|
-
).configuration.type === NetworkClientType.Custom;
|
|
2496
|
-
};
|
|
2497
|
-
_getSelectedAccount = new WeakSet();
|
|
2498
|
-
getSelectedAccount_fn = function() {
|
|
2499
|
-
return this.messagingSystem.call("AccountsController:getSelectedAccount");
|
|
2500
|
-
};
|
|
2501
|
-
|
|
2502
|
-
export {
|
|
2503
|
-
HARDFORK,
|
|
2504
|
-
CANCEL_RATE,
|
|
2505
|
-
SPEED_UP_RATE,
|
|
2506
|
-
ApprovalState,
|
|
2507
|
-
TransactionController
|
|
2508
|
-
};
|
|
2509
|
-
//# sourceMappingURL=chunk-XTMJ25EF.mjs.map
|