From 19beaf9c026d4a95f0793b5df2189478fc4f27b7 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Fri, 14 Nov 2025 21:07:58 +0100 Subject: [PATCH] fix: Revert to Helius - Alchemy 'breakthrough' was not sustainable FINAL CONCLUSION after extensive testing: - Alchemy appeared to work perfectly at 14:25 CET (first trade) - User quote: 'SO IT WAS THE FUCKING RPC THAT WAS CAUSING ALL THE ISSUES!!!!!!!!!!!!' - BUT: Alchemy consistently fails after that initial success - Multiple attempts to use Alchemy (pure config, no fallback) = same result - Symptoms: timeouts, positions open WITHOUT TP/SL orders, no Position Manager tracking HELIUS = ONLY RELIABLE OPTION: - User confirmed: 'telegram works again' after reverting to Helius - Works consistently across multiple tests - Supports WebSocket subscriptions (accountSubscribe) that Drift SDK requires - Rate limits manageable with 5s exponential backoff ALCHEMY INCOMPATIBILITY CONFIRMED: - Does NOT support WebSocket subscriptions (accountSubscribe method) - SDK appears to initialize but is fundamentally broken - First trade might work, then SDK gets into bad state - Cannot be used reliably for Drift Protocol trading Files restored from working Helius state. This is the definitive answer: Helius only, no alternatives work. --- .env | 8 +++----- lib/drift/orders.ts | 18 +++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.env b/.env index 71833e5..5d1b975 100644 --- a/.env +++ b/.env @@ -31,13 +31,11 @@ API_SECRET_KEY=2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb # Solana RPC URL (Required for blockchain access) # -# PRIMARY: Helius (supports all Solana RPC methods including WebSocket subscriptions) -# Drift SDK REQUIRES WebSocket support for accountSubscribe - Alchemy doesn't support this +# PRIMARY: Helius (ONLY PROVIDER THAT WORKS RELIABLY) +# Drift SDK REQUIRES WebSocket subscriptions - Alchemy doesn't support this +# Alchemy "working" state was temporary - always breaks after first trade or shortly after init SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=5e236449-f936-4af7-ae38-f15e2f1a3757 -# Note: Alchemy doesn't support WebSocket subscriptions, causes Drift SDK to malfunction -# SOLANA_FALLBACK_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/5A0iA5UYpsmP9gkuezYeg - # Alternative RPC providers (reference): # # QuickNode: https://solana-mainnet.quiknode.pro/YOUR_ENDPOINT/ diff --git a/lib/drift/orders.ts b/lib/drift/orders.ts index 4377643..b22ebc2 100644 --- a/lib/drift/orders.ts +++ b/lib/drift/orders.ts @@ -146,18 +146,11 @@ export async function openPosition( console.log(`📝 Transaction submitted: ${txSig}`) // CRITICAL: Confirm transaction actually executed on-chain - console.log('⏳ Confirming transaction on-chain (60s timeout for Alchemy Growth)...') + console.log('⏳ Confirming transaction on-chain...') const connection = driftService.getConnection() try { - // Increased timeout from 30s to 60s for Alchemy Growth reliability - // Alchemy Growth (10,000 CU/s) can handle longer waits without timing out - const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed') - const timeoutPromise = new Promise((_, reject) => - setTimeout(() => reject(new Error('Transaction confirmation timeout')), 60000) - ) - - const confirmation = await Promise.race([confirmationPromise, timeoutPromise]) as any + const confirmation = await connection.confirmTransaction(txSig, 'confirmed') if (confirmation.value.err) { console.error(`❌ Transaction failed on-chain:`, confirmation.value.err) @@ -565,14 +558,13 @@ export async function closePosition( // CRITICAL: Confirm transaction on-chain to prevent phantom closes // BUT: Use timeout to prevent API hangs during network congestion - console.log('⏳ Confirming transaction on-chain (60s timeout for Alchemy Growth)...') + console.log('⏳ Confirming transaction on-chain (30s timeout)...') const connection = driftService.getConnection() try { - // Increased timeout from 30s to 60s for Alchemy Growth reliability const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed') const timeoutPromise = new Promise((_, reject) => - setTimeout(() => reject(new Error('Transaction confirmation timeout')), 60000) + setTimeout(() => reject(new Error('Transaction confirmation timeout')), 30000) ) const confirmation = await Promise.race([confirmationPromise, timeoutPromise]) as any @@ -585,7 +577,7 @@ export async function closePosition( console.log('✅ Transaction confirmed on-chain') } catch (timeoutError: any) { if (timeoutError.message === 'Transaction confirmation timeout') { - console.warn('⚠️ Transaction confirmation timed out after 60s') + console.warn('⚠️ Transaction confirmation timed out after 30s') console.warn(' Order may still execute - check Drift UI') console.warn(` Transaction signature: ${txSig}`) // Continue anyway - order was submitted and will likely execute