https://github.com/vitwit/solana-pda-analyser
Analyze Program Derived Addresses (PDAs), monitor transactions, and uncover patterns on Solana. Includes a CLI, REST API, and modern web UI for real-time insights.
https://github.com/vitwit/solana-pda-analyser
pda pda-analyser solana
Last synced: 17 days ago
JSON representation
Analyze Program Derived Addresses (PDAs), monitor transactions, and uncover patterns on Solana. Includes a CLI, REST API, and modern web UI for real-time insights.
- Host: GitHub
- URL: https://github.com/vitwit/solana-pda-analyser
- Owner: vitwit
- License: mit
- Created: 2025-07-10T12:29:19.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-10T13:28:39.000Z (11 months ago)
- Last Synced: 2025-07-10T19:53:08.028Z (11 months ago)
- Topics: pda, pda-analyser, solana
- Language: Rust
- Homepage:
- Size: 99.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Solana PDA Analyzer
A comprehensive, production-ready tool for analyzing Solana Program Derived Addresses (PDAs), tracking transaction patterns, and understanding program behavior on the Solana blockchain. Features real-time analysis, pattern recognition, and beautiful visualization of PDA derivation patterns.
## Features
- **๐ Advanced PDA Analysis**: Derive seeds and analyze PDA patterns for any Solana program
- **๐ REST API Server**: Full-featured HTTP API for real-time PDA analysis (see [API_EXAMPLES.md](API_EXAMPLES.md))
- **๐ Real-World Examples**: Pre-loaded with examples from major protocols (SPL Token, Metaplex, Serum, Raydium)
- **๐ฏ Pattern Recognition**: Automatically detect and classify common PDA seed patterns
## ๐ Analysis Output Sample
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ SOLANA PDA ANALYZER - COMPREHENSIVE ANALYSIS REPORT
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Analyzing Program Derived Addresses from Live Solana Programs
๐ Reverse Engineering Seed Patterns and Derivation Logic
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ DETAILED ANALYSIS RESULTS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. โ
USDC Associated Token Account
๐ท๏ธ PDA Address: Gh9ZwEmd...hQKkx
๐ง Program: SPL Associated Token (ATokenGP...nL)
๐ Description: Stores USDC tokens for wallet 9WzDXwBbmkg8...
๐ฏ Pattern: WALLET_TOKEN_MINT (98% confidence)
โฑ๏ธ Analysis Time: 12ms
๐ฑ Seed Breakdown:
1. ๐ Pubkey (32 bytes): Wallet owner address
2. ๐ Pubkey (32 bytes): SPL Token Program ID
3. ๐ Pubkey (32 bytes): USDC mint address
๐ PATTERN ANALYSIS & STATISTICS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Pattern Distribution:
1. WALLET_TOKEN_MINT [โโโโโโโโโโโโโโโโโโโโ] 45.0% (9 PDAs)
2. STRING_PROGRAM_MINT [โโโโโโโโโโโโโโโโโโโโ] 20.0% (4 PDAs)
3. STRING_AUTHORITY [โโโโโโโโโโโโโโโโโโโโโ] 15.0% (3 PDAs)
4. PUBKEY_U64 [โโโโโโโโโโโโโโโโโโโโ] 10.0% (2 PDAs)
5. STRING_SINGLETON [โโโโโโโโโโโโโโโโโโโโ] 10.0% (2 PDAs)
๐ EXECUTIVE SUMMARY
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ Analysis Overview:
โข Total PDAs Analyzed: 20
โข Unique Patterns Detected: 8
โข Overall Success Rate: 95.0%
โข Total Processing Time: 234ms
โข Average Time per PDA: 11.7ms
```
## ๐ Quick Start
### Prerequisites
- Rust 1.70+
- PostgreSQL 12+
- Docker (optional)
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/your-username/solana-pda-analyzer.git
cd solana-pda-analyzer
```
2. **Set up the database**
```bash
# Create PostgreSQL database
createdb solana_pda_analyzer
# Copy environment file
cp .env.example .env
# Edit .env with your database credentials
nano .env
```
3. **Build the project**
```bash
make build
# or manually: cargo build --release
```
4. **Initialize the database**
```bash
make db-init
# or manually: ./target/release/pda-analyzer database init
```
5. **Run the tests**
```bash
make test-all
```
6. **Start the API server**
```bash
make run
# or manually: ./target/release/pda-analyzer serve
```
7. **Test the API**
```bash
# Health check
curl http://localhost:8080/health
# Analyze a PDA
curl -X POST http://localhost:8080/api/v1/analyze/pda \
-H "Content-Type: application/json" \
-d '{"address": "SysvarRent111111111111111111111111111111111", "program_id": "11111111111111111111111111111112"}'
```
8. **Access the API documentation**
Open your browser to `http://localhost:8080/docs`
### ๐ณ Docker Setup (Alternative)
```bash
# Start with Docker Compose
docker-compose up -d
# Run tests in Docker
docker-compose exec app make test-all
# View logs
docker-compose logs -f app
```
## ๐ป Usage
### Command Line Interface
#### Analyze Individual PDAs
```bash
# Analyze a specific PDA
./target/release/pda-analyzer analyze \
--address "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr" \
--program-id "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
# Batch analyze multiple PDAs
./target/release/pda-analyzer batch-analyze \
--input pdas.json \
--output results.json
```
#### Run Real-World Examples
```bash
# Run all example analyses
./examples/run_examples.sh
# Run specific category
./examples/run_examples.sh spl-token
./examples/run_examples.sh metaplex
./examples/run_examples.sh real-world
```
#### Database Operations
```bash
# Initialize database with schema
./target/release/pda-analyzer database init
# Check database status and metrics
./target/release/pda-analyzer database status
# Reset database (caution!)
./target/release/pda-analyzer database reset
# Run pending migrations
./target/release/pda-analyzer database migrate
```
#### Fetch and Analyze Transactions
```bash
# Fetch recent transactions for a program
./target/release/pda-analyzer fetch \
--program-id "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" \
--limit 1000
# Analyze transaction patterns
./target/release/pda-analyzer analyze-transactions \
--program-id "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
```
#### Statistics and Reports
```bash
# Show comprehensive statistics
./target/release/pda-analyzer stats
# Generate detailed analysis report
./target/release/pda-analyzer report \
--output html \
--file analysis_report.html
```
### ๐ REST API
#### Analyze PDAs
```bash
# Analyze a single PDA
curl -X POST http://localhost:8080/api/v1/analyze/pda \
-H "Content-Type: application/json" \
-d '{
"address": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
"program_id": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}'
# Batch analyze multiple PDAs
curl -X POST http://localhost:8080/api/v1/analyze/pda/batch \
-H "Content-Type: application/json" \
-d '{
"pdas": [
{"address": "PDA1...", "program_id": "PROG1..."},
{"address": "PDA2...", "program_id": "PROG2..."}
]
}'
```
#### Programs and Patterns
```bash
# Get all analyzed programs
curl http://localhost:8080/api/v1/programs
# Get program details and statistics
curl http://localhost:8080/api/v1/programs/{program_id}
# Get PDA patterns for a program
curl http://localhost:8080/api/v1/programs/{program_id}/patterns
```
#### Analytics and Reports
```bash
# Get database metrics
curl http://localhost:8080/api/v1/analytics/database
# Get pattern distribution
curl http://localhost:8080/api/v1/analytics/patterns
# Get performance metrics
curl http://localhost:8080/api/v1/analytics/performance
```
## Real-World Examples
The tool includes comprehensive examples from major Solana protocols:
### ๐ SPL Token Examples
- **Associated Token Accounts**: Most common PDA pattern on Solana
- **Mint Authorities**: Program-controlled token minting
- **Vault Token Accounts**: DeFi protocol escrow patterns
### ๐จ Metaplex NFT Examples
- **NFT Metadata**: Standard NFT information storage
- **Master Editions**: NFT printing and edition control
- **Collection Metadata**: NFT collection organization
- **Auction House**: NFT marketplace structures
### ๐ Protocol Examples
- **Serum DEX**: Market authorities and trading structures
- **Raydium AMM**: Liquidity pool management
- **Marinade Finance**: Liquid staking protocol state
- **Solana Name Service**: Domain name resolution
- **Governance**: DAO proposal and voting systems
Each example includes:
- โ
**Real PDA addresses** from mainnet/testnet
- ๐ **Expected seed patterns** with detailed breakdowns
- ๐ **Comprehensive descriptions** of functionality
- ๐งช **Automated tests** for validation
## โ๏ธ Configuration
### Environment Variables
Create a `.env` file (copy from `.env.example`) and update as required
## ๐งช Testing
### Running Tests
```bash
# Run all tests
make test-all
# Run specific test categories
make test-unit # Unit tests only
make test-integration # Integration tests only
make test-api # API endpoint tests
make test-performance # Performance benchmarks
# Run tests with coverage
make test-coverage
# Run example validation
make test-examples
```
### Performance Testing
```bash
# Run benchmark tests
cargo bench
# Load test the API
./tests/load_test.py --concurrent 50 --requests 1000
# Profile memory usage
./tests/memory_profile.sh
```
## ๐ API Reference
### Response Format
All API responses follow this format:
```json
{
"success": true,
"data": {
"pda_info": {
"address": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
"program_id": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
"seeds": [
{
"type": "Pubkey",
"value": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"description": "Wallet owner address"
}
],
"pattern": "WALLET_TOKEN_MINT",
"confidence": 0.98,
"analysis_time_ms": 12
}
},
"error": null,
"timestamp": "2024-01-01T00:00:00Z",
"request_id": "req_123456789"
}
```
### Complete Endpoint List
#### PDA Analysis
- `POST /api/v1/analyze/pda` - Analyze a single PDA
- `POST /api/v1/analyze/pda/batch` - Batch analyze multiple PDAs
- `GET /api/v1/pdas` - List analyzed PDAs with pagination
- `GET /api/v1/pdas/{address}` - Get detailed PDA information
#### Programs
- `GET /api/v1/programs` - List all programs
- `GET /api/v1/programs/{id}` - Get program details
- `GET /api/v1/programs/{id}/stats` - Get program statistics
- `GET /api/v1/programs/{id}/patterns` - Get program PDA patterns
#### Transactions
- `GET /api/v1/transactions` - List transactions with filters
- `GET /api/v1/transactions/{signature}` - Get transaction details
- `POST /api/v1/transactions/analyze` - Analyze transaction for PDAs
#### Analytics
- `GET /api/v1/analytics/database` - Database metrics and statistics
- `GET /api/v1/analytics/patterns` - Pattern distribution and trends
- `GET /api/v1/analytics/performance` - Performance metrics and timing
## ๐ค Contributing
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
### Quick Contribution Steps
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes and add tests
4. Run the test suite: `make test-all`
5. Commit your changes: `git commit -m "Add amazing feature"`
6. Push to the branch: `git push origin feature/amazing-feature`
7. Submit a pull request
### Development Setup
```bash
# Install development dependencies
make dev-setup
# Run development server with hot reload
make dev
# Run linting and formatting
make lint
make fmt
# Generate documentation
make docs
```
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Support
- **๐ Bug Reports**: [GitHub Issues](https://github.com/vitwit/solana-pda-analyzer/issues)
- **๐ก Feature Requests**: [GitHub Discussions](https://github.com/vitwit/solana-pda-analyzer/discussions)
- **๐ Documentation**: [Project Wiki](https://github.com/vitwit/solana-pda-analyzer/wiki)
- **๐ฌ Community**: [Telegram Channel](https://t.co/69gF5Se6IW)