A high-performance event processing system for Starknet blockchain events, built with Go and designed to handle vault operations, liquidity provider events, and option trading activities in real-time.
The Event Processor is a robust service that listens to PostgreSQL database notifications for Starknet blockchain events and processes them to maintain up-to-date state for various DeFi components including:
- Vaults: Manages locked, unlocked, and stashed balances
- Liquidity Providers: Tracks LP positions and balances across vaults
- Option Rounds: Handles auction mechanics, pricing, and settlement
- Option Buyers: Manages option minting, refunds, and bid processing
The system is built around a PostgreSQL-based event-driven architecture:
Starknet Blockchain → Database Triggers → Event Processor → State Updates
- Database Listener: Listens to PostgreSQL notifications for block insertions and updates
- Event Processor: Processes blockchain events and updates application state
- Transaction Management: Handles atomic operations with rollback capabilities
- State Recovery: Automatically recovers from the latest processed block
- Real-time Processing: Listens to database notifications for immediate event processing
- Atomic Operations: Ensures data consistency with transaction rollback support
- State Recovery: Automatically resumes processing from the last known state
- Block Reversion: Handles blockchain reorganizations by reverting affected events
- High Performance: Built with Go for optimal performance and memory efficiency
- Go 1.24.1 or higher
- PostgreSQL 12+ with notification support
- Rust 1.85.0 (for VM components)
- Docker and Docker Compose (optional)
-
Clone the repository
git clone <repository-url> cd event-processor
-
Install Go dependencies
go mod download
-
Install Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env rustup install 1.85.0 rustup default 1.85.0
-
Set up environment variables
cp .env.example .env # Edit .env with your database configuration -
Build the application
make build
-
Build and run with Docker Compose
docker-compose up --build
-
Or build manually
docker build -t event-processor . docker run -e DB_URL="your-database-url" event-processor
DB_URL: PostgreSQL connection stringPOSTGRES_USER: Database usernamePOSTGRES_PASSWORD: Database passwordPOSTGRES_DB: Database name
The system expects the following database triggers to be configured:
lp_row_update: Triggers on liquidity provider updatesvault_update: Triggers on vault state changesstate_transition: Triggers on state field changesob_update: Triggers on option buyer updatesor_update: Triggers on option round updates
# Run locally
./processor
# Run with Docker
docker-compose up
# Run with debug VM
VM_DEBUG=true make buildThe service runs on port 6060 by default and exposes:
- Health check endpoint (if implemented)
- Metrics endpoint (if implemented)
event-processor/
├── adaptors/ # Data adapters and utilities
├── db/ # Database operations and listeners
├── models/ # Data models and structures
├── juno/ # Starknet integration components
├── main.go # Application entry point
├── Dockerfile # Container configuration
├── docker-compose.yml # Local development setup
└── Makefile # Build and development tasks
# Standard build
make build
# Debug build with VM debugging
VM_DEBUG=true make build
# Build with specific version
VERSION=v1.0.0 make buildThe system works with the following key tables:
starknet_blocks: Blockchain block informationevents: Processed blockchain eventsvaults: Vault state and configurationliquidity_providers: LP positions and balancesoption_rounds: Auction rounds and pricingoption_buyers: Buyer positions and bids
The service provides comprehensive logging for:
- Block processing events
- Event processing status
- Database transaction operations
- Error conditions and recovery