@ledgerhq/coin-evm 9.0.1 → 10.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 (275) hide show
  1. package/.oxlintrc.json +2 -6
  2. package/CHANGELOG.md +18 -0
  3. package/lib/abis/index.d.ts +8 -0
  4. package/lib/abis/index.d.ts.map +1 -1
  5. package/lib/abis/index.js +30 -0
  6. package/lib/abis/index.js.map +1 -1
  7. package/lib/adapters/blockOperations.js +2 -2
  8. package/lib/adapters/blockOperations.js.map +1 -1
  9. package/lib/api/index.d.ts.map +1 -1
  10. package/lib/api/index.js +2 -1
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/internalTxSources.d.ts.map +1 -1
  13. package/lib/internalTxSources.js +21 -3
  14. package/lib/internalTxSources.js.map +1 -1
  15. package/lib/logic/common.d.ts.map +1 -1
  16. package/lib/logic/common.js +11 -3
  17. package/lib/logic/common.js.map +1 -1
  18. package/lib/logic/craftTransaction.d.ts.map +1 -1
  19. package/lib/logic/craftTransaction.js +4 -1
  20. package/lib/logic/craftTransaction.js.map +1 -1
  21. package/lib/logic/estimateFees.d.ts.map +1 -1
  22. package/lib/logic/estimateFees.js +4 -2
  23. package/lib/logic/estimateFees.js.map +1 -1
  24. package/lib/logic/getBalance.js +1 -1
  25. package/lib/logic/getBalance.js.map +1 -1
  26. package/lib/logic/internalTransactionsFetcher.js +2 -2
  27. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  28. package/lib/logic/listOperations.js +1 -1
  29. package/lib/logic/listOperations.js.map +1 -1
  30. package/lib/logic/predicates.d.ts +17 -0
  31. package/lib/logic/predicates.d.ts.map +1 -0
  32. package/lib/logic/predicates.js +126 -0
  33. package/lib/logic/predicates.js.map +1 -0
  34. package/lib/logic/validateIntent.d.ts.map +1 -1
  35. package/lib/logic/validateIntent.js +4 -6
  36. package/lib/logic/validateIntent.js.map +1 -1
  37. package/lib/network/explorer/index.d.ts +1 -1
  38. package/lib/network/explorer/index.d.ts.map +1 -1
  39. package/lib/network/explorer/index.js +2 -2
  40. package/lib/network/explorer/index.js.map +1 -1
  41. package/lib/network/explorer/ledger.js +3 -3
  42. package/lib/network/explorer/ledger.js.map +1 -1
  43. package/lib/network/explorer/types.d.ts.map +1 -1
  44. package/lib/network/explorer/types.js +11 -1
  45. package/lib/network/explorer/types.js.map +1 -1
  46. package/lib/network/gasTracker/ledger.d.ts +1 -2
  47. package/lib/network/gasTracker/ledger.d.ts.map +1 -1
  48. package/lib/network/gasTracker/ledger.js +3 -5
  49. package/lib/network/gasTracker/ledger.js.map +1 -1
  50. package/lib/network/gasTracker/types.d.ts +1 -2
  51. package/lib/network/gasTracker/types.d.ts.map +1 -1
  52. package/lib/network/gasTracker/types.js.map +1 -1
  53. package/lib/network/node/explorerProxy.d.ts.map +1 -1
  54. package/lib/network/node/explorerProxy.js +10 -5
  55. package/lib/network/node/explorerProxy.js.map +1 -1
  56. package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
  57. package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
  58. package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
  59. package/lib/network/node/index.js +1 -1
  60. package/lib/network/node/index.js.map +1 -1
  61. package/lib/network/node/ledger.d.ts.map +1 -1
  62. package/lib/network/node/ledger.js +11 -7
  63. package/lib/network/node/ledger.js.map +1 -1
  64. package/lib/network/node/rpc.common.d.ts.map +1 -1
  65. package/lib/network/node/rpc.common.js +60 -70
  66. package/lib/network/node/rpc.common.js.map +1 -1
  67. package/lib/network/node/types.d.ts +6 -7
  68. package/lib/network/node/types.d.ts.map +1 -1
  69. package/lib/network/node/types.js +0 -27
  70. package/lib/network/node/types.js.map +1 -1
  71. package/lib/nodeSources.d.ts.map +1 -1
  72. package/lib/nodeSources.js +11 -3
  73. package/lib/nodeSources.js.map +1 -1
  74. package/lib/staking/contracts.d.ts.map +1 -1
  75. package/lib/staking/contracts.js +1 -3
  76. package/lib/staking/contracts.js.map +1 -1
  77. package/lib/staking/detectOperationType.d.ts +0 -3
  78. package/lib/staking/detectOperationType.d.ts.map +1 -1
  79. package/lib/staking/detectOperationType.js +15 -14
  80. package/lib/staking/detectOperationType.js.map +1 -1
  81. package/lib/staking/fetchers.d.ts.map +1 -1
  82. package/lib/staking/fetchers.js +2 -3
  83. package/lib/staking/fetchers.js.map +1 -1
  84. package/lib/staking/operations/index.d.ts.map +1 -1
  85. package/lib/staking/operations/index.js +18 -1
  86. package/lib/staking/operations/index.js.map +1 -1
  87. package/lib/staking/prepareIntents.d.ts.map +1 -1
  88. package/lib/staking/prepareIntents.js +4 -3
  89. package/lib/staking/prepareIntents.js.map +1 -1
  90. package/lib/staking/redelegations.d.ts.map +1 -1
  91. package/lib/staking/redelegations.js +4 -7
  92. package/lib/staking/redelegations.js.map +1 -1
  93. package/lib/staking/unbondings.d.ts.map +1 -1
  94. package/lib/staking/unbondings.js +3 -4
  95. package/lib/staking/unbondings.js.map +1 -1
  96. package/lib/staking/utils.d.ts.map +1 -1
  97. package/lib/staking/utils.js +22 -27
  98. package/lib/staking/utils.js.map +1 -1
  99. package/lib/staking/validators/monad.d.ts.map +1 -1
  100. package/lib/staking/validators/monad.js +16 -8
  101. package/lib/staking/validators/monad.js.map +1 -1
  102. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  103. package/lib/staking/validators/monadResolver.js +4 -3
  104. package/lib/staking/validators/monadResolver.js.map +1 -1
  105. package/lib/staking/validators/somnia.js +5 -5
  106. package/lib/staking/validators/somnia.js.map +1 -1
  107. package/lib/staking/validators/zero_gravity.js +5 -5
  108. package/lib/staking/validators/zero_gravity.js.map +1 -1
  109. package/lib-es/abis/index.d.ts +8 -0
  110. package/lib-es/abis/index.d.ts.map +1 -1
  111. package/lib-es/abis/index.js +29 -0
  112. package/lib-es/abis/index.js.map +1 -1
  113. package/lib-es/adapters/blockOperations.js +1 -1
  114. package/lib-es/adapters/blockOperations.js.map +1 -1
  115. package/lib-es/api/index.d.ts.map +1 -1
  116. package/lib-es/api/index.js +2 -1
  117. package/lib-es/api/index.js.map +1 -1
  118. package/lib-es/internalTxSources.d.ts.map +1 -1
  119. package/lib-es/internalTxSources.js +21 -3
  120. package/lib-es/internalTxSources.js.map +1 -1
  121. package/lib-es/logic/common.d.ts.map +1 -1
  122. package/lib-es/logic/common.js +11 -3
  123. package/lib-es/logic/common.js.map +1 -1
  124. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  125. package/lib-es/logic/craftTransaction.js +4 -1
  126. package/lib-es/logic/craftTransaction.js.map +1 -1
  127. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  128. package/lib-es/logic/estimateFees.js +4 -2
  129. package/lib-es/logic/estimateFees.js.map +1 -1
  130. package/lib-es/logic/getBalance.js +1 -1
  131. package/lib-es/logic/getBalance.js.map +1 -1
  132. package/lib-es/logic/internalTransactionsFetcher.js +2 -2
  133. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  134. package/lib-es/logic/listOperations.js +1 -1
  135. package/lib-es/logic/listOperations.js.map +1 -1
  136. package/lib-es/logic/predicates.d.ts +17 -0
  137. package/lib-es/logic/predicates.d.ts.map +1 -0
  138. package/lib-es/logic/predicates.js +114 -0
  139. package/lib-es/logic/predicates.js.map +1 -0
  140. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  141. package/lib-es/logic/validateIntent.js +4 -6
  142. package/lib-es/logic/validateIntent.js.map +1 -1
  143. package/lib-es/network/explorer/index.d.ts +1 -1
  144. package/lib-es/network/explorer/index.d.ts.map +1 -1
  145. package/lib-es/network/explorer/index.js +2 -2
  146. package/lib-es/network/explorer/index.js.map +1 -1
  147. package/lib-es/network/explorer/ledger.js +3 -3
  148. package/lib-es/network/explorer/ledger.js.map +1 -1
  149. package/lib-es/network/explorer/types.d.ts.map +1 -1
  150. package/lib-es/network/explorer/types.js +11 -1
  151. package/lib-es/network/explorer/types.js.map +1 -1
  152. package/lib-es/network/gasTracker/ledger.d.ts +1 -2
  153. package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
  154. package/lib-es/network/gasTracker/ledger.js +3 -5
  155. package/lib-es/network/gasTracker/ledger.js.map +1 -1
  156. package/lib-es/network/gasTracker/types.d.ts +1 -2
  157. package/lib-es/network/gasTracker/types.d.ts.map +1 -1
  158. package/lib-es/network/gasTracker/types.js.map +1 -1
  159. package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
  160. package/lib-es/network/node/explorerProxy.js +10 -5
  161. package/lib-es/network/node/explorerProxy.js.map +1 -1
  162. package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
  163. package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
  164. package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
  165. package/lib-es/network/node/index.js +1 -1
  166. package/lib-es/network/node/index.js.map +1 -1
  167. package/lib-es/network/node/ledger.d.ts.map +1 -1
  168. package/lib-es/network/node/ledger.js +11 -7
  169. package/lib-es/network/node/ledger.js.map +1 -1
  170. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  171. package/lib-es/network/node/rpc.common.js +58 -68
  172. package/lib-es/network/node/rpc.common.js.map +1 -1
  173. package/lib-es/network/node/types.d.ts +6 -7
  174. package/lib-es/network/node/types.d.ts.map +1 -1
  175. package/lib-es/network/node/types.js +0 -25
  176. package/lib-es/network/node/types.js.map +1 -1
  177. package/lib-es/nodeSources.d.ts.map +1 -1
  178. package/lib-es/nodeSources.js +11 -3
  179. package/lib-es/nodeSources.js.map +1 -1
  180. package/lib-es/staking/contracts.d.ts.map +1 -1
  181. package/lib-es/staking/contracts.js +1 -3
  182. package/lib-es/staking/contracts.js.map +1 -1
  183. package/lib-es/staking/detectOperationType.d.ts +0 -3
  184. package/lib-es/staking/detectOperationType.d.ts.map +1 -1
  185. package/lib-es/staking/detectOperationType.js +15 -14
  186. package/lib-es/staking/detectOperationType.js.map +1 -1
  187. package/lib-es/staking/fetchers.d.ts.map +1 -1
  188. package/lib-es/staking/fetchers.js +2 -3
  189. package/lib-es/staking/fetchers.js.map +1 -1
  190. package/lib-es/staking/operations/index.d.ts.map +1 -1
  191. package/lib-es/staking/operations/index.js +18 -1
  192. package/lib-es/staking/operations/index.js.map +1 -1
  193. package/lib-es/staking/prepareIntents.d.ts.map +1 -1
  194. package/lib-es/staking/prepareIntents.js +2 -1
  195. package/lib-es/staking/prepareIntents.js.map +1 -1
  196. package/lib-es/staking/redelegations.d.ts.map +1 -1
  197. package/lib-es/staking/redelegations.js +1 -4
  198. package/lib-es/staking/redelegations.js.map +1 -1
  199. package/lib-es/staking/unbondings.d.ts.map +1 -1
  200. package/lib-es/staking/unbondings.js +3 -4
  201. package/lib-es/staking/unbondings.js.map +1 -1
  202. package/lib-es/staking/utils.d.ts.map +1 -1
  203. package/lib-es/staking/utils.js +20 -25
  204. package/lib-es/staking/utils.js.map +1 -1
  205. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  206. package/lib-es/staking/validators/monad.js +13 -5
  207. package/lib-es/staking/validators/monad.js.map +1 -1
  208. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  209. package/lib-es/staking/validators/monadResolver.js +2 -1
  210. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  211. package/lib-es/staking/validators/somnia.js +3 -3
  212. package/lib-es/staking/validators/somnia.js.map +1 -1
  213. package/lib-es/staking/validators/zero_gravity.js +3 -3
  214. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  215. package/package.json +2 -2
  216. package/src/abis/index.test.ts +36 -0
  217. package/src/abis/index.ts +30 -0
  218. package/src/adapters/blockOperations.ts +1 -1
  219. package/src/api/index.cronos.integ.test.ts +28 -0
  220. package/src/api/index.integ.test.ts +57 -94
  221. package/src/api/index.ts +3 -2
  222. package/src/internalTxSources.ts +20 -3
  223. package/src/logic/common.ts +13 -3
  224. package/src/logic/craftTransaction.ts +4 -2
  225. package/src/logic/estimateFees.ts +4 -3
  226. package/src/logic/getBalance.ts +1 -1
  227. package/src/logic/internalTransactionsFetcher.ts +2 -2
  228. package/src/logic/listOperations.ts +1 -1
  229. package/src/logic/predicates.ts +124 -0
  230. package/src/logic/tests/craftTransaction.test.ts +1 -1
  231. package/src/logic/tests/getStakes.test.ts +1 -0
  232. package/src/logic/tests/validateIntent.test.ts +4 -1
  233. package/src/logic/validateIntent.ts +2 -6
  234. package/src/network/explorer/index.test.ts +9 -16
  235. package/src/network/explorer/index.ts +2 -2
  236. package/src/network/explorer/ledger.test.ts +21 -15
  237. package/src/network/explorer/ledger.ts +3 -3
  238. package/src/network/explorer/types.ts +12 -3
  239. package/src/network/gasTracker/ledger.test.ts +0 -10
  240. package/src/network/gasTracker/ledger.ts +2 -7
  241. package/src/network/gasTracker/types.ts +0 -2
  242. package/src/network/node/explorerProxy.ts +11 -8
  243. package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
  244. package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
  245. package/src/network/node/index.ts +1 -1
  246. package/src/network/node/ledger.ts +15 -12
  247. package/src/network/node/rpc.common.ts +92 -88
  248. package/src/network/node/rpc.test.ts +119 -0
  249. package/src/network/node/types.ts +6 -35
  250. package/src/nodeSources.ts +11 -3
  251. package/src/staking/contracts.ts +1 -3
  252. package/src/staking/detectOperationType.ts +15 -14
  253. package/src/staking/fetchers.ts +2 -3
  254. package/src/staking/operations/index.test.ts +1 -0
  255. package/src/staking/operations/index.ts +26 -7
  256. package/src/staking/prepareIntents.ts +2 -1
  257. package/src/staking/redelegations.ts +1 -5
  258. package/src/staking/unbondings.ts +2 -4
  259. package/src/staking/utils.ts +19 -26
  260. package/src/staking/validators/monad.test.ts +6 -4
  261. package/src/staking/validators/monad.ts +12 -5
  262. package/src/staking/validators/monadResolver.ts +2 -1
  263. package/src/staking/validators/somnia.test.ts +1 -0
  264. package/src/staking/validators/somnia.ts +5 -5
  265. package/src/staking/validators/zero_gravity.test.ts +1 -0
  266. package/src/staking/validators/zero_gravity.ts +3 -3
  267. package/lib/logic/evmUnit.d.ts +0 -3
  268. package/lib/logic/evmUnit.d.ts.map +0 -1
  269. package/lib/logic/evmUnit.js +0 -94
  270. package/lib/logic/evmUnit.js.map +0 -1
  271. package/lib-es/logic/evmUnit.d.ts +0 -3
  272. package/lib-es/logic/evmUnit.d.ts.map +0 -1
  273. package/lib-es/logic/evmUnit.js +0 -91
  274. package/lib-es/logic/evmUnit.js.map +0 -1
  275. package/src/logic/evmUnit.ts +0 -93
@@ -34,7 +34,7 @@ export const getNodeApi = (config: EvmConfigInfo, currencyId: string, logger: Lo
34
34
  const type = node?.type
35
35
 
36
36
  if (type !== 'ledger' && type !== 'external') {
37
- throw new UnknownNode(`Unknown node "${type}" for currency: ${currencyId}`)
37
+ throw new UnknownNode(`Unknown node "${type}" for currency: ${config?.name}`)
38
38
  }
39
39
 
40
40
  const explorerUri = config.ledgerExplorerUri ?? DEFAULT_LEDGER_EXPLORER_URI
@@ -11,6 +11,7 @@ import { makeBatcher } from '@ledgerhq/live-network/batcher/index'
11
11
  import axios from 'axios'
12
12
  import BigNumber from 'bignumber.js'
13
13
  import { ethers } from 'ethers'
14
+ import { toInterfaceAbi } from '../../abis'
14
15
  import ERC20Abi from '../../abis/erc20.abi.json'
15
16
  import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.json'
16
17
  import { GasEstimationError } from '../../errors'
@@ -50,12 +51,12 @@ function makeFetchWithRetries(config: LedgerNodeApiConfig): LedgerFetch {
50
51
  }
51
52
  }
52
53
 
53
- function make<F extends (currencyId: string, ...args: any[]) => any>(
54
- f: (fetch: LedgerFetch, config: LedgerNodeApiConfig, ...args: Parameters<F>) => ReturnType<F>,
54
+ function make<Args extends readonly unknown[], R>(
55
+ f: (fetch: LedgerFetch, config: LedgerNodeApiConfig, currencyId: string, ...args: Args) => R,
55
56
  config: LedgerNodeApiConfig,
56
57
  fetch: LedgerFetch
57
- ): F {
58
- return ((...args: Parameters<F>) => f(fetch, config, ...args)) as F
58
+ ): (currencyId: string, ...args: Args) => R {
59
+ return (currencyId, ...args) => f(fetch, config, currencyId, ...args)
59
60
  }
60
61
 
61
62
  async function getTransaction(
@@ -200,18 +201,21 @@ async function getFeeData(
200
201
  _fetch: LedgerFetch,
201
202
  config: LedgerNodeApiConfig,
202
203
  evmConfig: Parameters<NodeApi['getFeeData']>[0],
203
- currencyId: Parameters<NodeApi['getFeeData']>[1],
204
+ _currencyId: Parameters<NodeApi['getFeeData']>[1],
204
205
  transaction: Parameters<NodeApi['getFeeData']>[2]
205
206
  ): Promise<Awaited<ReturnType<NodeApi['getFeeData']>>> {
206
207
  const options = await getGasOptions({
207
- currencyId,
208
208
  config: evmConfig,
209
209
  options: {
210
210
  useEIP1559: evmConfig.forceLegacyTransactions ? false : transaction.type === 2,
211
211
  overrideGasTracker: { type: 'ledger', explorerId: config.explorerId },
212
212
  },
213
213
  })
214
- return options?.[transaction.feesStrategy as keyof typeof options] ?? options.medium
214
+ const strategy = transaction.feesStrategy
215
+ if (strategy === 'slow' || strategy === 'medium' || strategy === 'fast') {
216
+ return options[strategy]
217
+ }
218
+ return options.medium
215
219
  }
216
220
 
217
221
  async function broadcastTransaction(
@@ -369,7 +373,7 @@ function makeGetTokenAllowance(
369
373
  config: LedgerNodeApiConfig,
370
374
  fetch: LedgerFetch
371
375
  ): NodeApi['getTokenAllowance'] {
372
- const iface = new ethers.Interface(ERC20Abi as ethers.InterfaceAbi)
376
+ const iface = new ethers.Interface(toInterfaceAbi(ERC20Abi))
373
377
  return async (_currencyId, ownerAddress, contractAddress, spenderAddress) => {
374
378
  const data = iface.encodeFunctionData('allowance', [
375
379
  ethers.getAddress(ownerAddress),
@@ -434,13 +438,12 @@ export function createLedgerNodeApi(config: LedgerNodeApiConfig, logger: Logger)
434
438
  getTokenBalance: makeGetTokenBalance(config, fetch, tokenBalancesBatchersMap),
435
439
  getTokenAllowance: makeGetTokenAllowance(config, fetch),
436
440
  getTransactionCount: make(getTransactionCount, config, fetch),
437
- getTransaction: ((currencyId, hash) =>
438
- getTransaction(fetch, config, currencyId, hash, logger)) as NodeApi['getTransaction'],
441
+ getTransaction: (currencyId, hash) => getTransaction(fetch, config, currencyId, hash, logger),
439
442
  getGasEstimation: makeGetGasEstimation(config, fetch, logger),
440
443
  // getFeeData takes `config` (EvmConfigInfo) first, not `currency`, so it doesn't fit the
441
444
  // currency-first `make` type bound; bind it directly (same fetch/config passthrough as `make`).
442
- getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) =>
443
- getFeeData(fetch, config, ...args)) as NodeApi['getFeeData'],
445
+ getFeeData: (evmConfig, currencyId, transaction) =>
446
+ getFeeData(fetch, config, evmConfig, currencyId, transaction),
444
447
  broadcastTransaction: make(broadcastTransaction, config, fetch),
445
448
  getOptimismAdditionalFees: make(getOptimismAdditionalFees, config, fetch),
446
449
  getScrollAdditionalFees: make(getScrollAdditionalFees, config, fetch),
@@ -6,7 +6,6 @@ import type { FeeHistory, FeeData } from '../../types'
6
6
  import type {
7
7
  NodeApi,
8
8
  ERC20Transfer,
9
- PrefetchedBlockTransaction,
10
9
  LogWithAddress,
11
10
  TransactionReceipt,
12
11
  TraceBlockItem,
@@ -25,6 +24,15 @@ import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.jso
25
24
  import ScrollGasPriceOracleAbi from '../../abis/scrollGasPriceOracle.abi.json'
26
25
  import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
27
26
  import { isSmartContractInput, safeEncodeEIP55, normalizeAddress } from '../../logic-public'
27
+ import {
28
+ isOptionalQuantity,
29
+ isOptionalString,
30
+ isQuantity,
31
+ isRecord,
32
+ isString,
33
+ isTraceBlockItem,
34
+ isTransactionReceipt,
35
+ } from '../../logic/predicates'
28
36
  import { withRetries } from '../withRetries'
29
37
  import { gethCallTracerToTraceBlockItems } from './gethCallTracerToTraceBlockItems'
30
38
  import {
@@ -34,7 +42,6 @@ import {
34
42
  isUnsupportedRpcMethodErrorMsg,
35
43
  isUnsupportedRpcMethodError,
36
44
  } from './rpc.errors'
37
- import { isTraceBlockItem } from './types'
38
45
 
39
46
  /**
40
47
  * ERC20 Transfer event topic: keccak256("Transfer(address,address,uint256)")
@@ -268,16 +275,17 @@ async function getTransaction(
268
275
  // Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
269
276
  // extra fields that contain L1 fees.
270
277
  // A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
271
- const [tx, receipt] = await Promise.all([
278
+ const [tx, rawReceipt] = await Promise.all([
272
279
  api.getTransaction(txHash),
273
- api.send('eth_getTransactionReceipt', [txHash]) as Promise<TransactionReceipt | null>,
280
+ api.send('eth_getTransactionReceipt', [txHash]),
274
281
  ])
275
282
 
276
- if (!tx || !receipt) {
283
+ if (!tx || !isTransactionReceipt(rawReceipt)) {
277
284
  throw new Error('Transaction or receipt not found')
278
285
  }
279
286
 
280
- const raw = receipt as TransactionReceipt & Record<string, unknown>
287
+ const receipt = rawReceipt
288
+ const raw = recordOf(receipt)
281
289
  const contractAddressRaw = raw.contractAddress
282
290
  const contractAddress =
283
291
  typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
@@ -285,19 +293,20 @@ async function getTransaction(
285
293
  : undefined
286
294
 
287
295
  const l1Fee = parseReceiptL1Fee(raw)
296
+ const envelopeType = receiptEnvelopeType(receipt.type)
288
297
 
289
298
  return {
290
299
  hash: tx.hash,
291
300
  blockHeight: tx.blockNumber ?? undefined,
292
301
  blockHash: tx.blockHash ?? undefined,
293
302
  nonce: tx.nonce,
294
- gasUsed: BigInt(receipt.gasUsed).toString(),
295
- gasPrice: BigInt(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0').toString(),
296
- status: receipt.status === null ? null : Number(receipt.status),
303
+ gasUsed: quantityToDecimal(receipt.gasUsed),
304
+ gasPrice: receiptGasPrice(receipt),
305
+ status: receiptStatus(receipt.status),
297
306
  value: tx.value.toString(),
298
307
  from: tx.from,
299
308
  to: tx.to ?? undefined,
300
- type: receipt.type !== undefined ? Number(receipt.type) : (tx.type ?? undefined),
309
+ type: envelopeType !== undefined ? envelopeType : (tx.type ?? undefined),
301
310
  ...(tx.data !== null && tx.data !== undefined && isSmartContractInput(tx.data)
302
311
  ? { input: tx.data }
303
312
  : {}),
@@ -597,23 +606,15 @@ async function getBlockByHeight(
597
606
  `Block ${blockHeight} contains malformed prefetched transaction at index ${index}`
598
607
  )
599
608
 
600
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
601
- const rawTx = tx as unknown as {
602
- data?: string
603
- // ethers v6: gasPrice is null for EIP-1559 (type-2) transactions
604
- gasPrice?: bigint | null
605
- maxFeePerGas?: bigint | null
606
- }
609
+ const data = tx.data
607
610
  return {
608
611
  hash: tx.hash,
609
612
  value: tx.value.toString(),
610
613
  from: tx.from,
611
614
  to: tx.to ?? undefined,
612
- ...(rawTx.data !== null && rawTx.data !== undefined && isSmartContractInput(rawTx.data)
613
- ? { input: rawTx.data }
614
- : {}),
615
+ ...(typeof data === 'string' && isSmartContractInput(data) ? { input: data } : {}),
615
616
  // EIP-1559 transactions have gasPrice: null; fall back to maxFeePerGas then 0
616
- gasPrice: (rawTx.gasPrice ?? rawTx.maxFeePerGas ?? 0n).toString(),
617
+ gasPrice: (tx.gasPrice ?? tx.maxFeePerGas ?? 0n).toString(),
617
618
  }
618
619
  })
619
620
 
@@ -631,11 +632,8 @@ async function getBlockByHeight(
631
632
  /** Specific error thrown by ethers when handling zksync blocks with missing signature fields in prefetched transactions */
632
633
  function isSignatureError(error: unknown): boolean {
633
634
  if (!hasErrorCode(error, 'INVALID_ARGUMENT')) return false
634
- if (typeof error !== 'object' || error === null) return false
635
-
636
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
637
- const ethersError = error as { argument?: unknown }
638
- return ethersError.argument === 'signature'
635
+ if (!isRecord(error)) return false
636
+ return error.argument === 'signature'
639
637
  }
640
638
 
641
639
  /**
@@ -662,10 +660,9 @@ async function getBlockByHeightFromRawRpc(
662
660
  ): Promise<BlockByHeightResult> {
663
661
  const blockTag = typeof blockHeight === 'number' ? ethers.toQuantity(blockHeight) : blockHeight
664
662
  const rawBlock = await api.send('eth_getBlockByNumber', [blockTag, prefetchTxs])
665
- if (typeof rawBlock !== 'object' || rawBlock === null)
666
- throw new Error('Invalid eth_getBlockByNumber response')
663
+ if (!isRecord(rawBlock)) throw new Error('Invalid eth_getBlockByNumber response')
667
664
 
668
- const block = rawBlock as Record<string, unknown>
665
+ const block = rawBlock
669
666
  if (typeof block.hash !== 'string')
670
667
  throw new Error('Malformed block hash in eth_getBlockByNumber')
671
668
  if (typeof block.parentHash !== 'string')
@@ -774,7 +771,7 @@ async function getBlockReceipts(
774
771
  if (!isTransactionReceipt(receipt))
775
772
  throw new Error(`Malformed eth_getBlockReceipts response at index ${index}`)
776
773
 
777
- const raw = receipt as Record<string, unknown>
774
+ const raw = recordOf(receipt)
778
775
  const contractAddressRaw = raw.contractAddress
779
776
  const contractAddress =
780
777
  typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
@@ -782,15 +779,16 @@ async function getBlockReceipts(
782
779
  : undefined
783
780
 
784
781
  const l1Fee = parseReceiptL1Fee(raw)
782
+ const envelopeType = receiptEnvelopeType(receipt.type)
785
783
 
786
784
  return {
787
785
  hash: receipt.transactionHash,
788
- gasUsed: BigInt(receipt.gasUsed).toString(),
789
- gasPrice: BigInt(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0').toString(),
790
- status: receipt.status === null ? null : Number(receipt.status),
786
+ gasUsed: quantityToDecimal(receipt.gasUsed),
787
+ gasPrice: receiptGasPrice(receipt),
788
+ status: receiptStatus(receipt.status),
791
789
  erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
792
790
  ...(contractAddress ? { contractAddress } : {}),
793
- ...(receipt.type !== undefined ? { type: Number(receipt.type) } : {}),
791
+ ...(envelopeType !== undefined ? { type: envelopeType } : {}),
794
792
  ...(l1Fee !== undefined ? { l1Fee } : {}),
795
793
  }
796
794
  })
@@ -853,30 +851,31 @@ function normalizeTraceBlockItems(traces: TraceBlockItem[]): TraceBlockItem[] {
853
851
  })
854
852
  }
855
853
 
856
- function isPrefetchedBlockTransaction(value: unknown): value is PrefetchedBlockTransaction {
854
+ type EthersPrefetchedTransaction = {
855
+ hash: string
856
+ value: string | bigint
857
+ from: string
858
+ to?: string | null
859
+ data?: string | null
860
+ gasPrice?: bigint | string | null
861
+ maxFeePerGas?: bigint | string | null
862
+ }
863
+
864
+ function recordOf(value: object): Record<string, unknown> {
865
+ if (isRecord(value)) return value
866
+ throw new Error('expected object')
867
+ }
868
+
869
+ function isPrefetchedBlockTransaction(value: unknown): value is EthersPrefetchedTransaction {
870
+ if (!isRecord(value)) return false
871
+ if (!isString(value.hash) || !isString(value.from) || !isQuantity(value.value)) return false
872
+ // gasPrice is intentionally not required: EIP-1559 (type-2) transactions have gasPrice: null
873
+ // in ethers v6, and the mapping falls back to maxFeePerGas ?? 0n
857
874
  return (
858
- typeof value === 'object' &&
859
- value !== null &&
860
- 'hash' in value &&
861
- 'value' in value &&
862
- 'from' in value &&
863
- // gasPrice is intentionally not required: EIP-1559 (type-2) transactions have gasPrice: null
864
- // in ethers v6, and the mapping falls back to maxFeePerGas ?? 0n
865
- ('gasPrice' in value
866
- ? value.gasPrice === null ||
867
- typeof value.gasPrice === 'bigint' ||
868
- typeof value.gasPrice === 'string'
869
- : true) &&
870
- ('to' in value
871
- ? typeof value.to === 'string' || value.to === null || value.to === undefined
872
- : true) &&
873
- typeof value.hash === 'string' &&
874
- (typeof value.value === 'string' || typeof value.value === 'bigint') &&
875
- typeof value.from === 'string' &&
876
- (!('data' in value) ||
877
- value.data === undefined ||
878
- value.data === null ||
879
- typeof value.data === 'string')
875
+ isOptionalString(value.to) &&
876
+ isOptionalQuantity(value.gasPrice) &&
877
+ isOptionalQuantity(value.maxFeePerGas) &&
878
+ isOptionalString(value.data)
880
879
  )
881
880
  }
882
881
 
@@ -892,18 +891,22 @@ function getPrefetchedBlockTransactions(block: ethers.Block): unknown[] | undefi
892
891
  }
893
892
  }
894
893
 
895
- function isTransactionReceipt(value: unknown): value is TransactionReceipt {
896
- return (
897
- typeof value === 'object' &&
898
- value !== null &&
899
- 'transactionHash' in value &&
900
- 'gasUsed' in value &&
901
- 'status' in value &&
902
- 'logs' in value &&
903
- typeof value.transactionHash === 'string' &&
904
- typeof value.gasUsed === 'string' &&
905
- Array.isArray(value.logs)
906
- )
894
+ function quantityToDecimal(value: string): string {
895
+ return BigInt(value).toString()
896
+ }
897
+
898
+ function receiptGasPrice(receipt: TransactionReceipt): string {
899
+ return quantityToDecimal(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0')
900
+ }
901
+
902
+ function receiptStatus(status: TransactionReceipt['status']): number | null {
903
+ if (status === null) return null
904
+ return Number(status)
905
+ }
906
+
907
+ function receiptEnvelopeType(type: TransactionReceipt['type']): number | undefined {
908
+ if (type === null || type === undefined) return undefined
909
+ return Number(type)
907
910
  }
908
911
 
909
912
  async function getOptimismAdditionalFees(
@@ -975,17 +978,15 @@ function cacheKeyOptimismL1Fees(
975
978
  return 'getOptimismL1BaseFee_' + currencyId + '_' + transaction
976
979
  }
977
980
 
978
- function make<F extends (currencyId: string, ...args: any[]) => any>(
979
- f: (api: JsonRpcProvider, ...args: Parameters<F>) => ReturnType<F>,
981
+ function make<Args extends readonly unknown[], R>(
982
+ f: (api: JsonRpcProvider, currencyId: string, ...args: Args) => Promise<R>,
980
983
  evmConfig: EvmConfigInfo,
981
984
  nodeConfig: ExternalNodeConfig,
982
985
  configOverride: Partial<ExternalNodeConfig> = {}
983
- ): F {
986
+ ): (currencyId: string, ...args: Args) => Promise<R> {
984
987
  const mergedConfig = { ...nodeConfig, ...configOverride }
985
- return ((...args: Parameters<F>) => {
986
- const [currencyId] = args
987
- return withApi(evmConfig, currencyId, (api) => f(api, ...args), mergedConfig)
988
- }) as F
988
+ return (currencyId, ...args) =>
989
+ withApi(evmConfig, currencyId, (api) => f(api, currencyId, ...args), mergedConfig)
989
990
  }
990
991
 
991
992
  export function createNodeApi(
@@ -995,47 +996,50 @@ export function createNodeApi(
995
996
  ): NodeApi {
996
997
  return {
997
998
  call: make(call, evmConfig, nodeConfig),
998
- getBlockByHeight: ((currencyId, blockHeight, prefetchTxs) =>
999
+ getBlockByHeight: (currencyId, blockHeight, prefetchTxs) =>
999
1000
  withApi(
1000
1001
  evmConfig,
1001
1002
  currencyId,
1002
1003
  (api) => getBlockByHeight(api, currencyId, blockHeight, logger, prefetchTxs),
1003
1004
  nodeConfig
1004
- )) as NodeApi['getBlockByHeight'],
1005
+ ),
1005
1006
  getCoinBalance: make(getCoinBalance, evmConfig, nodeConfig),
1006
1007
  getTokenBalance: make(getTokenBalance, evmConfig, nodeConfig),
1007
1008
  getTokenAllowance: make(getTokenAllowance, evmConfig, nodeConfig),
1008
1009
  getTransactionCount: make(getTransactionCount, evmConfig, nodeConfig),
1009
- getTransaction: ((currencyId, txHash) =>
1010
+ getTransaction: (currencyId, txHash) =>
1010
1011
  withApi(
1011
1012
  evmConfig,
1012
1013
  currencyId,
1013
1014
  (api) => getTransaction(api, currencyId, txHash, logger),
1014
1015
  nodeConfig
1015
- )) as NodeApi['getTransaction'],
1016
- getBlockReceipts: ((currencyId, blockHeight) =>
1016
+ ),
1017
+ getBlockReceipts: (currencyId, blockHeight) =>
1017
1018
  withApi(
1018
1019
  evmConfig,
1019
1020
  currencyId,
1020
1021
  (api) => getBlockReceipts(api, currencyId, blockHeight, logger),
1021
1022
  nodeConfig
1022
- )) as NonNullable<NodeApi['getBlockReceipts']>,
1023
+ ),
1023
1024
  traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
1024
1025
  traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
1025
1026
  getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
1026
1027
  // getFeeData takes `config` first (not `currencyId`), so it can't use the currencyId-first
1027
1028
  // `make` wrapper; bind it explicitly and pull `currencyId` from the second argument for `withApi`.
1028
- getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) => {
1029
- const [, currencyId] = args
1030
- return withApi(evmConfig, currencyId, (api) => getFeeData(api, ...args), nodeConfig)
1031
- }) as NodeApi['getFeeData'],
1032
- broadcastTransaction: ((currencyId, signedTxHex) =>
1029
+ getFeeData: (config, currencyId, transaction) =>
1030
+ withApi(
1031
+ evmConfig,
1032
+ currencyId,
1033
+ (api) => getFeeData(api, config, currencyId, transaction),
1034
+ nodeConfig
1035
+ ),
1036
+ broadcastTransaction: (currencyId, signedTxHex) =>
1033
1037
  withApi(
1034
1038
  evmConfig,
1035
1039
  currencyId,
1036
1040
  (api) => broadcastTransaction(api, currencyId, signedTxHex, logger),
1037
1041
  { ...nodeConfig, retries: 0 }
1038
- )) as NodeApi['broadcastTransaction'],
1042
+ ),
1039
1043
  getOptimismAdditionalFees: makeLRUCache(
1040
1044
  make(getOptimismAdditionalFees, evmConfig, nodeConfig),
1041
1045
  cacheKeyOptimismL1Fees,
@@ -326,6 +326,48 @@ describe('EVM Family', () => {
326
326
  expect(tx.l1Fee).toBeUndefined()
327
327
  })
328
328
 
329
+ it('should preserve a null pre-Byzantium status', async () => {
330
+ mockRawReceipt({ status: null, type: null })
331
+
332
+ const tx = await nodeApi.getTransaction(
333
+ currencyId,
334
+ '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
335
+ )
336
+
337
+ expect(tx.status).toBeNull()
338
+ expect(tx.type).toBe(0)
339
+ })
340
+
341
+ it.each([
342
+ ['status', { status: 'success' }],
343
+ ['gasUsed', { gasUsed: 'lots' }],
344
+ ['gasPrice', { gasPrice: {} }],
345
+ ['type', { type: 'eip1559' }],
346
+ ['logs', { logs: [42] }],
347
+ [
348
+ 'log data',
349
+ {
350
+ logs: [
351
+ {
352
+ address: '0x1111111111111111111111111111111111111111',
353
+ topics: [],
354
+ data: 'not-hex',
355
+ },
356
+ ],
357
+ },
358
+ ],
359
+ ['l1Fee', { l1Fee: 'nope' }],
360
+ ])('should reject a receipt with invalid %s', async (_field, overrides) => {
361
+ mockRawReceipt(overrides)
362
+
363
+ await expect(
364
+ nodeApi.getTransaction(
365
+ currencyId,
366
+ '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
367
+ )
368
+ ).rejects.toThrow('Transaction or receipt not found')
369
+ })
370
+
329
371
  it('should return the expected payload', async () => {
330
372
  expect(
331
373
  await nodeApi.getTransaction(
@@ -1448,6 +1490,83 @@ describe('EVM Family', () => {
1448
1490
  ])
1449
1491
  })
1450
1492
 
1493
+ it('should map a validated receipt, including log data later passed to BigInt', async () => {
1494
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
1495
+ if (method === 'eth_getBlockReceipts') {
1496
+ return [
1497
+ {
1498
+ transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
1499
+ gasUsed: '0x5208',
1500
+ effectiveGasPrice: null,
1501
+ gasPrice: '0x3b9aca00',
1502
+ status: 1,
1503
+ type: '0x2',
1504
+ logs: [
1505
+ {
1506
+ address: '0xabf26902fd7b624e0db40d31171ea9dddf078351',
1507
+ topics: [
1508
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
1509
+ '0x000000000000000000000000534eef6db44fbeb71047ee3eb4cb16e572862af6',
1510
+ '0x000000000000000000000000970402b253733a1f6f4f3cd1d07420006be2882d',
1511
+ ],
1512
+ data: '0x01',
1513
+ },
1514
+ ],
1515
+ },
1516
+ ]
1517
+ }
1518
+ throw new Error(`Method not mocked: ${method}`)
1519
+ })
1520
+
1521
+ expect(await nodeApi.getBlockReceipts!(currencyId, 1)).toEqual([
1522
+ {
1523
+ hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
1524
+ gasUsed: '21000',
1525
+ gasPrice: '1000000000',
1526
+ status: 1,
1527
+ type: 2,
1528
+ erc20Transfers: [
1529
+ {
1530
+ asset: {
1531
+ type: 'erc20',
1532
+ assetReference: '0xaBf26902Fd7B624e0db40D31171eA9ddDf078351',
1533
+ },
1534
+ from: '0x534eeF6Db44FBeB71047EE3eb4CB16E572862aF6',
1535
+ to: '0x970402B253733A1f6F4f3cd1d07420006be2882D',
1536
+ value: '1',
1537
+ },
1538
+ ],
1539
+ },
1540
+ ])
1541
+ })
1542
+
1543
+ it.each([
1544
+ ['status', { status: 'success' }],
1545
+ ['gasUsed', { gasUsed: '0x' }],
1546
+ ['effectiveGasPrice', { effectiveGasPrice: 'nope' }],
1547
+ ['type', { type: {} }],
1548
+ ['logs', { logs: [null] }],
1549
+ ])('should reject a receipt with invalid %s', async (_field, overrides) => {
1550
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
1551
+ if (method === 'eth_getBlockReceipts') {
1552
+ return [
1553
+ {
1554
+ transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
1555
+ gasUsed: '0x5208',
1556
+ status: '0x1',
1557
+ logs: [],
1558
+ ...overrides,
1559
+ },
1560
+ ]
1561
+ }
1562
+ throw new Error(`Method not mocked: ${method}`)
1563
+ })
1564
+
1565
+ await expect(nodeApi.getBlockReceipts!(currencyId, 1)).rejects.toThrow(
1566
+ 'Malformed eth_getBlockReceipts response at index 0'
1567
+ )
1568
+ })
1569
+
1451
1570
  it('should throw UnsupportedRpcMethodError for RPC -32601', async () => {
1452
1571
  jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
1453
1572
  if (method === 'eth_chainId') {
@@ -46,17 +46,6 @@ export type TraceBlockCallAction = {
46
46
  value: string
47
47
  }
48
48
 
49
- export function isTraceBlockCallAction(
50
- action: Record<string, unknown>
51
- ): action is TraceBlockCallAction {
52
- return (
53
- typeof action.from === 'string' &&
54
- typeof action.to === 'string' &&
55
- typeof action.callType === 'string' &&
56
- typeof action.value === 'string'
57
- )
58
- }
59
-
60
49
  /**
61
50
  * Other action types (e.g. reward, or other trace_block action shapes).
62
51
  * No specific fields are prescribed.
@@ -92,36 +81,18 @@ export type TraceBlockItem = {
92
81
  type: string
93
82
  }
94
83
 
95
- /** Type guard for {@link TraceBlockItem} (Erigon `trace_block` and Geth adapter output). */
96
- export function isTraceBlockItem(value: unknown): value is TraceBlockItem {
97
- if (typeof value !== 'object' || value === null) return false
98
- const o = value as Record<string, unknown>
99
- if (!o.action || typeof o.action !== 'object' || o.action === null) return false
100
- const action = o.action as Record<string, unknown>
101
- if (o.error !== undefined && typeof o.error !== 'string') return false
102
-
103
- const result = o.result
104
- const resultOk =
105
- result === undefined ||
106
- result === null ||
107
- (typeof result === 'object' &&
108
- ((result as Record<string, unknown>).error === undefined ||
109
- typeof (result as Record<string, unknown>).error === 'string'))
110
- const validCall = typeof o.transactionHash === 'string' && resultOk
111
-
112
- return !isTraceBlockCallAction(action) || validCall
113
- }
114
-
115
84
  /** A transaction receipt as returned by a RPC node. */
116
85
  export type TransactionReceipt = {
117
86
  transactionHash: string
118
87
  gasUsed: string
119
- effectiveGasPrice?: string
120
- gasPrice?: string
88
+ /** Absent, or JSON `null`, when the node does not report this field. */
89
+ effectiveGasPrice?: string | null
90
+ /** Absent, or JSON `null`, when the node does not report this field. */
91
+ gasPrice?: string | null
121
92
  status: string | number | null
122
93
  logs: LogWithAddress[]
123
- /** Tx envelope type per EIP-2718, hex-prefixed (e.g. "0x2" EIP-1559). */
124
- type?: string
94
+ /** Tx envelope type per EIP-2718, hex-prefixed (e.g. "0x2" EIP-1559). `null` when the node omits it. */
95
+ type?: string | null
125
96
  }
126
97
 
127
98
  /**
@@ -24,14 +24,22 @@ export function nodeSourcesFromList(sources: readonly string[]): NodeSourceList
24
24
  throw new Error('nodeSources: at least one source is required')
25
25
  }
26
26
  const seen = new Set<string>()
27
- sources.forEach((source) => {
27
+ const validated: NodeSource[] = []
28
+ for (const source of sources) {
28
29
  if (!isNodeSource(source)) {
29
30
  throw new Error(`nodeSources: invalid source "${source}"`)
30
31
  }
31
32
  if (seen.has(source)) throw new Error(`nodeSources: duplicate source "${source}"`)
32
33
  seen.add(source)
33
- })
34
- return Object.freeze([...sources]) as unknown as NodeSourceList
34
+ validated.push(source)
35
+ }
36
+ const frozen = Object.freeze(validated)
37
+ if (isNodeSourceList(frozen)) return frozen
38
+ throw new Error('nodeSources: invalid list')
39
+ }
40
+
41
+ function isNodeSourceList(sources: readonly NodeSource[]): sources is NodeSourceList {
42
+ return sources.length > 0 && new Set(sources).size === sources.length
35
43
  }
36
44
 
37
45
  /** Default: direct RPC node only. */
@@ -274,9 +274,7 @@ export const STAKING_CONTRACTS: Record<string, StakingContractConfig> = {
274
274
  return typeof shares !== 'bigint' || shares >= 10n ** 9n
275
275
  },
276
276
  gasMultiplier: ({ mode }) => {
277
- return (['delegate', 'undelegate'] as const).includes(mode as 'delegate' | 'undelegate')
278
- ? new BigNumber(1.2)
279
- : new BigNumber(1)
277
+ return mode === 'delegate' || mode === 'undelegate' ? new BigNumber(1.2) : new BigNumber(1)
280
278
  },
281
279
  },
282
280
  somnia: {