🚀 Fix Drift Protocol integration - Connection now working
✅ Key fixes: - Bypass problematic SDK subscription that caused 410 Gone errors - Use direct account verification without subscription - Add fallback modes for better reliability - Switch to Helius RPC endpoint for better rate limits - Implement proper error handling and retry logic 🔧 Technical changes: - Enhanced drift-trading.ts with no-subscription approach - Added Drift API endpoints (/api/drift/login, /balance, /positions) - Created DriftAccountStatus and DriftTradingPanel components - Updated Dashboard.tsx to show Drift account status - Added comprehensive test scripts for debugging 📊 Results: - Connection Status: Connected ✅ - Account verification: Working ✅ - Balance retrieval: Working ✅ (21.94 total collateral) - Private key authentication: Working ✅ - User account: 3dG7wayp7b9NBMo92D2qL2sy1curSC4TTmskFpaGDrtA 🌐 RPC improvements: - Using Helius RPC for better reliability - Added fallback RPC options in .env - Eliminated rate limiting issues
This commit is contained in:
82
test-drift-direct.js
Executable file
82
test-drift-direct.js
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Direct Drift SDK test
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
async function testDrift() {
|
||||
console.log('🌊 Testing Drift SDK directly...');
|
||||
|
||||
try {
|
||||
const { Connection, Keypair, PublicKey } = require('@solana/web3.js');
|
||||
const {
|
||||
DriftClient,
|
||||
Wallet,
|
||||
getUserAccountPublicKey,
|
||||
DRIFT_PROGRAM_ID
|
||||
} = require('@drift-labs/sdk');
|
||||
|
||||
// Setup connection and wallet
|
||||
const rpcUrl = process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com';
|
||||
const privateKey = JSON.parse(process.env.SOLANA_PRIVATE_KEY);
|
||||
const keypair = Keypair.fromSecretKey(Buffer.from(privateKey));
|
||||
const connection = new Connection(rpcUrl, 'confirmed');
|
||||
const wallet = new Wallet(keypair);
|
||||
|
||||
console.log(`🏠 Public Key: ${keypair.publicKey.toString()}`);
|
||||
console.log(`📡 RPC: ${rpcUrl}`);
|
||||
|
||||
// Create Drift client
|
||||
console.log('🔧 Creating Drift client...');
|
||||
const driftClient = new DriftClient({
|
||||
connection,
|
||||
wallet,
|
||||
env: 'mainnet-beta',
|
||||
opts: { commitment: 'confirmed' }
|
||||
});
|
||||
|
||||
console.log('📡 Subscribing to Drift client...');
|
||||
await driftClient.subscribe();
|
||||
|
||||
console.log('🔍 Checking user account...');
|
||||
const userAccountPublicKey = await getUserAccountPublicKey(
|
||||
new PublicKey(DRIFT_PROGRAM_ID),
|
||||
keypair.publicKey,
|
||||
0
|
||||
);
|
||||
|
||||
console.log(`👤 User account PK: ${userAccountPublicKey.toString()}`);
|
||||
|
||||
const userAccountInfo = await connection.getAccountInfo(userAccountPublicKey);
|
||||
console.log(`👤 User account exists: ${!!userAccountInfo}`);
|
||||
|
||||
if (userAccountInfo) {
|
||||
console.log('✅ User account found! Getting user data...');
|
||||
const user = driftClient.getUser();
|
||||
console.log('👤 User object created successfully');
|
||||
|
||||
// Try to get some basic data
|
||||
try {
|
||||
const totalCollateral = user.getTotalCollateral();
|
||||
console.log(`💰 Total collateral (raw): ${totalCollateral.toString()}`);
|
||||
} catch (e) {
|
||||
console.log(`⚠️ Could not get collateral: ${e.message}`);
|
||||
}
|
||||
} else {
|
||||
console.log('❌ User account not found - user needs to initialize account at app.drift.trade');
|
||||
}
|
||||
|
||||
console.log('🔌 Unsubscribing...');
|
||||
await driftClient.unsubscribe();
|
||||
|
||||
console.log('✅ Drift test completed successfully!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Drift test failed:', error.message);
|
||||
console.error('Stack:', error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
testDrift().catch(console.error);
|
||||
Reference in New Issue
Block a user