@metamask-previews/transaction-controller 69.2.1-preview-064aea96d → 69.2.1-preview-ec4680201
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 +4 -0
- package/dist/TransactionController-method-action-types.cjs.map +1 -1
- package/dist/TransactionController-method-action-types.d.cts.map +1 -1
- package/dist/TransactionController-method-action-types.d.mts.map +1 -1
- package/dist/TransactionController-method-action-types.mjs.map +1 -1
- package/dist/TransactionController.cjs +205 -205
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +1 -1
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/api/accounts-api.cjs +5 -5
- package/dist/api/accounts-api.cjs.map +1 -1
- package/dist/api/accounts-api.mjs.map +1 -1
- package/dist/api/simulation-api.cjs +8 -8
- package/dist/api/simulation-api.cjs.map +1 -1
- package/dist/api/simulation-api.d.cts.map +1 -1
- package/dist/api/simulation-api.d.mts.map +1 -1
- package/dist/api/simulation-api.mjs.map +1 -1
- package/dist/errors.cjs +4 -4
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.cjs +13 -13
- package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +10 -10
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +8 -8
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +10 -10
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +10 -10
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +13 -13
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +4 -4
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.cjs +2 -2
- package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +22 -22
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +2 -2
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +2 -2
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/MethodDataHelper.cjs +4 -4
- package/dist/helpers/MethodDataHelper.cjs.map +1 -1
- package/dist/helpers/MethodDataHelper.d.cts +2 -2
- package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
- package/dist/helpers/MethodDataHelper.d.mts +2 -2
- package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
- package/dist/helpers/MethodDataHelper.mjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.cjs +2 -2
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +22 -22
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts +2 -2
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts +2 -2
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/helpers/ResimulateHelper.cjs +6 -6
- package/dist/helpers/ResimulateHelper.cjs.map +1 -1
- package/dist/helpers/ResimulateHelper.d.cts.map +1 -1
- package/dist/helpers/ResimulateHelper.d.mts.map +1 -1
- package/dist/helpers/ResimulateHelper.mjs.map +1 -1
- package/dist/helpers/TransactionPoller.cjs +4 -4
- package/dist/helpers/TransactionPoller.cjs.map +1 -1
- package/dist/helpers/TransactionPoller.d.cts.map +1 -1
- package/dist/helpers/TransactionPoller.d.mts.map +1 -1
- package/dist/helpers/TransactionPoller.mjs.map +1 -1
- package/dist/hooks/CollectPublishHook.cjs +2 -2
- package/dist/hooks/CollectPublishHook.cjs.map +1 -1
- package/dist/hooks/CollectPublishHook.d.cts.map +1 -1
- package/dist/hooks/CollectPublishHook.d.mts.map +1 -1
- package/dist/hooks/CollectPublishHook.mjs.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.cjs +2 -2
- package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.cjs +2 -2
- package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
- package/dist/index.cjs +33 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/balance-changes.cjs +31 -31
- package/dist/utils/balance-changes.cjs.map +1 -1
- package/dist/utils/balance-changes.d.cts.map +1 -1
- package/dist/utils/balance-changes.d.mts.map +1 -1
- package/dist/utils/balance-changes.mjs.map +1 -1
- package/dist/utils/balance.cjs +2 -2
- package/dist/utils/balance.cjs.map +1 -1
- package/dist/utils/balance.d.cts.map +1 -1
- package/dist/utils/balance.d.mts.map +1 -1
- package/dist/utils/balance.mjs.map +1 -1
- package/dist/utils/batch.cjs +45 -45
- package/dist/utils/batch.cjs.map +1 -1
- package/dist/utils/batch.d.cts +1 -1
- package/dist/utils/batch.d.cts.map +1 -1
- package/dist/utils/batch.d.mts +1 -1
- package/dist/utils/batch.d.mts.map +1 -1
- package/dist/utils/batch.mjs +1 -1
- package/dist/utils/batch.mjs.map +1 -1
- package/dist/utils/eip7702.cjs +9 -9
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/external-transactions.cjs +2 -2
- package/dist/utils/external-transactions.cjs.map +1 -1
- package/dist/utils/external-transactions.d.cts.map +1 -1
- package/dist/utils/external-transactions.d.mts.map +1 -1
- package/dist/utils/external-transactions.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +5 -5
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/dist/utils/first-time-interaction.cjs +14 -14
- package/dist/utils/first-time-interaction.cjs.map +1 -1
- package/dist/utils/first-time-interaction.d.cts.map +1 -1
- package/dist/utils/first-time-interaction.d.mts.map +1 -1
- package/dist/utils/first-time-interaction.mjs.map +1 -1
- package/dist/utils/gas-fee-tokens.cjs +13 -13
- package/dist/utils/gas-fee-tokens.cjs.map +1 -1
- package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
- package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
- package/dist/utils/gas-fee-tokens.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +19 -19
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas-flow.cjs +6 -6
- package/dist/utils/gas-flow.cjs.map +1 -1
- package/dist/utils/gas-flow.d.cts.map +1 -1
- package/dist/utils/gas-flow.d.mts.map +1 -1
- package/dist/utils/gas-flow.mjs.map +1 -1
- package/dist/utils/gas.cjs +27 -27
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +2 -2
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/nonce.cjs +2 -2
- package/dist/utils/nonce.cjs.map +1 -1
- package/dist/utils/nonce.d.cts.map +1 -1
- package/dist/utils/nonce.d.mts.map +1 -1
- package/dist/utils/nonce.mjs.map +1 -1
- package/dist/utils/prepare.cjs.map +1 -1
- package/dist/utils/prepare.d.cts.map +1 -1
- package/dist/utils/prepare.d.mts.map +1 -1
- package/dist/utils/prepare.mjs.map +1 -1
- package/dist/utils/provider.cjs +2 -2
- package/dist/utils/provider.cjs.map +1 -1
- package/dist/utils/provider.d.cts.map +1 -1
- package/dist/utils/provider.d.mts.map +1 -1
- package/dist/utils/provider.mjs.map +1 -1
- package/dist/utils/retry.cjs.map +1 -1
- package/dist/utils/retry.d.cts.map +1 -1
- package/dist/utils/retry.d.mts.map +1 -1
- package/dist/utils/retry.mjs.map +1 -1
- package/dist/utils/revert-reason.cjs +4 -4
- package/dist/utils/revert-reason.cjs.map +1 -1
- package/dist/utils/revert-reason.d.cts.map +1 -1
- package/dist/utils/revert-reason.d.mts.map +1 -1
- package/dist/utils/revert-reason.mjs.map +1 -1
- package/dist/utils/swaps.cjs +28 -28
- package/dist/utils/swaps.cjs.map +1 -1
- package/dist/utils/swaps.d.cts.map +1 -1
- package/dist/utils/swaps.d.mts.map +1 -1
- package/dist/utils/swaps.mjs.map +1 -1
- package/dist/utils/transaction-type.cjs +14 -14
- package/dist/utils/transaction-type.cjs.map +1 -1
- package/dist/utils/transaction-type.d.cts.map +1 -1
- package/dist/utils/transaction-type.d.mts.map +1 -1
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/dist/utils/utils.cjs +8 -8
- package/dist/utils/utils.cjs.map +1 -1
- package/dist/utils/utils.d.cts.map +1 -1
- package/dist/utils/utils.d.mts.map +1 -1
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/validation.cjs +11 -11
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.cts.map +1 -1
- package/dist/utils/validation.d.mts.map +1 -1
- package/dist/utils/validation.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iEAAqE;AAErE,2CAAqD;AAIrD,
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iEAAqE;AAErE,2CAAqD;AAIrD,6CAA6C;AAS7C,2CAAsE;AACtE,uDAAkD;AAClD,kEAA2D;AAW3D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,oBAAoB,CAAC,CAAC;AAEpE,MAAM,eAAe,GAAU;IAC7B,0BAAO,CAAC,eAAe,CAAC;IACxB,0BAAO,CAAC,cAAc,CAAC;IACvB,0BAAO,CAAC,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,IAAI;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IAAA,wBAAU,EAAC;QAChB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,CAAC,MAAM,CAAC;KACjB,CAAsC,CAAC;AAC1C,CAAC,iGAGC,KAAU,EACV,WAA0D;IAE1D,MAAM,IAAI,GAAG,IAAA,0BAAO,EAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEzC,OAAO;QACL,GAAG;QACH,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC,qEAGC,QAAyC,EACzC,YAA6C;IAE7C,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC;QACvC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC;QAChD,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC;KAC3C,CAAC;AACJ,CAAC,yEAEa,IAAiB;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACtD,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import { ChainId, hexToBN, toHex } from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow.js';\n\ntype LineaEstimateGasResponse = {\n baseFeePerGas: Hex;\n priorityFeePerGas: Hex;\n};\n\ntype FeesByLevel = {\n [key in GasFeeEstimateLevel]: BN;\n};\n\nconst log = createModuleLogger(projectLogger, 'linea-gas-fee-flow');\n\nconst LINEA_CHAIN_IDS: Hex[] = [\n ChainId['linea-mainnet'],\n ChainId['linea-goerli'],\n ChainId['linea-sepolia'],\n];\n\nconst BASE_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.35,\n high: 1.7,\n};\n\nconst PRIORITY_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.05,\n high: 1.1,\n};\n\n/**\n * Implementation of a gas fee flow specific to Linea networks that obtains gas fee estimates using:\n * - The `linea_estimateGas` RPC method to obtain the base fee and lowest priority fee.\n * - Static multipliers to increase the base and priority fees.\n */\nexport class LineaGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n return LINEA_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getLineaGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n }\n\n async #getLineaGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, transactionMeta } = request;\n const { networkClientId } = transactionMeta;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n messenger,\n networkClientId,\n );\n\n log('Received Linea response', lineaResponse);\n\n const baseFees = this.#getValuesFromMultipliers(\n lineaResponse.baseFeePerGas,\n BASE_FEE_MULTIPLIERS,\n );\n\n log('Generated base fees', this.#feesToString(baseFees));\n\n const priorityFees = this.#getValuesFromMultipliers(\n lineaResponse.priorityFeePerGas,\n PRIORITY_FEE_MULTIPLIERS,\n );\n\n log('Generated priority fees', this.#feesToString(priorityFees));\n\n const maxFees = this.#getMaxFees(baseFees, priorityFees);\n\n log('Generated max fees', this.#feesToString(maxFees));\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: {\n maxFeePerGas: toHex(maxFees[level]),\n maxPriorityFeePerGas: toHex(priorityFees[level]),\n },\n }),\n { type: GasFeeEstimateType.FeeMarket } as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getLineaResponse(\n transactionMeta: TransactionMeta,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n ): Promise<LineaEstimateGasResponse> {\n const { from, to, value, data } = transactionMeta.txParams;\n\n const params: Record<string, string> = { from };\n\n if (to) {\n params.to = to;\n }\n\n if (value) {\n params.value = value;\n }\n\n if (data) {\n params.input = data;\n }\n\n return rpcRequest({\n messenger,\n networkClientId,\n method: 'linea_estimateGas',\n params: [params],\n }) as Promise<LineaEstimateGasResponse>;\n }\n\n #getValuesFromMultipliers(\n value: Hex,\n multipliers: { low: number; medium: number; high: number },\n ): FeesByLevel {\n const base = hexToBN(value);\n const low = base.muln(multipliers.low);\n const medium = base.muln(multipliers.medium);\n const high = base.muln(multipliers.high);\n\n return {\n low,\n medium,\n high,\n };\n }\n\n #getMaxFees(\n baseFees: Record<GasFeeEstimateLevel, BN>,\n priorityFees: Record<GasFeeEstimateLevel, BN>,\n ): FeesByLevel {\n return {\n low: baseFees.low.add(priorityFees.low),\n medium: baseFees.medium.add(priorityFees.medium),\n high: baseFees.high.add(priorityFees.high),\n };\n }\n\n #feesToString(fees: FeesByLevel): string[] {\n return Object.values(GasFeeEstimateLevel).map((level) =>\n fees[level].toString(10),\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAoB;AAkCrB;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,UAAU;;IAChD,kBAAkB,CAAC,EACjB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAIL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoH1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAoB;AAkCrB;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,UAAU;;IAChD,kBAAkB,CAAC,EACjB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO;IAIL,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoH1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAErE,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAIrD,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAErE,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAIrD,OAAO,EAAE,aAAa,EAAE,sBAAqB;AAS7C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,qBAAoB;AACtE,OAAO,EAAE,UAAU,EAAE,8BAA6B;AAClD,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAW3D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;AAEpE,MAAM,eAAe,GAAU;IAC7B,OAAO,CAAC,eAAe,CAAC;IACxB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,GAAG;CACV,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,GAAG;CACV,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAA5B;;IA8HA,CA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AAG,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEzC,OAAO;QACL,GAAG;QACH,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC,qEAGC,QAAyC,EACzC,YAA6C;IAE7C,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC;QACvC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC;QAChD,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC;KAC3C,CAAC;AACJ,CAAC,yEAEa,IAAiB;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACtD,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import { ChainId, hexToBN, toHex } from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow.js';\n\ntype LineaEstimateGasResponse = {\n baseFeePerGas: Hex;\n priorityFeePerGas: Hex;\n};\n\ntype FeesByLevel = {\n [key in GasFeeEstimateLevel]: BN;\n};\n\nconst log = createModuleLogger(projectLogger, 'linea-gas-fee-flow');\n\nconst LINEA_CHAIN_IDS: Hex[] = [\n ChainId['linea-mainnet'],\n ChainId['linea-goerli'],\n ChainId['linea-sepolia'],\n];\n\nconst BASE_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.35,\n high: 1.7,\n};\n\nconst PRIORITY_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.05,\n high: 1.1,\n};\n\n/**\n * Implementation of a gas fee flow specific to Linea networks that obtains gas fee estimates using:\n * - The `linea_estimateGas` RPC method to obtain the base fee and lowest priority fee.\n * - Static multipliers to increase the base and priority fees.\n */\nexport class LineaGasFeeFlow implements GasFeeFlow {\n matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): boolean {\n return LINEA_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getLineaGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n }\n\n async #getLineaGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { messenger, transactionMeta } = request;\n const { networkClientId } = transactionMeta;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n messenger,\n networkClientId,\n );\n\n log('Received Linea response', lineaResponse);\n\n const baseFees = this.#getValuesFromMultipliers(\n lineaResponse.baseFeePerGas,\n BASE_FEE_MULTIPLIERS,\n );\n\n log('Generated base fees', this.#feesToString(baseFees));\n\n const priorityFees = this.#getValuesFromMultipliers(\n lineaResponse.priorityFeePerGas,\n PRIORITY_FEE_MULTIPLIERS,\n );\n\n log('Generated priority fees', this.#feesToString(priorityFees));\n\n const maxFees = this.#getMaxFees(baseFees, priorityFees);\n\n log('Generated max fees', this.#feesToString(maxFees));\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: {\n maxFeePerGas: toHex(maxFees[level]),\n maxPriorityFeePerGas: toHex(priorityFees[level]),\n },\n }),\n { type: GasFeeEstimateType.FeeMarket } as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getLineaResponse(\n transactionMeta: TransactionMeta,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n ): Promise<LineaEstimateGasResponse> {\n const { from, to, value, data } = transactionMeta.txParams;\n\n const params: Record<string, string> = { from };\n\n if (to) {\n params.to = to;\n }\n\n if (value) {\n params.value = value;\n }\n\n if (data) {\n params.input = data;\n }\n\n return rpcRequest({\n messenger,\n networkClientId,\n method: 'linea_estimateGas',\n params: [params],\n }) as Promise<LineaEstimateGasResponse>;\n }\n\n #getValuesFromMultipliers(\n value: Hex,\n multipliers: { low: number; medium: number; high: number },\n ): FeesByLevel {\n const base = hexToBN(value);\n const low = base.muln(multipliers.low);\n const medium = base.muln(multipliers.medium);\n const high = base.muln(multipliers.high);\n\n return {\n low,\n medium,\n high,\n };\n }\n\n #getMaxFees(\n baseFees: Record<GasFeeEstimateLevel, BN>,\n priorityFees: Record<GasFeeEstimateLevel, BN>,\n ): FeesByLevel {\n return {\n low: baseFees.low.add(priorityFees.low),\n medium: baseFees.medium.add(priorityFees.medium),\n high: baseFees.high.add(priorityFees.high),\n };\n }\n\n #feesToString(fees: FeesByLevel): string[] {\n return Object.values(GasFeeEstimateLevel).map((level) =>\n fees[level].toString(10),\n );\n }\n}\n"]}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MantleLayer1GasFeeFlow = void 0;
|
|
4
4
|
const abi_1 = require("@ethersproject/abi");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const MANTLE_CHAIN_IDS = [
|
|
5
|
+
const constants_js_1 = require("../constants.cjs");
|
|
6
|
+
const provider_js_1 = require("../utils/provider.cjs");
|
|
7
|
+
const utils_js_1 = require("../utils/utils.cjs");
|
|
8
|
+
const OracleLayer1GasFeeFlow_js_1 = require("./OracleLayer1GasFeeFlow.cjs");
|
|
9
|
+
const MANTLE_CHAIN_IDS = [constants_js_1.CHAIN_IDS.MANTLE, constants_js_1.CHAIN_IDS.MANTLE_SEPOLIA];
|
|
10
10
|
const TOKEN_RATIO_ABI = [
|
|
11
11
|
{
|
|
12
12
|
inputs: [],
|
|
@@ -31,7 +31,7 @@ const TOKEN_RATIO_INTERFACE = new abi_1.Interface(TOKEN_RATIO_ABI);
|
|
|
31
31
|
* tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert
|
|
32
32
|
* the fee to MNT.
|
|
33
33
|
*/
|
|
34
|
-
class MantleLayer1GasFeeFlow extends
|
|
34
|
+
class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_js_1.OracleLayer1GasFeeFlow {
|
|
35
35
|
async matchesTransaction({ transactionMeta, }) {
|
|
36
36
|
return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);
|
|
37
37
|
}
|
|
@@ -49,7 +49,7 @@ class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_1.OracleLayer1GasFee
|
|
|
49
49
|
// `Web3Provider`, whose `setTimeout`-based dispatch never fires on React
|
|
50
50
|
// Native when the timer pump is starved (e.g. iOS display link freeze).
|
|
51
51
|
// See https://github.com/MetaMask/metamask-mobile/issues/32863
|
|
52
|
-
const result = await (0,
|
|
52
|
+
const result = await (0, provider_js_1.rpcRequest)({
|
|
53
53
|
messenger,
|
|
54
54
|
networkClientId,
|
|
55
55
|
method: 'eth_call',
|
|
@@ -58,7 +58,7 @@ class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_1.OracleLayer1GasFee
|
|
|
58
58
|
if (typeof result !== 'string' || result === '0x') {
|
|
59
59
|
throw new Error('No value returned from token ratio contract');
|
|
60
60
|
}
|
|
61
|
-
const tokenRatio = (0,
|
|
61
|
+
const tokenRatio = (0, utils_js_1.toBN)(result);
|
|
62
62
|
return oracleFee.mul(tokenRatio);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAI/C,
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAI/C,mDAA4C;AAG5C,uDAAkD;AAClD,iDAAyC;AACzC,4EAAqE;AAErE,MAAM,gBAAgB,GAAU,CAAC,wBAAS,CAAC,MAAM,EAAE,wBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,eAAe,GAAG;IACtB;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF,MAAM,qBAAqB,GAAG,IAAI,eAAS,CAAC,eAAe,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAa,sBAAuB,SAAQ,kDAAsB;IAChE,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAEkB,iBAAiB,CAClC,eAAgC;QAEhC,OAAO,CACL,eAAe,CAAC,OAAO;YACvB,eAAe,CAAC,QAAQ,CAAC,GAAG;YAC5B,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAClC,CAAC;IACJ,CAAC;IAEkB,KAAK,CAAC,kBAAkB,CACzC,SAAa,EACb,OAAgC;QAEhC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAC/C,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC;QAErD,MAAM,EAAE,GAAG,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,qBAAqB,CAAC,kBAAkB,CACnD,YAAY,EACZ,EAAE,CACI,CAAC;QAET,sEAAsE;QACtE,yEAAyE;QACzE,wEAAwE;QACxE,+DAA+D;QAC/D,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAU,EAAC;YAC9B,SAAS;YACT,eAAe;YACf,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC;SACjC,CAAC,CAAC;QAEH,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,eAAI,EAAC,MAAM,CAAC,CAAC;QAChC,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACF;AAnDD,wDAmDC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { Layer1GasFeeFlowRequest, TransactionMeta } from '../types.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { toBN } from '../utils/utils.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];\n\nconst TOKEN_RATIO_ABI = [\n {\n inputs: [],\n name: 'tokenRatio',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\nconst TOKEN_RATIO_INTERFACE = new Interface(TOKEN_RATIO_ABI);\n\n/**\n * Mantle layer 1 gas fee flow.\n *\n * Mantle uses MNT as its native gas token, but the oracle's getL1Fee returns\n * values denominated in ETH. This subclass multiplies the L1 fee by the\n * tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert\n * the fee to MNT.\n */\nexport class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n protected override getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return (\n transactionMeta.gasUsed ??\n transactionMeta.txParams.gas ??\n transactionMeta.txParams.gasLimit\n );\n }\n\n protected override async transformOracleFee(\n oracleFee: BN,\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = TOKEN_RATIO_INTERFACE.encodeFunctionData(\n 'tokenRatio',\n [],\n ) as Hex;\n\n // Direct `eth_call` RPC request rather than an ethers `Contract` with\n // `Web3Provider`, whose `setTimeout`-based dispatch never fires on React\n // Native when the timer pump is starved (e.g. iOS display link freeze).\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n const result = await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from token ratio contract');\n }\n\n const tokenRatio = toBN(result);\n return oracleFee.mul(tokenRatio);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAoB;AAG5E,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAsBrE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;cAID,iBAAiB,CAClC,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;cAQI,kBAAkB,CACzC,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,EAAE,CAAC;CA4Bf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAoB;AAG5E,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAsBrE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;cAID,iBAAiB,CAClC,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;cAQI,kBAAkB,CACzC,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,EAAE,CAAC;CA4Bf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAI/C,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAI/C,OAAO,EAAE,SAAS,EAAE,yBAAwB;AAG5C,OAAO,EAAE,UAAU,EAAE,8BAA6B;AAClD,OAAO,EAAE,IAAI,EAAE,2BAA0B;AACzC,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAErE,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,eAAe,GAAG;IACtB;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE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AC,CAAC;QACjE,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { Layer1GasFeeFlowRequest, TransactionMeta } from '../types.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { toBN } from '../utils/utils.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];\n\nconst TOKEN_RATIO_ABI = [\n {\n inputs: [],\n name: 'tokenRatio',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\nconst TOKEN_RATIO_INTERFACE = new Interface(TOKEN_RATIO_ABI);\n\n/**\n * Mantle layer 1 gas fee flow.\n *\n * Mantle uses MNT as its native gas token, but the oracle's getL1Fee returns\n * values denominated in ETH. This subclass multiplies the L1 fee by the\n * tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert\n * the fee to MNT.\n */\nexport class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n protected override getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return (\n transactionMeta.gasUsed ??\n transactionMeta.txParams.gas ??\n transactionMeta.txParams.gasLimit\n );\n }\n\n protected override async transformOracleFee(\n oracleFee: BN,\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = TOKEN_RATIO_INTERFACE.encodeFunctionData(\n 'tokenRatio',\n [],\n ) as Hex;\n\n // Direct `eth_call` RPC request rather than an ethers `Contract` with\n // `Web3Provider`, whose `setTimeout`-based dispatch never fires on React\n // Native when the timer pump is starved (e.g. iOS display link freeze).\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n const result = await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from token ratio contract');\n }\n\n const tokenRatio = toBN(result);\n return oracleFee.mul(tokenRatio);\n }\n}\n"]}
|
|
@@ -9,22 +9,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.OptimismLayer1GasFeeFlow = void 0;
|
|
10
10
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
11
11
|
const utils_1 = require("@metamask/utils");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const constants_js_1 = require("../constants.cjs");
|
|
13
|
+
const OracleLayer1GasFeeFlow_js_1 = require("./OracleLayer1GasFeeFlow.cjs");
|
|
14
14
|
const FALLBACK_OPTIMISM_STACK_CHAIN_IDS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
constants_js_1.CHAIN_IDS.OPTIMISM,
|
|
16
|
+
constants_js_1.CHAIN_IDS.OPTIMISM_TESTNET,
|
|
17
|
+
constants_js_1.CHAIN_IDS.BASE,
|
|
18
|
+
constants_js_1.CHAIN_IDS.BASE_TESTNET,
|
|
19
|
+
constants_js_1.CHAIN_IDS.OPBNB,
|
|
20
|
+
constants_js_1.CHAIN_IDS.OPBNB_TESTNET,
|
|
21
|
+
constants_js_1.CHAIN_IDS.ZORA,
|
|
22
22
|
];
|
|
23
23
|
const GAS_SUPPORTED_NETWORKS_ENDPOINT = 'https://gas.api.cx.metamask.io/v1/supportedNetworks';
|
|
24
24
|
/**
|
|
25
25
|
* Optimism layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.
|
|
26
26
|
*/
|
|
27
|
-
class OptimismLayer1GasFeeFlow extends
|
|
27
|
+
class OptimismLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_js_1.OracleLayer1GasFeeFlow {
|
|
28
28
|
constructor() {
|
|
29
29
|
super(...arguments);
|
|
30
30
|
_OptimismLayer1GasFeeFlow_instances.add(this);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iEAAyD;AACzD,2CAA8C;AAG9C,
|
|
1
|
+
{"version":3,"file":"OptimismLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iEAAyD;AACzD,2CAA8C;AAG9C,mDAA4C;AAG5C,4EAAqE;AAErE,MAAM,iCAAiC,GAAU;IAC/C,wBAAS,CAAC,QAAQ;IAClB,wBAAS,CAAC,gBAAgB;IAC1B,wBAAS,CAAC,IAAI;IACd,wBAAS,CAAC,YAAY;IACtB,wBAAS,CAAC,KAAK;IACf,wBAAS,CAAC,aAAa;IACvB,wBAAS,CAAC,IAAI;CACf,CAAC;AAWF,MAAM,+BAA+B,GACnC,qDAAqD,CAAC;AAExD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,kDAAsB;IAApE;;;IAoCA,CAAC;IAnCC,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,MAAM,eAAe,GAAG,IAAA,mBAAW,EAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAE7D,MAAM,eAAe,GAAG,MAAM,uBAAA,IAAI,mGAA8B,MAAlC,IAAI,CAAgC,CAAC;QAEnE,IAAI,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,iCAAiC,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC7E,CAAC;CAoBF;AApCD,4DAoCC;;AAlBC,8CAA8C;AAE9C;;;;GAIG;AACH,KAAK;IACH,IAAI,CAAC;QACH,MAAM,GAAG,GAA8B,MAAM,IAAA,8BAAW,EACtD,+BAA+B,CAChC,CAAC;QACF,MAAM,IAAI,GAAG,GAAG,EAAE,cAAc,EAAE,QAAQ,IAAI,EAAE,CAAC;QACjD,OAAO,IAAI,GAAG,CAAS,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { TransactionMeta } from '../types.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst FALLBACK_OPTIMISM_STACK_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.OPTIMISM_TESTNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.BASE_TESTNET,\n CHAIN_IDS.OPBNB,\n CHAIN_IDS.OPBNB_TESTNET,\n CHAIN_IDS.ZORA,\n];\n\n// Default oracle address now provided by base class\n\ntype SupportedNetworksResponse = {\n readonly fullSupport: readonly number[];\n readonly partialSupport: {\n readonly optimism: readonly number[];\n };\n};\n\nconst GAS_SUPPORTED_NETWORKS_ENDPOINT =\n 'https://gas.api.cx.metamask.io/v1/supportedNetworks';\n\n/**\n * Optimism layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class OptimismLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n const chainIdAsNumber = hexToNumber(transactionMeta.chainId);\n\n const supportedChains = await this.#fetchOptimismSupportedChains();\n\n if (supportedChains?.has(chainIdAsNumber)) {\n return true;\n }\n\n return FALLBACK_OPTIMISM_STACK_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n // Uses default oracle address from base class\n\n /**\n * Fetch remote OP-stack support list; fall back to local list when unavailable.\n *\n * @returns A set of supported OP-stack chain IDs or null on failure.\n */\n async #fetchOptimismSupportedChains(): Promise<Set<number> | null> {\n try {\n const res: SupportedNetworksResponse = await handleFetch(\n GAS_SUPPORTED_NETWORKS_ENDPOINT,\n );\n const list = res?.partialSupport?.optimism ?? [];\n return new Set<number>(list);\n } catch {\n return null;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"OptimismLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAoB;AACnD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAwBrE;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,sBAAsB;;IAC5D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CA8BrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"OptimismLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAoB;AACnD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAwBrE;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,sBAAsB;;IAC5D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;CA8BrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AACzD,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"OptimismLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AACzD,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,SAAS,EAAE,yBAAwB;AAG5C,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAErE,MAAM,iCAAiC,GAAU;IAC/C,SAAS,CAAC,QAAQ;IAClB,SAAS,CAAC,gBAAgB;IAC1B,SAAS,CAAC,IAAI;IACd,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,KAAK;IACf,SAAS,CAAC,aAAa;IACvB,SAAS,CAAC,IAAI;CACf,CAAC;AAWF,MAAM,+BAA+B,GACnC,qDAAqD,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,sBAAsB;IAApE;;;IAoCA,CAAC;IAnCC,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAE7D,MAAM,eAAe,GAAG,MAAM,uBAAA,IAAI,mGAA8B,MAAlC,IAAI,CAAgC,CAAC;QAEnE,IAAI,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,iCAAiC,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC7E,CAAC;CAoBF;;AAlBC,8CAA8C;AAE9C;;;;GAIG;AACH,KAAK;IACH,IAAI,CAAC;QACH,MAAM,GAAG,GAA8B,MAAM,WAAW,CACtD,+BAA+B,CAChC,CAAC;QACF,MAAM,IAAI,GAAG,GAAG,EAAE,cAAc,EAAE,QAAQ,IAAI,EAAE,CAAC;QACjD,OAAO,IAAI,GAAG,CAAS,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { TransactionMeta } from '../types.js';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow.js';\n\nconst FALLBACK_OPTIMISM_STACK_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.OPTIMISM_TESTNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.BASE_TESTNET,\n CHAIN_IDS.OPBNB,\n CHAIN_IDS.OPBNB_TESTNET,\n CHAIN_IDS.ZORA,\n];\n\n// Default oracle address now provided by base class\n\ntype SupportedNetworksResponse = {\n readonly fullSupport: readonly number[];\n readonly partialSupport: {\n readonly optimism: readonly number[];\n };\n};\n\nconst GAS_SUPPORTED_NETWORKS_ENDPOINT =\n 'https://gas.api.cx.metamask.io/v1/supportedNetworks';\n\n/**\n * Optimism layer 1 gas fee flow that obtains gas fee estimate using an oracle contract.\n */\nexport class OptimismLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n const chainIdAsNumber = hexToNumber(transactionMeta.chainId);\n\n const supportedChains = await this.#fetchOptimismSupportedChains();\n\n if (supportedChains?.has(chainIdAsNumber)) {\n return true;\n }\n\n return FALLBACK_OPTIMISM_STACK_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n // Uses default oracle address from base class\n\n /**\n * Fetch remote OP-stack support list; fall back to local list when unavailable.\n *\n * @returns A set of supported OP-stack chain IDs or null on failure.\n */\n async #fetchOptimismSupportedChains(): Promise<Set<number> | null> {\n try {\n const res: SupportedNetworksResponse = await handleFetch(\n GAS_SUPPORTED_NETWORKS_ENDPOINT,\n );\n const list = res?.partialSupport?.optimism ?? [];\n return new Set<number>(list);\n } catch {\n return null;\n }\n }\n}\n"]}
|
|
@@ -13,11 +13,11 @@ exports.OracleLayer1GasFeeFlow = void 0;
|
|
|
13
13
|
const abi_1 = require("@ethersproject/abi");
|
|
14
14
|
const utils_1 = require("@metamask/utils");
|
|
15
15
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const log = (0, utils_1.createModuleLogger)(
|
|
16
|
+
const logger_js_1 = require("../logger.cjs");
|
|
17
|
+
const prepare_js_1 = require("../utils/prepare.cjs");
|
|
18
|
+
const provider_js_1 = require("../utils/provider.cjs");
|
|
19
|
+
const utils_js_1 = require("../utils/utils.cjs");
|
|
20
|
+
const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'oracle-layer1-gas-fee-flow');
|
|
21
21
|
const ZERO = new bn_js_1.default(0);
|
|
22
22
|
const DUMMY_KEY = 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';
|
|
23
23
|
const GAS_PRICE_ORACLE_ABI = [
|
|
@@ -114,7 +114,7 @@ class OracleLayer1GasFeeFlow {
|
|
|
114
114
|
const transformedFee = await this.transformOracleFee(oracleFee, request);
|
|
115
115
|
const operatorFee = await __classPrivateFieldGet(this, _OracleLayer1GasFeeFlow_instances, "m", _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee).call(this, request);
|
|
116
116
|
return {
|
|
117
|
-
layer1Fee: (0, utils_1.add0x)((0,
|
|
117
|
+
layer1Fee: (0, utils_1.add0x)((0, utils_js_1.padHexToEvenLength)(transformedFee.add(operatorFee).toString(16))),
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
catch (error) {
|
|
@@ -144,7 +144,7 @@ _OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOr
|
|
|
144
144
|
if (typeof result !== 'string' || result === '0x') {
|
|
145
145
|
throw new Error('No value returned from oracle contract');
|
|
146
146
|
}
|
|
147
|
-
return (0,
|
|
147
|
+
return (0, utils_js_1.toBN)(result);
|
|
148
148
|
}, _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee = async function _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee(request) {
|
|
149
149
|
const gas = this.getOperatorFeeGas(request.transactionMeta);
|
|
150
150
|
if (!gas) {
|
|
@@ -157,7 +157,7 @@ _OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOr
|
|
|
157
157
|
if (typeof result !== 'string' || result === '0x') {
|
|
158
158
|
return ZERO;
|
|
159
159
|
}
|
|
160
|
-
return (0,
|
|
160
|
+
return (0, utils_js_1.toBN)(result);
|
|
161
161
|
}
|
|
162
162
|
catch (error) {
|
|
163
163
|
log('Failed to get operator layer 1 gas fee', error);
|
|
@@ -166,7 +166,7 @@ _OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOr
|
|
|
166
166
|
}, _OracleLayer1GasFeeFlow_buildUnserializedTransaction = function _OracleLayer1GasFeeFlow_buildUnserializedTransaction(transactionMeta, sign) {
|
|
167
167
|
const txParams = __classPrivateFieldGet(this, _OracleLayer1GasFeeFlow_instances, "m", _OracleLayer1GasFeeFlow_buildTransactionParams).call(this, transactionMeta);
|
|
168
168
|
const { chainId } = transactionMeta;
|
|
169
|
-
let unserializedTransaction = (0,
|
|
169
|
+
let unserializedTransaction = (0, prepare_js_1.prepareTransaction)(chainId, txParams);
|
|
170
170
|
if (sign) {
|
|
171
171
|
// eslint-disable-next-line no-restricted-globals
|
|
172
172
|
const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');
|
|
@@ -191,7 +191,7 @@ async function _OracleLayer1GasFeeFlow_callGasPriceOracle(request, functionName,
|
|
|
191
191
|
const { chainId, networkClientId } = transactionMeta;
|
|
192
192
|
const to = this.getOracleAddressForChain(chainId);
|
|
193
193
|
const data = GAS_PRICE_ORACLE_INTERFACE.encodeFunctionData(functionName, args);
|
|
194
|
-
return await (0,
|
|
194
|
+
return await (0, provider_js_1.rpcRequest)({
|
|
195
195
|
messenger,
|
|
196
196
|
networkClientId,
|
|
197
197
|
method: 'eth_call',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/O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,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,iCAAiC;AACjC,+DAA+D;AAC/D,KAAK,qDACH,OAAgC,EAChC,YAAoB,EACpB,IAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC;IAErD,MAAM,EAAE,GAAG,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,0BAA0B,CAAC,kBAAkB,CACxD,YAAY,EACZ,IAAI,CACE,CAAC;IAET,OAAO,MAAM,IAAA,qBAAU,EAAC;QACtB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { rpcRequest } from '../utils/provider';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\nconst GAS_PRICE_ORACLE_INTERFACE = new Interface(GAS_PRICE_ORACLE_ABI);\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (messenger + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const oracleFee = await this.#getOracleLayer1GasFee(request);\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(request);\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(request: Layer1GasFeeFlowRequest): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n request.transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await this.#callGasPriceOracle(request, 'getL1Fee', [\n serializedTransaction,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(request.transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await this.#callGasPriceOracle(request, 'getOperatorFee', [\n gas,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n // The oracle is called via a direct `eth_call` RPC request rather than an\n // ethers `Contract` with `Web3Provider`, as `Web3Provider` schedules its\n // JSON-RPC dispatch with `setTimeout`, which never fires on React Native\n // when the timer pump is starved (e.g. iOS display link freeze), blocking\n // `addTransaction` indefinitely.\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n async #callGasPriceOracle(\n request: Layer1GasFeeFlowRequest,\n functionName: string,\n args: readonly unknown[],\n ): Promise<unknown> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = GAS_PRICE_ORACLE_INTERFACE.encodeFunctionData(\n functionName,\n args,\n ) as Hex;\n\n return await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA+C;AAE/C,2CAA4D;AAC5D,kDAAuB;AAEvB,6CAA6C;AAQ7C,qDAAyD;AACzD,uDAAkD;AAClD,iDAA6D;AAE7D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD,8BAA8B;IAC9B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF,2EAA2E;AAC3E,MAAM,gCAAgC,GACpC,4CAAmD,CAAC;AAEtD,MAAM,0BAA0B,GAAG,IAAI,eAAS,CAAC,oBAAoB,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAsB,sBAAsB;IAA5C;;IAuLA,CAAC;IAtLC;;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AC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,iCAAiC;AACjC,+DAA+D;AAC/D,KAAK,qDACH,OAAgC,EAChC,YAAoB,EACpB,IAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC;IAErD,MAAM,EAAE,GAAG,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,0BAA0B,CAAC,kBAAkB,CACxD,YAAY,EACZ,IAAI,CACE,CAAC;IAET,OAAO,MAAM,IAAA,wBAAU,EAAC;QACtB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { prepareTransaction } from '../utils/prepare.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { padHexToEvenLength, toBN } from '../utils/utils.js';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\nconst GAS_PRICE_ORACLE_INTERFACE = new Interface(GAS_PRICE_ORACLE_ABI);\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (messenger + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const oracleFee = await this.#getOracleLayer1GasFee(request);\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(request);\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(request: Layer1GasFeeFlowRequest): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n request.transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await this.#callGasPriceOracle(request, 'getL1Fee', [\n serializedTransaction,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(request.transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await this.#callGasPriceOracle(request, 'getOperatorFee', [\n gas,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n // The oracle is called via a direct `eth_call` RPC request rather than an\n // ethers `Contract` with `Web3Provider`, as `Web3Provider` schedules its\n // JSON-RPC dispatch with `setTimeout`, which never fires on React Native\n // when the timer pump is starved (e.g. iOS display link freeze), blocking\n // `addTransaction` indefinitely.\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n async #callGasPriceOracle(\n request: Layer1GasFeeFlowRequest,\n functionName: string,\n args: readonly unknown[],\n ): Promise<unknown> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = GAS_PRICE_ORACLE_INTERFACE.encodeFunctionData(\n functionName,\n args,\n ) as Hex;\n\n return await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EAChB,qBAAoB;AA4DrB;;GAEG;AACH,8BAAsB,sBAAuB,YAAW,gBAAgB;;IACtE;;;;;;;OAOG;IACH,SAAS,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;IAItD;;;;;;;;OAQG;IACH,SAAS,CAAC,qBAAqB,IAAI,OAAO;IAI1C,QAAQ,CAAC,kBAAkB,CAAC,EAC1B,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;IAEpB;;;;;;;;;;OAUG;cACa,kBAAkB,CAChC,SAAS,EAAE,EAAE,EACb,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,EAAE,CAAC;IAIR,YAAY,CAChB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAkCpC;;;;;;;;OAQG;IACH,SAAS,CAAC,iBAAiB,CACzB,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;CAoFtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EAChB,qBAAoB;AA4DrB;;GAEG;AACH,8BAAsB,sBAAuB,YAAW,gBAAgB;;IACtE;;;;;;;OAOG;IACH,SAAS,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;IAItD;;;;;;;;OAQG;IACH,SAAS,CAAC,qBAAqB,IAAI,OAAO;IAI1C,QAAQ,CAAC,kBAAkB,CAAC,EAC1B,eAAe,EACf,SAAS,GACV,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;IAEpB;;;;;;;;;;OAUG;cACa,kBAAkB,CAChC,SAAS,EAAE,EAAE,EACb,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,EAAE,CAAC;IAIR,YAAY,CAChB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAkCpC;;;;;;;;OAQG;IACH,SAAS,CAAC,iBAAiB,CACzB,eAAe,EAA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port { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { rpcRequest } from '../utils/provider';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\nconst GAS_PRICE_ORACLE_INTERFACE = new Interface(GAS_PRICE_ORACLE_ABI);\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (messenger + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const oracleFee = await this.#getOracleLayer1GasFee(request);\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(request);\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(request: Layer1GasFeeFlowRequest): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n request.transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await this.#callGasPriceOracle(request, 'getL1Fee', [\n serializedTransaction,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(request.transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await this.#callGasPriceOracle(request, 'getOperatorFee', [\n gas,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n // The oracle is called via a direct `eth_call` RPC request rather than an\n // ethers `Contract` with `Web3Provider`, as `Web3Provider` schedules its\n // JSON-RPC dispatch with `setTimeout`, which never fires on React Native\n // when the timer pump is starved (e.g. iOS display link freeze), blocking\n // `addTransaction` indefinitely.\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n async #callGasPriceOracle(\n request: Layer1GasFeeFlowRequest,\n functionName: string,\n args: readonly unknown[],\n ): Promise<unknown> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = GAS_PRICE_ORACLE_INTERFACE.encodeFunctionData(\n functionName,\n args,\n ) as Hex;\n\n return await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAE/C,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAC5D,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,aAAa,EAAE,sBAAqB;AAQ7C,OAAO,EAAE,kBAAkB,EAAE,6BAA4B;AACzD,OAAO,EAAE,UAAU,EAAE,8BAA6B;AAClD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,2BAA0B;AAE7D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD,8BAA8B;IAC9B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EA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QACT,eAAe;QACf,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types.js';\nimport { prepareTransaction } from '../utils/prepare.js';\nimport { rpcRequest } from '../utils/provider.js';\nimport { padHexToEvenLength, toBN } from '../utils/utils.js';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\nconst GAS_PRICE_ORACLE_INTERFACE = new Interface(GAS_PRICE_ORACLE_ABI);\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (messenger + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const oracleFee = await this.#getOracleLayer1GasFee(request);\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(request);\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(request: Layer1GasFeeFlowRequest): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n request.transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await this.#callGasPriceOracle(request, 'getL1Fee', [\n serializedTransaction,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(request.transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await this.#callGasPriceOracle(request, 'getOperatorFee', [\n gas,\n ]);\n\n if (typeof result !== 'string' || result === '0x') {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n // The oracle is called via a direct `eth_call` RPC request rather than an\n // ethers `Contract` with `Web3Provider`, as `Web3Provider` schedules its\n // JSON-RPC dispatch with `setTimeout`, which never fires on React Native\n // when the timer pump is starved (e.g. iOS display link freeze), blocking\n // `addTransaction` indefinitely.\n // See https://github.com/MetaMask/metamask-mobile/issues/32863\n async #callGasPriceOracle(\n request: Layer1GasFeeFlowRequest,\n functionName: string,\n args: readonly unknown[],\n ): Promise<unknown> {\n const { messenger, transactionMeta } = request;\n const { chainId, networkClientId } = transactionMeta;\n\n const to = this.getOracleAddressForChain(chainId);\n const data = GAS_PRICE_ORACLE_INTERFACE.encodeFunctionData(\n functionName,\n args,\n ) as Hex;\n\n return await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_call',\n params: [{ to, data }, 'latest'],\n });\n }\n}\n"]}
|
|
@@ -9,12 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.randomiseDecimalGWEIAndConvertToHex = exports.RandomisedEstimationsGasFeeFlow = void 0;
|
|
10
10
|
const gas_fee_controller_1 = require("@metamask/gas-fee-controller");
|
|
11
11
|
const utils_1 = require("@metamask/utils");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const log = (0, utils_1.createModuleLogger)(
|
|
12
|
+
const logger_js_1 = require("../logger.cjs");
|
|
13
|
+
const types_js_1 = require("../types.cjs");
|
|
14
|
+
const feature_flags_js_1 = require("../utils/feature-flags.cjs");
|
|
15
|
+
const gas_fees_js_1 = require("../utils/gas-fees.cjs");
|
|
16
|
+
const DefaultGasFeeFlow_js_1 = require("./DefaultGasFeeFlow.cjs");
|
|
17
|
+
const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'randomised-estimation-gas-fee-flow');
|
|
18
18
|
const DEFAULT_PRESERVE_NUMBER_OF_DIGITS = 2;
|
|
19
19
|
/**
|
|
20
20
|
* Implementation of a gas fee flow that randomises the last digits of gas fee estimations
|
|
@@ -25,7 +25,7 @@ class RandomisedEstimationsGasFeeFlow {
|
|
|
25
25
|
}
|
|
26
26
|
matchesTransaction({ transactionMeta, messenger, }) {
|
|
27
27
|
const { chainId } = transactionMeta;
|
|
28
|
-
const gasFeeRandomisation = (0,
|
|
28
|
+
const gasFeeRandomisation = (0, feature_flags_js_1.getGasFeeRandomisation)(messenger);
|
|
29
29
|
const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[chainId];
|
|
30
30
|
return randomisedGasFeeDigits !== undefined;
|
|
31
31
|
}
|
|
@@ -41,11 +41,11 @@ class RandomisedEstimationsGasFeeFlow {
|
|
|
41
41
|
}
|
|
42
42
|
exports.RandomisedEstimationsGasFeeFlow = RandomisedEstimationsGasFeeFlow;
|
|
43
43
|
_RandomisedEstimationsGasFeeFlow_instances = new WeakSet(), _RandomisedEstimationsGasFeeFlow_getDefaultGasFees = async function _RandomisedEstimationsGasFeeFlow_getDefaultGasFees(request) {
|
|
44
|
-
return new
|
|
44
|
+
return new DefaultGasFeeFlow_js_1.DefaultGasFeeFlow().getGasFees(request);
|
|
45
45
|
}, _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees = async function _RandomisedEstimationsGasFeeFlow_getRandomisedGasFees(request) {
|
|
46
46
|
const { messenger, gasFeeControllerData, transactionMeta } = request;
|
|
47
47
|
const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
|
|
48
|
-
const gasFeeRandomisation = (0,
|
|
48
|
+
const gasFeeRandomisation = (0, feature_flags_js_1.getGasFeeRandomisation)(messenger);
|
|
49
49
|
const randomisedGasFeeDigits = gasFeeRandomisation.randomisedGasFeeDigits[transactionMeta.chainId];
|
|
50
50
|
const preservedNumberOfDigits = gasFeeRandomisation.preservedNumberOfDigits ??
|
|
51
51
|
DEFAULT_PRESERVE_NUMBER_OF_DIGITS;
|
|
@@ -59,17 +59,17 @@ _RandomisedEstimationsGasFeeFlow_instances = new WeakSet(), _RandomisedEstimatio
|
|
|
59
59
|
}
|
|
60
60
|
return await __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getDefaultGasFees).call(this, request);
|
|
61
61
|
}, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketEstimates(gasFeeEstimates, lastNDigits, preservedNumberOfDigits) {
|
|
62
|
-
const levels = Object.values(
|
|
62
|
+
const levels = Object.values(types_js_1.GasFeeEstimateLevel).reduce((result, level) => ({
|
|
63
63
|
...result,
|
|
64
64
|
[level]: __classPrivateFieldGet(this, _RandomisedEstimationsGasFeeFlow_instances, "m", _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel).call(this, gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits),
|
|
65
65
|
}), {});
|
|
66
66
|
return {
|
|
67
|
-
type:
|
|
67
|
+
type: types_js_1.GasFeeEstimateType.FeeMarket,
|
|
68
68
|
...levels,
|
|
69
69
|
};
|
|
70
70
|
}, _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel = function _RandomisedEstimationsGasFeeFlow_getRandomisedFeeMarketLevel(gasFeeEstimates, level, lastNDigits, preservedNumberOfDigits) {
|
|
71
71
|
return {
|
|
72
|
-
maxFeePerGas: (0,
|
|
72
|
+
maxFeePerGas: (0, gas_fees_js_1.gweiDecimalToWeiHex)(gasFeeEstimates[level].suggestedMaxFeePerGas),
|
|
73
73
|
// Only priority fee is randomised
|
|
74
74
|
maxPriorityFeePerGas: randomiseDecimalGWEIAndConvertToHex(gasFeeEstimates[level].suggestedMaxPriorityFeePerGas, lastNDigits, preservedNumberOfDigits),
|
|
75
75
|
};
|
|
@@ -98,7 +98,7 @@ function generateRandomDigits(digitCount, minValue) {
|
|
|
98
98
|
* @returns The randomised value converted to Wei in hexadecimal format
|
|
99
99
|
*/
|
|
100
100
|
function randomiseDecimalGWEIAndConvertToHex(gweiDecimalValue, numberOfDigitsToRandomizeAtTheEnd, preservedNumberOfDigits) {
|
|
101
|
-
const weiDecimalValue = (0,
|
|
101
|
+
const weiDecimalValue = (0, gas_fees_js_1.gweiDecimalToWeiDecimal)(gweiDecimalValue);
|
|
102
102
|
const decimalLength = weiDecimalValue.length;
|
|
103
103
|
// Determine how many digits to randomise while preserving the PRESERVE_NUMBER_OF_DIGITS
|
|
104
104
|
const effectiveDigitsToRandomise = Math.min(numberOfDigitsToRandomizeAtTheEnd, decimalLength - preservedNumberOfDigits);
|