@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
@@ -0,0 +1,112 @@
1
+ import {
2
+ gweiDecimalToWeiHex
3
+ } from "./chunk-4M7FHI4S.mjs";
4
+ import {
5
+ projectLogger
6
+ } from "./chunk-UQQWZT6C.mjs";
7
+ import {
8
+ GasFeeEstimateLevel
9
+ } from "./chunk-N6JXPWLY.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 _getFeeMarkEstimates, getFeeMarkEstimates_fn, _getLegacyEstimates, getLegacyEstimates_fn, _getGasPriceEstimates, getGasPriceEstimates_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
+ var DefaultGasFeeFlow = class {
21
+ constructor() {
22
+ __privateAdd(this, _getFeeMarkEstimates);
23
+ __privateAdd(this, _getLegacyEstimates);
24
+ __privateAdd(this, _getGasPriceEstimates);
25
+ __privateAdd(this, _getFeeMarketLevel);
26
+ __privateAdd(this, _getLegacyLevel);
27
+ }
28
+ matchesTransaction(_transactionMeta) {
29
+ return true;
30
+ }
31
+ async getGasFees(request) {
32
+ const { gasFeeControllerData } = request;
33
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
34
+ let response;
35
+ switch (gasEstimateType) {
36
+ case GAS_ESTIMATE_TYPES.FEE_MARKET:
37
+ log("Using fee market estimates", gasFeeEstimates);
38
+ response = __privateMethod(this, _getFeeMarkEstimates, getFeeMarkEstimates_fn).call(this, gasFeeEstimates);
39
+ break;
40
+ case GAS_ESTIMATE_TYPES.LEGACY:
41
+ log("Using legacy estimates", gasFeeEstimates);
42
+ response = __privateMethod(this, _getLegacyEstimates, getLegacyEstimates_fn).call(this, gasFeeEstimates);
43
+ break;
44
+ case GAS_ESTIMATE_TYPES.ETH_GASPRICE:
45
+ log("Using eth_gasPrice estimates", gasFeeEstimates);
46
+ response = __privateMethod(this, _getGasPriceEstimates, getGasPriceEstimates_fn).call(this, gasFeeEstimates);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);
50
+ }
51
+ return {
52
+ estimates: response
53
+ };
54
+ }
55
+ };
56
+ _getFeeMarkEstimates = new WeakSet();
57
+ getFeeMarkEstimates_fn = function(gasFeeEstimates) {
58
+ const levels = Object.values(GasFeeEstimateLevel).reduce(
59
+ (result, level) => ({
60
+ ...result,
61
+ [level]: __privateMethod(this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level)
62
+ }),
63
+ {}
64
+ );
65
+ return {
66
+ type: "fee-market" /* FeeMarket */,
67
+ ...levels
68
+ };
69
+ };
70
+ _getLegacyEstimates = new WeakSet();
71
+ getLegacyEstimates_fn = function(gasFeeEstimates) {
72
+ const levels = Object.values(GasFeeEstimateLevel).reduce(
73
+ (result, level) => ({
74
+ ...result,
75
+ [level]: __privateMethod(this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level)
76
+ }),
77
+ {}
78
+ );
79
+ return {
80
+ type: "legacy" /* Legacy */,
81
+ ...levels
82
+ };
83
+ };
84
+ _getGasPriceEstimates = new WeakSet();
85
+ getGasPriceEstimates_fn = function(gasFeeEstimates) {
86
+ return {
87
+ type: "eth_gasPrice" /* GasPrice */,
88
+ gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice)
89
+ };
90
+ };
91
+ _getFeeMarketLevel = new WeakSet();
92
+ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
93
+ const maxFeePerGas = gweiDecimalToWeiHex(
94
+ gasFeeEstimates[level].suggestedMaxFeePerGas
95
+ );
96
+ const maxPriorityFeePerGas = gweiDecimalToWeiHex(
97
+ gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
98
+ );
99
+ return {
100
+ maxFeePerGas,
101
+ maxPriorityFeePerGas
102
+ };
103
+ };
104
+ _getLegacyLevel = new WeakSet();
105
+ getLegacyLevel_fn = function(gasFeeEstimates, level) {
106
+ return gweiDecimalToWeiHex(gasFeeEstimates[level]);
107
+ };
108
+
109
+ export {
110
+ DefaultGasFeeFlow
111
+ };
112
+ //# sourceMappingURL=chunk-REOG6YD4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n EthGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n GasPriceGasFeeEstimates,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\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 { gasFeeControllerData } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n let response: GasFeeEstimates;\n\n switch (gasEstimateType) {\n case GAS_ESTIMATE_TYPES.FEE_MARKET:\n log('Using fee market estimates', gasFeeEstimates);\n response = this.#getFeeMarkEstimates(gasFeeEstimates);\n break;\n case GAS_ESTIMATE_TYPES.LEGACY:\n log('Using legacy estimates', gasFeeEstimates);\n response = this.#getLegacyEstimates(\n gasFeeEstimates as LegacyGasPriceEstimate,\n );\n break;\n case GAS_ESTIMATE_TYPES.ETH_GASPRICE:\n log('Using eth_gasPrice estimates', gasFeeEstimates);\n response = this.#getGasPriceEstimates(\n gasFeeEstimates as EthGasPriceEstimate,\n );\n break;\n default:\n throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);\n }\n\n return {\n estimates: response,\n };\n }\n\n #getFeeMarkEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getFeeMarketLevel(gasFeeEstimates, level),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getLegacyEstimates(\n gasFeeEstimates: LegacyGasPriceEstimate,\n ): LegacyGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getLegacyLevel(gasFeeEstimates, level),\n }),\n {} as Omit<LegacyGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.Legacy,\n ...levels,\n };\n }\n\n #getGasPriceEstimates(\n gasFeeEstimates: EthGasPriceEstimate,\n ): GasPriceGasFeeEstimates {\n return {\n type: GasFeeEstimateType.GasPrice,\n gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice),\n };\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): FeeMarketGasFeeEstimateForLevel {\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 ): Hex {\n return gweiDecimalToWeiHex(gasFeeEstimates[level]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAKA,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AAiBnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAxBpE;AA6BO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAqCL;AAiBA;AAiBA;AASA;AAkBA;AAAA;AAAA,EAjGA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,qBAAqB,IAAI;AACjC,UAAM,EAAE,iBAAiB,gBAAgB,IAAI;AAE7C,QAAI;AAEJ,YAAQ,iBAAiB;AAAA,MACvB,KAAK,mBAAmB;AACtB,YAA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L;AAAA,IACA;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SACb,iBACA,OACK;AACL,SAAO,oBAAoB,gBAAgB,KAAK,CAAC;AACnD;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-NOHEXQ7Y.mjs";
4
4
  import {
5
5
  getGasFeeFlow
6
- } from "./chunk-TWND5SFD.mjs";
6
+ } from "./chunk-AGJNOOBN.mjs";
7
7
  import {
8
8
  projectLogger
9
9
  } from "./chunk-UQQWZT6C.mjs";
@@ -20,11 +20,12 @@ import { createModuleLogger } from "@metamask/utils";
20
20
  import EventEmitter from "events";
21
21
  var log = createModuleLogger(projectLogger, "gas-fee-poller");
22
22
  var INTERVAL_MILLISECONDS = 1e4;
23
- var _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn;
23
+ var _findNetworkClientIdByChainId, _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn, _getGasFeeControllerData, getGasFeeControllerData_fn;
24
24
  var GasFeePoller = class {
25
25
  /**
26
26
  * Constructs a new instance of the GasFeePoller.
27
27
  * @param options - The options for this instance.
28
+ * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
28
29
  * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
29
30
  * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
30
31
  * @param options.getProvider - Callback to obtain a provider instance.
@@ -33,6 +34,7 @@ var GasFeePoller = class {
33
34
  * @param options.onStateChange - Callback to register a listener for controller state changes.
34
35
  */
35
36
  constructor({
37
+ findNetworkClientIdByChainId,
36
38
  gasFeeFlows,
37
39
  getGasFeeControllerEstimates,
38
40
  getProvider,
@@ -48,7 +50,9 @@ var GasFeePoller = class {
48
50
  __privateAdd(this, _updateTransactionGasFeeEstimates);
49
51
  __privateAdd(this, _updateTransactionLayer1GasFee);
50
52
  __privateAdd(this, _getUnapprovedTransactions);
53
+ __privateAdd(this, _getGasFeeControllerData);
51
54
  this.hub = new EventEmitter();
55
+ __privateAdd(this, _findNetworkClientIdByChainId, void 0);
52
56
  __privateAdd(this, _gasFeeFlows, void 0);
53
57
  __privateAdd(this, _getGasFeeControllerEstimates, void 0);
54
58
  __privateAdd(this, _getProvider, void 0);
@@ -56,6 +60,7 @@ var GasFeePoller = class {
56
60
  __privateAdd(this, _layer1GasFeeFlows, void 0);
57
61
  __privateAdd(this, _timeout, void 0);
58
62
  __privateAdd(this, _running, false);
63
+ __privateSet(this, _findNetworkClientIdByChainId, findNetworkClientIdByChainId);
59
64
  __privateSet(this, _gasFeeFlows, gasFeeFlows);
60
65
  __privateSet(this, _layer1GasFeeFlows, layer1GasFeeFlows);
61
66
  __privateSet(this, _getGasFeeControllerEstimates, getGasFeeControllerEstimates);
@@ -71,6 +76,7 @@ var GasFeePoller = class {
71
76
  });
72
77
  }
73
78
  };
79
+ _findNetworkClientIdByChainId = new WeakMap();
74
80
  _gasFeeFlows = new WeakMap();
75
81
  _getGasFeeControllerEstimates = new WeakMap();
76
82
  _getProvider = new WeakMap();
@@ -105,20 +111,27 @@ onTimeout_fn = async function() {
105
111
  _updateUnapprovedTransactions = new WeakSet();
106
112
  updateUnapprovedTransactions_fn = async function() {
107
113
  const unapprovedTransactions = __privateMethod(this, _getUnapprovedTransactions, getUnapprovedTransactions_fn).call(this);
108
- if (unapprovedTransactions.length) {
109
- log("Found unapproved transactions", unapprovedTransactions.length);
114
+ if (!unapprovedTransactions.length) {
115
+ return;
110
116
  }
117
+ log("Found unapproved transactions", unapprovedTransactions.length);
118
+ const gasFeeControllerDataByChainId = await __privateMethod(this, _getGasFeeControllerData, getGasFeeControllerData_fn).call(this, unapprovedTransactions);
119
+ log("Retrieved gas fee controller data", gasFeeControllerDataByChainId);
111
120
  await Promise.all(
112
- unapprovedTransactions.flatMap(
113
- (tx) => __privateMethod(this, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn).call(this, tx)
114
- )
121
+ unapprovedTransactions.flatMap((tx) => {
122
+ const { chainId } = tx;
123
+ const gasFeeControllerData = gasFeeControllerDataByChainId.get(
124
+ chainId
125
+ );
126
+ return __privateMethod(this, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn).call(this, tx, gasFeeControllerData);
127
+ })
115
128
  );
116
129
  };
117
130
  _updateUnapprovedTransaction = new WeakSet();
118
- updateUnapprovedTransaction_fn = async function(transactionMeta) {
131
+ updateUnapprovedTransaction_fn = async function(transactionMeta, gasFeeControllerData) {
119
132
  const { id } = transactionMeta;
120
133
  const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([
121
- __privateMethod(this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta),
134
+ __privateMethod(this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta, gasFeeControllerData),
122
135
  __privateMethod(this, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn).call(this, transactionMeta)
123
136
  ]);
124
137
  if (!gasFeeEstimatesResponse && !layer1GasFee) {
@@ -132,7 +145,7 @@ updateUnapprovedTransaction_fn = async function(transactionMeta) {
132
145
  });
133
146
  };
134
147
  _updateTransactionGasFeeEstimates = new WeakSet();
135
- updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
148
+ updateTransactionGasFeeEstimates_fn = async function(transactionMeta, gasFeeControllerData) {
136
149
  const { chainId, networkClientId } = transactionMeta;
137
150
  const ethQuery = new EthQuery(__privateGet(this, _getProvider).call(this, chainId, networkClientId));
138
151
  const gasFeeFlow = getGasFeeFlow(transactionMeta, __privateGet(this, _gasFeeFlows));
@@ -145,7 +158,7 @@ updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
145
158
  }
146
159
  const request = {
147
160
  ethQuery,
148
- getGasFeeControllerEstimates: __privateGet(this, _getGasFeeControllerEstimates),
161
+ gasFeeControllerData,
149
162
  transactionMeta
150
163
  };
151
164
  let gasFeeEstimates;
@@ -186,8 +199,30 @@ getUnapprovedTransactions_fn = function() {
186
199
  (tx) => tx.status === "unapproved" /* unapproved */
187
200
  );
188
201
  };
202
+ _getGasFeeControllerData = new WeakSet();
203
+ getGasFeeControllerData_fn = async function(transactions) {
204
+ const networkClientIdsByChainId = /* @__PURE__ */ new Map();
205
+ for (const transaction of transactions) {
206
+ const { chainId, networkClientId: transactionNetworkClientId } = transaction;
207
+ if (networkClientIdsByChainId.has(chainId)) {
208
+ continue;
209
+ }
210
+ const networkClientId = transactionNetworkClientId ?? __privateGet(this, _findNetworkClientIdByChainId).call(this, chainId);
211
+ networkClientIdsByChainId.set(chainId, networkClientId);
212
+ }
213
+ log("Extracted network client IDs by chain ID", networkClientIdsByChainId);
214
+ const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(
215
+ async ([chainId, networkClientId]) => {
216
+ return [
217
+ chainId,
218
+ await __privateGet(this, _getGasFeeControllerEstimates).call(this, { networkClientId })
219
+ ];
220
+ }
221
+ );
222
+ return new Map(await Promise.all(entryPromises));
223
+ };
189
224
 
190
225
  export {
191
226
  GasFeePoller
192
227
  };
193
- //# sourceMappingURL=chunk-HHK4QSNF.mjs.map
228
+ //# sourceMappingURL=chunk-SL3GHHKG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\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 #findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n\n #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => 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.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.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 findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n\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 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 #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\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 #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\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 gasFeeControllerData,\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 async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAOrB,SAAS,0BAA0B;AACnC,OAAO,kBAAkB;AAazB,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,wBAAwB;AAvB9B;AA4BO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAA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,IAAI,aAAa,CAAC;AACjD;","names":[]}
@@ -0,0 +1,66 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
7
+
8
+ // src/gas-flows/TestGasFeeFlow.ts
9
+ var _controllerutils = require('@metamask/controller-utils');
10
+ var INCREMENT = 1e15;
11
+ var LEVEL_DIFFERENCE = 0.5;
12
+ var _counter, _getValueForTotalFee, getValueForTotalFee_fn;
13
+ var TestGasFeeFlow = class {
14
+ constructor() {
15
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getValueForTotalFee);
16
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _counter, 1);
17
+ }
18
+ matchesTransaction(_transactionMeta) {
19
+ return true;
20
+ }
21
+ async getGasFees(request) {
22
+ const { transactionMeta } = request;
23
+ const { txParams } = transactionMeta;
24
+ const { gas: gasHex } = txParams;
25
+ if (!gasHex) {
26
+ throw new Error("Cannot estimate fee without gas value");
27
+ }
28
+ const gasDecimal = parseInt(gasHex, 16);
29
+ const difference = INCREMENT * LEVEL_DIFFERENCE;
30
+ const mediumMaxTarget = (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) + 1) * INCREMENT;
31
+ const mediumPriorityTarget = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) * INCREMENT;
32
+ const lowMaxTarget = mediumMaxTarget - difference;
33
+ const lowPriorityTarget = mediumPriorityTarget - difference;
34
+ const highMaxTarget = mediumMaxTarget + difference;
35
+ const highPriorityTarget = mediumPriorityTarget + difference;
36
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _counter, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) + 1);
37
+ return {
38
+ estimates: {
39
+ type: "fee-market" /* FeeMarket */,
40
+ low: {
41
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, lowMaxTarget, gasDecimal),
42
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, lowPriorityTarget, gasDecimal)
43
+ },
44
+ medium: {
45
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, mediumMaxTarget, gasDecimal),
46
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, mediumPriorityTarget, gasDecimal)
47
+ },
48
+ high: {
49
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, highMaxTarget, gasDecimal),
50
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, highPriorityTarget, gasDecimal)
51
+ }
52
+ }
53
+ };
54
+ }
55
+ };
56
+ _counter = new WeakMap();
57
+ _getValueForTotalFee = new WeakSet();
58
+ getValueForTotalFee_fn = function(totalFee, gas) {
59
+ const feeDecimal = Math.ceil(totalFee / gas);
60
+ return _controllerutils.toHex.call(void 0, feeDecimal);
61
+ };
62
+
63
+
64
+
65
+ exports.TestGasFeeFlow = TestGasFeeFlow;
66
+ //# sourceMappingURL=chunk-TJMQEH57.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,aAAa;AAWtB,IAAM,YAAY;AAClB,IAAM,mBAAmB;AAZzB;AAmBO,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AA0DL;AAzDA,iCAAW;AAAA;AAAA,EAEX,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,gBAAgB,IAAI;AAC5B,UAAM,EAAE,SAAS,IAAI;AACrB,UAAM,EAAE,KAAK,OAAO,IAAI;AAExB,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AAEA,UAAM,aAAa,SAAS,QAAQ,EAAE;AACtC,UAAM,aAAa,YAAY;AAE/B,UAAM,mBAAmB,mBAAK,YAAW,KAAK;AAC9C,UAAM,uBAAuB,mBAAK,YAAW;AAE7C,UAAM,eAAe,kBAAkB;AACvC,UAAM,oBAAoB,uBAAuB;AAEjD,UAAM,gBAAgB,kBAAkB;AACxC,UAAM,qBAAqB,uBAAuB;AAElD,uBAAK,UAAL,mBAAK,YAAY;AAEjB,WAAO;AAAA,MACL,WAAW;AAAA,QACT;AAAA,QACA,KAAK;AAAA,UACH,cAAc,sBAAK,8CAAL,WAA0B,cAAc;AAAA,UACtD,sBAAsB,sBAAK,8CAAL,WACpB,mBACA;AAAA,QAEJ;AAAA,QACA,QAAQ;AAAA,UACN,cAAc,sBAAK,8CAAL,WAA0B,iBAAiB;AAAA,UACzD,sBAAsB,sBAAK,8CAAL,WACpB,sBACA;AAAA,QAEJ;AAAA,QACA,MAAM;AAAA,UACJ,cAAc,sBAAK,8CAAL,WAA0B,eAAe;AAAA,UACvD,sBAAsB,sBAAK,8CAAL,WACpB,oBACA;AAAA,QAEJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAMF;AA7DE;AAyDA;AAAA,yBAAoB,SAAC,UAAkB,KAAkB;AACvD,QAAM,aAAa,KAAK,KAAK,WAAW,GAAG;AAC3C,SAAO,MAAM,UAAU;AACzB","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n GasFeeEstimateType,\n type GasFeeFlow,\n type GasFeeFlowRequest,\n type GasFeeFlowResponse,\n type TransactionMeta,\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(_transactionMeta: TransactionMeta): 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"]}
@@ -0,0 +1,112 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkKNYSD4JPjs = require('./chunk-KNYSD4JP.js');
4
+
5
+
6
+ var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
7
+
8
+
9
+ var _chunk5C3CSQADjs = require('./chunk-5C3CSQAD.js');
10
+
11
+
12
+
13
+ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
14
+
15
+ // src/gas-flows/DefaultGasFeeFlow.ts
16
+ var _gasfeecontroller = require('@metamask/gas-fee-controller');
17
+ var _utils = require('@metamask/utils');
18
+ var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger, "default-gas-fee-flow");
19
+ var _getFeeMarkEstimates, getFeeMarkEstimates_fn, _getLegacyEstimates, getLegacyEstimates_fn, _getGasPriceEstimates, getGasPriceEstimates_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
+ var DefaultGasFeeFlow = class {
21
+ constructor() {
22
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getFeeMarkEstimates);
23
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getLegacyEstimates);
24
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getGasPriceEstimates);
25
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getFeeMarketLevel);
26
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getLegacyLevel);
27
+ }
28
+ matchesTransaction(_transactionMeta) {
29
+ return true;
30
+ }
31
+ async getGasFees(request) {
32
+ const { gasFeeControllerData } = request;
33
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
34
+ let response;
35
+ switch (gasEstimateType) {
36
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.FEE_MARKET:
37
+ log("Using fee market estimates", gasFeeEstimates);
38
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getFeeMarkEstimates, getFeeMarkEstimates_fn).call(this, gasFeeEstimates);
39
+ break;
40
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.LEGACY:
41
+ log("Using legacy estimates", gasFeeEstimates);
42
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLegacyEstimates, getLegacyEstimates_fn).call(this, gasFeeEstimates);
43
+ break;
44
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.ETH_GASPRICE:
45
+ log("Using eth_gasPrice estimates", gasFeeEstimates);
46
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getGasPriceEstimates, getGasPriceEstimates_fn).call(this, gasFeeEstimates);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);
50
+ }
51
+ return {
52
+ estimates: response
53
+ };
54
+ }
55
+ };
56
+ _getFeeMarkEstimates = new WeakSet();
57
+ getFeeMarkEstimates_fn = function(gasFeeEstimates) {
58
+ const levels = Object.values(_chunk5C3CSQADjs.GasFeeEstimateLevel).reduce(
59
+ (result, level) => ({
60
+ ...result,
61
+ [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level)
62
+ }),
63
+ {}
64
+ );
65
+ return {
66
+ type: "fee-market" /* FeeMarket */,
67
+ ...levels
68
+ };
69
+ };
70
+ _getLegacyEstimates = new WeakSet();
71
+ getLegacyEstimates_fn = function(gasFeeEstimates) {
72
+ const levels = Object.values(_chunk5C3CSQADjs.GasFeeEstimateLevel).reduce(
73
+ (result, level) => ({
74
+ ...result,
75
+ [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level)
76
+ }),
77
+ {}
78
+ );
79
+ return {
80
+ type: "legacy" /* Legacy */,
81
+ ...levels
82
+ };
83
+ };
84
+ _getGasPriceEstimates = new WeakSet();
85
+ getGasPriceEstimates_fn = function(gasFeeEstimates) {
86
+ return {
87
+ type: "eth_gasPrice" /* GasPrice */,
88
+ gasPrice: _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates.gasPrice)
89
+ };
90
+ };
91
+ _getFeeMarketLevel = new WeakSet();
92
+ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
93
+ const maxFeePerGas = _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0,
94
+ gasFeeEstimates[level].suggestedMaxFeePerGas
95
+ );
96
+ const maxPriorityFeePerGas = _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0,
97
+ gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
98
+ );
99
+ return {
100
+ maxFeePerGas,
101
+ maxPriorityFeePerGas
102
+ };
103
+ };
104
+ _getLegacyLevel = new WeakSet();
105
+ getLegacyLevel_fn = function(gasFeeEstimates, level) {
106
+ return _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates[level]);
107
+ };
108
+
109
+
110
+
111
+ exports.DefaultGasFeeFlow = DefaultGasFeeFlow;
112
+ //# sourceMappingURL=chunk-VJYFB7BM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AAiBnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAxBpE;AA6BO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAqCL;AAiBA;AAiBA;AASA;AAkBA;AAAA;AAAA,EAjGA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,qBAAqB,IAAI;AACjC,UAAM,EAAE,iBAAiB,gBAAgB,IAAI;AAE7C,QAAI;AAEJ,YAAQ,iBAAiB;AAAA,MACvB,KAAK,mBAAmB;AACtB,YAAI,8BAA8B,eAAe;AACjD,mBAAW,sBAAK,8CAAL,WAA0B;AACrC;AAAA,MACF,KAAK,mBAAmB;AACtB,YAAI,0BAA0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C;AACnD","sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n EthGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n GasPriceGasFeeEstimates,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\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 { gasFeeControllerData } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n let response: GasFeeEstimates;\n\n switch (gasEstimateType) {\n case GAS_ESTIMATE_TYPES.FEE_MARKET:\n log('Using fee market estimates', gasFeeEstimates);\n response = this.#getFeeMarkEstimates(gasFeeEstimates);\n break;\n case GAS_ESTIMATE_TYPES.LEGACY:\n log('Using legacy estimates', gasFeeEstimates);\n response = this.#getLegacyEstimates(\n gasFeeEstimates as LegacyGasPriceEstimate,\n );\n break;\n case GAS_ESTIMATE_TYPES.ETH_GASPRICE:\n log('Using eth_gasPrice estimates', gasFeeEstimates);\n response = this.#getGasPriceEstimates(\n gasFeeEstimates as EthGasPriceEstimate,\n );\n break;\n default:\n throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);\n }\n\n return {\n estimates: response,\n };\n }\n\n #getFeeMarkEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getFeeMarketLevel(gasFeeEstimates, level),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getLegacyEstimates(\n gasFeeEstimates: LegacyGasPriceEstimate,\n ): LegacyGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getLegacyLevel(gasFeeEstimates, level),\n }),\n {} as Omit<LegacyGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.Legacy,\n ...levels,\n };\n }\n\n #getGasPriceEstimates(\n gasFeeEstimates: EthGasPriceEstimate,\n ): GasPriceGasFeeEstimates {\n return {\n type: GasFeeEstimateType.GasPrice,\n gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice),\n };\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): FeeMarketGasFeeEstimateForLevel {\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 ): Hex {\n return gweiDecimalToWeiHex(gasFeeEstimates[level]);\n }\n}\n"]}
@@ -161,24 +161,26 @@ function parseEventArgValue(value) {
161
161
  return (value.toHexString?.() ?? value).toLowerCase();
162
162
  }
163
163
  async function getTokenBalanceChanges(request, events) {
164
- const balanceTransactionsByToken = getTokenBalanceTransactions(
164
+ const balanceTxs = getTokenBalanceTransactions(request, events);
165
+ log("Generated balance transactions", [...balanceTxs.after.values()]);
166
+ const transactions = [
167
+ ...balanceTxs.before.values(),
165
168
  request,
166
- events
167
- );
168
- const balanceTransactions = [...balanceTransactionsByToken.values()];
169
- log("Generated balance transactions", balanceTransactions);
170
- if (!balanceTransactions.length) {
169
+ ...balanceTxs.after.values()
170
+ ];
171
+ if (transactions.length === 1) {
171
172
  return [];
172
173
  }
173
174
  const response = await _chunkKT6UAKBBjs.simulateTransactions.call(void 0, request.chainId, {
174
- transactions: [...balanceTransactions, request, ...balanceTransactions]
175
+ transactions
175
176
  });
176
177
  log("Balance simulation response", response);
177
- if (response.transactions.length !== balanceTransactions.length * 2 + 1) {
178
+ if (response.transactions.length !== transactions.length) {
178
179
  throw new (0, _chunkHMOSP33Fjs.SimulationInvalidResponseError)();
179
180
  }
180
- return [...balanceTransactionsByToken.keys()].map((token, index) => {
181
- const previousBalance = getValueFromBalanceTransaction(
181
+ return [...balanceTxs.after.keys()].map((token, index) => {
182
+ const previousBalanceCheckSkipped = !balanceTxs.before.get(token);
183
+ const previousBalance = previousBalanceCheckSkipped ? "0x0" : getValueFromBalanceTransaction(
182
184
  request.from,
183
185
  token,
184
186
  response.transactions[index]
@@ -186,7 +188,7 @@ async function getTokenBalanceChanges(request, events) {
186
188
  const newBalance = getValueFromBalanceTransaction(
187
189
  request.from,
188
190
  token,
189
- response.transactions[index + balanceTransactions.length + 1]
191
+ response.transactions[index + balanceTxs.before.size + 1]
190
192
  );
191
193
  const balanceChange = getSimulationBalanceChange(
192
194
  previousBalance,
@@ -203,11 +205,13 @@ async function getTokenBalanceChanges(request, events) {
203
205
  }
204
206
  function getTokenBalanceTransactions(request, events) {
205
207
  const tokenKeys = /* @__PURE__ */ new Set();
208
+ const before = /* @__PURE__ */ new Map();
209
+ const after = /* @__PURE__ */ new Map();
206
210
  const userEvents = events.filter(
207
211
  (event) => SUPPORTED_EVENTS.includes(event.name) && [event.args.from, event.args.to].includes(request.from)
208
212
  );
209
213
  log("Filtered user events", userEvents);
210
- return userEvents.reduce((result, event) => {
214
+ for (const event of userEvents) {
211
215
  const tokenIds = getEventTokenIds(event);
212
216
  log("Extracted token ids", tokenIds);
213
217
  for (const tokenId of tokenIds) {
@@ -230,14 +234,23 @@ function getTokenBalanceTransactions(request, events) {
230
234
  request.from,
231
235
  tokenId
232
236
  );
233
- result.set(simulationToken, {
237
+ const transaction = {
234
238
  from: request.from,
235
239
  to: event.contractAddress,
236
240
  data
237
- });
241
+ };
242
+ if (skipPriorBalanceCheck(event)) {
243
+ after.set(simulationToken, transaction);
244
+ } else {
245
+ before.set(simulationToken, transaction);
246
+ after.set(simulationToken, transaction);
247
+ }
238
248
  }
239
- return result;
240
- }, /* @__PURE__ */ new Map());
249
+ }
250
+ return { before, after };
251
+ }
252
+ function skipPriorBalanceCheck(event) {
253
+ return event.name === "Transfer" && event.tokenStandard === "erc721" /* erc721 */ && parseInt(event.args.from, 16) === 0;
241
254
  }
242
255
  function getEventTokenIds(event) {
243
256
  if (event.tokenStandard === "erc721" /* erc721 */) {
@@ -332,5 +345,6 @@ function getContractInterfaces() {
332
345
 
333
346
 
334
347
 
335
- exports.SupportedToken = SupportedToken; exports.getSimulationData = getSimulationData;
336
- //# sourceMappingURL=chunk-JAYYMCBQ.js.map
348
+
349
+ exports.SupportedToken = SupportedToken; exports.getSimulationData = getSimulationData; exports.getEvents = getEvents;
350
+ //# sourceMappingURL=chunk-X3KACH5P.js.map