-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
59 lines (48 loc) · 1.9 KB
/
index.ts
File metadata and controls
59 lines (48 loc) · 1.9 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
import { formatUnits } from 'viem';
import { initializeNetwork } from './src/network';
import { getAllPairsInfo, type PairInfo } from './src/getinfo';
import { ArbitrageGraph } from './src/graph';
import { DEBUG, ADDRESSES } from './src/constants';
import { EventMonitor } from './src/event';
import { findAndLogArbitrageOpportunities } from "./src/opp";
import { createNonceManager } from './src/nonce';
async function main() {
try {
// Initialize network and get pairs info
console.log("Initializing network...");
const network = await initializeNetwork();
// Initialize nonce manager
console.log("Initializing nonce manager...");
const nonceManager = createNonceManager(network.account);
await nonceManager.initialize(network.client);
console.log("Fetching pairs information...");
const pairs = await getAllPairsInfo(network.client);
if (DEBUG) {
console.log(`Found ${pairs.length} pairs`);
}
// Initialize and build the arbitrage graph
console.log("Building arbitrage graph...");
const graph = new ArbitrageGraph();
// Add all pairs to the graph
for (const pair of pairs) {
graph.addPair(pair);
}
// Find arbitrage opportunities
console.log("Searching for initial arbitrage opportunities...");
await findAndLogArbitrageOpportunities(graph, network);
// Start monitoring events
console.log("\nStarting event monitor...");
const monitor = new EventMonitor(graph, network);
await monitor.start();
// Keep the process running
process.on('SIGINT', async () => {
console.log('\nStopping event monitor...');
await monitor.stop();
process.exit();
});
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
}
main();