@metamask/bridge-status-controller 64.4.0 → 64.4.2

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 CHANGED
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [64.4.2]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/transaction-controller` from `^62.8.0` to `^62.9.1` ([#7602](https://github.com/MetaMask/core/pull/7602), [#7604](https://github.com/MetaMask/core/pull/7604))
15
+ - Bump `@metamask/network-controller` from `^27.2.0` to `^28.0.0` ([#7604](https://github.com/MetaMask/core/pull/7604))
16
+ - Bump `@metamask/accounts-controller` from `^35.0.0` to `^35.0.1` ([#7604](https://github.com/MetaMask/core/pull/7604))
17
+ - Bump `@metamask/bridge-controller` from `^64.4.0` to `^64.4.1` ([#7604](https://github.com/MetaMask/core/pull/7604))
18
+ - Bump `@metamask/gas-fee-controller` from `^26.0.0` to `^26.0.1` ([#7604](https://github.com/MetaMask/core/pull/7604))
19
+ - Bump `@metamask/polling-controller` from `^16.0.0` to `^16.0.1` ([#7604](https://github.com/MetaMask/core/pull/7604))
20
+
21
+ ## [64.4.1]
22
+
23
+ ### Fixed
24
+
25
+ - Use `BRIDGE_PREFERRED_GAS_ESTIMATE` from `@metamask/bridge-controller` for gas price estimates to align with validation ([#7582](https://github.com/MetaMask/core/pull/7582))
26
+
10
27
  ## [64.4.0]
11
28
 
12
29
  ### Added
@@ -853,7 +870,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
853
870
 
854
871
  - Initial release ([#5317](https://github.com/MetaMask/core/pull/5317))
855
872
 
856
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.0...HEAD
873
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.2...HEAD
874
+ [64.4.2]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.1...@metamask/bridge-status-controller@64.4.2
875
+ [64.4.1]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.0...@metamask/bridge-status-controller@64.4.1
857
876
  [64.4.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.3.0...@metamask/bridge-status-controller@64.4.0
858
877
  [64.3.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.2.0...@metamask/bridge-status-controller@64.3.0
859
878
  [64.2.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.1.0...@metamask/bridge-status-controller@64.2.0
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calcActualGasUsed = exports.calculateGasFees = exports.getTxGasEstimates = void 0;
4
+ const bridge_controller_1 = require("@metamask/bridge-controller");
4
5
  const controller_utils_1 = require("@metamask/controller-utils");
5
6
  const bignumber_js_1 = require("bignumber.js");
6
7
  const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
7
- const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};
8
+ const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};
8
9
  const baseAndPriorityFeePerGas = maxPriorityFeePerGas
9
10
  ? new bignumber_js_1.BigNumber(estimatedBaseFee, 10)
10
11
  .times(10 ** 9)
@@ -1 +1 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AACA,iEAAmD;AAWnD,+CAAyC;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,iBAAiB,EAAE,IAAI,IAAI,EAAE,CAAC;IAE7E,MAAM,w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rC,IAAI,CAAC,CACP,CAAC;IAEF,MAAM,iBAAiB,GAAG,iBAAiB;QACzC,EAAE,GAAG,CAAC,IAAI,wBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B","sourcesContent":["import type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n disable7702: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (!disable7702) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
1
+ {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAAA,mEAA4E;AAE5E,iEAAmD;AAWnD,+CAAyC;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAC1C,iBAAiB,EAAE,CAAC,iDAA6B,CAAC,IAAI,EAAE,CAAC;IAE3D,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,wBAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aACd,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;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IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B","sourcesContent":["import { BRIDGE_PREFERRED_GAS_ESTIMATE } from '@metamask/bridge-controller';\nimport type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } =\n txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n disable7702: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (!disable7702) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,oCAAoC;AAE7E,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAChC,qBAAiB;AAqBlB;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,gBACd,OAAO,gEAEF,OAAO,sBAAsB,SAAS,CAAC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file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,oCAAoC;AAE7E,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAChC,qBAAiB;AAqBlB;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,gBACd,OAAO,gEAEF,OAAO,sBAAsB,SAAS,CAAC,cAAc,sCACnC,MAAM,mBACzB,MAAM,WACd,GAAG,UACJ;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,gBAgC/D,CAAC;AAQF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
1
+ {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,oCAAoC;AAE7E,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAChC,qBAAiB;AAsBlB;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,gBACd,OAAO,gEAEF,OAAO,sBAAsB,SAAS,CAAC,cAAc,sCACnC,MAAM,mBACzB,MAAM,WACd,GAAG,UACJ;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,gBAgC/D,CAAC;AAQF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
@@ -1,7 +1,8 @@
1
+ import { BRIDGE_PREFERRED_GAS_ESTIMATE } from "@metamask/bridge-controller";
1
2
  import { toHex } from "@metamask/controller-utils";
2
3
  import { BigNumber } from "bignumber.js";
3
4
  const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
4
- const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};
5
+ const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};
5
6
  const baseAndPriorityFeePerGas = maxPriorityFeePerGas
6
7
  ? new BigNumber(estimatedBaseFee, 10)
7
8
  .times(10 ** 9)
@@ -1 +1 @@
1
- {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAWnD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C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,EAAE,IAAI,CACL,eAAe,CACb,iBAAiB,EAAE,OAAO,EAC1B,iBAAiB,EAAE,iBAAiB,CACrC,IAAI,CAAC,CACP,CAAC;IAEF,MAAM,iBAAiB,GAAG,iBAAiB;QACzC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["import type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n disable7702: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (!disable7702) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
1
+ {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,oCAAoC;AAE5E,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAWnD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAC1C,iBAAiB,EAAE,CAAC,6BAA6B,CAAC,IAAI,EAAE,CAAC;IAE3D,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,SAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,K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EAAE,CAAC,CAAC;SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["import { BRIDGE_PREFERRED_GAS_ESTIMATE } from '@metamask/bridge-controller';\nimport type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } =\n txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n disable7702: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (!disable7702) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/bridge-status-controller",
3
- "version": "64.4.0",
3
+ "version": "64.4.2",
4
4
  "description": "Manages bridge-related status fetching functionality for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -48,16 +48,16 @@
48
48
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
49
49
  },
50
50
  "dependencies": {
51
- "@metamask/accounts-controller": "^35.0.0",
51
+ "@metamask/accounts-controller": "^35.0.1",
52
52
  "@metamask/base-controller": "^9.0.0",
53
- "@metamask/bridge-controller": "^64.4.0",
53
+ "@metamask/bridge-controller": "^64.4.1",
54
54
  "@metamask/controller-utils": "^11.18.0",
55
- "@metamask/gas-fee-controller": "^26.0.0",
56
- "@metamask/network-controller": "^27.2.0",
57
- "@metamask/polling-controller": "^16.0.0",
55
+ "@metamask/gas-fee-controller": "^26.0.1",
56
+ "@metamask/network-controller": "^28.0.0",
57
+ "@metamask/polling-controller": "^16.0.1",
58
58
  "@metamask/snaps-controllers": "^17.2.0",
59
59
  "@metamask/superstruct": "^3.1.0",
60
- "@metamask/transaction-controller": "^62.8.0",
60
+ "@metamask/transaction-controller": "^62.9.1",
61
61
  "@metamask/utils": "^11.9.0",
62
62
  "bignumber.js": "^9.1.2",
63
63
  "uuid": "^8.3.2"