Files
brk/crates/brk_computer/src/supply/compute.rs
2026-03-09 15:16:52 +01:00

85 lines
2.6 KiB
Rust

use brk_error::Result;
use brk_types::Indexes;
use vecdb::Exit;
use super::Vecs;
use crate::{blocks, distribution, mining, prices, scripts, transactions};
impl Vecs {
#[allow(clippy::too_many_arguments)]
pub(crate) fn compute(
&mut self,
scripts: &scripts::Vecs,
blocks: &blocks::Vecs,
mining: &mining::Vecs,
transactions: &transactions::Vecs,
prices: &prices::Vecs,
distribution: &distribution::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
// 1. Compute burned/unspendable supply
self.burned.compute(
scripts,
mining,
&blocks.lookback,
prices,
starting_indexes,
exit,
)?;
// 2. Compute inflation rate: (supply[h] / supply[1y_ago]) - 1
let circulating_supply = &distribution.utxo_cohorts.all.metrics.supply.total.sats;
self.inflation_rate
.bps
.height
.compute_rolling_ratio_change(
starting_indexes.height,
&blocks.lookback.height_1y_ago,
&circulating_supply.height,
exit,
)?;
// 3. Compute velocity at height level
self.velocity
.compute(blocks, transactions, distribution, starting_indexes, exit)?;
// 4. Compute market cap delta (change + rate across 4 windows)
let window_starts = blocks.lookback.window_starts();
self.market_cap_delta.compute(
starting_indexes.height,
&window_starts,
&self.market_cap.cents.height,
exit,
)?;
// 5. market_cap_rate - realized_cap_rate per window
let all_realized = &distribution.utxo_cohorts.all.metrics.realized;
let mcr_arr = self.market_cap_delta.rate.0.as_array();
let diff_arr = self.market_minus_realized_cap_growth_rate.0.as_mut_array();
// 24h, 1w, 1y from extended; 1m from core delta
let rcr_rates = [
&all_realized.cap_delta_extended.rate_24h.bps.height,
&all_realized.cap_delta_extended.rate_1w.bps.height,
&all_realized.cap_delta.rate_1m.bps.height,
&all_realized.cap_delta_extended.rate_1y.bps.height,
];
for i in 0..4 {
diff_arr[i].height.compute_subtract(
starting_indexes.height,
&mcr_arr[i].bps.height,
rcr_rates[i],
exit,
)?;
}
let _lock = exit.lock();
self.db.compact()?;
Ok(())
}
}