@ledgerhq/coin-evm 16.5.0 → 16.5.2

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 (40) 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/logic/getBlock.d.ts.map +1 -1
  11. package/lib/logic/getBlock.js +24 -2
  12. package/lib/logic/getBlock.js.map +1 -1
  13. package/lib/logic/internalTransactionsFetcher.d.ts +20 -0
  14. package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
  15. package/lib/logic/internalTransactionsFetcher.js +57 -0
  16. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  17. package/lib-es/chains.d.ts +0 -1
  18. package/lib-es/chains.d.ts.map +1 -1
  19. package/lib-es/chains.js +0 -1
  20. package/lib-es/chains.js.map +1 -1
  21. package/lib-es/config.d.ts +9 -0
  22. package/lib-es/config.d.ts.map +1 -1
  23. package/lib-es/config.js +4 -0
  24. package/lib-es/config.js.map +1 -1
  25. package/lib-es/logic/getBlock.d.ts.map +1 -1
  26. package/lib-es/logic/getBlock.js +25 -3
  27. package/lib-es/logic/getBlock.js.map +1 -1
  28. package/lib-es/logic/internalTransactionsFetcher.d.ts +20 -0
  29. package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
  30. package/lib-es/logic/internalTransactionsFetcher.js +55 -0
  31. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  32. package/package.json +2 -2
  33. package/src/api/tests/getBlock.integ.test.ts +2 -70
  34. package/src/chains.ts +0 -1
  35. package/src/config.ts +11 -0
  36. package/src/logic/getBlock.ts +47 -3
  37. package/src/logic/internalTransactionsFetcher.ts +72 -0
  38. package/src/logic/tests/getBlock.test.ts +274 -2
  39. package/src/logic/tests/internalTransactionsFetcher.test.ts +141 -1
  40. package/src/network/tests/node/rpc.test.ts +2 -2
@@ -178,6 +178,78 @@ export function makeSourceFetchers(
178
178
  }
179
179
  }
180
180
 
181
+ /**
182
+ * Drops the internal native transfers between a fee collector contract (see
183
+ * `feeCollectorContracts`) and the fee payer of their transaction. They move the fee that the
184
+ * transaction `fees` already holds: keeping them would debit the fee payer twice. A transfer
185
+ * between a fee collector and another account is kept: `fees` does not hold it.
186
+ *
187
+ * @param feesPayers fee payer of each transaction, by hash
188
+ */
189
+ export function dropFeeCollectorTransfers(
190
+ internalTxs: InternalTxsByHash,
191
+ feeCollectorContracts: readonly string[],
192
+ feesPayers: ReadonlyMap<string, string | undefined>
193
+ ): InternalTxsByHash {
194
+ const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()))
195
+ const isFeeTransfer = (operation: BlockOperation, feesPayer: string): boolean => {
196
+ if (operation.type !== 'transfer' || operation.asset.type !== 'native') return false
197
+ if (operation.peer === undefined) return false
198
+ const address = operation.address.toLowerCase()
199
+ const peer = operation.peer.toLowerCase()
200
+ return (
201
+ (collectors.has(address) && peer === feesPayer) ||
202
+ (collectors.has(peer) && address === feesPayer)
203
+ )
204
+ }
205
+
206
+ return new Map(
207
+ [...internalTxs].map(([hash, operations]) => {
208
+ const feesPayer = feesPayers.get(hash)?.toLowerCase()
209
+ return [
210
+ hash,
211
+ feesPayer === undefined
212
+ ? operations
213
+ : operations.filter((operation) => !isFeeTransfer(operation, feesPayer)),
214
+ ]
215
+ })
216
+ )
217
+ }
218
+
219
+ /**
220
+ * Finds the account that paid the fee of a transaction to a fee collector contract (see
221
+ * `feeCollectorContracts`), when it is not the sender: a zkSync paymaster prepays the fee to the
222
+ * bootloader for the sender, and gets the unused gas back.
223
+ *
224
+ * @param operations internal operations of the transaction
225
+ * @param sender sender of the transaction
226
+ * @returns the account that sent native coins to a fee collector, if it is a single account
227
+ * other than the sender
228
+ */
229
+ export function findFeeCollectorPayer(
230
+ operations: readonly BlockOperation[],
231
+ feeCollectorContracts: readonly string[],
232
+ sender: string | undefined
233
+ ): string | undefined {
234
+ const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()))
235
+ const payers = new Set(
236
+ operations.flatMap((operation) =>
237
+ operation.type === 'transfer' &&
238
+ operation.asset.type === 'native' &&
239
+ operation.amount < 0n &&
240
+ operation.peer !== undefined &&
241
+ collectors.has(operation.peer.toLowerCase()) &&
242
+ !collectors.has(operation.address.toLowerCase())
243
+ ? [operation.address.toLowerCase()]
244
+ : []
245
+ )
246
+ )
247
+ if (payers.size !== 1 || (sender !== undefined && payers.has(sender.toLowerCase()))) {
248
+ return undefined
249
+ }
250
+ return [...payers][0]
251
+ }
252
+
181
253
  export function createInternalTransactionsFetcher(
182
254
  config: EvmConfigInfo,
183
255
  nodeApi: NodeApi,
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { ChainId, EvmContext } from '../../config'
4
+ import type { ChainId, EvmConfigInfo, EvmContext } from '../../config'
5
5
  import type {
6
6
  BlockByHeightResult,
7
7
  BlockReceiptInfo,
@@ -14,7 +14,7 @@ import type {
14
14
  import type { EtherscanInternalTransaction } from '../../types'
15
15
  import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
16
16
  import { ethers } from 'ethers'
17
- import { CHAIN_ID, internalTxSourcesFromList } from '../../config'
17
+ import { CHAIN_ID, evmDefaults, internalTxSourcesFromList } from '../../config'
18
18
  import { UnsupportedRpcMethodError } from '../../errors'
19
19
  import {
20
20
  createMockEvmConfigInfo,
@@ -1063,6 +1063,278 @@ describe('getBlock', () => {
1063
1063
  })
1064
1064
  })
1065
1065
 
1066
+ describe('zkSync bootloader fee prepayment and refund', () => {
1067
+ // Values of tx 0x13600459c61346e7195861973c04158d1b8b86adde05028066ae16ec852ac00f (zkSync Era,
1068
+ // height 4419528): gasLimit 758351, gasUsed 407022, gasPrice 0.25 gwei. The sender prepays
1069
+ // gasLimit × gasPrice to the bootloader, which refunds the unused gas.
1070
+ const USER = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
1071
+ const BOOTLOADER = '0x0000000000000000000000000000000000008001'
1072
+ const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
1073
+ const GAS_PRICE = '250000000'
1074
+ const GAS_USED = '407022'
1075
+ const PREPAYMENT = 189587750000000n
1076
+ const REFUND = 87832250000000n
1077
+ const FEE = 101755500000000n
1078
+
1079
+ function userNativeDelta(operations: BlockOperation[]): bigint {
1080
+ return operations.reduce(
1081
+ (sum, op) =>
1082
+ op.type === 'transfer' && op.asset.type === 'native' && op.address === USER
1083
+ ? sum + op.amount
1084
+ : sum,
1085
+ 0n
1086
+ )
1087
+ }
1088
+
1089
+ function bootloaderNativeOps(operations: BlockOperation[]): BlockOperation[] {
1090
+ return operations.filter(
1091
+ (op) =>
1092
+ op.type === 'transfer' &&
1093
+ op.asset.type === 'native' &&
1094
+ (op.address.toLowerCase() === BOOTLOADER || op.peer?.toLowerCase() === BOOTLOADER)
1095
+ )
1096
+ }
1097
+
1098
+ function mockBulkBlock(
1099
+ network: Pick<EvmConfigInfo, 'chainId' | 'feeCollectorContracts'>
1100
+ ): EvmContext {
1101
+ const context = createMockEvmContext(
1102
+ createMockEvmConfigInfo({
1103
+ ...network,
1104
+ node: mkExternalNode(),
1105
+ explorer: mkEtherscanExplorer(),
1106
+ })
1107
+ )
1108
+ mockGetBlockNodeApi(
1109
+ mockNodeApi({
1110
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
1111
+ makeNodeBlock({
1112
+ transactions: [
1113
+ makeNodeBlockTx({ from: USER, to: address2, value: '0', gasPrice: GAS_PRICE }),
1114
+ ],
1115
+ })
1116
+ ),
1117
+ getBlockReceipts: jest.fn().mockResolvedValueOnce([
1118
+ makeNodeBlockReceipt({
1119
+ gasUsed: GAS_USED,
1120
+ gasPrice: GAS_PRICE,
1121
+ erc20Transfers: [
1122
+ makeNodeErc20Transfer({
1123
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1124
+ from: USER,
1125
+ to: BOOTLOADER,
1126
+ value: PREPAYMENT.toString(),
1127
+ }),
1128
+ makeNodeErc20Transfer({
1129
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1130
+ from: BOOTLOADER,
1131
+ to: USER,
1132
+ value: REFUND.toString(),
1133
+ }),
1134
+ ],
1135
+ }),
1136
+ ]),
1137
+ getTransaction: jest.fn(),
1138
+ })
1139
+ )
1140
+ return context
1141
+ }
1142
+
1143
+ it.each([
1144
+ ['ZKsync', evmDefaults.zksync],
1145
+ ['ZKsync Sepolia', evmDefaults.zksync_sepolia],
1146
+ ])(
1147
+ 'on %s, drops the native prepayment leg so the sender pays the fee once',
1148
+ async (_, network) => {
1149
+ const context = mockBulkBlock({
1150
+ chainId: network.chainId,
1151
+ feeCollectorContracts: network.feeCollectorContracts,
1152
+ })
1153
+ jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
1154
+ makeExplorerInternalTransaction({
1155
+ from: USER,
1156
+ to: BOOTLOADER,
1157
+ value: PREPAYMENT.toString(),
1158
+ }),
1159
+ ])
1160
+
1161
+ const [tx] = (await getBlock(context, 12345)).transactions
1162
+
1163
+ expect(bootloaderNativeOps(tx.operations)).toEqual([])
1164
+ expect(userNativeDelta(tx.operations)).toBe(0n)
1165
+ expect(tx.fees).toBe(FEE)
1166
+ expect(tx.feesPayer).toBe(USER)
1167
+ }
1168
+ )
1169
+
1170
+ it('drops a native refund leg too, and keeps the other internal transfers and the base-token legs', async () => {
1171
+ const context = mockBulkBlock({
1172
+ chainId: CHAIN_ID.ZKSYNC,
1173
+ feeCollectorContracts: [BOOTLOADER],
1174
+ })
1175
+ jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
1176
+ makeExplorerInternalTransaction({
1177
+ from: USER,
1178
+ to: BOOTLOADER,
1179
+ value: PREPAYMENT.toString(),
1180
+ }),
1181
+ makeExplorerInternalTransaction({ from: BOOTLOADER, to: USER, value: REFUND.toString() }),
1182
+ makeExplorerInternalTransaction({ from: address2, to: USER, value: '1000' }),
1183
+ ])
1184
+
1185
+ const [tx] = (await getBlock(context, 12345)).transactions
1186
+
1187
+ expect(bootloaderNativeOps(tx.operations)).toEqual([])
1188
+ expect(userNativeDelta(tx.operations)).toBe(1000n)
1189
+ expect(tx.operations).toEqual(
1190
+ expect.arrayContaining([
1191
+ expect.objectContaining({
1192
+ address: USER,
1193
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1194
+ amount: -PREPAYMENT,
1195
+ }),
1196
+ expect.objectContaining({
1197
+ address: USER,
1198
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1199
+ amount: REFUND,
1200
+ }),
1201
+ ])
1202
+ )
1203
+ })
1204
+
1205
+ it('charges the fee to a paymaster that prepays it, not to the sender', async () => {
1206
+ // Values of tx 0x23f32c7199a6568f2c551cd0f1e29a10780a811128037efa7691cfc32cf4615d (zkSync
1207
+ // Era, height 72812813): the paymaster prepays gasLimit 1100000 × 0.04525 gwei to the
1208
+ // bootloader and gets the unused gas back, and the sender moves no ETH. Blockscout only
1209
+ // reports the prepayment as an internal transaction.
1210
+ const SENDER = '0x1B4a3d0A5712362FA06CDD4930b9ca720Ed6db18'
1211
+ const PAYMASTER = '0xA2Aac7bC9725c36ad9B12D2407dF8de6B2B68359'
1212
+ const PAYMASTER_PREPAYMENT = 49775000000000n
1213
+ const PAYMASTER_REFUND = 42357348500000n
1214
+ const PAYMASTER_FEE = 7417651500000n
1215
+ const context = createMockEvmContext(
1216
+ createMockEvmConfigInfo({
1217
+ chainId: CHAIN_ID.ZKSYNC,
1218
+ feeCollectorContracts: [BOOTLOADER],
1219
+ node: mkExternalNode(),
1220
+ explorer: mkEtherscanExplorer(),
1221
+ })
1222
+ )
1223
+ mockGetBlockNodeApi(
1224
+ mockNodeApi({
1225
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
1226
+ makeNodeBlock({
1227
+ transactions: [
1228
+ makeNodeBlockTx({ from: SENDER, to: address2, value: '0', gasPrice: '45250000' }),
1229
+ ],
1230
+ })
1231
+ ),
1232
+ getBlockReceipts: jest.fn().mockResolvedValueOnce([
1233
+ makeNodeBlockReceipt({
1234
+ gasUsed: '163926',
1235
+ gasPrice: '45250000',
1236
+ erc20Transfers: [
1237
+ makeNodeErc20Transfer({
1238
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1239
+ from: PAYMASTER,
1240
+ to: BOOTLOADER,
1241
+ value: PAYMASTER_PREPAYMENT.toString(),
1242
+ }),
1243
+ makeNodeErc20Transfer({
1244
+ asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
1245
+ from: BOOTLOADER,
1246
+ to: PAYMASTER,
1247
+ value: PAYMASTER_REFUND.toString(),
1248
+ }),
1249
+ ],
1250
+ }),
1251
+ ]),
1252
+ getTransaction: jest.fn(),
1253
+ })
1254
+ )
1255
+ jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
1256
+ makeExplorerInternalTransaction({
1257
+ from: PAYMASTER.toLowerCase(),
1258
+ to: BOOTLOADER,
1259
+ value: PAYMASTER_PREPAYMENT.toString(),
1260
+ }),
1261
+ ])
1262
+
1263
+ const [tx] = (await getBlock(context, 12345)).transactions
1264
+
1265
+ const nativeDelta = (account: string): bigint =>
1266
+ tx.operations.reduce(
1267
+ (sum, op) =>
1268
+ op.type === 'transfer' && op.asset.type === 'native' && op.address === account
1269
+ ? sum + op.amount
1270
+ : sum,
1271
+ 0n
1272
+ )
1273
+ expect(tx.feesPayer).toBe(PAYMASTER)
1274
+ expect(tx.fees).toBe(PAYMASTER_FEE)
1275
+ expect(bootloaderNativeOps(tx.operations)).toEqual([])
1276
+ expect(nativeDelta(SENDER)).toBe(0n)
1277
+ expect(nativeDelta(PAYMASTER)).toBe(0n)
1278
+ })
1279
+
1280
+ it('drops the native prepayment leg when transactions are fetched one by one', async () => {
1281
+ const context = createMockEvmContext(
1282
+ createMockEvmConfigInfo({
1283
+ chainId: CHAIN_ID.ZKSYNC,
1284
+ feeCollectorContracts: [BOOTLOADER],
1285
+ node: mkExternalNode(),
1286
+ explorer: mkEtherscanExplorer(),
1287
+ })
1288
+ )
1289
+ mockGetBlockNodeApi(
1290
+ mockNodeApi({
1291
+ getBlockByHeight: jest
1292
+ .fn()
1293
+ .mockResolvedValueOnce(makeNodeBlock({ transactionHashes: ['0xtx1'] })),
1294
+ getBlockReceipts: jest.fn(),
1295
+ getTransaction: jest.fn().mockResolvedValueOnce(
1296
+ makeNodeTxInfo({
1297
+ from: USER,
1298
+ to: address2,
1299
+ value: '0',
1300
+ gasUsed: GAS_USED,
1301
+ gasPrice: GAS_PRICE,
1302
+ })
1303
+ ),
1304
+ })
1305
+ )
1306
+ jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
1307
+ makeExplorerInternalTransaction({
1308
+ from: USER,
1309
+ to: BOOTLOADER,
1310
+ value: PREPAYMENT.toString(),
1311
+ }),
1312
+ ])
1313
+
1314
+ const [tx] = (await getBlock(context, 12345)).transactions
1315
+
1316
+ expect(bootloaderNativeOps(tx.operations)).toEqual([])
1317
+ expect(userNativeDelta(tx.operations)).toBe(0n)
1318
+ expect(tx.fees).toBe(FEE)
1319
+ })
1320
+
1321
+ it('keeps native transfers to the bootloader address when the network lists no fee collector', async () => {
1322
+ const context = mockBulkBlock({ chainId: CHAIN_ID.ETHEREUM })
1323
+ jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
1324
+ makeExplorerInternalTransaction({
1325
+ from: USER,
1326
+ to: BOOTLOADER,
1327
+ value: PREPAYMENT.toString(),
1328
+ }),
1329
+ ])
1330
+
1331
+ const [tx] = (await getBlock(context, 12345)).transactions
1332
+
1333
+ expect(bootloaderNativeOps(tx.operations)).toHaveLength(2)
1334
+ expect(userNativeDelta(tx.operations)).toBe(-PREPAYMENT)
1335
+ })
1336
+ })
1337
+
1066
1338
  it('when explorer is not etherscan like, falls back to node.traceBlockErigon', async () => {
1067
1339
  const context = createMockEvmContext(
1068
1340
  createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode(), explorer: mkLedgerExplorer() })
@@ -15,7 +15,12 @@ import {
15
15
  import { getInternalTransactionsByBlock as getBlockscoutV2InternalTransactionsByBlock } from '../../network/blockscoutV2'
16
16
  import { getInternalTransactionsByBlock } from '../../network/explorer/etherscan'
17
17
  import { mockNodeApi } from '../../network/tests/node/node.fixtures'
18
- import { composeInternalTxsFetcher, makeSourceFetchers } from '../internalTransactionsFetcher'
18
+ import {
19
+ composeInternalTxsFetcher,
20
+ dropFeeCollectorTransfers,
21
+ findFeeCollectorPayer,
22
+ makeSourceFetchers,
23
+ } from '../internalTransactionsFetcher'
19
24
 
20
25
  jest.mock('../../network/explorer/etherscan', () => ({
21
26
  getInternalTransactionsByBlock: jest.fn().mockResolvedValue([]),
@@ -322,3 +327,138 @@ describe('makeSourceFetchers', () => {
322
327
  await expect(fetchers.empty(1)).resolves.toEqual(new Map<string, BlockOperation[]>())
323
328
  })
324
329
  })
330
+
331
+ const BOOTLOADER = '0x0000000000000000000000000000000000008001'
332
+ const USER = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
333
+ const OTHER = '0x0459a84952C85c6E9345e5d22d9B110790a5e1Ba'
334
+
335
+ function nativeTransfer(address: string, peer: string | undefined, amount: bigint): BlockOperation {
336
+ return {
337
+ type: 'transfer',
338
+ address,
339
+ ...(peer !== undefined ? { peer } : {}),
340
+ asset: { type: 'native' },
341
+ amount,
342
+ }
343
+ }
344
+
345
+ describe('dropFeeCollectorTransfers', () => {
346
+ it('drops the native transfers between a fee collector and the fee payer and keeps the other operations', () => {
347
+ const otherTransfer = nativeTransfer(USER, OTHER, -7n)
348
+ const unknownPeer = nativeTransfer(USER, undefined, -3n)
349
+ const baseTokenLeg: BlockOperation = {
350
+ type: 'transfer',
351
+ address: USER,
352
+ peer: BOOTLOADER,
353
+ asset: { type: 'erc20', assetReference: '0x000000000000000000000000000000000000800A' },
354
+ amount: -5n,
355
+ }
356
+ const otherOperation: BlockOperation = { type: 'other' }
357
+ const internalTxs = new Map<string, BlockOperation[]>([
358
+ [
359
+ '0x1',
360
+ [
361
+ nativeTransfer(USER, BOOTLOADER, -5n),
362
+ nativeTransfer(BOOTLOADER, USER, 5n),
363
+ otherTransfer,
364
+ unknownPeer,
365
+ baseTokenLeg,
366
+ otherOperation,
367
+ ],
368
+ ],
369
+ ['0x2', [nativeTransfer(BOOTLOADER, USER, 2n), nativeTransfer(USER, BOOTLOADER, -2n)]],
370
+ ])
371
+ const feesPayers = new Map([
372
+ ['0x1', USER],
373
+ ['0x2', USER],
374
+ ])
375
+
376
+ const result = dropFeeCollectorTransfers(internalTxs, [BOOTLOADER], feesPayers)
377
+
378
+ expect(result.get('0x1')).toEqual([otherTransfer, unknownPeer, baseTokenLeg, otherOperation])
379
+ expect(result.get('0x2')).toEqual([])
380
+ })
381
+
382
+ it('keeps the native transfers between a fee collector and an account that is not the fee payer', () => {
383
+ // A zkSync paymaster prepays the fee of USER's transaction and gets the unused gas back
384
+ const paymasterLegs = [
385
+ nativeTransfer(OTHER, BOOTLOADER, -5n),
386
+ nativeTransfer(BOOTLOADER, OTHER, 5n),
387
+ nativeTransfer(BOOTLOADER, OTHER, 2n),
388
+ nativeTransfer(OTHER, BOOTLOADER, -2n),
389
+ ]
390
+ const internalTxs = new Map<string, BlockOperation[]>([['0x1', paymasterLegs]])
391
+
392
+ const result = dropFeeCollectorTransfers(internalTxs, [BOOTLOADER], new Map([['0x1', USER]]))
393
+
394
+ expect(result.get('0x1')).toEqual(paymasterLegs)
395
+ })
396
+
397
+ it('keeps the operations of a transaction without a known fee payer', () => {
398
+ const operations = [nativeTransfer(USER, BOOTLOADER, -5n), nativeTransfer(BOOTLOADER, USER, 5n)]
399
+ const internalTxs = new Map<string, BlockOperation[]>([['0x1', operations]])
400
+
401
+ expect(dropFeeCollectorTransfers(internalTxs, [BOOTLOADER], new Map()).get('0x1')).toEqual(
402
+ operations
403
+ )
404
+ })
405
+
406
+ it('matches the fee collector and fee payer addresses whatever their case', () => {
407
+ const internalTxs = new Map<string, BlockOperation[]>([
408
+ ['0x1', [nativeTransfer(USER.toUpperCase().replace('0X', '0x'), OTHER.toLowerCase(), -5n)]],
409
+ ])
410
+
411
+ expect(
412
+ dropFeeCollectorTransfers(internalTxs, [OTHER], new Map([['0x1', USER.toLowerCase()]])).get(
413
+ '0x1'
414
+ )
415
+ ).toEqual([])
416
+ })
417
+ })
418
+
419
+ describe('findFeeCollectorPayer', () => {
420
+ const PAYMASTER = '0xA2Aac7bC9725c36ad9B12D2407dF8de6B2B68359'
421
+
422
+ it('finds a paymaster that prepays the fee to the fee collector', () => {
423
+ const operations = [
424
+ nativeTransfer(PAYMASTER, BOOTLOADER, -5n),
425
+ nativeTransfer(BOOTLOADER, PAYMASTER, 5n),
426
+ ]
427
+
428
+ expect(findFeeCollectorPayer(operations, [BOOTLOADER], USER)).toBe(PAYMASTER.toLowerCase())
429
+ })
430
+
431
+ it('finds no other payer when the sender prepays the fee', () => {
432
+ const operations = [
433
+ nativeTransfer(USER.toLowerCase(), BOOTLOADER, -5n),
434
+ nativeTransfer(BOOTLOADER, USER, 5n),
435
+ ]
436
+
437
+ expect(findFeeCollectorPayer(operations, [BOOTLOADER], USER)).toBeUndefined()
438
+ })
439
+
440
+ it('finds no payer without a native prepayment to the fee collector', () => {
441
+ const operations: BlockOperation[] = [
442
+ nativeTransfer(BOOTLOADER, PAYMASTER, 5n),
443
+ nativeTransfer(PAYMASTER, OTHER, -5n),
444
+ {
445
+ type: 'transfer',
446
+ address: PAYMASTER,
447
+ peer: BOOTLOADER,
448
+ asset: { type: 'erc20', assetReference: '0x000000000000000000000000000000000000800A' },
449
+ amount: -5n,
450
+ },
451
+ ]
452
+
453
+ expect(findFeeCollectorPayer(operations, [BOOTLOADER], USER)).toBeUndefined()
454
+ })
455
+
456
+ it('finds no payer when several accounts other than the sender prepay', () => {
457
+ const operations = [
458
+ nativeTransfer(PAYMASTER, BOOTLOADER, -5n),
459
+ nativeTransfer(OTHER, BOOTLOADER, -2n),
460
+ ]
461
+
462
+ expect(findFeeCollectorPayer(operations, [BOOTLOADER], USER)).toBeUndefined()
463
+ })
464
+ })
@@ -362,8 +362,8 @@ describe('EVM Family', () => {
362
362
  const TRANSFER_TOPIC = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
363
363
  const APPROVAL_TOPIC = '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925'
364
364
 
365
- it('should parse single ERC20 Transfer (Velas EVM)', () => {
366
- // Real data from Velas EVM tx 0x23f9232e929f9a13f4f2d6d4e9bf27d717a2b1250d207c030fc66565c4e205e1
365
+ it('should parse a single ERC20 Transfer log', () => {
366
+ // ERC20 Transfer log fixture.
367
367
  const logs = [
368
368
  {
369
369
  address: '0xabf26902fd7b624e0db40d31171ea9dddf078351',