WebSocket server for monitoring Solana program accounts in real-time.
Subscribes to Solana program accounts via Carbon datapipeline, decodes them, stores in SQLite + Redis, and broadcasts updates to WebSocket clients.
Currently monitoring: Meteora DAMM V2 program (can be changed to any Solana program)
- Rust 1.70+
- Redis
- SQLite
- Solana RPC endpoint with subscription support
macOS:
brew install redis sqliteLinux:
sudo apt install redis-server sqlite3git clone <repo-url>
cd account_socket
cargo buildCreate .env file:
RPC_URL=wss://mainnet.helius-rpc.com/?api-key=YOUR_KEY
DATABASE_URL=sqlite:account.db
REDIS_URL=redis://127.0.0.1:6379
WEBSOCKET_PORT=8080cargo install sqlx-cli --no-default-features --features sqlite
sqlx migrate runredis-servercargo runServer starts on ws://127.0.0.1:8080/ws
const ws = new WebSocket('ws://localhost:8080/ws');
ws.onmessage = (event) => console.log(JSON.parse(event.data));ws.send(JSON.stringify({
action: "subscribe",
pubkey: "CPpeWQrniBd4WARd3kEjS7XP1oxVtD8Fr3hie19F6gXV"
}));Returns current state immediately, then streams updates.
ws.send(JSON.stringify({
action: "unsubscribe",
pubkey: "CPpeWQrniBd4WARd3kEjS7XP1oxVtD8Fr3hie19F6gXV"
}));{
"pubkey": "...",
"source": "cache|database|realtime",
"account": {
"slot": 370462731,
"account_type": "Pool",
"owner": "...",
"lamports": 8630400,
"data_json": { /* decoded account data */ },
"created_at": "2025-10-01T10:50:05Z"
}
}Using wscat:
npm install -g wscat
wscat -c ws://localhost:8080/ws
> {"action":"subscribe","pubkey":"CPpeWQrniBd4WARd3kEjS7XP1oxVtD8Fr3hie19F6gXV"}Using websocat:
cargo install websocat
echo '{"action":"subscribe","pubkey":"CPpeWQrniBd4WARd3kEjS7XP1oxVtD8Fr3hie19F6gXV"}' | websocat ws://localhost:8080/wsTo monitor a different Solana program:
- Add decoder to
Cargo.toml - Update
PROGRAM_IDinsrc/main.rs - Update account types in
src/processor.rs
# Recent updates
sqlite3 account.db "SELECT pubkey, slot, account_type FROM account_updates ORDER BY created_at DESC LIMIT 10;"
# Account history
sqlite3 account.db "SELECT slot, account_type FROM account_updates WHERE pubkey = 'YOUR_PUBKEY' ORDER BY slot DESC;"Solana RPC → Carbon Pipeline → Decoder → Processor → SQLite + Redis → WebSocket Broadcast
- On subscribe: checks Redis → SQLite for current state, then streams real-time updates
- Uses
serde_jsonwitharbitrary_precisionfor u128 values - Supports account types: Pool, Position, Config, ClaimFeeOperator, TokenBadge, Vesting
Redis not running:
redis-cli ping # should return PONGNo updates:
- Check RPC endpoint supports subscriptions
- Verify account is owned by the program
- Check logs:
RUST_LOG=debug cargo run