#!/usr/bin/env node

/**
 * Quick test to verify private key usage
 */

require('dotenv').config();

async function quickTest() {
  console.log('🔐 Quick private key verification...');
  
  try {
    const { Connection, Keypair } = require('@solana/web3.js');
    
    // This is exactly what our drift-trading.ts does
    const secret = process.env.SOLANA_PRIVATE_KEY;
    if (!secret) {
      throw new Error('SOLANA_PRIVATE_KEY not found');
    }
    
    const keypair = Keypair.fromSecretKey(Buffer.from(JSON.parse(secret)));
    const connection = new Connection(process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com', 'confirmed');
    
    console.log('✅ Private key parsed successfully');
    console.log('🔑 Public key:', keypair.publicKey.toString());
    
    // Quick balance check
    const balance = await connection.getBalance(keypair.publicKey);
    console.log('💰 SOL balance:', (balance / 1e9).toFixed(6), 'SOL');
    
    console.log('\n✅ Your private key from .env is working correctly!');
    console.log('📝 The issue is likely with Drift SDK subscription or user account initialization.');
    
  } catch (error) {
    console.error('❌ Private key test failed:', error.message);
  }
}

quickTest().catch(console.error);
