// Test minimal Drift connection
require('dotenv').config() // Load environment variables
const { Connection, Keypair } = require('@solana/web3.js')

async function testMinimalDrift() {
  try {
    console.log('🧪 Testing minimal Drift setup...')
    
    // Check if we have the private key
    if (!process.env.SOLANA_PRIVATE_KEY) {
      console.log('❌ No SOLANA_PRIVATE_KEY found')
      return
    }
    
    console.log('✅ Environment variable found')
    
    // Test connection
    const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed')
    console.log('✅ Connection created')
    
    // Test keypair
    const privateKeyArray = JSON.parse(process.env.SOLANA_PRIVATE_KEY)
    const keypair = Keypair.fromSecretKey(new Uint8Array(privateKeyArray))
    console.log('✅ Keypair created:', keypair.publicKey.toString())
    
    // Test Anchor Wallet
    const { Wallet } = await import('@coral-xyz/anchor')
    const wallet = new Wallet(keypair)
    console.log('✅ Wallet created')
    
    // Test Drift imports
    const { DriftClient, initialize } = await import('@drift-labs/sdk')
    console.log('✅ Drift SDK imported')
    
    // Test initialize
    const sdkConfig = initialize({ env: 'mainnet-beta' })
    console.log('✅ Drift initialized', sdkConfig.DRIFT_PROGRAM_ID.toString())
    
    console.log('🎉 All tests passed!')
    
  } catch (error) {
    console.error('❌ Error:', error.message)
    console.error('Stack:', error.stack)
  }
}

testMinimalDrift()
