@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
@@ -1,11 +1,17 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { EvmConfigInfo } from '../../config'
4
5
  import type { LedgerExplorerOperation } from '../../types'
5
6
  import type { ExplorerApi } from './types'
6
- import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
7
+ import type {
8
+ AssetInfo,
9
+ MemoNotSupported,
10
+ Operation,
11
+ } from '@ledgerhq/coin-module-framework/api/types'
7
12
  import { delay } from '@ledgerhq/coin-module-framework/promises'
8
13
  import axios from 'axios'
14
+ import eip55 from 'eip55'
9
15
  import {
10
16
  ledgerERC1155EventToOperations,
11
17
  ledgerERC20EventToOperations,
@@ -14,13 +20,33 @@ import {
14
20
  ledgerOperationToOperations,
15
21
  } from '../../adapters/index'
16
22
  import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
17
- import { LedgerExplorerUsedIncorrectly, RateLimitError } from '../../errors'
23
+ import {
24
+ LedgerExplorerUsedIncorrectly,
25
+ RateLimitError,
26
+ UnpageableLedgerExplorerBlock,
27
+ } from '../../errors'
28
+ import { safeEncodeEIP55 } from '../../logic-public'
18
29
  import { isLedgerExplorerConfig, NO_TOKEN } from './types'
19
30
 
20
31
  export const DEFAULT_BATCH_SIZE = 10_000
21
32
  export const LEDGER_TIMEOUT = 200 // 200ms between 2 calls
22
33
  export const DEFAULT_RETRIES_API = 2
23
34
 
35
+ /**
36
+ * Page size for the discovery walk (see `discoverTokenAssets` below). Once discovery no longer
37
+ * accumulates pages (see `fetchPaginatedOpsWithRetries`), its peak memory is one *parsed* page,
38
+ * so this constant is a memory bound, not a throughput knob — it does not affect `getOperations`.
39
+ */
40
+ export const DISCOVERY_BATCH_SIZE = 100
41
+
42
+ /**
43
+ * The explorer serves at most this many records per request regardless of a larger `batch_size`
44
+ * — measured against `https://explorers.api.live.ledger.com`: a requested 10 000 is served as
45
+ * 500. A raw page at or above this ceiling can never be trusted as proof there is nothing more,
46
+ * no matter how large `batch_size` was asked to be — see `fetchLedgerOpsPage`.
47
+ */
48
+ export const EXPLORER_MAX_PAGE_SIZE = 500
49
+
24
50
  type OperationsRequestParams = {
25
51
  explorerId: string
26
52
  address: string
@@ -28,12 +54,65 @@ type OperationsRequestParams = {
28
54
  batchSize: number
29
55
  }
30
56
 
57
+ /**
58
+ * Layered onto `OperationsRequestParams` only by the paged fetch below. Kept as a separate,
59
+ * fully-optional type so the legacy exhaustive callers' object literals (`fetchPaginatedOpsWithRetries`,
60
+ * `discoverTokenAssets`) do not need to change: they keep requesting ascending with no ceiling.
61
+ */
62
+ type OrderedRequestParams = {
63
+ toBlock?: number | undefined
64
+ order?: 'asc' | 'desc' | undefined
65
+ }
66
+
31
67
  /** Both default to what the env used to supply, so the previous call shape keeps working. */
32
68
  type LedgerExplorerSettings = {
33
69
  explorerUri?: string | undefined
34
70
  clientVersion?: string | undefined
35
71
  }
36
72
 
73
+ type OpsPage = { operations: LedgerExplorerOperation[]; token: string }
74
+
75
+ function mapExplorerOrder(order: 'asc' | 'desc' = 'asc'): 'ascending' | 'descending' {
76
+ return order === 'desc' ? 'descending' : 'ascending'
77
+ }
78
+
79
+ /**
80
+ * Bare HTTP call for a single page: no retry, no accumulation.
81
+ *
82
+ * `paginationToken`: `undefined` omits the `token` parameter entirely (the paged fetch resumes
83
+ * through `from_height`/`to_height`, never through the explorer's own token); `null` or a string
84
+ * requests continuation through the explorer's token, as the exhaustive walks below do.
85
+ */
86
+ async function requestOpsPage(
87
+ params: Required<OperationsRequestParams> & LedgerExplorerSettings & OrderedRequestParams,
88
+ paginationToken: string | null | undefined
89
+ ): Promise<OpsPage> {
90
+ const {
91
+ data: { data: operations, token },
92
+ } = await axios.request<{
93
+ data: LedgerExplorerOperation[]
94
+ token: string
95
+ }>({
96
+ ...(params.clientVersion
97
+ ? { headers: { 'X-Ledger-Client-Version': params.clientVersion } }
98
+ : {}),
99
+ method: 'GET',
100
+ url: `${params.explorerUri ?? DEFAULT_LEDGER_EXPLORER_URI}/blockchain/v4/${params.explorerId}/address/${params.address}/txs`,
101
+ params: {
102
+ filtering: true,
103
+ from_height: params.fromBlock ?? 0,
104
+ // Needed to make sure we get transactions after the block height and not before, when no
105
+ // explicit order is requested. Order is still descending in the end for that legacy walk.
106
+ order: mapExplorerOrder(params.order),
107
+ batch_size: params.batchSize,
108
+ ...(params.toBlock !== undefined ? { to_height: params.toBlock } : {}),
109
+ ...(paginationToken !== undefined ? { token: paginationToken } : {}),
110
+ },
111
+ })
112
+
113
+ return { operations, token }
114
+ }
115
+
37
116
  /**
38
117
  * Request fetching all operations from an address
39
118
  * and supporting pagination through tokens.
@@ -45,25 +124,7 @@ export async function fetchPaginatedOpsWithRetries(
45
124
  retries = DEFAULT_RETRIES_API
46
125
  ): Promise<LedgerExplorerOperation[]> {
47
126
  try {
48
- const {
49
- data: { data: operationsBatch, token },
50
- } = await axios.request<{
51
- data: LedgerExplorerOperation[]
52
- token: string
53
- }>({
54
- ...(params.clientVersion
55
- ? { headers: { 'X-Ledger-Client-Version': params.clientVersion } }
56
- : {}),
57
- method: 'GET',
58
- url: `${params.explorerUri ?? DEFAULT_LEDGER_EXPLORER_URI}/blockchain/v4/${params.explorerId}/address/${params.address}/txs`,
59
- params: {
60
- filtering: true,
61
- from_height: params.fromBlock ?? 0,
62
- order: 'ascending', // Needed to make sure we get transactions after the block height and not before. Order is still descending in the end
63
- batch_size: params.batchSize,
64
- token: paginationToken,
65
- },
66
- })
127
+ const { operations: operationsBatch, token } = await requestOpsPage(params, paginationToken)
67
128
 
68
129
  previousOperations.push(...operationsBatch)
69
130
 
@@ -88,39 +149,210 @@ export async function fetchPaginatedOpsWithRetries(
88
149
  }
89
150
 
90
151
  /**
91
- * Returns all operation types from an address
152
+ * Fetch a single page, retrying up to `retries` times on failure. Shared by the discovery walk
153
+ * and the paged fetch below. Unlike `fetchPaginatedOpsWithRetries`, the retry budget is per page,
154
+ * not per walk: a page that keeps failing after its own retries propagates instead of being
155
+ * silently skipped — a hole in the middle of a walk is worse than a failure.
92
156
  *
93
- * Note: Ledger explorer fetches all pages recursively internally,
94
- * so pagination parameters are ignored and nextPagingToken is always empty.
95
- * Pagination may be supported in the future.
157
+ * A rate limit is the one error that is never retried, exactly as the exhaustive walk treats it:
158
+ * it is not transient, so spending the budget on it only walks the caller into a timeout.
96
159
  */
97
- export const getOperations: ExplorerApi['getOperations'] = async (
98
- config,
99
- currencyId,
100
- address,
101
- fromBlock
102
- ) => {
103
- const { explorer } = config || /* istanbul ignore next */ {}
104
- if (!isLedgerExplorerConfig(explorer)) {
105
- throw new LedgerExplorerUsedIncorrectly(
106
- `Ledger explorer used incorrectly with currency: ${currencyId}`
107
- )
160
+ async function requestOpsPageWithRetries(
161
+ params: Required<OperationsRequestParams> & LedgerExplorerSettings & OrderedRequestParams,
162
+ paginationToken: string | null | undefined,
163
+ retries = DEFAULT_RETRIES_API
164
+ ): Promise<OpsPage> {
165
+ try {
166
+ return await requestOpsPage(params, paginationToken)
167
+ } catch (e) {
168
+ if (axios.isAxiosError(e) && e.response?.status === 429) {
169
+ throw new RateLimitError()
170
+ }
171
+ if (retries) {
172
+ await delay(LEDGER_TIMEOUT)
173
+ return requestOpsPageWithRetries(params, paginationToken, retries - 1)
174
+ }
175
+ throw e
108
176
  }
177
+ }
109
178
 
110
- const ledgerExplorerOps = await fetchPaginatedOpsWithRetries(
111
- {
112
- explorerUri: config.ledgerExplorerUri,
113
- clientVersion: config.ledgerClientVersion,
114
- explorerId: explorer.explorerId,
115
- address,
116
- fromBlock,
117
- batchSize: explorer.batchSize ?? DEFAULT_BATCH_SIZE,
118
- },
119
- null,
120
- [],
121
- explorer.retries ?? DEFAULT_RETRIES_API
179
+ /**
180
+ * A ledger-explorer pagination cursor: the height and hash of the last record a page delivered.
181
+ *
182
+ * Deliberately not the explorer's own continuation token — the framework's cursor contract
183
+ * requires a cursor that "can be used long after the last request and still provide consistent
184
+ * results" (`@ledgerhq/coin-module-framework/api/types`), which a server-side token with an
185
+ * undocumented lifetime does not guarantee by construction. Height-plus-hash needs no server
186
+ * state and doubles as the request's ceiling (descending) or floor (ascending) on the next call.
187
+ */
188
+ type LedgerCursor = { height: number; hash: string }
189
+
190
+ /** Serialises a cursor, or `NO_TOKEN` when there is no record to resume from. */
191
+ export function serializeLedgerCursor(record?: LedgerCursor): string {
192
+ return record ? `${record.height}:${record.hash}` : NO_TOKEN
193
+ }
194
+
195
+ /**
196
+ * Parses a cursor produced by `serializeLedgerCursor`. Returns `undefined` for an absent cursor
197
+ * or `NO_TOKEN` (first page); throws on anything else that does not match the `height:hash` shape
198
+ * — mirroring `deserializePagingToken`'s contract for the etherscan-like arm.
199
+ */
200
+ export function parseLedgerCursor(cursor: string | undefined): LedgerCursor | undefined {
201
+ if (cursor === undefined || cursor === NO_TOKEN) return undefined
202
+
203
+ const separatorIndex = cursor.indexOf(':')
204
+ const heightPart = cursor.slice(0, separatorIndex)
205
+ const hash = cursor.slice(separatorIndex + 1)
206
+ const height = Number.parseInt(heightPart, 10)
207
+
208
+ if (separatorIndex <= 0 || hash.length === 0 || Number.isNaN(height)) {
209
+ throw new Error(`Invalid ledger explorer cursor: ${cursor}`)
210
+ }
211
+
212
+ return { height, hash }
213
+ }
214
+
215
+ /**
216
+ * Resolves the block window for one paged request: the cursor caps a descending walk (it is a
217
+ * ceiling, combined with the caller's `toBlock` as the more restrictive of the two) and floors an
218
+ * ascending one (combined with the caller's `fromBlock` the same way). `from_height` is always a
219
+ * floor on this explorer, never a resume point — resuming a descending walk therefore goes
220
+ * through `to_height`, not `from_height`.
221
+ */
222
+ function resolveWindow(
223
+ order: 'asc' | 'desc',
224
+ fromBlock: number,
225
+ toBlock: number | undefined,
226
+ cursor: LedgerCursor | undefined
227
+ ): { fromBlock: number; toBlock: number | undefined } {
228
+ if (order === 'desc') {
229
+ const ceiling =
230
+ cursor === undefined
231
+ ? toBlock
232
+ : toBlock === undefined
233
+ ? cursor.height
234
+ : Math.min(cursor.height, toBlock)
235
+ return { fromBlock, toBlock: ceiling }
236
+ }
237
+
238
+ const floor = cursor === undefined ? fromBlock : Math.max(cursor.height, fromBlock)
239
+ return { fromBlock: floor, toBlock }
240
+ }
241
+
242
+ type PagedFetchParams = {
243
+ explorerId: string
244
+ address: string
245
+ fromBlock: number
246
+ toBlock?: number | undefined
247
+ cursor?: string | undefined
248
+ limit: number
249
+ order: 'asc' | 'desc'
250
+ /** Per-page retry budget; falls back to `DEFAULT_RETRIES_API` when the explorer sets none. */
251
+ retries?: number | undefined
252
+ } & LedgerExplorerSettings
253
+
254
+ /**
255
+ * Fetch exactly one page for a caller that supplied `limit`: one explorer request in the common
256
+ * case, more only to work around boundary exhaustion (see below). Never accumulates further
257
+ * pages — a caller that stops after this page causes no further explorer request.
258
+ */
259
+ async function fetchLedgerOpsPage(
260
+ params: PagedFetchParams
261
+ ): Promise<{ operations: LedgerExplorerOperation[]; nextPagingToken: string }> {
262
+ const cursor = parseLedgerCursor(params.cursor)
263
+ const { fromBlock, toBlock } = resolveWindow(
264
+ params.order,
265
+ params.fromBlock,
266
+ params.toBlock,
267
+ cursor
122
268
  )
123
269
 
270
+ let batchSize = params.limit
271
+ let records: LedgerExplorerOperation[] = []
272
+ let rawPageIsFull = false
273
+
274
+ for (;;) {
275
+ const { operations: rawRecords } = await requestOpsPageWithRetries(
276
+ {
277
+ explorerUri: params.explorerUri,
278
+ clientVersion: params.clientVersion,
279
+ explorerId: params.explorerId,
280
+ address: params.address,
281
+ fromBlock,
282
+ toBlock,
283
+ batchSize,
284
+ order: params.order,
285
+ },
286
+ undefined, // resumed through from_height/to_height, never through the explorer's token
287
+ params.retries
288
+ )
289
+
290
+ // A raw page at or beyond the explorer's own page-size ceiling can never prove the window is
291
+ // exhausted, no matter how large `batchSize` was asked to be (measured: requests above ~500
292
+ // are served as 500) — "full" is judged against whichever of the two is smaller, so doubling
293
+ // past that ceiling cannot be mistaken for the walk having reached the end of the window.
294
+ rawPageIsFull = rawRecords.length >= Math.min(batchSize, EXPLORER_MAX_PAGE_SIZE)
295
+
296
+ const cursorIndex = cursor ? rawRecords.findIndex((record) => record.hash === cursor.hash) : -1
297
+ // No cursor: the whole page is new. A cursor supplied but not located in this page is never
298
+ // treated as "nothing to skip" — that would risk re-serving already-delivered records if a
299
+ // caller changed `limit` between two calls — it is treated the same as an exhausted boundary
300
+ // block below, so the loop can only end once every already-delivered record is accounted for.
301
+ records = !cursor ? rawRecords : cursorIndex === -1 ? [] : rawRecords.slice(cursorIndex + 1)
302
+
303
+ // Boundary exhaustion: everything the cursor should skip is still in this page, and the raw
304
+ // page was full, so the block holding the cursor's record may hold more records than the
305
+ // requested page size. Enlarge the page and re-request the same window. Bounded by that
306
+ // block's record count: the loop ends once a new record surfaces or the explorer confirms
307
+ // there is nothing left (a raw page that is not full).
308
+ if (records.length > 0 || !rawPageIsFull) break
309
+
310
+ if (batchSize >= EXPLORER_MAX_PAGE_SIZE) {
311
+ // Even a request at the explorer's own ceiling cannot get past this block: there is no
312
+ // per-block offset in this API, so no `batch_size` ever will either. Paging through it is
313
+ // impossible, not merely slow — fail loudly rather than loop forever or silently report the
314
+ // end of the history (which would be indistinguishable from a genuinely complete one).
315
+ // This branch is only reachable with a cursor: without one, `records` always equals
316
+ // `rawRecords`, so `records.length === 0` (the other condition to reach here) requires an
317
+ // empty raw page, which is never "full" and breaks the loop before this check.
318
+ const boundaryHeight = cursor!.height
319
+ throw new UnpageableLedgerExplorerBlock(
320
+ `Ledger explorer block ${boundaryHeight} holds more records than a single page can ` +
321
+ `serve (explorer page-size ceiling: ${EXPLORER_MAX_PAGE_SIZE})`,
322
+ { blockHeight: boundaryHeight, explorerMaxPageSize: EXPLORER_MAX_PAGE_SIZE }
323
+ )
324
+ }
325
+ batchSize *= 2
326
+ }
327
+
328
+ // `rawPageIsFull` is only ever true when the loop above broke on `records.length > 0`, so
329
+ // `lastRecord` is always defined on that branch.
330
+ const lastRecord = records[records.length - 1]
331
+ const nextPagingToken = rawPageIsFull
332
+ ? serializeLedgerCursor({ height: lastRecord.block.height, hash: lastRecord.hash })
333
+ : NO_TOKEN
334
+
335
+ return { operations: records, nextPagingToken }
336
+ }
337
+
338
+ type AdaptedLedgerOperations = {
339
+ lastCoinOperations: Array<Operation<MemoNotSupported>>
340
+ lastTokenOperations: Array<Operation<MemoNotSupported>>
341
+ lastNftOperations: Array<Operation<MemoNotSupported>>
342
+ lastInternalOperations: Array<Operation<MemoNotSupported>>
343
+ }
344
+
345
+ /**
346
+ * Turns explorer records into the four operation buckets `getOperations` returns. Shared by both
347
+ * the legacy exhaustive path and the paged path: the same input records must produce the same
348
+ * operations regardless of which path fetched them.
349
+ */
350
+ function adaptLedgerRecords(
351
+ config: EvmConfigInfo,
352
+ currencyId: string,
353
+ address: string,
354
+ records: LedgerExplorerOperation[]
355
+ ): AdaptedLedgerOperations {
124
356
  const lastCoinOperations: Array<Operation<MemoNotSupported>> = []
125
357
  const lastTokenOperations: Array<Operation<MemoNotSupported>> = []
126
358
  const lastNftOperations: Array<Operation<MemoNotSupported>> = []
@@ -131,7 +363,7 @@ export const getOperations: ExplorerApi['getOperations'] = async (
131
363
  const isNativeContract = (contract: string): boolean =>
132
364
  nativeContractsSet.has(contract.toLowerCase())
133
365
 
134
- for (const ledgerOp of ledgerExplorerOps) {
366
+ for (const ledgerOp of records) {
135
367
  const coinOps = ledgerOperationToOperations(address, currencyId, ledgerOp)
136
368
 
137
369
  const erc20TransferEvents =
@@ -163,17 +395,157 @@ export const getOperations: ExplorerApi['getOperations'] = async (
163
395
  lastInternalOperations.push(...internalOps)
164
396
  }
165
397
 
398
+ return { lastCoinOperations, lastTokenOperations, lastNftOperations, lastInternalOperations }
399
+ }
400
+
401
+ /**
402
+ * Returns all operation types from an address.
403
+ *
404
+ * With no `limit`, Ledger explorer fetches all pages recursively internally, so `nextPagingToken`
405
+ * is always empty — this is the legacy, unchanged shape. With a `limit`, exactly one page is
406
+ * fetched and `nextPagingToken` carries a cursor the caller can resume from (see
407
+ * `serializeLedgerCursor`).
408
+ */
409
+ export const getOperations: ExplorerApi['getOperations'] = async (
410
+ config,
411
+ currencyId,
412
+ address,
413
+ fromBlock,
414
+ toBlock,
415
+ pagingToken,
416
+ limit,
417
+ order
418
+ ) => {
419
+ const { explorer } = config || /* istanbul ignore next */ {}
420
+ if (!isLedgerExplorerConfig(explorer)) {
421
+ throw new LedgerExplorerUsedIncorrectly(
422
+ `Ledger explorer used incorrectly with currency: ${currencyId}`
423
+ )
424
+ }
425
+
426
+ const settings = {
427
+ explorerUri: config.ledgerExplorerUri,
428
+ clientVersion: config.ledgerClientVersion,
429
+ explorerId: explorer.explorerId,
430
+ address,
431
+ }
432
+
433
+ let records: LedgerExplorerOperation[]
434
+ let nextPagingToken: string
435
+
436
+ if (limit === undefined) {
437
+ records = await fetchPaginatedOpsWithRetries(
438
+ {
439
+ ...settings,
440
+ fromBlock,
441
+ batchSize: explorer.batchSize ?? DEFAULT_BATCH_SIZE,
442
+ },
443
+ null,
444
+ [],
445
+ explorer.retries ?? DEFAULT_RETRIES_API
446
+ )
447
+ nextPagingToken = NO_TOKEN // Ledger explorer fetches all pages internally
448
+ } else {
449
+ const page = await fetchLedgerOpsPage({
450
+ ...settings,
451
+ fromBlock,
452
+ toBlock,
453
+ cursor: pagingToken,
454
+ limit,
455
+ order: order ?? 'desc',
456
+ retries: explorer.retries ?? DEFAULT_RETRIES_API,
457
+ })
458
+ records = page.operations
459
+ nextPagingToken = page.nextPagingToken
460
+ }
461
+
166
462
  return {
167
- lastCoinOperations,
168
- lastTokenOperations,
169
- lastNftOperations,
170
- lastInternalOperations,
171
- nextPagingToken: NO_TOKEN, // Ledger explorer fetches all pages internally
463
+ ...adaptLedgerRecords(config, currencyId, address, records),
464
+ nextPagingToken,
172
465
  }
173
466
  }
174
467
 
468
+ /**
469
+ * Discover which tokens an address holds by walking its ERC20 transfer events, one page at a
470
+ * time, without ever holding more than the current page in memory.
471
+ *
472
+ * Unlike `getOperations`, this walk loops instead of recursing over pages and drops each page
473
+ * once its events are folded into the running `Map<assetReference, AssetInfo>`, so its peak
474
+ * memory is O(distinct contracts), not O(history length). It never caps or truncates: it keeps
475
+ * walking until the explorer says there is no more, and a page that cannot be fetched after its
476
+ * own retry budget propagates rather than being skipped.
477
+ */
478
+ export const discoverTokenAssets: ExplorerApi['discoverTokenAssets'] = async (
479
+ config,
480
+ currencyId,
481
+ address,
482
+ fromBlock
483
+ ) => {
484
+ const { explorer } = config || /* istanbul ignore next */ {}
485
+ if (!isLedgerExplorerConfig(explorer)) {
486
+ throw new LedgerExplorerUsedIncorrectly(
487
+ `Ledger explorer used incorrectly with currency: ${currencyId}`
488
+ )
489
+ }
490
+
491
+ // A smaller operator-configured batch size is honoured (it only shrinks the page); a larger
492
+ // one cannot defeat the memory bound the discovery walk relies on. A non-positive one is not
493
+ // honoured at all: it would make every page empty, end the walk immediately, and report an
494
+ // account as holding no token -- which the framework turns into a zero balance on every token
495
+ // it does hold.
496
+ const configuredBatchSize = explorer.batchSize
497
+ const batchSize =
498
+ configuredBatchSize !== undefined && configuredBatchSize > 0
499
+ ? Math.min(configuredBatchSize, DISCOVERY_BATCH_SIZE)
500
+ : DISCOVERY_BATCH_SIZE
501
+ const params = {
502
+ explorerUri: config.ledgerExplorerUri,
503
+ clientVersion: config.ledgerClientVersion,
504
+ explorerId: explorer.explorerId,
505
+ address,
506
+ fromBlock: fromBlock ?? 0,
507
+ batchSize,
508
+ }
509
+
510
+ const checksummedAddress = eip55.encode(address)
511
+ const assets = new Map<string, AssetInfo>()
512
+ let token: string | null = null
513
+
514
+ for (;;) {
515
+ const page = await requestOpsPageWithRetries(
516
+ params,
517
+ token,
518
+ explorer.retries ?? DEFAULT_RETRIES_API
519
+ )
520
+
521
+ for (const record of page.operations) {
522
+ for (const event of record.transfer_events) {
523
+ // Same party filter as the ERC20 adapter: an event contributes an asset only if the
524
+ // requested address is its `from` or `to`, never a third party the address merely
525
+ // co-occurred with in the same transaction.
526
+ const isParty =
527
+ safeEncodeEIP55(event.from) === checksummedAddress ||
528
+ safeEncodeEIP55(event.to) === checksummedAddress
529
+ if (!isParty) continue
530
+
531
+ const contract = eip55.encode(event.contract)
532
+ assets.set(contract, { type: 'erc20', assetReference: contract, assetOwner: address })
533
+ }
534
+ }
535
+
536
+ // Stop on: a falsy token (normal end of history), an empty page that still carries a token
537
+ // (defends against a misbehaving explorer), or a token identical to the one just used (a
538
+ // cycling-cursor guard a plain recursion could not express).
539
+ if (!page.token || page.operations.length === 0 || page.token === token) break
540
+ token = page.token
541
+ }
542
+
543
+ return Array.from(assets.values())
544
+ }
545
+
175
546
  const ledgerExplorerAPI: ExplorerApi = {
176
547
  getOperations,
548
+ discoverTokenAssets,
177
549
  }
178
550
 
179
551
  export default ledgerExplorerAPI
@@ -18,8 +18,11 @@ export const getOperations: ExplorerApi['getOperations'] = async () => {
18
18
  }
19
19
  }
20
20
 
21
+ export const discoverTokenAssets: ExplorerApi['discoverTokenAssets'] = async () => []
22
+
21
23
  const noExplorerAPI: ExplorerApi = {
22
24
  getOperations,
25
+ discoverTokenAssets,
23
26
  }
24
27
 
25
28
  export default noExplorerAPI
@@ -2,7 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { EvmConfigInfo } from '../../config'
5
- import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
5
+ import type {
6
+ AssetInfo,
7
+ MemoNotSupported,
8
+ Operation,
9
+ } from '@ledgerhq/coin-module-framework/api/types'
10
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
6
11
 
7
12
  /** Constant representing no pagination token (end of pagination or first page) */
8
13
  export const NO_TOKEN = ''
@@ -13,10 +18,11 @@ export type ExplorerApi = {
13
18
  currencyId: string,
14
19
  address: string,
15
20
  fromBlock: number,
16
- toBlock?: number,
17
- pagingToken?: string,
18
- limit?: number,
19
- order?: 'asc' | 'desc'
21
+ toBlock: number | undefined,
22
+ pagingToken: string | undefined,
23
+ limit: number | undefined,
24
+ order: 'asc' | 'desc' | undefined,
25
+ logger: Logger
20
26
  ) => Promise<{
21
27
  lastCoinOperations: Array<Operation<MemoNotSupported>>
22
28
  lastTokenOperations: Array<Operation<MemoNotSupported>>
@@ -24,6 +30,24 @@ export type ExplorerApi = {
24
30
  lastInternalOperations: Array<Operation<MemoNotSupported>>
25
31
  nextPagingToken: string
26
32
  }>
33
+
34
+ /**
35
+ * Discover the tokens an address holds, without accumulating its operation history.
36
+ *
37
+ * Returns the deduplicated set of assets the address has ever transferred, as of the current
38
+ * chain head (or resumed from `fromBlock` when the arm supports it) — never operations, never
39
+ * raw explorer records. This is the only input `getBalance` needs to know which contracts to
40
+ * read a balance for.
41
+ *
42
+ * @param fromBlock resume the walk from this height instead of from genesis; an arm that does
43
+ * not support resuming ignores it and walks the full history.
44
+ */
45
+ discoverTokenAssets: (
46
+ config: EvmConfigInfo,
47
+ currencyId: string,
48
+ address: string,
49
+ fromBlock?: number
50
+ ) => Promise<AssetInfo[]>
27
51
  }
28
52
 
29
53
  type ExplorerConfig = EvmConfigInfo['explorer']
@@ -0,0 +1,7 @@
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './node'
5
+ export * from './node/types'
6
+ export * from './gasTracker'
7
+ export * from './gasTracker/types'