@ledgerhq/coin-evm 16.5.2 → 16.5.3

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 (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/lib/config.d.ts +9 -0
  3. package/lib/config.d.ts.map +1 -1
  4. package/lib/config.js +4 -0
  5. package/lib/config.js.map +1 -1
  6. package/lib/errors.d.ts +15 -0
  7. package/lib/errors.d.ts.map +1 -1
  8. package/lib/errors.js +31 -1
  9. package/lib/errors.js.map +1 -1
  10. package/lib/logic/feeCollectorOperations.d.ts +61 -0
  11. package/lib/logic/feeCollectorOperations.d.ts.map +1 -0
  12. package/lib/logic/feeCollectorOperations.js +206 -0
  13. package/lib/logic/feeCollectorOperations.js.map +1 -0
  14. package/lib/logic/listOperations.d.ts.map +1 -1
  15. package/lib/logic/listOperations.js +4 -1
  16. package/lib/logic/listOperations.js.map +1 -1
  17. package/lib/network/node/rpc.common.d.ts.map +1 -1
  18. package/lib/network/node/rpc.common.js +84 -29
  19. package/lib/network/node/rpc.common.js.map +1 -1
  20. package/lib-es/config.d.ts +9 -0
  21. package/lib-es/config.d.ts.map +1 -1
  22. package/lib-es/config.js +4 -0
  23. package/lib-es/config.js.map +1 -1
  24. package/lib-es/errors.d.ts +15 -0
  25. package/lib-es/errors.d.ts.map +1 -1
  26. package/lib-es/errors.js +27 -0
  27. package/lib-es/errors.js.map +1 -1
  28. package/lib-es/logic/feeCollectorOperations.d.ts +61 -0
  29. package/lib-es/logic/feeCollectorOperations.d.ts.map +1 -0
  30. package/lib-es/logic/feeCollectorOperations.js +201 -0
  31. package/lib-es/logic/feeCollectorOperations.js.map +1 -0
  32. package/lib-es/logic/listOperations.d.ts.map +1 -1
  33. package/lib-es/logic/listOperations.js +4 -1
  34. package/lib-es/logic/listOperations.js.map +1 -1
  35. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  36. package/lib-es/network/node/rpc.common.js +85 -30
  37. package/lib-es/network/node/rpc.common.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/api/tests/getBlock.integ.test.ts +3 -32
  40. package/src/api/tests/index.alpen_testnet.integ.test.ts +2 -7
  41. package/src/api/tests/index.arbitrum.integ.test.ts +2 -12
  42. package/src/api/tests/index.arc.integ.test.ts +2 -13
  43. package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +2 -12
  44. package/src/api/tests/index.cronos.integ.test.ts +2 -12
  45. package/src/api/tests/index.flare.integ.test.ts +2 -8
  46. package/src/api/tests/index.integ.test.ts +5 -35
  47. package/src/api/tests/index.linea.integ.test.ts +2 -15
  48. package/src/api/tests/index.monad_testnet.integ.test.ts +5 -13
  49. package/src/api/tests/index.optimism.integ.test.ts +2 -12
  50. package/src/api/tests/index.rsk.integ.test.ts +2 -12
  51. package/src/api/tests/index.scroll.integ.test.ts +4 -7
  52. package/src/api/tests/index.shape.integ.test.ts +3 -27
  53. package/src/api/tests/index.somnia.integ.test.ts +2 -6
  54. package/src/api/tests/index.unichain.integ.test.ts +2 -12
  55. package/src/api/tests/index.zksync.integ.test.ts +5 -8
  56. package/src/config.ts +11 -0
  57. package/src/errors.ts +27 -0
  58. package/src/logic/feeCollectorOperations.ts +272 -0
  59. package/src/logic/listOperations.ts +20 -1
  60. package/src/logic/tests/broadcast.integ.test.ts +4 -15
  61. package/src/logic/tests/listOperations.test.ts +563 -0
  62. package/src/network/node/rpc.common.ts +128 -30
  63. package/src/network/tests/node/rpc.test.ts +79 -7
  64. package/src/staking/validators.integ.test.ts +5 -22
@@ -5,13 +5,12 @@ import type { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index
5
5
  import type { BufferTxData, Operation } from '@ledgerhq/coin-module-framework/api/types'
6
6
  import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
7
7
  import { ethers } from 'ethers'
8
+ import { evmDefaults } from '../../config'
8
9
  import {
9
10
  createMockEvmConfigInfo,
10
11
  createMockEvmContext,
11
12
  mkEtherscanExplorer,
12
13
  mkExternalNode,
13
- mkLedgerExplorer,
14
- mkLedgerNode,
15
14
  } from '../../fixtures/context.fixtures'
16
15
  import { isNative } from '../../types/assets'
17
16
  import { createApi } from '../index'
@@ -29,9 +28,7 @@ describe.each([
29
28
  [
30
29
  'ledger node and explorer',
31
30
  createMockEvmConfigInfo({
32
- chainId: 1,
33
- node: mkLedgerNode({ explorerId: 'eth' }),
34
- explorer: mkLedgerExplorer({ explorerId: 'eth' }),
31
+ ...evmDefaults.ethereum,
35
32
  supportedTokens: ['erc721', 'erc1155'],
36
33
  }),
37
34
  ],
@@ -342,16 +339,7 @@ describe.each([
342
339
  */
343
340
  it('returns at least 10 token balances on Optimisim', async () => {
344
341
  const module = createApi()
345
- const context = createMockEvmContext(
346
- createMockEvmConfigInfo({
347
- chainId: 10,
348
- node: mkExternalNode({ uri: 'https://mainnet.optimism.io' }),
349
- explorer: {
350
- type: 'blockscout' as const,
351
- uri: 'https://proxyblockscout.api.live.ledger.com/10/api',
352
- },
353
- })
354
- )
342
+ const context = createMockEvmContext(evmDefaults.optimism)
355
343
  const result = await module.getBalance(context, '0x1CDDb825910426644e00e769072Ce1Ea7d4e34BB')
356
344
 
357
345
  expect(result.length).toBeGreaterThan(10)
@@ -961,15 +949,7 @@ describe('EVM Api (SEI Network)', () => {
961
949
  const seiStakingSender = '0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3'
962
950
  const seiStakingRecipient = '0x0000000000000000000000000000000000001005'
963
951
  const seiStakingDelegationAmount = 1000000000000000n // 0.001 SEI
964
- const context = createMockEvmContext(
965
- createMockEvmConfigInfo({
966
- chainId: 1329,
967
- node: mkExternalNode({ uri: 'https://sei-evm.coin.ledger.com' }),
968
- explorer: mkEtherscanExplorer({
969
- uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1329',
970
- }),
971
- })
972
- )
952
+ const context = createMockEvmContext(evmDefaults.sei_evm)
973
953
 
974
954
  beforeAll(() => {
975
955
  module = createApi()
@@ -1099,17 +1079,7 @@ describe('EVM Api (SEI Network)', () => {
1099
1079
 
1100
1080
  describe('EVM Api (Zero Gravity)', () => {
1101
1081
  let module: ReturnType<typeof createApi>
1102
- const context = createMockEvmContext(
1103
- createMockEvmConfigInfo({
1104
- chainId: 16661,
1105
- node: mkExternalNode({ uri: 'https://zero-gravity.coin.ledger.com' }),
1106
- explorer: {
1107
- type: 'etherscan' as const,
1108
- uri: 'https://chainscan.0g.ai/open/api',
1109
- maxLimit: 99, // use 99 so internal `limit + 1` probing stays within the explorer's hard max of 100
1110
- },
1111
- })
1112
- )
1082
+ const context = createMockEvmContext(evmDefaults.zero_gravity)
1113
1083
 
1114
1084
  beforeAll(() => {
1115
1085
  module = createApi()
@@ -1,7 +1,7 @@
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 { evmDefaults } from '../../config'
5
5
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
6
6
  import { createApi } from '../index'
7
7
 
@@ -25,20 +25,7 @@ describe('Linea (etherscan explorer)', () => {
25
25
  const TO = '0x9F41fE989C556d8b312Ce398b7f7B5Ac90919a73'
26
26
 
27
27
  let module: ReturnType<typeof createApi>
28
- const lineaConfig: EvmConfigInfo = {
29
- status: { type: 'active' },
30
- chainId: 59144,
31
- name: 'Linea',
32
- unit: { name: 'ETH', code: 'ETH', magnitude: 18 },
33
- node: {
34
- type: 'external',
35
- uri: 'https://linea.coin.ledger.com',
36
- },
37
- explorer: {
38
- type: 'etherscan',
39
- uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/59144',
40
- },
41
- }
28
+ const lineaConfig = evmDefaults.linea
42
29
 
43
30
  beforeAll(() => {
44
31
  module = createApi()
@@ -1,12 +1,9 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { evmDefaults } from '../../config'
4
5
  import { EtherscanAPIError } from '../../errors'
5
- import {
6
- createMockEvmConfigInfo,
7
- createMockEvmContext,
8
- testLogger,
9
- } from '../../fixtures/context.fixtures'
6
+ import { createMockEvmContext, testLogger } from '../../fixtures/context.fixtures'
10
7
  import { getNodeApi } from '../../network/node'
11
8
  import { nodeSourcesFromList } from '../../nodeSources'
12
9
  import { createApi } from '../index'
@@ -14,15 +11,10 @@ import { createApi } from '../index'
14
11
  describe('EVM Api (Monad Testnet)', () => {
15
12
  let module: ReturnType<typeof createApi>
16
13
 
17
- const config = createMockEvmConfigInfo({
18
- chainId: 10143,
19
- node: { type: 'external', uri: 'https://monad-testnet.coin.ledger.com' },
20
- explorer: {
21
- type: 'etherscan',
22
- uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/10143',
23
- },
14
+ const config = {
15
+ ...evmDefaults.monad_testnet,
24
16
  nodeSources: nodeSourcesFromList(['explorer-proxy', 'node']),
25
- })
17
+ }
26
18
  beforeAll(() => {
27
19
  module = createApi()
28
20
  })
@@ -1,25 +1,15 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
5
4
  import type { Operation } from '@ledgerhq/coin-module-framework/api/types'
5
+ import { evmDefaults } from '../../config'
6
6
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
7
7
  import { createApi } from '../index'
8
8
 
9
9
  describe('EVM Optimism Network', () => {
10
10
  let module: ReturnType<typeof createApi>
11
11
 
12
- const config: Partial<EvmConfigInfo> = {
13
- chainId: 10,
14
- node: {
15
- type: 'external',
16
- uri: 'https://optimism.coin.ledger.com',
17
- },
18
- explorer: {
19
- type: 'etherscan',
20
- uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/10',
21
- },
22
- }
12
+ const config = evmDefaults.optimism
23
13
  beforeAll(() => {
24
14
  module = createApi()
25
15
  })
@@ -1,24 +1,14 @@
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 { evmDefaults } from '../../config'
5
5
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
6
6
  import { createApi } from '../index'
7
7
 
8
8
  describe('EVM RSK Network', () => {
9
9
  let module: ReturnType<typeof createApi>
10
10
 
11
- const config: Partial<EvmConfigInfo> = {
12
- chainId: 30,
13
- node: {
14
- type: 'external',
15
- uri: 'https://rsk.coin.ledger.com',
16
- },
17
- explorer: {
18
- type: 'blockscout',
19
- uri: 'https://proxyblockscout.api.live.ledger.com/30/api',
20
- },
21
- }
11
+ const config = evmDefaults.rsk
22
12
  beforeAll(() => {
23
13
  module = createApi()
24
14
  })
@@ -3,17 +3,14 @@
3
3
 
4
4
  import type { EvmConfigInfo } from '../../config'
5
5
  import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
6
- import { internalTxSourcesFromList } from '../../config'
6
+ import { evmDefaults, internalTxSourcesFromList } from '../../config'
7
7
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
8
8
  import { createApi } from '../index'
9
9
 
10
10
  describe('EVM Scroll Network (blockscout-v2 explorer)', () => {
11
- const config: Partial<EvmConfigInfo> = {
12
- chainId: 534352,
13
- node: {
14
- type: 'external',
15
- uri: 'https://scroll.alpaca.api.ledger.com',
16
- },
11
+ const config: EvmConfigInfo = {
12
+ ...evmDefaults.scroll,
13
+ // These tests target the blockscout-v2 API and NFT transfers, unlike the default config.
17
14
  explorer: {
18
15
  type: 'blockscout-v2',
19
16
  uri: 'https://proxyblockscout.api.live.ledger.com/534352/api/v2',
@@ -1,28 +1,14 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
5
4
  import { fail } from 'assert'
5
+ import { evmDefaults } from '../../config'
6
6
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
7
7
  import { createApi } from '../index'
8
8
 
9
9
  describe('Shape (external node)', () => {
10
10
  describe('getBlock', () => {
11
- const shapeConfig: EvmConfigInfo = {
12
- status: { type: 'active' },
13
- chainId: 360,
14
- name: 'Shape',
15
- unit: { name: 'ETH', code: 'ETH', magnitude: 18 },
16
- node: {
17
- type: 'external',
18
- uri: 'https://mainnet.shape.network',
19
- },
20
- explorer: {
21
- type: 'blockscout',
22
- uri: 'https://proxyblockscout.api.live.ledger.com/360/api',
23
- },
24
- supportedTokens: ['erc721', 'erc1155'],
25
- }
11
+ const shapeConfig = evmDefaults.shape
26
12
  const module = createApi()
27
13
 
28
14
  it('should return WETH mint from Deposit log in block 26327282 (tx 0x08761e…) see BACK-10995', async () => {
@@ -50,17 +36,7 @@ describe('Shape (external node)', () => {
50
36
 
51
37
  // Shape's Blockscout reports the L1 data fee in `txlist` (`L1FeesPaid`), so the v1 API is enough
52
38
  describe('fees include the L1 data fee', () => {
53
- const config: Partial<EvmConfigInfo> = {
54
- chainId: 360,
55
- node: {
56
- type: 'external',
57
- uri: 'https://mainnet.shape.network',
58
- },
59
- explorer: {
60
- type: 'blockscout',
61
- uri: 'https://proxyblockscout.api.live.ledger.com/360/api',
62
- },
63
- }
39
+ const config = evmDefaults.shape
64
40
  const module = createApi()
65
41
 
66
42
  const txHash = '0x68d2739afa41ec0523e03eb672002152195af1cf928ba6afa4b48944462d6754'
@@ -1,18 +1,14 @@
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 { evmDefaults } from '../../config'
5
5
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
6
6
  import { createApi } from '../index'
7
7
 
8
8
  describe('EVM Api (Somnia)', () => {
9
9
  let module: ReturnType<typeof createApi>
10
10
 
11
- const config: Partial<EvmConfigInfo> = {
12
- chainId: 5031,
13
- node: { type: 'external', uri: 'https://api.infra.mainnet.somnia.network' },
14
- explorer: { type: 'blockscout', uri: 'https://explorer.somnia.network/api/' },
15
- }
11
+ const config = evmDefaults.somnia
16
12
 
17
13
  beforeAll(() => {
18
14
  module = createApi()
@@ -1,24 +1,14 @@
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 { evmDefaults } from '../../config'
5
5
  import { createMockEvmContext } from '../../fixtures/context.fixtures'
6
6
  import { createApi } from '../index'
7
7
 
8
8
  describe('EVM Unichain Network', () => {
9
9
  const module = createApi()
10
10
 
11
- const config: Partial<EvmConfigInfo> = {
12
- chainId: 130,
13
- node: {
14
- type: 'external',
15
- uri: 'https://unichain-rpc.publicnode.com',
16
- },
17
- explorer: {
18
- type: 'etherscan',
19
- uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/130',
20
- },
21
- }
11
+ const config = evmDefaults.unichain
22
12
 
23
13
  const txHash = '0x39051f6ca394bb88cc17b3a38f00fd64444152056ab3c3bc9c2840da1f7c6f45'
24
14
  // gasUsed × gasPrice (467932 × 100890 = 47_209_659_480) + l1Fee (13_500_719_807), see LIVE-38797
@@ -1,7 +1,8 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { createMockEvmContext, mkExternalNode } from '../../fixtures/context.fixtures'
4
+ import { evmDefaults } from '../../config'
5
+ import { createMockEvmContext } from '../../fixtures/context.fixtures'
5
6
  import { createApi } from '../index'
6
7
 
7
8
  /**
@@ -24,13 +25,9 @@ describe('ZkSync (blockscout explorer)', () => {
24
25
  it('listOperations completes without timing out', async () => {
25
26
  const { items } = await module.listOperations(
26
27
  createMockEvmContext({
27
- chainId: 324,
28
- node: mkExternalNode({ uri: 'https://zksync.coin.ledger.com', retries: 0 }),
29
- explorer: {
30
- type: 'blockscout',
31
- uri: 'https://proxyblockscout.api.live.ledger.com/324/api',
32
- retries: 0,
33
- },
28
+ ...evmDefaults.zksync,
29
+ node: { ...evmDefaults.zksync.node, retries: 0 },
30
+ explorer: { ...evmDefaults.zksync.explorer, retries: 0 },
34
31
  }),
35
32
  ADDRESS,
36
33
  { minHeight: 0, order: 'asc', limit: 1 }
package/src/config.ts CHANGED
@@ -132,6 +132,13 @@ export type EvmConfig = {
132
132
  * Addresses are matched case-insensitively.
133
133
  */
134
134
  feeCollectorContracts?: string[]
135
+ /**
136
+ * Token contracts that carry the native coin to and from the `feeCollectorContracts` (e.g. the
137
+ * zkSync base token, the native coin as an ERC-20). A transfer of one of them to a fee collector
138
+ * pays the fee, like a native transfer; another token sent to it does not.
139
+ * Addresses are matched case-insensitively.
140
+ */
141
+ feeCollectorTokens?: string[]
135
142
  /**
136
143
  * Minimum effective price per gas (in wei, decimal string) accepted by this chain's
137
144
  * mempool. Applied as a floor to both the legacy `gasPrice` and the EIP-1559
@@ -964,6 +971,8 @@ export const evmDefaults = {
964
971
  explorer: { type: 'blockscout', uri: 'https://proxyblockscout.api.live.ledger.com/324/api' },
965
972
  // bootloader
966
973
  feeCollectorContracts: ['0x0000000000000000000000000000000000008001'],
974
+ // base token (L2BaseToken)
975
+ feeCollectorTokens: ['0x000000000000000000000000000000000000800A'],
967
976
  },
968
977
  zksync_sepolia: {
969
978
  status: {
@@ -977,6 +986,8 @@ export const evmDefaults = {
977
986
  explorer: { type: 'blockscout', uri: 'https://zksync-sepolia.blockscout.com/api' },
978
987
  // bootloader
979
988
  feeCollectorContracts: ['0x0000000000000000000000000000000000008001'],
989
+ // base token (L2BaseToken)
990
+ feeCollectorTokens: ['0x000000000000000000000000000000000000800A'],
980
991
  },
981
992
  monad: {
982
993
  status: {
package/src/errors.ts CHANGED
@@ -94,6 +94,33 @@ export class UnsupportedRpcMethodError extends Error {
94
94
  }
95
95
  }
96
96
 
97
+ /** The node has no such transaction, or no receipt for it yet. */
98
+ export class NodeTransactionNotFound extends Error {
99
+ override name = 'NodeTransactionNotFound'
100
+ constructor(message?: string, fields?: Record<string, unknown>) {
101
+ super(message || 'NodeTransactionNotFound')
102
+ if (fields) Object.assign(this, fields)
103
+ }
104
+ }
105
+
106
+ /** The node has no such block, or answered with an empty stub block. */
107
+ export class NodeBlockNotFound extends Error {
108
+ override name = 'NodeBlockNotFound'
109
+ constructor(message?: string, fields?: Record<string, unknown>) {
110
+ super(message || 'NodeBlockNotFound')
111
+ if (fields) Object.assign(this, fields)
112
+ }
113
+ }
114
+
115
+ /** The node answered with a response that does not have the expected shape. */
116
+ export class MalformedNodeResponse extends Error {
117
+ override name = 'MalformedNodeResponse'
118
+ constructor(message?: string, fields?: Record<string, unknown>) {
119
+ super(message || 'MalformedNodeResponse')
120
+ if (fields) Object.assign(this, fields)
121
+ }
122
+ }
123
+
97
124
  /**
98
125
  * Internal-tx source should be skipped (not propagated): not configured, structurally
99
126
  * unsupported, best-effort runtime failure (e.g. explorer), or all sources exhausted