@metamask/transaction-controller 28.1.1 → 29.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -1
- package/dist/TransactionController.js +11 -10
- package/dist/TransactionController.mjs +10 -9
- package/dist/{chunk-HQAADNXH.mjs → chunk-26BABWPE.mjs} +201 -113
- package/dist/chunk-26BABWPE.mjs.map +1 -0
- package/dist/{chunk-LDXTSESK.mjs → chunk-4M7FHI4S.mjs} +20 -4
- package/dist/chunk-4M7FHI4S.mjs.map +1 -0
- package/dist/{chunk-FK7AP6SH.js → chunk-5C3CSQAD.js} +12 -5
- package/dist/{chunk-YEJJKWT2.mjs.map → chunk-5C3CSQAD.js.map} +1 -1
- package/dist/{chunk-V6UIRCOF.js → chunk-7DJO6UZA.js} +48 -13
- package/dist/chunk-7DJO6UZA.js.map +1 -0
- package/dist/{chunk-TWND5SFD.mjs → chunk-AGJNOOBN.mjs} +17 -12
- package/dist/chunk-AGJNOOBN.mjs.map +1 -0
- package/dist/{chunk-LNX4JTOL.js → chunk-DUFOYA4D.js} +7 -7
- package/dist/chunk-DUFOYA4D.js.map +1 -0
- package/dist/{chunk-UH7FNVKS.js → chunk-EMDU4XLM.js} +19 -14
- package/dist/chunk-EMDU4XLM.js.map +1 -0
- package/dist/chunk-FMRLPVFZ.mjs +66 -0
- package/dist/chunk-FMRLPVFZ.mjs.map +1 -0
- package/dist/{chunk-EQNKFFTM.js → chunk-KNYSD4JP.js} +21 -5
- package/dist/chunk-KNYSD4JP.js.map +1 -0
- package/dist/{chunk-FMCTVRU2.js → chunk-KT3F6CZP.js} +204 -116
- package/dist/chunk-KT3F6CZP.js.map +1 -0
- package/dist/{chunk-YEJJKWT2.mjs → chunk-N6JXPWLY.mjs} +11 -4
- package/dist/chunk-N6JXPWLY.mjs.map +1 -0
- package/dist/chunk-REOG6YD4.mjs +112 -0
- package/dist/chunk-REOG6YD4.mjs.map +1 -0
- package/dist/{chunk-HHK4QSNF.mjs → chunk-SL3GHHKG.mjs} +47 -12
- package/dist/chunk-SL3GHHKG.mjs.map +1 -0
- package/dist/chunk-TJMQEH57.js +66 -0
- package/dist/chunk-TJMQEH57.js.map +1 -0
- package/dist/chunk-VJYFB7BM.js +112 -0
- package/dist/chunk-VJYFB7BM.js.map +1 -0
- package/dist/{chunk-NCRWKI6Y.mjs → chunk-XL3HBKDE.mjs} +4 -4
- package/dist/chunk-XL3HBKDE.mjs.map +1 -0
- package/dist/errors.js +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.js +5 -5
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +4 -4
- package/dist/gas-flows/LineaGasFeeFlow.js +6 -6
- package/dist/gas-flows/LineaGasFeeFlow.mjs +5 -5
- package/dist/gas-flows/TestGasFeeFlow.js +9 -0
- package/dist/gas-flows/TestGasFeeFlow.js.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.mjs +9 -0
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
- 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 +15 -10
- package/dist/index.mjs +14 -9
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts +16 -7
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -1
- package/dist/types/gas-flows/TestGasFeeFlow.d.ts +12 -0
- package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts +5 -3
- package/dist/types/helpers/GasFeePoller.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 +36 -18
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/gas-flow.d.ts +8 -14
- package/dist/types/utils/gas-flow.d.ts.map +1 -1
- package/dist/types.js +4 -2
- package/dist/types.mjs +3 -1
- package/dist/utils/external-transactions.js +1 -1
- package/dist/utils/external-transactions.mjs +1 -1
- package/dist/utils/gas-fees.js +4 -4
- package/dist/utils/gas-fees.mjs +3 -3
- 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 +1 -1
- package/dist/utils/swaps.mjs +1 -1
- package/dist/utils/transaction-type.js +1 -1
- package/dist/utils/transaction-type.mjs +1 -1
- package/dist/utils/utils.js +1 -1
- package/dist/utils/utils.mjs +1 -1
- package/dist/utils/validation.js +1 -1
- package/dist/utils/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/chunk-4RJXBKSR.js +0 -90
- package/dist/chunk-4RJXBKSR.js.map +0 -1
- package/dist/chunk-EQNKFFTM.js.map +0 -1
- package/dist/chunk-FK7AP6SH.js.map +0 -1
- package/dist/chunk-FMCTVRU2.js.map +0 -1
- package/dist/chunk-HHK4QSNF.mjs.map +0 -1
- package/dist/chunk-HQAADNXH.mjs.map +0 -1
- package/dist/chunk-LDXTSESK.mjs.map +0 -1
- package/dist/chunk-LNX4JTOL.js.map +0 -1
- package/dist/chunk-NCRWKI6Y.mjs.map +0 -1
- package/dist/chunk-NPEXNXSY.mjs +0 -90
- package/dist/chunk-NPEXNXSY.mjs.map +0 -1
- package/dist/chunk-TWND5SFD.mjs.map +0 -1
- package/dist/chunk-UH7FNVKS.js.map +0 -1
- package/dist/chunk-V6UIRCOF.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/gas-flow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAMhC;AAAA,EACE;AAAA,OAEK;AAiBA,SAAS,cACd,iBACA,aACwB;AACxB,SAAO,YAAY;AAAA,IAAK,CAAC,eACvB,WAAW,mBAAmB,eAAe;AAAA,EAC/C;AACF;AAsBO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAEuE;AACrE,MAAI,iCAAiC,mBAAmB,YAAY;AAClE,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,UACP,0BAA0B,KAAK;AAAA,UAC/B,2BAA2B,KAAK;AAAA,QAClC;AAAA,MACF;AAAA,MACA,EAAE,GAAG,0BAA0B;AAAA,IACjC;AAAA,EACF;AAEA,MAAI,iCAAiC,mBAAmB,QAAQ;AAC9D,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG,kBAAkB,2BAA2B,KAAK,CAAC;AAAA,MAC9D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAQA,SAAS,uBACP,0BACA,2BACe;AACf,SAAO;AAAA,IACL,GAAG;AAAA,IACH,uBAAuB;AAAA,MACrB,0BAA0B;AAAA,IAC5B;AAAA,IACA,+BAA+B;AAAA,MAC7B,0BAA0B;AAAA,IAC5B;AAAA,EACF;AACF;AAOA,SAAS,kBACP,2BACQ;AACR,SAAO,gBAAgB,0BAA0B,YAAY;AAC/D","sourcesContent":["import { weiHexToGweiDec } from '@metamask/controller-utils';\nimport type {\n Eip1559GasFee,\n GasFeeEstimates,\n LegacyGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\n\nimport {\n type GasFeeEstimates as TransactionGasFeeEstimates,\n type GasFeeFlow,\n type TransactionMeta,\n type GasFeeEstimatesForLevel,\n GasFeeEstimateLevel,\n} from '../types';\n\n/**\n * Returns the first gas fee flow that matches the transaction.\n *\n * @param transactionMeta - The transaction metadata to find a gas fee flow for.\n * @param gasFeeFlows - The gas fee flows to search.\n * @returns The first gas fee flow that matches the transaction, or undefined if none match.\n */\nexport function getGasFeeFlow(\n transactionMeta: TransactionMeta,\n gasFeeFlows: GasFeeFlow[],\n): GasFeeFlow | undefined {\n return gasFeeFlows.find((gasFeeFlow) =>\n gasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\ntype FeeMarketMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'fee-market';\n gasFeeControllerEstimates: GasFeeEstimates;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\ntype LegacyMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'legacy';\n gasFeeControllerEstimates: LegacyGasPriceEstimate;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\n/**\n * Merge the gas fee estimates from the gas fee controller with the gas fee estimates from a transaction.\n * @param request - Data required to merge gas fee estimates.\n * @param request.gasFeeControllerEstimateType - Gas fee estimate type from the gas fee controller.\n * @param request.gasFeeControllerEstimates - Gas fee estimates from the GasFeeController.\n * @param request.transactionGasFeeEstimates - Gas fee estimates from the transaction.\n * @returns The merged gas fee estimates.\n */\nexport function mergeGasFeeEstimates({\n gasFeeControllerEstimateType,\n gasFeeControllerEstimates,\n transactionGasFeeEstimates,\n}:\n | FeeMarketMergeGasFeeEstimatesRequest\n | LegacyMergeGasFeeEstimatesRequest): GasFeeState['gasFeeEstimates'] {\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: mergeFeeMarketEstimate(\n gasFeeControllerEstimates[level],\n transactionGasFeeEstimates[level],\n ),\n }),\n { ...gasFeeControllerEstimates } as GasFeeEstimates,\n );\n }\n\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: getLegacyEstimate(transactionGasFeeEstimates[level]),\n }),\n {} as LegacyGasPriceEstimate,\n );\n }\n\n return gasFeeControllerEstimates;\n}\n\n/**\n * Merge a specific priority level of EIP-1559 gas fee estimates.\n * @param gasFeeControllerEstimate - The gas fee estimate from the gas fee controller.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The merged gas fee estimate.\n */\nfunction mergeFeeMarketEstimate(\n gasFeeControllerEstimate: Eip1559GasFee,\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): Eip1559GasFee {\n return {\n ...gasFeeControllerEstimate,\n suggestedMaxFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxFeePerGas,\n ),\n suggestedMaxPriorityFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxPriorityFeePerGas,\n ),\n };\n}\n\n/**\n * Generate a specific priority level for a legacy gas fee estimate.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The legacy gas fee estimate.\n */\nfunction getLegacyEstimate(\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): string {\n return weiHexToGweiDec(transactionGasFeeEstimate.maxFeePerGas);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAIrB,SAAS,0BAA0B;AACnC,OAAO,kBAAkB;AAazB,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,wBAAwB;AApB9B;AAyBO,IAAM,eAAN,M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iB,uBAAuB,KAAK;AACxD;AAEM;AAAA,mCAA8B,eAClC,iBAC0B;AAC1B,QAAM,EAAE,SAAS,gBAAgB,IAAI;AACrC,QAAM,WAAW,mBAAK,cAAL,WAAkB,SAAS;AAE5C,QAAM,eAAe,MAAM,2BAA2B;AAAA,IACpD,mBAAmB,mBAAK;AAAA,IACxB;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,cAAc;AAChB,QAAI,2BAA2B,cAAc,gBAAgB,EAAE;AAAA,EACjE;AAEA,SAAO;AACT;AAEA;AAAA,+BAA0B,WAAG;AAC3B,SAAO,mBAAK,kBAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG;AAAA,EACb;AACF","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n} from '../types';\nimport { TransactionStatus, type TransactionMeta } from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n\n #getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n\n #getTransactions: () => TransactionMeta[];\n\n #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n * @param options - The options for this instance.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop() {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n log('Found unapproved transactions', unapprovedTransactions.length);\n }\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) =>\n this.#updateUnapprovedTransaction(tx),\n ),\n );\n }\n\n async #updateUnapprovedTransaction(transactionMeta: TransactionMeta) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(transactionMeta),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { chainId, networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(chainId, networkClientId));\n const gasFeeFlow = getGasFeeFlow(transactionMeta, this.#gasFeeFlows);\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n getGasFeeControllerEstimates: this.#getGasFeeControllerEstimates,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { chainId, networkClientId } = transactionMeta;\n const provider = this.#getProvider(chainId, networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n}\n"]}
|