@ledgerhq/coin-evm 5.3.2 → 5.3.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 (47) hide show
  1. package/.oxlintrc.json +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/package.json +2 -2
  4. package/src/adapters/blockOperations.test.ts +27 -29
  5. package/src/api/index.flare.integ.test.ts +1 -13
  6. package/src/api/index.integ.test.ts +86 -97
  7. package/src/fixtures/context.fixtures.ts +79 -1
  8. package/src/fixtures/ethers.fixtures.ts +26 -0
  9. package/src/logic/broadcast.integ.test.ts +6 -18
  10. package/src/logic/broadcast.test.ts +19 -31
  11. package/src/logic/broadcastSource.test.ts +6 -7
  12. package/src/logic/common.test.ts +120 -112
  13. package/src/logic/craftTransaction.test.ts +161 -199
  14. package/src/logic/craftTransactionData.test.ts +6 -6
  15. package/src/logic/estimateFees.test.ts +19 -15
  16. package/src/logic/getBalance.test.ts +15 -14
  17. package/src/logic/getBlock.test.ts +372 -382
  18. package/src/logic/getBlockInfo.test.ts +6 -6
  19. package/src/logic/getNextSequence.test.ts +5 -5
  20. package/src/logic/getStakes.test.ts +34 -34
  21. package/src/logic/internalTransactionsFetcher.test.ts +23 -19
  22. package/src/logic/lastBlock.test.ts +29 -21
  23. package/src/logic/listOperations.test.ts +43 -40
  24. package/src/logic/validateIntent.test.ts +151 -101
  25. package/src/logic.test.ts +13 -18
  26. package/src/network/explorer/etherscan.test.ts +5 -5
  27. package/src/network/explorer/index.test.ts +51 -21
  28. package/src/network/explorer/ledger.test.ts +15 -4
  29. package/src/network/gasTracker/index.test.ts +14 -8
  30. package/src/network/gasTracker/ledger.test.ts +25 -13
  31. package/src/network/node/index.memoization.test.ts +25 -31
  32. package/src/network/node/index.test.ts +14 -25
  33. package/src/network/node/ledger.test.ts +45 -60
  34. package/src/network/node/node.fixtures.ts +0 -2
  35. package/src/network/node/rpc.test.ts +152 -177
  36. package/src/staking/encoder.test.ts +13 -21
  37. package/src/staking/logic.test.ts +20 -14
  38. package/src/staking/operations/index.test.ts +28 -28
  39. package/src/staking/prepareIntents.test.ts +26 -20
  40. package/src/staking/redelegations.test.ts +27 -18
  41. package/src/staking/rewards.test.ts +23 -15
  42. package/src/staking/rewardsFromReceipt.test.ts +19 -20
  43. package/src/staking/transactionData.test.ts +22 -22
  44. package/src/staking/validators/monad.test.ts +65 -24
  45. package/src/staking/validators/somnia.test.ts +21 -13
  46. package/src/staking/validators/zero_gravity.test.ts +118 -48
  47. package/src/staking/validators.integ.test.ts +13 -25
@@ -1,12 +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
- import type { EvmContext } from '../config'
4
+ import type { EvmConfig, EvmContext } from '../config'
6
5
  import type { ExplorerApi } from '../network/explorer/types'
7
6
  import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
8
7
  import BigNumber from 'bignumber.js'
9
- import { createMockEvmContext } from '../fixtures/context.fixtures'
8
+ import {
9
+ createMockEvmContext,
10
+ mkEtherscanExplorer,
11
+ mkLedgerExplorer,
12
+ } from '../fixtures/context.fixtures'
10
13
  import etherscanExplorer from '../network/explorer/etherscan'
11
14
  import ledgerExplorer from '../network/explorer/ledger'
12
15
  import { listOperations } from './listOperations'
@@ -17,8 +20,8 @@ describe('listOperations', () => {
17
20
 
18
21
  // The logic layer resolves config from the threaded context, so tests carry their explorer
19
22
  // config on the context instead of seeding the module-level singleton.
20
- const ctxWithExplorer = (explorer: unknown): EvmContext =>
21
- createMockEvmContext({ explorer } as unknown as Partial<EvmConfigInfo>)
23
+ const ctxWithExplorer = (explorer: EvmConfig['explorer']): EvmContext =>
24
+ createMockEvmContext({ explorer })
22
25
 
23
26
  afterEach(() => {
24
27
  jest.clearAllMocks()
@@ -273,13 +276,13 @@ describe('listOperations', () => {
273
276
  })
274
277
 
275
278
  it.each([
276
- ['an etherscan explorer', { type: 'etherscan' }, etherscanExplorer.explorerApi],
279
+ ['an etherscan explorer', mkEtherscanExplorer(), etherscanExplorer.explorerApi],
277
280
  [
278
281
  'a no cache etherscan explorer',
279
- { type: 'etherscan', noCache: true },
282
+ mkEtherscanExplorer({ noCache: true }),
280
283
  etherscanExplorer.explorerApiNoCache,
281
284
  ],
282
- ['a ledger explorer', { type: 'ledger' }, ledgerExplorer],
285
+ ['a ledger explorer', mkLedgerExplorer(), ledgerExplorer],
283
286
  ])('lists latest operations using %s', async (_, config, explorer) => {
284
287
  const testContext = ctxWithExplorer(config)
285
288
  const getOperationsSpy = buildOperationsSpy(explorer)
@@ -548,7 +551,7 @@ describe('listOperations', () => {
548
551
  })
549
552
 
550
553
  it('filters out operations where the requested address is not involved (case insensitive)', async () => {
551
- const testContext = ctxWithExplorer({ type: 'ledger' })
554
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
552
555
  const address = 'address'
553
556
  // Explorer returns: one native op for "address", and one internal op (same tx) where
554
557
  // senders/recipients and parent senders/recipients do NOT include "address"
@@ -646,7 +649,7 @@ describe('listOperations', () => {
646
649
  })
647
650
 
648
651
  it('should use token transfer value for ERC20 operations, not parent native value', async () => {
649
- const testContext = ctxWithExplorer({ type: 'ledger' })
652
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
650
653
 
651
654
  const txHash = '0x4235dc16c74aecb248ad1005f3a0c82582a25afe797e62ecc8f4eed86ca628a1'
652
655
  const txFee = 21000000000000n
@@ -750,7 +753,7 @@ describe('listOperations', () => {
750
753
  })
751
754
 
752
755
  it('leaves feesPayer undefined when token op has no parent coin op (no reference operation)', async () => {
753
- const testContext = ctxWithExplorer({ type: 'ledger' })
756
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
754
757
 
755
758
  const recipient = '0xrecipient'
756
759
  const sender = '0xsender'
@@ -818,7 +821,7 @@ describe('listOperations', () => {
818
821
  * @see https://ledgerhq.atlassian.net/browse/BACK-10954
819
822
  */
820
823
  it('uses parent coin operation fee for token ops when explorer fee on token row differs', async () => {
821
- const testContext = ctxWithExplorer({ type: 'ledger' })
824
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
822
825
 
823
826
  const address = '0x63f5c1b5a54a2423a0284b55ad6e48485e048e6a'
824
827
  const txHash = '0xdd046a625b9b4b1ec9c9eaabfa61869f74d9d744433dae3c7686432301713bb3'
@@ -898,7 +901,7 @@ describe('listOperations', () => {
898
901
  * A token op keeps its own block.hash when present, and only falls back to the parent's.
899
902
  */
900
903
  it('falls back to the parent block.hash on token ops when the explorer token row omits it', async () => {
901
- const testContext = ctxWithExplorer({ type: 'etherscan' })
904
+ const testContext = ctxWithExplorer(mkEtherscanExplorer())
902
905
  const txHash = '0x6593efaefa1752c9ba92ba079fc9705daad1f67b3437b07139692e8e5b647021'
903
906
  const parentBlockHash = '0x77fd02171913e7af2b4d76aeaca2bd70d36e112a66092790c4c2c8a57566a7e2'
904
907
  const date = new Date('2026-02-16T09:25:37.000Z')
@@ -937,7 +940,7 @@ describe('listOperations', () => {
937
940
  },
938
941
  tx: {
939
942
  hash: txHash,
940
- block: { height: 24886171, time: date },
943
+ block: { height: 24886171, hash: '', time: date },
941
944
  fees: 0n,
942
945
  date,
943
946
  failed: false,
@@ -967,7 +970,7 @@ describe('listOperations', () => {
967
970
 
968
971
  it('inherits the parent nonce on token ops, whose fees-only native op is dropped', async () => {
969
972
  // LIVE-35844: the Ledger explorer only reports the nonce on the native op
970
- const testContext = ctxWithExplorer({ type: 'ledger' })
973
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
971
974
 
972
975
  const address = '0xb69b37a4fb4a18b3258f974ff6e9f529ad2647b1'
973
976
  const txHash = '0xf034ecf17ad61bc29bab12fc303296428d6c7c8a285bd92b2e30a92b1dd5f3bc'
@@ -1018,7 +1021,7 @@ describe('listOperations', () => {
1018
1021
  })
1019
1022
 
1020
1023
  it('should emit both native and token operations when tx has native value > 0 and token transfers', async () => {
1021
- const testContext = ctxWithExplorer({ type: 'ledger' })
1024
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1022
1025
 
1023
1026
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
1024
1027
  lastCoinOperations: [
@@ -1164,7 +1167,7 @@ describe('listOperations', () => {
1164
1167
  it.each(paginationBehaviors)(
1165
1168
  'etherscan explorer sort parameter is respected %s',
1166
1169
  async ({ limit, order, expectedExplorerOrder, expectedResultOrder }) => {
1167
- const testContext = ctxWithExplorer({ type: 'etherscan' })
1170
+ const testContext = ctxWithExplorer(mkEtherscanExplorer())
1168
1171
  const getOperationsSpy = buildOperationsSpy(etherscanExplorer.explorerApi)
1169
1172
  const { items: result } = await listOperations(testContext, currency, address, {
1170
1173
  minHeight: 0,
@@ -1236,7 +1239,7 @@ describe('listOperations', () => {
1236
1239
  details: { internal: true, sequence: BigNumber(1) },
1237
1240
  }
1238
1241
 
1239
- const testContext = ctxWithExplorer({ type: 'ledger' })
1242
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1240
1243
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
1241
1244
  lastCoinOperations: [ambiguousParentSenders],
1242
1245
  lastTokenOperations: [relatedTokenOp],
@@ -1259,7 +1262,7 @@ describe('listOperations', () => {
1259
1262
  it('preserves semantic operation types (DELEGATE, NFT_*, etc.) instead of mapping to IN/OUT', async () => {
1260
1263
  const address = '0xdelegator'
1261
1264
  const stakingContract = '0xstaking'
1262
- const testContext = ctxWithExplorer({ type: 'ledger' })
1265
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1263
1266
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
1264
1267
  lastCoinOperations: [
1265
1268
  {
@@ -1299,7 +1302,7 @@ describe('listOperations', () => {
1299
1302
  it('preserves REWARD type for outbound claim-reward tx (not downgraded to OUT/FEES)', async () => {
1300
1303
  const address = '0xdelegator'
1301
1304
  const distributionPrecompile = '0x0000000000000000000000000000000000001007'
1302
- const testContext = ctxWithExplorer({ type: 'ledger' })
1305
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1303
1306
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
1304
1307
  lastCoinOperations: [
1305
1308
  {
@@ -1335,7 +1338,7 @@ describe('listOperations', () => {
1335
1338
  })
1336
1339
 
1337
1340
  it('copies smart contract fields from explorer extra into operation details', async () => {
1338
- const testContext = ctxWithExplorer({ type: 'ledger' })
1341
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1339
1342
  const contractAddr = '0x1111111111111111111111111111111111111111'
1340
1343
  const payload = '0xabcd'
1341
1344
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
@@ -1517,7 +1520,7 @@ describe('listOperations', () => {
1517
1520
  }
1518
1521
 
1519
1522
  it('Case 1: simple native transfer between EOAs', async () => {
1520
- const testContext = ctxWithExplorer({ type: 'ledger' })
1523
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1521
1524
  mockGetOperations({
1522
1525
  lastCoinOperations: [
1523
1526
  {
@@ -1563,7 +1566,7 @@ describe('listOperations', () => {
1563
1566
  })
1564
1567
 
1565
1568
  it('Case 2: native self send from EOA', async () => {
1566
- const testContext = ctxWithExplorer({ type: 'ledger' })
1569
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1567
1570
  mockGetOperations({
1568
1571
  lastCoinOperations: [
1569
1572
  {
@@ -1602,7 +1605,7 @@ describe('listOperations', () => {
1602
1605
  })
1603
1606
 
1604
1607
  it('Case 2: when explorer returns IN+OUT for self-send, still 2 ops', async () => {
1605
- const testContext = ctxWithExplorer({ type: 'ledger' })
1608
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1606
1609
  mockGetOperations(
1607
1610
  {
1608
1611
  lastCoinOperations: [
@@ -1634,7 +1637,7 @@ describe('listOperations', () => {
1634
1637
  })
1635
1638
 
1636
1639
  it('Case 3: simple ERC20 transfer between EOAs', async () => {
1637
- const testContext = ctxWithExplorer({ type: 'ledger' })
1640
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1638
1641
  const sharedTxHash = '0xcase3'
1639
1642
  mockGetOperations(
1640
1643
  {
@@ -1694,7 +1697,7 @@ describe('listOperations', () => {
1694
1697
  })
1695
1698
 
1696
1699
  it('Case 4: ERC20 self send from EOA', async () => {
1697
- const testContext = ctxWithExplorer({ type: 'ledger' })
1700
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1698
1701
  mockGetOperations(
1699
1702
  {
1700
1703
  lastCoinOperations: [
@@ -1746,7 +1749,7 @@ describe('listOperations', () => {
1746
1749
  })
1747
1750
 
1748
1751
  it('Case 5: ETH transfer from smart contract', async () => {
1749
- const testContext = ctxWithExplorer({ type: 'ledger' })
1752
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1750
1753
  const sharedTxHash = '0xcase5'
1751
1754
  mockGetOperations(
1752
1755
  {
@@ -1805,7 +1808,7 @@ describe('listOperations', () => {
1805
1808
  })
1806
1809
 
1807
1810
  it('Case 6: ERC20 transfer from smart contract', async () => {
1808
- const testContext = ctxWithExplorer({ type: 'ledger' })
1811
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1809
1812
  const sharedTxHash = '0xcase6'
1810
1813
  mockGetOperations(
1811
1814
  {
@@ -1880,7 +1883,7 @@ describe('listOperations', () => {
1880
1883
  })
1881
1884
 
1882
1885
  it('Case 7: ETH transfer to smart contract', async () => {
1883
- const testContext = ctxWithExplorer({ type: 'ledger' })
1886
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1884
1887
  mockGetOperations({
1885
1888
  lastCoinOperations: [
1886
1889
  {
@@ -1911,7 +1914,7 @@ describe('listOperations', () => {
1911
1914
  })
1912
1915
 
1913
1916
  it('Case 8: ERC20 transfer to smart contract', async () => {
1914
- const testContext = ctxWithExplorer({ type: 'ledger' })
1917
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1915
1918
  mockGetOperations(
1916
1919
  {
1917
1920
  lastCoinOperations: [
@@ -1955,7 +1958,7 @@ describe('listOperations', () => {
1955
1958
  })
1956
1959
 
1957
1960
  it('Case 9: ETH transfer through smart contract', async () => {
1958
- const testContext = ctxWithExplorer({ type: 'ledger' })
1961
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
1959
1962
  const sharedTxHash = '0xcase9'
1960
1963
  mockGetOperations(
1961
1964
  {
@@ -2014,7 +2017,7 @@ describe('listOperations', () => {
2014
2017
  })
2015
2018
 
2016
2019
  it('Case 10: mixed assets smart contract interaction', async () => {
2017
- const testContext = ctxWithExplorer({ type: 'ledger' })
2020
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2018
2021
  const sharedTxHash = '0xcase10'
2019
2022
  mockGetOperations(
2020
2023
  {
@@ -2084,7 +2087,7 @@ describe('listOperations', () => {
2084
2087
  })
2085
2088
 
2086
2089
  it('Case 11: Spoofed token transfer through smart contract', async () => {
2087
- const testContext = ctxWithExplorer({ type: 'ledger' })
2090
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2088
2091
  const sharedTxHash = '0xcase11'
2089
2092
  mockGetOperations(
2090
2093
  {
@@ -2163,7 +2166,7 @@ describe('listOperations', () => {
2163
2166
  })
2164
2167
 
2165
2168
  it('Case: root trace internal tx is deduplicated against parent coin op (Blockscout bug)', async () => {
2166
- const testContext = ctxWithExplorer({ type: 'ledger' })
2169
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2167
2170
  const sharedTxHash = '0xRootTraceBug'
2168
2171
  // Blockscout returns the top-level call as an internal tx with from=EOA.
2169
2172
  // Regular tx: user → router, value=6 (in txlist)
@@ -2213,7 +2216,7 @@ describe('listOperations', () => {
2213
2216
  })
2214
2217
 
2215
2218
  it('Case: root trace dedup is sender-based, filters even when internal value differs', async () => {
2216
- const testContext = ctxWithExplorer({ type: 'ledger' })
2219
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2217
2220
  const sharedTxHash = '0xRootTraceDiffValue'
2218
2221
  // Variant where the internal root trace has a different value than the coin op.
2219
2222
  // The filter is purely sender-based (not value-based), so it still deduplicates.
@@ -2258,7 +2261,7 @@ describe('listOperations', () => {
2258
2261
  })
2259
2262
 
2260
2263
  it('Case: incoming root trace internal tx is deduplicated against parent operation', async () => {
2261
- const testContext = ctxWithExplorer({ type: 'ledger' })
2264
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2262
2265
  const sharedTxHash = '0xIncomingRootTrace'
2263
2266
  mockGetOperations(
2264
2267
  {
@@ -2290,7 +2293,7 @@ describe('listOperations', () => {
2290
2293
  })
2291
2294
 
2292
2295
  it('Case: incoming internal tx with different value is NOT filtered', async () => {
2293
- const testContext = ctxWithExplorer({ type: 'ledger' })
2296
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2294
2297
  const sharedTxHash = '0xIncomingDiffValue'
2295
2298
  mockGetOperations(
2296
2299
  {
@@ -2324,7 +2327,7 @@ describe('listOperations', () => {
2324
2327
  })
2325
2328
 
2326
2329
  it('Case: incoming internal tx with same value but different sender is NOT filtered', async () => {
2327
- const testContext = ctxWithExplorer({ type: 'ledger' })
2330
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2328
2331
  const sharedTxHash = '0xIncomingSameValueDiffSender'
2329
2332
  mockGetOperations(
2330
2333
  {
@@ -2358,7 +2361,7 @@ describe('listOperations', () => {
2358
2361
  })
2359
2362
 
2360
2363
  it('Case: legitimate internal tx is NOT filtered when parent sender differs (smart contract wallet)', async () => {
2361
- const testContext = ctxWithExplorer({ type: 'ledger' })
2364
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2362
2365
  const sharedTxHash = '0xSCWCase'
2363
2366
  // A relayer sends a tx to the wallet (coin op), then the wallet makes a sub-call (internal tx).
2364
2367
  // The internal tx sender (wallet) matches the queried address, but the parent sender (relayer) differs.
@@ -2403,7 +2406,7 @@ describe('listOperations', () => {
2403
2406
  })
2404
2407
 
2405
2408
  it('Case 12: Smart contract token minting', async () => {
2406
- const testContext = ctxWithExplorer({ type: 'ledger' })
2409
+ const testContext = ctxWithExplorer(mkLedgerExplorer())
2407
2410
  const sharedTxHash = '0xcase12'
2408
2411
  const zeroAddress = '0x0000000000000000000000000000000000000000'
2409
2412
  mockGetOperations(