@ledgerhq/coin-evm 16.8.1 → 17.1.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 (101) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/lib/adapters/etherscan.d.ts.map +1 -1
  3. package/lib/adapters/etherscan.js +5 -0
  4. package/lib/adapters/etherscan.js.map +1 -1
  5. package/lib/adapters/ledger.d.ts.map +1 -1
  6. package/lib/adapters/ledger.js +1 -0
  7. package/lib/adapters/ledger.js.map +1 -1
  8. package/lib/api/index.d.ts +2 -5
  9. package/lib/api/index.d.ts.map +1 -1
  10. package/lib/api/index.js +1 -2
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/logic/cip64Fees.d.ts +25 -3
  13. package/lib/logic/cip64Fees.d.ts.map +1 -1
  14. package/lib/logic/cip64Fees.js +78 -24
  15. package/lib/logic/cip64Fees.js.map +1 -1
  16. package/lib/logic/feeCollectorOperations.d.ts +3 -3
  17. package/lib/logic/feeCollectorOperations.js +3 -3
  18. package/lib/logic/getBlock.d.ts +2 -2
  19. package/lib/logic/getBlock.d.ts.map +1 -1
  20. package/lib/logic/getBlock.js +5 -11
  21. package/lib/logic/getBlock.js.map +1 -1
  22. package/lib/logic/listOperations.d.ts.map +1 -1
  23. package/lib/logic/listOperations.js +21 -3
  24. package/lib/logic/listOperations.js.map +1 -1
  25. package/lib/logic/tokenFeeOperations.d.ts +61 -0
  26. package/lib/logic/tokenFeeOperations.d.ts.map +1 -0
  27. package/lib/logic/tokenFeeOperations.js +128 -0
  28. package/lib/logic/tokenFeeOperations.js.map +1 -0
  29. package/lib/network/node/rpc.common.d.ts.map +1 -1
  30. package/lib/network/node/rpc.common.js +18 -0
  31. package/lib/network/node/rpc.common.js.map +1 -1
  32. package/lib/network/node/types.d.ts +2 -0
  33. package/lib/network/node/types.d.ts.map +1 -1
  34. package/lib/network/node/types.js.map +1 -1
  35. package/lib/network/node/withNodeSources.d.ts.map +1 -1
  36. package/lib/network/node/withNodeSources.js +2 -0
  37. package/lib/network/node/withNodeSources.js.map +1 -1
  38. package/lib-es/adapters/etherscan.d.ts.map +1 -1
  39. package/lib-es/adapters/etherscan.js +5 -0
  40. package/lib-es/adapters/etherscan.js.map +1 -1
  41. package/lib-es/adapters/ledger.d.ts.map +1 -1
  42. package/lib-es/adapters/ledger.js +1 -0
  43. package/lib-es/adapters/ledger.js.map +1 -1
  44. package/lib-es/api/index.d.ts +2 -5
  45. package/lib-es/api/index.d.ts.map +1 -1
  46. package/lib-es/api/index.js +1 -2
  47. package/lib-es/api/index.js.map +1 -1
  48. package/lib-es/logic/cip64Fees.d.ts +25 -3
  49. package/lib-es/logic/cip64Fees.d.ts.map +1 -1
  50. package/lib-es/logic/cip64Fees.js +77 -24
  51. package/lib-es/logic/cip64Fees.js.map +1 -1
  52. package/lib-es/logic/feeCollectorOperations.d.ts +3 -3
  53. package/lib-es/logic/feeCollectorOperations.js +3 -3
  54. package/lib-es/logic/getBlock.d.ts +2 -2
  55. package/lib-es/logic/getBlock.d.ts.map +1 -1
  56. package/lib-es/logic/getBlock.js +5 -11
  57. package/lib-es/logic/getBlock.js.map +1 -1
  58. package/lib-es/logic/listOperations.d.ts.map +1 -1
  59. package/lib-es/logic/listOperations.js +21 -3
  60. package/lib-es/logic/listOperations.js.map +1 -1
  61. package/lib-es/logic/tokenFeeOperations.d.ts +61 -0
  62. package/lib-es/logic/tokenFeeOperations.d.ts.map +1 -0
  63. package/lib-es/logic/tokenFeeOperations.js +122 -0
  64. package/lib-es/logic/tokenFeeOperations.js.map +1 -0
  65. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  66. package/lib-es/network/node/rpc.common.js +18 -0
  67. package/lib-es/network/node/rpc.common.js.map +1 -1
  68. package/lib-es/network/node/types.d.ts +2 -0
  69. package/lib-es/network/node/types.d.ts.map +1 -1
  70. package/lib-es/network/node/types.js.map +1 -1
  71. package/lib-es/network/node/withNodeSources.d.ts.map +1 -1
  72. package/lib-es/network/node/withNodeSources.js +2 -0
  73. package/lib-es/network/node/withNodeSources.js.map +1 -1
  74. package/package.json +2 -2
  75. package/src/adapters/blockscoutV2.test.ts +2 -0
  76. package/src/adapters/etherscan.test.ts +21 -0
  77. package/src/adapters/etherscan.ts +5 -0
  78. package/src/adapters/ledger.test.ts +8 -0
  79. package/src/adapters/ledger.ts +1 -0
  80. package/src/api/index.ts +1 -4
  81. package/src/api/tests/index.celo.integ.test.ts +144 -3
  82. package/src/api/tests/index.optimism.integ.test.ts +1 -0
  83. package/src/api/tests/index.test.ts +0 -9
  84. package/src/logic/cip64Fees.ts +99 -26
  85. package/src/logic/feeCollectorOperations.ts +3 -3
  86. package/src/logic/getBlock.ts +6 -17
  87. package/src/logic/listOperations.ts +32 -2
  88. package/src/logic/tests/cip64Fees.test.ts +128 -4
  89. package/src/logic/tests/getBlock.test.ts +10 -23
  90. package/src/logic/tests/listOperations.test.ts +522 -2
  91. package/src/logic/tests/validateIntent.test.ts +4 -0
  92. package/src/logic/tokenFeeOperations.ts +169 -0
  93. package/src/network/node/rpc.common.ts +19 -0
  94. package/src/network/node/types.ts +2 -0
  95. package/src/network/node/withNodeSources.ts +3 -0
  96. package/src/network/tests/explorer/etherscan.test.ts +1 -0
  97. package/src/network/tests/explorer/ledger.test.ts +4 -0
  98. package/src/network/tests/node/rpc.test.ts +36 -0
  99. package/src/network/tests/node/withNodeSources.test.ts +17 -0
  100. package/src/staking/rewardsFromReceipt.test.ts +1 -0
  101. package/src/staking/validators/monad.test.ts +1 -0
@@ -3,12 +3,15 @@
3
3
 
4
4
  import type { EvmConfig, EvmContext } from '../../config'
5
5
  import type { ExplorerApi } from '../../network/explorer/types'
6
+ import type { ERC20Transfer } from '../../network/node/types'
6
7
  import type { LedgerExplorerOperation } from '../../types'
7
8
  import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
8
9
  import type { AxiosRequestConfig } from 'axios'
9
10
  import { InvalidParameterError } from '@ledgerhq/coin-module-framework/errors'
10
11
  import axios from 'axios'
11
12
  import BigNumber from 'bignumber.js'
13
+ import { CHAIN_ID } from '../../config'
14
+ import { UnexpectedFeeLogsError, UnsupportedFeeCurrencyError } from '../../errors'
12
15
  import {
13
16
  createMockEvmContext,
14
17
  mkEtherscanExplorer,
@@ -20,6 +23,7 @@ import { getNodeApi } from '../../network/node'
20
23
  import { mockNodeApi } from '../../network/tests/node/node.fixtures'
21
24
  import { readReceiptTransfers } from '../feeCollectorOperations'
22
25
  import { listOperations } from '../listOperations'
26
+ import { fetchCeloTransactionFee } from '../tokenFeeOperations'
23
27
 
24
28
  jest.mock('../../network/node')
25
29
 
@@ -70,6 +74,7 @@ describe('listOperations', () => {
70
74
  hash: 'coin-op-1-tx-hash',
71
75
  block: { height: 10, hash: 'coin-op-1-block-hash', time: new Date('2025-02-12') },
72
76
  fees: 20n,
77
+ feesAsset: { type: 'native' },
73
78
  feesPayer: 'address1',
74
79
  date: new Date('2025-02-12'),
75
80
  failed: false,
@@ -87,6 +92,7 @@ describe('listOperations', () => {
87
92
  hash: 'coin-op-2-tx-hash',
88
93
  block: { height: 20, hash: 'coin-op-2-block-hash', time: new Date('2025-02-20') },
89
94
  fees: 20n,
95
+ feesAsset: { type: 'native' },
90
96
  feesPayer: 'address',
91
97
  date: new Date('2025-02-20'),
92
98
  failed: true,
@@ -104,6 +110,7 @@ describe('listOperations', () => {
104
110
  hash: 'token-op-1-tx-hash',
105
111
  block: { height: 20, hash: 'coin-op-2-block-hash', time: new Date('2025-02-20') },
106
112
  fees: 20n,
113
+ feesAsset: { type: 'native' },
107
114
  feesPayer: 'address',
108
115
  date: new Date('2025-02-20'),
109
116
  failed: false,
@@ -121,6 +128,7 @@ describe('listOperations', () => {
121
128
  hash: 'token-op-2-tx-hash',
122
129
  block: { height: 20, hash: 'coin-op-2-block-hash', time: new Date('2025-02-20') },
123
130
  fees: 20n,
131
+ feesAsset: { type: 'native' },
124
132
  feesPayer: 'address1',
125
133
  date: new Date('2025-02-20'),
126
134
  failed: false,
@@ -138,6 +146,7 @@ describe('listOperations', () => {
138
146
  hash: 'token-op-3-tx-hash',
139
147
  block: { height: 20, hash: 'coin-op-3-block-hash', time: new Date('2025-02-20') },
140
148
  fees: 20n,
149
+ feesAsset: { type: 'native' },
141
150
  feesPayer: 'address',
142
151
  date: new Date('2025-02-20'),
143
152
  failed: true,
@@ -155,6 +164,7 @@ describe('listOperations', () => {
155
164
  hash: 'coin-op-6-tx-hash',
156
165
  block: { height: 20, hash: 'coin-op-6-block-hash', time: new Date('2025-02-20') },
157
166
  fees: 15n,
167
+ feesAsset: { type: 'native' },
158
168
  feesPayer: 'contract-address',
159
169
  date: new Date('2025-02-20'),
160
170
  failed: false,
@@ -178,6 +188,7 @@ describe('listOperations', () => {
178
188
  hash: 'token-op-1-tx-hash',
179
189
  block: { height: 20, hash: 'token-op-1-block-hash', time: new Date('2025-02-20') },
180
190
  fees: 20n,
191
+ feesAsset: { type: 'native' },
181
192
  date: new Date('2025-02-20'),
182
193
  failed: false,
183
194
  },
@@ -204,6 +215,7 @@ describe('listOperations', () => {
204
215
  hash: 'token-op-2-tx-hash',
205
216
  block: { height: 20, hash: 'token-op-2-block-hash', time: new Date('2025-02-20') },
206
217
  fees: 20n,
218
+ feesAsset: { type: 'native' },
207
219
  date: new Date('2025-02-20'),
208
220
  failed: false,
209
221
  },
@@ -230,6 +242,7 @@ describe('listOperations', () => {
230
242
  hash: 'token-op-3-tx-hash',
231
243
  block: { height: 20, hash: 'token-op-3-block-hash', time: new Date('2025-02-20') },
232
244
  fees: 20n,
245
+ feesAsset: { type: 'native' },
233
246
  date: new Date('2025-02-20'),
234
247
  failed: false,
235
248
  },
@@ -257,6 +270,7 @@ describe('listOperations', () => {
257
270
  hash: 'token-op-3-tx-hash',
258
271
  block: { height: 20, hash: 'token-op-3-block-hash', time: new Date('2025-02-20') },
259
272
  fees: 0n,
273
+ feesAsset: { type: 'native' },
260
274
  date: new Date('2025-02-20'),
261
275
  failed: false,
262
276
  },
@@ -275,6 +289,7 @@ describe('listOperations', () => {
275
289
  hash: 'coin-op-6-tx-hash',
276
290
  block: { height: 20, hash: 'token-op-3-block-hash', time: new Date('2025-02-20') },
277
291
  fees: 0n,
292
+ feesAsset: { type: 'native' },
278
293
  date: new Date('2025-02-20'),
279
294
  failed: false,
280
295
  },
@@ -295,6 +310,7 @@ describe('listOperations', () => {
295
310
  hash: 'orphan-internal-tx-hash',
296
311
  block: { height: 25, hash: '', time: new Date('2025-02-25') },
297
312
  fees: 0n,
313
+ feesAsset: { type: 'native' },
298
314
  date: new Date('2025-02-25'),
299
315
  failed: false,
300
316
  },
@@ -345,6 +361,7 @@ describe('listOperations', () => {
345
361
  time: new Date('2025-02-12'),
346
362
  },
347
363
  fees: 20n,
364
+ feesAsset: { type: 'native' },
348
365
  feesPayer: 'address1', // feesPayer is always the sender of the native operation
349
366
  date: new Date('2025-02-12'),
350
367
  failed: false,
@@ -366,6 +383,7 @@ describe('listOperations', () => {
366
383
  time: new Date('2025-02-20'),
367
384
  },
368
385
  fees: 20n,
386
+ feesAsset: { type: 'native' },
369
387
  feesPayer: 'address', // feesPayer is always the sender of the native operation
370
388
  date: new Date('2025-02-20'),
371
389
  failed: true,
@@ -387,6 +405,7 @@ describe('listOperations', () => {
387
405
  time: new Date('2025-02-20'),
388
406
  },
389
407
  fees: 15n,
408
+ feesAsset: { type: 'native' },
390
409
  feesPayer: 'contract-address', // feesPayer is always the sender of the native operation
391
410
  date: new Date('2025-02-20'),
392
411
  failed: false,
@@ -408,6 +427,7 @@ describe('listOperations', () => {
408
427
  time: new Date('2025-02-20'),
409
428
  },
410
429
  fees: 20n,
430
+ feesAsset: { type: 'native' },
411
431
  feesPayer: 'address', // feesPayer is the parent sender of the token operation
412
432
  date: new Date('2025-02-20'),
413
433
  failed: false,
@@ -442,6 +462,7 @@ describe('listOperations', () => {
442
462
  },
443
463
  date: new Date('2025-02-20'),
444
464
  fees: 20n,
465
+ feesAsset: { type: 'native' },
445
466
  feesPayer: 'address1', // feesPayer is the parent sender of the token operation
446
467
  failed: false,
447
468
  },
@@ -470,6 +491,7 @@ describe('listOperations', () => {
470
491
  time: new Date('2025-02-20'),
471
492
  },
472
493
  fees: 20n,
494
+ feesAsset: { type: 'native' },
473
495
  feesPayer: 'address', // feesPayer is the parent sender of the token operation
474
496
  date: new Date('2025-02-20'),
475
497
  failed: true,
@@ -501,6 +523,7 @@ describe('listOperations', () => {
501
523
  date: new Date('2025-02-20'),
502
524
  failed: false,
503
525
  fees: 20n, // from parent coin-op-5
526
+ feesAsset: { type: 'native' },
504
527
  feesPayer: 'address', // feesPayer is the parent sender of the internal operation
505
528
  hash: 'token-op-3-tx-hash',
506
529
  },
@@ -526,6 +549,7 @@ describe('listOperations', () => {
526
549
  date: new Date('2025-02-20'),
527
550
  failed: false,
528
551
  fees: 15n, // from parent coin-op-6 (internal-op-2 has fee=0)
552
+ feesAsset: { type: 'native' },
529
553
  feesPayer: 'contract-address', // feesPayer is the parent sender of the internal operation
530
554
  hash: 'coin-op-6-tx-hash',
531
555
  },
@@ -552,6 +576,7 @@ describe('listOperations', () => {
552
576
  date: new Date('2025-02-25'),
553
577
  failed: false,
554
578
  fees: 0n,
579
+ feesAsset: { type: 'native' },
555
580
  // no feesPayer for orphan internal operation
556
581
  hash: 'orphan-internal-tx-hash',
557
582
  },
@@ -597,6 +622,7 @@ describe('listOperations', () => {
597
622
  hash: '0xTxForAddress',
598
623
  block: { height: 100, hash: '0xBlockHash', time: new Date('2025-02-20') },
599
624
  fees: 10n,
625
+ feesAsset: { type: 'native' },
600
626
  feesPayer: address.toUpperCase(),
601
627
  date: new Date('2025-02-20'),
602
628
  failed: false,
@@ -614,6 +640,7 @@ describe('listOperations', () => {
614
640
  hash: '0xTxUnrelated',
615
641
  block: { height: 101, hash: '0xBlockHash2', time: new Date('2025-02-20') },
616
642
  fees: 10n,
643
+ feesAsset: { type: 'native' },
617
644
  feesPayer: '0xOtherA',
618
645
  date: new Date('2025-02-20'),
619
646
  failed: false,
@@ -635,6 +662,7 @@ describe('listOperations', () => {
635
662
  hash: '0xTxUnrelated',
636
663
  block: { height: 101, hash: '0xBlockHash2', time: new Date('2025-02-20') },
637
664
  fees: 0n,
665
+ feesAsset: { type: 'native' },
638
666
  date: new Date('2025-02-20'),
639
667
  failed: false,
640
668
  },
@@ -666,6 +694,7 @@ describe('listOperations', () => {
666
694
  time: new Date('2025-02-20'),
667
695
  },
668
696
  fees: 10n,
697
+ feesAsset: { type: 'native' },
669
698
  feesPayer: 'ADDRESS',
670
699
  date: new Date('2025-02-20'),
671
700
  failed: false,
@@ -700,6 +729,7 @@ describe('listOperations', () => {
700
729
  time: new Date('2025-02-20'),
701
730
  },
702
731
  fees: txFee,
732
+ feesAsset: { type: 'native' },
703
733
  feesPayer: 'address1',
704
734
  date: new Date('2025-02-20'),
705
735
  failed: false,
@@ -723,6 +753,7 @@ describe('listOperations', () => {
723
753
  time: new Date('2025-02-20'),
724
754
  },
725
755
  fees: txFee,
756
+ feesAsset: { type: 'native' },
726
757
  date: new Date('2025-02-20'),
727
758
  failed: false,
728
759
  },
@@ -762,6 +793,7 @@ describe('listOperations', () => {
762
793
  time: new Date('2025-02-20'),
763
794
  },
764
795
  fees: 21000000000000n,
796
+ feesAsset: { type: 'native' },
765
797
  feesPayer: 'address1',
766
798
  date: new Date('2025-02-20'),
767
799
  failed: false,
@@ -800,6 +832,7 @@ describe('listOperations', () => {
800
832
  hash: '0xOtherTxHash',
801
833
  block: { height: 100, hash: '0xBlockHash', time: new Date('2025-02-20') },
802
834
  fees: 1n,
835
+ feesAsset: { type: 'native' },
803
836
  feesPayer: recipient,
804
837
  date: new Date('2025-02-20'),
805
838
  failed: false,
@@ -819,6 +852,7 @@ describe('listOperations', () => {
819
852
  hash: txHash,
820
853
  block: { height: 101, hash: '0xBlockHash2', time: new Date('2025-02-20') },
821
854
  fees: 0n,
855
+ feesAsset: { type: 'native' },
822
856
  date: new Date('2025-02-20'),
823
857
  failed: false,
824
858
  },
@@ -872,6 +906,7 @@ describe('listOperations', () => {
872
906
  hash: txHash,
873
907
  block,
874
908
  fees: parentFee,
909
+ feesAsset: { type: 'native' },
875
910
  feesPayer: address,
876
911
  date: new Date('2023-06-10T08:56:43.000Z'),
877
912
  failed: false,
@@ -893,6 +928,7 @@ describe('listOperations', () => {
893
928
  hash: txHash,
894
929
  block,
895
930
  fees: wrongTokenFee,
931
+ feesAsset: { type: 'native' },
896
932
  date: new Date('2023-06-10T08:56:43.000Z'),
897
933
  failed: false,
898
934
  },
@@ -948,6 +984,7 @@ describe('listOperations', () => {
948
984
  hash: txHash,
949
985
  block: { height: 24886171, hash: parentBlockHash, time: date },
950
986
  fees: 997504000000000n,
987
+ feesAsset: { type: 'native' },
951
988
  feesPayer: address,
952
989
  date,
953
990
  failed: false,
@@ -971,6 +1008,7 @@ describe('listOperations', () => {
971
1008
  hash: txHash,
972
1009
  block: { height: 24886171, hash: '', time: date },
973
1010
  fees: 0n,
1011
+ feesAsset: { type: 'native' },
974
1012
  date,
975
1013
  failed: false,
976
1014
  },
@@ -1004,7 +1042,14 @@ describe('listOperations', () => {
1004
1042
  const address = '0xb69b37a4fb4a18b3258f974ff6e9f529ad2647b1'
1005
1043
  const txHash = '0xf034ecf17ad61bc29bab12fc303296428d6c7c8a285bd92b2e30a92b1dd5f3bc'
1006
1044
  const block = { height: 25745506, hash: '0xblock', time: new Date('2026-08-13T10:29:00.000Z') }
1007
- const tx = { hash: txHash, block, fees: 41826029222736n, date: block.time, failed: false }
1045
+ const tx = {
1046
+ hash: txHash,
1047
+ block,
1048
+ fees: 41826029222736n,
1049
+ feesAsset: { type: 'native' as const },
1050
+ date: block.time,
1051
+ failed: false,
1052
+ }
1008
1053
 
1009
1054
  jest.spyOn(ledgerExplorer, 'getOperations').mockResolvedValue({
1010
1055
  lastCoinOperations: [
@@ -1067,6 +1112,7 @@ describe('listOperations', () => {
1067
1112
  hash: '0xMixedTransactionHash',
1068
1113
  block: { height: 100, hash: '0xBlockHash', time: new Date('2025-02-20') },
1069
1114
  fees: 21000000000000n,
1115
+ feesAsset: { type: 'native' },
1070
1116
  feesPayer: 'address1',
1071
1117
  date: new Date('2025-02-20'),
1072
1118
  failed: false,
@@ -1090,6 +1136,7 @@ describe('listOperations', () => {
1090
1136
  hash: '0xMixedTransactionHash',
1091
1137
  block: { height: 100, hash: '0xBlockHash', time: new Date('2025-02-20') },
1092
1138
  fees: 21000000000000n,
1139
+ feesAsset: { type: 'native' },
1093
1140
  date: new Date('2025-02-20'),
1094
1141
  failed: false,
1095
1142
  },
@@ -1129,6 +1176,7 @@ describe('listOperations', () => {
1129
1176
  time: new Date('2025-02-20'),
1130
1177
  },
1131
1178
  fees: 21000000000000n,
1179
+ feesAsset: { type: 'native' },
1132
1180
  feesPayer: 'address1',
1133
1181
  date: new Date('2025-02-20'),
1134
1182
  failed: false,
@@ -1154,6 +1202,7 @@ describe('listOperations', () => {
1154
1202
  time: new Date('2025-02-20'),
1155
1203
  },
1156
1204
  fees: 21000000000000n,
1205
+ feesAsset: { type: 'native' },
1157
1206
  feesPayer: 'address1',
1158
1207
  date: new Date('2025-02-20'),
1159
1208
  failed: false,
@@ -1318,6 +1367,7 @@ describe('listOperations', () => {
1318
1367
  hash: 'coin-op-1-tx-hash',
1319
1368
  block: { height: 10, hash: 'coin-op-1-block-hash', time: new Date('2025-02-12') },
1320
1369
  fees: 20n,
1370
+ feesAsset: { type: 'native' as const },
1321
1371
  date: new Date('2025-02-12'),
1322
1372
  failed: false,
1323
1373
  }
@@ -1395,6 +1445,7 @@ describe('listOperations', () => {
1395
1445
  hash: '0xdelegate-tx',
1396
1446
  block: { height: 100, hash: '0xblock', time: new Date('2025-02-20') },
1397
1447
  fees: 1n,
1448
+ feesAsset: { type: 'native' },
1398
1449
  feesPayer: address,
1399
1450
  date: new Date('2025-02-20'),
1400
1451
  failed: false,
@@ -1435,6 +1486,7 @@ describe('listOperations', () => {
1435
1486
  hash: '0xreward-tx',
1436
1487
  block: { height: 100, hash: '0xblock', time: new Date('2025-02-20') },
1437
1488
  fees: 1n,
1489
+ feesAsset: { type: 'native' },
1438
1490
  feesPayer: address,
1439
1491
  date: new Date('2025-02-20'),
1440
1492
  failed: false,
@@ -1473,6 +1525,7 @@ describe('listOperations', () => {
1473
1525
  hash: '0xsci-hash',
1474
1526
  block: { height: 10, hash: '0xblock', time: new Date('2025-02-20') },
1475
1527
  fees: 1n,
1528
+ feesAsset: { type: 'native' },
1476
1529
  feesPayer: 'address',
1477
1530
  date: new Date('2025-02-20'),
1478
1531
  failed: false,
@@ -1539,6 +1592,13 @@ describe('listOperations', () => {
1539
1592
  id?: string
1540
1593
  hash?: string
1541
1594
  }>
1595
+ lastNftOperations?: Array<{
1596
+ type: string
1597
+ senders: string[]
1598
+ recipients: string[]
1599
+ contract: string
1600
+ fee: number | string
1601
+ }>
1542
1602
  },
1543
1603
  sharedHash?: string
1544
1604
  ) {
@@ -1576,6 +1636,7 @@ describe('listOperations', () => {
1576
1636
  hash: op.hash ?? operationTxHash,
1577
1637
  block: { height: blockHeight, hash: blockHash, time: date },
1578
1638
  fees: toBigInt(op.fee),
1639
+ feesAsset: { type: 'native' },
1579
1640
  ...(op.senders.length === 1 ? { feesPayer: op.senders[0] } : {}),
1580
1641
  date,
1581
1642
  failed: false,
@@ -1599,6 +1660,7 @@ describe('listOperations', () => {
1599
1660
  hash: op.hash ?? operationTxHash,
1600
1661
  block: { height: blockHeight, hash: blockHash, time: date },
1601
1662
  fees: toBigInt(op.fee),
1663
+ feesAsset: { type: 'native' },
1602
1664
  date,
1603
1665
  failed: false,
1604
1666
  },
@@ -1623,15 +1685,35 @@ describe('listOperations', () => {
1623
1685
  hash: op.hash ?? operationTxHash,
1624
1686
  block: { height: blockHeight, hash: blockHash, time: date },
1625
1687
  fees: toBigInt(op.fee),
1688
+ feesAsset: { type: 'native' },
1626
1689
  date,
1627
1690
  failed: false,
1628
1691
  },
1629
1692
  details: { internal: true, sequence: BigNumber(1) },
1630
1693
  }))
1694
+ const nftOps: Array<Operation<MemoNotSupported>> = (response.lastNftOperations ?? []).map(
1695
+ (op, i) => ({
1696
+ id: `nft-op-${i}`,
1697
+ type: op.type,
1698
+ senders: op.senders,
1699
+ recipients: op.recipients,
1700
+ value: 1n,
1701
+ asset: { type: 'erc721', assetReference: op.contract, assetOwner: queriedAddress },
1702
+ tx: {
1703
+ hash: operationTxHash,
1704
+ block: { height: blockHeight, hash: blockHash, time: date },
1705
+ fees: toBigInt(op.fee),
1706
+ feesAsset: { type: 'native' },
1707
+ date,
1708
+ failed: false,
1709
+ },
1710
+ details: { sequence: BigNumber(1) },
1711
+ })
1712
+ )
1631
1713
  return {
1632
1714
  lastCoinOperations: coinOps,
1633
1715
  lastTokenOperations: tokenOps,
1634
- lastNftOperations: [],
1716
+ lastNftOperations: nftOps,
1635
1717
  lastInternalOperations: internalOps,
1636
1718
  nextPagingToken: '',
1637
1719
  }
@@ -3137,5 +3219,443 @@ describe('listOperations', () => {
3137
3219
  expect(items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
3138
3220
  })
3139
3221
  })
3222
+
3223
+ describe('Celo fee paid in a token', () => {
3224
+ const USDT = '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e'
3225
+ const USDT_ADAPTER = '0x0E2A3e05bc9A16F5292A6170456A710cb89C6f72'
3226
+ const HOLDER = '0x000000000000000000000000000000000Ce106A5'
3227
+ const SEQUENCER_VAULT = '0x4200000000000000000000000000000000000011'
3228
+ const FEE_HANDLER = '0xcD437749E43A154C07F3553504c68fBfD56B8778'
3229
+ const PAYER = '0x5362C723476b46a1e65D54E667C00e46b46F6f12'
3230
+ const OTHER = '0xfb4863FC2FE52A8131696e4a3a86676cff40A806'
3231
+ const HASH = '0xce1o'
3232
+ const UNSUPPORTED_FEE_CURRENCY = '0x857BF24e29da0773687E804a743c2E421a394C16'
3233
+ const NATIVE_FEE = 999
3234
+
3235
+ const celoContext: EvmContext = createMockEvmContext({
3236
+ chainId: CHAIN_ID.CELO,
3237
+ explorer: mkLedgerExplorer(),
3238
+ })
3239
+
3240
+ const transfer = (from: string, to: string, value: bigint): ERC20Transfer => ({
3241
+ asset: { type: 'erc20', assetReference: USDT },
3242
+ from,
3243
+ to,
3244
+ value: value.toString(),
3245
+ })
3246
+ const debit = transfer(PAYER, HOLDER, 4252n)
3247
+ const credits = [
3248
+ transfer(HOLDER, SEQUENCER_VAULT, 0n),
3249
+ transfer(HOLDER, FEE_HANDLER, 3176n),
3250
+ transfer(HOLDER, PAYER, 1076n),
3251
+ ]
3252
+ // The explorer rows of the fee logs that reach the payer: the debit and the refund
3253
+ const payerFeeRows = [
3254
+ {
3255
+ type: 'OUT',
3256
+ senders: [PAYER],
3257
+ recipients: [HOLDER],
3258
+ value: 4252,
3259
+ contract: USDT,
3260
+ fee: NATIVE_FEE,
3261
+ },
3262
+ {
3263
+ type: 'IN',
3264
+ senders: [HOLDER],
3265
+ recipients: [PAYER],
3266
+ value: 1076,
3267
+ contract: USDT,
3268
+ fee: NATIVE_FEE,
3269
+ },
3270
+ ]
3271
+ const tokenFee = {
3272
+ fees: 3176n,
3273
+ feesAsset: { type: 'erc20', assetReference: USDT },
3274
+ feesPayer: PAYER,
3275
+ }
3276
+
3277
+ const mockCeloNode = (
3278
+ userTransfers: ERC20Transfer[],
3279
+ feeCurrency: string | null = USDT_ADAPTER
3280
+ ): jest.Mocked<ReturnType<typeof getNodeApi>> => {
3281
+ const nodeApi = mockNodeApi({
3282
+ getTransaction: jest.fn().mockResolvedValue({
3283
+ hash: HASH,
3284
+ from: PAYER,
3285
+ type: 0x7b,
3286
+ erc20Transfers: [debit, ...userTransfers, ...credits],
3287
+ }),
3288
+ getFeeCurrency: jest.fn().mockResolvedValue(feeCurrency),
3289
+ })
3290
+ jest.mocked(getNodeApi).mockReturnValue(nodeApi)
3291
+ return nodeApi
3292
+ }
3293
+
3294
+ beforeEach(() => {
3295
+ fetchCeloTransactionFee.reset()
3296
+ })
3297
+
3298
+ it('reports the token fee of a token transfer and removes its fee rows', async () => {
3299
+ mockCeloNode([transfer(PAYER, OTHER, 5000n)])
3300
+ mockGetOperations(
3301
+ {
3302
+ lastCoinOperations: [
3303
+ { type: 'FEES', senders: [PAYER], recipients: [USDT], value: 0, fee: NATIVE_FEE },
3304
+ ],
3305
+ lastTokenOperations: [
3306
+ ...payerFeeRows,
3307
+ {
3308
+ type: 'OUT',
3309
+ senders: [PAYER],
3310
+ recipients: [OTHER],
3311
+ value: 5000,
3312
+ contract: USDT,
3313
+ fee: NATIVE_FEE,
3314
+ },
3315
+ ],
3316
+ },
3317
+ HASH
3318
+ )
3319
+
3320
+ const { items } = await listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3321
+
3322
+ expect(items).toEqual([
3323
+ expect.objectContaining({
3324
+ type: 'OUT',
3325
+ recipients: [OTHER],
3326
+ value: 5000n,
3327
+ asset: expect.objectContaining({ type: 'erc20', assetReference: USDT }),
3328
+ tx: expect.objectContaining(tokenFee),
3329
+ }),
3330
+ ])
3331
+ })
3332
+
3333
+ it('keeps the native operation as the carrier of a fee-only transaction', async () => {
3334
+ mockCeloNode([])
3335
+ mockGetOperations(
3336
+ {
3337
+ lastCoinOperations: [
3338
+ { type: 'FEES', senders: [PAYER], recipients: [USDT], value: 0, fee: NATIVE_FEE },
3339
+ ],
3340
+ lastTokenOperations: payerFeeRows,
3341
+ },
3342
+ HASH
3343
+ )
3344
+
3345
+ const { items } = await listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3346
+
3347
+ // listOperations reports a sender-only FEES row as OUT, whatever pays the fee
3348
+ expect(items).toEqual([
3349
+ expect.objectContaining({
3350
+ type: 'OUT',
3351
+ value: 0n,
3352
+ asset: { type: 'native' },
3353
+ tx: expect.objectContaining(tokenFee),
3354
+ }),
3355
+ ])
3356
+ })
3357
+
3358
+ it('keeps both native rows of a value-0 self-send, as for a native fee', async () => {
3359
+ mockCeloNode([])
3360
+ mockGetOperations(
3361
+ {
3362
+ lastCoinOperations: [
3363
+ {
3364
+ id: 'self-in',
3365
+ type: 'IN',
3366
+ senders: [PAYER],
3367
+ recipients: [PAYER],
3368
+ value: 0,
3369
+ fee: NATIVE_FEE,
3370
+ },
3371
+ {
3372
+ id: 'self-out',
3373
+ type: 'OUT',
3374
+ senders: [PAYER],
3375
+ recipients: [PAYER],
3376
+ value: 0,
3377
+ fee: NATIVE_FEE,
3378
+ },
3379
+ ],
3380
+ lastTokenOperations: payerFeeRows,
3381
+ },
3382
+ HASH
3383
+ )
3384
+
3385
+ const { items } = await listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3386
+
3387
+ expect(items).toEqual([
3388
+ expect.objectContaining({ type: 'IN', value: 0n, tx: expect.objectContaining(tokenFee) }),
3389
+ expect.objectContaining({
3390
+ type: 'OUT',
3391
+ value: 0n,
3392
+ tx: expect.objectContaining(tokenFee),
3393
+ }),
3394
+ ])
3395
+ })
3396
+
3397
+ it('removes as many identical rows as the receipt has fee transfers, whatever their casing', async () => {
3398
+ // The transaction itself sends the holder the same amount as the fee debit
3399
+ mockCeloNode([transfer(PAYER, HOLDER, 4252n)])
3400
+ const lowerCaseRow = {
3401
+ type: 'OUT',
3402
+ senders: [PAYER.toLowerCase()],
3403
+ recipients: [HOLDER.toLowerCase()],
3404
+ value: 4252,
3405
+ contract: USDT.toLowerCase(),
3406
+ fee: NATIVE_FEE,
3407
+ }
3408
+ mockGetOperations(
3409
+ {
3410
+ lastCoinOperations: [
3411
+ { type: 'FEES', senders: [PAYER], recipients: [USDT], value: 0, fee: NATIVE_FEE },
3412
+ ],
3413
+ lastTokenOperations: [lowerCaseRow, lowerCaseRow, payerFeeRows[1]],
3414
+ },
3415
+ HASH.toUpperCase()
3416
+ )
3417
+
3418
+ const { items } = await listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3419
+
3420
+ expect(items).toEqual([
3421
+ expect.objectContaining({
3422
+ value: 4252n,
3423
+ recipients: [HOLDER.toLowerCase()],
3424
+ tx: expect.objectContaining(tokenFee),
3425
+ }),
3426
+ ])
3427
+ })
3428
+
3429
+ it('gives the token fee to the NFT and internal operations of the transaction', async () => {
3430
+ mockCeloNode([])
3431
+ mockGetOperations(
3432
+ {
3433
+ lastTokenOperations: payerFeeRows,
3434
+ lastNftOperations: [
3435
+ {
3436
+ type: 'NFT_IN',
3437
+ senders: [PAYER],
3438
+ recipients: [OTHER],
3439
+ contract: '0xNft',
3440
+ fee: NATIVE_FEE,
3441
+ },
3442
+ ],
3443
+ lastInternalOperations: [
3444
+ { type: 'IN', senders: ['0xContract'], recipients: [OTHER], value: 3, fee: 0 },
3445
+ ],
3446
+ },
3447
+ HASH
3448
+ )
3449
+
3450
+ const { items } = await listOperations(celoContext, OTHER, { minHeight: 0, order: 'asc' })
3451
+
3452
+ expect(items).toHaveLength(2)
3453
+ expect(items).toEqual(
3454
+ expect.arrayContaining([
3455
+ expect.objectContaining({ type: 'NFT_IN', tx: expect.objectContaining(tokenFee) }),
3456
+ expect.objectContaining({
3457
+ type: 'IN',
3458
+ value: 3n,
3459
+ asset: { type: 'native' },
3460
+ tx: expect.objectContaining(tokenFee),
3461
+ }),
3462
+ ])
3463
+ )
3464
+ })
3465
+
3466
+ it('gives the token fee and its payer to a transfer the account received', async () => {
3467
+ mockCeloNode([transfer(PAYER, OTHER, 5000n)])
3468
+ mockGetOperations(
3469
+ {
3470
+ lastTokenOperations: [
3471
+ {
3472
+ type: 'OUT',
3473
+ senders: [PAYER],
3474
+ recipients: [OTHER],
3475
+ value: 5000,
3476
+ contract: USDT,
3477
+ fee: NATIVE_FEE,
3478
+ },
3479
+ ],
3480
+ },
3481
+ HASH
3482
+ )
3483
+
3484
+ const { items } = await listOperations(celoContext, OTHER, { minHeight: 0, order: 'asc' })
3485
+
3486
+ expect(items).toEqual([
3487
+ expect.objectContaining({
3488
+ type: 'IN',
3489
+ value: 5000n,
3490
+ tx: expect.objectContaining(tokenFee),
3491
+ }),
3492
+ ])
3493
+ })
3494
+
3495
+ it('keeps the native fee of a CIP-64 transaction that pays in the native coin', async () => {
3496
+ const nodeApi = mockNodeApi({
3497
+ getTransaction: jest
3498
+ .fn()
3499
+ .mockResolvedValue({ hash: HASH, from: PAYER, type: 0x7b, erc20Transfers: [] }),
3500
+ getFeeCurrency: jest.fn().mockResolvedValue(null),
3501
+ })
3502
+ jest.mocked(getNodeApi).mockReturnValue(nodeApi)
3503
+ mockGetOperations(
3504
+ {
3505
+ lastCoinOperations: [
3506
+ { type: 'OUT', senders: [PAYER], recipients: [OTHER], value: 7, fee: NATIVE_FEE },
3507
+ ],
3508
+ },
3509
+ HASH
3510
+ )
3511
+
3512
+ const { items } = await listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3513
+
3514
+ expect(items).toEqual([
3515
+ expect.objectContaining({
3516
+ value: 7n,
3517
+ tx: expect.objectContaining({ fees: 999n, feesAsset: { type: 'native' } }),
3518
+ }),
3519
+ ])
3520
+ expect(nodeApi.getFeeCurrency).toHaveBeenCalledWith(HASH)
3521
+ })
3522
+
3523
+ it('rejects a page where the account paid a fee in an unsupported currency', async () => {
3524
+ mockCeloNode([], UNSUPPORTED_FEE_CURRENCY)
3525
+ mockGetOperations(
3526
+ {
3527
+ lastCoinOperations: [
3528
+ { type: 'FEES', senders: [PAYER], recipients: [USDT], value: 0, fee: NATIVE_FEE },
3529
+ ],
3530
+ },
3531
+ HASH
3532
+ )
3533
+
3534
+ await expect(
3535
+ listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3536
+ ).rejects.toThrow(
3537
+ expect.objectContaining({
3538
+ name: UnsupportedFeeCurrencyError.name,
3539
+ hash: HASH,
3540
+ feeCurrency: UNSUPPORTED_FEE_CURRENCY,
3541
+ payer: PAYER,
3542
+ })
3543
+ )
3544
+ })
3545
+
3546
+ it('rejects an unsupported fee the node shows the account paid, without its native row', async () => {
3547
+ mockCeloNode([], UNSUPPORTED_FEE_CURRENCY)
3548
+ mockGetOperations(
3549
+ {
3550
+ lastTokenOperations: [
3551
+ {
3552
+ type: 'OUT',
3553
+ senders: [PAYER],
3554
+ recipients: [OTHER],
3555
+ value: 5000,
3556
+ contract: USDT,
3557
+ fee: NATIVE_FEE,
3558
+ },
3559
+ ],
3560
+ },
3561
+ HASH
3562
+ )
3563
+
3564
+ await expect(
3565
+ listOperations(celoContext, PAYER.toLowerCase(), { minHeight: 0, order: 'asc' })
3566
+ ).rejects.toThrow(UnsupportedFeeCurrencyError)
3567
+ })
3568
+
3569
+ it('keeps the explorer rows of a transaction another account paid in an unsupported currency', async () => {
3570
+ mockCeloNode([], UNSUPPORTED_FEE_CURRENCY)
3571
+ mockGetOperations(
3572
+ {
3573
+ lastCoinOperations: [
3574
+ { type: 'OUT', senders: [PAYER], recipients: [OTHER], value: 1, fee: NATIVE_FEE },
3575
+ ],
3576
+ },
3577
+ HASH
3578
+ )
3579
+
3580
+ const { items } = await listOperations(celoContext, OTHER, { minHeight: 0, order: 'asc' })
3581
+
3582
+ expect(items).toEqual([
3583
+ expect.objectContaining({
3584
+ type: 'IN',
3585
+ value: 1n,
3586
+ tx: expect.objectContaining({ fees: 999n, feesAsset: { type: 'native' } }),
3587
+ }),
3588
+ ])
3589
+ expect(celoContext.logger).toHaveBeenCalledWith(
3590
+ 'warn',
3591
+ expect.any(String),
3592
+ expect.objectContaining({ hash: HASH, feeCurrency: UNSUPPORTED_FEE_CURRENCY })
3593
+ )
3594
+ })
3595
+
3596
+ it('applies the payer rule per account to a cached unsupported fee', async () => {
3597
+ const nodeApi = mockCeloNode([], UNSUPPORTED_FEE_CURRENCY)
3598
+ mockGetOperations(
3599
+ {
3600
+ lastCoinOperations: [
3601
+ { type: 'OUT', senders: [PAYER], recipients: [OTHER], value: 1, fee: NATIVE_FEE },
3602
+ ],
3603
+ },
3604
+ HASH
3605
+ )
3606
+
3607
+ await expect(
3608
+ listOperations(celoContext, OTHER, { minHeight: 0, order: 'asc' })
3609
+ ).resolves.toBeDefined()
3610
+ await expect(
3611
+ listOperations(celoContext, PAYER, { minHeight: 0, order: 'asc' })
3612
+ ).rejects.toThrow(UnsupportedFeeCurrencyError)
3613
+ expect(nodeApi.getTransaction).toHaveBeenCalledTimes(1)
3614
+ })
3615
+
3616
+ it('rejects a page with fee logs that do not match a supported currency, whoever paid', async () => {
3617
+ jest.mocked(getNodeApi).mockReturnValue(
3618
+ mockNodeApi({
3619
+ getTransaction: jest
3620
+ .fn()
3621
+ .mockResolvedValue({ hash: HASH, from: PAYER, type: 0x7b, erc20Transfers: credits }),
3622
+ getFeeCurrency: jest.fn().mockResolvedValue(USDT_ADAPTER),
3623
+ })
3624
+ )
3625
+ mockGetOperations(
3626
+ {
3627
+ lastCoinOperations: [
3628
+ { type: 'OUT', senders: [PAYER], recipients: [OTHER], value: 1, fee: NATIVE_FEE },
3629
+ ],
3630
+ },
3631
+ HASH
3632
+ )
3633
+
3634
+ await expect(
3635
+ listOperations(celoContext, OTHER, { minHeight: 0, order: 'asc' })
3636
+ ).rejects.toThrow(UnexpectedFeeLogsError)
3637
+ })
3638
+
3639
+ it('reads no transaction on another network', async () => {
3640
+ const nodeApi = mockCeloNode([])
3641
+ mockGetOperations(
3642
+ {
3643
+ lastCoinOperations: [
3644
+ { type: 'FEES', senders: [PAYER], recipients: [USDT], value: 0, fee: NATIVE_FEE },
3645
+ ],
3646
+ lastTokenOperations: payerFeeRows,
3647
+ },
3648
+ HASH
3649
+ )
3650
+
3651
+ const { items } = await listOperations(ctxWithExplorer(mkLedgerExplorer()), PAYER, {
3652
+ minHeight: 0,
3653
+ order: 'asc',
3654
+ })
3655
+
3656
+ expect(nodeApi.getTransaction).not.toHaveBeenCalled()
3657
+ expect(items.every((op) => op.tx.feesAsset?.type === 'native')).toBe(true)
3658
+ })
3659
+ })
3140
3660
  })
3141
3661
  })