Files
237-combo/scripts/verify-setup.ts

170 lines
5.6 KiB
TypeScript
Raw Permalink Normal View History

#!/usr/bin/env tsx
/**
* Comprehensive Setup Verification Script
*
* Verifies that all scripts are properly configured with environment variables
* and that connections work correctly.
*
* Usage:
* tsx scripts/verify-setup.ts
*/
// Load dotenv FIRST
import dotenv from 'dotenv';
dotenv.config();
import { existsSync } from 'fs';
import { join } from 'path';
import chalk from 'chalk';
async function main() {
console.log(chalk.blue('='.repeat(70)));
console.log(chalk.blue('DeFi Strategy Testing Framework - Setup Verification'));
console.log(chalk.blue('='.repeat(70)));
console.log('');
let allGood = true;
// Check .env file
console.log(chalk.yellow('1. Checking .env file...'));
if (existsSync('.env')) {
console.log(chalk.green(' ✓ .env file exists'));
} else {
console.log(chalk.yellow(' ⚠ .env file not found'));
console.log(chalk.yellow(' Create it from .env.example: cp .env.example .env'));
allGood = false;
}
console.log('');
// Check .env.example
console.log(chalk.yellow('2. Checking .env.example...'));
if (existsSync('.env.example')) {
console.log(chalk.green(' ✓ .env.example exists'));
} else {
console.log(chalk.red(' ✗ .env.example not found'));
allGood = false;
}
console.log('');
// Check environment variables
console.log(chalk.yellow('3. Checking environment variables...'));
const requiredVars = ['MAINNET_RPC_URL'];
const optionalVars = ['BASE_RPC_URL', 'ARBITRUM_RPC_URL', 'OPTIMISM_RPC_URL', 'POLYGON_RPC_URL', 'PRIVATE_KEY'];
for (const varName of requiredVars) {
const value = process.env[varName];
if (value && !value.includes('YOUR_KEY') && !value.includes('YOUR_INFURA_KEY')) {
console.log(chalk.green(`${varName} is set`));
} else {
console.log(chalk.red(`${varName} is not properly configured`));
allGood = false;
}
}
for (const varName of optionalVars) {
const value = process.env[varName];
if (value && !value.includes('YOUR_KEY') && !value.includes('YOUR_INFURA_KEY')) {
console.log(chalk.green(`${varName} is set`));
} else if (value) {
console.log(chalk.yellow(`${varName} contains placeholder`));
} else {
console.log(chalk.gray(` - ${varName} not set (optional)`));
}
}
console.log('');
// Check scripts load dotenv
console.log(chalk.yellow('4. Checking scripts load dotenv...'));
const scripts = [
'src/strat/cli.ts',
'src/cli/cli.ts',
'scripts/test-strategy.ts',
];
for (const script of scripts) {
if (existsSync(script)) {
// Read first few lines to check for dotenv
const fs = await import('fs');
const content = fs.readFileSync(script, 'utf-8');
const lines = content.split('\n').slice(0, 20);
const hasDotenv = lines.some(line =>
line.includes('dotenv') && (line.includes('import') || line.includes('require'))
);
const dotenvConfigLine = lines.findIndex(line => line.includes('dotenv.config()'));
const firstNonDotenvImport = lines.findIndex(line =>
line.includes('import') && !line.includes('dotenv') && !line.trim().startsWith('//')
);
const dotenvBeforeImports = dotenvConfigLine !== -1 &&
(firstNonDotenvImport === -1 || dotenvConfigLine < firstNonDotenvImport);
if (hasDotenv && dotenvBeforeImports) {
console.log(chalk.green(`${script} loads dotenv correctly`));
} else if (hasDotenv) {
console.log(chalk.yellow(`${script} loads dotenv but may be after other imports`));
} else {
console.log(chalk.red(`${script} does not load dotenv`));
allGood = false;
}
}
}
console.log('');
// Check network config
console.log(chalk.yellow('5. Checking network configuration...'));
try {
const { getNetwork } = await import('../src/strat/config/networks.js');
const network = getNetwork('mainnet');
if (network.rpcUrl && !network.rpcUrl.includes('YOUR_KEY')) {
console.log(chalk.green(` ✓ Network config loads correctly`));
console.log(chalk.gray(` Mainnet RPC: ${network.rpcUrl.substring(0, 50)}...`));
} else {
console.log(chalk.yellow(` ⚠ Network config has placeholder RPC URL`));
}
} catch (error: any) {
console.log(chalk.red(` ✗ Network config error: ${error.message}`));
allGood = false;
}
console.log('');
// Check scenario files
console.log(chalk.yellow('6. Checking scenario files...'));
const scenarios = [
'scenarios/aave/leveraged-long.yml',
'scenarios/aave/liquidation-drill.yml',
'scenarios/compound3/supply-borrow.yml',
];
for (const scenario of scenarios) {
if (existsSync(scenario)) {
console.log(chalk.green(`${scenario} exists`));
} else {
console.log(chalk.yellow(`${scenario} not found`));
}
}
console.log('');
// Summary
console.log(chalk.blue('='.repeat(70)));
if (allGood) {
console.log(chalk.green('✓ Setup verification passed!'));
console.log('');
console.log('Next steps:');
console.log(' 1. Run environment check: pnpm run check:env');
console.log(' 2. Test a scenario: pnpm run strat:test');
console.log(' 3. Run a scenario: pnpm run strat run scenarios/aave/leveraged-long.yml');
} else {
console.log(chalk.yellow('⚠ Setup verification found some issues'));
console.log('');
console.log('Please:');
console.log(' 1. Create .env file: cp .env.example .env');
console.log(' 2. Fill in your RPC URLs in .env');
console.log(' 3. Run: pnpm run check:env');
process.exit(1);
}
console.log('');
}
main().catch(console.error);