@ledgerhq/coin-evm 8.0.0 → 9.0.1

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 (288) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/docs/getBlock-internal-txs-schema.md +1 -1
  3. package/docs/network/node/index.md +3 -1
  4. package/lib/adapters/blockOperations.d.ts +4 -3
  5. package/lib/adapters/blockOperations.d.ts.map +1 -1
  6. package/lib/adapters/blockOperations.js +17 -17
  7. package/lib/adapters/blockOperations.js.map +1 -1
  8. package/lib/adapters/etherscan.d.ts +7 -6
  9. package/lib/adapters/etherscan.d.ts.map +1 -1
  10. package/lib/adapters/etherscan.js +19 -19
  11. package/lib/adapters/etherscan.js.map +1 -1
  12. package/lib/adapters/ledger.d.ts +6 -5
  13. package/lib/adapters/ledger.d.ts.map +1 -1
  14. package/lib/adapters/ledger.js +15 -15
  15. package/lib/adapters/ledger.js.map +1 -1
  16. package/lib/api/index.d.ts.map +1 -1
  17. package/lib/api/index.js +1 -2
  18. package/lib/api/index.js.map +1 -1
  19. package/lib/logic/common.js +1 -1
  20. package/lib/logic/common.js.map +1 -1
  21. package/lib/logic/getBalance.d.ts.map +1 -1
  22. package/lib/logic/getBalance.js +3 -3
  23. package/lib/logic/getBalance.js.map +1 -1
  24. package/lib/logic/getBlock.d.ts.map +1 -1
  25. package/lib/logic/getBlock.js +22 -23
  26. package/lib/logic/getBlock.js.map +1 -1
  27. package/lib/logic/getStakes.d.ts.map +1 -1
  28. package/lib/logic/getStakes.js +2 -2
  29. package/lib/logic/getStakes.js.map +1 -1
  30. package/lib/logic/internalTransactionsFetcher.d.ts +3 -2
  31. package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
  32. package/lib/logic/internalTransactionsFetcher.js +13 -10
  33. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  34. package/lib/logic/listOperations.js +1 -1
  35. package/lib/logic/listOperations.js.map +1 -1
  36. package/lib/logic-public/utils.d.ts +3 -2
  37. package/lib/logic-public/utils.d.ts.map +1 -1
  38. package/lib/logic-public/utils.js +7 -6
  39. package/lib/logic-public/utils.js.map +1 -1
  40. package/lib/network/explorer/etherscan.d.ts +3 -2
  41. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  42. package/lib/network/explorer/etherscan.js +13 -12
  43. package/lib/network/explorer/etherscan.js.map +1 -1
  44. package/lib/network/explorer/ledger.d.ts.map +1 -1
  45. package/lib/network/explorer/ledger.js +11 -11
  46. package/lib/network/explorer/ledger.js.map +1 -1
  47. package/lib/network/explorer/types.d.ts +2 -2
  48. package/lib/network/explorer/types.d.ts.map +1 -1
  49. package/lib/network/explorer/types.js.map +1 -1
  50. package/lib/network/node/explorerProxy.js +3 -3
  51. package/lib/network/node/explorerProxy.js.map +1 -1
  52. package/lib/network/node/index.d.ts.map +1 -1
  53. package/lib/network/node/index.js +2 -2
  54. package/lib/network/node/index.js.map +1 -1
  55. package/lib/network/node/ledger.d.ts +2 -1
  56. package/lib/network/node/ledger.d.ts.map +1 -1
  57. package/lib/network/node/ledger.js +9 -10
  58. package/lib/network/node/ledger.js.map +1 -1
  59. package/lib/network/node/rpc.common.d.ts +3 -2
  60. package/lib/network/node/rpc.common.d.ts.map +1 -1
  61. package/lib/network/node/rpc.common.js +52 -31
  62. package/lib/network/node/rpc.common.js.map +1 -1
  63. package/lib/network/node/rpc.errors.d.ts +1 -3
  64. package/lib/network/node/rpc.errors.d.ts.map +1 -1
  65. package/lib/network/node/rpc.errors.js +21 -2
  66. package/lib/network/node/rpc.errors.js.map +1 -1
  67. package/lib/staking/contracts.js +2 -2
  68. package/lib/staking/contracts.js.map +1 -1
  69. package/lib/staking/fetchers.d.ts.map +1 -1
  70. package/lib/staking/fetchers.js +7 -7
  71. package/lib/staking/fetchers.js.map +1 -1
  72. package/lib/staking/prepareIntents.d.ts +2 -1
  73. package/lib/staking/prepareIntents.d.ts.map +1 -1
  74. package/lib/staking/prepareIntents.js +4 -4
  75. package/lib/staking/prepareIntents.js.map +1 -1
  76. package/lib/staking/redelegations.d.ts +5 -4
  77. package/lib/staking/redelegations.d.ts.map +1 -1
  78. package/lib/staking/redelegations.js +13 -14
  79. package/lib/staking/redelegations.js.map +1 -1
  80. package/lib/staking/rewards.d.ts +2 -1
  81. package/lib/staking/rewards.d.ts.map +1 -1
  82. package/lib/staking/rewards.js +4 -5
  83. package/lib/staking/rewards.js.map +1 -1
  84. package/lib/staking/rewardsFromReceipt.d.ts +2 -1
  85. package/lib/staking/rewardsFromReceipt.d.ts.map +1 -1
  86. package/lib/staking/rewardsFromReceipt.js +2 -3
  87. package/lib/staking/rewardsFromReceipt.js.map +1 -1
  88. package/lib/staking/unbondings.d.ts +2 -1
  89. package/lib/staking/unbondings.d.ts.map +1 -1
  90. package/lib/staking/unbondings.js +4 -5
  91. package/lib/staking/unbondings.js.map +1 -1
  92. package/lib/staking/validators/index.d.ts +9 -4
  93. package/lib/staking/validators/index.d.ts.map +1 -1
  94. package/lib/staking/validators/index.js +19 -10
  95. package/lib/staking/validators/index.js.map +1 -1
  96. package/lib/staking/validators/monad.d.ts +6 -5
  97. package/lib/staking/validators/monad.d.ts.map +1 -1
  98. package/lib/staking/validators/monad.js +33 -29
  99. package/lib/staking/validators/monad.js.map +1 -1
  100. package/lib/staking/validators/monadResolver.d.ts +2 -1
  101. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  102. package/lib/staking/validators/monadResolver.js +2 -3
  103. package/lib/staking/validators/monadResolver.js.map +1 -1
  104. package/lib/staking/validators/somnia.d.ts +3 -2
  105. package/lib/staking/validators/somnia.d.ts.map +1 -1
  106. package/lib/staking/validators/somnia.js +16 -15
  107. package/lib/staking/validators/somnia.js.map +1 -1
  108. package/lib/staking/validators/types.d.ts +2 -1
  109. package/lib/staking/validators/types.d.ts.map +1 -1
  110. package/lib/staking/validators/zero_gravity.d.ts +2 -1
  111. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  112. package/lib/staking/validators/zero_gravity.js +7 -8
  113. package/lib/staking/validators/zero_gravity.js.map +1 -1
  114. package/lib/types/staking.d.ts +4 -3
  115. package/lib/types/staking.d.ts.map +1 -1
  116. package/lib-es/adapters/blockOperations.d.ts +4 -3
  117. package/lib-es/adapters/blockOperations.d.ts.map +1 -1
  118. package/lib-es/adapters/blockOperations.js +17 -17
  119. package/lib-es/adapters/blockOperations.js.map +1 -1
  120. package/lib-es/adapters/etherscan.d.ts +7 -6
  121. package/lib-es/adapters/etherscan.d.ts.map +1 -1
  122. package/lib-es/adapters/etherscan.js +19 -19
  123. package/lib-es/adapters/etherscan.js.map +1 -1
  124. package/lib-es/adapters/ledger.d.ts +6 -5
  125. package/lib-es/adapters/ledger.d.ts.map +1 -1
  126. package/lib-es/adapters/ledger.js +15 -15
  127. package/lib-es/adapters/ledger.js.map +1 -1
  128. package/lib-es/api/index.d.ts.map +1 -1
  129. package/lib-es/api/index.js +1 -2
  130. package/lib-es/api/index.js.map +1 -1
  131. package/lib-es/logic/common.js +1 -1
  132. package/lib-es/logic/common.js.map +1 -1
  133. package/lib-es/logic/getBalance.d.ts.map +1 -1
  134. package/lib-es/logic/getBalance.js +3 -3
  135. package/lib-es/logic/getBalance.js.map +1 -1
  136. package/lib-es/logic/getBlock.d.ts.map +1 -1
  137. package/lib-es/logic/getBlock.js +22 -23
  138. package/lib-es/logic/getBlock.js.map +1 -1
  139. package/lib-es/logic/getStakes.d.ts.map +1 -1
  140. package/lib-es/logic/getStakes.js +2 -2
  141. package/lib-es/logic/getStakes.js.map +1 -1
  142. package/lib-es/logic/internalTransactionsFetcher.d.ts +3 -2
  143. package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
  144. package/lib-es/logic/internalTransactionsFetcher.js +13 -10
  145. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  146. package/lib-es/logic/listOperations.js +1 -1
  147. package/lib-es/logic/listOperations.js.map +1 -1
  148. package/lib-es/logic-public/utils.d.ts +3 -2
  149. package/lib-es/logic-public/utils.d.ts.map +1 -1
  150. package/lib-es/logic-public/utils.js +7 -6
  151. package/lib-es/logic-public/utils.js.map +1 -1
  152. package/lib-es/network/explorer/etherscan.d.ts +3 -2
  153. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  154. package/lib-es/network/explorer/etherscan.js +13 -12
  155. package/lib-es/network/explorer/etherscan.js.map +1 -1
  156. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  157. package/lib-es/network/explorer/ledger.js +11 -11
  158. package/lib-es/network/explorer/ledger.js.map +1 -1
  159. package/lib-es/network/explorer/types.d.ts +2 -2
  160. package/lib-es/network/explorer/types.d.ts.map +1 -1
  161. package/lib-es/network/explorer/types.js.map +1 -1
  162. package/lib-es/network/node/explorerProxy.js +3 -3
  163. package/lib-es/network/node/explorerProxy.js.map +1 -1
  164. package/lib-es/network/node/index.d.ts.map +1 -1
  165. package/lib-es/network/node/index.js +2 -2
  166. package/lib-es/network/node/index.js.map +1 -1
  167. package/lib-es/network/node/ledger.d.ts +2 -1
  168. package/lib-es/network/node/ledger.d.ts.map +1 -1
  169. package/lib-es/network/node/ledger.js +9 -10
  170. package/lib-es/network/node/ledger.js.map +1 -1
  171. package/lib-es/network/node/rpc.common.d.ts +3 -2
  172. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  173. package/lib-es/network/node/rpc.common.js +53 -32
  174. package/lib-es/network/node/rpc.common.js.map +1 -1
  175. package/lib-es/network/node/rpc.errors.d.ts +1 -3
  176. package/lib-es/network/node/rpc.errors.d.ts.map +1 -1
  177. package/lib-es/network/node/rpc.errors.js +20 -2
  178. package/lib-es/network/node/rpc.errors.js.map +1 -1
  179. package/lib-es/staking/contracts.js +2 -2
  180. package/lib-es/staking/contracts.js.map +1 -1
  181. package/lib-es/staking/fetchers.d.ts.map +1 -1
  182. package/lib-es/staking/fetchers.js +7 -7
  183. package/lib-es/staking/fetchers.js.map +1 -1
  184. package/lib-es/staking/prepareIntents.d.ts +2 -1
  185. package/lib-es/staking/prepareIntents.d.ts.map +1 -1
  186. package/lib-es/staking/prepareIntents.js +4 -4
  187. package/lib-es/staking/prepareIntents.js.map +1 -1
  188. package/lib-es/staking/redelegations.d.ts +5 -4
  189. package/lib-es/staking/redelegations.d.ts.map +1 -1
  190. package/lib-es/staking/redelegations.js +13 -14
  191. package/lib-es/staking/redelegations.js.map +1 -1
  192. package/lib-es/staking/rewards.d.ts +2 -1
  193. package/lib-es/staking/rewards.d.ts.map +1 -1
  194. package/lib-es/staking/rewards.js +4 -5
  195. package/lib-es/staking/rewards.js.map +1 -1
  196. package/lib-es/staking/rewardsFromReceipt.d.ts +2 -1
  197. package/lib-es/staking/rewardsFromReceipt.d.ts.map +1 -1
  198. package/lib-es/staking/rewardsFromReceipt.js +2 -3
  199. package/lib-es/staking/rewardsFromReceipt.js.map +1 -1
  200. package/lib-es/staking/unbondings.d.ts +2 -1
  201. package/lib-es/staking/unbondings.d.ts.map +1 -1
  202. package/lib-es/staking/unbondings.js +4 -5
  203. package/lib-es/staking/unbondings.js.map +1 -1
  204. package/lib-es/staking/validators/index.d.ts +9 -4
  205. package/lib-es/staking/validators/index.d.ts.map +1 -1
  206. package/lib-es/staking/validators/index.js +18 -10
  207. package/lib-es/staking/validators/index.js.map +1 -1
  208. package/lib-es/staking/validators/monad.d.ts +6 -5
  209. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  210. package/lib-es/staking/validators/monad.js +33 -29
  211. package/lib-es/staking/validators/monad.js.map +1 -1
  212. package/lib-es/staking/validators/monadResolver.d.ts +2 -1
  213. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  214. package/lib-es/staking/validators/monadResolver.js +2 -3
  215. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  216. package/lib-es/staking/validators/somnia.d.ts +3 -2
  217. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  218. package/lib-es/staking/validators/somnia.js +16 -15
  219. package/lib-es/staking/validators/somnia.js.map +1 -1
  220. package/lib-es/staking/validators/types.d.ts +2 -1
  221. package/lib-es/staking/validators/types.d.ts.map +1 -1
  222. package/lib-es/staking/validators/zero_gravity.d.ts +2 -1
  223. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  224. package/lib-es/staking/validators/zero_gravity.js +7 -8
  225. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  226. package/lib-es/types/staking.d.ts +4 -3
  227. package/lib-es/types/staking.d.ts.map +1 -1
  228. package/package.json +4 -4
  229. package/src/adapters/blockOperations.test.ts +86 -67
  230. package/src/adapters/blockOperations.ts +28 -17
  231. package/src/adapters/etherscan.test.ts +151 -85
  232. package/src/adapters/etherscan.ts +27 -18
  233. package/src/adapters/ledger.test.ts +210 -83
  234. package/src/adapters/ledger.ts +21 -15
  235. package/src/api/index.integ.test.ts +7 -6
  236. package/src/api/index.test.ts +2 -2
  237. package/src/api/index.ts +1 -2
  238. package/src/logic/common.ts +1 -1
  239. package/src/logic/getBalance.ts +4 -3
  240. package/src/logic/getBlock.ts +43 -27
  241. package/src/logic/getStakes.ts +2 -1
  242. package/src/logic/internalTransactionsFetcher.ts +16 -10
  243. package/src/logic/listOperations.ts +2 -2
  244. package/src/logic/tests/getBalance.test.ts +5 -3
  245. package/src/logic/tests/getBlock.test.ts +16 -15
  246. package/src/logic/tests/internalTransactionsFetcher.test.ts +6 -5
  247. package/src/logic/tests/listOperations.test.ts +4 -4
  248. package/src/logic-public/tests/utils.test.ts +6 -5
  249. package/src/logic-public/utils.ts +8 -5
  250. package/src/logic.test.ts +5 -5
  251. package/src/network/explorer/etherscan.test.ts +169 -55
  252. package/src/network/explorer/etherscan.ts +27 -16
  253. package/src/network/explorer/index.test.ts +2 -1
  254. package/src/network/explorer/ledger.test.ts +207 -35
  255. package/src/network/explorer/ledger.ts +12 -8
  256. package/src/network/explorer/types.ts +3 -2
  257. package/src/network/node/explorerProxy.ts +3 -3
  258. package/src/network/node/index.ts +3 -2
  259. package/src/network/node/ledger.test.ts +25 -25
  260. package/src/network/node/ledger.ts +13 -10
  261. package/src/network/node/rpc.common.ts +107 -30
  262. package/src/network/node/rpc.errors.test.ts +53 -1
  263. package/src/network/node/rpc.errors.ts +25 -2
  264. package/src/network/node/rpc.test.ts +106 -47
  265. package/src/staking/contracts.ts +2 -2
  266. package/src/staking/fetchers.ts +20 -8
  267. package/src/staking/prepareIntents.test.ts +33 -12
  268. package/src/staking/prepareIntents.ts +9 -5
  269. package/src/staking/redelegations.test.ts +96 -35
  270. package/src/staking/redelegations.ts +20 -12
  271. package/src/staking/rewards.test.ts +15 -10
  272. package/src/staking/rewards.ts +8 -5
  273. package/src/staking/rewardsFromReceipt.test.ts +5 -4
  274. package/src/staking/rewardsFromReceipt.ts +4 -3
  275. package/src/staking/unbondings.test.ts +15 -12
  276. package/src/staking/unbondings.ts +7 -5
  277. package/src/staking/validators/index.ts +30 -10
  278. package/src/staking/validators/monad.test.ts +57 -43
  279. package/src/staking/validators/monad.ts +55 -32
  280. package/src/staking/validators/monadResolver.ts +4 -3
  281. package/src/staking/validators/somnia.test.ts +14 -13
  282. package/src/staking/validators/somnia.ts +35 -19
  283. package/src/staking/validators/types.ts +2 -0
  284. package/src/staking/validators/zero_gravity.test.ts +48 -26
  285. package/src/staking/validators/zero_gravity.ts +14 -8
  286. package/src/staking/validators.integ.test.ts +2 -2
  287. package/src/staking/validators.test.ts +30 -26
  288. package/src/types/staking.ts +9 -2
@@ -1,7 +1,11 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { isRpcMethodNotImplementedError } from './rpc.errors'
4
+ import {
5
+ isRpcMethodNotAvailableOnChainError,
6
+ isRpcMethodNotImplementedError,
7
+ isUnsupportedRpcMethodErrorMsg,
8
+ } from './rpc.errors'
5
9
 
6
10
  describe('isRpcMethodNotImplementedError', () => {
7
11
  it.each([
@@ -28,3 +32,51 @@ describe('isRpcMethodNotImplementedError', () => {
28
32
  expect(isRpcMethodNotImplementedError(error)).toBe(false)
29
33
  })
30
34
  })
35
+
36
+ describe('isUnsupportedRpcMethodErrorMsg', () => {
37
+ it.each([
38
+ [{ code: -32000, message: 'required historical state unavailable (reexec=0)' }],
39
+ [{ code: 27, message: 'Unknown state. First available state is 14823652' }],
40
+ ])('is true for %j', (error) => {
41
+ expect(isUnsupportedRpcMethodErrorMsg(error)).toBe(true)
42
+ })
43
+
44
+ it.each([
45
+ [{ code: -32000, message: 'execution reverted' }],
46
+ [{ code: 'TIMEOUT', message: 'timeout' }],
47
+ ])('is false for %j', (error) => {
48
+ expect(isUnsupportedRpcMethodErrorMsg(error)).toBe(false)
49
+ })
50
+ })
51
+
52
+ describe('isRpcMethodNotAvailableOnChainError', () => {
53
+ const alchemyMessage =
54
+ 'trace_block is not available on the ASTAR_MAINNET. For more information see our docs: https://docs.alchemy.com/alchemy/documentation/apis/ethereum'
55
+
56
+ it.each([
57
+ [{ code: -32600, message: alchemyMessage }],
58
+ [
59
+ {
60
+ code: 'SERVER_ERROR',
61
+ info: {
62
+ responseStatus: '400 Bad Request',
63
+ responseBody: JSON.stringify({
64
+ jsonrpc: '2.0',
65
+ id: 1,
66
+ error: { code: -32600, message: alchemyMessage },
67
+ }),
68
+ },
69
+ },
70
+ ],
71
+ ])('is true for %j', (error) => {
72
+ expect(isRpcMethodNotAvailableOnChainError(error)).toBe(true)
73
+ })
74
+
75
+ it.each([
76
+ [{ code: -32600, message: 'invalid request' }],
77
+ [{ code: -32000, message: 'header not found' }],
78
+ [{ code: 'TIMEOUT', message: 'timeout' }],
79
+ ])('is false for %j', (error) => {
80
+ expect(isRpcMethodNotAvailableOnChainError(error)).toBe(false)
81
+ })
82
+ })
@@ -43,10 +43,33 @@ export function isRpcMethodNotImplementedError(error: unknown): boolean {
43
43
 
44
44
  /**
45
45
  * call this function when RPC returns a generic code, like -32000 which can be used for different errors
46
+ *
47
+ * - "required historical state unavailable": geth node without the state for the requested block
48
+ * - "unknown state": Alchemy node without the state for the requested block
49
+ * (e.g. "Unknown state. First available state is 14823652")
46
50
  */
51
+ const HISTORICAL_STATE_UNAVAILABLE_MARKERS = [
52
+ 'required historical state unavailable',
53
+ 'unknown state',
54
+ ]
55
+
47
56
  export function isUnsupportedRpcMethodErrorMsg(error: unknown): boolean {
48
- const marker = 'required historical state unavailable'
49
- return collectRpcErrorFields(error).messages.some((m) => m.toLowerCase().includes(marker))
57
+ return collectRpcErrorFields(error).messages.some((m) => {
58
+ const message = m.toLowerCase()
59
+ return HISTORICAL_STATE_UNAVAILABLE_MARKERS.some((marker) => message.includes(marker))
60
+ })
61
+ }
62
+
63
+ /**
64
+ * Alchemy rejects methods it does not serve on a chain with a generic -32600 code and a message like
65
+ * "trace_block is not available on the ASTAR_MAINNET".
66
+ */
67
+ const RPC_METHOD_NOT_AVAILABLE_ON_CHAIN_MESSAGE = /\b\w+_\w+ is not available on\b/i
68
+
69
+ export function isRpcMethodNotAvailableOnChainError(error: unknown): boolean {
70
+ return collectRpcErrorFields(error).messages.some((m) =>
71
+ RPC_METHOD_NOT_AVAILABLE_ON_CHAIN_MESSAGE.test(m)
72
+ )
50
73
  }
51
74
 
52
75
  function extractRpcErrorCode(key: string, field: unknown): string | null {
@@ -7,7 +7,11 @@ import { delay } from '@ledgerhq/coin-module-framework/promises'
7
7
  import BigNumber from 'bignumber.js'
8
8
  import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
9
9
  import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
10
- import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
10
+ import {
11
+ createMockEvmConfigInfo,
12
+ mkExternalNode,
13
+ testLogger,
14
+ } from '../../fixtures/context.fixtures'
11
15
  import {
12
16
  mkBlock,
13
17
  mkTransactionReceipt,
@@ -32,11 +36,15 @@ const evmConfig = createMockEvmConfigInfo({
32
36
  node: mkExternalNode({ uri: 'http://test' }),
33
37
  })
34
38
 
35
- const nodeApi = createNodeApi(evmConfig, {
36
- type: 'external',
37
- uri: 'http://test',
38
- retries: DEFAULT_RETRIES_RPC_METHODS,
39
- })
39
+ const nodeApi = createNodeApi(
40
+ evmConfig,
41
+ {
42
+ type: 'external',
43
+ uri: 'http://test',
44
+ retries: DEFAULT_RETRIES_RPC_METHODS,
45
+ },
46
+ testLogger
47
+ )
40
48
 
41
49
  jest.useFakeTimers()
42
50
 
@@ -359,7 +367,7 @@ describe('EVM Family', () => {
359
367
  },
360
368
  ]
361
369
 
362
- const result = parseERC20TransfersFromLogs(logs)
370
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
363
371
 
364
372
  expect(result).toEqual([
365
373
  {
@@ -397,7 +405,7 @@ describe('EVM Family', () => {
397
405
  },
398
406
  ]
399
407
 
400
- const result = parseERC20TransfersFromLogs(logs)
408
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
401
409
  expect(result.map((r) => r.value)).toEqual([
402
410
  '5480989920044678351000',
403
411
  '81274972180027185554775',
@@ -426,7 +434,7 @@ describe('EVM Family', () => {
426
434
  },
427
435
  ]
428
436
 
429
- const result = parseERC20TransfersFromLogs(logs)
437
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
430
438
  // Only the Transfer, not the Approval
431
439
  expect(result.map((r) => r.value)).toEqual(['1'])
432
440
  })
@@ -440,13 +448,13 @@ describe('EVM Family', () => {
440
448
  },
441
449
  ]
442
450
 
443
- const result = parseERC20TransfersFromLogs(logs)
451
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
444
452
 
445
453
  expect(result).toHaveLength(0)
446
454
  })
447
455
 
448
456
  it('should handle empty logs array', () => {
449
- expect(parseERC20TransfersFromLogs([])).toEqual([])
457
+ expect(parseERC20TransfersFromLogs([], testLogger)).toEqual([])
450
458
  })
451
459
 
452
460
  describe('EIP-7708 SYSTEM_ADDRESS logs', () => {
@@ -462,14 +470,17 @@ describe('EVM Family', () => {
462
470
  })
463
471
 
464
472
  it('should skip Transfer-shaped logs emitted by SYSTEM_ADDRESS', () => {
465
- expect(parseERC20TransfersFromLogs([makeSystemTransferLog(SYSTEM_ADDRESS)])).toEqual([])
473
+ expect(
474
+ parseERC20TransfersFromLogs([makeSystemTransferLog(SYSTEM_ADDRESS)], testLogger)
475
+ ).toEqual([])
466
476
  })
467
477
 
468
478
  it('should skip SYSTEM_ADDRESS logs whatever the case of the emitter', () => {
469
479
  expect(
470
- parseERC20TransfersFromLogs([
471
- makeSystemTransferLog('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfE'),
472
- ])
480
+ parseERC20TransfersFromLogs(
481
+ [makeSystemTransferLog('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfE')],
482
+ testLogger
483
+ )
473
484
  ).toEqual([])
474
485
  })
475
486
 
@@ -493,7 +504,7 @@ describe('EVM Family', () => {
493
504
  },
494
505
  ]
495
506
 
496
- expect(parseERC20TransfersFromLogs(logs)).toEqual([])
507
+ expect(parseERC20TransfersFromLogs(logs, testLogger)).toEqual([])
497
508
  })
498
509
 
499
510
  it('should still parse a genuine ERC20 Transfer sitting next to a system log', () => {
@@ -510,7 +521,7 @@ describe('EVM Family', () => {
510
521
  },
511
522
  ]
512
523
 
513
- const result = parseERC20TransfersFromLogs(logs)
524
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
514
525
 
515
526
  expect(result).toEqual([
516
527
  {
@@ -564,7 +575,7 @@ describe('EVM Family', () => {
564
575
  // Note: ERC-1155 uses different event signatures (TransferSingle/TransferBatch)
565
576
  // so it's already filtered out by the topic[0] check, not by topics.length
566
577
 
567
- const result = parseERC20TransfersFromLogs(logs)
578
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
568
579
 
569
580
  expect(result.map((r) => r.value)).toEqual(['1'])
570
581
  })
@@ -583,7 +594,7 @@ describe('EVM Family', () => {
583
594
  },
584
595
  ]
585
596
 
586
- const result = parseERC20TransfersFromLogs(logs)
597
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
587
598
 
588
599
  expect(result).toEqual([])
589
600
  })
@@ -600,7 +611,7 @@ describe('EVM Family', () => {
600
611
  },
601
612
  ]
602
613
 
603
- const result = parseERC20TransfersFromLogs(logs)
614
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
604
615
 
605
616
  expect(result).toEqual([
606
617
  {
@@ -627,7 +638,7 @@ describe('EVM Family', () => {
627
638
  },
628
639
  ]
629
640
 
630
- const result = parseERC20TransfersFromLogs(logs)
641
+ const result = parseERC20TransfersFromLogs(logs, testLogger)
631
642
 
632
643
  expect(result).toEqual([
633
644
  {
@@ -645,16 +656,19 @@ describe('EVM Family', () => {
645
656
  it('parses Mint as Transfer from 0x0', () => {
646
657
  const MINT_TOPIC = '0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'
647
658
  const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
648
- const result = parseERC20TransfersFromLogs([
649
- {
650
- address: L2_BASE_TOKEN,
651
- topics: [
652
- MINT_TOPIC,
653
- '0x000000000000000000000000beb30f27e61efff46aa27dce18e23ee8d5a7c6a4',
654
- ],
655
- data: '0x0000000000000000000000000000000000000000000000000000000000000064',
656
- },
657
- ])
659
+ const result = parseERC20TransfersFromLogs(
660
+ [
661
+ {
662
+ address: L2_BASE_TOKEN,
663
+ topics: [
664
+ MINT_TOPIC,
665
+ '0x000000000000000000000000beb30f27e61efff46aa27dce18e23ee8d5a7c6a4',
666
+ ],
667
+ data: '0x0000000000000000000000000000000000000000000000000000000000000064',
668
+ },
669
+ ],
670
+ testLogger
671
+ )
658
672
  expect(result).toEqual([
659
673
  {
660
674
  asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
@@ -1204,6 +1218,38 @@ describe('EVM Family', () => {
1204
1218
  })
1205
1219
  })
1206
1220
 
1221
+ it('should throw when the node returns an empty stub block (zero timestamp)', async () => {
1222
+ // not mockResolvedValueOnce: the node API retries on error
1223
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
1224
+ mkBlock({
1225
+ hash: '0x9196eeae33b2e2a2080a9660a1b2554cf01260129756e26fc17e5cbd883bdb61',
1226
+ number: 956855,
1227
+ timestamp: 0,
1228
+ transactions: [],
1229
+ })
1230
+ )
1231
+
1232
+ await expect(nodeApi.getBlockByHeight(currencyId, 956855)).rejects.toThrow(
1233
+ 'Block 956855 not found (the node returned an empty stub block)'
1234
+ )
1235
+ })
1236
+
1237
+ it('should accept a zero timestamp on the genesis block', async () => {
1238
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
1239
+ mkBlock({
1240
+ hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1241
+ number: 0,
1242
+ timestamp: 0,
1243
+ transactions: [],
1244
+ })
1245
+ )
1246
+
1247
+ await expect(nodeApi.getBlockByHeight(currencyId, 0)).resolves.toMatchObject({
1248
+ height: 0,
1249
+ timestamp: 0,
1250
+ })
1251
+ })
1252
+
1207
1253
  it('should prefetch block transactions when requested', async () => {
1208
1254
  jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
1209
1255
  mkBlock({
@@ -1485,6 +1531,12 @@ describe('EVM Family', () => {
1485
1531
  message: 'API key is not allowed to access method',
1486
1532
  label: '-32053 (e.g. API key cannot call trace_block)',
1487
1533
  },
1534
+ {
1535
+ code: -32600,
1536
+ message:
1537
+ 'trace_block is not available on the ASTAR_MAINNET. For more information see our docs: https://docs.alchemy.com/alchemy/documentation/apis/ethereum',
1538
+ label: '-32600 (e.g. Alchemy method not available on chain)',
1539
+ },
1488
1540
  ])(
1489
1541
  'should throw UnsupportedRpcMethodError when trace_block returns $label',
1490
1542
  async ({ code, message }) => {
@@ -1574,24 +1626,31 @@ describe('EVM Family', () => {
1574
1626
  }
1575
1627
  )
1576
1628
 
1577
- it('throws UnsupportedRpcMethodError when debug_traceBlockByNumber reports historical state unavailable', async () => {
1578
- jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method: string) => {
1579
- if (method === 'debug_traceBlockByNumber') {
1580
- throw {
1581
- code: -32000,
1582
- message: 'required historical state unavailable (reexec=0)',
1629
+ it.each([
1630
+ { code: -32000, message: 'required historical state unavailable (reexec=0)', label: 'geth' },
1631
+ {
1632
+ code: 27,
1633
+ message: 'Unknown state. First available state is 14823652',
1634
+ label: 'Alchemy',
1635
+ },
1636
+ ])(
1637
+ 'throws UnsupportedRpcMethodError when debug_traceBlockByNumber reports historical state unavailable ($label)',
1638
+ async ({ code, message }) => {
1639
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method: string) => {
1640
+ if (method === 'debug_traceBlockByNumber') {
1641
+ throw { code, message }
1583
1642
  }
1584
- }
1585
- throw new Error(`Method not mocked: ${method}`)
1586
- })
1643
+ throw new Error(`Method not mocked: ${method}`)
1644
+ })
1587
1645
 
1588
- const err = await nodeApi.traceBlockGeth!(currencyId, 1).then(
1589
- () => null,
1590
- (e: unknown) => e
1591
- )
1592
- expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1593
- expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1594
- })
1646
+ const err = await nodeApi.traceBlockGeth!(currencyId, 1).then(
1647
+ () => null,
1648
+ (e: unknown) => e
1649
+ )
1650
+ expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1651
+ expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1652
+ }
1653
+ )
1595
1654
  })
1596
1655
 
1597
1656
  describe('getOptimismAdditionalFees', () => {
@@ -189,9 +189,9 @@ export const STAKING_CONTRACTS: Record<string, StakingContractConfig> = {
189
189
  // Including the delegation-queue delay (1–2 epochs), the maximum wait is ~3 epochs ≈ 17 h.
190
190
  // Source: https://docs.monad.xyz/monad-arch/consensus/staking (WITHDRAWAL_DELAY constant)
191
191
  unbondingPeriodDays: 0.75,
192
- resolveValidatorAddress: (config, d, _contractAddress) => {
192
+ resolveValidatorAddress: (config, d, _contractAddress, logger) => {
193
193
  return typeof d[0] === 'bigint'
194
- ? getValidatorAddressById(config, 'monad', d[0])
194
+ ? getValidatorAddressById(config, 'monad', d[0], logger)
195
195
  : Promise.resolve(null)
196
196
  },
197
197
  resolveOperationAmount: async (_config, decoded, operationType) => {
@@ -9,6 +9,7 @@ import type {
9
9
  StakingStrategy,
10
10
  } from '../types/staking'
11
11
  import type { Stake, Validator } from '@ledgerhq/coin-module-framework/api/types'
12
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
12
13
  import { delay } from '@ledgerhq/coin-module-framework/promises'
13
14
  import { evmUnit } from '../logic/evmUnit'
14
15
  import { withApi } from '../network/node/rpc.common'
@@ -29,18 +30,28 @@ const createStakingFetcher = (
29
30
  getValidatorsFn: (
30
31
  evmConfig: EvmConfigInfo,
31
32
  config: StakingContractConfig,
32
- currencyId: string
33
+ currencyId: string,
34
+ logger: Logger
33
35
  ) => Promise<Validator[]>
34
36
  ) => {
35
37
  return async (
36
38
  evmConfig: EvmConfigInfo,
37
39
  address: string,
38
40
  config: StakingContractConfig,
39
- currencyId: string
41
+ currencyId: string,
42
+ logger: Logger,
43
+ _knownValIds?: string[]
40
44
  ): Promise<Stake[]> => {
41
- const validators = await getValidatorsFn(evmConfig, config, currencyId)
45
+ const validators = await getValidatorsFn(evmConfig, config, currencyId, logger)
42
46
  const validatorAddresses = validators.map((v) => v.address)
43
- return getStakesForValidators(evmConfig, address, config, currencyId, validatorAddresses)
47
+ return getStakesForValidators(
48
+ evmConfig,
49
+ address,
50
+ config,
51
+ currencyId,
52
+ validatorAddresses,
53
+ logger
54
+ )
44
55
  }
45
56
  }
46
57
 
@@ -48,8 +59,8 @@ export const STAKING_CONFIG: Record<string, StakingStrategy> = {
48
59
  sei_evm: {
49
60
  // Sei returns its whole validator set in a single page, so the first page's
50
61
  // items are the complete list.
51
- fetcher: createStakingFetcher(async (evmConfig, _config, currencyId) => {
52
- const { items } = await getValidators(evmConfig, currencyId)
62
+ fetcher: createStakingFetcher(async (evmConfig, _config, currencyId, logger) => {
63
+ const { items } = await getValidators(evmConfig, currencyId, logger)
53
64
  return items
54
65
  }),
55
66
  },
@@ -214,7 +225,8 @@ const getStakesForValidators = async (
214
225
  address: string,
215
226
  config: StakingContractConfig,
216
227
  currencyId: string,
217
- validators: string[]
228
+ validators: string[],
229
+ logger: Logger
218
230
  ): Promise<Stake[]> => {
219
231
  if (validators.length === 0) {
220
232
  console.error('No validators available', { currencyId })
@@ -224,7 +236,7 @@ const getStakesForValidators = async (
224
236
  // Fired here so its latency overlaps the precompile batch loop below;
225
237
  // awaited at the end. Any failure resolves to an empty map so the staking
226
238
  // sync never blocks on the off-chain rewards call.
227
- const rewardsPromise = fetchRewards(evmConfig, currencyId, address).catch(
239
+ const rewardsPromise = fetchRewards(evmConfig, currencyId, address, logger).catch(
228
240
  () => new Map<string, bigint>()
229
241
  )
230
242
 
@@ -7,7 +7,7 @@ import type { TransactionRequest } from 'ethers'
7
7
  import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
8
8
  import { ethers } from 'ethers'
9
9
  import zeroGravityAbi from '../abis/zero_gravity-validator.abi.json'
10
- import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
10
+ import { createMockEvmConfigInfo, mkExternalNode, testLogger } from '../fixtures/context.fixtures'
11
11
  import { withApi } from '../network/node/rpc.common'
12
12
  import { isExternalNodeConfig } from '../network/node/types'
13
13
  import { prepareStakingIntent } from './prepareIntents'
@@ -88,7 +88,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
88
88
  const result = await prepareStakingIntent(
89
89
  mockConfig,
90
90
  'zero_gravity',
91
- makeIntent({ useAllAmount: false })
91
+ makeIntent({ useAllAmount: false }),
92
+ testLogger
92
93
  )
93
94
 
94
95
  expect(result).toMatchObject({ shares: 1_500_000_000n, txValue: 5n * 10n ** 9n })
@@ -98,7 +99,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
98
99
  setupProvider(makeCallHandler({ getDelegationShares: 0n }))
99
100
 
100
101
  await expect(
101
- prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent({ useAllAmount: false }))
102
+ prepareStakingIntent(
103
+ mockConfig,
104
+ 'zero_gravity',
105
+ makeIntent({ useAllAmount: false }),
106
+ testLogger
107
+ )
102
108
  ).rejects.toThrow('no shares to undelegate from this validator')
103
109
  })
104
110
 
@@ -114,7 +120,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
114
120
  const result = await prepareStakingIntent(
115
121
  mockConfig,
116
122
  'zero_gravity',
117
- makeIntent({ useAllAmount: false })
123
+ makeIntent({ useAllAmount: false }),
124
+ testLogger
118
125
  )
119
126
 
120
127
  expect(result).toMatchObject({ shares: 2_000_000_000n })
@@ -132,7 +139,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
132
139
  const result = await prepareStakingIntent(
133
140
  mockConfig,
134
141
  'zero_gravity',
135
- makeIntent({ useAllAmount: false })
142
+ makeIntent({ useAllAmount: false }),
143
+ testLogger
136
144
  )
137
145
 
138
146
  expect(result).toMatchObject({ shares: 1_000_000_000n })
@@ -148,7 +156,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
148
156
  )
149
157
 
150
158
  await expect(
151
- prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent({ useAllAmount: false }))
159
+ prepareStakingIntent(
160
+ mockConfig,
161
+ 'zero_gravity',
162
+ makeIntent({ useAllAmount: false }),
163
+ testLogger
164
+ )
152
165
  ).rejects.toThrow('requested amount exceeds delegated shares')
153
166
  })
154
167
 
@@ -162,7 +175,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
162
175
  )
163
176
 
164
177
  await expect(
165
- prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent({ useAllAmount: false }))
178
+ prepareStakingIntent(
179
+ mockConfig,
180
+ 'zero_gravity',
181
+ makeIntent({ useAllAmount: false }),
182
+ testLogger
183
+ )
166
184
  ).rejects.toThrow('shares below 0G contract minimum')
167
185
  })
168
186
 
@@ -172,7 +190,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
172
190
  const result = await prepareStakingIntent(
173
191
  mockConfig,
174
192
  'zero_gravity',
175
- makeIntent({ useAllAmount: true })
193
+ makeIntent({ useAllAmount: true }),
194
+ testLogger
176
195
  )
177
196
 
178
197
  expect(result).toMatchObject({ shares: 1_000_000_000n, txValue: 5n * 10n ** 9n })
@@ -182,7 +201,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
182
201
  const result = await prepareStakingIntent(
183
202
  mockConfig,
184
203
  'zero_gravity',
185
- makeIntent({ shares: 42n })
204
+ makeIntent({ shares: 42n }),
205
+ testLogger
186
206
  )
187
207
 
188
208
  expect(result).toMatchObject({
@@ -197,7 +217,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
197
217
  const result = await prepareStakingIntent(
198
218
  mockConfig,
199
219
  'zero_gravity',
200
- makeIntent({ mode: 'delegate' })
220
+ makeIntent({ mode: 'delegate' }),
221
+ testLogger
201
222
  )
202
223
 
203
224
  expect(result).toMatchObject({
@@ -210,7 +231,7 @@ describe('prepareStakingIntent / zero_gravity', () => {
210
231
  it('is a no-op when node is not external', async () => {
211
232
  mockedIsExternalNodeConfig.mockReturnValue(false)
212
233
 
213
- const result = await prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent())
234
+ const result = await prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent(), testLogger)
214
235
 
215
236
  expect(result).toMatchObject({
216
237
  mode: 'undelegate',
@@ -220,7 +241,7 @@ describe('prepareStakingIntent / zero_gravity', () => {
220
241
  })
221
242
 
222
243
  it('is a no-op for unknown currencies', async () => {
223
- const result = await prepareStakingIntent(mockConfig, 'unknown_chain', makeIntent())
244
+ const result = await prepareStakingIntent(mockConfig, 'unknown_chain', makeIntent(), testLogger)
224
245
 
225
246
  expect(result).toMatchObject({
226
247
  mode: 'undelegate',
@@ -7,6 +7,7 @@ import type {
7
7
  MemoNotSupported,
8
8
  TransactionIntent,
9
9
  } from '@ledgerhq/coin-module-framework/api/index'
10
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
10
11
  import { ethers } from 'ethers'
11
12
  import { isStakingIntent } from '../logic-public'
12
13
  import { withApi } from '../network/node/rpc.common'
@@ -40,10 +41,11 @@ function isWithdrawalFeeInGweiResult(value: unknown): value is WithdrawalFeeInGw
40
41
  type IntentPreparer = (
41
42
  config: EvmConfigInfo,
42
43
  currencyId: string,
43
- intent: StakingIntent
44
+ intent: StakingIntent,
45
+ logger: Logger
44
46
  ) => Promise<StakingIntent>
45
47
 
46
- const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent) => {
48
+ const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent, logger) => {
47
49
  if (!isStakingIntent(intent)) return intent
48
50
  if (intent.mode !== 'undelegate' || intent.withdrawId !== undefined || !intent.valId) {
49
51
  return intent
@@ -53,7 +55,8 @@ const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent) =
53
55
  config,
54
56
  'monad',
55
57
  BigInt(intent.valId),
56
- intent.sender
58
+ intent.sender,
59
+ logger
57
60
  )
58
61
  if (withdrawId === null) {
59
62
  throw new Error(
@@ -153,8 +156,9 @@ const STAKING_INTENT_PREPARERS: Record<string, IntentPreparer> = {
153
156
  export const prepareStakingIntent = async (
154
157
  config: EvmConfigInfo,
155
158
  currencyId: string,
156
- intent: StakingIntent
159
+ intent: StakingIntent,
160
+ logger: Logger
157
161
  ): Promise<StakingIntent> => {
158
162
  const prepare = STAKING_INTENT_PREPARERS[currencyId]
159
- return prepare ? prepare(config, currencyId, intent) : intent
163
+ return prepare ? prepare(config, currencyId, intent, logger) : intent
160
164
  }