global: snapshot

This commit is contained in:
nym21
2026-03-10 18:10:50 +01:00
parent db1dce0f3b
commit d50c6e0a73
54 changed files with 2398 additions and 3239 deletions

View File

@@ -1,16 +1,18 @@
use brk_error::Result;
use brk_types::{Bitcoin, Dollars, Indexes, StoredF32};
use vecdb::Exit;
use brk_types::{Bitcoin, Dollars, Indexes, Sats, StoredF32};
use vecdb::{Exit, ReadableVec};
use super::{gini, Vecs};
use crate::{distribution, internal::RatioDollarsBp32, mining, transactions};
use crate::{distribution, internal::RatioDollarsBp32, market, mining, transactions};
impl Vecs {
#[allow(clippy::too_many_arguments)]
pub(crate) fn compute(
&mut self,
mining: &mining::Vecs,
distribution: &distribution::Vecs,
transactions: &transactions::Vecs,
market: &market::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
@@ -72,7 +74,6 @@ impl Vecs {
)?;
// Thermocap Multiple: market_cap / thermo_cap
// thermo_cap = cumulative subsidy in USD
self.thermocap_multiple
.bps
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
@@ -82,15 +83,9 @@ impl Vecs {
exit,
)?;
let all_activity = &distribution.utxo_cohorts.all.metrics.activity;
let supply_total_sats = &distribution
.utxo_cohorts
.all
.metrics
.supply
.total
.sats
.height;
let all_metrics = &distribution.utxo_cohorts.all.metrics;
let all_activity = &all_metrics.activity;
let supply_total_sats = &all_metrics.supply.total.sats.height;
// Supply-Adjusted CDD = sum_24h(CDD) / circulating_supply_btc
self.coindays_destroyed_supply_adjusted
@@ -110,7 +105,7 @@ impl Vecs {
exit,
)?;
// Supply-Adjusted CYD = CYD / circulating_supply_btc (CYD = 1y rolling sum of CDD)
// Supply-Adjusted CYD = CYD / circulating_supply_btc
self.coinyears_destroyed_supply_adjusted
.height
.compute_transform2(
@@ -146,6 +141,66 @@ impl Vecs {
exit,
)?;
// Stock-to-Flow: supply / annual_issuance
// annual_issuance ≈ subsidy_per_block × 52560 (blocks/year)
self.stock_to_flow.height.compute_transform2(
starting_indexes.height,
supply_total_sats,
&mining.rewards.subsidy.base.sats.height,
|(i, supply_sats, subsidy_sats, ..)| {
let annual_flow = subsidy_sats.as_u128() as f64 * 52560.0;
if annual_flow == 0.0 {
(i, StoredF32::from(0.0f32))
} else {
(i, StoredF32::from(
(supply_sats.as_u128() as f64 / annual_flow) as f32,
))
}
},
exit,
)?;
// Dormancy Flow: supply_btc / dormancy
self.dormancy_flow.height.compute_transform2(
starting_indexes.height,
supply_total_sats,
&all_activity.dormancy.height,
|(i, supply_sats, dormancy, ..)| {
let d = f64::from(dormancy);
if d == 0.0 {
(i, StoredF32::from(0.0f32))
} else {
let supply = f64::from(Bitcoin::from(supply_sats));
(i, StoredF32::from((supply / d) as f32))
}
},
exit,
)?;
// Seller Exhaustion Constant: % supply_in_profit × 30d_volatility
self.seller_exhaustion_constant
.height
.compute_transform2(
starting_indexes.height,
&all_metrics.supply.in_profit.sats.height,
&market.volatility._1m.height,
|(i, profit_sats, volatility, ..)| {
let total_sats: Sats = supply_total_sats
.collect_one(i)
.unwrap_or_default();
let total = total_sats.as_u128() as f64;
if total == 0.0 {
(i, StoredF32::from(0.0f32))
} else {
let pct_in_profit = profit_sats.as_u128() as f64 / total;
(i, StoredF32::from(
(pct_in_profit * f64::from(volatility)) as f32,
))
}
},
exit,
)?;
let _lock = exit.lock();
self.db.compact()?;
Ok(())

View File

@@ -32,6 +32,10 @@ impl Vecs {
ComputedPerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?;
let dormancy_supply_adjusted =
ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?;
let stock_to_flow = ComputedPerBlock::forced_import(&db, "stock_to_flow", v, indexes)?;
let dormancy_flow = ComputedPerBlock::forced_import(&db, "dormancy_flow", v, indexes)?;
let seller_exhaustion_constant =
ComputedPerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?;
let this = Self {
db,
@@ -43,6 +47,9 @@ impl Vecs {
coindays_destroyed_supply_adjusted,
coinyears_destroyed_supply_adjusted,
dormancy_supply_adjusted,
stock_to_flow,
dormancy_flow,
seller_exhaustion_constant,
};
finalize_db(&this.db, &this)?;
Ok(this)

View File

@@ -16,4 +16,7 @@ pub struct Vecs<M: StorageMode = Rw> {
pub coindays_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub coinyears_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub dormancy_supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub stock_to_flow: ComputedPerBlock<StoredF32, M>,
pub dormancy_flow: ComputedPerBlock<StoredF32, M>,
pub seller_exhaustion_constant: ComputedPerBlock<StoredF32, M>,
}