@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
@@ -9,16 +9,17 @@ import type {
9
9
  MemoNotSupported,
10
10
  TransactionIntent,
11
11
  } from '@ledgerhq/coin-module-framework/api/index'
12
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
12
13
  import {
13
14
  isSendTransactionIntent,
14
15
  isStakingTransactionIntent,
15
16
  } from '@ledgerhq/coin-module-framework/utils'
16
17
  import BigNumber from 'bignumber.js'
17
18
  import { ethers } from 'ethers'
19
+ import { isEthAddress } from '../logic-public'
18
20
  import { getNodeApi } from '../network/node'
19
21
  import { buildStakingTransactionParams, prepareStakingIntent, STAKING_CONTRACTS } from '../staking'
20
22
  import { isNative, TransactionTypes } from '../types'
21
- import { isEthAddress } from '../utils'
22
23
  import { getErc20Data } from './getErc20Data'
23
24
 
24
25
  export function isApiGasOptions(options: unknown): options is ApiGasOptions {
@@ -155,11 +156,12 @@ export async function prepareUnsignedTxParams(
155
156
  config: EvmConfigInfo,
156
157
  currencyId: string,
157
158
  transactionIntent: TransactionIntent<MemoNotSupported, BufferTxData>,
159
+ logger: Logger,
158
160
  customFeesParameters?: FeeEstimation['parameters']
159
161
  ): Promise<TransactionLikeWithPreparedParams> {
160
162
  const { sender, type } = transactionIntent
161
163
  const transactionType = getTransactionType(type)
162
- const node = getNodeApi(config, currencyId)
164
+ const node = getNodeApi(config, currencyId, logger)
163
165
  const isSend = isSendTransactionIntent(transactionIntent)
164
166
 
165
167
  // Prepare staking intents once (can require async on-chain lookups). See: LIVE-32750
@@ -34,6 +34,7 @@ export async function craftTransaction(
34
34
  config,
35
35
  currencyId,
36
36
  transactionIntent,
37
+ context.logger,
37
38
  customFees?.parameters
38
39
  )
39
40
 
@@ -79,7 +80,7 @@ export async function craftTransaction(
79
80
  }
80
81
 
81
82
  if (!hasFeeData) {
82
- const node = getNodeApi(config, currencyId)
83
+ const node = getNodeApi(config, currencyId, context.logger)
83
84
  const feeData = await node.getFeeData(config, currencyId, {
84
85
  type,
85
86
  feesStrategy: customFees?.parameters?.feesStrategy as FeesStrategy | undefined,
@@ -11,15 +11,16 @@ import type {
11
11
  MemoNotSupported,
12
12
  TransactionIntent,
13
13
  } from '@ledgerhq/coin-module-framework/api/index'
14
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
14
15
  import type { TransactionLike } from 'ethers'
15
16
  import BigNumber from 'bignumber.js'
16
17
  import { Transaction } from 'ethers'
17
18
  import { getAdditionalLayer2Fees } from '../logic'
19
+ import { isEthAddress, isStakingIntent } from '../logic-public'
18
20
  import { getGasTracker } from '../network/gasTracker'
19
21
  import { getNodeApi } from '../network/node'
20
22
  import { STAKING_CONTRACTS } from '../staking'
21
23
  import { TransactionTypes } from '../types'
22
- import { isEthAddress, isStakingIntent } from '../utils'
23
24
  import { getTransactionType, prepareUnsignedTxParams } from './common'
24
25
  import { getNextSequence } from './getNextSequence'
25
26
 
@@ -28,7 +29,8 @@ const SEND_MAX_L1_FEE_BUFFER = new BigNumber(2)
28
29
  async function computeAdditionalFees(
29
30
  config: EvmConfigInfo,
30
31
  currencyId: string,
31
- unsignedTransaction: TransactionLike
32
+ unsignedTransaction: TransactionLike,
33
+ logger: Logger
32
34
  ): Promise<BigNumber | undefined> {
33
35
  // Fake signature is added to get the best approximation possible for the gas on L1
34
36
  const transaction: TransactionLike = {
@@ -44,7 +46,8 @@ async function computeAdditionalFees(
44
46
  return await getAdditionalLayer2Fees(
45
47
  config,
46
48
  currencyId,
47
- Transaction.from(transaction).serialized
49
+ Transaction.from(transaction).serialized,
50
+ logger
48
51
  )
49
52
  } catch {
50
53
  return new BigNumber(0)
@@ -179,7 +182,7 @@ export async function estimateFees(
179
182
  return { finalFeeData: remoteGasOptions[feesStrategy], finalGasOptions: remoteGasOptions }
180
183
  }
181
184
 
182
- const node = getNodeApi(config, currencyId)
185
+ const node = getNodeApi(config, currencyId, context.logger)
183
186
  const feeData = await node.getFeeData(config, currencyId, {
184
187
  type: txType,
185
188
  feesStrategy,
@@ -192,7 +195,13 @@ export async function estimateFees(
192
195
  // all independent network calls and sequencing them triples the latency.
193
196
  const [{ to, data, value, gasLimit }, nonce, { finalFeeData, finalGasOptions }] =
194
197
  await Promise.all([
195
- prepareUnsignedTxParams(config, currencyId, transactionIntent, customFeesParameters),
198
+ prepareUnsignedTxParams(
199
+ config,
200
+ currencyId,
201
+ transactionIntent,
202
+ context.logger,
203
+ customFeesParameters
204
+ ),
196
205
  noncePromise,
197
206
  feeDataPromise,
198
207
  ])
@@ -230,7 +239,12 @@ export async function estimateFees(
230
239
  value,
231
240
  chainId,
232
241
  }
233
- const rawAdditionalFees = await computeAdditionalFees(config, currencyId, unsignedTransaction)
242
+ const rawAdditionalFees = await computeAdditionalFees(
243
+ config,
244
+ currencyId,
245
+ unsignedTransaction,
246
+ context.logger
247
+ )
234
248
  const additionalFees =
235
249
  transactionIntent.useAllAmount && rawAdditionalFees
236
250
  ? rawAdditionalFees.multipliedBy(SEND_MAX_L1_FEE_BUFFER).integerValue(BigNumber.ROUND_CEIL)
@@ -5,13 +5,7 @@ import type { EvmConfigInfo } from '../config'
5
5
  import type { EvmContext } from '../config'
6
6
  import type { ExplorerApi } from '../network/explorer/types'
7
7
  import type { NodeApi } from '../network/node/types'
8
- import type {
9
- Balance,
10
- AssetInfo,
11
- BalanceOptions,
12
- MemoNotSupported,
13
- Operation,
14
- } from '@ledgerhq/coin-module-framework/api/types'
8
+ import type { AssetInfo, Balance, BalanceOptions } from '@ledgerhq/coin-module-framework/api/types'
15
9
  import { getExplorerApi } from '../network/explorer'
16
10
  import { getNodeApi } from '../network/node'
17
11
  import { STAKING_CONFIG } from '../staking'
@@ -33,7 +27,7 @@ export async function getBalance(
33
27
  options?: BalanceOptions
34
28
  ): Promise<Balance[]> {
35
29
  const config = await context.config(currencyId)
36
- const nodeApi = getNodeApi(config, currencyId)
30
+ const nodeApi = getNodeApi(config, currencyId, context.logger)
37
31
  const explorerApi = getExplorerApi(config, currencyId)
38
32
 
39
33
  const [nativeBalance, tokensBalances] = await Promise.all([
@@ -69,27 +63,79 @@ async function getTokenBalances(
69
63
  ): Promise<Balance[]> {
70
64
  const balances: Balance[] = []
71
65
 
72
- const opsResult = await explorerApi
73
- .getOperations(config, currencyId, address, 0)
74
- .catch(() => null)
75
- const lastCoinOperations = opsResult?.lastCoinOperations ?? []
76
- const lastTokenOperations = opsResult?.lastTokenOperations ?? []
66
+ // Monad's `getStakes` extracts "known" validator IDs from delegate/undelegate/withdraw calls
67
+ // found in the account's coin operations (`extractKnownValIds`, `staking/validators/monad.ts`).
68
+ // For a currency that declares an extractor, the SAME `getOperations` walk also serves as
69
+ // this currency's token-discovery source (its `lastTokenOperations`) — the account's history
70
+ // is walked once, not twice, and `discoverTokenAssets` is not called on this branch. Every
71
+ // other currency relies solely on the bounded `discoverTokenAssets` walk. Either way, a failed
72
+ // walk must not be reported as a successful empty one: the framework turns an empty token
73
+ // list into `{ value: 0n }` for every already-known sub-account, which would silently display
74
+ // a held token's balance as zero — so the explorer's own error is left to propagate, never
75
+ // swallowed into an empty result.
76
+ const extractKnownValIds = STAKING_CONFIG[currencyId]?.extractKnownValIds
77
+
78
+ let discoveredAssets: AssetInfo[]
79
+ let knownValidatorIds: string[] | undefined
80
+
81
+ if (extractKnownValIds) {
82
+ const ops = await explorerApi.getOperations(
83
+ config,
84
+ currencyId,
85
+ address,
86
+ 0,
87
+ undefined,
88
+ undefined,
89
+ undefined,
90
+ undefined,
91
+ context.logger
92
+ )
93
+ knownValidatorIds = extractKnownValIds(currencyId, ops.lastCoinOperations)
94
+
95
+ discoveredAssets = []
96
+ for (const operation of ops.lastTokenOperations) {
97
+ if (!('assetReference' in operation.asset) || !operation.asset.assetReference) continue
98
+ discoveredAssets.push(operation.asset)
99
+ }
100
+ } else {
101
+ // Scanning from a height without the known set drops every asset last moved below it, which
102
+ // a consumer reads back as a zero balance on a token still held. The pair is ignored rather
103
+ // than half-applied: one extra full scan, no wrong balance.
104
+ const scanMinHeight = options?.knownAssets?.length ? options.scanAssetsMinHeight : undefined
105
+
106
+ discoveredAssets = await explorerApi.discoverTokenAssets(
107
+ config,
108
+ currencyId,
109
+ address,
110
+ scanMinHeight
111
+ )
112
+ }
77
113
 
78
- const knownValidatorIds = STAKING_CONFIG[currencyId]?.extractKnownValIds?.(
79
- currencyId,
80
- lastCoinOperations
81
- )
114
+ // `union(knownAssets, scanned)`, deduplicated on a lower-cased reference the way
115
+ // `nativeContracts` is matched below: nothing makes the two sources agree on casing, and a
116
+ // case-sensitive key would read one contract's balance twice. The scanned form wins, so the
117
+ // module keeps emitting its own normalisation.
118
+ const knownAssetsByReference = new Map<string, AssetInfo>()
119
+ for (const asset of [...(options?.knownAssets ?? []), ...discoveredAssets]) {
120
+ if (!('assetReference' in asset) || !asset.assetReference) continue
121
+ knownAssetsByReference.set(asset.assetReference.toLowerCase(), asset)
122
+ }
82
123
 
83
124
  // Contracts whose ERC20 balance mirrors the native balance — skip them here to avoid
84
125
  // counting the same value twice (the native balance is already returned upstream).
85
126
  const { nativeContracts = [] } = config
86
127
  const nativeContractsSet = new Set(nativeContracts.map((c) => c.toLowerCase()))
87
128
 
88
- // Staking and token-asset collection run in parallel; both depend only on the
89
- // operations result fetched above.
129
+ // Staking and token-asset collection run in parallel; staking depends on the coin operations
130
+ // fetched above (Monad only), token-asset collection on the discovered/known assets union.
90
131
  const [stakingResult, tokenAssetsResult] = await Promise.allSettled([
91
132
  getStakes(context, currencyId, address, { knownValidatorIds }),
92
- collectTokenAssets(lastTokenOperations, address, nativeContractsSet, options),
133
+ collectTokenAssets(
134
+ Array.from(knownAssetsByReference.values()),
135
+ address,
136
+ nativeContractsSet,
137
+ options
138
+ ),
93
139
  ])
94
140
 
95
141
  // Add staking positions to balances (with error handling)
@@ -130,12 +176,12 @@ async function getTokenBalances(
130
176
  }
131
177
 
132
178
  /**
133
- * Walk token-transfer operations and build the set of contracts whose balance we need,
179
+ * Walk the discovered/known assets and build the set of contracts whose balance we need,
134
180
  * along with their AssetInfo metadata. Contracts in `nativeContractsSet` are skipped
135
181
  * (their balance is the native balance, returned upstream).
136
182
  */
137
183
  async function collectTokenAssets(
138
- lastTokenOperations: Array<Operation<MemoNotSupported>>,
184
+ discoveredAssets: AssetInfo[],
139
185
  address: string,
140
186
  nativeContractsSet: Set<string>,
141
187
  options: BalanceOptions | undefined
@@ -143,14 +189,14 @@ async function collectTokenAssets(
143
189
  const contracts = new Set<string>()
144
190
  const assets = new Map<string, AssetInfo>()
145
191
 
146
- for (const operation of lastTokenOperations) {
147
- if (!('assetReference' in operation.asset)) continue
148
- const contract = operation.asset.assetReference
192
+ for (const asset of discoveredAssets) {
193
+ if (!('assetReference' in asset)) continue
194
+ const contract = asset.assetReference
149
195
  if (!contract) continue
150
196
  if (nativeContractsSet.has(contract.toLowerCase())) continue
151
197
 
152
198
  const assetInfo: AssetInfo = {
153
- type: operation.asset.type,
199
+ type: asset.type,
154
200
  assetReference: contract,
155
201
  assetOwner: address,
156
202
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import type { EvmContext } from '../config'
5
5
  import type { BlockReceiptInfo, PrefetchedBlockTransaction } from '../network/node/types'
6
+ import type { InternalTxsByHash } from './internalTransactionsFetcher'
6
7
  import type {
7
8
  Block,
8
9
  BlockInfo,
@@ -15,8 +16,8 @@ import { log } from '@ledgerhq/logs'
15
16
  import { rpcTransactionToBlockOperations } from '../adapters/blockOperations'
16
17
  import { DEFAULT_INTERNAL_TX_SOURCES } from '../config'
17
18
  import { UnsupportedRpcMethodError } from '../errors'
19
+ import { buildSmartContractDetails, safeEncodeEIP55 } from '../logic-public'
18
20
  import { getNodeApi } from '../network/node'
19
- import { buildSmartContractDetails, safeEncodeEIP55 } from '../utils'
20
21
  import { createInternalTransactionsFetcher } from './internalTransactionsFetcher'
21
22
  import { dropRootTraceDuplicates } from './rootTraceDedup'
22
23
 
@@ -30,9 +31,11 @@ export async function getBlock(
30
31
  // - fetch transaction receipts in one call using eth_getBlockReceipts
31
32
  // - if the RPC does not support prefetchTxs or eth_getBlockReceipts, fall back to fetching the transaction+receipts
32
33
  // one by one
33
- // - in parallel, fetch internal transactions from explorer (etherscan/blockscout) and merge into block transactions
34
+ // - unless the block is empty, fetch internal transactions (RPC trace methods or explorer,
35
+ // per `getBlockInternalTxsSources`) in parallel with the receipts, and merge them into the
36
+ // block transactions
34
37
  const config = await context.config(currencyId)
35
- const nodeApi = getNodeApi(config, currencyId)
38
+ const nodeApi = getNodeApi(config, currencyId, context.logger)
36
39
  const internalTxSources = config.getBlockInternalTxsSources ?? DEFAULT_INTERNAL_TX_SOURCES
37
40
  const fetchInternalTxs = createInternalTransactionsFetcher(
38
41
  config,
@@ -40,10 +43,8 @@ export async function getBlock(
40
43
  currencyId,
41
44
  internalTxSources
42
45
  )
43
- const [result, internalTxs] = await Promise.all([
44
- nodeApi.getBlockByHeight(currencyId, height, true),
45
- fetchInternalTxs(height),
46
- ])
46
+
47
+ const result = await nodeApi.getBlockByHeight(currencyId, height, true)
47
48
 
48
49
  const info: BlockInfo = {
49
50
  height: result.height,
@@ -58,13 +59,24 @@ export async function getBlock(
58
59
  }
59
60
  }
60
61
 
61
- const transactions = await getTransactionsFromNode(
62
- currencyId,
63
- result.transactionHashes || result.transactions?.map((tx) => tx.hash) || [],
64
- nodeApi,
65
- result.height,
66
- result.transactions
67
- )
62
+ const transactionHashes =
63
+ result.transactionHashes || result.transactions?.map((tx) => tx.hash) || []
64
+
65
+ // Internal transactions only exist inside transactions, so a block with none has nothing to
66
+ // merge. Skipping the fetch avoids a request for a guaranteed-empty answer — on the `explorer`
67
+ // source that is one metered `txlistinternal` call per empty block.
68
+ const [transactions, internalTxs] = await Promise.all([
69
+ getTransactionsFromNode(
70
+ currencyId,
71
+ transactionHashes,
72
+ nodeApi,
73
+ result.height,
74
+ result.transactions
75
+ ),
76
+ transactionHashes.length === 0
77
+ ? Promise.resolve<InternalTxsByHash>(new Map())
78
+ : fetchInternalTxs(height),
79
+ ])
68
80
 
69
81
  const mergedTransactions = mergeInternalTransactions(transactions, internalTxs)
70
82
 
@@ -11,7 +11,7 @@ export async function getBlockInfo(
11
11
  height: number
12
12
  ): Promise<BlockInfo> {
13
13
  const config = await context.config(currencyId)
14
- const api = getNodeApi(config, currencyId)
14
+ const api = getNodeApi(config, currencyId, context.logger)
15
15
  const result = await api.getBlockByHeight(currencyId, height)
16
16
 
17
17
  const blockInfo: BlockInfo = {
@@ -10,6 +10,9 @@ export async function getNextSequence(
10
10
  address: string
11
11
  ): Promise<bigint> {
12
12
  const config = await context.config(currencyId)
13
- const txCount = await getNodeApi(config, currencyId).getTransactionCount(currencyId, address)
13
+ const txCount = await getNodeApi(config, currencyId, context.logger).getTransactionCount(
14
+ currencyId,
15
+ address
16
+ )
14
17
  return typeof txCount === 'number' ? BigInt(txCount) : txCount
15
18
  }
@@ -1,9 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ // Re-export the standalone L2-fees helper (src/logic.ts) so it stays reachable
5
+ // from the `@ledgerhq/coin-evm/logic` entry point.
6
+ export * from '../logic'
4
7
  export * from './broadcast'
5
8
  export * from './lastBlock'
6
9
  export * from './combine'
10
+ export * from './getErc20Data'
7
11
  export * from './getBalance'
8
12
  export * from './estimateFees'
9
13
  export * from './listOperations'
@@ -7,7 +7,7 @@ import { getNodeApi } from '../network/node'
7
7
 
8
8
  export async function lastBlock(context: EvmContext, currencyId: string): Promise<BlockInfo> {
9
9
  const config = await context.config(currencyId)
10
- const api = getNodeApi(config, currencyId)
10
+ const api = getNodeApi(config, currencyId, context.logger)
11
11
  const { finalizationLevel = 'latest' } = config
12
12
  const result = await api.getBlockByHeight(currencyId, finalizationLevel)
13
13
 
@@ -8,6 +8,7 @@ import type {
8
8
  Operation,
9
9
  ListOperationsOptions,
10
10
  } from '@ledgerhq/coin-module-framework/api/types'
11
+ import { InvalidParameterError } from '@ledgerhq/coin-module-framework/errors'
11
12
  import { getExplorerApi } from '../network/explorer'
12
13
 
13
14
  // the sort parameter has a double meaning:
@@ -47,6 +48,17 @@ export async function listOperations(
47
48
  address: string,
48
49
  options: ListOperationsOptions
49
50
  ): Promise<Page<Operation<MemoNotSupported>>> {
51
+ // A page of zero operations is not a page this module can serve: it carries no record to build
52
+ // a cursor from, so it could only be answered with the caller's own cursor -- which the
53
+ // response contract forbids (a truthy `next` must advance). Raised rather than clamped, because
54
+ // a caller asking for zero operations is a caller bug, not a preference to honour. The public
55
+ // HTTP schema does allow `limit: 0`, so this is reachable from outside this repository.
56
+ if (options.limit !== undefined && options.limit <= 0) {
57
+ throw new InvalidParameterError(
58
+ `listOperations: limit must be a positive integer, got ${options.limit}`
59
+ )
60
+ }
61
+
50
62
  const config = await context.config(currencyId)
51
63
  const explorerApi = getExplorerApi(config, currencyId)
52
64
  const explorerOrder = options.limit === undefined ? 'desc' : (options.order ?? 'desc')
@@ -64,7 +76,8 @@ export async function listOperations(
64
76
  undefined,
65
77
  options.cursor,
66
78
  options.limit,
67
- explorerOrder
79
+ explorerOrder,
80
+ context.logger
68
81
  )
69
82
 
70
83
  const tokenOrNftHashes = new Set(
@@ -0,0 +1,53 @@
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { EvmContext } from '../../config'
5
+ import { Wallet } from 'ethers'
6
+ import {
7
+ createMockEvmConfigInfo,
8
+ createMockEvmContext,
9
+ mkExternalNode,
10
+ mkLedgerNode,
11
+ } from '../../fixtures/context.fixtures'
12
+ import broadcast from '../broadcast'
13
+
14
+ const contextForNetwork = (network: string): EvmContext => {
15
+ switch (network) {
16
+ case 'ethereum':
17
+ return createMockEvmContext(
18
+ createMockEvmConfigInfo({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) })
19
+ )
20
+ case 'sonic':
21
+ return createMockEvmContext(
22
+ createMockEvmConfigInfo({
23
+ chainId: 146,
24
+ node: mkExternalNode({ uri: 'https://sonic.coin.ledger.com' }),
25
+ })
26
+ )
27
+ default:
28
+ throw new Error('Unhandled currency')
29
+ }
30
+ }
31
+
32
+ describe('Broadcast', () => {
33
+ it.each([
34
+ ['ethereum', 1],
35
+ ['sonic', 146],
36
+ ])('throws on insufficient funds on %s', async (network, chainId) => {
37
+ const wallet = Wallet.createRandom()
38
+ const tx = {
39
+ to: wallet.address,
40
+ value: 1n,
41
+ nonce: 0,
42
+ gasLimit: 21000n,
43
+ maxFeePerGas: 10000000000000n,
44
+ maxPriorityFeePerGas: 1000000000n,
45
+ chainId,
46
+ }
47
+ const signature = await wallet.signTransaction(tx)
48
+
49
+ await expect(broadcast(contextForNetwork(network), network, { signature })).rejects.toThrow(
50
+ /insufficient funds for gas \* price \+ value|InsufficientFunds/
51
+ )
52
+ })
53
+ })
@@ -1,13 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { mockEvmContext } from '../fixtures/context.fixtures'
5
- import { getNodeApi } from '../network/node/index'
6
- import { mockNodeApi } from '../network/node/node.fixtures'
7
- import { broadcast } from './broadcast'
4
+ import { mockEvmContext } from '../../fixtures/context.fixtures'
5
+ import { getNodeApi } from '../../network/node/index'
6
+ import { mockNodeApi } from '../../network/node/node.fixtures'
7
+ import { broadcast } from '../broadcast'
8
8
 
9
- jest.mock('../network/node/index', () => ({
10
- ...jest.requireActual('../network/node/index'),
9
+ jest.mock('../../network/node/index', () => ({
10
+ ...jest.requireActual('../../network/node/index'),
11
11
  getNodeApi: jest.fn(),
12
12
  }))
13
13
 
@@ -27,7 +27,7 @@ describe('broadcastLogic', () => {
27
27
  signature: '0xabcdef',
28
28
  broadcastConfig: { mevProtected: true },
29
29
  })
30
- expect(mockGetNodeApi).toHaveBeenCalledWith(expect.anything(), 'ethereum')
30
+ expect(mockGetNodeApi).toHaveBeenCalledWith(expect.anything(), 'ethereum', expect.any(Function))
31
31
  expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith('ethereum', '0xabcdef', {
32
32
  mevProtected: true,
33
33
  })
@@ -1,13 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { mockEvmContext } from '../fixtures/context.fixtures'
5
- import { getNodeApi } from '../network/node/index'
6
- import { mockNodeApi } from '../network/node/node.fixtures'
7
- import { broadcast } from './broadcast'
4
+ import { mockEvmContext } from '../../fixtures/context.fixtures'
5
+ import { getNodeApi } from '../../network/node/index'
6
+ import { mockNodeApi } from '../../network/node/node.fixtures'
7
+ import { broadcast } from '../broadcast'
8
8
 
9
- jest.mock('../network/node/index', () => ({
10
- ...jest.requireActual('../network/node/index'),
9
+ jest.mock('../../network/node/index', () => ({
10
+ ...jest.requireActual('../../network/node/index'),
11
11
  getNodeApi: jest.fn(),
12
12
  }))
13
13
 
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ethers, SigningKey, Wallet } from 'ethers'
5
- import { combine } from './combine'
5
+ import { combine } from '../combine'
6
6
 
7
7
  describe('combine', () => {
8
8
  const privateKey = '0xb40eddd40b507adb0df9d44fe668a12c7d43d75bb0a3fc46cdaba1fe46dede2d'