@metamask/bridge-status-controller 64.4.0 → 64.4.1
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 +8 -1
- package/dist/utils/gas.cjs +2 -1
- 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 +2 -1
- package/dist/utils/gas.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [64.4.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- 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))
|
|
15
|
+
|
|
10
16
|
## [64.4.0]
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -853,7 +859,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
853
859
|
|
|
854
860
|
- Initial release ([#5317](https://github.com/MetaMask/core/pull/5317))
|
|
855
861
|
|
|
856
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.
|
|
862
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.1...HEAD
|
|
863
|
+
[64.4.1]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.4.0...@metamask/bridge-status-controller@64.4.1
|
|
857
864
|
[64.4.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.3.0...@metamask/bridge-status-controller@64.4.0
|
|
858
865
|
[64.3.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.2.0...@metamask/bridge-status-controller@64.3.0
|
|
859
866
|
[64.2.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@64.1.0...@metamask/bridge-status-controller@64.2.0
|
package/dist/utils/gas.cjs
CHANGED
|
@@ -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?.
|
|
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)
|
package/dist/utils/gas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;
|
|
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,I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AAiB,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 { 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/dist/utils/gas.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gas.d.cts","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"}
|
package/dist/utils/gas.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/utils/gas.mjs
CHANGED
|
@@ -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?.
|
|
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)
|
package/dist/utils/gas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"
|
|
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,SAA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AM,iBAAiB,GAAG,eAAe,CACvC,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,iBAAiB,CAC7B,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 { 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"]}
|