@metamask/transaction-controller 28.1.0 → 29.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/dist/TransactionController.js +12 -11
  3. package/dist/TransactionController.mjs +11 -10
  4. package/dist/{chunk-LDXTSESK.mjs → chunk-4M7FHI4S.mjs} +20 -4
  5. package/dist/chunk-4M7FHI4S.mjs.map +1 -0
  6. package/dist/{chunk-FK7AP6SH.js → chunk-5C3CSQAD.js} +12 -5
  7. package/dist/{chunk-YEJJKWT2.mjs.map → chunk-5C3CSQAD.js.map} +1 -1
  8. package/dist/{chunk-V6UIRCOF.js → chunk-7DJO6UZA.js} +48 -13
  9. package/dist/chunk-7DJO6UZA.js.map +1 -0
  10. package/dist/{chunk-MG7HTD3H.mjs → chunk-7TPXSDXL.mjs} +121 -35
  11. package/dist/chunk-7TPXSDXL.mjs.map +1 -0
  12. package/dist/{chunk-TWND5SFD.mjs → chunk-AGJNOOBN.mjs} +17 -12
  13. package/dist/chunk-AGJNOOBN.mjs.map +1 -0
  14. package/dist/{chunk-LNX4JTOL.js → chunk-DUFOYA4D.js} +7 -7
  15. package/dist/chunk-DUFOYA4D.js.map +1 -0
  16. package/dist/{chunk-UH7FNVKS.js → chunk-EMDU4XLM.js} +19 -14
  17. package/dist/chunk-EMDU4XLM.js.map +1 -0
  18. package/dist/chunk-FMRLPVFZ.mjs +66 -0
  19. package/dist/chunk-FMRLPVFZ.mjs.map +1 -0
  20. package/dist/{chunk-EQNKFFTM.js → chunk-KNYSD4JP.js} +21 -5
  21. package/dist/chunk-KNYSD4JP.js.map +1 -0
  22. package/dist/{chunk-IZVRGO3P.mjs → chunk-MDRMMUMS.mjs} +32 -18
  23. package/dist/chunk-MDRMMUMS.mjs.map +1 -0
  24. package/dist/{chunk-DMMUAJKY.js → chunk-N55SEKK7.js} +125 -39
  25. package/dist/chunk-N55SEKK7.js.map +1 -0
  26. package/dist/{chunk-YEJJKWT2.mjs → chunk-N6JXPWLY.mjs} +11 -4
  27. package/dist/chunk-N6JXPWLY.mjs.map +1 -0
  28. package/dist/chunk-REOG6YD4.mjs +112 -0
  29. package/dist/chunk-REOG6YD4.mjs.map +1 -0
  30. package/dist/{chunk-HHK4QSNF.mjs → chunk-SL3GHHKG.mjs} +47 -12
  31. package/dist/chunk-SL3GHHKG.mjs.map +1 -0
  32. package/dist/chunk-TJMQEH57.js +66 -0
  33. package/dist/chunk-TJMQEH57.js.map +1 -0
  34. package/dist/chunk-VJYFB7BM.js +112 -0
  35. package/dist/chunk-VJYFB7BM.js.map +1 -0
  36. package/dist/{chunk-JAYYMCBQ.js → chunk-X3KACH5P.js} +32 -18
  37. package/dist/chunk-X3KACH5P.js.map +1 -0
  38. package/dist/{chunk-NCRWKI6Y.mjs → chunk-XL3HBKDE.mjs} +4 -4
  39. package/dist/chunk-XL3HBKDE.mjs.map +1 -0
  40. package/dist/errors.js +1 -1
  41. package/dist/errors.mjs +1 -1
  42. package/dist/gas-flows/DefaultGasFeeFlow.js +5 -5
  43. package/dist/gas-flows/DefaultGasFeeFlow.mjs +4 -4
  44. package/dist/gas-flows/LineaGasFeeFlow.js +6 -6
  45. package/dist/gas-flows/LineaGasFeeFlow.mjs +5 -5
  46. package/dist/gas-flows/TestGasFeeFlow.js +9 -0
  47. package/dist/gas-flows/TestGasFeeFlow.js.map +1 -0
  48. package/dist/gas-flows/TestGasFeeFlow.mjs +9 -0
  49. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
  50. package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
  51. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
  52. package/dist/helpers/GasFeePoller.js +4 -4
  53. package/dist/helpers/GasFeePoller.mjs +3 -3
  54. package/dist/helpers/MultichainTrackingHelper.js +1 -1
  55. package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
  56. package/dist/helpers/PendingTransactionTracker.js +1 -1
  57. package/dist/helpers/PendingTransactionTracker.mjs +1 -1
  58. package/dist/index.js +16 -11
  59. package/dist/index.mjs +15 -10
  60. package/dist/tsconfig.build.tsbuildinfo +1 -1
  61. package/dist/types/TransactionController.d.ts +12 -5
  62. package/dist/types/TransactionController.d.ts.map +1 -1
  63. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -1
  64. package/dist/types/gas-flows/TestGasFeeFlow.d.ts +12 -0
  65. package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +1 -0
  66. package/dist/types/helpers/GasFeePoller.d.ts +5 -3
  67. package/dist/types/helpers/GasFeePoller.d.ts.map +1 -1
  68. package/dist/types/index.d.ts +2 -2
  69. package/dist/types/index.d.ts.map +1 -1
  70. package/dist/types/types.d.ts +36 -18
  71. package/dist/types/types.d.ts.map +1 -1
  72. package/dist/types/utils/gas-flow.d.ts +8 -14
  73. package/dist/types/utils/gas-flow.d.ts.map +1 -1
  74. package/dist/types/utils/simulation.d.ts +18 -0
  75. package/dist/types/utils/simulation.d.ts.map +1 -1
  76. package/dist/types.js +4 -2
  77. package/dist/types.mjs +3 -1
  78. package/dist/utils/external-transactions.js +1 -1
  79. package/dist/utils/external-transactions.mjs +1 -1
  80. package/dist/utils/gas-fees.js +4 -4
  81. package/dist/utils/gas-fees.mjs +3 -3
  82. package/dist/utils/gas-flow.js +3 -3
  83. package/dist/utils/gas-flow.mjs +2 -2
  84. package/dist/utils/simulation-api.js +1 -1
  85. package/dist/utils/simulation-api.mjs +1 -1
  86. package/dist/utils/simulation.js +5 -3
  87. package/dist/utils/simulation.mjs +4 -2
  88. package/dist/utils/swaps.js +1 -1
  89. package/dist/utils/swaps.mjs +1 -1
  90. package/dist/utils/transaction-type.js +1 -1
  91. package/dist/utils/transaction-type.mjs +1 -1
  92. package/dist/utils/utils.js +1 -1
  93. package/dist/utils/utils.mjs +1 -1
  94. package/dist/utils/validation.js +1 -1
  95. package/dist/utils/validation.mjs +1 -1
  96. package/package.json +4 -4
  97. package/dist/chunk-4RJXBKSR.js +0 -90
  98. package/dist/chunk-4RJXBKSR.js.map +0 -1
  99. package/dist/chunk-DMMUAJKY.js.map +0 -1
  100. package/dist/chunk-EQNKFFTM.js.map +0 -1
  101. package/dist/chunk-FK7AP6SH.js.map +0 -1
  102. package/dist/chunk-HHK4QSNF.mjs.map +0 -1
  103. package/dist/chunk-IZVRGO3P.mjs.map +0 -1
  104. package/dist/chunk-JAYYMCBQ.js.map +0 -1
  105. package/dist/chunk-LDXTSESK.mjs.map +0 -1
  106. package/dist/chunk-LNX4JTOL.js.map +0 -1
  107. package/dist/chunk-MG7HTD3H.mjs.map +0 -1
  108. package/dist/chunk-NCRWKI6Y.mjs.map +0 -1
  109. package/dist/chunk-NPEXNXSY.mjs +0 -90
  110. package/dist/chunk-NPEXNXSY.mjs.map +0 -1
  111. package/dist/chunk-TWND5SFD.mjs.map +0 -1
  112. package/dist/chunk-UH7FNVKS.js.map +0 -1
  113. package/dist/chunk-V6UIRCOF.js.map +0 -1
@@ -1,90 +0,0 @@
1
- import {
2
- gweiDecimalToWeiHex
3
- } from "./chunk-LDXTSESK.mjs";
4
- import {
5
- projectLogger
6
- } from "./chunk-UQQWZT6C.mjs";
7
- import {
8
- GasFeeEstimateLevel
9
- } from "./chunk-YEJJKWT2.mjs";
10
- import {
11
- __privateAdd,
12
- __privateMethod
13
- } from "./chunk-XUI43LEZ.mjs";
14
-
15
- // src/gas-flows/DefaultGasFeeFlow.ts
16
- import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
17
- import { createModuleLogger } from "@metamask/utils";
18
- var log = createModuleLogger(projectLogger, "default-gas-fee-flow");
19
- var _getEstimateLevel, getEstimateLevel_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
- var DefaultGasFeeFlow = class {
21
- constructor() {
22
- __privateAdd(this, _getEstimateLevel);
23
- __privateAdd(this, _getFeeMarketLevel);
24
- __privateAdd(this, _getLegacyLevel);
25
- }
26
- matchesTransaction(_transactionMeta) {
27
- return true;
28
- }
29
- async getGasFees(request) {
30
- const { getGasFeeControllerEstimates, transactionMeta } = request;
31
- const { networkClientId } = transactionMeta;
32
- const { gasEstimateType, gasFeeEstimates } = await getGasFeeControllerEstimates({ networkClientId });
33
- if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
34
- log("Using fee market estimates", gasFeeEstimates);
35
- } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
36
- log("Using legacy estimates", gasFeeEstimates);
37
- } else {
38
- throw new Error(`'No gas fee estimates available`);
39
- }
40
- const estimates = Object.values(GasFeeEstimateLevel).reduce(
41
- (result, level) => ({
42
- ...result,
43
- [level]: __privateMethod(this, _getEstimateLevel, getEstimateLevel_fn).call(this, {
44
- gasEstimateType,
45
- gasFeeEstimates,
46
- level
47
- })
48
- }),
49
- {}
50
- );
51
- return { estimates };
52
- }
53
- };
54
- _getEstimateLevel = new WeakSet();
55
- getEstimateLevel_fn = function({
56
- gasEstimateType,
57
- gasFeeEstimates,
58
- level
59
- }) {
60
- if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
61
- return __privateMethod(this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level);
62
- }
63
- return __privateMethod(this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level);
64
- };
65
- _getFeeMarketLevel = new WeakSet();
66
- getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
67
- const maxFeePerGas = gweiDecimalToWeiHex(
68
- gasFeeEstimates[level].suggestedMaxFeePerGas
69
- );
70
- const maxPriorityFeePerGas = gweiDecimalToWeiHex(
71
- gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
72
- );
73
- return {
74
- maxFeePerGas,
75
- maxPriorityFeePerGas
76
- };
77
- };
78
- _getLegacyLevel = new WeakSet();
79
- getLegacyLevel_fn = function(gasFeeEstimates, level) {
80
- const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);
81
- return {
82
- maxFeePerGas: gasPrice,
83
- maxPriorityFeePerGas: gasPrice
84
- };
85
- };
86
-
87
- export {
88
- DefaultGasFeeFlow
89
- };
90
- //# sourceMappingURL=chunk-NPEXNXSY.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeEstimatesForLevel,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\n\ntype FeeMarketGetEstimateLevelRequest = {\n gasEstimateType: 'fee-market';\n gasFeeEstimates: FeeMarketGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\ntype LegacyGetEstimateLevelRequest = {\n gasEstimateType: 'legacy';\n gasFeeEstimates: LegacyGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\n/**\n * The standard implementation of a gas fee flow that obtains gas fee estimates using only the GasFeeController.\n */\nexport class DefaultGasFeeFlow implements GasFeeFlow {\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { getGasFeeControllerEstimates, transactionMeta } = request;\n const { networkClientId } = transactionMeta;\n\n const { gasEstimateType, gasFeeEstimates } =\n await getGasFeeControllerEstimates({ networkClientId });\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Using fee market estimates', gasFeeEstimates);\n } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n log('Using legacy estimates', gasFeeEstimates);\n } else {\n throw new Error(`'No gas fee estimates available`);\n }\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n } as FeeMarketGetEstimateLevelRequest | LegacyGetEstimateLevelRequest),\n }),\n {} as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n }:\n | FeeMarketGetEstimateLevelRequest\n | LegacyGetEstimateLevelRequest): GasFeeEstimatesForLevel {\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return this.#getFeeMarketLevel(gasFeeEstimates, level);\n }\n\n return this.#getLegacyLevel(gasFeeEstimates, level);\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const maxFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n );\n\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n );\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n }\n\n #getLegacyLevel(\n gasFeeEstimates: LegacyGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);\n\n return {\n maxFeePerGas: gasPrice,\n maxPriorityFeePerGas: gasPrice,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAIA,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAcnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAnBpE;AAoCO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAmCL;AAcA;AAkBA;AAAA;A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IACL,cAAc;AAAA,IACd,sBAAsB;AAAA,EACxB;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/gas-flow.ts"],"sourcesContent":["import { weiHexToGweiDec } from '@metamask/controller-utils';\nimport type {\n Eip1559GasFee,\n GasFeeEstimates,\n LegacyGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\n\nimport {\n type GasFeeEstimates as TransactionGasFeeEstimates,\n type GasFeeFlow,\n type TransactionMeta,\n type GasFeeEstimatesForLevel,\n GasFeeEstimateLevel,\n} from '../types';\n\n/**\n * Returns the first gas fee flow that matches the transaction.\n *\n * @param transactionMeta - The transaction metadata to find a gas fee flow for.\n * @param gasFeeFlows - The gas fee flows to search.\n * @returns The first gas fee flow that matches the transaction, or undefined if none match.\n */\nexport function getGasFeeFlow(\n transactionMeta: TransactionMeta,\n gasFeeFlows: GasFeeFlow[],\n): GasFeeFlow | undefined {\n return gasFeeFlows.find((gasFeeFlow) =>\n gasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\ntype FeeMarketMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'fee-market';\n gasFeeControllerEstimates: GasFeeEstimates;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\ntype LegacyMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'legacy';\n gasFeeControllerEstimates: LegacyGasPriceEstimate;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\n/**\n * Merge the gas fee estimates from the gas fee controller with the gas fee estimates from a transaction.\n * @param request - Data required to merge gas fee estimates.\n * @param request.gasFeeControllerEstimateType - Gas fee estimate type from the gas fee controller.\n * @param request.gasFeeControllerEstimates - Gas fee estimates from the GasFeeController.\n * @param request.transactionGasFeeEstimates - Gas fee estimates from the transaction.\n * @returns The merged gas fee estimates.\n */\nexport function mergeGasFeeEstimates({\n gasFeeControllerEstimateType,\n gasFeeControllerEstimates,\n transactionGasFeeEstimates,\n}:\n | FeeMarketMergeGasFeeEstimatesRequest\n | LegacyMergeGasFeeEstimatesRequest): GasFeeState['gasFeeEstimates'] {\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: mergeFeeMarketEstimate(\n gasFeeControllerEstimates[level],\n transactionGasFeeEstimates[level],\n ),\n }),\n { ...gasFeeControllerEstimates } as GasFeeEstimates,\n );\n }\n\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: getLegacyEstimate(transactionGasFeeEstimates[level]),\n }),\n {} as LegacyGasPriceEstimate,\n );\n }\n\n return gasFeeControllerEstimates;\n}\n\n/**\n * Merge a specific priority level of EIP-1559 gas fee estimates.\n * @param gasFeeControllerEstimate - The gas fee estimate from the gas fee controller.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The merged gas fee estimate.\n */\nfunction mergeFeeMarketEstimate(\n gasFeeControllerEstimate: Eip1559GasFee,\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): Eip1559GasFee {\n return {\n ...gasFeeControllerEstimate,\n suggestedMaxFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxFeePerGas,\n ),\n suggestedMaxPriorityFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxPriorityFeePerGas,\n ),\n };\n}\n\n/**\n * Generate a specific priority level for a legacy gas fee estimate.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The legacy gas fee estimate.\n */\nfunction getLegacyEstimate(\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): string {\n return weiHexToGweiDec(transactionGasFeeEstimate.maxFeePerGas);\n}\n"],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAMhC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AS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAEuE;AACrE,MAAI,iCAAiC,mBAAmB,YAAY;AAClE,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,UACP,0BAA0B,KAAK;AAAA,UAC/B,2BAA2B,KAAK;AAAA,QAClC;AAAA,MACF;AAAA,MACA,EAAE,GAAG,0BAA0B;AAAA,IACjC;AAAA,EACF;AAEA,MAAI,iCAAiC,mBAAmB,QAAQ;AAC9D,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG,kBAAkB,2BAA2B,KAAK,CAAC;AAAA,MAC9D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAQA,SAAS,uBACP,0BACA,2BACe;AACf,SAAO;AAAA,IACL,GAAG;AAAA,IACH,uBAAuB;AAAA,MACrB,0BAA0B;AAAA,IAC5B;AAAA,IACA,+BAA+B;AAAA,MAC7B,0BAA0B;AAAA,IAC5B;AAAA,EACF;AACF;AAOA,SAAS,kBACP,2BACQ;AACR,SAAO,gBAAgB,0BAA0B,YAAY;AAC/D","sourcesContent":["import { weiHexToGweiDec } from '@metamask/controller-utils';\nimport type {\n Eip1559GasFee,\n GasFeeEstimates,\n LegacyGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\n\nimport {\n type GasFeeEstimates as TransactionGasFeeEstimates,\n type GasFeeFlow,\n type TransactionMeta,\n type GasFeeEstimatesForLevel,\n GasFeeEstimateLevel,\n} from '../types';\n\n/**\n * Returns the first gas fee flow that matches the transaction.\n *\n * @param transactionMeta - The transaction metadata to find a gas fee flow for.\n * @param gasFeeFlows - The gas fee flows to search.\n * @returns The first gas fee flow that matches the transaction, or undefined if none match.\n */\nexport function getGasFeeFlow(\n transactionMeta: TransactionMeta,\n gasFeeFlows: GasFeeFlow[],\n): GasFeeFlow | undefined {\n return gasFeeFlows.find((gasFeeFlow) =>\n gasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\ntype FeeMarketMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'fee-market';\n gasFeeControllerEstimates: GasFeeEstimates;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\ntype LegacyMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'legacy';\n gasFeeControllerEstimates: LegacyGasPriceEstimate;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\n/**\n * Merge the gas fee estimates from the gas fee controller with the gas fee estimates from a transaction.\n * @param request - Data required to merge gas fee estimates.\n * @param request.gasFeeControllerEstimateType - Gas fee estimate type from the gas fee controller.\n * @param request.gasFeeControllerEstimates - Gas fee estimates from the GasFeeController.\n * @param request.transactionGasFeeEstimates - Gas fee estimates from the transaction.\n * @returns The merged gas fee estimates.\n */\nexport function mergeGasFeeEstimates({\n gasFeeControllerEstimateType,\n gasFeeControllerEstimates,\n transactionGasFeeEstimates,\n}:\n | FeeMarketMergeGasFeeEstimatesRequest\n | LegacyMergeGasFeeEstimatesRequest): GasFeeState['gasFeeEstimates'] {\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: mergeFeeMarketEstimate(\n gasFeeControllerEstimates[level],\n transactionGasFeeEstimates[level],\n ),\n }),\n { ...gasFeeControllerEstimates } as GasFeeEstimates,\n );\n }\n\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: getLegacyEstimate(transactionGasFeeEstimates[level]),\n }),\n {} as LegacyGasPriceEstimate,\n );\n }\n\n return gasFeeControllerEstimates;\n}\n\n/**\n * Merge a specific priority level of EIP-1559 gas fee estimates.\n * @param gasFeeControllerEstimate - The gas fee estimate from the gas fee controller.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The merged gas fee estimate.\n */\nfunction mergeFeeMarketEstimate(\n gasFeeControllerEstimate: Eip1559GasFee,\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): Eip1559GasFee {\n return {\n ...gasFeeControllerEstimate,\n suggestedMaxFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxFeePerGas,\n ),\n suggestedMaxPriorityFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxPriorityFeePerGas,\n ),\n };\n}\n\n/**\n * Generate a specific priority level for a legacy gas fee estimate.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The legacy gas fee estimate.\n */\nfunction getLegacyEstimate(\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): string {\n return weiHexToGweiDec(transactionGasFeeEstimate.maxFeePerGas);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAIrB,SAAS,0BAA0B;AACnC,OAAO,kBAAkB;AAazB,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,wBAAwB;AApB9B;AAyBO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BxB,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAOG;AAkBH;AAcA;AAaA,uBAAM;AAON,uBAAM;AAcN,uBAAM;AAoBN,uBAAM;AAgDN,uBAAM;AAmBN;AAjMA,eAAoB,IAAI,aAAa;AAErC;AAEA;AAEA;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;AAAA,EACjE;AAEA,SAAO;AACT;AAEA;AAAA,+BAA0B,WAAG;AAC3B,SAAO,mBAAK,kBAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG;AAAA,EACb;AACF","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n} from '../types';\nimport { TransactionStatus, type TransactionMeta } from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n\n #getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n\n #getTransactions: () => TransactionMeta[];\n\n #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\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.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\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() {\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() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n log('Found unapproved transactions', unapprovedTransactions.length);\n }\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) =>\n this.#updateUnapprovedTransaction(tx),\n ),\n );\n }\n\n async #updateUnapprovedTransaction(transactionMeta: TransactionMeta) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(transactionMeta),\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 #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { chainId, networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(chainId, networkClientId));\n const gasFeeFlow = getGasFeeFlow(transactionMeta, this.#gasFeeFlows);\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n getGasFeeControllerEstimates: this.#getGasFeeControllerEstimates,\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 { chainId, networkClientId } = transactionMeta;\n const provider = this.#getProvider(chainId, networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n}\n"]}