@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-JIFPK37W.mjs
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
validateIfTransactionUnapproved
|
|
3
|
-
} from "./chunk-UHSRHP55.mjs";
|
|
4
|
-
import {
|
|
5
|
-
CHAIN_IDS
|
|
6
|
-
} from "./chunk-O6ZZVIFH.mjs";
|
|
7
|
-
import {
|
|
8
|
-
createModuleLogger,
|
|
9
|
-
projectLogger
|
|
10
|
-
} from "./chunk-UQQWZT6C.mjs";
|
|
11
|
-
|
|
12
|
-
// src/utils/swaps.ts
|
|
13
|
-
import { query } from "@metamask/controller-utils";
|
|
14
|
-
import { merge, pickBy } from "lodash";
|
|
15
|
-
var log = createModuleLogger(projectLogger, "swaps");
|
|
16
|
-
var UPDATE_POST_TX_BALANCE_TIMEOUT = 5e3;
|
|
17
|
-
var UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;
|
|
18
|
-
var SWAPS_TESTNET_CHAIN_ID = "0x539";
|
|
19
|
-
var DEFAULT_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
20
|
-
var ETH_SWAPS_TOKEN_OBJECT = {
|
|
21
|
-
name: "Ether",
|
|
22
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
23
|
-
decimals: 18
|
|
24
|
-
};
|
|
25
|
-
var BNB_SWAPS_TOKEN_OBJECT = {
|
|
26
|
-
name: "Binance Coin",
|
|
27
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
28
|
-
decimals: 18
|
|
29
|
-
};
|
|
30
|
-
var MATIC_SWAPS_TOKEN_OBJECT = {
|
|
31
|
-
name: "Matic",
|
|
32
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
33
|
-
decimals: 18
|
|
34
|
-
};
|
|
35
|
-
var AVAX_SWAPS_TOKEN_OBJECT = {
|
|
36
|
-
name: "Avalanche",
|
|
37
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
38
|
-
decimals: 18
|
|
39
|
-
};
|
|
40
|
-
var TEST_ETH_SWAPS_TOKEN_OBJECT = {
|
|
41
|
-
name: "Test Ether",
|
|
42
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
43
|
-
decimals: 18
|
|
44
|
-
};
|
|
45
|
-
var GOERLI_SWAPS_TOKEN_OBJECT = {
|
|
46
|
-
name: "Ether",
|
|
47
|
-
address: DEFAULT_TOKEN_ADDRESS,
|
|
48
|
-
decimals: 18
|
|
49
|
-
};
|
|
50
|
-
var ARBITRUM_SWAPS_TOKEN_OBJECT = {
|
|
51
|
-
...ETH_SWAPS_TOKEN_OBJECT
|
|
52
|
-
};
|
|
53
|
-
var OPTIMISM_SWAPS_TOKEN_OBJECT = {
|
|
54
|
-
...ETH_SWAPS_TOKEN_OBJECT
|
|
55
|
-
};
|
|
56
|
-
var ZKSYNC_ERA_SWAPS_TOKEN_OBJECT = {
|
|
57
|
-
...ETH_SWAPS_TOKEN_OBJECT
|
|
58
|
-
};
|
|
59
|
-
var SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
|
|
60
|
-
[CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,
|
|
61
|
-
[SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,
|
|
62
|
-
[CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,
|
|
63
|
-
[CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,
|
|
64
|
-
[CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,
|
|
65
|
-
[CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,
|
|
66
|
-
[CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,
|
|
67
|
-
[CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,
|
|
68
|
-
[CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT
|
|
69
|
-
};
|
|
70
|
-
var SWAP_TRANSACTION_TYPES = [
|
|
71
|
-
"swap" /* swap */,
|
|
72
|
-
"swapAndSend" /* swapAndSend */,
|
|
73
|
-
"swapApproval" /* swapApproval */
|
|
74
|
-
];
|
|
75
|
-
function updateSwapsTransaction(transactionMeta, transactionType, swaps, {
|
|
76
|
-
isSwapsDisabled,
|
|
77
|
-
cancelTransaction,
|
|
78
|
-
messenger
|
|
79
|
-
}) {
|
|
80
|
-
if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {
|
|
81
|
-
return transactionMeta;
|
|
82
|
-
}
|
|
83
|
-
if (transactionType === "swap" /* swap */ && swaps?.hasApproveTx === false && transactionMeta.simulationFails) {
|
|
84
|
-
cancelTransaction(transactionMeta.id);
|
|
85
|
-
throw new Error("Simulation failed");
|
|
86
|
-
}
|
|
87
|
-
const swapsMeta = swaps?.meta;
|
|
88
|
-
if (!swapsMeta) {
|
|
89
|
-
return transactionMeta;
|
|
90
|
-
}
|
|
91
|
-
let updatedTransactionMeta = transactionMeta;
|
|
92
|
-
if (transactionType === "swapApproval" /* swapApproval */) {
|
|
93
|
-
updatedTransactionMeta = updateSwapApprovalTransaction(
|
|
94
|
-
transactionMeta,
|
|
95
|
-
swapsMeta
|
|
96
|
-
);
|
|
97
|
-
messenger.publish("TransactionController:transactionNewSwapApproval", {
|
|
98
|
-
transactionMeta: updatedTransactionMeta
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (transactionType === "swapAndSend" /* swapAndSend */) {
|
|
102
|
-
updatedTransactionMeta = updateSwapAndSendTransaction(
|
|
103
|
-
transactionMeta,
|
|
104
|
-
swapsMeta
|
|
105
|
-
);
|
|
106
|
-
messenger.publish("TransactionController:transactionNewSwapAndSend", {
|
|
107
|
-
transactionMeta: updatedTransactionMeta
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (transactionType === "swap" /* swap */) {
|
|
111
|
-
updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);
|
|
112
|
-
messenger.publish("TransactionController:transactionNewSwap", {
|
|
113
|
-
transactionMeta: updatedTransactionMeta
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
return updatedTransactionMeta;
|
|
117
|
-
}
|
|
118
|
-
async function updatePostTransactionBalance(transactionMeta, {
|
|
119
|
-
ethQuery,
|
|
120
|
-
getTransaction,
|
|
121
|
-
updateTransaction
|
|
122
|
-
}) {
|
|
123
|
-
log("Updating post transaction balance", transactionMeta.id);
|
|
124
|
-
const transactionId = transactionMeta.id;
|
|
125
|
-
let latestTransactionMeta;
|
|
126
|
-
let approvalTransactionMeta;
|
|
127
|
-
for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {
|
|
128
|
-
log("Querying balance", { attempt: i });
|
|
129
|
-
const postTransactionBalance = await query(ethQuery, "getBalance", [
|
|
130
|
-
transactionMeta.txParams.from
|
|
131
|
-
]);
|
|
132
|
-
latestTransactionMeta = {
|
|
133
|
-
...getTransaction(transactionId) ?? {}
|
|
134
|
-
};
|
|
135
|
-
approvalTransactionMeta = latestTransactionMeta.approvalTxId ? getTransaction(latestTransactionMeta.approvalTxId) : void 0;
|
|
136
|
-
latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);
|
|
137
|
-
const isDefaultTokenAddress = isSwapsDefaultTokenAddress(
|
|
138
|
-
transactionMeta.destinationTokenAddress,
|
|
139
|
-
transactionMeta.chainId
|
|
140
|
-
);
|
|
141
|
-
if (!isDefaultTokenAddress || transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance) {
|
|
142
|
-
log("Finishing post balance update", {
|
|
143
|
-
isDefaultTokenAddress,
|
|
144
|
-
preTxBalance: transactionMeta.preTxBalance,
|
|
145
|
-
postTxBalance: latestTransactionMeta.postTxBalance
|
|
146
|
-
});
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
log("Waiting for balance to update", {
|
|
150
|
-
delay: UPDATE_POST_TX_BALANCE_TIMEOUT
|
|
151
|
-
});
|
|
152
|
-
await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);
|
|
153
|
-
}
|
|
154
|
-
updateTransaction(
|
|
155
|
-
latestTransactionMeta,
|
|
156
|
-
"TransactionController#updatePostTransactionBalance - Add post transaction balance"
|
|
157
|
-
);
|
|
158
|
-
log("Completed post balance update", latestTransactionMeta?.postTxBalance);
|
|
159
|
-
return {
|
|
160
|
-
updatedTransactionMeta: latestTransactionMeta,
|
|
161
|
-
approvalTransactionMeta
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function updateSwapTransaction(transactionMeta, {
|
|
165
|
-
sourceTokenSymbol,
|
|
166
|
-
destinationTokenSymbol,
|
|
167
|
-
type,
|
|
168
|
-
destinationTokenDecimals,
|
|
169
|
-
destinationTokenAddress,
|
|
170
|
-
swapMetaData,
|
|
171
|
-
swapTokenValue,
|
|
172
|
-
estimatedBaseFee,
|
|
173
|
-
approvalTxId
|
|
174
|
-
}) {
|
|
175
|
-
validateIfTransactionUnapproved(transactionMeta, "updateSwapTransaction");
|
|
176
|
-
let swapTransaction = {
|
|
177
|
-
sourceTokenSymbol,
|
|
178
|
-
destinationTokenSymbol,
|
|
179
|
-
type,
|
|
180
|
-
destinationTokenDecimals,
|
|
181
|
-
destinationTokenAddress,
|
|
182
|
-
swapMetaData,
|
|
183
|
-
swapTokenValue,
|
|
184
|
-
estimatedBaseFee,
|
|
185
|
-
approvalTxId
|
|
186
|
-
};
|
|
187
|
-
swapTransaction = pickBy(swapTransaction);
|
|
188
|
-
return merge({}, transactionMeta, swapTransaction);
|
|
189
|
-
}
|
|
190
|
-
function updateSwapAndSendTransaction(transactionMeta, {
|
|
191
|
-
approvalTxId,
|
|
192
|
-
destinationTokenAddress,
|
|
193
|
-
destinationTokenAmount,
|
|
194
|
-
destinationTokenDecimals,
|
|
195
|
-
destinationTokenSymbol,
|
|
196
|
-
estimatedBaseFee,
|
|
197
|
-
sourceTokenAddress,
|
|
198
|
-
sourceTokenAmount,
|
|
199
|
-
sourceTokenDecimals,
|
|
200
|
-
sourceTokenSymbol,
|
|
201
|
-
swapAndSendRecipient,
|
|
202
|
-
swapMetaData,
|
|
203
|
-
swapTokenValue,
|
|
204
|
-
type
|
|
205
|
-
}) {
|
|
206
|
-
validateIfTransactionUnapproved(transactionMeta, "updateSwapTransaction");
|
|
207
|
-
let swapTransaction = {
|
|
208
|
-
approvalTxId,
|
|
209
|
-
destinationTokenAddress,
|
|
210
|
-
destinationTokenAmount,
|
|
211
|
-
destinationTokenDecimals,
|
|
212
|
-
destinationTokenSymbol,
|
|
213
|
-
estimatedBaseFee,
|
|
214
|
-
sourceTokenAddress,
|
|
215
|
-
sourceTokenAmount,
|
|
216
|
-
sourceTokenDecimals,
|
|
217
|
-
sourceTokenSymbol,
|
|
218
|
-
swapAndSendRecipient,
|
|
219
|
-
swapMetaData,
|
|
220
|
-
swapTokenValue,
|
|
221
|
-
type
|
|
222
|
-
};
|
|
223
|
-
swapTransaction = pickBy(swapTransaction);
|
|
224
|
-
return merge({}, transactionMeta, swapTransaction);
|
|
225
|
-
}
|
|
226
|
-
function updateSwapApprovalTransaction(transactionMeta, { type, sourceTokenSymbol }) {
|
|
227
|
-
validateIfTransactionUnapproved(
|
|
228
|
-
transactionMeta,
|
|
229
|
-
"updateSwapApprovalTransaction"
|
|
230
|
-
);
|
|
231
|
-
let swapApprovalTransaction = { type, sourceTokenSymbol };
|
|
232
|
-
swapApprovalTransaction = pickBy({
|
|
233
|
-
type,
|
|
234
|
-
sourceTokenSymbol
|
|
235
|
-
});
|
|
236
|
-
return merge({}, transactionMeta, swapApprovalTransaction);
|
|
237
|
-
}
|
|
238
|
-
function isSwapsDefaultTokenAddress(address, chainId) {
|
|
239
|
-
if (!address || !chainId) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
return address === SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId]?.address;
|
|
243
|
-
}
|
|
244
|
-
function sleep(ms) {
|
|
245
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export {
|
|
249
|
-
UPDATE_POST_TX_BALANCE_TIMEOUT,
|
|
250
|
-
UPDATE_POST_TX_BALANCE_ATTEMPTS,
|
|
251
|
-
DEFAULT_TOKEN_ADDRESS,
|
|
252
|
-
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
|
|
253
|
-
SWAP_TRANSACTION_TYPES,
|
|
254
|
-
updateSwapsTransaction,
|
|
255
|
-
updatePostTransactionBalance
|
|
256
|
-
};
|
|
257
|
-
//# sourceMappingURL=chunk-JIFPK37W.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/swaps.ts"],"sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { merge, pickBy } from 'lodash';\n\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { TransactionType } from '../types';\nimport { validateIfTransactionUnapproved } from './utils';\n\nconst log = createModuleLogger(projectLogger, 'swaps');\n\n/**\n * Interval in milliseconds between checks of post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;\n\n/**\n * Retry attempts for checking post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;\n\nconst SWAPS_TESTNET_CHAIN_ID = '0x539';\n\n/**\n * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have\n */\nexport const DEFAULT_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000';\n\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface SwapsTokenObject {\n /**\n * The name for the network\n */\n name: string;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n}\n\nconst ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n};\n\nconst BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Binance Coin',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Matic',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst AVAX_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Avalanche',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst TEST_ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Test Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst GOERLI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst ARBITRUM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst OPTIMISM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst ZKSYNC_ERA_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {\n [CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,\n [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAP_TRANSACTION_TYPES = [\n TransactionType.swap,\n TransactionType.swapAndSend,\n TransactionType.swapApproval,\n];\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - The transaction meta object to update\n * @param transactionType - The type of the transaction\n * @param swaps - The swaps object\n * @param swaps.hasApproveTx - Whether the swap has an approval transaction\n * @param swaps.meta - The swap meta object\n * @param updateSwapsTransactionRequest - Dependency bag\n * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled\n * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction\n * @param updateSwapsTransactionRequest.messenger - TransactionController messenger\n * @returns A copy of the transaction meta object with updates, or the same\n * transaction meta object if no updates were made.\n */\nexport function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n messenger,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n messenger: TransactionControllerMessenger;\n },\n): TransactionMeta {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return transactionMeta;\n }\n\n // The simulationFails property is added if the estimateGas call fails. In cases\n // when no swaps approval tx is required, this indicates that the swap will likely\n // fail. There was an earlier estimateGas call made by the swaps controller,\n // but it is possible that external conditions have change since then, and\n // a previously succeeding estimate gas call could now fail. By checking for\n // the `simulationFails` property here, we can reduce the number of swap\n // transactions that get published to the blockchain only to fail and thereby\n // waste the user's funds on gas.\n if (\n transactionType === TransactionType.swap &&\n swaps?.hasApproveTx === false &&\n transactionMeta.simulationFails\n ) {\n cancelTransaction(transactionMeta.id);\n throw new Error('Simulation failed');\n }\n\n const swapsMeta = swaps?.meta as Partial<TransactionMeta>;\n\n if (!swapsMeta) {\n return transactionMeta;\n }\n\n let updatedTransactionMeta = transactionMeta;\n\n if (transactionType === TransactionType.swapApproval) {\n updatedTransactionMeta = updateSwapApprovalTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapApproval', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swapAndSend) {\n updatedTransactionMeta = updateSwapAndSendTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapAndSend', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);\n messenger.publish('TransactionController:transactionNewSwap', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n return updatedTransactionMeta;\n}\n\n/**\n * Attempts to update the post transaction balance of the provided transaction\n *\n * @param transactionMeta - Transaction meta object to update\n * @param updatePostTransactionBalanceRequest - Dependency bag\n * @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object\n * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state\n * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function\n */\nexport async function updatePostTransactionBalance(\n transactionMeta: TransactionMeta,\n {\n ethQuery,\n getTransaction,\n updateTransaction,\n }: {\n ethQuery: EthQuery;\n getTransaction: (transactionId: string) => TransactionMeta | undefined;\n updateTransaction: (transactionMeta: TransactionMeta, note: string) => void;\n },\n): Promise<{\n updatedTransactionMeta: TransactionMeta;\n approvalTransactionMeta?: TransactionMeta;\n}> {\n log('Updating post transaction balance', transactionMeta.id);\n\n const transactionId = transactionMeta.id;\n let latestTransactionMeta: TransactionMeta | undefined;\n let approvalTransactionMeta;\n\n for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {\n log('Querying balance', { attempt: i });\n\n const postTransactionBalance = await query(ethQuery, 'getBalance', [\n transactionMeta.txParams.from,\n ]);\n\n latestTransactionMeta = {\n ...(getTransaction(transactionId) ?? ({} as TransactionMeta)),\n };\n\n approvalTransactionMeta = latestTransactionMeta.approvalTxId\n ? getTransaction(latestTransactionMeta.approvalTxId)\n : undefined;\n\n latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);\n\n const isDefaultTokenAddress = isSwapsDefaultTokenAddress(\n transactionMeta.destinationTokenAddress as string,\n transactionMeta.chainId,\n );\n\n if (\n !isDefaultTokenAddress ||\n transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance\n ) {\n log('Finishing post balance update', {\n isDefaultTokenAddress,\n preTxBalance: transactionMeta.preTxBalance,\n postTxBalance: latestTransactionMeta.postTxBalance,\n });\n\n break;\n }\n\n log('Waiting for balance to update', {\n delay: UPDATE_POST_TX_BALANCE_TIMEOUT,\n });\n\n await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);\n }\n\n updateTransaction(\n latestTransactionMeta as TransactionMeta,\n 'TransactionController#updatePostTransactionBalance - Add post transaction balance',\n );\n\n log('Completed post balance update', latestTransactionMeta?.postTxBalance);\n\n return {\n updatedTransactionMeta: latestTransactionMeta as TransactionMeta,\n approvalTransactionMeta,\n };\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapTransaction(\n transactionMeta: TransactionMeta,\n {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.destinationTokenAmount - The raw amount of the destination token\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.sourceTokenAddress - The address of the source token\n * @param propsToUpdate.sourceTokenAmount - The raw amount of the source token\n * @param propsToUpdate.sourceTokenDecimals - The decimals of the source token\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.swapAndSendRecipient - The recipient of the swap and send transaction\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped – possibly the same as sourceTokenAmount; included for consistency\n * @param propsToUpdate.type - Type of the transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapAndSendTransaction(\n transactionMeta: TransactionMeta,\n {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap approval information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @returns The updated transaction meta object.\n */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(\n transactionMeta,\n 'updateSwapApprovalTransaction',\n );\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let swapApprovalTransaction = { type, sourceTokenSymbol } as any;\n swapApprovalTransaction = pickBy({\n type,\n sourceTokenSymbol,\n }) as Partial<TransactionMeta>;\n\n return merge({}, transactionMeta, swapApprovalTransaction);\n}\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nfunction isSwapsDefaultTokenAddress(address: string, chainId: string) {\n if (!address || !chainId) {\n return false;\n }\n\n return (\n address ===\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ]?.address\n );\n}\n\n/**\n * Sleeps for the provided number of milliseconds\n *\n * @param ms - Number of milliseconds to sleep\n * @returns Promise that resolves after the provided number of milliseconds\n */\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":"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","names":[]}
|
package/dist/chunk-JOQK7A5G.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// src/utils/retry.ts
|
|
2
|
-
import { convertHexToDecimal } from "@metamask/controller-utils";
|
|
3
|
-
import { add0x } from "@metamask/utils";
|
|
4
|
-
function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate, newGasValues) {
|
|
5
|
-
const newGasPrice = getIncreasedGasPrice(
|
|
6
|
-
originalTransactionParams,
|
|
7
|
-
rate,
|
|
8
|
-
newGasValues
|
|
9
|
-
);
|
|
10
|
-
const new1559Values = getIncreased1559Values(
|
|
11
|
-
originalTransactionParams,
|
|
12
|
-
rate,
|
|
13
|
-
newGasValues
|
|
14
|
-
);
|
|
15
|
-
if (new1559Values) {
|
|
16
|
-
const newTxParams = {
|
|
17
|
-
...originalTransactionParams,
|
|
18
|
-
...new1559Values
|
|
19
|
-
};
|
|
20
|
-
delete newTxParams.gasPrice;
|
|
21
|
-
return newTxParams;
|
|
22
|
-
}
|
|
23
|
-
if (newGasPrice) {
|
|
24
|
-
const newTxParams = {
|
|
25
|
-
...originalTransactionParams,
|
|
26
|
-
gasPrice: newGasPrice
|
|
27
|
-
};
|
|
28
|
-
delete newTxParams.maxFeePerGas;
|
|
29
|
-
delete newTxParams.maxPriorityFeePerGas;
|
|
30
|
-
return newTxParams;
|
|
31
|
-
}
|
|
32
|
-
throw new Error(
|
|
33
|
-
"Cannot increase gas fee as no current values and no new values were provided"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
|
|
37
|
-
if (newGasValues && "maxFeePerGas" in newGasValues && "maxPriorityFeePerGas" in newGasValues) {
|
|
38
|
-
return newGasValues;
|
|
39
|
-
}
|
|
40
|
-
const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas;
|
|
41
|
-
const currentMaxPriorityFeePerGas = originalTransactionParams.maxPriorityFeePerGas;
|
|
42
|
-
if (!currentMaxFeePerGas || !currentMaxPriorityFeePerGas || currentMaxFeePerGas === "0x0" || currentMaxPriorityFeePerGas === "0x0") {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);
|
|
46
|
-
const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);
|
|
47
|
-
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
48
|
-
}
|
|
49
|
-
function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
|
|
50
|
-
if (newGasValues && "gasPrice" in newGasValues) {
|
|
51
|
-
return newGasValues.gasPrice;
|
|
52
|
-
}
|
|
53
|
-
const currentGasPrice = originalTransactionParams.gasPrice;
|
|
54
|
-
if (!currentGasPrice || currentGasPrice === "0x0") {
|
|
55
|
-
return void 0;
|
|
56
|
-
}
|
|
57
|
-
return multiplyHex(currentGasPrice, rate);
|
|
58
|
-
}
|
|
59
|
-
function multiplyHex(value, multiplier) {
|
|
60
|
-
const decimalValue = convertHexToDecimal(value);
|
|
61
|
-
const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);
|
|
62
|
-
return add0x(decimalResult.toString(16));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export {
|
|
66
|
-
getTransactionParamsWithIncreasedGasFee
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=chunk-JOQK7A5G.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/retry.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AAEpC,SAAS,aAAa;AAYf,SAAS,wCACd,2BACA,MACA,cACmB;AACnB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAEA,WAAO,YAAY;AACnB,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AASA,SAAS,uBACP,2BACA,MACA,cACoC;AACpC,MACE,gBACA,kBAAkB,gBAClB,0BAA0B,cAC1B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,sBAAsB,0BAA0B;AAItD,QAAM,8BACJ,0BAA0B;AAE5B,MACE,CAAC,uBACD,CAAC,+BACD,wBAAwB,SACxB,gCAAgC,OAChC;AACA,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,YAAY,qBAAqB,IAAI;AAC1D,QAAM,uBAAuB,YAAY,6BAA6B,IAAI;AAE1E,SAAO,EAAE,cAAc,qBAAqB;AAC9C;AASA,SAAS,qBACP,2BACA,MACA,cACiB;AACjB,MAAI,gBAAgB,cAAc,cAAc;AAC9C,WAAO,aAAa;AAAA,EACtB;AAEA,QAAM,kBAAkB,0BAA0B;AAElD,MAAI,CAAC,mBAAmB,oBAAoB,OAAO;AACjD,WAAO;AAAA,EACT;AAEA,SAAO,YAAY,iBAAiB,IAAI;AAC1C;AAQA,SAAS,YAAY,OAAwB,YAAyB;AACpE,QAAM,eAAe,oBAAoB,KAAK;AAC9C,QAAM,gBAAgB,SAAS,GAAG,eAAe,UAAU,IAAI,EAAE;AAEjE,SAAO,MAAM,cAAc,SAAS,EAAE,CAAC;AACzC;","names":[]}
|
package/dist/chunk-K4KOSAGM.mjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SimulationChainNotSupportedError,
|
|
3
|
-
SimulationError
|
|
4
|
-
} from "./chunk-HQSNKCXI.mjs";
|
|
5
|
-
import {
|
|
6
|
-
projectLogger
|
|
7
|
-
} from "./chunk-UQQWZT6C.mjs";
|
|
8
|
-
|
|
9
|
-
// src/utils/simulation-api.ts
|
|
10
|
-
import { convertHexToDecimal } from "@metamask/controller-utils";
|
|
11
|
-
import { createModuleLogger } from "@metamask/utils";
|
|
12
|
-
var log = createModuleLogger(projectLogger, "simulation-api");
|
|
13
|
-
var RPC_METHOD = "infura_simulateTransactions";
|
|
14
|
-
var BASE_URL = "https://tx-sentinel-{0}.api.cx.metamask.io/";
|
|
15
|
-
var ENDPOINT_NETWORKS = "networks";
|
|
16
|
-
var requestIdCounter = 0;
|
|
17
|
-
async function simulateTransactions(chainId, request) {
|
|
18
|
-
const url = await getSimulationUrl(chainId);
|
|
19
|
-
log("Sending request", url, request);
|
|
20
|
-
const requestId = requestIdCounter;
|
|
21
|
-
requestIdCounter += 1;
|
|
22
|
-
const response = await fetch(url, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
body: JSON.stringify({
|
|
25
|
-
id: String(requestId),
|
|
26
|
-
jsonrpc: "2.0",
|
|
27
|
-
method: RPC_METHOD,
|
|
28
|
-
params: [request]
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
const responseJson = await response.json();
|
|
32
|
-
log("Received response", responseJson);
|
|
33
|
-
if (responseJson.error) {
|
|
34
|
-
const { code, message } = responseJson.error;
|
|
35
|
-
throw new SimulationError(message, code);
|
|
36
|
-
}
|
|
37
|
-
return responseJson?.result;
|
|
38
|
-
}
|
|
39
|
-
async function getSimulationUrl(chainId) {
|
|
40
|
-
const networkData = await getNetworkData();
|
|
41
|
-
const chainIdDecimal = convertHexToDecimal(chainId);
|
|
42
|
-
const network = networkData[chainIdDecimal];
|
|
43
|
-
if (!network?.confirmations) {
|
|
44
|
-
log("Chain is not supported", chainId);
|
|
45
|
-
throw new SimulationChainNotSupportedError(chainId);
|
|
46
|
-
}
|
|
47
|
-
return getUrl(network.network);
|
|
48
|
-
}
|
|
49
|
-
async function getNetworkData() {
|
|
50
|
-
const url = `${getUrl("ethereum-mainnet")}${ENDPOINT_NETWORKS}`;
|
|
51
|
-
const response = await fetch(url);
|
|
52
|
-
return response.json();
|
|
53
|
-
}
|
|
54
|
-
function getUrl(subdomain) {
|
|
55
|
-
return BASE_URL.replace("{0}", subdomain);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
simulateTransactions
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=chunk-K4KOSAGM.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/simulation-api.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,oBAAoB;AA4I1B,IAAI,mBAAmB;AAOvB,eAAsB,qBACpB,SACA,SAC6B;AAC7B,QAAM,MAAM,MAAM,iBAAiB,OAAO;AAE1C,MAAI,mBAAmB,KAAK,OAAO;AAEnC,QAAM,YAAY;AAClB,sBAAoB;AAEpB,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,IAAI,OAAO,SAAS;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ,CAAC,OAAO;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,eAAe,MAAM,SAAS,KAAK;AAEzC,MAAI,qBAAqB,YAAY;AAErC,MAAI,aAAa,OAAO;AACtB,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,UAAM,IAAI,gBAAgB,SAAS,IAAI;AAAA,EACzC;AAEA,SAAO,cAAc;AACvB;AAOA,eAAe,iBAAiB,SAA+B;AAC7D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,UAAU,YAAY,cAAc;AAE1C,MAAI,CAAC,SAAS,eAAe;AAC3B,QAAI,0BAA0B,OAAO;AACrC,UAAM,IAAI,iCAAiC,OAAO;AAAA,EACpD;AAEA,SAAO,OAAO,QAAQ,OAAO;AAC/B;AAKA,eAAe,iBAAqD;AAClE,QAAM,MAAM,GAAG,OAAO,kBAAkB,CAAC,GAAG,iBAAiB;AAC7D,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,SAAO,SAAS,KAAK;AACvB;AAOA,SAAS,OAAO,WAA2B;AACzC,SAAO,SAAS,QAAQ,OAAO,SAAS;AAC1C;","names":[]}
|
package/dist/chunk-KG4UW4K4.mjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// src/utils/transaction-type.ts
|
|
2
|
-
import { Interface } from "@ethersproject/abi";
|
|
3
|
-
import { query } from "@metamask/controller-utils";
|
|
4
|
-
import {
|
|
5
|
-
abiERC721,
|
|
6
|
-
abiERC20,
|
|
7
|
-
abiERC1155,
|
|
8
|
-
abiFiatTokenV2
|
|
9
|
-
} from "@metamask/metamask-eth-abis";
|
|
10
|
-
var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
11
|
-
var ERC20Interface = new Interface(abiERC20);
|
|
12
|
-
var ERC721Interface = new Interface(abiERC721);
|
|
13
|
-
var ERC1155Interface = new Interface(abiERC1155);
|
|
14
|
-
var USDCInterface = new Interface(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 query(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
|
-
export {
|
|
85
|
-
ESTIMATE_GAS_ERROR,
|
|
86
|
-
determineTransactionType
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=chunk-KG4UW4K4.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/transaction-type.ts"],"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"],"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,IAAI;AACf,WAAO,EAAE,iDAAsC,iBAAiB,OAAU;AAAA,EAC5E;AAEA,QAAM,EAAE,cAAc,iBAAiB,kBAAkB,IACvD,MAAM,sBAAsB,UAAU,EAAE;AAE1C,MAAI,CAAC,mBAAmB;AACtB,WAAO,EAAE,qCAAkC,gBAAgB;AAAA,EAC7D;AAEA,QAAM,WAAW,OAAO,SAAS,SAAS,GAAG,MAAM;AAEnD,QAAM,4BAA4B;AAAA,IAChC;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,UAAU;AACrB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,kCAAkC,IAAI,GAAG;AAEtD,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,EAAE;AAAA,IACA,CAAC,eAAe,WAAW,YAAY,MAAO,KAAgB,YAAY;AAAA,EAC5E;AAEA,MAAI,iBAAiB;AACnB,WAAO,EAAE,MAAM,iBAAiB,gBAAgB;AAAA,EAClD;AAEA,SAAO;AACT;AAUA,SAAS,kCACP,MACoC;AACpC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,eAAe,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACjD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,gBAAgB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EAClD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,iBAAiB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACnD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,cAAc,iBAAiB,EAAE,KAAK,CAAC;AAAA,EAChD,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AASA,eAAe,sBACb,UACA,SAIC;AACD,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,MAAM,UAAU,WAAW,CAAC,OAAO,CAAC;AAAA,EAC3D,SAAS,GAAG;AACV,mBAAe;AAAA,EACjB;AAEA,QAAM,oBAAoB,eACtB,iBAAiB,QAAQ,iBAAiB,QAC1C;AACJ,SAAO,EAAE,cAAc,kBAAkB;AAC3C;","names":[]}
|
package/dist/chunk-KT6UAKBB.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkHMOSP33Fjs = require('./chunk-HMOSP33F.js');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
|
|
8
|
-
|
|
9
|
-
// src/utils/simulation-api.ts
|
|
10
|
-
var _controllerutils = require('@metamask/controller-utils');
|
|
11
|
-
var _utils = require('@metamask/utils');
|
|
12
|
-
var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger, "simulation-api");
|
|
13
|
-
var RPC_METHOD = "infura_simulateTransactions";
|
|
14
|
-
var BASE_URL = "https://tx-sentinel-{0}.api.cx.metamask.io/";
|
|
15
|
-
var ENDPOINT_NETWORKS = "networks";
|
|
16
|
-
var requestIdCounter = 0;
|
|
17
|
-
async function simulateTransactions(chainId, request) {
|
|
18
|
-
const url = await getSimulationUrl(chainId);
|
|
19
|
-
log("Sending request", url, request);
|
|
20
|
-
const requestId = requestIdCounter;
|
|
21
|
-
requestIdCounter += 1;
|
|
22
|
-
const response = await fetch(url, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
body: JSON.stringify({
|
|
25
|
-
id: String(requestId),
|
|
26
|
-
jsonrpc: "2.0",
|
|
27
|
-
method: RPC_METHOD,
|
|
28
|
-
params: [request]
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
const responseJson = await response.json();
|
|
32
|
-
log("Received response", responseJson);
|
|
33
|
-
if (responseJson.error) {
|
|
34
|
-
const { code, message } = responseJson.error;
|
|
35
|
-
throw new (0, _chunkHMOSP33Fjs.SimulationError)(message, code);
|
|
36
|
-
}
|
|
37
|
-
return responseJson?.result;
|
|
38
|
-
}
|
|
39
|
-
async function getSimulationUrl(chainId) {
|
|
40
|
-
const networkData = await getNetworkData();
|
|
41
|
-
const chainIdDecimal = _controllerutils.convertHexToDecimal.call(void 0, chainId);
|
|
42
|
-
const network = networkData[chainIdDecimal];
|
|
43
|
-
if (!network?.confirmations) {
|
|
44
|
-
log("Chain is not supported", chainId);
|
|
45
|
-
throw new (0, _chunkHMOSP33Fjs.SimulationChainNotSupportedError)(chainId);
|
|
46
|
-
}
|
|
47
|
-
return getUrl(network.network);
|
|
48
|
-
}
|
|
49
|
-
async function getNetworkData() {
|
|
50
|
-
const url = `${getUrl("ethereum-mainnet")}${ENDPOINT_NETWORKS}`;
|
|
51
|
-
const response = await fetch(url);
|
|
52
|
-
return response.json();
|
|
53
|
-
}
|
|
54
|
-
function getUrl(subdomain) {
|
|
55
|
-
return BASE_URL.replace("{0}", subdomain);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
exports.simulateTransactions = simulateTransactions;
|
|
61
|
-
//# sourceMappingURL=chunk-KT6UAKBB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/simulation-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,oBAAoB;AA4I1B,IAAI,mBAAmB;AAOvB,eAAsB,qBACpB,SACA,SAC6B;AAC7B,QAAM,MAAM,MAAM,iBAAiB,OAAO;AAE1C,MAAI,mBAAmB,KAAK,OAAO;AAEnC,QAAM,YAAY;AAClB,sBAAoB;AAEpB,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,IAAI,OAAO,SAAS;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ,CAAC,OAAO;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,eAAe,MAAM,SAAS,KAAK;AAEzC,MAAI,qBAAqB,YAAY;AAErC,MAAI,aAAa,OAAO;AACtB,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,UAAM,IAAI,gBAAgB,SAAS,IAAI;AAAA,EACzC;AAEA,SAAO,cAAc;AACvB;AAOA,eAAe,iBAAiB,SAA+B;AAC7D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,UAAU,YAAY,cAAc;AAE1C,MAAI,CAAC,SAAS,eAAe;AAC3B,QAAI,0BAA0B,OAAO;AACrC,UAAM,IAAI,iCAAiC,OAAO;AAAA,EACpD;AAEA,SAAO,OAAO,QAAQ,OAAO;AAC/B;AAKA,eAAe,iBAAqD;AAClE,QAAM,MAAM,GAAG,OAAO,kBAAkB,CAAC,GAAG,iBAAiB;AAC7D,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,SAAO,SAAS,KAAK;AACvB;AAOA,SAAS,OAAO,WAA2B;AACzC,SAAO,SAAS,QAAQ,OAAO,SAAS;AAC1C","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
|