@metamask/transaction-controller 36.1.0 → 37.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/dist/TransactionController.cjs +2071 -0
- package/dist/TransactionController.cjs.map +1 -0
- package/dist/{types/TransactionController.d.ts → TransactionController.d.cts} +19 -26
- package/dist/TransactionController.d.cts.map +1 -0
- package/dist/TransactionController.d.mts +828 -0
- package/dist/TransactionController.d.mts.map +1 -0
- package/dist/TransactionController.mjs +2072 -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 +327 -0
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
- package/dist/{types/helpers/PendingTransactionTracker.d.ts → helpers/PendingTransactionTracker.d.cts} +7 -8
- 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 +319 -8
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +11 -10
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +7 -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} +35 -35
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +1027 -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 +20 -15
- 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-SD6CWFDF.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/transaction-type.ts
|
|
2
|
-
var _abi = require('@ethersproject/abi');
|
|
3
|
-
var _controllerutils = require('@metamask/controller-utils');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _metamaskethabis = require('@metamask/metamask-eth-abis');
|
|
10
|
-
var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
11
|
-
var ERC20Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC20);
|
|
12
|
-
var ERC721Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC721);
|
|
13
|
-
var ERC1155Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC1155);
|
|
14
|
-
var USDCInterface = new (0, _abi.Interface)(_metamaskethabis.abiFiatTokenV2);
|
|
15
|
-
async function determineTransactionType(txParams, ethQuery) {
|
|
16
|
-
const { data, to } = txParams;
|
|
17
|
-
if (data && !to) {
|
|
18
|
-
return { type: "contractDeployment" /* deployContract */, getCodeResponse: void 0 };
|
|
19
|
-
}
|
|
20
|
-
const { contractCode: getCodeResponse, isContractAddress } = await readAddressAsContract(ethQuery, to);
|
|
21
|
-
if (!isContractAddress) {
|
|
22
|
-
return { type: "simpleSend" /* simpleSend */, getCodeResponse };
|
|
23
|
-
}
|
|
24
|
-
const hasValue = Number(txParams.value ?? "0") !== 0;
|
|
25
|
-
const contractInteractionResult = {
|
|
26
|
-
type: "contractInteraction" /* contractInteraction */,
|
|
27
|
-
getCodeResponse
|
|
28
|
-
};
|
|
29
|
-
if (!data || hasValue) {
|
|
30
|
-
return contractInteractionResult;
|
|
31
|
-
}
|
|
32
|
-
const name = parseStandardTokenTransactionData(data)?.name;
|
|
33
|
-
if (!name) {
|
|
34
|
-
return contractInteractionResult;
|
|
35
|
-
}
|
|
36
|
-
const tokenMethodName = [
|
|
37
|
-
"approve" /* tokenMethodApprove */,
|
|
38
|
-
"setapprovalforall" /* tokenMethodSetApprovalForAll */,
|
|
39
|
-
"transfer" /* tokenMethodTransfer */,
|
|
40
|
-
"transferfrom" /* tokenMethodTransferFrom */,
|
|
41
|
-
"safetransferfrom" /* tokenMethodSafeTransferFrom */,
|
|
42
|
-
"increaseAllowance" /* tokenMethodIncreaseAllowance */
|
|
43
|
-
].find(
|
|
44
|
-
(methodName) => methodName.toLowerCase() === name.toLowerCase()
|
|
45
|
-
);
|
|
46
|
-
if (tokenMethodName) {
|
|
47
|
-
return { type: tokenMethodName, getCodeResponse };
|
|
48
|
-
}
|
|
49
|
-
return contractInteractionResult;
|
|
50
|
-
}
|
|
51
|
-
function parseStandardTokenTransactionData(data) {
|
|
52
|
-
if (!data) {
|
|
53
|
-
return void 0;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
return ERC20Interface.parseTransaction({ data });
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
return ERC721Interface.parseTransaction({ data });
|
|
61
|
-
} catch {
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
return ERC1155Interface.parseTransaction({ data });
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
return USDCInterface.parseTransaction({ data });
|
|
69
|
-
} catch {
|
|
70
|
-
}
|
|
71
|
-
return void 0;
|
|
72
|
-
}
|
|
73
|
-
async function readAddressAsContract(ethQuery, address) {
|
|
74
|
-
let contractCode;
|
|
75
|
-
try {
|
|
76
|
-
contractCode = await _controllerutils.query.call(void 0, ethQuery, "getCode", [address]);
|
|
77
|
-
} catch (e) {
|
|
78
|
-
contractCode = null;
|
|
79
|
-
}
|
|
80
|
-
const isContractAddress = contractCode ? contractCode !== "0x" && contractCode !== "0x0" : false;
|
|
81
|
-
return { contractCode, isContractAddress };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
exports.ESTIMATE_GAS_ERROR = ESTIMATE_GAS_ERROR; exports.determineTransactionType = determineTransactionType;
|
|
88
|
-
//# sourceMappingURL=chunk-SD6CWFDF.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/transaction-type.ts"],"names":[],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,qBAAqB;AAElC,IAAM,iBAAiB,IAAI,UAAU,QAAQ;AAC7C,IAAM,kBAAkB,IAAI,UAAU,SAAS;AAC/C,IAAM,mBAAmB,IAAI,UAAU,UAAU;AACjD,IAAM,gBAAgB,IAAI,UAAU,cAAc;AAWlD,eAAsB,yBACpB,UACA,UACqC;AACrC,QAAM,EAAE,MAAM,GAAG,IAAI;AAErB,MAAI,QAAQ,CAAC,IAA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SAAS,GAAG;AACV,mBAAe;AAAA,EACjB;AAEA,QAAM,oBAAoB,eACtB,iBAAiB,QAAQ,iBAAiB,QAC1C;AACJ,SAAO,EAAE,cAAc,kBAAkB;AAC3C","sourcesContent":["import type { TransactionDescription } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\n\nimport type { InferTransactionTypeResult, TransactionParams } from '../types';\nimport { TransactionType } from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\nconst USDCInterface = new Interface(abiFiatTokenV2);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n const { contractCode: getCodeResponse, isContractAddress } =\n await readAddressAsContract(ethQuery, to);\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = parseStandardTokenTransactionData(data)?.name;\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n TransactionType.tokenMethodIncreaseAllowance,\n ].find(\n (methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),\n );\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @returns A representation of an ethereum contract call.\n */\nfunction parseStandardTokenTransactionData(\n data?: string,\n): TransactionDescription | undefined {\n if (!data) {\n return undefined;\n }\n\n try {\n return ERC20Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc721 ABI\n }\n\n try {\n return ERC721Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc1155 ABI\n }\n\n try {\n return ERC1155Interface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n try {\n return USDCInterface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n return undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n } catch (e) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' && contractCode !== '0x0'\n : false;\n return { contractCode, isContractAddress };\n}\n"]}
|
package/dist/chunk-SFFOC25Q.mjs
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SWAP_TRANSACTION_TYPES
|
|
3
|
-
} from "./chunk-JIFPK37W.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getGasFeeFlow
|
|
6
|
-
} from "./chunk-NNHSNPT2.mjs";
|
|
7
|
-
import {
|
|
8
|
-
projectLogger
|
|
9
|
-
} from "./chunk-UQQWZT6C.mjs";
|
|
10
|
-
|
|
11
|
-
// src/utils/gas-fees.ts
|
|
12
|
-
import {
|
|
13
|
-
ORIGIN_METAMASK,
|
|
14
|
-
gweiDecToWEIBN,
|
|
15
|
-
query,
|
|
16
|
-
toHex
|
|
17
|
-
} from "@metamask/controller-utils";
|
|
18
|
-
import { add0x, createModuleLogger } from "@metamask/utils";
|
|
19
|
-
var log = createModuleLogger(projectLogger, "gas-fees");
|
|
20
|
-
async function updateGasFees(request) {
|
|
21
|
-
const { txMeta } = request;
|
|
22
|
-
const initialParams = { ...txMeta.txParams };
|
|
23
|
-
const isSwap = SWAP_TRANSACTION_TYPES.includes(
|
|
24
|
-
txMeta.type
|
|
25
|
-
);
|
|
26
|
-
const savedGasFees = isSwap ? void 0 : request.getSavedGasFees(txMeta.chainId);
|
|
27
|
-
const suggestedGasFees = await getSuggestedGasFees(request);
|
|
28
|
-
log("Suggested gas fees", suggestedGasFees);
|
|
29
|
-
const getGasFeeRequest = {
|
|
30
|
-
...request,
|
|
31
|
-
initialParams,
|
|
32
|
-
savedGasFees,
|
|
33
|
-
suggestedGasFees
|
|
34
|
-
};
|
|
35
|
-
txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);
|
|
36
|
-
txMeta.txParams.maxPriorityFeePerGas = getMaxPriorityFeePerGas(getGasFeeRequest);
|
|
37
|
-
txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);
|
|
38
|
-
txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);
|
|
39
|
-
log("Updated gas fee properties", {
|
|
40
|
-
maxFeePerGas: txMeta.txParams.maxFeePerGas,
|
|
41
|
-
maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,
|
|
42
|
-
gasPrice: txMeta.txParams.gasPrice
|
|
43
|
-
});
|
|
44
|
-
if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {
|
|
45
|
-
delete txMeta.txParams.gasPrice;
|
|
46
|
-
}
|
|
47
|
-
if (txMeta.txParams.gasPrice) {
|
|
48
|
-
delete txMeta.txParams.maxFeePerGas;
|
|
49
|
-
delete txMeta.txParams.maxPriorityFeePerGas;
|
|
50
|
-
}
|
|
51
|
-
updateDefaultGasEstimates(txMeta);
|
|
52
|
-
}
|
|
53
|
-
function gweiDecimalToWeiHex(value) {
|
|
54
|
-
return toHex(gweiDecToWEIBN(value));
|
|
55
|
-
}
|
|
56
|
-
function getMaxFeePerGas(request) {
|
|
57
|
-
const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;
|
|
58
|
-
if (!eip1559) {
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
if (savedGasFees) {
|
|
62
|
-
const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);
|
|
63
|
-
log("Using maxFeePerGas from savedGasFees", maxFeePerGas);
|
|
64
|
-
return maxFeePerGas;
|
|
65
|
-
}
|
|
66
|
-
if (initialParams.maxFeePerGas) {
|
|
67
|
-
log("Using maxFeePerGas from request", initialParams.maxFeePerGas);
|
|
68
|
-
return initialParams.maxFeePerGas;
|
|
69
|
-
}
|
|
70
|
-
if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {
|
|
71
|
-
log(
|
|
72
|
-
"Setting maxFeePerGas to gasPrice from request",
|
|
73
|
-
initialParams.gasPrice
|
|
74
|
-
);
|
|
75
|
-
return initialParams.gasPrice;
|
|
76
|
-
}
|
|
77
|
-
if (suggestedGasFees.maxFeePerGas) {
|
|
78
|
-
log("Using suggested maxFeePerGas", suggestedGasFees.maxFeePerGas);
|
|
79
|
-
return suggestedGasFees.maxFeePerGas;
|
|
80
|
-
}
|
|
81
|
-
if (suggestedGasFees.gasPrice) {
|
|
82
|
-
log(
|
|
83
|
-
"Setting maxFeePerGas to suggested gasPrice",
|
|
84
|
-
suggestedGasFees.gasPrice
|
|
85
|
-
);
|
|
86
|
-
return suggestedGasFees.gasPrice;
|
|
87
|
-
}
|
|
88
|
-
log("maxFeePerGas not set");
|
|
89
|
-
return void 0;
|
|
90
|
-
}
|
|
91
|
-
function getMaxPriorityFeePerGas(request) {
|
|
92
|
-
const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
|
|
93
|
-
if (!eip1559) {
|
|
94
|
-
return void 0;
|
|
95
|
-
}
|
|
96
|
-
if (savedGasFees) {
|
|
97
|
-
const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);
|
|
98
|
-
log(
|
|
99
|
-
"Using maxPriorityFeePerGas from savedGasFees.priorityFee",
|
|
100
|
-
maxPriorityFeePerGas
|
|
101
|
-
);
|
|
102
|
-
return maxPriorityFeePerGas;
|
|
103
|
-
}
|
|
104
|
-
if (initialParams.maxPriorityFeePerGas) {
|
|
105
|
-
log(
|
|
106
|
-
"Using maxPriorityFeePerGas from request",
|
|
107
|
-
initialParams.maxPriorityFeePerGas
|
|
108
|
-
);
|
|
109
|
-
return initialParams.maxPriorityFeePerGas;
|
|
110
|
-
}
|
|
111
|
-
if (initialParams.gasPrice && !initialParams.maxFeePerGas) {
|
|
112
|
-
log(
|
|
113
|
-
"Setting maxPriorityFeePerGas to gasPrice from request",
|
|
114
|
-
initialParams.gasPrice
|
|
115
|
-
);
|
|
116
|
-
return initialParams.gasPrice;
|
|
117
|
-
}
|
|
118
|
-
if (suggestedGasFees.maxPriorityFeePerGas) {
|
|
119
|
-
log(
|
|
120
|
-
"Using suggested maxPriorityFeePerGas",
|
|
121
|
-
suggestedGasFees.maxPriorityFeePerGas
|
|
122
|
-
);
|
|
123
|
-
return suggestedGasFees.maxPriorityFeePerGas;
|
|
124
|
-
}
|
|
125
|
-
if (txMeta.txParams.maxFeePerGas) {
|
|
126
|
-
log(
|
|
127
|
-
"Setting maxPriorityFeePerGas to maxFeePerGas",
|
|
128
|
-
txMeta.txParams.maxFeePerGas
|
|
129
|
-
);
|
|
130
|
-
return txMeta.txParams.maxFeePerGas;
|
|
131
|
-
}
|
|
132
|
-
log("maxPriorityFeePerGas not set");
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
function getGasPrice(request) {
|
|
136
|
-
const { eip1559, initialParams, suggestedGasFees } = request;
|
|
137
|
-
if (eip1559) {
|
|
138
|
-
return void 0;
|
|
139
|
-
}
|
|
140
|
-
if (initialParams.gasPrice) {
|
|
141
|
-
log("Using gasPrice from request", initialParams.gasPrice);
|
|
142
|
-
return initialParams.gasPrice;
|
|
143
|
-
}
|
|
144
|
-
if (suggestedGasFees.maxFeePerGas) {
|
|
145
|
-
log("Using suggested maxFeePerGas", suggestedGasFees.maxFeePerGas);
|
|
146
|
-
return suggestedGasFees.maxFeePerGas;
|
|
147
|
-
}
|
|
148
|
-
if (suggestedGasFees.gasPrice) {
|
|
149
|
-
log("Using suggested gasPrice", suggestedGasFees.gasPrice);
|
|
150
|
-
return suggestedGasFees.gasPrice;
|
|
151
|
-
}
|
|
152
|
-
log("gasPrice not set");
|
|
153
|
-
return void 0;
|
|
154
|
-
}
|
|
155
|
-
function getUserFeeLevel(request) {
|
|
156
|
-
const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
|
|
157
|
-
if (!eip1559) {
|
|
158
|
-
return void 0;
|
|
159
|
-
}
|
|
160
|
-
if (savedGasFees) {
|
|
161
|
-
return "custom" /* CUSTOM */;
|
|
162
|
-
}
|
|
163
|
-
if (!initialParams.maxFeePerGas && !initialParams.maxPriorityFeePerGas && initialParams.gasPrice) {
|
|
164
|
-
return txMeta.origin === ORIGIN_METAMASK ? "custom" /* CUSTOM */ : "dappSuggested" /* DAPP_SUGGESTED */;
|
|
165
|
-
}
|
|
166
|
-
if (!initialParams.maxFeePerGas && !initialParams.maxPriorityFeePerGas && suggestedGasFees.maxFeePerGas && suggestedGasFees.maxPriorityFeePerGas) {
|
|
167
|
-
return "medium" /* MEDIUM */;
|
|
168
|
-
}
|
|
169
|
-
if (txMeta.origin === ORIGIN_METAMASK) {
|
|
170
|
-
return "medium" /* MEDIUM */;
|
|
171
|
-
}
|
|
172
|
-
return "dappSuggested" /* DAPP_SUGGESTED */;
|
|
173
|
-
}
|
|
174
|
-
function updateDefaultGasEstimates(txMeta) {
|
|
175
|
-
if (!txMeta.defaultGasEstimates) {
|
|
176
|
-
txMeta.defaultGasEstimates = {};
|
|
177
|
-
}
|
|
178
|
-
txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;
|
|
179
|
-
txMeta.defaultGasEstimates.maxPriorityFeePerGas = txMeta.txParams.maxPriorityFeePerGas;
|
|
180
|
-
txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;
|
|
181
|
-
txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;
|
|
182
|
-
}
|
|
183
|
-
async function getSuggestedGasFees(request) {
|
|
184
|
-
const { eip1559, ethQuery, gasFeeFlows, getGasFeeEstimates, txMeta } = request;
|
|
185
|
-
const { networkClientId } = txMeta;
|
|
186
|
-
if (!eip1559 && txMeta.txParams.gasPrice || eip1559 && txMeta.txParams.maxFeePerGas && txMeta.txParams.maxPriorityFeePerGas) {
|
|
187
|
-
return {};
|
|
188
|
-
}
|
|
189
|
-
const gasFeeFlow = getGasFeeFlow(txMeta, gasFeeFlows);
|
|
190
|
-
try {
|
|
191
|
-
const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });
|
|
192
|
-
const response = await gasFeeFlow.getGasFees({
|
|
193
|
-
ethQuery,
|
|
194
|
-
gasFeeControllerData,
|
|
195
|
-
transactionMeta: txMeta
|
|
196
|
-
});
|
|
197
|
-
const gasFeeEstimateType = response.estimates?.type;
|
|
198
|
-
switch (gasFeeEstimateType) {
|
|
199
|
-
case "fee-market" /* FeeMarket */:
|
|
200
|
-
return response.estimates.medium;
|
|
201
|
-
case "legacy" /* Legacy */:
|
|
202
|
-
return {
|
|
203
|
-
gasPrice: response.estimates.medium
|
|
204
|
-
};
|
|
205
|
-
case "eth_gasPrice" /* GasPrice */:
|
|
206
|
-
return { gasPrice: response.estimates.gasPrice };
|
|
207
|
-
default:
|
|
208
|
-
throw new Error(
|
|
209
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
211
|
-
`Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
} catch (error) {
|
|
215
|
-
log("Failed to get suggested gas fees", error);
|
|
216
|
-
}
|
|
217
|
-
const gasPriceDecimal = await query(ethQuery, "gasPrice");
|
|
218
|
-
const gasPrice = gasPriceDecimal ? add0x(gasPriceDecimal.toString(16)) : void 0;
|
|
219
|
-
return { gasPrice };
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export {
|
|
223
|
-
updateGasFees,
|
|
224
|
-
gweiDecimalToWeiHex
|
|
225
|
-
};
|
|
226
|
-
//# sourceMappingURL=chunk-SFFOC25Q.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/gas-fees.ts"],"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"],"mappings":";;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAS,OAAO,0BAA0B;AAqC1C,IAAM,MAAM,mBAAmB,eAAe,UAAU;AAExD,eAAsB,cAAc,SAA+B;AACjE,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,gBAAgB,EAAE,GAAG,OAAO,SAAS;AAE3C,QAAM,SAAS,uBAAuB;AAAA,IACpC,OAAO;AAAA,EACT;AACA,QAAM,eAAe,SACjB,SACA,QAAQ,gBAAgB,OAAO,OAAO;AAE1C,QAAM,mBAAmB,MAAM,oBAAoB,OAAO;AAE1D,MAAI,sBAAsB,gBAAgB;AAE1C,QAAM,mBAAqC;AAAA,IACzC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,SAAS,eAAe,gBAAgB,gBAAgB;AAE/D,SAAO,SAAS,uBACd,wBAAwB,gBAAgB;AAE1C,SAAO,SAAS,WAAW,YAAY,gBAAgB;AACvD,SAAO,eAAe,gBAAgB,gBAAgB;AAEtD,MAAI,8BAA8B;AAAA,IAChC,cAAc,OAAO,SAAS;AAAA,IAC9B,sBAAsB,OAAO,SAAS;AAAA,IACtC,UAAU,OAAO,SAAS;AAAA,EAC5B,CAAC;AAED,MAAI,OAAO,SAAS,gBAAgB,OAAO,SAAS,sBAAsB;AACxE,WAAO,OAAO,SAAS;AAAA,EACzB;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,OAAO,SAAS;AACvB,WAAO,OAAO,SAAS;AAAA,EACzB;AAEA,4BAA0B,MAAM;AAClC;AAEO,SAAS,oBAAoB,OAAe;AACjD,SAAO,MAAM,eAAe,KAA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AAoB,WAAW,OAAO,SAAS;AACtD,SAAO,oBAAoB,eAAe,OAAO;AACnD;AAEA,eAAe,oBACb,SAC2B;AAC3B,QAAM,EAAE,SAAS,UAAU,aAAa,oBAAoB,OAAO,IACjE;AAEF,QAAM,EAAE,gBAAgB,IAAI;AAE5B,MACG,CAAC,WAAW,OAAO,SAAS,YAC5B,WACC,OAAO,SAAS,gBAChB,OAAO,SAAS,sBAClB;AACA,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,aAAa,cAAc,QAAQ,WAAW;AAEpD,MAAI;AACF,UAAM,uBAAuB,MAAM,mBAAmB,EAAE,gBAAgB,CAAC;AAEzE,UAAM,WAAW,MAAM,WAAW,WAAW;AAAA,MAC3C;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,IACnB,CAAC;AAED,UAAM,qBAAqB,SAAS,WAAW;AAE/C,YAAQ,oBAAoB;AAAA,MAC1B;AACE,eAAO,SAAS,UAAU;AAAA,MAC5B;AACE,eAAO;AAAA,UACL,UAAU,SAAS,UAAU;AAAA,QAC/B;AAAA,MACF;AACE,eAAO,EAAE,UAAU,SAAS,UAAU,SAAS;AAAA,MACjD;AACE,cAAM,IAAI;AAAA;AAAA;AAAA,UAGR,yDAAyD,kBAAkB;AAAA,QAC7E;AAAA,IACJ;AAAA,EACF,SAAS,OAAO;AACd,QAAI,oCAAoC,KAAK;AAAA,EAC/C;AAEA,QAAM,kBAAmB,MAAM,MAAM,UAAU,UAAU;AAEzD,QAAM,WAAW,kBACb,MAAM,gBAAgB,SAAS,EAAE,CAAC,IAClC;AAEJ,SAAO,EAAE,SAAS;AACpB;","names":[]}
|
package/dist/chunk-SMC5Q6ZH.mjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// src/utils/history.ts
|
|
2
|
-
import jsonDiffer from "fast-json-patch";
|
|
3
|
-
import { cloneDeep, merge } from "lodash";
|
|
4
|
-
var MAX_TRANSACTION_HISTORY_LENGTH = 100;
|
|
5
|
-
var DISPLAYED_TRANSACTION_HISTORY_PATHS = [
|
|
6
|
-
"/status",
|
|
7
|
-
"/txParams/gasPrice",
|
|
8
|
-
"/txParams/gas",
|
|
9
|
-
"/estimatedBaseFee",
|
|
10
|
-
"/blockTimestamp"
|
|
11
|
-
];
|
|
12
|
-
function addInitialHistorySnapshot(transactionMeta) {
|
|
13
|
-
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
14
|
-
return merge({}, transactionMeta, { history: [snapshot] });
|
|
15
|
-
}
|
|
16
|
-
function updateTransactionHistory(transactionMeta, note) {
|
|
17
|
-
if (!transactionMeta.history) {
|
|
18
|
-
return transactionMeta;
|
|
19
|
-
}
|
|
20
|
-
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
21
|
-
const previousState = replayHistory(transactionMeta.history);
|
|
22
|
-
const newHistoryEntry = generateHistoryEntry(
|
|
23
|
-
previousState,
|
|
24
|
-
currentState,
|
|
25
|
-
note
|
|
26
|
-
);
|
|
27
|
-
if (newHistoryEntry.length === 0) {
|
|
28
|
-
return transactionMeta;
|
|
29
|
-
}
|
|
30
|
-
let updatedHistory = [
|
|
31
|
-
...transactionMeta.history,
|
|
32
|
-
newHistoryEntry
|
|
33
|
-
];
|
|
34
|
-
if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {
|
|
35
|
-
updatedHistory = compressTransactionHistory(updatedHistory);
|
|
36
|
-
}
|
|
37
|
-
return merge({}, transactionMeta, {
|
|
38
|
-
history: updatedHistory
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function compressTransactionHistory(transactionHistory) {
|
|
42
|
-
const initialEntry = transactionHistory[0];
|
|
43
|
-
const historyEntries = transactionHistory.slice(
|
|
44
|
-
1
|
|
45
|
-
);
|
|
46
|
-
const firstNonDisplayedEntryIndex = historyEntries.findIndex(
|
|
47
|
-
(historyEntry) => {
|
|
48
|
-
return !historyEntry.some(
|
|
49
|
-
({ path }) => DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
if (firstNonDisplayedEntryIndex === -1) {
|
|
54
|
-
return transactionHistory;
|
|
55
|
-
}
|
|
56
|
-
const mergeTargetEntryIndex = (
|
|
57
|
-
// Merge with previous entry if there is no next entry.
|
|
58
|
-
// We default to merging with next because the next entry might also be non-displayed, so it
|
|
59
|
-
// might be removed in a future trim, saving more space.
|
|
60
|
-
firstNonDisplayedEntryIndex === historyEntries.length - 1 ? firstNonDisplayedEntryIndex - 1 : firstNonDisplayedEntryIndex + 1
|
|
61
|
-
);
|
|
62
|
-
const firstIndexToMerge = Math.min(
|
|
63
|
-
firstNonDisplayedEntryIndex,
|
|
64
|
-
mergeTargetEntryIndex
|
|
65
|
-
);
|
|
66
|
-
const firstEntryToMerge = historyEntries[firstIndexToMerge];
|
|
67
|
-
const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];
|
|
68
|
-
const beforeMergeState = replayHistory([
|
|
69
|
-
initialEntry,
|
|
70
|
-
...historyEntries.slice(0, firstIndexToMerge)
|
|
71
|
-
]);
|
|
72
|
-
const afterMergeState = replayHistory([
|
|
73
|
-
beforeMergeState,
|
|
74
|
-
firstEntryToMerge,
|
|
75
|
-
secondEntryToMerge
|
|
76
|
-
]);
|
|
77
|
-
const mergedHistoryEntry = generateHistoryEntry(
|
|
78
|
-
beforeMergeState,
|
|
79
|
-
afterMergeState,
|
|
80
|
-
`${String(firstEntryToMerge[0].note)}, ${String(
|
|
81
|
-
secondEntryToMerge[0].note
|
|
82
|
-
)}`
|
|
83
|
-
);
|
|
84
|
-
historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);
|
|
85
|
-
return [initialEntry, ...historyEntries];
|
|
86
|
-
}
|
|
87
|
-
function generateHistoryEntry(previousState, currentState, note) {
|
|
88
|
-
const historyOperationsEntry = jsonDiffer.compare(
|
|
89
|
-
previousState,
|
|
90
|
-
currentState
|
|
91
|
-
);
|
|
92
|
-
if (historyOperationsEntry[0]) {
|
|
93
|
-
if (note) {
|
|
94
|
-
historyOperationsEntry[0].note = note;
|
|
95
|
-
}
|
|
96
|
-
historyOperationsEntry[0].timestamp = Date.now();
|
|
97
|
-
}
|
|
98
|
-
return historyOperationsEntry;
|
|
99
|
-
}
|
|
100
|
-
function replayHistory(transactionHistory) {
|
|
101
|
-
const shortHistory = cloneDeep(transactionHistory);
|
|
102
|
-
return shortHistory.reduce(
|
|
103
|
-
// TODO: Replace `any` with type
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
-
(val, entry) => jsonDiffer.applyPatch(val, entry).newDocument
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
function snapshotFromTransactionMeta(transactionMeta) {
|
|
109
|
-
const snapshot = { ...transactionMeta };
|
|
110
|
-
delete snapshot.history;
|
|
111
|
-
return cloneDeep(snapshot);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export {
|
|
115
|
-
MAX_TRANSACTION_HISTORY_LENGTH,
|
|
116
|
-
DISPLAYED_TRANSACTION_HISTORY_PATHS,
|
|
117
|
-
addInitialHistorySnapshot,
|
|
118
|
-
updateTransactionHistory
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=chunk-SMC5Q6ZH.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/history.ts"],"sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep, merge } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from '../types';\n\n/**\n * The maximum allowed length of the `transaction.history` property.\n */\nexport const MAX_TRANSACTION_HISTORY_LENGTH = 100;\n\n/**\n * A list of trarnsaction history paths that may be used for display. These entries will not be\n * compressed.\n */\nexport const DISPLAYED_TRANSACTION_HISTORY_PATHS = [\n '/status',\n '/txParams/gasPrice',\n '/txParams/gas',\n '/estimatedBaseFee',\n '/blockTimestamp',\n];\n\n/**\n * Build a new version of the provided transaction with an initial history\n * entry, which is just a snapshot of the transaction.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n * @returns A copy of `transactionMeta` with a new `history` property.\n */\nexport function addInitialHistorySnapshot(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n return merge({}, transactionMeta, { history: [snapshot] });\n}\n\n/**\n * Builds a new version of the transaction with a new history entry if\n * it has a `history` property, or just returns the transaction.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n * @returns A copy of `transactionMeta` with a new `history` entry if it has an\n * existing non-empty `history` array.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): TransactionMeta {\n if (!transactionMeta.history) {\n return transactionMeta;\n }\n\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(transactionMeta.history);\n const newHistoryEntry = generateHistoryEntry(\n previousState,\n currentState,\n note,\n );\n\n if (newHistoryEntry.length === 0) {\n return transactionMeta;\n }\n\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n let updatedHistory = [\n ...transactionMeta.history,\n newHistoryEntry,\n ] as TransactionHistory;\n\n if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {\n updatedHistory = compressTransactionHistory(updatedHistory);\n }\n\n return merge({}, transactionMeta, {\n history: updatedHistory,\n });\n}\n\n/**\n * Compress the transaction history, if it is possible to do so without compressing entries used\n * for display. History entries are merged together to make room for a single new entry.\n *\n * @param transactionHistory - The transaction history to compress.\n * @returns A compressed transaction history.\n */\nfunction compressTransactionHistory(\n transactionHistory: TransactionHistory,\n): TransactionHistory {\n const initialEntry = transactionHistory[0];\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n const historyEntries = transactionHistory.slice(\n 1,\n ) as TransactionHistoryEntry[];\n\n const firstNonDisplayedEntryIndex = historyEntries.findIndex(\n (historyEntry) => {\n return !historyEntry.some(({ path }) =>\n DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path),\n );\n },\n );\n\n // If no non-displayed entry is found, let history exceed max size.\n // TODO: Move data used for display to another property, so that we can more reliably limit\n // history size or remove it altogether.\n if (firstNonDisplayedEntryIndex === -1) {\n return transactionHistory;\n }\n\n // If a non-displayed entry is found that we can remove, merge it with another entry.\n // The entry we're merging with might be a \"displayed\" entry, but that's OK, merging more changes\n // in does not break our display logic.\n const mergeTargetEntryIndex =\n // Merge with previous entry if there is no next entry.\n // We default to merging with next because the next entry might also be non-displayed, so it\n // might be removed in a future trim, saving more space.\n firstNonDisplayedEntryIndex === historyEntries.length - 1\n ? firstNonDisplayedEntryIndex - 1\n : firstNonDisplayedEntryIndex + 1;\n const firstIndexToMerge = Math.min(\n firstNonDisplayedEntryIndex,\n mergeTargetEntryIndex,\n );\n const firstEntryToMerge = historyEntries[firstIndexToMerge];\n const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];\n\n const beforeMergeState = replayHistory([\n initialEntry,\n ...historyEntries.slice(0, firstIndexToMerge),\n ]);\n const afterMergeState = replayHistory([\n beforeMergeState,\n firstEntryToMerge,\n secondEntryToMerge,\n ]);\n const mergedHistoryEntry = generateHistoryEntry(\n beforeMergeState,\n afterMergeState,\n `${String(firstEntryToMerge[0].note)}, ${String(\n secondEntryToMerge[0].note,\n )}`,\n );\n\n historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);\n return [initialEntry, ...historyEntries];\n}\n\n/**\n * Generates a history entry from the previous and new transaction metadata.\n *\n * @param previousState - The previous transaction metadata.\n * @param currentState - The new transaction metadata.\n * @param note - A note for the transaction metada update.\n * @returns An array of history operation.\n */\nfunction generateHistoryEntry(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n previousState: any,\n currentState: TransactionMeta,\n note: string,\n): TransactionHistoryEntry {\n const historyOperationsEntry = jsonDiffer.compare(\n previousState,\n currentState,\n ) as TransactionHistoryEntry;\n // Add a note to the first operation, since it breaks if we append it to the entry\n if (historyOperationsEntry[0]) {\n if (note) {\n historyOperationsEntry[0].note = note;\n }\n historyOperationsEntry[0].timestamp = Date.now();\n }\n return historyOperationsEntry;\n}\n\n/**\n * Recovers previous transactionMeta from passed history array.\n *\n * @param transactionHistory - The transaction metadata to replay.\n * @returns The transaction metadata.\n */\nfunction replayHistory(\n transactionHistory: TransactionHistory,\n): TransactionMeta {\n const shortHistory = cloneDeep(transactionHistory);\n return shortHistory.reduce(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (val, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n ) as TransactionMeta;\n}\n\n/**\n * Clone the transaction meta data without the history property.\n *\n * @param transactionMeta - The transaction metadata to snapshot.\n * @returns A deep clone of transaction metadata without history property.\n */\nfunction snapshotFromTransactionMeta(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = { ...transactionMeta };\n delete snapshot.history;\n return cloneDeep(snapshot);\n}\n"],"mappings":";AAAA,OAAO,gBAAgB;AACvB,SAAS,WAAW,aAAa;AAW1B,IAAM,iCAAiC;AAMvC,IAAM,sCAAsC;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASO,SAAS,0BACd,iBACiB;AACjB,QAAM,WAAW,4BAA4B,eAAe;AAC5D,SAAO,MAAM,CAAC,GAAG,iBAAiB,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC3D;AAWO,SAAS,yBACd,iBACA,MACiB;AACjB,MAAI,CAAC,gBAAgB,SAAS;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,4BAA4B,eAAe;AAChE,QAAM,gBAAgB,cAAc,gBAAgB,OAAO;AAC3D,QAAM,kBAAkB;AAAA,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AAe,OAAO,mBAAmB,GAAG,kBAAkB;AAC9D,SAAO,CAAC,cAAc,GAAG,cAAc;AACzC;AAUA,SAAS,qBAGP,eACA,cACA,MACyB;AACzB,QAAM,yBAAyB,WAAW;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,MAAI,uBAAuB,CAAC,GAAG;AAC7B,QAAI,MAAM;AACR,6BAAuB,CAAC,EAAE,OAAO;AAAA,IACnC;AACA,2BAAuB,CAAC,EAAE,YAAY,KAAK,IAAI;AAAA,EACjD;AACA,SAAO;AACT;AAQA,SAAS,cACP,oBACiB;AACjB,QAAM,eAAe,UAAU,kBAAkB;AACjD,SAAO,aAAa;AAAA;AAAA;AAAA,IAGlB,CAAC,KAAK,UAAe,WAAW,WAAW,KAAK,KAAK,EAAE;AAAA,EACzD;AACF;AAQA,SAAS,4BACP,iBACiB;AACjB,QAAM,WAAW,EAAE,GAAG,gBAAgB;AACtC,SAAO,SAAS;AAChB,SAAO,UAAU,QAAQ;AAC3B;","names":[]}
|
package/dist/chunk-TIE3CPF7.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/utils/history.ts
|
|
2
|
-
var _fastjsonpatch = require('fast-json-patch'); var _fastjsonpatch2 = _interopRequireDefault(_fastjsonpatch);
|
|
3
|
-
var _lodash = require('lodash');
|
|
4
|
-
var MAX_TRANSACTION_HISTORY_LENGTH = 100;
|
|
5
|
-
var DISPLAYED_TRANSACTION_HISTORY_PATHS = [
|
|
6
|
-
"/status",
|
|
7
|
-
"/txParams/gasPrice",
|
|
8
|
-
"/txParams/gas",
|
|
9
|
-
"/estimatedBaseFee",
|
|
10
|
-
"/blockTimestamp"
|
|
11
|
-
];
|
|
12
|
-
function addInitialHistorySnapshot(transactionMeta) {
|
|
13
|
-
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
14
|
-
return _lodash.merge.call(void 0, {}, transactionMeta, { history: [snapshot] });
|
|
15
|
-
}
|
|
16
|
-
function updateTransactionHistory(transactionMeta, note) {
|
|
17
|
-
if (!transactionMeta.history) {
|
|
18
|
-
return transactionMeta;
|
|
19
|
-
}
|
|
20
|
-
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
21
|
-
const previousState = replayHistory(transactionMeta.history);
|
|
22
|
-
const newHistoryEntry = generateHistoryEntry(
|
|
23
|
-
previousState,
|
|
24
|
-
currentState,
|
|
25
|
-
note
|
|
26
|
-
);
|
|
27
|
-
if (newHistoryEntry.length === 0) {
|
|
28
|
-
return transactionMeta;
|
|
29
|
-
}
|
|
30
|
-
let updatedHistory = [
|
|
31
|
-
...transactionMeta.history,
|
|
32
|
-
newHistoryEntry
|
|
33
|
-
];
|
|
34
|
-
if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {
|
|
35
|
-
updatedHistory = compressTransactionHistory(updatedHistory);
|
|
36
|
-
}
|
|
37
|
-
return _lodash.merge.call(void 0, {}, transactionMeta, {
|
|
38
|
-
history: updatedHistory
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function compressTransactionHistory(transactionHistory) {
|
|
42
|
-
const initialEntry = transactionHistory[0];
|
|
43
|
-
const historyEntries = transactionHistory.slice(
|
|
44
|
-
1
|
|
45
|
-
);
|
|
46
|
-
const firstNonDisplayedEntryIndex = historyEntries.findIndex(
|
|
47
|
-
(historyEntry) => {
|
|
48
|
-
return !historyEntry.some(
|
|
49
|
-
({ path }) => DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
if (firstNonDisplayedEntryIndex === -1) {
|
|
54
|
-
return transactionHistory;
|
|
55
|
-
}
|
|
56
|
-
const mergeTargetEntryIndex = (
|
|
57
|
-
// Merge with previous entry if there is no next entry.
|
|
58
|
-
// We default to merging with next because the next entry might also be non-displayed, so it
|
|
59
|
-
// might be removed in a future trim, saving more space.
|
|
60
|
-
firstNonDisplayedEntryIndex === historyEntries.length - 1 ? firstNonDisplayedEntryIndex - 1 : firstNonDisplayedEntryIndex + 1
|
|
61
|
-
);
|
|
62
|
-
const firstIndexToMerge = Math.min(
|
|
63
|
-
firstNonDisplayedEntryIndex,
|
|
64
|
-
mergeTargetEntryIndex
|
|
65
|
-
);
|
|
66
|
-
const firstEntryToMerge = historyEntries[firstIndexToMerge];
|
|
67
|
-
const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];
|
|
68
|
-
const beforeMergeState = replayHistory([
|
|
69
|
-
initialEntry,
|
|
70
|
-
...historyEntries.slice(0, firstIndexToMerge)
|
|
71
|
-
]);
|
|
72
|
-
const afterMergeState = replayHistory([
|
|
73
|
-
beforeMergeState,
|
|
74
|
-
firstEntryToMerge,
|
|
75
|
-
secondEntryToMerge
|
|
76
|
-
]);
|
|
77
|
-
const mergedHistoryEntry = generateHistoryEntry(
|
|
78
|
-
beforeMergeState,
|
|
79
|
-
afterMergeState,
|
|
80
|
-
`${String(firstEntryToMerge[0].note)}, ${String(
|
|
81
|
-
secondEntryToMerge[0].note
|
|
82
|
-
)}`
|
|
83
|
-
);
|
|
84
|
-
historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);
|
|
85
|
-
return [initialEntry, ...historyEntries];
|
|
86
|
-
}
|
|
87
|
-
function generateHistoryEntry(previousState, currentState, note) {
|
|
88
|
-
const historyOperationsEntry = _fastjsonpatch2.default.compare(
|
|
89
|
-
previousState,
|
|
90
|
-
currentState
|
|
91
|
-
);
|
|
92
|
-
if (historyOperationsEntry[0]) {
|
|
93
|
-
if (note) {
|
|
94
|
-
historyOperationsEntry[0].note = note;
|
|
95
|
-
}
|
|
96
|
-
historyOperationsEntry[0].timestamp = Date.now();
|
|
97
|
-
}
|
|
98
|
-
return historyOperationsEntry;
|
|
99
|
-
}
|
|
100
|
-
function replayHistory(transactionHistory) {
|
|
101
|
-
const shortHistory = _lodash.cloneDeep.call(void 0, transactionHistory);
|
|
102
|
-
return shortHistory.reduce(
|
|
103
|
-
// TODO: Replace `any` with type
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
-
(val, entry) => _fastjsonpatch2.default.applyPatch(val, entry).newDocument
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
function snapshotFromTransactionMeta(transactionMeta) {
|
|
109
|
-
const snapshot = { ...transactionMeta };
|
|
110
|
-
delete snapshot.history;
|
|
111
|
-
return _lodash.cloneDeep.call(void 0, snapshot);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
exports.MAX_TRANSACTION_HISTORY_LENGTH = MAX_TRANSACTION_HISTORY_LENGTH; exports.DISPLAYED_TRANSACTION_HISTORY_PATHS = DISPLAYED_TRANSACTION_HISTORY_PATHS; exports.addInitialHistorySnapshot = addInitialHistorySnapshot; exports.updateTransactionHistory = updateTransactionHistory;
|
|
120
|
-
//# sourceMappingURL=chunk-TIE3CPF7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/history.ts"],"names":[],"mappings":";AAAA,OAAO,gBAAgB;AACvB,SAAS,WAAW,aAAa;AAW1B,IAAM,iCAAiC;AAMvC,IAAM,sCAAsC;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASO,SAAS,0BACd,iBACiB;AACjB,QAAM,WAAW,4BAA4B,eAAe;AAC5D,SAAO,MAAM,CAAC,GAAG,iBAAiB,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC3D;AAWO,SAAS,yBACd,iBACA,MACiB;AACjB,MAAI,CAAC,gBAAgB,SAAS;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,4BAA4B,eAAe;AAChE,QAAM,gBAAgB,cAAc,gBAAgB,OAAO;AAC3D,QAAM,kBAAkB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AEA,iBAAe,OAAO,mBAAmB,GAAG,kBAAkB;AAC9D,SAAO,CAAC,cAAc,GAAG,cAAc;AACzC;AAUA,SAAS,qBAGP,eACA,cACA,MACyB;AACzB,QAAM,yBAAyB,WAAW;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,MAAI,uBAAuB,CAAC,GAAG;AAC7B,QAAI,MAAM;AACR,6BAAuB,CAAC,EAAE,OAAO;AAAA,IACnC;AACA,2BAAuB,CAAC,EAAE,YAAY,KAAK,IAAI;AAAA,EACjD;AACA,SAAO;AACT;AAQA,SAAS,cACP,oBACiB;AACjB,QAAM,eAAe,UAAU,kBAAkB;AACjD,SAAO,aAAa;AAAA;AAAA;AAAA,IAGlB,CAAC,KAAK,UAAe,WAAW,WAAW,KAAK,KAAK,EAAE;AAAA,EACzD;AACF;AAQA,SAAS,4BACP,iBACiB;AACjB,QAAM,WAAW,EAAE,GAAG,gBAAgB;AACtC,SAAO,SAAS;AAChB,SAAO,UAAU,QAAQ;AAC3B","sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep, merge } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from '../types';\n\n/**\n * The maximum allowed length of the `transaction.history` property.\n */\nexport const MAX_TRANSACTION_HISTORY_LENGTH = 100;\n\n/**\n * A list of trarnsaction history paths that may be used for display. These entries will not be\n * compressed.\n */\nexport const DISPLAYED_TRANSACTION_HISTORY_PATHS = [\n '/status',\n '/txParams/gasPrice',\n '/txParams/gas',\n '/estimatedBaseFee',\n '/blockTimestamp',\n];\n\n/**\n * Build a new version of the provided transaction with an initial history\n * entry, which is just a snapshot of the transaction.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n * @returns A copy of `transactionMeta` with a new `history` property.\n */\nexport function addInitialHistorySnapshot(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n return merge({}, transactionMeta, { history: [snapshot] });\n}\n\n/**\n * Builds a new version of the transaction with a new history entry if\n * it has a `history` property, or just returns the transaction.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n * @returns A copy of `transactionMeta` with a new `history` entry if it has an\n * existing non-empty `history` array.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): TransactionMeta {\n if (!transactionMeta.history) {\n return transactionMeta;\n }\n\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(transactionMeta.history);\n const newHistoryEntry = generateHistoryEntry(\n previousState,\n currentState,\n note,\n );\n\n if (newHistoryEntry.length === 0) {\n return transactionMeta;\n }\n\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n let updatedHistory = [\n ...transactionMeta.history,\n newHistoryEntry,\n ] as TransactionHistory;\n\n if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {\n updatedHistory = compressTransactionHistory(updatedHistory);\n }\n\n return merge({}, transactionMeta, {\n history: updatedHistory,\n });\n}\n\n/**\n * Compress the transaction history, if it is possible to do so without compressing entries used\n * for display. History entries are merged together to make room for a single new entry.\n *\n * @param transactionHistory - The transaction history to compress.\n * @returns A compressed transaction history.\n */\nfunction compressTransactionHistory(\n transactionHistory: TransactionHistory,\n): TransactionHistory {\n const initialEntry = transactionHistory[0];\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n const historyEntries = transactionHistory.slice(\n 1,\n ) as TransactionHistoryEntry[];\n\n const firstNonDisplayedEntryIndex = historyEntries.findIndex(\n (historyEntry) => {\n return !historyEntry.some(({ path }) =>\n DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path),\n );\n },\n );\n\n // If no non-displayed entry is found, let history exceed max size.\n // TODO: Move data used for display to another property, so that we can more reliably limit\n // history size or remove it altogether.\n if (firstNonDisplayedEntryIndex === -1) {\n return transactionHistory;\n }\n\n // If a non-displayed entry is found that we can remove, merge it with another entry.\n // The entry we're merging with might be a \"displayed\" entry, but that's OK, merging more changes\n // in does not break our display logic.\n const mergeTargetEntryIndex =\n // Merge with previous entry if there is no next entry.\n // We default to merging with next because the next entry might also be non-displayed, so it\n // might be removed in a future trim, saving more space.\n firstNonDisplayedEntryIndex === historyEntries.length - 1\n ? firstNonDisplayedEntryIndex - 1\n : firstNonDisplayedEntryIndex + 1;\n const firstIndexToMerge = Math.min(\n firstNonDisplayedEntryIndex,\n mergeTargetEntryIndex,\n );\n const firstEntryToMerge = historyEntries[firstIndexToMerge];\n const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];\n\n const beforeMergeState = replayHistory([\n initialEntry,\n ...historyEntries.slice(0, firstIndexToMerge),\n ]);\n const afterMergeState = replayHistory([\n beforeMergeState,\n firstEntryToMerge,\n secondEntryToMerge,\n ]);\n const mergedHistoryEntry = generateHistoryEntry(\n beforeMergeState,\n afterMergeState,\n `${String(firstEntryToMerge[0].note)}, ${String(\n secondEntryToMerge[0].note,\n )}`,\n );\n\n historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);\n return [initialEntry, ...historyEntries];\n}\n\n/**\n * Generates a history entry from the previous and new transaction metadata.\n *\n * @param previousState - The previous transaction metadata.\n * @param currentState - The new transaction metadata.\n * @param note - A note for the transaction metada update.\n * @returns An array of history operation.\n */\nfunction generateHistoryEntry(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n previousState: any,\n currentState: TransactionMeta,\n note: string,\n): TransactionHistoryEntry {\n const historyOperationsEntry = jsonDiffer.compare(\n previousState,\n currentState,\n ) as TransactionHistoryEntry;\n // Add a note to the first operation, since it breaks if we append it to the entry\n if (historyOperationsEntry[0]) {\n if (note) {\n historyOperationsEntry[0].note = note;\n }\n historyOperationsEntry[0].timestamp = Date.now();\n }\n return historyOperationsEntry;\n}\n\n/**\n * Recovers previous transactionMeta from passed history array.\n *\n * @param transactionHistory - The transaction metadata to replay.\n * @returns The transaction metadata.\n */\nfunction replayHistory(\n transactionHistory: TransactionHistory,\n): TransactionMeta {\n const shortHistory = cloneDeep(transactionHistory);\n return shortHistory.reduce(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (val, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n ) as TransactionMeta;\n}\n\n/**\n * Clone the transaction meta data without the history property.\n *\n * @param transactionMeta - The transaction metadata to snapshot.\n * @returns A deep clone of transaction metadata without history property.\n */\nfunction snapshotFromTransactionMeta(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = { ...transactionMeta };\n delete snapshot.history;\n return cloneDeep(snapshot);\n}\n"]}
|