@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
@@ -4,6 +4,7 @@
4
4
  import type { EvmConfigInfo } from '../config'
5
5
  import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
6
6
  import { ethers } from 'ethers'
7
+ import { testLogger } from '../fixtures/context.fixtures'
7
8
  import { STAKING_CONTRACTS } from './contracts'
8
9
  import { fetchUnbondings } from './unbondings'
9
10
  import { USEI_TO_EVM_SCALE } from './utils'
@@ -79,35 +80,37 @@ describe('staking/unbondings', () => {
79
80
  })
80
81
 
81
82
  it('should return [] for an unknown currencyId', async () => {
82
- expect(await fetchUnbondings(mockConfig, 'unknown_chain', EVM_ADDRESS)).toEqual([])
83
+ expect(await fetchUnbondings(mockConfig, 'unknown_chain', EVM_ADDRESS, testLogger)).toEqual(
84
+ []
85
+ )
83
86
  expect(mockNetwork).not.toHaveBeenCalled()
84
87
  })
85
88
 
86
89
  it('should return [] for a currency without an unbonding strategy', async () => {
87
- expect(await fetchUnbondings(mockConfig, 'celo', EVM_ADDRESS)).toEqual([])
90
+ expect(await fetchUnbondings(mockConfig, 'celo', EVM_ADDRESS, testLogger)).toEqual([])
88
91
  expect(mockNetwork).not.toHaveBeenCalled()
89
92
  })
90
93
 
91
94
  it('should return [] when the address is not associated on-chain yet', async () => {
92
95
  mockGetSeiAddr.mockResolvedValue(null)
93
- expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
96
+ expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
94
97
  expect(mockNetwork).not.toHaveBeenCalled()
95
98
  })
96
99
 
97
100
  it('should return [] when the REST call fails', async () => {
98
101
  mockNetwork.mockRejectedValue(new Error('network error'))
99
- expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
102
+ expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
100
103
  })
101
104
 
102
105
  it('should return [] when the response has no unbonding_responses array', async () => {
103
106
  mockNetwork.mockResolvedValue({ data: {} })
104
- expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
107
+ expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
105
108
  })
106
109
 
107
110
  it('should query the delegator endpoint with the resolved Cosmos address', async () => {
108
111
  mockNetwork.mockResolvedValue({ data: { unbonding_responses: [] } })
109
112
 
110
- await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
113
+ await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
111
114
 
112
115
  expect(mockNetwork).toHaveBeenCalledWith({
113
116
  url: 'https://rest.sei-apis.com/cosmos/staking/v1beta1/delegators/sei1defaultcosmosaddressfortest/unbonding_delegations',
@@ -127,7 +130,7 @@ describe('staking/unbondings', () => {
127
130
  },
128
131
  })
129
132
 
130
- const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
133
+ const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
131
134
 
132
135
  expect(stakes).toHaveLength(1)
133
136
  expect(stakes[0]).toMatchObject({
@@ -150,7 +153,7 @@ describe('staking/unbondings', () => {
150
153
  },
151
154
  })
152
155
 
153
- const [stake] = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
156
+ const [stake] = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
154
157
 
155
158
  // Sei credits the funds back automatically: no withdraw transaction exists.
156
159
  expect(stake.actions).toEqual([])
@@ -169,7 +172,7 @@ describe('staking/unbondings', () => {
169
172
  },
170
173
  })
171
174
 
172
- const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
175
+ const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
173
176
 
174
177
  expect(stakes).toHaveLength(2)
175
178
  expect(new Set(stakes.map((s) => s.uid)).size).toBe(2)
@@ -191,7 +194,7 @@ describe('staking/unbondings', () => {
191
194
  },
192
195
  })
193
196
 
194
- const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
197
+ const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
195
198
 
196
199
  expect(stakes.map((s) => s.delegate)).toEqual([VALIDATOR, OTHER_VALIDATOR])
197
200
  })
@@ -208,7 +211,7 @@ describe('staking/unbondings', () => {
208
211
  },
209
212
  })
210
213
 
211
- const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
214
+ const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
212
215
 
213
216
  expect(stakes).toHaveLength(1)
214
217
  expect(stakes[0].amount).toBe(2000000n * USEI_TO_EVM_SCALE)
@@ -228,7 +231,7 @@ describe('staking/unbondings', () => {
228
231
  },
229
232
  })
230
233
 
231
- const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
234
+ const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
232
235
 
233
236
  expect(stakes).toHaveLength(1)
234
237
  expect(stakes[0].amount).toBe(3000000n * USEI_TO_EVM_SCALE)
@@ -4,8 +4,8 @@
4
4
  import type { EvmConfigInfo } from '../config'
5
5
  import type { StakingContractConfig, UnbondingStrategy } from '../types/staking'
6
6
  import type { Stake } from '@ledgerhq/coin-module-framework/api/types'
7
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
7
8
  import network from '@ledgerhq/live-network'
8
- import { log } from '@ledgerhq/logs'
9
9
  import { evmUnit } from '../logic/evmUnit'
10
10
  import { isExternalNodeConfig } from '../network/node/types'
11
11
  import { STAKING_CONTRACTS } from './contracts'
@@ -35,7 +35,8 @@ async function fetchCosmosRestUnbondings(
35
35
  config: StakingContractConfig,
36
36
  strategy: Extract<UnbondingStrategy, { type: 'cosmos-rest' }>,
37
37
  currencyId: string,
38
- evmAddress: string
38
+ evmAddress: string,
39
+ logger: Logger
39
40
  ): Promise<Stake[]> {
40
41
  const baseUrl = config.apiConfig?.baseUrl
41
42
  const precompileAddress = config.apiConfig?.precompileAddress
@@ -55,7 +56,7 @@ async function fetchCosmosRestUnbondings(
55
56
  const res = await network<UnbondingsApiResponse>({ url, method: 'GET' })
56
57
  data = res.data
57
58
  } catch (e) {
58
- log('coin-evm/staking', 'fetchCosmosRestUnbondings: REST request failed', {
59
+ logger('coin-evm/staking', 'fetchCosmosRestUnbondings: REST request failed', {
59
60
  url,
60
61
  error: e instanceof Error ? e.message : String(e),
61
62
  })
@@ -122,7 +123,8 @@ async function fetchCosmosRestUnbondings(
122
123
  export async function fetchUnbondings(
123
124
  evmConfig: EvmConfigInfo,
124
125
  currencyId: string,
125
- evmAddress: string
126
+ evmAddress: string,
127
+ logger: Logger
126
128
  ): Promise<Stake[]> {
127
129
  const config = STAKING_CONTRACTS[currencyId]
128
130
  const strategy = config?.unbondingStrategy
@@ -130,7 +132,7 @@ export async function fetchUnbondings(
130
132
 
131
133
  switch (strategy.type) {
132
134
  case 'cosmos-rest':
133
- return fetchCosmosRestUnbondings(evmConfig, config, strategy, currencyId, evmAddress)
135
+ return fetchCosmosRestUnbondings(evmConfig, config, strategy, currencyId, evmAddress, logger)
134
136
  default:
135
137
  return []
136
138
  }
@@ -1,9 +1,10 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
4
+ import type { EvmConfigInfo, EvmContext } from '../../config'
5
5
  import type { ValidatorApi } from './types'
6
6
  import type { Cursor, Page, Validator } from '@ledgerhq/coin-module-framework/api/index'
7
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
7
8
  import { makeLRUCache } from '@ledgerhq/live-network/cache'
8
9
  import { STAKING_CONTRACTS } from '../contracts'
9
10
  import monadValidatorApi from './monad'
@@ -35,11 +36,12 @@ export const getValidatorApi = (currencyId: string): ValidatorApi | undefined =>
35
36
  const resolveValidators = async (
36
37
  config: EvmConfigInfo,
37
38
  currencyId: string,
39
+ logger: Logger,
38
40
  cursor?: Cursor
39
41
  ): Promise<Page<Validator>> => {
40
42
  const api = getValidatorApi(currencyId)
41
43
  if (!api) return { items: [], next: undefined }
42
- return api.fetchValidators(config, currencyId, cursor)
44
+ return api.fetchValidators(config, currencyId, logger, cursor)
43
45
  }
44
46
 
45
47
  // One cache key per page, so each page of a paginated chain (e.g. Monad) is
@@ -49,10 +51,12 @@ const resolveValidators = async (
49
51
  const pageKey = (currencyId: string, cursor?: Cursor): string => `${currencyId}-${cursor ?? ''}`
50
52
 
51
53
  const validatorsCache = makeLRUCache(
52
- (config: EvmConfigInfo, currencyId: string, cursor?: Cursor) =>
53
- resolveValidators(config, currencyId, cursor),
54
- // config is deterministic per currency, so it is intentionally excluded from the cache key.
55
- (_config: EvmConfigInfo, currencyId: string, cursor?: Cursor) => pageKey(currencyId, cursor),
54
+ (config: EvmConfigInfo, currencyId: string, logger: Logger, cursor?: Cursor) =>
55
+ resolveValidators(config, currencyId, logger, cursor),
56
+ // config and logger are deterministic/side-channel per currency, so they are intentionally
57
+ // excluded from the cache key.
58
+ (_config: EvmConfigInfo, currencyId: string, _logger: Logger, cursor?: Cursor) =>
59
+ pageKey(currencyId, cursor),
56
60
  { max: 50, ttl: CACHE_MAX_AGE_MS }
57
61
  )
58
62
 
@@ -80,13 +84,14 @@ export const clearValidatorsCache = (currencyId?: string): void => {
80
84
  export const getValidators = async (
81
85
  config: EvmConfigInfo,
82
86
  currencyId: string,
87
+ logger: Logger,
83
88
  cursor?: Cursor
84
89
  ): Promise<Page<Validator>> => {
85
90
  const key = pageKey(currencyId, cursor)
86
91
  issuedKeys.add(key)
87
92
 
88
93
  try {
89
- const page = await validatorsCache(config, currencyId, cursor)
94
+ const page = await validatorsCache(config, currencyId, logger, cursor)
90
95
  // Never keep an empty page cached, so a transient empty response is retried next time.
91
96
  if (page.items.length === 0) {
92
97
  validatorsCache.clear(key)
@@ -106,8 +111,12 @@ export const getValidators = async (
106
111
  * cache entry already returns without a network call, so repeated calls are cheap.
107
112
  * Only the first page is warmed; subsequent pages are fetched lazily by the hook.
108
113
  */
109
- export const prefetchValidators = (config: EvmConfigInfo, currencyId: string): void => {
110
- void getValidators(config, currencyId).catch(() => {
114
+ export const prefetchValidators = (
115
+ config: EvmConfigInfo,
116
+ currencyId: string,
117
+ logger: Logger
118
+ ): void => {
119
+ void getValidators(config, currencyId, logger).catch(() => {
111
120
  /* swallow: the hook surfaces errors via its own flow */
112
121
  })
113
122
  }
@@ -148,4 +157,15 @@ export const hasChainRewards = (currencyId: string): boolean => {
148
157
  return typeof config?.functions.claimReward === 'string'
149
158
  }
150
159
 
151
- export const getValidatorsPage = getValidators
160
+ /**
161
+ * Public entry for a validators page: takes the instance-scoped {@link EvmContext} and
162
+ * resolves the currency config (and logger) from it, delegating to {@link getValidators}.
163
+ */
164
+ export const getValidatorsPage = async (
165
+ context: EvmContext,
166
+ currencyId: string,
167
+ cursor?: Cursor
168
+ ): Promise<Page<Validator>> => {
169
+ const config = await context.config(currencyId)
170
+ return getValidators(config, currencyId, context.logger, cursor)
171
+ }
@@ -11,6 +11,7 @@ import {
11
11
  createMockEvmConfigInfo,
12
12
  mkExternalNode,
13
13
  mkLedgerNode,
14
+ testLogger,
14
15
  } from '../../fixtures/context.fixtures'
15
16
  import { mkJsonRpcProvider } from '../../fixtures/ethers.fixtures'
16
17
  import { withApi } from '../../network/node/rpc.common'
@@ -170,7 +171,7 @@ describe('staking/validators/monad', () => {
170
171
  })
171
172
  )
172
173
 
173
- expect(await getValidators(mockConfig, 'monad')).toStrictEqual({
174
+ expect(await getValidators(mockConfig, 'monad', testLogger)).toStrictEqual({
174
175
  items: [
175
176
  {
176
177
  id: '1',
@@ -199,7 +200,7 @@ describe('staking/validators/monad', () => {
199
200
 
200
201
  // a non-empty page is cached: the second read makes no further RPC calls
201
202
  const callsAfterFirst = callMock.mock.calls.length
202
- await getValidators(mockConfig, 'monad')
203
+ await getValidators(mockConfig, 'monad', testLogger)
203
204
  expect(callMock.mock.calls.length).toBe(callsAfterFirst)
204
205
  })
205
206
 
@@ -221,7 +222,7 @@ describe('staking/validators/monad', () => {
221
222
  status: 200,
222
223
  })
223
224
 
224
- const page = await getValidators(mockConfig, 'monad')
225
+ const page = await getValidators(mockConfig, 'monad', testLogger)
225
226
 
226
227
  expect(page.items[0]).toMatchObject({
227
228
  address: ethers.computeAddress(
@@ -253,7 +254,7 @@ describe('staking/validators/monad', () => {
253
254
  })
254
255
  )
255
256
 
256
- const page = await getValidators(mockConfig, 'monad')
257
+ const page = await getValidators(mockConfig, 'monad', testLogger)
257
258
 
258
259
  expect(page.items).toHaveLength(1)
259
260
  expect(page.items[0]).toMatchObject({
@@ -272,19 +273,19 @@ describe('staking/validators/monad', () => {
272
273
  })
273
274
  )
274
275
 
275
- const page = await getValidators(mockConfig, 'monad')
276
+ const page = await getValidators(mockConfig, 'monad', testLogger)
276
277
 
277
278
  expect(page.items).toStrictEqual([])
278
279
  expect(page.next).toBeUndefined()
279
280
 
280
281
  // empty results are not cached, so the next read hits the precompile again
281
282
  const callsAfterFirst = callMock.mock.calls.length
282
- await getValidators(mockConfig, 'monad')
283
+ await getValidators(mockConfig, 'monad', testLogger)
283
284
  expect(callMock.mock.calls.length).toBeGreaterThan(callsAfterFirst)
284
285
  })
285
286
 
286
287
  it('returns an empty page when the node config is not external', async () => {
287
- const page = await getValidators(ledgerConfig, 'monad')
288
+ const page = await getValidators(ledgerConfig, 'monad', testLogger)
288
289
 
289
290
  expect(page.items).toStrictEqual([])
290
291
  expect(page.next).toBeUndefined()
@@ -300,7 +301,7 @@ describe('staking/validators/monad', () => {
300
301
  })
301
302
  )
302
303
 
303
- const page = await getValidators(mockConfig, 'monad')
304
+ const page = await getValidators(mockConfig, 'monad', testLogger)
304
305
 
305
306
  expect(page.items).toHaveLength(2)
306
307
  expect(page.next).toBe('100')
@@ -317,10 +318,10 @@ describe('staking/validators/monad', () => {
317
318
  })
318
319
  )
319
320
 
320
- const first = await getValidators(mockConfig, 'monad')
321
+ const first = await getValidators(mockConfig, 'monad', testLogger)
321
322
  expect(first.next).toBe('100')
322
323
 
323
- const second = await getValidators(mockConfig, 'monad', first.next)
324
+ const second = await getValidators(mockConfig, 'monad', testLogger, first.next)
324
325
  expect(second.items).toHaveLength(1)
325
326
  expect(second.next).toBeUndefined()
326
327
  })
@@ -337,7 +338,7 @@ describe('staking/validators/monad', () => {
337
338
  })
338
339
  )
339
340
 
340
- const page = await getValidators(mockConfig, 'monad')
341
+ const page = await getValidators(mockConfig, 'monad', testLogger)
341
342
 
342
343
  expect(page.next).toBeUndefined()
343
344
  })
@@ -352,10 +353,10 @@ describe('staking/validators/monad', () => {
352
353
  })
353
354
  )
354
355
 
355
- await getValidators(mockConfig, 'monad')
356
+ await getValidators(mockConfig, 'monad', testLogger)
356
357
  const callCountAfterFirst = callMock.mock.calls.length
357
358
 
358
- const second = await getValidators(mockConfig, 'monad')
359
+ const second = await getValidators(mockConfig, 'monad', testLogger)
359
360
  expect(second.items).toHaveLength(1)
360
361
  expect(callMock.mock.calls.length).toBe(callCountAfterFirst)
361
362
  })
@@ -371,8 +372,8 @@ describe('staking/validators/monad', () => {
371
372
  })
372
373
  )
373
374
 
374
- const firstPage = await getValidators(mockConfig, 'monad')
375
- const secondPage = await getValidators(mockConfig, 'monad', '100')
375
+ const firstPage = await getValidators(mockConfig, 'monad', testLogger)
376
+ const secondPage = await getValidators(mockConfig, 'monad', testLogger, '100')
376
377
  const callsAfterBoth = callMock.mock.calls.length
377
378
 
378
379
  expect(firstPage).toStrictEqual({
@@ -393,8 +394,8 @@ describe('staking/validators/monad', () => {
393
394
  expect(secondPage.next).toBeUndefined()
394
395
 
395
396
  // both cursors are now cached independently — no further RPC calls
396
- expect(await getValidators(mockConfig, 'monad')).toStrictEqual(firstPage)
397
- expect(await getValidators(mockConfig, 'monad', '100')).toStrictEqual(secondPage)
397
+ expect(await getValidators(mockConfig, 'monad', testLogger)).toStrictEqual(firstPage)
398
+ expect(await getValidators(mockConfig, 'monad', testLogger, '100')).toStrictEqual(secondPage)
398
399
  expect(callMock.mock.calls.length).toBe(callsAfterBoth)
399
400
  })
400
401
 
@@ -409,15 +410,15 @@ describe('staking/validators/monad', () => {
409
410
  })
410
411
  )
411
412
 
412
- await getValidators(mockConfig, 'monad')
413
- await getValidators(mockConfig, 'monad', '100')
413
+ await getValidators(mockConfig, 'monad', testLogger)
414
+ await getValidators(mockConfig, 'monad', testLogger, '100')
414
415
  const callsBeforeClear = callMock.mock.calls.length
415
416
 
416
417
  clearValidatorsCache('monad')
417
418
 
418
419
  // every cursor was evicted, so both reads hit the precompile again
419
- await getValidators(mockConfig, 'monad')
420
- await getValidators(mockConfig, 'monad', '100')
420
+ await getValidators(mockConfig, 'monad', testLogger)
421
+ await getValidators(mockConfig, 'monad', testLogger, '100')
421
422
  expect(callMock.mock.calls.length).toBeGreaterThan(callsBeforeClear)
422
423
  })
423
424
  })
@@ -435,7 +436,7 @@ describe('staking/validators/monad', () => {
435
436
  })
436
437
  )
437
438
 
438
- expect(await getValidatorAddressById(mockConfig, 'monad', 7n)).toEqual(
439
+ expect(await getValidatorAddressById(mockConfig, 'monad', 7n, testLogger)).toEqual(
439
440
  ethers.computeAddress(
440
441
  '0x036e44a092493800e427b2b08d3427d804348b1368ecd0a6af6510ae40ce507187'
441
442
  )
@@ -443,13 +444,13 @@ describe('staking/validators/monad', () => {
443
444
  })
444
445
 
445
446
  it('returns null when the node config is not external', async () => {
446
- expect(await getValidatorAddressById(ledgerConfig, 'monad', 7n)).toBeNull()
447
+ expect(await getValidatorAddressById(ledgerConfig, 'monad', 7n, testLogger)).toBeNull()
447
448
  })
448
449
 
449
450
  it('returns null when the getValidator call fails', async () => {
450
451
  setupRpc(routeByName({ getValidator: () => new Error('boom') }))
451
452
 
452
- expect(await getValidatorAddressById(mockConfig, 'monad', 7n)).toBeNull()
453
+ expect(await getValidatorAddressById(mockConfig, 'monad', 7n, testLogger)).toBeNull()
453
454
  })
454
455
  })
455
456
 
@@ -465,7 +466,7 @@ describe('staking/validators/monad', () => {
465
466
  }
466
467
 
467
468
  const fetchStakes = (config: EvmConfigInfo = mockConfig) =>
468
- fetchMonadStakes(config, DELEGATOR, dummyStakingConfig, 'monad')
469
+ fetchMonadStakes(config, DELEGATOR, dummyStakingConfig, 'monad', testLogger)
469
470
 
470
471
  const encodeDelegator = (
471
472
  stake: bigint,
@@ -855,9 +856,14 @@ describe('staking/validators/monad', () => {
855
856
  })
856
857
  )
857
858
 
858
- const stakes = await fetchMonadStakes(mockConfig, DELEGATOR, dummyStakingConfig, 'monad', [
859
- '92',
860
- ])
859
+ const stakes = await fetchMonadStakes(
860
+ mockConfig,
861
+ DELEGATOR,
862
+ dummyStakingConfig,
863
+ 'monad',
864
+ testLogger,
865
+ ['92']
866
+ )
861
867
 
862
868
  const withdrawal = stakes.find((s) => s.details?.validatorId === '92')
863
869
  expect(withdrawal).toMatchObject({
@@ -880,9 +886,14 @@ describe('staking/validators/monad', () => {
880
886
  })
881
887
  )
882
888
 
883
- const stakes = await fetchMonadStakes(mockConfig, DELEGATOR, dummyStakingConfig, 'monad', [
884
- '7',
885
- ])
889
+ const stakes = await fetchMonadStakes(
890
+ mockConfig,
891
+ DELEGATOR,
892
+ dummyStakingConfig,
893
+ 'monad',
894
+ testLogger,
895
+ ['7']
896
+ )
886
897
 
887
898
  expect(stakes).toHaveLength(1)
888
899
  expect(delegatorCallCount).toBe(1)
@@ -912,47 +923,50 @@ describe('staking/validators/monad', () => {
912
923
 
913
924
  it('extracts a validator id from a DELEGATE op', () => {
914
925
  const payload = monadIface.encodeFunctionData('delegate', [42n])
915
- expect(extractMonadKnownValIds('monad', [makeOp('DELEGATE', payload)])).toStrictEqual(['42'])
926
+ expect(
927
+ extractMonadKnownValIds('monad', [makeOp('DELEGATE', payload)], testLogger)
928
+ ).toStrictEqual(['42'])
916
929
  })
917
930
 
918
931
  it('extracts a validator id from an UNDELEGATE op', () => {
919
932
  const payload = monadIface.encodeFunctionData('undelegate', [92n, 10_000_000_000n, 0n])
920
- expect(extractMonadKnownValIds('monad', [makeOp('UNDELEGATE', payload)])).toStrictEqual([
921
- '92',
922
- ])
933
+ expect(
934
+ extractMonadKnownValIds('monad', [makeOp('UNDELEGATE', payload)], testLogger)
935
+ ).toStrictEqual(['92'])
923
936
  })
924
937
 
925
938
  it('extracts a validator id from a WITHDRAW_UNBONDED op', () => {
926
939
  const payload = monadIface.encodeFunctionData('withdraw', [7n, 3n])
927
940
  expect(
928
- extractMonadKnownValIds('monad', [makeOp('WITHDRAW_UNBONDED', payload)])
941
+ extractMonadKnownValIds('monad', [makeOp('WITHDRAW_UNBONDED', payload)], testLogger)
929
942
  ).toStrictEqual(['7'])
930
943
  })
931
944
 
932
945
  it('deduplicates repeated validator ids across multiple ops', () => {
933
946
  const p1 = monadIface.encodeFunctionData('undelegate', [92n, 5_000_000_000n, 0n])
934
947
  const p2 = monadIface.encodeFunctionData('undelegate', [92n, 5_000_000_000n, 1n])
935
- const result = extractMonadKnownValIds('monad', [
936
- makeOp('UNDELEGATE', p1),
937
- makeOp('UNDELEGATE', p2),
938
- ])
948
+ const result = extractMonadKnownValIds(
949
+ 'monad',
950
+ [makeOp('UNDELEGATE', p1), makeOp('UNDELEGATE', p2)],
951
+ testLogger
952
+ )
939
953
  expect(result).toStrictEqual(['92'])
940
954
  })
941
955
 
942
956
  it('ignores ops whose type is not a staking function', () => {
943
- const result = extractMonadKnownValIds('monad', [makeOp('OUT'), makeOp('IN')])
957
+ const result = extractMonadKnownValIds('monad', [makeOp('OUT'), makeOp('IN')], testLogger)
944
958
  expect(result).toStrictEqual([])
945
959
  })
946
960
 
947
961
  it('skips ops with no contractPayload without throwing', () => {
948
- const result = extractMonadKnownValIds('monad', [makeOp('UNDELEGATE')])
962
+ const result = extractMonadKnownValIds('monad', [makeOp('UNDELEGATE')], testLogger)
949
963
  expect(result).toStrictEqual([])
950
964
  })
951
965
 
952
966
  it('returns an empty array for an unknown currencyId (no ABI available)', () => {
953
967
  const payload = monadIface.encodeFunctionData('undelegate', [7n, 1n, 0n])
954
968
  expect(
955
- extractMonadKnownValIds('unknown_coin', [makeOp('UNDELEGATE', payload)])
969
+ extractMonadKnownValIds('unknown_coin', [makeOp('UNDELEGATE', payload)], testLogger)
956
970
  ).toStrictEqual([])
957
971
  })
958
972
  })