diff --git a/.env b/.env index b66e07a..68bf728 100644 --- a/.env +++ b/.env @@ -31,26 +31,16 @@ API_SECRET_KEY=2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb # Solana RPC URL (Required for blockchain access) # -# CRITICAL: Primary RPC for normal trading operations -# Current: Alchemy (300M compute units/month free tier, excellent stability) -SOLANA_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/5A0iA5UYpsmP9gkuezYeg +# PRIMARY: Helius WebSocket RPC (supports accountSubscribe for Drift SDK) +SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=5e236449-f936-4af7-ae38-f15e2f1a3757 -# Fallback RPC URL (Optional but HIGHLY recommended) -# -# SMART STRATEGY (DISABLED - Helius API key issue): -# 1. Bot STARTS with fallback (Helius) - handles startup burst better (10 req/sec sustained) -# 2. After init, SWITCHES to primary (Alchemy) - more stable for trading operations -# 3. On 429 errors, falls back to Helius temporarily, then returns to Alchemy -# -# TEMPORARILY DISABLED: Set to empty until Helius API key fixed -# SOLANA_FALLBACK_RPC_URL=https://mainnet.helius-rpc.com/?api-key=dcca4bf0-0b91-4f6a-8d12-1c5a4c1c6e5b -SOLANA_FALLBACK_RPC_URL= +# Fallback RPC URL (used for trade execution - higher throughput) +# Helius: startup/subscriptions, Alchemy: trade execution +SOLANA_FALLBACK_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/5A0iA5UYpsmP9gkuezYeg -# RPC Provider Comparison (as of Nov 2025): -# ✅ Alchemy: 300M CU/month, excellent for trading operations (PRIMARY) -# ✅ Helius: 10 req/sec sustained, perfect for startup bursts (STARTUP + FALLBACK) -# QuickNode: Paid plans, very reliable -# Ankr/Public: Unreliable, not recommended +# Alternative RPC providers: +# QuickNode: https://solana-mainnet.quiknode.pro/YOUR_ENDPOINT/ +# Public (not recommended): https://api.mainnet-beta.solana.com # ================================ # REQUIRED - PYTH NETWORK (Price Feeds) diff --git a/lib/drift/client.ts b/lib/drift/client.ts index adc25c7..698738d 100644 --- a/lib/drift/client.ts +++ b/lib/drift/client.ts @@ -470,6 +470,13 @@ export class DriftService { return this.connection } + /** + * Get fallback connection (Alchemy for trade execution) + */ + getFallbackConnection(): Connection | null { + return this.fallbackConnection || null + } + /** * Get user instance */ diff --git a/lib/drift/orders.ts b/lib/drift/orders.ts index b22ebc2..a5742c4 100644 --- a/lib/drift/orders.ts +++ b/lib/drift/orders.ts @@ -146,8 +146,16 @@ export async function openPosition( console.log(`📝 Transaction submitted: ${txSig}`) // CRITICAL: Confirm transaction actually executed on-chain - console.log('⏳ Confirming transaction on-chain...') - const connection = driftService.getConnection() + // Use Alchemy (fallback RPC) for confirmation - higher throughput + console.log('⏳ Confirming transaction on-chain (using Alchemy for high throughput)...') + const alchemyConnection = driftService.getFallbackConnection() + const connection = alchemyConnection || driftService.getConnection() + + if (alchemyConnection) { + console.log('✅ Using Alchemy RPC for transaction confirmation') + } else { + console.log('⚠️ No fallback RPC available, using primary RPC') + } try { const confirmation = await connection.confirmTransaction(txSig, 'confirmed') @@ -557,9 +565,16 @@ export async function closePosition( console.log(`✅ Close order placed! Transaction: ${txSig}`) // 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 (30s timeout)...') - const connection = driftService.getConnection() + // Use Alchemy (fallback RPC) for confirmation - higher throughput + console.log('⏳ Confirming transaction on-chain (using Alchemy, 30s timeout)...') + const alchemyConnection = driftService.getFallbackConnection() + const connection = alchemyConnection || driftService.getConnection() + + if (alchemyConnection) { + console.log('✅ Using Alchemy RPC for transaction confirmation') + } else { + console.log('⚠️ No fallback RPC available, using primary RPC') + } try { const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed')