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