mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 17:38:09 -07:00
global: snapshot
This commit is contained in:
@@ -44,39 +44,34 @@ impl Vecs {
|
||||
self.velocity
|
||||
.compute(blocks, transactions, distribution, starting_indexes, exit)?;
|
||||
|
||||
// 4. Compute cap growth rates across 4 windows
|
||||
// 4. Compute market cap delta (change + rate across 4 windows)
|
||||
let window_starts = blocks.count.window_starts();
|
||||
|
||||
let realized_cap = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
.metrics
|
||||
.realized
|
||||
.realized_cap
|
||||
.height;
|
||||
self.market_cap_delta.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.market_cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mcgr_arr = self.market_cap_growth_rate.0.as_mut_array();
|
||||
let rcgr_arr = self.realized_cap_growth_rate.0.as_mut_array();
|
||||
// 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();
|
||||
let starts_arr = window_starts.as_array();
|
||||
|
||||
// 24h, 1w, 1y from extended; 1m from core delta
|
||||
let rcr_rates = [
|
||||
&all_realized.realized_cap_delta_extended.rate_24h.bps.height,
|
||||
&all_realized.realized_cap_delta_extended.rate_1w.bps.height,
|
||||
&all_realized.realized_cap_delta.rate_1m.bps.height,
|
||||
&all_realized.realized_cap_delta_extended.rate_1y.bps.height,
|
||||
];
|
||||
|
||||
for i in 0..4 {
|
||||
mcgr_arr[i].bps.height.compute_rolling_ratio_change(
|
||||
starting_indexes.height,
|
||||
*starts_arr[i],
|
||||
&self.market_cap.height,
|
||||
exit,
|
||||
)?;
|
||||
rcgr_arr[i].bps.height.compute_rolling_ratio_change(
|
||||
starting_indexes.height,
|
||||
*starts_arr[i],
|
||||
realized_cap,
|
||||
exit,
|
||||
)?;
|
||||
diff_arr[i].height.compute_subtract(
|
||||
starting_indexes.height,
|
||||
&mcgr_arr[i].bps.height,
|
||||
&rcgr_arr[i].bps.height,
|
||||
&mcr_arr[i].bps.height,
|
||||
rcr_rates[i],
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_types::{Cents, Dollars, Sats, Version};
|
||||
use crate::{
|
||||
distribution, indexes,
|
||||
internal::{
|
||||
Identity, LazyFromHeight, LazyValueFromHeight, PercentFromHeight, PercentRollingWindows,
|
||||
FiatRollingDelta, Identity, LazyFiatFromHeight, LazyValueFromHeight, PercentFromHeight,
|
||||
RollingWindows, SatsToBitcoin, finalize_db, open_db,
|
||||
},
|
||||
};
|
||||
@@ -45,30 +45,22 @@ impl Vecs {
|
||||
// Velocity
|
||||
let velocity = super::velocity::Vecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
// Market cap - lazy identity from distribution supply in USD
|
||||
let market_cap = LazyFromHeight::from_lazy::<Identity<Dollars>, Cents>(
|
||||
"market_cap",
|
||||
version,
|
||||
&supply_metrics.total.usd,
|
||||
);
|
||||
// Market cap - lazy fiat (cents + usd) from distribution supply
|
||||
let market_cap =
|
||||
LazyFiatFromHeight::from_computed("market_cap", version, &supply_metrics.total.cents);
|
||||
|
||||
// Growth rates (4 windows: 24h, 1w, 1m, 1y)
|
||||
let market_cap_growth_rate = PercentRollingWindows::forced_import(
|
||||
// Market cap delta (change + rate across 4 windows)
|
||||
let market_cap_delta = FiatRollingDelta::forced_import(
|
||||
&db,
|
||||
"market_cap_growth_rate",
|
||||
version + Version::TWO,
|
||||
indexes,
|
||||
)?;
|
||||
let realized_cap_growth_rate = PercentRollingWindows::forced_import(
|
||||
&db,
|
||||
"realized_cap_growth_rate",
|
||||
version + Version::TWO,
|
||||
"market_cap_delta",
|
||||
version + Version::new(3),
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let market_minus_realized_cap_growth_rate = RollingWindows::forced_import(
|
||||
&db,
|
||||
"market_minus_realized_cap_growth_rate",
|
||||
version + Version::ONE,
|
||||
version + Version::TWO,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
@@ -79,8 +71,7 @@ impl Vecs {
|
||||
inflation_rate,
|
||||
velocity,
|
||||
market_cap,
|
||||
market_cap_growth_rate,
|
||||
realized_cap_growth_rate,
|
||||
market_cap_delta,
|
||||
market_minus_realized_cap_growth_rate,
|
||||
};
|
||||
finalize_db(&this.db, &this)?;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned32, Dollars};
|
||||
use brk_types::{BasisPointsSigned32, Cents, CentsSigned};
|
||||
use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use super::{burned, velocity};
|
||||
use crate::internal::{
|
||||
LazyFromHeight, LazyValueFromHeight, PercentFromHeight, PercentRollingWindows, RollingWindows,
|
||||
FiatRollingDelta, LazyFiatFromHeight, LazyValueFromHeight, PercentFromHeight, RollingWindows,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -16,8 +16,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub burned: burned::Vecs<M>,
|
||||
pub inflation_rate: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub velocity: velocity::Vecs<M>,
|
||||
pub market_cap: LazyFromHeight<Dollars>,
|
||||
pub market_cap_growth_rate: PercentRollingWindows<BasisPointsSigned32, M>,
|
||||
pub realized_cap_growth_rate: PercentRollingWindows<BasisPointsSigned32, M>,
|
||||
pub market_cap: LazyFiatFromHeight<Cents>,
|
||||
pub market_cap_delta: FiatRollingDelta<Cents, CentsSigned, M>,
|
||||
pub market_minus_realized_cap_growth_rate: RollingWindows<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user