@metamask-previews/gas-fee-controller 15.0.0-preview-aedc5103 → 15.1.0-preview-cb17e99

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 (86) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/GasFeeController.js +3 -9
  3. package/dist/GasFeeController.mjs +2 -8
  4. package/dist/{chunk-HCUEQ4NY.js → chunk-JVVQPARV.js} +110 -87
  5. package/dist/chunk-JVVQPARV.js.map +1 -0
  6. package/dist/{chunk-QVES4OOM.mjs → chunk-KORLXV32.mjs} +28 -1
  7. package/dist/{chunk-QVES4OOM.mjs.map → chunk-KORLXV32.mjs.map} +1 -1
  8. package/dist/{chunk-G2HAZY5F.mjs → chunk-NCX6ACX5.mjs} +102 -79
  9. package/dist/chunk-NCX6ACX5.mjs.map +1 -0
  10. package/dist/{chunk-NARPHUTR.js → chunk-Q2YPK5SL.js} +30 -3
  11. package/dist/chunk-Q2YPK5SL.js.map +1 -0
  12. package/dist/determineGasFeeCalculations.js +3 -9
  13. package/dist/determineGasFeeCalculations.mjs +2 -8
  14. package/dist/gas-util.js +2 -3
  15. package/dist/gas-util.mjs +1 -2
  16. package/dist/index.js +3 -9
  17. package/dist/index.mjs +2 -8
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/dist/types/GasFeeController.d.ts +5 -1
  20. package/dist/types/GasFeeController.d.ts.map +1 -1
  21. package/dist/types/determineGasFeeCalculations.d.ts +17 -16
  22. package/dist/types/determineGasFeeCalculations.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/dist/chunk-5INBFZXY.js +0 -127
  25. package/dist/chunk-5INBFZXY.js.map +0 -1
  26. package/dist/chunk-AQN4AQEF.mjs +0 -127
  27. package/dist/chunk-AQN4AQEF.mjs.map +0 -1
  28. package/dist/chunk-C4I7KKIU.mjs +0 -12
  29. package/dist/chunk-C4I7KKIU.mjs.map +0 -1
  30. package/dist/chunk-EXCWMMNV.mjs +0 -39
  31. package/dist/chunk-EXCWMMNV.mjs.map +0 -1
  32. package/dist/chunk-EZVGDV5H.js +0 -39
  33. package/dist/chunk-EZVGDV5H.js.map +0 -1
  34. package/dist/chunk-G2HAZY5F.mjs.map +0 -1
  35. package/dist/chunk-GE7RMDFV.js +0 -77
  36. package/dist/chunk-GE7RMDFV.js.map +0 -1
  37. package/dist/chunk-GUWY6WP6.mjs +0 -77
  38. package/dist/chunk-GUWY6WP6.mjs.map +0 -1
  39. package/dist/chunk-HCUEQ4NY.js.map +0 -1
  40. package/dist/chunk-LO7OP5FM.js +0 -19
  41. package/dist/chunk-LO7OP5FM.js.map +0 -1
  42. package/dist/chunk-NARPHUTR.js.map +0 -1
  43. package/dist/chunk-S2EH2EPS.js +0 -12
  44. package/dist/chunk-S2EH2EPS.js.map +0 -1
  45. package/dist/chunk-SINQOHIN.mjs +0 -19
  46. package/dist/chunk-SINQOHIN.mjs.map +0 -1
  47. package/dist/chunk-XUI43LEZ.mjs +0 -30
  48. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  49. package/dist/chunk-Z4BLTVTB.js +0 -30
  50. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  51. package/dist/fetchBlockFeeHistory.js +0 -8
  52. package/dist/fetchBlockFeeHistory.js.map +0 -1
  53. package/dist/fetchBlockFeeHistory.mjs +0 -8
  54. package/dist/fetchBlockFeeHistory.mjs.map +0 -1
  55. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js +0 -9
  56. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js.map +0 -1
  57. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.mjs +0 -9
  58. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.mjs.map +0 -1
  59. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js +0 -8
  60. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js.map +0 -1
  61. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.mjs +0 -8
  62. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.mjs.map +0 -1
  63. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js +0 -8
  64. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js.map +0 -1
  65. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.mjs +0 -8
  66. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.mjs.map +0 -1
  67. package/dist/fetchGasEstimatesViaEthFeeHistory/types.js +0 -1
  68. package/dist/fetchGasEstimatesViaEthFeeHistory/types.js.map +0 -1
  69. package/dist/fetchGasEstimatesViaEthFeeHistory/types.mjs +0 -1
  70. package/dist/fetchGasEstimatesViaEthFeeHistory/types.mjs.map +0 -1
  71. package/dist/fetchGasEstimatesViaEthFeeHistory.js +0 -12
  72. package/dist/fetchGasEstimatesViaEthFeeHistory.js.map +0 -1
  73. package/dist/fetchGasEstimatesViaEthFeeHistory.mjs +0 -12
  74. package/dist/fetchGasEstimatesViaEthFeeHistory.mjs.map +0 -1
  75. package/dist/types/fetchBlockFeeHistory.d.ts +0 -115
  76. package/dist/types/fetchBlockFeeHistory.d.ts.map +0 -1
  77. package/dist/types/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts +0 -17
  78. package/dist/types/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts.map +0 -1
  79. package/dist/types/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts +0 -12
  80. package/dist/types/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts.map +0 -1
  81. package/dist/types/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts +0 -10
  82. package/dist/types/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts.map +0 -1
  83. package/dist/types/fetchGasEstimatesViaEthFeeHistory/types.d.ts +0 -7
  84. package/dist/types/fetchGasEstimatesViaEthFeeHistory/types.d.ts.map +0 -1
  85. package/dist/types/fetchGasEstimatesViaEthFeeHistory.d.ts +0 -22
  86. package/dist/types/fetchGasEstimatesViaEthFeeHistory.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/GasFeeController.ts","../src/determineGasFeeCalculations.ts"],"names":["fetchGasEstimates","fetchGasEstimatesViaEthFeeHistory","fetchLegacyGasPriceEstimates","fetchEthGasPriceEstimate","calculateTimeEstimate"],"mappings":";;;;;;;;;;;;;;;;;AAKA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,cAAc;AAUrB,SAAS,uCAAuC;AAEhD,SAAS,MAAM,cAAc;AAWtB,IAAM,mBAAmB;AA0BzB,IAAM,qBAAqB;AAAA,EAChC,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,MAAM;AACR;AAiGA,IAAM,WAAW;AAAA,EACf,0BAA0B;AAAA,IACxB,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,iBAAiB,EAAE,SAAS,MAAM,WAAW,MAAM;AAAA,EACnD,2BAA2B,EAAE,SAAS,MAAM,WAAW,MAAM;AAAA,EAC7D,iBAAiB,EAAE,SAAS,MAAM,WAAW,MAAM;AACrD;AAkDA,IAAM,OAAO;AA0Bb,IAAM,eAA4B;AAAA,EAChC,0BAA0B,CAAC;AAAA,EAC3B,iBAAiB,CAAC;AAAA,EAClB,2BAA2B,CAAC;AAAA,EAC5B,iBAAiB,mBAAmB;AACtC;AA1PA;AA+PO,IAAM,mBAAN,cAA+B,gCAIpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgDA,YAAY;AAAA,IACV,WAAW;AAAA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,iBAAiB,mBAAmB;AAAA,MACtC;AAAA,IACF,WAAW,0BAA0B;AACnC,YAAM,YAAY,MAAMF;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,aAAO;AAAA,QACL,iBAAiB;AAAA,QACjB,2BAA2B,CAAC;AAAA,QAC5B,iBAAiB,mBAAmB;AAAA,MACtC;AAAA,IACF;AACA,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE,QAAQ;AACN,QAAI;AACF,YAAM,YAAY,MAAMC,0BAAyB,QAAQ;AACzD,aAAO;AAAA,QACL,iBAAiB;AAAA,QACjB,2BAA2B,CAAC;AAAA,QAC5B,iBAAiB,mBAAmB;AAAA,MACtC;AAAA,IACF,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,cAAM,IAAI;AAAA,UACR,6CAA6C,MAAM,OAAO;AAAA,QAC5D;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport {\n convertHexToDecimal,\n safelyExecute,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClientId,\n NetworkControllerGetEIP1559CompatibilityAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerNetworkDidChangeEvent,\n NetworkState,\n ProviderProxy,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { Hex } from '@metamask/utils';\nimport { v1 as random } from 'uuid';\n\nimport determineGasFeeCalculations from './determineGasFeeCalculations';\nimport fetchGasEstimatesViaEthFeeHistory from './fetchGasEstimatesViaEthFeeHistory';\nimport {\n calculateTimeEstimate,\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n} from './gas-util';\n\nexport const GAS_API_BASE_URL = 'https://gas.api.infura.io';\n\nexport type unknownString = 'unknown';\n\n// Fee Market describes the way gas is set after the london hardfork, and was\n// defined by EIP-1559.\nexport type FeeMarketEstimateType = 'fee-market';\n// Legacy describes gasPrice estimates from before london hardfork, when the\n// user is connected to mainnet and are presented with fast/average/slow\n// estimate levels to choose from.\nexport type LegacyEstimateType = 'legacy';\n// EthGasPrice describes a gasPrice estimate received from eth_gasPrice. Post\n// london this value should only be used for legacy type transactions when on\n// networks that support EIP-1559. This type of estimate is the most accurate\n// to display on custom networks that don't support EIP-1559.\nexport type EthGasPriceEstimateType = 'eth_gasPrice';\n// NoEstimate describes the state of the controller before receiving its first\n// estimate.\nexport type NoEstimateType = 'none';\n\n/**\n * Indicates which type of gasEstimate the controller is currently returning.\n * This is useful as a way of asserting that the shape of gasEstimates matches\n * expectations. NONE is a special case indicating that no previous gasEstimate\n * has been fetched.\n */\nexport const GAS_ESTIMATE_TYPES = {\n FEE_MARKET: 'fee-market' as FeeMarketEstimateType,\n LEGACY: 'legacy' as LegacyEstimateType,\n ETH_GASPRICE: 'eth_gasPrice' as EthGasPriceEstimateType,\n NONE: 'none' as NoEstimateType,\n};\n\nexport type GasEstimateType =\n | FeeMarketEstimateType\n | EthGasPriceEstimateType\n | LegacyEstimateType\n | NoEstimateType;\n\nexport type EstimatedGasFeeTimeBounds = {\n lowerTimeBound: number | null;\n upperTimeBound: number | unknownString;\n};\n\n/**\n * @type EthGasPriceEstimate\n *\n * A single gas price estimate for networks and accounts that don't support EIP-1559\n * This estimate comes from eth_gasPrice but is converted to dec gwei to match other\n * return values\n * @property gasPrice - A GWEI dec string\n */\n\nexport type EthGasPriceEstimate = {\n gasPrice: string;\n};\n\n/**\n * @type LegacyGasPriceEstimate\n *\n * A set of gas price estimates for networks and accounts that don't support EIP-1559\n * These estimates include low, medium and high all as strings representing gwei in\n * decimal format.\n * @property high - gasPrice, in decimal gwei string format, suggested for fast inclusion\n * @property medium - gasPrice, in decimal gwei string format, suggested for avg inclusion\n * @property low - gasPrice, in decimal gwei string format, suggested for slow inclusion\n */\nexport type LegacyGasPriceEstimate = {\n high: string;\n medium: string;\n low: string;\n};\n\n/**\n * @type Eip1559GasFee\n *\n * Data necessary to provide an estimate of a gas fee with a specific tip\n * @property minWaitTimeEstimate - The fastest the transaction will take, in milliseconds\n * @property maxWaitTimeEstimate - The slowest the transaction will take, in milliseconds\n * @property suggestedMaxPriorityFeePerGas - A suggested \"tip\", a GWEI hex number\n * @property suggestedMaxFeePerGas - A suggested max fee, the most a user will pay. a GWEI hex number\n */\nexport type Eip1559GasFee = {\n minWaitTimeEstimate: number; // a time duration in milliseconds\n maxWaitTimeEstimate: number; // a time duration in milliseconds\n suggestedMaxPriorityFeePerGas: string; // a GWEI decimal number\n suggestedMaxFeePerGas: string; // a GWEI decimal number\n};\n\n/**\n * @type GasFeeEstimates\n *\n * Data necessary to provide multiple GasFee estimates, and supporting information, to the user\n * @property low - A GasFee for a minimum necessary combination of tip and maxFee\n * @property medium - A GasFee for a recommended combination of tip and maxFee\n * @property high - A GasFee for a high combination of tip and maxFee\n * @property estimatedBaseFee - An estimate of what the base fee will be for the pending/next block. A GWEI dec number\n * @property networkCongestion - A normalized number that can be used to gauge the congestion\n * level of the network, with 0 meaning not congested and 1 meaning extremely congested\n */\nexport type GasFeeEstimates = SourcedGasFeeEstimates | FallbackGasFeeEstimates;\n\ntype SourcedGasFeeEstimates = {\n low: Eip1559GasFee;\n medium: Eip1559GasFee;\n high: Eip1559GasFee;\n estimatedBaseFee: string;\n historicalBaseFeeRange: [string, string];\n baseFeeTrend: 'up' | 'down' | 'level';\n latestPriorityFeeRange: [string, string];\n historicalPriorityFeeRange: [string, string];\n priorityFeeTrend: 'up' | 'down' | 'level';\n networkCongestion: number;\n};\n\ntype FallbackGasFeeEstimates = {\n low: Eip1559GasFee;\n medium: Eip1559GasFee;\n high: Eip1559GasFee;\n estimatedBaseFee: string;\n historicalBaseFeeRange: null;\n baseFeeTrend: null;\n latestPriorityFeeRange: null;\n historicalPriorityFeeRange: null;\n priorityFeeTrend: null;\n networkCongestion: null;\n};\n\nconst metadata = {\n gasFeeEstimatesByChainId: {\n persist: true,\n anonymous: false,\n },\n gasFeeEstimates: { persist: true, anonymous: false },\n estimatedGasFeeTimeBounds: { persist: true, anonymous: false },\n gasEstimateType: { persist: true, anonymous: false },\n};\n\nexport type GasFeeStateEthGasPrice = {\n gasFeeEstimates: EthGasPriceEstimate;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: EthGasPriceEstimateType;\n};\n\nexport type GasFeeStateFeeMarket = {\n gasFeeEstimates: GasFeeEstimates;\n estimatedGasFeeTimeBounds: EstimatedGasFeeTimeBounds | Record<string, never>;\n gasEstimateType: FeeMarketEstimateType;\n};\n\nexport type GasFeeStateLegacy = {\n gasFeeEstimates: LegacyGasPriceEstimate;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: LegacyEstimateType;\n};\n\nexport type GasFeeStateNoEstimates = {\n gasFeeEstimates: Record<string, never>;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: NoEstimateType;\n};\n\nexport type FetchGasFeeEstimateOptions = {\n shouldUpdateState?: boolean;\n networkClientId?: NetworkClientId;\n};\n\n/**\n * @type GasFeeState\n *\n * Gas Fee controller state\n * @property gasFeeEstimates - Gas fee estimate data based on new EIP-1559 properties\n * @property estimatedGasFeeTimeBounds - Estimates representing the minimum and maximum\n */\nexport type SingleChainGasFeeState =\n | GasFeeStateEthGasPrice\n | GasFeeStateFeeMarket\n | GasFeeStateLegacy\n | GasFeeStateNoEstimates;\n\nexport type GasFeeEstimatesByChainId = {\n gasFeeEstimatesByChainId?: Record<string, SingleChainGasFeeState>;\n};\n\nexport type GasFeeState = GasFeeEstimatesByChainId & SingleChainGasFeeState;\n\nconst name = 'GasFeeController';\n\nexport type GasFeeStateChange = ControllerStateChangeEvent<\n typeof name,\n GasFeeState\n>;\n\nexport type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;\n\nexport type GasFeeControllerActions = GetGasFeeState;\n\nexport type GasFeeControllerEvents = GasFeeStateChange;\n\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetEIP1559CompatibilityAction;\n\ntype GasFeeMessenger = RestrictedControllerMessenger<\n typeof name,\n GasFeeControllerActions | AllowedActions,\n GasFeeControllerEvents | NetworkControllerNetworkDidChangeEvent,\n AllowedActions['type'],\n NetworkControllerNetworkDidChangeEvent['type']\n>;\n\nconst defaultState: GasFeeState = {\n gasFeeEstimatesByChainId: {},\n gasFeeEstimates: {},\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.NONE,\n};\n\n/**\n * Controller that retrieves gas fee estimate data and polls for updated data on a set interval\n */\nexport class GasFeeController extends StaticIntervalPollingController<\n typeof name,\n GasFeeState,\n GasFeeMessenger\n> {\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private readonly intervalDelay;\n\n private readonly pollTokens: Set<string>;\n\n private readonly legacyAPIEndpoint: string;\n\n private readonly EIP1559APIEndpoint: string;\n\n private readonly getCurrentNetworkEIP1559Compatibility;\n\n private readonly getCurrentNetworkLegacyGasAPICompatibility;\n\n private readonly getCurrentAccountEIP1559Compatibility;\n\n private readonly infuraAPIKey: string;\n\n private currentChainId;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n * @param options.infuraAPIKey - The Infura API key used for infura API requests.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n clientId,\n infuraAPIKey,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n clientId?: string;\n infuraAPIKey: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/suggestedGasFees`;\n this.legacyAPIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/gasPrices`;\n this.clientId = clientId;\n this.infuraAPIKey = infuraAPIKey;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n this.currentChainId = this.messagingSystem.call(\n 'NetworkController:getState',\n ).providerConfig.chainId;\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n },\n );\n }\n }\n\n async resetPolling() {\n if (this.pollTokens.size !== 0) {\n const tokens = Array.from(this.pollTokens);\n this.stopPolling();\n await this.getGasFeeEstimatesAndStartPolling(tokens[0]);\n tokens.slice(1).forEach((token) => {\n this.pollTokens.add(token);\n });\n }\n }\n\n async fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions) {\n return await this._fetchGasFeeEstimateData(options);\n }\n\n async getGasFeeEstimatesAndStartPolling(\n pollToken: string | undefined,\n ): Promise<string> {\n const _pollToken = pollToken || random();\n\n this.pollTokens.add(_pollToken);\n\n if (this.pollTokens.size === 1) {\n await this._fetchGasFeeEstimateData();\n this._poll();\n }\n\n return _pollToken;\n }\n\n /**\n * Gets and sets gasFeeEstimates in state.\n *\n * @param options - The gas fee estimate options.\n * @param options.shouldUpdateState - Determines whether the state should be updated with the\n * updated gas estimates.\n * @returns The gas fee estimates.\n */\n async _fetchGasFeeEstimateData(\n options: FetchGasFeeEstimateOptions = {},\n ): Promise<GasFeeState> {\n const { shouldUpdateState = true, networkClientId } = options;\n\n let ethQuery,\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n decimalChainId: number;\n\n if (networkClientId !== undefined) {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n isLegacyGasAPICompatible = networkClient.configuration.chainId === '0x38';\n\n decimalChainId = convertHexToDecimal(networkClient.configuration.chainId);\n\n try {\n const result = await this.messagingSystem.call(\n 'NetworkController:getEIP1559Compatibility',\n networkClientId,\n );\n isEIP1559Compatible = result || false;\n } catch {\n isEIP1559Compatible = false;\n }\n ethQuery = new EthQuery(networkClient.provider);\n }\n\n ethQuery ??= this.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchGasEstimatesViaEthFeeHistory,\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n infuraAPIKey: this.infuraAPIKey,\n });\n\n if (shouldUpdateState) {\n this.update((state) => {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[toHex(decimalChainId)] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n stopPolling() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n this.pollTokens.clear();\n this.resetState();\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopPolling();\n }\n\n private _poll() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n\n this.intervalId = setInterval(async () => {\n await safelyExecute(() => this._fetchGasFeeEstimateData());\n }, this.intervalDelay);\n }\n\n /**\n * Fetching token list from the Token Service API.\n *\n * @private\n * @param networkClientId - The ID of the network client triggering the fetch.\n * @returns A promise that resolves when this operation completes.\n */\n async _executePoll(networkClientId: string): Promise<void> {\n await this._fetchGasFeeEstimateData({ networkClientId });\n }\n\n private resetState() {\n this.update(() => {\n return defaultState;\n });\n }\n\n private async getEIP1559Compatibility() {\n const currentNetworkIsEIP1559Compatible =\n await this.getCurrentNetworkEIP1559Compatibility();\n const currentAccountIsEIP1559Compatible =\n this.getCurrentAccountEIP1559Compatibility?.() ?? true;\n\n return (\n currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible\n );\n }\n\n getTimeEstimate(\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n ): EstimatedGasFeeTimeBounds | Record<string, never> {\n if (\n !this.state.gasFeeEstimates ||\n this.state.gasEstimateType !== GAS_ESTIMATE_TYPES.FEE_MARKET\n ) {\n return {};\n }\n return calculateTimeEstimate(\n maxPriorityFeePerGas,\n maxFeePerGas,\n this.state.gasFeeEstimates,\n );\n }\n\n async #onNetworkControllerDidChange(networkControllerState: NetworkState) {\n const newChainId = networkControllerState.providerConfig.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n}\n\nexport default GasFeeController;\n","import type {\n EstimatedGasFeeTimeBounds,\n EthGasPriceEstimate,\n GasFeeEstimates,\n GasFeeState as GasFeeCalculations,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\nimport { GAS_ESTIMATE_TYPES } from './GasFeeController';\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.fetchGasEstimatesViaEthFeeHistory - A function that fetches gas estimates using\n * `eth_feeHistory` (an EIP-1559 feature).\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.infuraAPIKey - Infura API key to use for requests to Infura.\n * @returns The gas fee calculations.\n */\nexport default async function determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl,\n fetchGasEstimatesViaEthFeeHistory,\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId,\n ethQuery,\n infuraAPIKey,\n}: {\n isEIP1559Compatible: boolean;\n isLegacyGasAPICompatible: boolean;\n fetchGasEstimates: (\n url: string,\n infuraAPIKey: string,\n clientId?: string,\n ) => Promise<GasFeeEstimates>;\n fetchGasEstimatesUrl: string;\n fetchGasEstimatesViaEthFeeHistory: (\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ethQuery: any,\n ) => Promise<GasFeeEstimates>;\n fetchLegacyGasPriceEstimates: (\n url: string,\n infuraAPIKey: 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 infuraAPIKey: string;\n}): Promise<GasFeeCalculations> {\n try {\n if (isEIP1559Compatible) {\n let estimates: GasFeeEstimates;\n try {\n estimates = await fetchGasEstimates(\n fetchGasEstimatesUrl,\n infuraAPIKey,\n clientId,\n );\n } catch {\n estimates = await fetchGasEstimatesViaEthFeeHistory(ethQuery);\n }\n const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } =\n estimates.medium;\n const estimatedGasFeeTimeBounds = calculateTimeEstimate(\n suggestedMaxPriorityFeePerGas,\n suggestedMaxFeePerGas,\n estimates,\n );\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds,\n gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET,\n };\n } else if (isLegacyGasAPICompatible) {\n const estimates = await fetchLegacyGasPriceEstimates(\n fetchLegacyGasPriceEstimatesUrl,\n infuraAPIKey,\n clientId,\n );\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY,\n };\n }\n throw new Error('Main gas fee/price estimation failed. Use fallback');\n } catch {\n try {\n const estimates = await fetchEthGasPriceEstimate(ethQuery);\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE,\n };\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Gas fee/price estimation failed. Message: ${error.message}`,\n );\n }\n throw error;\n }\n }\n}\n"]}
@@ -1,19 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts
2
- var _controllerutils = require('@metamask/controller-utils');
3
- async function fetchLatestBlock(ethQuery, includeFullTransactionData = false) {
4
- const blockNumber = await _controllerutils.query.call(void 0, ethQuery, "blockNumber");
5
- const block = await _controllerutils.query.call(void 0, ethQuery, "getBlockByNumber", [
6
- blockNumber,
7
- includeFullTransactionData
8
- ]);
9
- return {
10
- ...block,
11
- number: _controllerutils.fromHex.call(void 0, block.number),
12
- baseFeePerGas: _controllerutils.fromHex.call(void 0, block.baseFeePerGas)
13
- };
14
- }
15
-
16
-
17
-
18
- exports.fetchLatestBlock = fetchLatestBlock;
19
- //# sourceMappingURL=chunk-LO7OP5FM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts"],"names":[],"mappings":";AAAA,SAAS,OAAO,eAAe;AAa/B,eAAO,iBACL,UACA,6BAA6B,OACV;AACnB,QAAM,cAAc,MAAM,MAAM,UAAU,aAAa;AACvD,QAAM,QAAQ,MAAM,MAAM,UAAU,oBAAoB;AAAA,IACtD;AAAA,IACA;AAAA,EACF,CAAC;AACD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,QAAQ,MAAM,MAAM;AAAA,IAC5B,eAAe,QAAQ,MAAM,aAAa;AAAA,EAC5C;AACF","sourcesContent":["import { query, fromHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\n\nimport type { EthBlock } from './types';\n\n/**\n * Returns information about the latest completed block.\n *\n * @param ethQuery - An EthQuery instance\n * @param includeFullTransactionData - Whether or not to include all data for transactions as\n * opposed to merely hashes. False by default.\n * @returns The block.\n */\nexport default async function fetchLatestBlock(\n ethQuery: EthQuery,\n includeFullTransactionData = false,\n): Promise<EthBlock> {\n const blockNumber = await query(ethQuery, 'blockNumber');\n const block = await query(ethQuery, 'getBlockByNumber', [\n blockNumber,\n includeFullTransactionData,\n ]);\n return {\n ...block,\n number: fromHex(block.number),\n baseFeePerGas: fromHex(block.baseFeePerGas),\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gas-util.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,QAAQ;AAUf,IAAM,qBAAqB,CAAC,cAAsB,EAAE,eAAe,SAAS;AAQrE,SAAS,4BAA4B,GAAoB;AAC9D,QAAM,iBAAiB,eAAe,CAAC,EAAE,SAAS,EAAE;AACpD,QAAM,eAAe,gBAAgB,cAAc;AACnD,SAAO;AACT;AAUA,eAAsB,kBACpB,KACA,cACA,UAC0B;AAC1B,QAAM,kBAAkB,qBAAqB,YAAY;AACzD,QAAM,YAAY,MAAM,YAAY,KAAK;AAAA,IACvC,SAAS,WAAW,iBAAiB,QAAQ;AAAA,EAC/C,CAAC;AACD,SAAO;AAAA,IACL,KAAK;AAAA,MACH,GAAG,UAAU;AAAA,MACb,+BAA+B;AAAA,QAC7B,UAAU,IAAI;AAAA,MAChB;AAAA,MACA,uBAAuB;AAAA,QACrB,UAAU,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,GAAG,UAAU;AAAA,MACb,+BAA+B;AAAA,QAC7B,UAAU,OAAO;AAAA,MACnB;AAAA,MACA,uBAAuB;AAAA,QACrB,UAAU,OAAO;AAAA,MACnB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,GAAG,UAAU;AAAA,MACb,+BAA+B;AAAA,QAC7B,UAAU,KAAK;AAAA,MACjB;AAAA,MACA,uBAAuB;AAAA,QACrB,UAAU,KAAK;AAAA,MACjB;AAAA,IACF;AAAA,IACA,kBAAkB,4BAA4B,UAAU,gBAAgB;AAAA,IACxE,wBAAwB,UAAU;AAAA,IAClC,cAAc,UAAU;AAAA,IACxB,wBAAwB,UAAU;AAAA,IAClC,4BAA4B,UAAU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KACrD,wBAAwB,GAAG,uBAAuB,GAClD;AACA,qBAAiB,OAAO;AACxB,qBAAiB,OAAO;AAAA,EAC1B,WAAW,wBAAwB,GAAG,uBAAuB,GAAG;AAC9D,qBAAiB,KAAK;AACtB,qBAAiB,KAAK;AAAA,EACxB,OAAO;AACL,qBAAiB;AACjB,qBAAiB,KAAK;AAAA,EACxB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAQA,SAAS,qBAAqB,cAAsB;AAElD,SAAO,OAAO,KAAK,GAAG,YAAY,GAAG,EAAE,SAAS,QAAQ;AAC1D;AASA,SAAS,WAAW,iBAAyB,UAAmB;AAC9D,SAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,eAAe,SAAS,eAAe;AAAA;AAAA,IAEvC,GAAI,UAAU,KAAK,IAAI,mBAAmB,QAAQ,IAAI,CAAC;AAAA,EACzD;AACF","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 infuraAPIKey - The Infura API key used for infura API requests.\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 infuraAPIKey: string,\n clientId?: string,\n): Promise<GasFeeEstimates> {\n const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);\n const estimates = await handleFetch(url, {\n headers: getHeaders(infuraAuthToken, clientId),\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 infuraAPIKey - The Infura API key used for infura API requests.\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 infuraAPIKey: string,\n clientId?: string,\n): Promise<LegacyGasPriceEstimate> {\n const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);\n const result = await handleFetch(url, {\n referrer: url,\n referrerPolicy: 'no-referrer-when-downgrade',\n method: 'GET',\n mode: 'cors',\n headers: getHeaders(infuraAuthToken, clientId),\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\n/**\n * Build an infura auth token from the given API key and secret.\n *\n * @param infuraAPIKey - The Infura API key.\n * @returns The base64 encoded auth token.\n */\nfunction buildInfuraAuthToken(infuraAPIKey: string) {\n // We intentionally leave the password empty, as Infura does not require one\n return Buffer.from(`${infuraAPIKey}:`).toString('base64');\n}\n\n/**\n * Get the headers for a request to the gas fee API.\n *\n * @param infuraAuthToken - The Infura auth token to use for the request.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The headers for the request.\n */\nfunction getHeaders(infuraAuthToken: string, clientId?: string) {\n return {\n 'Content-Type': 'application/json',\n Authorization: `Basic ${infuraAuthToken}`,\n // Only add the clientId header if clientId is a non-empty string\n ...(clientId?.trim() ? makeClientIdHeader(clientId) : {}),\n };\n}\n"]}
@@ -1,12 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/fetchGasEstimatesViaEthFeeHistory/medianOf.ts
2
- function medianOf(numbers) {
3
- const sortedNumbers = numbers.slice().sort((a, b) => a.cmp(b));
4
- const len = sortedNumbers.length;
5
- const index = Math.floor((len - 1) / 2);
6
- return sortedNumbers[index];
7
- }
8
-
9
-
10
-
11
- exports.medianOf = medianOf;
12
- //# sourceMappingURL=chunk-S2EH2EPS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/fetchGasEstimatesViaEthFeeHistory/medianOf.ts"],"names":[],"mappings":";AASe,SAAR,SAA0B,SAAmB;AAClD,QAAM,gBAAgB,QAAQ,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC;AAC7D,QAAM,MAAM,cAAc;AAC1B,QAAM,QAAQ,KAAK,OAAO,MAAM,KAAK,CAAC;AACtC,SAAO,cAAc,KAAK;AAC5B","sourcesContent":["import type * as BN from 'bn.js';\n\n/**\n * Finds the median among a list of numbers. Note that this is different from the implementation\n * in the MetaSwap API, as we want to hold to using BN as much as possible.\n *\n * @param numbers - A list of numbers, as BNs. Will be sorted automatically if unsorted.\n * @returns The median number.\n */\nexport default function medianOf(numbers: BN[]): BN {\n const sortedNumbers = numbers.slice().sort((a, b) => a.cmp(b));\n const len = sortedNumbers.length;\n const index = Math.floor((len - 1) / 2);\n return sortedNumbers[index];\n}\n"]}
@@ -1,19 +0,0 @@
1
- // src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts
2
- import { query, fromHex } from "@metamask/controller-utils";
3
- async function fetchLatestBlock(ethQuery, includeFullTransactionData = false) {
4
- const blockNumber = await query(ethQuery, "blockNumber");
5
- const block = await query(ethQuery, "getBlockByNumber", [
6
- blockNumber,
7
- includeFullTransactionData
8
- ]);
9
- return {
10
- ...block,
11
- number: fromHex(block.number),
12
- baseFeePerGas: fromHex(block.baseFeePerGas)
13
- };
14
- }
15
-
16
- export {
17
- fetchLatestBlock
18
- };
19
- //# sourceMappingURL=chunk-SINQOHIN.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts"],"sourcesContent":["import { query, fromHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\n\nimport type { EthBlock } from './types';\n\n/**\n * Returns information about the latest completed block.\n *\n * @param ethQuery - An EthQuery instance\n * @param includeFullTransactionData - Whether or not to include all data for transactions as\n * opposed to merely hashes. False by default.\n * @returns The block.\n */\nexport default async function fetchLatestBlock(\n ethQuery: EthQuery,\n includeFullTransactionData = false,\n): Promise<EthBlock> {\n const blockNumber = await query(ethQuery, 'blockNumber');\n const block = await query(ethQuery, 'getBlockByNumber', [\n blockNumber,\n includeFullTransactionData,\n ]);\n return {\n ...block,\n number: fromHex(block.number),\n baseFeePerGas: fromHex(block.baseFeePerGas),\n };\n}\n"],"mappings":";AAAA,SAAS,OAAO,eAAe;AAa/B,eAAO,iBACL,UACA,6BAA6B,OACV;AACnB,QAAM,cAAc,MAAM,MAAM,UAAU,aAAa;AACvD,QAAM,QAAQ,MAAM,MAAM,UAAU,oBAAoB;AAAA,IACtD;AAAA,IACA;AAAA,EACF,CAAC;AACD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,QAAQ,MAAM,MAAM;AAAA,IAC5B,eAAe,QAAQ,MAAM,aAAa;AAAA,EAC5C;AACF;","names":[]}
@@ -1,30 +0,0 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
22
- };
23
-
24
- export {
25
- __privateGet,
26
- __privateAdd,
27
- __privateSet,
28
- __privateMethod
29
- };
30
- //# sourceMappingURL=chunk-XUI43LEZ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,30 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
22
- };
23
-
24
-
25
-
26
-
27
-
28
-
29
- exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod;
30
- //# sourceMappingURL=chunk-Z4BLTVTB.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunk5INBFZXYjs = require('./chunk-5INBFZXY.js');
4
- require('./chunk-Z4BLTVTB.js');
5
-
6
-
7
- exports.default = _chunk5INBFZXYjs.fetchBlockFeeHistory;
8
- //# sourceMappingURL=fetchBlockFeeHistory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- import {
2
- fetchBlockFeeHistory
3
- } from "./chunk-AQN4AQEF.mjs";
4
- import "./chunk-XUI43LEZ.mjs";
5
- export {
6
- fetchBlockFeeHistory as default
7
- };
8
- //# sourceMappingURL=fetchBlockFeeHistory.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,9 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkGE7RMDFVjs = require('../chunk-GE7RMDFV.js');
4
- require('../chunk-S2EH2EPS.js');
5
- require('../chunk-Z4BLTVTB.js');
6
-
7
-
8
- exports.default = _chunkGE7RMDFVjs.calculateGasFeeEstimatesForPriorityLevels;
9
- //# sourceMappingURL=calculateGasFeeEstimatesForPriorityLevels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import {
2
- calculateGasFeeEstimatesForPriorityLevels
3
- } from "../chunk-GUWY6WP6.mjs";
4
- import "../chunk-C4I7KKIU.mjs";
5
- import "../chunk-XUI43LEZ.mjs";
6
- export {
7
- calculateGasFeeEstimatesForPriorityLevels as default
8
- };
9
- //# sourceMappingURL=calculateGasFeeEstimatesForPriorityLevels.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkLO7OP5FMjs = require('../chunk-LO7OP5FM.js');
4
- require('../chunk-Z4BLTVTB.js');
5
-
6
-
7
- exports.default = _chunkLO7OP5FMjs.fetchLatestBlock;
8
- //# sourceMappingURL=fetchLatestBlock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- import {
2
- fetchLatestBlock
3
- } from "../chunk-SINQOHIN.mjs";
4
- import "../chunk-XUI43LEZ.mjs";
5
- export {
6
- fetchLatestBlock as default
7
- };
8
- //# sourceMappingURL=fetchLatestBlock.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkS2EH2EPSjs = require('../chunk-S2EH2EPS.js');
4
- require('../chunk-Z4BLTVTB.js');
5
-
6
-
7
- exports.default = _chunkS2EH2EPSjs.medianOf;
8
- //# sourceMappingURL=medianOf.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- import {
2
- medianOf
3
- } from "../chunk-C4I7KKIU.mjs";
4
- import "../chunk-XUI43LEZ.mjs";
5
- export {
6
- medianOf as default
7
- };
8
- //# sourceMappingURL=medianOf.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +0,0 @@
1
- "use strict";//# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,12 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkEZVGDV5Hjs = require('./chunk-EZVGDV5H.js');
4
- require('./chunk-5INBFZXY.js');
5
- require('./chunk-GE7RMDFV.js');
6
- require('./chunk-S2EH2EPS.js');
7
- require('./chunk-LO7OP5FM.js');
8
- require('./chunk-Z4BLTVTB.js');
9
-
10
-
11
- exports.default = _chunkEZVGDV5Hjs.fetchGasEstimatesViaEthFeeHistory;
12
- //# sourceMappingURL=fetchGasEstimatesViaEthFeeHistory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,12 +0,0 @@
1
- import {
2
- fetchGasEstimatesViaEthFeeHistory
3
- } from "./chunk-EXCWMMNV.mjs";
4
- import "./chunk-AQN4AQEF.mjs";
5
- import "./chunk-GUWY6WP6.mjs";
6
- import "./chunk-C4I7KKIU.mjs";
7
- import "./chunk-SINQOHIN.mjs";
8
- import "./chunk-XUI43LEZ.mjs";
9
- export {
10
- fetchGasEstimatesViaEthFeeHistory as default
11
- };
12
- //# sourceMappingURL=fetchGasEstimatesViaEthFeeHistory.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,115 +0,0 @@
1
- import BN from 'bn.js';
2
- type EthQuery = any;
3
- /**
4
- * @type EthFeeHistoryResponse
5
- *
6
- * Response data for `eth_feeHistory`.
7
- * @property oldestBlock - The id of the oldest block (in hex format) in the range of blocks
8
- * requested.
9
- * @property baseFeePerGas - Base fee per gas for each block in the range of blocks requested.
10
- * For go-ethereum based chains baseFeePerGas will not returned in case of empty results
11
- * <github.com/ethereum/go-ethereum/blob/v1.10.16/internal/ethapi/api.go#L87>
12
- * @property gasUsedRatio - A number between 0 and 1 that represents the gas used vs. gas limit for
13
- * each block in the range of blocks requested.
14
- * @property reward - The priority fee at the percentiles requested for each block in the range of
15
- * blocks requested.
16
- */
17
- export type EthFeeHistoryResponse = {
18
- oldestBlock: string;
19
- baseFeePerGas?: string[];
20
- gasUsedRatio: number[];
21
- reward?: string[][];
22
- };
23
- /**
24
- * @type ExistingFeeHistoryBlock
25
- *
26
- * Historical data for a particular block that exists on the blockchain.
27
- * @property number - The number of the block, as a BN.
28
- * @property baseFeePerGas - The base fee per gas for the block in WEI, as a BN.
29
- * @property gasUsedRatio - A number between 0 and 1 that represents the ratio between the gas paid
30
- * for the block and its set gas limit.
31
- * @property priorityFeesByPercentile - The priority fees paid for the transactions in the block
32
- * that occurred at particular levels at which those transactions contributed to the overall gas
33
- * used for the block, indexed by those percentiles. (See docs for {@link fetchBlockFeeHistory} for more
34
- * on how this works.)
35
- */
36
- type ExistingFeeHistoryBlock<Percentile extends number> = {
37
- number: BN;
38
- baseFeePerGas: BN;
39
- gasUsedRatio: number;
40
- priorityFeesByPercentile: Record<Percentile, BN>;
41
- };
42
- /**
43
- * @type NextFeeHistoryBlock
44
- *
45
- * Historical data for a theoretical block that could exist in the future.
46
- * @property number - The number of the block, as a BN.
47
- * @property baseFeePerGas - The estimated base fee per gas for the block in WEI, as a BN.
48
- */
49
- type NextFeeHistoryBlock = {
50
- number: BN;
51
- baseFeePerGas: BN;
52
- };
53
- /**
54
- * @type FeeHistoryBlock
55
- *
56
- * Historical data for a particular block.
57
- * @property number - The number of the block, as a BN.
58
- * @property baseFeePerGas - The base fee per gas for the block in WEI, as a BN.
59
- * @property gasUsedRatio - A number between 0 and 1 that represents the ratio between the gas paid
60
- * for the block and its set gas limit.
61
- * @property priorityFeesByPercentile - The priority fees paid for the transactions in the block
62
- * that occurred at particular levels at which those transactions contributed to the overall gas
63
- * used for the block, indexed by those percentiles. (See docs for {@link fetchBlockFeeHistory} for more
64
- * on how this works.)
65
- */
66
- export type FeeHistoryBlock<Percentile extends number> = ExistingFeeHistoryBlock<Percentile> | NextFeeHistoryBlock;
67
- /**
68
- * @type ExtractPercentileFrom
69
- *
70
- * Extracts the percentiles that the type assigned to an array of FeeHistoryBlock has been created
71
- * with. This makes use of the `infer` keyword to read the type argument.
72
- */
73
- export type ExtractPercentileFrom<T> = T extends FeeHistoryBlock<infer P>[] ? P : never;
74
- /**
75
- * Uses `eth_feeHistory` (an EIP-1559 feature) to obtain information about gas fees from a range of
76
- * blocks that have occurred recently on a network.
77
- *
78
- * To learn more, see these resources:
79
- *
80
- * - <https://infura.io/docs/ethereum#operation/eth_feeHistory>
81
- * - <https://github.com/zsfelfoldi/feehistory/blob/main/docs/feeHistory.md>
82
- * - <https://github.com/ethereum/go-ethereum/blob/57a3fab8a75eeb9c2f4fab770b73b51b9fe672c5/eth/gasprice/feehistory.go#L180>
83
- * - <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md>
84
- * - <https://gas-api.metaswap.codefi.network/testFeeHistory>
85
- *
86
- * @param args - The arguments to this function.
87
- * @param args.ethQuery - An EthQuery instance that wraps a provider for the network in question.
88
- * @param args.endBlock - The desired end of the requested block range. Can be "latest" if you want
89
- * to start from the latest successful block or the number of a known past block.
90
- * @param args.numberOfBlocks - How many total blocks to fetch. Note that if this is more than 1024,
91
- * multiple calls to `eth_feeHistory` will be made.
92
- * @param args.percentiles - A set of numbers between 1 and 100 which will dictate how
93
- * `priorityFeesByPercentile` in each returned block will be formed. When Ethereum runs the
94
- * `eth_feeHistory` method, for each block it is considering, it will first sort all transactions by
95
- * the priority fee. It will then go through each transaction and add the total amount of gas paid
96
- * for that transaction to a bucket which maxes out at the total gas used for the whole block. As
97
- * the bucket fills, it will cross percentages which correspond to the percentiles specified here,
98
- * and the priority fees of the first transactions which cause it to reach those percentages will be
99
- * recorded. Hence, `priorityFeesByPercentile` represents the priority fees of transactions at key
100
- * gas used contribution levels, where earlier levels have smaller contributions and later levels
101
- * have higher contributions.
102
- * @param args.includeNextBlock - Whether to include an extra block that represents the next
103
- * block after the latest one. Only the `baseFeePerGas` will be filled in for this block (which is
104
- * estimated).
105
- * @returns The list of blocks and their fee data, sorted from oldest to newest.
106
- */
107
- export default function fetchBlockFeeHistory<Percentile extends number>({ ethQuery, numberOfBlocks: totalNumberOfBlocks, endBlock: givenEndBlock, percentiles: givenPercentiles, includeNextBlock, }: {
108
- ethQuery: EthQuery;
109
- numberOfBlocks: number;
110
- endBlock?: 'latest' | BN;
111
- percentiles?: readonly Percentile[];
112
- includeNextBlock?: boolean;
113
- }): Promise<FeeHistoryBlock<Percentile>[]>;
114
- export {};
115
- //# sourceMappingURL=fetchBlockFeeHistory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchBlockFeeHistory.d.ts","sourceRoot":"","sources":["../../src/fetchBlockFeeHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,OAAO,CAAC;AAIvB,KAAK,QAAQ,GAAG,GAAG,CAAC;AAcpB;;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AAC,EAAE,OAAO,CAAC;CAC5B,GAAG,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAwCzC"}
@@ -1,17 +0,0 @@
1
- import type { FeeHistoryBlock } from '../fetchBlockFeeHistory';
2
- import type { GasFeeEstimates } from '../GasFeeController';
3
- export type PriorityLevel = (typeof PRIORITY_LEVELS)[number];
4
- export type Percentile = (typeof PRIORITY_LEVEL_PERCENTILES)[number];
5
- declare const PRIORITY_LEVELS: readonly ["low", "medium", "high"];
6
- declare const PRIORITY_LEVEL_PERCENTILES: readonly [10, 20, 30];
7
- /**
8
- * Calculates a set of estimates suitable for different priority levels based on the data returned
9
- * by `eth_feeHistory`.
10
- *
11
- * @param blocks - A set of blocks populated with data for priority fee percentiles 10, 20, and 30,
12
- * obtained via {@link BlockFeeHistoryDatasetFetcher}.
13
- * @returns The estimates.
14
- */
15
- export default function calculateGasFeeEstimatesForPriorityLevels(blocks: FeeHistoryBlock<Percentile>[]): Pick<GasFeeEstimates, PriorityLevel>;
16
- export {};
17
- //# sourceMappingURL=calculateGasFeeEstimatesForPriorityLevels.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculateGasFeeEstimatesForPriorityLevels.d.ts","sourceRoot":"","sources":["../../../src/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAiB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG1E,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,QAAA,MAAM,eAAe,oCAAqC,CAAC;AAC3D,QAAA,MAAM,0BAA0B,uBAAwB,CAAC;AAiFzD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,yCAAyC,CAC/D,MAAM,EAAE,eAAe,CAAC,UAAU,CAAC,EAAE,GACpC,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,CAQtC"}
@@ -1,12 +0,0 @@
1
- import type EthQuery from '@metamask/eth-query';
2
- import type { EthBlock } from './types';
3
- /**
4
- * Returns information about the latest completed block.
5
- *
6
- * @param ethQuery - An EthQuery instance
7
- * @param includeFullTransactionData - Whether or not to include all data for transactions as
8
- * opposed to merely hashes. False by default.
9
- * @returns The block.
10
- */
11
- export default function fetchLatestBlock(ethQuery: EthQuery, includeFullTransactionData?: boolean): Promise<EthBlock>;
12
- //# sourceMappingURL=fetchLatestBlock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchLatestBlock.d.ts","sourceRoot":"","sources":["../../../src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;GAOG;AACH,wBAA8B,gBAAgB,CAC5C,QAAQ,EAAE,QAAQ,EAClB,0BAA0B,UAAQ,GACjC,OAAO,CAAC,QAAQ,CAAC,CAWnB"}
@@ -1,10 +0,0 @@
1
- import type * as BN from 'bn.js';
2
- /**
3
- * Finds the median among a list of numbers. Note that this is different from the implementation
4
- * in the MetaSwap API, as we want to hold to using BN as much as possible.
5
- *
6
- * @param numbers - A list of numbers, as BNs. Will be sorted automatically if unsorted.
7
- * @returns The median number.
8
- */
9
- export default function medianOf(numbers: BN[]): BN;
10
- //# sourceMappingURL=medianOf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"medianOf.d.ts","sourceRoot":"","sources":["../../../src/fetchGasEstimatesViaEthFeeHistory/medianOf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,OAAO,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAKlD"}
@@ -1,7 +0,0 @@
1
- import type * as BN from 'bn.js';
2
- export type EthBlock = {
3
- number: BN;
4
- baseFeePerGas: BN;
5
- };
6
- export type FeeRange = [string, string];
7
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/fetchGasEstimatesViaEthFeeHistory/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,OAAO,CAAC;AAEjC,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,EAAE,CAAC;IACX,aAAa,EAAE,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -1,22 +0,0 @@
1
- import type EthQuery from '@metamask/eth-query';
2
- import type { GasFeeEstimates } from './GasFeeController';
3
- /**
4
- * Generates gas fee estimates based on gas fees that have been used in the recent past so that
5
- * those estimates can be displayed to users.
6
- *
7
- * To produce the estimates, the last 5 blocks are read from the network, and for each block, the
8
- * priority fees for transactions at the 10th, 20th, and 30th percentiles are also read (here
9
- * "percentile" signifies the level at which those transactions contribute to the overall gas used
10
- * for the block, where higher percentiles correspond to higher fees). This information is used to
11
- * calculate reasonable max priority and max fees for three different priority levels (higher
12
- * priority = higher fee).
13
- *
14
- * Note that properties are returned for other data that are normally obtained via the API; however,
15
- * to prevent extra requests to Infura, these properties are empty.
16
- *
17
- * @param ethQuery - An EthQuery instance.
18
- * @returns Base and priority fee estimates, categorized by priority level, as well as an estimate
19
- * for the next block's base fee.
20
- */
21
- export default function fetchGasEstimatesViaEthFeeHistory(ethQuery: EthQuery): Promise<GasFeeEstimates>;
22
- //# sourceMappingURL=fetchGasEstimatesViaEthFeeHistory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchGasEstimatesViaEthFeeHistory.d.ts","sourceRoot":"","sources":["../../src/fetchGasEstimatesViaEthFeeHistory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAA8B,iCAAiC,CAC7D,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,eAAe,CAAC,CAuB1B"}