@ledgerhq/coin-evm 16.5.1 → 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 (73) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/chains.d.ts +0 -1
  3. package/lib/chains.d.ts.map +1 -1
  4. package/lib/chains.js +0 -1
  5. package/lib/chains.js.map +1 -1
  6. package/lib/config.d.ts +9 -0
  7. package/lib/config.d.ts.map +1 -1
  8. package/lib/config.js +4 -0
  9. package/lib/config.js.map +1 -1
  10. package/lib/errors.d.ts +15 -0
  11. package/lib/errors.d.ts.map +1 -1
  12. package/lib/errors.js +31 -1
  13. package/lib/errors.js.map +1 -1
  14. package/lib/logic/feeCollectorOperations.d.ts +61 -0
  15. package/lib/logic/feeCollectorOperations.d.ts.map +1 -0
  16. package/lib/logic/feeCollectorOperations.js +206 -0
  17. package/lib/logic/feeCollectorOperations.js.map +1 -0
  18. package/lib/logic/listOperations.d.ts.map +1 -1
  19. package/lib/logic/listOperations.js +4 -1
  20. package/lib/logic/listOperations.js.map +1 -1
  21. package/lib/network/node/rpc.common.d.ts.map +1 -1
  22. package/lib/network/node/rpc.common.js +84 -29
  23. package/lib/network/node/rpc.common.js.map +1 -1
  24. package/lib-es/chains.d.ts +0 -1
  25. package/lib-es/chains.d.ts.map +1 -1
  26. package/lib-es/chains.js +0 -1
  27. package/lib-es/chains.js.map +1 -1
  28. package/lib-es/config.d.ts +9 -0
  29. package/lib-es/config.d.ts.map +1 -1
  30. package/lib-es/config.js +4 -0
  31. package/lib-es/config.js.map +1 -1
  32. package/lib-es/errors.d.ts +15 -0
  33. package/lib-es/errors.d.ts.map +1 -1
  34. package/lib-es/errors.js +27 -0
  35. package/lib-es/errors.js.map +1 -1
  36. package/lib-es/logic/feeCollectorOperations.d.ts +61 -0
  37. package/lib-es/logic/feeCollectorOperations.d.ts.map +1 -0
  38. package/lib-es/logic/feeCollectorOperations.js +201 -0
  39. package/lib-es/logic/feeCollectorOperations.js.map +1 -0
  40. package/lib-es/logic/listOperations.d.ts.map +1 -1
  41. package/lib-es/logic/listOperations.js +4 -1
  42. package/lib-es/logic/listOperations.js.map +1 -1
  43. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  44. package/lib-es/network/node/rpc.common.js +85 -30
  45. package/lib-es/network/node/rpc.common.js.map +1 -1
  46. package/package.json +2 -2
  47. package/src/api/tests/getBlock.integ.test.ts +5 -102
  48. package/src/api/tests/index.alpen_testnet.integ.test.ts +2 -7
  49. package/src/api/tests/index.arbitrum.integ.test.ts +2 -12
  50. package/src/api/tests/index.arc.integ.test.ts +2 -13
  51. package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +2 -12
  52. package/src/api/tests/index.cronos.integ.test.ts +2 -12
  53. package/src/api/tests/index.flare.integ.test.ts +2 -8
  54. package/src/api/tests/index.integ.test.ts +5 -35
  55. package/src/api/tests/index.linea.integ.test.ts +2 -15
  56. package/src/api/tests/index.monad_testnet.integ.test.ts +5 -13
  57. package/src/api/tests/index.optimism.integ.test.ts +2 -12
  58. package/src/api/tests/index.rsk.integ.test.ts +2 -12
  59. package/src/api/tests/index.scroll.integ.test.ts +4 -7
  60. package/src/api/tests/index.shape.integ.test.ts +3 -27
  61. package/src/api/tests/index.somnia.integ.test.ts +2 -6
  62. package/src/api/tests/index.unichain.integ.test.ts +2 -12
  63. package/src/api/tests/index.zksync.integ.test.ts +5 -8
  64. package/src/chains.ts +0 -1
  65. package/src/config.ts +11 -0
  66. package/src/errors.ts +27 -0
  67. package/src/logic/feeCollectorOperations.ts +272 -0
  68. package/src/logic/listOperations.ts +20 -1
  69. package/src/logic/tests/broadcast.integ.test.ts +4 -15
  70. package/src/logic/tests/listOperations.test.ts +563 -0
  71. package/src/network/node/rpc.common.ts +128 -30
  72. package/src/network/tests/node/rpc.test.ts +81 -9
  73. package/src/staking/validators.integ.test.ts +5 -22
@@ -16,8 +16,13 @@ import {
16
16
  } from '../../fixtures/context.fixtures'
17
17
  import etherscanExplorer from '../../network/explorer/etherscan'
18
18
  import ledgerExplorer from '../../network/explorer/ledger'
19
+ import { getNodeApi } from '../../network/node'
20
+ import { mockNodeApi } from '../../network/tests/node/node.fixtures'
21
+ import { readReceiptTransfers } from '../feeCollectorOperations'
19
22
  import { listOperations } from '../listOperations'
20
23
 
24
+ jest.mock('../../network/node')
25
+
21
26
  describe('listOperations', () => {
22
27
  const address = 'address'
23
28
 
@@ -2574,5 +2579,563 @@ describe('listOperations', () => {
2574
2579
  tx: { fees: 1n, feesPayer: 'address1' },
2575
2580
  })
2576
2581
  })
2582
+
2583
+ describe('zkSync fee payer, from the fee prepayment to the bootloader', () => {
2584
+ const BOOTLOADER = '0x0000000000000000000000000000000000008001'
2585
+ const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
2586
+ const zkSyncContext = (
2587
+ feeCollectorContracts?: string[],
2588
+ feeCollectorTokens: string[] = [L2_BASE_TOKEN]
2589
+ ): EvmContext =>
2590
+ createMockEvmContext({
2591
+ explorer: mkLedgerExplorer(),
2592
+ ...(feeCollectorContracts !== undefined && { feeCollectorContracts, feeCollectorTokens }),
2593
+ })
2594
+
2595
+ beforeEach(() => {
2596
+ readReceiptTransfers.reset()
2597
+ })
2598
+
2599
+ // The receipt of the tx, for its ETH-token (0x800A) transfers
2600
+ const mockReceipt = (
2601
+ erc20Transfers: Array<{ from: string; to: string; value: string }>
2602
+ ): jest.Mocked<ReturnType<typeof getNodeApi>> => {
2603
+ const nodeApi = mockNodeApi({
2604
+ getTransaction: jest.fn().mockResolvedValue({
2605
+ erc20Transfers: erc20Transfers.map((transfer) => ({
2606
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
2607
+ ...transfer,
2608
+ })),
2609
+ }),
2610
+ })
2611
+ jest.mocked(getNodeApi).mockReturnValue(nodeApi)
2612
+ return nodeApi
2613
+ }
2614
+
2615
+ // tx 0x23f32c7199a6568f2c551cd0f1e29a10780a811128037efa7691cfc32cf4615d (height 72812813):
2616
+ // the paymaster prepays 49775000000000 to the bootloader and gets 42357348500000 back, for a
2617
+ // fee of 7417651500000; the sender moves no ETH.
2618
+ const SENDER = '0x1B4a3d0A5712362FA06CDD4930b9ca720Ed6db18'
2619
+ const PAYMASTER = '0xA2Aac7bC9725c36ad9B12D2407dF8de6B2B68359'
2620
+ const TOKEN = '0xBD4372e44c5eE654dd838304006E1f0f69983154'
2621
+ const FEE = 7417651500000
2622
+ // What the explorer returns for the paymaster: the tx is not in its txlist
2623
+ const paymasterHistory = {
2624
+ lastTokenOperations: [
2625
+ {
2626
+ type: 'IN',
2627
+ senders: [SENDER],
2628
+ recipients: [PAYMASTER],
2629
+ value: '625953755962972422822',
2630
+ contract: TOKEN,
2631
+ fee: FEE,
2632
+ },
2633
+ {
2634
+ type: 'OUT',
2635
+ senders: [PAYMASTER],
2636
+ recipients: [SENDER],
2637
+ value: '536579509637710163043',
2638
+ contract: TOKEN,
2639
+ fee: FEE,
2640
+ },
2641
+ {
2642
+ type: 'OUT',
2643
+ senders: [PAYMASTER],
2644
+ recipients: [BOOTLOADER],
2645
+ value: 49775000000000,
2646
+ contract: L2_BASE_TOKEN,
2647
+ fee: FEE,
2648
+ },
2649
+ {
2650
+ type: 'IN',
2651
+ senders: [BOOTLOADER],
2652
+ recipients: [PAYMASTER],
2653
+ value: 42357348500000,
2654
+ contract: L2_BASE_TOKEN,
2655
+ fee: FEE,
2656
+ },
2657
+ ],
2658
+ // Blockscout reports the prepayment, not the refund, and no fee for it
2659
+ lastInternalOperations: [
2660
+ {
2661
+ type: 'OUT',
2662
+ senders: [PAYMASTER],
2663
+ recipients: [BOOTLOADER],
2664
+ value: 49775000000000,
2665
+ fee: 0,
2666
+ },
2667
+ ],
2668
+ }
2669
+ // What the explorer returns for the sender: no transfer to the bootloader
2670
+ const senderHistory = {
2671
+ lastCoinOperations: [
2672
+ { type: 'FEES', senders: [SENDER], recipients: ['0xContract'], value: 0, fee: FEE },
2673
+ ],
2674
+ lastTokenOperations: [
2675
+ {
2676
+ type: 'OUT',
2677
+ senders: [SENDER],
2678
+ recipients: [PAYMASTER],
2679
+ value: '625953755962972422822',
2680
+ contract: TOKEN,
2681
+ fee: FEE,
2682
+ },
2683
+ {
2684
+ type: 'IN',
2685
+ senders: [PAYMASTER],
2686
+ recipients: [SENDER],
2687
+ value: '536579509637710163043',
2688
+ contract: TOKEN,
2689
+ fee: FEE,
2690
+ },
2691
+ ],
2692
+ }
2693
+
2694
+ it('charges the fee to the paymaster and drops its native prepayment', async () => {
2695
+ mockGetOperations(paymasterHistory)
2696
+
2697
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), PAYMASTER, {
2698
+ minHeight: 0,
2699
+ order: 'asc',
2700
+ })
2701
+
2702
+ expect(items.filter((op) => op.asset.type === 'native')).toEqual([])
2703
+ expect(items).toHaveLength(4)
2704
+ for (const op of items) {
2705
+ expect(op.tx).toMatchObject({ fees: BigInt(FEE), feesPayer: PAYMASTER })
2706
+ }
2707
+ })
2708
+
2709
+ it('does not charge the fee to the sender of a transaction a paymaster paid', async () => {
2710
+ mockGetOperations(senderHistory)
2711
+ const nodeApi = mockReceipt([
2712
+ { from: PAYMASTER, to: BOOTLOADER, value: '49775000000000' },
2713
+ { from: BOOTLOADER, to: PAYMASTER, value: '42357348500000' },
2714
+ ])
2715
+
2716
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), SENDER, {
2717
+ minHeight: 0,
2718
+ order: 'asc',
2719
+ })
2720
+
2721
+ expect(nodeApi.getTransaction).toHaveBeenCalledTimes(1)
2722
+ expect(items.length).toBeGreaterThan(0)
2723
+ for (const op of items) {
2724
+ expect(op.tx.feesPayer).toBeUndefined()
2725
+ }
2726
+ })
2727
+
2728
+ it('reads the receipt of a transaction once across syncs', async () => {
2729
+ mockGetOperations(senderHistory)
2730
+ const nodeApi = mockReceipt([{ from: PAYMASTER, to: BOOTLOADER, value: '49775000000000' }])
2731
+ const sync = () =>
2732
+ listOperations(zkSyncContext([BOOTLOADER]), SENDER, { minHeight: 0, order: 'asc' })
2733
+
2734
+ await sync()
2735
+ const { items } = await sync()
2736
+
2737
+ expect(nodeApi.getTransaction).toHaveBeenCalledTimes(1)
2738
+ expect(items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
2739
+ })
2740
+
2741
+ it('applies each network setting to a receipt read once', async () => {
2742
+ mockGetOperations(senderHistory)
2743
+ // The sender's base-token prepayment, in a receipt read with the base token listed or not
2744
+ const nodeApi = mockReceipt([{ from: SENDER, to: BOOTLOADER, value: '49775000000000' }])
2745
+ const sync = (feeCollectorTokens: string[]) =>
2746
+ listOperations(zkSyncContext([BOOTLOADER], feeCollectorTokens), SENDER, {
2747
+ minHeight: 0,
2748
+ order: 'asc',
2749
+ })
2750
+
2751
+ const unlisted = await sync([])
2752
+ const listed = await sync([L2_BASE_TOKEN])
2753
+
2754
+ expect(nodeApi.getTransaction).toHaveBeenCalledTimes(1)
2755
+ expect(unlisted.items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
2756
+ expect(listed.items.every((op) => op.tx.feesPayer === SENDER)).toBe(true)
2757
+ })
2758
+
2759
+ it('reads again a receipt that could not be read on the previous sync', async () => {
2760
+ mockGetOperations(senderHistory)
2761
+ const getTransaction = jest
2762
+ .fn()
2763
+ .mockRejectedValueOnce(new Error('rate limited'))
2764
+ .mockResolvedValue({
2765
+ erc20Transfers: [
2766
+ {
2767
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
2768
+ from: PAYMASTER,
2769
+ to: BOOTLOADER,
2770
+ value: '49775000000000',
2771
+ },
2772
+ ],
2773
+ })
2774
+ jest.mocked(getNodeApi).mockReturnValue(mockNodeApi({ getTransaction }))
2775
+ const sync = () =>
2776
+ listOperations(zkSyncContext([BOOTLOADER]), SENDER, { minHeight: 0, order: 'asc' })
2777
+
2778
+ const first = await sync()
2779
+ const second = await sync()
2780
+
2781
+ expect(getTransaction).toHaveBeenCalledTimes(2)
2782
+ expect(first.items.every((op) => op.tx.feesPayer === SENDER)).toBe(true)
2783
+ expect(second.items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
2784
+ })
2785
+
2786
+ it('does not take another token sent to the bootloader for the fee prepayment', async () => {
2787
+ // In a sponsored transaction, the sender also sends some USDC to the bootloader
2788
+ const USDC = '0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4'
2789
+ mockGetOperations({
2790
+ ...senderHistory,
2791
+ lastTokenOperations: [
2792
+ ...senderHistory.lastTokenOperations,
2793
+ {
2794
+ type: 'OUT',
2795
+ senders: [SENDER],
2796
+ recipients: [BOOTLOADER],
2797
+ value: 5,
2798
+ contract: USDC,
2799
+ fee: FEE,
2800
+ },
2801
+ ],
2802
+ })
2803
+ mockReceipt([{ from: PAYMASTER, to: BOOTLOADER, value: '49775000000000' }])
2804
+
2805
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), SENDER, {
2806
+ minHeight: 0,
2807
+ order: 'asc',
2808
+ })
2809
+
2810
+ expect(items.length).toBeGreaterThan(0)
2811
+ for (const op of items) {
2812
+ expect(op.tx.feesPayer).toBeUndefined()
2813
+ }
2814
+ })
2815
+
2816
+ it('takes a base-token transfer for the fee prepayment only on a network that lists it', async () => {
2817
+ // tx 0x1360…c00f: the sender prepays in the base token, and its history has no native leg
2818
+ const USER = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
2819
+ const history = {
2820
+ lastCoinOperations: [
2821
+ {
2822
+ type: 'FEES',
2823
+ senders: [USER],
2824
+ recipients: ['0xContract'],
2825
+ value: 0,
2826
+ fee: 101755500000000,
2827
+ },
2828
+ ],
2829
+ lastTokenOperations: [
2830
+ {
2831
+ type: 'OUT',
2832
+ senders: [USER],
2833
+ recipients: [BOOTLOADER],
2834
+ value: 189587750000000,
2835
+ contract: L2_BASE_TOKEN,
2836
+ fee: 101755500000000,
2837
+ },
2838
+ ],
2839
+ }
2840
+ const nodeApi = mockReceipt([])
2841
+
2842
+ mockGetOperations(history)
2843
+ const listed = await listOperations(zkSyncContext([BOOTLOADER]), USER, {
2844
+ minHeight: 0,
2845
+ order: 'asc',
2846
+ })
2847
+ mockGetOperations(history)
2848
+ const unlisted = await listOperations(zkSyncContext([BOOTLOADER], []), USER, {
2849
+ minHeight: 0,
2850
+ order: 'asc',
2851
+ })
2852
+
2853
+ expect(listed.items.every((op) => op.tx.feesPayer === USER)).toBe(true)
2854
+ expect(nodeApi.getTransaction).toHaveBeenCalledTimes(1)
2855
+ // Without the base token listed, the receipt (empty here) tells who paid: not the user
2856
+ expect(unlisted.items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
2857
+ })
2858
+
2859
+ it('does not take another token in the receipt for the fee prepayment', async () => {
2860
+ mockGetOperations(senderHistory)
2861
+ // The receipt shows a USDC transfer of the sender to the bootloader, and the paymaster's
2862
+ // base-token prepayment
2863
+ const nodeApi = mockNodeApi({
2864
+ getTransaction: jest.fn().mockResolvedValue({
2865
+ erc20Transfers: [
2866
+ {
2867
+ asset: {
2868
+ type: 'erc20',
2869
+ assetReference: '0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4',
2870
+ },
2871
+ from: SENDER,
2872
+ to: BOOTLOADER,
2873
+ value: '5',
2874
+ },
2875
+ {
2876
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
2877
+ from: PAYMASTER,
2878
+ to: BOOTLOADER,
2879
+ value: '49775000000000',
2880
+ },
2881
+ ],
2882
+ }),
2883
+ })
2884
+ jest.mocked(getNodeApi).mockReturnValue(nodeApi)
2885
+
2886
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), SENDER, {
2887
+ minHeight: 0,
2888
+ order: 'asc',
2889
+ })
2890
+
2891
+ for (const op of items) {
2892
+ expect(op.tx.feesPayer).toBeUndefined()
2893
+ }
2894
+ })
2895
+
2896
+ it('keeps the sender as the payer when the receipt shows its prepayment, missing from the page', async () => {
2897
+ mockGetOperations(senderHistory)
2898
+ mockReceipt([{ from: SENDER, to: BOOTLOADER, value: '49775000000000' }])
2899
+
2900
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), SENDER, {
2901
+ minHeight: 0,
2902
+ order: 'asc',
2903
+ })
2904
+
2905
+ for (const op of items) {
2906
+ expect(op.tx.feesPayer).toBe(SENDER)
2907
+ }
2908
+ })
2909
+
2910
+ it('keeps the sender as the payer when the receipt cannot be read', async () => {
2911
+ mockGetOperations(senderHistory)
2912
+ jest
2913
+ .mocked(getNodeApi)
2914
+ .mockReturnValue(
2915
+ mockNodeApi({ getTransaction: jest.fn().mockRejectedValue(new Error('node down')) })
2916
+ )
2917
+
2918
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), SENDER, {
2919
+ minHeight: 0,
2920
+ order: 'asc',
2921
+ })
2922
+
2923
+ for (const op of items) {
2924
+ expect(op.tx.feesPayer).toBe(SENDER)
2925
+ }
2926
+ })
2927
+
2928
+ it('keeps the sender as the payer when it prepays the fee', async () => {
2929
+ // tx 0x13600459c61346e7195861973c04158d1b8b86adde05028066ae16ec852ac00f (height 4419528)
2930
+ const USER = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
2931
+ mockGetOperations({
2932
+ lastCoinOperations: [
2933
+ {
2934
+ type: 'FEES',
2935
+ senders: [USER],
2936
+ recipients: ['0xContract'],
2937
+ value: 0,
2938
+ fee: 101755500000000,
2939
+ },
2940
+ ],
2941
+ lastTokenOperations: [
2942
+ {
2943
+ type: 'OUT',
2944
+ senders: [USER],
2945
+ recipients: [BOOTLOADER],
2946
+ value: 189587750000000,
2947
+ contract: L2_BASE_TOKEN,
2948
+ fee: 101755500000000,
2949
+ },
2950
+ {
2951
+ type: 'IN',
2952
+ senders: [BOOTLOADER],
2953
+ recipients: [USER],
2954
+ value: 87832250000000,
2955
+ contract: L2_BASE_TOKEN,
2956
+ fee: 101755500000000,
2957
+ },
2958
+ ],
2959
+ lastInternalOperations: [
2960
+ {
2961
+ type: 'OUT',
2962
+ senders: [USER],
2963
+ recipients: [BOOTLOADER],
2964
+ value: 189587750000000,
2965
+ fee: 0,
2966
+ },
2967
+ ],
2968
+ })
2969
+
2970
+ const nodeApi = mockReceipt([])
2971
+
2972
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), USER, {
2973
+ minHeight: 0,
2974
+ order: 'asc',
2975
+ })
2976
+
2977
+ expect(nodeApi.getTransaction).not.toHaveBeenCalled()
2978
+
2979
+ expect(items.filter((op) => op.asset.type === 'native')).toEqual([])
2980
+ expect(items).toHaveLength(2)
2981
+ for (const op of items) {
2982
+ expect(op.tx).toMatchObject({ fees: 101755500000000n, feesPayer: USER })
2983
+ }
2984
+ })
2985
+
2986
+ it('carries the fee of a paymaster whose only operation was its native prepayment', async () => {
2987
+ // A token row of the tx, without the account, gives the fee: gasUsed × gasPrice
2988
+ mockGetOperations({
2989
+ lastTokenOperations: [
2990
+ {
2991
+ type: 'OUT',
2992
+ senders: [SENDER],
2993
+ recipients: ['0xOther'],
2994
+ value: 1,
2995
+ contract: TOKEN,
2996
+ fee: FEE,
2997
+ },
2998
+ ],
2999
+ lastInternalOperations: [
3000
+ {
3001
+ type: 'OUT',
3002
+ senders: [PAYMASTER],
3003
+ recipients: [BOOTLOADER],
3004
+ value: 49775000000000,
3005
+ fee: 0,
3006
+ },
3007
+ ],
3008
+ })
3009
+
3010
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), PAYMASTER, {
3011
+ minHeight: 0,
3012
+ order: 'asc',
3013
+ })
3014
+
3015
+ expect(items).toEqual([
3016
+ expect.objectContaining({
3017
+ type: 'FEES',
3018
+ value: 0n,
3019
+ asset: { type: 'native' },
3020
+ tx: expect.objectContaining({ fees: BigInt(FEE), feesPayer: PAYMASTER }),
3021
+ }),
3022
+ ])
3023
+ })
3024
+
3025
+ it('keeps the native prepayment of a paymaster when nothing gives the fee', async () => {
3026
+ // Internal operations carry no fee: a carrier would charge 0
3027
+ mockGetOperations({
3028
+ lastInternalOperations: [
3029
+ {
3030
+ type: 'OUT',
3031
+ senders: [PAYMASTER],
3032
+ recipients: [BOOTLOADER],
3033
+ value: 49775000000000,
3034
+ fee: 0,
3035
+ },
3036
+ ],
3037
+ })
3038
+
3039
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), PAYMASTER, {
3040
+ minHeight: 0,
3041
+ order: 'asc',
3042
+ })
3043
+
3044
+ expect(items).toEqual([
3045
+ expect.objectContaining({ value: 49775000000000n, asset: { type: 'native' } }),
3046
+ ])
3047
+ })
3048
+
3049
+ it('keeps the native prepayment of a paymaster with other operations when nothing gives the fee', async () => {
3050
+ mockGetOperations({
3051
+ lastInternalOperations: [
3052
+ {
3053
+ type: 'OUT',
3054
+ senders: [PAYMASTER],
3055
+ recipients: [BOOTLOADER],
3056
+ value: 49775000000000,
3057
+ fee: 0,
3058
+ },
3059
+ { type: 'IN', senders: [SENDER], recipients: [PAYMASTER], value: 1000, fee: 0 },
3060
+ ],
3061
+ })
3062
+
3063
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), PAYMASTER, {
3064
+ minHeight: 0,
3065
+ order: 'asc',
3066
+ })
3067
+
3068
+ expect(items.map((op) => op.value).sort()).toEqual([1000n, 49775000000000n])
3069
+ for (const op of items) {
3070
+ expect(op.tx.feesPayer).toBe(PAYMASTER)
3071
+ }
3072
+ })
3073
+
3074
+ it('gives the fee to every operation of a paymaster, including one without a fee of its own', async () => {
3075
+ // A native transfer to the paymaster in the same tx: Blockscout gives it no fee
3076
+ mockGetOperations({
3077
+ ...paymasterHistory,
3078
+ lastInternalOperations: [
3079
+ ...paymasterHistory.lastInternalOperations,
3080
+ { type: 'IN', senders: [SENDER], recipients: [PAYMASTER], value: 1000, fee: 0 },
3081
+ ],
3082
+ })
3083
+
3084
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), PAYMASTER, {
3085
+ minHeight: 0,
3086
+ order: 'asc',
3087
+ })
3088
+
3089
+ const native = items.filter((op) => op.asset.type === 'native')
3090
+ expect(native).toEqual([
3091
+ expect.objectContaining({
3092
+ value: 1000n,
3093
+ tx: expect.objectContaining({ fees: BigInt(FEE), feesPayer: PAYMASTER }),
3094
+ }),
3095
+ ])
3096
+ })
3097
+
3098
+ it('keeps a refund from the bootloader to an account that did not pay the fee', async () => {
3099
+ // The refund recipient of an L1→L2 deposit: the fee was paid on L1
3100
+ const RECIPIENT = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
3101
+ mockGetOperations({
3102
+ lastInternalOperations: [
3103
+ {
3104
+ type: 'IN',
3105
+ senders: [BOOTLOADER],
3106
+ recipients: [RECIPIENT],
3107
+ value: 287193761364190,
3108
+ fee: 0,
3109
+ },
3110
+ ],
3111
+ })
3112
+
3113
+ const { items } = await listOperations(zkSyncContext([BOOTLOADER]), RECIPIENT, {
3114
+ minHeight: 0,
3115
+ order: 'asc',
3116
+ })
3117
+
3118
+ expect(items).toEqual([
3119
+ expect.objectContaining({
3120
+ type: 'IN',
3121
+ value: 287193761364190n,
3122
+ asset: { type: 'native' },
3123
+ }),
3124
+ ])
3125
+ expect(items[0].tx.feesPayer).toBeUndefined()
3126
+ })
3127
+
3128
+ it('changes nothing on a network without fee collector', async () => {
3129
+ mockGetOperations(paymasterHistory)
3130
+
3131
+ const { items } = await listOperations(zkSyncContext(), PAYMASTER, {
3132
+ minHeight: 0,
3133
+ order: 'asc',
3134
+ })
3135
+
3136
+ expect(items.filter((op) => op.asset.type === 'native')).toHaveLength(1)
3137
+ expect(items.every((op) => op.tx.feesPayer === undefined)).toBe(true)
3138
+ })
3139
+ })
2577
3140
  })
2578
3141
  })