mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Dollars, Indexes};
|
||||
use brk_types::{Bitcoin, Dollars, Indexes, StoredF32};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::{gini, Vecs};
|
||||
@@ -71,6 +71,81 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Thermocap Multiple: market_cap / thermo_cap
|
||||
// thermo_cap = cumulative subsidy in USD
|
||||
self.thermocap_multiple
|
||||
.bps
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
starting_indexes.height,
|
||||
market_cap,
|
||||
&mining.rewards.subsidy.cumulative.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let all_activity = &distribution.utxo_cohorts.all.metrics.activity;
|
||||
let supply_total_sats = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
.metrics
|
||||
.supply
|
||||
.total
|
||||
.sats
|
||||
.height;
|
||||
|
||||
// Supply-Adjusted CDD = sum_24h(CDD) / circulating_supply_btc
|
||||
self.coindays_destroyed_supply_adjusted
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&all_activity.coindays_destroyed.sum._24h.height,
|
||||
supply_total_sats,
|
||||
|(i, cdd_24h, supply_sats, ..)| {
|
||||
let supply = f64::from(Bitcoin::from(supply_sats));
|
||||
if supply == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
(i, StoredF32::from((f64::from(cdd_24h) / supply) as f32))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Supply-Adjusted CYD = CYD / circulating_supply_btc (CYD = 1y rolling sum of CDD)
|
||||
self.coinyears_destroyed_supply_adjusted
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&all_activity.coinyears_destroyed.height,
|
||||
supply_total_sats,
|
||||
|(i, cyd, supply_sats, ..)| {
|
||||
let supply = f64::from(Bitcoin::from(supply_sats));
|
||||
if supply == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
(i, StoredF32::from((f64::from(cyd) / supply) as f32))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Supply-Adjusted Dormancy = dormancy / circulating_supply_btc
|
||||
self.dormancy_supply_adjusted
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&all_activity.dormancy.height,
|
||||
supply_total_sats,
|
||||
|(i, dormancy, supply_sats, ..)| {
|
||||
let supply = f64::from(Bitcoin::from(supply_sats));
|
||||
if supply == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
(i, StoredF32::from((f64::from(dormancy) / supply) as f32))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.db.compact()?;
|
||||
Ok(())
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_types::Version;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{finalize_db, open_db, PercentPerBlock, RatioPerBlock},
|
||||
internal::{finalize_db, open_db, ComputedPerBlock, PercentPerBlock, RatioPerBlock},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::new(1);
|
||||
@@ -24,6 +24,14 @@ impl Vecs {
|
||||
let nvt = RatioPerBlock::forced_import_raw(&db, "nvt", v, indexes)?;
|
||||
let gini = PercentPerBlock::forced_import(&db, "gini", v, indexes)?;
|
||||
let rhodl_ratio = RatioPerBlock::forced_import_raw(&db, "rhodl_ratio", v, indexes)?;
|
||||
let thermocap_multiple =
|
||||
RatioPerBlock::forced_import_raw(&db, "thermocap_multiple", v, indexes)?;
|
||||
let coindays_destroyed_supply_adjusted =
|
||||
ComputedPerBlock::forced_import(&db, "coindays_destroyed_supply_adjusted", v, indexes)?;
|
||||
let coinyears_destroyed_supply_adjusted =
|
||||
ComputedPerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?;
|
||||
let dormancy_supply_adjusted =
|
||||
ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
@@ -31,6 +39,10 @@ impl Vecs {
|
||||
nvt,
|
||||
gini,
|
||||
rhodl_ratio,
|
||||
thermocap_multiple,
|
||||
coindays_destroyed_supply_adjusted,
|
||||
coinyears_destroyed_supply_adjusted,
|
||||
dormancy_supply_adjusted,
|
||||
};
|
||||
finalize_db(&this.db, &this)?;
|
||||
Ok(this)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, BasisPoints32};
|
||||
use brk_types::{BasisPoints16, BasisPoints32, StoredF32};
|
||||
use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PercentPerBlock, RatioPerBlock};
|
||||
use crate::internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
@@ -12,4 +12,8 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub nvt: RatioPerBlock<BasisPoints32, M>,
|
||||
pub gini: PercentPerBlock<BasisPoints16, M>,
|
||||
pub rhodl_ratio: RatioPerBlock<BasisPoints32, M>,
|
||||
pub thermocap_multiple: RatioPerBlock<BasisPoints32, M>,
|
||||
pub coindays_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
pub coinyears_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
pub dormancy_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user