@metamask/transaction-controller 52.2.0 → 52.3.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 (156) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/TransactionController.cjs +22 -4
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +0 -2
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +0 -2
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +25 -7
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/constants.cjs +1 -0
  11. package/dist/constants.cjs.map +1 -1
  12. package/dist/constants.d.cts +1 -0
  13. package/dist/constants.d.cts.map +1 -1
  14. package/dist/constants.d.mts +1 -0
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.mjs +1 -0
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/gas-flows/DefaultGasFeeFlow.cjs +1 -3
  19. package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -1
  20. package/dist/gas-flows/DefaultGasFeeFlow.d.cts +2 -2
  21. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -1
  22. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +2 -2
  23. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -1
  24. package/dist/gas-flows/DefaultGasFeeFlow.mjs +1 -3
  25. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
  26. package/dist/gas-flows/LineaGasFeeFlow.cjs +1 -1
  27. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  28. package/dist/gas-flows/LineaGasFeeFlow.d.cts +5 -1
  29. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  30. package/dist/gas-flows/LineaGasFeeFlow.d.mts +5 -1
  31. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  32. package/dist/gas-flows/LineaGasFeeFlow.mjs +1 -1
  33. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  34. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +1 -1
  35. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
  36. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts +5 -1
  37. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
  38. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +5 -1
  39. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
  40. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +1 -1
  41. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  42. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -1
  43. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts +5 -1
  44. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -1
  45. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +5 -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 +123 -0
  49. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -0
  50. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts +28 -0
  51. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -0
  52. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts +28 -0
  53. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -0
  54. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs +118 -0
  55. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -0
  56. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +1 -1
  57. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
  58. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts +5 -1
  59. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
  60. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +5 -1
  61. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
  62. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +1 -1
  63. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  64. package/dist/gas-flows/TestGasFeeFlow.cjs +1 -1
  65. package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -1
  66. package/dist/gas-flows/TestGasFeeFlow.d.cts +2 -2
  67. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -1
  68. package/dist/gas-flows/TestGasFeeFlow.d.mts +2 -2
  69. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -1
  70. package/dist/gas-flows/TestGasFeeFlow.mjs +1 -1
  71. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
  72. package/dist/helpers/GasFeePoller.cjs +11 -8
  73. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  74. package/dist/helpers/GasFeePoller.d.cts +6 -5
  75. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  76. package/dist/helpers/GasFeePoller.d.mts +6 -5
  77. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  78. package/dist/helpers/GasFeePoller.mjs +11 -8
  79. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  80. package/dist/helpers/IncomingTransactionHelper.cjs +2 -1
  81. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  82. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  83. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  84. package/dist/helpers/IncomingTransactionHelper.mjs +2 -1
  85. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  86. package/dist/helpers/PendingTransactionTracker.cjs +6 -2
  87. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  88. package/dist/helpers/PendingTransactionTracker.d.cts +5 -2
  89. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  90. package/dist/helpers/PendingTransactionTracker.d.mts +5 -2
  91. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  92. package/dist/helpers/PendingTransactionTracker.mjs +6 -2
  93. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  94. package/dist/helpers/TransactionPoller.cjs +12 -8
  95. package/dist/helpers/TransactionPoller.cjs.map +1 -1
  96. package/dist/helpers/TransactionPoller.d.cts +7 -3
  97. package/dist/helpers/TransactionPoller.d.cts.map +1 -1
  98. package/dist/helpers/TransactionPoller.d.mts +7 -3
  99. package/dist/helpers/TransactionPoller.d.mts.map +1 -1
  100. package/dist/helpers/TransactionPoller.mjs +11 -7
  101. package/dist/helpers/TransactionPoller.mjs.map +1 -1
  102. package/dist/types.cjs.map +1 -1
  103. package/dist/types.d.cts +18 -5
  104. package/dist/types.d.cts.map +1 -1
  105. package/dist/types.d.mts +18 -5
  106. package/dist/types.d.mts.map +1 -1
  107. package/dist/types.mjs.map +1 -1
  108. package/dist/utils/feature-flags.cjs +39 -2
  109. package/dist/utils/feature-flags.cjs.map +1 -1
  110. package/dist/utils/feature-flags.d.cts +49 -0
  111. package/dist/utils/feature-flags.d.cts.map +1 -1
  112. package/dist/utils/feature-flags.d.mts +49 -0
  113. package/dist/utils/feature-flags.d.mts.map +1 -1
  114. package/dist/utils/feature-flags.mjs +36 -1
  115. package/dist/utils/feature-flags.mjs.map +1 -1
  116. package/dist/utils/gas-fees.cjs +21 -3
  117. package/dist/utils/gas-fees.cjs.map +1 -1
  118. package/dist/utils/gas-fees.d.cts +14 -0
  119. package/dist/utils/gas-fees.d.cts.map +1 -1
  120. package/dist/utils/gas-fees.d.mts +14 -0
  121. package/dist/utils/gas-fees.d.mts.map +1 -1
  122. package/dist/utils/gas-fees.mjs +19 -2
  123. package/dist/utils/gas-fees.mjs.map +1 -1
  124. package/dist/utils/gas-flow.cjs +3 -2
  125. package/dist/utils/gas-flow.cjs.map +1 -1
  126. package/dist/utils/gas-flow.d.cts +3 -1
  127. package/dist/utils/gas-flow.d.cts.map +1 -1
  128. package/dist/utils/gas-flow.d.mts +3 -1
  129. package/dist/utils/gas-flow.d.mts.map +1 -1
  130. package/dist/utils/gas-flow.mjs +3 -2
  131. package/dist/utils/gas-flow.mjs.map +1 -1
  132. package/dist/utils/layer1-gas-fee-flow.cjs +9 -4
  133. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  134. package/dist/utils/layer1-gas-fee-flow.d.cts +4 -1
  135. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  136. package/dist/utils/layer1-gas-fee-flow.d.mts +4 -1
  137. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  138. package/dist/utils/layer1-gas-fee-flow.mjs +9 -4
  139. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  140. package/dist/utils/simulation.cjs +17 -2
  141. package/dist/utils/simulation.cjs.map +1 -1
  142. package/dist/utils/simulation.d.cts +1 -0
  143. package/dist/utils/simulation.d.cts.map +1 -1
  144. package/dist/utils/simulation.d.mts +1 -0
  145. package/dist/utils/simulation.d.mts.map +1 -1
  146. package/dist/utils/simulation.mjs +17 -2
  147. package/dist/utils/simulation.mjs.map +1 -1
  148. package/dist/utils/utils.cjs +23 -1
  149. package/dist/utils/utils.cjs.map +1 -1
  150. package/dist/utils/utils.d.cts +8 -0
  151. package/dist/utils/utils.d.cts.map +1 -1
  152. package/dist/utils/utils.d.mts +8 -0
  153. package/dist/utils/utils.d.mts.map +1 -1
  154. package/dist/utils/utils.mjs +22 -1
  155. package/dist/utils/utils.mjs.map +1 -1
  156. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"OracleLayer1GasFeeFlow.mjs","sourceRoot":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ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [{ internalType: 'bytes', name: '_data', type: 'bytes' }],\n name: 'getL1Fee',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n readonly #oracleAddress: Hex;\n\n readonly #signTransaction: boolean;\n\n constructor(oracleAddress: Hex, signTransaction?: boolean) {\n this.#oracleAddress = oracleAddress;\n this.#signTransaction = signTransaction ?? false;\n }\n\n abstract matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n return await this.#getOracleLayer1GasFee(request);\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n const { provider, transactionMeta } = request;\n\n const contract = new Contract(\n this.#oracleAddress,\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.#signTransaction,\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return {\n layer1Fee: result.toHexString(),\n };\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ) {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n unserializedTransaction = unserializedTransaction.sign(keyBuffer);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"OracleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAyB,iCAAiC;AAE/E,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAQ1C,OAAO,EAAE,kBAAkB,EAAE,6BAAyB;AAEtD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACjE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE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yB,eAAe,CAAC,CAAC;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IAEpC,IAAI,uBAAuB,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEpE,IAAI,IAAI,EAAE;QACR,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KACnE;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider, type ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [{ internalType: 'bytes', name: '_data', type: 'bytes' }],\n name: 'getL1Fee',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n readonly #oracleAddress: Hex;\n\n readonly #signTransaction: boolean;\n\n constructor(oracleAddress: Hex, signTransaction?: boolean) {\n this.#oracleAddress = oracleAddress;\n this.#signTransaction = signTransaction ?? false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean;\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n return await this.#getOracleLayer1GasFee(request);\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n const { provider, transactionMeta } = request;\n\n const contract = new Contract(\n this.#oracleAddress,\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.#signTransaction,\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return {\n layer1Fee: result.toHexString(),\n };\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ) {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n unserializedTransaction = unserializedTransaction.sign(keyBuffer);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n}\n"]}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _RandomisedEstimationsGasFeeFlow_instances, _RandomisedEstimationsGasFeeFlow_getDefaultGasFees, _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.randomiseDecimalGWEIAndConvertToHex = exports.RandomisedEstimationsGasFeeFlow = void 0;
10
+ const gas_fee_controller_1 = require("@metamask/gas-fee-controller");
11
+ const utils_1 = require("@metamask/utils");
12
+ const DefaultGasFeeFlow_1 = require("./DefaultGasFeeFlow.cjs");
13
+ const logger_1 = require("../logger.cjs");
14
+ const types_1 = require("../types.cjs");
15
+ const feature_flags_1 = require("../utils/feature-flags.cjs");
16
+ const gas_fees_1 = require("../utils/gas-fees.cjs");
17
+ const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'randomised-estimation-gas-fee-flow');
18
+ const DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;
19
+ /**
20
+ * Implementation of a gas fee flow that randomises the last digits of gas fee estimations
21
+ */
22
+ class RandomisedEstimationsGasFeeFlow {
23
+ constructor() {
24
+ _RandomisedEstimationsGasFeeFlow_instances.add(this);
25
+ }
26
+ matchesTransaction({ transactionMeta, messenger, }) {
27
+ const { chainId } = transactionMeta;
28
+ const gasFeeRandomisation = (0, feature_flags_1.getGasFeeRandomisation)(messenger);
29
+ const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[chainId];
30
+ return randomisedGasFeeDigits !== undefined;
31
+ }
32
+ async getGasFees(request) {
33
+ try {
34
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees).call(this, request);
35
+ }
36
+ catch (error) {
37
+ log('Using default flow as fallback due to error', error);
38
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getDefaultGasFees).call(this, request);
39
+ }
40
+ }
41
+ }
42
+ exports.RandomisedEstimationsGasFeeFlow = RandomisedEstimationsGasFeeFlow;
43
+ _RandomisedEstimationsGasFeeFlow_instances = new WeakSet(), _RandomisedEstimationsGasFeeFlow_getDefaultGasFees = async function _RandomisedEstimationsGasFeeFlow_getDefaultGasFees(request) {
44
+ return new DefaultGasFeeFlow_1.DefaultGasFeeFlow().getGasFees(request);
45
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees = async function _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees(request) {
46
+ const { messenger, gasFeeControllerData, transactionMeta } = request;
47
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
48
+ const gasFeeRandomisation = (0, feature_flags_1.getGasFeeRandomisation)(messenger);
49
+ const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];
50
+ const preservedNumberOfDigits = gasFeeRandomisation.preservedNumberOfDigits ??
51
+ DEFAULT_PRESERVE_NUMBER_OF_DIGITS;
52
+ if (gasEstimateType === gas_fee_controller_1.GAS_ESTIMATE_TYPES.FEE_MARKET) {
53
+ log('Randomising fee market estimates', gasFeeEstimates);
54
+ const randomisedFeeMarketEstimates = __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates).call(this, gasFeeEstimates, randomisedGasFeeDigits, preservedNumberOfDigits);
55
+ log('Added randomised fee market estimates', randomisedFeeMarketEstimates);
56
+ return {
57
+ estimates: randomisedFeeMarketEstimates,
58
+ };
59
+ }
60
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getDefaultGasFees).call(this, request);
61
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates(gasFeeEstimates, lastNDigits, preservedNumberOfDigits) {
62
+ const levels = Object.values(types_1.GasFeeEstimateLevel).reduce((result, level) => ({
63
+ ...result,
64
+ [level]: __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel).call(this, gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits),
65
+ }), {});
66
+ return {
67
+ type: types_1.GasFeeEstimateType.FeeMarket,
68
+ ...levels,
69
+ };
70
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel(gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits) {
71
+ return {
72
+ maxFeePerGas: (0, gas_fees_1.gweiDecimalToWeiHex)(gasFeeEstimates[level].suggestedMaxFeePerGas),
73
+ // Only priority fee is randomised
74
+ maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(gasFeeEstimates[level].suggestedMaxPriorityFeePerGas, lastNDigits, preservedNumberOfDigits),
75
+ };
76
+ };
77
+ /**
78
+ * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.
79
+ *
80
+ * @param digitCount - The number of digits the random number should have
81
+ * @param minValue - The minimum value the random number should have
82
+ * @returns A random number with the specified number of digits
83
+ */
84
+ function generateRandomDigits(digitCount, minValue) {
85
+ const multiplier = 10 ** digitCount;
86
+ return minValue + Math.floor(Math.random() * (multiplier - minValue));
87
+ }
88
+ /**
89
+ * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.
90
+ *
91
+ * This function preserves the more significant digits while randomizing only the least significant ones,
92
+ * ensuring that fees remain close to the original estimation while providing randomisation.
93
+ * The randomisation is performed in Wei units for more precision.
94
+ *
95
+ * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)
96
+ * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise
97
+ * @param preservedNumberOfDigits - The number of most significant digits to preserve
98
+ * @returns The randomised value converted to Wei in hexadecimal format
99
+ */
100
+ function randomiseDecimalGWEIAndConvertToHex(gweiDecimalValue, numberOfDigitsToRandomizeAtTheEnd, preservedNumberOfDigits) {
101
+ const weiDecimalValue = (0, gas_fees_1.gweiDecimalToWeiDecimal)(gweiDecimalValue);
102
+ const decimalLength = weiDecimalValue.length;
103
+ // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS
104
+ const effectiveDigitsToRandomise = Math.min(numberOfDigitsToRandomizeAtTheEnd, decimalLength - preservedNumberOfDigits);
105
+ // Handle the case when the value is 0 or too small
106
+ if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {
107
+ return `0x${Number(weiDecimalValue).toString(16)}`;
108
+ }
109
+ // Use string manipulation to get the base part (significant digits)
110
+ const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;
111
+ const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);
112
+ // Get the original ending digits using string manipulation
113
+ const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);
114
+ const originalEndingDigits = Number(endingDigits);
115
+ // Generate random digits that are greater than or equal to the original ending digits
116
+ const randomEndingDigits = generateRandomDigits(effectiveDigitsToRandomise, originalEndingDigits);
117
+ const basePart = BigInt(significantDigits + '0'.repeat(effectiveDigitsToRandomise));
118
+ const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);
119
+ const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;
120
+ return (0, utils_1.add0x)(hexRandomisedWei);
121
+ }
122
+ exports.randomiseDecimalGWEIAndConvertToHex = randomiseDecimalGWEIAndConvertToHex;
123
+ //# sourceMappingURL=RandomisedEstimationsGasFeeFlow.cjs.map
@@ -0,0 +1 @@
1
+ {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D,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, type Hex } from '@metamask/utils';\n\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\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';\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 Hex;\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"]}
@@ -0,0 +1,28 @@
1
+ import { type Hex } from "@metamask/utils";
2
+ import type { TransactionControllerMessenger } from "../TransactionController.cjs";
3
+ import type { GasFeeFlow, GasFeeFlowRequest, GasFeeFlowResponse, TransactionMeta } from "../types.cjs";
4
+ /**
5
+ * Implementation of a gas fee flow that randomises the last digits of gas fee estimations
6
+ */
7
+ export declare class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {
8
+ #private;
9
+ matchesTransaction({ transactionMeta, messenger, }: {
10
+ transactionMeta: TransactionMeta;
11
+ messenger: TransactionControllerMessenger;
12
+ }): boolean;
13
+ getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse>;
14
+ }
15
+ /**
16
+ * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.
17
+ *
18
+ * This function preserves the more significant digits while randomizing only the least significant ones,
19
+ * ensuring that fees remain close to the original estimation while providing randomisation.
20
+ * The randomisation is performed in Wei units for more precision.
21
+ *
22
+ * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)
23
+ * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise
24
+ * @param preservedNumberOfDigits - The number of most significant digits to preserve
25
+ * @returns The randomised value converted to Wei in hexadecimal format
26
+ */
27
+ export declare function randomiseDecimalGWEIAndConvertToHex(gweiDecimalValue: string | number, numberOfDigitsToRandomizeAtTheEnd: number, preservedNumberOfDigits: number): Hex;
28
+ //# sourceMappingURL=RandomisedEstimationsGasFeeFlow.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,GAAG,EAAE,wBAAwB;AAItE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAelB;;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"}
@@ -0,0 +1,28 @@
1
+ import { type Hex } from "@metamask/utils";
2
+ import type { TransactionControllerMessenger } from "../TransactionController.mjs";
3
+ import type { GasFeeFlow, GasFeeFlowRequest, GasFeeFlowResponse, TransactionMeta } from "../types.mjs";
4
+ /**
5
+ * Implementation of a gas fee flow that randomises the last digits of gas fee estimations
6
+ */
7
+ export declare class RandomisedEstimationsGasFeeFlow implements GasFeeFlow {
8
+ #private;
9
+ matchesTransaction({ transactionMeta, messenger, }: {
10
+ transactionMeta: TransactionMeta;
11
+ messenger: TransactionControllerMessenger;
12
+ }): boolean;
13
+ getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse>;
14
+ }
15
+ /**
16
+ * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.
17
+ *
18
+ * This function preserves the more significant digits while randomizing only the least significant ones,
19
+ * ensuring that fees remain close to the original estimation while providing randomisation.
20
+ * The randomisation is performed in Wei units for more precision.
21
+ *
22
+ * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)
23
+ * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise
24
+ * @param preservedNumberOfDigits - The number of most significant digits to preserve
25
+ * @returns The randomised value converted to Wei in hexadecimal format
26
+ */
27
+ export declare function randomiseDecimalGWEIAndConvertToHex(gweiDecimalValue: string | number, numberOfDigitsToRandomizeAtTheEnd: number, preservedNumberOfDigits: number): Hex;
28
+ //# sourceMappingURL=RandomisedEstimationsGasFeeFlow.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RandomisedEstimationsGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/RandomisedEstimationsGasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,GAAG,EAAE,wBAAwB;AAItE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAGV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAelB;;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"}
@@ -0,0 +1,118 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _RandomisedEstimationsGasFeeFlow_instances, _RandomisedEstimationsGasFeeFlow_getDefaultGasFees, _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel;
7
+ import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
8
+ import { add0x, createModuleLogger } from "@metamask/utils";
9
+ import { DefaultGasFeeFlow } from "./DefaultGasFeeFlow.mjs";
10
+ import { projectLogger } from "../logger.mjs";
11
+ import { GasFeeEstimateLevel, GasFeeEstimateType } from "../types.mjs";
12
+ import { getGasFeeRandomisation } from "../utils/feature-flags.mjs";
13
+ import { gweiDecimalToWeiDecimal, gweiDecimalToWeiHex } from "../utils/gas-fees.mjs";
14
+ const log = createModuleLogger(projectLogger, 'randomised-estimation-gas-fee-flow');
15
+ const DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;
16
+ /**
17
+ * Implementation of a gas fee flow that randomises the last digits of gas fee estimations
18
+ */
19
+ export class RandomisedEstimationsGasFeeFlow {
20
+ constructor() {
21
+ _RandomisedEstimationsGasFeeFlow_instances.add(this);
22
+ }
23
+ matchesTransaction({ transactionMeta, messenger, }) {
24
+ const { chainId } = transactionMeta;
25
+ const gasFeeRandomisation = getGasFeeRandomisation(messenger);
26
+ const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[chainId];
27
+ return randomisedGasFeeDigits !== undefined;
28
+ }
29
+ async getGasFees(request) {
30
+ try {
31
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees).call(this, request);
32
+ }
33
+ catch (error) {
34
+ log('Using default flow as fallback due to error', error);
35
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getDefaultGasFees).call(this, request);
36
+ }
37
+ }
38
+ }
39
+ _RandomisedEstimationsGasFeeFlow_instances = new WeakSet(), _RandomisedEstimationsGasFeeFlow_getDefaultGasFees = async function _RandomisedEstimationsGasFeeFlow_getDefaultGasFees(request) {
40
+ return new DefaultGasFeeFlow().getGasFees(request);
41
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees = async function _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees(request) {
42
+ const { messenger, gasFeeControllerData, transactionMeta } = request;
43
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
44
+ const gasFeeRandomisation = getGasFeeRandomisation(messenger);
45
+ const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];
46
+ const preservedNumberOfDigits = gasFeeRandomisation.preservedNumberOfDigits ??
47
+ DEFAULT_PRESERVE_NUMBER_OF_DIGITS;
48
+ if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
49
+ log('Randomising fee market estimates', gasFeeEstimates);
50
+ const randomisedFeeMarketEstimates = __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates).call(this, gasFeeEstimates, randomisedGasFeeDigits, preservedNumberOfDigits);
51
+ log('Added randomised fee market estimates', randomisedFeeMarketEstimates);
52
+ return {
53
+ estimates: randomisedFeeMarketEstimates,
54
+ };
55
+ }
56
+ return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getDefaultGasFees).call(this, request);
57
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates(gasFeeEstimates, lastNDigits, preservedNumberOfDigits) {
58
+ const levels = Object.values(GasFeeEstimateLevel).reduce((result, level) => ({
59
+ ...result,
60
+ [level]: __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel).call(this, gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits),
61
+ }), {});
62
+ return {
63
+ type: GasFeeEstimateType.FeeMarket,
64
+ ...levels,
65
+ };
66
+ }, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel(gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits) {
67
+ return {
68
+ maxFeePerGas: gweiDecimalToWeiHex(gasFeeEstimates[level].suggestedMaxFeePerGas),
69
+ // Only priority fee is randomised
70
+ maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(gasFeeEstimates[level].suggestedMaxPriorityFeePerGas, lastNDigits, preservedNumberOfDigits),
71
+ };
72
+ };
73
+ /**
74
+ * Generates a random number with the specified number of digits that is greater than or equal to the given minimum value.
75
+ *
76
+ * @param digitCount - The number of digits the random number should have
77
+ * @param minValue - The minimum value the random number should have
78
+ * @returns A random number with the specified number of digits
79
+ */
80
+ function generateRandomDigits(digitCount, minValue) {
81
+ const multiplier = 10 ** digitCount;
82
+ return minValue + Math.floor(Math.random() * (multiplier - minValue));
83
+ }
84
+ /**
85
+ * Randomises the least significant digits of a decimal gas fee value and converts it to a hexadecimal Wei value.
86
+ *
87
+ * This function preserves the more significant digits while randomizing only the least significant ones,
88
+ * ensuring that fees remain close to the original estimation while providing randomisation.
89
+ * The randomisation is performed in Wei units for more precision.
90
+ *
91
+ * @param gweiDecimalValue - The original gas fee value in Gwei (decimal)
92
+ * @param numberOfDigitsToRandomizeAtTheEnd - The number of least significant digits to randomise
93
+ * @param preservedNumberOfDigits - The number of most significant digits to preserve
94
+ * @returns The randomised value converted to Wei in hexadecimal format
95
+ */
96
+ export function randomiseDecimalGWEIAndConvertToHex(gweiDecimalValue, numberOfDigitsToRandomizeAtTheEnd, preservedNumberOfDigits) {
97
+ const weiDecimalValue = gweiDecimalToWeiDecimal(gweiDecimalValue);
98
+ const decimalLength = weiDecimalValue.length;
99
+ // Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS
100
+ const effectiveDigitsToRandomise = Math.min(numberOfDigitsToRandomizeAtTheEnd, decimalLength - preservedNumberOfDigits);
101
+ // Handle the case when the value is 0 or too small
102
+ if (Number(weiDecimalValue) === 0 || effectiveDigitsToRandomise <= 0) {
103
+ return `0x${Number(weiDecimalValue).toString(16)}`;
104
+ }
105
+ // Use string manipulation to get the base part (significant digits)
106
+ const significantDigitsCount = decimalLength - effectiveDigitsToRandomise;
107
+ const significantDigits = weiDecimalValue.slice(0, significantDigitsCount);
108
+ // Get the original ending digits using string manipulation
109
+ const endingDigits = weiDecimalValue.slice(-effectiveDigitsToRandomise);
110
+ const originalEndingDigits = Number(endingDigits);
111
+ // Generate random digits that are greater than or equal to the original ending digits
112
+ const randomEndingDigits = generateRandomDigits(effectiveDigitsToRandomise, originalEndingDigits);
113
+ const basePart = BigInt(significantDigits + '0'.repeat(effectiveDigitsToRandomise));
114
+ const randomisedWeiDecimal = basePart + BigInt(randomEndingDigits);
115
+ const hexRandomisedWei = `0x${randomisedWeiDecimal.toString(16)}`;
116
+ return add0x(hexRandomisedWei);
117
+ }
118
+ //# sourceMappingURL=RandomisedEstimationsGasFeeFlow.mjs.map
@@ -0,0 +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,EAAY,wBAAwB;AAEtE,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,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;AAE3B,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;YACF,OAAO,MAAM,uBAAA,IAAI,yGAAsB,MAA1B,IAAI,EAAuB,OAAO,CAAC,CAAC;SAClD;QAAC,OAAO,KAAK,EAAE;YACd,GAAG,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;YAC1D,OAAO,MAAM,uBAAA,I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pE,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, type Hex } from '@metamask/utils';\n\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\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';\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 Hex;\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"]}
@@ -13,7 +13,7 @@ class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_1.OracleLayer1GasFee
13
13
  constructor() {
14
14
  super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);
15
15
  }
16
- matchesTransaction(transactionMeta) {
16
+ matchesTransaction({ transactionMeta, }) {
17
17
  return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);
18
18
  }
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAEA,yEAAkE;AAClE,gDAAyC;AAGzC,MAAM,gBAAgB,GAAU,CAAC,qBAAS,CAAC,MAAM,EAAE,qBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAA4C,CAAC;AAE/C;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAAsB;IAChE;QACE,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,eAAgC;QACjD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AARD,wDAQC","sourcesContent":["import { type Hex } from '@metamask/utils';\n\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionMeta } from '../types';\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';\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 constructor() {\n super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);\n }\n\n matchesTransaction(transactionMeta: TransactionMeta): 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,yEAAkE;AAClE,gDAAyC;AAIzC,MAAM,gBAAgB,GAAU,CAAC,qBAAS,CAAC,MAAM,EAAE,qBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAA4C,CAAC;AAE/C;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAAsB;IAChE;QACE,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,EACjB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AAbD,wDAaC","sourcesContent":["import { type Hex } from '@metamask/utils';\n\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\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';\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 constructor() {\n super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);\n }\n\n matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
@@ -1,10 +1,14 @@
1
1
  import { OracleLayer1GasFeeFlow } from "./OracleLayer1GasFeeFlow.cjs";
2
+ import type { TransactionControllerMessenger } from "../TransactionController.cjs";
2
3
  import type { TransactionMeta } from "../types.cjs";
3
4
  /**
4
5
  * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.
5
6
  */
6
7
  export declare class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
7
8
  constructor();
8
- matchesTransaction(transactionMeta: TransactionMeta): boolean;
9
+ matchesTransaction({ transactionMeta, }: {
10
+ transactionMeta: TransactionMeta;
11
+ messenger: TransactionControllerMessenger;
12
+ }): boolean;
9
13
  }
10
14
  //# sourceMappingURL=ScrollLayer1GasFeeFlow.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAQhD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;;IAKhE,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO;CAG9D"}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAQhD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;;IAKhE,kBAAkB,CAAC,EACjB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;CAGZ"}
@@ -1,10 +1,14 @@
1
1
  import { OracleLayer1GasFeeFlow } from "./OracleLayer1GasFeeFlow.mjs";
2
+ import type { TransactionControllerMessenger } from "../TransactionController.mjs";
2
3
  import type { TransactionMeta } from "../types.mjs";
3
4
  /**
4
5
  * Scroll layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.
5
6
  */
6
7
  export declare class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
7
8
  constructor();
8
- matchesTransaction(transactionMeta: TransactionMeta): boolean;
9
+ matchesTransaction({ transactionMeta, }: {
10
+ transactionMeta: TransactionMeta;
11
+ messenger: TransactionControllerMessenger;
12
+ }): boolean;
9
13
  }
10
14
  //# sourceMappingURL=ScrollLayer1GasFeeFlow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAQhD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;;IAKhE,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO;CAG9D"}
1
+ {"version":3,"file":"ScrollLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAQhD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;;IAKhE,kBAAkB,CAAC,EACjB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;CAGZ"}
@@ -10,7 +10,7 @@ export class ScrollLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
10
10
  constructor() {
11
11
  super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);
12
12
  }
13
- matchesTransaction(transactionMeta) {
13
+ matchesTransaction({ transactionMeta, }) {
14
14
  return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);
15
15
  }
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/ScrollLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAGzC,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAA4C,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAChE;QACE,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,eAAgC;QACjD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import { type Hex } from '@metamask/utils';\n\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionMeta } from '../types';\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';\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 constructor() {\n super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);\n }\n\n matchesTransaction(transactionMeta: TransactionMeta): 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,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAIzC,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,qGAAqG;AACrG,MAAM,+BAA+B,GACnC,4CAA4C,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAChE;QACE,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,EACjB,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 { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\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';\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 constructor() {\n super(SCROLL_GAS_PRICE_ORACLE_ADDRESS, true);\n }\n\n matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n return SCROLL_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n}\n"]}
@@ -27,7 +27,7 @@ class TestGasFeeFlow {
27
27
  _TestGasFeeFlow_instances.add(this);
28
28
  _TestGasFeeFlow_counter.set(this, 1);
29
29
  }
30
- matchesTransaction(_transactionMeta) {
30
+ matchesTransaction() {
31
31
  return true;
32
32
  }
33
33
  async getGasFees(request) {
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAmD;AAGnD,wCAMkB;AAElB,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,CAAC,gBAAiC;QAClD,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;YACX,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;SAC1D;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,0BAAkB,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 {\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"]}
1
+ {"version":3,"file":"TestGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAmD;AAGnD,wCAKkB;AAElB,MAAM,SAAS,GAAG,I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AAU,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 {\n GasFeeEstimateType,\n type GasFeeFlow,\n type GasFeeFlowRequest,\n type 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,4 +1,4 @@
1
- import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse, type TransactionMeta } from "../types.cjs";
1
+ import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse } from "../types.cjs";
2
2
  /**
3
3
  * A gas fee flow to facilitate testing in the clients.
4
4
  * Increments the total gas fee by a fixed amount each time it is called.
@@ -6,7 +6,7 @@ import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse, type
6
6
  */
7
7
  export declare class TestGasFeeFlow implements GasFeeFlow {
8
8
  #private;
9
- matchesTransaction(_transactionMeta: TransactionMeta): boolean;
9
+ matchesTransaction(): boolean;
10
10
  getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse>;
11
11
  }
12
12
  //# sourceMappingURL=TestGasFeeFlow.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,qBAAiB;AAKlB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAG/C,kBAAkB,CAAC,gBAAgB,EAAE,eAAe,GAAG,OAAO;IAIxD,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":"AAGA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,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,4 +1,4 @@
1
- import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse, type TransactionMeta } from "../types.mjs";
1
+ import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse } from "../types.mjs";
2
2
  /**
3
3
  * A gas fee flow to facilitate testing in the clients.
4
4
  * Increments the total gas fee by a fixed amount each time it is called.
@@ -6,7 +6,7 @@ import { type GasFeeFlow, type GasFeeFlowRequest, type GasFeeFlowResponse, type
6
6
  */
7
7
  export declare class TestGasFeeFlow implements GasFeeFlow {
8
8
  #private;
9
- matchesTransaction(_transactionMeta: TransactionMeta): boolean;
9
+ matchesTransaction(): boolean;
10
10
  getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse>;
11
11
  }
12
12
  //# sourceMappingURL=TestGasFeeFlow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,qBAAiB;AAKlB;;;;GAIG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAG/C,kBAAkB,CAAC,gBAAgB,EAAE,eAAe,GAAG,OAAO;IAIxD,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":"AAGA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,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"}
@@ -24,7 +24,7 @@ export class TestGasFeeFlow {
24
24
  _TestGasFeeFlow_instances.add(this);
25
25
  _TestGasFeeFlow_counter.set(this, 1);
26
26
  }
27
- matchesTransaction(_transactionMeta) {
27
+ matchesTransaction() {
28
28
  return true;
29
29
  }
30
30
  async getGasFees(request) {
@@ -1 +1 @@
1
- {"version":3,"file":"TestGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAGnD,OAAO,EACL,kBAAkB,EAKnB,qBAAiB;AAElB,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,YAAY;AACpC,MAAM,gBAAgB,GAAG,GAAG,CAA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,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 {\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"]}
1
+ {"version":3,"file":"TestGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAGnD,OAAO,EACL,kBAAkB,EAInB,qBAAiB;AAElB,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,YAAY;AACpC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B;;;;GAIG;AACH,MAAM,OAAO,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,C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E,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 {\n GasFeeEstimateType,\n type GasFeeFlow,\n type GasFeeFlowRequest,\n type 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"]}