@metamask/transaction-controller 36.0.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 +39 -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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
export interface EtherscanTransactionMetaBase {
|
|
3
|
+
blockNumber: string;
|
|
4
|
+
blockHash: string;
|
|
5
|
+
confirmations: string;
|
|
6
|
+
contractAddress: string;
|
|
7
|
+
cumulativeGasUsed: string;
|
|
8
|
+
from: string;
|
|
9
|
+
gas: string;
|
|
10
|
+
gasPrice: string;
|
|
11
|
+
gasUsed: string;
|
|
12
|
+
hash: string;
|
|
13
|
+
nonce: string;
|
|
14
|
+
timeStamp: string;
|
|
15
|
+
to: string;
|
|
16
|
+
transactionIndex: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
export interface EtherscanTransactionMeta extends EtherscanTransactionMetaBase {
|
|
20
|
+
functionName: string;
|
|
21
|
+
input: string;
|
|
22
|
+
isError: string;
|
|
23
|
+
methodId: string;
|
|
24
|
+
txreceipt_status: string;
|
|
25
|
+
}
|
|
26
|
+
export interface EtherscanTokenTransactionMeta extends EtherscanTransactionMetaBase {
|
|
27
|
+
tokenDecimal: string;
|
|
28
|
+
tokenName: string;
|
|
29
|
+
tokenSymbol: string;
|
|
30
|
+
}
|
|
31
|
+
export interface EtherscanTransactionResponse<T extends EtherscanTransactionMetaBase> {
|
|
32
|
+
status: '0' | '1';
|
|
33
|
+
message?: string;
|
|
34
|
+
result: string | T[];
|
|
35
|
+
}
|
|
36
|
+
export interface EtherscanTransactionRequest {
|
|
37
|
+
address: string;
|
|
38
|
+
chainId: Hex;
|
|
39
|
+
fromBlock?: number;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves transaction data from Etherscan.
|
|
44
|
+
*
|
|
45
|
+
* @param request - Configuration required to fetch transactions.
|
|
46
|
+
* @param request.address - Address to retrieve transactions for.
|
|
47
|
+
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
48
|
+
* @param request.fromBlock - Block number to start fetching transactions from.
|
|
49
|
+
* @param request.limit - Number of transactions to retrieve.
|
|
50
|
+
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fetchEtherscanTransactions({ address, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTransactionMeta>>;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves token transaction data from Etherscan.
|
|
55
|
+
*
|
|
56
|
+
* @param request - Configuration required to fetch token transactions.
|
|
57
|
+
* @param request.address - Address to retrieve token transactions for.
|
|
58
|
+
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
59
|
+
* @param request.fromBlock - Block number to start fetching token transactions from.
|
|
60
|
+
* @param request.limit - Number of token transactions to retrieve.
|
|
61
|
+
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
62
|
+
*/
|
|
63
|
+
export declare function fetchEtherscanTokenTransactions({ address, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTokenTransactionMeta>>;
|
|
64
|
+
/**
|
|
65
|
+
* Return the host url used to fetch data from Etherscan.
|
|
66
|
+
*
|
|
67
|
+
* @param chainId - Current chain ID used to determine subdomain and domain.
|
|
68
|
+
* @returns host URL to access Etherscan data.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getEtherscanApiHost(chainId: Hex): string;
|
|
71
|
+
//# sourceMappingURL=etherscan.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"etherscan.d.mts","sourceRoot":"","sources":["../../src/utils/etherscan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAQ3C,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IAGjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAKD,MAAM,WAAW,6BACf,SAAQ,4BAA4B;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAKD,MAAM,WAAW,4BAA4B,CAG3C,CAAC,SAAS,4BAA4B;IAEtC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;CACtB;AAKD,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,2BAA2B,GAAG,OAAO,CACtC,4BAA4B,CAAC,wBAAwB,CAAC,CACvD,CAOA;AAED;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CAAC,EACpD,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,2BAA2B,GAAG,OAAO,CACtC,4BAA4B,CAAC,6BAA6B,CAAC,CAC5D,CAOA;AAgFD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,GAAG,UAW/C"}
|
package/dist/utils/etherscan.mjs
CHANGED
|
@@ -1,14 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { handleFetch } from "@metamask/controller-utils";
|
|
2
|
+
import { ETHERSCAN_SUPPORTED_NETWORKS } from "../constants.mjs";
|
|
3
|
+
import { incomingTransactionsLogger as log } from "../logger.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves transaction data from Etherscan.
|
|
6
|
+
*
|
|
7
|
+
* @param request - Configuration required to fetch transactions.
|
|
8
|
+
* @param request.address - Address to retrieve transactions for.
|
|
9
|
+
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
10
|
+
* @param request.fromBlock - Block number to start fetching transactions from.
|
|
11
|
+
* @param request.limit - Number of transactions to retrieve.
|
|
12
|
+
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
13
|
+
*/
|
|
14
|
+
export async function fetchEtherscanTransactions({ address, chainId, fromBlock, limit, }) {
|
|
15
|
+
return await fetchTransactions('txlist', {
|
|
16
|
+
address,
|
|
17
|
+
chainId,
|
|
18
|
+
fromBlock,
|
|
19
|
+
limit,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves token transaction data from Etherscan.
|
|
24
|
+
*
|
|
25
|
+
* @param request - Configuration required to fetch token transactions.
|
|
26
|
+
* @param request.address - Address to retrieve token transactions for.
|
|
27
|
+
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
28
|
+
* @param request.fromBlock - Block number to start fetching token transactions from.
|
|
29
|
+
* @param request.limit - Number of token transactions to retrieve.
|
|
30
|
+
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
31
|
+
*/
|
|
32
|
+
export async function fetchEtherscanTokenTransactions({ address, chainId, fromBlock, limit, }) {
|
|
33
|
+
return await fetchTransactions('tokentx', {
|
|
34
|
+
address,
|
|
35
|
+
chainId,
|
|
36
|
+
fromBlock,
|
|
37
|
+
limit,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves transaction data from Etherscan from a specific endpoint.
|
|
42
|
+
*
|
|
43
|
+
* @param action - The Etherscan endpoint to use.
|
|
44
|
+
* @param options - Options bag.
|
|
45
|
+
* @param options.address - Address to retrieve transactions for.
|
|
46
|
+
* @param options.chainId - Current chain ID used to determine subdomain and domain.
|
|
47
|
+
* @param options.fromBlock - Block number to start fetching transactions from.
|
|
48
|
+
* @param options.limit - Number of transactions to retrieve.
|
|
49
|
+
* @returns An object containing the request status and an array of transaction data.
|
|
50
|
+
*/
|
|
51
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
53
|
+
async function fetchTransactions(action, { address, chainId, fromBlock, limit, }) {
|
|
54
|
+
const urlParams = {
|
|
55
|
+
module: 'account',
|
|
56
|
+
address,
|
|
57
|
+
startBlock: fromBlock?.toString(),
|
|
58
|
+
offset: limit?.toString(),
|
|
59
|
+
sort: 'desc',
|
|
60
|
+
};
|
|
61
|
+
const etherscanTxUrl = getEtherscanApiUrl(chainId, {
|
|
62
|
+
...urlParams,
|
|
63
|
+
action,
|
|
64
|
+
});
|
|
65
|
+
log('Sending Etherscan request', etherscanTxUrl);
|
|
66
|
+
const response = (await handleFetch(etherscanTxUrl));
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return a URL that can be used to fetch data from Etherscan.
|
|
71
|
+
*
|
|
72
|
+
* @param chainId - Current chain ID used to determine subdomain and domain.
|
|
73
|
+
* @param urlParams - The parameters used to construct the URL.
|
|
74
|
+
* @returns URL to access Etherscan data.
|
|
75
|
+
*/
|
|
76
|
+
function getEtherscanApiUrl(chainId, urlParams) {
|
|
77
|
+
const apiUrl = getEtherscanApiHost(chainId);
|
|
78
|
+
let url = `${apiUrl}/api?`;
|
|
79
|
+
for (const paramKey of Object.keys(urlParams)) {
|
|
80
|
+
const value = urlParams[paramKey];
|
|
81
|
+
if (!value) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
url += `${paramKey}=${value}&`;
|
|
85
|
+
}
|
|
86
|
+
url += 'tag=latest&page=1';
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Return the host url used to fetch data from Etherscan.
|
|
91
|
+
*
|
|
92
|
+
* @param chainId - Current chain ID used to determine subdomain and domain.
|
|
93
|
+
* @returns host URL to access Etherscan data.
|
|
94
|
+
*/
|
|
95
|
+
export function getEtherscanApiHost(chainId) {
|
|
96
|
+
// @ts-expect-error We account for `chainId` not being a property below
|
|
97
|
+
const networkInfo = ETHERSCAN_SUPPORTED_NETWORKS[chainId];
|
|
98
|
+
if (!networkInfo) {
|
|
99
|
+
throw new Error(`Etherscan does not support chain with ID: ${chainId}`);
|
|
100
|
+
}
|
|
101
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
103
|
+
return `https://${networkInfo.subdomain}.${networkInfo.domain}`;
|
|
104
|
+
}
|
|
14
105
|
//# sourceMappingURL=etherscan.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"etherscan.mjs","sourceRoot":"","sources":["../../src/utils/etherscan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAGzD,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;AAC5D,OAAO,EAAE,0BAA0B,IAAI,GAAG,EAAE,sBAAkB;AAqE9D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAC/C,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACuB;IAG5B,OAAO,MAAM,iBAAiB,CAAC,QAAQ,EAAE;QACvC,OAAO;QACP,OAAO;QACP,SAAS;QACT,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,EACpD,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACuB;IAG5B,OAAO,MAAM,iBAAiB,CAAC,SAAS,EAAE;QACxC,OAAO;QACP,OAAO;QACP,SAAS;QACT,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,gFAAgF;AACh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AAC;KACzE;IAED,gFAAgF;IAChF,4EAA4E;IAC5E,OAAO,WAAW,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;AAClE,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from '../constants';\nimport { incomingTransactionsLogger as log } from '../logger';\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface EtherscanTransactionMetaBase {\n blockNumber: string;\n blockHash: string;\n confirmations: string;\n contractAddress: string;\n cumulativeGasUsed: string;\n from: string;\n gas: string;\n gasPrice: string;\n gasUsed: string;\n hash: string;\n nonce: string;\n timeStamp: string;\n to: string;\n transactionIndex: string;\n value: string;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface EtherscanTransactionMeta extends EtherscanTransactionMetaBase {\n functionName: string;\n input: string;\n isError: string;\n methodId: string;\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n txreceipt_status: string;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface EtherscanTokenTransactionMeta\n extends EtherscanTransactionMetaBase {\n tokenDecimal: string;\n tokenName: string;\n tokenSymbol: string;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface EtherscanTransactionResponse<\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n T extends EtherscanTransactionMetaBase,\n> {\n status: '0' | '1';\n message?: string;\n result: string | T[];\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface EtherscanTransactionRequest {\n address: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n}\n\n/**\n * Retrieves transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch transactions.\n * @param request.address - Address to retrieve transactions for.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching transactions from.\n * @param request.limit - Number of transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTransactions({\n address,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTransactionMeta>\n> {\n return await fetchTransactions('txlist', {\n address,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves token transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch token transactions.\n * @param request.address - Address to retrieve token transactions for.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching token transactions from.\n * @param request.limit - Number of token transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTokenTransactions({\n address,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTokenTransactionMeta>\n> {\n return await fetchTransactions('tokentx', {\n address,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves transaction data from Etherscan from a specific endpoint.\n *\n * @param action - The Etherscan endpoint to use.\n * @param options - Options bag.\n * @param options.address - Address to retrieve transactions for.\n * @param options.chainId - Current chain ID used to determine subdomain and domain.\n * @param options.fromBlock - Block number to start fetching transactions from.\n * @param options.limit - Number of transactions to retrieve.\n * @returns An object containing the request status and an array of transaction data.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nasync function fetchTransactions<T extends EtherscanTransactionMetaBase>(\n action: string,\n {\n address,\n chainId,\n fromBlock,\n limit,\n }: {\n address: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n },\n): Promise<EtherscanTransactionResponse<T>> {\n const urlParams = {\n module: 'account',\n address,\n startBlock: fromBlock?.toString(),\n offset: limit?.toString(),\n sort: 'desc',\n };\n\n const etherscanTxUrl = getEtherscanApiUrl(chainId, {\n ...urlParams,\n action,\n });\n\n log('Sending Etherscan request', etherscanTxUrl);\n\n const response = (await handleFetch(\n etherscanTxUrl,\n )) as EtherscanTransactionResponse<T>;\n\n return response;\n}\n\n/**\n * Return a URL that can be used to fetch data from Etherscan.\n *\n * @param chainId - Current chain ID used to determine subdomain and domain.\n * @param urlParams - The parameters used to construct the URL.\n * @returns URL to access Etherscan data.\n */\nfunction getEtherscanApiUrl(\n chainId: Hex,\n urlParams: Record<string, string | undefined>,\n): string {\n const apiUrl = getEtherscanApiHost(chainId);\n let url = `${apiUrl}/api?`;\n\n for (const paramKey of Object.keys(urlParams)) {\n const value = urlParams[paramKey];\n\n if (!value) {\n continue;\n }\n\n url += `${paramKey}=${value}&`;\n }\n\n url += 'tag=latest&page=1';\n\n return url;\n}\n\n/**\n * Return the host url used to fetch data from Etherscan.\n *\n * @param chainId - Current chain ID used to determine subdomain and domain.\n * @returns host URL to access Etherscan data.\n */\nexport function getEtherscanApiHost(chainId: Hex) {\n // @ts-expect-error We account for `chainId` not being a property below\n const networkInfo = ETHERSCAN_SUPPORTED_NETWORKS[chainId];\n\n if (!networkInfo) {\n throw new Error(`Etherscan does not support chain with ID: ${chainId}`);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `https://${networkInfo.subdomain}.${networkInfo.domain}`;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfirmedExternalTransaction = void 0;
|
|
4
|
+
// These utility functions are exclusively used by `confirmExternalTransaction` method in controller
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
6
|
+
const types_1 = require("../types.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Validates the external provided transaction meta.
|
|
9
|
+
*
|
|
10
|
+
* @param transactionMeta - The transaction meta to validate.
|
|
11
|
+
* @param confirmedTxs - The confirmed transactions in controller state.
|
|
12
|
+
* @param pendingTxs - The submitted transactions in controller state.
|
|
13
|
+
*/
|
|
14
|
+
function validateConfirmedExternalTransaction(transactionMeta, confirmedTxs, pendingTxs) {
|
|
15
|
+
if (!transactionMeta || !transactionMeta.txParams) {
|
|
16
|
+
throw rpc_errors_1.rpcErrors.invalidParams('"transactionMeta" or "transactionMeta.txParams" is missing');
|
|
17
|
+
}
|
|
18
|
+
if (transactionMeta.status !== types_1.TransactionStatus.confirmed) {
|
|
19
|
+
throw rpc_errors_1.rpcErrors.invalidParams('External transaction status should be "confirmed"');
|
|
20
|
+
}
|
|
21
|
+
const externalTxNonce = transactionMeta.txParams.nonce;
|
|
22
|
+
if (pendingTxs && pendingTxs.length > 0) {
|
|
23
|
+
const foundPendingTxByNonce = pendingTxs.find((tx) => tx.txParams?.nonce === externalTxNonce);
|
|
24
|
+
if (foundPendingTxByNonce) {
|
|
25
|
+
throw rpc_errors_1.rpcErrors.invalidParams('External transaction nonce should not be in pending txs');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (confirmedTxs && confirmedTxs.length > 0) {
|
|
29
|
+
const foundConfirmedTxByNonce = confirmedTxs.find((tx) => tx.txParams?.nonce === externalTxNonce);
|
|
30
|
+
if (foundConfirmedTxByNonce) {
|
|
31
|
+
throw rpc_errors_1.rpcErrors.invalidParams('External transaction nonce should not be in confirmed txs');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.validateConfirmedExternalTransaction = validateConfirmedExternalTransaction;
|
|
36
|
+
//# sourceMappingURL=external-transactions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-transactions.cjs","sourceRoot":"","sources":["../../src/utils/external-transactions.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACpG,qDAAiD;AAEjD,wCAA6C;AAG7C;;;;;;GAMG;AACH,SAAgB,oCAAoC,CAClD,eAAiC,EACjC,YAAgC,EAChC,UAA8B;IAE9B,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;QACjD,MAAM,sBAAS,CAAC,aAAa,CAC3B,4DAA4D,CAC7D,CAAC;KACH;IAED,IAAI,eAAe,CAAC,MAAM,KAAK,yBAAiB,CAAC,SAAS,EAAE;QAC1D,MAAM,sBAAS,CAAC,aAAa,CAC3B,mDAAmD,CACpD,CAAC;KACH;IAED,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAC3C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,eAAe,CAC/C,CAAC;QACF,IAAI,qBAAqB,EAAE;YACzB,MAAM,sBAAS,CAAC,aAAa,CAC3B,yDAAyD,CAC1D,CAAC;SACH;KACF;IAED,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,uBAAuB,GAAG,YAAY,CAAC,IAAI,CAC/C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,eAAe,CAC/C,CAAC;QACF,IAAI,uBAAuB,EAAE;YAC3B,MAAM,sBAAS,CAAC,aAAa,CAC3B,2DAA2D,CAC5D,CAAC;SACH;KACF;AACH,CAAC;AAvCD,oFAuCC","sourcesContent":["// These utility functions are exclusively used by `confirmExternalTransaction` method in controller\nimport { rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionStatus } from '../types';\nimport type { TransactionMeta } from '../types';\n\n/**\n * Validates the external provided transaction meta.\n *\n * @param transactionMeta - The transaction meta to validate.\n * @param confirmedTxs - The confirmed transactions in controller state.\n * @param pendingTxs - The submitted transactions in controller state.\n */\nexport function validateConfirmedExternalTransaction(\n transactionMeta?: TransactionMeta,\n confirmedTxs?: TransactionMeta[],\n pendingTxs?: TransactionMeta[],\n) {\n if (!transactionMeta || !transactionMeta.txParams) {\n throw rpcErrors.invalidParams(\n '\"transactionMeta\" or \"transactionMeta.txParams\" is missing',\n );\n }\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n throw rpcErrors.invalidParams(\n 'External transaction status should be \"confirmed\"',\n );\n }\n\n const externalTxNonce = transactionMeta.txParams.nonce;\n if (pendingTxs && pendingTxs.length > 0) {\n const foundPendingTxByNonce = pendingTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundPendingTxByNonce) {\n throw rpcErrors.invalidParams(\n 'External transaction nonce should not be in pending txs',\n );\n }\n }\n\n if (confirmedTxs && confirmedTxs.length > 0) {\n const foundConfirmedTxByNonce = confirmedTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundConfirmedTxByNonce) {\n throw rpcErrors.invalidParams(\n 'External transaction nonce should not be in confirmed txs',\n );\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransactionMeta } from
|
|
1
|
+
import type { TransactionMeta } from "../types.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Validates the external provided transaction meta.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import type { TransactionMeta } from '../types';
|
|
|
7
7
|
* @param pendingTxs - The submitted transactions in controller state.
|
|
8
8
|
*/
|
|
9
9
|
export declare function validateConfirmedExternalTransaction(transactionMeta?: TransactionMeta, confirmedTxs?: TransactionMeta[], pendingTxs?: TransactionMeta[]): void;
|
|
10
|
-
//# sourceMappingURL=external-transactions.d.
|
|
10
|
+
//# sourceMappingURL=external-transactions.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-transactions.d.cts","sourceRoot":"","sources":["../../src/utils/external-transactions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAEhD;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,CAAC,EAAE,eAAe,EACjC,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,UAAU,CAAC,EAAE,eAAe,EAAE,QAoC/B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TransactionMeta } from "../types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the external provided transaction meta.
|
|
4
|
+
*
|
|
5
|
+
* @param transactionMeta - The transaction meta to validate.
|
|
6
|
+
* @param confirmedTxs - The confirmed transactions in controller state.
|
|
7
|
+
* @param pendingTxs - The submitted transactions in controller state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateConfirmedExternalTransaction(transactionMeta?: TransactionMeta, confirmedTxs?: TransactionMeta[], pendingTxs?: TransactionMeta[]): void;
|
|
10
|
+
//# sourceMappingURL=external-transactions.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-transactions.d.mts","sourceRoot":"","sources":["../../src/utils/external-transactions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAEhD;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,CAAC,EAAE,eAAe,EACjC,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,UAAU,CAAC,EAAE,eAAe,EAAE,QAoC/B"}
|
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} from "../
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// These utility functions are exclusively used by `confirmExternalTransaction` method in controller
|
|
2
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { TransactionStatus } from "../types.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Validates the external provided transaction meta.
|
|
6
|
+
*
|
|
7
|
+
* @param transactionMeta - The transaction meta to validate.
|
|
8
|
+
* @param confirmedTxs - The confirmed transactions in controller state.
|
|
9
|
+
* @param pendingTxs - The submitted transactions in controller state.
|
|
10
|
+
*/
|
|
11
|
+
export function validateConfirmedExternalTransaction(transactionMeta, confirmedTxs, pendingTxs) {
|
|
12
|
+
if (!transactionMeta || !transactionMeta.txParams) {
|
|
13
|
+
throw rpcErrors.invalidParams('"transactionMeta" or "transactionMeta.txParams" is missing');
|
|
14
|
+
}
|
|
15
|
+
if (transactionMeta.status !== TransactionStatus.confirmed) {
|
|
16
|
+
throw rpcErrors.invalidParams('External transaction status should be "confirmed"');
|
|
17
|
+
}
|
|
18
|
+
const externalTxNonce = transactionMeta.txParams.nonce;
|
|
19
|
+
if (pendingTxs && pendingTxs.length > 0) {
|
|
20
|
+
const foundPendingTxByNonce = pendingTxs.find((tx) => tx.txParams?.nonce === externalTxNonce);
|
|
21
|
+
if (foundPendingTxByNonce) {
|
|
22
|
+
throw rpcErrors.invalidParams('External transaction nonce should not be in pending txs');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (confirmedTxs && confirmedTxs.length > 0) {
|
|
26
|
+
const foundConfirmedTxByNonce = confirmedTxs.find((tx) => tx.txParams?.nonce === externalTxNonce);
|
|
27
|
+
if (foundConfirmedTxByNonce) {
|
|
28
|
+
throw rpcErrors.invalidParams('External transaction nonce should not be in confirmed txs');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
9
32
|
//# sourceMappingURL=external-transactions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"external-transactions.mjs","sourceRoot":"","sources":["../../src/utils/external-transactions.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,iBAAiB,EAAE,qBAAiB;AAG7C;;;;;;GAMG;AACH,MAAM,UAAU,oCAAoC,CAClD,eAAiC,EACjC,YAAgC,EAChC,UAA8B;IAE9B,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;QACjD,MAAM,SAAS,CAAC,aAAa,CAC3B,4DAA4D,CAC7D,CAAC;KACH;IAED,IAAI,eAAe,CAAC,MAAM,KAAK,iBAAiB,CAAC,SAAS,EAAE;QAC1D,MAAM,SAAS,CAAC,aAAa,CAC3B,mDAAmD,CACpD,CAAC;KACH;IAED,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAC3C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,eAAe,CAC/C,CAAC;QACF,IAAI,qBAAqB,EAAE;YACzB,MAAM,SAAS,CAAC,aAAa,CAC3B,yDAAyD,CAC1D,CAAC;SACH;KACF;IAED,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,uBAAuB,GAAG,YAAY,CAAC,IAAI,CAC/C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,eAAe,CAC/C,CAAC;QACF,IAAI,uBAAuB,EAAE;YAC3B,MAAM,SAAS,CAAC,aAAa,CAC3B,2DAA2D,CAC5D,CAAC;SACH;KACF;AACH,CAAC","sourcesContent":["// These utility functions are exclusively used by `confirmExternalTransaction` method in controller\nimport { rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionStatus } from '../types';\nimport type { TransactionMeta } from '../types';\n\n/**\n * Validates the external provided transaction meta.\n *\n * @param transactionMeta - The transaction meta to validate.\n * @param confirmedTxs - The confirmed transactions in controller state.\n * @param pendingTxs - The submitted transactions in controller state.\n */\nexport function validateConfirmedExternalTransaction(\n transactionMeta?: TransactionMeta,\n confirmedTxs?: TransactionMeta[],\n pendingTxs?: TransactionMeta[],\n) {\n if (!transactionMeta || !transactionMeta.txParams) {\n throw rpcErrors.invalidParams(\n '\"transactionMeta\" or \"transactionMeta.txParams\" is missing',\n );\n }\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n throw rpcErrors.invalidParams(\n 'External transaction status should be \"confirmed\"',\n );\n }\n\n const externalTxNonce = transactionMeta.txParams.nonce;\n if (pendingTxs && pendingTxs.length > 0) {\n const foundPendingTxByNonce = pendingTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundPendingTxByNonce) {\n throw rpcErrors.invalidParams(\n 'External transaction nonce should not be in pending txs',\n );\n }\n }\n\n if (confirmedTxs && confirmedTxs.length > 0) {\n const foundConfirmedTxByNonce = confirmedTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundConfirmedTxByNonce) {\n throw rpcErrors.invalidParams(\n 'External transaction nonce should not be in confirmed txs',\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.gweiDecimalToWeiHex = exports.updateGasFees = void 0;
|
|
5
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
+
const utils_1 = require("@metamask/utils");
|
|
7
|
+
const logger_1 = require("../logger.cjs");
|
|
8
|
+
const types_1 = require("../types.cjs");
|
|
9
|
+
const gas_flow_1 = require("./gas-flow.cjs");
|
|
10
|
+
const swaps_1 = require("./swaps.cjs");
|
|
11
|
+
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'gas-fees');
|
|
12
|
+
async function updateGasFees(request) {
|
|
13
|
+
const { txMeta } = request;
|
|
14
|
+
const initialParams = { ...txMeta.txParams };
|
|
15
|
+
const isSwap = swaps_1.SWAP_TRANSACTION_TYPES.includes(txMeta.type);
|
|
16
|
+
const savedGasFees = isSwap
|
|
17
|
+
? undefined
|
|
18
|
+
: request.getSavedGasFees(txMeta.chainId);
|
|
19
|
+
const suggestedGasFees = await getSuggestedGasFees(request);
|
|
20
|
+
log('Suggested gas fees', suggestedGasFees);
|
|
21
|
+
const getGasFeeRequest = {
|
|
22
|
+
...request,
|
|
23
|
+
initialParams,
|
|
24
|
+
savedGasFees,
|
|
25
|
+
suggestedGasFees,
|
|
26
|
+
};
|
|
27
|
+
txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);
|
|
28
|
+
txMeta.txParams.maxPriorityFeePerGas =
|
|
29
|
+
getMaxPriorityFeePerGas(getGasFeeRequest);
|
|
30
|
+
txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);
|
|
31
|
+
txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);
|
|
32
|
+
log('Updated gas fee properties', {
|
|
33
|
+
maxFeePerGas: txMeta.txParams.maxFeePerGas,
|
|
34
|
+
maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,
|
|
35
|
+
gasPrice: txMeta.txParams.gasPrice,
|
|
36
|
+
});
|
|
37
|
+
if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {
|
|
38
|
+
delete txMeta.txParams.gasPrice;
|
|
39
|
+
}
|
|
40
|
+
if (txMeta.txParams.gasPrice) {
|
|
41
|
+
delete txMeta.txParams.maxFeePerGas;
|
|
42
|
+
delete txMeta.txParams.maxPriorityFeePerGas;
|
|
43
|
+
}
|
|
44
|
+
updateDefaultGasEstimates(txMeta);
|
|
45
|
+
}
|
|
46
|
+
exports.updateGasFees = updateGasFees;
|
|
47
|
+
function gweiDecimalToWeiHex(value) {
|
|
48
|
+
return (0, controller_utils_1.toHex)((0, controller_utils_1.gweiDecToWEIBN)(value));
|
|
49
|
+
}
|
|
50
|
+
exports.gweiDecimalToWeiHex = gweiDecimalToWeiHex;
|
|
51
|
+
function getMaxFeePerGas(request) {
|
|
52
|
+
const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;
|
|
53
|
+
if (!eip1559) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (savedGasFees) {
|
|
57
|
+
const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);
|
|
58
|
+
log('Using maxFeePerGas from savedGasFees', maxFeePerGas);
|
|
59
|
+
return maxFeePerGas;
|
|
60
|
+
}
|
|
61
|
+
if (initialParams.maxFeePerGas) {
|
|
62
|
+
log('Using maxFeePerGas from request', initialParams.maxFeePerGas);
|
|
63
|
+
return initialParams.maxFeePerGas;
|
|
64
|
+
}
|
|
65
|
+
if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {
|
|
66
|
+
log('Setting maxFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
67
|
+
return initialParams.gasPrice;
|
|
68
|
+
}
|
|
69
|
+
if (suggestedGasFees.maxFeePerGas) {
|
|
70
|
+
log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
|
|
71
|
+
return suggestedGasFees.maxFeePerGas;
|
|
72
|
+
}
|
|
73
|
+
if (suggestedGasFees.gasPrice) {
|
|
74
|
+
log('Setting maxFeePerGas to suggested gasPrice', suggestedGasFees.gasPrice);
|
|
75
|
+
return suggestedGasFees.gasPrice;
|
|
76
|
+
}
|
|
77
|
+
log('maxFeePerGas not set');
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function getMaxPriorityFeePerGas(request) {
|
|
81
|
+
const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
|
|
82
|
+
if (!eip1559) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (savedGasFees) {
|
|
86
|
+
const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);
|
|
87
|
+
log('Using maxPriorityFeePerGas from savedGasFees.priorityFee', maxPriorityFeePerGas);
|
|
88
|
+
return maxPriorityFeePerGas;
|
|
89
|
+
}
|
|
90
|
+
if (initialParams.maxPriorityFeePerGas) {
|
|
91
|
+
log('Using maxPriorityFeePerGas from request', initialParams.maxPriorityFeePerGas);
|
|
92
|
+
return initialParams.maxPriorityFeePerGas;
|
|
93
|
+
}
|
|
94
|
+
if (initialParams.gasPrice && !initialParams.maxFeePerGas) {
|
|
95
|
+
log('Setting maxPriorityFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
96
|
+
return initialParams.gasPrice;
|
|
97
|
+
}
|
|
98
|
+
if (suggestedGasFees.maxPriorityFeePerGas) {
|
|
99
|
+
log('Using suggested maxPriorityFeePerGas', suggestedGasFees.maxPriorityFeePerGas);
|
|
100
|
+
return suggestedGasFees.maxPriorityFeePerGas;
|
|
101
|
+
}
|
|
102
|
+
if (txMeta.txParams.maxFeePerGas) {
|
|
103
|
+
log('Setting maxPriorityFeePerGas to maxFeePerGas', txMeta.txParams.maxFeePerGas);
|
|
104
|
+
return txMeta.txParams.maxFeePerGas;
|
|
105
|
+
}
|
|
106
|
+
log('maxPriorityFeePerGas not set');
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function getGasPrice(request) {
|
|
110
|
+
const { eip1559, initialParams, suggestedGasFees } = request;
|
|
111
|
+
if (eip1559) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (initialParams.gasPrice) {
|
|
115
|
+
log('Using gasPrice from request', initialParams.gasPrice);
|
|
116
|
+
return initialParams.gasPrice;
|
|
117
|
+
}
|
|
118
|
+
if (suggestedGasFees.maxFeePerGas) {
|
|
119
|
+
log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
|
|
120
|
+
return suggestedGasFees.maxFeePerGas;
|
|
121
|
+
}
|
|
122
|
+
if (suggestedGasFees.gasPrice) {
|
|
123
|
+
log('Using suggested gasPrice', suggestedGasFees.gasPrice);
|
|
124
|
+
return suggestedGasFees.gasPrice;
|
|
125
|
+
}
|
|
126
|
+
log('gasPrice not set');
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
function getUserFeeLevel(request) {
|
|
130
|
+
const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
|
|
131
|
+
if (!eip1559) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
if (savedGasFees) {
|
|
135
|
+
return types_1.UserFeeLevel.CUSTOM;
|
|
136
|
+
}
|
|
137
|
+
if (!initialParams.maxFeePerGas &&
|
|
138
|
+
!initialParams.maxPriorityFeePerGas &&
|
|
139
|
+
initialParams.gasPrice) {
|
|
140
|
+
return txMeta.origin === controller_utils_1.ORIGIN_METAMASK
|
|
141
|
+
? types_1.UserFeeLevel.CUSTOM
|
|
142
|
+
: types_1.UserFeeLevel.DAPP_SUGGESTED;
|
|
143
|
+
}
|
|
144
|
+
if (!initialParams.maxFeePerGas &&
|
|
145
|
+
!initialParams.maxPriorityFeePerGas &&
|
|
146
|
+
suggestedGasFees.maxFeePerGas &&
|
|
147
|
+
suggestedGasFees.maxPriorityFeePerGas) {
|
|
148
|
+
return types_1.UserFeeLevel.MEDIUM;
|
|
149
|
+
}
|
|
150
|
+
if (txMeta.origin === controller_utils_1.ORIGIN_METAMASK) {
|
|
151
|
+
return types_1.UserFeeLevel.MEDIUM;
|
|
152
|
+
}
|
|
153
|
+
return types_1.UserFeeLevel.DAPP_SUGGESTED;
|
|
154
|
+
}
|
|
155
|
+
function updateDefaultGasEstimates(txMeta) {
|
|
156
|
+
if (!txMeta.defaultGasEstimates) {
|
|
157
|
+
txMeta.defaultGasEstimates = {};
|
|
158
|
+
}
|
|
159
|
+
txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;
|
|
160
|
+
txMeta.defaultGasEstimates.maxPriorityFeePerGas =
|
|
161
|
+
txMeta.txParams.maxPriorityFeePerGas;
|
|
162
|
+
txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;
|
|
163
|
+
txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;
|
|
164
|
+
}
|
|
165
|
+
async function getSuggestedGasFees(request) {
|
|
166
|
+
const { eip1559, ethQuery, gasFeeFlows, getGasFeeEstimates, txMeta } = request;
|
|
167
|
+
const { networkClientId } = txMeta;
|
|
168
|
+
if ((!eip1559 && txMeta.txParams.gasPrice) ||
|
|
169
|
+
(eip1559 &&
|
|
170
|
+
txMeta.txParams.maxFeePerGas &&
|
|
171
|
+
txMeta.txParams.maxPriorityFeePerGas)) {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
const gasFeeFlow = (0, gas_flow_1.getGasFeeFlow)(txMeta, gasFeeFlows);
|
|
175
|
+
try {
|
|
176
|
+
const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });
|
|
177
|
+
const response = await gasFeeFlow.getGasFees({
|
|
178
|
+
ethQuery,
|
|
179
|
+
gasFeeControllerData,
|
|
180
|
+
transactionMeta: txMeta,
|
|
181
|
+
});
|
|
182
|
+
const gasFeeEstimateType = response.estimates?.type;
|
|
183
|
+
switch (gasFeeEstimateType) {
|
|
184
|
+
case types_1.GasFeeEstimateType.FeeMarket:
|
|
185
|
+
return response.estimates.medium;
|
|
186
|
+
case types_1.GasFeeEstimateType.Legacy:
|
|
187
|
+
return {
|
|
188
|
+
gasPrice: response.estimates.medium,
|
|
189
|
+
};
|
|
190
|
+
case types_1.GasFeeEstimateType.GasPrice:
|
|
191
|
+
return { gasPrice: response.estimates.gasPrice };
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(
|
|
194
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
196
|
+
`Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
log('Failed to get suggested gas fees', error);
|
|
201
|
+
}
|
|
202
|
+
const gasPriceDecimal = (await (0, controller_utils_1.query)(ethQuery, 'gasPrice'));
|
|
203
|
+
const gasPrice = gasPriceDecimal
|
|
204
|
+
? (0, utils_1.add0x)(gasPriceDecimal.toString(16))
|
|
205
|
+
: undefined;
|
|
206
|
+
return { gasPrice };
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=gas-fees.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";AAAA,wCAAwC;;;AAExC,iEAKoC;AAOpC,2CAA4D;AAE5D,0CAA0C;AAQ1C,wCAA4D;AAC5D,6CAA2C;AAC3C,uCAAiD;AAyBjD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,UAAU,CAAC,CAAC;AAEnD,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,MAAM,GAAG,8BAAsB,CAAC,QAAQ,CAC5C,MAAM,CAAC,IAAuB,CAC/B,CAAC;IACF,MAAM,YAAY,GAAG,MAAM;QACzB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE5C,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE5D,GAAG,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;IAE5C,MAAM,gBAAgB,GAAqB;QACzC,GAAG,OAAO;QACV,aAAa;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AQ,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACnD;gBACE,MAAM,IAAI,KAAK;gBACb,gFAAgF;gBAChF,4EAA4E;gBAC5E,yDAAyD,kBAAkB,EAAE,CAC9E,CAAC;SACL;KACF;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;KAChD;IAED,MAAM,eAAe,GAAG,CAAC,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAW,CAAC;IAEtE,MAAM,QAAQ,GAAG,eAAe;QAC9B,CAAC,CAAC,IAAA,aAAK,EAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n\nimport {\n ORIGIN_METAMASK,\n gweiDecToWEIBN,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n TransactionType,\n GasFeeFlow,\n} from '../types';\nimport { GasFeeEstimateType, UserFeeLevel } from '../types';\nimport { getGasFeeFlow } from './gas-flow';\nimport { SWAP_TRANSACTION_TYPES } from './swaps';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n ethQuery: EthQuery;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (chainId: Hex) => SavedGasFees | undefined;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const isSwap = SWAP_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n const savedGasFees = isSwap\n ? undefined\n : request.getSavedGasFees(txMeta.chainId);\n\n const suggestedGasFees = await getSuggestedGasFees(request);\n\n log('Suggested gas fees', suggestedGasFees);\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\nexport function gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee as string);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n if (initialParams.maxFeePerGas) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n if (initialParams.maxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\nfunction getUserFeeLevel(request: GetGasFeeRequest): UserFeeLevel | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n return UserFeeLevel.CUSTOM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.origin === ORIGIN_METAMASK) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta) {\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<SuggestedGasFees> {\n const { eip1559, ethQuery, gasFeeFlows, getGasFeeEstimates, txMeta } =\n request;\n\n const { networkClientId } = txMeta;\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (eip1559 &&\n txMeta.txParams.maxFeePerGas &&\n txMeta.txParams.maxPriorityFeePerGas)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(txMeta, gasFeeFlows) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n ethQuery,\n gasFeeControllerData,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return response.estimates.medium;\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice: response.estimates.medium,\n };\n case GasFeeEstimateType.GasPrice:\n return { gasPrice: response.estimates.gasPrice };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n const gasPriceDecimal = (await query(ethQuery, 'gasPrice')) as number;\n\n const gasPrice = gasPriceDecimal\n ? add0x(gasPriceDecimal.toString(16))\n : undefined;\n\n return { gasPrice };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type EthQuery from
|
|
2
|
-
import type { FetchGasFeeEstimateOptions, GasFeeState } from
|
|
3
|
-
import type { Hex } from
|
|
4
|
-
import type { SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from
|
|
1
|
+
import type EthQuery from "@metamask/eth-query";
|
|
2
|
+
import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
|
|
3
|
+
import type { Hex } from "@metamask/utils";
|
|
4
|
+
import type { SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.cjs";
|
|
5
5
|
export type UpdateGasFeesRequest = {
|
|
6
6
|
eip1559: boolean;
|
|
7
7
|
ethQuery: EthQuery;
|
|
@@ -23,4 +23,4 @@ type SuggestedGasFees = {
|
|
|
23
23
|
export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
|
|
24
24
|
export declare function gweiDecimalToWeiHex(value: string): `0x${string}`;
|
|
25
25
|
export {};
|
|
26
|
-
//# sourceMappingURL=gas-fees.d.
|
|
26
|
+
//# sourceMappingURL=gas-fees.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,QAAQ,4BAA4B;AAChD,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EAEf,UAAU,EACX,qBAAiB;AAKlB,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,kBAAkB,EAAE,CAClB,OAAO,EAAE,0BAA0B,KAChC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1B,eAAe,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,YAAY,GAAG,SAAS,CAAC;IAC5D,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBA8ChE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,iBAEhD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type EthQuery from "@metamask/eth-query";
|
|
2
|
+
import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
|
|
3
|
+
import type { Hex } from "@metamask/utils";
|
|
4
|
+
import type { SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.mjs";
|
|
5
|
+
export type UpdateGasFeesRequest = {
|
|
6
|
+
eip1559: boolean;
|
|
7
|
+
ethQuery: EthQuery;
|
|
8
|
+
gasFeeFlows: GasFeeFlow[];
|
|
9
|
+
getGasFeeEstimates: (options: FetchGasFeeEstimateOptions) => Promise<GasFeeState>;
|
|
10
|
+
getSavedGasFees: (chainId: Hex) => SavedGasFees | undefined;
|
|
11
|
+
txMeta: TransactionMeta;
|
|
12
|
+
};
|
|
13
|
+
export type GetGasFeeRequest = UpdateGasFeesRequest & {
|
|
14
|
+
initialParams: TransactionParams;
|
|
15
|
+
savedGasFees?: SavedGasFees;
|
|
16
|
+
suggestedGasFees: SuggestedGasFees;
|
|
17
|
+
};
|
|
18
|
+
type SuggestedGasFees = {
|
|
19
|
+
maxFeePerGas?: string;
|
|
20
|
+
maxPriorityFeePerGas?: string;
|
|
21
|
+
gasPrice?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
|
|
24
|
+
export declare function gweiDecimalToWeiHex(value: string): `0x${string}`;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=gas-fees.d.mts.map
|