@metamask/transaction-controller 24.0.0 → 25.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -1
- package/dist/TransactionController.js +39 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +40 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2YXA3K67.mjs +62 -0
- package/dist/chunk-2YXA3K67.mjs.map +1 -0
- package/dist/chunk-3D3SA6PY.mjs +211 -0
- package/dist/chunk-3D3SA6PY.mjs.map +1 -0
- package/dist/chunk-4S25HUCL.js +46 -0
- package/dist/chunk-4S25HUCL.js.map +1 -0
- package/dist/chunk-5OQ373JS.js +211 -0
- package/dist/chunk-5OQ373JS.js.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-72OTU5ZW.mjs +2332 -0
- package/dist/chunk-72OTU5ZW.mjs.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7XPI7KU5.mjs +46 -0
- package/dist/chunk-7XPI7KU5.mjs.map +1 -0
- package/dist/chunk-BILEZLAT.js +182 -0
- package/dist/chunk-BILEZLAT.js.map +1 -0
- package/dist/chunk-CQBXHAYR.js +121 -0
- package/dist/chunk-CQBXHAYR.js.map +1 -0
- package/dist/chunk-CXXGL43K.js +85 -0
- package/dist/chunk-CXXGL43K.js.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTONMSFW.mjs +208 -0
- package/dist/chunk-DTONMSFW.mjs.map +1 -0
- package/dist/chunk-EEMJC7S7.mjs +182 -0
- package/dist/chunk-EEMJC7S7.mjs.map +1 -0
- package/dist/chunk-F3CMU2DM.js +170 -0
- package/dist/chunk-F3CMU2DM.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-ITDY6AIZ.js +127 -0
- package/dist/chunk-ITDY6AIZ.js.map +1 -0
- package/dist/chunk-IZI7FQIN.mjs +170 -0
- package/dist/chunk-IZI7FQIN.mjs.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-K26EBMGI.mjs +121 -0
- package/dist/chunk-K26EBMGI.mjs.map +1 -0
- package/dist/chunk-KFL2GGZC.mjs +48 -0
- package/dist/chunk-KFL2GGZC.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM4LTWRU.mjs +76 -0
- package/dist/chunk-NM4LTWRU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NRWEI43Q.js +320 -0
- package/dist/chunk-NRWEI43Q.js.map +1 -0
- package/dist/chunk-O7H2MC7R.js +62 -0
- package/dist/chunk-O7H2MC7R.js.map +1 -0
- package/dist/chunk-OF6NSLXF.mjs +90 -0
- package/dist/chunk-OF6NSLXF.mjs.map +1 -0
- package/dist/chunk-QDIYZX5V.js +2332 -0
- package/dist/chunk-QDIYZX5V.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-QPNEFZB3.js +208 -0
- package/dist/chunk-QPNEFZB3.js.map +1 -0
- package/dist/chunk-QSBIXUMB.mjs +242 -0
- package/dist/chunk-QSBIXUMB.mjs.map +1 -0
- package/dist/chunk-R7NJVDWN.js +48 -0
- package/dist/chunk-R7NJVDWN.js.map +1 -0
- package/dist/chunk-RQKICZYP.js +137 -0
- package/dist/chunk-RQKICZYP.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-TXVH44HM.js +90 -0
- package/dist/chunk-TXVH44HM.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VEREDMI2.mjs +85 -0
- package/dist/chunk-VEREDMI2.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-W3GAOR7Y.js +76 -0
- package/dist/chunk-W3GAOR7Y.js.map +1 -0
- package/dist/chunk-WXQZIUNW.js +242 -0
- package/dist/chunk-WXQZIUNW.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XKNFL657.mjs +137 -0
- package/dist/chunk-XKNFL657.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z3HHSD5I.mjs +127 -0
- package/dist/chunk-Z3HHSD5I.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/chunk-ZQFMTLZJ.mjs +320 -0
- package/dist/chunk-ZQFMTLZJ.mjs.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +11 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +12 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +57 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +236 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +10 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +5 -3
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +94 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts +16 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.js +9 -0
- package/dist/utils/layer1-gas-fee-flow.js.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.mjs +9 -0
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -160
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +22 -10
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/utils.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"names":[],"mappings":";AAAO,IAAM,YAAY;AAAA,EACvB,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,cAAc;AAAA,EACd,KAAK;AAAA,EACL,aAAa;AAAA,EACb,UAAU;AAAA,EACV,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,mBAAmB;AAAA,E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AO,GAAG;AAAA,IACnB,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,CAAC,UAAU,eAAe,GAAG;AAAA,IAC3B,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,SAAS,GAAG;AAAA,IACrB,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,CAAC,UAAU,iBAAiB,GAAG;AAAA,IAC7B,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,MAAM,GAAG;AAAA,IAClB,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,CAAC,UAAU,cAAc,GAAG;AAAA,IAC1B,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,QAAQ,GAAG;AAAA,IACpB,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,gBAAgB,GAAG;AAAA,IAC5B,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,SAAS,GAAG;AAAA,IACrB,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AAAA,EACA,CAAC,UAAU,MAAM,GAAG;AAAA,IAClB,QAAQ;AAAA,IACR,WAAW,GAAG,kCAAkC;AAAA,EAClD;AACF;AAEO,IAAM,6BAA6B;AAAA,EACxC,CAAC,UAAU,QAAQ,GAAG;AAAA,EACtB,CAAC,UAAU,gBAAgB,GAAG;AAChC","sourcesContent":["export const CHAIN_IDS = {\n MAINNET: '0x1',\n GOERLI: '0x5',\n BASE: '0x2105',\n BASE_TESTNET: '0x14a33',\n BSC: '0x38',\n BSC_TESTNET: '0x61',\n OPTIMISM: '0xa',\n OPTIMISM_TESTNET: '0x1a4',\n OPBNB: '0xcc',\n OPBNB_TESTNET: '0x15eb',\n OPTIMISM_SEPOLIA: '0xaa37dc',\n POLYGON: '0x89',\n POLYGON_TESTNET: '0x13881',\n AVALANCHE: '0xa86a',\n AVALANCHE_TESTNET: '0xa869',\n FANTOM: '0xfa',\n FANTOM_TESTNET: '0xfa2',\n SEPOLIA: '0xaa36a7',\n LINEA_GOERLI: '0xe704',\n LINEA_SEPOLIA: '0xe705',\n LINEA_MAINNET: '0xe708',\n MOONBEAM: '0x504',\n MOONBEAM_TESTNET: '0x507',\n MOONRIVER: '0x505',\n GNOSIS: '0x64',\n ARBITRUM: '0xa4b1',\n ZKSYNC_ERA: '0x144',\n} as const;\n\nexport const DEFAULT_ETHERSCAN_DOMAIN = 'etherscan.io';\nexport const DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX = 'api';\n\nexport const ETHERSCAN_SUPPORTED_NETWORKS = {\n [CHAIN_IDS.GOERLI]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-goerli`,\n },\n [CHAIN_IDS.MAINNET]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.SEPOLIA]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-sepolia`,\n },\n [CHAIN_IDS.LINEA_GOERLI]: {\n domain: 'lineascan.build',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-goerli`,\n },\n [CHAIN_IDS.LINEA_SEPOLIA]: {\n domain: 'lineascan.build',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-sepolia`,\n },\n [CHAIN_IDS.LINEA_MAINNET]: {\n domain: 'lineascan.build',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.BSC]: {\n domain: 'bscscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.BSC_TESTNET]: {\n domain: 'bscscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.OPTIMISM]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-optimistic`,\n },\n [CHAIN_IDS.OPTIMISM_SEPOLIA]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-sepolia-optimistic`,\n },\n [CHAIN_IDS.POLYGON]: {\n domain: 'polygonscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.POLYGON_TESTNET]: {\n domain: 'polygonscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-mumbai`,\n },\n [CHAIN_IDS.AVALANCHE]: {\n domain: 'snowtrace.io',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.AVALANCHE_TESTNET]: {\n domain: 'snowtrace.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.FANTOM]: {\n domain: 'ftmscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.FANTOM_TESTNET]: {\n domain: 'ftmscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.MOONBEAM]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonbeam`,\n },\n [CHAIN_IDS.MOONBEAM_TESTNET]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonbase`,\n },\n [CHAIN_IDS.MOONRIVER]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonriver`,\n },\n [CHAIN_IDS.GNOSIS]: {\n domain: 'gnosisscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-gnosis`,\n },\n};\n\nexport const GAS_BUFFER_CHAIN_OVERRIDES = {\n [CHAIN_IDS.OPTIMISM]: 1,\n [CHAIN_IDS.OPTIMISM_SEPOLIA]: 1,\n};\n"]}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchEtherscanTokenTransactions,
|
|
3
|
+
fetchEtherscanTransactions
|
|
4
|
+
} from "./chunk-VEREDMI2.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ETHERSCAN_SUPPORTED_NETWORKS
|
|
7
|
+
} from "./chunk-Z3HHSD5I.mjs";
|
|
8
|
+
import {
|
|
9
|
+
incomingTransactionsLogger
|
|
10
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__privateAdd,
|
|
13
|
+
__privateGet,
|
|
14
|
+
__privateMethod,
|
|
15
|
+
__privateSet
|
|
16
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
17
|
+
|
|
18
|
+
// src/helpers/EtherscanRemoteTransactionSource.ts
|
|
19
|
+
import { BNToHex } from "@metamask/controller-utils";
|
|
20
|
+
import { Mutex } from "async-mutex";
|
|
21
|
+
import BN from "bn.js";
|
|
22
|
+
import { v1 as random } from "uuid";
|
|
23
|
+
var ETHERSCAN_RATE_LIMIT_INTERVAL = 5e3;
|
|
24
|
+
var _includeTokenTransfers, _isTokenRequestPending, _mutex, _releaseLockAfterInterval, releaseLockAfterInterval_fn, _fetchNormalTransactions, _fetchTokenTransactions, _getResponseTransactions, getResponseTransactions_fn, _normalizeTransaction, normalizeTransaction_fn, _normalizeTokenTransaction, normalizeTokenTransaction_fn, _normalizeTransactionBase, normalizeTransactionBase_fn;
|
|
25
|
+
var EtherscanRemoteTransactionSource = class {
|
|
26
|
+
constructor({
|
|
27
|
+
includeTokenTransfers
|
|
28
|
+
} = {}) {
|
|
29
|
+
__privateAdd(this, _releaseLockAfterInterval);
|
|
30
|
+
__privateAdd(this, _getResponseTransactions);
|
|
31
|
+
__privateAdd(this, _normalizeTransaction);
|
|
32
|
+
__privateAdd(this, _normalizeTokenTransaction);
|
|
33
|
+
__privateAdd(this, _normalizeTransactionBase);
|
|
34
|
+
__privateAdd(this, _includeTokenTransfers, void 0);
|
|
35
|
+
__privateAdd(this, _isTokenRequestPending, void 0);
|
|
36
|
+
__privateAdd(this, _mutex, new Mutex());
|
|
37
|
+
__privateAdd(this, _fetchNormalTransactions, async (request, etherscanRequest) => {
|
|
38
|
+
const { currentChainId } = request;
|
|
39
|
+
const etherscanTransactions = await fetchEtherscanTransactions(
|
|
40
|
+
etherscanRequest
|
|
41
|
+
);
|
|
42
|
+
return __privateMethod(this, _getResponseTransactions, getResponseTransactions_fn).call(this, etherscanTransactions).map(
|
|
43
|
+
(tx) => __privateMethod(this, _normalizeTransaction, normalizeTransaction_fn).call(this, tx, currentChainId)
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
__privateAdd(this, _fetchTokenTransactions, async (request, etherscanRequest) => {
|
|
47
|
+
const { currentChainId } = request;
|
|
48
|
+
const etherscanTransactions = await fetchEtherscanTokenTransactions(
|
|
49
|
+
etherscanRequest
|
|
50
|
+
);
|
|
51
|
+
return __privateMethod(this, _getResponseTransactions, getResponseTransactions_fn).call(this, etherscanTransactions).map(
|
|
52
|
+
(tx) => __privateMethod(this, _normalizeTokenTransaction, normalizeTokenTransaction_fn).call(this, tx, currentChainId)
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
__privateSet(this, _includeTokenTransfers, includeTokenTransfers ?? true);
|
|
56
|
+
__privateSet(this, _isTokenRequestPending, false);
|
|
57
|
+
}
|
|
58
|
+
isSupportedNetwork(chainId) {
|
|
59
|
+
return Object.keys(ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);
|
|
60
|
+
}
|
|
61
|
+
getLastBlockVariations() {
|
|
62
|
+
return [__privateGet(this, _isTokenRequestPending) ? "token" : "normal"];
|
|
63
|
+
}
|
|
64
|
+
async fetchTransactions(request) {
|
|
65
|
+
const releaseLock = await __privateGet(this, _mutex).acquire();
|
|
66
|
+
const acquiredTime = Date.now();
|
|
67
|
+
const etherscanRequest = {
|
|
68
|
+
...request,
|
|
69
|
+
chainId: request.currentChainId
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const transactions = __privateGet(this, _isTokenRequestPending) ? await __privateGet(this, _fetchTokenTransactions).call(this, request, etherscanRequest) : await __privateGet(this, _fetchNormalTransactions).call(this, request, etherscanRequest);
|
|
73
|
+
if (__privateGet(this, _includeTokenTransfers)) {
|
|
74
|
+
__privateSet(this, _isTokenRequestPending, !__privateGet(this, _isTokenRequestPending));
|
|
75
|
+
}
|
|
76
|
+
return transactions;
|
|
77
|
+
} finally {
|
|
78
|
+
__privateMethod(this, _releaseLockAfterInterval, releaseLockAfterInterval_fn).call(this, acquiredTime, releaseLock);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
_includeTokenTransfers = new WeakMap();
|
|
83
|
+
_isTokenRequestPending = new WeakMap();
|
|
84
|
+
_mutex = new WeakMap();
|
|
85
|
+
_releaseLockAfterInterval = new WeakSet();
|
|
86
|
+
releaseLockAfterInterval_fn = function(acquireTime, releaseLock) {
|
|
87
|
+
const elapsedTime = Date.now() - acquireTime;
|
|
88
|
+
const remainingTime = Math.max(
|
|
89
|
+
0,
|
|
90
|
+
ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime
|
|
91
|
+
);
|
|
92
|
+
if (remainingTime > 0) {
|
|
93
|
+
setTimeout(releaseLock, remainingTime);
|
|
94
|
+
} else {
|
|
95
|
+
releaseLock();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
_fetchNormalTransactions = new WeakMap();
|
|
99
|
+
_fetchTokenTransactions = new WeakMap();
|
|
100
|
+
_getResponseTransactions = new WeakSet();
|
|
101
|
+
getResponseTransactions_fn = function(response) {
|
|
102
|
+
let result = response.result;
|
|
103
|
+
if (response.status === "0") {
|
|
104
|
+
result = [];
|
|
105
|
+
if (response.result.length) {
|
|
106
|
+
incomingTransactionsLogger("Ignored Etherscan request error", {
|
|
107
|
+
message: response.result,
|
|
108
|
+
type: __privateGet(this, _isTokenRequestPending) ? "token" : "normal"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
_normalizeTransaction = new WeakSet();
|
|
115
|
+
normalizeTransaction_fn = function(txMeta, currentChainId) {
|
|
116
|
+
const base = __privateMethod(this, _normalizeTransactionBase, normalizeTransactionBase_fn).call(this, txMeta, currentChainId);
|
|
117
|
+
return {
|
|
118
|
+
...base,
|
|
119
|
+
txParams: {
|
|
120
|
+
...base.txParams,
|
|
121
|
+
data: txMeta.input
|
|
122
|
+
},
|
|
123
|
+
...txMeta.isError === "0" ? { status: "confirmed" /* confirmed */ } : {
|
|
124
|
+
error: new Error("Transaction failed"),
|
|
125
|
+
status: "failed" /* failed */
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
_normalizeTokenTransaction = new WeakSet();
|
|
130
|
+
normalizeTokenTransaction_fn = function(txMeta, currentChainId) {
|
|
131
|
+
const base = __privateMethod(this, _normalizeTransactionBase, normalizeTransactionBase_fn).call(this, txMeta, currentChainId);
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
isTransfer: true,
|
|
135
|
+
transferInformation: {
|
|
136
|
+
contractAddress: txMeta.contractAddress,
|
|
137
|
+
decimals: Number(txMeta.tokenDecimal),
|
|
138
|
+
symbol: txMeta.tokenSymbol
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
_normalizeTransactionBase = new WeakSet();
|
|
143
|
+
normalizeTransactionBase_fn = function(txMeta, currentChainId) {
|
|
144
|
+
const time = parseInt(txMeta.timeStamp, 10) * 1e3;
|
|
145
|
+
return {
|
|
146
|
+
blockNumber: txMeta.blockNumber,
|
|
147
|
+
chainId: currentChainId,
|
|
148
|
+
hash: txMeta.hash,
|
|
149
|
+
id: random({ msecs: time }),
|
|
150
|
+
status: "confirmed" /* confirmed */,
|
|
151
|
+
time,
|
|
152
|
+
txParams: {
|
|
153
|
+
chainId: currentChainId,
|
|
154
|
+
from: txMeta.from,
|
|
155
|
+
gas: BNToHex(new BN(txMeta.gas)),
|
|
156
|
+
gasPrice: BNToHex(new BN(txMeta.gasPrice)),
|
|
157
|
+
gasUsed: BNToHex(new BN(txMeta.gasUsed)),
|
|
158
|
+
nonce: BNToHex(new BN(txMeta.nonce)),
|
|
159
|
+
to: txMeta.to,
|
|
160
|
+
value: BNToHex(new BN(txMeta.value))
|
|
161
|
+
},
|
|
162
|
+
type: "incoming" /* incoming */,
|
|
163
|
+
verifiedOnBlockchain: false
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
EtherscanRemoteTransactionSource
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=chunk-IZI7FQIN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/EtherscanRemoteTransactionSource.ts"],"sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from '../constants';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport {\n fetchEtherscanTokenTransactions,\n fetchEtherscanTransactions,\n} from '../utils/etherscan';\nimport type {\n EtherscanTokenTransactionMeta,\n EtherscanTransactionMeta,\n EtherscanTransactionMetaBase,\n EtherscanTransactionRequest,\n EtherscanTransactionResponse,\n} from '../utils/etherscan';\n\nconst ETHERSCAN_RATE_LIMIT_INTERVAL = 5000;\n/**\n * A RemoteTransactionSource that fetches transaction data from Etherscan.\n */\nexport class EtherscanRemoteTransactionSource\n implements RemoteTransactionSource\n{\n #includeTokenTransfers: boolean;\n\n #isTokenRequestPending: boolean;\n\n #mutex = new Mutex();\n\n constructor({\n includeTokenTransfers,\n }: { includeTokenTransfers?: boolean } = {}) {\n this.#includeTokenTransfers = includeTokenTransfers ?? true;\n this.#isTokenRequestPending = false;\n }\n\n isSupportedNetwork(chainId: Hex): boolean {\n return Object.keys(ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);\n }\n\n getLastBlockVariations(): string[] {\n return [this.#isTokenRequestPending ? 'token' : 'normal'];\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const releaseLock = await this.#mutex.acquire();\n const acquiredTime = Date.now();\n\n const etherscanRequest: EtherscanTransactionRequest = {\n ...request,\n chainId: request.currentChainId,\n };\n\n try {\n const transactions = this.#isTokenRequestPending\n ? await this.#fetchTokenTransactions(request, etherscanRequest)\n : await this.#fetchNormalTransactions(request, etherscanRequest);\n\n if (this.#includeTokenTransfers) {\n this.#isTokenRequestPending = !this.#isTokenRequestPending;\n }\n\n return transactions;\n } finally {\n this.#releaseLockAfterInterval(acquiredTime, releaseLock);\n }\n }\n\n #releaseLockAfterInterval(acquireTime: number, releaseLock: () => void) {\n const elapsedTime = Date.now() - acquireTime;\n const remainingTime = Math.max(\n 0,\n ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime,\n );\n // Wait for the remaining time if it hasn't been 5 seconds yet\n if (remainingTime > 0) {\n setTimeout(releaseLock, remainingTime);\n } else {\n releaseLock();\n }\n }\n\n #fetchNormalTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTransaction(tx, currentChainId),\n );\n };\n\n #fetchTokenTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTokenTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTokenTransaction(tx, currentChainId),\n );\n };\n\n #getResponseTransactions<T extends EtherscanTransactionMetaBase>(\n response: EtherscanTransactionResponse<T>,\n ): T[] {\n let result = response.result as T[];\n\n if (response.status === '0') {\n result = [];\n\n if (response.result.length) {\n log('Ignored Etherscan request error', {\n message: response.result,\n type: this.#isTokenRequestPending ? 'token' : 'normal',\n });\n }\n }\n\n return result;\n }\n\n #normalizeTransaction(\n txMeta: EtherscanTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n txParams: {\n ...base.txParams,\n data: txMeta.input,\n },\n ...(txMeta.isError === '0'\n ? { status: TransactionStatus.confirmed }\n : {\n error: new Error('Transaction failed'),\n status: TransactionStatus.failed,\n }),\n };\n }\n\n #normalizeTokenTransaction(\n txMeta: EtherscanTokenTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n isTransfer: true,\n transferInformation: {\n contractAddress: txMeta.contractAddress,\n decimals: Number(txMeta.tokenDecimal),\n symbol: txMeta.tokenSymbol,\n },\n };\n }\n\n #normalizeTransactionBase(\n txMeta: EtherscanTransactionMetaBase,\n currentChainId: Hex,\n ): TransactionMeta {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n\n return {\n blockNumber: txMeta.blockNumber,\n chainId: currentChainId,\n hash: txMeta.hash,\n id: random({ msecs: time }),\n status: TransactionStatus.confirmed,\n time,\n txParams: {\n chainId: currentChainId,\n from: txMeta.from,\n gas: BNToHex(new BN(txMeta.gas)),\n gasPrice: BNToHex(new BN(txMeta.gasPrice)),\n gasUsed: BNToHex(new BN(txMeta.gasUsed)),\n nonce: BNToHex(new BN(txMeta.nonce)),\n to: txMeta.to,\n value: BNToHex(new BN(txMeta.value)),\n },\n type: TransactionType.incoming,\n verifiedOnBlockchain: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAExB,SAAS,aAAa;AACtB,OAAO,QAAQ;AACf,SAAS,MAAM,cAAc;AAsB7B,IAAM,gCAAgC;AA1BtC;AA8BO,IAAM,mCAAN,MAEP;AAAA,EAOE,YAAY;AAAA,IACV;AAAA,EACF,IAAyC,CAAC,GAAG;AAuC7C;AA4CA;AAmBA;AAqBA;AAiBA;AApJA;AAEA;AAEA,+BAAS,IAAI,MAAM;AAyDnB,iDAA2B,OACzB,SACA,qBACG;AACH,YAAM,EAAE,eAAe,IAAI;AAE3B,YAAM,wBAAwB,MAAM;AAAA,QAClC;AAAA,MACF;AAEA,aAAO,sBAAK,sDAAL,WAA8B,uBAAuB;AAAA,QAAI,CAAC,OAC/D,sBAAK,gDAAL,WAA2B,IAAI;AAAA,MACjC;AAAA,IACF;AAEA,gDAA0B,OACxB,SACA,qBACG;AACH,YAAM,EAAE,eAAe,IAAI;AAE3B,YAAM,wBAAwB,MAAM;AAAA,QAClC;AAAA,MACF;AAEA,aAAO,sBAAK,sDAAL,WAA8B,uBAAuB;AAAA,QAAI,CAAC,OAC/D,sBAAK,0DAAL,WAAgC,IAAI;AAAA,MACtC;AAAA,IACF;AAhFE,uBAAK,wBAAyB,yBAAyB;AACvD,uBAAK,wBAAyB;AAAA,EAChC;A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,123 @@
|
|
|
1
|
+
// src/utils/utils.ts
|
|
2
|
+
import { convertHexToDecimal } from "@metamask/controller-utils";
|
|
3
|
+
import {
|
|
4
|
+
add0x,
|
|
5
|
+
getKnownPropertyNames,
|
|
6
|
+
isStrictHexString
|
|
7
|
+
} from "@metamask/utils";
|
|
8
|
+
var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
9
|
+
var NORMALIZERS = {
|
|
10
|
+
data: (data) => add0x(padHexToEvenLength(data)),
|
|
11
|
+
from: (from) => add0x(from).toLowerCase(),
|
|
12
|
+
gas: (gas) => add0x(gas),
|
|
13
|
+
gasLimit: (gas) => add0x(gas),
|
|
14
|
+
gasPrice: (gasPrice) => add0x(gasPrice),
|
|
15
|
+
nonce: (nonce) => add0x(nonce),
|
|
16
|
+
to: (to) => add0x(to).toLowerCase(),
|
|
17
|
+
value: (value) => add0x(value),
|
|
18
|
+
maxFeePerGas: (maxFeePerGas) => add0x(maxFeePerGas),
|
|
19
|
+
maxPriorityFeePerGas: (maxPriorityFeePerGas) => add0x(maxPriorityFeePerGas),
|
|
20
|
+
estimatedBaseFee: (maxPriorityFeePerGas) => add0x(maxPriorityFeePerGas),
|
|
21
|
+
type: (type) => add0x(type)
|
|
22
|
+
};
|
|
23
|
+
function normalizeTransactionParams(txParams) {
|
|
24
|
+
const normalizedTxParams = { from: "" };
|
|
25
|
+
for (const key of getKnownPropertyNames(NORMALIZERS)) {
|
|
26
|
+
if (txParams[key]) {
|
|
27
|
+
normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!normalizedTxParams.value) {
|
|
31
|
+
normalizedTxParams.value = "0x0";
|
|
32
|
+
}
|
|
33
|
+
return normalizedTxParams;
|
|
34
|
+
}
|
|
35
|
+
function isEIP1559Transaction(txParams) {
|
|
36
|
+
const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
37
|
+
return hasOwnProp(txParams, "maxFeePerGas") && hasOwnProp(txParams, "maxPriorityFeePerGas");
|
|
38
|
+
}
|
|
39
|
+
var validateGasValues = (gasValues) => {
|
|
40
|
+
Object.keys(gasValues).forEach((key) => {
|
|
41
|
+
const value = gasValues[key];
|
|
42
|
+
if (typeof value !== "string" || !isStrictHexString(value)) {
|
|
43
|
+
throw new TypeError(
|
|
44
|
+
`expected hex string for ${key} but received: ${value}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var isFeeMarketEIP1559Values = (gasValues) => gasValues?.maxFeePerGas !== void 0 || gasValues?.maxPriorityFeePerGas !== void 0;
|
|
50
|
+
var isGasPriceValue = (gasValues) => gasValues?.gasPrice !== void 0;
|
|
51
|
+
var getIncreasedPriceHex = (value, rate) => add0x(`${parseInt(`${value * rate}`, 10).toString(16)}`);
|
|
52
|
+
var getIncreasedPriceFromExisting = (value, rate) => {
|
|
53
|
+
return getIncreasedPriceHex(convertHexToDecimal(value), rate);
|
|
54
|
+
};
|
|
55
|
+
function validateMinimumIncrease(proposed, min) {
|
|
56
|
+
const proposedDecimal = convertHexToDecimal(proposed);
|
|
57
|
+
const minDecimal = convertHexToDecimal(min);
|
|
58
|
+
if (proposedDecimal >= minDecimal) {
|
|
59
|
+
return proposed;
|
|
60
|
+
}
|
|
61
|
+
const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;
|
|
62
|
+
throw new Error(errorMsg);
|
|
63
|
+
}
|
|
64
|
+
function validateIfTransactionUnapproved(transactionMeta, fnName) {
|
|
65
|
+
if (transactionMeta?.status !== "unapproved" /* unapproved */) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`TransactionsController: Can only call ${fnName} on an unapproved transaction.
|
|
68
|
+
Current tx status: ${transactionMeta?.status}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function normalizeTxError(error) {
|
|
73
|
+
return {
|
|
74
|
+
name: error.name,
|
|
75
|
+
message: error.message,
|
|
76
|
+
stack: error.stack,
|
|
77
|
+
code: error.code,
|
|
78
|
+
rpc: isJsonCompatible(error.value) ? error.value : void 0
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function normalizeGasFeeValues(gasFeeValues) {
|
|
82
|
+
const normalize = (value) => typeof value === "string" ? add0x(value) : value;
|
|
83
|
+
if ("gasPrice" in gasFeeValues) {
|
|
84
|
+
return {
|
|
85
|
+
gasPrice: normalize(gasFeeValues.gasPrice)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),
|
|
90
|
+
maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function isJsonCompatible(value) {
|
|
94
|
+
try {
|
|
95
|
+
JSON.parse(JSON.stringify(value));
|
|
96
|
+
return true;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function padHexToEvenLength(hex) {
|
|
102
|
+
const prefix = hex.toLowerCase().startsWith("0x") ? hex.slice(0, 2) : "";
|
|
103
|
+
const data = prefix ? hex.slice(2) : hex;
|
|
104
|
+
const evenData = data.length % 2 === 0 ? data : `0${data}`;
|
|
105
|
+
return prefix + evenData;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
ESTIMATE_GAS_ERROR,
|
|
110
|
+
normalizeTransactionParams,
|
|
111
|
+
isEIP1559Transaction,
|
|
112
|
+
validateGasValues,
|
|
113
|
+
isFeeMarketEIP1559Values,
|
|
114
|
+
isGasPriceValue,
|
|
115
|
+
getIncreasedPriceHex,
|
|
116
|
+
getIncreasedPriceFromExisting,
|
|
117
|
+
validateMinimumIncrease,
|
|
118
|
+
validateIfTransactionUnapproved,
|
|
119
|
+
normalizeTxError,
|
|
120
|
+
normalizeGasFeeValues,
|
|
121
|
+
padHexToEvenLength
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=chunk-J56A7UCK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/utils.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\n\nimport type {\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../TransactionController';\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\nexport const isFeeMarketEIP1559Values = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is FeeMarketEIP1559Values =>\n (gasValues as FeeMarketEIP1559Values)?.maxFeePerGas !== undefined ||\n (gasValues as FeeMarketEIP1559Values)?.maxPriorityFeePerGas !== undefined;\n\nexport const isGasPriceValue = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is GasPriceValue =>\n (gasValues as GasPriceValue)?.gasPrice !== undefined;\n\nexport const getIncreasedPriceHex = (value: number, rate: number): string =>\n add0x(`${parseInt(`${value * rate}`, 10).toString(16)}`);\n\nexport const getIncreasedPriceFromExisting = (\n value: string | undefined,\n rate: number,\n): string => {\n return getIncreasedPriceHex(convertHexToDecimal(value), rate);\n};\n\n/**\n * Validates that the proposed value is greater than or equal to the minimum value.\n *\n * @param proposed - The proposed value.\n * @param min - The minimum value.\n * @returns The proposed value.\n * @throws Will throw if the proposed value is too low.\n */\nexport function validateMinimumIncrease(proposed: string, min: string) {\n const proposedDecimal = convertHexToDecimal(proposed);\n const minDecimal = convertHexToDecimal(min);\n if (proposedDecimal >= minDecimal) {\n return proposed;\n }\n const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;\n throw new Error(errorMsg);\n}\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error.code,\n rpc: isJsonCompatible(error.value) ? error.value : undefined,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Determines whether the given value can be encoded as JSON.\n *\n * @param value - The value.\n * @returns True if the value is JSON-encodable, false if not.\n */\nfunction isJsonCompatible(value: unknown): value is Json {\n try {\n JSON.parse(JSON.stringify(value));\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcA,IAAM,qBAAqB;AAIlC,IAAM,cAA2D;AAAA,EAC/D,MAAM,CAAC,SAAiB,MAAM,mBAAmB,IAAI,CAAC;AAAA,EACtD,MAAM,CAAC,SAAiB,MAAM,IAAI,EAAE,YAAY;AAAA,EAChD,KAAK,CAAC,QAAgB,MAAM,GAAG;AAAA,EAC/B,UAAU,CAAC,QAAgB,MAAM,GAAG;AAAA,EACpC,UAAU,CAAC,aAAqB,MAAM,QAAQ;AAAA,EAC9C,OAAO,CAAC,UAAkB,MAAM,KAAK;AAAA,EACrC,IAAI,CAAC,OAAe,MAAM,EAAE,EAAE,YAAY;AAAA,EAC1C,OAAO,CAAC,UAAkB,MAAM,KAAK;AAAA,EACrC,cAAc,CAAC,iBAAyB,MAAM,YAAY;AAAA,EAC1D,sBAAsB,CAAC,yBACrB,MAAM,oBAAoB;AAAA,EAC5B,kBAAkB,CAAC,yBACjB,MAAM,oBAAoB;AAAA,EAC5B,MAAM,CAAC,SAAiB,MAAM,IAAI;AACpC;AAQO,SAAS,2BAA2B,UAA6B;AACtE,QAAM,qBAAwC,EAAE,MAAM,GAAG;AAEzD,aAAW,OAAO,sBAAsB,WAAW,GAAG;AACpD,QAAI,SAAS,GAAG,GAAG;AACjB,yBAAmB,GAAG,IAAI,YAAY,GAAG,EAAE,SAAS,GAAG,C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,iBAAiB,MAAM;AAAA,IAC9C;AAAA,EACF;AACF;AAQO,SAAS,iBACd,OACkB;AAClB,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,SAAS,MAAM;AAAA,IACf,OAAO,MAAM;AAAA,IACb,MAAM,MAAM;AAAA,IACZ,KAAK,iBAAiB,MAAM,KAAK,IAAI,MAAM,QAAQ;AAAA,EACrD;AACF;AAQO,SAAS,sBACd,cACwC;AAGxC,QAAM,YAAY,CAAC,UACjB,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;AAE7C,MAAI,cAAc,cAAc;AAC9B,WAAO;AAAA,MACL,UAAU,UAAU,aAAa,QAAQ;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AAAA,IACL,cAAc,UAAU,aAAa,YAAY;AAAA,IACjD,sBAAsB,UAAU,aAAa,oBAAoB;AAAA,EACnE;AACF;AAQA,SAAS,iBAAiB,OAA+B;AACvD,MAAI;AACF,SAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASO,SAAS,mBAAmB,KAAa;AAC9C,QAAM,SAAS,IAAI,YAAY,EAAE,WAAW,IAAI,IAAI,IAAI,MAAM,GAAG,CAAC,IAAI;AACtE,QAAM,OAAO,SAAS,IAAI,MAAM,CAAC,IAAI;AACrC,QAAM,WAAW,KAAK,SAAS,MAAM,IAAI,OAAO,IAAI,IAAI;AAExD,SAAO,SAAS;AAClB;","names":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/utils/transaction-type.ts
|
|
2
|
+
import { Interface } from "@ethersproject/abi";
|
|
3
|
+
import { query } from "@metamask/controller-utils";
|
|
4
|
+
import { abiERC721, abiERC20, abiERC1155 } from "@metamask/metamask-eth-abis";
|
|
5
|
+
var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
6
|
+
var ERC20Interface = new Interface(abiERC20);
|
|
7
|
+
var ERC721Interface = new Interface(abiERC721);
|
|
8
|
+
var ERC1155Interface = new Interface(abiERC1155);
|
|
9
|
+
async function determineTransactionType(txParams, ethQuery) {
|
|
10
|
+
const { data, to } = txParams;
|
|
11
|
+
if (data && !to) {
|
|
12
|
+
return { type: "contractDeployment" /* deployContract */, getCodeResponse: void 0 };
|
|
13
|
+
}
|
|
14
|
+
const { contractCode: getCodeResponse, isContractAddress } = await readAddressAsContract(ethQuery, to);
|
|
15
|
+
if (!isContractAddress) {
|
|
16
|
+
return { type: "simpleSend" /* simpleSend */, getCodeResponse };
|
|
17
|
+
}
|
|
18
|
+
const hasValue = Number(txParams.value ?? "0") !== 0;
|
|
19
|
+
const contractInteractionResult = {
|
|
20
|
+
type: "contractInteraction" /* contractInteraction */,
|
|
21
|
+
getCodeResponse
|
|
22
|
+
};
|
|
23
|
+
if (!data || hasValue) {
|
|
24
|
+
return contractInteractionResult;
|
|
25
|
+
}
|
|
26
|
+
const name = parseStandardTokenTransactionData(data)?.name;
|
|
27
|
+
if (!name) {
|
|
28
|
+
return contractInteractionResult;
|
|
29
|
+
}
|
|
30
|
+
const tokenMethodName = [
|
|
31
|
+
"approve" /* tokenMethodApprove */,
|
|
32
|
+
"setapprovalforall" /* tokenMethodSetApprovalForAll */,
|
|
33
|
+
"transfer" /* tokenMethodTransfer */,
|
|
34
|
+
"transferfrom" /* tokenMethodTransferFrom */,
|
|
35
|
+
"safetransferfrom" /* tokenMethodSafeTransferFrom */
|
|
36
|
+
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
|
|
37
|
+
if (tokenMethodName) {
|
|
38
|
+
return { type: tokenMethodName, getCodeResponse };
|
|
39
|
+
}
|
|
40
|
+
return contractInteractionResult;
|
|
41
|
+
}
|
|
42
|
+
function parseStandardTokenTransactionData(data) {
|
|
43
|
+
if (!data) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return ERC20Interface.parseTransaction({ data });
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return ERC721Interface.parseTransaction({ data });
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return ERC1155Interface.parseTransaction({ data });
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
async function readAddressAsContract(ethQuery, address) {
|
|
61
|
+
let contractCode;
|
|
62
|
+
try {
|
|
63
|
+
contractCode = await query(ethQuery, "getCode", [address]);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
contractCode = null;
|
|
66
|
+
}
|
|
67
|
+
const isContractAddress = contractCode ? contractCode !== "0x" && contractCode !== "0x0" : false;
|
|
68
|
+
return { contractCode, isContractAddress };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
ESTIMATE_GAS_ERROR,
|
|
73
|
+
determineTransactionType
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=chunk-JRBREX22.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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 { abiERC721, abiERC20, abiERC1155 } 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);\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 ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());\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 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,SAAS,WAAW,UAAU,kBAAkB;AAKzC,IAAM,qBAAqB;AAElC,IAAM,iBAAiB,IAAI,UAAU,QAAQ;AAC7C,IAAM,kBAAkB,IAAI,UAAU,SAAS;AAC/C,IAAM,mBAAmB,IAAI,UAAU,UAAU;AAWjD,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,EAMxB,EAAE,KAAK,CAAC,eAAe,WAAW,YAAY,MAAM,KAAK,YAAY,CAAC;AAEtE,MAAI,iBAAiB;AACnB,WAAO,EAAE,MAAM,iBAAi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