@ledgerhq/coin-evm 8.0.0 → 9.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 (278) hide show
  1. package/CHANGELOG.md +19 -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 +37 -29
  62. package/lib/network/node/rpc.common.js.map +1 -1
  63. package/lib/staking/contracts.js +2 -2
  64. package/lib/staking/contracts.js.map +1 -1
  65. package/lib/staking/fetchers.d.ts.map +1 -1
  66. package/lib/staking/fetchers.js +7 -7
  67. package/lib/staking/fetchers.js.map +1 -1
  68. package/lib/staking/prepareIntents.d.ts +2 -1
  69. package/lib/staking/prepareIntents.d.ts.map +1 -1
  70. package/lib/staking/prepareIntents.js +4 -4
  71. package/lib/staking/prepareIntents.js.map +1 -1
  72. package/lib/staking/redelegations.d.ts +5 -4
  73. package/lib/staking/redelegations.d.ts.map +1 -1
  74. package/lib/staking/redelegations.js +13 -14
  75. package/lib/staking/redelegations.js.map +1 -1
  76. package/lib/staking/rewards.d.ts +2 -1
  77. package/lib/staking/rewards.d.ts.map +1 -1
  78. package/lib/staking/rewards.js +4 -5
  79. package/lib/staking/rewards.js.map +1 -1
  80. package/lib/staking/rewardsFromReceipt.d.ts +2 -1
  81. package/lib/staking/rewardsFromReceipt.d.ts.map +1 -1
  82. package/lib/staking/rewardsFromReceipt.js +2 -3
  83. package/lib/staking/rewardsFromReceipt.js.map +1 -1
  84. package/lib/staking/unbondings.d.ts +2 -1
  85. package/lib/staking/unbondings.d.ts.map +1 -1
  86. package/lib/staking/unbondings.js +4 -5
  87. package/lib/staking/unbondings.js.map +1 -1
  88. package/lib/staking/validators/index.d.ts +9 -4
  89. package/lib/staking/validators/index.d.ts.map +1 -1
  90. package/lib/staking/validators/index.js +19 -10
  91. package/lib/staking/validators/index.js.map +1 -1
  92. package/lib/staking/validators/monad.d.ts +6 -5
  93. package/lib/staking/validators/monad.d.ts.map +1 -1
  94. package/lib/staking/validators/monad.js +33 -29
  95. package/lib/staking/validators/monad.js.map +1 -1
  96. package/lib/staking/validators/monadResolver.d.ts +2 -1
  97. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  98. package/lib/staking/validators/monadResolver.js +2 -3
  99. package/lib/staking/validators/monadResolver.js.map +1 -1
  100. package/lib/staking/validators/somnia.d.ts +3 -2
  101. package/lib/staking/validators/somnia.d.ts.map +1 -1
  102. package/lib/staking/validators/somnia.js +16 -15
  103. package/lib/staking/validators/somnia.js.map +1 -1
  104. package/lib/staking/validators/types.d.ts +2 -1
  105. package/lib/staking/validators/types.d.ts.map +1 -1
  106. package/lib/staking/validators/zero_gravity.d.ts +2 -1
  107. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  108. package/lib/staking/validators/zero_gravity.js +7 -8
  109. package/lib/staking/validators/zero_gravity.js.map +1 -1
  110. package/lib/types/staking.d.ts +4 -3
  111. package/lib/types/staking.d.ts.map +1 -1
  112. package/lib-es/adapters/blockOperations.d.ts +4 -3
  113. package/lib-es/adapters/blockOperations.d.ts.map +1 -1
  114. package/lib-es/adapters/blockOperations.js +17 -17
  115. package/lib-es/adapters/blockOperations.js.map +1 -1
  116. package/lib-es/adapters/etherscan.d.ts +7 -6
  117. package/lib-es/adapters/etherscan.d.ts.map +1 -1
  118. package/lib-es/adapters/etherscan.js +19 -19
  119. package/lib-es/adapters/etherscan.js.map +1 -1
  120. package/lib-es/adapters/ledger.d.ts +6 -5
  121. package/lib-es/adapters/ledger.d.ts.map +1 -1
  122. package/lib-es/adapters/ledger.js +15 -15
  123. package/lib-es/adapters/ledger.js.map +1 -1
  124. package/lib-es/api/index.d.ts.map +1 -1
  125. package/lib-es/api/index.js +1 -2
  126. package/lib-es/api/index.js.map +1 -1
  127. package/lib-es/logic/common.js +1 -1
  128. package/lib-es/logic/common.js.map +1 -1
  129. package/lib-es/logic/getBalance.d.ts.map +1 -1
  130. package/lib-es/logic/getBalance.js +3 -3
  131. package/lib-es/logic/getBalance.js.map +1 -1
  132. package/lib-es/logic/getBlock.d.ts.map +1 -1
  133. package/lib-es/logic/getBlock.js +22 -23
  134. package/lib-es/logic/getBlock.js.map +1 -1
  135. package/lib-es/logic/getStakes.d.ts.map +1 -1
  136. package/lib-es/logic/getStakes.js +2 -2
  137. package/lib-es/logic/getStakes.js.map +1 -1
  138. package/lib-es/logic/internalTransactionsFetcher.d.ts +3 -2
  139. package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
  140. package/lib-es/logic/internalTransactionsFetcher.js +13 -10
  141. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  142. package/lib-es/logic/listOperations.js +1 -1
  143. package/lib-es/logic/listOperations.js.map +1 -1
  144. package/lib-es/logic-public/utils.d.ts +3 -2
  145. package/lib-es/logic-public/utils.d.ts.map +1 -1
  146. package/lib-es/logic-public/utils.js +7 -6
  147. package/lib-es/logic-public/utils.js.map +1 -1
  148. package/lib-es/network/explorer/etherscan.d.ts +3 -2
  149. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  150. package/lib-es/network/explorer/etherscan.js +13 -12
  151. package/lib-es/network/explorer/etherscan.js.map +1 -1
  152. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  153. package/lib-es/network/explorer/ledger.js +11 -11
  154. package/lib-es/network/explorer/ledger.js.map +1 -1
  155. package/lib-es/network/explorer/types.d.ts +2 -2
  156. package/lib-es/network/explorer/types.d.ts.map +1 -1
  157. package/lib-es/network/explorer/types.js.map +1 -1
  158. package/lib-es/network/node/explorerProxy.js +3 -3
  159. package/lib-es/network/node/explorerProxy.js.map +1 -1
  160. package/lib-es/network/node/index.d.ts.map +1 -1
  161. package/lib-es/network/node/index.js +2 -2
  162. package/lib-es/network/node/index.js.map +1 -1
  163. package/lib-es/network/node/ledger.d.ts +2 -1
  164. package/lib-es/network/node/ledger.d.ts.map +1 -1
  165. package/lib-es/network/node/ledger.js +9 -10
  166. package/lib-es/network/node/ledger.js.map +1 -1
  167. package/lib-es/network/node/rpc.common.d.ts +3 -2
  168. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  169. package/lib-es/network/node/rpc.common.js +37 -29
  170. package/lib-es/network/node/rpc.common.js.map +1 -1
  171. package/lib-es/staking/contracts.js +2 -2
  172. package/lib-es/staking/contracts.js.map +1 -1
  173. package/lib-es/staking/fetchers.d.ts.map +1 -1
  174. package/lib-es/staking/fetchers.js +7 -7
  175. package/lib-es/staking/fetchers.js.map +1 -1
  176. package/lib-es/staking/prepareIntents.d.ts +2 -1
  177. package/lib-es/staking/prepareIntents.d.ts.map +1 -1
  178. package/lib-es/staking/prepareIntents.js +4 -4
  179. package/lib-es/staking/prepareIntents.js.map +1 -1
  180. package/lib-es/staking/redelegations.d.ts +5 -4
  181. package/lib-es/staking/redelegations.d.ts.map +1 -1
  182. package/lib-es/staking/redelegations.js +13 -14
  183. package/lib-es/staking/redelegations.js.map +1 -1
  184. package/lib-es/staking/rewards.d.ts +2 -1
  185. package/lib-es/staking/rewards.d.ts.map +1 -1
  186. package/lib-es/staking/rewards.js +4 -5
  187. package/lib-es/staking/rewards.js.map +1 -1
  188. package/lib-es/staking/rewardsFromReceipt.d.ts +2 -1
  189. package/lib-es/staking/rewardsFromReceipt.d.ts.map +1 -1
  190. package/lib-es/staking/rewardsFromReceipt.js +2 -3
  191. package/lib-es/staking/rewardsFromReceipt.js.map +1 -1
  192. package/lib-es/staking/unbondings.d.ts +2 -1
  193. package/lib-es/staking/unbondings.d.ts.map +1 -1
  194. package/lib-es/staking/unbondings.js +4 -5
  195. package/lib-es/staking/unbondings.js.map +1 -1
  196. package/lib-es/staking/validators/index.d.ts +9 -4
  197. package/lib-es/staking/validators/index.d.ts.map +1 -1
  198. package/lib-es/staking/validators/index.js +18 -10
  199. package/lib-es/staking/validators/index.js.map +1 -1
  200. package/lib-es/staking/validators/monad.d.ts +6 -5
  201. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  202. package/lib-es/staking/validators/monad.js +33 -29
  203. package/lib-es/staking/validators/monad.js.map +1 -1
  204. package/lib-es/staking/validators/monadResolver.d.ts +2 -1
  205. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  206. package/lib-es/staking/validators/monadResolver.js +2 -3
  207. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  208. package/lib-es/staking/validators/somnia.d.ts +3 -2
  209. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  210. package/lib-es/staking/validators/somnia.js +16 -15
  211. package/lib-es/staking/validators/somnia.js.map +1 -1
  212. package/lib-es/staking/validators/types.d.ts +2 -1
  213. package/lib-es/staking/validators/types.d.ts.map +1 -1
  214. package/lib-es/staking/validators/zero_gravity.d.ts +2 -1
  215. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  216. package/lib-es/staking/validators/zero_gravity.js +7 -8
  217. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  218. package/lib-es/types/staking.d.ts +4 -3
  219. package/lib-es/types/staking.d.ts.map +1 -1
  220. package/package.json +2 -3
  221. package/src/adapters/blockOperations.test.ts +86 -67
  222. package/src/adapters/blockOperations.ts +28 -17
  223. package/src/adapters/etherscan.test.ts +151 -85
  224. package/src/adapters/etherscan.ts +27 -18
  225. package/src/adapters/ledger.test.ts +210 -83
  226. package/src/adapters/ledger.ts +21 -15
  227. package/src/api/index.integ.test.ts +7 -6
  228. package/src/api/index.test.ts +2 -2
  229. package/src/api/index.ts +1 -2
  230. package/src/logic/common.ts +1 -1
  231. package/src/logic/getBalance.ts +4 -3
  232. package/src/logic/getBlock.ts +43 -27
  233. package/src/logic/getStakes.ts +2 -1
  234. package/src/logic/internalTransactionsFetcher.ts +16 -10
  235. package/src/logic/listOperations.ts +2 -2
  236. package/src/logic/tests/getBalance.test.ts +5 -3
  237. package/src/logic/tests/getBlock.test.ts +16 -15
  238. package/src/logic/tests/internalTransactionsFetcher.test.ts +6 -5
  239. package/src/logic/tests/listOperations.test.ts +4 -4
  240. package/src/logic-public/tests/utils.test.ts +6 -5
  241. package/src/logic-public/utils.ts +8 -5
  242. package/src/logic.test.ts +5 -5
  243. package/src/network/explorer/etherscan.test.ts +169 -55
  244. package/src/network/explorer/etherscan.ts +27 -16
  245. package/src/network/explorer/index.test.ts +2 -1
  246. package/src/network/explorer/ledger.test.ts +207 -35
  247. package/src/network/explorer/ledger.ts +12 -8
  248. package/src/network/explorer/types.ts +3 -2
  249. package/src/network/node/explorerProxy.ts +3 -3
  250. package/src/network/node/index.ts +3 -2
  251. package/src/network/node/ledger.test.ts +25 -25
  252. package/src/network/node/ledger.ts +13 -10
  253. package/src/network/node/rpc.common.ts +84 -28
  254. package/src/network/node/rpc.test.ts +45 -31
  255. package/src/staking/contracts.ts +2 -2
  256. package/src/staking/fetchers.ts +20 -8
  257. package/src/staking/prepareIntents.test.ts +33 -12
  258. package/src/staking/prepareIntents.ts +9 -5
  259. package/src/staking/redelegations.test.ts +96 -35
  260. package/src/staking/redelegations.ts +20 -12
  261. package/src/staking/rewards.test.ts +15 -10
  262. package/src/staking/rewards.ts +8 -5
  263. package/src/staking/rewardsFromReceipt.test.ts +5 -4
  264. package/src/staking/rewardsFromReceipt.ts +4 -3
  265. package/src/staking/unbondings.test.ts +15 -12
  266. package/src/staking/unbondings.ts +7 -5
  267. package/src/staking/validators/index.ts +30 -10
  268. package/src/staking/validators/monad.test.ts +57 -43
  269. package/src/staking/validators/monad.ts +55 -32
  270. package/src/staking/validators/monadResolver.ts +4 -3
  271. package/src/staking/validators/somnia.test.ts +14 -13
  272. package/src/staking/validators/somnia.ts +35 -19
  273. package/src/staking/validators/types.ts +2 -0
  274. package/src/staking/validators/zero_gravity.test.ts +48 -26
  275. package/src/staking/validators/zero_gravity.ts +14 -8
  276. package/src/staking/validators.integ.test.ts +2 -2
  277. package/src/staking/validators.test.ts +30 -26
  278. package/src/types/staking.ts +9 -2
@@ -13,10 +13,10 @@ import type {
13
13
  StakeState,
14
14
  Validator,
15
15
  } from '@ledgerhq/coin-module-framework/api/types'
16
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
16
17
  import type { JsonRpcProvider } from 'ethers'
17
18
  import network from '@ledgerhq/live-network'
18
19
  import { makeLRUCache } from '@ledgerhq/live-network/cache'
19
- import { log } from '@ledgerhq/logs'
20
20
  import { ethers } from 'ethers'
21
21
  import { evmUnit } from '../../logic/evmUnit'
22
22
  import { withApi } from '../../network/node/rpc.common'
@@ -55,7 +55,11 @@ type ValidatorInfo = { name: string }
55
55
  * The resolved promise is cached, so a miss is not re-requested; only transient/non-404
56
56
  * errors are rethrown so the cache evicts and a later call retries.
57
57
  */
58
- const fetchValidatorName = async (currencyId: string, secp: string): Promise<string | null> => {
58
+ const fetchValidatorName = async (
59
+ currencyId: string,
60
+ secp: string,
61
+ logger: Logger
62
+ ): Promise<string | null> => {
59
63
  const baseUrl = STAKING_CONTRACTS[currencyId]?.validatorNameSource?.baseUrl
60
64
  if (!baseUrl) return null
61
65
 
@@ -69,7 +73,7 @@ const fetchValidatorName = async (currencyId: string, secp: string): Promise<str
69
73
  // A 404 just means this validator hasn't published info — cache the miss.
70
74
  if (status === 404) return null
71
75
  // Anything else is transient: log and rethrow so the cache doesn't pin a miss.
72
- log('coin-evm/staking', 'fetchValidatorName: validator-info lookup failed', {
76
+ logger('coin-evm/staking', 'fetchValidatorName: validator-info lookup failed', {
73
77
  currencyId,
74
78
  secp,
75
79
  error: error instanceof Error ? error.message : String(error),
@@ -81,7 +85,8 @@ const fetchValidatorName = async (currencyId: string, secp: string): Promise<str
81
85
  // Concurrent calls for the same (currencyId, secp) share one in-flight request.
82
86
  const validatorNameCache = makeLRUCache(
83
87
  fetchValidatorName,
84
- (currencyId: string, secp: string) => `${currencyId}-${secp}`,
88
+ // logger is a side-channel arg, excluded from the cache key.
89
+ (currencyId: string, secp: string, _logger: Logger) => `${currencyId}-${secp}`,
85
90
  { max: 1000, ttl: NAME_CACHE_MAX_AGE_MS }
86
91
  )
87
92
 
@@ -154,7 +159,8 @@ const fetchValidatorDetails = async (
154
159
  provider: JsonRpcProvider,
155
160
  iface: ethers.Interface,
156
161
  contractAddress: string,
157
- valIds: bigint[]
162
+ valIds: bigint[],
163
+ logger: Logger
158
164
  ): Promise<Validator[]> => {
159
165
  const items: Validator[] = []
160
166
 
@@ -168,7 +174,9 @@ const fetchValidatorDetails = async (
168
174
  const [, , stake, , commission, , , , , , secpPubkey] = decoded
169
175
  const secp = secpPubkey.toLowerCase().replace(/^0x/, '')
170
176
  const name =
171
- secp.length > 0 ? await validatorNameCache(currencyId, secp).catch(() => null) : null
177
+ secp.length > 0
178
+ ? await validatorNameCache(currencyId, secp, logger).catch(() => null)
179
+ : null
172
180
 
173
181
  return {
174
182
  id: valId.toString(),
@@ -183,7 +191,7 @@ const fetchValidatorDetails = async (
183
191
 
184
192
  settled.forEach((res, idx) => {
185
193
  if (res.status === 'rejected') {
186
- log('coin-evm/staking', 'fetchValidatorDetails: getValidator call failed', {
194
+ logger('coin-evm/staking', 'fetchValidatorDetails: getValidator call failed', {
187
195
  valId: chunk[idx].toString(),
188
196
  error: res.reason instanceof Error ? res.reason.message : String(res.reason),
189
197
  })
@@ -204,7 +212,8 @@ const fetchPage = async (
204
212
  provider: JsonRpcProvider,
205
213
  iface: ethers.Interface,
206
214
  contractAddress: string,
207
- startIndex: bigint
215
+ startIndex: bigint,
216
+ logger: Logger
208
217
  ): Promise<Page<Validator>> => {
209
218
  const data = iface.encodeFunctionData('getExecutionValidatorSet', [startIndex])
210
219
  const raw = await provider.call({ to: contractAddress, data })
@@ -216,7 +225,7 @@ const fetchPage = async (
216
225
  const items =
217
226
  pageIds.length === 0
218
227
  ? []
219
- : await fetchValidatorDetails(currencyId, provider, iface, contractAddress, pageIds)
228
+ : await fetchValidatorDetails(currencyId, provider, iface, contractAddress, pageIds, logger)
220
229
 
221
230
  const exhausted = isDone || pageIds.length === 0 || nextIndex <= startIndex
222
231
  return { items, next: exhausted ? undefined : nextIndex.toString() }
@@ -225,6 +234,7 @@ const fetchPage = async (
225
234
  const fetchValidators = async (
226
235
  evmConfig: EvmConfigInfo,
227
236
  currencyId: string,
237
+ logger: Logger,
228
238
  cursor?: Cursor
229
239
  ): Promise<Page<Validator>> => {
230
240
  const ctx = resolveContext(evmConfig, currencyId)
@@ -238,12 +248,12 @@ const fetchValidators = async (
238
248
  currencyId,
239
249
  async (provider) => {
240
250
  const iface = new ethers.Interface(ctx.abi)
241
- return fetchPage(currencyId, provider, iface, ctx.contractAddress, startIndex)
251
+ return fetchPage(currencyId, provider, iface, ctx.contractAddress, startIndex, logger)
242
252
  },
243
253
  ctx.node
244
254
  )
245
255
  } catch (error) {
246
- log('coin-evm/staking', 'fetchValidators: Monad validators page fetch failed', {
256
+ logger('coin-evm/staking', 'fetchValidators: Monad validators page fetch failed', {
247
257
  error: error instanceof Error ? error.message : String(error),
248
258
  currencyId,
249
259
  cursor,
@@ -287,7 +297,8 @@ const fetchStakeForValId = async (
287
297
  contractAddress: string,
288
298
  delegator: string,
289
299
  valId: bigint,
290
- currentEpoch: bigint | null
300
+ currentEpoch: bigint | null,
301
+ logger: Logger
291
302
  ): Promise<Stake[]> => {
292
303
  const data = iface.encodeFunctionData('getDelegator', [valId, delegator])
293
304
  const raw = await provider.call({ to: contractAddress, data })
@@ -302,7 +313,8 @@ const fetchStakeForValId = async (
302
313
  iface,
303
314
  contractAddress,
304
315
  valId,
305
- delegator
316
+ delegator,
317
+ logger
306
318
  )
307
319
 
308
320
  if (
@@ -323,7 +335,8 @@ const fetchStakeForValId = async (
323
335
  validatorAddress = ethers.computeAddress(secpPubkey)
324
336
  const secp = secpPubkey.toLowerCase().replace(/^0x/, '')
325
337
  if (secp.length > 0) {
326
- validatorName = (await validatorNameCache(currencyId, secp).catch(() => null)) ?? undefined
338
+ validatorName =
339
+ (await validatorNameCache(currencyId, secp, logger).catch(() => null)) ?? undefined
327
340
  }
328
341
  }
329
342
 
@@ -378,7 +391,8 @@ const fetchStakeForValId = async (
378
391
 
379
392
  export const extractMonadKnownValIds = (
380
393
  currencyId: string,
381
- ops: Array<Operation<MemoNotSupported>>
394
+ ops: Array<Operation<MemoNotSupported>>,
395
+ logger: Logger
382
396
  ): string[] => {
383
397
  const fnNames: Record<string, string> = {
384
398
  DELEGATE: 'delegate',
@@ -401,7 +415,7 @@ export const extractMonadKnownValIds = (
401
415
  const d = iface.decodeFunctionData(fnName, payload)
402
416
  if (typeof d[0] === 'bigint') valIds.add(d[0].toString())
403
417
  } catch (err) {
404
- log('coin-evm/staking', 'extractMonadKnownValIds: failed to decode payload', {
418
+ logger('coin-evm/staking', 'extractMonadKnownValIds: failed to decode payload', {
405
419
  type: op.type,
406
420
  error: err instanceof Error ? err.message : String(err),
407
421
  })
@@ -416,6 +430,7 @@ export const fetchMonadStakes = async (
416
430
  address: string,
417
431
  _config: StakingContractConfig,
418
432
  currencyId: string,
433
+ logger: Logger,
419
434
  knownValIds?: string[]
420
435
  ): Promise<Stake[]> => {
421
436
  const ctx = resolveContext(evmConfig, currencyId)
@@ -440,7 +455,7 @@ export const fetchMonadStakes = async (
440
455
  const valIds = [...valIdSet]
441
456
  if (valIds.length === 0) return []
442
457
 
443
- const currentEpoch = await callGetEpoch(provider, iface, ctx.contractAddress)
458
+ const currentEpoch = await callGetEpoch(provider, iface, ctx.contractAddress, logger)
444
459
 
445
460
  const stakes: Stake[] = []
446
461
  for (let i = 0; i < valIds.length; i += DETAILS_BATCH_SIZE) {
@@ -455,14 +470,15 @@ export const fetchMonadStakes = async (
455
470
  ctx.contractAddress,
456
471
  address,
457
472
  valId,
458
- currentEpoch
473
+ currentEpoch,
474
+ logger
459
475
  )
460
476
  )
461
477
  )
462
478
 
463
479
  settled.forEach((res, idx) => {
464
480
  if (res.status === 'rejected') {
465
- log('coin-evm/staking', 'fetchMonadStakes: getDelegator call failed', {
481
+ logger('coin-evm/staking', 'fetchMonadStakes: getDelegator call failed', {
466
482
  valId: chunk[idx].toString(),
467
483
  error: res.reason instanceof Error ? res.reason.message : String(res.reason),
468
484
  })
@@ -477,7 +493,7 @@ export const fetchMonadStakes = async (
477
493
  ctx.node
478
494
  )
479
495
  } catch (error) {
480
- log('coin-evm/staking', 'fetchMonadStakes: delegations fetch failed', {
496
+ logger('coin-evm/staking', 'fetchMonadStakes: delegations fetch failed', {
481
497
  currencyId,
482
498
  error: error instanceof Error ? error.message : String(error),
483
499
  })
@@ -528,7 +544,8 @@ const fetchWithdrawalRequests = async (
528
544
  iface: ethers.Interface,
529
545
  contractAddress: string,
530
546
  valId: bigint,
531
- delegator: string
547
+ delegator: string,
548
+ logger: Logger
532
549
  ): Promise<OccupiedWithdrawal[]> => {
533
550
  const occupied: OccupiedWithdrawal[] = []
534
551
 
@@ -545,7 +562,7 @@ const fetchWithdrawalRequests = async (
545
562
  settled.forEach((res, i) => {
546
563
  const withdrawId = ids[i]
547
564
  if (res.status === 'rejected') {
548
- log('coin-evm/staking', 'fetchWithdrawalRequests: getWithdrawalRequest call failed', {
565
+ logger('coin-evm/staking', 'fetchWithdrawalRequests: getWithdrawalRequest call failed', {
549
566
  valId: valId.toString(),
550
567
  withdrawId,
551
568
  error: res.reason instanceof Error ? res.reason.message : String(res.reason),
@@ -566,7 +583,8 @@ export const findFirstFreeWithdrawId = async (
566
583
  evmConfig: EvmConfigInfo,
567
584
  currencyId: string,
568
585
  valId: bigint,
569
- delegator: string
586
+ delegator: string,
587
+ logger: Logger
570
588
  ): Promise<number | null> => {
571
589
  const ctx = resolveContext(evmConfig, currencyId)
572
590
  if (!ctx) return null
@@ -598,12 +616,16 @@ export const findFirstFreeWithdrawId = async (
598
616
  for (let i = 0; i < settled.length; i++) {
599
617
  const res = settled[i]
600
618
  if (res.status === 'rejected') {
601
- log('coin-evm/staking', 'findFirstFreeWithdrawId: getWithdrawalRequest call failed', {
602
- currencyId,
603
- valId: valId.toString(),
604
- withdrawId: ids[i],
605
- error: res.reason instanceof Error ? res.reason.message : String(res.reason),
606
- })
619
+ logger(
620
+ 'coin-evm/staking',
621
+ 'findFirstFreeWithdrawId: getWithdrawalRequest call failed',
622
+ {
623
+ currencyId,
624
+ valId: valId.toString(),
625
+ withdrawId: ids[i],
626
+ error: res.reason instanceof Error ? res.reason.message : String(res.reason),
627
+ }
628
+ )
607
629
  continue
608
630
  }
609
631
  if (res.value && !isWithdrawIdInUse(res.value)) return ids[i]
@@ -615,7 +637,7 @@ export const findFirstFreeWithdrawId = async (
615
637
  ctx.node
616
638
  )
617
639
  } catch (error) {
618
- log('coin-evm/staking', 'findFirstFreeWithdrawId: lookup failed', {
640
+ logger('coin-evm/staking', 'findFirstFreeWithdrawId: lookup failed', {
619
641
  currencyId,
620
642
  valId: valId.toString(),
621
643
  error: error instanceof Error ? error.message : String(error),
@@ -641,7 +663,8 @@ const callGetWithdrawalRequest = async (
641
663
  export const callGetEpoch = async (
642
664
  provider: JsonRpcProvider,
643
665
  iface: ethers.Interface,
644
- contractAddress: string
666
+ contractAddress: string,
667
+ logger: Logger
645
668
  ): Promise<bigint | null> => {
646
669
  try {
647
670
  const data = iface.encodeFunctionData('getEpoch', [])
@@ -649,7 +672,7 @@ export const callGetEpoch = async (
649
672
  const decoded = iface.decodeFunctionResult('getEpoch', raw)
650
673
  return Array.isArray(decoded) && typeof decoded[0] === 'bigint' ? decoded[0] : null
651
674
  } catch (error) {
652
- log('coin-evm/staking', 'callGetEpoch: getEpoch call failed', {
675
+ logger('coin-evm/staking', 'callGetEpoch: getEpoch call failed', {
653
676
  error: error instanceof Error ? error.message : String(error),
654
677
  })
655
678
  return null
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { EvmConfigInfo } from '../../config'
5
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
5
6
  import type { JsonRpcProvider } from 'ethers'
6
- import { log } from '@ledgerhq/logs'
7
7
  import { ethers } from 'ethers'
8
8
  import { withApi } from '../../network/node/rpc.common'
9
9
  import { isExternalNodeConfig } from '../../network/node/types'
@@ -54,7 +54,8 @@ export const callGetValidator = async (
54
54
  export const getValidatorAddressById = async (
55
55
  config: EvmConfigInfo,
56
56
  currencyId: string,
57
- valId: bigint
57
+ valId: bigint,
58
+ logger: Logger
58
59
  ): Promise<string | null> => {
59
60
  const abi = getStakingABI(currencyId)
60
61
  if (!abi) return null
@@ -76,7 +77,7 @@ export const getValidatorAddressById = async (
76
77
  node
77
78
  )
78
79
  } catch (error) {
79
- log('coin-evm/staking', 'getValidatorAddressById: getValidator call failed', {
80
+ logger('coin-evm/staking', 'getValidatorAddressById: getValidator call failed', {
80
81
  currencyId,
81
82
  valId: valId.toString(),
82
83
  error: error instanceof Error ? error.message : String(error),
@@ -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 { withApi } from '../../network/node/rpc.common'
16
17
  import { STAKING_CONTRACTS } from '../contracts'
@@ -137,7 +138,7 @@ describe('staking/validators/somnia', () => {
137
138
  })
138
139
  )
139
140
 
140
- const page = await getValidators(mockConfig, 'somnia')
141
+ const page = await getValidators(mockConfig, 'somnia', testLogger)
141
142
 
142
143
  expect(page.next).toBeUndefined()
143
144
  expect(page.items).toHaveLength(2)
@@ -170,7 +171,7 @@ describe('staking/validators/somnia', () => {
170
171
  })
171
172
  )
172
173
 
173
- const page = await getValidators(mockConfig, 'somnia')
174
+ const page = await getValidators(mockConfig, 'somnia', testLogger)
174
175
 
175
176
  expect(page.items).toHaveLength(1)
176
177
  expect(page.items[0].address).toBe(VALIDATOR_B)
@@ -183,14 +184,14 @@ describe('staking/validators/somnia', () => {
183
184
  })
184
185
  )
185
186
 
186
- const page = await getValidators(mockConfig, 'somnia')
187
+ const page = await getValidators(mockConfig, 'somnia', testLogger)
187
188
 
188
189
  expect(page.items).toStrictEqual([])
189
190
  expect(page.next).toBeUndefined()
190
191
  })
191
192
 
192
193
  it('returns empty when the node config is not external', async () => {
193
- const page = await getValidators(ledgerConfig, 'somnia')
194
+ const page = await getValidators(ledgerConfig, 'somnia', testLogger)
194
195
 
195
196
  expect(page.items).toStrictEqual([])
196
197
  expect(mockedWithApi).not.toHaveBeenCalled()
@@ -199,7 +200,7 @@ describe('staking/validators/somnia', () => {
199
200
  it('returns empty on getCommitteeValidators failure', async () => {
200
201
  setupRpc(routeByName({ getCommitteeValidators: () => new Error('network error') }))
201
202
 
202
- const page = await getValidators(mockConfig, 'somnia')
203
+ const page = await getValidators(mockConfig, 'somnia', testLogger)
203
204
 
204
205
  expect(page.items).toStrictEqual([])
205
206
  })
@@ -214,7 +215,7 @@ describe('staking/validators/somnia', () => {
214
215
  [VALIDATOR_B.toLowerCase()]: 'Kiln',
215
216
  })
216
217
 
217
- const names = await fetchValidatorNames('somnia')
218
+ const names = await fetchValidatorNames('somnia', testLogger)
218
219
 
219
220
  expect(names).toStrictEqual({
220
221
  [VALIDATOR_A.toLowerCase()]: 'BitGo',
@@ -229,7 +230,7 @@ describe('staking/validators/somnia', () => {
229
230
  '0x1234': 'Too short',
230
231
  })
231
232
 
232
- const names = await fetchValidatorNames('somnia')
233
+ const names = await fetchValidatorNames('somnia', testLogger)
233
234
 
234
235
  expect(names).toStrictEqual({ [VALIDATOR_A.toLowerCase()]: 'Everstake' })
235
236
  })
@@ -243,7 +244,7 @@ describe('staking/validators/somnia', () => {
243
244
  '0x4444444444444444444444444444444444444444': null,
244
245
  })
245
246
 
246
- const names = await fetchValidatorNames('somnia')
247
+ const names = await fetchValidatorNames('somnia', testLogger)
247
248
 
248
249
  expect(names).toStrictEqual({ [VALIDATOR_A.toLowerCase()]: 'Everstake' })
249
250
  })
@@ -255,7 +256,7 @@ describe('staking/validators/somnia', () => {
255
256
  error: { code: -32600, message: 'invalid request' },
256
257
  })
257
258
 
258
- const names = await fetchValidatorNames('somnia')
259
+ const names = await fetchValidatorNames('somnia', testLogger)
259
260
 
260
261
  expect(names).toStrictEqual({})
261
262
  })
@@ -263,7 +264,7 @@ describe('staking/validators/somnia', () => {
263
264
  it('returns {} when the payload is an array', async () => {
264
265
  mockNamesResponse([{ addr: VALIDATOR_A, name: 'BitGo' }])
265
266
 
266
- const names = await fetchValidatorNames('somnia')
267
+ const names = await fetchValidatorNames('somnia', testLogger)
267
268
 
268
269
  expect(names).toStrictEqual({})
269
270
  })
@@ -271,7 +272,7 @@ describe('staking/validators/somnia', () => {
271
272
  it('returns {} when the payload is null', async () => {
272
273
  mockNamesResponse(null)
273
274
 
274
- const names = await fetchValidatorNames('somnia')
275
+ const names = await fetchValidatorNames('somnia', testLogger)
275
276
 
276
277
  expect(names).toStrictEqual({})
277
278
  })
@@ -279,13 +280,13 @@ describe('staking/validators/somnia', () => {
279
280
  it('rethrows on network error so makeLRUCache evicts (callers stay best-effort)', async () => {
280
281
  mockedNetwork.mockRejectedValue(new Error('network down'))
281
282
 
282
- await expect(fetchValidatorNames('somnia')).rejects.toThrow('network down')
283
+ await expect(fetchValidatorNames('somnia', testLogger)).rejects.toThrow('network down')
283
284
  })
284
285
  })
285
286
 
286
287
  describe('fetchSomniaStakes', () => {
287
288
  const fetchStakes = (config: EvmConfigInfo = mockConfig) =>
288
- fetchSomniaStakes(config, DELEGATOR, STAKING_CONTRACTS['somnia'], 'somnia')
289
+ fetchSomniaStakes(config, DELEGATOR, STAKING_CONTRACTS['somnia'], 'somnia', testLogger)
289
290
 
290
291
  const defaultStakeHandlers = (
291
292
  overrides: {
@@ -4,12 +4,12 @@
4
4
  import type { EvmConfigInfo } from '../../config'
5
5
  import type { StakingContractConfig } from '../../types/staking'
6
6
  import type { ValidatorApi } from './types'
7
- import type { Page } from '@ledgerhq/coin-module-framework/api/index'
7
+ import type { Cursor, Page } from '@ledgerhq/coin-module-framework/api/index'
8
8
  import type { AssetInfo, Stake, Validator } from '@ledgerhq/coin-module-framework/api/types'
9
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
9
10
  import type { JsonRpcProvider } from 'ethers'
10
11
  import network from '@ledgerhq/live-network'
11
12
  import { makeLRUCache } from '@ledgerhq/live-network/cache'
12
- import { log } from '@ledgerhq/logs'
13
13
  import { ethers } from 'ethers'
14
14
  import { evmUnit } from '../../logic/evmUnit'
15
15
  import { withApi } from '../../network/node/rpc.common'
@@ -94,7 +94,10 @@ const resolveContext = (
94
94
  * Returns `{}` when unconfigured/malformed; rethrows on transient network errors so the cache evicts.
95
95
  * Callers should treat it as best-effort and fall back to the on-chain address as the display name.
96
96
  */
97
- export const fetchValidatorNames = async (currencyId: string): Promise<ValidatorNamesMap> => {
97
+ export const fetchValidatorNames = async (
98
+ currencyId: string,
99
+ logger: Logger
100
+ ): Promise<ValidatorNamesMap> => {
98
101
  const baseUrl = STAKING_CONTRACTS[currencyId]?.validatorNameSource?.baseUrl
99
102
  if (!baseUrl) return {}
100
103
 
@@ -112,7 +115,7 @@ export const fetchValidatorNames = async (currencyId: string): Promise<Validator
112
115
  }
113
116
  return out
114
117
  } catch (error) {
115
- log('coin-evm/staking', 'fetchValidatorNames: validator-names lookup failed', {
118
+ logger('coin-evm/staking', 'fetchValidatorNames: validator-names lookup failed', {
116
119
  currencyId,
117
120
  error: error instanceof Error ? error.message : String(error),
118
121
  })
@@ -120,10 +123,15 @@ export const fetchValidatorNames = async (currencyId: string): Promise<Validator
120
123
  }
121
124
  }
122
125
 
123
- const validatorNamesCache = makeLRUCache(fetchValidatorNames, (currencyId: string) => currencyId, {
124
- max: 10,
125
- ttl: NAME_CACHE_MAX_AGE_MS,
126
- })
126
+ const validatorNamesCache = makeLRUCache(
127
+ fetchValidatorNames,
128
+ // logger is a side-channel arg, excluded from the cache key.
129
+ (currencyId: string, _logger: Logger) => currencyId,
130
+ {
131
+ max: 10,
132
+ ttl: NAME_CACHE_MAX_AGE_MS,
133
+ }
134
+ )
127
135
 
128
136
  // Drop the cached validator-names overlay for a currency (primarily to keep tests deterministic,
129
137
  // since the cache is module-level and keyed only by currencyId).
@@ -135,9 +143,10 @@ const fetchValidatorDetails = async (
135
143
  provider: JsonRpcProvider,
136
144
  iface: ethers.Interface,
137
145
  contractAddress: string,
138
- addresses: string[]
146
+ addresses: string[],
147
+ logger: Logger
139
148
  ): Promise<Validator[]> => {
140
- const names = await validatorNamesCache(currencyId).catch(() => ({}) as ValidatorNamesMap)
149
+ const names = await validatorNamesCache(currencyId, logger).catch(() => ({}) as ValidatorNamesMap)
141
150
 
142
151
  const items: Validator[] = []
143
152
 
@@ -170,7 +179,7 @@ const fetchValidatorDetails = async (
170
179
 
171
180
  settled.forEach((res, idx) => {
172
181
  if (res.status === 'rejected') {
173
- log('coin-evm/staking', 'fetchSomniaValidatorDetails: getStake call failed', {
182
+ logger('coin-evm/staking', 'fetchSomniaValidatorDetails: getStake call failed', {
174
183
  address: chunk[idx],
175
184
  error: res.reason instanceof Error ? res.reason.message : String(res.reason),
176
185
  })
@@ -186,7 +195,9 @@ const fetchValidatorDetails = async (
186
195
 
187
196
  const fetchValidators = async (
188
197
  evmConfig: EvmConfigInfo,
189
- currencyId: string
198
+ currencyId: string,
199
+ logger: Logger,
200
+ _cursor?: Cursor
190
201
  ): Promise<Page<Validator>> => {
191
202
  const ctx = resolveContext(evmConfig, currencyId)
192
203
  if (!ctx) return { items: [], next: undefined }
@@ -211,14 +222,15 @@ const fetchValidators = async (
211
222
  provider,
212
223
  iface,
213
224
  ctx.contractAddress,
214
- addresses
225
+ addresses,
226
+ logger
215
227
  )
216
228
  return { items, next: undefined }
217
229
  },
218
230
  ctx.node
219
231
  )
220
232
  } catch (error) {
221
- log('coin-evm/staking', 'fetchSomniaValidators: fetch failed', {
233
+ logger('coin-evm/staking', 'fetchSomniaValidators: fetch failed', {
222
234
  currencyId,
223
235
  error: error instanceof Error ? error.message : String(error),
224
236
  })
@@ -288,7 +300,9 @@ export const fetchSomniaStakes = async (
288
300
  evmConfig: EvmConfigInfo,
289
301
  address: string,
290
302
  _config: StakingContractConfig,
291
- currencyId: string
303
+ currencyId: string,
304
+ logger: Logger,
305
+ _knownValIds?: string[]
292
306
  ): Promise<Stake[]> => {
293
307
  const ctx = resolveContext(evmConfig, currencyId)
294
308
  if (!ctx) return []
@@ -313,7 +327,9 @@ export const fetchSomniaStakes = async (
313
327
 
314
328
  // Display-name overlay, keyed by lowercased operator address. Best-effort: on failure
315
329
  // the delegation still shows, falling back to the raw address as its name.
316
- const names = await validatorNamesCache(currencyId).catch(() => ({}) as ValidatorNamesMap)
330
+ const names = await validatorNamesCache(currencyId, logger).catch(
331
+ () => ({}) as ValidatorNamesMap
332
+ )
317
333
 
318
334
  const asset: AssetInfo = {
319
335
  type: 'native',
@@ -339,7 +355,7 @@ export const fetchSomniaStakes = async (
339
355
  settled.forEach((res, idx) => {
340
356
  const validatorAddress = chunk[idx]
341
357
  if (res.status === 'rejected') {
342
- log('coin-evm/staking', 'fetchSomniaStakes: stake fetch failed', {
358
+ logger('coin-evm/staking', 'fetchSomniaStakes: stake fetch failed', {
343
359
  validator: validatorAddress,
344
360
  error: res.reason instanceof Error ? res.reason.message : String(res.reason),
345
361
  })
@@ -358,7 +374,7 @@ export const fetchSomniaStakes = async (
358
374
  } catch (error) {
359
375
  // A malformed validator address (or other toStake failure) shouldn't drop the
360
376
  // rest of the batch — skip this one and keep the valid stakes.
361
- log('coin-evm/staking', 'fetchSomniaStakes: toStake failed', {
377
+ logger('coin-evm/staking', 'fetchSomniaStakes: toStake failed', {
362
378
  validator: validatorAddress,
363
379
  error: error instanceof Error ? error.message : String(error),
364
380
  })
@@ -370,7 +386,7 @@ export const fetchSomniaStakes = async (
370
386
  ctx.node
371
387
  )
372
388
  } catch (error) {
373
- log('coin-evm/staking', 'fetchSomniaStakes: delegations fetch failed', {
389
+ logger('coin-evm/staking', 'fetchSomniaStakes: delegations fetch failed', {
374
390
  currencyId,
375
391
  error: error instanceof Error ? error.message : String(error),
376
392
  })
@@ -4,11 +4,13 @@
4
4
  import type { EvmConfigInfo } from '../../config'
5
5
  import type { Cursor, Page } from '@ledgerhq/coin-module-framework/api/index'
6
6
  import type { Validator } from '@ledgerhq/coin-module-framework/api/types'
7
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
7
8
 
8
9
  export type ValidatorApi = {
9
10
  fetchValidators: (
10
11
  config: EvmConfigInfo,
11
12
  currencyId: string,
13
+ logger: Logger,
12
14
  cursor?: Cursor
13
15
  ) => Promise<Page<Validator>>
14
16
  }