@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,201 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { promiseAllBatched } from '@ledgerhq/coin-module-framework/promises';
|
|
4
|
+
import { makeLRUCache } from '@ledgerhq/live-network/cache';
|
|
5
|
+
import { getNodeApi } from '../network/node';
|
|
6
|
+
// Receipts read in parallel, as getBlock does for transactions it fetches one by one
|
|
7
|
+
const MAX_RECEIPT_CONCURRENCY = 2;
|
|
8
|
+
/**
|
|
9
|
+
* True when a transfer moves the fee: a positive amount of the native coin, as a native transfer
|
|
10
|
+
* or as one of the network's `feeCollectorTokens` (the zkSync base token). Another token sent to a
|
|
11
|
+
* fee collector does not pay the fee.
|
|
12
|
+
*
|
|
13
|
+
* @param feeCollectorTokens lower-cased `feeCollectorTokens` of the network
|
|
14
|
+
*/
|
|
15
|
+
function isFeePayment(asset, amount, feeCollectorTokens) {
|
|
16
|
+
if (amount <= 0n)
|
|
17
|
+
return false;
|
|
18
|
+
if (asset.type === 'native')
|
|
19
|
+
return true;
|
|
20
|
+
return (asset.assetReference !== undefined && feeCollectorTokens.has(asset.assetReference.toLowerCase()));
|
|
21
|
+
}
|
|
22
|
+
function lowerCased(addresses) {
|
|
23
|
+
return new Set((addresses ?? []).map((address) => address.toLowerCase()));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The ERC-20 transfers of a transaction, from its receipt. A mined transaction keeps them, so each
|
|
27
|
+
* receipt is read once: a sync of the whole history does not read the receipts of the transactions
|
|
28
|
+
* paid by others again. Kept per chain and transaction, before any network setting applies. A
|
|
29
|
+
* failed read is not kept.
|
|
30
|
+
*/
|
|
31
|
+
export const readReceiptTransfers = makeLRUCache(async (config, logger, hash) => {
|
|
32
|
+
const { erc20Transfers } = await getNodeApi(config, logger).getTransaction(hash);
|
|
33
|
+
return erc20Transfers;
|
|
34
|
+
}, (config, _logger, hash) => `${config.chainId}:${hash}`, { max: 10_000, ttl: 24 * 60 * 60 * 1000 });
|
|
35
|
+
/**
|
|
36
|
+
* The accounts that sent the network's fee collectors a fee payment in a transaction (see
|
|
37
|
+
* {@link isFeePayment}), lowercase, from its receipt.
|
|
38
|
+
*/
|
|
39
|
+
async function findFeeCollectorPrepayers(config, logger, hash) {
|
|
40
|
+
const collectors = lowerCased(config.feeCollectorContracts);
|
|
41
|
+
const tokens = lowerCased(config.feeCollectorTokens);
|
|
42
|
+
const transfers = await readReceiptTransfers(config, logger, hash);
|
|
43
|
+
return transfers
|
|
44
|
+
.filter((transfer) => collectors.has(transfer.to.toLowerCase()) &&
|
|
45
|
+
isFeePayment(transfer.asset, BigInt(transfer.value), tokens))
|
|
46
|
+
.map((transfer) => transfer.from.toLowerCase());
|
|
47
|
+
}
|
|
48
|
+
function addressMatchers(address, feeCollectorContracts) {
|
|
49
|
+
const account = address.toLowerCase();
|
|
50
|
+
const collectors = new Set(feeCollectorContracts.map((contract) => contract.toLowerCase()));
|
|
51
|
+
return {
|
|
52
|
+
isAccount: (other) => other.toLowerCase() === account,
|
|
53
|
+
isCollector: (other) => collectors.has(other.toLowerCase()),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The account, as the explorer spells it (EIP-55), by hash of the transactions its history shows
|
|
58
|
+
* it paid: a fee payment from the account to a fee collector (see {@link isFeePayment}), on zkSync
|
|
59
|
+
* the base-token (`0x800A`, a `feeCollectorTokens` entry) prepayment to the bootloader.
|
|
60
|
+
*/
|
|
61
|
+
function findPrepayments(address, feeCollectorContracts, feeCollectorTokens, evidence) {
|
|
62
|
+
const { isAccount, isCollector } = addressMatchers(address, feeCollectorContracts);
|
|
63
|
+
const tokens = lowerCased(feeCollectorTokens);
|
|
64
|
+
const payers = new Map();
|
|
65
|
+
for (const op of evidence) {
|
|
66
|
+
const sender = op.senders.find(isAccount);
|
|
67
|
+
if (sender === undefined || !op.recipients.some(isCollector))
|
|
68
|
+
continue;
|
|
69
|
+
if (isFeePayment(op.asset, op.value, tokens))
|
|
70
|
+
payers.set(op.tx.hash, sender);
|
|
71
|
+
}
|
|
72
|
+
return payers;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Finds the transactions whose fee the explorer charges to the account but that another account
|
|
76
|
+
* paid, on a network that collects the fee in a contract (see `feeCollectorContracts`).
|
|
77
|
+
*
|
|
78
|
+
* The explorer names the sender as the fee payer. When the account history has no prepayment of
|
|
79
|
+
* the account to a fee collector for such a transaction, its receipt tells who paid: a zkSync
|
|
80
|
+
* paymaster prepays the fee to the bootloader, and an L1→L2 deposit pays it on L1. A transaction
|
|
81
|
+
* whose receipt cannot be read keeps the explorer's fee payer.
|
|
82
|
+
*
|
|
83
|
+
* @param operations operations of the account, as listOperations returns them
|
|
84
|
+
* @param evidence the token, NFT and internal operations of the account from the explorer
|
|
85
|
+
* @returns hashes of the transactions the account did not pay
|
|
86
|
+
*/
|
|
87
|
+
export async function findTransactionsPaidByOthers(config, logger, address, operations, evidence) {
|
|
88
|
+
const feeCollectorContracts = config.feeCollectorContracts ?? [];
|
|
89
|
+
if (feeCollectorContracts.length === 0)
|
|
90
|
+
return new Set();
|
|
91
|
+
const { isAccount } = addressMatchers(address, feeCollectorContracts);
|
|
92
|
+
const prepayments = findPrepayments(address, feeCollectorContracts, config.feeCollectorTokens ?? [], evidence);
|
|
93
|
+
const unconfirmed = [
|
|
94
|
+
...new Set(operations
|
|
95
|
+
.filter((op) => op.tx.feesPayer !== undefined && isAccount(op.tx.feesPayer))
|
|
96
|
+
.map((op) => op.tx.hash)
|
|
97
|
+
.filter((hash) => !prepayments.has(hash))),
|
|
98
|
+
];
|
|
99
|
+
if (unconfirmed.length === 0)
|
|
100
|
+
return new Set();
|
|
101
|
+
const paidByOthers = await promiseAllBatched(MAX_RECEIPT_CONCURRENCY, unconfirmed, async (hash) => {
|
|
102
|
+
try {
|
|
103
|
+
const prepayers = await findFeeCollectorPrepayers(config, logger, hash);
|
|
104
|
+
return prepayers.some(isAccount) ? undefined : hash;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
logger('warn', 'EVM listOperations: cannot read the receipt to find the fee payer', {
|
|
108
|
+
currency: config.name,
|
|
109
|
+
hash,
|
|
110
|
+
error,
|
|
111
|
+
});
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return new Set(paidByOthers.filter((hash) => hash !== undefined));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gives the operations of an account the fee payer seen from the account's own history, on a
|
|
119
|
+
* network that collects the fee in a contract (see `feeCollectorContracts`, e.g. the zkSync
|
|
120
|
+
* bootloader).
|
|
121
|
+
*
|
|
122
|
+
* The account paid the fee of a transaction when its history has a transfer from the account to a
|
|
123
|
+
* fee collector in that transaction (see {@link findPrepayments}):
|
|
124
|
+
* - a paying account is the `feesPayer` of all its operations of the transaction, which carry
|
|
125
|
+
* the fee of the transaction, from whichever of its operations knows it;
|
|
126
|
+
* - an account that another account paid for (see {@link findTransactionsPaidByOthers}) is never
|
|
127
|
+
* the `feesPayer`: ADR-016 leaves the payer unset when it is unknown, rather than defaulting
|
|
128
|
+
* to the sender.
|
|
129
|
+
*
|
|
130
|
+
* The internal native transfers between a paying account and a fee collector move the fee, which
|
|
131
|
+
* `fees` holds: keeping them would debit the account twice, so they are dropped when another
|
|
132
|
+
* operation of the transaction gives the fee. Internal operations carry none, so without one the
|
|
133
|
+
* native transfers stay, as the only trace of what the account paid. When one was the only
|
|
134
|
+
* operation of the transaction for the account, a value-0 `FEES` operation carries the fee
|
|
135
|
+
* instead, as ADR-016 allows.
|
|
136
|
+
*
|
|
137
|
+
* The fee also moves as base-token transfers (zkSync `0x800A`), which stay as token operations,
|
|
138
|
+
* as `getBlock` keeps them (BACK-11036). ADR-068 (proposed) would remove fee movements in every
|
|
139
|
+
* asset, behind an opt-in option; this function does not follow it.
|
|
140
|
+
*
|
|
141
|
+
* @param operations operations of the account, as listOperations returns them
|
|
142
|
+
* @param address the account
|
|
143
|
+
* @param feeCollectorContracts fee collector contracts of the network
|
|
144
|
+
* @param feeCollectorTokens tokens that carry the native coin to those contracts
|
|
145
|
+
* @param evidence the token, NFT and internal operations of the account from the explorer, before
|
|
146
|
+
* listOperations drops any of them
|
|
147
|
+
* @param paidByOthers hashes of the transactions the account did not pay
|
|
148
|
+
*/
|
|
149
|
+
export function attributeFeeCollectorPayments(operations, address, feeCollectorContracts, feeCollectorTokens, evidence, paidByOthers) {
|
|
150
|
+
if (feeCollectorContracts.length === 0)
|
|
151
|
+
return operations;
|
|
152
|
+
const { isAccount, isCollector } = addressMatchers(address, feeCollectorContracts);
|
|
153
|
+
const payers = findPrepayments(address, feeCollectorContracts, feeCollectorTokens, evidence);
|
|
154
|
+
const feesByHash = new Map();
|
|
155
|
+
for (const op of [...operations, ...evidence]) {
|
|
156
|
+
if (op.tx.fees > (feesByHash.get(op.tx.hash) ?? 0n))
|
|
157
|
+
feesByHash.set(op.tx.hash, op.tx.fees);
|
|
158
|
+
}
|
|
159
|
+
// Only the payer's transfers move the fee: a refund to an account that did not pay, such as the
|
|
160
|
+
// refund recipient of an L1→L2 deposit, is a real credit
|
|
161
|
+
const isFeeLeg = (op) => payers.has(op.tx.hash) &&
|
|
162
|
+
feesByHash.has(op.tx.hash) &&
|
|
163
|
+
op.asset.type === 'native' &&
|
|
164
|
+
((op.senders.some(isAccount) && op.recipients.some(isCollector)) ||
|
|
165
|
+
(op.senders.some(isCollector) && op.recipients.some(isAccount)));
|
|
166
|
+
const feeLegs = operations.filter(isFeeLeg);
|
|
167
|
+
const kept = operations.filter((op) => !isFeeLeg(op));
|
|
168
|
+
const attributed = kept.map((op) => {
|
|
169
|
+
const payer = payers.get(op.tx.hash);
|
|
170
|
+
if (payer !== undefined) {
|
|
171
|
+
const fees = feesByHash.get(op.tx.hash) ?? op.tx.fees;
|
|
172
|
+
return { ...op, tx: { ...op.tx, fees, feesPayer: payer } };
|
|
173
|
+
}
|
|
174
|
+
if (!paidByOthers.has(op.tx.hash) ||
|
|
175
|
+
op.tx.feesPayer === undefined ||
|
|
176
|
+
!isAccount(op.tx.feesPayer)) {
|
|
177
|
+
return op;
|
|
178
|
+
}
|
|
179
|
+
const { feesPayer: _notThePayer, ...tx } = op.tx;
|
|
180
|
+
return { ...op, tx };
|
|
181
|
+
});
|
|
182
|
+
const keptHashes = new Set(kept.map((op) => op.tx.hash));
|
|
183
|
+
const carriers = new Map();
|
|
184
|
+
for (const leg of feeLegs) {
|
|
185
|
+
if (keptHashes.has(leg.tx.hash) || carriers.has(leg.tx.hash))
|
|
186
|
+
continue;
|
|
187
|
+
carriers.set(leg.tx.hash, {
|
|
188
|
+
...leg,
|
|
189
|
+
id: `${leg.id}-FEES`,
|
|
190
|
+
type: 'FEES',
|
|
191
|
+
value: 0n,
|
|
192
|
+
tx: {
|
|
193
|
+
...leg.tx,
|
|
194
|
+
fees: feesByHash.get(leg.tx.hash) ?? 0n,
|
|
195
|
+
feesPayer: payers.get(leg.tx.hash) ?? leg.senders[0],
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return [...attributed, ...carriers.values()];
|
|
200
|
+
}
|
|
201
|
+
//# 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;AAMtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;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;QAAE,OAAO,IAAI,CAAA;IACxC,OAAO,CACL,KAAK,CAAC,cAAc,KAAK,SAAS,IAAI,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,C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rD;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"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { InvalidParameterError } from '@ledgerhq/coin-module-framework/errors';
|
|
4
4
|
import { getExplorerApi } from '../network/explorer';
|
|
5
|
+
import { attributeFeeCollectorPayments, findTransactionsPaidByOthers, } from './feeCollectorOperations';
|
|
5
6
|
// the sort parameter has a double meaning:
|
|
6
7
|
// - legacy (for the bridge): it's used to sort the operations in the result list. Explorer always queried in "desc" order.
|
|
7
8
|
// - new: it's used to sort AND query the explorer with the correct order.
|
|
@@ -205,11 +206,13 @@ export async function listOperations(context, address, options) {
|
|
|
205
206
|
}));
|
|
206
207
|
const nativeExpanded = expandSelfSendToTwoOps(nativeWithPerspective, address);
|
|
207
208
|
const tokenExpanded = expandSelfSendToTwoOps(tokenOperations, address);
|
|
208
|
-
const
|
|
209
|
+
const accountOperations = nativeExpanded
|
|
209
210
|
.concat(tokenExpanded)
|
|
210
211
|
.concat(internalOperations)
|
|
211
212
|
.filter(hasValidType)
|
|
212
213
|
.filter(isAddressInvolved);
|
|
214
|
+
const feeEvidence = [...lastTokenOperations, ...lastNftOperations, ...lastInternalOperations];
|
|
215
|
+
const operations = attributeFeeCollectorPayments(accountOperations, address, config.feeCollectorContracts ?? [], config.feeCollectorTokens ?? [], feeEvidence, await findTransactionsPaidByOthers(config, context.logger, address, accountOperations, feeEvidence));
|
|
213
216
|
operations.sort((a, b) => options.order === 'asc'
|
|
214
217
|
? a.tx.date.getTime() - b.tx.date.getTime()
|
|
215
218
|
: 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;AAStC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAStC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,0BAA0B,CAAA;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;I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AA;IAED,OAAO,EAAE,KAAK,EAAE,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"}
|
|
@@ -8,7 +8,7 @@ import ERC20Abi from '../../abis/erc20.abi.json';
|
|
|
8
8
|
import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.json';
|
|
9
9
|
import ScrollGasPriceOracleAbi from '../../abis/scrollGasPriceOracle.abi.json';
|
|
10
10
|
import { CHAIN_ID, OP_STACK_L1_FEE_CHAIN_IDS } from '../../config';
|
|
11
|
-
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors';
|
|
11
|
+
import { GasEstimationError, InsufficientFunds, MalformedNodeResponse, NodeBlockNotFound, NodeTransactionNotFound, UnsupportedRpcMethodError, } from '../../errors';
|
|
12
12
|
import { isSmartContractInput, safeEncodeEIP55, normalizeAddress } from '../../logic-public';
|
|
13
13
|
import { isOptionalQuantity, isOptionalString, isQuantity, isRecord, isString, isTraceBlockItem, isTransactionReceipt, } from '../../logic/predicates';
|
|
14
14
|
import { withRetries } from '../withRetries';
|
|
@@ -217,16 +217,71 @@ function parseReceiptL1Fee(raw) {
|
|
|
217
217
|
const l1Fee = raw.l1Fee;
|
|
218
218
|
return typeof l1Fee === 'string' ? BigInt(l1Fee).toString() : undefined;
|
|
219
219
|
}
|
|
220
|
+
function rawQuantity(value, fieldName) {
|
|
221
|
+
if (typeof value === 'string' || typeof value === 'number')
|
|
222
|
+
return BigInt(value);
|
|
223
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`);
|
|
224
|
+
}
|
|
225
|
+
function rawString(value, fieldName) {
|
|
226
|
+
if (typeof value === 'string')
|
|
227
|
+
return value;
|
|
228
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Reads a transaction with the raw `eth_getTransactionByHash`, for a transaction ethers cannot
|
|
232
|
+
* format: zkSync L1→L2 deposits (type `0xff`) have no signature fields.
|
|
233
|
+
*/
|
|
234
|
+
async function getTransactionFromRawRpc(api, txHash) {
|
|
235
|
+
const raw = await api.send('eth_getTransactionByHash', [txHash]);
|
|
236
|
+
if (raw === null || raw === undefined)
|
|
237
|
+
return null;
|
|
238
|
+
if (!isRecord(raw))
|
|
239
|
+
throw new MalformedNodeResponse('Invalid eth_getTransactionByHash response');
|
|
240
|
+
const blockNumber = raw.blockNumber;
|
|
241
|
+
return {
|
|
242
|
+
hash: rawString(raw.hash, 'hash'),
|
|
243
|
+
blockNumber: blockNumber === null || blockNumber === undefined
|
|
244
|
+
? null
|
|
245
|
+
: Number(rawQuantity(blockNumber, 'blockNumber')),
|
|
246
|
+
blockHash: typeof raw.blockHash === 'string' ? raw.blockHash : null,
|
|
247
|
+
nonce: Number(rawQuantity(raw.nonce, 'nonce')),
|
|
248
|
+
gasLimit: rawQuantity(raw.gas, 'gas'),
|
|
249
|
+
value: rawQuantity(raw.value, 'value'),
|
|
250
|
+
// Checksummed, as ethers gives them
|
|
251
|
+
from: ethers.getAddress(rawString(raw.from, 'from')),
|
|
252
|
+
to: typeof raw.to === 'string' ? ethers.getAddress(raw.to) : null,
|
|
253
|
+
type: Number(rawQuantity(raw.type ?? 0, 'type')),
|
|
254
|
+
data: typeof raw.input === 'string' ? raw.input : '0x',
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Reads a transaction with ethers, or with the raw RPC when ethers cannot format it for missing
|
|
259
|
+
* signature fields, as {@link getBlockByHeight} does for a block.
|
|
260
|
+
*/
|
|
261
|
+
async function readTransaction(api, txHash, logger) {
|
|
262
|
+
try {
|
|
263
|
+
return await api.getTransaction(txHash);
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
if (!isSignatureError(error))
|
|
267
|
+
throw error;
|
|
268
|
+
logger('warn', 'EVM getTransaction fallback: using raw eth_getTransactionByHash response', {
|
|
269
|
+
txHash,
|
|
270
|
+
error: String(error),
|
|
271
|
+
});
|
|
272
|
+
return getTransactionFromRawRpc(api, txHash);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
220
275
|
async function getTransaction(api, txHash, logger) {
|
|
221
276
|
// Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
|
|
222
277
|
// extra fields that contain L1 fees.
|
|
223
278
|
// A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
|
|
224
279
|
const [tx, rawReceipt] = await Promise.all([
|
|
225
|
-
api
|
|
280
|
+
readTransaction(api, txHash, logger),
|
|
226
281
|
api.send('eth_getTransactionReceipt', [txHash]),
|
|
227
282
|
]);
|
|
228
283
|
if (!tx || !isTransactionReceipt(rawReceipt)) {
|
|
229
|
-
throw new
|
|
284
|
+
throw new NodeTransactionNotFound('Transaction or receipt not found', { txHash });
|
|
230
285
|
}
|
|
231
286
|
const receipt = rawReceipt;
|
|
232
287
|
const raw = recordOf(receipt);
|
|
@@ -415,7 +470,7 @@ async function broadcastTransaction(api, signedTxHex, logger) {
|
|
|
415
470
|
*/
|
|
416
471
|
function assertNotStubBlock(blockHeight, height, timestampInSeconds) {
|
|
417
472
|
if (height > 0 && timestampInSeconds === 0) {
|
|
418
|
-
throw new
|
|
473
|
+
throw new NodeBlockNotFound(`Block ${blockHeight} not found (the node returned an empty stub block)`, { blockHeight });
|
|
419
474
|
}
|
|
420
475
|
}
|
|
421
476
|
async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
@@ -436,11 +491,11 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
436
491
|
throw error;
|
|
437
492
|
}
|
|
438
493
|
if (!block) {
|
|
439
|
-
throw new
|
|
494
|
+
throw new NodeBlockNotFound(`Block ${blockHeight} not found`, { blockHeight });
|
|
440
495
|
}
|
|
441
496
|
assertNotStubBlock(blockHeight, block.number, block.timestamp);
|
|
442
497
|
if (!block.hash) {
|
|
443
|
-
throw new
|
|
498
|
+
throw new MalformedNodeResponse(`Block ${blockHeight} is missing hash`);
|
|
444
499
|
}
|
|
445
500
|
const transactionHashes = block.transactions === undefined
|
|
446
501
|
? undefined
|
|
@@ -453,7 +508,7 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
453
508
|
const prefetchedTransactions = prefetchTxs ? getPrefetchedBlockTransactions(block) : undefined;
|
|
454
509
|
const transactions = prefetchedTransactions?.map((tx, index) => {
|
|
455
510
|
if (!isPrefetchedBlockTransaction(tx))
|
|
456
|
-
throw new
|
|
511
|
+
throw new MalformedNodeResponse(`Block ${blockHeight} contains malformed prefetched transaction at index ${index}`);
|
|
457
512
|
const data = tx.data;
|
|
458
513
|
return {
|
|
459
514
|
hash: tx.hash,
|
|
@@ -479,7 +534,7 @@ async function getBlockByHeight(api, blockHeight, logger, prefetchTxs) {
|
|
|
479
534
|
...(transactionHashes !== undefined && { transactionHashes }),
|
|
480
535
|
};
|
|
481
536
|
}
|
|
482
|
-
/** Specific error thrown by ethers when
|
|
537
|
+
/** Specific error thrown by ethers when formatting zkSync transactions with missing signature fields */
|
|
483
538
|
function isSignatureError(error) {
|
|
484
539
|
if (!hasErrorCode(error, 'INVALID_ARGUMENT'))
|
|
485
540
|
return false;
|
|
@@ -498,7 +553,7 @@ function parseRpcHexQuantity(value, fieldName) {
|
|
|
498
553
|
return value;
|
|
499
554
|
if (typeof value === 'string')
|
|
500
555
|
return Number(BigInt(value));
|
|
501
|
-
throw new
|
|
556
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getBlockByNumber response`);
|
|
502
557
|
}
|
|
503
558
|
/**
|
|
504
559
|
* Fallback implementation of {@link getBlockByHeight} using raw RPC call to eth_getBlockByNumber, to handle cases where
|
|
@@ -509,50 +564,50 @@ async function getBlockByHeightFromRawRpc(api, blockHeight, prefetchTxs) {
|
|
|
509
564
|
const blockTag = typeof blockHeight === 'number' ? ethers.toQuantity(blockHeight) : blockHeight;
|
|
510
565
|
const rawBlock = await api.send('eth_getBlockByNumber', [blockTag, prefetchTxs]);
|
|
511
566
|
if (!isRecord(rawBlock))
|
|
512
|
-
throw new
|
|
567
|
+
throw new MalformedNodeResponse('Invalid eth_getBlockByNumber response');
|
|
513
568
|
const block = rawBlock;
|
|
514
569
|
if (typeof block.hash !== 'string')
|
|
515
|
-
throw new
|
|
570
|
+
throw new MalformedNodeResponse('Malformed block hash in eth_getBlockByNumber');
|
|
516
571
|
if (typeof block.parentHash !== 'string')
|
|
517
|
-
throw new
|
|
572
|
+
throw new MalformedNodeResponse('Malformed block parentHash in eth_getBlockByNumber');
|
|
518
573
|
const height = parseRpcHexQuantity(block.number, 'block.number');
|
|
519
574
|
const timestampInSeconds = parseRpcHexQuantity(block.timestamp, 'block.timestamp');
|
|
520
575
|
assertNotStubBlock(blockHeight, height, timestampInSeconds);
|
|
521
576
|
const rawTransactions = block.transactions;
|
|
522
577
|
if (rawTransactions !== undefined && !Array.isArray(rawTransactions))
|
|
523
|
-
throw new
|
|
578
|
+
throw new MalformedNodeResponse('Malformed block.transactions in eth_getBlockByNumber response');
|
|
524
579
|
const transactionHashes = rawTransactions?.map((tx, index) => {
|
|
525
580
|
if (typeof tx === 'string')
|
|
526
581
|
return tx;
|
|
527
582
|
if (typeof tx === 'object' && tx !== null && 'hash' in tx && typeof tx.hash === 'string')
|
|
528
583
|
return tx.hash;
|
|
529
|
-
throw new
|
|
584
|
+
throw new MalformedNodeResponse(`Malformed block transaction at index ${index} in eth_getBlockByNumber response`);
|
|
530
585
|
});
|
|
531
586
|
const transactions = prefetchTxs && rawTransactions
|
|
532
587
|
? rawTransactions.map((tx) => {
|
|
533
588
|
if (typeof tx === 'string')
|
|
534
|
-
throw new
|
|
589
|
+
throw new MalformedNodeResponse('Expected prefetched transaction object, got hash string');
|
|
535
590
|
if (typeof tx !== 'object' || tx === null)
|
|
536
|
-
throw new
|
|
591
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction in eth_getBlockByNumber response');
|
|
537
592
|
if (!('hash' in tx) || typeof tx.hash !== 'string')
|
|
538
|
-
throw new
|
|
593
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction hash in eth_getBlockByNumber response');
|
|
539
594
|
if (!('from' in tx) || typeof tx.from !== 'string')
|
|
540
|
-
throw new
|
|
595
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction from in eth_getBlockByNumber response');
|
|
541
596
|
if ('to' in tx && tx.to !== null && tx.to !== undefined && typeof tx.to !== 'string')
|
|
542
|
-
throw new
|
|
597
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction to in eth_getBlockByNumber response');
|
|
543
598
|
if ('value' in tx && tx.value !== undefined && typeof tx.value !== 'string')
|
|
544
|
-
throw new
|
|
599
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction value in eth_getBlockByNumber response');
|
|
545
600
|
if ('gasPrice' in tx && tx.gasPrice !== undefined && typeof tx.gasPrice !== 'string')
|
|
546
|
-
throw new
|
|
601
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction gasPrice in eth_getBlockByNumber response');
|
|
547
602
|
if ('gas' in tx && tx.gas !== undefined && typeof tx.gas !== 'string')
|
|
548
|
-
throw new
|
|
603
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction gas in eth_getBlockByNumber response');
|
|
549
604
|
if ('nonce' in tx && tx.nonce !== undefined && typeof tx.nonce !== 'string')
|
|
550
|
-
throw new
|
|
605
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction nonce in eth_getBlockByNumber response');
|
|
551
606
|
if ('input' in tx &&
|
|
552
607
|
tx.input !== undefined &&
|
|
553
608
|
tx.input !== null &&
|
|
554
609
|
typeof tx.input !== 'string')
|
|
555
|
-
throw new
|
|
610
|
+
throw new MalformedNodeResponse('Malformed prefetched transaction input in eth_getBlockByNumber response');
|
|
556
611
|
return {
|
|
557
612
|
hash: tx.hash,
|
|
558
613
|
value: BigInt(tx.value ?? '0x0').toString(),
|
|
@@ -596,10 +651,10 @@ async function getBlockReceipts(api, blockHeight, logger) {
|
|
|
596
651
|
throw error;
|
|
597
652
|
}
|
|
598
653
|
if (!Array.isArray(receipts))
|
|
599
|
-
throw new
|
|
654
|
+
throw new MalformedNodeResponse('Invalid eth_getBlockReceipts response');
|
|
600
655
|
return receipts.map((receipt, index) => {
|
|
601
656
|
if (!isTransactionReceipt(receipt))
|
|
602
|
-
throw new
|
|
657
|
+
throw new MalformedNodeResponse(`Malformed eth_getBlockReceipts response at index ${index}`);
|
|
603
658
|
const raw = recordOf(receipt);
|
|
604
659
|
const contractAddressRaw = raw.contractAddress;
|
|
605
660
|
const contractAddress = typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
|
|
@@ -635,7 +690,7 @@ async function traceBlockGeth(api, blockHeight) {
|
|
|
635
690
|
throw error;
|
|
636
691
|
});
|
|
637
692
|
if (!Array.isArray(debugResults))
|
|
638
|
-
throw new
|
|
693
|
+
throw new MalformedNodeResponse('Invalid debug_traceBlockByNumber response');
|
|
639
694
|
return normalizeTraceBlockItems(gethCallTracerToTraceBlockItems(blockHeight, debugResults));
|
|
640
695
|
}
|
|
641
696
|
async function traceBlockErigon(api, blockHeight) {
|
|
@@ -653,10 +708,10 @@ async function traceBlockErigon(api, blockHeight) {
|
|
|
653
708
|
}
|
|
654
709
|
function normalizeTraceBlockItems(traces) {
|
|
655
710
|
if (!Array.isArray(traces))
|
|
656
|
-
throw new
|
|
711
|
+
throw new MalformedNodeResponse('Invalid trace block response');
|
|
657
712
|
return traces.map((trace, index) => {
|
|
658
713
|
if (!isTraceBlockItem(trace)) {
|
|
659
|
-
throw new
|
|
714
|
+
throw new MalformedNodeResponse(`Malformed trace block response at index ${index} ${JSON.stringify(trace)}`);
|
|
660
715
|
}
|
|
661
716
|
return trace;
|
|
662
717
|
});
|
|
@@ -664,7 +719,7 @@ function normalizeTraceBlockItems(traces) {
|
|
|
664
719
|
function recordOf(value) {
|
|
665
720
|
if (isRecord(value))
|
|
666
721
|
return value;
|
|
667
|
-
throw new
|
|
722
|
+
throw new MalformedNodeResponse('expected object');
|
|
668
723
|
}
|
|
669
724
|
function isPrefetchedBlockTransaction(value) {
|
|
670
725
|
if (!isRecord(value))
|