#!/usr/bin/env node

// Minimal Drift test to identify what's being blocked
import { Connection, Keypair } from '@solana/web3.js'

async function testMinimalDrift() {
  try {
    console.log('🧪 Testing minimal Drift functionality...')

    // Test different RPC endpoints
    const rpcEndpoints = [
      'https://mainnet.helius-rpc.com/?api-key=demo',
      'https://rpc.ankr.com/solana',
      'https://api.mainnet-beta.solana.com'
    ]

    for (const rpcUrl of rpcEndpoints) {
      try {
        console.log(`\n🔗 Testing RPC: ${rpcUrl}`)
        const connection = new Connection(rpcUrl, 'confirmed')
        
        // Test basic operations
        console.log('  Testing getVersion...')
        const version = await connection.getVersion()
        console.log('  ✅ Version:', version['solana-core'])
        
        console.log('  Testing getLatestBlockhash...')
        const blockHash = await connection.getLatestBlockhash()
        console.log('  ✅ Block hash:', blockHash.blockhash.slice(0, 10) + '...')
        
        // Test program account access (this might be what's blocked)
        console.log('  Testing program account access...')
        const { initialize } = await import('@drift-labs/sdk')
        const sdkConfig = initialize({ env: 'mainnet-beta' })
        
        console.log('  Testing getAccountInfo for Drift program...')
        const programInfo = await connection.getAccountInfo(sdkConfig.DRIFT_PROGRAM_ID)
        console.log('  ✅ Program info:', programInfo ? 'Found' : 'Not found')
        
        // If we get here, this RPC works
        console.log(`  ✅ RPC ${rpcUrl} works for all tests!`)
        break
        
      } catch (error) {
        console.log(`  ❌ RPC ${rpcUrl} failed:`, error.message)
        if (error.message.includes('410') || error.message.includes('disabled')) {
          console.log('    This RPC has disabled certain calls')
        }
      }
    }

  } catch (error) {
    console.error('❌ Minimal test failed:', error)
  }
}

testMinimalDrift()
