-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.js
More file actions
442 lines (413 loc) · 14.4 KB
/
config.js
File metadata and controls
442 lines (413 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/**
* Configuration module for logtui
* Provides network endpoints and event signature presets
*/
import fetch from "node-fetch";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Path to store cached networks
const CACHE_FILE = path.join(__dirname, "../.networks-cache.json");
const HYPERSYNC_PROTOCOL = "https://";
function normalizeNetworkUrl(url) {
if (typeof url !== "string") return url;
return url.replace(/^http:\/\//, HYPERSYNC_PROTOCOL);
}
function normalizeNetworks(networks) {
return Object.fromEntries(
Object.entries(networks).map(([name, url]) => [name, normalizeNetworkUrl(url)])
);
}
// Default network endpoint configuration (used as fallback if API fetch fails)
export const DEFAULT_NETWORKS = {
eth: "https://eth.hypersync.xyz",
arbitrum: "https://arbitrum.hypersync.xyz",
optimism: "https://optimism.hypersync.xyz",
base: "https://base.hypersync.xyz",
polygon: "https://polygon.hypersync.xyz",
};
// Runtime networks object that will be populated
export let NETWORKS = { ...DEFAULT_NETWORKS };
// API endpoint to fetch available networks
const NETWORKS_API_URL = "https://chains.hyperquery.xyz/active_chains";
/**
* Load networks from cache file
* @returns {Object} Cached networks or default networks if cache not found
*/
function loadNetworksFromCache() {
try {
if (fs.existsSync(CACHE_FILE)) {
const data = fs.readFileSync(CACHE_FILE, "utf8");
const networks = JSON.parse(data);
const normalizedNetworks = normalizeNetworks(networks);
if (JSON.stringify(networks) !== JSON.stringify(normalizedNetworks)) {
saveNetworksToCache(normalizedNetworks);
}
console.debug("Loaded networks from cache");
return normalizedNetworks;
}
} catch (error) {
console.warn(`Failed to load networks from cache: ${error.message}`);
}
return DEFAULT_NETWORKS;
}
/**
* Save networks to cache file
* @param {Object} networks - Networks to cache
*/
function saveNetworksToCache(networks) {
try {
const data = JSON.stringify(normalizeNetworks(networks), null, 2);
fs.writeFileSync(CACHE_FILE, data);
console.debug("Saved networks to cache");
} catch (error) {
console.warn(`Failed to save networks to cache: ${error.message}`);
}
}
/**
* Fetches all available networks from the Hypersync API
* @param {boolean} forceRefresh - Whether to force a refresh from API
* @returns {Promise<Object>} Object with network names as keys and URLs as values
*/
export async function fetchNetworks(forceRefresh = false) {
// If not forcing refresh, try to load from cache first
if (!forceRefresh) {
const cachedNetworks = loadNetworksFromCache();
if (
Object.keys(cachedNetworks).length > Object.keys(DEFAULT_NETWORKS).length
) {
// If cache has more networks than default, use it
NETWORKS = { ...cachedNetworks };
return cachedNetworks;
}
}
try {
console.debug("Fetching networks from API...");
const response = await fetch(NETWORKS_API_URL);
if (!response.ok) {
throw new Error(`API responded with status: ${response.status}`);
}
const networks = await response.json();
const result = {};
// Process the API response into our format
networks.forEach((network) => {
// Skip non-EVM networks for now
if (network.ecosystem !== "evm") return;
// Convert network name to URL format
const url = `${HYPERSYNC_PROTOCOL}${network.name}.hypersync.xyz`;
result[network.name] = url;
});
// Update the NETWORKS object
NETWORKS = { ...result };
// Save to cache
saveNetworksToCache(result);
return result;
} catch (error) {
console.warn(`Warning: Failed to fetch networks: ${error.message}`);
console.warn("Using previously cached or default networks instead.");
// Fall back to cached networks if available, or defaults
const cachedNetworks = loadNetworksFromCache();
NETWORKS = { ...cachedNetworks };
return cachedNetworks;
}
}
// Try to load networks from cache immediately
try {
const cachedNetworks = loadNetworksFromCache();
if (Object.keys(cachedNetworks).length > 0) {
NETWORKS = { ...cachedNetworks };
}
} catch (err) {
console.warn(`Failed to load networks from cache: ${err.message}`);
}
// Event signature presets
export const EVENT_PRESETS = {
"uniswap-v3": {
name: "Uniswap V3",
description: "Uniswap V3 core events",
signatures: [
"PoolCreated(address,address,uint24,int24,address)",
"Burn(address,int24,int24,uint128,uint256,uint256)",
"Initialize(uint160,int24)",
"Mint(address,address,int24,int24,uint128,uint256,uint256)",
"Swap(address,address,int256,int256,uint160,uint128,int24)",
],
},
"uniswap-v4": {
name: "Uniswap V4",
description: "Uniswap V4 PoolManager events",
signatures: [
"Donate(bytes32,address,uint256,uint256)",
"Initialize(bytes32,address,address,uint24,int24,address,uint160,int24)",
"ModifyLiquidity(bytes32,address,int24,int24,int256,bytes32)",
"Swap(bytes32,address,int128,int128,uint160,uint128,int24,uint24)",
"Transfer(address,address,address,uint256,uint256)",
],
},
erc20: {
name: "ERC-20",
description: "Standard ERC-20 token events",
signatures: [
"Transfer(address,address,uint256)",
"Approval(address,address,uint256)",
],
},
erc721: {
name: "ERC-721",
description: "Standard ERC-721 NFT events",
signatures: [
"Transfer(address,address,uint256)",
"Approval(address,address,uint256)",
"ApprovalForAll(address,address,bool)",
],
},
// Oracle Presets
"chainlink-price-feeds": {
name: "Chainlink Price Feeds",
description: "Chainlink price oracle events",
signatures: [
"AnswerUpdated(int256,uint256,uint256)",
"NewRound(uint256,address,uint256)",
"ResponseReceived(int256,uint256,address)",
"AggregatorConfigSet(address,address,address)",
"RoundDetailsUpdated(uint128,uint32,int192,uint32)",
],
},
"chainlink-vrf": {
name: "Chainlink VRF",
description: "Chainlink Verifiable Random Function events",
signatures: [
"RandomWordsRequested(bytes32,uint256,uint256,uint64,uint16,uint32,uint32,address)",
"RandomWordsFulfilled(uint256,uint256,uint96,bool)",
"ConfigSet(uint16,uint32,uint32,uint32,uint32)",
"SubscriptionCreated(uint64,address)",
"SubscriptionFunded(uint64,uint256,uint256)",
],
},
pyth: {
name: "Pyth Network",
description: "Pyth Network oracle events",
signatures: [
"BatchPriceFeedUpdate(bytes32[],bytes[])",
"PriceFeedUpdate(bytes32,bytes)",
"BatchPriceUpdate(bytes32[],int64[],uint64[],int32[],uint32[])",
"PriceUpdate(bytes32,int64,uint64,int32,uint32)",
],
},
uma: {
name: "UMA Protocol",
description: "UMA Oracle events",
signatures: [
"PriceProposed(address,uint256,uint256,int256)",
"PriceDisputed(address,uint256,uint256,int256)",
"PriceSettled(address,uint256,int256,uint256)",
],
},
// DeFi Presets
aave: {
name: "Aave V3",
description: "Aave V3 lending protocol events",
signatures: [
"Supply(address,address,address,uint256,uint16)",
"Withdraw(address,address,address,uint256)",
"Borrow(address,address,address,uint256,uint256,uint16)",
"Repay(address,address,address,uint256,bool)",
"LiquidationCall(address,address,address,uint256,uint256,address,bool)",
],
},
curve: {
name: "Curve Finance",
description: "Curve pool events",
signatures: [
"TokenExchange(address,int128,uint256,int128,uint256)",
"AddLiquidity(address,uint256[],uint256,uint256)",
"RemoveLiquidity(address,uint256,uint256[])",
"RemoveLiquidityOne(address,uint256,uint256)",
],
},
// Cross-chain & Bridges
layerzero: {
name: "LayerZero",
description: "LayerZero cross-chain messaging events",
signatures: [
"MessageSent(bytes,uint64,bytes32,bytes)",
"PacketReceived(uint16,bytes,address,uint64,bytes32)",
"RelayerAdded(address,uint16)",
"RelayerRemoved(address,uint16)",
],
},
weth: {
name: "WETH",
description: "Wrapped Ether events",
signatures: [
"Deposit(address,uint256)",
"Withdrawal(address,uint256)",
"Transfer(address,address,uint256)",
"Approval(address,address,uint256)",
],
},
// L2 Infrastructure
arbitrum: {
name: "Arbitrum",
description: "Arbitrum sequencer and bridge events",
signatures: [
"SequencerBatchDelivered(uint256,bytes32,address,uint256)",
"MessageDelivered(uint256,bytes32,address,uint8,address,bytes32)",
"BridgeCallTriggered(address,address,uint256,bytes)",
],
},
// Gaming/NFTs
blur: {
name: "Blur",
description: "Blur NFT marketplace events",
signatures: [
"OrdersMatched(address,address,bytes32,bytes32)",
"NonceIncremented(address,uint256)",
"NewBlurExchange(address)",
"NewExecutionDelegate(address)",
],
},
axie: {
name: "Axie Infinity",
description: "Axie Infinity game events",
signatures: [
"AxieSpawned(uint256,uint256,uint256,uint256,uint256)",
"AxieBred(address,uint256,uint256,uint256)",
"Transfer(address,address,uint256)",
"BreedingApproval(address,uint256,address)",
],
},
// Stablecoins
usdc: {
name: "USDC",
description: "USD Coin stablecoin events",
signatures: [
"Transfer(address,address,uint256)",
"Approval(address,address,uint256)",
"Mint(address,uint256)",
"Burn(address,uint256)",
"BlacklistAdded(address)",
"BlacklistRemoved(address)",
],
},
// DAOs/Governance
ens: {
name: "ENS",
description: "Ethereum Name Service registry events",
signatures: [
"NewOwner(bytes32,bytes32,address)",
"Transfer(bytes32,address)",
"NewResolver(bytes32,address)",
"NewTTL(bytes32,uint64)",
"NameRegistered(string,bytes32,address,uint256,uint256)",
],
},
// Emerging/Trending
erc4337: {
name: "ERC-4337",
description: "Account Abstraction events",
signatures: [
"UserOperationEvent(bytes32,address,address,uint256,bool,uint256,uint256)",
"AccountDeployed(bytes32,address,address,address)",
],
},
universalRouter: {
name: "Uniswap Universal Router",
description: "Uniswap's intent-based router events",
signatures: [
"RewardsSent(address,uint256)",
"ERC20Transferred(address,address,uint256)",
"ERC721Transferred(address,address,address,uint256)",
"ERC1155Transferred(address,address,address,uint256,uint256)",
],
},
"gmx-v1-perps": {
name: "GMX V1 Perps",
description: "GMX v1 perps orders, position changes, and liquidations",
signatures: [
// Vault position lifecycle
"IncreasePosition(bytes32,address,address,address,uint256,uint256,bool,uint256,uint256)",
"DecreasePosition(bytes32,address,address,address,uint256,uint256,bool,uint256,uint256)",
"LiquidatePosition(bytes32,address,address,address,bool,uint256,uint256,uint256,int256,uint256)",
"UpdatePosition(bytes32,uint256,uint256,uint256,uint256,uint256,int256,uint256)",
"ClosePosition(bytes32,uint256,uint256,uint256,uint256,uint256,int256)",
// PositionRouter order lifecycle (increase)
"CreateIncreasePosition(address,address[],address,uint256,uint256,uint256,bool,uint256,uint256,uint256,uint256,uint256,uint256,uint256)",
"ExecuteIncreasePosition(address,address[],address,uint256,uint256,uint256,bool,uint256,uint256,uint256,uint256)",
"CancelIncreasePosition(address,address[],address,uint256,uint256,uint256,bool,uint256,uint256,uint256,uint256)",
// PositionRouter order lifecycle (decrease)
"CreateDecreasePosition(address,address[],address,uint256,uint256,bool,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)",
"ExecuteDecreasePosition(address,address[],address,uint256,uint256,bool,address,uint256,uint256,uint256,uint256)",
"CancelDecreasePosition(address,address[],address,uint256,uint256,bool,address,uint256,uint256,uint256,uint256)",
// OrderBook (increase orders)
"CreateIncreaseOrder(address,uint256,address,uint256,address,address,uint256,bool,uint256,bool,uint256)",
"ExecuteIncreaseOrder(address,uint256,address,uint256,address,address,uint256,bool,uint256,bool,uint256,uint256)",
"CancelIncreaseOrder(address,uint256,address,uint256,address,address,uint256,bool,uint256,bool,uint256)",
// OrderBook (decrease orders)
"CreateDecreaseOrder(address,uint256,address,uint256,address,uint256,bool,uint256,bool,uint256)",
"ExecuteDecreaseOrder(address,uint256,address,uint256,address,uint256,bool,uint256,bool,uint256,uint256)",
"CancelDecreaseOrder(address,uint256,address,uint256,address,uint256,bool,uint256,bool,uint256)",
],
},
};
/**
* Get network URL from network name
* @param {string} network - Network name
* @returns {string} Network URL
*/
export function getNetworkUrl(network) {
if (!NETWORKS[network]) {
throw new Error(
`Network '${network}' not supported. Available networks: ${Object.keys(
NETWORKS
)
.slice(0, 10)
.join(", ")}... (Use --list-networks to see all)`
);
}
return NETWORKS[network];
}
/**
* Get event signatures from preset name
* @param {string} presetName - Preset name
* @returns {Array<string>} Array of event signatures
*/
export function getEventSignatures(presetName) {
if (!EVENT_PRESETS[presetName]) {
throw new Error(
`Preset '${presetName}' not found. Available presets: ${Object.keys(
EVENT_PRESETS
).join(", ")}`
);
}
return EVENT_PRESETS[presetName].signatures;
}
/**
* Check if a preset exists
* @param {string} presetName - Preset name
* @returns {boolean} Whether the preset exists
*/
export function hasPreset(presetName) {
return Boolean(EVENT_PRESETS[presetName]);
}
/**
* List all available presets
* @returns {Object} All presets with name and description
*/
export function listPresets() {
return Object.entries(EVENT_PRESETS).map(([id, preset]) => ({
id,
name: preset.name,
description: preset.description,
}));
}
/**
* Force refresh networks from API
* @returns {Promise<Object>} Updated networks list
*/
export async function refreshNetworks() {
return await fetchNetworks(true);
}