@metamask-previews/gas-fee-controller 20.0.0-preview-cf09c0a → 20.0.0-preview-09a2ffd5

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 (55) hide show
  1. package/dist/GasFeeController.js +14 -0
  2. package/dist/GasFeeController.js.map +1 -0
  3. package/dist/GasFeeController.mjs +12 -296
  4. package/dist/GasFeeController.mjs.map +1 -1
  5. package/dist/chunk-2MFVV2BX.js +156 -0
  6. package/dist/chunk-2MFVV2BX.js.map +1 -0
  7. package/dist/chunk-R3IOI7AK.mjs +156 -0
  8. package/dist/chunk-R3IOI7AK.mjs.map +1 -0
  9. package/dist/chunk-S5H5NUEH.js +401 -0
  10. package/dist/chunk-S5H5NUEH.js.map +1 -0
  11. package/dist/chunk-WXXOCPNT.mjs +401 -0
  12. package/dist/chunk-WXXOCPNT.mjs.map +1 -0
  13. package/dist/determineGasFeeCalculations.js +8 -0
  14. package/dist/determineGasFeeCalculations.js.map +1 -0
  15. package/dist/determineGasFeeCalculations.mjs +7 -101
  16. package/dist/determineGasFeeCalculations.mjs.map +1 -1
  17. package/dist/gas-util.js +15 -0
  18. package/dist/gas-util.js.map +1 -0
  19. package/dist/gas-util.mjs +14 -138
  20. package/dist/gas-util.mjs.map +1 -1
  21. package/dist/index.js +12 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.mjs +11 -1
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/tsconfig.build.tsbuildinfo +1 -0
  26. package/dist/{GasFeeController.d.mts → types/GasFeeController.d.ts} +5 -5
  27. package/dist/types/GasFeeController.d.ts.map +1 -0
  28. package/dist/{determineGasFeeCalculations.d.cts → types/determineGasFeeCalculations.d.ts} +2 -2
  29. package/dist/types/determineGasFeeCalculations.d.ts.map +1 -0
  30. package/dist/{gas-util.d.cts → types/gas-util.d.ts} +3 -3
  31. package/dist/types/gas-util.d.ts.map +1 -0
  32. package/dist/types/index.d.ts +2 -0
  33. package/dist/types/index.d.ts.map +1 -0
  34. package/package.json +7 -12
  35. package/dist/GasFeeController.cjs +0 -298
  36. package/dist/GasFeeController.cjs.map +0 -1
  37. package/dist/GasFeeController.d.cts +0 -244
  38. package/dist/GasFeeController.d.cts.map +0 -1
  39. package/dist/GasFeeController.d.mts.map +0 -1
  40. package/dist/determineGasFeeCalculations.cjs +0 -105
  41. package/dist/determineGasFeeCalculations.cjs.map +0 -1
  42. package/dist/determineGasFeeCalculations.d.cts.map +0 -1
  43. package/dist/determineGasFeeCalculations.d.mts +0 -42
  44. package/dist/determineGasFeeCalculations.d.mts.map +0 -1
  45. package/dist/gas-util.cjs +0 -143
  46. package/dist/gas-util.cjs.map +0 -1
  47. package/dist/gas-util.d.cts.map +0 -1
  48. package/dist/gas-util.d.mts +0 -43
  49. package/dist/gas-util.d.mts.map +0 -1
  50. package/dist/index.cjs +0 -18
  51. package/dist/index.cjs.map +0 -1
  52. package/dist/index.d.cts +0 -2
  53. package/dist/index.d.cts.map +0 -1
  54. package/dist/index.d.mts +0 -2
  55. package/dist/index.d.mts.map +0 -1
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const GasFeeController_1 = require("./GasFeeController.cjs");
4
- /**
5
- * Obtains a set of max base and priority fee estimates along with time estimates so that we
6
- * can present them to users when they are sending transactions or making swaps.
7
- *
8
- * @param args - The arguments.
9
- * @param args.isEIP1559Compatible - Governs whether or not we can use an EIP-1559-only method to
10
- * produce estimates.
11
- * @param args.isLegacyGasAPICompatible - Governs whether or not we can use a non-EIP-1559 method to
12
- * produce estimates (for instance, testnets do not support estimates altogether).
13
- * @param args.fetchGasEstimates - A function that fetches gas estimates using an EIP-1559-specific
14
- * API.
15
- * @param args.fetchGasEstimatesUrl - The URL for the API we can use to obtain EIP-1559-specific
16
- * estimates.
17
- * @param args.fetchLegacyGasPriceEstimates - A function that fetches gas estimates using an
18
- * non-EIP-1559-specific API.
19
- * @param args.fetchLegacyGasPriceEstimatesUrl - The URL for the API we can use to obtain
20
- * non-EIP-1559-specific estimates.
21
- * @param args.fetchEthGasPriceEstimate - A function that fetches gas estimates using
22
- * `eth_gasPrice`.
23
- * @param args.calculateTimeEstimate - A function that determine time estimate bounds.
24
- * @param args.clientId - An identifier that an API can use to know who is asking for estimates.
25
- * @param args.ethQuery - An EthQuery instance we can use to talk to Ethereum directly.
26
- * @param args.nonRPCGasFeeApisDisabled - Whether to disable requests to the legacyAPIEndpoint and the EIP1559APIEndpoint
27
- * @returns The gas fee calculations.
28
- */
29
- async function determineGasFeeCalculations(args) {
30
- try {
31
- return await getEstimatesUsingFallbacks(args);
32
- }
33
- catch (error) {
34
- if (error instanceof Error) {
35
- throw new Error(`Gas fee/price estimation failed. Message: ${error.message}`);
36
- }
37
- throw error;
38
- }
39
- }
40
- exports.default = determineGasFeeCalculations;
41
- /**
42
- * Retrieve the gas fee estimates using a series of fallback mechanisms.
43
- * @param request - The request object.
44
- * @returns The gas fee estimates.
45
- */
46
- async function getEstimatesUsingFallbacks(request) {
47
- const { isEIP1559Compatible, isLegacyGasAPICompatible, nonRPCGasFeeApisDisabled, } = request;
48
- try {
49
- if (isEIP1559Compatible && !nonRPCGasFeeApisDisabled) {
50
- return await getEstimatesUsingFeeMarketEndpoint(request);
51
- }
52
- if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {
53
- return await getEstimatesUsingLegacyEndpoint(request);
54
- }
55
- throw new Error('Main gas fee/price estimation failed. Use fallback');
56
- }
57
- catch {
58
- return await getEstimatesUsingProvider(request);
59
- }
60
- }
61
- /**
62
- * Retrieve gas fee estimates using the EIP-1559 endpoint of the gas API.
63
- * @param request - The request object.
64
- * @returns The gas fee estimates.
65
- */
66
- async function getEstimatesUsingFeeMarketEndpoint(request) {
67
- const { fetchGasEstimates, fetchGasEstimatesUrl, clientId, calculateTimeEstimate, } = request;
68
- const estimates = await fetchGasEstimates(fetchGasEstimatesUrl, clientId);
69
- const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
70
- const estimatedGasFeeTimeBounds = calculateTimeEstimate(suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas, estimates);
71
- return {
72
- gasFeeEstimates: estimates,
73
- estimatedGasFeeTimeBounds,
74
- gasEstimateType: GasFeeController_1.GAS_ESTIMATE_TYPES.FEE_MARKET,
75
- };
76
- }
77
- /**
78
- * Retrieve gas fee estimates using the legacy endpoint of the gas API.
79
- * @param request - The request object.
80
- * @returns The gas fee estimates.
81
- */
82
- async function getEstimatesUsingLegacyEndpoint(request) {
83
- const { fetchLegacyGasPriceEstimates, fetchLegacyGasPriceEstimatesUrl, clientId, } = request;
84
- const estimates = await fetchLegacyGasPriceEstimates(fetchLegacyGasPriceEstimatesUrl, clientId);
85
- return {
86
- gasFeeEstimates: estimates,
87
- estimatedGasFeeTimeBounds: {},
88
- gasEstimateType: GasFeeController_1.GAS_ESTIMATE_TYPES.LEGACY,
89
- };
90
- }
91
- /**
92
- * Retrieve gas fee estimates using an `eth_gasPrice` call to the RPC provider.
93
- * @param request - The request object.
94
- * @returns The gas fee estimates.
95
- */
96
- async function getEstimatesUsingProvider(request) {
97
- const { ethQuery, fetchEthGasPriceEstimate } = request;
98
- const estimates = await fetchEthGasPriceEstimate(ethQuery);
99
- return {
100
- gasFeeEstimates: estimates,
101
- estimatedGasFeeTimeBounds: {},
102
- gasEstimateType: GasFeeController_1.GAS_ESTIMATE_TYPES.ETH_GASPRICE,
103
- };
104
- }
105
- //# sourceMappingURL=determineGasFeeCalculations.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"determineGasFeeCalculations.cjs","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":";;AAOA,6DAAwD;AA8BxD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACY,KAAK,UAAU,2BAA2B,CACvD,IAAwC;IAExC,IAAI;QACF,OAAO,MAAM,0BAA0B,CAAC,IAAI,CAAC,CAAC;KAC/C;IAA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A2C;IAE3C,MAAM,EACJ,4BAA4B,EAC5B,+BAA+B,EAC/B,QAAQ,GACT,GAAG,OAAO,CAAC;IAEZ,MAAM,SAAS,GAAG,MAAM,4BAA4B,CAClD,+BAA+B,EAC/B,QAAQ,CACT,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,SAAS;QAC1B,yBAAyB,EAAE,EAAE;QAC7B,eAAe,EAAE,qCAAkB,CAAC,MAAM;KAC3C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,yBAAyB,CACtC,OAA2C;IAE3C,MAAM,EAAE,QAAQ,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;IAEvD,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAE3D,OAAO;QACL,eAAe,EAAE,SAAS;QAC1B,yBAAyB,EAAE,EAAE;QAC7B,eAAe,EAAE,qCAAkB,CAAC,YAAY;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n EstimatedGasFeeTimeBounds,\n EthGasPriceEstimate,\n GasFeeEstimates,\n GasFeeState as GasFeeCalculations,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\nimport { GAS_ESTIMATE_TYPES } from './GasFeeController';\n\ntype DetermineGasFeeCalculationsRequest = {\n isEIP1559Compatible: boolean;\n isLegacyGasAPICompatible: boolean;\n fetchGasEstimates: (\n url: string,\n clientId?: string,\n ) => Promise<GasFeeEstimates>;\n fetchGasEstimatesUrl: string;\n fetchLegacyGasPriceEstimates: (\n url: string,\n clientId?: string,\n ) => Promise<LegacyGasPriceEstimate>;\n fetchLegacyGasPriceEstimatesUrl: string;\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fetchEthGasPriceEstimate: (ethQuery: any) => Promise<EthGasPriceEstimate>;\n calculateTimeEstimate: (\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n gasFeeEstimates: GasFeeEstimates,\n ) => EstimatedGasFeeTimeBounds;\n clientId: string | undefined;\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ethQuery: any;\n nonRPCGasFeeApisDisabled?: boolean;\n};\n\n/**\n * Obtains a set of max base and priority fee estimates along with time estimates so that we\n * can present them to users when they are sending transactions or making swaps.\n *\n * @param args - The arguments.\n * @param args.isEIP1559Compatible - Governs whether or not we can use an EIP-1559-only method to\n * produce estimates.\n * @param args.isLegacyGasAPICompatible - Governs whether or not we can use a non-EIP-1559 method to\n * produce estimates (for instance, testnets do not support estimates altogether).\n * @param args.fetchGasEstimates - A function that fetches gas estimates using an EIP-1559-specific\n * API.\n * @param args.fetchGasEstimatesUrl - The URL for the API we can use to obtain EIP-1559-specific\n * estimates.\n * @param args.fetchLegacyGasPriceEstimates - A function that fetches gas estimates using an\n * non-EIP-1559-specific API.\n * @param args.fetchLegacyGasPriceEstimatesUrl - The URL for the API we can use to obtain\n * non-EIP-1559-specific estimates.\n * @param args.fetchEthGasPriceEstimate - A function that fetches gas estimates using\n * `eth_gasPrice`.\n * @param args.calculateTimeEstimate - A function that determine time estimate bounds.\n * @param args.clientId - An identifier that an API can use to know who is asking for estimates.\n * @param args.ethQuery - An EthQuery instance we can use to talk to Ethereum directly.\n * @param args.nonRPCGasFeeApisDisabled - Whether to disable requests to the legacyAPIEndpoint and the EIP1559APIEndpoint\n * @returns The gas fee calculations.\n */\nexport default async function determineGasFeeCalculations(\n args: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n try {\n return await getEstimatesUsingFallbacks(args);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Gas fee/price estimation failed. Message: ${error.message}`,\n );\n }\n\n throw error;\n }\n}\n\n/**\n * Retrieve the gas fee estimates using a series of fallback mechanisms.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingFallbacks(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n nonRPCGasFeeApisDisabled,\n } = request;\n\n try {\n if (isEIP1559Compatible && !nonRPCGasFeeApisDisabled) {\n return await getEstimatesUsingFeeMarketEndpoint(request);\n }\n\n if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {\n return await getEstimatesUsingLegacyEndpoint(request);\n }\n\n throw new Error('Main gas fee/price estimation failed. Use fallback');\n } catch {\n return await getEstimatesUsingProvider(request);\n }\n}\n\n/**\n * Retrieve gas fee estimates using the EIP-1559 endpoint of the gas API.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingFeeMarketEndpoint(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n fetchGasEstimates,\n fetchGasEstimatesUrl,\n clientId,\n calculateTimeEstimate,\n } = request;\n\n const estimates = await fetchGasEstimates(fetchGasEstimatesUrl, clientId);\n\n const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } =\n estimates.medium;\n\n const estimatedGasFeeTimeBounds = calculateTimeEstimate(\n suggestedMaxPriorityFeePerGas,\n suggestedMaxFeePerGas,\n estimates,\n );\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds,\n gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET,\n };\n}\n\n/**\n * Retrieve gas fee estimates using the legacy endpoint of the gas API.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingLegacyEndpoint(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl,\n clientId,\n } = request;\n\n const estimates = await fetchLegacyGasPriceEstimates(\n fetchLegacyGasPriceEstimatesUrl,\n clientId,\n );\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY,\n };\n}\n\n/**\n * Retrieve gas fee estimates using an `eth_gasPrice` call to the RPC provider.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingProvider(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const { ethQuery, fetchEthGasPriceEstimate } = request;\n\n const estimates = await fetchEthGasPriceEstimate(ethQuery);\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"determineGasFeeCalculations.d.cts","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,WAAW,IAAI,kBAAkB,EACjC,sBAAsB,EACvB,+BAA2B;AAG5B,KAAK,kCAAkC,GAAG;IACxC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,wBAAwB,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,4BAA4B,EAAE,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,+BAA+B,EAAE,MAAM,CAAC;IAGxC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1E,qBAAqB,EAAE,CACrB,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,KAC7B,yBAAyB,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAG7B,QAAQ,EAAE,GAAG,CAAC;IACd,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAA8B,2BAA2B,CACvD,IAAI,EAAE,kCAAkC,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
@@ -1,42 +0,0 @@
1
- import type { EstimatedGasFeeTimeBounds, EthGasPriceEstimate, GasFeeEstimates, GasFeeState as GasFeeCalculations, LegacyGasPriceEstimate } from "./GasFeeController.mjs";
2
- type DetermineGasFeeCalculationsRequest = {
3
- isEIP1559Compatible: boolean;
4
- isLegacyGasAPICompatible: boolean;
5
- fetchGasEstimates: (url: string, clientId?: string) => Promise<GasFeeEstimates>;
6
- fetchGasEstimatesUrl: string;
7
- fetchLegacyGasPriceEstimates: (url: string, clientId?: string) => Promise<LegacyGasPriceEstimate>;
8
- fetchLegacyGasPriceEstimatesUrl: string;
9
- fetchEthGasPriceEstimate: (ethQuery: any) => Promise<EthGasPriceEstimate>;
10
- calculateTimeEstimate: (maxPriorityFeePerGas: string, maxFeePerGas: string, gasFeeEstimates: GasFeeEstimates) => EstimatedGasFeeTimeBounds;
11
- clientId: string | undefined;
12
- ethQuery: any;
13
- nonRPCGasFeeApisDisabled?: boolean;
14
- };
15
- /**
16
- * Obtains a set of max base and priority fee estimates along with time estimates so that we
17
- * can present them to users when they are sending transactions or making swaps.
18
- *
19
- * @param args - The arguments.
20
- * @param args.isEIP1559Compatible - Governs whether or not we can use an EIP-1559-only method to
21
- * produce estimates.
22
- * @param args.isLegacyGasAPICompatible - Governs whether or not we can use a non-EIP-1559 method to
23
- * produce estimates (for instance, testnets do not support estimates altogether).
24
- * @param args.fetchGasEstimates - A function that fetches gas estimates using an EIP-1559-specific
25
- * API.
26
- * @param args.fetchGasEstimatesUrl - The URL for the API we can use to obtain EIP-1559-specific
27
- * estimates.
28
- * @param args.fetchLegacyGasPriceEstimates - A function that fetches gas estimates using an
29
- * non-EIP-1559-specific API.
30
- * @param args.fetchLegacyGasPriceEstimatesUrl - The URL for the API we can use to obtain
31
- * non-EIP-1559-specific estimates.
32
- * @param args.fetchEthGasPriceEstimate - A function that fetches gas estimates using
33
- * `eth_gasPrice`.
34
- * @param args.calculateTimeEstimate - A function that determine time estimate bounds.
35
- * @param args.clientId - An identifier that an API can use to know who is asking for estimates.
36
- * @param args.ethQuery - An EthQuery instance we can use to talk to Ethereum directly.
37
- * @param args.nonRPCGasFeeApisDisabled - Whether to disable requests to the legacyAPIEndpoint and the EIP1559APIEndpoint
38
- * @returns The gas fee calculations.
39
- */
40
- export default function determineGasFeeCalculations(args: DetermineGasFeeCalculationsRequest): Promise<GasFeeCalculations>;
41
- export {};
42
- //# sourceMappingURL=determineGasFeeCalculations.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"determineGasFeeCalculations.d.mts","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,WAAW,IAAI,kBAAkB,EACjC,sBAAsB,EACvB,+BAA2B;AAG5B,KAAK,kCAAkC,GAAG;IACxC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,wBAAwB,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,4BAA4B,EAAE,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,+BAA+B,EAAE,MAAM,CAAC;IAGxC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1E,qBAAqB,EAAE,CACrB,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,KAC7B,yBAAyB,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAG7B,QAAQ,EAAE,GAAG,CAAC;IACd,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAA8B,2BAA2B,CACvD,IAAI,EAAE,kCAAkC,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
package/dist/gas-util.cjs DELETED
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculateTimeEstimate = exports.fetchEthGasPriceEstimate = exports.fetchLegacyGasPriceEstimates = exports.fetchGasEstimates = exports.normalizeGWEIDecimalNumbers = void 0;
7
- const controller_utils_1 = require("@metamask/controller-utils");
8
- const bn_js_1 = __importDefault(require("bn.js"));
9
- const makeClientIdHeader = (clientId) => ({ 'X-Client-Id': clientId });
10
- /**
11
- * Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.
12
- *
13
- * @param n - The input GWEI amount, as a decimal string or a number.
14
- * @returns The decimal string GWEI amount.
15
- */
16
- function normalizeGWEIDecimalNumbers(n) {
17
- const numberAsWEIHex = (0, controller_utils_1.gweiDecToWEIBN)(n).toString(16);
18
- const numberAsGWEI = (0, controller_utils_1.weiHexToGweiDec)(numberAsWEIHex);
19
- return numberAsGWEI;
20
- }
21
- exports.normalizeGWEIDecimalNumbers = normalizeGWEIDecimalNumbers;
22
- /**
23
- * Fetch gas estimates from the given URL.
24
- *
25
- * @param url - The gas estimate URL.
26
- * @param clientId - The client ID used to identify to the API who is asking for estimates.
27
- * @returns The gas estimates.
28
- */
29
- async function fetchGasEstimates(url, clientId) {
30
- const estimates = await (0, controller_utils_1.handleFetch)(url, clientId ? { headers: makeClientIdHeader(clientId) } : undefined);
31
- return {
32
- low: {
33
- ...estimates.low,
34
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxPriorityFeePerGas),
35
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxFeePerGas),
36
- },
37
- medium: {
38
- ...estimates.medium,
39
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxPriorityFeePerGas),
40
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxFeePerGas),
41
- },
42
- high: {
43
- ...estimates.high,
44
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxPriorityFeePerGas),
45
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxFeePerGas),
46
- },
47
- estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),
48
- historicalBaseFeeRange: estimates.historicalBaseFeeRange,
49
- baseFeeTrend: estimates.baseFeeTrend,
50
- latestPriorityFeeRange: estimates.latestPriorityFeeRange,
51
- historicalPriorityFeeRange: estimates.historicalPriorityFeeRange,
52
- priorityFeeTrend: estimates.priorityFeeTrend,
53
- networkCongestion: estimates.networkCongestion,
54
- };
55
- }
56
- exports.fetchGasEstimates = fetchGasEstimates;
57
- /**
58
- * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium
59
- * high values from that API.
60
- *
61
- * @param url - The URL to fetch gas price estimates from.
62
- * @param clientId - The client ID used to identify to the API who is asking for estimates.
63
- * @returns The gas price estimates.
64
- */
65
- async function fetchLegacyGasPriceEstimates(url, clientId) {
66
- const result = await (0, controller_utils_1.handleFetch)(url, {
67
- referrer: url,
68
- referrerPolicy: 'no-referrer-when-downgrade',
69
- method: 'GET',
70
- mode: 'cors',
71
- headers: {
72
- 'Content-Type': 'application/json',
73
- ...(clientId && makeClientIdHeader(clientId)),
74
- },
75
- });
76
- return {
77
- low: result.SafeGasPrice,
78
- medium: result.ProposeGasPrice,
79
- high: result.FastGasPrice,
80
- };
81
- }
82
- exports.fetchLegacyGasPriceEstimates = fetchLegacyGasPriceEstimates;
83
- /**
84
- * Get a gas price estimate from the network using the `eth_gasPrice` method.
85
- *
86
- * @param ethQuery - The EthQuery instance to call the network with.
87
- * @returns A gas price estimate.
88
- */
89
- async function fetchEthGasPriceEstimate(ethQuery) {
90
- const gasPrice = await (0, controller_utils_1.query)(ethQuery, 'gasPrice');
91
- return {
92
- gasPrice: (0, controller_utils_1.weiHexToGweiDec)(gasPrice).toString(),
93
- };
94
- }
95
- exports.fetchEthGasPriceEstimate = fetchEthGasPriceEstimate;
96
- /**
97
- * Estimate the time it will take for a transaction to be confirmed.
98
- *
99
- * @param maxPriorityFeePerGas - The max priority fee per gas.
100
- * @param maxFeePerGas - The max fee per gas.
101
- * @param gasFeeEstimates - The gas fee estimates.
102
- * @returns The estimated lower and upper bounds for when this transaction will be confirmed.
103
- */
104
- function calculateTimeEstimate(maxPriorityFeePerGas, maxFeePerGas, gasFeeEstimates) {
105
- const { low, medium, high, estimatedBaseFee } = gasFeeEstimates;
106
- const maxPriorityFeePerGasInWEI = (0, controller_utils_1.gweiDecToWEIBN)(maxPriorityFeePerGas);
107
- const maxFeePerGasInWEI = (0, controller_utils_1.gweiDecToWEIBN)(maxFeePerGas);
108
- const estimatedBaseFeeInWEI = (0, controller_utils_1.gweiDecToWEIBN)(estimatedBaseFee);
109
- const effectiveMaxPriorityFee = bn_js_1.default.min(maxPriorityFeePerGasInWEI, maxFeePerGasInWEI.sub(estimatedBaseFeeInWEI));
110
- const lowMaxPriorityFeeInWEI = (0, controller_utils_1.gweiDecToWEIBN)(low.suggestedMaxPriorityFeePerGas);
111
- const mediumMaxPriorityFeeInWEI = (0, controller_utils_1.gweiDecToWEIBN)(medium.suggestedMaxPriorityFeePerGas);
112
- const highMaxPriorityFeeInWEI = (0, controller_utils_1.gweiDecToWEIBN)(high.suggestedMaxPriorityFeePerGas);
113
- let lowerTimeBound;
114
- let upperTimeBound;
115
- if (effectiveMaxPriorityFee.lt(lowMaxPriorityFeeInWEI)) {
116
- lowerTimeBound = null;
117
- upperTimeBound = 'unknown';
118
- }
119
- else if (effectiveMaxPriorityFee.gte(lowMaxPriorityFeeInWEI) &&
120
- effectiveMaxPriorityFee.lt(mediumMaxPriorityFeeInWEI)) {
121
- lowerTimeBound = low.minWaitTimeEstimate;
122
- upperTimeBound = low.maxWaitTimeEstimate;
123
- }
124
- else if (effectiveMaxPriorityFee.gte(mediumMaxPriorityFeeInWEI) &&
125
- effectiveMaxPriorityFee.lt(highMaxPriorityFeeInWEI)) {
126
- lowerTimeBound = medium.minWaitTimeEstimate;
127
- upperTimeBound = medium.maxWaitTimeEstimate;
128
- }
129
- else if (effectiveMaxPriorityFee.eq(highMaxPriorityFeeInWEI)) {
130
- lowerTimeBound = high.minWaitTimeEstimate;
131
- upperTimeBound = high.maxWaitTimeEstimate;
132
- }
133
- else {
134
- lowerTimeBound = 0;
135
- upperTimeBound = high.maxWaitTimeEstimate;
136
- }
137
- return {
138
- lowerTimeBound,
139
- upperTimeBound,
140
- };
141
- }
142
- exports.calculateTimeEstimate = calculateTimeEstimate;
143
- //# sourceMappingURL=gas-util.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas-util.cjs","sourceRoot":"","sources":["../src/gas-util.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AAEpC,kDAAuB;AAUvB,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,CAAkB;IAC5D,MAAM,cAAc,GAAG,IAAA,iCAAc,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,IAAA,kCAAe,EAAC,cAAc,CAAC,CAAC;IACrD,OAAO,YAAY,CAAC;AACtB,CAAC;AAJD,kEAIC;AAED;;;;;;GAMG;AACI,KAAK,U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AC3C,GAAG,CAAC,6BAA6B,CAClC,CAAC;IACF,MAAM,yBAAyB,GAAG,IAAA,iCAAc,EAC9C,MAAM,CAAC,6BAA6B,CACrC,CAAC;IACF,MAAM,uBAAuB,GAAG,IAAA,iCAAc,EAC5C,IAAI,CAAC,6BAA6B,CACnC,CAAC;IAEF,IAAI,cAAc,CAAC;IACnB,IAAI,cAAc,CAAC;IAEnB,IAAI,uBAAuB,CAAC,EAAE,CAAC,sBAAsB,CAAC,EAAE;QACtD,cAAc,GAAG,IAAI,CAAC;QACtB,cAAc,GAAG,SAA0B,CAAC;KAC7C;SAAM,IACL,uBAAuB,CAAC,GAAG,CAAC,sBAAsB,CAAC;QACnD,uBAAuB,CAAC,EAAE,CAAC,yBAAyB,CAAC,EACrD;QACA,cAAc,GAAG,GAAG,CAAC,mBAAmB,CAAC;QACzC,cAAc,GAAG,GAAG,CAAC,mBAAmB,CAAC;KAC1C;SAAM,IACL,uBAAuB,CAAC,GAAG,CAAC,yBAAyB,CAAC;QACtD,uBAAuB,CAAC,EAAE,CAAC,uBAAuB,CAAC,EACnD;QACA,cAAc,GAAG,MAAM,CAAC,mBAAmB,CAAC;QAC5C,cAAc,GAAG,MAAM,CAAC,mBAAmB,CAAC;KAC7C;SAAM,IAAI,uBAAuB,CAAC,EAAE,CAAC,uBAAuB,CAAC,EAAE;QAC9D,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAC1C,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;KAC3C;SAAM;QACL,cAAc,GAAG,CAAC,CAAC;QACnB,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;KAC3C;IAED,OAAO;QACL,cAAc;QACd,cAAc;KACf,CAAC;AACJ,CAAC;AAxDD,sDAwDC","sourcesContent":["import {\n query,\n handleFetch,\n gweiDecToWEIBN,\n weiHexToGweiDec,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport BN from 'bn.js';\n\nimport type {\n GasFeeEstimates,\n EthGasPriceEstimate,\n EstimatedGasFeeTimeBounds,\n unknownString,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\n\nconst makeClientIdHeader = (clientId: string) => ({ 'X-Client-Id': clientId });\n\n/**\n * Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.\n *\n * @param n - The input GWEI amount, as a decimal string or a number.\n * @returns The decimal string GWEI amount.\n */\nexport function normalizeGWEIDecimalNumbers(n: string | number) {\n const numberAsWEIHex = gweiDecToWEIBN(n).toString(16);\n const numberAsGWEI = weiHexToGweiDec(numberAsWEIHex);\n return numberAsGWEI;\n}\n\n/**\n * Fetch gas estimates from the given URL.\n *\n * @param url - The gas estimate URL.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas estimates.\n */\nexport async function fetchGasEstimates(\n url: string,\n clientId?: string,\n): Promise<GasFeeEstimates> {\n const estimates = await handleFetch(\n url,\n clientId ? { headers: makeClientIdHeader(clientId) } : undefined,\n );\n return {\n low: {\n ...estimates.low,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxFeePerGas,\n ),\n },\n medium: {\n ...estimates.medium,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxFeePerGas,\n ),\n },\n high: {\n ...estimates.high,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxFeePerGas,\n ),\n },\n estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),\n historicalBaseFeeRange: estimates.historicalBaseFeeRange,\n baseFeeTrend: estimates.baseFeeTrend,\n latestPriorityFeeRange: estimates.latestPriorityFeeRange,\n historicalPriorityFeeRange: estimates.historicalPriorityFeeRange,\n priorityFeeTrend: estimates.priorityFeeTrend,\n networkCongestion: estimates.networkCongestion,\n };\n}\n\n/**\n * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium\n * high values from that API.\n *\n * @param url - The URL to fetch gas price estimates from.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas price estimates.\n */\nexport async function fetchLegacyGasPriceEstimates(\n url: string,\n clientId?: string,\n): Promise<LegacyGasPriceEstimate> {\n const result = await handleFetch(url, {\n referrer: url,\n referrerPolicy: 'no-referrer-when-downgrade',\n method: 'GET',\n mode: 'cors',\n headers: {\n 'Content-Type': 'application/json',\n ...(clientId && makeClientIdHeader(clientId)),\n },\n });\n return {\n low: result.SafeGasPrice,\n medium: result.ProposeGasPrice,\n high: result.FastGasPrice,\n };\n}\n\n/**\n * Get a gas price estimate from the network using the `eth_gasPrice` method.\n *\n * @param ethQuery - The EthQuery instance to call the network with.\n * @returns A gas price estimate.\n */\nexport async function fetchEthGasPriceEstimate(\n ethQuery: EthQuery,\n): Promise<EthGasPriceEstimate> {\n const gasPrice = await query(ethQuery, 'gasPrice');\n return {\n gasPrice: weiHexToGweiDec(gasPrice).toString(),\n };\n}\n\n/**\n * Estimate the time it will take for a transaction to be confirmed.\n *\n * @param maxPriorityFeePerGas - The max priority fee per gas.\n * @param maxFeePerGas - The max fee per gas.\n * @param gasFeeEstimates - The gas fee estimates.\n * @returns The estimated lower and upper bounds for when this transaction will be confirmed.\n */\nexport function calculateTimeEstimate(\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n gasFeeEstimates: GasFeeEstimates,\n): EstimatedGasFeeTimeBounds {\n const { low, medium, high, estimatedBaseFee } = gasFeeEstimates;\n\n const maxPriorityFeePerGasInWEI = gweiDecToWEIBN(maxPriorityFeePerGas);\n const maxFeePerGasInWEI = gweiDecToWEIBN(maxFeePerGas);\n const estimatedBaseFeeInWEI = gweiDecToWEIBN(estimatedBaseFee);\n\n const effectiveMaxPriorityFee = BN.min(\n maxPriorityFeePerGasInWEI,\n maxFeePerGasInWEI.sub(estimatedBaseFeeInWEI),\n );\n\n const lowMaxPriorityFeeInWEI = gweiDecToWEIBN(\n low.suggestedMaxPriorityFeePerGas,\n );\n const mediumMaxPriorityFeeInWEI = gweiDecToWEIBN(\n medium.suggestedMaxPriorityFeePerGas,\n );\n const highMaxPriorityFeeInWEI = gweiDecToWEIBN(\n high.suggestedMaxPriorityFeePerGas,\n );\n\n let lowerTimeBound;\n let upperTimeBound;\n\n if (effectiveMaxPriorityFee.lt(lowMaxPriorityFeeInWEI)) {\n lowerTimeBound = null;\n upperTimeBound = 'unknown' as unknownString;\n } else if (\n effectiveMaxPriorityFee.gte(lowMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(mediumMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = low.minWaitTimeEstimate;\n upperTimeBound = low.maxWaitTimeEstimate;\n } else if (\n effectiveMaxPriorityFee.gte(mediumMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(highMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = medium.minWaitTimeEstimate;\n upperTimeBound = medium.maxWaitTimeEstimate;\n } else if (effectiveMaxPriorityFee.eq(highMaxPriorityFeeInWEI)) {\n lowerTimeBound = high.minWaitTimeEstimate;\n upperTimeBound = high.maxWaitTimeEstimate;\n } else {\n lowerTimeBound = 0;\n upperTimeBound = high.maxWaitTimeEstimate;\n }\n\n return {\n lowerTimeBound,\n upperTimeBound,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas-util.d.cts","sourceRoot":"","sources":["../src/gas-util.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,4BAA4B;AAGhD,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EAEzB,sBAAsB,EACvB,+BAA2B;AAI5B;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,OAI7D;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,CAAC,CAyC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAgBjC;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,GAC/B,yBAAyB,CAoD3B"}
@@ -1,43 +0,0 @@
1
- import type EthQuery from "@metamask/eth-query";
2
- import type { GasFeeEstimates, EthGasPriceEstimate, EstimatedGasFeeTimeBounds, LegacyGasPriceEstimate } from "./GasFeeController.mjs";
3
- /**
4
- * Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.
5
- *
6
- * @param n - The input GWEI amount, as a decimal string or a number.
7
- * @returns The decimal string GWEI amount.
8
- */
9
- export declare function normalizeGWEIDecimalNumbers(n: string | number): any;
10
- /**
11
- * Fetch gas estimates from the given URL.
12
- *
13
- * @param url - The gas estimate URL.
14
- * @param clientId - The client ID used to identify to the API who is asking for estimates.
15
- * @returns The gas estimates.
16
- */
17
- export declare function fetchGasEstimates(url: string, clientId?: string): Promise<GasFeeEstimates>;
18
- /**
19
- * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium
20
- * high values from that API.
21
- *
22
- * @param url - The URL to fetch gas price estimates from.
23
- * @param clientId - The client ID used to identify to the API who is asking for estimates.
24
- * @returns The gas price estimates.
25
- */
26
- export declare function fetchLegacyGasPriceEstimates(url: string, clientId?: string): Promise<LegacyGasPriceEstimate>;
27
- /**
28
- * Get a gas price estimate from the network using the `eth_gasPrice` method.
29
- *
30
- * @param ethQuery - The EthQuery instance to call the network with.
31
- * @returns A gas price estimate.
32
- */
33
- export declare function fetchEthGasPriceEstimate(ethQuery: EthQuery): Promise<EthGasPriceEstimate>;
34
- /**
35
- * Estimate the time it will take for a transaction to be confirmed.
36
- *
37
- * @param maxPriorityFeePerGas - The max priority fee per gas.
38
- * @param maxFeePerGas - The max fee per gas.
39
- * @param gasFeeEstimates - The gas fee estimates.
40
- * @returns The estimated lower and upper bounds for when this transaction will be confirmed.
41
- */
42
- export declare function calculateTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string, gasFeeEstimates: GasFeeEstimates): EstimatedGasFeeTimeBounds;
43
- //# sourceMappingURL=gas-util.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas-util.d.mts","sourceRoot":"","sources":["../src/gas-util.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,4BAA4B;AAGhD,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EAEzB,sBAAsB,EACvB,+BAA2B;AAI5B;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,OAI7D;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,CAAC,CAyC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAgBjC;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,GAC/B,yBAAyB,CAoD3B"}
package/dist/index.cjs DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./GasFeeController.cjs"), exports);
18
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC","sourcesContent":["export * from './GasFeeController';\n"]}
package/dist/index.d.cts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./GasFeeController.cjs";
2
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC"}
package/dist/index.d.mts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./GasFeeController.mjs";
2
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC"}