@ledgerhq/coin-evm 16.5.0 → 16.5.1
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.
- package/CHANGELOG.md +6 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +4 -0
- package/lib/config.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +24 -2
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +20 -0
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +57 -0
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +25 -3
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +20 -0
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +55 -0
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +11 -0
- package/src/logic/getBlock.ts +47 -3
- package/src/logic/internalTransactionsFetcher.ts +72 -0
- package/src/logic/tests/getBlock.test.ts +274 -2
- package/src/logic/tests/internalTransactionsFetcher.test.ts +141 -1
|
@@ -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 {
|
|
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
|
+
})
|