@metamask/transaction-controller 63.3.1 → 64.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/TransactionController.cjs +85 -103
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts.map +1 -1
  5. package/dist/TransactionController.d.mts.map +1 -1
  6. package/dist/TransactionController.mjs +86 -108
  7. package/dist/TransactionController.mjs.map +1 -1
  8. package/dist/gas-flows/LineaGasFeeFlow.cjs +22 -11
  9. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  10. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  11. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  12. package/dist/gas-flows/LineaGasFeeFlow.mjs +23 -12
  13. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  14. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -2
  15. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
  16. package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
  17. package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
  18. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +1 -1
  19. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
  20. package/dist/helpers/GasFeePoller.cjs +5 -19
  21. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  22. package/dist/helpers/GasFeePoller.d.cts +1 -6
  23. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  24. package/dist/helpers/GasFeePoller.d.mts +1 -6
  25. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  26. package/dist/helpers/GasFeePoller.mjs +5 -26
  27. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  28. package/dist/helpers/MethodDataHelper.cjs +10 -6
  29. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  30. package/dist/helpers/MethodDataHelper.d.cts +4 -4
  31. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  32. package/dist/helpers/MethodDataHelper.d.mts +4 -4
  33. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  34. package/dist/helpers/MethodDataHelper.mjs +10 -6
  35. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  36. package/dist/helpers/MultichainTrackingHelper.cjs +0 -2
  37. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  38. package/dist/helpers/MultichainTrackingHelper.d.cts +0 -2
  39. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  40. package/dist/helpers/MultichainTrackingHelper.d.mts +0 -2
  41. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  42. package/dist/helpers/MultichainTrackingHelper.mjs +0 -2
  43. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  44. package/dist/helpers/PendingTransactionTracker.cjs +38 -24
  45. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  46. package/dist/helpers/PendingTransactionTracker.d.cts +3 -7
  47. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  48. package/dist/helpers/PendingTransactionTracker.d.mts +3 -7
  49. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  50. package/dist/helpers/PendingTransactionTracker.mjs +38 -24
  51. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  52. package/dist/hooks/SequentialPublishBatchHook.cjs +4 -6
  53. package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
  54. package/dist/hooks/SequentialPublishBatchHook.d.cts +2 -4
  55. package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
  56. package/dist/hooks/SequentialPublishBatchHook.d.mts +2 -4
  57. package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
  58. package/dist/hooks/SequentialPublishBatchHook.mjs +4 -6
  59. package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
  60. package/dist/index.cjs +1 -3
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.cts +0 -1
  63. package/dist/index.d.cts.map +1 -1
  64. package/dist/index.d.mts +0 -1
  65. package/dist/index.d.mts.map +1 -1
  66. package/dist/index.mjs +0 -1
  67. package/dist/index.mjs.map +1 -1
  68. package/dist/types.cjs.map +1 -1
  69. package/dist/types.d.cts +14 -3
  70. package/dist/types.d.cts.map +1 -1
  71. package/dist/types.d.mts +14 -3
  72. package/dist/types.d.mts.map +1 -1
  73. package/dist/types.mjs.map +1 -1
  74. package/dist/utils/balance-changes.cjs +2 -2
  75. package/dist/utils/balance-changes.cjs.map +1 -1
  76. package/dist/utils/balance-changes.d.cts +4 -2
  77. package/dist/utils/balance-changes.d.cts.map +1 -1
  78. package/dist/utils/balance-changes.d.mts +4 -2
  79. package/dist/utils/balance-changes.d.mts.map +1 -1
  80. package/dist/utils/balance-changes.mjs +2 -2
  81. package/dist/utils/balance-changes.mjs.map +1 -1
  82. package/dist/utils/balance.cjs +14 -10
  83. package/dist/utils/balance.cjs.map +1 -1
  84. package/dist/utils/balance.d.cts +8 -5
  85. package/dist/utils/balance.d.cts.map +1 -1
  86. package/dist/utils/balance.d.mts +8 -5
  87. package/dist/utils/balance.d.mts.map +1 -1
  88. package/dist/utils/balance.mjs +14 -10
  89. package/dist/utils/balance.mjs.map +1 -1
  90. package/dist/utils/batch.cjs +19 -19
  91. package/dist/utils/batch.cjs.map +1 -1
  92. package/dist/utils/batch.d.cts +1 -5
  93. package/dist/utils/batch.d.cts.map +1 -1
  94. package/dist/utils/batch.d.mts +1 -5
  95. package/dist/utils/batch.d.mts.map +1 -1
  96. package/dist/utils/batch.mjs +20 -20
  97. package/dist/utils/batch.mjs.map +1 -1
  98. package/dist/utils/eip7702.cjs +13 -6
  99. package/dist/utils/eip7702.cjs.map +1 -1
  100. package/dist/utils/eip7702.d.cts +6 -5
  101. package/dist/utils/eip7702.d.cts.map +1 -1
  102. package/dist/utils/eip7702.d.mts +6 -5
  103. package/dist/utils/eip7702.d.mts.map +1 -1
  104. package/dist/utils/eip7702.mjs +14 -7
  105. package/dist/utils/eip7702.mjs.map +1 -1
  106. package/dist/utils/gas-fee-tokens.cjs +4 -3
  107. package/dist/utils/gas-fee-tokens.cjs.map +1 -1
  108. package/dist/utils/gas-fee-tokens.d.cts +6 -4
  109. package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
  110. package/dist/utils/gas-fee-tokens.d.mts +6 -4
  111. package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
  112. package/dist/utils/gas-fee-tokens.mjs +4 -3
  113. package/dist/utils/gas-fee-tokens.mjs.map +1 -1
  114. package/dist/utils/gas-fees.cjs +8 -6
  115. package/dist/utils/gas-fees.cjs.map +1 -1
  116. package/dist/utils/gas-fees.d.cts +0 -2
  117. package/dist/utils/gas-fees.d.cts.map +1 -1
  118. package/dist/utils/gas-fees.d.mts +0 -2
  119. package/dist/utils/gas-fees.d.mts.map +1 -1
  120. package/dist/utils/gas-fees.mjs +9 -7
  121. package/dist/utils/gas-fees.mjs.map +1 -1
  122. package/dist/utils/gas.cjs +60 -34
  123. package/dist/utils/gas.cjs.map +1 -1
  124. package/dist/utils/gas.d.cts +6 -11
  125. package/dist/utils/gas.d.cts.map +1 -1
  126. package/dist/utils/gas.d.mts +6 -11
  127. package/dist/utils/gas.d.mts.map +1 -1
  128. package/dist/utils/gas.mjs +61 -35
  129. package/dist/utils/gas.mjs.map +1 -1
  130. package/dist/utils/layer1-gas-fee-flow.cjs +7 -3
  131. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  132. package/dist/utils/layer1-gas-fee-flow.d.cts +2 -5
  133. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  134. package/dist/utils/layer1-gas-fee-flow.d.mts +2 -5
  135. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  136. package/dist/utils/layer1-gas-fee-flow.mjs +7 -3
  137. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  138. package/dist/utils/provider.cjs +74 -0
  139. package/dist/utils/provider.cjs.map +1 -0
  140. package/dist/utils/provider.d.cts +65 -0
  141. package/dist/utils/provider.d.cts.map +1 -0
  142. package/dist/utils/provider.d.mts +65 -0
  143. package/dist/utils/provider.d.mts.map +1 -0
  144. package/dist/utils/provider.mjs +67 -0
  145. package/dist/utils/provider.mjs.map +1 -0
  146. package/dist/utils/swaps.cjs +11 -7
  147. package/dist/utils/swaps.cjs.map +1 -1
  148. package/dist/utils/swaps.d.cts +6 -4
  149. package/dist/utils/swaps.d.cts.map +1 -1
  150. package/dist/utils/swaps.d.mts +6 -4
  151. package/dist/utils/swaps.d.mts.map +1 -1
  152. package/dist/utils/swaps.mjs +11 -7
  153. package/dist/utils/swaps.mjs.map +1 -1
  154. package/dist/utils/transaction-type.cjs +17 -8
  155. package/dist/utils/transaction-type.cjs.map +1 -1
  156. package/dist/utils/transaction-type.d.cts +9 -3
  157. package/dist/utils/transaction-type.d.cts.map +1 -1
  158. package/dist/utils/transaction-type.d.mts +9 -3
  159. package/dist/utils/transaction-type.d.mts.map +1 -1
  160. package/dist/utils/transaction-type.mjs +17 -8
  161. package/dist/utils/transaction-type.mjs.map +1 -1
  162. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.cjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oEAA2C;AAO3C,2CAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0EAAmE;AACnE,0CAA0C;AAW1C,wCAKkB;AAClB,oDAAkD;AAClD,0EAA0E;AAE1E,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAa,YAAY;IA2BvB;;;;;;;;;;;;;OAaG;IACH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D,QAAQ,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QACnE,CAAC;QAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,MAAM,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;YACrD,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC;YACjC,QAAQ,CAAC,oBAAoB,GAAG,QAAQ,CAAC;QAC3C,CAAC;QAED,4CAA4C;QAC5C,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,mCAAmC;QACnC,IAAI,eAAe,KAAK,0BAAkB,CAAC,SAAS,EAAE,CAAC;YACrD,MAAM,wBAAwB,GAAG,eAAe,CAAC;YACjD,QAAQ,CAAC,QAAQ,GAAG,wBAAwB,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;QAC3E,CAAC;QAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,QAAQ,EAAE,CAAC;YACpD,MAAM,uBAAuB,GAAG,eAAe,CAAC;YAChD,QAAQ,CAAC,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QACvD,CAAC;QAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;QAED,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,YAAY,CAAC;QAC7B,OAAO,QAAQ,CAAC,oBAAoB,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { DefaultGasFeeFlow } from '../gas-flows/DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n TransactionMeta,\n TransactionParams,\n TransactionBatchMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #getTransactionBatches: () => TransactionBatchMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.getTransactionBatches - Callback to obtain the transaction batch data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n getTransactionBatches,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n getTransactionBatches: () => TransactionBatchMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n this.#getTransactionBatches = getTransactionBatches;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (\n unapprovedTransactions.length ||\n unapprovedTransactionBatches.length\n ) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start(): void {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop(): void {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout(): Promise<void> {\n await this.#updateUnapprovedTransactions();\n await this.#updateUnapprovedTransactionBatches();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions(): Promise<void> {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransactionBatches(): Promise<void> {\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (!unapprovedTransactionBatches.length) {\n return;\n }\n\n log(\n 'Found unapproved transaction batches',\n unapprovedTransactionBatches.length,\n );\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactionBatches,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactionBatches.flatMap((txBatch) => {\n const { chainId } = txBatch;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransactionBatch(\n txBatch,\n gasFeeControllerData,\n );\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateUnapprovedTransactionBatch(\n txBatchMeta: TransactionBatchMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = txBatchMeta;\n\n const ethQuery = new EthQuery(\n this.#getProvider(txBatchMeta.networkClientId),\n );\n const defaultGasFeeFlow = new DefaultGasFeeFlow();\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta: {\n ...txBatchMeta,\n txParams: {\n ...txBatchMeta.transactions?.[0],\n from: txBatchMeta.from,\n gas: txBatchMeta.gas,\n },\n time: Date.now(),\n },\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n try {\n const response = await defaultGasFeeFlow.getGasFees(request);\n\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get gas fees for batch', txBatchMeta.id, error);\n }\n\n if (!gasFeeEstimates) {\n return;\n }\n\n this.hub.emit('transaction-batch-updated', {\n transactionBatchId: id,\n gasFeeEstimates,\n gasFeeEstimatesLoaded: true,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(networkClientId));\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { networkClientId } = transactionMeta;\n const provider = this.#getProvider(networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n #getUnapprovedTransactionBatches(): TransactionBatchMeta[] {\n return this.#getTransactionBatches().filter(\n (batch) => batch.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[] | TransactionBatchMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Updates gas properties for transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function updateTransactionGasProperties({\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n txMeta,\n}: {\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n txMeta: TransactionMeta;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (\n shouldUpdateTxParamsGasFees &&\n isUsingGasFeeEstimateLevel &&\n gasFeeEstimates\n ) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txMeta.txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.userFeeLevel - The user fee level.\n */\nexport function updateTransactionGasEstimates({\n txMeta,\n userFeeLevel,\n}: {\n txMeta: TransactionMeta;\n userFeeLevel: GasFeeEstimateLevel;\n}): void {\n const { txParams, gasFeeEstimates } = txMeta;\n\n if (!gasFeeEstimates) {\n return;\n }\n\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n}\n\n/**\n * Updates gas fee parameters based on transaction type and gas estimate type\n *\n * @param txParams - The transaction parameters to update\n * @param gasFeeEstimates - The gas fee estimates\n * @param userFeeLevel - The user fee level\n * @param isEIP1559Compatible - Whether the transaction is EIP-1559 compatible\n */\nfunction updateGasFeeParameters(\n txParams: TransactionParams,\n gasFeeEstimates: GasFeeEstimates,\n userFeeLevel: GasFeeEstimateLevel,\n isEIP1559Compatible: boolean,\n): void {\n const { type: gasEstimateType } = gasFeeEstimates;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n txParams.maxFeePerGas = gasPrice;\n txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txParams.maxFeePerGas;\n delete txParams.maxPriorityFeePerGas;\n }\n}\n"]}
1
+ {"version":3,"file":"GasFeePoller.cjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,2CAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0EAAmE;AACnE,0CAA0C;AAW1C,wCAKkB;AAClB,oDAAkD;AAClD,0EAA0E;AAC1E,oDAAuD;AAEvD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAa,YAAY;IAqBvB;;;;;;;;;;;OAWG;IACH,YAAY,EACV,WAAW,EACX,4BAA4B,EAC5B,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EACT,aAAa,GAWd;;QAlDD,QAAG,GAAiB,IAAI,gBAAY,EAAE,CAAC;QAE9B,4CAA2B;QAE3B,6DAEi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AQ,CAAC;QACvD,CAAC;QAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;QAED,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,YAAY,CAAC;QAC7B,OAAO,QAAQ,CAAC,oBAAoB,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { DefaultGasFeeFlow } from '../gas-flows/DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n TransactionMeta,\n TransactionParams,\n TransactionBatchMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\nimport { getNetworkClientId } from '../utils/provider';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #getTransactionBatches: () => TransactionBatchMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.getTransactionBatches - Callback to obtain the transaction batch data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getTransactions,\n getTransactionBatches,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getTransactions: () => TransactionMeta[];\n getTransactionBatches: () => TransactionBatchMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getTransactions = getTransactions;\n this.#getTransactionBatches = getTransactionBatches;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (\n unapprovedTransactions.length ||\n unapprovedTransactionBatches.length\n ) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start(): void {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop(): void {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout(): Promise<void> {\n await this.#updateUnapprovedTransactions();\n await this.#updateUnapprovedTransactionBatches();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions(): Promise<void> {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransactionBatches(): Promise<void> {\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (!unapprovedTransactionBatches.length) {\n return;\n }\n\n log(\n 'Found unapproved transaction batches',\n unapprovedTransactionBatches.length,\n );\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactionBatches,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactionBatches.flatMap((txBatch) => {\n const { chainId } = txBatch;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransactionBatch(\n txBatch,\n gasFeeControllerData,\n );\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateUnapprovedTransactionBatch(\n txBatchMeta: TransactionBatchMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = txBatchMeta;\n\n const defaultGasFeeFlow = new DefaultGasFeeFlow();\n const request: GasFeeFlowRequest = {\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta: {\n ...txBatchMeta,\n txParams: {\n ...txBatchMeta.transactions?.[0],\n from: txBatchMeta.from,\n gas: txBatchMeta.gas,\n },\n time: Date.now(),\n },\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n try {\n const response = await defaultGasFeeFlow.getGasFees(request);\n\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get gas fees for batch', txBatchMeta.id, error);\n }\n\n if (!gasFeeEstimates) {\n return;\n }\n\n this.hub.emit('transaction-batch-updated', {\n transactionBatchId: id,\n gasFeeEstimates,\n gasFeeEstimatesLoaded: true,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n #getUnapprovedTransactionBatches(): TransactionBatchMeta[] {\n return this.#getTransactionBatches().filter(\n (batch) => batch.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[] | TransactionBatchMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n getNetworkClientId({ messenger: this.#messenger, chainId });\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Updates gas properties for transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function updateTransactionGasProperties({\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n txMeta,\n}: {\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n txMeta: TransactionMeta;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (\n shouldUpdateTxParamsGasFees &&\n isUsingGasFeeEstimateLevel &&\n gasFeeEstimates\n ) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txMeta.txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.userFeeLevel - The user fee level.\n */\nexport function updateTransactionGasEstimates({\n txMeta,\n userFeeLevel,\n}: {\n txMeta: TransactionMeta;\n userFeeLevel: GasFeeEstimateLevel;\n}): void {\n const { txParams, gasFeeEstimates } = txMeta;\n\n if (!gasFeeEstimates) {\n return;\n }\n\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n}\n\n/**\n * Updates gas fee parameters based on transaction type and gas estimate type\n *\n * @param txParams - The transaction parameters to update\n * @param gasFeeEstimates - The gas fee estimates\n * @param userFeeLevel - The user fee level\n * @param isEIP1559Compatible - Whether the transaction is EIP-1559 compatible\n */\nfunction updateGasFeeParameters(\n txParams: TransactionParams,\n gasFeeEstimates: GasFeeEstimates,\n userFeeLevel: GasFeeEstimateLevel,\n isEIP1559Compatible: boolean,\n): void {\n const { type: gasEstimateType } = gasFeeEstimates;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n txParams.maxFeePerGas = gasPrice;\n txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txParams.maxFeePerGas;\n delete txParams.maxPriorityFeePerGas;\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
3
- import type { NetworkClientId, Provider } from "@metamask/network-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
4
  import EventEmitter from "events";
6
5
  import type { TransactionControllerMessenger } from "../TransactionController.cjs";
@@ -16,21 +15,17 @@ export declare class GasFeePoller {
16
15
  * Constructs a new instance of the GasFeePoller.
17
16
  *
18
17
  * @param options - The options for this instance.
19
- * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
20
18
  * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
21
19
  * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
22
- * @param options.getProvider - Callback to obtain a provider instance.
23
20
  * @param options.getTransactions - Callback to obtain the transaction data.
24
21
  * @param options.getTransactionBatches - Callback to obtain the transaction batch data.
25
22
  * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
26
23
  * @param options.messenger - The TransactionControllerMessenger instance.
27
24
  * @param options.onStateChange - Callback to register a listener for controller state changes.
28
25
  */
29
- constructor({ findNetworkClientIdByChainId, gasFeeFlows, getGasFeeControllerEstimates, getProvider, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }: {
30
- findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
26
+ constructor({ gasFeeFlows, getGasFeeControllerEstimates, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }: {
31
27
  gasFeeFlows: GasFeeFlow[];
32
28
  getGasFeeControllerEstimates: (options: FetchGasFeeEstimateOptions) => Promise<GasFeeState>;
33
- getProvider: (networkClientId: NetworkClientId) => Provider;
34
29
  getTransactions: () => TransactionMeta[];
35
30
  getTransactionBatches: () => TransactionBatchMeta[];
36
31
  layer1GasFeeFlows: Layer1GasFeeFlow[];
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.d.cts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,YAAY,eAAe;AAIlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAEV,gBAAgB,EAChB,eAAe,EAEf,oBAAoB,EACrB,qBAAiB;AAClB,OAAO,EACL,mBAAmB,EAIpB,qBAAiB;AAQlB;;GAEG;AACH,qBAAa,YAAY;;IACvB,GAAG,EAAE,YAAY,CAAsB;IA0BvC;;;;;;;;;;;;;OAaG;gBACS,EACV,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EACT,aAAa,GACd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AAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,IAAI,CAgBP"}
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
3
- import type { NetworkClientId, Provider } from "@metamask/network-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
4
  import EventEmitter from "events";
6
5
  import type { TransactionControllerMessenger } from "../TransactionController.mjs";
@@ -16,21 +15,17 @@ export declare class GasFeePoller {
16
15
  * Constructs a new instance of the GasFeePoller.
17
16
  *
18
17
  * @param options - The options for this instance.
19
- * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
20
18
  * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
21
19
  * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
22
- * @param options.getProvider - Callback to obtain a provider instance.
23
20
  * @param options.getTransactions - Callback to obtain the transaction data.
24
21
  * @param options.getTransactionBatches - Callback to obtain the transaction batch data.
25
22
  * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
26
23
  * @param options.messenger - The TransactionControllerMessenger instance.
27
24
  * @param options.onStateChange - Callback to register a listener for controller state changes.
28
25
  */
29
- constructor({ findNetworkClientIdByChainId, gasFeeFlows, getGasFeeControllerEstimates, getProvider, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }: {
30
- findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
26
+ constructor({ gasFeeFlows, getGasFeeControllerEstimates, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }: {
31
27
  gasFeeFlows: GasFeeFlow[];
32
28
  getGasFeeControllerEstimates: (options: FetchGasFeeEstimateOptions) => Promise<GasFeeState>;
33
- getProvider: (networkClientId: NetworkClientId) => Provider;
34
29
  getTransactions: () => TransactionMeta[];
35
30
  getTransactionBatches: () => TransactionBatchMeta[];
36
31
  layer1GasFeeFlows: Lay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e,EAAE,MAAM,eAAe,EAAE,CAAC;QACzC,qBAAqB,EAAE,MAAM,oBAAoB,EAAE,CAAC;QACpD,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;QACtC,SAAS,EAAE,8BAA8B,CAAC;QAC1C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;KAC/C;CA6SF;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,eAAe,EACf,qBAAqB,EACrB,8BAA8B,EAC9B,YAAY,EACZ,MAAM,GACP,EAAE;IACD,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8BAA8B,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC;IAC9E,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;CACzB,GAAG,IAAI,CAiCP;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,MAAM,EACN,YAAY,GACb,EAAE;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,IAAI,CAgBP"}
@@ -9,15 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _GasFeePoller_instances, _GasFeePoller_findNetworkClientIdByChainId, _GasFeePoller_gasFeeFlows, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getProvider, _GasFeePoller_getTransactions, _GasFeePoller_getTransactionBatches, _GasFeePoller_layer1GasFeeFlows, _GasFeePoller_messenger, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateUnapprovedTransactionBatches, _GasFeePoller_updateUnapprovedTransaction, _GasFeePoller_updateUnapprovedTransactionBatch, _GasFeePoller_updateTransactionGasFeeEstimates, _GasFeePoller_updateTransactionLayer1GasFee, _GasFeePoller_getUnapprovedTransactions, _GasFeePoller_getUnapprovedTransactionBatches, _GasFeePoller_getGasFeeControllerData;
13
- function $importDefault(module) {
14
- if (module?.__esModule) {
15
- return module.default;
16
- }
17
- return module;
18
- }
19
- import $EthQuery from "@metamask/eth-query";
20
- const EthQuery = $importDefault($EthQuery);
12
+ var _GasFeePoller_instances, _GasFeePoller_gasFeeFlows, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getTransactions, _GasFeePoller_getTransactionBatches, _GasFeePoller_layer1GasFeeFlows, _GasFeePoller_messenger, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateUnapprovedTransactionBatches, _GasFeePoller_updateUnapprovedTransaction, _GasFeePoller_updateUnapprovedTransactionBatch, _GasFeePoller_updateTransactionGasFeeEstimates, _GasFeePoller_updateTransactionLayer1GasFee, _GasFeePoller_getUnapprovedTransactions, _GasFeePoller_getUnapprovedTransactionBatches, _GasFeePoller_getGasFeeControllerData;
21
13
  import { createModuleLogger } from "@metamask/utils";
22
14
  // This package purposefully relies on Node's EventEmitter module.
23
15
  // eslint-disable-next-line import-x/no-nodejs-modules
@@ -27,6 +19,7 @@ import { projectLogger } from "../logger.mjs";
27
19
  import { GasFeeEstimateLevel, GasFeeEstimateType, TransactionStatus, TransactionEnvelopeType } from "../types.mjs";
28
20
  import { getGasFeeFlow } from "../utils/gas-flow.mjs";
29
21
  import { getTransactionLayer1GasFee } from "../utils/layer1-gas-fee-flow.mjs";
22
+ import { getNetworkClientId } from "../utils/provider.mjs";
30
23
  const log = createModuleLogger(projectLogger, 'gas-fee-poller');
31
24
  const INTERVAL_MILLISECONDS = 10000;
32
25
  /**
@@ -37,34 +30,28 @@ export class GasFeePoller {
37
30
  * Constructs a new instance of the GasFeePoller.
38
31
  *
39
32
  * @param options - The options for this instance.
40
- * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
41
33
  * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
42
34
  * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
43
- * @param options.getProvider - Callback to obtain a provider instance.
44
35
  * @param options.getTransactions - Callback to obtain the transaction data.
45
36
  * @param options.getTransactionBatches - Callback to obtain the transaction batch data.
46
37
  * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
47
38
  * @param options.messenger - The TransactionControllerMessenger instance.
48
39
  * @param options.onStateChange - Callback to register a listener for controller state changes.
49
40
  */
50
- constructor({ findNetworkClientIdByChainId, gasFeeFlows, getGasFeeControllerEstimates, getProvider, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }) {
41
+ constructor({ gasFeeFlows, getGasFeeControllerEstimates, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }) {
51
42
  _GasFeePoller_instances.add(this);
52
43
  this.hub = new EventEmitter();
53
- _GasFeePoller_findNetworkClientIdByChainId.set(this, void 0);
54
44
  _GasFeePoller_gasFeeFlows.set(this, void 0);
55
45
  _GasFeePoller_getGasFeeControllerEstimates.set(this, void 0);
56
- _GasFeePoller_getProvider.set(this, void 0);
57
46
  _GasFeePoller_getTransactions.set(this, void 0);
58
47
  _GasFeePoller_getTransactionBatches.set(this, void 0);
59
48
  _GasFeePoller_layer1GasFeeFlows.set(this, void 0);
60
49
  _GasFeePoller_messenger.set(this, void 0);
61
50
  _GasFeePoller_timeout.set(this, void 0);
62
51
  _GasFeePoller_running.set(this, false);
63
- __classPrivateFieldSet(this, _GasFeePoller_findNetworkClientIdByChainId, findNetworkClientIdByChainId, "f");
64
52
  __classPrivateFieldSet(this, _GasFeePoller_gasFeeFlows, gasFeeFlows, "f");
65
53
  __classPrivateFieldSet(this, _GasFeePoller_layer1GasFeeFlows, layer1GasFeeFlows, "f");
66
54
  __classPrivateFieldSet(this, _GasFeePoller_getGasFeeControllerEstimates, getGasFeeControllerEstimates, "f");
67
- __classPrivateFieldSet(this, _GasFeePoller_getProvider, getProvider, "f");
68
55
  __classPrivateFieldSet(this, _GasFeePoller_getTransactions, getTransactions, "f");
69
56
  __classPrivateFieldSet(this, _GasFeePoller_getTransactionBatches, getTransactionBatches, "f");
70
57
  __classPrivateFieldSet(this, _GasFeePoller_messenger, messenger, "f");
@@ -81,7 +68,7 @@ export class GasFeePoller {
81
68
  });
82
69
  }
83
70
  }
84
- _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEstimates = new WeakMap(), _GasFeePoller_getProvider = new WeakMap(), _GasFeePoller_getTransactions = new WeakMap(), _GasFeePoller_getTransactionBatches = new WeakMap(), _GasFeePoller_layer1GasFeeFlows = new WeakMap(), _GasFeePoller_messenger = new WeakMap(), _GasFeePoller_timeout = new WeakMap(), _GasFeePoller_running = new WeakMap(), _GasFeePoller_instances = new WeakSet(), _GasFeePoller_start = function _GasFeePoller_start() {
71
+ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEstimates = new WeakMap(), _GasFeePoller_getTransactions = new WeakMap(), _GasFeePoller_getTransactionBatches = new WeakMap(), _GasFeePoller_layer1GasFeeFlows = new WeakMap(), _GasFeePoller_messenger = new WeakMap(), _GasFeePoller_timeout = new WeakMap(), _GasFeePoller_running = new WeakMap(), _GasFeePoller_instances = new WeakSet(), _GasFeePoller_start = function _GasFeePoller_start() {
85
72
  if (__classPrivateFieldGet(this, _GasFeePoller_running, "f")) {
86
73
  return;
87
74
  }
@@ -146,10 +133,8 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
146
133
  });
147
134
  }, _GasFeePoller_updateUnapprovedTransactionBatch = async function _GasFeePoller_updateUnapprovedTransactionBatch(txBatchMeta, gasFeeControllerData) {
148
135
  const { id } = txBatchMeta;
149
- const ethQuery = new EthQuery(__classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, txBatchMeta.networkClientId));
150
136
  const defaultGasFeeFlow = new DefaultGasFeeFlow();
151
137
  const request = {
152
- ethQuery,
153
138
  gasFeeControllerData,
154
139
  messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
155
140
  transactionMeta: {
@@ -179,14 +164,11 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
179
164
  gasFeeEstimatesLoaded: true,
180
165
  });
181
166
  }, _GasFeePoller_updateTransactionGasFeeEstimates = async function _GasFeePoller_updateTransactionGasFeeEstimates(transactionMeta, gasFeeControllerData) {
182
- const { networkClientId } = transactionMeta;
183
- const ethQuery = new EthQuery(__classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, networkClientId));
184
167
  const gasFeeFlow = getGasFeeFlow(transactionMeta, __classPrivateFieldGet(this, _GasFeePoller_gasFeeFlows, "f"), __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"));
185
168
  if (gasFeeFlow) {
186
169
  log('Found gas fee flow', gasFeeFlow.constructor.name, transactionMeta.id);
187
170
  }
188
171
  const request = {
189
- ethQuery,
190
172
  gasFeeControllerData,
191
173
  messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
192
174
  transactionMeta,
@@ -210,12 +192,9 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
210
192
  });
211
193
  return { gasFeeEstimates, gasFeeEstimatesLoaded: true };
212
194
  }, _GasFeePoller_updateTransactionLayer1GasFee = async function _GasFeePoller_updateTransactionLayer1GasFee(transactionMeta) {
213
- const { networkClientId } = transactionMeta;
214
- const provider = __classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, networkClientId);
215
195
  const layer1GasFee = await getTransactionLayer1GasFee({
216
196
  layer1GasFeeFlows: __classPrivateFieldGet(this, _GasFeePoller_layer1GasFeeFlows, "f"),
217
197
  messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
218
- provider,
219
198
  transactionMeta,
220
199
  });
221
200
  if (layer1GasFee) {
@@ -234,7 +213,7 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
234
213
  continue;
235
214
  }
236
215
  const networkClientId = transactionNetworkClientId ??
237
- __classPrivateFieldGet(this, _GasFeePoller_findNetworkClientIdByChainId, "f").call(this, chainId);
216
+ getNetworkClientId({ messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"), chainId });
238
217
  networkClientIdsByChainId.set(chainId, networkClientId);
239
218
  }
240
219
  log('Extracted network client IDs by chain ID', networkClientIdsByChainId);
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.mjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAQ,4BAA4B;;AAO3C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,iBAAiB,EAAE,2CAAuC;AACnE,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAW1C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,8BAA0B;AAClD,OAAO,EAAE,0BAA0B,EAAE,yCAAqC;AAE1E,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IA2BvB;;;;;;;;;;;;;O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AAQ,CAAC;QACnE,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,MAAM,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;YACrD,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC;YACjC,QAAQ,CAAC,oBAAoB,GAAG,QAAQ,CAAC;QAC3C,CAAC;QAED,4CAA4C;QAC5C,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,mCAAmC;QACnC,IAAI,eAAe,KAAK,kBAAkB,CAAC,SAAS,EAAE,CAAC;YACrD,MAAM,wBAAwB,GAAG,eAAe,CAAC;YACjD,QAAQ,CAAC,QAAQ,GAAG,wBAAwB,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;QAC3E,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YACpD,MAAM,uBAAuB,GAAG,eAAe,CAAC;YAChD,QAAQ,CAAC,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QACvD,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;QAED,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,YAAY,CAAC;QAC7B,OAAO,QAAQ,CAAC,oBAAoB,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { DefaultGasFeeFlow } from '../gas-flows/DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n TransactionMeta,\n TransactionParams,\n TransactionBatchMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #getTransactionBatches: () => TransactionBatchMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.getTransactionBatches - Callback to obtain the transaction batch data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n getTransactionBatches,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n getTransactionBatches: () => TransactionBatchMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n this.#getTransactionBatches = getTransactionBatches;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (\n unapprovedTransactions.length ||\n unapprovedTransactionBatches.length\n ) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start(): void {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop(): void {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout(): Promise<void> {\n await this.#updateUnapprovedTransactions();\n await this.#updateUnapprovedTransactionBatches();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions(): Promise<void> {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransactionBatches(): Promise<void> {\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (!unapprovedTransactionBatches.length) {\n return;\n }\n\n log(\n 'Found unapproved transaction batches',\n unapprovedTransactionBatches.length,\n );\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactionBatches,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactionBatches.flatMap((txBatch) => {\n const { chainId } = txBatch;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransactionBatch(\n txBatch,\n gasFeeControllerData,\n );\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateUnapprovedTransactionBatch(\n txBatchMeta: TransactionBatchMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = txBatchMeta;\n\n const ethQuery = new EthQuery(\n this.#getProvider(txBatchMeta.networkClientId),\n );\n const defaultGasFeeFlow = new DefaultGasFeeFlow();\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta: {\n ...txBatchMeta,\n txParams: {\n ...txBatchMeta.transactions?.[0],\n from: txBatchMeta.from,\n gas: txBatchMeta.gas,\n },\n time: Date.now(),\n },\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n try {\n const response = await defaultGasFeeFlow.getGasFees(request);\n\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get gas fees for batch', txBatchMeta.id, error);\n }\n\n if (!gasFeeEstimates) {\n return;\n }\n\n this.hub.emit('transaction-batch-updated', {\n transactionBatchId: id,\n gasFeeEstimates,\n gasFeeEstimatesLoaded: true,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(networkClientId));\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { networkClientId } = transactionMeta;\n const provider = this.#getProvider(networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n #getUnapprovedTransactionBatches(): TransactionBatchMeta[] {\n return this.#getTransactionBatches().filter(\n (batch) => batch.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[] | TransactionBatchMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Updates gas properties for transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function updateTransactionGasProperties({\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n txMeta,\n}: {\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n txMeta: TransactionMeta;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (\n shouldUpdateTxParamsGasFees &&\n isUsingGasFeeEstimateLevel &&\n gasFeeEstimates\n ) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txMeta.txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.userFeeLevel - The user fee level.\n */\nexport function updateTransactionGasEstimates({\n txMeta,\n userFeeLevel,\n}: {\n txMeta: TransactionMeta;\n userFeeLevel: GasFeeEstimateLevel;\n}): void {\n const { txParams, gasFeeEstimates } = txMeta;\n\n if (!gasFeeEstimates) {\n return;\n }\n\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n}\n\n/**\n * Updates gas fee parameters based on transaction type and gas estimate type\n *\n * @param txParams - The transaction parameters to update\n * @param gasFeeEstimates - The gas fee estimates\n * @param userFeeLevel - The user fee level\n * @param isEIP1559Compatible - Whether the transaction is EIP-1559 compatible\n */\nfunction updateGasFeeParameters(\n txParams: TransactionParams,\n gasFeeEstimates: GasFeeEstimates,\n userFeeLevel: GasFeeEstimateLevel,\n isEIP1559Compatible: boolean,\n): void {\n const { type: gasEstimateType } = gasFeeEstimates;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n txParams.maxFeePerGas = gasPrice;\n txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txParams.maxFeePerGas;\n delete txParams.maxPriorityFeePerGas;\n }\n}\n"]}
1
+ {"version":3,"file":"GasFeePoller.mjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,iBAAiB,EAAE,2CAAuC;AACnE,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAW1C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,8BAA0B;AAClD,OAAO,EAAE,0BAA0B,EAAE,yCAAqC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,8BAA0B;AAEvD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,YAAY;IAqBvB;;;;;;;;;;;OAWG;IAC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BAAkB,CAAC,QAAQ,EAAE,CAAC;YACpD,MAAM,uBAAuB,GAAG,eAAe,CAAC;YAChD,QAAQ,CAAC,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QACvD,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAClD,MAAM,qBAAqB,GAAG,eAAe,CAAC;YAC9C,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;QAED,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,YAAY,CAAC;QAC7B,OAAO,QAAQ,CAAC,oBAAoB,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { DefaultGasFeeFlow } from '../gas-flows/DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n TransactionMeta,\n TransactionParams,\n TransactionBatchMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\nimport { getNetworkClientId } from '../utils/provider';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #getTransactionBatches: () => TransactionBatchMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n readonly #messenger: TransactionControllerMessenger;\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.getTransactionBatches - Callback to obtain the transaction batch data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.messenger - The TransactionControllerMessenger instance.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getTransactions,\n getTransactionBatches,\n layer1GasFeeFlows,\n messenger,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getTransactions: () => TransactionMeta[];\n getTransactionBatches: () => TransactionBatchMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n onStateChange: (listener: () => void) => void;\n }) {\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getTransactions = getTransactions;\n this.#getTransactionBatches = getTransactionBatches;\n this.#messenger = messenger;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (\n unapprovedTransactions.length ||\n unapprovedTransactionBatches.length\n ) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start(): void {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop(): void {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout(): Promise<void> {\n await this.#updateUnapprovedTransactions();\n await this.#updateUnapprovedTransactionBatches();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions(): Promise<void> {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransactionBatches(): Promise<void> {\n const unapprovedTransactionBatches =\n this.#getUnapprovedTransactionBatches();\n\n if (!unapprovedTransactionBatches.length) {\n return;\n }\n\n log(\n 'Found unapproved transaction batches',\n unapprovedTransactionBatches.length,\n );\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactionBatches,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactionBatches.flatMap((txBatch) => {\n const { chainId } = txBatch;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransactionBatch(\n txBatch,\n gasFeeControllerData,\n );\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateUnapprovedTransactionBatch(\n txBatchMeta: TransactionBatchMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<void> {\n const { id } = txBatchMeta;\n\n const defaultGasFeeFlow = new DefaultGasFeeFlow();\n const request: GasFeeFlowRequest = {\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta: {\n ...txBatchMeta,\n txParams: {\n ...txBatchMeta.transactions?.[0],\n from: txBatchMeta.from,\n gas: txBatchMeta.gas,\n },\n time: Date.now(),\n },\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n try {\n const response = await defaultGasFeeFlow.getGasFees(request);\n\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get gas fees for batch', txBatchMeta.id, error);\n }\n\n if (!gasFeeEstimates) {\n return;\n }\n\n this.hub.emit('transaction-batch-updated', {\n transactionBatchId: id,\n gasFeeEstimates,\n gasFeeEstimatesLoaded: true,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const gasFeeFlow = getGasFeeFlow(\n transactionMeta,\n this.#gasFeeFlows,\n this.#messenger,\n );\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n gasFeeControllerData,\n messenger: this.#messenger,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n messenger: this.#messenger,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n #getUnapprovedTransactionBatches(): TransactionBatchMeta[] {\n return this.#getTransactionBatches().filter(\n (batch) => batch.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[] | TransactionBatchMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n getNetworkClientId({ messenger: this.#messenger, chainId });\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Updates gas properties for transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport function updateTransactionGasProperties({\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n txMeta,\n}: {\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: (transactionMeta: TransactionMeta) => boolean;\n layer1GasFee?: Hex;\n txMeta: TransactionMeta;\n}): void {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);\n\n if (\n shouldUpdateTxParamsGasFees &&\n isUsingGasFeeEstimateLevel &&\n gasFeeEstimates\n ) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txMeta.txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Updates `txParams` gas values accordingly with given `userFeeLevel` from `txMeta.gasFeeEstimates`.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.userFeeLevel - The user fee level.\n */\nexport function updateTransactionGasEstimates({\n txMeta,\n userFeeLevel,\n}: {\n txMeta: TransactionMeta;\n userFeeLevel: GasFeeEstimateLevel;\n}): void {\n const { txParams, gasFeeEstimates } = txMeta;\n\n if (!gasFeeEstimates) {\n return;\n }\n\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy;\n\n updateGasFeeParameters(\n txParams,\n gasFeeEstimates,\n userFeeLevel,\n isEIP1559Compatible,\n );\n}\n\n/**\n * Updates gas fee parameters based on transaction type and gas estimate type\n *\n * @param txParams - The transaction parameters to update\n * @param gasFeeEstimates - The gas fee estimates\n * @param userFeeLevel - The user fee level\n * @param isEIP1559Compatible - Whether the transaction is EIP-1559 compatible\n */\nfunction updateGasFeeParameters(\n txParams: TransactionParams,\n gasFeeEstimates: GasFeeEstimates,\n userFeeLevel: GasFeeEstimateLevel,\n isEIP1559Compatible: boolean,\n): void {\n const { type: gasEstimateType } = gasFeeEstimates;\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n txParams.maxFeePerGas = gasPrice;\n txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates;\n txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txParams.maxFeePerGas;\n delete txParams.maxPriorityFeePerGas;\n }\n}\n"]}
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _MethodDataHelper_instances, _MethodDataHelper_getProvider, _MethodDataHelper_getState, _MethodDataHelper_methodRegistryByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_registryLookup;
16
+ var _MethodDataHelper_instances, _MethodDataHelper_getState, _MethodDataHelper_messenger, _MethodDataHelper_methodRegistryByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_registryLookup;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MethodDataHelper = void 0;
19
19
  const utils_1 = require("@metamask/utils");
@@ -23,16 +23,17 @@ const eth_method_registry_1 = require("eth-method-registry");
23
23
  // eslint-disable-next-line import-x/no-nodejs-modules
24
24
  const events_1 = __importDefault(require("events"));
25
25
  const logger_1 = require("../logger.cjs");
26
+ const provider_1 = require("../utils/provider.cjs");
26
27
  const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'method-data');
27
28
  class MethodDataHelper {
28
- constructor({ getProvider, getState, }) {
29
+ constructor({ messenger, getState, }) {
29
30
  _MethodDataHelper_instances.add(this);
30
- _MethodDataHelper_getProvider.set(this, void 0);
31
31
  _MethodDataHelper_getState.set(this, void 0);
32
+ _MethodDataHelper_messenger.set(this, void 0);
32
33
  _MethodDataHelper_methodRegistryByNetworkClientId.set(this, void 0);
33
34
  _MethodDataHelper_mutex.set(this, new async_mutex_1.Mutex());
34
35
  this.hub = new events_1.default();
35
- __classPrivateFieldSet(this, _MethodDataHelper_getProvider, getProvider, "f");
36
+ __classPrivateFieldSet(this, _MethodDataHelper_messenger, messenger, "f");
36
37
  __classPrivateFieldSet(this, _MethodDataHelper_getState, getState, "f");
37
38
  __classPrivateFieldSet(this, _MethodDataHelper_methodRegistryByNetworkClientId, new Map(), "f");
38
39
  }
@@ -47,7 +48,10 @@ class MethodDataHelper {
47
48
  }
48
49
  let registry = __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").get(networkClientId);
49
50
  if (!registry) {
50
- const provider = __classPrivateFieldGet(this, _MethodDataHelper_getProvider, "f").call(this, networkClientId);
51
+ const provider = (0, provider_1.getProvider)({
52
+ messenger: __classPrivateFieldGet(this, _MethodDataHelper_messenger, "f"),
53
+ networkClientId,
54
+ });
51
55
  // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed
52
56
  registry = new eth_method_registry_1.MethodRegistry({ provider });
53
57
  __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").set(networkClientId, registry);
@@ -64,7 +68,7 @@ class MethodDataHelper {
64
68
  }
65
69
  }
66
70
  exports.MethodDataHelper = MethodDataHelper;
67
- _MethodDataHelper_getProvider = new WeakMap(), _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_methodRegistryByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_registryLookup = async function _MethodDataHelper_registryLookup(fourBytePrefix, methodRegistry) {
71
+ _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_messenger = new WeakMap(), _MethodDataHelper_methodRegistryByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_registryLookup = async function _MethodDataHelper_registryLookup(fourBytePrefix, methodRegistry) {
68
72
  const registryMethod = await methodRegistry.lookup(fourBytePrefix);
69
73
  if (!registryMethod) {
70
74
  log('No method found', fourBytePrefix);
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.cjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,2CAAqD;AACrD,6CAAoC;AACpC,6DAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAa,gBAAgB;IAc3B,YAAY,EACV,WAAW,EACX,QAAQ,GAIT;;QAjBQ,gDAA6D;QAE7D,6CAA4C;QAE5C,oEAGP;QAEO,kCAAS,IAAI,mBAAK,EAAE,EAAC;QAS5B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAY,EAAE,CAAC;QAE9B,uBAAA,IAAI,iCAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,8BAAa,QAAQ,MAAA,CAAC;QAC1B,uBAAA,IAAI,qDAAoC,IAAI,GAAG,EAAE,MAAA,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,MAAM,CACV,cAAsB,EACtB,eAAgC;QAEhC,GAAG,CAAC,QAAQ,EAAE,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c,CAAC,CAAC;IAEnE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAEvC,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3D,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/B,MAAM,oBAAoB,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport { MethodRegistry } from 'eth-method-registry';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { MethodData } from '../TransactionController';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getState: () => Record<string, MethodData>;\n\n readonly #methodRegistryByNetworkClientId: Map<\n NetworkClientId,\n MethodRegistry\n >;\n\n readonly #mutex = new Mutex();\n\n constructor({\n getProvider,\n getState,\n }: {\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getState: () => Record<string, MethodData>;\n }) {\n this.hub = new EventEmitter();\n\n this.#getProvider = getProvider;\n this.#getState = getState;\n this.#methodRegistryByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let registry = this.#methodRegistryByNetworkClientId.get(networkClientId);\n\n if (!registry) {\n const provider = this.#getProvider(networkClientId);\n\n // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed\n registry = new MethodRegistry({ provider });\n\n this.#methodRegistryByNetworkClientId.set(networkClientId, registry);\n\n log('Created registry', networkClientId);\n }\n\n const methodData = await this.#registryLookup(fourBytePrefix, registry);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #registryLookup(\n fourBytePrefix: string,\n methodRegistry: MethodRegistry,\n ): Promise<MethodData> {\n const registryMethod = await methodRegistry.lookup(fourBytePrefix);\n\n if (!registryMethod) {\n log('No method found', fourBytePrefix);\n\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n\n log('Parsing', registryMethod);\n\n const parsedRegistryMethod = methodRegistry.parse(registryMethod);\n\n return { registryMethod, parsedRegistryMethod };\n }\n}\n"]}
1
+ {"version":3,"file":"MethodDataHelper.cjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,2CAAqD;AACrD,6CAAoC;AACpC,6DAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA0C;AAK1C,oDAAgD;AAEhD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAa,gBAAgB;IAc3B,YAAY,EACV,SAAS,EACT,QAAQ,GAIT;;QAjBQ,6CAA4C;QAE5C,8CAA2C;QAE3C,oEAGP;QAEO,kCAAS,IAAI,mBAAK,EAAE,EAAC;QAS5B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAY,EAAE,CAAC;QAE9B,uBAAA,IAAI,+BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,8BAAa,QA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AAU,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;CAuBF;AA7FD,4CA6FC;qRArBC,KAAK,2CACH,cAAsB,EACtB,cAA8B;IAE9B,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAEvC,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3D,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/B,MAAM,oBAAoB,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport { MethodRegistry } from 'eth-method-registry';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n MethodData,\n TransactionControllerMessenger,\n} from '../TransactionController';\nimport { getProvider } from '../utils/provider';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n readonly #getState: () => Record<string, MethodData>;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #methodRegistryByNetworkClientId: Map<\n NetworkClientId,\n MethodRegistry\n >;\n\n readonly #mutex = new Mutex();\n\n constructor({\n messenger,\n getState,\n }: {\n messenger: TransactionControllerMessenger;\n getState: () => Record<string, MethodData>;\n }) {\n this.hub = new EventEmitter();\n\n this.#messenger = messenger;\n this.#getState = getState;\n this.#methodRegistryByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let registry = this.#methodRegistryByNetworkClientId.get(networkClientId);\n\n if (!registry) {\n const provider = getProvider({\n messenger: this.#messenger,\n networkClientId,\n });\n\n // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed\n registry = new MethodRegistry({ provider });\n\n this.#methodRegistryByNetworkClientId.set(networkClientId, registry);\n\n log('Created registry', networkClientId);\n }\n\n const methodData = await this.#registryLookup(fourBytePrefix, registry);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #registryLookup(\n fourBytePrefix: string,\n methodRegistry: MethodRegistry,\n ): Promise<MethodData> {\n const registryMethod = await methodRegistry.lookup(fourBytePrefix);\n\n if (!registryMethod) {\n log('No method found', fourBytePrefix);\n\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n\n log('Parsing', registryMethod);\n\n const parsedRegistryMethod = methodRegistry.parse(registryMethod);\n\n return { registryMethod, parsedRegistryMethod };\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
- import type { NetworkClientId, Provider } from "@metamask/network-controller";
2
+ import type { NetworkClientId } from "@metamask/network-controller";
3
3
  import EventEmitter from "events";
4
- import type { MethodData } from "../TransactionController.cjs";
4
+ import type { MethodData, TransactionControllerMessenger } from "../TransactionController.cjs";
5
5
  export declare class MethodDataHelper {
6
6
  #private;
7
7
  hub: EventEmitter;
8
- constructor({ getProvider, getState, }: {
9
- getProvider: (networkClientId: NetworkClientId) => Provider;
8
+ constructor({ messenger, getState, }: {
9
+ messenger: TransactionControllerMessenger;
10
10
  getState: () => Record<string, MethodData>;
11
11
  });
12
12
  lookup(fourBytePrefix: string, networkClientId: NetworkClientId): Promise<MethodData>;
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAM9E,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AAI3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAaN,EACV,WAAW,EACX,QAAQ,GACT,EAAE;QACD,WAAW,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,QAAQ,CAAC;QAC5D,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA2DvB"}
1
+ {"version":3,"file":"MethodDataHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAMpE,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EACV,UAAU,EACV,8BAA8B,EAC/B,qCAAiC;AAKlC,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAaN,EACV,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA8DvB"}
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
- import type { NetworkClientId, Provider } from "@metamask/network-controller";
2
+ import type { NetworkClientId } from "@metamask/network-controller";
3
3
  import EventEmitter from "events";
4
- import type { MethodData } from "../TransactionController.mjs";
4
+ import type { MethodData, TransactionControllerMessenger } from "../TransactionController.mjs";
5
5
  export declare class MethodDataHelper {
6
6
  #private;
7
7
  hub: EventEmitter;
8
- constructor({ getProvider, getState, }: {
9
- getProvider: (networkClientId: NetworkClientId) => Provider;
8
+ constructor({ messenger, getState, }: {
9
+ messenger: TransactionControllerMessenger;
10
10
  getState: () => Record<string, MethodData>;
11
11
  });
12
12
  lookup(fourBytePrefix: string, networkClientId: NetworkClientId): Promise<MethodData>;
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAM9E,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AAI3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAaN,EACV,WAAW,EACX,QAAQ,GACT,EAAE;QACD,WAAW,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,QAAQ,CAAC;QAC5D,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA2DvB"}
1
+ {"version":3,"file":"MethodDataHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAMpE,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EACV,UAAU,EACV,8BAA8B,EAC/B,qCAAiC;AAKlC,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAaN,EACV,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA8DvB"}