-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-setup.js
More file actions
executable file
Β·206 lines (181 loc) Β· 6.57 KB
/
Copy pathvalidate-setup.js
File metadata and controls
executable file
Β·206 lines (181 loc) Β· 6.57 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
#!/usr/bin/env node
// Setup Validation Script
// Run this before starting the oracle to verify configuration
import dotenv from 'dotenv';
import { existsSync } from 'fs';
import { createClient } from '@supabase/supabase-js';
import { JsonRpcProvider, Wallet } from 'ethers';
dotenv.config();
const errors = [];
const warnings = [];
console.log('\nπ Validating Arbitrum YouTube Oracle Setup\n');
console.log('β'.repeat(60));
// Check environment file
if (!existsSync('.env')) {
errors.push('.env file not found');
} else {
console.log('β
.env file found');
}
// Check required environment variables
const requiredVars = [
'PRIVATE_KEY',
'CONTRACT_ADDRESS',
'YOUTUBE_API_KEY',
'CHANNEL_ID',
'SUPABASE_ANON_KEY'
];
console.log('\nπ Checking environment variables:');
for (const varName of requiredVars) {
if (!process.env[varName]) {
errors.push(`Missing ${varName} in .env`);
console.log(`β ${varName} - MISSING`);
} else if (process.env[varName].includes('Your') || process.env[varName].includes('your_')) {
warnings.push(`${varName} appears to be a placeholder`);
console.log(`β οΈ ${varName} - PLACEHOLDER (needs to be updated)`);
} else {
const maskedValue = varName.includes('KEY') || varName.includes('PRIVATE')
? process.env[varName].substring(0, 10) + '...'
: process.env[varName].substring(0, 20) + '...';
console.log(`β
${varName} - ${maskedValue}`);
}
}
// Check optional but important variables
console.log('\nβοΈ Optional configuration:');
const optionalVars = {
'VIDEO_ID': process.env.VIDEO_ID || 'LQAFm01IOT0',
'CHECK_INTERVAL_MINUTES': process.env.CHECK_INTERVAL_MINUTES || '45',
'RPC_URL': process.env.RPC_URL || 'https://arb1.arbitrum.io/rpc'
};
for (const [key, value] of Object.entries(optionalVars)) {
console.log(` ${key}: ${value}`);
}
// Check directories
console.log('\nπ Checking directories:');
const dirs = ['logs', 'thumbnails', 'dist'];
for (const dir of dirs) {
if (existsSync(dir)) {
console.log(`β
${dir}/ exists`);
} else {
warnings.push(`${dir}/ directory not found`);
console.log(`β οΈ ${dir}/ not found (will be created)`);
}
}
// Check compiled files
console.log('\nπ¨ Checking build:');
if (existsSync('dist/youtube-oracle.js')) {
console.log('β
Compiled JavaScript found');
} else {
errors.push('Compiled JavaScript not found - run: npm run build');
console.log('β dist/youtube-oracle.js not found');
}
// Test Supabase connection
console.log('\nπΎ Testing Supabase connection:');
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
try {
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY
);
// Try a simple query
const { data, error } = await supabase
.from('oracle_state')
.select('*')
.limit(1);
if (error) {
if (error.message.includes('relation') || error.message.includes('does not exist')) {
errors.push('Supabase tables not created - run supabase-schema.sql');
console.log('β Tables not found - run SQL schema in Supabase');
} else {
errors.push(`Supabase error: ${error.message}`);
console.log(`β Connection error: ${error.message}`);
}
} else {
console.log('β
Supabase connected and tables exist');
}
} catch (err) {
errors.push(`Failed to connect to Supabase: ${err.message}`);
console.log(`β Connection failed: ${err.message}`);
}
} else {
errors.push('Supabase credentials missing');
console.log('β Supabase credentials not configured');
}
// Test RPC connection
console.log('\nβοΈ Testing Arbitrum RPC:');
if (process.env.RPC_URL || true) {
try {
const rpcUrl = process.env.RPC_URL || 'https://arb1.arbitrum.io/rpc';
const provider = new JsonRpcProvider(rpcUrl);
const network = await provider.getNetwork();
const blockNumber = await provider.getBlockNumber();
if (network.chainId === 42161n) {
console.log(`β
Connected to Arbitrum One (Chain ID: ${network.chainId})`);
console.log(` Latest block: ${blockNumber}`);
} else {
warnings.push(`Connected to chain ${network.chainId}, expected 42161 (Arbitrum One)`);
console.log(`β οΈ Connected to chain ${network.chainId} (expected 42161)`);
}
} catch (err) {
errors.push(`Failed to connect to RPC: ${err.message}`);
console.log(`β RPC connection failed: ${err.message}`);
}
}
// Test wallet
console.log('\nπΌ Testing wallet:');
if (process.env.PRIVATE_KEY) {
try {
const wallet = new Wallet(process.env.PRIVATE_KEY);
console.log(`β
Wallet address: ${wallet.address}`);
// Check balance if RPC is available
if (process.env.RPC_URL || true) {
const rpcUrl = process.env.RPC_URL || 'https://arb1.arbitrum.io/rpc';
const provider = new JsonRpcProvider(rpcUrl);
const walletWithProvider = wallet.connect(provider);
const balance = await walletWithProvider.provider.getBalance(wallet.address);
const ethBalance = parseFloat(balance.toString()) / 1e18;
if (ethBalance < 0.001) {
warnings.push('Wallet ETH balance is low');
console.log(`β οΈ Balance: ${ethBalance.toFixed(6)} ETH (may need more for gas)`);
} else {
console.log(`β
Balance: ${ethBalance.toFixed(6)} ETH`);
}
}
} catch (err) {
errors.push(`Invalid private key: ${err.message}`);
console.log(`β Invalid private key`);
}
}
// Summary
console.log('\n' + 'β'.repeat(60));
console.log('\nπ VALIDATION SUMMARY:\n');
if (errors.length === 0 && warnings.length === 0) {
console.log('π All checks passed! You\'re ready to start the oracle.\n');
console.log('To start:');
console.log(' npm start # Test run');
console.log(' pm2 start pm2.config.js # Production deployment');
process.exit(0);
} else {
if (errors.length > 0) {
console.log(`β ${errors.length} ERROR(S) found:\n`);
errors.forEach((err, i) => {
console.log(` ${i + 1}. ${err}`);
});
console.log('');
}
if (warnings.length > 0) {
console.log(`β οΈ ${warnings.length} WARNING(S):\n`);
warnings.forEach((warn, i) => {
console.log(` ${i + 1}. ${warn}`);
});
console.log('');
}
if (errors.length > 0) {
console.log('β Please fix the errors before starting the oracle.\n');
console.log('See SETUP_GUIDE.md for detailed instructions.');
process.exit(1);
} else {
console.log('β οΈ Warnings found, but oracle can still run.');
console.log('Consider addressing warnings for optimal performance.\n');
process.exit(0);
}
}