A full-stack web application for tracking cryptocurrency protocol attacks and exploits. Data refreshes automatically every 48 hours via Supabase cron jobs, with an interactive dashboard for visualization and analysis.
- Real-time attack tracking across multiple protocols
- Interactive dashboard with charts and visualizations
- Automated data refresh (every 48 hours)
- NEW: Manual rekt.news scraping with LLM-powered data extraction
- Multiple data sources: Rekt.news, DeFiYield, and SlowMist
- CSV export for offline analysis
- Responsive design for desktop and mobile
- React 18+ with TypeScript
- Vite (build tool)
- Tailwind CSS
- Recharts (data visualization)
- React Query for state management
- Axios for HTTP requests
- FastAPI (Python 3.11+)
- Supabase PostgreSQL
- Supabase Python Client
- pandas for data processing
- OpenAI API for LLM-powered data extraction
- BeautifulSoup4 for web scraping
- Supabase PostgreSQL database
- Supabase Edge Functions for cron jobs
- Vercel (frontend) and Railway/Render (backend) for deployment
defi-final-project/
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── services/ # API client services
│ │ ├── types/ # TypeScript interfaces
│ │ ├── hooks/ # Custom React hooks
│ │ ├── utils/ # Utility functions
│ │ ├── App.tsx
│ │ └── main.tsx
│ ├── package.json
│ └── vite.config.ts
│
├── api/ # FastAPI backend
│ ├── app/
│ │ ├── routers/ # API endpoints
│ │ ├── services/ # Business logic
│ │ ├── models/ # Pydantic schemas
│ │ ├── utils/ # Helper functions
│ │ └── main.py
│ ├── scripts/ # Utility scripts
│ └── requirements.txt
│
├── supabase/ # Supabase configuration
│ ├── migrations/ # Database migrations
│ └── functions/ # Edge functions
│
└── README.md
See QUICKSTART.md for a detailed setup guide.
- Node.js 18+ and npm
- Python 3.11+
- Supabase account
-
Navigate to the API directory:
cd api -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create .env file with your Supabase credentials and OpenAI API key:
cat > .env << EOF SUPABASE_URL=your_supabase_url SUPABASE_ANON_KEY=your_anon_key SUPABASE_SERVICE_KEY=your_service_key OPENAI_API_KEY=your_openai_api_key FRONTEND_URL=http://localhost:5173 PORT=8000 ENVIRONMENT=development EOF
Note: The
OPENAI_API_KEYis required for the rekt.news scraping feature. If not provided, the scraper will use basic processing without LLM enhancement. -
Run the development server:
uvicorn app.main:app --reload
The API will be available at
http://localhost:8000
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Create .env file:
cat > .env << EOF VITE_API_BASE_URL=http://localhost:8000/api/v1 VITE_SUPABASE_URL=your_supabase_url VITE_SUPABASE_ANON_KEY=your_anon_key EOF
-
Run the development server:
npm run dev
The app will be available at
http://localhost:5173
-
Create a Supabase project at supabase.com
-
Run the migration:
- Go to the SQL Editor in your Supabase dashboard
- Copy and paste the contents of
supabase/migrations/001_initial_schema.sql - Execute the query
-
Deploy the Edge Function:
supabase functions deploy refresh-data
-
Set up the cron job:
- Run the SQL in
supabase/cron_schedule.sqlin the SQL Editor - Update the URLs with your actual function URL
- Run the SQL in
GET /attacks- Get all attacks with optional filtersGET /attacks/summary- Get summary statisticsGET /attacks/timeline- Get timeline dataGET /attacks/by-protocol- Get protocol breakdownGET /attacks/by-type- Get attack type breakdownGET /attacks/top- Get top attacks by loss amountGET /attacks/export- Export data to CSVPOST /attacks/refresh- Trigger manual data refresh (requires service key)POST /attacks/scrape-rekt- Scrape rekt.news leaderboard and process with LLMGET /attacks/refresh/status- Get refresh status
The application automatically refreshes data every 48 hours at 2 AM UTC. You can also trigger a manual refresh:
cd api
source venv/bin/activate
python scripts/manual_refresh.pyThe dashboard includes a "Scrape Rekt.news" button that:
- Scrapes the latest data from https://rekt.news/leaderboard
- Uses OpenAI's LLM to extract and structure attack information
- Automatically categorizes attack types and identifies blockchains
- Updates the database with new and updated records
This feature requires an OPENAI_API_KEY in your backend .env file. The LLM processes the scraped data to extract:
- Attack types (exploit, flash loan, reentrancy, etc.)
- Blockchain networks
- Detailed descriptions
- Proper date formatting
IMPORTANT: Never commit .env files or expose your SUPABASE_SERVICE_KEY in client-side code.
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_KEY=your_service_key
OPENAI_API_KEY=your_openai_api_key # Required for rekt.news scraping
FRONTEND_URL=http://localhost:5173
PORT=8000
ENVIRONMENT=development
VITE_API_BASE_URL=http://localhost:8000/api/v1
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_anon_key
See DEPLOYMENT.md for detailed deployment instructions.
cd frontend
npm run build
vercel deploy- Connect your repository
- Set environment variables
- Deploy from the
apidirectory
- All sensitive credentials stored in
.envfiles (git-ignored) - Service role key never exposed to frontend
- CORS configured for specific origins only
- API authentication on protected endpoints
- Input validation on all endpoints
- QUICKSTART.md - Setup guide
- DEPLOYMENT.md - Production deployment instructions
- TROUBLESHOOTING.md - Common issues and solutions
MIT License
Contributions welcome. Submit a pull request or open an issue for bugs and feature requests.
CS 194 - DeFi Final Project