@metamask-previews/transaction-controller 69.4.0-preview-507508c10 → 69.4.0-preview-0efc7ef01
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.
- package/CHANGELOG.md +10 -0
- package/dist/utils/feature-flags.cjs +33 -1
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +54 -0
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +54 -0
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +30 -0
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +111 -8
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts +2 -1
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts +2 -1
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +111 -8
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
12
|
- Bump `@metamask/network-controller` from `^35.0.0` to `^35.0.1` ([#9758](https://github.com/MetaMask/core/pull/9758))
|
|
13
|
+
- Replace underpriced dapp-suggested gas fees with the wallet's suggested estimates ([#9704](https://github.com/MetaMask/core/pull/9704))
|
|
14
|
+
- If the new `replaceUnderpricedDappGasFees` feature flag is enabled for the chain, dapp-suggested EIP-1559 fees with a `maxFeePerGas` below the current low estimate are replaced with the suggested medium values, as they are unlikely to result in inclusion in a block before fee values change.
|
|
15
|
+
- The `userFeeLevel` for such transactions is set to `medium` instead of `dappSuggested`, so the values are kept updated while the transaction is unapproved.
|
|
16
|
+
- The original dapp-suggested values remain available via `dappSuggestedGasFees` on the transaction metadata.
|
|
17
|
+
- Disabled by default.
|
|
18
|
+
- Ignore underpriced saved (advanced) gas fee preferences in favour of the wallet's suggested estimates ([#9704](https://github.com/MetaMask/core/pull/9704))
|
|
19
|
+
- If the new `replaceUnderpricedSavedGasFees` feature flag is enabled for the chain, saved custom fees with a `maxBaseFee` below the current low estimate are ignored and the suggested medium values are used instead, as they are unlikely to result in inclusion in a block before fee values change.
|
|
20
|
+
- Level-based saved preferences track current estimates and are never ignored.
|
|
21
|
+
- The `userFeeLevel` for such transactions is set to `medium` instead of `custom`, so the values are kept updated while the transaction is unapproved.
|
|
22
|
+
- Disabled by default.
|
|
13
23
|
|
|
14
24
|
### Fixed
|
|
15
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTimeoutAttempts = exports.getGasEstimateBuffer = exports.getGasEstimateFallback = exports.getGasFeeRandomisation = exports.getAcceleratedPollingParams = exports.getTransactionHistoryLimit = exports.getSubmitHistoryLimit = exports.getBatchSizeLimit = exports.getEIP7702UpgradeContractAddress = exports.getEIP7702ContractAddresses = exports.getEIP7702SupportedChains = exports.FeatureFlag = void 0;
|
|
3
|
+
exports.getReplaceUnderpricedSavedGasFeesEnabled = exports.getReplaceUnderpricedDappGasFeesEnabled = exports.getTimeoutAttempts = exports.getGasEstimateBuffer = exports.getGasEstimateFallback = exports.getGasFeeRandomisation = exports.getAcceleratedPollingParams = exports.getTransactionHistoryLimit = exports.getSubmitHistoryLimit = exports.getBatchSizeLimit = exports.getEIP7702UpgradeContractAddress = exports.getEIP7702ContractAddresses = exports.getEIP7702SupportedChains = exports.FeatureFlag = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const logger_js_1 = require("../logger.cjs");
|
|
6
6
|
const signature_js_1 = require("./signature.cjs");
|
|
@@ -203,6 +203,38 @@ function getTimeoutAttempts(chainId, messenger) {
|
|
|
203
203
|
timeoutAttemptsFlags?.default);
|
|
204
204
|
}
|
|
205
205
|
exports.getTimeoutAttempts = getTimeoutAttempts;
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves whether underpriced dapp-suggested gas fees should be replaced
|
|
208
|
+
* with the wallet's suggested fees.
|
|
209
|
+
*
|
|
210
|
+
* @param chainId - The chain ID.
|
|
211
|
+
* @param messenger - The controller messenger instance.
|
|
212
|
+
* @returns Whether the replacement is enabled.
|
|
213
|
+
*/
|
|
214
|
+
function getReplaceUnderpricedDappGasFeesEnabled(chainId, messenger) {
|
|
215
|
+
const featureFlags = getFeatureFlags(messenger);
|
|
216
|
+
const replaceUnderpricedDappGasFeesFlags = featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedDappGasFees;
|
|
217
|
+
return (replaceUnderpricedDappGasFeesFlags?.perChainConfig?.[chainId] ??
|
|
218
|
+
replaceUnderpricedDappGasFeesFlags?.default ??
|
|
219
|
+
false);
|
|
220
|
+
}
|
|
221
|
+
exports.getReplaceUnderpricedDappGasFeesEnabled = getReplaceUnderpricedDappGasFeesEnabled;
|
|
222
|
+
/**
|
|
223
|
+
* Retrieves whether underpriced saved (advanced) gas fee preferences should be
|
|
224
|
+
* ignored in favour of the wallet's suggested fees.
|
|
225
|
+
*
|
|
226
|
+
* @param chainId - The chain ID.
|
|
227
|
+
* @param messenger - The controller messenger instance.
|
|
228
|
+
* @returns Whether the replacement is enabled.
|
|
229
|
+
*/
|
|
230
|
+
function getReplaceUnderpricedSavedGasFeesEnabled(chainId, messenger) {
|
|
231
|
+
const featureFlags = getFeatureFlags(messenger);
|
|
232
|
+
const replaceUnderpricedSavedGasFeesFlags = featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedSavedGasFees;
|
|
233
|
+
return (replaceUnderpricedSavedGasFeesFlags?.perChainConfig?.[chainId] ??
|
|
234
|
+
replaceUnderpricedSavedGasFeesFlags?.default ??
|
|
235
|
+
false);
|
|
236
|
+
}
|
|
237
|
+
exports.getReplaceUnderpricedSavedGasFeesEnabled = getReplaceUnderpricedSavedGasFeesEnabled;
|
|
206
238
|
/**
|
|
207
239
|
* Retrieves the relevant feature flags from the remote feature flag controller.
|
|
208
240
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.cjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAGrD,6CAA6C;AAE7C,kDAAkD;AAClD,0CAAgD;AAEhD,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,qCAAqC,GAAG,EAAE,CAAC;AACjD,MAAM,uCAAuC,GAAG,CAAC,GAAG,IAAI,CAAC;AACzD,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC,MAAM,2CAA2C,GAAG,EAAE,CAAC;AACvD,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAE7C;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,iDAAkC,CAAA;IAClC,qDAAsC,CAAA;IACtC,0DAA2C,CAAA;AAC7C,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAuKD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,eAAe,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,SAAgB,yBAAyB,CACvC,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAChD,OAAO,YAAY,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,eAAe,IAAI,EAAE,CAAC;AACpE,CAAC;AALD,8DAKC;AAED;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CACzC,OAAY,EACZ,SAAyC,EACzC,SAAc;IAEd,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,MAAM,SAAS,GACb,YAAY,EAAE,CAAC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;QAChB,wBAAwB;QACxB,cAAc,EAAE,OAAO;QACvB,2BAA2B,CAC5B,CAAC;AACJ,CAAC;AA9BD,oDA8BC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,OAAY,EACZ,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,MAAM,oBAAoB,GACxB,YAAY,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;IAE5D,OAAO,CACL,oBAAoB,EAAE,cAAc,EAAE,CAAC,OAAO,CAAC;QAC/C,oBAAoB,EAAE,OAAO,CAC9B,CAAC;AACJ,CAAC;AAbD,gDAaC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,SAAyC;IAEzC,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CACjC,sCAAsC,CACvC,CAAC,kBAAkB,CAAC;QAErB,GAAG,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;QAE7C,OAAO,YAAiD,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { isValidSignature } from './signature.js';\nimport { padHexToEvenLength } from './utils.js';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_BLOCK_TIME = 12 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\nconst DEFAULT_SUBMIT_HISTORY_LIMIT = 100;\nconst DEFAULT_TRANSACTION_HISTORY_LIMIT = 40;\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n\n /**\n * The maximum gas limit the fallback can resolve to, representing the chain's\n * per-transaction gas cap. Clamps the `fixed` or `percentage`-derived fallback\n * so it can never exceed the gas limit the RPC will accept (e.g. ~33.5M on\n * Polygon, whereas 35% of its ~140M block gas limit would otherwise be ~49M).\n */\n maxGasLimit?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /** Maximum number of entries in the submit history. */\n submitHistoryLimit?: number;\n\n /** Maximum number of transactions stored in state. */\n transactionHistoryLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Block time in milliseconds.\n */\n blockTime?: number;\n\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n\n /**\n * Number of attempts to wait before automatically marking a transaction as failed\n * if it has no receipt status and hash is not found on the network.\n */\n timeoutAttempts?: {\n /** Automatic fail threshold on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: number;\n };\n\n /**\n * Default automatic fail threshold.\n * This value is used when no specific threshold is found for a chain ID.\n */\n default?: number;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the submit history limit.\n * Defaults to 100 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The submit history limit.\n */\nexport function getSubmitHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.submitHistoryLimit ??\n DEFAULT_SUBMIT_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the transaction history limit.\n * Defaults to 40 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The transaction history limit.\n */\nexport function getTransactionHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n if (!featureFlags) {\n return undefined;\n }\n\n return (\n featureFlags[FeatureFlag.Transactions]?.transactionHistoryLimit ??\n DEFAULT_TRANSACTION_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { blockTime: number; countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ??\n acceleratedPollingParams?.defaultCountMax ??\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ??\n acceleratedPollingParams?.defaultIntervalMs ??\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n const blockTime =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.blockTime ??\n DEFAULT_BLOCK_TIME;\n\n return { blockTime, countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation ?? {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits ?? {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n maxGasLimit?: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n const maxGasLimit =\n chainFlags?.maxGasLimit ?? gasEstimateFallbackFlags?.default?.maxGasLimit;\n\n return { fixed, percentage, maxGasLimit };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithData - Whether the transaction is an EIP-7702 upgrade combined with a call.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithData,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithData: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithData ? chainFlags?.eip7702 : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the incoming transactions polling interval.\n * Retrieves the number of attempts to wait before automatically marking a transaction as dropped\n * if it has no receipt status.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The threshold number of attempts, or undefined if the feature is disabled.\n */\nexport function getTimeoutAttempts(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n const timeoutAttemptsFlags =\n featureFlags?.[FeatureFlag.Transactions]?.timeoutAttempts;\n\n return (\n timeoutAttemptsFlags?.perChainConfig?.[chainId] ??\n timeoutAttemptsFlags?.default\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags | undefined {\n try {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n } catch {\n log('RemoteFeatureFlagController not available');\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feature-flags.cjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAGrD,6CAA6C;AAE7C,kDAAkD;AAClD,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nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { isValidSignature } from './signature.js';\nimport { padHexToEvenLength } from './utils.js';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_BLOCK_TIME = 12 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\nconst DEFAULT_SUBMIT_HISTORY_LIMIT = 100;\nconst DEFAULT_TRANSACTION_HISTORY_LIMIT = 40;\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n\n /**\n * The maximum gas limit the fallback can resolve to, representing the chain's\n * per-transaction gas cap. Clamps the `fixed` or `percentage`-derived fallback\n * so it can never exceed the gas limit the RPC will accept (e.g. ~33.5M on\n * Polygon, whereas 35% of its ~140M block gas limit would otherwise be ~49M).\n */\n maxGasLimit?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /** Maximum number of entries in the submit history. */\n submitHistoryLimit?: number;\n\n /** Maximum number of transactions stored in state. */\n transactionHistoryLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Block time in milliseconds.\n */\n blockTime?: number;\n\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n\n /**\n * Number of attempts to wait before automatically marking a transaction as failed\n * if it has no receipt status and hash is not found on the network.\n */\n timeoutAttempts?: {\n /** Automatic fail threshold on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: number;\n };\n\n /**\n * Default automatic fail threshold.\n * This value is used when no specific threshold is found for a chain ID.\n */\n default?: number;\n };\n\n /**\n * Replacement of underpriced dapp-suggested gas fees.\n * If enabled, dapp-suggested EIP-1559 fees with a `maxFeePerGas` below the\n * current low estimate are replaced with the wallet's suggested fees, as\n * they are unlikely to be included in a block before fee values change.\n */\n replaceUnderpricedDappGasFees?: {\n /** Enablement on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: boolean;\n };\n\n /**\n * Default enablement.\n * This value is used when no specific value is found for a chain ID.\n */\n default?: boolean;\n };\n\n /**\n * Replacement of underpriced saved (advanced) gas fee preferences.\n * If enabled, saved custom fees with a `maxBaseFee` below the current low\n * estimate are ignored in favour of the wallet's suggested fees, as they\n * are unlikely to be included in a block before fee values change.\n * Level-based saved preferences track current estimates and are never\n * ignored.\n */\n replaceUnderpricedSavedGasFees?: {\n /** Enablement on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: boolean;\n };\n\n /**\n * Default enablement.\n * This value is used when no specific value is found for a chain ID.\n */\n default?: boolean;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the submit history limit.\n * Defaults to 100 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The submit history limit.\n */\nexport function getSubmitHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.submitHistoryLimit ??\n DEFAULT_SUBMIT_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the transaction history limit.\n * Defaults to 40 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The transaction history limit.\n */\nexport function getTransactionHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n if (!featureFlags) {\n return undefined;\n }\n\n return (\n featureFlags[FeatureFlag.Transactions]?.transactionHistoryLimit ??\n DEFAULT_TRANSACTION_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { blockTime: number; countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ??\n acceleratedPollingParams?.defaultCountMax ??\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ??\n acceleratedPollingParams?.defaultIntervalMs ??\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n const blockTime =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.blockTime ??\n DEFAULT_BLOCK_TIME;\n\n return { blockTime, countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation ?? {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits ?? {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n maxGasLimit?: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n const maxGasLimit =\n chainFlags?.maxGasLimit ?? gasEstimateFallbackFlags?.default?.maxGasLimit;\n\n return { fixed, percentage, maxGasLimit };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithData - Whether the transaction is an EIP-7702 upgrade combined with a call.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithData,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithData: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithData ? chainFlags?.eip7702 : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the incoming transactions polling interval.\n * Retrieves the number of attempts to wait before automatically marking a transaction as dropped\n * if it has no receipt status.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The threshold number of attempts, or undefined if the feature is disabled.\n */\nexport function getTimeoutAttempts(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n const timeoutAttemptsFlags =\n featureFlags?.[FeatureFlag.Transactions]?.timeoutAttempts;\n\n return (\n timeoutAttemptsFlags?.perChainConfig?.[chainId] ??\n timeoutAttemptsFlags?.default\n );\n}\n\n/**\n * Retrieves whether underpriced dapp-suggested gas fees should be replaced\n * with the wallet's suggested fees.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns Whether the replacement is enabled.\n */\nexport function getReplaceUnderpricedDappGasFeesEnabled(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const featureFlags = getFeatureFlags(messenger);\n\n const replaceUnderpricedDappGasFeesFlags =\n featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedDappGasFees;\n\n return (\n replaceUnderpricedDappGasFeesFlags?.perChainConfig?.[chainId] ??\n replaceUnderpricedDappGasFeesFlags?.default ??\n false\n );\n}\n\n/**\n * Retrieves whether underpriced saved (advanced) gas fee preferences should be\n * ignored in favour of the wallet's suggested fees.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns Whether the replacement is enabled.\n */\nexport function getReplaceUnderpricedSavedGasFeesEnabled(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const featureFlags = getFeatureFlags(messenger);\n\n const replaceUnderpricedSavedGasFeesFlags =\n featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedSavedGasFees;\n\n return (\n replaceUnderpricedSavedGasFeesFlags?.perChainConfig?.[chainId] ??\n replaceUnderpricedSavedGasFeesFlags?.default ??\n false\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags | undefined {\n try {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n } catch {\n log('RemoteFeatureFlagController not available');\n return undefined;\n }\n}\n"]}
|
|
@@ -143,6 +143,42 @@ export type TransactionControllerFeatureFlags = {
|
|
|
143
143
|
*/
|
|
144
144
|
default?: number;
|
|
145
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Replacement of underpriced dapp-suggested gas fees.
|
|
148
|
+
* If enabled, dapp-suggested EIP-1559 fees with a `maxFeePerGas` below the
|
|
149
|
+
* current low estimate are replaced with the wallet's suggested fees, as
|
|
150
|
+
* they are unlikely to be included in a block before fee values change.
|
|
151
|
+
*/
|
|
152
|
+
replaceUnderpricedDappGasFees?: {
|
|
153
|
+
/** Enablement on a per-chain basis. */
|
|
154
|
+
perChainConfig?: {
|
|
155
|
+
[chainId: Hex]: boolean;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Default enablement.
|
|
159
|
+
* This value is used when no specific value is found for a chain ID.
|
|
160
|
+
*/
|
|
161
|
+
default?: boolean;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Replacement of underpriced saved (advanced) gas fee preferences.
|
|
165
|
+
* If enabled, saved custom fees with a `maxBaseFee` below the current low
|
|
166
|
+
* estimate are ignored in favour of the wallet's suggested fees, as they
|
|
167
|
+
* are unlikely to be included in a block before fee values change.
|
|
168
|
+
* Level-based saved preferences track current estimates and are never
|
|
169
|
+
* ignored.
|
|
170
|
+
*/
|
|
171
|
+
replaceUnderpricedSavedGasFees?: {
|
|
172
|
+
/** Enablement on a per-chain basis. */
|
|
173
|
+
perChainConfig?: {
|
|
174
|
+
[chainId: Hex]: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Default enablement.
|
|
178
|
+
* This value is used when no specific value is found for a chain ID.
|
|
179
|
+
*/
|
|
180
|
+
default?: boolean;
|
|
181
|
+
};
|
|
146
182
|
};
|
|
147
183
|
};
|
|
148
184
|
/**
|
|
@@ -255,5 +291,23 @@ export declare function getGasEstimateBuffer({ chainId, isCustomRPC, isUpgradeWi
|
|
|
255
291
|
* @returns The threshold number of attempts, or undefined if the feature is disabled.
|
|
256
292
|
*/
|
|
257
293
|
export declare function getTimeoutAttempts(chainId: Hex, messenger: TransactionControllerMessenger): number | undefined;
|
|
294
|
+
/**
|
|
295
|
+
* Retrieves whether underpriced dapp-suggested gas fees should be replaced
|
|
296
|
+
* with the wallet's suggested fees.
|
|
297
|
+
*
|
|
298
|
+
* @param chainId - The chain ID.
|
|
299
|
+
* @param messenger - The controller messenger instance.
|
|
300
|
+
* @returns Whether the replacement is enabled.
|
|
301
|
+
*/
|
|
302
|
+
export declare function getReplaceUnderpricedDappGasFeesEnabled(chainId: Hex, messenger: TransactionControllerMessenger): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Retrieves whether underpriced saved (advanced) gas fee preferences should be
|
|
305
|
+
* ignored in favour of the wallet's suggested fees.
|
|
306
|
+
*
|
|
307
|
+
* @param chainId - The chain ID.
|
|
308
|
+
* @param messenger - The controller messenger instance.
|
|
309
|
+
* @returns Whether the replacement is enabled.
|
|
310
|
+
*/
|
|
311
|
+
export declare function getReplaceUnderpricedSavedGasFeesEnabled(chainId: Hex, messenger: TransactionControllerMessenger): boolean;
|
|
258
312
|
export {};
|
|
259
313
|
//# sourceMappingURL=feature-flags.d.cts.map
|
|
@@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,EAAE,MAAM,CAAC;CACtB,CAmBA;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,SAAS,GACV,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,8BAA8B,CAAC;CAC3C,GAAG,MAAM,CAoBT;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC,MAAM,GAAG,SAAS,CAUpB"}
|
|
1
|
+
{"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAalF;;GAEG;AACH,oBAAY,WAAW;IACrB,OAAO,2BAA2B;IAClC,SAAS,6BAA6B;IACtC,YAAY,+BAA+B;CAC5C;AAED,KAAK,mBAAmB,GAAG;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,+DAA+D;IAC/D,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE;QACtB;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,CAChB,GAAG,EACH;YACE,qCAAqC;YACrC,OAAO,EAAE,GAAG,CAAC;YAEb,qDAAqD;YACrD,SAAS,EAAE,GAAG,CAAC;SAChB,EAAE,CACJ,CAAC;QAEF,sDAAsD;QACtD,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC;KACzB,CAAC;IAEF;;;OAGG;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GAOG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC,OAAO,CAWT;AAED;;;;;;;GAOG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC,OAAO,CAWT"}
|
|
@@ -143,6 +143,42 @@ export type TransactionControllerFeatureFlags = {
|
|
|
143
143
|
*/
|
|
144
144
|
default?: number;
|
|
145
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Replacement of underpriced dapp-suggested gas fees.
|
|
148
|
+
* If enabled, dapp-suggested EIP-1559 fees with a `maxFeePerGas` below the
|
|
149
|
+
* current low estimate are replaced with the wallet's suggested fees, as
|
|
150
|
+
* they are unlikely to be included in a block before fee values change.
|
|
151
|
+
*/
|
|
152
|
+
replaceUnderpricedDappGasFees?: {
|
|
153
|
+
/** Enablement on a per-chain basis. */
|
|
154
|
+
perChainConfig?: {
|
|
155
|
+
[chainId: Hex]: boolean;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Default enablement.
|
|
159
|
+
* This value is used when no specific value is found for a chain ID.
|
|
160
|
+
*/
|
|
161
|
+
default?: boolean;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Replacement of underpriced saved (advanced) gas fee preferences.
|
|
165
|
+
* If enabled, saved custom fees with a `maxBaseFee` below the current low
|
|
166
|
+
* estimate are ignored in favour of the wallet's suggested fees, as they
|
|
167
|
+
* are unlikely to be included in a block before fee values change.
|
|
168
|
+
* Level-based saved preferences track current estimates and are never
|
|
169
|
+
* ignored.
|
|
170
|
+
*/
|
|
171
|
+
replaceUnderpricedSavedGasFees?: {
|
|
172
|
+
/** Enablement on a per-chain basis. */
|
|
173
|
+
perChainConfig?: {
|
|
174
|
+
[chainId: Hex]: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Default enablement.
|
|
178
|
+
* This value is used when no specific value is found for a chain ID.
|
|
179
|
+
*/
|
|
180
|
+
default?: boolean;
|
|
181
|
+
};
|
|
146
182
|
};
|
|
147
183
|
};
|
|
148
184
|
/**
|
|
@@ -255,5 +291,23 @@ export declare function getGasEstimateBuffer({ chainId, isCustomRPC, isUpgradeWi
|
|
|
255
291
|
* @returns The threshold number of attempts, or undefined if the feature is disabled.
|
|
256
292
|
*/
|
|
257
293
|
export declare function getTimeoutAttempts(chainId: Hex, messenger: TransactionControllerMessenger): number | undefined;
|
|
294
|
+
/**
|
|
295
|
+
* Retrieves whether underpriced dapp-suggested gas fees should be replaced
|
|
296
|
+
* with the wallet's suggested fees.
|
|
297
|
+
*
|
|
298
|
+
* @param chainId - The chain ID.
|
|
299
|
+
* @param messenger - The controller messenger instance.
|
|
300
|
+
* @returns Whether the replacement is enabled.
|
|
301
|
+
*/
|
|
302
|
+
export declare function getReplaceUnderpricedDappGasFeesEnabled(chainId: Hex, messenger: TransactionControllerMessenger): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Retrieves whether underpriced saved (advanced) gas fee preferences should be
|
|
305
|
+
* ignored in favour of the wallet's suggested fees.
|
|
306
|
+
*
|
|
307
|
+
* @param chainId - The chain ID.
|
|
308
|
+
* @param messenger - The controller messenger instance.
|
|
309
|
+
* @returns Whether the replacement is enabled.
|
|
310
|
+
*/
|
|
311
|
+
export declare function getReplaceUnderpricedSavedGasFeesEnabled(chainId: Hex, messenger: TransactionControllerMessenger): boolean;
|
|
258
312
|
export {};
|
|
259
313
|
//# sourceMappingURL=feature-flags.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.mts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAalF;;GAEG;AACH,oBAAY,WAAW;IACrB,OAAO,2BAA2B;IAClC,SAAS,6BAA6B;IACtC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
|
return (timeoutAttemptsFlags?.perChainConfig?.[chainId] ??
|
|
190
190
|
timeoutAttemptsFlags?.default);
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves whether underpriced dapp-suggested gas fees should be replaced
|
|
194
|
+
* with the wallet's suggested fees.
|
|
195
|
+
*
|
|
196
|
+
* @param chainId - The chain ID.
|
|
197
|
+
* @param messenger - The controller messenger instance.
|
|
198
|
+
* @returns Whether the replacement is enabled.
|
|
199
|
+
*/
|
|
200
|
+
export function getReplaceUnderpricedDappGasFeesEnabled(chainId, messenger) {
|
|
201
|
+
const featureFlags = getFeatureFlags(messenger);
|
|
202
|
+
const replaceUnderpricedDappGasFeesFlags = featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedDappGasFees;
|
|
203
|
+
return (replaceUnderpricedDappGasFeesFlags?.perChainConfig?.[chainId] ??
|
|
204
|
+
replaceUnderpricedDappGasFeesFlags?.default ??
|
|
205
|
+
false);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Retrieves whether underpriced saved (advanced) gas fee preferences should be
|
|
209
|
+
* ignored in favour of the wallet's suggested fees.
|
|
210
|
+
*
|
|
211
|
+
* @param chainId - The chain ID.
|
|
212
|
+
* @param messenger - The controller messenger instance.
|
|
213
|
+
* @returns Whether the replacement is enabled.
|
|
214
|
+
*/
|
|
215
|
+
export function getReplaceUnderpricedSavedGasFeesEnabled(chainId, messenger) {
|
|
216
|
+
const featureFlags = getFeatureFlags(messenger);
|
|
217
|
+
const replaceUnderpricedSavedGasFeesFlags = featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedSavedGasFees;
|
|
218
|
+
return (replaceUnderpricedSavedGasFeesFlags?.perChainConfig?.[chainId] ??
|
|
219
|
+
replaceUnderpricedSavedGasFeesFlags?.default ??
|
|
220
|
+
false);
|
|
221
|
+
}
|
|
192
222
|
/**
|
|
193
223
|
* Retrieves the relevant feature flags from the remote feature flag controller.
|
|
194
224
|
*
|
|
@@ -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ACH,MAAM,UAAU,kBAAkB,CAChC,OAAY,EACZ,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,MAAM,oBAAoB,GACxB,YAAY,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;IAE5D,OAAO,CACL,oBAAoB,EAAE,cAAc,EAAE,CAAC,OAAO,CAAC;QAC/C,oBAAoB,EAAE,OAAO,CAC9B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,SAAyC;IAEzC,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CACjC,sCAAsC,CACvC,CAAC,kBAAkB,CAAC;QAErB,GAAG,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;QAE7C,OAAO,YAAiD,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { isValidSignature } from './signature.js';\nimport { padHexToEvenLength } from './utils.js';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_BLOCK_TIME = 12 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\nconst DEFAULT_SUBMIT_HISTORY_LIMIT = 100;\nconst DEFAULT_TRANSACTION_HISTORY_LIMIT = 40;\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n\n /**\n * The maximum gas limit the fallback can resolve to, representing the chain's\n * per-transaction gas cap. Clamps the `fixed` or `percentage`-derived fallback\n * so it can never exceed the gas limit the RPC will accept (e.g. ~33.5M on\n * Polygon, whereas 35% of its ~140M block gas limit would otherwise be ~49M).\n */\n maxGasLimit?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /** Maximum number of entries in the submit history. */\n submitHistoryLimit?: number;\n\n /** Maximum number of transactions stored in state. */\n transactionHistoryLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Block time in milliseconds.\n */\n blockTime?: number;\n\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n\n /**\n * Number of attempts to wait before automatically marking a transaction as failed\n * if it has no receipt status and hash is not found on the network.\n */\n timeoutAttempts?: {\n /** Automatic fail threshold on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: number;\n };\n\n /**\n * Default automatic fail threshold.\n * This value is used when no specific threshold is found for a chain ID.\n */\n default?: number;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the submit history limit.\n * Defaults to 100 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The submit history limit.\n */\nexport function getSubmitHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.submitHistoryLimit ??\n DEFAULT_SUBMIT_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the transaction history limit.\n * Defaults to 40 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The transaction history limit.\n */\nexport function getTransactionHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n if (!featureFlags) {\n return undefined;\n }\n\n return (\n featureFlags[FeatureFlag.Transactions]?.transactionHistoryLimit ??\n DEFAULT_TRANSACTION_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { blockTime: number; countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ??\n acceleratedPollingParams?.defaultCountMax ??\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ??\n acceleratedPollingParams?.defaultIntervalMs ??\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n const blockTime =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.blockTime ??\n DEFAULT_BLOCK_TIME;\n\n return { blockTime, countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation ?? {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits ?? {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n maxGasLimit?: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n const maxGasLimit =\n chainFlags?.maxGasLimit ?? gasEstimateFallbackFlags?.default?.maxGasLimit;\n\n return { fixed, percentage, maxGasLimit };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithData - Whether the transaction is an EIP-7702 upgrade combined with a call.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithData,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithData: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithData ? chainFlags?.eip7702 : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the incoming transactions polling interval.\n * Retrieves the number of attempts to wait before automatically marking a transaction as dropped\n * if it has no receipt status.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The threshold number of attempts, or undefined if the feature is disabled.\n */\nexport function getTimeoutAttempts(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n const timeoutAttemptsFlags =\n featureFlags?.[FeatureFlag.Transactions]?.timeoutAttempts;\n\n return (\n timeoutAttemptsFlags?.perChainConfig?.[chainId] ??\n timeoutAttemptsFlags?.default\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags | undefined {\n try {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n } catch {\n log('RemoteFeatureFlagController not available');\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAGrD,OAAO,EAAE,aAAa,EAAE,sBAAqB;AAE7C,OAAO,EAAE,gBAAgB,EAAE,wBAAuB;AAClD,OAAO,EAAE,kBAAkB,EAAE,oBAAmB;AAEhD,MAAM,w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,OAAO,CAC9B,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAAY,EACZ,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,MAAM,kCAAkC,GACtC,YAAY,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,6BAA6B,CAAC;IAE1E,OAAO,CACL,kCAAkC,EAAE,cAAc,EAAE,CAAC,OAAO,CAAC;QAC7D,kCAAkC,EAAE,OAAO;QAC3C,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wCAAwC,CACtD,OAAY,EACZ,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,MAAM,mCAAmC,GACvC,YAAY,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,8BAA8B,CAAC;IAE3E,OAAO,CACL,mCAAmC,EAAE,cAAc,EAAE,CAAC,OAAO,CAAC;QAC9D,mCAAmC,EAAE,OAAO;QAC5C,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,SAAyC;IAEzC,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CACjC,sCAAsC,CACvC,CAAC,kBAAkB,CAAC;QAErB,GAAG,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;QAE7C,OAAO,YAAiD,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { isValidSignature } from './signature.js';\nimport { padHexToEvenLength } from './utils.js';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_BLOCK_TIME = 12 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\nconst DEFAULT_SUBMIT_HISTORY_LIMIT = 100;\nconst DEFAULT_TRANSACTION_HISTORY_LIMIT = 40;\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n\n /**\n * The maximum gas limit the fallback can resolve to, representing the chain's\n * per-transaction gas cap. Clamps the `fixed` or `percentage`-derived fallback\n * so it can never exceed the gas limit the RPC will accept (e.g. ~33.5M on\n * Polygon, whereas 35% of its ~140M block gas limit would otherwise be ~49M).\n */\n maxGasLimit?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /** Maximum number of entries in the submit history. */\n submitHistoryLimit?: number;\n\n /** Maximum number of transactions stored in state. */\n transactionHistoryLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Block time in milliseconds.\n */\n blockTime?: number;\n\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n\n /**\n * Number of attempts to wait before automatically marking a transaction as failed\n * if it has no receipt status and hash is not found on the network.\n */\n timeoutAttempts?: {\n /** Automatic fail threshold on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: number;\n };\n\n /**\n * Default automatic fail threshold.\n * This value is used when no specific threshold is found for a chain ID.\n */\n default?: number;\n };\n\n /**\n * Replacement of underpriced dapp-suggested gas fees.\n * If enabled, dapp-suggested EIP-1559 fees with a `maxFeePerGas` below the\n * current low estimate are replaced with the wallet's suggested fees, as\n * they are unlikely to be included in a block before fee values change.\n */\n replaceUnderpricedDappGasFees?: {\n /** Enablement on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: boolean;\n };\n\n /**\n * Default enablement.\n * This value is used when no specific value is found for a chain ID.\n */\n default?: boolean;\n };\n\n /**\n * Replacement of underpriced saved (advanced) gas fee preferences.\n * If enabled, saved custom fees with a `maxBaseFee` below the current low\n * estimate are ignored in favour of the wallet's suggested fees, as they\n * are unlikely to be included in a block before fee values change.\n * Level-based saved preferences track current estimates and are never\n * ignored.\n */\n replaceUnderpricedSavedGasFees?: {\n /** Enablement on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: boolean;\n };\n\n /**\n * Default enablement.\n * This value is used when no specific value is found for a chain ID.\n */\n default?: boolean;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the submit history limit.\n * Defaults to 100 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The submit history limit.\n */\nexport function getSubmitHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.submitHistoryLimit ??\n DEFAULT_SUBMIT_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the transaction history limit.\n * Defaults to 40 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The transaction history limit.\n */\nexport function getTransactionHistoryLimit(\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n if (!featureFlags) {\n return undefined;\n }\n\n return (\n featureFlags[FeatureFlag.Transactions]?.transactionHistoryLimit ??\n DEFAULT_TRANSACTION_HISTORY_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { blockTime: number; countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ??\n acceleratedPollingParams?.defaultCountMax ??\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ??\n acceleratedPollingParams?.defaultIntervalMs ??\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n const blockTime =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.blockTime ??\n DEFAULT_BLOCK_TIME;\n\n return { blockTime, countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation ?? {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits ?? {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n maxGasLimit?: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n const maxGasLimit =\n chainFlags?.maxGasLimit ?? gasEstimateFallbackFlags?.default?.maxGasLimit;\n\n return { fixed, percentage, maxGasLimit };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithData - Whether the transaction is an EIP-7702 upgrade combined with a call.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithData,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithData: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithData ? chainFlags?.eip7702 : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the incoming transactions polling interval.\n * Retrieves the number of attempts to wait before automatically marking a transaction as dropped\n * if it has no receipt status.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The threshold number of attempts, or undefined if the feature is disabled.\n */\nexport function getTimeoutAttempts(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): number | undefined {\n const featureFlags = getFeatureFlags(messenger);\n\n const timeoutAttemptsFlags =\n featureFlags?.[FeatureFlag.Transactions]?.timeoutAttempts;\n\n return (\n timeoutAttemptsFlags?.perChainConfig?.[chainId] ??\n timeoutAttemptsFlags?.default\n );\n}\n\n/**\n * Retrieves whether underpriced dapp-suggested gas fees should be replaced\n * with the wallet's suggested fees.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns Whether the replacement is enabled.\n */\nexport function getReplaceUnderpricedDappGasFeesEnabled(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const featureFlags = getFeatureFlags(messenger);\n\n const replaceUnderpricedDappGasFeesFlags =\n featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedDappGasFees;\n\n return (\n replaceUnderpricedDappGasFeesFlags?.perChainConfig?.[chainId] ??\n replaceUnderpricedDappGasFeesFlags?.default ??\n false\n );\n}\n\n/**\n * Retrieves whether underpriced saved (advanced) gas fee preferences should be\n * ignored in favour of the wallet's suggested fees.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns Whether the replacement is enabled.\n */\nexport function getReplaceUnderpricedSavedGasFeesEnabled(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const featureFlags = getFeatureFlags(messenger);\n\n const replaceUnderpricedSavedGasFeesFlags =\n featureFlags?.[FeatureFlag.Transactions]?.replaceUnderpricedSavedGasFees;\n\n return (\n replaceUnderpricedSavedGasFeesFlags?.perChainConfig?.[chainId] ??\n replaceUnderpricedSavedGasFeesFlags?.default ??\n false\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags | undefined {\n try {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n } catch {\n log('RemoteFeatureFlagController not available');\n return undefined;\n }\n}\n"]}
|
package/dist/utils/gas-fees.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const controller_utils_1 = require("@metamask/controller-utils");
|
|
|
5
5
|
const utils_1 = require("@metamask/utils");
|
|
6
6
|
const logger_js_1 = require("../logger.cjs");
|
|
7
7
|
const types_js_1 = require("../types.cjs");
|
|
8
|
+
const feature_flags_js_1 = require("./feature-flags.cjs");
|
|
8
9
|
const gas_flow_js_1 = require("./gas-flow.cjs");
|
|
9
10
|
const provider_js_1 = require("./provider.cjs");
|
|
10
11
|
const swaps_js_1 = require("./swaps.cjs");
|
|
@@ -23,7 +24,7 @@ async function updateGasFees(request) {
|
|
|
23
24
|
const { txMeta } = request;
|
|
24
25
|
const initialParams = { ...txMeta.txParams };
|
|
25
26
|
const shouldIgnoreSavedGasFees = SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(txMeta.type);
|
|
26
|
-
|
|
27
|
+
let savedGasFees = shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)
|
|
27
28
|
? undefined
|
|
28
29
|
: request.getSavedGasFees(txMeta);
|
|
29
30
|
const suggestedGasFees = await getSuggestedGasFees({
|
|
@@ -31,6 +32,10 @@ async function updateGasFees(request) {
|
|
|
31
32
|
savedGasFees,
|
|
32
33
|
});
|
|
33
34
|
log('Suggested gas fees', suggestedGasFees);
|
|
35
|
+
if (shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)) {
|
|
36
|
+
log('Ignoring saved custom gas fees below low estimate', savedGasFees?.maxBaseFee, suggestedGasFees.low?.maxFeePerGas);
|
|
37
|
+
savedGasFees = undefined;
|
|
38
|
+
}
|
|
34
39
|
const getGasFeeRequest = {
|
|
35
40
|
...request,
|
|
36
41
|
initialParams,
|
|
@@ -83,6 +88,76 @@ function gweiDecimalToWeiDecimal(gweiDecimal) {
|
|
|
83
88
|
return weiValue.toString().split('.')[0];
|
|
84
89
|
}
|
|
85
90
|
exports.gweiDecimalToWeiDecimal = gweiDecimalToWeiDecimal;
|
|
91
|
+
/**
|
|
92
|
+
* Determine whether saved (advanced) gas fee preferences should be ignored in
|
|
93
|
+
* favour of the suggested gas fees, as the saved custom `maxBaseFee` is below
|
|
94
|
+
* the current low estimate and hence unlikely to result in timely inclusion in
|
|
95
|
+
* a block. Level-based saved preferences track current estimates and are never
|
|
96
|
+
* ignored.
|
|
97
|
+
*
|
|
98
|
+
* @param savedGasFees - The saved gas fee preferences.
|
|
99
|
+
* @param suggestedGasFees - The suggested gas fees.
|
|
100
|
+
* @param request - The request object.
|
|
101
|
+
* @returns Whether the saved gas fee preferences should be ignored.
|
|
102
|
+
*/
|
|
103
|
+
function shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request) {
|
|
104
|
+
const { eip1559, messenger, txMeta } = request;
|
|
105
|
+
if (!eip1559 ||
|
|
106
|
+
!savedGasFees?.maxBaseFee ||
|
|
107
|
+
!(0, feature_flags_js_1.getReplaceUnderpricedSavedGasFeesEnabled)(txMeta.chainId, messenger)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
|
|
111
|
+
const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
|
|
112
|
+
Boolean(suggestedGasFees.maxPriorityFeePerGas);
|
|
113
|
+
if (!lowMaxFeePerGas || !hasReplacement) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return isFeeBelowLowEstimate(gweiDecimalToWeiHex(savedGasFees.maxBaseFee), lowMaxFeePerGas);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Determine whether a fee value is below the low estimate.
|
|
120
|
+
*
|
|
121
|
+
* @param valueHex - The fee value as a hex string.
|
|
122
|
+
* @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.
|
|
123
|
+
* @returns Whether the fee value is below the low estimate.
|
|
124
|
+
*/
|
|
125
|
+
function isFeeBelowLowEstimate(valueHex, lowMaxFeePerGasHex) {
|
|
126
|
+
try {
|
|
127
|
+
return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Determine whether dapp-suggested gas fees should be ignored in favour of the
|
|
135
|
+
* suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current
|
|
136
|
+
* low estimate and hence unlikely to result in timely inclusion in a block.
|
|
137
|
+
*
|
|
138
|
+
* @param request - The request object.
|
|
139
|
+
* @returns Whether the dapp-suggested gas fees should be ignored.
|
|
140
|
+
*/
|
|
141
|
+
function shouldIgnoreDappGasFees(request) {
|
|
142
|
+
const { eip1559, initialParams, messenger, savedGasFees, suggestedGasFees, txMeta, } = request;
|
|
143
|
+
if (!eip1559 ||
|
|
144
|
+
savedGasFees ||
|
|
145
|
+
txMeta.isInternal ||
|
|
146
|
+
!(0, feature_flags_js_1.getReplaceUnderpricedDappGasFeesEnabled)(txMeta.chainId, messenger)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const dappMaxFeePerGas = initialParams.maxFeePerGas ??
|
|
150
|
+
(initialParams.gasPrice && !initialParams.maxPriorityFeePerGas
|
|
151
|
+
? initialParams.gasPrice
|
|
152
|
+
: undefined);
|
|
153
|
+
const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
|
|
154
|
+
const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
|
|
155
|
+
Boolean(suggestedGasFees.maxPriorityFeePerGas);
|
|
156
|
+
if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);
|
|
160
|
+
}
|
|
86
161
|
/**
|
|
87
162
|
* Determine the maxFeePerGas value for the transaction.
|
|
88
163
|
*
|
|
@@ -99,14 +174,20 @@ function getMaxFeePerGas(request) {
|
|
|
99
174
|
log('Using maxFeePerGas from savedGasFees', maxFeePerGas);
|
|
100
175
|
return maxFeePerGas;
|
|
101
176
|
}
|
|
102
|
-
|
|
177
|
+
const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
|
|
178
|
+
if (initialParams.maxFeePerGas && !ignoreDappGasFees) {
|
|
103
179
|
log('Using maxFeePerGas from request', initialParams.maxFeePerGas);
|
|
104
180
|
return initialParams.maxFeePerGas;
|
|
105
181
|
}
|
|
106
|
-
if (initialParams.gasPrice &&
|
|
182
|
+
if (initialParams.gasPrice &&
|
|
183
|
+
!initialParams.maxPriorityFeePerGas &&
|
|
184
|
+
!ignoreDappGasFees) {
|
|
107
185
|
log('Setting maxFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
108
186
|
return initialParams.gasPrice;
|
|
109
187
|
}
|
|
188
|
+
if (ignoreDappGasFees) {
|
|
189
|
+
log('Ignoring dapp-suggested maxFeePerGas below low estimate', initialParams.maxFeePerGas ?? initialParams.gasPrice, suggestedGasFees.low?.maxFeePerGas);
|
|
190
|
+
}
|
|
110
191
|
if (suggestedGasFees.maxFeePerGas) {
|
|
111
192
|
log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
|
|
112
193
|
return suggestedGasFees.maxFeePerGas;
|
|
@@ -134,11 +215,14 @@ function getMaxPriorityFeePerGas(request) {
|
|
|
134
215
|
log('Using maxPriorityFeePerGas from savedGasFees.priorityFee', maxPriorityFeePerGas);
|
|
135
216
|
return maxPriorityFeePerGas;
|
|
136
217
|
}
|
|
137
|
-
|
|
218
|
+
const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
|
|
219
|
+
if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {
|
|
138
220
|
log('Using maxPriorityFeePerGas from request', initialParams.maxPriorityFeePerGas);
|
|
139
221
|
return initialParams.maxPriorityFeePerGas;
|
|
140
222
|
}
|
|
141
|
-
if (initialParams.gasPrice &&
|
|
223
|
+
if (initialParams.gasPrice &&
|
|
224
|
+
!initialParams.maxFeePerGas &&
|
|
225
|
+
!ignoreDappGasFees) {
|
|
142
226
|
log('Setting maxPriorityFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
143
227
|
return initialParams.gasPrice;
|
|
144
228
|
}
|
|
@@ -206,6 +290,12 @@ function getUserFeeLevel(request) {
|
|
|
206
290
|
// overwrite the override or misrepresent the fee as matching the level.
|
|
207
291
|
return canUseSavedLevel ? savedGasFees.level : types_js_1.UserFeeLevel.CUSTOM;
|
|
208
292
|
}
|
|
293
|
+
// Underpriced dapp-suggested fees are replaced with the suggested medium
|
|
294
|
+
// values, so also use the medium fee level to keep the values updated while
|
|
295
|
+
// the transaction is unapproved.
|
|
296
|
+
if (shouldIgnoreDappGasFees(request)) {
|
|
297
|
+
return types_js_1.UserFeeLevel.MEDIUM;
|
|
298
|
+
}
|
|
209
299
|
if (!initialParams.maxFeePerGas &&
|
|
210
300
|
!initialParams.maxPriorityFeePerGas &&
|
|
211
301
|
initialParams.gasPrice) {
|
|
@@ -251,10 +341,16 @@ function updateDefaultGasEstimates(txMeta) {
|
|
|
251
341
|
async function getSuggestedGasFees(request) {
|
|
252
342
|
const { eip1559, gasFeeFlows, getGasFeeEstimates, messenger, savedGasFees, txMeta, } = request;
|
|
253
343
|
const { networkClientId } = txMeta;
|
|
344
|
+
const hasCompleteDappFees = eip1559 &&
|
|
345
|
+
Boolean(txMeta.txParams.maxFeePerGas) &&
|
|
346
|
+
Boolean(txMeta.txParams.maxPriorityFeePerGas);
|
|
347
|
+
// Estimates are still required for transactions with complete dapp-suggested
|
|
348
|
+
// fees if they may be replaced due to being underpriced.
|
|
349
|
+
const isEstimateRequiredForDappFees = hasCompleteDappFees &&
|
|
350
|
+
!txMeta.isInternal &&
|
|
351
|
+
(0, feature_flags_js_1.getReplaceUnderpricedDappGasFeesEnabled)(txMeta.chainId, messenger);
|
|
254
352
|
if ((!eip1559 && txMeta.txParams.gasPrice) ||
|
|
255
|
-
(
|
|
256
|
-
txMeta.txParams.maxFeePerGas &&
|
|
257
|
-
txMeta.txParams.maxPriorityFeePerGas)) {
|
|
353
|
+
(hasCompleteDappFees && !isEstimateRequiredForDappFees)) {
|
|
258
354
|
return {};
|
|
259
355
|
}
|
|
260
356
|
const gasFeeFlow = (0, gas_flow_js_1.getGasFeeFlow)(txMeta, gasFeeFlows, messenger);
|
|
@@ -273,6 +369,7 @@ async function getSuggestedGasFees(request) {
|
|
|
273
369
|
...(response.estimates[savedGasFeeEstimateLevel] ??
|
|
274
370
|
response.estimates.medium),
|
|
275
371
|
isEstimateLevelApplied: true,
|
|
372
|
+
low: response.estimates.low,
|
|
276
373
|
};
|
|
277
374
|
case types_js_1.GasFeeEstimateType.Legacy:
|
|
278
375
|
return {
|
|
@@ -295,6 +392,12 @@ async function getSuggestedGasFees(request) {
|
|
|
295
392
|
catch (error) {
|
|
296
393
|
log('Failed to get suggested gas fees', error);
|
|
297
394
|
}
|
|
395
|
+
// Estimates on this path are only needed to check complete dapp-suggested
|
|
396
|
+
// fees, so no fallback is required and any failure must not block
|
|
397
|
+
// transaction creation.
|
|
398
|
+
if (hasCompleteDappFees) {
|
|
399
|
+
return {};
|
|
400
|
+
}
|
|
298
401
|
const gasPriceHex = (await (0, provider_js_1.rpcRequest)({
|
|
299
402
|
messenger,
|
|
300
403
|
networkClientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-fees.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,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n GasFeeFlow,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionType,\n UserFeeLevel,\n} from '../types.js';\nimport { getGasFeeFlow } from './gas-flow.js';\nimport { rpcRequest } from './provider.js';\nimport { SWAP_TRANSACTION_TYPES } from './swaps.js';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (\n transactionMeta: TransactionMeta,\n ) => SavedGasFees | undefined;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n\n /**\n * Whether the suggested fee was derived from a specific estimate level,\n * such as `low`/`medium`/`high`. This is `false` for estimate types that\n * do not support per-level pricing, such as a flat `eth_gasPrice` value,\n * or when the gas fee flow failed and a raw RPC fallback was used.\n */\n isEstimateLevelApplied?: boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nconst SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [\n ...SWAP_TRANSACTION_TYPES,\n TransactionType.bridge,\n TransactionType.bridgeApproval,\n];\n\n/**\n * Update the gas fee properties of the provided transaction meta.\n *\n * @param request - The request object.\n */\nexport async function updateGasFees(\n request: UpdateGasFeesRequest,\n): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const shouldIgnoreSavedGasFees =\n SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n\n const savedGasFees =\n shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)\n ? undefined\n : request.getSavedGasFees(txMeta);\n\n const suggestedGasFees = await getSuggestedGasFees({\n ...request,\n savedGasFees,\n });\n\n log('Suggested gas fees', suggestedGasFees);\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\n/**\n * Convert GWEI from decimal string to WEI as hex string.\n *\n * @param value - The GWEI value as a decimal string.\n * @returns The WEI value in hex.\n */\nexport function gweiDecimalToWeiHex(value: string): Hex {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Converts a value from Gwei decimal representation to Wei decimal representation\n *\n * @param gweiDecimal - The value in Gwei as a string or number\n * @returns The value in Wei as a string\n *\n * @example\n * // Convert 1.5 Gwei to Wei\n * gweiDecimalToWeiDecimal(\"1.5\")\n * // Returns \"1500000000\"\n */\nexport function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string {\n const weiValue = Number(gweiDecimal) * 1e9;\n\n return weiValue.toString().split('.')[0];\n}\n\n/**\n * Determine the maxFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxFeePerGas value.\n */\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.maxBaseFee) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n if (initialParams.maxFeePerGas) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the maxPriorityFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxPriorityFeePerGas value.\n */\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.priorityFee) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n if (initialParams.maxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the gasPrice value for the transaction.\n *\n * @param request - The request object.\n * @returns The gasPrice value.\n */\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.gasPrice) {\n const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);\n log('Using gasPrice from savedGasFees.gasPrice', gasPrice);\n return gasPrice;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\n/**\n * Determine the user fee level.\n *\n * @param request - The request object.\n * @returns The user fee level.\n */\nfunction getUserFeeLevel(request: GetGasFeeRequest): string | undefined {\n const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;\n\n if (savedGasFees) {\n const hasCustomOverride =\n savedGasFees.maxBaseFee !== undefined ||\n savedGasFees.priorityFee !== undefined ||\n savedGasFees.gasPrice !== undefined;\n\n const canUseSavedLevel =\n !hasCustomOverride &&\n savedGasFees.level !== undefined &&\n suggestedGasFees.isEstimateLevelApplied;\n\n // A custom override on any field, or an estimate type that does not\n // support per-level pricing (e.g. a flat eth_gasPrice value), means the\n // fee is no longer purely level-derived, so it must not be tracked as a\n // live estimate level by the gas fee poller, which would otherwise\n // overwrite the override or misrepresent the fee as matching the level.\n return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.isInternal\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.gasPrice\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.isInternal) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Update the default gas estimates for the provided transaction.\n *\n * @param txMeta - The transaction metadata.\n */\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta): void {\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\n/**\n * Retrieve the suggested gas fees using the gas fee flows.\n *\n * @param request - The request object.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest & { savedGasFees?: SavedGasFees },\n): Promise<SuggestedGasFees> {\n const {\n eip1559,\n gasFeeFlows,\n getGasFeeEstimates,\n messenger,\n savedGasFees,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (eip1559 &&\n txMeta.txParams.maxFeePerGas &&\n txMeta.txParams.maxPriorityFeePerGas)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(\n txMeta,\n gasFeeFlows,\n messenger,\n ) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n gasFeeControllerData,\n messenger,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return {\n ...(response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium),\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice:\n response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium,\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.GasPrice:\n return {\n gasPrice: response.estimates.gasPrice,\n isEstimateLevelApplied: false,\n };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n const gasPriceHex = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_gasPrice',\n })) as Hex | undefined;\n\n const gasPrice = gasPriceHex ? add0x(gasPriceHex) : undefined;\n\n return { gasPrice };\n}\n\nfunction hasInitialGasFeeParams(initialParams: TransactionParams): boolean {\n return [\n initialParams.maxFeePerGas,\n initialParams.maxPriorityFeePerGas,\n initialParams.gasPrice,\n ].some(Boolean);\n}\n\nfunction getSavedGasFeeEstimateLevel(\n savedGasFees: SavedGasFees | undefined,\n): GasFeeEstimateLevel {\n return isGasFeeEstimateLevel(savedGasFees?.level)\n ? savedGasFees.level\n : GasFeeEstimateLevel.Medium;\n}\n\nfunction isGasFeeEstimateLevel(level: unknown): level is GasFeeEstimateLevel {\n return Object.values(GasFeeEstimateLevel).includes(\n level as GasFeeEstimateLevel,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;AAAA,iEAAmE;AAMnE,2CAA4D;AAE5D,6CAA6C;AAS7C,2CAKqB;AACrB,0DAG4B;AAC5B,gDAA8C;AAC9C,gDAA2C;AAC3C,0CAAoD;AAqCpD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,UAAU,CAAC,CAAC;AAE1D,MAAM,wCAAwC,GAAG;IAC/C,GAAG,iCAAsB;IACzB,0BAAe,CAAC,MAAM;IACtB,0BAAe,CAAC,cAAc;CAC/B,CAAC;AAEF;;;;GAIG;AACI,KAAK,UAAU,aAAa,CACjC,OAA6B;IAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,wBAAwB,GAC5B,wCAAwC,CAAC,QAAQ,CAC/C,MAAM,CAAC,IAAuB,CAC/B,CAAC;IAEJ,IAAI,YAAY,GACd,wBAAwB,IAAI,sBAAsB,CAAC,aAAa,CAAC;QAC/D,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,gBAAgB,GAAG,MAAM,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AAI,mBAAmB,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,MAAM,IAAA,wBAAU,EAAC;QACpC,SAAS;QACT,eAAe;QACf,MAAM,EAAE,cAAc;KACvB,CAAC,CAAoB,CAAC;IAEvB,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,sBAAsB,CAAC,aAAgC;IAC9D,OAAO;QACL,aAAa,CAAC,YAAY;QAC1B,aAAa,CAAC,oBAAoB;QAClC,aAAa,CAAC,QAAQ;KACvB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,2BAA2B,CAClC,YAAsC;IAEtC,OAAO,qBAAqB,CAAC,YAAY,EAAE,KAAK,CAAC;QAC/C,CAAC,CAAC,YAAY,CAAC,KAAK;QACpB,CAAC,CAAC,8BAAmB,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC,QAAQ,CAChD,KAA4B,CAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { gweiDecToWEIBN, toHex } from '@metamask/controller-utils';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n GasFeeFlow,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionType,\n UserFeeLevel,\n} from '../types.js';\nimport {\n getReplaceUnderpricedDappGasFeesEnabled,\n getReplaceUnderpricedSavedGasFeesEnabled,\n} from './feature-flags.js';\nimport { getGasFeeFlow } from './gas-flow.js';\nimport { rpcRequest } from './provider.js';\nimport { SWAP_TRANSACTION_TYPES } from './swaps.js';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (\n transactionMeta: TransactionMeta,\n ) => SavedGasFees | undefined;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n\n /**\n * Whether the suggested fee was derived from a specific estimate level,\n * such as `low`/`medium`/`high`. This is `false` for estimate types that\n * do not support per-level pricing, such as a flat `eth_gasPrice` value,\n * or when the gas fee flow failed and a raw RPC fallback was used.\n */\n isEstimateLevelApplied?: boolean;\n\n low?: FeeMarketGasFeeEstimateForLevel;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nconst SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [\n ...SWAP_TRANSACTION_TYPES,\n TransactionType.bridge,\n TransactionType.bridgeApproval,\n];\n\n/**\n * Update the gas fee properties of the provided transaction meta.\n *\n * @param request - The request object.\n */\nexport async function updateGasFees(\n request: UpdateGasFeesRequest,\n): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const shouldIgnoreSavedGasFees =\n SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n\n let savedGasFees =\n shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)\n ? undefined\n : request.getSavedGasFees(txMeta);\n\n const suggestedGasFees = await getSuggestedGasFees({\n ...request,\n savedGasFees,\n });\n\n log('Suggested gas fees', suggestedGasFees);\n\n if (\n shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)\n ) {\n log(\n 'Ignoring saved custom gas fees below low estimate',\n savedGasFees?.maxBaseFee,\n suggestedGasFees.low?.maxFeePerGas,\n );\n savedGasFees = undefined;\n }\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\n/**\n * Convert GWEI from decimal string to WEI as hex string.\n *\n * @param value - The GWEI value as a decimal string.\n * @returns The WEI value in hex.\n */\nexport function gweiDecimalToWeiHex(value: string): Hex {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Converts a value from Gwei decimal representation to Wei decimal representation\n *\n * @param gweiDecimal - The value in Gwei as a string or number\n * @returns The value in Wei as a string\n *\n * @example\n * // Convert 1.5 Gwei to Wei\n * gweiDecimalToWeiDecimal(\"1.5\")\n * // Returns \"1500000000\"\n */\nexport function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string {\n const weiValue = Number(gweiDecimal) * 1e9;\n\n return weiValue.toString().split('.')[0];\n}\n\n/**\n * Determine whether saved (advanced) gas fee preferences should be ignored in\n * favour of the suggested gas fees, as the saved custom `maxBaseFee` is below\n * the current low estimate and hence unlikely to result in timely inclusion in\n * a block. Level-based saved preferences track current estimates and are never\n * ignored.\n *\n * @param savedGasFees - The saved gas fee preferences.\n * @param suggestedGasFees - The suggested gas fees.\n * @param request - The request object.\n * @returns Whether the saved gas fee preferences should be ignored.\n */\nfunction shouldIgnoreUnderpricedSavedGasFees(\n savedGasFees: SavedGasFees | undefined,\n suggestedGasFees: SuggestedGasFees,\n request: UpdateGasFeesRequest,\n): boolean {\n const { eip1559, messenger, txMeta } = request;\n\n if (\n !eip1559 ||\n !savedGasFees?.maxBaseFee ||\n !getReplaceUnderpricedSavedGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(\n gweiDecimalToWeiHex(savedGasFees.maxBaseFee),\n lowMaxFeePerGas,\n );\n}\n\n/**\n * Determine whether a fee value is below the low estimate.\n *\n * @param valueHex - The fee value as a hex string.\n * @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.\n * @returns Whether the fee value is below the low estimate.\n */\nfunction isFeeBelowLowEstimate(\n valueHex: string,\n lowMaxFeePerGasHex: string,\n): boolean {\n try {\n return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);\n } catch {\n return false;\n }\n}\n\n/**\n * Determine whether dapp-suggested gas fees should be ignored in favour of the\n * suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current\n * low estimate and hence unlikely to result in timely inclusion in a block.\n *\n * @param request - The request object.\n * @returns Whether the dapp-suggested gas fees should be ignored.\n */\nfunction shouldIgnoreDappGasFees(request: GetGasFeeRequest): boolean {\n const {\n eip1559,\n initialParams,\n messenger,\n savedGasFees,\n suggestedGasFees,\n txMeta,\n } = request;\n\n if (\n !eip1559 ||\n savedGasFees ||\n txMeta.isInternal ||\n !getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const dappMaxFeePerGas =\n initialParams.maxFeePerGas ??\n (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas\n ? initialParams.gasPrice\n : undefined);\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);\n}\n\n/**\n * Determine the maxFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxFeePerGas value.\n */\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.maxBaseFee) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxFeePerGas && !ignoreDappGasFees) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxPriorityFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (ignoreDappGasFees) {\n log(\n 'Ignoring dapp-suggested maxFeePerGas below low estimate',\n initialParams.maxFeePerGas ?? initialParams.gasPrice,\n suggestedGasFees.low?.maxFeePerGas,\n );\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the maxPriorityFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxPriorityFeePerGas value.\n */\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.priorityFee) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the gasPrice value for the transaction.\n *\n * @param request - The request object.\n * @returns The gasPrice value.\n */\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.gasPrice) {\n const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);\n log('Using gasPrice from savedGasFees.gasPrice', gasPrice);\n return gasPrice;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\n/**\n * Determine the user fee level.\n *\n * @param request - The request object.\n * @returns The user fee level.\n */\nfunction getUserFeeLevel(request: GetGasFeeRequest): string | undefined {\n const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;\n\n if (savedGasFees) {\n const hasCustomOverride =\n savedGasFees.maxBaseFee !== undefined ||\n savedGasFees.priorityFee !== undefined ||\n savedGasFees.gasPrice !== undefined;\n\n const canUseSavedLevel =\n !hasCustomOverride &&\n savedGasFees.level !== undefined &&\n suggestedGasFees.isEstimateLevelApplied;\n\n // A custom override on any field, or an estimate type that does not\n // support per-level pricing (e.g. a flat eth_gasPrice value), means the\n // fee is no longer purely level-derived, so it must not be tracked as a\n // live estimate level by the gas fee poller, which would otherwise\n // overwrite the override or misrepresent the fee as matching the level.\n return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;\n }\n\n // Underpriced dapp-suggested fees are replaced with the suggested medium\n // values, so also use the medium fee level to keep the values updated while\n // the transaction is unapproved.\n if (shouldIgnoreDappGasFees(request)) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.isInternal\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.gasPrice\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.isInternal) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Update the default gas estimates for the provided transaction.\n *\n * @param txMeta - The transaction metadata.\n */\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta): void {\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\n/**\n * Retrieve the suggested gas fees using the gas fee flows.\n *\n * @param request - The request object.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest & { savedGasFees?: SavedGasFees },\n): Promise<SuggestedGasFees> {\n const {\n eip1559,\n gasFeeFlows,\n getGasFeeEstimates,\n messenger,\n savedGasFees,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n\n const hasCompleteDappFees =\n eip1559 &&\n Boolean(txMeta.txParams.maxFeePerGas) &&\n Boolean(txMeta.txParams.maxPriorityFeePerGas);\n\n // Estimates are still required for transactions with complete dapp-suggested\n // fees if they may be replaced due to being underpriced.\n const isEstimateRequiredForDappFees =\n hasCompleteDappFees &&\n !txMeta.isInternal &&\n getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger);\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (hasCompleteDappFees && !isEstimateRequiredForDappFees)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(\n txMeta,\n gasFeeFlows,\n messenger,\n ) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n gasFeeControllerData,\n messenger,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return {\n ...(response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium),\n isEstimateLevelApplied: true,\n low: response.estimates.low,\n };\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice:\n response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium,\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.GasPrice:\n return {\n gasPrice: response.estimates.gasPrice,\n isEstimateLevelApplied: false,\n };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n // Estimates on this path are only needed to check complete dapp-suggested\n // fees, so no fallback is required and any failure must not block\n // transaction creation.\n if (hasCompleteDappFees) {\n return {};\n }\n\n const gasPriceHex = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_gasPrice',\n })) as Hex | undefined;\n\n const gasPrice = gasPriceHex ? add0x(gasPriceHex) : undefined;\n\n return { gasPrice };\n}\n\nfunction hasInitialGasFeeParams(initialParams: TransactionParams): boolean {\n return [\n initialParams.maxFeePerGas,\n initialParams.maxPriorityFeePerGas,\n initialParams.gasPrice,\n ].some(Boolean);\n}\n\nfunction getSavedGasFeeEstimateLevel(\n savedGasFees: SavedGasFees | undefined,\n): GasFeeEstimateLevel {\n return isGasFeeEstimateLevel(savedGasFees?.level)\n ? savedGasFees.level\n : GasFeeEstimateLevel.Medium;\n}\n\nfunction isGasFeeEstimateLevel(level: unknown): level is GasFeeEstimateLevel {\n return Object.values(GasFeeEstimateLevel).includes(\n level as GasFeeEstimateLevel,\n );\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
|
|
2
2
|
import type { Hex } from "@metamask/utils";
|
|
3
3
|
import type { TransactionControllerMessenger } from "../TransactionController.cjs";
|
|
4
|
-
import type { SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.cjs";
|
|
4
|
+
import type { FeeMarketGasFeeEstimateForLevel, SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.cjs";
|
|
5
5
|
export type UpdateGasFeesRequest = {
|
|
6
6
|
eip1559: boolean;
|
|
7
7
|
gasFeeFlows: GasFeeFlow[];
|
|
@@ -26,6 +26,7 @@ type SuggestedGasFees = {
|
|
|
26
26
|
* or when the gas fee flow failed and a raw RPC fallback was used.
|
|
27
27
|
*/
|
|
28
28
|
isEstimateLevelApplied?: boolean;
|
|
29
|
+
low?: FeeMarketGasFeeEstimateForLevel;
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
* Update the gas fee properties of the provided transaction meta.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV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;IAEjC,GAAG,CAAC,EAAE,+BAA+B,CAAC;CACvC,CAAC;AAUF;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA+Df;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAEtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAI5E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
|
|
2
2
|
import type { Hex } from "@metamask/utils";
|
|
3
3
|
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
4
|
-
import type { SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.mjs";
|
|
4
|
+
import type { FeeMarketGasFeeEstimateForLevel, SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.mjs";
|
|
5
5
|
export type UpdateGasFeesRequest = {
|
|
6
6
|
eip1559: boolean;
|
|
7
7
|
gasFeeFlows: GasFeeFlow[];
|
|
@@ -26,6 +26,7 @@ type SuggestedGasFees = {
|
|
|
26
26
|
* or when the gas fee flow failed and a raw RPC fallback was used.
|
|
27
27
|
*/
|
|
28
28
|
isEstimateLevelApplied?: boolean;
|
|
29
|
+
low?: FeeMarketGasFeeEstimateForLevel;
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
* Update the gas fee properties of the provided transaction meta.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE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oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA+Df;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAEtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAI5E"}
|
package/dist/utils/gas-fees.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { gweiDecToWEIBN, toHex } from "@metamask/controller-utils";
|
|
|
2
2
|
import { add0x, createModuleLogger } from "@metamask/utils";
|
|
3
3
|
import { projectLogger } from "../logger.mjs";
|
|
4
4
|
import { GasFeeEstimateLevel, GasFeeEstimateType, TransactionType, UserFeeLevel } from "../types.mjs";
|
|
5
|
+
import { getReplaceUnderpricedDappGasFeesEnabled, getReplaceUnderpricedSavedGasFeesEnabled } from "./feature-flags.mjs";
|
|
5
6
|
import { getGasFeeFlow } from "./gas-flow.mjs";
|
|
6
7
|
import { rpcRequest } from "./provider.mjs";
|
|
7
8
|
import { SWAP_TRANSACTION_TYPES } from "./swaps.mjs";
|
|
@@ -20,7 +21,7 @@ export async function updateGasFees(request) {
|
|
|
20
21
|
const { txMeta } = request;
|
|
21
22
|
const initialParams = { ...txMeta.txParams };
|
|
22
23
|
const shouldIgnoreSavedGasFees = SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(txMeta.type);
|
|
23
|
-
|
|
24
|
+
let savedGasFees = shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)
|
|
24
25
|
? undefined
|
|
25
26
|
: request.getSavedGasFees(txMeta);
|
|
26
27
|
const suggestedGasFees = await getSuggestedGasFees({
|
|
@@ -28,6 +29,10 @@ export async function updateGasFees(request) {
|
|
|
28
29
|
savedGasFees,
|
|
29
30
|
});
|
|
30
31
|
log('Suggested gas fees', suggestedGasFees);
|
|
32
|
+
if (shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)) {
|
|
33
|
+
log('Ignoring saved custom gas fees below low estimate', savedGasFees?.maxBaseFee, suggestedGasFees.low?.maxFeePerGas);
|
|
34
|
+
savedGasFees = undefined;
|
|
35
|
+
}
|
|
31
36
|
const getGasFeeRequest = {
|
|
32
37
|
...request,
|
|
33
38
|
initialParams,
|
|
@@ -77,6 +82,76 @@ export function gweiDecimalToWeiDecimal(gweiDecimal) {
|
|
|
77
82
|
const weiValue = Number(gweiDecimal) * 1e9;
|
|
78
83
|
return weiValue.toString().split('.')[0];
|
|
79
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Determine whether saved (advanced) gas fee preferences should be ignored in
|
|
87
|
+
* favour of the suggested gas fees, as the saved custom `maxBaseFee` is below
|
|
88
|
+
* the current low estimate and hence unlikely to result in timely inclusion in
|
|
89
|
+
* a block. Level-based saved preferences track current estimates and are never
|
|
90
|
+
* ignored.
|
|
91
|
+
*
|
|
92
|
+
* @param savedGasFees - The saved gas fee preferences.
|
|
93
|
+
* @param suggestedGasFees - The suggested gas fees.
|
|
94
|
+
* @param request - The request object.
|
|
95
|
+
* @returns Whether the saved gas fee preferences should be ignored.
|
|
96
|
+
*/
|
|
97
|
+
function shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request) {
|
|
98
|
+
const { eip1559, messenger, txMeta } = request;
|
|
99
|
+
if (!eip1559 ||
|
|
100
|
+
!savedGasFees?.maxBaseFee ||
|
|
101
|
+
!getReplaceUnderpricedSavedGasFeesEnabled(txMeta.chainId, messenger)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
|
|
105
|
+
const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
|
|
106
|
+
Boolean(suggestedGasFees.maxPriorityFeePerGas);
|
|
107
|
+
if (!lowMaxFeePerGas || !hasReplacement) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return isFeeBelowLowEstimate(gweiDecimalToWeiHex(savedGasFees.maxBaseFee), lowMaxFeePerGas);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Determine whether a fee value is below the low estimate.
|
|
114
|
+
*
|
|
115
|
+
* @param valueHex - The fee value as a hex string.
|
|
116
|
+
* @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.
|
|
117
|
+
* @returns Whether the fee value is below the low estimate.
|
|
118
|
+
*/
|
|
119
|
+
function isFeeBelowLowEstimate(valueHex, lowMaxFeePerGasHex) {
|
|
120
|
+
try {
|
|
121
|
+
return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Determine whether dapp-suggested gas fees should be ignored in favour of the
|
|
129
|
+
* suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current
|
|
130
|
+
* low estimate and hence unlikely to result in timely inclusion in a block.
|
|
131
|
+
*
|
|
132
|
+
* @param request - The request object.
|
|
133
|
+
* @returns Whether the dapp-suggested gas fees should be ignored.
|
|
134
|
+
*/
|
|
135
|
+
function shouldIgnoreDappGasFees(request) {
|
|
136
|
+
const { eip1559, initialParams, messenger, savedGasFees, suggestedGasFees, txMeta, } = request;
|
|
137
|
+
if (!eip1559 ||
|
|
138
|
+
savedGasFees ||
|
|
139
|
+
txMeta.isInternal ||
|
|
140
|
+
!getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const dappMaxFeePerGas = initialParams.maxFeePerGas ??
|
|
144
|
+
(initialParams.gasPrice && !initialParams.maxPriorityFeePerGas
|
|
145
|
+
? initialParams.gasPrice
|
|
146
|
+
: undefined);
|
|
147
|
+
const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
|
|
148
|
+
const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
|
|
149
|
+
Boolean(suggestedGasFees.maxPriorityFeePerGas);
|
|
150
|
+
if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);
|
|
154
|
+
}
|
|
80
155
|
/**
|
|
81
156
|
* Determine the maxFeePerGas value for the transaction.
|
|
82
157
|
*
|
|
@@ -93,14 +168,20 @@ function getMaxFeePerGas(request) {
|
|
|
93
168
|
log('Using maxFeePerGas from savedGasFees', maxFeePerGas);
|
|
94
169
|
return maxFeePerGas;
|
|
95
170
|
}
|
|
96
|
-
|
|
171
|
+
const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
|
|
172
|
+
if (initialParams.maxFeePerGas && !ignoreDappGasFees) {
|
|
97
173
|
log('Using maxFeePerGas from request', initialParams.maxFeePerGas);
|
|
98
174
|
return initialParams.maxFeePerGas;
|
|
99
175
|
}
|
|
100
|
-
if (initialParams.gasPrice &&
|
|
176
|
+
if (initialParams.gasPrice &&
|
|
177
|
+
!initialParams.maxPriorityFeePerGas &&
|
|
178
|
+
!ignoreDappGasFees) {
|
|
101
179
|
log('Setting maxFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
102
180
|
return initialParams.gasPrice;
|
|
103
181
|
}
|
|
182
|
+
if (ignoreDappGasFees) {
|
|
183
|
+
log('Ignoring dapp-suggested maxFeePerGas below low estimate', initialParams.maxFeePerGas ?? initialParams.gasPrice, suggestedGasFees.low?.maxFeePerGas);
|
|
184
|
+
}
|
|
104
185
|
if (suggestedGasFees.maxFeePerGas) {
|
|
105
186
|
log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
|
|
106
187
|
return suggestedGasFees.maxFeePerGas;
|
|
@@ -128,11 +209,14 @@ function getMaxPriorityFeePerGas(request) {
|
|
|
128
209
|
log('Using maxPriorityFeePerGas from savedGasFees.priorityFee', maxPriorityFeePerGas);
|
|
129
210
|
return maxPriorityFeePerGas;
|
|
130
211
|
}
|
|
131
|
-
|
|
212
|
+
const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
|
|
213
|
+
if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {
|
|
132
214
|
log('Using maxPriorityFeePerGas from request', initialParams.maxPriorityFeePerGas);
|
|
133
215
|
return initialParams.maxPriorityFeePerGas;
|
|
134
216
|
}
|
|
135
|
-
if (initialParams.gasPrice &&
|
|
217
|
+
if (initialParams.gasPrice &&
|
|
218
|
+
!initialParams.maxFeePerGas &&
|
|
219
|
+
!ignoreDappGasFees) {
|
|
136
220
|
log('Setting maxPriorityFeePerGas to gasPrice from request', initialParams.gasPrice);
|
|
137
221
|
return initialParams.gasPrice;
|
|
138
222
|
}
|
|
@@ -200,6 +284,12 @@ function getUserFeeLevel(request) {
|
|
|
200
284
|
// overwrite the override or misrepresent the fee as matching the level.
|
|
201
285
|
return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;
|
|
202
286
|
}
|
|
287
|
+
// Underpriced dapp-suggested fees are replaced with the suggested medium
|
|
288
|
+
// values, so also use the medium fee level to keep the values updated while
|
|
289
|
+
// the transaction is unapproved.
|
|
290
|
+
if (shouldIgnoreDappGasFees(request)) {
|
|
291
|
+
return UserFeeLevel.MEDIUM;
|
|
292
|
+
}
|
|
203
293
|
if (!initialParams.maxFeePerGas &&
|
|
204
294
|
!initialParams.maxPriorityFeePerGas &&
|
|
205
295
|
initialParams.gasPrice) {
|
|
@@ -245,10 +335,16 @@ function updateDefaultGasEstimates(txMeta) {
|
|
|
245
335
|
async function getSuggestedGasFees(request) {
|
|
246
336
|
const { eip1559, gasFeeFlows, getGasFeeEstimates, messenger, savedGasFees, txMeta, } = request;
|
|
247
337
|
const { networkClientId } = txMeta;
|
|
338
|
+
const hasCompleteDappFees = eip1559 &&
|
|
339
|
+
Boolean(txMeta.txParams.maxFeePerGas) &&
|
|
340
|
+
Boolean(txMeta.txParams.maxPriorityFeePerGas);
|
|
341
|
+
// Estimates are still required for transactions with complete dapp-suggested
|
|
342
|
+
// fees if they may be replaced due to being underpriced.
|
|
343
|
+
const isEstimateRequiredForDappFees = hasCompleteDappFees &&
|
|
344
|
+
!txMeta.isInternal &&
|
|
345
|
+
getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger);
|
|
248
346
|
if ((!eip1559 && txMeta.txParams.gasPrice) ||
|
|
249
|
-
(
|
|
250
|
-
txMeta.txParams.maxFeePerGas &&
|
|
251
|
-
txMeta.txParams.maxPriorityFeePerGas)) {
|
|
347
|
+
(hasCompleteDappFees && !isEstimateRequiredForDappFees)) {
|
|
252
348
|
return {};
|
|
253
349
|
}
|
|
254
350
|
const gasFeeFlow = getGasFeeFlow(txMeta, gasFeeFlows, messenger);
|
|
@@ -267,6 +363,7 @@ async function getSuggestedGasFees(request) {
|
|
|
267
363
|
...(response.estimates[savedGasFeeEstimateLevel] ??
|
|
268
364
|
response.estimates.medium),
|
|
269
365
|
isEstimateLevelApplied: true,
|
|
366
|
+
low: response.estimates.low,
|
|
270
367
|
};
|
|
271
368
|
case GasFeeEstimateType.Legacy:
|
|
272
369
|
return {
|
|
@@ -289,6 +386,12 @@ async function getSuggestedGasFees(request) {
|
|
|
289
386
|
catch (error) {
|
|
290
387
|
log('Failed to get suggested gas fees', error);
|
|
291
388
|
}
|
|
389
|
+
// Estimates on this path are only needed to check complete dapp-suggested
|
|
390
|
+
// fees, so no fallback is required and any failure must not block
|
|
391
|
+
// transaction creation.
|
|
392
|
+
if (hasCompleteDappFees) {
|
|
393
|
+
return {};
|
|
394
|
+
}
|
|
292
395
|
const gasPriceHex = (await rpcRequest({
|
|
293
396
|
messenger,
|
|
294
397
|
networkClientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,mCAAmC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} from '@metamask/controller-utils';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n GasFeeFlow,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionType,\n UserFeeLevel,\n} from '../types.js';\nimport { getGasFeeFlow } from './gas-flow.js';\nimport { rpcRequest } from './provider.js';\nimport { SWAP_TRANSACTION_TYPES } from './swaps.js';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (\n transactionMeta: TransactionMeta,\n ) => SavedGasFees | undefined;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n\n /**\n * Whether the suggested fee was derived from a specific estimate level,\n * such as `low`/`medium`/`high`. This is `false` for estimate types that\n * do not support per-level pricing, such as a flat `eth_gasPrice` value,\n * or when the gas fee flow failed and a raw RPC fallback was used.\n */\n isEstimateLevelApplied?: boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nconst SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [\n ...SWAP_TRANSACTION_TYPES,\n TransactionType.bridge,\n TransactionType.bridgeApproval,\n];\n\n/**\n * Update the gas fee properties of the provided transaction meta.\n *\n * @param request - The request object.\n */\nexport async function updateGasFees(\n request: UpdateGasFeesRequest,\n): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const shouldIgnoreSavedGasFees =\n SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n\n const savedGasFees =\n shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)\n ? undefined\n : request.getSavedGasFees(txMeta);\n\n const suggestedGasFees = await getSuggestedGasFees({\n ...request,\n savedGasFees,\n });\n\n log('Suggested gas fees', suggestedGasFees);\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\n/**\n * Convert GWEI from decimal string to WEI as hex string.\n *\n * @param value - The GWEI value as a decimal string.\n * @returns The WEI value in hex.\n */\nexport function gweiDecimalToWeiHex(value: string): Hex {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Converts a value from Gwei decimal representation to Wei decimal representation\n *\n * @param gweiDecimal - The value in Gwei as a string or number\n * @returns The value in Wei as a string\n *\n * @example\n * // Convert 1.5 Gwei to Wei\n * gweiDecimalToWeiDecimal(\"1.5\")\n * // Returns \"1500000000\"\n */\nexport function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string {\n const weiValue = Number(gweiDecimal) * 1e9;\n\n return weiValue.toString().split('.')[0];\n}\n\n/**\n * Determine the maxFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxFeePerGas value.\n */\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.maxBaseFee) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n if (initialParams.maxFeePerGas) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the maxPriorityFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxPriorityFeePerGas value.\n */\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.priorityFee) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n if (initialParams.maxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the gasPrice value for the transaction.\n *\n * @param request - The request object.\n * @returns The gasPrice value.\n */\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.gasPrice) {\n const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);\n log('Using gasPrice from savedGasFees.gasPrice', gasPrice);\n return gasPrice;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\n/**\n * Determine the user fee level.\n *\n * @param request - The request object.\n * @returns The user fee level.\n */\nfunction getUserFeeLevel(request: GetGasFeeRequest): string | undefined {\n const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;\n\n if (savedGasFees) {\n const hasCustomOverride =\n savedGasFees.maxBaseFee !== undefined ||\n savedGasFees.priorityFee !== undefined ||\n savedGasFees.gasPrice !== undefined;\n\n const canUseSavedLevel =\n !hasCustomOverride &&\n savedGasFees.level !== undefined &&\n suggestedGasFees.isEstimateLevelApplied;\n\n // A custom override on any field, or an estimate type that does not\n // support per-level pricing (e.g. a flat eth_gasPrice value), means the\n // fee is no longer purely level-derived, so it must not be tracked as a\n // live estimate level by the gas fee poller, which would otherwise\n // overwrite the override or misrepresent the fee as matching the level.\n return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.isInternal\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.gasPrice\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.isInternal) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Update the default gas estimates for the provided transaction.\n *\n * @param txMeta - The transaction metadata.\n */\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta): void {\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\n/**\n * Retrieve the suggested gas fees using the gas fee flows.\n *\n * @param request - The request object.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest & { savedGasFees?: SavedGasFees },\n): Promise<SuggestedGasFees> {\n const {\n eip1559,\n gasFeeFlows,\n getGasFeeEstimates,\n messenger,\n savedGasFees,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (eip1559 &&\n txMeta.txParams.maxFeePerGas &&\n txMeta.txParams.maxPriorityFeePerGas)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(\n txMeta,\n gasFeeFlows,\n messenger,\n ) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n gasFeeControllerData,\n messenger,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return {\n ...(response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium),\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice:\n response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium,\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.GasPrice:\n return {\n gasPrice: response.estimates.gasPrice,\n isEstimateLevelApplied: false,\n };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n const gasPriceHex = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_gasPrice',\n })) as Hex | undefined;\n\n const gasPrice = gasPriceHex ? add0x(gasPriceHex) : undefined;\n\n return { gasPrice };\n}\n\nfunction hasInitialGasFeeParams(initialParams: TransactionParams): boolean {\n return [\n initialParams.maxFeePerGas,\n initialParams.maxPriorityFeePerGas,\n initialParams.gasPrice,\n ].some(Boolean);\n}\n\nfunction getSavedGasFeeEstimateLevel(\n savedGasFees: SavedGasFees | undefined,\n): GasFeeEstimateLevel {\n return isGasFeeEstimateLevel(savedGasFees?.level)\n ? savedGasFees.level\n : GasFeeEstimateLevel.Medium;\n}\n\nfunction isGasFeeEstimateLevel(level: unknown): level is GasFeeEstimateLevel {\n return Object.values(GasFeeEstimateLevel).includes(\n level as GasFeeEstimateLevel,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,mCAAmC;AAMnE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE5D,OAAO,EAAE,aAAa,EAAE,sBAAqB;AAS7C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACb,qBAAoB;AACrB,OAAO,EACL,uCAAuC,EACvC,wCAAwC,EACzC,4BAA2B;AAC5B,OAAO,EAAE,aAAa,EAAE,uBAAsB;AAC9C,OAAO,EAAE,UAAU,EAAE,uBAAsB;AAC3C,OAAO,EAAE,sBAAsB,EAAE,oBAAmB;AAqCpD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAE1D,MAAM,wCAAwC,GAAG;IAC/C,GAAG,sBAAsB;IACzB,eAAe,CAAC,MAAM;IACtB,eAAe,CAAC,cAAc;CAC/B,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6B;IAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM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AAI,KAAK;gBACb,gFAAgF;gBAChF,4EAA4E;gBAC5E,yDAAyD,kBAAkB,EAAE,CAC9E,CAAC;QACN,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,0EAA0E;IAC1E,kEAAkE;IAClE,wBAAwB;IACxB,IAAI,mBAAmB,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,MAAM,UAAU,CAAC;QACpC,SAAS;QACT,eAAe;QACf,MAAM,EAAE,cAAc;KACvB,CAAC,CAAoB,CAAC;IAEvB,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,sBAAsB,CAAC,aAAgC;IAC9D,OAAO;QACL,aAAa,CAAC,YAAY;QAC1B,aAAa,CAAC,oBAAoB;QAClC,aAAa,CAAC,QAAQ;KACvB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,2BAA2B,CAClC,YAAsC;IAEtC,OAAO,qBAAqB,CAAC,YAAY,EAAE,KAAK,CAAC;QAC/C,CAAC,CAAC,YAAY,CAAC,KAAK;QACpB,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAChD,KAA4B,CAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { gweiDecToWEIBN, toHex } from '@metamask/controller-utils';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n GasFeeFlow,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionType,\n UserFeeLevel,\n} from '../types.js';\nimport {\n getReplaceUnderpricedDappGasFeesEnabled,\n getReplaceUnderpricedSavedGasFeesEnabled,\n} from './feature-flags.js';\nimport { getGasFeeFlow } from './gas-flow.js';\nimport { rpcRequest } from './provider.js';\nimport { SWAP_TRANSACTION_TYPES } from './swaps.js';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (\n transactionMeta: TransactionMeta,\n ) => SavedGasFees | undefined;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n\n /**\n * Whether the suggested fee was derived from a specific estimate level,\n * such as `low`/`medium`/`high`. This is `false` for estimate types that\n * do not support per-level pricing, such as a flat `eth_gasPrice` value,\n * or when the gas fee flow failed and a raw RPC fallback was used.\n */\n isEstimateLevelApplied?: boolean;\n\n low?: FeeMarketGasFeeEstimateForLevel;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nconst SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [\n ...SWAP_TRANSACTION_TYPES,\n TransactionType.bridge,\n TransactionType.bridgeApproval,\n];\n\n/**\n * Update the gas fee properties of the provided transaction meta.\n *\n * @param request - The request object.\n */\nexport async function updateGasFees(\n request: UpdateGasFeesRequest,\n): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const shouldIgnoreSavedGasFees =\n SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n\n let savedGasFees =\n shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)\n ? undefined\n : request.getSavedGasFees(txMeta);\n\n const suggestedGasFees = await getSuggestedGasFees({\n ...request,\n savedGasFees,\n });\n\n log('Suggested gas fees', suggestedGasFees);\n\n if (\n shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)\n ) {\n log(\n 'Ignoring saved custom gas fees below low estimate',\n savedGasFees?.maxBaseFee,\n suggestedGasFees.low?.maxFeePerGas,\n );\n savedGasFees = undefined;\n }\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\n/**\n * Convert GWEI from decimal string to WEI as hex string.\n *\n * @param value - The GWEI value as a decimal string.\n * @returns The WEI value in hex.\n */\nexport function gweiDecimalToWeiHex(value: string): Hex {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Converts a value from Gwei decimal representation to Wei decimal representation\n *\n * @param gweiDecimal - The value in Gwei as a string or number\n * @returns The value in Wei as a string\n *\n * @example\n * // Convert 1.5 Gwei to Wei\n * gweiDecimalToWeiDecimal(\"1.5\")\n * // Returns \"1500000000\"\n */\nexport function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string {\n const weiValue = Number(gweiDecimal) * 1e9;\n\n return weiValue.toString().split('.')[0];\n}\n\n/**\n * Determine whether saved (advanced) gas fee preferences should be ignored in\n * favour of the suggested gas fees, as the saved custom `maxBaseFee` is below\n * the current low estimate and hence unlikely to result in timely inclusion in\n * a block. Level-based saved preferences track current estimates and are never\n * ignored.\n *\n * @param savedGasFees - The saved gas fee preferences.\n * @param suggestedGasFees - The suggested gas fees.\n * @param request - The request object.\n * @returns Whether the saved gas fee preferences should be ignored.\n */\nfunction shouldIgnoreUnderpricedSavedGasFees(\n savedGasFees: SavedGasFees | undefined,\n suggestedGasFees: SuggestedGasFees,\n request: UpdateGasFeesRequest,\n): boolean {\n const { eip1559, messenger, txMeta } = request;\n\n if (\n !eip1559 ||\n !savedGasFees?.maxBaseFee ||\n !getReplaceUnderpricedSavedGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(\n gweiDecimalToWeiHex(savedGasFees.maxBaseFee),\n lowMaxFeePerGas,\n );\n}\n\n/**\n * Determine whether a fee value is below the low estimate.\n *\n * @param valueHex - The fee value as a hex string.\n * @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.\n * @returns Whether the fee value is below the low estimate.\n */\nfunction isFeeBelowLowEstimate(\n valueHex: string,\n lowMaxFeePerGasHex: string,\n): boolean {\n try {\n return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);\n } catch {\n return false;\n }\n}\n\n/**\n * Determine whether dapp-suggested gas fees should be ignored in favour of the\n * suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current\n * low estimate and hence unlikely to result in timely inclusion in a block.\n *\n * @param request - The request object.\n * @returns Whether the dapp-suggested gas fees should be ignored.\n */\nfunction shouldIgnoreDappGasFees(request: GetGasFeeRequest): boolean {\n const {\n eip1559,\n initialParams,\n messenger,\n savedGasFees,\n suggestedGasFees,\n txMeta,\n } = request;\n\n if (\n !eip1559 ||\n savedGasFees ||\n txMeta.isInternal ||\n !getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const dappMaxFeePerGas =\n initialParams.maxFeePerGas ??\n (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas\n ? initialParams.gasPrice\n : undefined);\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);\n}\n\n/**\n * Determine the maxFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxFeePerGas value.\n */\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.maxBaseFee) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxFeePerGas && !ignoreDappGasFees) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxPriorityFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (ignoreDappGasFees) {\n log(\n 'Ignoring dapp-suggested maxFeePerGas below low estimate',\n initialParams.maxFeePerGas ?? initialParams.gasPrice,\n suggestedGasFees.low?.maxFeePerGas,\n );\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the maxPriorityFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxPriorityFeePerGas value.\n */\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.priorityFee) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the gasPrice value for the transaction.\n *\n * @param request - The request object.\n * @returns The gasPrice value.\n */\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.gasPrice) {\n const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);\n log('Using gasPrice from savedGasFees.gasPrice', gasPrice);\n return gasPrice;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\n/**\n * Determine the user fee level.\n *\n * @param request - The request object.\n * @returns The user fee level.\n */\nfunction getUserFeeLevel(request: GetGasFeeRequest): string | undefined {\n const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;\n\n if (savedGasFees) {\n const hasCustomOverride =\n savedGasFees.maxBaseFee !== undefined ||\n savedGasFees.priorityFee !== undefined ||\n savedGasFees.gasPrice !== undefined;\n\n const canUseSavedLevel =\n !hasCustomOverride &&\n savedGasFees.level !== undefined &&\n suggestedGasFees.isEstimateLevelApplied;\n\n // A custom override on any field, or an estimate type that does not\n // support per-level pricing (e.g. a flat eth_gasPrice value), means the\n // fee is no longer purely level-derived, so it must not be tracked as a\n // live estimate level by the gas fee poller, which would otherwise\n // overwrite the override or misrepresent the fee as matching the level.\n return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;\n }\n\n // Underpriced dapp-suggested fees are replaced with the suggested medium\n // values, so also use the medium fee level to keep the values updated while\n // the transaction is unapproved.\n if (shouldIgnoreDappGasFees(request)) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.isInternal\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.gasPrice\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.isInternal) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Update the default gas estimates for the provided transaction.\n *\n * @param txMeta - The transaction metadata.\n */\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta): void {\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\n/**\n * Retrieve the suggested gas fees using the gas fee flows.\n *\n * @param request - The request object.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest & { savedGasFees?: SavedGasFees },\n): Promise<SuggestedGasFees> {\n const {\n eip1559,\n gasFeeFlows,\n getGasFeeEstimates,\n messenger,\n savedGasFees,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n\n const hasCompleteDappFees =\n eip1559 &&\n Boolean(txMeta.txParams.maxFeePerGas) &&\n Boolean(txMeta.txParams.maxPriorityFeePerGas);\n\n // Estimates are still required for transactions with complete dapp-suggested\n // fees if they may be replaced due to being underpriced.\n const isEstimateRequiredForDappFees =\n hasCompleteDappFees &&\n !txMeta.isInternal &&\n getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger);\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (hasCompleteDappFees && !isEstimateRequiredForDappFees)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(\n txMeta,\n gasFeeFlows,\n messenger,\n ) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n gasFeeControllerData,\n messenger,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return {\n ...(response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium),\n isEstimateLevelApplied: true,\n low: response.estimates.low,\n };\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice:\n response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium,\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.GasPrice:\n return {\n gasPrice: response.estimates.gasPrice,\n isEstimateLevelApplied: false,\n };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n // Estimates on this path are only needed to check complete dapp-suggested\n // fees, so no fallback is required and any failure must not block\n // transaction creation.\n if (hasCompleteDappFees) {\n return {};\n }\n\n const gasPriceHex = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_gasPrice',\n })) as Hex | undefined;\n\n const gasPrice = gasPriceHex ? add0x(gasPriceHex) : undefined;\n\n return { gasPrice };\n}\n\nfunction hasInitialGasFeeParams(initialParams: TransactionParams): boolean {\n return [\n initialParams.maxFeePerGas,\n initialParams.maxPriorityFeePerGas,\n initialParams.gasPrice,\n ].some(Boolean);\n}\n\nfunction getSavedGasFeeEstimateLevel(\n savedGasFees: SavedGasFees | undefined,\n): GasFeeEstimateLevel {\n return isGasFeeEstimateLevel(savedGasFees?.level)\n ? savedGasFees.level\n : GasFeeEstimateLevel.Medium;\n}\n\nfunction isGasFeeEstimateLevel(level: unknown): level is GasFeeEstimateLevel {\n return Object.values(GasFeeEstimateLevel).includes(\n level as GasFeeEstimateLevel,\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/transaction-controller",
|
|
3
|
-
"version": "69.4.0-preview-
|
|
3
|
+
"version": "69.4.0-preview-0efc7ef01",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|