A data pipeline for collecting and analyzing MEV-Commit protocol data using TimescaleDB.
This project implements a data pipeline that:
- Collects event data from the MEV-Commit protocol
- Stores it in TimescaleDB
- Creates materialized views for efficient querying
- Exposes the data via PostgREST API
The pipeline consists of two main components:
- Main Event Pipeline (
main.py
): Collects protocol events from both MEV-Commit and validator contracts - L1 Transaction Pipeline (
fetch_l1_txs.py
): Fetches corresponding L1 transaction data
The system maintains several materialized views for efficient querying:
-
openedcommitmentstoredall
- Consolidates data from both v1 and v2 of opened commitments
- Primary view for tracking all opened commitments
- Indexed by
commitmentIndex
andblocknumber
-
preconf_txs (in api schema)
- Combines data from multiple tables for preconfirmation transactions
- Includes commitment details, L1 transaction data, and processed status
- Calculates decay multipliers and ETH values
- Indexed by
commitmentIndex
andhash
- Docker and Docker Compose
.env
file with required environment variables
Create a .env
file with the following variables:
DB_NAME=mev_commit_testnet
DB_USER=postgres
DB_PASSWORD=your_password
DB_PORT=5432
DB_HOST=localhost
# PostgREST Configuration
PGRST_DB_URI=postgres://postgres:your_password@timescaledb:5432/mev_commit_testnet
PGRST_DB_SCHEMA=api
PGRST_DB_ANON_ROLE=web_anon
PGRST_SERVER_PORT=3000
- Build and start the containers:
docker compose build
docker compose up -d
- Check container status:
docker compose ps
- View logs:
# All containers
docker compose logs -f
# Specific container
docker compose logs -f app
- Connect to docker container:
docker exec -it mev_timescaledb /bin/bash
- Connect to database:
psql -U postgres -d mev_commit_testnet
- Connect to default database:
psql -U postgres -d postgres
- Terminate existing connections:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'mev_commit_testnet';
- Drop and recreate database:
DROP DATABASE mev_commit_testnet;
CREATE DATABASE mev_commit_testnet;
The PostgREST API is available at http://localhost:3003
and provides RESTful access to the database views and tables.
Example queries:
# Get recent preconfirmation transactions
curl "http://localhost:3003/preconf_txs?order=block_number.desc&limit=10"
# Get commitments for specific bidder
curl "http://localhost:3003/preconf_txs?bidder=eq.0x..."
├── pipeline/
│ ├── db.py # Database operations
│ ├── events.py # Event definitions
│ ├── queries.py # Data fetching logic
│ └── materialized_views.py # View management
├── main.py # Main event pipeline
├── fetch_l1_txs.py # L1 transaction pipeline
├── docker-compose.yml
└── Dockerfile
- Define event configuration in
pipeline/events.py
- Add event to appropriate config in
main.py
- Update materialized views if needed in
pipeline/materialized_views.py