| Crates.io | brk_computer |
| lib.rs | brk_computer |
| version | 0.0.109 |
| created_at | 2025-02-23 23:32:22.034672+00 |
| updated_at | 2025-09-20 17:21:58.180421+00 |
| description | A Bitcoin dataset computer built on top of brk_indexer |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1566727 |
| size | 1,016,856 |
Advanced Bitcoin analytics engine that transforms indexed blockchain data into comprehensive metrics and financial analytics.
This crate provides a sophisticated analytics engine that processes indexed Bitcoin blockchain data to compute comprehensive metrics, financial analytics, and statistical aggregations. Built on top of brk_indexer, it transforms raw blockchain data into actionable insights through state tracking, cohort analysis, market metrics, and advanced Bitcoin-specific calculations.
Key Features:
Target Use Cases:
cargo add brk_computer
use brk_computer::Computer;
use brk_indexer::Indexer;
use brk_fetcher::Fetcher;
use vecdb::Exit;
use std::path::Path;
// Initialize dependencies
let outputs_path = Path::new("./analytics_data");
let indexer = Indexer::forced_import(outputs_path)?;
let fetcher = Some(Fetcher::import(true, None)?);
// Create computer with price data support
let mut computer = Computer::forced_import(outputs_path, &indexer, fetcher)?;
// Compute analytics from indexer state
let exit = Exit::default();
let starting_indexes = brk_indexer::Indexes::default();
computer.compute(&indexer, starting_indexes, &exit)?;
println!("Analytics computation completed!");
The Computer is organized into 7 specialized computation modules:
indexes: Fundamental blockchain index computationsconstants: Network constants and protocol parametersmarket: Price-based financial metrics and market analysispools: Mining pool analysis and centralization metricschain: Core blockchain metrics (difficulty, hashrate, fees)stateful: Advanced state tracking (UTXO lifecycles, address behaviors)cointime: Cointime economics and value-time calculationsComputer::forced_import(outputs_path, indexer, fetcher) -> Result<Self>
Creates computer instance with optional price data integration.
compute(&mut self, indexer: &Indexer, starting_indexes: Indexes, exit: &Exit) -> Result<()>
Main computation pipeline processing all analytics modules.
Market Analytics:
On-Chain Analytics:
Monetary Analytics:
use brk_computer::Computer;
// Initialize with indexer and optional price data
let computer = Computer::forced_import(
"./analytics_output",
&indexer,
Some(price_fetcher)
)?;
// Compute all analytics modules
let exit = vecdb::Exit::default();
computer.compute(&indexer, starting_indexes, &exit)?;
// Access computed metrics
println!("Market cap vectors computed: {}", computer.market.len());
println!("Chain metrics computed: {}", computer.chain.len());
println!("Stateful analysis completed: {}", computer.stateful.len());
use brk_computer::Computer;
use brk_structs::{DateIndex, Height};
let computer = Computer::forced_import(/* ... */)?;
// Access market metrics after computation
if let Some(market) = &computer.market {
// Daily market cap analysis
let date_index = DateIndex::from_days_since_genesis(5000);
if let Some(market_cap) = market.dateindex_to_market_cap.get(date_index)? {
println!("Market cap on day {}: ${}", date_index, market_cap.to_dollars());
}
// MVRV (Market Value to Realized Value) ratio
if let Some(mvrv) = market.dateindex_to_mvrv.get(date_index)? {
println!("MVRV ratio: {:.2}", mvrv);
}
}
// Chain-level metrics
let height = Height::new(800000);
if let Some(difficulty) = computer.chain.height_to_difficulty.get(height)? {
println!("Network difficulty at height {}: {}", height, difficulty);
}
use brk_computer::Computer;
use brk_structs::{DateIndex, CohortId};
let computer = Computer::forced_import(/* ... */)?;
// Address cohort analysis
let cohort_date = DateIndex::from_days_since_genesis(4000);
// Analyze address behavior patterns
if let Some(address_cohorts) = &computer.stateful.address_cohorts {
for cohort_id in address_cohorts.get_cohort_ids_for_date(cohort_date)? {
let cohort_data = address_cohorts.get_cohort(cohort_id)?;
println!("Cohort {}: {} addresses created",
cohort_id, cohort_data.addresses.len());
println!("Average holding period: {} days",
cohort_data.avg_holding_period.as_days());
}
}
// UTXO cohort lifecycle analysis
if let Some(utxo_cohorts) = &computer.stateful.utxo_cohorts {
let active_utxos = utxo_cohorts.get_active_utxos_for_date(cohort_date)?;
println!("Active UTXOs from cohort: {}", active_utxos.len());
}
use brk_computer::Computer;
use brk_structs::{Height, DateIndex};
let computer = Computer::forced_import(/* ... */)?;
// Supply dynamics
let height = Height::new(750000);
if let Some(supply) = computer.chain.height_to_circulating_supply.get(height)? {
println!("Circulating supply: {} BTC", supply.to_btc());
}
// Realized vs unrealized analysis
let date = DateIndex::from_days_since_genesis(5000);
if let Some(realized_cap) = computer.market.dateindex_to_realized_cap.get(date)? {
if let Some(market_cap) = computer.market.dateindex_to_market_cap.get(date)? {
let unrealized_pnl = market_cap - realized_cap;
println!("Unrealized P&L: ${:.2}B", unrealized_pnl.to_dollars() / 1e9);
}
}
The computer implements a sophisticated multi-stage pipeline:
Allocation Tracking:
allocative integration for memory usage analysisPerformance Optimization:
rayon parallel processing for CPU-intensive calculationsStateful Analytics:
Cointime Economics:
Each computation module operates independently:
Required Dependencies:
brk_indexer: Raw blockchain data accessbrk_structs: Type definitions and conversionsOptional Dependencies:
brk_fetcher: Price data for financial metricsSequential Stages:
Exit Handling:
Main Structure: Computer struct coordinating 7 specialized analytics modules (indexes, constants, market, pools, chain, stateful, cointime)
Computation Pipeline: Multi-stage analytics processing with parallel execution and dependency management
State Tracking: Advanced UTXO and address lifecycle analysis with cohort-based behavioral clustering
Financial Analytics: Comprehensive market metrics including realized/unrealized analysis and cointime economics
Memory Optimization: allocative tracking with lazy/eager evaluation strategies and compressed vector storage
Parallel Processing: rayon integration for CPU-intensive calculations with coordinated exit handling
Architecture: Modular analytics engine transforming indexed blockchain data into actionable financial and economic insights
This README was generated by Claude Code