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