🚀 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:
mindesbunister
2025-07-13 00:20:01 +02:00
parent a9bbcc7b5f
commit e985a9ec6f
32 changed files with 3875 additions and 771 deletions

View File

@@ -0,0 +1,11 @@
import { NextResponse } from 'next/server'
import { driftTradingService } from '../../../../lib/drift-trading'
export async function GET() {
try {
const balance = await driftTradingService.getAccountBalance()
return NextResponse.json(balance)
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 })
}
}

View File

@@ -0,0 +1,19 @@
import { NextResponse } from 'next/server'
import { driftTradingService } from '../../../../lib/drift-trading'
export async function POST() {
try {
const loginStatus = await driftTradingService.login()
return NextResponse.json(loginStatus)
} catch (error: any) {
return NextResponse.json(
{
isLoggedIn: false,
publicKey: '',
userAccountExists: false,
error: error.message
},
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,11 @@
import { NextResponse } from 'next/server'
import { driftTradingService } from '../../../../lib/drift-trading'
export async function GET() {
try {
const positions = await driftTradingService.getPositions()
return NextResponse.json({ positions })
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 })
}
}

View File

@@ -4,6 +4,16 @@ import { driftTradingService } from '../../../lib/drift-trading'
export async function POST(req: NextRequest) {
try {
const params = await req.json()
// Ensure user is logged in before executing trade
const loginStatus = await driftTradingService.login()
if (!loginStatus.isLoggedIn) {
return NextResponse.json(
{ error: `Cannot execute trade: ${loginStatus.error}` },
{ status: 401 }
)
}
const result = await driftTradingService.executeTrade(params)
return NextResponse.json(result)
} catch (e: any) {
@@ -13,6 +23,15 @@ export async function POST(req: NextRequest) {
export async function GET() {
try {
// Ensure user is logged in before getting positions
const loginStatus = await driftTradingService.login()
if (!loginStatus.isLoggedIn) {
return NextResponse.json(
{ error: `Cannot get positions: ${loginStatus.error}` },
{ status: 401 }
)
}
const positions = await driftTradingService.getPositions()
return NextResponse.json({ positions })
} catch (e: any) {