@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.
- package/CHANGELOG.md +12 -0
- package/lib/chains.d.ts +0 -1
- package/lib/chains.d.ts.map +1 -1
- package/lib/chains.js +0 -1
- package/lib/chains.js.map +1 -1
- 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/errors.d.ts +15 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +31 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/feeCollectorOperations.d.ts +61 -0
- package/lib/logic/feeCollectorOperations.d.ts.map +1 -0
- package/lib/logic/feeCollectorOperations.js +206 -0
- package/lib/logic/feeCollectorOperations.js.map +1 -0
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +4 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +84 -29
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib-es/chains.d.ts +0 -1
- package/lib-es/chains.d.ts.map +1 -1
- package/lib-es/chains.js +0 -1
- package/lib-es/chains.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/errors.d.ts +15 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +27 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/feeCollectorOperations.d.ts +61 -0
- package/lib-es/logic/feeCollectorOperations.d.ts.map +1 -0
- package/lib-es/logic/feeCollectorOperations.js +201 -0
- package/lib-es/logic/feeCollectorOperations.js.map +1 -0
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +85 -30
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/package.json +2 -2
- package/src/api/tests/getBlock.integ.test.ts +5 -102
- package/src/api/tests/index.alpen_testnet.integ.test.ts +2 -7
- package/src/api/tests/index.arbitrum.integ.test.ts +2 -12
- package/src/api/tests/index.arc.integ.test.ts +2 -13
- package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +2 -12
- package/src/api/tests/index.cronos.integ.test.ts +2 -12
- package/src/api/tests/index.flare.integ.test.ts +2 -8
- package/src/api/tests/index.integ.test.ts +5 -35
- package/src/api/tests/index.linea.integ.test.ts +2 -15
- package/src/api/tests/index.monad_testnet.integ.test.ts +5 -13
- package/src/api/tests/index.optimism.integ.test.ts +2 -12
- package/src/api/tests/index.rsk.integ.test.ts +2 -12
- package/src/api/tests/index.scroll.integ.test.ts +4 -7
- package/src/api/tests/index.shape.integ.test.ts +3 -27
- package/src/api/tests/index.somnia.integ.test.ts +2 -6
- package/src/api/tests/index.unichain.integ.test.ts +2 -12
- package/src/api/tests/index.zksync.integ.test.ts +5 -8
- package/src/chains.ts +0 -1
- package/src/config.ts +11 -0
- package/src/errors.ts +27 -0
- package/src/logic/feeCollectorOperations.ts +272 -0
- package/src/logic/listOperations.ts +20 -1
- package/src/logic/tests/broadcast.integ.test.ts +4 -15
- package/src/logic/tests/listOperations.test.ts +563 -0
- package/src/network/node/rpc.common.ts +128 -30
- package/src/network/tests/node/rpc.test.ts +81 -9
- package/src/staking/validators.integ.test.ts +5 -22
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.readReceiptTransfers = void 0;
|
|
6
|
+
exports.findTransactionsPaidByOthers = findTransactionsPaidByOthers;
|
|
7
|
+
exports.attributeFeeCollectorPayments = attributeFeeCollectorPayments;
|
|
8
|
+
const promises_1 = require("@ledgerhq/coin-module-framework/promises");
|
|
9
|
+
const cache_1 = require("@ledgerhq/live-network/cache");
|
|
10
|
+
const node_1 = require("../network/node");
|
|
11
|
+
// Receipts read in parallel, as getBlock does for transactions it fetches one by one
|
|
12
|
+
const MAX_RECEIPT_CONCURRENCY = 2;
|
|
13
|
+
/**
|
|
14
|
+
* True when a transfer moves the fee: a positive amount of the native coin, as a native transfer
|
|
15
|
+
* or as one of the network's `feeCollectorTokens` (the zkSync base token). Another token sent to a
|
|
16
|
+
* fee collector does not pay the fee.
|
|
17
|
+
*
|
|
18
|
+
* @param feeCollectorTokens lower-cased `feeCollectorTokens` of the network
|
|
19
|
+
*/
|
|
20
|
+
function isFeePayment(asset, amount, feeCollectorTokens) {
|
|
21
|
+
if (amount <= 0n)
|
|
22
|
+
return false;
|
|
23
|
+
if (asset.type === 'native')
|
|
24
|
+
return true;
|
|
25
|
+
return (asset.assetReference !== undefined && feeCollectorTokens.has(asset.assetReference.toLowerCase()));
|
|
26
|
+
}
|
|
27
|
+
function lowerCased(addresses) {
|
|
28
|
+
return new Set((addresses ?? []).map((address) => address.toLowerCase()));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The ERC-20 transfers of a transaction, from its receipt. A mined transaction keeps them, so each
|
|
32
|
+
* receipt is read once: a sync of the whole history does not read the receipts of the transactions
|
|
33
|
+
* paid by others again. Kept per chain and transaction, before any network setting applies. A
|
|
34
|
+
* failed read is not kept.
|
|
35
|
+
*/
|
|
36
|
+
exports.readReceiptTransfers = (0, cache_1.makeLRUCache)(async (config, logger, hash) => {
|
|
37
|
+
const { erc20Transfers } = await (0, node_1.getNodeApi)(config, logger).getTransaction(hash);
|
|
38
|
+
return erc20Transfers;
|
|
39
|
+
}, (config, _logger, hash) => `${config.chainId}:${hash}`, { max: 10_000, ttl: 24 * 60 * 60 * 1000 });
|
|
40
|
+
/**
|
|
41
|
+
* The accounts that sent the network's fee collectors a fee payment in a transaction (see
|
|
42
|
+
* {@link isFeePayment}), lowercase, from its receipt.
|
|
43
|
+
*/
|
|
44
|
+
async function findFeeCollectorPrepayers(config, logger, hash) {
|
|
45
|
+
const collectors = lowerCased(config.feeCollectorContracts);
|
|
46
|
+
const tokens = lowerCased(config.feeCollectorTokens);
|
|
47
|
+
const transfers = await (0, exports.readReceiptTransfers)(config, logger, hash);
|
|
48
|
+
return transfers
|
|
49
|
+
.filter((transfer) => collectors.has(transfer.to.toLowerCase()) &&
|
|
50
|
+
isFeePayment(transfer.asset, BigInt(transfer.value), tokens))
|
|
51
|
+
.map((transfer) => transfer.from.toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
function addressMatchers(address, feeCollectorContracts) {
|
|
54
|
+
const account = address.toLowerCase();
|
|
55
|
+
const collectors = new Set(feeCollectorContracts.map((contract) => contract.toLowerCase()));
|
|
56
|
+
return {
|
|
57
|
+
isAccount: (other) => other.toLowerCase() === account,
|
|
58
|
+
isCollector: (other) => collectors.has(other.toLowerCase()),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The account, as the explorer spells it (EIP-55), by hash of the transactions its history shows
|
|
63
|
+
* it paid: a fee payment from the account to a fee collector (see {@link isFeePayment}), on zkSync
|
|
64
|
+
* the base-token (`0x800A`, a `feeCollectorTokens` entry) prepayment to the bootloader.
|
|
65
|
+
*/
|
|
66
|
+
function findPrepayments(address, feeCollectorContracts, feeCollectorTokens, evidence) {
|
|
67
|
+
const { isAccount, isCollector } = addressMatchers(address, feeCollectorContracts);
|
|
68
|
+
const tokens = lowerCased(feeCollectorTokens);
|
|
69
|
+
const payers = new Map();
|
|
70
|
+
for (const op of evidence) {
|
|
71
|
+
const sender = op.senders.find(isAccount);
|
|
72
|
+
if (sender === undefined || !op.recipients.some(isCollector))
|
|
73
|
+
continue;
|
|
74
|
+
if (isFeePayment(op.asset, op.value, tokens))
|
|
75
|
+
payers.set(op.tx.hash, sender);
|
|
76
|
+
}
|
|
77
|
+
return payers;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Finds the transactions whose fee the explorer charges to the account but that another account
|
|
81
|
+
* paid, on a network that collects the fee in a contract (see `feeCollectorContracts`).
|
|
82
|
+
*
|
|
83
|
+
* The explorer names the sender as the fee payer. When the account history has no prepayment of
|
|
84
|
+
* the account to a fee collector for such a transaction, its receipt tells who paid: a zkSync
|
|
85
|
+
* paymaster prepays the fee to the bootloader, and an L1→L2 deposit pays it on L1. A transaction
|
|
86
|
+
* whose receipt cannot be read keeps the explorer's fee payer.
|
|
87
|
+
*
|
|
88
|
+
* @param operations operations of the account, as listOperations returns them
|
|
89
|
+
* @param evidence the token, NFT and internal operations of the account from the explorer
|
|
90
|
+
* @returns hashes of the transactions the account did not pay
|
|
91
|
+
*/
|
|
92
|
+
async function findTransactionsPaidByOthers(config, logger, address, operations, evidence) {
|
|
93
|
+
const feeCollectorContracts = config.feeCollectorContracts ?? [];
|
|
94
|
+
if (feeCollectorContracts.length === 0)
|
|
95
|
+
return new Set();
|
|
96
|
+
const { isAccount } = addressMatchers(address, feeCollectorContracts);
|
|
97
|
+
const prepayments = findPrepayments(address, feeCollectorContracts, config.feeCollectorTokens ?? [], evidence);
|
|
98
|
+
const unconfirmed = [
|
|
99
|
+
...new Set(operations
|
|
100
|
+
.filter((op) => op.tx.feesPayer !== undefined && isAccount(op.tx.feesPayer))
|
|
101
|
+
.map((op) => op.tx.hash)
|
|
102
|
+
.filter((hash) => !prepayments.has(hash))),
|
|
103
|
+
];
|
|
104
|
+
if (unconfirmed.length === 0)
|
|
105
|
+
return new Set();
|
|
106
|
+
const paidByOthers = await (0, promises_1.promiseAllBatched)(MAX_RECEIPT_CONCURRENCY, unconfirmed, async (hash) => {
|
|
107
|
+
try {
|
|
108
|
+
const prepayers = await findFeeCollectorPrepayers(config, logger, hash);
|
|
109
|
+
return prepayers.some(isAccount) ? undefined : hash;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
logger('warn', 'EVM listOperations: cannot read the receipt to find the fee payer', {
|
|
113
|
+
currency: config.name,
|
|
114
|
+
hash,
|
|
115
|
+
error,
|
|
116
|
+
});
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return new Set(paidByOthers.filter((hash) => hash !== undefined));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Gives the operations of an account the fee payer seen from the account's own history, on a
|
|
124
|
+
* network that collects the fee in a contract (see `feeCollectorContracts`, e.g. the zkSync
|
|
125
|
+
* bootloader).
|
|
126
|
+
*
|
|
127
|
+
* The account paid the fee of a transaction when its history has a transfer from the account to a
|
|
128
|
+
* fee collector in that transaction (see {@link findPrepayments}):
|
|
129
|
+
* - a paying account is the `feesPayer` of all its operations of the transaction, which carry
|
|
130
|
+
* the fee of the transaction, from whichever of its operations knows it;
|
|
131
|
+
* - an account that another account paid for (see {@link findTransactionsPaidByOthers}) is never
|
|
132
|
+
* the `feesPayer`: ADR-016 leaves the payer unset when it is unknown, rather than defaulting
|
|
133
|
+
* to the sender.
|
|
134
|
+
*
|
|
135
|
+
* The internal native transfers between a paying account and a fee collector move the fee, which
|
|
136
|
+
* `fees` holds: keeping them would debit the account twice, so they are dropped when another
|
|
137
|
+
* operation of the transaction gives the fee. Internal operations carry none, so without one the
|
|
138
|
+
* native transfers stay, as the only trace of what the account paid. When one was the only
|
|
139
|
+
* operation of the transaction for the account, a value-0 `FEES` operation carries the fee
|
|
140
|
+
* instead, as ADR-016 allows.
|
|
141
|
+
*
|
|
142
|
+
* The fee also moves as base-token transfers (zkSync `0x800A`), which stay as token operations,
|
|
143
|
+
* as `getBlock` keeps them (BACK-11036). ADR-068 (proposed) would remove fee movements in every
|
|
144
|
+
* asset, behind an opt-in option; this function does not follow it.
|
|
145
|
+
*
|
|
146
|
+
* @param operations operations of the account, as listOperations returns them
|
|
147
|
+
* @param address the account
|
|
148
|
+
* @param feeCollectorContracts fee collector contracts of the network
|
|
149
|
+
* @param feeCollectorTokens tokens that carry the native coin to those contracts
|
|
150
|
+
* @param evidence the token, NFT and internal operations of the account from the explorer, before
|
|
151
|
+
* listOperations drops any of them
|
|
152
|
+
* @param paidByOthers hashes of the transactions the account did not pay
|
|
153
|
+
*/
|
|
154
|
+
function attributeFeeCollectorPayments(operations, address, feeCollectorContracts, feeCollectorTokens, evidence, paidByOthers) {
|
|
155
|
+
if (feeCollectorContracts.length === 0)
|
|
156
|
+
return operations;
|
|
157
|
+
const { isAccount, isCollector } = addressMatchers(address, feeCollectorContracts);
|
|
158
|
+
const payers = findPrepayments(address, feeCollectorContracts, feeCollectorTokens, evidence);
|
|
159
|
+
const feesByHash = new Map();
|
|
160
|
+
for (const op of [...operations, ...evidence]) {
|
|
161
|
+
if (op.tx.fees > (feesByHash.get(op.tx.hash) ?? 0n))
|
|
162
|
+
feesByHash.set(op.tx.hash, op.tx.fees);
|
|
163
|
+
}
|
|
164
|
+
// Only the payer's transfers move the fee: a refund to an account that did not pay, such as the
|
|
165
|
+
// refund recipient of an L1→L2 deposit, is a real credit
|
|
166
|
+
const isFeeLeg = (op) => payers.has(op.tx.hash) &&
|
|
167
|
+
feesByHash.has(op.tx.hash) &&
|
|
168
|
+
op.asset.type === 'native' &&
|
|
169
|
+
((op.senders.some(isAccount) && op.recipients.some(isCollector)) ||
|
|
170
|
+
(op.senders.some(isCollector) && op.recipients.some(isAccount)));
|
|
171
|
+
const feeLegs = operations.filter(isFeeLeg);
|
|
172
|
+
const kept = operations.filter((op) => !isFeeLeg(op));
|
|
173
|
+
const attributed = kept.map((op) => {
|
|
174
|
+
const payer = payers.get(op.tx.hash);
|
|
175
|
+
if (payer !== undefined) {
|
|
176
|
+
const fees = feesByHash.get(op.tx.hash) ?? op.tx.fees;
|
|
177
|
+
return { ...op, tx: { ...op.tx, fees, feesPayer: payer } };
|
|
178
|
+
}
|
|
179
|
+
if (!paidByOthers.has(op.tx.hash) ||
|
|
180
|
+
op.tx.feesPayer === undefined ||
|
|
181
|
+
!isAccount(op.tx.feesPayer)) {
|
|
182
|
+
return op;
|
|
183
|
+
}
|
|
184
|
+
const { feesPayer: _notThePayer, ...tx } = op.tx;
|
|
185
|
+
return { ...op, tx };
|
|
186
|
+
});
|
|
187
|
+
const keptHashes = new Set(kept.map((op) => op.tx.hash));
|
|
188
|
+
const carriers = new Map();
|
|
189
|
+
for (const leg of feeLegs) {
|
|
190
|
+
if (keptHashes.has(leg.tx.hash) || carriers.has(leg.tx.hash))
|
|
191
|
+
continue;
|
|
192
|
+
carriers.set(leg.tx.hash, {
|
|
193
|
+
...leg,
|
|
194
|
+
id: `${leg.id}-FEES`,
|
|
195
|
+
type: 'FEES',
|
|
196
|
+
value: 0n,
|
|
197
|
+
tx: {
|
|
198
|
+
...leg.tx,
|
|
199
|
+
fees: feesByHash.get(leg.tx.hash) ?? 0n,
|
|
200
|
+
feesPayer: payers.get(leg.tx.hash) ?? leg.senders[0],
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return [...attributed, ...carriers.values()];
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=feeCollectorOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feeCollectorOperations.js","sourceRoot":"","sources":["../../src/logic/feeCollectorOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;AA8HtC,oEA6CC;AAkCD,sEAiEC;AAxQD,uEAA4E;AAC5E,wDAA2D;AAC3D,0CAA4C;AAI5C,qFAAqF;AACrF,MAAM,uBAAuB,GAAG,CAAC,CAAA;AAEjC;;;;;;GAMG;AACH,SAAS,YAAY,CACnB,KAAgD,EAChD,MAAc,EACd,kBAAuC;IAEvC,IAAI,MAAM,IAAI,EAAE;QAAE,OAAO,KAAK,CAAA;IAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;Q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,CAAC,IAAI,EAAE;gBACvC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;aACrD;SACF,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EACV,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACtB,MAAM,2CAA2C,CAAA;
|
|
1
|
+
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EACV,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACtB,MAAM,2CAA2C,CAAA;AAuClD,wBAAsB,cAAc,CAClC,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAmQ5C"}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.listOperations = listOperations;
|
|
6
6
|
const errors_1 = require("@ledgerhq/coin-module-framework/errors");
|
|
7
7
|
const explorer_1 = require("../network/explorer");
|
|
8
|
+
const feeCollectorOperations_1 = require("./feeCollectorOperations");
|
|
8
9
|
// the sort parameter has a double meaning:
|
|
9
10
|
// - legacy (for the bridge): it's used to sort the operations in the result list. Explorer always queried in "desc" order.
|
|
10
11
|
// - new: it's used to sort AND query the explorer with the correct order.
|
|
@@ -208,11 +209,13 @@ async function listOperations(context, address, options) {
|
|
|
208
209
|
}));
|
|
209
210
|
const nativeExpanded = expandSelfSendToTwoOps(nativeWithPerspective, address);
|
|
210
211
|
const tokenExpanded = expandSelfSendToTwoOps(tokenOperations, address);
|
|
211
|
-
const
|
|
212
|
+
const accountOperations = nativeExpanded
|
|
212
213
|
.concat(tokenExpanded)
|
|
213
214
|
.concat(internalOperations)
|
|
214
215
|
.filter(hasValidType)
|
|
215
216
|
.filter(isAddressInvolved);
|
|
217
|
+
const feeEvidence = [...lastTokenOperations, ...lastNftOperations, ...lastInternalOperations];
|
|
218
|
+
const operations = (0, feeCollectorOperations_1.attributeFeeCollectorPayments)(accountOperations, address, config.feeCollectorContracts ?? [], config.feeCollectorTokens ?? [], feeEvidence, await (0, feeCollectorOperations_1.findTransactionsPaidByOthers)(config, context.logger, address, accountOperations, feeEvidence));
|
|
216
219
|
operations.sort((a, b) => options.order === 'asc'
|
|
217
220
|
? a.tx.date.getTime() - b.tx.date.getTime()
|
|
218
221
|
: b.tx.date.getTime() - a.tx.date.getTime());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;
|
|
1
|
+
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AA+CtC,wCAuQC;AA7SD,mEAA8E;AAC9E,kDAAoD;AACpD,qEAGiC;AAEjC,2CAA2C;AAC3C,2HAA2H;AAC3H,0EAA0E;AAE1E,+HAA+H;AAC/H,oDAAoD;AACpD,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,mBAAmB;IACnB,QAAQ;IACR,QAAQ;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E,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,CAAA;AACrD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.common.d.ts","sourceRoot":"","sources":["../../../src/network/node/rpc.common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiC,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEpG,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,cAAc,EAOf,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAA;AAIpE,OAAO,EAAwB,eAAe,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc.common.d.ts","sourceRoot":"","sources":["../../../src/network/node/rpc.common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiC,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEpG,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,cAAc,EAOf,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAA;AAIpE,OAAO,EAAwB,eAAe,EAAE,MAAM,QAAQ,CAAA;AAiC9D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,uEACqC,CAAA;AAEtE,4GAA4G;AAC5G,eAAO,MAAM,kBAAkB,uEACuC,CAAA;AAEtE,oHAAoH;AACpH,eAAO,MAAM,qBAAqB,uEACoC,CAAA;AAEtE,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,uEAAuE,CAAA;AAEpG,4FAA4F;AAC5F,eAAO,MAAM,cAAc,+CAA+C,CAAA;AAoE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,EACnC,MAAM,EAAE,MAAM,GACb,aAAa,EAAE,CAmDjB;AAED,eAAO,MAAM,WAAW,QAGiE,CAAA;AACzF,eAAO,MAAM,2BAA2B,QAG8C,CAAA;AAetF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAK7C;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,EAC7C,UAAU,EAAE,kBAAkB,GAC7B,OAAO,CAAC,CAAC,CAAC,CAkBZ;AAwzBD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CA4CT"}
|
|
@@ -227,16 +227,71 @@ function parseReceiptL1Fee(raw) {
|
|
|
227
227
|
const l1Fee = raw.l1Fee;
|
|
228
228
|
return typeof l1Fee === 'string' ? BigInt(l1Fee).toString() : undefined;
|
|
229
229
|
}
|
|
230
|
+
function rawQuantity(value, fieldName) {
|
|
231
|
+
if (typeof value === 'string' || typeof value === 'number')
|
|
232
|
+
return BigInt(value);
|
|
233
|
+
throw new errors_1.MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`);
|
|
234
|
+
}
|
|
235
|
+
function rawString(value, fieldName) {
|
|
236
|
+
if (typeof value === 'string')
|
|
237
|
+
return value;
|
|
238
|
+
throw new errors_1.MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Reads a transaction with the raw `eth_getTransactionByHash`, for a transaction ethers cannot
|
|
242
|
+
* format: zkSync L1→L2 deposits (type `0xff`) have no signature fields.
|
|
243
|
+
*/
|
|
244
|
+
async function getTransactionFromRawRpc(api, txHash) {
|
|
245
|
+
const raw = await api.send('eth_getTransactionByHash', [txHash]);
|
|
246
|
+
if (raw === null || raw === undefined)
|
|
247
|
+
return null;
|
|
248
|
+
if (!(0, predicates_1.isRecord)(raw))
|
|
249
|
+
throw new errors_1.MalformedNodeResponse('Invalid eth_getTransactionByHash response');
|
|
250
|
+
const blockNumber = raw.blockNumber;
|
|
251
|
+
return {
|
|
252
|
+
hash: rawString(raw.hash, 'hash'),
|
|
253
|
+
blockNumber: blockNumber === null || blockNumber === undefined
|
|
254
|
+
? null
|
|
255
|
+
: Number(rawQuantity(blockNumber, 'blockNumber')),
|
|
256
|
+
blockHash: typeof raw.blockHash === 'string' ? raw.blockHash : null,
|
|
257
|
+
nonce: Number(rawQuantity(raw.nonce, 'nonce')),
|
|
258
|
+
gasLimit: rawQuantity(raw.gas, 'gas'),
|
|
259
|
+
value: rawQuantity(raw.value, 'value'),
|
|
260
|
+
// Checksummed, as ethers gives them
|
|
261
|
+
from: ethers_1.ethers.getAddress(rawString(raw.from, 'from')),
|
|
262
|
+
to: typeof raw.to === 'string' ? ethers_1.ethers.getAddress(raw.to) : null,
|
|
263
|
+
type: Number(rawQuantity(raw.type ?? 0, 'type')),
|
|
264
|
+
data: typeof raw.input === 'string' ? raw.input : '0x',
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Reads a transaction with ethers, or with the raw RPC when ethers cannot format it for missing
|
|
269
|
+
* signature fields, as {@link getBlockByHeight} does for a block.
|
|
270
|
+
*/
|
|
271
|
+
async function readTransaction(api, txHash, logger) {
|
|
272
|
+
try {
|
|
273
|
+
return await api.getTransaction(txHash);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (!isSignatureError(error))
|
|
277
|
+
throw error;
|
|
278
|
+
logger('warn', 'EVM getTransaction fallback: using raw eth_getTransactionByHash response', {
|
|
279
|
+
txHash,
|
|
280
|
+
error: String(error),
|
|
281
|
+
});
|
|
282
|
+
return getTransactionFromRawRpc(api, txHash);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
230
285
|
async function getTransaction(api, txHash, logger) {
|
|
231
286
|
// Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
|
|
232
287
|
// extra fields that contain L1 fees.
|
|
233
288
|
// A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
|
|
234
289
|
const [tx, rawReceipt] = await Promise.all([
|
|
235
|
-
api
|
|
290
|
+
readTransaction(api, txHash, logger),
|
|
236
291
|
api.send('eth_getTransactionReceipt', [txHash]),
|
|
237
292
|
]);
|
|
238
293
|
if (!tx || !(0, predicates_1.isTransactionReceipt)(rawReceipt)) {
|
|
239
|
-
throw new
|
|
294
|
+
throw new errors_1.NodeTransactionNotFound('Transaction or receipt not found', { txHash });
|
|
240
295
|
}
|
|
241
296
|
const receipt = rawReceipt;
|
|
242
297
|
const raw = recordOf(receipt);
|
|
@@ -425,7 +480,7 @@ async function broadcastTransaction(api, signedTxHex, logger) {
|
|
|
425
480
|
*/
|
|
426
481
|
function assertNotStubBlock(blockHeight, height, timestampInSeconds) {
|
|
427
482
|
if (height > 0 && timestampInSeconds === 0) {
|
|
428
|
-
throw new
|
|
483
|
+
throw new errors_1.NodeBlockNotFound(`Block ${blockHeight} not found (the node returned an empty stub block)`, { blockHeight });
|
|
429
484
|
}
|
|
430
485
|
}
|
|
431
486
|
async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
@@ -446,11 +501,11 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
446
501
|
throw error;
|
|
447
502
|
}
|
|
448
503
|
if (!block) {
|
|
449
|
-
throw new
|
|
504
|
+
throw new errors_1.NodeBlockNotFound(`Block ${blockHeight} not found`, { blockHeight });
|
|
450
505
|
}
|
|
451
506
|
assertNotStubBlock(blockHeight, block.number, block.timestamp);
|
|
452
507
|
if (!block.hash) {
|
|
453
|
-
throw new
|
|
508
|
+
throw new errors_1.MalformedNodeResponse(`Block ${blockHeight} is missing hash`);
|
|
454
509
|
}
|
|
455
510
|
const transactionHashes = block.transactions === undefined
|
|
456
511
|
? undefined
|
|
@@ -463,7 +518,7 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
463
518
|
const prefetchedTransactions = prefetchTxs ? getPrefetchedBlockTransactions(block) : undefined;
|
|
464
519
|
const transactions = prefetchedTransactions?.map((tx, index) => {
|
|
465
520
|
if (!isPrefetchedBlockTransaction(tx))
|
|
466
|
-
throw new
|
|
521
|
+
throw new errors_1.MalformedNodeResponse(`Block ${blockHeight} contains malformed prefetched transaction at index ${index}`);
|
|
467
522
|
const data = tx.data;
|
|
468
523
|
return {
|
|
469
524
|
hash: tx.hash,
|
|
@@ -489,7 +544,7 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
489
544
|
...(transactionHashes !== undefined && { transactionHashes }),
|
|
490
545
|
};
|
|
491
546
|
}
|
|
492
|
-
/** Specific error thrown by ethers when
|
|
547
|
+
/** Specific error thrown by ethers when formatting zkSync transactions with missing signature fields */
|
|
493
548
|
function isSignatureError(error) {
|
|
494
549
|
if (!(0, rpc_errors_1.hasErrorCode)(error, 'INVALID_ARGUMENT'))
|
|
495
550
|
return false;
|
|
@@ -508,7 +563,7 @@ function parseRpcHexQuantity(value, fieldName) {
|
|
|
508
563
|
return value;
|
|
509
564
|
if (typeof value === 'string')
|
|
510
565
|
return Number(BigInt(value));
|
|
511
|
-
throw new
|
|
566
|
+
throw new errors_1.MalformedNodeResponse(`Malformed ${fieldName} in eth_getBlockByNumber response`);
|
|
512
567
|
}
|
|
513
568
|
/**
|
|
514
569
|
* Fallback implementation of {@link getBlockByHeight} using raw RPC call to eth_getBlockByNumber, to handle cases where
|
|
@@ -519,50 +574,50 @@ async function getBlockByHeightFromRawRpc(api, blockHeight, prefetchTxs) {
|
|
|
519
574
|
const blockTag = typeof blockHeight === 'number' ? ethers_1.ethers.toQuantity(blockHeight) : blockHeight;
|
|
520
575
|
const rawBlock = await api.send('eth_getBlockByNumber', [blockTag, prefetchTxs]);
|
|
521
576
|
if (!(0, predicates_1.isRecord)(rawBlock))
|
|
522
|
-
throw new
|
|
577
|
+
throw new errors_1.MalformedNodeResponse('Invalid eth_getBlockByNumber response');
|
|
523
578
|
const block = rawBlock;
|
|
524
579
|
if (typeof block.hash !== 'string')
|
|
525
|
-
throw new
|
|
580
|
+
throw new errors_1.MalformedNodeResponse('Malformed block hash in eth_getBlockByNumber');
|
|
526
581
|
if (typeof block.parentHash !== 'string')
|
|
527
|
-
throw new
|
|
582
|
+
throw new errors_1.MalformedNodeResponse('Malformed block parentHash in eth_getBlockByNumber');
|
|
528
583
|
const height = parseRpcHexQuantity(block.number, 'block.number');
|
|
529
584
|
const timestampInSeconds = parseRpcHexQuantity(block.timestamp, 'block.timestamp');
|
|
530
585
|
assertNotStubBlock(blockHeight, height, timestampInSeconds);
|
|
531
586
|
const rawTransactions = block.transactions;
|
|
532
587
|
if (rawTransactions !== undefined && !Array.isArray(rawTransactions))
|
|
533
|
-
throw new
|
|
588
|
+
throw new errors_1.MalformedNodeResponse('Malformed block.transactions in eth_getBlockByNumber response');
|
|
534
589
|
const transactionHashes = rawTransactions?.map((tx, index) => {
|
|
535
590
|
if (typeof tx === 'string')
|
|
536
591
|
return tx;
|
|
537
592
|
if (typeof tx === 'object' && tx !== null && 'hash' in tx && typeof tx.hash === 'string')
|
|
538
593
|
return tx.hash;
|
|
539
|
-
throw new
|
|
594
|
+
throw new errors_1.MalformedNodeResponse(`Malformed block transaction at index ${index} in eth_getBlockByNumber response`);
|
|
540
595
|
});
|
|
541
596
|
const transactions = prefetchTxs && rawTransactions
|
|
542
597
|
? rawTransactions.map((tx) => {
|
|
543
598
|
if (typeof tx === 'string')
|
|
544
|
-
throw new
|
|
599
|
+
throw new errors_1.MalformedNodeResponse('Expected prefetched transaction object, got hash string');
|
|
545
600
|
if (typeof tx !== 'object' || tx === null)
|
|
546
|
-
throw new
|
|
601
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction in eth_getBlockByNumber response');
|
|
547
602
|
if (!('hash' in tx) || typeof tx.hash !== 'string')
|
|
548
|
-
throw new
|
|
603
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction hash in eth_getBlockByNumber response');
|
|
549
604
|
if (!('from' in tx) || typeof tx.from !== 'string')
|
|
550
|
-
throw new
|
|
605
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction from in eth_getBlockByNumber response');
|
|
551
606
|
if ('to' in tx && tx.to !== null && tx.to !== undefined && typeof tx.to !== 'string')
|
|
552
|
-
throw new
|
|
607
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction to in eth_getBlockByNumber response');
|
|
553
608
|
if ('value' in tx && tx.value !== undefined && typeof tx.value !== 'string')
|
|
554
|
-
throw new
|
|
609
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction value in eth_getBlockByNumber response');
|
|
555
610
|
if ('gasPrice' in tx && tx.gasPrice !== undefined && typeof tx.gasPrice !== 'string')
|
|
556
|
-
throw new
|
|
611
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction gasPrice in eth_getBlockByNumber response');
|
|
557
612
|
if ('gas' in tx && tx.gas !== undefined && typeof tx.gas !== 'string')
|
|
558
|
-
throw new
|
|
613
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction gas in eth_getBlockByNumber response');
|
|
559
614
|
if ('nonce' in tx && tx.nonce !== undefined && typeof tx.nonce !== 'string')
|
|
560
|
-
throw new
|
|
615
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction nonce in eth_getBlockByNumber response');
|
|
561
616
|
if ('input' in tx &&
|
|
562
617
|
tx.input !== undefined &&
|
|
563
618
|
tx.input !== null &&
|
|
564
619
|
typeof tx.input !== 'string')
|
|
565
|
-
throw new
|
|
620
|
+
throw new errors_1.MalformedNodeResponse('Malformed prefetched transaction input in eth_getBlockByNumber response');
|
|
566
621
|
return {
|
|
567
622
|
hash: tx.hash,
|
|
568
623
|
value: BigInt(tx.value ?? '0x0').toString(),
|
|
@@ -606,10 +661,10 @@ async function getBlockReceipts(api, blockHeight, logger) {
|
|
|
606
661
|
throw error;
|
|
607
662
|
}
|
|
608
663
|
if (!Array.isArray(receipts))
|
|
609
|
-
throw new
|
|
664
|
+
throw new errors_1.MalformedNodeResponse('Invalid eth_getBlockReceipts response');
|
|
610
665
|
return receipts.map((receipt, index) => {
|
|
611
666
|
if (!(0, predicates_1.isTransactionReceipt)(receipt))
|
|
612
|
-
throw new
|
|
667
|
+
throw new errors_1.MalformedNodeResponse(`Malformed eth_getBlockReceipts response at index ${index}`);
|
|
613
668
|
const raw = recordOf(receipt);
|
|
614
669
|
const contractAddressRaw = raw.contractAddress;
|
|
615
670
|
const contractAddress = typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
|
|
@@ -645,7 +700,7 @@ async function traceBlockGeth(api, blockHeight) {
|
|
|
645
700
|
throw error;
|
|
646
701
|
});
|
|
647
702
|
if (!Array.isArray(debugResults))
|
|
648
|
-
throw new
|
|
703
|
+
throw new errors_1.MalformedNodeResponse('Invalid debug_traceBlockByNumber response');
|
|
649
704
|
return normalizeTraceBlockItems((0, gethCallTracerToTraceBlockItems_1.gethCallTracerToTraceBlockItems)(blockHeight, debugResults));
|
|
650
705
|
}
|
|
651
706
|
async function traceBlockErigon(api, blockHeight) {
|
|
@@ -663,10 +718,10 @@ async function traceBlockErigon(api, blockHeight) {
|
|
|
663
718
|
}
|
|
664
719
|
function normalizeTraceBlockItems(traces) {
|
|
665
720
|
if (!Array.isArray(traces))
|
|
666
|
-
throw new
|
|
721
|
+
throw new errors_1.MalformedNodeResponse('Invalid trace block response');
|
|
667
722
|
return traces.map((trace, index) => {
|
|
668
723
|
if (!(0, predicates_1.isTraceBlockItem)(trace)) {
|
|
669
|
-
throw new
|
|
724
|
+
throw new errors_1.MalformedNodeResponse(`Malformed trace block response at index ${index} ${JSON.stringify(trace)}`);
|
|
670
725
|
}
|
|
671
726
|
return trace;
|
|
672
727
|
});
|
|
@@ -674,7 +729,7 @@ function normalizeTraceBlockItems(traces) {
|
|
|
674
729
|
function recordOf(value) {
|
|
675
730
|
if ((0, predicates_1.isRecord)(value))
|
|
676
731
|
return value;
|
|
677
|
-
throw new
|
|
732
|
+
throw new errors_1.MalformedNodeResponse('expected object');
|
|
678
733
|
}
|
|
679
734
|
function isPrefetchedBlockTransaction(value) {
|
|
680
735
|
if (!(0, predicates_1.isRecord)(value))
|