@metamask-previews/transaction-controller 69.2.1-preview-064aea96d → 69.2.1-preview-ec4680201

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 (229) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/TransactionController-method-action-types.cjs.map +1 -1
  3. package/dist/TransactionController-method-action-types.d.cts.map +1 -1
  4. package/dist/TransactionController-method-action-types.d.mts.map +1 -1
  5. package/dist/TransactionController-method-action-types.mjs.map +1 -1
  6. package/dist/TransactionController.cjs +205 -205
  7. package/dist/TransactionController.cjs.map +1 -1
  8. package/dist/TransactionController.d.cts.map +1 -1
  9. package/dist/TransactionController.d.mts.map +1 -1
  10. package/dist/TransactionController.mjs +1 -1
  11. package/dist/TransactionController.mjs.map +1 -1
  12. package/dist/api/accounts-api.cjs +5 -5
  13. package/dist/api/accounts-api.cjs.map +1 -1
  14. package/dist/api/accounts-api.mjs.map +1 -1
  15. package/dist/api/simulation-api.cjs +8 -8
  16. package/dist/api/simulation-api.cjs.map +1 -1
  17. package/dist/api/simulation-api.d.cts.map +1 -1
  18. package/dist/api/simulation-api.d.mts.map +1 -1
  19. package/dist/api/simulation-api.mjs.map +1 -1
  20. package/dist/errors.cjs +4 -4
  21. package/dist/errors.cjs.map +1 -1
  22. package/dist/errors.mjs.map +1 -1
  23. package/dist/gas-flows/DefaultGasFeeFlow.cjs +13 -13
  24. package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -1
  25. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -1
  26. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -1
  27. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
  28. package/dist/gas-flows/LineaGasFeeFlow.cjs +10 -10
  29. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  30. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  31. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  32. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  33. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +8 -8
  34. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -1
  35. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -1
  36. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -1
  37. package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -1
  38. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +10 -10
  39. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
  40. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
  41. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
  42. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  43. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +10 -10
  44. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -1
  45. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -1
  46. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -1
  47. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
  48. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +13 -13
  49. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -1
  50. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -1
  51. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -1
  52. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -1
  53. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +4 -4
  54. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
  55. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
  56. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
  57. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  58. package/dist/gas-flows/TestGasFeeFlow.cjs +2 -2
  59. package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -1
  60. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -1
  61. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -1
  62. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
  63. package/dist/helpers/GasFeePoller.cjs +22 -22
  64. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  65. package/dist/helpers/GasFeePoller.d.cts +2 -2
  66. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  67. package/dist/helpers/GasFeePoller.d.mts +2 -2
  68. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  69. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  70. package/dist/helpers/MethodDataHelper.cjs +4 -4
  71. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  72. package/dist/helpers/MethodDataHelper.d.cts +2 -2
  73. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  74. package/dist/helpers/MethodDataHelper.d.mts +2 -2
  75. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  76. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  77. package/dist/helpers/MultichainTrackingHelper.cjs +2 -2
  78. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  79. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  80. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  81. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  82. package/dist/helpers/PendingTransactionTracker.cjs +22 -22
  83. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  84. package/dist/helpers/PendingTransactionTracker.d.cts +2 -2
  85. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  86. package/dist/helpers/PendingTransactionTracker.d.mts +2 -2
  87. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  88. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  89. package/dist/helpers/ResimulateHelper.cjs +6 -6
  90. package/dist/helpers/ResimulateHelper.cjs.map +1 -1
  91. package/dist/helpers/ResimulateHelper.d.cts.map +1 -1
  92. package/dist/helpers/ResimulateHelper.d.mts.map +1 -1
  93. package/dist/helpers/ResimulateHelper.mjs.map +1 -1
  94. package/dist/helpers/TransactionPoller.cjs +4 -4
  95. package/dist/helpers/TransactionPoller.cjs.map +1 -1
  96. package/dist/helpers/TransactionPoller.d.cts.map +1 -1
  97. package/dist/helpers/TransactionPoller.d.mts.map +1 -1
  98. package/dist/helpers/TransactionPoller.mjs.map +1 -1
  99. package/dist/hooks/CollectPublishHook.cjs +2 -2
  100. package/dist/hooks/CollectPublishHook.cjs.map +1 -1
  101. package/dist/hooks/CollectPublishHook.d.cts.map +1 -1
  102. package/dist/hooks/CollectPublishHook.d.mts.map +1 -1
  103. package/dist/hooks/CollectPublishHook.mjs.map +1 -1
  104. package/dist/hooks/ExtraTransactionsPublishHook.cjs +2 -2
  105. package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -1
  106. package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -1
  107. package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -1
  108. package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -1
  109. package/dist/hooks/SequentialPublishBatchHook.cjs +2 -2
  110. package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
  111. package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
  112. package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
  113. package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
  114. package/dist/index.cjs +33 -33
  115. package/dist/index.cjs.map +1 -1
  116. package/dist/index.d.cts.map +1 -1
  117. package/dist/index.d.mts.map +1 -1
  118. package/dist/index.mjs.map +1 -1
  119. package/dist/types.cjs.map +1 -1
  120. package/dist/types.d.cts.map +1 -1
  121. package/dist/types.d.mts.map +1 -1
  122. package/dist/types.mjs.map +1 -1
  123. package/dist/utils/balance-changes.cjs +31 -31
  124. package/dist/utils/balance-changes.cjs.map +1 -1
  125. package/dist/utils/balance-changes.d.cts.map +1 -1
  126. package/dist/utils/balance-changes.d.mts.map +1 -1
  127. package/dist/utils/balance-changes.mjs.map +1 -1
  128. package/dist/utils/balance.cjs +2 -2
  129. package/dist/utils/balance.cjs.map +1 -1
  130. package/dist/utils/balance.d.cts.map +1 -1
  131. package/dist/utils/balance.d.mts.map +1 -1
  132. package/dist/utils/balance.mjs.map +1 -1
  133. package/dist/utils/batch.cjs +45 -45
  134. package/dist/utils/batch.cjs.map +1 -1
  135. package/dist/utils/batch.d.cts +1 -1
  136. package/dist/utils/batch.d.cts.map +1 -1
  137. package/dist/utils/batch.d.mts +1 -1
  138. package/dist/utils/batch.d.mts.map +1 -1
  139. package/dist/utils/batch.mjs +1 -1
  140. package/dist/utils/batch.mjs.map +1 -1
  141. package/dist/utils/eip7702.cjs +9 -9
  142. package/dist/utils/eip7702.cjs.map +1 -1
  143. package/dist/utils/eip7702.d.cts.map +1 -1
  144. package/dist/utils/eip7702.d.mts.map +1 -1
  145. package/dist/utils/eip7702.mjs.map +1 -1
  146. package/dist/utils/external-transactions.cjs +2 -2
  147. package/dist/utils/external-transactions.cjs.map +1 -1
  148. package/dist/utils/external-transactions.d.cts.map +1 -1
  149. package/dist/utils/external-transactions.d.mts.map +1 -1
  150. package/dist/utils/external-transactions.mjs.map +1 -1
  151. package/dist/utils/feature-flags.cjs +5 -5
  152. package/dist/utils/feature-flags.cjs.map +1 -1
  153. package/dist/utils/feature-flags.d.cts.map +1 -1
  154. package/dist/utils/feature-flags.d.mts.map +1 -1
  155. package/dist/utils/feature-flags.mjs.map +1 -1
  156. package/dist/utils/first-time-interaction.cjs +14 -14
  157. package/dist/utils/first-time-interaction.cjs.map +1 -1
  158. package/dist/utils/first-time-interaction.d.cts.map +1 -1
  159. package/dist/utils/first-time-interaction.d.mts.map +1 -1
  160. package/dist/utils/first-time-interaction.mjs.map +1 -1
  161. package/dist/utils/gas-fee-tokens.cjs +13 -13
  162. package/dist/utils/gas-fee-tokens.cjs.map +1 -1
  163. package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
  164. package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
  165. package/dist/utils/gas-fee-tokens.mjs.map +1 -1
  166. package/dist/utils/gas-fees.cjs +19 -19
  167. package/dist/utils/gas-fees.cjs.map +1 -1
  168. package/dist/utils/gas-fees.d.cts.map +1 -1
  169. package/dist/utils/gas-fees.d.mts.map +1 -1
  170. package/dist/utils/gas-fees.mjs.map +1 -1
  171. package/dist/utils/gas-flow.cjs +6 -6
  172. package/dist/utils/gas-flow.cjs.map +1 -1
  173. package/dist/utils/gas-flow.d.cts.map +1 -1
  174. package/dist/utils/gas-flow.d.mts.map +1 -1
  175. package/dist/utils/gas-flow.mjs.map +1 -1
  176. package/dist/utils/gas.cjs +27 -27
  177. package/dist/utils/gas.cjs.map +1 -1
  178. package/dist/utils/gas.d.cts.map +1 -1
  179. package/dist/utils/gas.d.mts.map +1 -1
  180. package/dist/utils/gas.mjs.map +1 -1
  181. package/dist/utils/layer1-gas-fee-flow.cjs +2 -2
  182. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  183. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  184. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  185. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  186. package/dist/utils/nonce.cjs +2 -2
  187. package/dist/utils/nonce.cjs.map +1 -1
  188. package/dist/utils/nonce.d.cts.map +1 -1
  189. package/dist/utils/nonce.d.mts.map +1 -1
  190. package/dist/utils/nonce.mjs.map +1 -1
  191. package/dist/utils/prepare.cjs.map +1 -1
  192. package/dist/utils/prepare.d.cts.map +1 -1
  193. package/dist/utils/prepare.d.mts.map +1 -1
  194. package/dist/utils/prepare.mjs.map +1 -1
  195. package/dist/utils/provider.cjs +2 -2
  196. package/dist/utils/provider.cjs.map +1 -1
  197. package/dist/utils/provider.d.cts.map +1 -1
  198. package/dist/utils/provider.d.mts.map +1 -1
  199. package/dist/utils/provider.mjs.map +1 -1
  200. package/dist/utils/retry.cjs.map +1 -1
  201. package/dist/utils/retry.d.cts.map +1 -1
  202. package/dist/utils/retry.d.mts.map +1 -1
  203. package/dist/utils/retry.mjs.map +1 -1
  204. package/dist/utils/revert-reason.cjs +4 -4
  205. package/dist/utils/revert-reason.cjs.map +1 -1
  206. package/dist/utils/revert-reason.d.cts.map +1 -1
  207. package/dist/utils/revert-reason.d.mts.map +1 -1
  208. package/dist/utils/revert-reason.mjs.map +1 -1
  209. package/dist/utils/swaps.cjs +28 -28
  210. package/dist/utils/swaps.cjs.map +1 -1
  211. package/dist/utils/swaps.d.cts.map +1 -1
  212. package/dist/utils/swaps.d.mts.map +1 -1
  213. package/dist/utils/swaps.mjs.map +1 -1
  214. package/dist/utils/transaction-type.cjs +14 -14
  215. package/dist/utils/transaction-type.cjs.map +1 -1
  216. package/dist/utils/transaction-type.d.cts.map +1 -1
  217. package/dist/utils/transaction-type.d.mts.map +1 -1
  218. package/dist/utils/transaction-type.mjs.map +1 -1
  219. package/dist/utils/utils.cjs +8 -8
  220. package/dist/utils/utils.cjs.map +1 -1
  221. package/dist/utils/utils.d.cts.map +1 -1
  222. package/dist/utils/utils.d.mts.map +1 -1
  223. package/dist/utils/utils.mjs.map +1 -1
  224. package/dist/utils/validation.cjs +11 -11
  225. package/dist/utils/validation.cjs.map +1 -1
  226. package/dist/utils/validation.d.cts.map +1 -1
  227. package/dist/utils/validation.d.mts.map +1 -1
  228. package/dist/utils/validation.mjs.map +1 -1
  229. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"RandomisedEstimationsGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEst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AkB,GAAG,oBAAoB,CAC7C,0BAA0B,EAC1B,oBAAoB,CACrB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CACrB,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAC3D,CAAC;IACF,MAAM,oBAAoB,GAAG,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GAAG,KAAK,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAElE,OAAO,IAAA,aAAK,EAAC,gBAAgB,CAAC,CAAC;AACjC,CAAC;AAzCD,kFAyCC","sourcesContent":["import type { GasFeeEstimates as FeeMarketGasPriceEstimate } from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { getGasFeeRandomisation } from '../utils/feature-flags';\nimport {\n gweiDecimalToWeiDecimal,\n gweiDecimalToWeiHex,\n} from '../utils/gas-fees';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\n\nconst log = createModuleLogger(\n projectLogger,\n 'randomised-estimation-gas-fee-flow',\n);\n\nconst DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;\n\n/**\n * Implementation of a gas fee flow that randomises the last digits of gas fee estimations\n */\nexport class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n const { chainId } = transactionMeta;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[chainId];\n\n return randomisedGasFeeDigits !== undefined;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getRandomisedGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return await this.#getDefaultGasFees(request);\n }\n }\n\n async #getDefaultGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n\n async #getRandomisedGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, gasFeeControllerData, transactionMeta } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];\n\n const preservedNumberOfDigits =\n gasFeeRandomisation.preservedNumberOfDigits ??\n DEFAULT_PRESERVE_NUMBER_OF_DIGITS;\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Randomising fee market estimates', gasFeeEstimates);\n const randomisedFeeMarketEstimates =\n this.#getRandomisedFeeMarketEstimates(\n gasFeeEstimates,\n randomisedGasFeeDigits,\n preservedNumberOfDigits,\n );\n log(\n 'Added randomised fee market estimates',\n randomisedFeeMarketEstimates,\n );\n\n return {\n estimates: randomisedFeeMarketEstimates,\n };\n }\n\n return await this.#getDefaultGasFees(request);\n }\n\n #getRandomisedFeeMarketEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getRandomisedFeeMarketLevel(\n gasFeeEstimates,\n level,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getRandomisedFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimateForLevel {\n return {\n maxFeePerGas: gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n ),\n // Only priority fee is randomised\n maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n };\n }\n}\n\n/**\n * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.\n *\n * @param digitCount - The number of digits the random number should have\n * @param minValue - The minimum value the random number should have\n * @returns A random number with the specified number of digits\n */\nfunction generateRandomDigits(digitCount: number, minValue: number): number {\n const multiplier = 10 ** digitCount;\n return minValue + Math.floor(Math.random() * (multiplier - minValue));\n}\n\n/**\n * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.\n *\n * This function preserves the more significant digits while randomizing only the least significant ones,\n * ensuring that fees remain close to the original estimation while providing randomisation.\n * The randomisation is performed in Wei units for more precision.\n *\n * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)\n * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise\n * @param preservedNumberOfDigits - The number of most significant digits to preserve\n * @returns The randomised value converted to Wei in hexadecimal format\n */\nexport function randomiseDecimalGWEIAndConvertToHex(\n gweiDecimalValue: string | number,\n numberOfDigitsToRandomizeAtTheEnd: number,\n preservedNumberOfDigits: number,\n): Hex {\n const weiDecimalValue = gweiDecimalToWeiDecimal(gweiDecimalValue);\n const decimalLength = weiDecimalValue.length;\n\n // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS\n const effectiveDigitsToRandomise = Math.min(\n numberOfDigitsToRandomizeAtTheEnd,\n decimalLength - preservedNumberOfDigits,\n );\n\n // Handle the case when the value is 0 or too small\n if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {\n return `0x${Number(weiDecimalValue).toString(16)}` as const;\n }\n\n // Use string manipulation to get the base part (significant digits)\n const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;\n const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);\n\n // Get the original ending digits using string manipulation\n const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);\n const originalEndingDigits = Number(endingDigits);\n\n // Generate random digits that are greater than or equal to the original ending digits\n const randomEndingDigits = generateRandomDigits(\n effectiveDigitsToRandomise,\n originalEndingDigits,\n );\n\n const basePart = BigInt(\n significantDigits + '0'.repeat(effectiveDigitsToRandomise),\n );\n const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);\n\n const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;\n\n return add0x(hexRandomisedWei);\n}\n"]}
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AACA,qEAAkE;AAClE,2CAA4D;AAG5D,6CAA6C;AAU7C,2CAAsE;AACtE,iEAAmE;AACnE,uDAG8B;AAC9B,kEAA2D;AAE3D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAC5B,yBAAa,EACb,oCAAoC,CACrC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAa,+BAA+B;IAA5C;;IA+GA,CAAC;IA9GC,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GAIV;QACC,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAEpC,MAAM,mBAAmB,GAAG,IAAA,yCAAsB,EAAC,SAAS,CAAC,CAAC;QAE9D,MAAM,sBAAsB,GAC1B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CAAuB,EAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAAC;IAE7C,wFAAwF;IACxF,MAAM,0BAA0B,GAAG,IAAI,CAAC,GAAG,CACzC,iCAAiC,EACjC,aAAa,GAAG,uBAAuB,CACxC,CAAC;IAEF,mDAAmD;IACnD,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,0BAA0B,IAAI,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAW,CAAC;IAC9D,CAAC;IAED,oEAAoE;IACpE,MAAM,sBAAsB,GAAG,aAAa,GAAG,0BAA0B,CAAC;IAC1E,MAAM,iBAAiB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAE3E,2DAA2D;IAC3D,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,0BAA0B,CAAC,CAAC;IACxE,MAAM,oBAAoB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAElD,sFAAsF;IACtF,MAAM,kBAAkB,GAAG,oBAAoB,CAC7C,0BAA0B,EAC1B,oBAAoB,CACrB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CACrB,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAC3D,CAAC;IACF,MAAM,oBAAoB,GAAG,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GAAG,KAAK,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAElE,OAAO,IAAA,aAAK,EAAC,gBAAgB,CAAC,CAAC;AACjC,CAAC;AAzCD,kFAyCC","sourcesContent":["import type { GasFeeEstimates as FeeMarketGasPriceEstimate } from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types.js';\nimport { getGasFeeRandomisation } from '../utils/feature-flags.js';\nimport {\n gweiDecimalToWeiDecimal,\n gweiDecimalToWeiHex,\n} from '../utils/gas-fees.js';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow.js';\n\nconst log = createModuleLogger(\n projectLogger,\n 'randomised-estimation-gas-fee-flow',\n);\n\nconst DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;\n\n/**\n * Implementation of a gas fee flow that randomises the last digits of gas fee estimations\n */\nexport class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n const { chainId } = transactionMeta;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[chainId];\n\n return randomisedGasFeeDigits !== undefined;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getRandomisedGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return await this.#getDefaultGasFees(request);\n }\n }\n\n async #getDefaultGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n\n async #getRandomisedGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, gasFeeControllerData, transactionMeta } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];\n\n const preservedNumberOfDigits =\n gasFeeRandomisation.preservedNumberOfDigits ??\n DEFAULT_PRESERVE_NUMBER_OF_DIGITS;\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Randomising fee market estimates', gasFeeEstimates);\n const randomisedFeeMarketEstimates =\n this.#getRandomisedFeeMarketEstimates(\n gasFeeEstimates,\n randomisedGasFeeDigits,\n preservedNumberOfDigits,\n );\n log(\n 'Added randomised fee market estimates',\n randomisedFeeMarketEstimates,\n );\n\n return {\n estimates: randomisedFeeMarketEstimates,\n };\n }\n\n return await this.#getDefaultGasFees(request);\n }\n\n #getRandomisedFeeMarketEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getRandomisedFeeMarketLevel(\n gasFeeEstimates,\n level,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getRandomisedFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimateForLevel {\n return {\n maxFeePerGas: gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n ),\n // Only priority fee is randomised\n maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n };\n }\n}\n\n/**\n * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.\n *\n * @param digitCount - The number of digits the random number should have\n * @param minValue - The minimum value the random number should have\n * @returns A random number with the specified number of digits\n */\nfunction generateRandomDigits(digitCount: number, minValue: number): number {\n const multiplier = 10 ** digitCount;\n return minValue + Math.floor(Math.random() * (multiplier - minValue));\n}\n\n/**\n * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.\n *\n * This function preserves the more significant digits while randomizing only the least significant ones,\n * ensuring that fees remain close to the original estimation while providing randomisation.\n * The randomisation is performed in Wei units for more precision.\n *\n * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)\n * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise\n * @param preservedNumberOfDigits - The number of most significant digits to preserve\n * @returns The randomised value converted to Wei in hexadecimal format\n */\nexport function randomiseDecimalGWEIAndConvertToHex(\n gweiDecimalValue: string | number,\n numberOfDigitsToRandomizeAtTheEnd: number,\n preservedNumberOfDigits: number,\n): Hex {\n const weiDecimalValue = gweiDecimalToWeiDecimal(gweiDecimalValue);\n const decimalLength = weiDecimalValue.length;\n\n // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS\n const effectiveDigitsToRandomise = Math.min(\n numberOfDigitsToRandomizeAtTheEnd,\n decimalLength - preservedNumberOfDigits,\n );\n\n // Handle the case when the value is 0 or too small\n if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {\n return `0x${Number(weiDecimalValue).toString(16)}` as const;\n }\n\n // Use string manipulation to get the base part (significant digits)\n const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;\n const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);\n\n // Get the original ending digits using string manipulation\n const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);\n const originalEndingDigits = Number(endingDigits);\n\n // Generate random digits that are greater than or equal to the original ending digits\n const randomEndingDigits = generateRandomDigits(\n effectiveDigitsToRandomise,\n originalEndingDigits,\n );\n\n const basePart = BigInt(\n significantDigits + '0'.repeat(effectiveDigitsToRandomise),\n );\n const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);\n\n const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;\n\n return add0x(hexRandomisedWei);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAgBlB;;GAEG;AACH,qBAAa,+BAAgC,YAAW,UAAU;;IAChE,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAWL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA6F1E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,MAAM,GAAG,MAAM,EACjC,iCAAiC,EAAE,MAAM,EACzC,uBAAuB,EAAE,MAAM,GAC9B,GAAG,CAqCL"}
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAoB;AAgBrB;;GAEG;AACH,qBAAa,+BAAgC,YAAW,UAAU;;IAChE,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAWL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA6F1E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,MAAM,GAAG,MAAM,EACjC,iCAAiC,EAAE,MAAM,EACzC,uBAAuB,EAAE,MAAM,GAC9B,GAAG,CAqCL"}
@@ -1 +1 @@
1
- {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAgBlB;;GAEG;AACH,qBAAa,+BAAgC,YAAW,UAAU;;IAChE,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAWL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA6F1E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,MAAM,GAAG,MAAM,EACjC,iCAAiC,EAAE,MAAM,EACzC,uBAAuB,EAAE,MAAM,GAC9B,GAAG,CAqCL"}
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAoB;AAgBrB;;GAEG;AACH,qBAAa,+BAAgC,YAAW,UAAU;;IAChE,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAWL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA6F1E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,MAAM,GAAG,MAAM,EACjC,iCAAiC,EAAE,MAAM,EACzC,uBAAuB,EAAE,MAAM,GAC9B,GAAG,CAqCL"}
@@ -1 +1 @@
1
- {"version":3,"file":"RandomisedEstimationsGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,qCAAqC;AAClE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAG5D,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAU1C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,qBAAiB;AACnE,OAAO,EAAE,sBAAsB,EAAE,mCAA+B;AAChE,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACpB,8BAA0B;AAC3B,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AAExD,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,oCAAoC,CACrC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAA5C;;IA+GA,CAAC;IA9GC,kBAAkB,CAAC,EACjB,eA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esContent":["import type { GasFeeEstimates as FeeMarketGasPriceEstimate } from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { getGasFeeRandomisation } from '../utils/feature-flags';\nimport {\n gweiDecimalToWeiDecimal,\n gweiDecimalToWeiHex,\n} from '../utils/gas-fees';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\n\nconst log = createModuleLogger(\n projectLogger,\n 'randomised-estimation-gas-fee-flow',\n);\n\nconst DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;\n\n/**\n * Implementation of a gas fee flow that randomises the last digits of gas fee estimations\n */\nexport class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n const { chainId } = transactionMeta;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[chainId];\n\n return randomisedGasFeeDigits !== undefined;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getRandomisedGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return await this.#getDefaultGasFees(request);\n }\n }\n\n async #getDefaultGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n\n async #getRandomisedGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, gasFeeControllerData, transactionMeta } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];\n\n const preservedNumberOfDigits =\n gasFeeRandomisation.preservedNumberOfDigits ??\n DEFAULT_PRESERVE_NUMBER_OF_DIGITS;\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Randomising fee market estimates', gasFeeEstimates);\n const randomisedFeeMarketEstimates =\n this.#getRandomisedFeeMarketEstimates(\n gasFeeEstimates,\n randomisedGasFeeDigits,\n preservedNumberOfDigits,\n );\n log(\n 'Added randomised fee market estimates',\n randomisedFeeMarketEstimates,\n );\n\n return {\n estimates: randomisedFeeMarketEstimates,\n };\n }\n\n return await this.#getDefaultGasFees(request);\n }\n\n #getRandomisedFeeMarketEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getRandomisedFeeMarketLevel(\n gasFeeEstimates,\n level,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getRandomisedFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimateForLevel {\n return {\n maxFeePerGas: gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n ),\n // Only priority fee is randomised\n maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n };\n }\n}\n\n/**\n * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.\n *\n * @param digitCount - The number of digits the random number should have\n * @param minValue - The minimum value the random number should have\n * @returns A random number with the specified number of digits\n */\nfunction generateRandomDigits(digitCount: number, minValue: number): number {\n const multiplier = 10 ** digitCount;\n return minValue + Math.floor(Math.random() * (multiplier - minValue));\n}\n\n/**\n * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.\n *\n * This function preserves the more significant digits while randomizing only the least significant ones,\n * ensuring that fees remain close to the original estimation while providing randomisation.\n * The randomisation is performed in Wei units for more precision.\n *\n * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)\n * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise\n * @param preservedNumberOfDigits - The number of most significant digits to preserve\n * @returns The randomised value converted to Wei in hexadecimal format\n */\nexport function randomiseDecimalGWEIAndConvertToHex(\n gweiDecimalValue: string | number,\n numberOfDigitsToRandomizeAtTheEnd: number,\n preservedNumberOfDigits: number,\n): Hex {\n const weiDecimalValue = gweiDecimalToWeiDecimal(gweiDecimalValue);\n const decimalLength = weiDecimalValue.length;\n\n // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS\n const effectiveDigitsToRandomise = Math.min(\n numberOfDigitsToRandomizeAtTheEnd,\n decimalLength - preservedNumberOfDigits,\n );\n\n // Handle the case when the value is 0 or too small\n if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {\n return `0x${Number(weiDecimalValue).toString(16)}` as const;\n }\n\n // Use string manipulation to get the base part (significant digits)\n const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;\n const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);\n\n // Get the original ending digits using string manipulation\n const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);\n const originalEndingDigits = Number(endingDigits);\n\n // Generate random digits that are greater than or equal to the original ending digits\n const randomEndingDigits = generateRandomDigits(\n effectiveDigitsToRandomise,\n originalEndingDigits,\n );\n\n const basePart = BigInt(\n significantDigits + '0'.repeat(effectiveDigitsToRandomise),\n );\n const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);\n\n const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;\n\n return add0x(hexRandomisedWei);\n}\n"]}
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,qCAAqC;AAClE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAG5D,OAAO,EAAE,aAAa,EAAE,sBAAqB;AAU7C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,qBAAoB;AACtE,OAAO,EAAE,sBAAsB,EAAE,mCAAkC;AACnE,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACpB,8BAA6B;AAC9B,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAE3D,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,oCAAoC,CACrC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAA5C;;IA+GA,CAAC;IA9GC,kBAAkB,CAAC,EACjB,eAAe,EACf,SAAS,GAIV;QACC,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAEpC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAE9D,MAAM,sBAAsB,GAC1B,mBAAmB,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAEtD,OAAO,sBAAsB,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAA0B;QACzC,IAAI,CAAC;YACH,OAAO,MAAM,uBAAA,IAAI,yGAAsB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MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,0BAA0B,IAAI,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAW,CAAC;IAC9D,CAAC;IAED,oEAAoE;IACpE,MAAM,sBAAsB,GAAG,aAAa,GAAG,0BAA0B,CAAC;IAC1E,MAAM,iBAAiB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAE3E,2DAA2D;IAC3D,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,0BAA0B,CAAC,CAAC;IACxE,MAAM,oBAAoB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAElD,sFAAsF;IACtF,MAAM,kBAAkB,GAAG,oBAAoB,CAC7C,0BAA0B,EAC1B,oBAAoB,CACrB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CACrB,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAC3D,CAAC;IACF,MAAM,oBAAoB,GAAG,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GAAG,KAAK,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAElE,OAAO,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import type { GasFeeEstimates as FeeMarketGasPriceEstimate } from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types.js';\nimport { getGasFeeRandomisation } from '../utils/feature-flags.js';\nimport {\n gweiDecimalToWeiDecimal,\n gweiDecimalToWeiHex,\n} from '../utils/gas-fees.js';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow.js';\n\nconst log = createModuleLogger(\n projectLogger,\n 'randomised-estimation-gas-fee-flow',\n);\n\nconst DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;\n\n/**\n * Implementation of a gas fee flow that randomises the last digits of gas fee estimations\n */\nexport class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n const { chainId } = transactionMeta;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[chainId];\n\n return randomisedGasFeeDigits !== undefined;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getRandomisedGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return await this.#getDefaultGasFees(request);\n }\n }\n\n async #getDefaultGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n\n async #getRandomisedGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, gasFeeControllerData, transactionMeta } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n const gasFeeRandomisation = getGasFeeRandomisation(messenger);\n\n const randomisedGasFeeDigits =\n gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];\n\n const preservedNumberOfDigits =\n gasFeeRandomisation.preservedNumberOfDigits ??\n DEFAULT_PRESERVE_NUMBER_OF_DIGITS;\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Randomising fee market estimates', gasFeeEstimates);\n const randomisedFeeMarketEstimates =\n this.#getRandomisedFeeMarketEstimates(\n gasFeeEstimates,\n randomisedGasFeeDigits,\n preservedNumberOfDigits,\n );\n log(\n 'Added randomised fee market estimates',\n randomisedFeeMarketEstimates,\n );\n\n return {\n estimates: randomisedFeeMarketEstimates,\n };\n }\n\n return await this.#getDefaultGasFees(request);\n }\n\n #getRandomisedFeeMarketEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getRandomisedFeeMarketLevel(\n gasFeeEstimates,\n level,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getRandomisedFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n lastNDigits: number,\n preservedNumberOfDigits: number,\n ): FeeMarketGasFeeEstimateForLevel {\n return {\n maxFeePerGas: gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n ),\n // Only priority fee is randomised\n maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n lastNDigits,\n preservedNumberOfDigits,\n ),\n };\n }\n}\n\n/**\n * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.\n *\n * @param digitCount - The number of digits the random number should have\n * @param minValue - The minimum value the random number should have\n * @returns A random number with the specified number of digits\n */\nfunction generateRandomDigits(digitCount: number, minValue: number): number {\n const multiplier = 10 ** digitCount;\n return minValue + Math.floor(Math.random() * (multiplier - minValue));\n}\n\n/**\n * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.\n *\n * This function preserves the more significant digits while randomizing only the least significant ones,\n * ensuring that fees remain close to the original estimation while providing randomisation.\n * The randomisation is performed in Wei units for more precision.\n *\n * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)\n * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise\n * @param preservedNumberOfDigits - The number of most significant digits to preserve\n * @returns The randomised value converted to Wei in hexadecimal format\n */\nexport function randomiseDecimalGWEIAndConvertToHex(\n gweiDecimalValue: string | number,\n numberOfDigitsToRandomizeAtTheEnd: number,\n preservedNumberOfDigits: number,\n): Hex {\n const weiDecimalValue = gweiDecimalToWeiDecimal(gweiDecimalValue);\n const decimalLength = weiDecimalValue.length;\n\n // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS\n const effectiveDigitsToRandomise = Math.min(\n numberOfDigitsToRandomizeAtTheEnd,\n decimalLength - preservedNumberOfDigits,\n );\n\n // Handle the case when the value is 0 or too small\n if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {\n return `0x${Number(weiDecimalValue).toString(16)}` as const;\n }\n\n // Use string manipulation to get the base part (significant digits)\n const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;\n const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);\n\n // Get the original ending digits using string manipulation\n const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);\n const originalEndingDigits = Number(endingDigits);\n\n // Generate random digits that are greater than or equal to the original ending digits\n const randomEndingDigits = generateRandomDigits(\n effectiveDigitsToRandomise,\n originalEndingDigits,\n );\n\n const basePart = BigInt(\n significantDigits + '0'.repeat(effectiveDigitsToRandomise),\n );\n const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);\n\n const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;\n\n return add0x(hexRandomisedWei);\n}\n"]}
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScrollLayer1GasFeeFlow = void 0;
4
- const constants_1 = require("../constants.cjs");
5
- const OracleLayer1GasFeeFlow_1 = require("./OracleLayer1GasFeeFlow.cjs");
6
- const SCROLL_CHAIN_IDS = [constants_1.CHAIN_IDS.SCROLL, constants_1.CHAIN_IDS.SCROLL_SEPOLIA];
4
+ const constants_js_1 = require("../constants.cjs");
5
+ const OracleLayer1GasFeeFlow_js_1 = require("./OracleLayer1GasFeeFlow.cjs");
6
+ const SCROLL_CHAIN_IDS = [constants_js_1.CHAIN_IDS.SCROLL, constants_js_1.CHAIN_IDS.SCROLL_SEPOLIA];
7
7
  // BlockExplorer link: https://scrollscan.com/address/0x5300000000000000000000000000000000000002#code
8
8
  const SCROLL_GAS_PRICE_ORACLE_ADDRESS = '0x5300000000000000000000000000000000000002';
9
9
  /**
10
10
  * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.
11
11
  */
12
- class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_1.OracleLayer1GasFeeFlow {
12
+ class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_js_1.OracleLayer1GasFeeFlow {
13
13
  getOracleAddressForChain(_chainId) {
14
14
  return SCROLL_GAS_PRICE_ORACLE_ADDRESS;
15
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAEA,gDAAyC;AAGzC,yEAAkE;AAElE,MAAM,gBAAgB,GAAU,CAAC,qBAAS,CAAC,MAAM,EAAE,qBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAAmD,CAAC;AAEtD;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAAsB;IAC7C,wBAAwB,CAAC,QAAa;QACvD,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAEkB,qBAAqB;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AAjBD,wDAiBC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\n\nconst SCROLL_CHAIN_IDS: Hex[] = [CHAIN_IDS.SCROLL, CHAIN_IDS.SCROLL_SEPOLIA];\n\n// BlockExplorer link: https://scrollscan.com/address/0x5300000000000000000000000000000000000002#code\nconst SCROLL_GAS_PRICE_ORACLE_ADDRESS =\n '0x5300000000000000000000000000000000000002' as Hex;\n\n/**\n * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n protected override getOracleAddressForChain(_chainId: Hex): Hex {\n return SCROLL_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n protected override shouldSignTransaction(): boolean {\n return true;\n }\n\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAEA,mDAA4C;AAG5C,4EAAqE;AAErE,MAAM,gBAAgB,GAAU,CAAC,wBAAS,CAAC,MAAM,EAAE,wBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAAmD,CAAC;AAEtD;;GAEG;AACH,MAAa,sBAAuB,SAAQ,kDAAsB;IAC7C,wBAAwB,CAAC,QAAa;QACvD,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAEkB,qBAAqB;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AAjBD,wDAiBC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { TransactionMeta } from '../types.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst SCROLL_CHAIN_IDS: Hex[] = [CHAIN_IDS.SCROLL, CHAIN_IDS.SCROLL_SEPOLIA];\n\n// BlockExplorer link: https://scrollscan.com/address/0x5300000000000000000000000000000000000002#code\nconst SCROLL_GAS_PRICE_ORACLE_ADDRESS =\n '0x5300000000000000000000000000000000000002' as Hex;\n\n/**\n * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n protected override getOracleAddressForChain(_chainId: Hex): Hex {\n return SCROLL_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n protected override shouldSignTransaction(): boolean {\n return true;\n }\n\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAChD,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAQlE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;cAC7C,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;cAI5C,qBAAqB,IAAI,OAAO;IAI7C,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrB"}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAoB;AACnD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAQrE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;cAC7C,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;cAI5C,qBAAqB,IAAI,OAAO;IAI7C,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAChD,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAQlE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;cAC7C,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;cAI5C,qBAAqB,IAAI,OAAO;IAI7C,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrB"}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAoB;AACnD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAQrE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;cAC7C,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;cAI5C,qBAAqB,IAAI,OAAO;IAI7C,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAGzC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAAmD,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAC7C,wBAAwB,CAAC,QAAa;QACvD,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAEkB,qBAAqB;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\n\nconst SCROLL_CHAIN_IDS: Hex[] = [CHAIN_IDS.SCROLL, CHAIN_IDS.SCROLL_SEPOLIA];\n\n// BlockExplorer link: https://scrollscan.com/address/0x5300000000000000000000000000000000000002#code\nconst SCROLL_GAS_PRICE_ORACLE_ADDRESS =\n '0x5300000000000000000000000000000000000002' as Hex;\n\n/**\n * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n protected override getOracleAddressForChain(_chainId: Hex): Hex {\n return SCROLL_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n protected override shouldSignTransaction(): boolean {\n return true;\n }\n\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,yBAAwB;AAG5C,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAErE,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAAmD,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAC7C,wBAAwB,CAAC,QAAa;QACvD,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAEkB,qBAAqB;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { TransactionMeta } from '../types.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst SCROLL_CHAIN_IDS: Hex[] = [CHAIN_IDS.SCROLL, CHAIN_IDS.SCROLL_SEPOLIA];\n\n// BlockExplorer link: https://scrollscan.com/address/0x5300000000000000000000000000000000000002#code\nconst SCROLL_GAS_PRICE_ORACLE_ADDRESS =\n '0x5300000000000000000000000000000000000002' as Hex;\n\n/**\n * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n protected override getOracleAddressForChain(_chainId: Hex): Hex {\n return SCROLL_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n protected override shouldSignTransaction(): boolean {\n return true;\n }\n\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
@@ -14,7 +14,7 @@ var _TestGasFeeFlow_instances, _TestGasFeeFlow_counter, _TestGasFeeFlow_getValue
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TestGasFeeFlow = void 0;
16
16
  const controller_utils_1 = require("@metamask/controller-utils");
17
- const types_1 = require("../types.cjs");
17
+ const types_js_1 = require("../types.cjs");
18
18
  const INCREMENT = 1e15; // 0.001 ETH
19
19
  const LEVEL_DIFFERENCE = 0.5;
20
20
  /**
@@ -48,7 +48,7 @@ class TestGasFeeFlow {
48
48
  __classPrivateFieldSet(this, _TestGasFeeFlow_counter, __classPrivateFieldGet(this, _TestGasFeeFlow_counter, "f") + 1, "f");
49
49
  return {
50
50
  estimates: {
51
- type: types_1.GasFeeEstimateType.FeeMarket,
51
+ type: types_js_1.GasFeeEstimateType.FeeMarket,
52
52
  low: {
53
53
  maxFeePerGas: __classPrivateFieldGet(this, _TestGasFeeFlow_instances, "m", _TestGasFeeFlow_getValueForTotalFee).call(this, lowMaxTarget, gasDecimal),
54
54
  maxPriorityFeePerGas: __classPrivateFieldGet(this, _TestGasFeeFlow_instances, "m", _TestGasFeeFlow_getValueForTotalFee).call(this, lowPriorityTarget, gasDecimal),
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAmD;AAGnD,wCAA8C;AAO9C,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,YAAY;AACpC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B;;;;GAIG;AACH,MAAa,cAAc;IAA3B;;QACE,kCAAW,CAAC,EAAC;IA6Df,CAAC;IA3DC,kBAAkB;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAA0B;QACzC,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QACpC,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;QACrC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;QAEjC,IAAI,CAAC,MAAM,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CACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CAMF;AA9DD,wCA8DC;uKAJsB,QAAgB,EAAE,GAAW;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;IAC7C,OAAO,IAAA,wBAAK,EAAC,UAAU,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { GasFeeEstimateType } from '../types';\nimport type {\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n} from '../types';\n\nconst INCREMENT = 1e15; // 0.001 ETH\nconst LEVEL_DIFFERENCE = 0.5;\n\n/**\n * A gas fee flow to facilitate testing in the clients.\n * Increments the total gas fee by a fixed amount each time it is called.\n * Relies on the transaction's gas value to generate a distinct total fee in the UI.\n */\nexport class TestGasFeeFlow implements GasFeeFlow {\n #counter = 1;\n\n matchesTransaction(): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { transactionMeta } = request;\n const { txParams } = transactionMeta;\n const { gas: gasHex } = txParams;\n\n if (!gasHex) {\n throw new Error('Cannot estimate fee without gas value');\n }\n\n const gasDecimal = parseInt(gasHex, 16);\n const difference = INCREMENT * LEVEL_DIFFERENCE;\n\n const mediumMaxTarget = (this.#counter + 1) * INCREMENT;\n const mediumPriorityTarget = this.#counter * INCREMENT;\n\n const lowMaxTarget = mediumMaxTarget - difference;\n const lowPriorityTarget = mediumPriorityTarget - difference;\n\n const highMaxTarget = mediumMaxTarget + difference;\n const highPriorityTarget = mediumPriorityTarget + difference;\n\n this.#counter += 1;\n\n return {\n estimates: {\n type: GasFeeEstimateType.FeeMarket,\n low: {\n maxFeePerGas: this.#getValueForTotalFee(lowMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n lowPriorityTarget,\n gasDecimal,\n ),\n },\n medium: {\n maxFeePerGas: this.#getValueForTotalFee(mediumMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n mediumPriorityTarget,\n gasDecimal,\n ),\n },\n high: {\n maxFeePerGas: this.#getValueForTotalFee(highMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n highPriorityTarget,\n gasDecimal,\n ),\n },\n },\n };\n }\n\n #getValueForTotalFee(totalFee: number, gas: number): Hex {\n const feeDecimal = Math.ceil(totalFee / gas);\n return toHex(feeDecimal);\n }\n}\n"]}
1
+ {"version":3,"file":"TestGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAmD;AAGnD,2CAAiD;AAOjD,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,YAAY;AACpC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B;;;;GAIG;AACH,MAAa,cAAc;IAA3B;;QACE,kCAAW,CAAC,EAAC;IA6Df,CAAC;IA3DC,kBAAkB;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAA0B;QACzC,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QACpC,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;QACrC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;QAEjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,SAAS,GAAG,gBAAgB,CAAC;QAEhD,MAAM,eAAe,GAAG,CAAC,uBAAA,IAAI,+BAAS,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;QACxD,MAAM,oBAAoB,GAAG,uBAAA,IAAI,+BAAS,GAAG,SAAS,CAAC;QAEvD,MAAM,YAAY,GAAG,eAAe,GAAG,UAAU,CAAC;QAClD,MAAM,iBAAiB,GAAG,oBAAoB,GAAG,UAAU,CAAC;QAE5D,MAAM,aAAa,GAAG,eAAe,GAAG,UAAU,CAAC;QACnD,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,UAAU,CAAC;QAE7D,mHAAiB,CAAC,MAAA,CAAC;QAEnB,OAAO;YACL,SAAS,EAAE;gBACT,IAAI,EAAE,6BAAkB,CAAC,SAAS;gBAClC,GAAG,EAAE;oBACH,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,YAAY,EAAE,UAAU,CAAC;oBACjE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,iBAAiB,EACjB,UAAU,CACX;iBACF;gBACD,MAAM,EAAE;oBACN,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,eAAe,EAAE,UAAU,CAAC;oBACpE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,oBAAoB,EACpB,UAAU,CACX;iBACF;gBACD,IAAI,EAAE;oBACJ,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,aAAa,EAAE,UAAU,CAAC;oBAClE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,kBAAkB,EAClB,UAAU,CACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CAMF;AA9DD,wCA8DC;uKAJsB,QAAgB,EAAE,GAAW;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;IAC7C,OAAO,IAAA,wBAAK,EAAC,UAAU,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { GasFeeEstimateType } from '../types.js';\nimport type {\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n} from '../types.js';\n\nconst INCREMENT = 1e15; // 0.001 ETH\nconst LEVEL_DIFFERENCE = 0.5;\n\n/**\n * A gas fee flow to facilitate testing in the clients.\n * Increments the total gas fee by a fixed amount each time it is called.\n * Relies on the transaction's gas value to generate a distinct total fee in the UI.\n */\nexport class TestGasFeeFlow implements GasFeeFlow {\n #counter = 1;\n\n matchesTransaction(): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { transactionMeta } = request;\n const { txParams } = transactionMeta;\n const { gas: gasHex } = txParams;\n\n if (!gasHex) {\n throw new Error('Cannot estimate fee without gas value');\n }\n\n const gasDecimal = parseInt(gasHex, 16);\n const difference = INCREMENT * LEVEL_DIFFERENCE;\n\n const mediumMaxTarget = (this.#counter + 1) * INCREMENT;\n const mediumPriorityTarget = this.#counter * INCREMENT;\n\n const lowMaxTarget = mediumMaxTarget - difference;\n const lowPriorityTarget = mediumPriorityTarget - difference;\n\n const highMaxTarget = mediumMaxTarget + difference;\n const highPriorityTarget = mediumPriorityTarget + difference;\n\n this.#counter += 1;\n\n return {\n estimates: {\n type: GasFeeEstimateType.FeeMarket,\n low: {\n maxFeePerGas: this.#getValueForTotalFee(lowMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n lowPriorityTarget,\n gasDecimal,\n ),\n },\n medium: {\n maxFeePerGas: this.#getValueForTotalFee(mediumMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n mediumPriorityTarget,\n gasDecimal,\n ),\n },\n high: {\n maxFeePerGas: this.#getValueForTotalFee(highMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n highPriorityTarget,\n gasDecimal,\n ),\n },\n },\n };\n }\n\n #getValueForTotalFee(totalFee: number, gas: number): Hex {\n const feeDecimal = Math.ceil(totalFee / gas);\n return toHex(feeDecimal);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,qBAAiB;AAKlB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAG/C,kBAAkB,IAAI,OAAO;IAIvB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAuD1E"}
1
+ {"version":3,"file":"TestGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,qBAAoB;AAKrB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAG/C,kBAAkB,IAAI,OAAO;IAIvB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAuD1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,qBAAiB;AAKlB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAG/C,kBAAkB,IAAI,OAAO;IAIvB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAuD1E"}
1
+ {"version":3,"file":"TestGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,qBAAoB;AAKrB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;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Ae,GAAG,UAAU,CAAC;QACnD,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,UAAU,CAAC;QAE7D,mHAAiB,CAAC,MAAA,CAAC;QAEnB,OAAO;YACL,SAAS,EAAE;gBACT,IAAI,EAAE,kBAAkB,CAAC,SAAS;gBAClC,GAAG,EAAE;oBACH,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,YAAY,EAAE,UAAU,CAAC;oBACjE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,iBAAiB,EACjB,UAAU,CACX;iBACF;gBACD,MAAM,EAAE;oBACN,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,eAAe,EAAE,UAAU,CAAC;oBACpE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,oBAAoB,EACpB,UAAU,CACX;iBACF;gBACD,IAAI,EAAE;oBACJ,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,aAAa,EAAE,UAAU,CAAC;oBAClE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,kBAAkB,EAClB,UAAU,CACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CAMF;uKAJsB,QAAgB,EAAE,GAAW;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { GasFeeEstimateType } from '../types';\nimport type {\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n} from '../types';\n\nconst INCREMENT = 1e15; // 0.001 ETH\nconst LEVEL_DIFFERENCE = 0.5;\n\n/**\n * A gas fee flow to facilitate testing in the clients.\n * Increments the total gas fee by a fixed amount each time it is called.\n * Relies on the transaction's gas value to generate a distinct total fee in the UI.\n */\nexport class TestGasFeeFlow implements GasFeeFlow {\n #counter = 1;\n\n matchesTransaction(): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { transactionMeta } = request;\n const { txParams } = transactionMeta;\n const { gas: gasHex } = txParams;\n\n if (!gasHex) {\n throw new Error('Cannot estimate fee without gas value');\n }\n\n const gasDecimal = parseInt(gasHex, 16);\n const difference = INCREMENT * LEVEL_DIFFERENCE;\n\n const mediumMaxTarget = (this.#counter + 1) * INCREMENT;\n const mediumPriorityTarget = this.#counter * INCREMENT;\n\n const lowMaxTarget = mediumMaxTarget - difference;\n const lowPriorityTarget = mediumPriorityTarget - difference;\n\n const highMaxTarget = mediumMaxTarget + difference;\n const highPriorityTarget = mediumPriorityTarget + difference;\n\n this.#counter += 1;\n\n return {\n estimates: {\n type: GasFeeEstimateType.FeeMarket,\n low: {\n maxFeePerGas: this.#getValueForTotalFee(lowMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n lowPriorityTarget,\n gasDecimal,\n ),\n },\n medium: {\n maxFeePerGas: this.#getValueForTotalFee(mediumMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n mediumPriorityTarget,\n gasDecimal,\n ),\n },\n high: {\n maxFeePerGas: this.#getValueForTotalFee(highMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n highPriorityTarget,\n gasDecimal,\n ),\n },\n },\n };\n }\n\n #getValueForTotalFee(totalFee: number, gas: number): Hex {\n const feeDecimal = Math.ceil(totalFee / gas);\n return toHex(feeDecimal);\n }\n}\n"]}
1
+ {"version":3,"file":"TestGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAGnD,OAAO,EAAE,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AAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,iBAAiB,EACjB,UAAU,CACX;iBACF;gBACD,MAAM,EAAE;oBACN,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,eAAe,EAAE,UAAU,CAAC;oBACpE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,oBAAoB,EACpB,UAAU,CACX;iBACF;gBACD,IAAI,EAAE;oBACJ,YAAY,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EAAsB,aAAa,EAAE,UAAU,CAAC;oBAClE,oBAAoB,EAAE,uBAAA,IAAI,sEAAqB,MAAzB,IAAI,EACxB,kBAAkB,EAClB,UAAU,CACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CAMF;uKAJsB,QAAgB,EAAE,GAAW;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { GasFeeEstimateType } from '../types.js';\nimport type {\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n} from '../types.js';\n\nconst INCREMENT = 1e15; // 0.001 ETH\nconst LEVEL_DIFFERENCE = 0.5;\n\n/**\n * A gas fee flow to facilitate testing in the clients.\n * Increments the total gas fee by a fixed amount each time it is called.\n * Relies on the transaction's gas value to generate a distinct total fee in the UI.\n */\nexport class TestGasFeeFlow implements GasFeeFlow {\n #counter = 1;\n\n matchesTransaction(): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { transactionMeta } = request;\n const { txParams } = transactionMeta;\n const { gas: gasHex } = txParams;\n\n if (!gasHex) {\n throw new Error('Cannot estimate fee without gas value');\n }\n\n const gasDecimal = parseInt(gasHex, 16);\n const difference = INCREMENT * LEVEL_DIFFERENCE;\n\n const mediumMaxTarget = (this.#counter + 1) * INCREMENT;\n const mediumPriorityTarget = this.#counter * INCREMENT;\n\n const lowMaxTarget = mediumMaxTarget - difference;\n const lowPriorityTarget = mediumPriorityTarget - difference;\n\n const highMaxTarget = mediumMaxTarget + difference;\n const highPriorityTarget = mediumPriorityTarget + difference;\n\n this.#counter += 1;\n\n return {\n estimates: {\n type: GasFeeEstimateType.FeeMarket,\n low: {\n maxFeePerGas: this.#getValueForTotalFee(lowMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n lowPriorityTarget,\n gasDecimal,\n ),\n },\n medium: {\n maxFeePerGas: this.#getValueForTotalFee(mediumMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n mediumPriorityTarget,\n gasDecimal,\n ),\n },\n high: {\n maxFeePerGas: this.#getValueForTotalFee(highMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n highPriorityTarget,\n gasDecimal,\n ),\n },\n },\n };\n }\n\n #getValueForTotalFee(totalFee: number, gas: number): Hex {\n const feeDecimal = Math.ceil(totalFee / gas);\n return toHex(feeDecimal);\n }\n}\n"]}
@@ -20,13 +20,13 @@ const utils_1 = require("@metamask/utils");
20
20
  // This package purposefully relies on Node's EventEmitter module.
21
21
  // eslint-disable-next-line import-x/no-nodejs-modules
22
22
  const events_1 = __importDefault(require("events"));
23
- const DefaultGasFeeFlow_1 = require("../gas-flows/DefaultGasFeeFlow.cjs");
24
- const logger_1 = require("../logger.cjs");
25
- const types_1 = require("../types.cjs");
26
- const gas_flow_1 = require("../utils/gas-flow.cjs");
27
- const layer1_gas_fee_flow_1 = require("../utils/layer1-gas-fee-flow.cjs");
28
- const provider_1 = require("../utils/provider.cjs");
29
- const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'gas-fee-poller');
23
+ const DefaultGasFeeFlow_js_1 = require("../gas-flows/DefaultGasFeeFlow.cjs");
24
+ const logger_js_1 = require("../logger.cjs");
25
+ const types_js_1 = require("../types.cjs");
26
+ const gas_flow_js_1 = require("../utils/gas-flow.cjs");
27
+ const layer1_gas_fee_flow_js_1 = require("../utils/layer1-gas-fee-flow.cjs");
28
+ const provider_js_1 = require("../utils/provider.cjs");
29
+ const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'gas-fee-poller');
30
30
  const INTERVAL_MILLISECONDS = 10000;
31
31
  /**
32
32
  * Automatically polls and updates suggested gas fees on unapproved transactions.
@@ -140,7 +140,7 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
140
140
  });
141
141
  }, _GasFeePoller_updateUnapprovedTransactionBatch = async function _GasFeePoller_updateUnapprovedTransactionBatch(txBatchMeta, gasFeeControllerData) {
142
142
  const { id } = txBatchMeta;
143
- const defaultGasFeeFlow = new DefaultGasFeeFlow_1.DefaultGasFeeFlow();
143
+ const defaultGasFeeFlow = new DefaultGasFeeFlow_js_1.DefaultGasFeeFlow();
144
144
  const request = {
145
145
  gasFeeControllerData,
146
146
  messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
@@ -171,7 +171,7 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
171
171
  gasFeeEstimatesLoaded: true,
172
172
  });
173
173
  }, _GasFeePoller_updateTransactionGasFeeEstimates = async function _GasFeePoller_updateTransactionGasFeeEstimates(transactionMeta, gasFeeControllerData) {
174
- const gasFeeFlow = (0, gas_flow_1.getGasFeeFlow)(transactionMeta, __classPrivateFieldGet(this, _GasFeePoller_gasFeeFlows, "f"), __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"));
174
+ const gasFeeFlow = (0, gas_flow_js_1.getGasFeeFlow)(transactionMeta, __classPrivateFieldGet(this, _GasFeePoller_gasFeeFlows, "f"), __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"));
175
175
  if (gasFeeFlow) {
176
176
  log('Found gas fee flow', gasFeeFlow.constructor.name, transactionMeta.id);
177
177
  }
@@ -199,7 +199,7 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
199
199
  });
200
200
  return { gasFeeEstimates, gasFeeEstimatesLoaded: true };
201
201
  }, _GasFeePoller_updateTransactionLayer1GasFee = async function _GasFeePoller_updateTransactionLayer1GasFee(transactionMeta) {
202
- const layer1GasFee = await (0, layer1_gas_fee_flow_1.getTransactionLayer1GasFee)({
202
+ const layer1GasFee = await (0, layer1_gas_fee_flow_js_1.getTransactionLayer1GasFee)({
203
203
  layer1GasFeeFlows: __classPrivateFieldGet(this, _GasFeePoller_layer1GasFeeFlows, "f"),
204
204
  messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
205
205
  transactionMeta,
@@ -209,9 +209,9 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
209
209
  }
210
210
  return layer1GasFee;
211
211
  }, _GasFeePoller_getUnapprovedTransactions = function _GasFeePoller_getUnapprovedTransactions() {
212
- return __classPrivateFieldGet(this, _GasFeePoller_getTransactions, "f").call(this).filter((tx) => tx.status === types_1.TransactionStatus.unapproved);
212
+ return __classPrivateFieldGet(this, _GasFeePoller_getTransactions, "f").call(this).filter((tx) => tx.status === types_js_1.TransactionStatus.unapproved);
213
213
  }, _GasFeePoller_getUnapprovedTransactionBatches = function _GasFeePoller_getUnapprovedTransactionBatches() {
214
- return __classPrivateFieldGet(this, _GasFeePoller_getTransactionBatches, "f").call(this).filter((batch) => batch.status === types_1.TransactionStatus.unapproved);
214
+ return __classPrivateFieldGet(this, _GasFeePoller_getTransactionBatches, "f").call(this).filter((batch) => batch.status === types_js_1.TransactionStatus.unapproved);
215
215
  }, _GasFeePoller_getGasFeeControllerData = async function _GasFeePoller_getGasFeeControllerData(transactions) {
216
216
  const networkClientIdsByChainId = new Map();
217
217
  for (const transaction of transactions) {
@@ -220,7 +220,7 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
220
220
  continue;
221
221
  }
222
222
  const networkClientId = transactionNetworkClientId ??
223
- (0, provider_1.getNetworkClientId)({ messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"), chainId });
223
+ (0, provider_js_1.getNetworkClientId)({ messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"), chainId });
224
224
  networkClientIdsByChainId.set(chainId, networkClientId);
225
225
  }
226
226
  log('Extracted network client IDs by chain ID', networkClientIdsByChainId);
@@ -244,12 +244,12 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
244
244
  */
245
245
  function updateTransactionGasProperties({ gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, txMeta, }) {
246
246
  const userFeeLevel = txMeta.userFeeLevel;
247
- const isUsingGasFeeEstimateLevel = Object.values(types_1.GasFeeEstimateLevel).includes(userFeeLevel);
247
+ const isUsingGasFeeEstimateLevel = Object.values(types_js_1.GasFeeEstimateLevel).includes(userFeeLevel);
248
248
  const shouldUpdateTxParamsGasFees = isTxParamsGasFeeUpdatesEnabled(txMeta);
249
249
  if (shouldUpdateTxParamsGasFees &&
250
250
  isUsingGasFeeEstimateLevel &&
251
251
  gasFeeEstimates) {
252
- const isEIP1559Compatible = txMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy;
252
+ const isEIP1559Compatible = txMeta.txParams.type !== types_js_1.TransactionEnvelopeType.legacy;
253
253
  updateGasFeeParameters(txMeta.txParams, gasFeeEstimates, userFeeLevel, isEIP1559Compatible);
254
254
  }
255
255
  if (gasFeeEstimates) {
@@ -275,7 +275,7 @@ function updateTransactionGasEstimates({ txMeta, userFeeLevel, }) {
275
275
  if (!gasFeeEstimates) {
276
276
  return;
277
277
  }
278
- const isEIP1559Compatible = txMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy;
278
+ const isEIP1559Compatible = txMeta.txParams.type !== types_js_1.TransactionEnvelopeType.legacy;
279
279
  updateGasFeeParameters(txParams, gasFeeEstimates, userFeeLevel, isEIP1559Compatible);
280
280
  }
281
281
  exports.updateTransactionGasEstimates = updateTransactionGasEstimates;
@@ -291,19 +291,19 @@ function updateGasFeeParameters(txParams, gasFeeEstimates, userFeeLevel, isEIP15
291
291
  const { type: gasEstimateType } = gasFeeEstimates;
292
292
  if (isEIP1559Compatible) {
293
293
  // Handle EIP-1559 compatible transactions
294
- if (gasEstimateType === types_1.GasFeeEstimateType.FeeMarket) {
294
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.FeeMarket) {
295
295
  const feeMarketGasFeeEstimates = gasFeeEstimates;
296
296
  txParams.maxFeePerGas =
297
297
  feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;
298
298
  txParams.maxPriorityFeePerGas =
299
299
  feeMarketGasFeeEstimates[userFeeLevel]?.maxPriorityFeePerGas;
300
300
  }
301
- if (gasEstimateType === types_1.GasFeeEstimateType.GasPrice) {
301
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.GasPrice) {
302
302
  const gasPriceGasFeeEstimates = gasFeeEstimates;
303
303
  txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;
304
304
  txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;
305
305
  }
306
- if (gasEstimateType === types_1.GasFeeEstimateType.Legacy) {
306
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.Legacy) {
307
307
  const legacyGasFeeEstimates = gasFeeEstimates;
308
308
  const gasPrice = legacyGasFeeEstimates[userFeeLevel];
309
309
  txParams.maxFeePerGas = gasPrice;
@@ -314,15 +314,15 @@ function updateGasFeeParameters(txParams, gasFeeEstimates, userFeeLevel, isEIP15
314
314
  }
315
315
  else {
316
316
  // Handle non-EIP-1559 transactions
317
- if (gasEstimateType === types_1.GasFeeEstimateType.FeeMarket) {
317
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.FeeMarket) {
318
318
  const feeMarketGasFeeEstimates = gasFeeEstimates;
319
319
  txParams.gasPrice = feeMarketGasFeeEstimates[userFeeLevel]?.maxFeePerGas;
320
320
  }
321
- if (gasEstimateType === types_1.GasFeeEstimateType.GasPrice) {
321
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.GasPrice) {
322
322
  const gasPriceGasFeeEstimates = gasFeeEstimates;
323
323
  txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;
324
324
  }
325
- if (gasEstimateType === types_1.GasFeeEstimateType.Legacy) {
325
+ if (gasEstimateType === types_js_1.GasFeeEstimateType.Legacy) {
326
326
  const legacyGasFeeEstimates = gasFeeEstimates;
327
327
  txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];
328
328
  }
@@ -1 +1 @@
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,6DAEiB;QAEjB,gDAA0C;QAE1C,sDAAqD;QAErD,kDAAuC;QAEvC,0CAA2C;QAEpD,wCAAoD;QAEpD,gCAAW,KAAK,EAAC;QAiCf,uBAAA,I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C,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
+ {"version":3,"file":"GasFeePoller.cjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,2CAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,6EAAsE;AACtE,6CAA6C;AAW7C,2CAKqB;AACrB,uDAAqD;AACrD,6EAA6E;AAC7E,uDAA0D;AAE1D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,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,6DAEiB;QAEjB,gDAA0C;QAE1C,sDAAqD;QAErD,kDAAuC;QAEvC,0CAA2C;QAEpD,wCAAoD;QAEpD,gCAAW,KAAK,EAAC;QAiCf,uBAAA,IAAI,6BAAgB,WAAW,MAAA,CAAC;QAChC,uBAA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,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.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n TransactionMeta,\n TransactionParams,\n TransactionBatchMeta,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} from '../types.js';\nimport { getGasFeeFlow } from '../utils/gas-flow.js';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow.js';\nimport { getNetworkClientId } from '../utils/provider.js';\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,6 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node/events" />
3
- /// <reference types="npm-which/node_modules/@types/node/events" />
2
+ /// <reference types="node/events.js" />
3
+ /// <reference types="npm-which/node_modules/@types/node/events.js" />
4
4
  import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
5
5
  import type { Hex } from "@metamask/utils";
6
6
  import EventEmitter from "events";
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.d.cts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AAEtC,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;AASlB;;GAEG;AACH,qBAAa,YAAY;;IACvB,GAAG,EAAE,YAAY,CAAsB;IAoBvC;;;;;;;;;;;OAWG;gBACS,EACV,WAAW,EACX,4BAA4B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@@
1
1
  /// <reference types="node" />
2
- /// <reference types="node/events" />
3
- /// <reference types="npm-which/node_modules/@types/node/events" />
2
+ /// <reference types="node/events.js" />
3
+ /// <reference types="npm-which/node_modules/@types/node/events.js" />
4
4
  import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
5
5
  import type { Hex } from "@metamask/utils";
6
6
  import EventEmitter from "events";
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.d.mts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AAEtC,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;AASlB;;GAEG;AACH,qBAAa,YAAY;;IACvB,GAAG,EAAE,YAAY,CAAsB;IAoBvC;;;;;;;;;;;OAWG;gBACS,EACV,WAAW,EACX,4BAA4B,EAC5B,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EACT,aAAa,GACd,EAAE;QACD,WAAW,EAAE,UAAU,EAAE,CAAC;QAC1B,4BAA4B,EAAE,CAC5B,OAAO,EAAE,0BAA0B,KAChC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1B,eAAe,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;;;;;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