@ledgerhq/coin-tester-evm 1.6.0-nightly.8 → 1.6.0

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 (56) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +41 -59
  3. package/lib/src/helpers.d.ts +6 -6
  4. package/lib/src/helpers.d.ts.map +1 -1
  5. package/lib/src/helpers.js +11 -12
  6. package/lib/src/helpers.js.map +1 -1
  7. package/lib/src/indexer.d.ts.map +1 -1
  8. package/lib/src/indexer.js +184 -193
  9. package/lib/src/indexer.js.map +1 -1
  10. package/lib/src/scenarii/blast.d.ts.map +1 -1
  11. package/lib/src/scenarii/blast.js +8 -8
  12. package/lib/src/scenarii/blast.js.map +1 -1
  13. package/lib/src/scenarii/ethereum.d.ts.map +1 -1
  14. package/lib/src/scenarii/ethereum.js +10 -10
  15. package/lib/src/scenarii/ethereum.js.map +1 -1
  16. package/lib/src/scenarii/polygon.d.ts.map +1 -1
  17. package/lib/src/scenarii/polygon.js +11 -11
  18. package/lib/src/scenarii/polygon.js.map +1 -1
  19. package/lib/src/scenarii/scroll.d.ts.map +1 -1
  20. package/lib/src/scenarii/scroll.js +8 -8
  21. package/lib/src/scenarii/scroll.js.map +1 -1
  22. package/lib/src/scenarii/sonic.d.ts.map +1 -1
  23. package/lib/src/scenarii/sonic.js +8 -8
  24. package/lib/src/scenarii/sonic.js.map +1 -1
  25. package/lib/tsconfig.tsbuildinfo +1 -1
  26. package/lib-es/src/helpers.d.ts +6 -6
  27. package/lib-es/src/helpers.d.ts.map +1 -1
  28. package/lib-es/src/helpers.js +11 -12
  29. package/lib-es/src/helpers.js.map +1 -1
  30. package/lib-es/src/indexer.d.ts.map +1 -1
  31. package/lib-es/src/indexer.js +185 -194
  32. package/lib-es/src/indexer.js.map +1 -1
  33. package/lib-es/src/scenarii/blast.d.ts.map +1 -1
  34. package/lib-es/src/scenarii/blast.js +9 -9
  35. package/lib-es/src/scenarii/blast.js.map +1 -1
  36. package/lib-es/src/scenarii/ethereum.d.ts.map +1 -1
  37. package/lib-es/src/scenarii/ethereum.js +11 -11
  38. package/lib-es/src/scenarii/ethereum.js.map +1 -1
  39. package/lib-es/src/scenarii/polygon.d.ts.map +1 -1
  40. package/lib-es/src/scenarii/polygon.js +12 -12
  41. package/lib-es/src/scenarii/polygon.js.map +1 -1
  42. package/lib-es/src/scenarii/scroll.d.ts.map +1 -1
  43. package/lib-es/src/scenarii/scroll.js +9 -9
  44. package/lib-es/src/scenarii/scroll.js.map +1 -1
  45. package/lib-es/src/scenarii/sonic.d.ts.map +1 -1
  46. package/lib-es/src/scenarii/sonic.js +9 -9
  47. package/lib-es/src/scenarii/sonic.js.map +1 -1
  48. package/lib-es/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +11 -11
  50. package/src/helpers.ts +14 -15
  51. package/src/indexer.ts +205 -200
  52. package/src/scenarii/blast.ts +11 -9
  53. package/src/scenarii/ethereum.ts +13 -11
  54. package/src/scenarii/polygon.ts +14 -12
  55. package/src/scenarii/scroll.ts +11 -9
  56. package/src/scenarii/sonic.ts +11 -9
@@ -12,15 +12,14 @@ const ethers_1 = require("ethers");
12
12
  const index_1 = require("@ledgerhq/coin-evm/abis/index");
13
13
  const utils_1 = require("@ledgerhq/coin-evm/utils");
14
14
  const MAX_BLOCK_RANGE = 1024;
15
- const ERC20Interface = new ethers_1.ethers.Interface(index_1.ERC20_ABI);
16
- const ERC721Interface = new ethers_1.ethers.Interface(index_1.ERC721_ABI);
17
- const ERC1155Interface = new ethers_1.ethers.Interface(index_1.ERC1155_ABI);
15
+ const ERC20Interface = new ethers_1.utils.Interface(index_1.ERC20_ABI);
16
+ const ERC721Interface = new ethers_1.utils.Interface(index_1.ERC721_ABI);
17
+ const ERC1155Interface = new ethers_1.utils.Interface(index_1.ERC1155_ABI);
18
18
  const TRANSFER_EVENTS_TOPICS = {
19
- ERC20: ERC20Interface.getEvent("Transfer")?.topicHash || "",
20
- ERC721: ERC721Interface.getEvent("Transfer")?.topicHash || "",
21
- ERC1155: ERC1155Interface.getEvent("TransferSingle")?.topicHash || "",
19
+ ERC20: ERC20Interface.getEventTopic("Transfer"),
20
+ ERC721: ERC721Interface.getEventTopic("Transfer"),
21
+ ERC1155: ERC1155Interface.getEventTopic("TransferSingle"),
22
22
  };
23
- const abiCoder = new ethers_1.AbiCoder();
24
23
  const explorerEtherscanOperationByAddress = {};
25
24
  const explorerEtherscanERC20EventsByAddress = {};
26
25
  const explorerEtherscanERC721EventsByAddress = {};
@@ -51,21 +50,11 @@ const resetIndexer = () => {
51
50
  };
52
51
  exports.resetIndexer = resetIndexer;
53
52
  const handleLog = async (log, provider) => {
54
- let hasDecimals = false;
55
- try {
56
- const res = await provider.call({
57
- to: log.address,
58
- data: ERC20Interface.encodeFunctionData("decimals"),
59
- });
60
- // if call didn’t revert and returned something valid
61
- hasDecimals = !!(res && res !== "0x");
62
- }
63
- catch {
64
- // execution reverted → no decimals()
65
- hasDecimals = false;
66
- }
67
- const isERC20 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC20 && hasDecimals;
68
- const isERC721 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC721 && !hasDecimals;
53
+ const contractDecimals = await provider
54
+ .call({ to: log.address, data: ERC20Interface.encodeFunctionData("decimals") })
55
+ .then(res => (!res || res === "0x" ? false : true));
56
+ const isERC20 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC20 && contractDecimals;
57
+ const isERC721 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC721 && !contractDecimals;
69
58
  const isERC1155 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC1155;
70
59
  if (isERC20) {
71
60
  return handleERC20Log(log, provider);
@@ -81,10 +70,10 @@ const handleERC20Log = async (log, provider) => {
81
70
  const [name, ticker, decimals, block, tx, receipt] = await Promise.all([
82
71
  provider
83
72
  .call({ to: log.address, data: ERC20Interface.encodeFunctionData("name") })
84
- .then(res => abiCoder.decode(["string"], res)[0]),
73
+ .then(res => ethers_1.ethers.utils.defaultAbiCoder.decode(["string"], res)[0]),
85
74
  provider
86
75
  .call({ to: log.address, data: ERC20Interface.encodeFunctionData("symbol") })
87
- .then(res => abiCoder.decode(["string"], res)[0]),
76
+ .then(res => ethers_1.ethers.utils.defaultAbiCoder.decode(["string"], res)[0]),
88
77
  provider
89
78
  .call({ to: log.address, data: ERC20Interface.encodeFunctionData("decimals") })
90
79
  .then(res => new bignumber_js_1.default(res).toString()),
@@ -92,29 +81,29 @@ const handleERC20Log = async (log, provider) => {
92
81
  provider.getTransaction(log.transactionHash),
93
82
  provider.getTransactionReceipt(log.transactionHash),
94
83
  ]);
95
- const from = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[1])[0]);
96
- const to = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[2])[0]);
97
- const amount = BigInt(log.data === "0x" ? 0 : log.data).toString();
84
+ const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
85
+ const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
86
+ const amount = ethers_1.ethers.BigNumber.from(log.data === "0x" ? 0 : log.data).toString();
98
87
  const etherscanErc20Event = {
99
- blockNumber: block?.number.toString() || "0",
100
- timeStamp: block?.timestamp.toString() || "0",
88
+ blockNumber: block.number.toString(),
89
+ timeStamp: block.timestamp.toString(),
101
90
  hash: log.transactionHash,
102
- nonce: tx?.nonce.toString() || "0",
103
- blockHash: block?.hash || "",
91
+ nonce: tx.nonce.toString(),
92
+ blockHash: block.hash,
104
93
  from,
105
94
  to,
106
95
  value: amount,
107
96
  tokenName: name,
108
97
  tokenSymbol: ticker,
109
98
  tokenDecimal: decimals,
110
- transactionIndex: block?.transactions.indexOf(log.transactionHash).toString() || "0",
111
- gas: tx?.gasLimit.toString() || "0",
112
- gasPrice: tx?.gasPrice?.toString() || "",
113
- cumulativeGasUsed: receipt?.cumulativeGasUsed.toString() || "0",
99
+ transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
100
+ gas: tx.gasLimit.toString(),
101
+ gasPrice: tx.gasPrice?.toString() || "",
102
+ cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
114
103
  gasUsed: receipt?.gasUsed?.toString() || "0",
115
- input: tx?.data || "0x",
116
- confirmations: tx?.confirmations.toString() || "0",
117
- contractAddress: tx?.to.toLowerCase() || "",
104
+ input: tx.data,
105
+ confirmations: tx.confirmations.toString(),
106
+ contractAddress: tx.to.toLowerCase(),
118
107
  };
119
108
  if (!explorerEtherscanERC20EventsByAddress[from]) {
120
109
  explorerEtherscanERC20EventsByAddress[from] = new Map();
@@ -130,9 +119,8 @@ const handleERC20Log = async (log, provider) => {
130
119
  if (!explorerLedgerOperationByAddress[to]) {
131
120
  explorerLedgerOperationByAddress[to] = new Map();
132
121
  }
133
- const txHash = tx?.hash;
134
- const alreadyExistingOperation = (txHash && explorerLedgerOperationByAddress[from].get(txHash)) ||
135
- (txHash && explorerLedgerOperationByAddress[to].get(txHash));
122
+ const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
123
+ explorerLedgerOperationByAddress[to].get(tx.hash);
136
124
  const ledgerOperation = alreadyExistingOperation
137
125
  ? {
138
126
  ...alreadyExistingOperation,
@@ -147,16 +135,16 @@ const handleERC20Log = async (log, provider) => {
147
135
  }
148
136
  : {
149
137
  hash: log.transactionHash,
150
- transaction_type: receipt?.type ?? 0,
138
+ transaction_type: receipt.type,
151
139
  nonce: "",
152
140
  nonce_value: -1,
153
- value: tx?.value.toString() ?? "0",
154
- gas: tx?.gasLimit.toString() ?? "0",
155
- gas_price: receipt?.gasPrice.toString() ?? "0",
156
- max_fee_per_gas: tx?.type === 2 ? tx.maxFeePerGas.toString() : null,
157
- max_priority_fee_per_gas: tx?.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
158
- from: tx?.from ?? "0x",
159
- to: tx?.to ?? "0x0000000000000000000000000000000000000000",
141
+ value: tx.value.toString(),
142
+ gas: tx.gasLimit.toString(),
143
+ gas_price: receipt.effectiveGasPrice.toString(),
144
+ max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
145
+ max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
146
+ from: tx.from,
147
+ to: tx.to,
160
148
  transfer_events: [
161
149
  {
162
150
  contract: log.address,
@@ -169,16 +157,16 @@ const handleERC20Log = async (log, provider) => {
169
157
  erc1155_transfer_events: [],
170
158
  approval_events: [],
171
159
  actions: [],
172
- confirmations: tx?.confirmations ? await tx.confirmations() : 0,
160
+ confirmations: tx.confirmations,
173
161
  input: null,
174
- gas_used: receipt?.gasUsed.toString() ?? "0",
175
- cumulative_gas_used: receipt?.cumulativeGasUsed.toString() ?? "0",
176
- status: receipt?.status ?? 0,
177
- received_at: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
162
+ gas_used: receipt.gasUsed.toString(),
163
+ cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
164
+ status: receipt.status,
165
+ received_at: new Date(block.timestamp * 1000).toISOString(),
178
166
  block: {
179
167
  hash: log.blockHash,
180
168
  height: log.blockNumber,
181
- time: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
169
+ time: new Date(block.timestamp * 1000).toISOString(),
182
170
  },
183
171
  };
184
172
  explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
@@ -190,25 +178,25 @@ const handleERC721Log = async (log, provider) => {
190
178
  provider.getTransaction(log.transactionHash),
191
179
  provider.getTransactionReceipt(log.transactionHash),
192
180
  ]);
193
- const from = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[1])[0]);
194
- const to = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[2])[0]);
195
- const tokenID = abiCoder.decode(["uint256"], log.topics[3])[0].toString();
181
+ const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
182
+ const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
183
+ const tokenID = ethers_1.ethers.utils.defaultAbiCoder.decode(["uint256"], log.topics[3])[0].toString();
196
184
  const erc721Event = {
197
- blockNumber: block?.number.toString() || "0",
198
- timeStamp: block?.timestamp.toString() || "0",
199
- hash: tx?.hash || "",
200
- nonce: tx?.nonce.toString() || "0",
201
- blockHash: block?.hash || "",
185
+ blockNumber: block.number.toString(),
186
+ timeStamp: block.timestamp.toString(),
187
+ hash: tx.hash,
188
+ nonce: tx.nonce.toString(),
189
+ blockHash: block.hash,
202
190
  from,
203
191
  to,
204
- transactionIndex: block?.transactions.indexOf(log.transactionHash).toString() || "0",
205
- gas: tx?.gasLimit.toString() || "0",
206
- gasPrice: tx?.gasPrice?.toString() || "",
207
- cumulativeGasUsed: receipt?.cumulativeGasUsed.toString() || "0",
192
+ transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
193
+ gas: tx.gasLimit.toString(),
194
+ gasPrice: tx.gasPrice?.toString() || "",
195
+ cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
208
196
  gasUsed: receipt?.gasUsed?.toString() || "0",
209
- input: tx?.data || "0x",
210
- confirmations: tx?.confirmations.toString() || "0",
211
- contractAddress: tx?.to ?? "0x0000000000000000000000000000000000000000",
197
+ input: tx.data,
198
+ confirmations: tx.confirmations.toString(),
199
+ contractAddress: tx.to,
212
200
  tokenID,
213
201
  tokenName: "tokenName",
214
202
  tokenSymbol: "tokenSymbol",
@@ -228,9 +216,8 @@ const handleERC721Log = async (log, provider) => {
228
216
  if (!explorerLedgerOperationByAddress[to]) {
229
217
  explorerLedgerOperationByAddress[to] = new Map();
230
218
  }
231
- const txHash = tx?.hash;
232
- const alreadyExistingOperation = (txHash && explorerLedgerOperationByAddress[from].get(txHash)) ||
233
- (txHash && explorerLedgerOperationByAddress[to].get(txHash));
219
+ const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
220
+ explorerLedgerOperationByAddress[to].get(tx.hash);
234
221
  const ledgerOperation = alreadyExistingOperation
235
222
  ? {
236
223
  ...alreadyExistingOperation,
@@ -245,16 +232,16 @@ const handleERC721Log = async (log, provider) => {
245
232
  }
246
233
  : {
247
234
  hash: log.transactionHash,
248
- transaction_type: receipt?.type ?? 0,
235
+ transaction_type: receipt.type,
249
236
  nonce: "",
250
237
  nonce_value: -1,
251
- value: tx?.value.toString() ?? "0",
252
- gas: tx?.gasLimit.toString() ?? "0",
253
- gas_price: receipt?.gasPrice.toString() ?? "0",
254
- max_fee_per_gas: tx?.type === 2 ? tx?.maxFeePerGas.toString() : null,
255
- max_priority_fee_per_gas: tx?.type === 2 ? tx?.maxPriorityFeePerGas.toString() : null,
256
- from: tx?.from ?? "0x",
257
- to: tx?.to ?? "0x0000000000000000000000000000000000000000",
238
+ value: tx.value.toString(),
239
+ gas: tx.gasLimit.toString(),
240
+ gas_price: receipt.effectiveGasPrice.toString(),
241
+ max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
242
+ max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
243
+ from: tx.from,
244
+ to: tx.to,
258
245
  transfer_events: [],
259
246
  erc721_transfer_events: [
260
247
  {
@@ -267,16 +254,16 @@ const handleERC721Log = async (log, provider) => {
267
254
  erc1155_transfer_events: [],
268
255
  approval_events: [],
269
256
  actions: [],
270
- confirmations: tx?.confirmations ? await tx.confirmations() : 0,
257
+ confirmations: tx.confirmations,
271
258
  input: null,
272
- gas_used: receipt?.gasUsed.toString() ?? "0",
273
- cumulative_gas_used: receipt?.cumulativeGasUsed.toString() ?? "0",
274
- status: receipt?.status ?? 0,
275
- received_at: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
259
+ gas_used: receipt.gasUsed.toString(),
260
+ cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
261
+ status: receipt.status,
262
+ received_at: new Date(block.timestamp * 1000).toISOString(),
276
263
  block: {
277
264
  hash: log.blockHash,
278
265
  height: log.blockNumber,
279
- time: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
266
+ time: new Date(block.timestamp * 1000).toISOString(),
280
267
  },
281
268
  };
282
269
  explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
@@ -288,28 +275,28 @@ const handleERC1155Log = async (log, provider) => {
288
275
  provider.getTransaction(log.transactionHash),
289
276
  provider.getTransactionReceipt(log.transactionHash),
290
277
  ]);
291
- const from = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[2])[0]);
292
- const to = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[3])[0]);
293
- const operator = (0, utils_1.safeEncodeEIP55)(abiCoder.decode(["address"], log.topics[1])[0]);
294
- const transfersMap = abiCoder
278
+ const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
279
+ const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[3])[0]);
280
+ const operator = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
281
+ const transfersMap = ethers_1.ethers.utils.defaultAbiCoder
295
282
  .decode(["uint256", "uint256"], log.data)
296
283
  .map((value, index) => [index === 0 ? "id" : "value", value.toString()]);
297
284
  const etherscanERC1155Events = transfersMap.map(([id, value]) => ({
298
- blockNumber: block?.number.toString() || "0",
299
- timeStamp: block?.timestamp.toString() || "0",
300
- hash: tx?.hash || "",
301
- nonce: tx?.nonce.toString() || "0",
302
- blockHash: block?.hash || "",
285
+ blockNumber: block.number.toString(),
286
+ timeStamp: block.timestamp.toString(),
287
+ hash: tx.hash,
288
+ nonce: tx.nonce.toString(),
289
+ blockHash: block.hash,
303
290
  from,
304
291
  to,
305
- transactionIndex: block?.transactions.indexOf(log.transactionHash).toString() || "0",
306
- gas: tx?.gasLimit.toString() || "0",
307
- gasPrice: tx?.gasPrice?.toString() || "",
308
- cumulativeGasUsed: receipt?.cumulativeGasUsed.toString() || "0",
292
+ transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
293
+ gas: tx.gasLimit.toString(),
294
+ gasPrice: tx.gasPrice?.toString() || "",
295
+ cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
309
296
  gasUsed: receipt?.gasUsed?.toString() || "0",
310
- input: tx?.data || "0x",
311
- confirmations: tx?.confirmations.toString() || "0",
312
- contractAddress: tx?.to ?? "0x0000000000000000000000000000000000000000",
297
+ input: tx.data,
298
+ confirmations: tx.confirmations.toString(),
299
+ contractAddress: tx.to,
313
300
  tokenID: id,
314
301
  tokenValue: value,
315
302
  tokenName: "tokenName",
@@ -331,9 +318,8 @@ const handleERC1155Log = async (log, provider) => {
331
318
  if (!explorerLedgerOperationByAddress[to]) {
332
319
  explorerLedgerOperationByAddress[to] = new Map();
333
320
  }
334
- const txHash = tx?.hash;
335
- const alreadyExistingOperation = (txHash && explorerLedgerOperationByAddress[from].get(txHash)) ||
336
- (txHash && explorerLedgerOperationByAddress[to].get(txHash));
321
+ const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
322
+ explorerLedgerOperationByAddress[to].get(tx.hash);
337
323
  const ledgerOperation = alreadyExistingOperation
338
324
  ? {
339
325
  ...alreadyExistingOperation,
@@ -348,17 +334,17 @@ const handleERC1155Log = async (log, provider) => {
348
334
  ],
349
335
  }
350
336
  : {
351
- hash: log.transactionHash || "",
352
- transaction_type: receipt?.type ?? 0,
337
+ hash: log.transactionHash,
338
+ transaction_type: receipt.type,
353
339
  nonce: "",
354
340
  nonce_value: -1,
355
- value: tx?.value.toString() || "0",
356
- gas: tx?.gasLimit.toString() || "0",
357
- gas_price: receipt?.gasPrice.toString() || "0",
358
- max_fee_per_gas: tx?.type === 2 ? tx?.maxFeePerGas.toString() : null,
359
- max_priority_fee_per_gas: tx?.type === 2 ? tx?.maxPriorityFeePerGas.toString() : null,
360
- from: tx?.from ?? "0x",
361
- to: tx?.to ?? "0x0000000000000000000000000000000000000000",
341
+ value: tx.value.toString(),
342
+ gas: tx.gasLimit.toString(),
343
+ gas_price: receipt.effectiveGasPrice.toString(),
344
+ max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
345
+ max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
346
+ from: tx.from,
347
+ to: tx.to,
362
348
  transfer_events: [],
363
349
  erc721_transfer_events: [],
364
350
  erc1155_transfer_events: [
@@ -372,52 +358,52 @@ const handleERC1155Log = async (log, provider) => {
372
358
  ],
373
359
  approval_events: [],
374
360
  actions: [],
375
- confirmations: tx?.confirmations ? await tx.confirmations() : 0,
361
+ confirmations: tx.confirmations,
376
362
  input: null,
377
- gas_used: receipt?.gasUsed.toString() || "0",
378
- cumulative_gas_used: receipt?.cumulativeGasUsed.toString() || "0",
379
- status: receipt?.status ?? 0,
380
- received_at: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
363
+ gas_used: receipt.gasUsed.toString(),
364
+ cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
365
+ status: receipt.status,
366
+ received_at: new Date(block.timestamp * 1000).toISOString(),
381
367
  block: {
382
368
  hash: log.blockHash,
383
369
  height: log.blockNumber,
384
- time: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
370
+ time: new Date(block.timestamp * 1000).toISOString(),
385
371
  },
386
372
  };
387
373
  explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
388
374
  explorerLedgerOperationByAddress[to].set(ledgerOperation.hash, ledgerOperation);
389
375
  };
390
376
  const handleBlock = async (blockNumber, provider) => {
391
- const block = await provider.getBlock(blockNumber, true);
377
+ const block = await provider.getBlockWithTransactions(blockNumber);
392
378
  for (const transaction of block?.transactions || []) {
393
379
  const [tx, receipt, traces] = await Promise.all([
394
- provider.getTransaction(transaction),
395
- provider.getTransactionReceipt(transaction),
396
- provider.send("trace_transaction", [transaction]).catch(() => []),
380
+ provider.getTransaction(transaction.hash),
381
+ provider.getTransactionReceipt(transaction.hash),
382
+ provider.send("trace_transaction", [transaction.hash]).catch(() => []),
397
383
  ]);
398
- const code = tx?.to ? await provider.getCode(tx?.to) : false;
399
- const from = (0, utils_1.safeEncodeEIP55)(tx?.from || "");
400
- const to = (0, utils_1.safeEncodeEIP55)(tx?.to || "");
384
+ const code = transaction.to ? await provider.getCode(transaction.to) : false;
385
+ const from = (0, utils_1.safeEncodeEIP55)(transaction.from);
386
+ const to = (0, utils_1.safeEncodeEIP55)(transaction.to || "");
401
387
  const etherscanOperation = {
402
- blockNumber: block?.number.toString() || "0",
403
- timeStamp: block?.timestamp.toString() || "0",
404
- hash: tx?.hash || "",
405
- nonce: tx?.nonce.toString() || "0",
406
- blockHash: block?.hash || "",
407
- transactionIndex: block?.transactions.indexOf(transaction).toString() || "0",
388
+ blockNumber: block.number.toString(),
389
+ timeStamp: block.timestamp.toString(),
390
+ hash: transaction.hash,
391
+ nonce: transaction.nonce.toString(),
392
+ blockHash: block.hash,
393
+ transactionIndex: block.transactions.indexOf(transaction).toString(),
408
394
  from,
409
395
  to,
410
- value: tx?.value.toString() || "0",
411
- gas: tx?.gasLimit.toString() || "0",
412
- gasPrice: tx?.gasPrice?.toString() || "",
413
- isError: receipt?.status === 1 ? "0" : "1",
414
- txreceipt_status: receipt?.status.toString() || "0",
415
- input: tx?.data,
416
- contractAddress: code === "0x" ? "" : tx?.to ?? "0x0000000000000000000000000000000000000000",
417
- cumulativeGasUsed: receipt?.cumulativeGasUsed.toString() || "0",
396
+ value: transaction.value.toBigInt().toString(),
397
+ gas: transaction.gasLimit.toString(),
398
+ gasPrice: transaction.gasPrice?.toString() || "",
399
+ isError: receipt.status === 1 ? "0" : "1",
400
+ txreceipt_status: receipt.status.toString(),
401
+ input: transaction.data,
402
+ contractAddress: code === "0x" ? "" : transaction.to,
403
+ cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
418
404
  gasUsed: receipt?.gasUsed?.toString() || "0",
419
- confirmations: tx?.confirmations.toString() || "0",
420
- methodId: tx?.data && tx.data.length > 10 ? tx.data.slice(0, 10) : "",
405
+ confirmations: transaction.confirmations.toString(),
406
+ methodId: transaction.data?.length > 10 ? transaction.data.slice(0, 10) : "",
421
407
  functionName: "",
422
408
  };
423
409
  if (!explorerEtherscanOperationByAddress[from]) {
@@ -435,32 +421,32 @@ const handleBlock = async (blockNumber, provider) => {
435
421
  explorerLedgerOperationByAddress[to] = new Map();
436
422
  }
437
423
  const ledgerOperation = {
438
- hash: receipt?.hash || "",
439
- transaction_type: receipt?.type || 0,
424
+ hash: receipt.transactionHash,
425
+ transaction_type: receipt.type,
440
426
  nonce: "",
441
427
  nonce_value: -1,
442
- value: tx?.value.toString() || "0",
443
- gas: tx?.gasLimit.toString() || "0",
444
- gas_price: receipt?.gasPrice.toString() || "",
445
- max_fee_per_gas: tx?.type === 2 ? tx?.maxFeePerGas.toString() : null,
446
- max_priority_fee_per_gas: tx?.type === 2 ? tx?.maxPriorityFeePerGas.toString() : null,
447
- from: tx?.from || "",
448
- to: tx?.to ?? "0x0000000000000000000000000000000000000000",
428
+ value: tx.value.toString(),
429
+ gas: tx.gasLimit.toString(),
430
+ gas_price: receipt.effectiveGasPrice.toString(),
431
+ max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
432
+ max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
433
+ from: tx.from,
434
+ to: tx.to,
449
435
  transfer_events: [],
450
436
  erc721_transfer_events: [],
451
437
  erc1155_transfer_events: [],
452
438
  approval_events: [],
453
439
  actions: [],
454
- confirmations: tx?.confirmations ? await tx.confirmations() : 0,
440
+ confirmations: tx.confirmations,
455
441
  input: null,
456
- gas_used: receipt?.gasUsed.toString() || "0",
457
- cumulative_gas_used: receipt?.cumulativeGasUsed.toString() || "0",
458
- status: receipt?.status ?? 0,
459
- received_at: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
442
+ gas_used: receipt.gasUsed.toString(),
443
+ cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
444
+ status: receipt.status,
445
+ received_at: new Date(block.timestamp * 1000).toISOString(),
460
446
  block: {
461
- hash: receipt?.blockHash || "",
462
- height: receipt?.blockNumber || 0,
463
- time: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
447
+ hash: receipt.blockHash,
448
+ height: receipt.blockNumber,
449
+ time: new Date(block.timestamp * 1000).toISOString(),
464
450
  },
465
451
  };
466
452
  explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
@@ -473,18 +459,20 @@ const handleBlock = async (blockNumber, provider) => {
473
459
  const to = (0, utils_1.safeEncodeEIP55)(action.to || "");
474
460
  const etherscanInternalTransaction = {
475
461
  blockNumber: blockNumber.toString(),
476
- timeStamp: block?.timestamp.toString() || "0",
462
+ timeStamp: block.timestamp.toString(),
477
463
  hash: transactionHash,
478
464
  from,
479
465
  to,
480
- value: BigInt(action.value).toString() || "0",
466
+ value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
481
467
  contractAddress: code === "0x" ? "" : action.to,
482
468
  input: action.input || "0x",
483
469
  type,
484
- gas: BigInt(action.gas).toString(),
485
- gasUsed: BigInt(result?.gasUsed || "0").toString(),
470
+ gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
471
+ gasUsed: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
472
+ .toBigInt()
473
+ .toString(),
486
474
  traceId: transactionPosition.toString(),
487
- isError: receipt?.status === 1 ? "0" : "1",
475
+ isError: receipt.status === 1 ? "0" : "1",
488
476
  errCode: "",
489
477
  };
490
478
  if (!explorerEtherscanInternalByAddress[from]) {
@@ -501,9 +489,8 @@ const handleBlock = async (blockNumber, provider) => {
501
489
  if (!explorerLedgerOperationByAddress[to]) {
502
490
  explorerLedgerOperationByAddress[to] = new Map();
503
491
  }
504
- const txHash = tx?.hash;
505
- const alreadyExistingOperation = (txHash && explorerLedgerOperationByAddress[from].get(txHash)) ||
506
- (txHash && explorerLedgerOperationByAddress[to].get(txHash));
492
+ const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
493
+ explorerLedgerOperationByAddress[to].get(tx.hash);
507
494
  const ledgerOperation = alreadyExistingOperation
508
495
  ? {
509
496
  ...alreadyExistingOperation,
@@ -513,25 +500,27 @@ const handleBlock = async (blockNumber, provider) => {
513
500
  from,
514
501
  to,
515
502
  input: null,
516
- value: BigInt(action.value).toString(),
517
- gas: BigInt(action.gas).toString(),
518
- gas_used: BigInt(result?.gasUsed || "0").toString(),
503
+ value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
504
+ gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
505
+ gas_used: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
506
+ .toBigInt()
507
+ .toString(),
519
508
  error: null,
520
509
  },
521
510
  ],
522
511
  }
523
512
  : {
524
- hash: receipt?.hash || "",
525
- transaction_type: receipt?.type ?? 0,
513
+ hash: receipt.transactionHash,
514
+ transaction_type: receipt.type,
526
515
  nonce: "",
527
516
  nonce_value: -1,
528
- value: tx?.value.toString() || "0",
529
- gas: tx?.gasLimit.toString() || "0",
530
- gas_price: receipt?.gasPrice.toString() || "0",
531
- max_fee_per_gas: tx?.type === 2 ? tx?.maxFeePerGas.toString() : null,
532
- max_priority_fee_per_gas: tx?.type === 2 ? tx?.maxPriorityFeePerGas.toString() : null,
533
- from: tx?.from || "0x",
534
- to: tx?.to ?? "0x0000000000000000000000000000000000000000",
517
+ value: tx.value.toString(),
518
+ gas: tx.gasLimit.toString(),
519
+ gas_price: receipt.effectiveGasPrice.toString(),
520
+ max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
521
+ max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
522
+ from: tx.from,
523
+ to: tx.to,
535
524
  transfer_events: [],
536
525
  erc721_transfer_events: [],
537
526
  erc1155_transfer_events: [],
@@ -541,22 +530,24 @@ const handleBlock = async (blockNumber, provider) => {
541
530
  from,
542
531
  to,
543
532
  input: null,
544
- value: BigInt(action.value).toString(),
545
- gas: BigInt(action.gas).toString(),
546
- gas_used: BigInt(result?.gasUsed || "0").toString(),
533
+ value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
534
+ gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
535
+ gas_used: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
536
+ .toBigInt()
537
+ .toString(),
547
538
  error: null,
548
539
  },
549
540
  ],
550
- confirmations: tx?.confirmations ? await tx.confirmations() : 0,
541
+ confirmations: tx.confirmations,
551
542
  input: null,
552
- gas_used: receipt?.gasUsed.toString() || "0",
553
- cumulative_gas_used: receipt?.cumulativeGasUsed.toString() || "0",
554
- status: receipt?.status ?? 0,
555
- received_at: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
543
+ gas_used: receipt.gasUsed.toString(),
544
+ cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
545
+ status: receipt.status,
546
+ received_at: new Date(block.timestamp * 1000).toISOString(),
556
547
  block: {
557
- hash: receipt?.blockHash || "",
558
- height: receipt?.blockNumber || 0,
559
- time: new Date((block?.timestamp ?? 0) * 1000).toISOString(),
548
+ hash: receipt.blockHash,
549
+ height: receipt.blockNumber,
550
+ time: new Date(block.timestamp * 1000).toISOString(),
560
551
  },
561
552
  };
562
553
  explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
@@ -572,7 +563,7 @@ const indexBlocks = async () => {
572
563
  if (!fromBlock) {
573
564
  throw new Error("fromBlock is not set");
574
565
  }
575
- const provider = new ethers_1.ethers.JsonRpcProvider(process.env.RPC);
566
+ const provider = new ethers_1.providers.StaticJsonRpcProvider(process.env.RPC);
576
567
  let latestBlockNumber = await provider.getBlockNumber();
577
568
  const toBlock = Math.min(fromBlock + MAX_BLOCK_RANGE, latestBlockNumber);
578
569
  const rangeSize = toBlock - fromBlock + 1;