@ledgerhq/coin-evm 5.4.0 → 7.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 (342) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/docs/evm-family-integration-process/README.md +1 -1
  3. package/knip.json +2 -3
  4. package/lib/adapters/blockOperations.js +6 -6
  5. package/lib/adapters/blockOperations.js.map +1 -1
  6. package/lib/adapters/etherscan.js +23 -23
  7. package/lib/adapters/etherscan.js.map +1 -1
  8. package/lib/adapters/ledger.js +17 -17
  9. package/lib/adapters/ledger.js.map +1 -1
  10. package/lib/api/index.js +4 -4
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/config.d.ts +21 -15
  13. package/lib/config.d.ts.map +1 -1
  14. package/lib/config.js +5 -25
  15. package/lib/config.js.map +1 -1
  16. package/lib/errors.d.ts +9 -0
  17. package/lib/errors.d.ts.map +1 -1
  18. package/lib/errors.js +15 -1
  19. package/lib/errors.js.map +1 -1
  20. package/lib/logic/broadcast.js +1 -1
  21. package/lib/logic/broadcast.js.map +1 -1
  22. package/lib/logic/common.d.ts +2 -1
  23. package/lib/logic/common.d.ts.map +1 -1
  24. package/lib/logic/common.js +4 -4
  25. package/lib/logic/common.js.map +1 -1
  26. package/lib/logic/craftTransaction.d.ts.map +1 -1
  27. package/lib/logic/craftTransaction.js +2 -2
  28. package/lib/logic/craftTransaction.js.map +1 -1
  29. package/lib/logic/estimateFees.d.ts.map +1 -1
  30. package/lib/logic/estimateFees.js +9 -9
  31. package/lib/logic/estimateFees.js.map +1 -1
  32. package/lib/logic/getBalance.d.ts.map +1 -1
  33. package/lib/logic/getBalance.js +50 -16
  34. package/lib/logic/getBalance.js.map +1 -1
  35. package/lib/logic/getBlock.d.ts.map +1 -1
  36. package/lib/logic/getBlock.js +19 -11
  37. package/lib/logic/getBlock.js.map +1 -1
  38. package/lib/logic/getBlockInfo.js +1 -1
  39. package/lib/logic/getBlockInfo.js.map +1 -1
  40. package/lib/logic/getNextSequence.d.ts.map +1 -1
  41. package/lib/logic/getNextSequence.js +1 -1
  42. package/lib/logic/getNextSequence.js.map +1 -1
  43. package/lib/logic/index.d.ts +2 -0
  44. package/lib/logic/index.d.ts.map +1 -1
  45. package/lib/logic/index.js +4 -0
  46. package/lib/logic/index.js.map +1 -1
  47. package/lib/logic/lastBlock.js +1 -1
  48. package/lib/logic/lastBlock.js.map +1 -1
  49. package/lib/logic/listOperations.d.ts.map +1 -1
  50. package/lib/logic/listOperations.js +10 -1
  51. package/lib/logic/listOperations.js.map +1 -1
  52. package/lib/logic/validateIntent.d.ts.map +1 -1
  53. package/lib/logic/validateIntent.js +12 -12
  54. package/lib/logic/validateIntent.js.map +1 -1
  55. package/lib/logic-public/index.d.ts +3 -0
  56. package/lib/logic-public/index.d.ts.map +1 -0
  57. package/lib/logic-public/index.js +19 -0
  58. package/lib/logic-public/index.js.map +1 -0
  59. package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
  60. package/lib/logic-public/utils.d.ts.map +1 -0
  61. package/lib/logic-public/utils.js +166 -0
  62. package/lib/logic-public/utils.js.map +1 -0
  63. package/lib/logic.d.ts +2 -1
  64. package/lib/logic.d.ts.map +1 -1
  65. package/lib/logic.js +3 -3
  66. package/lib/logic.js.map +1 -1
  67. package/lib/network/explorer/etherscan.d.ts +16 -3
  68. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  69. package/lib/network/explorer/etherscan.js +61 -6
  70. package/lib/network/explorer/etherscan.js.map +1 -1
  71. package/lib/network/explorer/ledger.d.ts +50 -4
  72. package/lib/network/explorer/ledger.d.ts.map +1 -1
  73. package/lib/network/explorer/ledger.js +286 -37
  74. package/lib/network/explorer/ledger.js.map +1 -1
  75. package/lib/network/explorer/none.d.ts +1 -0
  76. package/lib/network/explorer/none.d.ts.map +1 -1
  77. package/lib/network/explorer/none.js +4 -1
  78. package/lib/network/explorer/none.js.map +1 -1
  79. package/lib/network/explorer/types.d.ts +15 -2
  80. package/lib/network/explorer/types.d.ts.map +1 -1
  81. package/lib/network/explorer/types.js.map +1 -1
  82. package/lib/network/index.d.ts +5 -0
  83. package/lib/network/index.d.ts.map +1 -0
  84. package/lib/network/index.js +23 -0
  85. package/lib/network/index.js.map +1 -0
  86. package/lib/network/node/explorerProxy.d.ts +27 -0
  87. package/lib/network/node/explorerProxy.d.ts.map +1 -0
  88. package/lib/network/node/explorerProxy.js +262 -0
  89. package/lib/network/node/explorerProxy.js.map +1 -0
  90. package/lib/network/node/index.d.ts +2 -1
  91. package/lib/network/node/index.d.ts.map +1 -1
  92. package/lib/network/node/index.js +11 -10
  93. package/lib/network/node/index.js.map +1 -1
  94. package/lib/network/node/ledger.js +7 -7
  95. package/lib/network/node/ledger.js.map +1 -1
  96. package/lib/network/node/rpc.common.d.ts +2 -2
  97. package/lib/network/node/rpc.common.js +19 -19
  98. package/lib/network/node/rpc.common.js.map +1 -1
  99. package/lib/network/node/withNodeSources.d.ts +21 -0
  100. package/lib/network/node/withNodeSources.d.ts.map +1 -0
  101. package/lib/network/node/withNodeSources.js +78 -0
  102. package/lib/network/node/withNodeSources.js.map +1 -0
  103. package/lib/nodeSources.d.ts +15 -0
  104. package/lib/nodeSources.d.ts.map +1 -0
  105. package/lib/nodeSources.js +33 -0
  106. package/lib/nodeSources.js.map +1 -0
  107. package/lib/staking/contracts.js +1 -1
  108. package/lib/staking/contracts.js.map +1 -1
  109. package/lib/staking/fetchers.js +1 -1
  110. package/lib/staking/fetchers.js.map +1 -1
  111. package/lib/staking/operations/sei.js +1 -1
  112. package/lib/staking/operations/sei.js.map +1 -1
  113. package/lib/staking/prepareIntents.js +3 -3
  114. package/lib/staking/prepareIntents.js.map +1 -1
  115. package/lib/staking/rewards.js +1 -1
  116. package/lib/staking/rewards.js.map +1 -1
  117. package/lib/staking/transactionData.js +2 -2
  118. package/lib/staking/transactionData.js.map +1 -1
  119. package/lib/staking/utils.d.ts +45 -0
  120. package/lib/staking/utils.d.ts.map +1 -0
  121. package/lib/{utils.js → staking/utils.js} +5 -164
  122. package/lib/staking/utils.js.map +1 -0
  123. package/lib/staking/validators/sei.js +1 -1
  124. package/lib/staking/validators/sei.js.map +1 -1
  125. package/lib/types/staking.d.ts +2 -2
  126. package/lib-es/adapters/blockOperations.js +1 -1
  127. package/lib-es/adapters/blockOperations.js.map +1 -1
  128. package/lib-es/adapters/etherscan.js +1 -1
  129. package/lib-es/adapters/etherscan.js.map +1 -1
  130. package/lib-es/adapters/ledger.js +1 -1
  131. package/lib-es/adapters/ledger.js.map +1 -1
  132. package/lib-es/api/index.js +2 -2
  133. package/lib-es/api/index.js.map +1 -1
  134. package/lib-es/config.d.ts +21 -15
  135. package/lib-es/config.d.ts.map +1 -1
  136. package/lib-es/config.js +1 -21
  137. package/lib-es/config.js.map +1 -1
  138. package/lib-es/errors.d.ts +9 -0
  139. package/lib-es/errors.d.ts.map +1 -1
  140. package/lib-es/errors.js +13 -0
  141. package/lib-es/errors.js.map +1 -1
  142. package/lib-es/logic/broadcast.js +1 -1
  143. package/lib-es/logic/broadcast.js.map +1 -1
  144. package/lib-es/logic/common.d.ts +2 -1
  145. package/lib-es/logic/common.d.ts.map +1 -1
  146. package/lib-es/logic/common.js +3 -3
  147. package/lib-es/logic/common.js.map +1 -1
  148. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  149. package/lib-es/logic/craftTransaction.js +2 -2
  150. package/lib-es/logic/craftTransaction.js.map +1 -1
  151. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  152. package/lib-es/logic/estimateFees.js +6 -6
  153. package/lib-es/logic/estimateFees.js.map +1 -1
  154. package/lib-es/logic/getBalance.d.ts.map +1 -1
  155. package/lib-es/logic/getBalance.js +50 -16
  156. package/lib-es/logic/getBalance.js.map +1 -1
  157. package/lib-es/logic/getBlock.d.ts.map +1 -1
  158. package/lib-es/logic/getBlock.js +16 -8
  159. package/lib-es/logic/getBlock.js.map +1 -1
  160. package/lib-es/logic/getBlockInfo.js +1 -1
  161. package/lib-es/logic/getBlockInfo.js.map +1 -1
  162. package/lib-es/logic/getNextSequence.d.ts.map +1 -1
  163. package/lib-es/logic/getNextSequence.js +1 -1
  164. package/lib-es/logic/getNextSequence.js.map +1 -1
  165. package/lib-es/logic/index.d.ts +2 -0
  166. package/lib-es/logic/index.d.ts.map +1 -1
  167. package/lib-es/logic/index.js +4 -0
  168. package/lib-es/logic/index.js.map +1 -1
  169. package/lib-es/logic/lastBlock.js +1 -1
  170. package/lib-es/logic/lastBlock.js.map +1 -1
  171. package/lib-es/logic/listOperations.d.ts.map +1 -1
  172. package/lib-es/logic/listOperations.js +10 -1
  173. package/lib-es/logic/listOperations.js.map +1 -1
  174. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  175. package/lib-es/logic/validateIntent.js +4 -4
  176. package/lib-es/logic/validateIntent.js.map +1 -1
  177. package/lib-es/logic-public/index.d.ts +3 -0
  178. package/lib-es/logic-public/index.d.ts.map +1 -0
  179. package/lib-es/logic-public/index.js +4 -0
  180. package/lib-es/logic-public/index.js.map +1 -0
  181. package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
  182. package/lib-es/logic-public/utils.d.ts.map +1 -0
  183. package/lib-es/logic-public/utils.js +150 -0
  184. package/lib-es/logic-public/utils.js.map +1 -0
  185. package/lib-es/logic.d.ts +2 -1
  186. package/lib-es/logic.d.ts.map +1 -1
  187. package/lib-es/logic.js +3 -3
  188. package/lib-es/logic.js.map +1 -1
  189. package/lib-es/network/explorer/etherscan.d.ts +16 -3
  190. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  191. package/lib-es/network/explorer/etherscan.js +60 -5
  192. package/lib-es/network/explorer/etherscan.js.map +1 -1
  193. package/lib-es/network/explorer/ledger.d.ts +50 -4
  194. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  195. package/lib-es/network/explorer/ledger.js +283 -37
  196. package/lib-es/network/explorer/ledger.js.map +1 -1
  197. package/lib-es/network/explorer/none.d.ts +1 -0
  198. package/lib-es/network/explorer/none.d.ts.map +1 -1
  199. package/lib-es/network/explorer/none.js +2 -0
  200. package/lib-es/network/explorer/none.js.map +1 -1
  201. package/lib-es/network/explorer/types.d.ts +15 -2
  202. package/lib-es/network/explorer/types.d.ts.map +1 -1
  203. package/lib-es/network/explorer/types.js.map +1 -1
  204. package/lib-es/network/index.d.ts +5 -0
  205. package/lib-es/network/index.d.ts.map +1 -0
  206. package/lib-es/network/index.js +7 -0
  207. package/lib-es/network/index.js.map +1 -0
  208. package/lib-es/network/node/explorerProxy.d.ts +27 -0
  209. package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
  210. package/lib-es/network/node/explorerProxy.js +254 -0
  211. package/lib-es/network/node/explorerProxy.js.map +1 -0
  212. package/lib-es/network/node/index.d.ts +2 -1
  213. package/lib-es/network/node/index.d.ts.map +1 -1
  214. package/lib-es/network/node/index.js +11 -10
  215. package/lib-es/network/node/index.js.map +1 -1
  216. package/lib-es/network/node/ledger.js +1 -1
  217. package/lib-es/network/node/ledger.js.map +1 -1
  218. package/lib-es/network/node/rpc.common.d.ts +2 -2
  219. package/lib-es/network/node/rpc.common.js +3 -3
  220. package/lib-es/network/node/rpc.common.js.map +1 -1
  221. package/lib-es/network/node/withNodeSources.d.ts +21 -0
  222. package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
  223. package/lib-es/network/node/withNodeSources.js +74 -0
  224. package/lib-es/network/node/withNodeSources.js.map +1 -0
  225. package/lib-es/nodeSources.d.ts +15 -0
  226. package/lib-es/nodeSources.d.ts.map +1 -0
  227. package/lib-es/nodeSources.js +28 -0
  228. package/lib-es/nodeSources.js.map +1 -0
  229. package/lib-es/staking/contracts.js +1 -1
  230. package/lib-es/staking/contracts.js.map +1 -1
  231. package/lib-es/staking/fetchers.js +1 -1
  232. package/lib-es/staking/fetchers.js.map +1 -1
  233. package/lib-es/staking/operations/sei.js +1 -1
  234. package/lib-es/staking/operations/sei.js.map +1 -1
  235. package/lib-es/staking/prepareIntents.js +1 -1
  236. package/lib-es/staking/prepareIntents.js.map +1 -1
  237. package/lib-es/staking/rewards.js +1 -1
  238. package/lib-es/staking/rewards.js.map +1 -1
  239. package/lib-es/staking/transactionData.js +1 -1
  240. package/lib-es/staking/transactionData.js.map +1 -1
  241. package/lib-es/staking/utils.d.ts +45 -0
  242. package/lib-es/staking/utils.d.ts.map +1 -0
  243. package/lib-es/{utils.js → staking/utils.js} +1 -147
  244. package/lib-es/staking/utils.js.map +1 -0
  245. package/lib-es/staking/validators/sei.js +1 -1
  246. package/lib-es/staking/validators/sei.js.map +1 -1
  247. package/lib-es/types/staking.d.ts +2 -2
  248. package/package.json +72 -7
  249. package/src/adapters/blockOperations.ts +1 -1
  250. package/src/adapters/etherscan.ts +1 -1
  251. package/src/adapters/ledger.ts +1 -1
  252. package/src/api/{index.arc_testnet.integ.test.ts → index.arc.integ.test.ts} +15 -12
  253. package/src/api/index.monad_testnet.integ.test.ts +95 -4
  254. package/src/api/index.ts +2 -2
  255. package/src/config.ts +22 -34
  256. package/src/errors.ts +13 -0
  257. package/src/fixtures/context.fixtures.ts +6 -1
  258. package/src/logic/broadcast.ts +1 -1
  259. package/src/logic/common.ts +4 -2
  260. package/src/logic/craftTransaction.ts +2 -1
  261. package/src/logic/estimateFees.ts +20 -6
  262. package/src/logic/getBalance.ts +72 -26
  263. package/src/logic/getBlock.ts +26 -14
  264. package/src/logic/getBlockInfo.ts +1 -1
  265. package/src/logic/getNextSequence.ts +4 -1
  266. package/src/logic/index.ts +4 -0
  267. package/src/logic/lastBlock.ts +1 -1
  268. package/src/logic/listOperations.ts +14 -1
  269. package/src/logic/tests/broadcast.integ.test.ts +53 -0
  270. package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
  271. package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
  272. package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
  273. package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
  274. package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
  275. package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
  276. package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
  277. package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
  278. package/src/logic/tests/getBalance.test.ts +602 -0
  279. package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
  280. package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
  281. package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
  282. package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
  283. package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
  284. package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
  285. package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
  286. package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
  287. package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
  288. package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
  289. package/src/logic/validateIntent.ts +7 -4
  290. package/src/logic-public/index.ts +18 -0
  291. package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
  292. package/src/logic-public/utils.ts +184 -0
  293. package/src/logic.test.ts +5 -59
  294. package/src/logic.ts +5 -3
  295. package/src/network/explorer/etherscan.test.ts +403 -195
  296. package/src/network/explorer/etherscan.ts +99 -10
  297. package/src/network/explorer/index.test.ts +27 -0
  298. package/src/network/explorer/ledger.test.ts +791 -62
  299. package/src/network/explorer/ledger.ts +426 -54
  300. package/src/network/explorer/none.ts +3 -0
  301. package/src/network/explorer/types.ts +29 -5
  302. package/src/network/index.ts +7 -0
  303. package/src/network/node/explorerProxy.test.ts +673 -0
  304. package/src/network/node/explorerProxy.ts +308 -0
  305. package/src/network/node/index.memoization.test.ts +22 -10
  306. package/src/network/node/index.test.ts +6 -3
  307. package/src/network/node/index.ts +11 -7
  308. package/src/network/node/ledger.ts +1 -1
  309. package/src/network/node/rpc.common.ts +3 -3
  310. package/src/network/node/rpc.test.ts +66 -105
  311. package/src/network/node/withNodeSources.test.ts +240 -0
  312. package/src/network/node/withNodeSources.ts +95 -0
  313. package/src/nodeSources.ts +38 -0
  314. package/src/staking/contracts.ts +1 -1
  315. package/src/staking/encoder.test.ts +1 -1
  316. package/src/staking/fetchers.ts +1 -1
  317. package/src/staking/operations/sei.ts +1 -1
  318. package/src/staking/prepareIntents.ts +1 -1
  319. package/src/staking/redelegations.test.ts +1 -1
  320. package/src/staking/rewards.test.ts +1 -1
  321. package/src/staking/rewards.ts +1 -1
  322. package/src/staking/transactionData.ts +1 -1
  323. package/src/staking/unbondings.test.ts +1 -1
  324. package/src/staking/utils.test.ts +25 -0
  325. package/src/{utils.ts → staking/utils.ts} +2 -182
  326. package/src/staking/validators/sei.ts +1 -1
  327. package/src/types/staking.ts +2 -2
  328. package/lib/constants.d.ts +0 -2
  329. package/lib/constants.d.ts.map +0 -1
  330. package/lib/constants.js +0 -11
  331. package/lib/constants.js.map +0 -1
  332. package/lib/utils.d.ts.map +0 -1
  333. package/lib/utils.js.map +0 -1
  334. package/lib-es/constants.d.ts +0 -2
  335. package/lib-es/constants.d.ts.map +0 -1
  336. package/lib-es/constants.js +0 -7
  337. package/lib-es/constants.js.map +0 -1
  338. package/lib-es/utils.d.ts.map +0 -1
  339. package/lib-es/utils.js.map +0 -1
  340. package/src/constants.ts +0 -9
  341. package/src/logic/broadcast.integ.test.ts +0 -46
  342. package/src/logic/getBalance.test.ts +0 -362
@@ -10,7 +10,12 @@ import type {
10
10
  EtherscanOperation,
11
11
  } from '../../types'
12
12
  import type { ExplorerApi } from './types'
13
- import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
13
+ import type {
14
+ AssetInfo,
15
+ MemoNotSupported,
16
+ Operation,
17
+ } from '@ledgerhq/coin-module-framework/api/types'
18
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
14
19
  import type { AxiosRequestConfig } from 'axios'
15
20
  import { delay } from '@ledgerhq/coin-module-framework/promises'
16
21
  import { makeLRUCache } from '@ledgerhq/live-network/cache'
@@ -39,6 +44,11 @@ import { isEtherscanLikeExplorerConfig } from './types'
39
44
  export const ETHERSCAN_TIMEOUT = 5000 // 5 seconds between 2 calls
40
45
  export const DEFAULT_RETRIES_API = 8
41
46
 
47
+ // Default upper bound on the extra pages `exhaustEndpoint` fetches to drain a boundary block,
48
+ // overridable per network with `explorer.maxBoundaryExhaustionPages`. Without it, an endpoint
49
+ // that keeps returning full pages of rows the adapter drops never terminates.
50
+ export const DEFAULT_MAX_BOUNDARY_EXHAUSTION_PAGES = 10
51
+
42
52
  function getConfiguredMaxLimit(config: EvmConfigInfo): number | undefined {
43
53
  const { explorer } = config || {}
44
54
  if (!isEtherscanLikeExplorerConfig(explorer)) return undefined
@@ -48,6 +58,16 @@ function getConfiguredMaxLimit(config: EvmConfigInfo): number | undefined {
48
58
  return flooredCap >= 1 ? flooredCap : undefined
49
59
  }
50
60
 
61
+ function getMaxBoundaryExhaustionPages(config: EvmConfigInfo): number {
62
+ const { explorer } = config || {}
63
+ const configured = isEtherscanLikeExplorerConfig(explorer)
64
+ ? explorer.maxBoundaryExhaustionPages
65
+ : undefined
66
+ return configured !== undefined && configured >= 0
67
+ ? Math.floor(configured)
68
+ : DEFAULT_MAX_BOUNDARY_EXHAUSTION_PAGES
69
+ }
70
+
51
71
  /**
52
72
  * Common parameters for fetching operations from an endpoint
53
73
  */
@@ -643,9 +663,11 @@ export type FetchOperations = (params: FetchOperationsParams) => Promise<Endpoin
643
663
  */
644
664
  export async function exhaustEndpoint(
645
665
  fetchOperations: FetchOperations,
646
- params: FetchOperationsParams
666
+ params: FetchOperationsParams,
667
+ logger: Logger
647
668
  ): Promise<EndpointResult> {
648
669
  const { limit } = params
670
+ const maxExtraPages = getMaxBoundaryExhaustionPages(params.config)
649
671
  const fetchPage = (
650
672
  page: number,
651
673
  limitOverride: number | undefined = limit
@@ -672,6 +694,14 @@ export async function exhaustEndpoint(
672
694
  return { ...firstPage, isPageFull: isPageFull(limit, firstPage.operations.length) }
673
695
  }
674
696
 
697
+ // A page whose raw rows are all dropped by the adapter (for `txlistinternal`, every
698
+ // `delegatecall` / `staticcall` / `callcode` row) yields no operations, so `boundBlock` is 0.
699
+ // There is no boundary block to drain: the loop below would filter every later page against
700
+ // block 0 and could only ever collect nothing. Stop and let the caller paginate.
701
+ if (firstPage.operations.length === 0) {
702
+ return firstPage
703
+ }
704
+
675
705
  // this is an optimization to avoid fetching the next page if the last 2 ops are not at the same block height (most likely case)
676
706
  // if the last 2 ops are at the same block height, we need to fetch the next pages
677
707
  // otherwise we can stop here (no heights spreading across pages)
@@ -700,12 +730,23 @@ export async function exhaustEndpoint(
700
730
  )
701
731
  allOperations.push(...boundaryOps)
702
732
  // Continue while all ops are at boundary block AND page is full (more pages might exist)
733
+ // `boundaryOps.length === nextPage.operations.length` also holds when a page adapts to no
734
+ // operations at all, which says nothing about the boundary block — hence the page budget.
703
735
  } while (
704
736
  boundaryOps.length === nextPage.operations.length &&
705
737
  nextPage.isPageFull &&
706
- !nextPage.isDone
738
+ !nextPage.isDone &&
739
+ currentPageNumber <= maxExtraPages
707
740
  )
708
741
 
742
+ if (currentPageNumber > maxExtraPages) {
743
+ logger(
744
+ 'warn',
745
+ 'EVM getOperations: boundary block exhaustion hit the page budget, some operations at this height may be missing',
746
+ { boundBlock: firstPage.boundBlock, pages: currentPageNumber, limit }
747
+ )
748
+ }
749
+
709
750
  // isDone = false if we found ops at other blocks (more to fetch), otherwise use last page's status
710
751
  const hasOpsAtOtherBlocks = boundaryOps.length < nextPage.operations.length
711
752
  const resultIsDone = hasOpsAtOtherBlocks ? false : nextPage.isDone
@@ -736,10 +777,11 @@ export const getOperations = makeLRUCache<
736
777
  currencyId: string,
737
778
  address: string,
738
779
  fromBlock: number,
739
- toBlock?: number,
740
- pagingToken?: string,
741
- limit?: number,
742
- order?: 'asc' | 'desc',
780
+ toBlock: number | undefined,
781
+ pagingToken: string | undefined,
782
+ limit: number | undefined,
783
+ order: 'asc' | 'desc' | undefined,
784
+ logger: Logger,
743
785
  ],
744
786
  {
745
787
  lastCoinOperations: Array<Operation<MemoNotSupported>>
@@ -749,7 +791,17 @@ export const getOperations = makeLRUCache<
749
791
  nextPagingToken: string
750
792
  }
751
793
  >(
752
- async (config, currencyId, address, fromBlock, toBlock, pagingToken, limit, order = 'desc') => {
794
+ async (
795
+ config,
796
+ currencyId,
797
+ address,
798
+ fromBlock,
799
+ toBlock,
800
+ pagingToken,
801
+ limit,
802
+ order = 'desc',
803
+ logger
804
+ ) => {
753
805
  try {
754
806
  const configuredMaxLimit = getConfiguredMaxLimit(config)
755
807
  const effectiveLimit =
@@ -803,7 +855,7 @@ export const getOperations = makeLRUCache<
803
855
  fromBlock: effectiveFromBlock,
804
856
  ...(effectiveToBlock !== undefined && { toBlock: effectiveToBlock }),
805
857
  }
806
- const result = await exhaustEndpoint(endpoint, params)
858
+ const result = await exhaustEndpoint(endpoint, params, logger)
807
859
  const effectiveBoundBlock = computeEffectiveBoundBlock(
808
860
  effectiveLimit,
809
861
  boundBlock,
@@ -888,7 +940,7 @@ export const getOperations = makeLRUCache<
888
940
  }
889
941
  } catch (err) {
890
942
  if (err instanceof RateLimitError) throw err
891
- log('EVM getOperations', 'Error while fetching data from Etherscan like API', err)
943
+ logger('EVM getOperations', 'Error while fetching data from Etherscan like API', err)
892
944
  const message =
893
945
  typeof err === 'string'
894
946
  ? err
@@ -911,12 +963,49 @@ export const getOperations = makeLRUCache<
911
963
  { ttl: ETHERSCAN_TIMEOUT }
912
964
  )
913
965
 
966
+ /**
967
+ * Discover which tokens an address holds through the dedicated ERC20 endpoint alone (`tokentx`,
968
+ * or the corescan equivalent), rather than through the full `getOperations` wrapper.
969
+ *
970
+ * `getBalance` only ever reads `lastTokenOperations` from `getOperations`'s result, and with
971
+ * `limit === undefined` (what a discovery call passes) `exhaustEndpoint` performs exactly one
972
+ * unbounded request per endpoint with no cross-endpoint bound in effect — so calling
973
+ * `getTokenOperations` alone yields the same asset references, while sparing the coin, internal
974
+ * and NFT endpoints, which this arm never needed to discover tokens.
975
+ */
976
+ export const discoverTokenAssets = makeLRUCache<
977
+ [config: EvmConfigInfo, currencyId: string, address: string, fromBlock?: number],
978
+ AssetInfo[]
979
+ >(
980
+ async (config, currencyId, address, fromBlock = 0) => {
981
+ const { operations } = await getTokenOperations({
982
+ currencyId,
983
+ config,
984
+ address,
985
+ fromBlock,
986
+ sort: 'desc',
987
+ })
988
+
989
+ const assets = new Map<string, AssetInfo>()
990
+ for (const operation of operations) {
991
+ if (!('assetReference' in operation.asset) || !operation.asset.assetReference) continue
992
+ assets.set(operation.asset.assetReference, operation.asset)
993
+ }
994
+
995
+ return Array.from(assets.values())
996
+ },
997
+ (_config, currencyId, address, fromBlock) => `${currencyId}:${address}:${fromBlock ?? 0}`,
998
+ { ttl: ETHERSCAN_TIMEOUT }
999
+ )
1000
+
914
1001
  const explorerApi: ExplorerApi = {
915
1002
  getOperations,
1003
+ discoverTokenAssets,
916
1004
  }
917
1005
 
918
1006
  const explorerApiNoCache: ExplorerApi = {
919
1007
  getOperations: getOperations.force,
1008
+ discoverTokenAssets: discoverTokenAssets.force,
920
1009
  }
921
1010
 
922
1011
  export default { explorerApi, explorerApiNoCache }
@@ -12,6 +12,7 @@ import {
12
12
  } from '../../fixtures/context.fixtures'
13
13
  import etherscanLikeApi from './etherscan'
14
14
  import ledgerExplorerApi from './ledger'
15
+ import noExplorerAPI from './none'
15
16
  import { getExplorerApi } from './index'
16
17
 
17
18
  const configFor = (currencyId: string): EvmConfigInfo => {
@@ -54,6 +55,8 @@ const configFor = (currencyId: string): EvmConfigInfo => {
54
55
  node,
55
56
  explorer: mkLedgerExplorer({ explorerId: 'eth' }),
56
57
  })
58
+ case 'none-coin':
59
+ return createMockEvmConfigInfo({ chainId: 1, node, explorer: { type: 'none' } })
57
60
  default:
58
61
  return createMockEvmConfigInfo({ chainId: 1, node })
59
62
  }
@@ -101,6 +104,30 @@ describe('EVM Family', () => {
101
104
 
102
105
  expect(explorerA).toBe(ledgerExplorerApi)
103
106
  })
107
+
108
+ it('should return the none api', () => {
109
+ const explorerA = getExplorerApi(configFor('none-coin'), 'none-coin')
110
+
111
+ expect(explorerA).toBe(noExplorerAPI)
112
+ })
113
+
114
+ it.each([
115
+ ['etherscan', 'etherscan-coin'],
116
+ ['ledger', 'ledger-coin'],
117
+ ['none', 'none-coin'],
118
+ ])('%s arm exposes discoverTokenAssets', (_type, currencyId) => {
119
+ const explorer = getExplorerApi(configFor(currencyId), currencyId)
120
+
121
+ expect(typeof explorer.discoverTokenAssets).toBe('function')
122
+ })
123
+
124
+ it('the none arm resolves discoverTokenAssets to an empty array', async () => {
125
+ const explorer = getExplorerApi(configFor('none-coin'), 'none-coin')
126
+
127
+ await expect(
128
+ explorer.discoverTokenAssets(configFor('none-coin'), 'none-coin', '0xaddress')
129
+ ).resolves.toEqual([])
130
+ })
104
131
  })
105
132
  })
106
133
  })