-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate-bot.js
More file actions
152 lines (141 loc) · 4.55 KB
/
validate-bot.js
File metadata and controls
152 lines (141 loc) · 4.55 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
/**
* Simple validation script to check bot code structure
* Run with: node validate-bot.js
*/
const fs = require('fs');
const path = require('path');
console.log('🔍 Validating Bot Code Structure...\n');
const checks = [];
let hasErrors = false;
// Check 1: Required files exist
const requiredFiles = [
'src/index.ts',
'src/config/env.ts',
'src/config/db.ts',
'src/services/tradeMonitor.ts',
'src/services/tradeExecutor.ts',
'src/utils/createClobClient.ts',
'src/utils/postOrder.ts',
'src/utils/fetchData.ts',
'src/utils/getMyBalance.ts',
'package.json',
'tsconfig.json'
];
console.log('📁 Checking required files...');
requiredFiles.forEach(file => {
const exists = fs.existsSync(file);
checks.push({ file, exists });
if (exists) {
console.log(` ✅ ${file}`);
} else {
console.log(` ❌ ${file} - MISSING`);
hasErrors = true;
}
});
// Check 2: Check key functions in tradeMonitor.ts
console.log('\n🔍 Checking tradeMonitor.ts implementation...');
try {
const tradeMonitorContent = fs.readFileSync('src/services/tradeMonitor.ts', 'utf8');
if (tradeMonitorContent.includes('fetchTradeData')) {
console.log(' ✅ fetchTradeData function exists');
} else {
console.log(' ❌ fetchTradeData function missing');
hasErrors = true;
}
if (tradeMonitorContent.includes('await fetchData')) {
console.log(' ✅ fetchTradeData uses fetchData');
} else {
console.log(' ⚠️ fetchTradeData might not be implemented');
}
} catch (e) {
console.log(' ❌ Could not read tradeMonitor.ts');
hasErrors = true;
}
// Check 3: Check key functions in tradeExecutor.ts
console.log('\n🔍 Checking tradeExecutor.ts implementation...');
try {
const tradeExecutorContent = fs.readFileSync('src/services/tradeExecutor.ts', 'utf8');
if (tradeExecutorContent.includes('doTrading')) {
console.log(' ✅ doTrading function exists');
} else {
console.log(' ❌ doTrading function missing');
hasErrors = true;
}
if (tradeExecutorContent.includes('await postOrder')) {
console.log(' ✅ doTrading calls postOrder');
} else {
console.log(' ⚠️ doTrading might not execute trades');
}
if (tradeExecutorContent.includes('condition')) {
console.log(' ✅ Trading condition logic exists');
}
} catch (e) {
console.log(' ❌ Could not read tradeExecutor.ts');
hasErrors = true;
}
// Check 4: Check package.json dependencies
console.log('\n📦 Checking dependencies...');
try {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const requiredDeps = [
'@polymarket/clob-client',
'axios',
'dotenv',
'ethers',
'mongoose',
'ora'
];
requiredDeps.forEach(dep => {
const hasDep = packageJson.dependencies && packageJson.dependencies[dep];
if (hasDep) {
console.log(` ✅ ${dep}`);
} else {
console.log(` ⚠️ ${dep} - check if needed`);
}
});
} catch (e) {
console.log(' ❌ Could not read package.json');
hasErrors = true;
}
// Check 5: Check for .env file
console.log('\n🔐 Checking environment configuration...');
if (fs.existsSync('.env')) {
console.log(' ✅ .env file exists');
try {
const envContent = fs.readFileSync('.env', 'utf8');
const requiredVars = [
'USER_ADDRESS',
'PROXY_WALLET',
'PRIVATE_KEY',
'CLOB_HTTP_URL',
'MONGO_URI',
'RPC_URL',
'USDC_CONTRACT_ADDRESS'
];
requiredVars.forEach(variable => {
if (envContent.includes(variable)) {
console.log(` ✅ ${variable}`);
} else {
console.log(` ⚠️ ${variable} - not found in .env`);
}
});
} catch (e) {
console.log(' ⚠️ Could not read .env file');
}
} else {
console.log(' ⚠️ .env file not found - create one from .env.example');
}
// Summary
console.log('\n' + '='.repeat(50));
if (hasErrors) {
console.log('❌ Validation found some issues. Please fix them before running the bot.');
process.exit(1);
} else {
console.log('✅ Basic validation passed!');
console.log('\n📝 Next steps:');
console.log(' 1. Install dependencies: npm install');
console.log(' 2. Create .env file with your configuration');
console.log(' 3. Start MongoDB');
console.log(' 4. Run the bot: npm run dev');
process.exit(0);
}