@metamask-previews/transaction-controller 63.1.0-preview-a0caca0c0 → 63.2.0-preview-17c76be24
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 +6 -4
- package/dist/TransactionController-method-action-types.cjs +1 -1
- package/dist/TransactionController-method-action-types.cjs.map +1 -1
- package/dist/TransactionController-method-action-types.d.cts +1 -1
- package/dist/TransactionController-method-action-types.d.mts +1 -1
- package/dist/TransactionController-method-action-types.mjs +1 -1
- package/dist/TransactionController-method-action-types.mjs.map +1 -1
- package/dist/TransactionController.cjs +101 -73
- 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 +106 -74
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +11 -22
- 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 +12 -23
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -2
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +19 -5
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +6 -1
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +6 -1
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +26 -5
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs +11 -2
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +11 -2
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/dist/helpers/MethodDataHelper.cjs +6 -10
- package/dist/helpers/MethodDataHelper.cjs.map +1 -1
- package/dist/helpers/MethodDataHelper.d.cts +4 -4
- package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
- package/dist/helpers/MethodDataHelper.d.mts +4 -4
- package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
- package/dist/helpers/MethodDataHelper.mjs +6 -10
- package/dist/helpers/MethodDataHelper.mjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.cjs +2 -0
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.cts +2 -0
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.mts +2 -0
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +2 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +24 -38
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts +7 -3
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts +7 -3
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +24 -38
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.cjs +6 -4
- package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.cts +4 -2
- package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.mts +4 -2
- package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.mjs +6 -4
- package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/balance-changes.cjs +2 -2
- package/dist/utils/balance-changes.cjs.map +1 -1
- package/dist/utils/balance-changes.d.cts +2 -4
- package/dist/utils/balance-changes.d.cts.map +1 -1
- package/dist/utils/balance-changes.d.mts +2 -4
- package/dist/utils/balance-changes.d.mts.map +1 -1
- package/dist/utils/balance-changes.mjs +2 -2
- package/dist/utils/balance-changes.mjs.map +1 -1
- package/dist/utils/balance.cjs +10 -14
- package/dist/utils/balance.cjs.map +1 -1
- package/dist/utils/balance.d.cts +5 -8
- package/dist/utils/balance.d.cts.map +1 -1
- package/dist/utils/balance.d.mts +5 -8
- package/dist/utils/balance.d.mts.map +1 -1
- package/dist/utils/balance.mjs +10 -14
- package/dist/utils/balance.mjs.map +1 -1
- package/dist/utils/batch.cjs +16 -15
- package/dist/utils/batch.cjs.map +1 -1
- package/dist/utils/batch.d.cts +5 -1
- package/dist/utils/batch.d.cts.map +1 -1
- package/dist/utils/batch.d.mts +5 -1
- package/dist/utils/batch.d.mts.map +1 -1
- package/dist/utils/batch.mjs +17 -16
- package/dist/utils/batch.mjs.map +1 -1
- package/dist/utils/eip7702.cjs +6 -13
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts +5 -6
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts +5 -6
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs +7 -14
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/gas-fee-tokens.cjs +3 -4
- package/dist/utils/gas-fee-tokens.cjs.map +1 -1
- package/dist/utils/gas-fee-tokens.d.cts +4 -6
- package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
- package/dist/utils/gas-fee-tokens.d.mts +4 -6
- package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
- package/dist/utils/gas-fee-tokens.mjs +3 -4
- package/dist/utils/gas-fee-tokens.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +6 -8
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts +2 -0
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts +2 -0
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +7 -9
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas.cjs +34 -60
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +11 -6
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +11 -6
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +35 -61
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +3 -7
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts +5 -2
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts +5 -2
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.mjs +3 -7
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/swaps.cjs +7 -11
- package/dist/utils/swaps.cjs.map +1 -1
- package/dist/utils/swaps.d.cts +4 -6
- package/dist/utils/swaps.d.cts.map +1 -1
- package/dist/utils/swaps.d.mts +4 -6
- package/dist/utils/swaps.d.mts.map +1 -1
- package/dist/utils/swaps.mjs +7 -11
- package/dist/utils/swaps.mjs.map +1 -1
- package/dist/utils/transaction-type.cjs +8 -17
- package/dist/utils/transaction-type.cjs.map +1 -1
- package/dist/utils/transaction-type.d.cts +3 -9
- package/dist/utils/transaction-type.d.cts.map +1 -1
- package/dist/utils/transaction-type.d.mts +3 -9
- package/dist/utils/transaction-type.d.mts.map +1 -1
- package/dist/utils/transaction-type.mjs +8 -17
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/utils/provider.cjs +0 -74
- package/dist/utils/provider.cjs.map +0 -1
- package/dist/utils/provider.d.cts +0 -65
- package/dist/utils/provider.d.cts.map +0 -1
- package/dist/utils/provider.d.mts +0 -65
- package/dist/utils/provider.d.mts.map +0 -1
- package/dist/utils/provider.mjs +0 -67
- package/dist/utils/provider.mjs.map +0 -1
|
@@ -12,7 +12,6 @@ const utils_1 = require("@metamask/utils");
|
|
|
12
12
|
const DefaultGasFeeFlow_1 = require("./DefaultGasFeeFlow.cjs");
|
|
13
13
|
const logger_1 = require("../logger.cjs");
|
|
14
14
|
const types_1 = require("../types.cjs");
|
|
15
|
-
const provider_1 = require("../utils/provider.cjs");
|
|
16
15
|
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'linea-gas-fee-flow');
|
|
17
16
|
const LINEA_CHAIN_IDS = [
|
|
18
17
|
controller_utils_1.ChainId['linea-mainnet'],
|
|
@@ -53,9 +52,8 @@ class LineaGasFeeFlow {
|
|
|
53
52
|
}
|
|
54
53
|
exports.LineaGasFeeFlow = LineaGasFeeFlow;
|
|
55
54
|
_LineaGasFeeFlow_instances = new WeakSet(), _LineaGasFeeFlow_getLineaGasFees = async function _LineaGasFeeFlow_getLineaGasFees(request) {
|
|
56
|
-
const {
|
|
57
|
-
const
|
|
58
|
-
const lineaResponse = await __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getLineaResponse).call(this, transactionMeta, messenger, networkClientId);
|
|
55
|
+
const { ethQuery, transactionMeta } = request;
|
|
56
|
+
const lineaResponse = await __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getLineaResponse).call(this, transactionMeta, ethQuery);
|
|
59
57
|
log('Received Linea response', lineaResponse);
|
|
60
58
|
const baseFees = __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getValuesFromMultipliers).call(this, lineaResponse.baseFeePerGas, BASE_FEE_MULTIPLIERS);
|
|
61
59
|
log('Generated base fees', __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_feesToString).call(this, baseFees));
|
|
@@ -71,24 +69,15 @@ _LineaGasFeeFlow_instances = new WeakSet(), _LineaGasFeeFlow_getLineaGasFees = a
|
|
|
71
69
|
},
|
|
72
70
|
}), { type: types_1.GasFeeEstimateType.FeeMarket });
|
|
73
71
|
return { estimates };
|
|
74
|
-
}, _LineaGasFeeFlow_getLineaResponse = function _LineaGasFeeFlow_getLineaResponse(transactionMeta,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (data) {
|
|
84
|
-
params.input = data;
|
|
85
|
-
}
|
|
86
|
-
return (0, provider_1.rpcRequest)({
|
|
87
|
-
messenger,
|
|
88
|
-
networkClientId,
|
|
89
|
-
method: 'linea_estimateGas',
|
|
90
|
-
params: [params],
|
|
91
|
-
});
|
|
72
|
+
}, _LineaGasFeeFlow_getLineaResponse = function _LineaGasFeeFlow_getLineaResponse(transactionMeta, ethQuery) {
|
|
73
|
+
return (0, controller_utils_1.query)(ethQuery, 'linea_estimateGas', [
|
|
74
|
+
{
|
|
75
|
+
from: transactionMeta.txParams.from,
|
|
76
|
+
to: transactionMeta.txParams.to,
|
|
77
|
+
value: transactionMeta.txParams.value,
|
|
78
|
+
input: transactionMeta.txParams.data,
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
92
81
|
}, _LineaGasFeeFlow_getValuesFromMultipliers = function _LineaGasFeeFlow_getValuesFromMultipliers(value, multipliers) {
|
|
93
82
|
const base = (0, controller_utils_1.hexToBN)(value);
|
|
94
83
|
const low = base.muln(multipliers.low);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iEAA4E;AAE5E,2CAAqD;AAIrD,+DAAwD;AACxD,0CAA0C;AAS1C,wCAAmE;AAWnE,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,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;IACZ,IAAI,EAAE,GAAG;CACV,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,GAAG;CAC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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,2BAAmB,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, query, toHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\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 { ethQuery, transactionMeta } = request;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n ethQuery,\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 ethQuery: EthQuery,\n ): Promise<LineaEstimateGasResponse> {\n return query(ethQuery, 'linea_estimateGas', [\n {\n from: transactionMeta.txParams.from,\n to: transactionMeta.txParams.to,\n value: transactionMeta.txParams.value,\n input: transactionMeta.txParams.data,\n },\n ]);\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":"AAQA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAgClB;;;;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;CAmG1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineaGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,qBAAiB;AAgClB;;;;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;CAmG1E"}
|
|
@@ -4,12 +4,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _LineaGasFeeFlow_instances, _LineaGasFeeFlow_getLineaGasFees, _LineaGasFeeFlow_getLineaResponse, _LineaGasFeeFlow_getValuesFromMultipliers, _LineaGasFeeFlow_getMaxFees, _LineaGasFeeFlow_feesToString;
|
|
7
|
-
import { ChainId, hexToBN, toHex } from "@metamask/controller-utils";
|
|
7
|
+
import { ChainId, hexToBN, query, toHex } from "@metamask/controller-utils";
|
|
8
8
|
import { createModuleLogger } from "@metamask/utils";
|
|
9
9
|
import { DefaultGasFeeFlow } from "./DefaultGasFeeFlow.mjs";
|
|
10
10
|
import { projectLogger } from "../logger.mjs";
|
|
11
11
|
import { GasFeeEstimateLevel, GasFeeEstimateType } from "../types.mjs";
|
|
12
|
-
import { rpcRequest } from "../utils/provider.mjs";
|
|
13
12
|
const log = createModuleLogger(projectLogger, 'linea-gas-fee-flow');
|
|
14
13
|
const LINEA_CHAIN_IDS = [
|
|
15
14
|
ChainId['linea-mainnet'],
|
|
@@ -49,9 +48,8 @@ export class LineaGasFeeFlow {
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
_LineaGasFeeFlow_instances = new WeakSet(), _LineaGasFeeFlow_getLineaGasFees = async function _LineaGasFeeFlow_getLineaGasFees(request) {
|
|
52
|
-
const {
|
|
53
|
-
const
|
|
54
|
-
const lineaResponse = await __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getLineaResponse).call(this, transactionMeta, messenger, networkClientId);
|
|
51
|
+
const { ethQuery, transactionMeta } = request;
|
|
52
|
+
const lineaResponse = await __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getLineaResponse).call(this, transactionMeta, ethQuery);
|
|
55
53
|
log('Received Linea response', lineaResponse);
|
|
56
54
|
const baseFees = __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_getValuesFromMultipliers).call(this, lineaResponse.baseFeePerGas, BASE_FEE_MULTIPLIERS);
|
|
57
55
|
log('Generated base fees', __classPrivateFieldGet(this, _LineaGasFeeFlow_instances, "m", _LineaGasFeeFlow_feesToString).call(this, baseFees));
|
|
@@ -67,24 +65,15 @@ _LineaGasFeeFlow_instances = new WeakSet(), _LineaGasFeeFlow_getLineaGasFees = a
|
|
|
67
65
|
},
|
|
68
66
|
}), { type: GasFeeEstimateType.FeeMarket });
|
|
69
67
|
return { estimates };
|
|
70
|
-
}, _LineaGasFeeFlow_getLineaResponse = function _LineaGasFeeFlow_getLineaResponse(transactionMeta,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (data) {
|
|
80
|
-
params.input = data;
|
|
81
|
-
}
|
|
82
|
-
return rpcRequest({
|
|
83
|
-
messenger,
|
|
84
|
-
networkClientId,
|
|
85
|
-
method: 'linea_estimateGas',
|
|
86
|
-
params: [params],
|
|
87
|
-
});
|
|
68
|
+
}, _LineaGasFeeFlow_getLineaResponse = function _LineaGasFeeFlow_getLineaResponse(transactionMeta, ethQuery) {
|
|
69
|
+
return query(ethQuery, 'linea_estimateGas', [
|
|
70
|
+
{
|
|
71
|
+
from: transactionMeta.txParams.from,
|
|
72
|
+
to: transactionMeta.txParams.to,
|
|
73
|
+
value: transactionMeta.txParams.value,
|
|
74
|
+
input: transactionMeta.txParams.data,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
88
77
|
}, _LineaGasFeeFlow_getValuesFromMultipliers = function _LineaGasFeeFlow_getValuesFromMultipliers(value, multipliers) {
|
|
89
78
|
const base = hexToBN(value);
|
|
90
79
|
const low = base.muln(multipliers.low);
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"LineaGasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/LineaGasFeeFlow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,mCAAmC;AAE5E,OAA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ACE,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI;YACnC,EAAE,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE;YAC/B,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,KAAK;YACrC,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI;SACrC;KACF,CAAC,CAAC;AACL,CAAC,iGAGC,KAAU,EACV,WAA0D;IAE1D,MAAM,IAAI,GAAG,OAAO,CAAC,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,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, query, toHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\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 { ethQuery, transactionMeta } = request;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n ethQuery,\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 ethQuery: EthQuery,\n ): Promise<LineaEstimateGasResponse> {\n return query(ethQuery, 'linea_estimateGas', [\n {\n from: transactionMeta.txParams.from,\n to: transactionMeta.txParams.to,\n value: transactionMeta.txParams.value,\n input: transactionMeta.txParams.data,\n },\n ]);\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"]}
|
|
@@ -13,11 +13,11 @@ exports.AccountsApiRemoteTransactionSource = exports.SUPPORTED_CHAIN_IDS = void
|
|
|
13
13
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
14
14
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
15
15
|
const uuid_1 = require("uuid");
|
|
16
|
+
const __1 = require("../index.cjs");
|
|
16
17
|
const accounts_api_1 = require("../api/accounts-api.cjs");
|
|
17
18
|
const constants_1 = require("../constants.cjs");
|
|
18
19
|
const logger_1 = require("../logger.cjs");
|
|
19
20
|
const types_1 = require("../types.cjs");
|
|
20
|
-
const transaction_type_1 = require("../utils/transaction-type.cjs");
|
|
21
21
|
exports.SUPPORTED_CHAIN_IDS = [
|
|
22
22
|
constants_1.CHAIN_IDS.MAINNET,
|
|
23
23
|
constants_1.CHAIN_IDS.POLYGON,
|
|
@@ -152,7 +152,7 @@ _AccountsApiRemoteTransactionSource_instances = new WeakSet(), _AccountsApiRemot
|
|
|
152
152
|
verifiedOnBlockchain,
|
|
153
153
|
};
|
|
154
154
|
if (isOutgoing) {
|
|
155
|
-
meta.type = (await (0,
|
|
155
|
+
meta.type = (await (0, __1.determineTransactionType)(meta.txParams)).type;
|
|
156
156
|
}
|
|
157
157
|
return meta;
|
|
158
158
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiRemoteTransactionSource.cjs","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAqD;AAErD,kDAAuB;AACvB,+BAAoC;AAMpC,0DAA6D;AAC7D,gDAAyC;AACzC,0CAA2E;AAO3E,wCAA8D;AAC9D,oEAAqE;AAExD,QAAA,mBAAmB,GAAU;IACxC,qBAAS,CAAC,OAAO;IACjB,qBAAS,CAAC,OAAO;IACjB,qBAAS,CAAC,GAAG;IACb,qBAAS,CAAC,aAAa;IACvB,qBAAS,CAAC,IAAI;IACd,qBAAS,CAAC,QAAQ;IAClB,qBAAS,CAAC,QAAQ;IAClB,qBAAS,CAAC,MAAM;IAChB,qBAAS,CAAC,GAAG;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BAAoB;KACrB,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,IAAA,2CAAwB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport type {\n GetAccountTransactionsResponse,\n TransactionResponse,\n} from '../api/accounts-api';\nimport { getAccountTransactions } from '../api/accounts-api';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, incomingTransactionsLogger } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionError,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport { determineTransactionType } from '../utils/transaction-type';\n\nexport const SUPPORTED_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.MAINNET,\n CHAIN_IDS.POLYGON,\n CHAIN_IDS.BSC,\n CHAIN_IDS.LINEA_MAINNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.ARBITRUM,\n CHAIN_IDS.SCROLL,\n CHAIN_IDS.SEI,\n CHAIN_IDS.MONAD,\n CHAIN_IDS.HYPEREVM,\n];\n\nconst log = createModuleLogger(\n incomingTransactionsLogger,\n 'accounts-api-source',\n);\n\n/**\n * A RemoteTransactionSource that fetches incoming transactions using the Accounts API.\n */\nexport class AccountsApiRemoteTransactionSource\n implements RemoteTransactionSource\n{\n getSupportedChains(): Hex[] {\n return SUPPORTED_CHAIN_IDS;\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const { address, chainIds } = request;\n\n const responseTransactions = await this.#queryTransactions(\n request,\n chainIds ?? SUPPORTED_CHAIN_IDS,\n );\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = await Promise.all(\n responseTransactions.map((tx) => this.#normalizeTransaction(address, tx)),\n );\n\n log('Normalized transactions', normalizedTransactions);\n\n const filteredTransactions = this.#filterTransactions(\n request,\n normalizedTransactions,\n );\n\n log(\n 'Filtered transactions',\n filteredTransactions.length,\n filteredTransactions,\n );\n\n return filteredTransactions;\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n ): Promise<TransactionResponse[]> {\n const { address, tags } = request;\n const transactions: TransactionResponse[] = [];\n\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n sortDirection: 'DESC',\n tags,\n });\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n }\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const { address, includeTokenTransfers, updateTransactions } = request;\n\n let filteredTransactions = transactions;\n\n if (!updateTransactions) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => tx.txParams.to === address,\n );\n }\n\n if (!includeTokenTransfers) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => !tx.isTransfer,\n );\n }\n\n return filteredTransactions;\n }\n\n async #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): Promise<TransactionMeta> {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as const;\n const { hash } = responseTransaction;\n const time = new Date(responseTransaction.timestamp).getTime();\n const id = random({ msecs: time });\n const { from } = responseTransaction;\n const gas = BNToHex(new BN(responseTransaction.gas));\n const gasPrice = BNToHex(new BN(responseTransaction.gasPrice));\n const gasUsed = BNToHex(new BN(responseTransaction.gasUsed));\n const nonce = BNToHex(new BN(responseTransaction.nonce));\n const data = responseTransaction.methodId;\n const type = TransactionType.incoming;\n const verifiedOnBlockchain = false;\n\n const status = responseTransaction.isError\n ? TransactionStatus.failed\n : TransactionStatus.confirmed;\n\n const valueTransfer = responseTransaction.valueTransfers.find(\n (vt) =>\n (vt.to.toLowerCase() === address.toLowerCase() ||\n vt.from.toLowerCase() === address.toLowerCase()) &&\n vt.contractAddress,\n );\n\n const isIncomingTokenTransfer =\n valueTransfer?.to.toLowerCase() === address.toLowerCase() &&\n from.toLowerCase() !== address.toLowerCase();\n\n const isOutgoing = from.toLowerCase() === address.toLowerCase();\n const amount = valueTransfer?.amount;\n const contractAddress = valueTransfer?.contractAddress as string;\n const decimals = valueTransfer?.decimal as number;\n const symbol = valueTransfer?.symbol as string;\n\n const value = BNToHex(\n new BN(\n isIncomingTokenTransfer\n ? (valueTransfer?.amount ?? responseTransaction.value)\n : responseTransaction.value,\n ),\n );\n\n const to = isIncomingTokenTransfer ? address : responseTransaction.to;\n\n const error =\n status === TransactionStatus.failed\n ? new Error('Transaction failed')\n : (undefined as unknown as TransactionError);\n\n const transferInformation = valueTransfer\n ? {\n amount,\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n const meta: TransactionMeta = {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer: isIncomingTokenTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n data,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n\n if (isOutgoing) {\n meta.type = (await determineTransactionType(meta.txParams)).type;\n }\n\n return meta;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AccountsApiRemoteTransactionSource.cjs","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAqD;AAErD,kDAAuB;AACvB,+BAAoC;AAEpC,oCAA8C;AAK9C,0DAA6D;AAC7D,gDAAyC;AACzC,0CAA2E;AAO3E,wCAA8D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AAE,uBAAuB;QACnC,yDAAyD;QACzD,eAAe,EAAE,EAAE;QACnB,MAAM;QACN,IAAI;QACJ,eAAe,EAAE,KAAK;QACtB,mBAAmB;QACnB,QAAQ,EAAE;YACR,OAAO;YACP,IAAI;YACJ,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,OAAO;YACP,KAAK;YACL,EAAE;YACF,KAAK;SACN;QACD,IAAI;QACJ,oBAAoB;KACrB,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,IAAA,4BAAwB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport { determineTransactionType } from '..';\nimport type {\n GetAccountTransactionsResponse,\n TransactionResponse,\n} from '../api/accounts-api';\nimport { getAccountTransactions } from '../api/accounts-api';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, incomingTransactionsLogger } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionError,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\n\nexport const SUPPORTED_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.MAINNET,\n CHAIN_IDS.POLYGON,\n CHAIN_IDS.BSC,\n CHAIN_IDS.LINEA_MAINNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.ARBITRUM,\n CHAIN_IDS.SCROLL,\n CHAIN_IDS.SEI,\n CHAIN_IDS.MONAD,\n CHAIN_IDS.HYPEREVM,\n];\n\nconst log = createModuleLogger(\n incomingTransactionsLogger,\n 'accounts-api-source',\n);\n\n/**\n * A RemoteTransactionSource that fetches incoming transactions using the Accounts API.\n */\nexport class AccountsApiRemoteTransactionSource\n implements RemoteTransactionSource\n{\n getSupportedChains(): Hex[] {\n return SUPPORTED_CHAIN_IDS;\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const { address, chainIds } = request;\n\n const responseTransactions = await this.#queryTransactions(\n request,\n chainIds ?? SUPPORTED_CHAIN_IDS,\n );\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = await Promise.all(\n responseTransactions.map((tx) => this.#normalizeTransaction(address, tx)),\n );\n\n log('Normalized transactions', normalizedTransactions);\n\n const filteredTransactions = this.#filterTransactions(\n request,\n normalizedTransactions,\n );\n\n log(\n 'Filtered transactions',\n filteredTransactions.length,\n filteredTransactions,\n );\n\n return filteredTransactions;\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n ): Promise<TransactionResponse[]> {\n const { address, tags } = request;\n const transactions: TransactionResponse[] = [];\n\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n sortDirection: 'DESC',\n tags,\n });\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n }\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const { address, includeTokenTransfers, updateTransactions } = request;\n\n let filteredTransactions = transactions;\n\n if (!updateTransactions) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => tx.txParams.to === address,\n );\n }\n\n if (!includeTokenTransfers) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => !tx.isTransfer,\n );\n }\n\n return filteredTransactions;\n }\n\n async #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): Promise<TransactionMeta> {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as const;\n const { hash } = responseTransaction;\n const time = new Date(responseTransaction.timestamp).getTime();\n const id = random({ msecs: time });\n const { from } = responseTransaction;\n const gas = BNToHex(new BN(responseTransaction.gas));\n const gasPrice = BNToHex(new BN(responseTransaction.gasPrice));\n const gasUsed = BNToHex(new BN(responseTransaction.gasUsed));\n const nonce = BNToHex(new BN(responseTransaction.nonce));\n const data = responseTransaction.methodId;\n const type = TransactionType.incoming;\n const verifiedOnBlockchain = false;\n\n const status = responseTransaction.isError\n ? TransactionStatus.failed\n : TransactionStatus.confirmed;\n\n const valueTransfer = responseTransaction.valueTransfers.find(\n (vt) =>\n (vt.to.toLowerCase() === address.toLowerCase() ||\n vt.from.toLowerCase() === address.toLowerCase()) &&\n vt.contractAddress,\n );\n\n const isIncomingTokenTransfer =\n valueTransfer?.to.toLowerCase() === address.toLowerCase() &&\n from.toLowerCase() !== address.toLowerCase();\n\n const isOutgoing = from.toLowerCase() === address.toLowerCase();\n const amount = valueTransfer?.amount;\n const contractAddress = valueTransfer?.contractAddress as string;\n const decimals = valueTransfer?.decimal as number;\n const symbol = valueTransfer?.symbol as string;\n\n const value = BNToHex(\n new BN(\n isIncomingTokenTransfer\n ? (valueTransfer?.amount ?? responseTransaction.value)\n : responseTransaction.value,\n ),\n );\n\n const to = isIncomingTokenTransfer ? address : responseTransaction.to;\n\n const error =\n status === TransactionStatus.failed\n ? new Error('Transaction failed')\n : (undefined as unknown as TransactionError);\n\n const transferInformation = valueTransfer\n ? {\n amount,\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n const meta: TransactionMeta = {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer: isIncomingTokenTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n data,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n\n if (isOutgoing) {\n meta.type = (await determineTransactionType(meta.txParams)).type;\n }\n\n return meta;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiRemoteTransactionSource.d.cts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"AccountsApiRemoteTransactionSource.d.cts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAY3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EAYpC,CAAC;AAOF;;GAEG;AACH,qBAAa,kCACX,YAAW,uBAAuB;;IAElC,kBAAkB,IAAI,GAAG,EAAE;IAIrB,iBAAiB,CACrB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,eAAe,EAAE,CAAC;CAmL9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiRemoteTransactionSource.d.mts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"AccountsApiRemoteTransactionSource.d.mts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAY3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EAYpC,CAAC;AAOF;;GAEG;AACH,qBAAa,kCACX,YAAW,uBAAuB;;IAElC,kBAAkB,IAAI,GAAG,EAAE;IAIrB,iBAAiB,CACrB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,eAAe,EAAE,CAAC;CAmL9B"}
|
|
@@ -14,11 +14,11 @@ import { BNToHex } from "@metamask/controller-utils";
|
|
|
14
14
|
import $BN from "bn.js";
|
|
15
15
|
const BN = $importDefault($BN);
|
|
16
16
|
import { v1 as random } from "uuid";
|
|
17
|
+
import { determineTransactionType } from "../index.mjs";
|
|
17
18
|
import { getAccountTransactions } from "../api/accounts-api.mjs";
|
|
18
19
|
import { CHAIN_IDS } from "../constants.mjs";
|
|
19
20
|
import { createModuleLogger, incomingTransactionsLogger } from "../logger.mjs";
|
|
20
21
|
import { TransactionStatus, TransactionType } from "../types.mjs";
|
|
21
|
-
import { determineTransactionType } from "../utils/transaction-type.mjs";
|
|
22
22
|
export const SUPPORTED_CHAIN_IDS = [
|
|
23
23
|
CHAIN_IDS.MAINNET,
|
|
24
24
|
CHAIN_IDS.POLYGON,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiRemoteTransactionSource.mjs","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AAErD,OAAO,GAAE,cAAc;;AACvB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAMpC,OAAO,EAAE,sBAAsB,EAAE,gCAA4B;AAC7D,OAAO,EAAE,SAAS,EAAE,yBAAqB;AACzC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,sBAAkB;AAO3E,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAiB;AAC9D,OAAO,EAAE,wBAAwB,EAAE,sCAAkC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAU;IACxC,SAAS,CAAC,OAAO;IACjB,SAAS,CAAC,OAAO;IACjB,SAAS,CAAC,GAAG;IACb,SAAS,CAAC,aAAa;IACvB,SAAS,CAAC,IAAI;IACd,SAAS,CAAC,QAAQ;IAClB,SAAS,CAAC,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,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,wBAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport type {\n GetAccountTransactionsResponse,\n TransactionResponse,\n} from '../api/accounts-api';\nimport { getAccountTransactions } from '../api/accounts-api';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, incomingTransactionsLogger } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionError,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport { determineTransactionType } from '../utils/transaction-type';\n\nexport const SUPPORTED_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.MAINNET,\n CHAIN_IDS.POLYGON,\n CHAIN_IDS.BSC,\n CHAIN_IDS.LINEA_MAINNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.ARBITRUM,\n CHAIN_IDS.SCROLL,\n CHAIN_IDS.SEI,\n CHAIN_IDS.MONAD,\n CHAIN_IDS.HYPEREVM,\n];\n\nconst log = createModuleLogger(\n incomingTransactionsLogger,\n 'accounts-api-source',\n);\n\n/**\n * A RemoteTransactionSource that fetches incoming transactions using the Accounts API.\n */\nexport class AccountsApiRemoteTransactionSource\n implements RemoteTransactionSource\n{\n getSupportedChains(): Hex[] {\n return SUPPORTED_CHAIN_IDS;\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const { address, chainIds } = request;\n\n const responseTransactions = await this.#queryTransactions(\n request,\n chainIds ?? SUPPORTED_CHAIN_IDS,\n );\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = await Promise.all(\n responseTransactions.map((tx) => this.#normalizeTransaction(address, tx)),\n );\n\n log('Normalized transactions', normalizedTransactions);\n\n const filteredTransactions = this.#filterTransactions(\n request,\n normalizedTransactions,\n );\n\n log(\n 'Filtered transactions',\n filteredTransactions.length,\n filteredTransactions,\n );\n\n return filteredTransactions;\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n ): Promise<TransactionResponse[]> {\n const { address, tags } = request;\n const transactions: TransactionResponse[] = [];\n\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n sortDirection: 'DESC',\n tags,\n });\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n }\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const { address, includeTokenTransfers, updateTransactions } = request;\n\n let filteredTransactions = transactions;\n\n if (!updateTransactions) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => tx.txParams.to === address,\n );\n }\n\n if (!includeTokenTransfers) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => !tx.isTransfer,\n );\n }\n\n return filteredTransactions;\n }\n\n async #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): Promise<TransactionMeta> {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as const;\n const { hash } = responseTransaction;\n const time = new Date(responseTransaction.timestamp).getTime();\n const id = random({ msecs: time });\n const { from } = responseTransaction;\n const gas = BNToHex(new BN(responseTransaction.gas));\n const gasPrice = BNToHex(new BN(responseTransaction.gasPrice));\n const gasUsed = BNToHex(new BN(responseTransaction.gasUsed));\n const nonce = BNToHex(new BN(responseTransaction.nonce));\n const data = responseTransaction.methodId;\n const type = TransactionType.incoming;\n const verifiedOnBlockchain = false;\n\n const status = responseTransaction.isError\n ? TransactionStatus.failed\n : TransactionStatus.confirmed;\n\n const valueTransfer = responseTransaction.valueTransfers.find(\n (vt) =>\n (vt.to.toLowerCase() === address.toLowerCase() ||\n vt.from.toLowerCase() === address.toLowerCase()) &&\n vt.contractAddress,\n );\n\n const isIncomingTokenTransfer =\n valueTransfer?.to.toLowerCase() === address.toLowerCase() &&\n from.toLowerCase() !== address.toLowerCase();\n\n const isOutgoing = from.toLowerCase() === address.toLowerCase();\n const amount = valueTransfer?.amount;\n const contractAddress = valueTransfer?.contractAddress as string;\n const decimals = valueTransfer?.decimal as number;\n const symbol = valueTransfer?.symbol as string;\n\n const value = BNToHex(\n new BN(\n isIncomingTokenTransfer\n ? (valueTransfer?.amount ?? responseTransaction.value)\n : responseTransaction.value,\n ),\n );\n\n const to = isIncomingTokenTransfer ? address : responseTransaction.to;\n\n const error =\n status === TransactionStatus.failed\n ? new Error('Transaction failed')\n : (undefined as unknown as TransactionError);\n\n const transferInformation = valueTransfer\n ? {\n amount,\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n const meta: TransactionMeta = {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer: isIncomingTokenTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n data,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n\n if (isOutgoing) {\n meta.type = (await determineTransactionType(meta.txParams)).type;\n }\n\n return meta;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AccountsApiRemoteTransactionSource.mjs","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AAErD,OAAO,GAAE,cAAc;;AACvB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,OAAO,EAAE,wBAAw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YACR,MAAM;SACP;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,IAAI,GAAoB;QAC5B,WAAW;QACX,OAAO;QACP,KAAK;QACL,IAAI;QACJ,EAAE;QACF,UAAU,EAAE,uBAAuB;QACnC,yDAAyD;QACzD,eAAe,EAAE,EAAE;QACnB,MAAM;QACN,IAAI;QACJ,eAAe,EAAE,KAAK;QACtB,mBAAmB;QACnB,QAAQ,EAAE;YACR,OAAO;YACP,IAAI;YACJ,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,OAAO;YACP,KAAK;YACL,EAAE;YACF,KAAK;SACN;QACD,IAAI;QACJ,oBAAoB;KACrB,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,wBAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport { determineTransactionType } from '..';\nimport type {\n GetAccountTransactionsResponse,\n TransactionResponse,\n} from '../api/accounts-api';\nimport { getAccountTransactions } from '../api/accounts-api';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, incomingTransactionsLogger } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionError,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\n\nexport const SUPPORTED_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.MAINNET,\n CHAIN_IDS.POLYGON,\n CHAIN_IDS.BSC,\n CHAIN_IDS.LINEA_MAINNET,\n CHAIN_IDS.BASE,\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.ARBITRUM,\n CHAIN_IDS.SCROLL,\n CHAIN_IDS.SEI,\n CHAIN_IDS.MONAD,\n CHAIN_IDS.HYPEREVM,\n];\n\nconst log = createModuleLogger(\n incomingTransactionsLogger,\n 'accounts-api-source',\n);\n\n/**\n * A RemoteTransactionSource that fetches incoming transactions using the Accounts API.\n */\nexport class AccountsApiRemoteTransactionSource\n implements RemoteTransactionSource\n{\n getSupportedChains(): Hex[] {\n return SUPPORTED_CHAIN_IDS;\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const { address, chainIds } = request;\n\n const responseTransactions = await this.#queryTransactions(\n request,\n chainIds ?? SUPPORTED_CHAIN_IDS,\n );\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = await Promise.all(\n responseTransactions.map((tx) => this.#normalizeTransaction(address, tx)),\n );\n\n log('Normalized transactions', normalizedTransactions);\n\n const filteredTransactions = this.#filterTransactions(\n request,\n normalizedTransactions,\n );\n\n log(\n 'Filtered transactions',\n filteredTransactions.length,\n filteredTransactions,\n );\n\n return filteredTransactions;\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n ): Promise<TransactionResponse[]> {\n const { address, tags } = request;\n const transactions: TransactionResponse[] = [];\n\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n sortDirection: 'DESC',\n tags,\n });\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n }\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ): TransactionMeta[] {\n const { address, includeTokenTransfers, updateTransactions } = request;\n\n let filteredTransactions = transactions;\n\n if (!updateTransactions) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => tx.txParams.to === address,\n );\n }\n\n if (!includeTokenTransfers) {\n filteredTransactions = filteredTransactions.filter(\n (tx) => !tx.isTransfer,\n );\n }\n\n return filteredTransactions;\n }\n\n async #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): Promise<TransactionMeta> {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as const;\n const { hash } = responseTransaction;\n const time = new Date(responseTransaction.timestamp).getTime();\n const id = random({ msecs: time });\n const { from } = responseTransaction;\n const gas = BNToHex(new BN(responseTransaction.gas));\n const gasPrice = BNToHex(new BN(responseTransaction.gasPrice));\n const gasUsed = BNToHex(new BN(responseTransaction.gasUsed));\n const nonce = BNToHex(new BN(responseTransaction.nonce));\n const data = responseTransaction.methodId;\n const type = TransactionType.incoming;\n const verifiedOnBlockchain = false;\n\n const status = responseTransaction.isError\n ? TransactionStatus.failed\n : TransactionStatus.confirmed;\n\n const valueTransfer = responseTransaction.valueTransfers.find(\n (vt) =>\n (vt.to.toLowerCase() === address.toLowerCase() ||\n vt.from.toLowerCase() === address.toLowerCase()) &&\n vt.contractAddress,\n );\n\n const isIncomingTokenTransfer =\n valueTransfer?.to.toLowerCase() === address.toLowerCase() &&\n from.toLowerCase() !== address.toLowerCase();\n\n const isOutgoing = from.toLowerCase() === address.toLowerCase();\n const amount = valueTransfer?.amount;\n const contractAddress = valueTransfer?.contractAddress as string;\n const decimals = valueTransfer?.decimal as number;\n const symbol = valueTransfer?.symbol as string;\n\n const value = BNToHex(\n new BN(\n isIncomingTokenTransfer\n ? (valueTransfer?.amount ?? responseTransaction.value)\n : responseTransaction.value,\n ),\n );\n\n const to = isIncomingTokenTransfer ? address : responseTransaction.to;\n\n const error =\n status === TransactionStatus.failed\n ? new Error('Transaction failed')\n : (undefined as unknown as TransactionError);\n\n const transferInformation = valueTransfer\n ? {\n amount,\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n const meta: TransactionMeta = {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer: isIncomingTokenTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n data,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n\n if (isOutgoing) {\n meta.type = (await determineTransactionType(meta.txParams)).type;\n }\n\n return meta;\n }\n}\n"]}
|
|
@@ -13,9 +13,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _GasFeePoller_instances, _GasFeePoller_gasFeeFlows, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getTransactions, _GasFeePoller_getTransactionBatches, _GasFeePoller_layer1GasFeeFlows, _GasFeePoller_messenger, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateUnapprovedTransactionBatches, _GasFeePoller_updateUnapprovedTransaction, _GasFeePoller_updateUnapprovedTransactionBatch, _GasFeePoller_updateTransactionGasFeeEstimates, _GasFeePoller_updateTransactionLayer1GasFee, _GasFeePoller_getUnapprovedTransactions, _GasFeePoller_getUnapprovedTransactionBatches, _GasFeePoller_getGasFeeControllerData;
|
|
16
|
+
var _GasFeePoller_instances, _GasFeePoller_findNetworkClientIdByChainId, _GasFeePoller_gasFeeFlows, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getProvider, _GasFeePoller_getTransactions, _GasFeePoller_getTransactionBatches, _GasFeePoller_layer1GasFeeFlows, _GasFeePoller_messenger, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateUnapprovedTransactionBatches, _GasFeePoller_updateUnapprovedTransaction, _GasFeePoller_updateUnapprovedTransactionBatch, _GasFeePoller_updateTransactionGasFeeEstimates, _GasFeePoller_updateTransactionLayer1GasFee, _GasFeePoller_getUnapprovedTransactions, _GasFeePoller_getUnapprovedTransactionBatches, _GasFeePoller_getGasFeeControllerData;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.updateTransactionGasEstimates = exports.updateTransactionGasProperties = exports.GasFeePoller = void 0;
|
|
19
|
+
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
19
20
|
const utils_1 = require("@metamask/utils");
|
|
20
21
|
// This package purposefully relies on Node's EventEmitter module.
|
|
21
22
|
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
@@ -25,7 +26,6 @@ const logger_1 = require("../logger.cjs");
|
|
|
25
26
|
const types_1 = require("../types.cjs");
|
|
26
27
|
const gas_flow_1 = require("../utils/gas-flow.cjs");
|
|
27
28
|
const layer1_gas_fee_flow_1 = require("../utils/layer1-gas-fee-flow.cjs");
|
|
28
|
-
const provider_1 = require("../utils/provider.cjs");
|
|
29
29
|
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'gas-fee-poller');
|
|
30
30
|
const INTERVAL_MILLISECONDS = 10000;
|
|
31
31
|
/**
|
|
@@ -36,28 +36,34 @@ class GasFeePoller {
|
|
|
36
36
|
* Constructs a new instance of the GasFeePoller.
|
|
37
37
|
*
|
|
38
38
|
* @param options - The options for this instance.
|
|
39
|
+
* @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
|
|
39
40
|
* @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
|
|
40
41
|
* @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
|
|
42
|
+
* @param options.getProvider - Callback to obtain a provider instance.
|
|
41
43
|
* @param options.getTransactions - Callback to obtain the transaction data.
|
|
42
44
|
* @param options.getTransactionBatches - Callback to obtain the transaction batch data.
|
|
43
45
|
* @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
|
|
44
46
|
* @param options.messenger - The TransactionControllerMessenger instance.
|
|
45
47
|
* @param options.onStateChange - Callback to register a listener for controller state changes.
|
|
46
48
|
*/
|
|
47
|
-
constructor({ gasFeeFlows, getGasFeeControllerEstimates, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }) {
|
|
49
|
+
constructor({ findNetworkClientIdByChainId, gasFeeFlows, getGasFeeControllerEstimates, getProvider, getTransactions, getTransactionBatches, layer1GasFeeFlows, messenger, onStateChange, }) {
|
|
48
50
|
_GasFeePoller_instances.add(this);
|
|
49
51
|
this.hub = new events_1.default();
|
|
52
|
+
_GasFeePoller_findNetworkClientIdByChainId.set(this, void 0);
|
|
50
53
|
_GasFeePoller_gasFeeFlows.set(this, void 0);
|
|
51
54
|
_GasFeePoller_getGasFeeControllerEstimates.set(this, void 0);
|
|
55
|
+
_GasFeePoller_getProvider.set(this, void 0);
|
|
52
56
|
_GasFeePoller_getTransactions.set(this, void 0);
|
|
53
57
|
_GasFeePoller_getTransactionBatches.set(this, void 0);
|
|
54
58
|
_GasFeePoller_layer1GasFeeFlows.set(this, void 0);
|
|
55
59
|
_GasFeePoller_messenger.set(this, void 0);
|
|
56
60
|
_GasFeePoller_timeout.set(this, void 0);
|
|
57
61
|
_GasFeePoller_running.set(this, false);
|
|
62
|
+
__classPrivateFieldSet(this, _GasFeePoller_findNetworkClientIdByChainId, findNetworkClientIdByChainId, "f");
|
|
58
63
|
__classPrivateFieldSet(this, _GasFeePoller_gasFeeFlows, gasFeeFlows, "f");
|
|
59
64
|
__classPrivateFieldSet(this, _GasFeePoller_layer1GasFeeFlows, layer1GasFeeFlows, "f");
|
|
60
65
|
__classPrivateFieldSet(this, _GasFeePoller_getGasFeeControllerEstimates, getGasFeeControllerEstimates, "f");
|
|
66
|
+
__classPrivateFieldSet(this, _GasFeePoller_getProvider, getProvider, "f");
|
|
61
67
|
__classPrivateFieldSet(this, _GasFeePoller_getTransactions, getTransactions, "f");
|
|
62
68
|
__classPrivateFieldSet(this, _GasFeePoller_getTransactionBatches, getTransactionBatches, "f");
|
|
63
69
|
__classPrivateFieldSet(this, _GasFeePoller_messenger, messenger, "f");
|
|
@@ -75,7 +81,7 @@ class GasFeePoller {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
exports.GasFeePoller = GasFeePoller;
|
|
78
|
-
_GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEstimates = new WeakMap(), _GasFeePoller_getTransactions = new WeakMap(), _GasFeePoller_getTransactionBatches = new WeakMap(), _GasFeePoller_layer1GasFeeFlows = new WeakMap(), _GasFeePoller_messenger = new WeakMap(), _GasFeePoller_timeout = new WeakMap(), _GasFeePoller_running = new WeakMap(), _GasFeePoller_instances = new WeakSet(), _GasFeePoller_start = function _GasFeePoller_start() {
|
|
84
|
+
_GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEstimates = new WeakMap(), _GasFeePoller_getProvider = new WeakMap(), _GasFeePoller_getTransactions = new WeakMap(), _GasFeePoller_getTransactionBatches = new WeakMap(), _GasFeePoller_layer1GasFeeFlows = new WeakMap(), _GasFeePoller_messenger = new WeakMap(), _GasFeePoller_timeout = new WeakMap(), _GasFeePoller_running = new WeakMap(), _GasFeePoller_instances = new WeakSet(), _GasFeePoller_start = function _GasFeePoller_start() {
|
|
79
85
|
if (__classPrivateFieldGet(this, _GasFeePoller_running, "f")) {
|
|
80
86
|
return;
|
|
81
87
|
}
|
|
@@ -140,8 +146,10 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
|
|
|
140
146
|
});
|
|
141
147
|
}, _GasFeePoller_updateUnapprovedTransactionBatch = async function _GasFeePoller_updateUnapprovedTransactionBatch(txBatchMeta, gasFeeControllerData) {
|
|
142
148
|
const { id } = txBatchMeta;
|
|
149
|
+
const ethQuery = new eth_query_1.default(__classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, txBatchMeta.networkClientId));
|
|
143
150
|
const defaultGasFeeFlow = new DefaultGasFeeFlow_1.DefaultGasFeeFlow();
|
|
144
151
|
const request = {
|
|
152
|
+
ethQuery,
|
|
145
153
|
gasFeeControllerData,
|
|
146
154
|
messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
|
|
147
155
|
transactionMeta: {
|
|
@@ -171,11 +179,14 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
|
|
|
171
179
|
gasFeeEstimatesLoaded: true,
|
|
172
180
|
});
|
|
173
181
|
}, _GasFeePoller_updateTransactionGasFeeEstimates = async function _GasFeePoller_updateTransactionGasFeeEstimates(transactionMeta, gasFeeControllerData) {
|
|
182
|
+
const { networkClientId } = transactionMeta;
|
|
183
|
+
const ethQuery = new eth_query_1.default(__classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, networkClientId));
|
|
174
184
|
const gasFeeFlow = (0, gas_flow_1.getGasFeeFlow)(transactionMeta, __classPrivateFieldGet(this, _GasFeePoller_gasFeeFlows, "f"), __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"));
|
|
175
185
|
if (gasFeeFlow) {
|
|
176
186
|
log('Found gas fee flow', gasFeeFlow.constructor.name, transactionMeta.id);
|
|
177
187
|
}
|
|
178
188
|
const request = {
|
|
189
|
+
ethQuery,
|
|
179
190
|
gasFeeControllerData,
|
|
180
191
|
messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
|
|
181
192
|
transactionMeta,
|
|
@@ -199,9 +210,12 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
|
|
|
199
210
|
});
|
|
200
211
|
return { gasFeeEstimates, gasFeeEstimatesLoaded: true };
|
|
201
212
|
}, _GasFeePoller_updateTransactionLayer1GasFee = async function _GasFeePoller_updateTransactionLayer1GasFee(transactionMeta) {
|
|
213
|
+
const { networkClientId } = transactionMeta;
|
|
214
|
+
const provider = __classPrivateFieldGet(this, _GasFeePoller_getProvider, "f").call(this, networkClientId);
|
|
202
215
|
const layer1GasFee = await (0, layer1_gas_fee_flow_1.getTransactionLayer1GasFee)({
|
|
203
216
|
layer1GasFeeFlows: __classPrivateFieldGet(this, _GasFeePoller_layer1GasFeeFlows, "f"),
|
|
204
217
|
messenger: __classPrivateFieldGet(this, _GasFeePoller_messenger, "f"),
|
|
218
|
+
provider,
|
|
205
219
|
transactionMeta,
|
|
206
220
|
});
|
|
207
221
|
if (layer1GasFee) {
|
|
@@ -220,7 +234,7 @@ _GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getGasFeeControllerEsti
|
|
|
220
234
|
continue;
|
|
221
235
|
}
|
|
222
236
|
const networkClientId = transactionNetworkClientId ??
|
|
223
|
-
|
|
237
|
+
__classPrivateFieldGet(this, _GasFeePoller_findNetworkClientIdByChainId, "f").call(this, chainId);
|
|
224
238
|
networkClientIdsByChainId.set(chainId, networkClientId);
|
|
225
239
|
}
|
|
226
240
|
log('Extracted network client IDs by chain ID', networkClientIdsByChainId);
|