@metamask-previews/transaction-controller 35.1.1-preview-e8f9512d → 35.1.1-preview-4f1ca72a
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/dist/TransactionController.js +11 -12
- package/dist/TransactionController.mjs +10 -11
- package/dist/{chunk-5HYWLTVQ.js → chunk-2EU6346V.js} +3 -3
- package/dist/{chunk-LFFYCDHB.mjs → chunk-6SJYXSF3.mjs} +1 -1
- package/dist/{chunk-LFFYCDHB.mjs.map → chunk-6SJYXSF3.mjs.map} +1 -1
- package/dist/{chunk-YWLMT7XH.js → chunk-76FONEDA.js} +4 -4
- package/dist/{chunk-UHAFIPSL.js → chunk-ARZHJFVG.js} +6 -6
- package/dist/{chunk-PSZ34BI5.js → chunk-AYTU4HU5.js} +1 -1
- package/dist/{chunk-PSZ34BI5.js.map → chunk-AYTU4HU5.js.map} +1 -1
- package/dist/{chunk-BZV72SCF.js → chunk-C3WC4OJ3.js} +5 -5
- package/dist/{chunk-JIFPK37W.mjs → chunk-GNAL5HC2.mjs} +2 -2
- package/dist/{chunk-4OYPDGHO.js → chunk-GPS6RX64.js} +6 -6
- package/dist/{chunk-AWIJZAW3.mjs → chunk-H2KZOK3J.mjs} +3 -3
- package/dist/{chunk-NNHSNPT2.mjs → chunk-JXXTNVU4.mjs} +2 -2
- package/dist/{chunk-X4XSEYPL.mjs → chunk-LTPS73D7.mjs} +3 -3
- package/dist/{chunk-KTGMNUTQ.js → chunk-OZ6UB42C.js} +23 -2
- package/dist/chunk-OZ6UB42C.js.map +1 -0
- package/dist/{chunk-UHSRHP55.mjs → chunk-Q56I5ONX.mjs} +22 -1
- package/dist/chunk-Q56I5ONX.mjs.map +1 -0
- package/dist/{chunk-QKV7E5BO.js → chunk-QH2H4W3N.js} +5 -5
- package/dist/{chunk-EHWAY6XU.js → chunk-QTKXIDGE.js} +9 -9
- package/dist/{chunk-VKWOHNDO.js → chunk-S3RZBMF7.js} +284 -214
- package/dist/chunk-S3RZBMF7.js.map +1 -0
- package/dist/{chunk-VGFPVAKX.mjs → chunk-SFFTNB2X.mjs} +2 -2
- package/dist/{chunk-XTMJ25EF.mjs → chunk-T3GOPPVF.mjs} +265 -195
- package/dist/chunk-T3GOPPVF.mjs.map +1 -0
- package/dist/{chunk-KYRW4BLA.mjs → chunk-UHG2LLVV.mjs} +3 -3
- package/dist/{chunk-SFFOC25Q.mjs → chunk-VXNPVIYL.mjs} +3 -3
- package/dist/errors.js +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.js +7 -7
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +6 -6
- package/dist/gas-flows/LineaGasFeeFlow.js +8 -8
- package/dist/gas-flows/LineaGasFeeFlow.mjs +7 -7
- package/dist/gas-flows/TestGasFeeFlow.js +1 -1
- package/dist/gas-flows/TestGasFeeFlow.mjs +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
- package/dist/helpers/GasFeePoller.js +4 -4
- package/dist/helpers/GasFeePoller.mjs +3 -3
- package/dist/helpers/MultichainTrackingHelper.js +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
- package/dist/helpers/PendingTransactionTracker.js +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +1 -1
- package/dist/index.js +11 -12
- package/dist/index.mjs +10 -11
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts +10 -8
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +0 -40
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/utils.d.ts +15 -1
- package/dist/types/utils/utils.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.mjs +1 -1
- package/dist/utils/external-transactions.js +1 -1
- package/dist/utils/external-transactions.mjs +1 -1
- package/dist/utils/gas-fees.js +6 -6
- package/dist/utils/gas-fees.mjs +5 -5
- package/dist/utils/gas-flow.js +3 -3
- package/dist/utils/gas-flow.mjs +2 -2
- package/dist/utils/simulation-api.js +1 -1
- package/dist/utils/simulation-api.mjs +1 -1
- package/dist/utils/simulation.js +1 -1
- package/dist/utils/simulation.mjs +1 -1
- package/dist/utils/swaps.js +4 -4
- package/dist/utils/swaps.mjs +3 -3
- package/dist/utils/transaction-type.js +1 -1
- package/dist/utils/transaction-type.mjs +1 -1
- package/dist/utils/utils.js +13 -3
- package/dist/utils/utils.mjs +14 -4
- package/dist/utils/validation.js +4 -4
- package/dist/utils/validation.mjs +3 -3
- package/package.json +2 -2
- package/dist/chunk-5QVDIVJH.js +0 -68
- package/dist/chunk-5QVDIVJH.js.map +0 -1
- package/dist/chunk-JOQK7A5G.mjs +0 -68
- package/dist/chunk-JOQK7A5G.mjs.map +0 -1
- package/dist/chunk-KTGMNUTQ.js.map +0 -1
- package/dist/chunk-UHSRHP55.mjs.map +0 -1
- package/dist/chunk-VKWOHNDO.js.map +0 -1
- package/dist/chunk-XTMJ25EF.mjs.map +0 -1
- package/dist/types/utils/retry.d.ts +0 -11
- package/dist/types/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js +0 -8
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/retry.mjs +0 -8
- package/dist/utils/retry.mjs.map +0 -1
- /package/dist/{chunk-5HYWLTVQ.js.map → chunk-2EU6346V.js.map} +0 -0
- /package/dist/{chunk-YWLMT7XH.js.map → chunk-76FONEDA.js.map} +0 -0
- /package/dist/{chunk-UHAFIPSL.js.map → chunk-ARZHJFVG.js.map} +0 -0
- /package/dist/{chunk-BZV72SCF.js.map → chunk-C3WC4OJ3.js.map} +0 -0
- /package/dist/{chunk-JIFPK37W.mjs.map → chunk-GNAL5HC2.mjs.map} +0 -0
- /package/dist/{chunk-4OYPDGHO.js.map → chunk-GPS6RX64.js.map} +0 -0
- /package/dist/{chunk-AWIJZAW3.mjs.map → chunk-H2KZOK3J.mjs.map} +0 -0
- /package/dist/{chunk-NNHSNPT2.mjs.map → chunk-JXXTNVU4.mjs.map} +0 -0
- /package/dist/{chunk-X4XSEYPL.mjs.map → chunk-LTPS73D7.mjs.map} +0 -0
- /package/dist/{chunk-QKV7E5BO.js.map → chunk-QH2H4W3N.js.map} +0 -0
- /package/dist/{chunk-EHWAY6XU.js.map → chunk-QTKXIDGE.js.map} +0 -0
- /package/dist/{chunk-VGFPVAKX.mjs.map → chunk-SFFTNB2X.mjs.map} +0 -0
- /package/dist/{chunk-KYRW4BLA.mjs.map → chunk-UHG2LLVV.mjs.map} +0 -0
- /package/dist/{chunk-SFFOC25Q.mjs.map → chunk-VXNPVIYL.mjs.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateTransactionOrigin,
|
|
3
3
|
validateTxParams
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-LTPS73D7.mjs";
|
|
5
|
+
import "../chunk-Q56I5ONX.mjs";
|
|
6
|
+
import "../chunk-6SJYXSF3.mjs";
|
|
7
7
|
import "../chunk-XUI43LEZ.mjs";
|
|
8
8
|
export {
|
|
9
9
|
validateTransactionOrigin,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/transaction-controller",
|
|
3
|
-
"version": "35.1.1-preview-
|
|
3
|
+
"version": "35.1.1-preview-4f1ca72a",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@metamask/ethjs-provider-http": "^0.3.0",
|
|
71
71
|
"@metamask/gas-fee-controller": "^19.0.1",
|
|
72
72
|
"@metamask/keyring-api": "^8.1.0",
|
|
73
|
-
"@metamask/network-controller": "^20.
|
|
73
|
+
"@metamask/network-controller": "^20.1.0",
|
|
74
74
|
"@types/bn.js": "^5.1.5",
|
|
75
75
|
"@types/jest": "^27.4.1",
|
|
76
76
|
"@types/node": "^16.18.54",
|
package/dist/chunk-5QVDIVJH.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/retry.ts
|
|
2
|
-
var _controllerutils = require('@metamask/controller-utils');
|
|
3
|
-
var _utils = require('@metamask/utils');
|
|
4
|
-
function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate, newGasValues) {
|
|
5
|
-
const newGasPrice = getIncreasedGasPrice(
|
|
6
|
-
originalTransactionParams,
|
|
7
|
-
rate,
|
|
8
|
-
newGasValues
|
|
9
|
-
);
|
|
10
|
-
const new1559Values = getIncreased1559Values(
|
|
11
|
-
originalTransactionParams,
|
|
12
|
-
rate,
|
|
13
|
-
newGasValues
|
|
14
|
-
);
|
|
15
|
-
if (new1559Values) {
|
|
16
|
-
const newTxParams = {
|
|
17
|
-
...originalTransactionParams,
|
|
18
|
-
...new1559Values
|
|
19
|
-
};
|
|
20
|
-
delete newTxParams.gasPrice;
|
|
21
|
-
return newTxParams;
|
|
22
|
-
}
|
|
23
|
-
if (newGasPrice) {
|
|
24
|
-
const newTxParams = {
|
|
25
|
-
...originalTransactionParams,
|
|
26
|
-
gasPrice: newGasPrice
|
|
27
|
-
};
|
|
28
|
-
delete newTxParams.maxFeePerGas;
|
|
29
|
-
delete newTxParams.maxPriorityFeePerGas;
|
|
30
|
-
return newTxParams;
|
|
31
|
-
}
|
|
32
|
-
throw new Error(
|
|
33
|
-
"Cannot increase gas fee as no current values and no new values were provided"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
|
|
37
|
-
if (newGasValues && "maxFeePerGas" in newGasValues && "maxPriorityFeePerGas" in newGasValues) {
|
|
38
|
-
return newGasValues;
|
|
39
|
-
}
|
|
40
|
-
const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas;
|
|
41
|
-
const currentMaxPriorityFeePerGas = originalTransactionParams.maxPriorityFeePerGas;
|
|
42
|
-
if (!currentMaxFeePerGas || !currentMaxPriorityFeePerGas || currentMaxFeePerGas === "0x0" || currentMaxPriorityFeePerGas === "0x0") {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);
|
|
46
|
-
const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);
|
|
47
|
-
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
48
|
-
}
|
|
49
|
-
function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
|
|
50
|
-
if (newGasValues && "gasPrice" in newGasValues) {
|
|
51
|
-
return newGasValues.gasPrice;
|
|
52
|
-
}
|
|
53
|
-
const currentGasPrice = originalTransactionParams.gasPrice;
|
|
54
|
-
if (!currentGasPrice || currentGasPrice === "0x0") {
|
|
55
|
-
return void 0;
|
|
56
|
-
}
|
|
57
|
-
return multiplyHex(currentGasPrice, rate);
|
|
58
|
-
}
|
|
59
|
-
function multiplyHex(value, multiplier) {
|
|
60
|
-
const decimalValue = _controllerutils.convertHexToDecimal.call(void 0, value);
|
|
61
|
-
const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);
|
|
62
|
-
return _utils.add0x.call(void 0, decimalResult.toString(16));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
exports.getTransactionParamsWithIncreasedGasFee = getTransactionParamsWithIncreasedGasFee;
|
|
68
|
-
//# sourceMappingURL=chunk-5QVDIVJH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/retry.ts"],"names":[],"mappings":";AAAA,SAAS,2BAA2B;AAEpC,SAAS,aAAa;AAYf,SAAS,wCACd,2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ent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"]}
|
package/dist/chunk-JOQK7A5G.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// src/utils/retry.ts
|
|
2
|
-
import { convertHexToDecimal } from "@metamask/controller-utils";
|
|
3
|
-
import { add0x } from "@metamask/utils";
|
|
4
|
-
function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate, newGasValues) {
|
|
5
|
-
const newGasPrice = getIncreasedGasPrice(
|
|
6
|
-
originalTransactionParams,
|
|
7
|
-
rate,
|
|
8
|
-
newGasValues
|
|
9
|
-
);
|
|
10
|
-
const new1559Values = getIncreased1559Values(
|
|
11
|
-
originalTransactionParams,
|
|
12
|
-
rate,
|
|
13
|
-
newGasValues
|
|
14
|
-
);
|
|
15
|
-
if (new1559Values) {
|
|
16
|
-
const newTxParams = {
|
|
17
|
-
...originalTransactionParams,
|
|
18
|
-
...new1559Values
|
|
19
|
-
};
|
|
20
|
-
delete newTxParams.gasPrice;
|
|
21
|
-
return newTxParams;
|
|
22
|
-
}
|
|
23
|
-
if (newGasPrice) {
|
|
24
|
-
const newTxParams = {
|
|
25
|
-
...originalTransactionParams,
|
|
26
|
-
gasPrice: newGasPrice
|
|
27
|
-
};
|
|
28
|
-
delete newTxParams.maxFeePerGas;
|
|
29
|
-
delete newTxParams.maxPriorityFeePerGas;
|
|
30
|
-
return newTxParams;
|
|
31
|
-
}
|
|
32
|
-
throw new Error(
|
|
33
|
-
"Cannot increase gas fee as no current values and no new values were provided"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
|
|
37
|
-
if (newGasValues && "maxFeePerGas" in newGasValues && "maxPriorityFeePerGas" in newGasValues) {
|
|
38
|
-
return newGasValues;
|
|
39
|
-
}
|
|
40
|
-
const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas;
|
|
41
|
-
const currentMaxPriorityFeePerGas = originalTransactionParams.maxPriorityFeePerGas;
|
|
42
|
-
if (!currentMaxFeePerGas || !currentMaxPriorityFeePerGas || currentMaxFeePerGas === "0x0" || currentMaxPriorityFeePerGas === "0x0") {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);
|
|
46
|
-
const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);
|
|
47
|
-
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
48
|
-
}
|
|
49
|
-
function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
|
|
50
|
-
if (newGasValues && "gasPrice" in newGasValues) {
|
|
51
|
-
return newGasValues.gasPrice;
|
|
52
|
-
}
|
|
53
|
-
const currentGasPrice = originalTransactionParams.gasPrice;
|
|
54
|
-
if (!currentGasPrice || currentGasPrice === "0x0") {
|
|
55
|
-
return void 0;
|
|
56
|
-
}
|
|
57
|
-
return multiplyHex(currentGasPrice, rate);
|
|
58
|
-
}
|
|
59
|
-
function multiplyHex(value, multiplier) {
|
|
60
|
-
const decimalValue = convertHexToDecimal(value);
|
|
61
|
-
const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);
|
|
62
|
-
return add0x(decimalResult.toString(16));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export {
|
|
66
|
-
getTransactionParamsWithIncreasedGasFee
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=chunk-JOQK7A5G.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/retry.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AAEpC,SAAS,aAAa;AAYf,SAAS,wCACd,2BACA,MACA,cACmB;AACnB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAEA,WAAO,YAAY;AACnB,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AASA,SAAS,uBACP,2BACA,MACA,cACoC;AACpC,MACE,gBACA,kBAAkB,gBAClB,0BAA0B,cAC1B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,sBAAsB,0BAA0B;AAItD,QAAM,8BACJ,0BAA0B;AAE5B,MACE,CAAC,uBACD,CAAC,+BACD,wBAAwB,SACxB,gCAAgC,OAChC;AACA,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,YAAY,qBAAqB,IAAI;AAC1D,Q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E7C,MAAI,cAAc,cAAc;AAC9B,WAAO;AAAA,MACL,UAAU,UAAU,aAAa,QAAQ;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AAAA,IACL,cAAc,UAAU,aAAa,YAAY;AAAA,IACjD,sBAAsB,UAAU,aAAa,oBAAoB;AAAA,EACnE;AACF;AAQA,SAAS,iBAAiB,OAA+B;AACvD,MAAI;AACF,SAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASO,SAAS,mBAAmB,KAAa;AAC9C,QAAM,SAAS,IAAI,YAAY,EAAE,WAAW,IAAI,IAAI,IAAI,MAAM,GAAG,CAAC,IAAI;AACtE,QAAM,OAAO,SAAS,IAAI,MAAM,CAAC,IAAI;AACrC,QAAM,WAAW,KAAK,SAAS,MAAM,IAAI,OAAO,IAAI,IAAI;AAExD,SAAO,SAAS;AAClB","sourcesContent":["import {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\n\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error.code,\n rpc: isJsonCompatible(error.value) ? error.value : undefined,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Determines whether the given value can be encoded as JSON.\n *\n * @param value - The value.\n * @returns True if the value is JSON-encodable, false if not.\n */\nfunction isJsonCompatible(value: unknown): value is Json {\n try {\n JSON.parse(JSON.stringify(value));\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/utils.ts"],"sourcesContent":["import {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\n\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error.code,\n rpc: isJsonCompatible(error.value) ? error.value : undefined,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Determines whether the given value can be encoded as JSON.\n *\n * @param value - The value.\n * @returns True if the value is JSON-encodable, false if not.\n */\nfunction isJsonCompatible(value: unknown): value is Json {\n try {\n JSON.parse(JSON.stringify(value));\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYA,IAAM,qBAAqB;AAIlC,IAAM,cAA2D;AAAA,EAC/D,MAAM,CAAC,SAAiB,MAAM,mBAAmB,IAAI,CAAC;AAAA,EACtD,MAAM,CAAC,SAAiB,MAAM,IAAI,EAAE,YAAY;AAAA,EAChD,KAAK,CAAC,QAAgB,MAAM,GAAG;AAAA,EAC/B,UAAU,CAAC,QAAgB,MAAM,GAAG;AAAA,EACpC,UAAU,CAAC,aAAqB,MAAM,QAAQ;AAAA,EAC9C,OAAO,CAAC,UAAkB,MAAM,KAAK;AAAA,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