@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
@@ -41,12 +41,13 @@ export const getNodeApi = (config: EvmConfigInfo, currencyId: string, logger: Lo
41
41
  const clientVersion = config.ledgerClientVersion ?? ''
42
42
  const nodeSources = JSON.stringify(config.nodeSources ?? ['node'])
43
43
  const key = cacheKey(currencyId, node, explorerUri, clientVersion, nodeSources)
44
+
44
45
  let api = nodeApiCache.get(key)
45
46
  if (api === undefined) {
46
47
  const raw =
47
48
  type === 'ledger'
48
- ? createLedgerNodeApi({ ...node, explorerUri, clientVersion })
49
- : createNodeApi(config, node)
49
+ ? createLedgerNodeApi({ ...node, explorerUri, clientVersion }, logger)
50
+ : createNodeApi(config, node, logger)
50
51
  api = withNodeSources(raw, config, logger)
51
52
  nodeApiCache.set(key, api)
52
53
  }
@@ -7,7 +7,7 @@ import BigNumber from 'bignumber.js'
7
7
  import { Transaction } from 'ethers'
8
8
  import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
9
9
  import { GasEstimationError } from '../../errors'
10
- import { createMockEvmConfigInfo } from '../../fixtures/context.fixtures'
10
+ import { createMockEvmConfigInfo, testLogger } from '../../fixtures/context.fixtures'
11
11
  import { getGasOptions } from '../gasTracker/ledger'
12
12
  import { createLedgerNodeApi } from './ledger'
13
13
 
@@ -50,7 +50,7 @@ describe('EVM Family', () => {
50
50
  })
51
51
 
52
52
  it('reads a contract through the explorer contract/read endpoint', async () => {
53
- const api = createLedgerNodeApi(ledgerConfig)
53
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
54
54
  const spy = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
55
55
  data: [
56
56
  {
@@ -73,7 +73,7 @@ describe('EVM Family', () => {
73
73
  })
74
74
 
75
75
  it('forwards the requested block', async () => {
76
- const api = createLedgerNodeApi(ledgerConfig)
76
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
77
77
  const spy = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
78
78
  data: [
79
79
  {
@@ -93,7 +93,7 @@ describe('EVM Family', () => {
93
93
  })
94
94
 
95
95
  it('throws when the node reports a failure (e.g. revert)', async () => {
96
- const api = createLedgerNodeApi(ledgerConfig)
96
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
97
97
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
98
98
  data: [
99
99
  {
@@ -111,7 +111,7 @@ describe('EVM Family', () => {
111
111
 
112
112
  describe('createLedgerNodeApi / retries', () => {
113
113
  it('should retry on fail', async () => {
114
- const api = createLedgerNodeApi(ledgerConfig)
114
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
115
115
  let attempts = 2
116
116
  const spy = jest.spyOn(axios, 'request').mockImplementation(async () => {
117
117
  if (attempts) {
@@ -139,7 +139,7 @@ describe('EVM Family', () => {
139
139
  })
140
140
 
141
141
  it('should throw after too many retries', async () => {
142
- const api = createLedgerNodeApi({ ...ledgerConfig, retries: 2 })
142
+ const api = createLedgerNodeApi({ ...ledgerConfig, retries: 2 }, testLogger)
143
143
  const SpyError = class SpyError extends Error {}
144
144
  let attempts = 3
145
145
  jest.spyOn(axios, 'request').mockImplementation(async () => {
@@ -155,7 +155,7 @@ describe('EVM Family', () => {
155
155
 
156
156
  describe('getTransaction', () => {
157
157
  it('should return the expected payload', async () => {
158
- const api = createLedgerNodeApi(ledgerConfig)
158
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
159
159
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
160
160
  data: {
161
161
  hash: '0x8d5ef4d7673fbfa6a4755cdfdb913742c47c7fdac2d214046387bbcbf10957c9',
@@ -239,7 +239,7 @@ describe('EVM Family', () => {
239
239
 
240
240
  describe('getCoinBalance', () => {
241
241
  it('should return the expected payload', async () => {
242
- const api = createLedgerNodeApi(ledgerConfig)
242
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
243
243
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
244
244
  data: { balance: '6969' },
245
245
  }))
@@ -250,7 +250,7 @@ describe('EVM Family', () => {
250
250
 
251
251
  describe('getTokenBalance', () => {
252
252
  it('should return the expected payload', async () => {
253
- const api = createLedgerNodeApi(ledgerConfig)
253
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
254
254
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
255
255
  data: [
256
256
  { address: '0xkvn', contract: '0xusdc', balance: '6969' },
@@ -266,7 +266,7 @@ describe('EVM Family', () => {
266
266
 
267
267
  describe('getTransactionCount', () => {
268
268
  it('should return the expected payload', async () => {
269
- const api = createLedgerNodeApi(ledgerConfig)
269
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
270
270
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
271
271
  data: { address: '0xkvn', nonce: 123 },
272
272
  }))
@@ -277,7 +277,7 @@ describe('EVM Family', () => {
277
277
 
278
278
  describe('getGasEstimation', () => {
279
279
  it('should throw GasEstimationError on failure', async () => {
280
- const api = createLedgerNodeApi(ledgerConfig)
280
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
281
281
  jest.spyOn(axios, 'request').mockImplementation(async () => {
282
282
  throw new Error()
283
283
  })
@@ -288,7 +288,7 @@ describe('EVM Family', () => {
288
288
  })
289
289
 
290
290
  it('should throw GasEstimationError if request throws ECONNABORTED', async () => {
291
- const api = createLedgerNodeApi(ledgerConfig)
291
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
292
292
  jest
293
293
  .spyOn(axios, 'request')
294
294
  .mockImplementation(() => Promise.reject({ code: 'ECONNABORTED' }))
@@ -299,7 +299,7 @@ describe('EVM Family', () => {
299
299
  })
300
300
 
301
301
  it('should return the expected payload', async () => {
302
- const api = createLedgerNodeApi(ledgerConfig)
302
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
303
303
  jest
304
304
  .spyOn(axios, 'request')
305
305
  .mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '789' } })
@@ -332,7 +332,7 @@ describe('EVM Family', () => {
332
332
 
333
333
  describe('getFeeData', () => {
334
334
  it("should return the fee data based on the transaction's feesStrategy", async () => {
335
- const api = createLedgerNodeApi(ledgerConfig)
335
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
336
336
  mockGetGasOptions.mockImplementation(async () => ({
337
337
  slow: {
338
338
  maxFeePerGas: new BigNumber(1),
@@ -400,7 +400,7 @@ describe('EVM Family', () => {
400
400
  })
401
401
 
402
402
  it('should return medium fee data if feesStrategy is not provided', async () => {
403
- const api = createLedgerNodeApi(ledgerConfig)
403
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
404
404
  mockGetGasOptions.mockImplementation(async () => ({
405
405
  slow: {
406
406
  maxFeePerGas: new BigNumber(1),
@@ -439,7 +439,7 @@ describe('EVM Family', () => {
439
439
 
440
440
  describe('broadcastTransaction', () => {
441
441
  it('should return the expected payload', async () => {
442
- const api = createLedgerNodeApi(ledgerConfig)
442
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
443
443
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
444
444
  data: {
445
445
  result: '0xHash',
@@ -450,7 +450,7 @@ describe('EVM Family', () => {
450
450
  })
451
451
 
452
452
  it('should include mevProtected=true in the request parameters when specified', async () => {
453
- const api = createLedgerNodeApi(ledgerConfig)
453
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
454
454
  const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
455
455
  data: {
456
456
  result: '0xHash',
@@ -471,7 +471,7 @@ describe('EVM Family', () => {
471
471
  })
472
472
 
473
473
  it('should include source headers when source is provided', async () => {
474
- const api = createLedgerNodeApi(ledgerConfig)
474
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
475
475
  const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
476
476
  data: {
477
477
  result: '0xHash',
@@ -496,7 +496,7 @@ describe('EVM Family', () => {
496
496
  })
497
497
 
498
498
  it('should not include source headers when source is not provided', async () => {
499
- const api = createLedgerNodeApi(ledgerConfig)
499
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
500
500
  const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
501
501
  data: {
502
502
  result: '0xHash',
@@ -518,7 +518,7 @@ describe('EVM Family', () => {
518
518
 
519
519
  describe('getBlockByHeight', () => {
520
520
  it('should return the expected payload', async () => {
521
- const api = createLedgerNodeApi(ledgerConfig)
521
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
522
522
  jest.spyOn(axios, 'request').mockImplementation(async ({ url }) => {
523
523
  if (url?.endsWith('current')) {
524
524
  return {
@@ -563,12 +563,12 @@ describe('EVM Family', () => {
563
563
 
564
564
  describe('getOptimismAdditionalFees', () => {
565
565
  it('should return 0 for an incompatible currency', async () => {
566
- const api = createLedgerNodeApi(ledgerConfig)
566
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
567
567
  expect(await api.getOptimismAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
568
568
  })
569
569
 
570
570
  it('should return the expected payload', async () => {
571
- const api = createLedgerNodeApi(ledgerConfig)
571
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
572
572
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
573
573
  data: [
574
574
  {
@@ -605,7 +605,7 @@ describe('EVM Family', () => {
605
605
  it.each(['blast', 'blast_sepolia', 'base', 'base_sepolia'])(
606
606
  'should query the OP-stack gas oracle for %s (not return 0)',
607
607
  async (currencyId) => {
608
- const api = createLedgerNodeApi(ledgerConfig)
608
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
609
609
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
610
610
  data: [
611
611
  {
@@ -643,12 +643,12 @@ describe('EVM Family', () => {
643
643
 
644
644
  describe('getScrollAdditionalFees', () => {
645
645
  it('should return 0 for an incompatible currency', async () => {
646
- const api = createLedgerNodeApi(ledgerConfig)
646
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
647
647
  expect(await api.getScrollAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
648
648
  })
649
649
 
650
650
  it('should return the expected payload', async () => {
651
- const api = createLedgerNodeApi(ledgerConfig)
651
+ const api = createLedgerNodeApi(ledgerConfig, testLogger)
652
652
  jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
653
653
  data: [
654
654
  {
@@ -4,10 +4,10 @@
4
4
  import type { BlockFinalizationTag, LedgerNodeConfig } from '../../config'
5
5
  import type { LedgerExplorerOperation } from '../../types'
6
6
  import type { BlockByHeightResult, EvmCallParams, NodeApi, TransactionInfo } from './types'
7
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
7
8
  import type { Batcher } from '@ledgerhq/live-network/batcher/types'
8
9
  import type { AxiosRequestConfig } from 'axios'
9
10
  import { makeBatcher } from '@ledgerhq/live-network/batcher/index'
10
- import { log } from '@ledgerhq/logs'
11
11
  import axios from 'axios'
12
12
  import BigNumber from 'bignumber.js'
13
13
  import { ethers } from 'ethers'
@@ -62,7 +62,8 @@ async function getTransaction(
62
62
  fetch: LedgerFetch,
63
63
  config: LedgerNodeApiConfig,
64
64
  _currencyId: string,
65
- hash: string
65
+ hash: string,
66
+ logger: Logger
66
67
  ): Promise<TransactionInfo> {
67
68
  const ledgerTransaction = await fetch<LedgerExplorerOperation>({
68
69
  method: 'GET',
@@ -83,10 +84,10 @@ async function getTransaction(
83
84
  erc20Transfers: ledgerTransaction.transfer_events.map((event) => ({
84
85
  asset: {
85
86
  type: 'erc20' as const,
86
- assetReference: safeEncodeEIP55(event.contract),
87
+ assetReference: safeEncodeEIP55(event.contract, logger),
87
88
  },
88
- from: safeEncodeEIP55(event.from),
89
- to: safeEncodeEIP55(event.to),
89
+ from: safeEncodeEIP55(event.from, logger),
90
+ to: safeEncodeEIP55(event.to, logger),
90
91
  value: event.count,
91
92
  })),
92
93
  }
@@ -167,7 +168,8 @@ async function getTransactionCount(
167
168
 
168
169
  function makeGetGasEstimation(
169
170
  config: LedgerNodeApiConfig,
170
- fetch: LedgerFetch
171
+ fetch: LedgerFetch,
172
+ logger: Logger
171
173
  ): NodeApi['getGasEstimation'] {
172
174
  return async (_currencyId, address, transaction) => {
173
175
  const { recipient: to, amount: value, data } = transaction
@@ -188,7 +190,7 @@ function makeGetGasEstimation(
188
190
  })
189
191
  return new BigNumber(gasEstimation)
190
192
  } catch (e) {
191
- log('error', 'EVM Family: Gas Estimation Error', e)
193
+ logger('error', 'EVM Family: Gas Estimation Error', e)
192
194
  throw new GasEstimationError()
193
195
  }
194
196
  }
@@ -419,7 +421,7 @@ async function getScrollAdditionalFees(
419
421
  return new BigNumber(result.response)
420
422
  }
421
423
 
422
- export function createLedgerNodeApi(config: LedgerNodeApiConfig): NodeApi {
424
+ export function createLedgerNodeApi(config: LedgerNodeApiConfig, logger: Logger): NodeApi {
423
425
  const fetch = makeFetchWithRetries(config)
424
426
  const tokenBalancesBatchersMap = new Map<
425
427
  string,
@@ -432,8 +434,9 @@ export function createLedgerNodeApi(config: LedgerNodeApiConfig): NodeApi {
432
434
  getTokenBalance: makeGetTokenBalance(config, fetch, tokenBalancesBatchersMap),
433
435
  getTokenAllowance: makeGetTokenAllowance(config, fetch),
434
436
  getTransactionCount: make(getTransactionCount, config, fetch),
435
- getTransaction: make(getTransaction, config, fetch),
436
- getGasEstimation: makeGetGasEstimation(config, fetch),
437
+ getTransaction: ((currencyId, hash) =>
438
+ getTransaction(fetch, config, currencyId, hash, logger)) as NodeApi['getTransaction'],
439
+ getGasEstimation: makeGetGasEstimation(config, fetch, logger),
437
440
  // getFeeData takes `config` (EvmConfigInfo) first, not `currency`, so it doesn't fit the
438
441
  // currency-first `make` type bound; bind it directly (same fetch/config passthrough as `make`).
439
442
  getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) =>
@@ -15,9 +15,9 @@ import type {
15
15
  BlockReceiptInfo,
16
16
  EvmCallParams,
17
17
  } from './types'
18
+ import type { Logger } from '@ledgerhq/coin-module-framework/config'
18
19
  /** ⚠️ keep this order of import. @see https://docs.ethers.io/v5/cookbook/react-native/#cookbook-reactnative ⚠️ */
19
20
  import { makeLRUCache } from '@ledgerhq/live-network/cache'
20
- import { log } from '@ledgerhq/logs'
21
21
  import BigNumber from 'bignumber.js'
22
22
  import { ethers, FetchRequest, JsonRpcProvider } from 'ethers'
23
23
  import ERC20Abi from '../../abis/erc20.abi.json'
@@ -29,6 +29,7 @@ import { withRetries } from '../withRetries'
29
29
  import { gethCallTracerToTraceBlockItems } from './gethCallTracerToTraceBlockItems'
30
30
  import {
31
31
  hasErrorCode,
32
+ isRpcMethodNotAvailableOnChainError,
32
33
  isRpcMethodNotImplementedError,
33
34
  isUnsupportedRpcMethodErrorMsg,
34
35
  isUnsupportedRpcMethodError,
@@ -58,15 +59,16 @@ export const ERC20_MINT_TOPIC = '0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea
58
59
  /** Emitter of the native transfer logs added by https://eips.ethereum.org/EIPS/eip-7708. */
59
60
  export const SYSTEM_ADDRESS = '0xfffffffffffffffffffffffffffffffffffffffe'
60
61
 
61
- const ZERO_ADDRESS_HEX = safeEncodeEIP55('0x0000000000000000000000000000000000000000')
62
+ /** All-zeros address; already EIP-55 checksummed since it contains no hex letters. */
63
+ const ZERO_ADDRESS_HEX = '0x0000000000000000000000000000000000000000'
62
64
 
63
65
  function isSystemLog(log: LogWithAddress): boolean {
64
66
  return normalizeAddress(log.address) === SYSTEM_ADDRESS
65
67
  }
66
68
 
67
- function topicToAddress(topic: string | undefined): string {
69
+ function topicToAddress(topic: string | undefined, logger: Logger): string {
68
70
  if (!topic || topic.length < 66) return ZERO_ADDRESS_HEX
69
- return safeEncodeEIP55('0x' + topic.slice(26))
71
+ return safeEncodeEIP55('0x' + topic.slice(26), logger)
70
72
  }
71
73
 
72
74
  function isTransfer(log: LogWithAddress): boolean {
@@ -85,11 +87,16 @@ function isMint(log: LogWithAddress): boolean {
85
87
  return log.topics[0] === ERC20_MINT_TOPIC && log.topics.length === 2 && log.data.length > 2
86
88
  }
87
89
 
88
- function makeErc20Transfer(log: LogWithAddress, from: string, to: string): ERC20Transfer {
90
+ function makeErc20Transfer(
91
+ log: LogWithAddress,
92
+ from: string,
93
+ to: string,
94
+ logger: Logger
95
+ ): ERC20Transfer {
89
96
  return {
90
97
  asset: {
91
98
  type: 'erc20',
92
- assetReference: safeEncodeEIP55(log.address),
99
+ assetReference: safeEncodeEIP55(log.address, logger),
93
100
  },
94
101
  from,
95
102
  to,
@@ -131,23 +138,39 @@ function makeErc20Transfer(log: LogWithAddress, from: string, to: string): ERC20
131
138
  * @param logs - Array of logs from transaction receipt
132
139
  * @returns Array of parsed ERC20 transfers
133
140
  */
134
- export function parseERC20TransfersFromLogs(logs: ReadonlyArray<LogWithAddress>): ERC20Transfer[] {
141
+ export function parseERC20TransfersFromLogs(
142
+ logs: ReadonlyArray<LogWithAddress>,
143
+ logger: Logger
144
+ ): ERC20Transfer[] {
135
145
  return logs.flatMap((log) => {
136
146
  // These mimic an ERC20 `Transfer` on a token that does not exist.
137
147
  if (isSystemLog(log)) {
138
148
  return []
139
149
  }
140
150
  if (isTransfer(log)) {
141
- return [makeErc20Transfer(log, topicToAddress(log.topics[1]), topicToAddress(log.topics[2]))]
151
+ return [
152
+ makeErc20Transfer(
153
+ log,
154
+ topicToAddress(log.topics[1], logger),
155
+ topicToAddress(log.topics[2], logger),
156
+ logger
157
+ ),
158
+ ]
142
159
  }
143
160
  if (isWethDeposit(log)) {
144
- return [makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1]))]
161
+ return [
162
+ makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1], logger), logger),
163
+ ]
145
164
  }
146
165
  if (isWethWithdrawal(log)) {
147
- return [makeErc20Transfer(log, topicToAddress(log.topics[1]), ZERO_ADDRESS_HEX)]
166
+ return [
167
+ makeErc20Transfer(log, topicToAddress(log.topics[1], logger), ZERO_ADDRESS_HEX, logger),
168
+ ]
148
169
  }
149
170
  if (isMint(log)) {
150
- return [makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1]))]
171
+ return [
172
+ makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1], logger), logger),
173
+ ]
151
174
  }
152
175
  return []
153
176
  })
@@ -239,7 +262,8 @@ function parseReceiptL1Fee(raw: Record<string, unknown>): string | undefined {
239
262
  async function getTransaction(
240
263
  api: JsonRpcProvider,
241
264
  _currencyId: string,
242
- txHash: string
265
+ txHash: string,
266
+ logger: Logger
243
267
  ): Promise<TransactionInfo> {
244
268
  // Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
245
269
  // extra fields that contain L1 fees.
@@ -278,7 +302,7 @@ async function getTransaction(
278
302
  ? { input: tx.data }
279
303
  : {}),
280
304
  ...(contractAddress ? { contractAddress } : {}),
281
- erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
305
+ erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
282
306
  ...(l1Fee !== undefined ? { l1Fee } : {}),
283
307
  }
284
308
  }
@@ -344,7 +368,8 @@ async function getTransactionCount(
344
368
  async function getGasEstimation(
345
369
  api: JsonRpcProvider,
346
370
  address: string,
347
- transaction: { amount: BigNumber; data?: Buffer | null | undefined; recipient: string }
371
+ transaction: { amount: BigNumber; data?: Buffer | null | undefined; recipient: string },
372
+ logger: Logger
348
373
  ): Promise<BigNumber> {
349
374
  const to = transaction.recipient ? normalizeAddress(transaction.recipient) : undefined
350
375
  const value = BigInt(transaction.amount.toFixed(0))
@@ -359,17 +384,18 @@ async function getGasEstimation(
359
384
 
360
385
  return new BigNumber(gasEstimation.toString())
361
386
  } catch (e) {
362
- log('error', 'EVM Family: Gas Estimation Error', e)
387
+ logger('error', 'EVM Family: Gas Estimation Error', e)
363
388
  throw new GasEstimationError()
364
389
  }
365
390
  }
366
391
 
367
392
  function makeGetGasEstimation(
368
393
  evmConfig: EvmConfigInfo,
369
- nodeConfig: ExternalNodeConfig
394
+ nodeConfig: ExternalNodeConfig,
395
+ logger: Logger
370
396
  ): NodeApi['getGasEstimation'] {
371
397
  return (currencyId, address, transaction) =>
372
- withApi(evmConfig, currencyId, (api) => getGasEstimation(api, address, transaction), {
398
+ withApi(evmConfig, currencyId, (api) => getGasEstimation(api, address, transaction, logger), {
373
399
  ...nodeConfig,
374
400
  retries: 0,
375
401
  })
@@ -491,24 +517,40 @@ async function getFeeData(
491
517
  async function broadcastTransaction(
492
518
  api: JsonRpcProvider,
493
519
  _currencyId: string,
494
- signedTxHex: string
520
+ signedTxHex: string,
521
+ logger: Logger
495
522
  ): Promise<string> {
496
523
  try {
497
524
  const { hash } = await api.broadcastTransaction(signedTxHex)
498
525
  return hash
499
526
  } catch (e) {
500
527
  if (hasErrorCode(e, 'INSUFFICIENT_FUNDS')) {
501
- log('error', 'EVM Family: Wrong estimation of fees', e)
528
+ logger('error', 'EVM Family: Wrong estimation of fees', e)
502
529
  throw new InsufficientFunds()
503
530
  }
504
531
  throw e
505
532
  }
506
533
  }
507
534
 
535
+ /**
536
+ * Some pruned nodes (e.g. Alchemy on Astar) answer blocks they do not store with an empty stub block
537
+ * (zero timestamp, no transactions) instead of null. Only the genesis block can have a zero timestamp.
538
+ */
539
+ function assertNotStubBlock(
540
+ blockHeight: number | BlockFinalizationTag,
541
+ height: number,
542
+ timestampInSeconds: number
543
+ ): void {
544
+ if (height > 0 && timestampInSeconds === 0) {
545
+ throw new Error(`Block ${blockHeight} not found (the node returned an empty stub block)`)
546
+ }
547
+ }
548
+
508
549
  async function getBlockByHeight(
509
550
  api: JsonRpcProvider,
510
551
  _currencyId: string,
511
552
  blockHeight: number | BlockFinalizationTag,
553
+ logger: Logger,
512
554
  prefetchTxs?: boolean
513
555
  ): Promise<BlockByHeightResult> {
514
556
  let block: ethers.Block | null
@@ -518,7 +560,7 @@ async function getBlockByHeight(
518
560
  // Some chains (e.g. zkSync) can return tx objects missing signature fields, ethers then fails while formatting
519
561
  // prefetched transactions => we fallback to a custom getBlock implementation
520
562
  if (prefetchTxs && isSignatureError(error)) {
521
- log('warn', 'EVM getBlock fallback: using raw eth_getBlockByNumber response', {
563
+ logger('warn', 'EVM getBlock fallback: using raw eth_getBlockByNumber response', {
522
564
  blockHeight,
523
565
  error: String(error),
524
566
  })
@@ -530,6 +572,7 @@ async function getBlockByHeight(
530
572
  if (!block) {
531
573
  throw new Error(`Block ${blockHeight} not found`)
532
574
  }
575
+ assertNotStubBlock(blockHeight, block.number, block.timestamp)
533
576
 
534
577
  if (!block.hash) {
535
578
  throw new Error(`Block ${blockHeight} is missing hash`)
@@ -630,6 +673,7 @@ async function getBlockByHeightFromRawRpc(
630
673
 
631
674
  const height = parseRpcHexQuantity(block.number, 'block.number')
632
675
  const timestampInSeconds = parseRpcHexQuantity(block.timestamp, 'block.timestamp')
676
+ assertNotStubBlock(blockHeight, height, timestampInSeconds)
633
677
  const rawTransactions = block.transactions
634
678
  if (rawTransactions !== undefined && !Array.isArray(rawTransactions))
635
679
  throw new Error('Malformed block.transactions in eth_getBlockByNumber response')
@@ -704,7 +748,8 @@ async function getBlockByHeightFromRawRpc(
704
748
  async function getBlockReceipts(
705
749
  api: JsonRpcProvider,
706
750
  _currencyId: string,
707
- blockHeight: number | 'latest'
751
+ blockHeight: number | 'latest',
752
+ logger: Logger
708
753
  ): Promise<BlockReceiptInfo[]> {
709
754
  const blockTag = blockHeight === 'latest' ? 'latest' : ethers.toQuantity(blockHeight)
710
755
  let receipts: unknown
@@ -743,7 +788,7 @@ async function getBlockReceipts(
743
788
  gasUsed: BigInt(receipt.gasUsed).toString(),
744
789
  gasPrice: BigInt(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0').toString(),
745
790
  status: receipt.status === null ? null : Number(receipt.status),
746
- erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
791
+ erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
747
792
  ...(contractAddress ? { contractAddress } : {}),
748
793
  ...(receipt.type !== undefined ? { type: Number(receipt.type) } : {}),
749
794
  ...(l1Fee !== undefined ? { l1Fee } : {}),
@@ -760,7 +805,11 @@ async function traceBlockGeth(
760
805
  const debugResults = await api
761
806
  .send('debug_traceBlockByNumber', [rpcBlockTag, { tracer: 'callTracer' }])
762
807
  .catch((error) => {
763
- if (isUnsupportedRpcMethodError(error) || isUnsupportedRpcMethodErrorMsg(error)) {
808
+ if (
809
+ isUnsupportedRpcMethodError(error) ||
810
+ isUnsupportedRpcMethodErrorMsg(error) ||
811
+ isRpcMethodNotAvailableOnChainError(error)
812
+ ) {
764
813
  throw new UnsupportedRpcMethodError(
765
814
  'debug_traceBlockByNumber is not supported by this RPC provider',
766
815
  {
@@ -782,7 +831,7 @@ async function traceBlockErigon(
782
831
  ): Promise<TraceBlockItem[]> {
783
832
  const blockTag = blockHeight === 'latest' ? 'latest' : ethers.toQuantity(blockHeight)
784
833
  const traces = await api.send('trace_block', [blockTag]).catch((error) => {
785
- if (isUnsupportedRpcMethodError(error)) {
834
+ if (isUnsupportedRpcMethodError(error) || isRpcMethodNotAvailableOnChainError(error)) {
786
835
  throw new UnsupportedRpcMethodError('trace_block is not supported by this RPC provider', {
787
836
  method: 'trace_block',
788
837
  rawError: error,
@@ -939,26 +988,54 @@ function make<F extends (currencyId: string, ...args: any[]) => any>(
939
988
  }) as F
940
989
  }
941
990
 
942
- export function createNodeApi(evmConfig: EvmConfigInfo, nodeConfig: ExternalNodeConfig): NodeApi {
991
+ export function createNodeApi(
992
+ evmConfig: EvmConfigInfo,
993
+ nodeConfig: ExternalNodeConfig,
994
+ logger: Logger
995
+ ): NodeApi {
943
996
  return {
944
997
  call: make(call, evmConfig, nodeConfig),
945
- getBlockByHeight: make(getBlockByHeight, evmConfig, nodeConfig),
998
+ getBlockByHeight: ((currencyId, blockHeight, prefetchTxs) =>
999
+ withApi(
1000
+ evmConfig,
1001
+ currencyId,
1002
+ (api) => getBlockByHeight(api, currencyId, blockHeight, logger, prefetchTxs),
1003
+ nodeConfig
1004
+ )) as NodeApi['getBlockByHeight'],
946
1005
  getCoinBalance: make(getCoinBalance, evmConfig, nodeConfig),
947
1006
  getTokenBalance: make(getTokenBalance, evmConfig, nodeConfig),
948
1007
  getTokenAllowance: make(getTokenAllowance, evmConfig, nodeConfig),
949
1008
  getTransactionCount: make(getTransactionCount, evmConfig, nodeConfig),
950
- getTransaction: make(getTransaction, evmConfig, nodeConfig),
951
- getBlockReceipts: make(getBlockReceipts, evmConfig, nodeConfig),
1009
+ getTransaction: ((currencyId, txHash) =>
1010
+ withApi(
1011
+ evmConfig,
1012
+ currencyId,
1013
+ (api) => getTransaction(api, currencyId, txHash, logger),
1014
+ nodeConfig
1015
+ )) as NodeApi['getTransaction'],
1016
+ getBlockReceipts: ((currencyId, blockHeight) =>
1017
+ withApi(
1018
+ evmConfig,
1019
+ currencyId,
1020
+ (api) => getBlockReceipts(api, currencyId, blockHeight, logger),
1021
+ nodeConfig
1022
+ )) as NonNullable<NodeApi['getBlockReceipts']>,
952
1023
  traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
953
1024
  traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
954
- getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig),
1025
+ getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
955
1026
  // getFeeData takes `config` first (not `currencyId`), so it can't use the currencyId-first
956
1027
  // `make` wrapper; bind it explicitly and pull `currencyId` from the second argument for `withApi`.
957
1028
  getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) => {
958
1029
  const [, currencyId] = args
959
1030
  return withApi(evmConfig, currencyId, (api) => getFeeData(api, ...args), nodeConfig)
960
1031
  }) as NodeApi['getFeeData'],
961
- broadcastTransaction: make(broadcastTransaction, evmConfig, nodeConfig, { retries: 0 }),
1032
+ broadcastTransaction: ((currencyId, signedTxHex) =>
1033
+ withApi(
1034
+ evmConfig,
1035
+ currencyId,
1036
+ (api) => broadcastTransaction(api, currencyId, signedTxHex, logger),
1037
+ { ...nodeConfig, retries: 0 }
1038
+ )) as NodeApi['broadcastTransaction'],
962
1039
  getOptimismAdditionalFees: makeLRUCache(
963
1040
  make(getOptimismAdditionalFees, evmConfig, nodeConfig),
964
1041
  cacheKeyOptimismL1Fees,