@metamask/transaction-controller 51.0.0 → 52.1.0

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/dist/TransactionController.cjs +30 -28
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +6 -3
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +6 -3
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +31 -29
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +3 -8
  11. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
  12. package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
  13. package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
  14. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +3 -8
  15. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
  16. package/dist/helpers/GasFeePoller.cjs +73 -1
  17. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  18. package/dist/helpers/GasFeePoller.d.cts +20 -2
  19. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  20. package/dist/helpers/GasFeePoller.d.mts +20 -2
  21. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  22. package/dist/helpers/GasFeePoller.mjs +72 -1
  23. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  24. package/dist/helpers/IncomingTransactionHelper.cjs +4 -12
  25. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  26. package/dist/helpers/IncomingTransactionHelper.d.cts +1 -3
  27. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  28. package/dist/helpers/IncomingTransactionHelper.d.mts +1 -3
  29. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  30. package/dist/helpers/IncomingTransactionHelper.mjs +4 -12
  31. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  32. package/dist/types.cjs.map +1 -1
  33. package/dist/types.d.cts +0 -4
  34. package/dist/types.d.cts.map +1 -1
  35. package/dist/types.d.mts +0 -4
  36. package/dist/types.d.mts.map +1 -1
  37. package/dist/types.mjs.map +1 -1
  38. package/dist/utils/feature-flags.cjs +2 -2
  39. package/dist/utils/feature-flags.cjs.map +1 -1
  40. package/dist/utils/feature-flags.d.cts +2 -2
  41. package/dist/utils/feature-flags.d.mts +2 -2
  42. package/dist/utils/feature-flags.mjs +2 -2
  43. package/dist/utils/feature-flags.mjs.map +1 -1
  44. package/dist/utils/gas.cjs +108 -8
  45. package/dist/utils/gas.cjs.map +1 -1
  46. package/dist/utils/gas.d.cts +16 -5
  47. package/dist/utils/gas.d.cts.map +1 -1
  48. package/dist/utils/gas.d.mts +16 -5
  49. package/dist/utils/gas.d.mts.map +1 -1
  50. package/dist/utils/gas.mjs +108 -8
  51. package/dist/utils/gas.mjs.map +1 -1
  52. package/dist/utils/simulation-api.cjs.map +1 -1
  53. package/dist/utils/simulation-api.d.cts +9 -5
  54. package/dist/utils/simulation-api.d.cts.map +1 -1
  55. package/dist/utils/simulation-api.d.mts +9 -5
  56. package/dist/utils/simulation-api.d.mts.map +1 -1
  57. package/dist/utils/simulation-api.mjs.map +1 -1
  58. package/package.json +2 -2
@@ -52,17 +52,12 @@ class AccountsApiRemoteTransactionSource {
52
52
  exports.AccountsApiRemoteTransactionSource = AccountsApiRemoteTransactionSource;
53
53
  _AccountsApiRemoteTransactionSource_instances = new WeakSet(), _AccountsApiRemoteTransactionSource_getTransactions = async function _AccountsApiRemoteTransactionSource_getTransactions(request) {
54
54
  log('Getting transactions', request);
55
- const { address, cache, chainIds: requestedChainIds } = request;
56
- const chainIds = requestedChainIds.filter((chainId) => exports.SUPPORTED_CHAIN_IDS.includes(chainId));
57
- const unsupportedChainIds = requestedChainIds.filter((chainId) => !chainIds.includes(chainId));
58
- if (unsupportedChainIds.length) {
59
- log('Ignoring unsupported chain IDs', unsupportedChainIds);
60
- }
61
- const cursor = __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_getCacheCursor).call(this, cache, chainIds, address);
55
+ const { address, cache } = request;
56
+ const cursor = __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_getCacheCursor).call(this, cache, exports.SUPPORTED_CHAIN_IDS, address);
62
57
  if (cursor) {
63
58
  log('Using cached cursor', cursor);
64
59
  }
65
- return await __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_queryTransactions).call(this, request, chainIds, cursor);
60
+ return await __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_queryTransactions).call(this, request, exports.SUPPORTED_CHAIN_IDS, cursor);
66
61
  }, _AccountsApiRemoteTransactionSource_queryTransactions = async function _AccountsApiRemoteTransactionSource_queryTransactions(request, chainIds, cursor) {
67
62
  const { address, queryEntireHistory, updateCache } = request;
68
63
  const transactions = [];
@@ -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;AAEjD,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;CACjB,CAAC;AAEF,MAAM,GAAG,GAAG,IA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,GAAG,uBAAA,IAAI,sGAAa,MAAjB,IAAI,EAAc,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,GAAG,CAAuB,CAAC;AAC1C,CAAC,6HAEoB,WAAmB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AACxC,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';\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];\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 } = request;\n\n const responseTransactions = await this.#getTransactions(request);\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = responseTransactions.map((tx) =>\n 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 #getTransactions(request: RemoteTransactionSourceRequest) {\n log('Getting transactions', request);\n\n const { address, cache, chainIds: requestedChainIds } = request;\n\n const chainIds = requestedChainIds.filter((chainId) =>\n SUPPORTED_CHAIN_IDS.includes(chainId),\n );\n\n const unsupportedChainIds = requestedChainIds.filter(\n (chainId) => !chainIds.includes(chainId),\n );\n\n if (unsupportedChainIds.length) {\n log('Ignoring unsupported chain IDs', unsupportedChainIds);\n }\n\n const cursor = this.#getCacheCursor(cache, chainIds, address);\n\n if (cursor) {\n log('Using cached cursor', cursor);\n }\n\n return await this.#queryTransactions(request, chainIds, cursor);\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n cursor?: string,\n ): Promise<TransactionResponse[]> {\n const { address, queryEntireHistory, updateCache } = request;\n const transactions: TransactionResponse[] = [];\n\n let hasNextPage = true;\n let currentCursor = cursor;\n let pageCount = 0;\n\n const startTimestamp =\n queryEntireHistory || cursor\n ? undefined\n : this.#getTimestampSeconds(Date.now());\n\n while (hasNextPage) {\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n cursor: currentCursor,\n sortDirection: 'ASC',\n startTimestamp,\n });\n\n pageCount += 1;\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n\n hasNextPage = response?.pageInfo?.hasNextPage;\n currentCursor = response?.pageInfo?.cursor;\n\n if (currentCursor) {\n // eslint-disable-next-line no-loop-func\n updateCache((cache) => {\n const key = this.#getCacheKey(chainIds, address);\n cache[key] = currentCursor;\n\n log('Updated cache', { key, newCursor: currentCursor });\n });\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n break;\n }\n }\n\n log('Queried transactions', { pageCount });\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ) {\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 #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): TransactionMeta {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as Hex;\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 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() && vt.contractAddress,\n );\n\n const isTransfer = Boolean(valueTransfer);\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(valueTransfer?.amount ?? responseTransaction.value),\n );\n\n const to = valueTransfer ? 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 = isTransfer\n ? {\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n return {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n }\n\n #getCacheKey(chainIds: Hex[], address: Hex): string {\n return `accounts-api#${chainIds.join(',')}#${address}`;\n }\n\n #getCacheCursor(\n cache: Record<string, unknown>,\n chainIds: Hex[],\n address: Hex,\n ): string | undefined {\n const key = this.#getCacheKey(chainIds, address);\n return cache[key] as string | undefined;\n }\n\n #getTimestampSeconds(timestampMs: number): number {\n return Math.floor(timestampMs / 1000);\n }\n}\n"]}
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;AAEjD,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;CACjB,CAAC;AAEF,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAC5B,mCAA0B,EAC1B,qBAAqB,CACtB,CAAC;AAEF;;GAEG;AACH,MAAa,kCAAkC;IAA/C;;IAmOA,CAAC;IAhOC,kBAAkB;QAChB,OAAO,2BAAmB,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,OAAuC;QAEvC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAE5B,MAAM,oBAAoB,GAAG,MAAM,uBAAA,IAAI,0GAAiB,MAArB,IAAI,EAAkB,OAAO,CAAC,CAAC;QAElE,GAAG,CACD,sBAAsB,EACtB,oBAAoB,CAAC,MAAM,EAC3B,oBAAoB,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QACzD,eAAe,EAAE,EAAE;QACnB,MAAM;QACN,IAAI;QACJ,eAAe,EAAE,KAAK;QACtB,mBAAmB;QACnB,QAAQ,EAAE;YACR,OAAO;YACP,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,OAAO;YACP,KAAK;YACL,EAAE;YACF,KAAK;SACN;QACD,IAAI;QACJ,oBAAoB;KACrB,CAAC;AACJ,CAAC,6GAEY,QAAe,EAAE,OAAY;IACxC,OAAO,gBAAgB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;AACzD,CAAC,mHAGC,KAA8B,EAC9B,QAAe,EACf,OAAY;IAEZ,MAAM,GAAG,GAAG,uBAAA,IAAI,sGAAa,MAAjB,IAAI,EAAc,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,GAAG,CAAuB,CAAC;AAC1C,CAAC,6HAEoB,WAAmB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AACxC,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';\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];\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 } = request;\n\n const responseTransactions = await this.#getTransactions(request);\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = responseTransactions.map((tx) =>\n 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 #getTransactions(request: RemoteTransactionSourceRequest) {\n log('Getting transactions', request);\n\n const { address, cache } = request;\n\n const cursor = this.#getCacheCursor(cache, SUPPORTED_CHAIN_IDS, address);\n\n if (cursor) {\n log('Using cached cursor', cursor);\n }\n\n return await this.#queryTransactions(request, SUPPORTED_CHAIN_IDS, cursor);\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n cursor?: string,\n ): Promise<TransactionResponse[]> {\n const { address, queryEntireHistory, updateCache } = request;\n const transactions: TransactionResponse[] = [];\n\n let hasNextPage = true;\n let currentCursor = cursor;\n let pageCount = 0;\n\n const startTimestamp =\n queryEntireHistory || cursor\n ? undefined\n : this.#getTimestampSeconds(Date.now());\n\n while (hasNextPage) {\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n cursor: currentCursor,\n sortDirection: 'ASC',\n startTimestamp,\n });\n\n pageCount += 1;\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n\n hasNextPage = response?.pageInfo?.hasNextPage;\n currentCursor = response?.pageInfo?.cursor;\n\n if (currentCursor) {\n // eslint-disable-next-line no-loop-func\n updateCache((cache) => {\n const key = this.#getCacheKey(chainIds, address);\n cache[key] = currentCursor;\n\n log('Updated cache', { key, newCursor: currentCursor });\n });\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n break;\n }\n }\n\n log('Queried transactions', { pageCount });\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ) {\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 #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): TransactionMeta {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as Hex;\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 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() && vt.contractAddress,\n );\n\n const isTransfer = Boolean(valueTransfer);\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(valueTransfer?.amount ?? responseTransaction.value),\n );\n\n const to = valueTransfer ? 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 = isTransfer\n ? {\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n return {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n }\n\n #getCacheKey(chainIds: Hex[], address: Hex): string {\n return `accounts-api#${chainIds.join(',')}#${address}`;\n }\n\n #getCacheCursor(\n cache: Record<string, unknown>,\n chainIds: Hex[],\n address: Hex,\n ): string | undefined {\n const key = this.#getCacheKey(chainIds, address);\n return cache[key] as string | undefined;\n }\n\n #getTimestampSeconds(timestampMs: number): number {\n return Math.floor(timestampMs / 1000);\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;AAW3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EASpC,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;CAsO9B"}
1
+ {"version":3,"file":"AccountsApiRemoteTransactionSource.d.cts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAW3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EASpC,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;CA0N9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsApiRemoteTransactionSource.d.mts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAW3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EASpC,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;CAsO9B"}
1
+ {"version":3,"file":"AccountsApiRemoteTransactionSource.d.mts","sourceRoot":"","sources":["../../src/helpers/AccountsApiRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAW3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAE9B,eAAe,EAChB,qBAAiB;AAGlB,eAAO,MAAM,mBAAmB,EAAE,GAAG,EASpC,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;CA0N9B"}
@@ -52,17 +52,12 @@ export class AccountsApiRemoteTransactionSource {
52
52
  }
53
53
  _AccountsApiRemoteTransactionSource_instances = new WeakSet(), _AccountsApiRemoteTransactionSource_getTransactions = async function _AccountsApiRemoteTransactionSource_getTransactions(request) {
54
54
  log('Getting transactions', request);
55
- const { address, cache, chainIds: requestedChainIds } = request;
56
- const chainIds = requestedChainIds.filter((chainId) => SUPPORTED_CHAIN_IDS.includes(chainId));
57
- const unsupportedChainIds = requestedChainIds.filter((chainId) => !chainIds.includes(chainId));
58
- if (unsupportedChainIds.length) {
59
- log('Ignoring unsupported chain IDs', unsupportedChainIds);
60
- }
61
- const cursor = __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_getCacheCursor).call(this, cache, chainIds, address);
55
+ const { address, cache } = request;
56
+ const cursor = __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_getCacheCursor).call(this, cache, SUPPORTED_CHAIN_IDS, address);
62
57
  if (cursor) {
63
58
  log('Using cached cursor', cursor);
64
59
  }
65
- return await __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_queryTransactions).call(this, request, chainIds, cursor);
60
+ return await __classPrivateFieldGet(this, _AccountsApiRemoteTransactionSource_instances, "m", _AccountsApiRemoteTransactionSource_queryTransactions).call(this, request, SUPPORTED_CHAIN_IDS, cursor);
66
61
  }, _AccountsApiRemoteTransactionSource_queryTransactions = async function _AccountsApiRemoteTransactionSource_queryTransactions(request, chainIds, cursor) {
67
62
  const { address, queryEntireHistory, updateCache } = request;
68
63
  const transactions = [];
@@ -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,EAA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,EAAE,KAAK;QACtB,mBAAmB;QACnB,QAAQ,EAAE;YACR,OAAO;YACP,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,OAAO;YACP,KAAK;YACL,EAAE;YACF,KAAK;SACN;QACD,IAAI;QACJ,oBAAoB;KACrB,CAAC;AACJ,CAAC,6GAEY,QAAe,EAAE,OAAY;IACxC,OAAO,gBAAgB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;AACzD,CAAC,mHAGC,KAA8B,EAC9B,QAAe,EACf,OAAY;IAEZ,MAAM,GAAG,GAAG,uBAAA,IAAI,sGAAa,MAAjB,IAAI,EAAc,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,GAAG,CAAuB,CAAC;AAC1C,CAAC,6HAEoB,WAAmB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AACxC,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';\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];\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 } = request;\n\n const responseTransactions = await this.#getTransactions(request);\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = responseTransactions.map((tx) =>\n 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 #getTransactions(request: RemoteTransactionSourceRequest) {\n log('Getting transactions', request);\n\n const { address, cache, chainIds: requestedChainIds } = request;\n\n const chainIds = requestedChainIds.filter((chainId) =>\n SUPPORTED_CHAIN_IDS.includes(chainId),\n );\n\n const unsupportedChainIds = requestedChainIds.filter(\n (chainId) => !chainIds.includes(chainId),\n );\n\n if (unsupportedChainIds.length) {\n log('Ignoring unsupported chain IDs', unsupportedChainIds);\n }\n\n const cursor = this.#getCacheCursor(cache, chainIds, address);\n\n if (cursor) {\n log('Using cached cursor', cursor);\n }\n\n return await this.#queryTransactions(request, chainIds, cursor);\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n cursor?: string,\n ): Promise<TransactionResponse[]> {\n const { address, queryEntireHistory, updateCache } = request;\n const transactions: TransactionResponse[] = [];\n\n let hasNextPage = true;\n let currentCursor = cursor;\n let pageCount = 0;\n\n const startTimestamp =\n queryEntireHistory || cursor\n ? undefined\n : this.#getTimestampSeconds(Date.now());\n\n while (hasNextPage) {\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n cursor: currentCursor,\n sortDirection: 'ASC',\n startTimestamp,\n });\n\n pageCount += 1;\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n\n hasNextPage = response?.pageInfo?.hasNextPage;\n currentCursor = response?.pageInfo?.cursor;\n\n if (currentCursor) {\n // eslint-disable-next-line no-loop-func\n updateCache((cache) => {\n const key = this.#getCacheKey(chainIds, address);\n cache[key] = currentCursor;\n\n log('Updated cache', { key, newCursor: currentCursor });\n });\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n break;\n }\n }\n\n log('Queried transactions', { pageCount });\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ) {\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 #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): TransactionMeta {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as Hex;\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 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() && vt.contractAddress,\n );\n\n const isTransfer = Boolean(valueTransfer);\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(valueTransfer?.amount ?? responseTransaction.value),\n );\n\n const to = valueTransfer ? 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 = isTransfer\n ? {\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n return {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n }\n\n #getCacheKey(chainIds: Hex[], address: Hex): string {\n return `accounts-api#${chainIds.join(',')}#${address}`;\n }\n\n #getCacheCursor(\n cache: Record<string, unknown>,\n chainIds: Hex[],\n address: Hex,\n ): string | undefined {\n const key = this.#getCacheKey(chainIds, address);\n return cache[key] as string | undefined;\n }\n\n #getTimestampSeconds(timestampMs: number): number {\n return Math.floor(timestampMs / 1000);\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;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;AAE9D,MAAM,CAAC,MAAM,mBAAmB,GAAU;IACxC,SAAS,CAAC,OAAO;IACjB,SAAS,CAAC,OAAO;IACjB,SAAS,CAAC,GAAG;IACb,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E,MAAM,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAC3D,CAAC;IAEF,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,CAAC;IAE5D,MAAM,KAAK,GACT,MAAM,KAAK,iBAAiB,CAAC,MAAM;QACjC,CAAC,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC;QACjC,CAAC,CAAE,SAAyC,CAAC;IAEjD,MAAM,mBAAmB,GAAG,UAAU;QACpC,CAAC,CAAC;YACE,eAAe;YACf,QAAQ;YACR,MAAM;SACP;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,WAAW;QACX,OAAO;QACP,KAAK;QACL,IAAI;QACJ,EAAE;QACF,UAAU;QACV,yDAAyD;QACzD,eAAe,EAAE,EAAE;QACnB,MAAM;QACN,IAAI;QACJ,eAAe,EAAE,KAAK;QACtB,mBAAmB;QACnB,QAAQ,EAAE;YACR,OAAO;YACP,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,OAAO;YACP,KAAK;YACL,EAAE;YACF,KAAK;SACN;QACD,IAAI;QACJ,oBAAoB;KACrB,CAAC;AACJ,CAAC,6GAEY,QAAe,EAAE,OAAY;IACxC,OAAO,gBAAgB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;AACzD,CAAC,mHAGC,KAA8B,EAC9B,QAAe,EACf,OAAY;IAEZ,MAAM,GAAG,GAAG,uBAAA,IAAI,sGAAa,MAAjB,IAAI,EAAc,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,GAAG,CAAuB,CAAC;AAC1C,CAAC,6HAEoB,WAAmB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AACxC,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';\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];\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 } = request;\n\n const responseTransactions = await this.#getTransactions(request);\n\n log(\n 'Fetched transactions',\n responseTransactions.length,\n responseTransactions,\n );\n\n const normalizedTransactions = responseTransactions.map((tx) =>\n 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 #getTransactions(request: RemoteTransactionSourceRequest) {\n log('Getting transactions', request);\n\n const { address, cache } = request;\n\n const cursor = this.#getCacheCursor(cache, SUPPORTED_CHAIN_IDS, address);\n\n if (cursor) {\n log('Using cached cursor', cursor);\n }\n\n return await this.#queryTransactions(request, SUPPORTED_CHAIN_IDS, cursor);\n }\n\n async #queryTransactions(\n request: RemoteTransactionSourceRequest,\n chainIds: Hex[],\n cursor?: string,\n ): Promise<TransactionResponse[]> {\n const { address, queryEntireHistory, updateCache } = request;\n const transactions: TransactionResponse[] = [];\n\n let hasNextPage = true;\n let currentCursor = cursor;\n let pageCount = 0;\n\n const startTimestamp =\n queryEntireHistory || cursor\n ? undefined\n : this.#getTimestampSeconds(Date.now());\n\n while (hasNextPage) {\n try {\n const response = await getAccountTransactions({\n address,\n chainIds,\n cursor: currentCursor,\n sortDirection: 'ASC',\n startTimestamp,\n });\n\n pageCount += 1;\n\n if (response?.data) {\n transactions.push(...response.data);\n }\n\n hasNextPage = response?.pageInfo?.hasNextPage;\n currentCursor = response?.pageInfo?.cursor;\n\n if (currentCursor) {\n // eslint-disable-next-line no-loop-func\n updateCache((cache) => {\n const key = this.#getCacheKey(chainIds, address);\n cache[key] = currentCursor;\n\n log('Updated cache', { key, newCursor: currentCursor });\n });\n }\n } catch (error) {\n log('Error while fetching transactions', error);\n break;\n }\n }\n\n log('Queried transactions', { pageCount });\n\n return transactions;\n }\n\n #filterTransactions(\n request: RemoteTransactionSourceRequest,\n transactions: TransactionMeta[],\n ) {\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 #normalizeTransaction(\n address: Hex,\n responseTransaction: GetAccountTransactionsResponse['data'][0],\n ): TransactionMeta {\n const blockNumber = String(responseTransaction.blockNumber);\n const chainId = `0x${responseTransaction.chainId.toString(16)}` as Hex;\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 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() && vt.contractAddress,\n );\n\n const isTransfer = Boolean(valueTransfer);\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(valueTransfer?.amount ?? responseTransaction.value),\n );\n\n const to = valueTransfer ? 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 = isTransfer\n ? {\n contractAddress,\n decimals,\n symbol,\n }\n : undefined;\n\n return {\n blockNumber,\n chainId,\n error,\n hash,\n id,\n isTransfer,\n // Populated by TransactionController when added to state\n networkClientId: '',\n status,\n time,\n toSmartContract: false,\n transferInformation,\n txParams: {\n chainId,\n from,\n gas,\n gasPrice,\n gasUsed,\n nonce,\n to,\n value,\n },\n type,\n verifiedOnBlockchain,\n };\n }\n\n #getCacheKey(chainIds: Hex[], address: Hex): string {\n return `accounts-api#${chainIds.join(',')}#${address}`;\n }\n\n #getCacheCursor(\n cache: Record<string, unknown>,\n chainIds: Hex[],\n address: Hex,\n ): string | undefined {\n const key = this.#getCacheKey(chainIds, address);\n return cache[key] as string | undefined;\n }\n\n #getTimestampSeconds(timestampMs: number): number {\n return Math.floor(timestampMs / 1000);\n }\n}\n"]}
@@ -15,7 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  var _GasFeePoller_instances, _GasFeePoller_findNetworkClientIdByChainId, _GasFeePoller_gasFeeFlows, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getProvider, _GasFeePoller_getTransactions, _GasFeePoller_layer1GasFeeFlows, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateUnapprovedTransaction, _GasFeePoller_updateTransactionGasFeeEstimates, _GasFeePoller_updateTransactionLayer1GasFee, _GasFeePoller_getUnapprovedTransactions, _GasFeePoller_getGasFeeControllerData;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.GasFeePoller = void 0;
18
+ exports.updateTransactionGasFees = exports.GasFeePoller = void 0;
19
19
  const eth_query_1 = __importDefault(require("@metamask/eth-query"));
20
20
  const utils_1 = require("@metamask/utils");
21
21
  // This package purposefully relies on Node's EventEmitter module.
@@ -185,4 +185,76 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
185
185
  });
186
186
  return new Map(await Promise.all(entryPromises));
187
187
  };
188
+ /**
189
+ * Update the gas fees for a transaction.
190
+ *
191
+ * @param args - Argument bag.
192
+ * @param args.txMeta - The transaction meta.
193
+ * @param args.gasFeeEstimates - The gas fee estimates.
194
+ * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.
195
+ * @param args.getEIP1559Compatibility - A function for verifying a network is EIP-1559 compatible.
196
+ * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
197
+ * @param args.layer1GasFee - The layer 1 gas fee.
198
+ */
199
+ async function updateTransactionGasFees({ txMeta, getEIP1559Compatibility, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }) {
200
+ const userFeeLevel = txMeta.userFeeLevel;
201
+ const isUsingGasFeeEstimateLevel = Object.values(types_1.GasFeeEstimateLevel).includes(userFeeLevel);
202
+ const { type: gasEstimateType } = gasFeeEstimates ?? {};
203
+ if (isTxParamsGasFeeUpdatesEnabled && isUsingGasFeeEstimateLevel) {
204
+ const isEIP1559Compatible = txMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy &&
205
+ (await getEIP1559Compatibility(txMeta.networkClientId));
206
+ if (isEIP1559Compatible) {
207
+ // Handle EIP-1559 compatible transactions
208
+ if (gasEstimateType === types_1.GasFeeEstimateType.FeeMarket) {
209
+ const feeMarketGasFeeEstimates = gasFeeEstimates;
210
+ txMeta.txParams.maxFeePerGas =
211
+ feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;
212
+ txMeta.txParams.maxPriorityFeePerGas =
213
+ feeMarketGasFeeEstimates[userFeeLevel].maxPriorityFeePerGas;
214
+ }
215
+ if (gasEstimateType === types_1.GasFeeEstimateType.GasPrice) {
216
+ const gasPriceGasFeeEstimates = gasFeeEstimates;
217
+ txMeta.txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;
218
+ txMeta.txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;
219
+ }
220
+ if (gasEstimateType === types_1.GasFeeEstimateType.Legacy) {
221
+ const legacyGasFeeEstimates = gasFeeEstimates;
222
+ const gasPrice = legacyGasFeeEstimates[userFeeLevel];
223
+ txMeta.txParams.maxFeePerGas = gasPrice;
224
+ txMeta.txParams.maxPriorityFeePerGas = gasPrice;
225
+ }
226
+ // Remove gasPrice for EIP-1559 transactions
227
+ delete txMeta.txParams.gasPrice;
228
+ }
229
+ else {
230
+ // Handle non-EIP-1559 transactions
231
+ if (gasEstimateType === types_1.GasFeeEstimateType.FeeMarket) {
232
+ const feeMarketGasFeeEstimates = gasFeeEstimates;
233
+ txMeta.txParams.gasPrice =
234
+ feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;
235
+ }
236
+ if (gasEstimateType === types_1.GasFeeEstimateType.GasPrice) {
237
+ const gasPriceGasFeeEstimates = gasFeeEstimates;
238
+ txMeta.txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;
239
+ }
240
+ if (gasEstimateType === types_1.GasFeeEstimateType.Legacy) {
241
+ const legacyGasFeeEstimates = gasFeeEstimates;
242
+ txMeta.txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];
243
+ }
244
+ // Remove EIP-1559 specific parameters for legacy transactions
245
+ delete txMeta.txParams.maxFeePerGas;
246
+ delete txMeta.txParams.maxPriorityFeePerGas;
247
+ }
248
+ }
249
+ if (gasFeeEstimates) {
250
+ txMeta.gasFeeEstimates = gasFeeEstimates;
251
+ }
252
+ if (gasFeeEstimatesLoaded !== undefined) {
253
+ txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;
254
+ }
255
+ if (layer1GasFee) {
256
+ txMeta.layer1GasFee = layer1GasFee;
257
+ }
258
+ }
259
+ exports.updateTransactionGasFees = updateTransactionGasFees;
188
260
  //# sourceMappingURL=GasFeePoller.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.cjs","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oEAA2C;AAO3C,2CAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA0C;AAO1C,wCAAmE;AACnE,oDAAkD;AAClD,0EAA0E;AAE1E,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAa,YAAY;IAuBvB;;;;;;;;;;;OAWG;IACH,YAAY,EACV,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,aAAa,GAWd;;QApDD,QAAG,GAAiB,IAAI,gBAAY,EAAE,CAAC;QAE9B,6DAEwB;QAExB,4CAA2B;QAE3B,6DAEiB;QAEjB,4CAA6D;QAE7D,gDAA0C;QAE1C,kDAAuC;QAEhD,wCAAoD;QAEpD,gCAAW,KAAK,EAAC;QAiCf,uBAAA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8B,MAAlC,IAAI,EAA+B,EAAE,eAAe,EAAE,CAAC;SACrD,CAAC;IACb,CAAC,CACF,CAAC;IAEF,OAAO,IAAI,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\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 readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\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 findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\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 return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\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 gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(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 gasFeeControllerData,\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 { networkClientId } = transactionMeta;\n const provider = this.#getProvider(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 async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n"]}
1
+ {"version":3,"file":"GasFeePoller.cjs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AM,CAAC,QAAQ,CAAC,QAAQ;oBACtB,wBAAwB,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC;aACvD;YAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,QAAQ,EAAE;gBACnD,MAAM,uBAAuB,GAC3B,eAA0C,CAAC;gBAC7C,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;aAC7D;YAED,IAAI,eAAe,KAAK,0BAAkB,CAAC,MAAM,EAAE;gBACjD,MAAM,qBAAqB,GAAG,eAAwC,CAAC;gBACvE,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;aAChE;YAED,8DAA8D;YAC9D,OAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC;YACpC,OAAO,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC;SAC7C;KACF;IAED,IAAI,eAAe,EAAE;QACnB,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;KAC1C;IAED,IAAI,qBAAqB,KAAK,SAAS,EAAE;QACvC,MAAM,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;KACtD;IAED,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;KACpC;AACH,CAAC;AA9FD,4DA8FC","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasPriceGasFeeEstimates,\n FeeMarketGasFeeEstimates,\n Layer1GasFeeFlow,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionStatus,\n TransactionEnvelopeType,\n} 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 readonly #findNetworkClientIdByChainId: (\n chainId: Hex,\n ) => NetworkClientId | undefined;\n\n readonly #gasFeeFlows: GasFeeFlow[];\n\n readonly #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n readonly #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n *\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\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 findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\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 return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\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 gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(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 gasFeeControllerData,\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 { networkClientId } = transactionMeta;\n const provider = this.#getProvider(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 async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n\n/**\n * Update the gas fees for a transaction.\n *\n * @param args - Argument bag.\n * @param args.txMeta - The transaction meta.\n * @param args.gasFeeEstimates - The gas fee estimates.\n * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.\n * @param args.getEIP1559Compatibility - A function for verifying a network is EIP-1559 compatible.\n * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.\n * @param args.layer1GasFee - The layer 1 gas fee.\n */\nexport async function updateTransactionGasFees({\n txMeta,\n getEIP1559Compatibility,\n gasFeeEstimates,\n gasFeeEstimatesLoaded,\n isTxParamsGasFeeUpdatesEnabled,\n layer1GasFee,\n}: {\n txMeta: TransactionMeta;\n getEIP1559Compatibility: (\n networkClientId: NetworkClientId,\n ) => Promise<boolean>;\n gasFeeEstimates?: GasFeeEstimates;\n gasFeeEstimatesLoaded?: boolean;\n isTxParamsGasFeeUpdatesEnabled: boolean;\n layer1GasFee?: Hex;\n}): Promise<void> {\n const userFeeLevel = txMeta.userFeeLevel as GasFeeEstimateLevel;\n const isUsingGasFeeEstimateLevel =\n Object.values(GasFeeEstimateLevel).includes(userFeeLevel);\n const { type: gasEstimateType } = gasFeeEstimates ?? {};\n\n if (isTxParamsGasFeeUpdatesEnabled && isUsingGasFeeEstimateLevel) {\n const isEIP1559Compatible =\n txMeta.txParams.type !== TransactionEnvelopeType.legacy &&\n (await getEIP1559Compatibility(txMeta.networkClientId));\n\n if (isEIP1559Compatible) {\n // Handle EIP-1559 compatible transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n txMeta.txParams.maxPriorityFeePerGas =\n feeMarketGasFeeEstimates[userFeeLevel].maxPriorityFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n\n txMeta.txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n const gasPrice = legacyGasFeeEstimates[userFeeLevel];\n\n txMeta.txParams.maxFeePerGas = gasPrice;\n txMeta.txParams.maxPriorityFeePerGas = gasPrice;\n }\n\n // Remove gasPrice for EIP-1559 transactions\n delete txMeta.txParams.gasPrice;\n } else {\n // Handle non-EIP-1559 transactions\n if (gasEstimateType === GasFeeEstimateType.FeeMarket) {\n const feeMarketGasFeeEstimates =\n gasFeeEstimates as FeeMarketGasFeeEstimates;\n txMeta.txParams.gasPrice =\n feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;\n }\n\n if (gasEstimateType === GasFeeEstimateType.GasPrice) {\n const gasPriceGasFeeEstimates =\n gasFeeEstimates as GasPriceGasFeeEstimates;\n txMeta.txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;\n }\n\n if (gasEstimateType === GasFeeEstimateType.Legacy) {\n const legacyGasFeeEstimates = gasFeeEstimates as LegacyGasFeeEstimates;\n txMeta.txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];\n }\n\n // Remove EIP-1559 specific parameters for legacy transactions\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n }\n\n if (gasFeeEstimates) {\n txMeta.gasFeeEstimates = gasFeeEstimates;\n }\n\n if (gasFeeEstimatesLoaded !== undefined) {\n txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;\n }\n\n if (layer1GasFee) {\n txMeta.layer1GasFee = layer1GasFee;\n }\n}\n"]}
@@ -3,8 +3,7 @@ import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-
3
3
  import type { NetworkClientId, Provider } from "@metamask/network-controller";
4
4
  import type { Hex } from "@metamask/utils";
5
5
  import EventEmitter from "events";
6
- import type { GasFeeFlow, Layer1GasFeeFlow } from "../types.cjs";
7
- import { type TransactionMeta } from "../types.cjs";
6
+ import type { GasFeeEstimates, GasFeeFlow, Layer1GasFeeFlow, TransactionMeta } from "../types.cjs";
8
7
  /**
9
8
  * Automatically polls and updates suggested gas fees on unapproved transactions.
10
9
  */
@@ -33,4 +32,23 @@ export declare class GasFeePoller {
33
32
  onStateChange: (listener: () => void) => void;
34
33
  });
35
34
  }
35
+ /**
36
+ * Update the gas fees for a transaction.
37
+ *
38
+ * @param args - Argument bag.
39
+ * @param args.txMeta - The transaction meta.
40
+ * @param args.gasFeeEstimates - The gas fee estimates.
41
+ * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.
42
+ * @param args.getEIP1559Compatibility - A function for verifying a network is EIP-1559 compatible.
43
+ * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
44
+ * @param args.layer1GasFee - The layer 1 gas fee.
45
+ */
46
+ export declare function updateTransactionGasFees({ txMeta, getEIP1559Compatibility, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }: {
47
+ txMeta: TransactionMeta;
48
+ getEIP1559Compatibility: (networkClientId: NetworkClientId) => Promise<boolean>;
49
+ gasFeeEstimates?: GasFeeEstimates;
50
+ gasFeeEstimatesLoaded?: boolean;
51
+ isTxParamsGasFeeUpdatesEnabled: boolean;
52
+ layer1GasFee?: Hex;
53
+ }): Promise<void>;
36
54
  //# sourceMappingURL=GasFeePoller.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.d.cts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAEV,UAAU,EAEV,gBAAgB,EACjB,qBAAiB;AAClB,OAAO,EAAqB,KAAK,eAAe,EAAE,qBAAiB;AAQnE;;GAEG;AACH,qBAAa,YAAY;;IACvB,GAAG,EAAE,YAAY,CAAsB;IAsBvC;;;;;;;;;;;OAWG;gBACS,EACV,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,aAAa,GACd,EAAE;QACD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,eAAe,GAAG,SAAS,CAAC;QAC5E,WAAW,EAAE,UAAU,EAAE,CAAC;QAC1B,4BAA4B,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MAAM,IAAI,KAAK,IAAI,CAAC;KAC/C;CAsNF;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,MAAM,EACN,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,8BAA8B,EAC9B,YAAY,GACb,EAAE;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,uBAAuB,EAAE,CACvB,eAAe,EAAE,eAAe,KAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8BAA8B,EAAE,OAAO,CAAC;IACxC,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8EhB"}
@@ -3,8 +3,7 @@ import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-
3
3
  import type { NetworkClientId, Provider } from "@metamask/network-controller";
4
4
  import type { Hex } from "@metamask/utils";
5
5
  import EventEmitter from "events";
6
- import type { GasFeeFlow, Layer1GasFeeFlow } from "../types.mjs";
7
- import { type TransactionMeta } from "../types.mjs";
6
+ import type { GasFeeEstimates, GasFeeFlow, Layer1GasFeeFlow, TransactionMeta } from "../types.mjs";
8
7
  /**
9
8
  * Automatically polls and updates suggested gas fees on unapproved transactions.
10
9
  */
@@ -33,4 +32,23 @@ export declare class GasFeePoller {
33
32
  onStateChange: (listener: () => void) => void;
34
33
  });
35
34
  }
35
+ /**
36
+ * Update the gas fees for a transaction.
37
+ *
38
+ * @param args - Argument bag.
39
+ * @param args.txMeta - The transaction meta.
40
+ * @param args.gasFeeEstimates - The gas fee estimates.
41
+ * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.
42
+ * @param args.getEIP1559Compatibility - A function for verifying a network is EIP-1559 compatible.
43
+ * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
44
+ * @param args.layer1GasFee - The layer 1 gas fee.
45
+ */
46
+ export declare function updateTransactionGasFees({ txMeta, getEIP1559Compatibility, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }: {
47
+ txMeta: TransactionMeta;
48
+ getEIP1559Compatibility: (networkClientId: NetworkClientId) => Promise<boolean>;
49
+ gasFeeEstimates?: GasFeeEstimates;
50
+ gasFeeEstimatesLoaded?: boolean;
51
+ isTxParamsGasFeeUpdatesEnabled: boolean;
52
+ layer1GasFee?: Hex;
53
+ }): Promise<void>;
36
54
  //# sourceMappingURL=GasFeePoller.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GasFeePoller.d.mts","sourceRoot":"","sources":["../../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAEV,UAAU,EAEV,gBAAgB,EACjB,qBAAiB;AAClB,OAAO,EAAqB,KAAK,eAAe,EAAE,qBAAiB;AAQnE;;GAEG;AACH,qBAAa,YAAY;;IACvB,GAAG,EAAE,YAAY,CAAsB;IAsBvC;;;;;;;;;;;OAWG;gBACS,EACV,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,aAAa,GACd,EAAE;QACD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,eAAe,GAAG,SAAS,CAAC;QAC5E,WAAW,EAAE,UAAU,EAAE,CAAC;QAC1B,4BAA4B,EAAE,CAC5B,OAAO,EAAE,0BAA0B,KAChC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1B,WAAW,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,QAAQ,CAAC;QAC5D,eAAe,EAA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B,8BAA8B,EAC9B,YAAY,GACb,EAAE;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,uBAAuB,EAAE,CACvB,eAAe,EAAE,eAAe,KAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8BAA8B,EAAE,OAAO,CAAC;IACxC,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8EhB"}
@@ -23,7 +23,7 @@ import { createModuleLogger } from "@metamask/utils";
23
23
  // eslint-disable-next-line import-x/no-nodejs-modules
24
24
  import EventEmitter from "events";
25
25
  import { projectLogger } from "../logger.mjs";
26
- import { TransactionStatus } from "../types.mjs";
26
+ import { GasFeeEstimateLevel, GasFeeEstimateType, TransactionStatus, TransactionEnvelopeType } from "../types.mjs";
27
27
  import { getGasFeeFlow } from "../utils/gas-flow.mjs";
28
28
  import { getTransactionLayer1GasFee } from "../utils/layer1-gas-fee-flow.mjs";
29
29
  const log = createModuleLogger(projectLogger, 'gas-fee-poller');
@@ -185,4 +185,75 @@ _GasFeePoller_findNetworkClientIdByChainId = new WeakMap(), _GasFeePoller_gasFee
185
185
  });
186
186
  return new Map(await Promise.all(entryPromises));
187
187
  };
188
+ /**
189
+ * Update the gas fees for a transaction.
190
+ *
191
+ * @param args - Argument bag.
192
+ * @param args.txMeta - The transaction meta.
193
+ * @param args.gasFeeEstimates - The gas fee estimates.
194
+ * @param args.gasFeeEstimatesLoaded - Whether the gas fee estimates are loaded.
195
+ * @param args.getEIP1559Compatibility - A function for verifying a network is EIP-1559 compatible.
196
+ * @param args.isTxParamsGasFeeUpdatesEnabled - Whether to update the gas fee properties in `txParams`.
197
+ * @param args.layer1GasFee - The layer 1 gas fee.
198
+ */
199
+ export async function updateTransactionGasFees({ txMeta, getEIP1559Compatibility, gasFeeEstimates, gasFeeEstimatesLoaded, isTxParamsGasFeeUpdatesEnabled, layer1GasFee, }) {
200
+ const userFeeLevel = txMeta.userFeeLevel;
201
+ const isUsingGasFeeEstimateLevel = Object.values(GasFeeEstimateLevel).includes(userFeeLevel);
202
+ const { type: gasEstimateType } = gasFeeEstimates ?? {};
203
+ if (isTxParamsGasFeeUpdatesEnabled && isUsingGasFeeEstimateLevel) {
204
+ const isEIP1559Compatible = txMeta.txParams.type !== TransactionEnvelopeType.legacy &&
205
+ (await getEIP1559Compatibility(txMeta.networkClientId));
206
+ if (isEIP1559Compatible) {
207
+ // Handle EIP-1559 compatible transactions
208
+ if (gasEstimateType === GasFeeEstimateType.FeeMarket) {
209
+ const feeMarketGasFeeEstimates = gasFeeEstimates;
210
+ txMeta.txParams.maxFeePerGas =
211
+ feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;
212
+ txMeta.txParams.maxPriorityFeePerGas =
213
+ feeMarketGasFeeEstimates[userFeeLevel].maxPriorityFeePerGas;
214
+ }
215
+ if (gasEstimateType === GasFeeEstimateType.GasPrice) {
216
+ const gasPriceGasFeeEstimates = gasFeeEstimates;
217
+ txMeta.txParams.maxFeePerGas = gasPriceGasFeeEstimates.gasPrice;
218
+ txMeta.txParams.maxPriorityFeePerGas = gasPriceGasFeeEstimates.gasPrice;
219
+ }
220
+ if (gasEstimateType === GasFeeEstimateType.Legacy) {
221
+ const legacyGasFeeEstimates = gasFeeEstimates;
222
+ const gasPrice = legacyGasFeeEstimates[userFeeLevel];
223
+ txMeta.txParams.maxFeePerGas = gasPrice;
224
+ txMeta.txParams.maxPriorityFeePerGas = gasPrice;
225
+ }
226
+ // Remove gasPrice for EIP-1559 transactions
227
+ delete txMeta.txParams.gasPrice;
228
+ }
229
+ else {
230
+ // Handle non-EIP-1559 transactions
231
+ if (gasEstimateType === GasFeeEstimateType.FeeMarket) {
232
+ const feeMarketGasFeeEstimates = gasFeeEstimates;
233
+ txMeta.txParams.gasPrice =
234
+ feeMarketGasFeeEstimates[userFeeLevel].maxFeePerGas;
235
+ }
236
+ if (gasEstimateType === GasFeeEstimateType.GasPrice) {
237
+ const gasPriceGasFeeEstimates = gasFeeEstimates;
238
+ txMeta.txParams.gasPrice = gasPriceGasFeeEstimates.gasPrice;
239
+ }
240
+ if (gasEstimateType === GasFeeEstimateType.Legacy) {
241
+ const legacyGasFeeEstimates = gasFeeEstimates;
242
+ txMeta.txParams.gasPrice = legacyGasFeeEstimates[userFeeLevel];
243
+ }
244
+ // Remove EIP-1559 specific parameters for legacy transactions
245
+ delete txMeta.txParams.maxFeePerGas;
246
+ delete txMeta.txParams.maxPriorityFeePerGas;
247
+ }
248
+ }
249
+ if (gasFeeEstimates) {
250
+ txMeta.gasFeeEstimates = gasFeeEstimates;
251
+ }
252
+ if (gasFeeEstimatesLoaded !== undefined) {
253
+ txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;
254
+ }
255
+ if (layer1GasFee) {
256
+ txMeta.layer1GasFee = layer1GasFee;
257
+ }
258
+ }
188
259
  //# sourceMappingURL=GasFeePoller.mjs.map