@ledgerhq/coin-evm 5.4.1 → 8.0.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 (355) hide show
  1. package/.oxlintrc.json +1 -1
  2. package/CHANGELOG.md +234 -0
  3. package/docs/evm-family-integration-process/README.md +1 -1
  4. package/knip.json +2 -3
  5. package/lib/adapters/blockOperations.js +6 -6
  6. package/lib/adapters/blockOperations.js.map +1 -1
  7. package/lib/adapters/etherscan.js +23 -23
  8. package/lib/adapters/etherscan.js.map +1 -1
  9. package/lib/adapters/ledger.js +17 -17
  10. package/lib/adapters/ledger.js.map +1 -1
  11. package/lib/api/index.js +4 -4
  12. package/lib/api/index.js.map +1 -1
  13. package/lib/config.d.ts +21 -16
  14. package/lib/config.d.ts.map +1 -1
  15. package/lib/config.js +5 -25
  16. package/lib/config.js.map +1 -1
  17. package/lib/errors.d.ts +9 -0
  18. package/lib/errors.d.ts.map +1 -1
  19. package/lib/errors.js +15 -1
  20. package/lib/errors.js.map +1 -1
  21. package/lib/logic/broadcast.js +1 -1
  22. package/lib/logic/broadcast.js.map +1 -1
  23. package/lib/logic/common.d.ts +2 -1
  24. package/lib/logic/common.d.ts.map +1 -1
  25. package/lib/logic/common.js +4 -4
  26. package/lib/logic/common.js.map +1 -1
  27. package/lib/logic/craftTransaction.d.ts.map +1 -1
  28. package/lib/logic/craftTransaction.js +2 -2
  29. package/lib/logic/craftTransaction.js.map +1 -1
  30. package/lib/logic/estimateFees.d.ts.map +1 -1
  31. package/lib/logic/estimateFees.js +9 -9
  32. package/lib/logic/estimateFees.js.map +1 -1
  33. package/lib/logic/getBalance.d.ts.map +1 -1
  34. package/lib/logic/getBalance.js +50 -16
  35. package/lib/logic/getBalance.js.map +1 -1
  36. package/lib/logic/getBlock.d.ts.map +1 -1
  37. package/lib/logic/getBlock.js +19 -11
  38. package/lib/logic/getBlock.js.map +1 -1
  39. package/lib/logic/getBlockInfo.js +1 -1
  40. package/lib/logic/getBlockInfo.js.map +1 -1
  41. package/lib/logic/getNextSequence.d.ts.map +1 -1
  42. package/lib/logic/getNextSequence.js +1 -1
  43. package/lib/logic/getNextSequence.js.map +1 -1
  44. package/lib/logic/index.d.ts +2 -0
  45. package/lib/logic/index.d.ts.map +1 -1
  46. package/lib/logic/index.js +4 -0
  47. package/lib/logic/index.js.map +1 -1
  48. package/lib/logic/lastBlock.js +1 -1
  49. package/lib/logic/lastBlock.js.map +1 -1
  50. package/lib/logic/listOperations.d.ts.map +1 -1
  51. package/lib/logic/listOperations.js +10 -1
  52. package/lib/logic/listOperations.js.map +1 -1
  53. package/lib/logic/validateIntent.d.ts.map +1 -1
  54. package/lib/logic/validateIntent.js +12 -12
  55. package/lib/logic/validateIntent.js.map +1 -1
  56. package/lib/logic-public/index.d.ts +3 -0
  57. package/lib/logic-public/index.d.ts.map +1 -0
  58. package/lib/logic-public/index.js +19 -0
  59. package/lib/logic-public/index.js.map +1 -0
  60. package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
  61. package/lib/logic-public/utils.d.ts.map +1 -0
  62. package/lib/logic-public/utils.js +166 -0
  63. package/lib/logic-public/utils.js.map +1 -0
  64. package/lib/logic.d.ts +2 -1
  65. package/lib/logic.d.ts.map +1 -1
  66. package/lib/logic.js +3 -3
  67. package/lib/logic.js.map +1 -1
  68. package/lib/network/explorer/etherscan.d.ts +16 -3
  69. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  70. package/lib/network/explorer/etherscan.js +61 -6
  71. package/lib/network/explorer/etherscan.js.map +1 -1
  72. package/lib/network/explorer/ledger.d.ts +50 -4
  73. package/lib/network/explorer/ledger.d.ts.map +1 -1
  74. package/lib/network/explorer/ledger.js +286 -37
  75. package/lib/network/explorer/ledger.js.map +1 -1
  76. package/lib/network/explorer/none.d.ts +1 -0
  77. package/lib/network/explorer/none.d.ts.map +1 -1
  78. package/lib/network/explorer/none.js +4 -1
  79. package/lib/network/explorer/none.js.map +1 -1
  80. package/lib/network/explorer/types.d.ts +15 -2
  81. package/lib/network/explorer/types.d.ts.map +1 -1
  82. package/lib/network/explorer/types.js.map +1 -1
  83. package/lib/network/index.d.ts +5 -0
  84. package/lib/network/index.d.ts.map +1 -0
  85. package/lib/network/index.js +23 -0
  86. package/lib/network/index.js.map +1 -0
  87. package/lib/network/node/explorerProxy.d.ts +27 -0
  88. package/lib/network/node/explorerProxy.d.ts.map +1 -0
  89. package/lib/network/node/explorerProxy.js +262 -0
  90. package/lib/network/node/explorerProxy.js.map +1 -0
  91. package/lib/network/node/index.d.ts +2 -1
  92. package/lib/network/node/index.d.ts.map +1 -1
  93. package/lib/network/node/index.js +11 -10
  94. package/lib/network/node/index.js.map +1 -1
  95. package/lib/network/node/ledger.js +7 -7
  96. package/lib/network/node/ledger.js.map +1 -1
  97. package/lib/network/node/rpc.common.d.ts +2 -2
  98. package/lib/network/node/rpc.common.js +19 -19
  99. package/lib/network/node/rpc.common.js.map +1 -1
  100. package/lib/network/node/withNodeSources.d.ts +21 -0
  101. package/lib/network/node/withNodeSources.d.ts.map +1 -0
  102. package/lib/network/node/withNodeSources.js +78 -0
  103. package/lib/network/node/withNodeSources.js.map +1 -0
  104. package/lib/nodeSources.d.ts +15 -0
  105. package/lib/nodeSources.d.ts.map +1 -0
  106. package/lib/nodeSources.js +33 -0
  107. package/lib/nodeSources.js.map +1 -0
  108. package/lib/staking/contracts.js +1 -1
  109. package/lib/staking/contracts.js.map +1 -1
  110. package/lib/staking/fetchers.js +1 -1
  111. package/lib/staking/fetchers.js.map +1 -1
  112. package/lib/staking/operations/sei.js +1 -1
  113. package/lib/staking/operations/sei.js.map +1 -1
  114. package/lib/staking/prepareIntents.js +3 -3
  115. package/lib/staking/prepareIntents.js.map +1 -1
  116. package/lib/staking/rewards.js +1 -1
  117. package/lib/staking/rewards.js.map +1 -1
  118. package/lib/staking/transactionData.js +2 -2
  119. package/lib/staking/transactionData.js.map +1 -1
  120. package/lib/staking/utils.d.ts +45 -0
  121. package/lib/staking/utils.d.ts.map +1 -0
  122. package/lib/{utils.js → staking/utils.js} +5 -164
  123. package/lib/staking/utils.js.map +1 -0
  124. package/lib/staking/validators/sei.js +1 -1
  125. package/lib/staking/validators/sei.js.map +1 -1
  126. package/lib/types/staking.d.ts +2 -2
  127. package/lib-es/adapters/blockOperations.js +1 -1
  128. package/lib-es/adapters/blockOperations.js.map +1 -1
  129. package/lib-es/adapters/etherscan.js +1 -1
  130. package/lib-es/adapters/etherscan.js.map +1 -1
  131. package/lib-es/adapters/ledger.js +1 -1
  132. package/lib-es/adapters/ledger.js.map +1 -1
  133. package/lib-es/api/index.js +2 -2
  134. package/lib-es/api/index.js.map +1 -1
  135. package/lib-es/config.d.ts +21 -16
  136. package/lib-es/config.d.ts.map +1 -1
  137. package/lib-es/config.js +1 -21
  138. package/lib-es/config.js.map +1 -1
  139. package/lib-es/errors.d.ts +9 -0
  140. package/lib-es/errors.d.ts.map +1 -1
  141. package/lib-es/errors.js +13 -0
  142. package/lib-es/errors.js.map +1 -1
  143. package/lib-es/logic/broadcast.js +1 -1
  144. package/lib-es/logic/broadcast.js.map +1 -1
  145. package/lib-es/logic/common.d.ts +2 -1
  146. package/lib-es/logic/common.d.ts.map +1 -1
  147. package/lib-es/logic/common.js +3 -3
  148. package/lib-es/logic/common.js.map +1 -1
  149. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  150. package/lib-es/logic/craftTransaction.js +2 -2
  151. package/lib-es/logic/craftTransaction.js.map +1 -1
  152. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  153. package/lib-es/logic/estimateFees.js +6 -6
  154. package/lib-es/logic/estimateFees.js.map +1 -1
  155. package/lib-es/logic/getBalance.d.ts.map +1 -1
  156. package/lib-es/logic/getBalance.js +50 -16
  157. package/lib-es/logic/getBalance.js.map +1 -1
  158. package/lib-es/logic/getBlock.d.ts.map +1 -1
  159. package/lib-es/logic/getBlock.js +16 -8
  160. package/lib-es/logic/getBlock.js.map +1 -1
  161. package/lib-es/logic/getBlockInfo.js +1 -1
  162. package/lib-es/logic/getBlockInfo.js.map +1 -1
  163. package/lib-es/logic/getNextSequence.d.ts.map +1 -1
  164. package/lib-es/logic/getNextSequence.js +1 -1
  165. package/lib-es/logic/getNextSequence.js.map +1 -1
  166. package/lib-es/logic/index.d.ts +2 -0
  167. package/lib-es/logic/index.d.ts.map +1 -1
  168. package/lib-es/logic/index.js +4 -0
  169. package/lib-es/logic/index.js.map +1 -1
  170. package/lib-es/logic/lastBlock.js +1 -1
  171. package/lib-es/logic/lastBlock.js.map +1 -1
  172. package/lib-es/logic/listOperations.d.ts.map +1 -1
  173. package/lib-es/logic/listOperations.js +10 -1
  174. package/lib-es/logic/listOperations.js.map +1 -1
  175. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  176. package/lib-es/logic/validateIntent.js +4 -4
  177. package/lib-es/logic/validateIntent.js.map +1 -1
  178. package/lib-es/logic-public/index.d.ts +3 -0
  179. package/lib-es/logic-public/index.d.ts.map +1 -0
  180. package/lib-es/logic-public/index.js +4 -0
  181. package/lib-es/logic-public/index.js.map +1 -0
  182. package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
  183. package/lib-es/logic-public/utils.d.ts.map +1 -0
  184. package/lib-es/logic-public/utils.js +150 -0
  185. package/lib-es/logic-public/utils.js.map +1 -0
  186. package/lib-es/logic.d.ts +2 -1
  187. package/lib-es/logic.d.ts.map +1 -1
  188. package/lib-es/logic.js +3 -3
  189. package/lib-es/logic.js.map +1 -1
  190. package/lib-es/network/explorer/etherscan.d.ts +16 -3
  191. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  192. package/lib-es/network/explorer/etherscan.js +60 -5
  193. package/lib-es/network/explorer/etherscan.js.map +1 -1
  194. package/lib-es/network/explorer/ledger.d.ts +50 -4
  195. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  196. package/lib-es/network/explorer/ledger.js +283 -37
  197. package/lib-es/network/explorer/ledger.js.map +1 -1
  198. package/lib-es/network/explorer/none.d.ts +1 -0
  199. package/lib-es/network/explorer/none.d.ts.map +1 -1
  200. package/lib-es/network/explorer/none.js +2 -0
  201. package/lib-es/network/explorer/none.js.map +1 -1
  202. package/lib-es/network/explorer/types.d.ts +15 -2
  203. package/lib-es/network/explorer/types.d.ts.map +1 -1
  204. package/lib-es/network/explorer/types.js.map +1 -1
  205. package/lib-es/network/index.d.ts +5 -0
  206. package/lib-es/network/index.d.ts.map +1 -0
  207. package/lib-es/network/index.js +7 -0
  208. package/lib-es/network/index.js.map +1 -0
  209. package/lib-es/network/node/explorerProxy.d.ts +27 -0
  210. package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
  211. package/lib-es/network/node/explorerProxy.js +254 -0
  212. package/lib-es/network/node/explorerProxy.js.map +1 -0
  213. package/lib-es/network/node/index.d.ts +2 -1
  214. package/lib-es/network/node/index.d.ts.map +1 -1
  215. package/lib-es/network/node/index.js +11 -10
  216. package/lib-es/network/node/index.js.map +1 -1
  217. package/lib-es/network/node/ledger.js +1 -1
  218. package/lib-es/network/node/ledger.js.map +1 -1
  219. package/lib-es/network/node/rpc.common.d.ts +2 -2
  220. package/lib-es/network/node/rpc.common.js +3 -3
  221. package/lib-es/network/node/rpc.common.js.map +1 -1
  222. package/lib-es/network/node/withNodeSources.d.ts +21 -0
  223. package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
  224. package/lib-es/network/node/withNodeSources.js +74 -0
  225. package/lib-es/network/node/withNodeSources.js.map +1 -0
  226. package/lib-es/nodeSources.d.ts +15 -0
  227. package/lib-es/nodeSources.d.ts.map +1 -0
  228. package/lib-es/nodeSources.js +28 -0
  229. package/lib-es/nodeSources.js.map +1 -0
  230. package/lib-es/staking/contracts.js +1 -1
  231. package/lib-es/staking/contracts.js.map +1 -1
  232. package/lib-es/staking/fetchers.js +1 -1
  233. package/lib-es/staking/fetchers.js.map +1 -1
  234. package/lib-es/staking/operations/sei.js +1 -1
  235. package/lib-es/staking/operations/sei.js.map +1 -1
  236. package/lib-es/staking/prepareIntents.js +1 -1
  237. package/lib-es/staking/prepareIntents.js.map +1 -1
  238. package/lib-es/staking/rewards.js +1 -1
  239. package/lib-es/staking/rewards.js.map +1 -1
  240. package/lib-es/staking/transactionData.js +1 -1
  241. package/lib-es/staking/transactionData.js.map +1 -1
  242. package/lib-es/staking/utils.d.ts +45 -0
  243. package/lib-es/staking/utils.d.ts.map +1 -0
  244. package/lib-es/{utils.js → staking/utils.js} +1 -147
  245. package/lib-es/staking/utils.js.map +1 -0
  246. package/lib-es/staking/validators/sei.js +1 -1
  247. package/lib-es/staking/validators/sei.js.map +1 -1
  248. package/lib-es/types/staking.d.ts +2 -2
  249. package/package.json +75 -9
  250. package/src/adapters/blockOperations.ts +1 -1
  251. package/src/adapters/etherscan.ts +1 -1
  252. package/src/adapters/ledger.ts +1 -1
  253. package/src/api/getBlock.integ.test.ts +10 -4
  254. package/src/api/index.arbitrum.integ.test.ts +1 -0
  255. package/src/api/index.arc.integ.test.ts +1 -0
  256. package/src/api/index.avalanche_c_chain_fuji.integ.test.ts +1 -0
  257. package/src/api/index.cronos.integ.test.ts +1 -0
  258. package/src/api/index.flare.integ.test.ts +4 -2
  259. package/src/api/index.linea.integ.test.ts +4 -2
  260. package/src/api/index.monad_testnet.integ.test.ts +95 -4
  261. package/src/api/index.optimism.integ.test.ts +1 -0
  262. package/src/api/index.rsk.integ.test.ts +1 -0
  263. package/src/api/index.shape.integ.test.ts +4 -2
  264. package/src/api/index.somnia.integ.test.ts +1 -0
  265. package/src/api/index.ts +2 -2
  266. package/src/config.ts +22 -35
  267. package/src/errors.ts +13 -0
  268. package/src/fixtures/context.fixtures.ts +9 -4
  269. package/src/logic/broadcast.ts +1 -1
  270. package/src/logic/common.ts +4 -2
  271. package/src/logic/craftTransaction.ts +2 -1
  272. package/src/logic/estimateFees.ts +20 -6
  273. package/src/logic/getBalance.ts +72 -26
  274. package/src/logic/getBlock.ts +26 -14
  275. package/src/logic/getBlockInfo.ts +1 -1
  276. package/src/logic/getNextSequence.ts +4 -1
  277. package/src/logic/index.ts +4 -0
  278. package/src/logic/lastBlock.ts +1 -1
  279. package/src/logic/listOperations.ts +14 -1
  280. package/src/logic/tests/broadcast.integ.test.ts +53 -0
  281. package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
  282. package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
  283. package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
  284. package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
  285. package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
  286. package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
  287. package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
  288. package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
  289. package/src/logic/tests/getBalance.test.ts +602 -0
  290. package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
  291. package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
  292. package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
  293. package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
  294. package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
  295. package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
  296. package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
  297. package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
  298. package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
  299. package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
  300. package/src/logic/validateIntent.ts +7 -4
  301. package/src/logic-public/index.ts +18 -0
  302. package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
  303. package/src/logic-public/utils.ts +184 -0
  304. package/src/logic.test.ts +5 -59
  305. package/src/logic.ts +5 -3
  306. package/src/network/explorer/etherscan.test.ts +403 -195
  307. package/src/network/explorer/etherscan.ts +99 -10
  308. package/src/network/explorer/index.test.ts +27 -0
  309. package/src/network/explorer/ledger.test.ts +792 -62
  310. package/src/network/explorer/ledger.ts +426 -54
  311. package/src/network/explorer/none.ts +3 -0
  312. package/src/network/explorer/types.ts +29 -5
  313. package/src/network/index.ts +7 -0
  314. package/src/network/node/explorerProxy.test.ts +673 -0
  315. package/src/network/node/explorerProxy.ts +308 -0
  316. package/src/network/node/index.memoization.test.ts +22 -10
  317. package/src/network/node/index.test.ts +6 -3
  318. package/src/network/node/index.ts +11 -7
  319. package/src/network/node/ledger.ts +1 -1
  320. package/src/network/node/node.fixtures.ts +2 -1
  321. package/src/network/node/rpc.common.ts +3 -3
  322. package/src/network/node/rpc.test.ts +66 -105
  323. package/src/network/node/withNodeSources.test.ts +240 -0
  324. package/src/network/node/withNodeSources.ts +95 -0
  325. package/src/nodeSources.ts +38 -0
  326. package/src/staking/contracts.ts +1 -1
  327. package/src/staking/encoder.test.ts +1 -1
  328. package/src/staking/fetchers.ts +1 -1
  329. package/src/staking/operations/sei.ts +1 -1
  330. package/src/staking/prepareIntents.ts +1 -1
  331. package/src/staking/redelegations.test.ts +3 -1
  332. package/src/staking/rewards.test.ts +1 -1
  333. package/src/staking/rewards.ts +1 -1
  334. package/src/staking/transactionData.ts +1 -1
  335. package/src/staking/unbondings.test.ts +2 -1
  336. package/src/staking/utils.test.ts +25 -0
  337. package/src/{utils.ts → staking/utils.ts} +2 -182
  338. package/src/staking/validators/sei.ts +1 -1
  339. package/src/staking/validators.test.ts +1 -0
  340. package/src/types/staking.ts +2 -2
  341. package/lib/constants.d.ts +0 -2
  342. package/lib/constants.d.ts.map +0 -1
  343. package/lib/constants.js +0 -11
  344. package/lib/constants.js.map +0 -1
  345. package/lib/utils.d.ts.map +0 -1
  346. package/lib/utils.js.map +0 -1
  347. package/lib-es/constants.d.ts +0 -2
  348. package/lib-es/constants.d.ts.map +0 -1
  349. package/lib-es/constants.js +0 -7
  350. package/lib-es/constants.js.map +0 -1
  351. package/lib-es/utils.d.ts.map +0 -1
  352. package/lib-es/utils.js.map +0 -1
  353. package/src/constants.ts +0 -9
  354. package/src/logic/broadcast.integ.test.ts +0 -46
  355. package/src/logic/getBalance.test.ts +0 -362
@@ -0,0 +1,673 @@
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import axios from 'axios'
5
+ import { BigNumber } from 'bignumber.js'
6
+ import {
7
+ createMockEvmConfigInfo,
8
+ mkExternalNode,
9
+ testLogger,
10
+ } from '../../fixtures/context.fixtures'
11
+ import {
12
+ createExplorerProxyNodeApi,
13
+ getBlockFromExplorerProxy,
14
+ getTransactionFromExplorerProxy,
15
+ } from './explorerProxy'
16
+
17
+ jest.mock('axios')
18
+ const mockAxiosGet = jest.mocked(axios.get)
19
+
20
+ const EXPLORER_URI = 'http://explorer.test'
21
+ const TX_HASH = '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab'
22
+
23
+ describe('createExplorerProxyNodeApi', () => {
24
+ let api: ReturnType<typeof createExplorerProxyNodeApi>
25
+ beforeEach(() => {
26
+ jest.clearAllMocks()
27
+ api = createExplorerProxyNodeApi(EXPLORER_URI, 0, testLogger)
28
+ })
29
+
30
+ describe('unsupported methods', () => {
31
+ it.each([
32
+ ['call', () => api.call('eth', { to: '0x', data: '0x' })],
33
+ ['getCoinBalance', () => api.getCoinBalance('eth', '0x')],
34
+ ['getTokenBalance', () => api.getTokenBalance('eth', '0x', '0x')],
35
+ ['getTokenAllowance', () => api.getTokenAllowance('eth', '0x', '0x', '0x')],
36
+ ['getTransactionCount', () => api.getTransactionCount('eth', '0x')],
37
+ [
38
+ 'getGasEstimation',
39
+ () => api.getGasEstimation('eth', '0x', { amount: new BigNumber(0), recipient: '0x' }),
40
+ ],
41
+ [
42
+ 'getFeeData',
43
+ () =>
44
+ api.getFeeData(
45
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
46
+ 'eth',
47
+ {}
48
+ ),
49
+ ],
50
+ ['broadcastTransaction', () => api.broadcastTransaction('eth', '0x')],
51
+ ['getOptimismAdditionalFees', () => api.getOptimismAdditionalFees('eth', '0x')],
52
+ ['getScrollAdditionalFees', () => api.getScrollAdditionalFees('eth', '0x')],
53
+ ] as const)(
54
+ '%s rejects immediately with "not supported by explorer proxy"',
55
+ async (_name, invoke) => {
56
+ await expect(invoke()).rejects.toThrow('not supported by explorer proxy')
57
+ expect(mockAxiosGet).not.toHaveBeenCalled()
58
+ }
59
+ )
60
+ })
61
+
62
+ describe('getBlockByHeight', () => {
63
+ it('throws before hitting the network when height is a BlockFinalizationTag', async () => {
64
+ await expect(api.getBlockByHeight('eth', 'latest')).rejects.toThrow(
65
+ 'explorer proxy only supports numeric heights'
66
+ )
67
+ expect(mockAxiosGet).not.toHaveBeenCalled()
68
+ })
69
+
70
+ it('throws when the proxy returns null (block not found or malformed)', async () => {
71
+ mockAxiosGet.mockResolvedValueOnce({ data: { result: null } })
72
+ await expect(api.getBlockByHeight('eth', 1)).rejects.toThrow(
73
+ 'explorer proxy returned no result for block 1'
74
+ )
75
+ })
76
+
77
+ it('returns the block when the proxy succeeds', async () => {
78
+ mockAxiosGet.mockResolvedValueOnce({
79
+ data: {
80
+ result: {
81
+ hash: '0xdeadbeef',
82
+ number: '0x1',
83
+ timestamp: '0x6849e2a5',
84
+ parentHash: '0xparent',
85
+ transactions: ['0xhash1'],
86
+ },
87
+ },
88
+ })
89
+ const result = await api.getBlockByHeight('eth', 1)
90
+ expect(result.hash).toBe('0xdeadbeef')
91
+ expect(result.height).toBe(1)
92
+ expect(result.transactionHashes).toEqual(['0xhash1'])
93
+ })
94
+
95
+ it('propagates network errors as a throw (via the null path)', async () => {
96
+ mockAxiosGet.mockRejectedValueOnce(new Error('ECONNREFUSED'))
97
+ await expect(api.getBlockByHeight('eth', 1)).rejects.toThrow(
98
+ 'explorer proxy returned no result for block 1'
99
+ )
100
+ })
101
+ })
102
+
103
+ describe('getTransaction', () => {
104
+ it('throws when the proxy returns null (tx not found)', async () => {
105
+ mockAxiosGet
106
+ .mockResolvedValueOnce({ data: { result: null } })
107
+ .mockResolvedValueOnce({ data: { result: null } })
108
+ await expect(api.getTransaction('eth', TX_HASH)).rejects.toThrow(
109
+ `explorer proxy returned no result for tx ${TX_HASH}`
110
+ )
111
+ })
112
+
113
+ it('returns the transaction when the proxy succeeds', async () => {
114
+ mockAxiosGet
115
+ .mockResolvedValueOnce({
116
+ data: {
117
+ result: {
118
+ hash: TX_HASH,
119
+ blockNumber: '0x1',
120
+ blockHash: '0xblockhash',
121
+ nonce: '0x1',
122
+ gasPrice: '0x3b9aca00',
123
+ value: '0x0',
124
+ from: '0xaabbcc0000000000000000000000000000000001',
125
+ to: '0xaabbcc0000000000000000000000000000000002',
126
+ input: '0x',
127
+ type: '0x2',
128
+ },
129
+ },
130
+ })
131
+ .mockResolvedValueOnce({
132
+ data: {
133
+ result: {
134
+ transactionHash: TX_HASH,
135
+ gasUsed: '0x5208',
136
+ effectiveGasPrice: '0x3b9aca00',
137
+ status: '0x1',
138
+ logs: [],
139
+ type: '0x2',
140
+ },
141
+ },
142
+ })
143
+ const result = await api.getTransaction('eth', TX_HASH)
144
+ expect(result.hash).toBe(TX_HASH)
145
+ expect(result.status).toBe(1)
146
+ expect(result.erc20Transfers).toEqual([])
147
+ })
148
+
149
+ it('propagates network errors as a throw (via the null path)', async () => {
150
+ mockAxiosGet.mockRejectedValue(new Error('ECONNREFUSED'))
151
+ await expect(api.getTransaction('eth', TX_HASH)).rejects.toThrow(
152
+ `explorer proxy returned no result for tx ${TX_HASH}`
153
+ )
154
+ })
155
+ })
156
+ })
157
+
158
+ describe('getBlockFromExplorerProxy', () => {
159
+ const HEIGHT = 14817811
160
+ const HEIGHT_HEX = '0x' + HEIGHT.toString(16)
161
+
162
+ beforeEach(() => jest.clearAllMocks())
163
+
164
+ it('parses hex fields and populates transactionHashes from the hash array', async () => {
165
+ mockAxiosGet.mockResolvedValueOnce({
166
+ data: {
167
+ result: {
168
+ hash: '0xdeadbeef',
169
+ number: HEIGHT_HEX,
170
+ timestamp: '0x6849e2a5',
171
+ parentHash: '0xparent',
172
+ transactions: ['0xhash1', '0xhash2'],
173
+ },
174
+ },
175
+ })
176
+
177
+ const result = await getBlockFromExplorerProxy(EXPLORER_URI, HEIGHT)
178
+
179
+ expect(result).toMatchObject({ hash: '0xdeadbeef', height: HEIGHT, parentHash: '0xparent' })
180
+ expect(result?.timestamp).toBe(Number(BigInt('0x6849e2a5')) * 1000)
181
+ expect(result?.transactionHashes).toEqual(['0xhash1', '0xhash2'])
182
+ expect(result?.transactions).toBeUndefined()
183
+ })
184
+
185
+ it('accepts a decimal block number (some explorer implementations omit the 0x prefix)', async () => {
186
+ mockAxiosGet.mockResolvedValueOnce({
187
+ data: {
188
+ result: {
189
+ hash: '0xdeadbeef',
190
+ number: '1',
191
+ timestamp: '0x6849e2a5',
192
+ parentHash: '0xparent',
193
+ transactions: [],
194
+ },
195
+ },
196
+ })
197
+ const result = await getBlockFromExplorerProxy(EXPLORER_URI, 1)
198
+ expect(result?.height).toBe(1)
199
+ })
200
+
201
+ it('returns null when block number does not match the requested height', async () => {
202
+ mockAxiosGet.mockResolvedValueOnce({
203
+ data: {
204
+ result: {
205
+ hash: '0xdeadbeef',
206
+ number: '0x2',
207
+ timestamp: '0x6849e2a5',
208
+ parentHash: '0xparent',
209
+ },
210
+ },
211
+ })
212
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
213
+ })
214
+
215
+ it('returns null when block number is absent', async () => {
216
+ mockAxiosGet.mockResolvedValueOnce({
217
+ data: {
218
+ result: {
219
+ hash: '0xdeadbeef',
220
+ timestamp: '0x6849e2a5',
221
+ parentHash: '0xparent',
222
+ },
223
+ },
224
+ })
225
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
226
+ })
227
+
228
+ it('returns null when timestamp or parentHash are missing', async () => {
229
+ mockAxiosGet.mockResolvedValueOnce({
230
+ data: {
231
+ result: {
232
+ hash: '0xdeadbeef',
233
+ number: '0x1',
234
+ },
235
+ },
236
+ })
237
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
238
+ })
239
+
240
+ it('returns null when result hash is all zeros', async () => {
241
+ mockAxiosGet.mockResolvedValueOnce({
242
+ data: {
243
+ result: { hash: '0x' + '0'.repeat(64), number: '0x1', timestamp: '0x1', parentHash: '0x0' },
244
+ },
245
+ })
246
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
247
+ })
248
+
249
+ it('returns null when transactions field is not an array', async () => {
250
+ mockAxiosGet.mockResolvedValueOnce({
251
+ data: {
252
+ result: {
253
+ hash: '0xdeadbeef',
254
+ number: '0x1',
255
+ timestamp: '0x6849e2a5',
256
+ parentHash: '0xparent',
257
+ transactions: 'not-an-array',
258
+ },
259
+ },
260
+ })
261
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
262
+ })
263
+
264
+ it('returns null when the transactions array contains a non-string entry', async () => {
265
+ mockAxiosGet.mockResolvedValueOnce({
266
+ data: {
267
+ result: {
268
+ hash: '0xdeadbeef',
269
+ number: '0x1',
270
+ timestamp: '0x6849e2a5',
271
+ parentHash: '0xparent',
272
+ transactions: ['0xhash1', 123],
273
+ },
274
+ },
275
+ })
276
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
277
+ })
278
+
279
+ it('returns null on network error', async () => {
280
+ mockAxiosGet.mockRejectedValueOnce(new Error('ECONNREFUSED'))
281
+ expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
282
+ })
283
+ })
284
+
285
+ describe('getTransactionFromExplorerProxy', () => {
286
+ beforeEach(() => jest.clearAllMocks())
287
+
288
+ it('returns a parsed TransactionInfo on success', async () => {
289
+ mockAxiosGet
290
+ .mockResolvedValueOnce({
291
+ data: {
292
+ result: {
293
+ hash: TX_HASH,
294
+ blockNumber: '0x1',
295
+ blockHash: '0xblockhash',
296
+ nonce: '0x1',
297
+ gasPrice: '0x3b9aca00',
298
+ value: '0xde0b6b3a7640000',
299
+ from: '0xaabbcc0000000000000000000000000000000001',
300
+ to: '0xaabbcc0000000000000000000000000000000002',
301
+ input: '0x',
302
+ type: '0x2',
303
+ },
304
+ },
305
+ })
306
+ .mockResolvedValueOnce({
307
+ data: {
308
+ result: {
309
+ transactionHash: TX_HASH,
310
+ gasUsed: '0x5208',
311
+ effectiveGasPrice: '0x3b9aca00',
312
+ status: '0x1',
313
+ logs: [],
314
+ type: '0x2',
315
+ },
316
+ },
317
+ })
318
+
319
+ const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
320
+
321
+ expect(result?.hash).toBe(TX_HASH)
322
+ expect(result?.blockHeight).toBe(1)
323
+ expect(result?.gasUsed).toBe('21000')
324
+ expect(result?.status).toBe(1)
325
+ expect(result?.erc20Transfers).toEqual([])
326
+ })
327
+
328
+ it('includes l1Fee from receipt when present (OP-stack chains)', async () => {
329
+ mockAxiosGet
330
+ .mockResolvedValueOnce({
331
+ data: {
332
+ result: {
333
+ hash: TX_HASH,
334
+ blockNumber: '0x1',
335
+ blockHash: '0xblockhash',
336
+ nonce: '0x1',
337
+ gasPrice: '0x3b9aca00',
338
+ value: '0x0',
339
+ from: '0xaabbcc0000000000000000000000000000000001',
340
+ to: '0xaabbcc0000000000000000000000000000000002',
341
+ input: '0x',
342
+ type: '0x0',
343
+ },
344
+ },
345
+ })
346
+ .mockResolvedValueOnce({
347
+ data: {
348
+ result: {
349
+ transactionHash: TX_HASH,
350
+ gasUsed: '0x5208',
351
+ effectiveGasPrice: '0x3b9aca00',
352
+ status: '0x1',
353
+ logs: [],
354
+ type: '0x0',
355
+ l1Fee: '0x1234',
356
+ },
357
+ },
358
+ })
359
+
360
+ const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
361
+
362
+ expect(result?.l1Fee).toBe(String(BigInt('0x1234')))
363
+ })
364
+
365
+ it('falls back to receipt.gasPrice when effectiveGasPrice is absent', async () => {
366
+ mockAxiosGet
367
+ .mockResolvedValueOnce({
368
+ data: {
369
+ result: {
370
+ hash: TX_HASH,
371
+ blockNumber: '0x1',
372
+ blockHash: '0xblockhash',
373
+ nonce: '0x1',
374
+ gasPrice: '0xdeadbeef',
375
+ value: '0x0',
376
+ from: '0xaabbcc0000000000000000000000000000000001',
377
+ to: '0xaabbcc0000000000000000000000000000000002',
378
+ input: '0x',
379
+ type: '0x0',
380
+ },
381
+ },
382
+ })
383
+ .mockResolvedValueOnce({
384
+ data: {
385
+ result: {
386
+ transactionHash: TX_HASH,
387
+ gasUsed: '0x5208',
388
+ gasPrice: '0xcafebabe',
389
+ status: '0x1',
390
+ logs: [],
391
+ type: '0x0',
392
+ },
393
+ },
394
+ })
395
+
396
+ const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
397
+
398
+ expect(result?.gasPrice).toBe(String(BigInt('0xcafebabe')))
399
+ })
400
+
401
+ it('handles contract-creation txs (to is null, contractAddress present)', async () => {
402
+ mockAxiosGet
403
+ .mockResolvedValueOnce({
404
+ data: {
405
+ result: {
406
+ hash: TX_HASH,
407
+ blockNumber: '0x1',
408
+ nonce: '0x0',
409
+ gasPrice: '0x3b9aca00',
410
+ value: '0x0',
411
+ from: '0xaabbcc0000000000000000000000000000000001',
412
+ to: null,
413
+ input: '0x6080',
414
+ type: '0x0',
415
+ },
416
+ },
417
+ })
418
+ .mockResolvedValueOnce({
419
+ data: {
420
+ result: {
421
+ transactionHash: TX_HASH,
422
+ gasUsed: '0x5208',
423
+ effectiveGasPrice: '0x3b9aca00',
424
+ status: '0x1',
425
+ logs: [],
426
+ type: '0x0',
427
+ contractAddress: '0xaabbcc0000000000000000000000000000000099',
428
+ },
429
+ },
430
+ })
431
+
432
+ const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
433
+
434
+ expect(result?.to).toBeUndefined()
435
+ expect(result?.contractAddress).toBe('0xaabbcc0000000000000000000000000000000099')
436
+ })
437
+
438
+ it('returns null when proxy returns a tx hash that does not match the request', async () => {
439
+ mockAxiosGet
440
+ .mockResolvedValueOnce({
441
+ data: {
442
+ result: {
443
+ hash: '0x' + 'a'.repeat(64),
444
+ blockNumber: '0x1',
445
+ blockHash: '0xblockhash',
446
+ nonce: '0x1',
447
+ gasPrice: '0x3b9aca00',
448
+ value: '0x0',
449
+ from: '0xaabbcc0000000000000000000000000000000001',
450
+ to: '0xaabbcc0000000000000000000000000000000002',
451
+ input: '0x',
452
+ type: '0x2',
453
+ },
454
+ },
455
+ })
456
+ .mockResolvedValueOnce({ data: { result: null } })
457
+
458
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
459
+ })
460
+
461
+ it('returns null when a required field (gasUsed) is absent from the receipt', async () => {
462
+ mockAxiosGet
463
+ .mockResolvedValueOnce({
464
+ data: {
465
+ result: {
466
+ hash: TX_HASH,
467
+ blockNumber: '0x1',
468
+ blockHash: '0xblockhash',
469
+ nonce: '0x1',
470
+ gasPrice: '0x3b9aca00',
471
+ value: '0x0',
472
+ from: '0xaabbcc0000000000000000000000000000000001',
473
+ to: '0xaabbcc0000000000000000000000000000000002',
474
+ input: '0x',
475
+ type: '0x2',
476
+ },
477
+ },
478
+ })
479
+ .mockResolvedValueOnce({
480
+ data: {
481
+ result: {
482
+ transactionHash: TX_HASH,
483
+ effectiveGasPrice: '0x3b9aca00',
484
+ status: '0x1',
485
+ logs: [],
486
+ type: '0x2',
487
+ },
488
+ },
489
+ })
490
+
491
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
492
+ })
493
+
494
+ it('returns null when the receipt contains a malformed hex quantity', async () => {
495
+ mockAxiosGet
496
+ .mockResolvedValueOnce({
497
+ data: {
498
+ result: {
499
+ hash: TX_HASH,
500
+ blockNumber: '0x1',
501
+ blockHash: '0xblockhash',
502
+ nonce: '0x1',
503
+ gasPrice: '0x3b9aca00',
504
+ value: '0x0',
505
+ from: '0xaabbcc0000000000000000000000000000000001',
506
+ to: '0xaabbcc0000000000000000000000000000000002',
507
+ input: '0x',
508
+ type: '0x2',
509
+ },
510
+ },
511
+ })
512
+ .mockResolvedValueOnce({
513
+ data: {
514
+ result: {
515
+ transactionHash: TX_HASH,
516
+ gasUsed: 'invalid',
517
+ effectiveGasPrice: '0x3b9aca00',
518
+ status: '0x1',
519
+ logs: [],
520
+ type: '0x2',
521
+ },
522
+ },
523
+ })
524
+
525
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
526
+ })
527
+
528
+ it('returns null when logs is absent from the receipt', async () => {
529
+ mockAxiosGet
530
+ .mockResolvedValueOnce({
531
+ data: {
532
+ result: {
533
+ hash: TX_HASH,
534
+ blockNumber: '0x1',
535
+ blockHash: '0xblockhash',
536
+ nonce: '0x1',
537
+ gasPrice: '0x3b9aca00',
538
+ value: '0x0',
539
+ from: '0xaabbcc0000000000000000000000000000000001',
540
+ to: '0xaabbcc0000000000000000000000000000000002',
541
+ input: '0x',
542
+ type: '0x2',
543
+ },
544
+ },
545
+ })
546
+ .mockResolvedValueOnce({
547
+ data: {
548
+ result: {
549
+ transactionHash: TX_HASH,
550
+ gasUsed: '0x5208',
551
+ effectiveGasPrice: '0x3b9aca00',
552
+ status: '0x1',
553
+ type: '0x2',
554
+ },
555
+ },
556
+ })
557
+
558
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
559
+ })
560
+
561
+ it('returns null when a log entry has a malformed field (missing address)', async () => {
562
+ mockAxiosGet
563
+ .mockResolvedValueOnce({
564
+ data: {
565
+ result: {
566
+ hash: TX_HASH,
567
+ blockNumber: '0x1',
568
+ nonce: '0x1',
569
+ gasPrice: '0x3b9aca00',
570
+ value: '0x0',
571
+ from: '0xaabbcc0000000000000000000000000000000001',
572
+ to: '0xaabbcc0000000000000000000000000000000002',
573
+ input: '0x',
574
+ type: '0x2',
575
+ },
576
+ },
577
+ })
578
+ .mockResolvedValueOnce({
579
+ data: {
580
+ result: {
581
+ transactionHash: TX_HASH,
582
+ gasUsed: '0x5208',
583
+ effectiveGasPrice: '0x3b9aca00',
584
+ status: '0x1',
585
+ logs: [{ topics: [], data: '0x' }],
586
+ type: '0x2',
587
+ },
588
+ },
589
+ })
590
+
591
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
592
+ })
593
+
594
+ it('returns null when from is absent from the transaction', async () => {
595
+ mockAxiosGet
596
+ .mockResolvedValueOnce({
597
+ data: {
598
+ result: {
599
+ hash: TX_HASH,
600
+ blockNumber: '0x1',
601
+ blockHash: '0xblockhash',
602
+ nonce: '0x1',
603
+ gasPrice: '0x3b9aca00',
604
+ value: '0x0',
605
+ to: '0xaabbcc0000000000000000000000000000000002',
606
+ input: '0x',
607
+ type: '0x2',
608
+ },
609
+ },
610
+ })
611
+ .mockResolvedValueOnce({
612
+ data: {
613
+ result: {
614
+ transactionHash: TX_HASH,
615
+ gasUsed: '0x5208',
616
+ effectiveGasPrice: '0x3b9aca00',
617
+ status: '0x1',
618
+ logs: [],
619
+ type: '0x2',
620
+ },
621
+ },
622
+ })
623
+
624
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
625
+ })
626
+
627
+ it('returns null when to is a malformed type (neither string nor null)', async () => {
628
+ mockAxiosGet
629
+ .mockResolvedValueOnce({
630
+ data: {
631
+ result: {
632
+ hash: TX_HASH,
633
+ blockNumber: '0x1',
634
+ blockHash: '0xblockhash',
635
+ nonce: '0x1',
636
+ gasPrice: '0x3b9aca00',
637
+ value: '0x0',
638
+ from: '0xaabbcc0000000000000000000000000000000001',
639
+ to: 12345,
640
+ input: '0x',
641
+ type: '0x2',
642
+ },
643
+ },
644
+ })
645
+ .mockResolvedValueOnce({
646
+ data: {
647
+ result: {
648
+ transactionHash: TX_HASH,
649
+ gasUsed: '0x5208',
650
+ effectiveGasPrice: '0x3b9aca00',
651
+ status: '0x1',
652
+ logs: [],
653
+ type: '0x2',
654
+ },
655
+ },
656
+ })
657
+
658
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
659
+ })
660
+
661
+ it('returns null when tx is not found', async () => {
662
+ mockAxiosGet
663
+ .mockResolvedValueOnce({ data: { result: null } })
664
+ .mockResolvedValueOnce({ data: { result: null } })
665
+
666
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
667
+ })
668
+
669
+ it('returns null on network error', async () => {
670
+ mockAxiosGet.mockRejectedValue(new Error('ECONNREFUSED'))
671
+ expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
672
+ })
673
+ })