@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
package/src/constants.ts DELETED
@@ -1,9 +0,0 @@
1
- // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- const EVM_DEAD_ADDRESS = '0x000000000000000000000000000000000000dEaD'
5
- // zkSync bans the dead address, so it gets a near-dead but accepted address.
6
- const EVM_ZKSYNC_ADDRESS = '0x123000000000000000000000000000000000dEaD'
7
-
8
- export const getEvmDummyAddress = (currencyId: string): string =>
9
- currencyId === 'zksync' || currencyId === 'zksync_sepolia' ? EVM_ZKSYNC_ADDRESS : EVM_DEAD_ADDRESS
@@ -1,46 +0,0 @@
1
- // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { Wallet } from 'ethers'
5
- import { createContext, setCoinConfig } from '../config'
6
- import { createMockEvmCoinConfig, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
7
- import broadcast from './broadcast'
8
-
9
- describe('Broadcast', () => {
10
- beforeAll(() => {
11
- setCoinConfig((currency) => {
12
- switch (currency) {
13
- case 'ethereum':
14
- return createMockEvmCoinConfig({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) })
15
- case 'sonic':
16
- return createMockEvmCoinConfig({
17
- chainId: 146,
18
- node: mkExternalNode({ uri: 'https://sonic.coin.ledger.com' }),
19
- })
20
- default:
21
- throw new Error('Unhandled currency')
22
- }
23
- })
24
- })
25
-
26
- it.each([
27
- ['ethereum', 1],
28
- ['sonic', 146],
29
- ])('throws on insufficient funds on %s', async (network, chainId) => {
30
- const wallet = Wallet.createRandom()
31
- const tx = {
32
- to: wallet.address,
33
- value: 1n,
34
- nonce: 0,
35
- gasLimit: 21000n,
36
- maxFeePerGas: 10000000000000n,
37
- maxPriorityFeePerGas: 1000000000n,
38
- chainId,
39
- }
40
- const signature = await wallet.signTransaction(tx)
41
-
42
- await expect(broadcast(createContext(), network, { signature })).rejects.toThrow(
43
- /insufficient funds for gas \* price \+ value|InsufficientFunds/
44
- )
45
- })
46
- })
@@ -1,362 +0,0 @@
1
- // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { EvmContext } from '../config'
5
- import type { AssetInfo } from '@ledgerhq/coin-module-framework/api/types'
6
- import BigNumber from 'bignumber.js'
7
- import { createMockEvmContext } from '../fixtures/context.fixtures'
8
- import { getExplorerApi } from '../network/explorer'
9
- import { getNodeApi } from '../network/node'
10
- import { mockNodeApi } from '../network/node/node.fixtures'
11
- import { getStakes } from './getStakes'
12
- import { getBalance } from '.'
13
-
14
- jest.mock('../network/node', () => ({
15
- ...jest.requireActual('../network/node'),
16
- getNodeApi: jest.fn(),
17
- }))
18
-
19
- jest.mock('../network/explorer', () => ({
20
- getExplorerApi: jest.fn(),
21
- }))
22
-
23
- jest.mock('./getStakes', () => ({
24
- getStakes: jest.fn(),
25
- }))
26
-
27
- const mockGetNodeApi = jest.mocked(getNodeApi)
28
- const mockGetExplorerApi = jest.mocked(getExplorerApi)
29
- const mockGetStakes = jest.mocked(getStakes)
30
-
31
- describe('getBalance', () => {
32
- const nodeApiMock = mockNodeApi()
33
- let context: EvmContext
34
- const setNativeContracts = (nativeContracts?: string[]) => {
35
- context = createMockEvmContext(Array.isArray(nativeContracts) ? { nativeContracts } : {})
36
- }
37
-
38
- beforeEach(() => {
39
- jest.clearAllMocks()
40
- mockGetNodeApi.mockReturnValue(nodeApiMock)
41
- setNativeContracts()
42
- })
43
-
44
- it.each([
45
- [
46
- 'native balance only', // test description
47
- { lastTokenOperations: [], nextPagingToken: '' }, // operation
48
- {}, // token balances (empty)
49
- [
50
- {
51
- value: BigInt('10000000000000000000000'),
52
- asset: { type: 'native' },
53
- },
54
- {
55
- value: BigInt('10000000000000000000000'),
56
- asset: { type: 'native' },
57
- stake: {
58
- uid: 'address',
59
- address: 'address',
60
- state: 'active',
61
- asset: { type: 'native' },
62
- amount: BigInt('10000000000000000000000'),
63
- actions: [],
64
- },
65
- },
66
- ], // expected
67
- ],
68
- [
69
- 'native and token balances', // test description
70
- {
71
- lastTokenOperations: [
72
- { asset: { type: 'erc20', assetReference: '0x123' } },
73
- { asset: { type: 'erc20', assetReference: '0x123' } },
74
- { asset: { type: 'erc20', assetReference: '0x456' } },
75
- ],
76
- nextPagingToken: '',
77
- }, // operations
78
- { '0x123': '1000000', '0x456': '2000000' }, // token balances
79
- [
80
- {
81
- value: BigInt('10000000000000000000000'),
82
- asset: { type: 'native' },
83
- }, // native balance
84
- {
85
- value: BigInt('10000000000000000000000'),
86
- asset: { type: 'native' },
87
- stake: {
88
- uid: 'address',
89
- address: 'address',
90
- state: 'active',
91
- asset: { type: 'native' },
92
- amount: BigInt('10000000000000000000000'),
93
- actions: [],
94
- },
95
- }, // stake
96
- {
97
- value: BigInt('1000000'),
98
- asset: { type: 'erc20', assetReference: '0x123', assetOwner: 'address' },
99
- },
100
- {
101
- value: BigInt('2000000'),
102
- asset: { type: 'erc20', assetReference: '0x456', assetOwner: 'address' },
103
- },
104
- ], // expected
105
- ],
106
- ])('returns %s', async (_, operations, tokenBalances: Record<string, string>, expected) => {
107
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('10000000000000000000000'))
108
- nodeApiMock.getTokenBalance.mockImplementation(
109
- (_currency: unknown, _address: string, contractAddress: string) =>
110
- Promise.resolve(new BigNumber(tokenBalances[contractAddress] || '0'))
111
- )
112
-
113
- mockGetExplorerApi.mockReturnValue({
114
- getOperations: jest.fn().mockResolvedValue(operations),
115
- })
116
-
117
- // Mock getStakes to return the expected stake data
118
- mockGetStakes.mockResolvedValue({
119
- items: [
120
- {
121
- uid: 'address',
122
- address: 'address',
123
- state: 'active',
124
- asset: { type: 'native' },
125
- amount: BigInt('10000000000000000000000'),
126
- actions: [],
127
- },
128
- ],
129
- })
130
-
131
- expect(await getBalance(context, '', 'address')).toEqual(expected)
132
- })
133
-
134
- it.each([
135
- {
136
- title: 'only one token',
137
- operations: {
138
- lastTokenOperations: [
139
- { asset: { type: 'erc20', assetReference: '0x123' } },
140
- { asset: { type: 'erc20', assetReference: '0x456' } },
141
- ],
142
- nextPagingToken: '',
143
- },
144
- includeAssets: (assetInfo: AssetInfo) => {
145
- return Promise.resolve(
146
- 'assetReference' in assetInfo && assetInfo.assetReference === '0x123'
147
- )
148
- },
149
- expected: [
150
- {
151
- value: BigInt('1000000'),
152
- asset: { type: 'erc20', assetReference: '0x123', assetOwner: '0x000' },
153
- },
154
- ],
155
- },
156
- {
157
- title: 'all tokens except one',
158
- operations: {
159
- lastTokenOperations: [
160
- { asset: { type: 'erc20', assetReference: '0x123' } },
161
- { asset: { type: 'erc20', assetReference: '0x456' } },
162
- { asset: { type: 'erc20', assetReference: '0x789' } },
163
- ],
164
- nextPagingToken: '',
165
- },
166
- includeAssets: (assetInfo: AssetInfo) => {
167
- return Promise.resolve(
168
- 'assetReference' in assetInfo && assetInfo.assetReference !== '0x789'
169
- )
170
- },
171
- expected: [
172
- {
173
- value: BigInt('1'),
174
- asset: { type: 'erc20', assetReference: '0x123', assetOwner: '0x000' },
175
- },
176
- {
177
- value: BigInt('2'),
178
- asset: { type: 'erc20', assetReference: '0x456', assetOwner: '0x000' },
179
- },
180
- ],
181
- },
182
- ])(
183
- 'should fetch balance only for tokens filtered by options: $title',
184
- async ({ operations, includeAssets, expected }) => {
185
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
186
- mockGetStakes.mockResolvedValue({ items: [] })
187
-
188
- mockGetExplorerApi.mockReturnValue({
189
- getOperations: jest.fn().mockResolvedValue(operations),
190
- })
191
-
192
- const currency = ''
193
- const userAddress = '0x000'
194
-
195
- await getBalance(context, currency, userAddress, { includeAssets })
196
-
197
- expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(expected.length)
198
- for (const balance of expected) {
199
- expect(nodeApiMock.getTokenBalance).toHaveBeenCalledWith(
200
- currency,
201
- userAddress,
202
- balance.asset.assetReference
203
- )
204
- }
205
-
206
- const notSupportedTokens = operations.lastTokenOperations.filter(
207
- (token) =>
208
- !expected.some((item) => item.asset.assetReference === token.asset.assetReference)
209
- )
210
-
211
- expect(notSupportedTokens).not.toHaveLength(0)
212
- for (const token of notSupportedTokens) {
213
- expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalledWith(
214
- currency,
215
- userAddress,
216
- token.asset.assetReference
217
- )
218
- }
219
- }
220
- )
221
-
222
- it('is resilient when failing to fetch token balances', async () => {
223
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber(10))
224
- nodeApiMock.getTokenBalance.mockImplementation(
225
- (_currency: unknown, _address: string, contract: string) => {
226
- if (contract === 'contract2') {
227
- return Promise.reject(new Error('Scam token'))
228
- }
229
- return Promise.resolve(new BigNumber(2))
230
- }
231
- )
232
- mockGetExplorerApi.mockReturnValue({
233
- getOperations: jest.fn().mockResolvedValue({
234
- lastCoinOperations: [],
235
- lastTokenOperations: [
236
- { asset: { type: 'erc20', assetReference: 'contract1' } },
237
- { asset: { type: 'erc20', assetReference: 'contract1' } },
238
- { asset: { type: 'erc20', assetReference: 'contract2' } },
239
- ],
240
- lastNftOperations: [],
241
- lastInternalOperations: [],
242
- nextPagingToken: '',
243
- }),
244
- })
245
- mockGetStakes.mockResolvedValue({
246
- items: [],
247
- })
248
-
249
- const result = await getBalance(context, '', 'address')
250
-
251
- expect(result).toEqual([
252
- { asset: { type: 'native' }, value: 10n },
253
- {
254
- asset: {
255
- type: 'erc20',
256
- assetReference: 'contract1',
257
- assetOwner: 'address',
258
- },
259
- value: 2n,
260
- },
261
- ])
262
- })
263
-
264
- describe('nativeContracts', () => {
265
- const NATIVE_CONTRACT = '0x3600000000000000000000000000000000000000'
266
- const REGULAR_CONTRACT = '0x123'
267
-
268
- it('skips fetching ERC20 balance for contracts listed in nativeContracts', async () => {
269
- setNativeContracts([NATIVE_CONTRACT])
270
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('42'))
271
- nodeApiMock.getTokenBalance.mockResolvedValue(new BigNumber('999'))
272
- mockGetStakes.mockResolvedValue({ items: [] })
273
- mockGetExplorerApi.mockReturnValue({
274
- getOperations: jest.fn().mockResolvedValue({
275
- lastTokenOperations: [
276
- { asset: { type: 'erc20', assetReference: NATIVE_CONTRACT } },
277
- { asset: { type: 'erc20', assetReference: REGULAR_CONTRACT } },
278
- ],
279
- nextPagingToken: '',
280
- }),
281
- })
282
-
283
- const result = await getBalance(context, '', 'address')
284
-
285
- expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(1)
286
- expect(nodeApiMock.getTokenBalance).toHaveBeenCalledWith(
287
- expect.anything(),
288
- 'address',
289
- REGULAR_CONTRACT
290
- )
291
- expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalledWith(
292
- expect.anything(),
293
- expect.anything(),
294
- NATIVE_CONTRACT
295
- )
296
- expect(result).toEqual([
297
- { asset: { type: 'native' }, value: 42n },
298
- {
299
- asset: { type: 'erc20', assetReference: REGULAR_CONTRACT, assetOwner: 'address' },
300
- value: 999n,
301
- },
302
- ])
303
- })
304
-
305
- it('matches nativeContracts case-insensitively', async () => {
306
- setNativeContracts([NATIVE_CONTRACT.toUpperCase()])
307
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
308
- mockGetStakes.mockResolvedValue({ items: [] })
309
- mockGetExplorerApi.mockReturnValue({
310
- getOperations: jest.fn().mockResolvedValue({
311
- lastTokenOperations: [
312
- { asset: { type: 'erc20', assetReference: NATIVE_CONTRACT.toLowerCase() } },
313
- ],
314
- nextPagingToken: '',
315
- }),
316
- })
317
-
318
- await getBalance(context, '', 'address')
319
-
320
- expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalled()
321
- })
322
-
323
- it('does not skip any contract when nativeContracts is undefined', async () => {
324
- setNativeContracts(undefined)
325
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
326
- nodeApiMock.getTokenBalance.mockResolvedValue(new BigNumber('1'))
327
- mockGetStakes.mockResolvedValue({ items: [] })
328
- mockGetExplorerApi.mockReturnValue({
329
- getOperations: jest.fn().mockResolvedValue({
330
- lastTokenOperations: [
331
- { asset: { type: 'erc20', assetReference: NATIVE_CONTRACT } },
332
- { asset: { type: 'erc20', assetReference: REGULAR_CONTRACT } },
333
- ],
334
- nextPagingToken: '',
335
- }),
336
- })
337
-
338
- await getBalance(context, '', 'address')
339
-
340
- expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(2)
341
- })
342
- })
343
-
344
- it('returns empty stake when balance is zero', async () => {
345
- nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber(0))
346
-
347
- mockGetExplorerApi.mockReturnValue({
348
- getOperations: jest.fn().mockResolvedValue({ lastTokenOperations: [], nextPagingToken: '' }),
349
- })
350
-
351
- // Mock getStakes to return empty stakes
352
- mockGetStakes.mockResolvedValue({
353
- items: [],
354
- })
355
-
356
- const result = await getBalance(context, '', 'address')
357
- expect(result[0]).toEqual({
358
- value: BigInt('0'),
359
- asset: { type: 'native' },
360
- })
361
- })
362
- })