An open API service indexing awesome lists of open source software.

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.

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)