import { NextResponse } from 'next/server' import { initializeDriftService } from '@/lib/drift/client' /** * GET /api/drift/account-health * * Returns current account health metrics from Drift Protocol * Used by settings UI to dynamically display collateral and calculate position sizes */ export async function GET() { try { const driftService = await initializeDriftService() if (!driftService) { return NextResponse.json( { error: 'Drift service not initialized' }, { status: 503 } ) } const health = await driftService.getAccountHealth() return NextResponse.json({ totalCollateral: health.totalCollateral, freeCollateral: health.freeCollateral, totalLiability: health.totalLiability, marginRatio: health.marginRatio, }) } catch (error: any) { console.error('❌ Error fetching account health:', error) return NextResponse.json( { error: 'Failed to fetch account health', details: error.message }, { status: 500 } ) } }