@indexing/jiti 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,18 @@
1
+ GPL-3.0-or-later License
2
+
3
+ JITI - Just In Time Indexing, for all.
4
+
5
+ Copyright (C) 2024 The Indexing Company
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Just In Time Indexing (JITI)
2
+
3
+ Open source template library for the JITI community.
4
+
5
+ NOTE: This is an active work in progress and not yet ready for community usage.
6
+
7
+ # Contributing
8
+
9
+ This package will be ready for external contributors in early 2025.
10
+
11
+ ## License
12
+
13
+ See the [LICENSE](LICENSE.md) file for license rights and limitations (GPL-3.0-or-later).
package/dist/main.js ADDED
@@ -0,0 +1,366 @@
1
+ var $8zHUo$viem = require("viem");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ function $parcel$exportWildcard(dest, source) {
9
+ Object.keys(source).forEach(function(key) {
10
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
11
+ return;
12
+ }
13
+
14
+ Object.defineProperty(dest, key, {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return source[key];
18
+ }
19
+ });
20
+ });
21
+
22
+ return dest;
23
+ }
24
+
25
+ $parcel$export(module.exports, "getAllTemplates", () => $882b6d93070905b3$export$cceb5167b935aafb);
26
+ $parcel$export(module.exports, "getTemplateByKey", () => $882b6d93070905b3$export$a07bfd14bbc36e4b);
27
+ $parcel$export(module.exports, "utils", () => $d7167569386d0d4c$exports);
28
+ $parcel$export(module.exports, "types", () => $faefaad95e5fcca0$exports);
29
+ const $49a91814dabec06a$var$allBlocks = {
30
+ key: "allBlocks",
31
+ name: "All Blocks",
32
+ description: "Get all blocks with all available fields",
33
+ tags: [
34
+ "EVM",
35
+ "TRANSACTIONS"
36
+ ],
37
+ disabled: false,
38
+ params: [],
39
+ transform: (payload)=>payload
40
+ };
41
+ var $49a91814dabec06a$export$2e2bcd8739ae039 = $49a91814dabec06a$var$allBlocks;
42
+
43
+
44
+ var $d7167569386d0d4c$exports = {};
45
+ var $596a656635c74d50$exports = {};
46
+
47
+ $parcel$export($596a656635c74d50$exports, "evmAddressToChecksum", () => $596a656635c74d50$export$db81f9ea057ab646);
48
+
49
+ function $596a656635c74d50$export$db81f9ea057ab646(address) {
50
+ if (!address || !/^(0x)?[0-9a-f]{40}$/i.test(address)) return null;
51
+ const stripAddress = address.slice(2).toLowerCase();
52
+ const keccakHash = (0, $8zHUo$viem.keccak256)(stripAddress);
53
+ let checksumAddress = "0x";
54
+ for(let i = 0; i < stripAddress.length; i++)checksumAddress += parseInt(keccakHash[i], 16) >= 8 ? stripAddress[i].toUpperCase() : stripAddress[i];
55
+ return checksumAddress;
56
+ }
57
+
58
+
59
+ var $e5566e47593dc3e2$exports = {};
60
+
61
+ $parcel$export($e5566e47593dc3e2$exports, "evmChainToId", () => $e5566e47593dc3e2$export$f93b8abed77a4120);
62
+ const $e5566e47593dc3e2$var$CHAIN_ID = {
63
+ ARBITRUM: 42161,
64
+ AVALANCHE: 43114,
65
+ BASE: 8453,
66
+ BASE_SEPOLIA: 84532,
67
+ BERACHAIN_BARTIO: 80084,
68
+ BLAST: 81457,
69
+ BSC: 56,
70
+ CELO: 42220,
71
+ CYBER: 7560,
72
+ DEGEN: 666666666,
73
+ ETHEREUM: 1,
74
+ ETH_HOLESKY: 17000,
75
+ ETH_SEPOLIA: 11155111,
76
+ FRAXTAL: 252,
77
+ FRAXTAL_SEPOLIA: 2522,
78
+ FUSE: 122,
79
+ GNOSIS: 100,
80
+ GOLD: 4653,
81
+ HAM: 5112,
82
+ HEMI_TESTNET: 743111,
83
+ LINEA: 59144,
84
+ LINEA_SEPOLIA: 59141,
85
+ LISK_SEPOLIA: 4202,
86
+ LYRA: 957,
87
+ LYRA_SEPOLIA: 901,
88
+ MODE: 34443,
89
+ MODE_SEPOLIA: 919,
90
+ NEON: 245022934,
91
+ OASIS_SAPPHIRE: 23294,
92
+ OPTIMISM: 10,
93
+ OP_SEPOLIA: 11155420,
94
+ ORDERLY: 291,
95
+ ORDERLY_SEPOLIA: 4460,
96
+ PGN_SEPOLIA: 58008,
97
+ POLYGON: 137,
98
+ POLYGON_AMOY: 80002,
99
+ POLYGON_ZKEVM: 1101,
100
+ PUBLIC_GOODS_NETWORK: 424,
101
+ SCROLL: 534352,
102
+ SCROLL_SEPOLIA: 534351,
103
+ STACK: 78225,
104
+ SYNDICATE_FRAME_CHAIN: 5101,
105
+ TRON: 728126428,
106
+ ZER0: 543210,
107
+ ZK_LINK: 810180,
108
+ ZORA: 7777777,
109
+ ZORA_SEPOLIA: 999999999
110
+ };
111
+ function $e5566e47593dc3e2$export$f93b8abed77a4120(chain) {
112
+ return $e5566e47593dc3e2$var$CHAIN_ID[chain?.toUpperCase()];
113
+ }
114
+
115
+
116
+ var $da55be3e40667945$exports = {};
117
+
118
+ $parcel$export($da55be3e40667945$exports, "evmDecodeLog", () => $da55be3e40667945$export$18467e329ea485c9);
119
+ $parcel$export($da55be3e40667945$exports, "evmDecodeLogWithMetadata", () => $da55be3e40667945$export$cf548b70626e2eb9);
120
+
121
+ var $f7a3fb164436c9c3$exports = {};
122
+
123
+ $parcel$export($f7a3fb164436c9c3$exports, "evmMethodSignatureToHex", () => $f7a3fb164436c9c3$export$49d5c9473f8f70f2);
124
+
125
+ function $f7a3fb164436c9c3$export$49d5c9473f8f70f2(sig) {
126
+ const [method, rest] = sig.split("(");
127
+ const params = rest.split(")")[0].split(",").map((p)=>p.trim());
128
+ const topic0 = (0, $8zHUo$viem.keccak256)(`${method.split(" ").pop()}(${params.map((p)=>p.split(" ")[0]).join(",")})`);
129
+ return topic0;
130
+ }
131
+
132
+
133
+ function $da55be3e40667945$export$18467e329ea485c9(log, signatures) {
134
+ if (Array.isArray(signatures)) {
135
+ for (const sig of signatures){
136
+ const decoded = $da55be3e40667945$export$18467e329ea485c9(log, sig);
137
+ if (decoded) return decoded;
138
+ }
139
+ return null;
140
+ }
141
+ if (typeof signatures !== "string" && Array.isArray(signatures.addresses) && signatures.addresses.length) {
142
+ const addresses = signatures.addresses.map((a)=>a?.toLowerCase());
143
+ if (!addresses.includes(log.address.toLowerCase())) return null;
144
+ }
145
+ let sig = (typeof signatures === "string" ? signatures : signatures.signature).trim();
146
+ if (!sig.startsWith("event ")) sig = "event " + sig;
147
+ const topic0 = typeof signatures !== "string" && signatures.topic0 ? signatures.topic0 : (0, $f7a3fb164436c9c3$export$49d5c9473f8f70f2)(sig);
148
+ if ((sig.match(/ indexed /g)?.length || 0) === log.topics.length - 1) {
149
+ if (log.topics[0] === topic0) try {
150
+ const result = (0, $8zHUo$viem.decodeEventLog)({
151
+ abi: (0, $8zHUo$viem.parseAbi)([
152
+ sig
153
+ ]),
154
+ data: log.data,
155
+ topics: log.topics
156
+ });
157
+ return result.args;
158
+ } catch (e) {
159
+ // ignore this
160
+ }
161
+ }
162
+ return null;
163
+ }
164
+ function $da55be3e40667945$export$cf548b70626e2eb9(log, signatures) {
165
+ for (const sig of [
166
+ signatures
167
+ ].flat()){
168
+ const decoded = $da55be3e40667945$export$18467e329ea485c9(log, sig);
169
+ if (decoded) return {
170
+ decoded: decoded,
171
+ metadata: {
172
+ name: (typeof sig === "string" ? sig : sig.signature).split("(")[0]
173
+ }
174
+ };
175
+ }
176
+ return null;
177
+ }
178
+
179
+
180
+
181
+ var $414c83047563e72e$exports = {};
182
+
183
+ $parcel$export($414c83047563e72e$exports, "normalizeEVMBlock", () => $414c83047563e72e$export$685b7dc2197cd06c);
184
+
185
+ function $414c83047563e72e$export$685b7dc2197cd06c(rawBlock) {
186
+ for (const k of [
187
+ "baseFeePerGas",
188
+ "gasLimit",
189
+ "gasUsed",
190
+ "number",
191
+ "size",
192
+ "timestamp"
193
+ ])if (typeof rawBlock[k] === "string") rawBlock[k] = parseInt(rawBlock[k]);
194
+ for (const k of [
195
+ "difficulty",
196
+ "totalDifficulty"
197
+ ])if (typeof rawBlock[k] === "string") rawBlock[k] = BigInt(rawBlock[k]).toString();
198
+ for (const k of [
199
+ "miner"
200
+ ])rawBlock[k] = (0, $596a656635c74d50$export$db81f9ea057ab646)(rawBlock[k]);
201
+ rawBlock.transactions = rawBlock.transactions.map((tx)=>{
202
+ for (const k of [
203
+ "blockNumber",
204
+ "cumulativeGasUsed",
205
+ "effectiveGasPrice",
206
+ "gas",
207
+ "gasUsed",
208
+ "nonce",
209
+ "status",
210
+ "transactionIndex"
211
+ ]){
212
+ if (typeof tx[k] === "string") tx[k] = parseInt(tx[k]);
213
+ if (typeof tx.receipt[k] === "string") tx.receipt[k] = parseInt(tx.receipt[k]);
214
+ }
215
+ for (const k of [
216
+ "gasPrice",
217
+ "maxFeePerGas",
218
+ "maxPriorityFeePerGas",
219
+ "value"
220
+ ]){
221
+ if (typeof tx[k] === "string") tx[k] = BigInt(tx[k]).toString();
222
+ if (typeof tx.receipt[k] === "string") tx.receipt[k] = BigInt(tx.receipt[k]).toString();
223
+ }
224
+ for (const k of [
225
+ "from",
226
+ "to"
227
+ ])if (typeof tx[k] === "string") tx[k] = (0, $596a656635c74d50$export$db81f9ea057ab646)(tx[k]);
228
+ for (const k of [
229
+ "contractAddress"
230
+ ])if (typeof tx.receipt[k] === "string") tx.receipt[k] = (0, $596a656635c74d50$export$db81f9ea057ab646)(tx.receipt[k]);
231
+ tx.type = parseInt(tx.type);
232
+ tx.receipt["status"] = Boolean(tx.receipt["status"]);
233
+ tx.receipt["logs"] = tx.receipt["logs"]?.map((log)=>{
234
+ for (const k of [
235
+ "blockNumber",
236
+ "logIndex",
237
+ "transactionIndex"
238
+ ])if (typeof log[k] === "string") log[k] = parseInt(log[k]);
239
+ log["address"] = (0, $596a656635c74d50$export$db81f9ea057ab646)(log["address"]);
240
+ return log;
241
+ });
242
+ return tx;
243
+ });
244
+ return rawBlock;
245
+ }
246
+
247
+
248
+ $parcel$exportWildcard($d7167569386d0d4c$exports, $596a656635c74d50$exports);
249
+ $parcel$exportWildcard($d7167569386d0d4c$exports, $e5566e47593dc3e2$exports);
250
+ $parcel$exportWildcard($d7167569386d0d4c$exports, $da55be3e40667945$exports);
251
+ $parcel$exportWildcard($d7167569386d0d4c$exports, $f7a3fb164436c9c3$exports);
252
+ $parcel$exportWildcard($d7167569386d0d4c$exports, $414c83047563e72e$exports);
253
+
254
+
255
+ const $6144a02851f23907$var$NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
256
+ const $6144a02851f23907$var$tokenTransfers = {
257
+ key: "tokenTransfers",
258
+ name: "Token Transfers",
259
+ description: "Get all token transfers for a set of token types.",
260
+ tags: [
261
+ "EVM",
262
+ "ERC20",
263
+ "ERC721",
264
+ "NFT",
265
+ "TOKEN"
266
+ ],
267
+ disabled: false,
268
+ params: [
269
+ {
270
+ key: "tokenTypes",
271
+ name: "Token Types",
272
+ type: "STRING",
273
+ multiple: true,
274
+ optional: true
275
+ }
276
+ ],
277
+ transform: (block, _ctx)=>{
278
+ const TOKEN_TYPES = _ctx.params.tokenTypes || [];
279
+ const transfers = [];
280
+ switch(block._network){
281
+ // @TODO: expand to non-EVM
282
+ // assume EVM as default for now
283
+ default:
284
+ for (const tx of block.transactions){
285
+ if (!tx.receipt) continue;
286
+ const timestamp = new Date(block.timestamp * 1000).toISOString();
287
+ const transactionGasFee = BigInt(tx.receipt.gasUsed) * BigInt(tx.receipt.effectiveGasPrice);
288
+ // track direct ETH transfers
289
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("NATIVE")) {
290
+ if (tx.value?.length >= 3 || /\d+/.test(tx.value)) {
291
+ transfers.push({
292
+ amount: BigInt(tx.value),
293
+ blockNumber: tx.blockNumber,
294
+ from: (0, $596a656635c74d50$export$db81f9ea057ab646)(tx.from) || $6144a02851f23907$var$NULL_ADDRESS,
295
+ timestamp: timestamp,
296
+ to: (0, $596a656635c74d50$export$db81f9ea057ab646)(tx.to) || $6144a02851f23907$var$NULL_ADDRESS,
297
+ tokenType: "NATIVE",
298
+ transactionGasFee: transactionGasFee,
299
+ transactionHash: tx.hash
300
+ });
301
+ if (Array.isArray(tx.traces)) for (const trace of tx.traces.filter((t)=>t.action)){
302
+ const action = trace.action;
303
+ if (!action?.value) continue;
304
+ transfers.push({
305
+ amount: BigInt(action.value),
306
+ blockNumber: tx.blockNumber,
307
+ from: (0, $596a656635c74d50$export$db81f9ea057ab646)(action.from) || $6144a02851f23907$var$NULL_ADDRESS,
308
+ index: trace.traceAddress?.join("-"),
309
+ timestamp: timestamp,
310
+ to: (0, $596a656635c74d50$export$db81f9ea057ab646)(action.to) || $6144a02851f23907$var$NULL_ADDRESS,
311
+ tokenType: "NATIVE",
312
+ transactionGasFee: transactionGasFee,
313
+ transactionHash: tx.hash
314
+ });
315
+ }
316
+ }
317
+ }
318
+ // track ERC20 transfers
319
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("TOKEN")) for (const log of tx.receipt.logs){
320
+ const txfer = (0, $da55be3e40667945$export$cf548b70626e2eb9)(log, [
321
+ "Transfer(address indexed from, address indexed to, uint256 value)"
322
+ ]);
323
+ if (txfer) transfers.push({
324
+ amount: txfer.decoded.value,
325
+ blockNumber: tx.blockNumber,
326
+ from: (0, $596a656635c74d50$export$db81f9ea057ab646)(txfer.decoded.from) || $6144a02851f23907$var$NULL_ADDRESS,
327
+ index: log.logIndex,
328
+ timestamp: timestamp,
329
+ to: (0, $596a656635c74d50$export$db81f9ea057ab646)(txfer.decoded.to) || $6144a02851f23907$var$NULL_ADDRESS,
330
+ token: (0, $596a656635c74d50$export$db81f9ea057ab646)(log.address),
331
+ tokenType: "TOKEN",
332
+ transactionGasFee: transactionGasFee,
333
+ transactionHash: tx.hash
334
+ });
335
+ }
336
+ // @TODO: add NFT transfers
337
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("NFT")) {
338
+ for (const log of tx.receipt.logs);
339
+ }
340
+ }
341
+ }
342
+ return transfers.filter((txfer)=>txfer.amount > BigInt(0));
343
+ }
344
+ };
345
+ var $6144a02851f23907$export$2e2bcd8739ae039 = $6144a02851f23907$var$tokenTransfers;
346
+
347
+
348
+ const $48f9879a44dd1195$export$a8fc3402335b0b04 = [
349
+ (0, $49a91814dabec06a$export$2e2bcd8739ae039),
350
+ (0, $6144a02851f23907$export$2e2bcd8739ae039)
351
+ ];
352
+
353
+
354
+
355
+ var $faefaad95e5fcca0$exports = {};
356
+
357
+
358
+ function $882b6d93070905b3$export$cceb5167b935aafb() {
359
+ return 0, $48f9879a44dd1195$export$a8fc3402335b0b04;
360
+ }
361
+ function $882b6d93070905b3$export$a07bfd14bbc36e4b(key) {
362
+ return (0, $48f9879a44dd1195$export$a8fc3402335b0b04).find((template)=>template.key === key);
363
+ }
364
+
365
+
366
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AEEA,MAAM,kCAAsB;IAC1B,KAAK;IACL,MAAM;IACN,aAAa;IACb,MAAM;QAAC;QAAO;KAAe;IAC7B,UAAU;IACV,QAAQ,EAAE;IACV,WAAW,CAAC,UAAY;AAC1B;IAEA,2CAAe;;;;;;;;AGVR,SAAS,0CAAqB,OAAe;IAClD,IAAI,CAAC,WAAW,CAAC,uBAAuB,IAAI,CAAC,UAC3C,OAAO;IAGT,MAAM,eAAe,QAAQ,KAAK,CAAC,GAAG,WAAW;IACjD,MAAM,aAAa,CAAA,GAAA,qBAAQ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;gCAC1B;4BACF;wBAEJ;oBAAA;oBAGF,wBAAwB;oBACxB,IAAI,CAAC,YAAY,MAAM,IAAI,YAAY,QAAQ,CAAC,UAC9C,KAAK,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAE;wBACjC,MAAM,QAAQ,CAAA,GAAA,yCAAuB,EAAE,KAAK;4BAC1C;yBACD;wBACD,IAAI,OACF,UAAU,IAAI,CAAC;4BACb,QAAQ,MAAM,OAAO,CAAC,KAAK;4BAC3B,aAAa,GAAG,WAAW;4BAC3B,MAAM,CAAA,GAAA,yCAAmB,EAAE,MAAM,OAAO,CAAC,IAAI,KAAe;4BAC5D,OAAO,IAAI,QAAQ;uCACnB;4BACA,IAAI,CAAA,GAAA,yCAAmB,EAAE,MAAM,OAAO,CAAC,EAAE,KAAe;4BACxD,OAAO,CAAA,GAAA,yCAAmB,EAAE,IAAI,OAAO;4BACvC,WAAW;+CACX;4BACA,iBAAiB,GAAG,IAAI;wBAC1B;oBAEJ;oBAGF,2BAA2B;oBAC3B,IAAI,CAAC,YAAY,MAAM,IAAI,YAAY,QAAQ,CAAC,QAAQ;wBACtD,KAAK,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI;oBAEnC;gBACF;QAEJ;QAEA,OAAO,UAAU,MAAM,CAAC,CAAC,QAAU,MAAM,MAAM,GAAG,OAAO;IAC3D;AACF;IAEA,2CAAe;;;AFhHR,MAAM,4CAAY;IAAC,CAAA,GAAA,wCAAQ;IAAG,CAAA,GAAA,wCAAa;CAAE;;;;;;;ADG7C,SAAS;IACd,OAAO,GAAA;AACT;AAEO,SAAS,0CAAiB,GAAW;IAC1C,OAAO,CAAA,GAAA,yCAAQ,EAAE,IAAI,CAAC,CAAC,WAAa,SAAS,GAAG,KAAK;AACvD","sources":["src/index.ts","src/templates/index.ts","src/templates/all-blocks.ts","src/templates/token-transfers.ts","src/utils/index.ts","src/utils/evm-address-to-checksum.ts","src/utils/evm-chain-to-id.ts","src/utils/evm-decode-log.ts","src/utils/evm-method-signature-to-hex.ts","src/utils/evm-normalize-raw-block.ts","src/types.ts"],"sourcesContent":["import { templates } from './templates';\nimport * as utils from './utils';\nimport * as types from './types';\n\nexport { utils, types };\n\nexport function getAllTemplates() {\n return templates;\n}\n\nexport function getTemplateByKey(key: string) {\n return templates.find((template) => template.key === key);\n}\n","import allBlocks from './all-blocks';\nimport tokenTransfers from './token-transfers';\n\nexport const templates = [allBlocks, tokenTransfers];","import { Template } from '../types';\n\nconst allBlocks: Template = {\n key: 'allBlocks',\n name: 'All Blocks',\n description: 'Get all blocks with all available fields',\n tags: ['EVM', 'TRANSACTIONS'],\n disabled: false,\n params: [],\n transform: (payload) => payload,\n};\n\nexport default allBlocks;\n","import { evmAddressToChecksum, evmDecodeLogWithMetadata } from '../utils';\nimport { Template } from '../types';\n\ntype NetworkTransfer = {\n amount: bigint;\n blockNumber: number;\n from: string;\n index?: string;\n timestamp: string;\n to: string;\n token?: string;\n tokenId?: string;\n tokenType: 'NATIVE' | 'TOKEN' | 'NFT';\n transactionGasFee: bigint;\n transactionHash: string;\n};\n\nconst NULL_ADDRESS = '0x0000000000000000000000000000000000000000';\n\nconst tokenTransfers: Template = {\n key: 'tokenTransfers',\n name: 'Token Transfers',\n description: 'Get all token transfers for a set of token types.',\n tags: ['EVM', 'ERC20', 'ERC721', 'NFT', 'TOKEN'],\n disabled: false,\n params: [{ key: 'tokenTypes', name: 'Token Types', type: 'STRING', multiple: true, optional: true }],\n\n transform: (block, _ctx) => {\n const TOKEN_TYPES = (_ctx.params.tokenTypes as NetworkTransfer['tokenType'][]) || [];\n const transfers: NetworkTransfer[] = [];\n\n switch (block._network) {\n // @TODO: expand to non-EVM\n\n // assume EVM as default for now\n default: {\n for (const tx of block.transactions as any[]) {\n if (!tx.receipt) {\n continue;\n }\n\n const timestamp = new Date((block.timestamp as number) * 1000).toISOString();\n const transactionGasFee = BigInt(tx.receipt.gasUsed) * BigInt(tx.receipt.effectiveGasPrice);\n\n // track direct ETH transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NATIVE')) {\n if ((tx.value as string)?.length >= 3 || /\\d+/.test(tx.value as string)) {\n transfers.push({\n amount: BigInt(tx.value as string),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(tx.from) || NULL_ADDRESS,\n timestamp,\n to: evmAddressToChecksum(tx.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n\n if (Array.isArray(tx.traces)) {\n for (const trace of tx.traces.filter((t) => t.action)) {\n const action = trace.action as unknown as { from: string; to: string; value: string };\n if (!action?.value) continue;\n\n transfers.push({\n amount: BigInt(action.value),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(action.from) || NULL_ADDRESS,\n index: trace.traceAddress?.join('-'),\n timestamp,\n to: evmAddressToChecksum(action.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n }\n\n // track ERC20 transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('TOKEN')) {\n for (const log of tx.receipt.logs) {\n const txfer = evmDecodeLogWithMetadata(log, [\n 'Transfer(address indexed from, address indexed to, uint256 value)',\n ]);\n if (txfer) {\n transfers.push({\n amount: txfer.decoded.value as bigint,\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(txfer.decoded.from as string) || NULL_ADDRESS,\n index: log.logIndex,\n timestamp,\n to: evmAddressToChecksum(txfer.decoded.to as string) || NULL_ADDRESS,\n token: evmAddressToChecksum(log.address as string),\n tokenType: 'TOKEN',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n\n // @TODO: add NFT transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NFT')) {\n for (const log of tx.receipt.logs) {\n }\n }\n }\n }\n }\n\n return transfers.filter((txfer) => txfer.amount > BigInt(0));\n },\n};\n\nexport default tokenTransfers;\n","export * from './evm-address-to-checksum';\nexport * from './evm-chain-to-id';\nexport * from './evm-decode-log';\nexport * from './evm-method-signature-to-hex';\nexport * from './evm-normalize-raw-block';\n","import { keccak256 } from 'viem';\n\nexport function evmAddressToChecksum(address: string) {\n if (!address || !/^(0x)?[0-9a-f]{40}$/i.test(address)) {\n return null;\n }\n\n const stripAddress = address.slice(2).toLowerCase();\n const keccakHash = keccak256(stripAddress as `0x${string}`);\n let checksumAddress = '0x';\n\n for (let i = 0; i < stripAddress.length; i++) {\n checksumAddress += parseInt(keccakHash[i], 16) >= 8 ? stripAddress[i].toUpperCase() : stripAddress[i];\n }\n\n return checksumAddress;\n}\n","const CHAIN_ID = {\n ARBITRUM: 42161,\n AVALANCHE: 43114,\n BASE: 8453,\n BASE_SEPOLIA: 84532,\n BERACHAIN_BARTIO: 80084,\n BLAST: 81457,\n BSC: 56,\n CELO: 42220,\n CYBER: 7560,\n DEGEN: 666666666,\n ETHEREUM: 1,\n ETH_HOLESKY: 17000,\n ETH_SEPOLIA: 11155111,\n FRAXTAL: 252,\n FRAXTAL_SEPOLIA: 2522,\n FUSE: 122,\n GNOSIS: 100,\n GOLD: 4653,\n HAM: 5112,\n HEMI_TESTNET: 743111,\n LINEA: 59144,\n LINEA_SEPOLIA: 59141,\n LISK_SEPOLIA: 4202,\n LYRA: 957,\n LYRA_SEPOLIA: 901,\n MODE: 34443,\n MODE_SEPOLIA: 919,\n NEON: 245022934,\n OASIS_SAPPHIRE: 23294,\n OPTIMISM: 10,\n OP_SEPOLIA: 11155420,\n ORDERLY: 291,\n ORDERLY_SEPOLIA: 4460,\n PGN_SEPOLIA: 58008,\n POLYGON: 137,\n POLYGON_AMOY: 80002,\n POLYGON_ZKEVM: 1101,\n PUBLIC_GOODS_NETWORK: 424,\n SCROLL: 534352,\n SCROLL_SEPOLIA: 534351,\n STACK: 78225,\n SYNDICATE_FRAME_CHAIN: 5101,\n TRON: 728126428,\n ZER0: 543210,\n ZK_LINK: 810180,\n ZORA: 7777777,\n ZORA_SEPOLIA: 999999999,\n};\n\nexport function evmChainToId(chain: string) {\n return CHAIN_ID[chain?.toUpperCase()];\n}\n","import { decodeEventLog, parseAbi } from 'viem';\n\nimport { evmMethodSignatureToHex } from './evm-method-signature-to-hex';\n\ntype BasicLog = Record<string, unknown> & { address: string; topics: string[] };\ntype SignaturesToDecode = string | { addresses?: string[]; signature: string; topic0?: string };\n\nexport function evmDecodeLog(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): Record<string, unknown> {\n if (Array.isArray(signatures)) {\n for (const sig of signatures) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return decoded;\n }\n }\n\n return null;\n }\n\n if (typeof signatures !== 'string' && Array.isArray(signatures.addresses) && signatures.addresses.length) {\n const addresses = signatures.addresses.map((a) => a?.toLowerCase());\n if (!addresses.includes(log.address.toLowerCase())) {\n return null;\n }\n }\n\n let sig = (typeof signatures === 'string' ? signatures : signatures.signature).trim();\n if (!sig.startsWith('event ')) {\n sig = 'event ' + sig;\n }\n const topic0 = typeof signatures !== 'string' && signatures.topic0 ? signatures.topic0 : evmMethodSignatureToHex(sig);\n if ((sig.match(/ indexed /g)?.length || 0) === log.topics.length - 1) {\n if (log.topics[0] === topic0) {\n try {\n const result = decodeEventLog({\n abi: parseAbi([sig]),\n data: log.data as `0x${string}`,\n topics: log.topics as [],\n });\n return result.args as unknown as Record<string, unknown>;\n } catch (e) {\n // ignore this\n }\n }\n }\n\n return null;\n}\n\nexport function evmDecodeLogWithMetadata(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): { decoded: Record<string, unknown>; metadata: { name: string } } {\n for (const sig of [signatures].flat()) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return {\n decoded,\n metadata: {\n name: (typeof sig === 'string' ? sig : sig.signature).split('(')[0],\n },\n };\n }\n }\n\n return null;\n}\n","import { keccak256 } from 'viem';\n\nexport function evmMethodSignatureToHex(sig: string): string {\n const [method, rest] = sig.split('(');\n const params = rest\n .split(')')[0]\n .split(',')\n .map((p) => p.trim());\n const topic0 = keccak256(\n `${method.split(' ').pop()}(${params.map((p) => p.split(' ')[0]).join(',')})` as `0x${string}`\n );\n return topic0;\n}\n","import { evmAddressToChecksum } from './evm-address-to-checksum';\n\nexport function normalizeEVMBlock(rawBlock: Record<string, unknown>): Record<string, unknown> {\n for (const k of ['baseFeePerGas', 'gasLimit', 'gasUsed', 'number', 'size', 'timestamp']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = parseInt(rawBlock[k] as string);\n }\n }\n\n for (const k of ['difficulty', 'totalDifficulty']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = BigInt(rawBlock[k] as string).toString();\n }\n }\n for (const k of ['miner']) {\n rawBlock[k] = evmAddressToChecksum(rawBlock[k] as string);\n }\n\n rawBlock.transactions = (\n rawBlock.transactions as { receipt: Record<string, unknown>; traces: Record<string, unknown>[] } & Record<\n string,\n unknown\n >[]\n ).map((tx) => {\n for (const k of [\n 'blockNumber',\n 'cumulativeGasUsed',\n 'effectiveGasPrice',\n 'gas',\n 'gasUsed',\n 'nonce',\n 'status',\n 'transactionIndex',\n ]) {\n if (typeof tx[k] === 'string') {\n tx[k] = parseInt(tx[k] as string);\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = parseInt(tx.receipt[k] as string);\n }\n }\n\n for (const k of ['gasPrice', 'maxFeePerGas', 'maxPriorityFeePerGas', 'value']) {\n if (typeof tx[k] === 'string') {\n tx[k] = BigInt(tx[k] as string).toString();\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = BigInt(tx.receipt[k] as string).toString();\n }\n }\n\n for (const k of ['from', 'to']) {\n if (typeof tx[k] === 'string') {\n tx[k] = evmAddressToChecksum(tx[k] as string);\n }\n }\n for (const k of ['contractAddress']) {\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = evmAddressToChecksum(tx.receipt[k] as string);\n }\n }\n\n tx.type = parseInt(tx.type as string);\n tx.receipt['status'] = Boolean(tx.receipt['status'] as string);\n\n tx.receipt['logs'] = (tx.receipt['logs'] as Record<string, unknown>[])?.map((log) => {\n for (const k of ['blockNumber', 'logIndex', 'transactionIndex']) {\n if (typeof log[k] === 'string') {\n log[k] = parseInt(log[k] as string);\n }\n }\n log['address'] = evmAddressToChecksum(log['address'] as string);\n return log;\n });\n\n return tx;\n });\n\n return rawBlock;\n}\n","export type Template = {\n key: string;\n name: string;\n description: string;\n disabled: boolean;\n tags: string[];\n params: Param[];\n transform: (\n payload: Record<string, unknown>,\n _ctx?: Record<string, unknown> & { params: Record<string, unknown> }\n ) => unknown;\n};\n\nexport type Param = {\n key: string;\n name: string;\n type: 'NETWORK' | 'ADDRESS' | 'STRING';\n multiple?: boolean;\n optional?: boolean;\n};\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js ADDED
@@ -0,0 +1,362 @@
1
+ import {keccak256 as $hgUW1$keccak256, decodeEventLog as $hgUW1$decodeEventLog, parseAbi as $hgUW1$parseAbi} from "viem";
2
+
3
+
4
+ function $parcel$exportWildcard(dest, source) {
5
+ Object.keys(source).forEach(function(key) {
6
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
7
+ return;
8
+ }
9
+
10
+ Object.defineProperty(dest, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return source[key];
14
+ }
15
+ });
16
+ });
17
+
18
+ return dest;
19
+ }
20
+
21
+ function $parcel$export(e, n, v, s) {
22
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
23
+ }
24
+ const $8369cdd4433d3a57$var$allBlocks = {
25
+ key: "allBlocks",
26
+ name: "All Blocks",
27
+ description: "Get all blocks with all available fields",
28
+ tags: [
29
+ "EVM",
30
+ "TRANSACTIONS"
31
+ ],
32
+ disabled: false,
33
+ params: [],
34
+ transform: (payload)=>payload
35
+ };
36
+ var $8369cdd4433d3a57$export$2e2bcd8739ae039 = $8369cdd4433d3a57$var$allBlocks;
37
+
38
+
39
+ var $fde9406d76ec24a9$exports = {};
40
+ var $42564d9f228fe302$exports = {};
41
+
42
+ $parcel$export($42564d9f228fe302$exports, "evmAddressToChecksum", () => $42564d9f228fe302$export$db81f9ea057ab646);
43
+
44
+ function $42564d9f228fe302$export$db81f9ea057ab646(address) {
45
+ if (!address || !/^(0x)?[0-9a-f]{40}$/i.test(address)) return null;
46
+ const stripAddress = address.slice(2).toLowerCase();
47
+ const keccakHash = (0, $hgUW1$keccak256)(stripAddress);
48
+ let checksumAddress = "0x";
49
+ for(let i = 0; i < stripAddress.length; i++)checksumAddress += parseInt(keccakHash[i], 16) >= 8 ? stripAddress[i].toUpperCase() : stripAddress[i];
50
+ return checksumAddress;
51
+ }
52
+
53
+
54
+ var $68871103c7bc00cf$exports = {};
55
+
56
+ $parcel$export($68871103c7bc00cf$exports, "evmChainToId", () => $68871103c7bc00cf$export$f93b8abed77a4120);
57
+ const $68871103c7bc00cf$var$CHAIN_ID = {
58
+ ARBITRUM: 42161,
59
+ AVALANCHE: 43114,
60
+ BASE: 8453,
61
+ BASE_SEPOLIA: 84532,
62
+ BERACHAIN_BARTIO: 80084,
63
+ BLAST: 81457,
64
+ BSC: 56,
65
+ CELO: 42220,
66
+ CYBER: 7560,
67
+ DEGEN: 666666666,
68
+ ETHEREUM: 1,
69
+ ETH_HOLESKY: 17000,
70
+ ETH_SEPOLIA: 11155111,
71
+ FRAXTAL: 252,
72
+ FRAXTAL_SEPOLIA: 2522,
73
+ FUSE: 122,
74
+ GNOSIS: 100,
75
+ GOLD: 4653,
76
+ HAM: 5112,
77
+ HEMI_TESTNET: 743111,
78
+ LINEA: 59144,
79
+ LINEA_SEPOLIA: 59141,
80
+ LISK_SEPOLIA: 4202,
81
+ LYRA: 957,
82
+ LYRA_SEPOLIA: 901,
83
+ MODE: 34443,
84
+ MODE_SEPOLIA: 919,
85
+ NEON: 245022934,
86
+ OASIS_SAPPHIRE: 23294,
87
+ OPTIMISM: 10,
88
+ OP_SEPOLIA: 11155420,
89
+ ORDERLY: 291,
90
+ ORDERLY_SEPOLIA: 4460,
91
+ PGN_SEPOLIA: 58008,
92
+ POLYGON: 137,
93
+ POLYGON_AMOY: 80002,
94
+ POLYGON_ZKEVM: 1101,
95
+ PUBLIC_GOODS_NETWORK: 424,
96
+ SCROLL: 534352,
97
+ SCROLL_SEPOLIA: 534351,
98
+ STACK: 78225,
99
+ SYNDICATE_FRAME_CHAIN: 5101,
100
+ TRON: 728126428,
101
+ ZER0: 543210,
102
+ ZK_LINK: 810180,
103
+ ZORA: 7777777,
104
+ ZORA_SEPOLIA: 999999999
105
+ };
106
+ function $68871103c7bc00cf$export$f93b8abed77a4120(chain) {
107
+ return $68871103c7bc00cf$var$CHAIN_ID[chain?.toUpperCase()];
108
+ }
109
+
110
+
111
+ var $cfa23334cbdf9391$exports = {};
112
+
113
+ $parcel$export($cfa23334cbdf9391$exports, "evmDecodeLog", () => $cfa23334cbdf9391$export$18467e329ea485c9);
114
+ $parcel$export($cfa23334cbdf9391$exports, "evmDecodeLogWithMetadata", () => $cfa23334cbdf9391$export$cf548b70626e2eb9);
115
+
116
+ var $f6a81337d3532e59$exports = {};
117
+
118
+ $parcel$export($f6a81337d3532e59$exports, "evmMethodSignatureToHex", () => $f6a81337d3532e59$export$49d5c9473f8f70f2);
119
+
120
+ function $f6a81337d3532e59$export$49d5c9473f8f70f2(sig) {
121
+ const [method, rest] = sig.split("(");
122
+ const params = rest.split(")")[0].split(",").map((p)=>p.trim());
123
+ const topic0 = (0, $hgUW1$keccak256)(`${method.split(" ").pop()}(${params.map((p)=>p.split(" ")[0]).join(",")})`);
124
+ return topic0;
125
+ }
126
+
127
+
128
+ function $cfa23334cbdf9391$export$18467e329ea485c9(log, signatures) {
129
+ if (Array.isArray(signatures)) {
130
+ for (const sig of signatures){
131
+ const decoded = $cfa23334cbdf9391$export$18467e329ea485c9(log, sig);
132
+ if (decoded) return decoded;
133
+ }
134
+ return null;
135
+ }
136
+ if (typeof signatures !== "string" && Array.isArray(signatures.addresses) && signatures.addresses.length) {
137
+ const addresses = signatures.addresses.map((a)=>a?.toLowerCase());
138
+ if (!addresses.includes(log.address.toLowerCase())) return null;
139
+ }
140
+ let sig = (typeof signatures === "string" ? signatures : signatures.signature).trim();
141
+ if (!sig.startsWith("event ")) sig = "event " + sig;
142
+ const topic0 = typeof signatures !== "string" && signatures.topic0 ? signatures.topic0 : (0, $f6a81337d3532e59$export$49d5c9473f8f70f2)(sig);
143
+ if ((sig.match(/ indexed /g)?.length || 0) === log.topics.length - 1) {
144
+ if (log.topics[0] === topic0) try {
145
+ const result = (0, $hgUW1$decodeEventLog)({
146
+ abi: (0, $hgUW1$parseAbi)([
147
+ sig
148
+ ]),
149
+ data: log.data,
150
+ topics: log.topics
151
+ });
152
+ return result.args;
153
+ } catch (e) {
154
+ // ignore this
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+ function $cfa23334cbdf9391$export$cf548b70626e2eb9(log, signatures) {
160
+ for (const sig of [
161
+ signatures
162
+ ].flat()){
163
+ const decoded = $cfa23334cbdf9391$export$18467e329ea485c9(log, sig);
164
+ if (decoded) return {
165
+ decoded: decoded,
166
+ metadata: {
167
+ name: (typeof sig === "string" ? sig : sig.signature).split("(")[0]
168
+ }
169
+ };
170
+ }
171
+ return null;
172
+ }
173
+
174
+
175
+
176
+ var $8f1e0ae1ead9a2a9$exports = {};
177
+
178
+ $parcel$export($8f1e0ae1ead9a2a9$exports, "normalizeEVMBlock", () => $8f1e0ae1ead9a2a9$export$685b7dc2197cd06c);
179
+
180
+ function $8f1e0ae1ead9a2a9$export$685b7dc2197cd06c(rawBlock) {
181
+ for (const k of [
182
+ "baseFeePerGas",
183
+ "gasLimit",
184
+ "gasUsed",
185
+ "number",
186
+ "size",
187
+ "timestamp"
188
+ ])if (typeof rawBlock[k] === "string") rawBlock[k] = parseInt(rawBlock[k]);
189
+ for (const k of [
190
+ "difficulty",
191
+ "totalDifficulty"
192
+ ])if (typeof rawBlock[k] === "string") rawBlock[k] = BigInt(rawBlock[k]).toString();
193
+ for (const k of [
194
+ "miner"
195
+ ])rawBlock[k] = (0, $42564d9f228fe302$export$db81f9ea057ab646)(rawBlock[k]);
196
+ rawBlock.transactions = rawBlock.transactions.map((tx)=>{
197
+ for (const k of [
198
+ "blockNumber",
199
+ "cumulativeGasUsed",
200
+ "effectiveGasPrice",
201
+ "gas",
202
+ "gasUsed",
203
+ "nonce",
204
+ "status",
205
+ "transactionIndex"
206
+ ]){
207
+ if (typeof tx[k] === "string") tx[k] = parseInt(tx[k]);
208
+ if (typeof tx.receipt[k] === "string") tx.receipt[k] = parseInt(tx.receipt[k]);
209
+ }
210
+ for (const k of [
211
+ "gasPrice",
212
+ "maxFeePerGas",
213
+ "maxPriorityFeePerGas",
214
+ "value"
215
+ ]){
216
+ if (typeof tx[k] === "string") tx[k] = BigInt(tx[k]).toString();
217
+ if (typeof tx.receipt[k] === "string") tx.receipt[k] = BigInt(tx.receipt[k]).toString();
218
+ }
219
+ for (const k of [
220
+ "from",
221
+ "to"
222
+ ])if (typeof tx[k] === "string") tx[k] = (0, $42564d9f228fe302$export$db81f9ea057ab646)(tx[k]);
223
+ for (const k of [
224
+ "contractAddress"
225
+ ])if (typeof tx.receipt[k] === "string") tx.receipt[k] = (0, $42564d9f228fe302$export$db81f9ea057ab646)(tx.receipt[k]);
226
+ tx.type = parseInt(tx.type);
227
+ tx.receipt["status"] = Boolean(tx.receipt["status"]);
228
+ tx.receipt["logs"] = tx.receipt["logs"]?.map((log)=>{
229
+ for (const k of [
230
+ "blockNumber",
231
+ "logIndex",
232
+ "transactionIndex"
233
+ ])if (typeof log[k] === "string") log[k] = parseInt(log[k]);
234
+ log["address"] = (0, $42564d9f228fe302$export$db81f9ea057ab646)(log["address"]);
235
+ return log;
236
+ });
237
+ return tx;
238
+ });
239
+ return rawBlock;
240
+ }
241
+
242
+
243
+ $parcel$exportWildcard($fde9406d76ec24a9$exports, $42564d9f228fe302$exports);
244
+ $parcel$exportWildcard($fde9406d76ec24a9$exports, $68871103c7bc00cf$exports);
245
+ $parcel$exportWildcard($fde9406d76ec24a9$exports, $cfa23334cbdf9391$exports);
246
+ $parcel$exportWildcard($fde9406d76ec24a9$exports, $f6a81337d3532e59$exports);
247
+ $parcel$exportWildcard($fde9406d76ec24a9$exports, $8f1e0ae1ead9a2a9$exports);
248
+
249
+
250
+ const $c18434deda90759d$var$NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
251
+ const $c18434deda90759d$var$tokenTransfers = {
252
+ key: "tokenTransfers",
253
+ name: "Token Transfers",
254
+ description: "Get all token transfers for a set of token types.",
255
+ tags: [
256
+ "EVM",
257
+ "ERC20",
258
+ "ERC721",
259
+ "NFT",
260
+ "TOKEN"
261
+ ],
262
+ disabled: false,
263
+ params: [
264
+ {
265
+ key: "tokenTypes",
266
+ name: "Token Types",
267
+ type: "STRING",
268
+ multiple: true,
269
+ optional: true
270
+ }
271
+ ],
272
+ transform: (block, _ctx)=>{
273
+ const TOKEN_TYPES = _ctx.params.tokenTypes || [];
274
+ const transfers = [];
275
+ switch(block._network){
276
+ // @TODO: expand to non-EVM
277
+ // assume EVM as default for now
278
+ default:
279
+ for (const tx of block.transactions){
280
+ if (!tx.receipt) continue;
281
+ const timestamp = new Date(block.timestamp * 1000).toISOString();
282
+ const transactionGasFee = BigInt(tx.receipt.gasUsed) * BigInt(tx.receipt.effectiveGasPrice);
283
+ // track direct ETH transfers
284
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("NATIVE")) {
285
+ if (tx.value?.length >= 3 || /\d+/.test(tx.value)) {
286
+ transfers.push({
287
+ amount: BigInt(tx.value),
288
+ blockNumber: tx.blockNumber,
289
+ from: (0, $42564d9f228fe302$export$db81f9ea057ab646)(tx.from) || $c18434deda90759d$var$NULL_ADDRESS,
290
+ timestamp: timestamp,
291
+ to: (0, $42564d9f228fe302$export$db81f9ea057ab646)(tx.to) || $c18434deda90759d$var$NULL_ADDRESS,
292
+ tokenType: "NATIVE",
293
+ transactionGasFee: transactionGasFee,
294
+ transactionHash: tx.hash
295
+ });
296
+ if (Array.isArray(tx.traces)) for (const trace of tx.traces.filter((t)=>t.action)){
297
+ const action = trace.action;
298
+ if (!action?.value) continue;
299
+ transfers.push({
300
+ amount: BigInt(action.value),
301
+ blockNumber: tx.blockNumber,
302
+ from: (0, $42564d9f228fe302$export$db81f9ea057ab646)(action.from) || $c18434deda90759d$var$NULL_ADDRESS,
303
+ index: trace.traceAddress?.join("-"),
304
+ timestamp: timestamp,
305
+ to: (0, $42564d9f228fe302$export$db81f9ea057ab646)(action.to) || $c18434deda90759d$var$NULL_ADDRESS,
306
+ tokenType: "NATIVE",
307
+ transactionGasFee: transactionGasFee,
308
+ transactionHash: tx.hash
309
+ });
310
+ }
311
+ }
312
+ }
313
+ // track ERC20 transfers
314
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("TOKEN")) for (const log of tx.receipt.logs){
315
+ const txfer = (0, $cfa23334cbdf9391$export$cf548b70626e2eb9)(log, [
316
+ "Transfer(address indexed from, address indexed to, uint256 value)"
317
+ ]);
318
+ if (txfer) transfers.push({
319
+ amount: txfer.decoded.value,
320
+ blockNumber: tx.blockNumber,
321
+ from: (0, $42564d9f228fe302$export$db81f9ea057ab646)(txfer.decoded.from) || $c18434deda90759d$var$NULL_ADDRESS,
322
+ index: log.logIndex,
323
+ timestamp: timestamp,
324
+ to: (0, $42564d9f228fe302$export$db81f9ea057ab646)(txfer.decoded.to) || $c18434deda90759d$var$NULL_ADDRESS,
325
+ token: (0, $42564d9f228fe302$export$db81f9ea057ab646)(log.address),
326
+ tokenType: "TOKEN",
327
+ transactionGasFee: transactionGasFee,
328
+ transactionHash: tx.hash
329
+ });
330
+ }
331
+ // @TODO: add NFT transfers
332
+ if (!TOKEN_TYPES.length || TOKEN_TYPES.includes("NFT")) {
333
+ for (const log of tx.receipt.logs);
334
+ }
335
+ }
336
+ }
337
+ return transfers.filter((txfer)=>txfer.amount > BigInt(0));
338
+ }
339
+ };
340
+ var $c18434deda90759d$export$2e2bcd8739ae039 = $c18434deda90759d$var$tokenTransfers;
341
+
342
+
343
+ const $70cb039dbeb3c65a$export$a8fc3402335b0b04 = [
344
+ (0, $8369cdd4433d3a57$export$2e2bcd8739ae039),
345
+ (0, $c18434deda90759d$export$2e2bcd8739ae039)
346
+ ];
347
+
348
+
349
+
350
+ var $81c1b644006d48ec$exports = {};
351
+
352
+
353
+ function $149c1bd638913645$export$cceb5167b935aafb() {
354
+ return 0, $70cb039dbeb3c65a$export$a8fc3402335b0b04;
355
+ }
356
+ function $149c1bd638913645$export$a07bfd14bbc36e4b(key) {
357
+ return (0, $70cb039dbeb3c65a$export$a8fc3402335b0b04).find((template)=>template.key === key);
358
+ }
359
+
360
+
361
+ export {$149c1bd638913645$export$cceb5167b935aafb as getAllTemplates, $149c1bd638913645$export$a07bfd14bbc36e4b as getTemplateByKey};
362
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;AEEA,MAAM,kCAAsB;IAC1B,KAAK;IACL,MAAM;IACN,aAAa;IACb,MAAM;QAAC;QAAO;KAAe;IAC7B,UAAU;IACV,QAAQ,EAAE;IACV,WAAW,CAAC,UAAY;AAC1B;IAEA,2CAAe;;;;;;;;AGVR,SAAS,0CAAqB,OAAe;IAClD,IAAI,CAAC,WAAW,CAAC,uBAAuB,IAAI,CAAC,UAC3C,OAAO;IAGT,MAAM,eAAe,QAAQ,KAAK,CAAC,GAAG,WAAW;IACjD,MAAM,aAAa,CAAA,GAAA,gBAAQ,EAAE;IAC7B,IAAI,kBAAkB;IAEtB,IAAK,IAAI,IAAI,GAAG,IAAI,aAAa,MAAM,EAAE,IACvC,mBAAmB,SAAS,UAAU,CAAC,EAAE,EAAE,OAAO,IAAI,YAAY,CAAC,EAAE,CAAC,WAAW,KAAK,YAAY,CAAC,EAAE;IAGvG,OAAO;AACT;;;;;;AChBA,MAAM,iCAAW;IACf,UAAU;IACV,WAAW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4BACb,QAAQ,MAAM,OAAO,CAAC,KAAK;4BAC3B,aAAa,GAAG,WAAW;4BAC3B,MAAM,CAAA,GAAA,yCAAmB,EAAE,MAAM,OAAO,CAAC,IAAI,KAAe;4BAC5D,OAAO,IAAI,QAAQ;uCACnB;4BACA,IAAI,CAAA,GAAA,yCAAmB,EAAE,MAAM,OAAO,CAAC,EAAE,KAAe;4BACxD,OAAO,CAAA,GAAA,yCAAmB,EAAE,IAAI,OAAO;4BACvC,WAAW;+CACX;4BACA,iBAAiB,GAAG,IAAI;wBAC1B;oBAEJ;oBAGF,2BAA2B;oBAC3B,IAAI,CAAC,YAAY,MAAM,IAAI,YAAY,QAAQ,CAAC,QAAQ;wBACtD,KAAK,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI;oBAEnC;gBACF;QAEJ;QAEA,OAAO,UAAU,MAAM,CAAC,CAAC,QAAU,MAAM,MAAM,GAAG,OAAO;IAC3D;AACF;IAEA,2CAAe;;;AFhHR,MAAM,4CAAY;IAAC,CAAA,GAAA,wCAAQ;IAAG,CAAA,GAAA,wCAAa;CAAE;;;;;;;ADG7C,SAAS;IACd,OAAO,GAAA;AACT;AAEO,SAAS,0CAAiB,GAAW;IAC1C,OAAO,CAAA,GAAA,yCAAQ,EAAE,IAAI,CAAC,CAAC,WAAa,SAAS,GAAG,KAAK;AACvD","sources":["src/index.ts","src/templates/index.ts","src/templates/all-blocks.ts","src/templates/token-transfers.ts","src/utils/index.ts","src/utils/evm-address-to-checksum.ts","src/utils/evm-chain-to-id.ts","src/utils/evm-decode-log.ts","src/utils/evm-method-signature-to-hex.ts","src/utils/evm-normalize-raw-block.ts","src/types.ts"],"sourcesContent":["import { templates } from './templates';\nimport * as utils from './utils';\nimport * as types from './types';\n\nexport { utils, types };\n\nexport function getAllTemplates() {\n return templates;\n}\n\nexport function getTemplateByKey(key: string) {\n return templates.find((template) => template.key === key);\n}\n","import allBlocks from './all-blocks';\nimport tokenTransfers from './token-transfers';\n\nexport const templates = [allBlocks, tokenTransfers];","import { Template } from '../types';\n\nconst allBlocks: Template = {\n key: 'allBlocks',\n name: 'All Blocks',\n description: 'Get all blocks with all available fields',\n tags: ['EVM', 'TRANSACTIONS'],\n disabled: false,\n params: [],\n transform: (payload) => payload,\n};\n\nexport default allBlocks;\n","import { evmAddressToChecksum, evmDecodeLogWithMetadata } from '../utils';\nimport { Template } from '../types';\n\ntype NetworkTransfer = {\n amount: bigint;\n blockNumber: number;\n from: string;\n index?: string;\n timestamp: string;\n to: string;\n token?: string;\n tokenId?: string;\n tokenType: 'NATIVE' | 'TOKEN' | 'NFT';\n transactionGasFee: bigint;\n transactionHash: string;\n};\n\nconst NULL_ADDRESS = '0x0000000000000000000000000000000000000000';\n\nconst tokenTransfers: Template = {\n key: 'tokenTransfers',\n name: 'Token Transfers',\n description: 'Get all token transfers for a set of token types.',\n tags: ['EVM', 'ERC20', 'ERC721', 'NFT', 'TOKEN'],\n disabled: false,\n params: [{ key: 'tokenTypes', name: 'Token Types', type: 'STRING', multiple: true, optional: true }],\n\n transform: (block, _ctx) => {\n const TOKEN_TYPES = (_ctx.params.tokenTypes as NetworkTransfer['tokenType'][]) || [];\n const transfers: NetworkTransfer[] = [];\n\n switch (block._network) {\n // @TODO: expand to non-EVM\n\n // assume EVM as default for now\n default: {\n for (const tx of block.transactions as any[]) {\n if (!tx.receipt) {\n continue;\n }\n\n const timestamp = new Date((block.timestamp as number) * 1000).toISOString();\n const transactionGasFee = BigInt(tx.receipt.gasUsed) * BigInt(tx.receipt.effectiveGasPrice);\n\n // track direct ETH transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NATIVE')) {\n if ((tx.value as string)?.length >= 3 || /\\d+/.test(tx.value as string)) {\n transfers.push({\n amount: BigInt(tx.value as string),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(tx.from) || NULL_ADDRESS,\n timestamp,\n to: evmAddressToChecksum(tx.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n\n if (Array.isArray(tx.traces)) {\n for (const trace of tx.traces.filter((t) => t.action)) {\n const action = trace.action as unknown as { from: string; to: string; value: string };\n if (!action?.value) continue;\n\n transfers.push({\n amount: BigInt(action.value),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(action.from) || NULL_ADDRESS,\n index: trace.traceAddress?.join('-'),\n timestamp,\n to: evmAddressToChecksum(action.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n }\n\n // track ERC20 transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('TOKEN')) {\n for (const log of tx.receipt.logs) {\n const txfer = evmDecodeLogWithMetadata(log, [\n 'Transfer(address indexed from, address indexed to, uint256 value)',\n ]);\n if (txfer) {\n transfers.push({\n amount: txfer.decoded.value as bigint,\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(txfer.decoded.from as string) || NULL_ADDRESS,\n index: log.logIndex,\n timestamp,\n to: evmAddressToChecksum(txfer.decoded.to as string) || NULL_ADDRESS,\n token: evmAddressToChecksum(log.address as string),\n tokenType: 'TOKEN',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n\n // @TODO: add NFT transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NFT')) {\n for (const log of tx.receipt.logs) {\n }\n }\n }\n }\n }\n\n return transfers.filter((txfer) => txfer.amount > BigInt(0));\n },\n};\n\nexport default tokenTransfers;\n","export * from './evm-address-to-checksum';\nexport * from './evm-chain-to-id';\nexport * from './evm-decode-log';\nexport * from './evm-method-signature-to-hex';\nexport * from './evm-normalize-raw-block';\n","import { keccak256 } from 'viem';\n\nexport function evmAddressToChecksum(address: string) {\n if (!address || !/^(0x)?[0-9a-f]{40}$/i.test(address)) {\n return null;\n }\n\n const stripAddress = address.slice(2).toLowerCase();\n const keccakHash = keccak256(stripAddress as `0x${string}`);\n let checksumAddress = '0x';\n\n for (let i = 0; i < stripAddress.length; i++) {\n checksumAddress += parseInt(keccakHash[i], 16) >= 8 ? stripAddress[i].toUpperCase() : stripAddress[i];\n }\n\n return checksumAddress;\n}\n","const CHAIN_ID = {\n ARBITRUM: 42161,\n AVALANCHE: 43114,\n BASE: 8453,\n BASE_SEPOLIA: 84532,\n BERACHAIN_BARTIO: 80084,\n BLAST: 81457,\n BSC: 56,\n CELO: 42220,\n CYBER: 7560,\n DEGEN: 666666666,\n ETHEREUM: 1,\n ETH_HOLESKY: 17000,\n ETH_SEPOLIA: 11155111,\n FRAXTAL: 252,\n FRAXTAL_SEPOLIA: 2522,\n FUSE: 122,\n GNOSIS: 100,\n GOLD: 4653,\n HAM: 5112,\n HEMI_TESTNET: 743111,\n LINEA: 59144,\n LINEA_SEPOLIA: 59141,\n LISK_SEPOLIA: 4202,\n LYRA: 957,\n LYRA_SEPOLIA: 901,\n MODE: 34443,\n MODE_SEPOLIA: 919,\n NEON: 245022934,\n OASIS_SAPPHIRE: 23294,\n OPTIMISM: 10,\n OP_SEPOLIA: 11155420,\n ORDERLY: 291,\n ORDERLY_SEPOLIA: 4460,\n PGN_SEPOLIA: 58008,\n POLYGON: 137,\n POLYGON_AMOY: 80002,\n POLYGON_ZKEVM: 1101,\n PUBLIC_GOODS_NETWORK: 424,\n SCROLL: 534352,\n SCROLL_SEPOLIA: 534351,\n STACK: 78225,\n SYNDICATE_FRAME_CHAIN: 5101,\n TRON: 728126428,\n ZER0: 543210,\n ZK_LINK: 810180,\n ZORA: 7777777,\n ZORA_SEPOLIA: 999999999,\n};\n\nexport function evmChainToId(chain: string) {\n return CHAIN_ID[chain?.toUpperCase()];\n}\n","import { decodeEventLog, parseAbi } from 'viem';\n\nimport { evmMethodSignatureToHex } from './evm-method-signature-to-hex';\n\ntype BasicLog = Record<string, unknown> & { address: string; topics: string[] };\ntype SignaturesToDecode = string | { addresses?: string[]; signature: string; topic0?: string };\n\nexport function evmDecodeLog(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): Record<string, unknown> {\n if (Array.isArray(signatures)) {\n for (const sig of signatures) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return decoded;\n }\n }\n\n return null;\n }\n\n if (typeof signatures !== 'string' && Array.isArray(signatures.addresses) && signatures.addresses.length) {\n const addresses = signatures.addresses.map((a) => a?.toLowerCase());\n if (!addresses.includes(log.address.toLowerCase())) {\n return null;\n }\n }\n\n let sig = (typeof signatures === 'string' ? signatures : signatures.signature).trim();\n if (!sig.startsWith('event ')) {\n sig = 'event ' + sig;\n }\n const topic0 = typeof signatures !== 'string' && signatures.topic0 ? signatures.topic0 : evmMethodSignatureToHex(sig);\n if ((sig.match(/ indexed /g)?.length || 0) === log.topics.length - 1) {\n if (log.topics[0] === topic0) {\n try {\n const result = decodeEventLog({\n abi: parseAbi([sig]),\n data: log.data as `0x${string}`,\n topics: log.topics as [],\n });\n return result.args as unknown as Record<string, unknown>;\n } catch (e) {\n // ignore this\n }\n }\n }\n\n return null;\n}\n\nexport function evmDecodeLogWithMetadata(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): { decoded: Record<string, unknown>; metadata: { name: string } } {\n for (const sig of [signatures].flat()) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return {\n decoded,\n metadata: {\n name: (typeof sig === 'string' ? sig : sig.signature).split('(')[0],\n },\n };\n }\n }\n\n return null;\n}\n","import { keccak256 } from 'viem';\n\nexport function evmMethodSignatureToHex(sig: string): string {\n const [method, rest] = sig.split('(');\n const params = rest\n .split(')')[0]\n .split(',')\n .map((p) => p.trim());\n const topic0 = keccak256(\n `${method.split(' ').pop()}(${params.map((p) => p.split(' ')[0]).join(',')})` as `0x${string}`\n );\n return topic0;\n}\n","import { evmAddressToChecksum } from './evm-address-to-checksum';\n\nexport function normalizeEVMBlock(rawBlock: Record<string, unknown>): Record<string, unknown> {\n for (const k of ['baseFeePerGas', 'gasLimit', 'gasUsed', 'number', 'size', 'timestamp']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = parseInt(rawBlock[k] as string);\n }\n }\n\n for (const k of ['difficulty', 'totalDifficulty']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = BigInt(rawBlock[k] as string).toString();\n }\n }\n for (const k of ['miner']) {\n rawBlock[k] = evmAddressToChecksum(rawBlock[k] as string);\n }\n\n rawBlock.transactions = (\n rawBlock.transactions as { receipt: Record<string, unknown>; traces: Record<string, unknown>[] } & Record<\n string,\n unknown\n >[]\n ).map((tx) => {\n for (const k of [\n 'blockNumber',\n 'cumulativeGasUsed',\n 'effectiveGasPrice',\n 'gas',\n 'gasUsed',\n 'nonce',\n 'status',\n 'transactionIndex',\n ]) {\n if (typeof tx[k] === 'string') {\n tx[k] = parseInt(tx[k] as string);\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = parseInt(tx.receipt[k] as string);\n }\n }\n\n for (const k of ['gasPrice', 'maxFeePerGas', 'maxPriorityFeePerGas', 'value']) {\n if (typeof tx[k] === 'string') {\n tx[k] = BigInt(tx[k] as string).toString();\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = BigInt(tx.receipt[k] as string).toString();\n }\n }\n\n for (const k of ['from', 'to']) {\n if (typeof tx[k] === 'string') {\n tx[k] = evmAddressToChecksum(tx[k] as string);\n }\n }\n for (const k of ['contractAddress']) {\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = evmAddressToChecksum(tx.receipt[k] as string);\n }\n }\n\n tx.type = parseInt(tx.type as string);\n tx.receipt['status'] = Boolean(tx.receipt['status'] as string);\n\n tx.receipt['logs'] = (tx.receipt['logs'] as Record<string, unknown>[])?.map((log) => {\n for (const k of ['blockNumber', 'logIndex', 'transactionIndex']) {\n if (typeof log[k] === 'string') {\n log[k] = parseInt(log[k] as string);\n }\n }\n log['address'] = evmAddressToChecksum(log['address'] as string);\n return log;\n });\n\n return tx;\n });\n\n return rawBlock;\n}\n","export type Template = {\n key: string;\n name: string;\n description: string;\n disabled: boolean;\n tags: string[];\n params: Param[];\n transform: (\n payload: Record<string, unknown>,\n _ctx?: Record<string, unknown> & { params: Record<string, unknown> }\n ) => unknown;\n};\n\nexport type Param = {\n key: string;\n name: string;\n type: 'NETWORK' | 'ADDRESS' | 'STRING';\n multiple?: boolean;\n optional?: boolean;\n};\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,22 @@
1
+ type Template = {
2
+ key: string;
3
+ name: string;
4
+ description: string;
5
+ disabled: boolean;
6
+ tags: string[];
7
+ params: Param[];
8
+ transform: (payload: Record<string, unknown>, _ctx?: Record<string, unknown> & {
9
+ params: Record<string, unknown>;
10
+ }) => unknown;
11
+ };
12
+ type Param = {
13
+ key: string;
14
+ name: string;
15
+ type: 'NETWORK' | 'ADDRESS' | 'STRING';
16
+ multiple?: boolean;
17
+ optional?: boolean;
18
+ };
19
+ export function getAllTemplates(): Template[];
20
+ export function getTemplateByKey(key: string): Template;
21
+
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,gBAAuB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,SAAS,EAAE,CACT,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KACjE,OAAO,CAAC;CACd,CAAC;AAEF,aAAoB;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AUbF,8CAEC;AAED,iCAAiC,GAAG,EAAE,MAAM,YAE3C","sources":["src/types.ts","src/templates/all-blocks.ts","src/utils/evm-address-to-checksum.ts","src/utils/evm-chain-to-id.ts","src/utils/evm-method-signature-to-hex.ts","src/utils/evm-decode-log.ts","src/utils/evm-normalize-raw-block.ts","src/utils/index.ts","src/templates/token-transfers.ts","src/templates/index.ts","src/index.ts"],"sourcesContent":["export type Template = {\n key: string;\n name: string;\n description: string;\n disabled: boolean;\n tags: string[];\n params: Param[];\n transform: (\n payload: Record<string, unknown>,\n _ctx?: Record<string, unknown> & { params: Record<string, unknown> }\n ) => unknown;\n};\n\nexport type Param = {\n key: string;\n name: string;\n type: 'NETWORK' | 'ADDRESS' | 'STRING';\n multiple?: boolean;\n optional?: boolean;\n};\n","import { Template } from '../types';\n\nconst allBlocks: Template = {\n key: 'allBlocks',\n name: 'All Blocks',\n description: 'Get all blocks with all available fields',\n tags: ['EVM', 'TRANSACTIONS'],\n disabled: false,\n params: [],\n transform: (payload) => payload,\n};\n\nexport default allBlocks;\n","import { keccak256 } from 'viem';\n\nexport function evmAddressToChecksum(address: string) {\n if (!address || !/^(0x)?[0-9a-f]{40}$/i.test(address)) {\n return null;\n }\n\n const stripAddress = address.slice(2).toLowerCase();\n const keccakHash = keccak256(stripAddress as `0x${string}`);\n let checksumAddress = '0x';\n\n for (let i = 0; i < stripAddress.length; i++) {\n checksumAddress += parseInt(keccakHash[i], 16) >= 8 ? stripAddress[i].toUpperCase() : stripAddress[i];\n }\n\n return checksumAddress;\n}\n","const CHAIN_ID = {\n ARBITRUM: 42161,\n AVALANCHE: 43114,\n BASE: 8453,\n BASE_SEPOLIA: 84532,\n BERACHAIN_BARTIO: 80084,\n BLAST: 81457,\n BSC: 56,\n CELO: 42220,\n CYBER: 7560,\n DEGEN: 666666666,\n ETHEREUM: 1,\n ETH_HOLESKY: 17000,\n ETH_SEPOLIA: 11155111,\n FRAXTAL: 252,\n FRAXTAL_SEPOLIA: 2522,\n FUSE: 122,\n GNOSIS: 100,\n GOLD: 4653,\n HAM: 5112,\n HEMI_TESTNET: 743111,\n LINEA: 59144,\n LINEA_SEPOLIA: 59141,\n LISK_SEPOLIA: 4202,\n LYRA: 957,\n LYRA_SEPOLIA: 901,\n MODE: 34443,\n MODE_SEPOLIA: 919,\n NEON: 245022934,\n OASIS_SAPPHIRE: 23294,\n OPTIMISM: 10,\n OP_SEPOLIA: 11155420,\n ORDERLY: 291,\n ORDERLY_SEPOLIA: 4460,\n PGN_SEPOLIA: 58008,\n POLYGON: 137,\n POLYGON_AMOY: 80002,\n POLYGON_ZKEVM: 1101,\n PUBLIC_GOODS_NETWORK: 424,\n SCROLL: 534352,\n SCROLL_SEPOLIA: 534351,\n STACK: 78225,\n SYNDICATE_FRAME_CHAIN: 5101,\n TRON: 728126428,\n ZER0: 543210,\n ZK_LINK: 810180,\n ZORA: 7777777,\n ZORA_SEPOLIA: 999999999,\n};\n\nexport function evmChainToId(chain: string) {\n return CHAIN_ID[chain?.toUpperCase()];\n}\n","import { keccak256 } from 'viem';\n\nexport function evmMethodSignatureToHex(sig: string): string {\n const [method, rest] = sig.split('(');\n const params = rest\n .split(')')[0]\n .split(',')\n .map((p) => p.trim());\n const topic0 = keccak256(\n `${method.split(' ').pop()}(${params.map((p) => p.split(' ')[0]).join(',')})` as `0x${string}`\n );\n return topic0;\n}\n","import { decodeEventLog, parseAbi } from 'viem';\n\nimport { evmMethodSignatureToHex } from './evm-method-signature-to-hex';\n\ntype BasicLog = Record<string, unknown> & { address: string; topics: string[] };\ntype SignaturesToDecode = string | { addresses?: string[]; signature: string; topic0?: string };\n\nexport function evmDecodeLog(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): Record<string, unknown> {\n if (Array.isArray(signatures)) {\n for (const sig of signatures) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return decoded;\n }\n }\n\n return null;\n }\n\n if (typeof signatures !== 'string' && Array.isArray(signatures.addresses) && signatures.addresses.length) {\n const addresses = signatures.addresses.map((a) => a?.toLowerCase());\n if (!addresses.includes(log.address.toLowerCase())) {\n return null;\n }\n }\n\n let sig = (typeof signatures === 'string' ? signatures : signatures.signature).trim();\n if (!sig.startsWith('event ')) {\n sig = 'event ' + sig;\n }\n const topic0 = typeof signatures !== 'string' && signatures.topic0 ? signatures.topic0 : evmMethodSignatureToHex(sig);\n if ((sig.match(/ indexed /g)?.length || 0) === log.topics.length - 1) {\n if (log.topics[0] === topic0) {\n try {\n const result = decodeEventLog({\n abi: parseAbi([sig]),\n data: log.data as `0x${string}`,\n topics: log.topics as [],\n });\n return result.args as unknown as Record<string, unknown>;\n } catch (e) {\n // ignore this\n }\n }\n }\n\n return null;\n}\n\nexport function evmDecodeLogWithMetadata(\n log: BasicLog,\n signatures: SignaturesToDecode | SignaturesToDecode[]\n): { decoded: Record<string, unknown>; metadata: { name: string } } {\n for (const sig of [signatures].flat()) {\n const decoded = evmDecodeLog(log, sig);\n if (decoded) {\n return {\n decoded,\n metadata: {\n name: (typeof sig === 'string' ? sig : sig.signature).split('(')[0],\n },\n };\n }\n }\n\n return null;\n}\n","import { evmAddressToChecksum } from './evm-address-to-checksum';\n\nexport function normalizeEVMBlock(rawBlock: Record<string, unknown>): Record<string, unknown> {\n for (const k of ['baseFeePerGas', 'gasLimit', 'gasUsed', 'number', 'size', 'timestamp']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = parseInt(rawBlock[k] as string);\n }\n }\n\n for (const k of ['difficulty', 'totalDifficulty']) {\n if (typeof rawBlock[k] === 'string') {\n rawBlock[k] = BigInt(rawBlock[k] as string).toString();\n }\n }\n for (const k of ['miner']) {\n rawBlock[k] = evmAddressToChecksum(rawBlock[k] as string);\n }\n\n rawBlock.transactions = (\n rawBlock.transactions as { receipt: Record<string, unknown>; traces: Record<string, unknown>[] } & Record<\n string,\n unknown\n >[]\n ).map((tx) => {\n for (const k of [\n 'blockNumber',\n 'cumulativeGasUsed',\n 'effectiveGasPrice',\n 'gas',\n 'gasUsed',\n 'nonce',\n 'status',\n 'transactionIndex',\n ]) {\n if (typeof tx[k] === 'string') {\n tx[k] = parseInt(tx[k] as string);\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = parseInt(tx.receipt[k] as string);\n }\n }\n\n for (const k of ['gasPrice', 'maxFeePerGas', 'maxPriorityFeePerGas', 'value']) {\n if (typeof tx[k] === 'string') {\n tx[k] = BigInt(tx[k] as string).toString();\n }\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = BigInt(tx.receipt[k] as string).toString();\n }\n }\n\n for (const k of ['from', 'to']) {\n if (typeof tx[k] === 'string') {\n tx[k] = evmAddressToChecksum(tx[k] as string);\n }\n }\n for (const k of ['contractAddress']) {\n if (typeof tx.receipt[k] === 'string') {\n tx.receipt[k] = evmAddressToChecksum(tx.receipt[k] as string);\n }\n }\n\n tx.type = parseInt(tx.type as string);\n tx.receipt['status'] = Boolean(tx.receipt['status'] as string);\n\n tx.receipt['logs'] = (tx.receipt['logs'] as Record<string, unknown>[])?.map((log) => {\n for (const k of ['blockNumber', 'logIndex', 'transactionIndex']) {\n if (typeof log[k] === 'string') {\n log[k] = parseInt(log[k] as string);\n }\n }\n log['address'] = evmAddressToChecksum(log['address'] as string);\n return log;\n });\n\n return tx;\n });\n\n return rawBlock;\n}\n","export * from './evm-address-to-checksum';\nexport * from './evm-chain-to-id';\nexport * from './evm-decode-log';\nexport * from './evm-method-signature-to-hex';\nexport * from './evm-normalize-raw-block';\n","import { evmAddressToChecksum, evmDecodeLogWithMetadata } from '../utils';\nimport { Template } from '../types';\n\ntype NetworkTransfer = {\n amount: bigint;\n blockNumber: number;\n from: string;\n index?: string;\n timestamp: string;\n to: string;\n token?: string;\n tokenId?: string;\n tokenType: 'NATIVE' | 'TOKEN' | 'NFT';\n transactionGasFee: bigint;\n transactionHash: string;\n};\n\nconst NULL_ADDRESS = '0x0000000000000000000000000000000000000000';\n\nconst tokenTransfers: Template = {\n key: 'tokenTransfers',\n name: 'Token Transfers',\n description: 'Get all token transfers for a set of token types.',\n tags: ['EVM', 'ERC20', 'ERC721', 'NFT', 'TOKEN'],\n disabled: false,\n params: [{ key: 'tokenTypes', name: 'Token Types', type: 'STRING', multiple: true, optional: true }],\n\n transform: (block, _ctx) => {\n const TOKEN_TYPES = (_ctx.params.tokenTypes as NetworkTransfer['tokenType'][]) || [];\n const transfers: NetworkTransfer[] = [];\n\n switch (block._network) {\n // @TODO: expand to non-EVM\n\n // assume EVM as default for now\n default: {\n for (const tx of block.transactions as any[]) {\n if (!tx.receipt) {\n continue;\n }\n\n const timestamp = new Date((block.timestamp as number) * 1000).toISOString();\n const transactionGasFee = BigInt(tx.receipt.gasUsed) * BigInt(tx.receipt.effectiveGasPrice);\n\n // track direct ETH transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NATIVE')) {\n if ((tx.value as string)?.length >= 3 || /\\d+/.test(tx.value as string)) {\n transfers.push({\n amount: BigInt(tx.value as string),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(tx.from) || NULL_ADDRESS,\n timestamp,\n to: evmAddressToChecksum(tx.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n\n if (Array.isArray(tx.traces)) {\n for (const trace of tx.traces.filter((t) => t.action)) {\n const action = trace.action as unknown as { from: string; to: string; value: string };\n if (!action?.value) continue;\n\n transfers.push({\n amount: BigInt(action.value),\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(action.from) || NULL_ADDRESS,\n index: trace.traceAddress?.join('-'),\n timestamp,\n to: evmAddressToChecksum(action.to) || NULL_ADDRESS,\n tokenType: 'NATIVE',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n }\n\n // track ERC20 transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('TOKEN')) {\n for (const log of tx.receipt.logs) {\n const txfer = evmDecodeLogWithMetadata(log, [\n 'Transfer(address indexed from, address indexed to, uint256 value)',\n ]);\n if (txfer) {\n transfers.push({\n amount: txfer.decoded.value as bigint,\n blockNumber: tx.blockNumber as number,\n from: evmAddressToChecksum(txfer.decoded.from as string) || NULL_ADDRESS,\n index: log.logIndex,\n timestamp,\n to: evmAddressToChecksum(txfer.decoded.to as string) || NULL_ADDRESS,\n token: evmAddressToChecksum(log.address as string),\n tokenType: 'TOKEN',\n transactionGasFee,\n transactionHash: tx.hash,\n });\n }\n }\n }\n\n // @TODO: add NFT transfers\n if (!TOKEN_TYPES.length || TOKEN_TYPES.includes('NFT')) {\n for (const log of tx.receipt.logs) {\n }\n }\n }\n }\n }\n\n return transfers.filter((txfer) => txfer.amount > BigInt(0));\n },\n};\n\nexport default tokenTransfers;\n","import allBlocks from './all-blocks';\nimport tokenTransfers from './token-transfers';\n\nexport const templates = [allBlocks, tokenTransfers];","import { templates } from './templates';\nimport * as utils from './utils';\nimport * as types from './types';\n\nexport { utils, types };\n\nexport function getAllTemplates() {\n return templates;\n}\n\nexport function getTemplateByKey(key: string) {\n return templates.find((template) => template.key === key);\n}\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@indexing/jiti",
3
+ "version": "0.0.1",
4
+ "description": "Just In Time Indexing, for all",
5
+ "source": "src/index.ts",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "types": "dist/types.d.ts",
9
+ "scripts": {
10
+ "build": "rm -rf dist .parcel-cache && parcel build --dist-dir dist",
11
+ "lint": "prettier --write **.ts && eslint .",
12
+ "test": "echo \"Error: no test specified\" && exit 1",
13
+ "watch": "parcel watch"
14
+ },
15
+ "author": "Indexing Co",
16
+ "license": "GPL-3.0-or-later",
17
+ "devDependencies": {
18
+ "@parcel/packager-ts": "^2.12.0",
19
+ "@parcel/transformer-typescript-types": "^2.12.0",
20
+ "@types/isomorphic-fetch": "^0.0.39",
21
+ "eslint-config-prettier": "^9.1.0",
22
+ "eslint-plugin-prettier": "^5.2.1",
23
+ "husky": "^9.1.5",
24
+ "parcel": "^2.12.0",
25
+ "prettier": "3.3.3",
26
+ "pretty-quick": "^4.0.0",
27
+ "typescript": "^5.5.4",
28
+ "typescript-eslint": "^8.3.0"
29
+ },
30
+ "dependencies": {
31
+ "isomorphic-fetch": "^3.0.0",
32
+ "viem": "^2.21.1"
33
+ }
34
+ }