global: snapshot

This commit is contained in:
nym21
2026-03-10 10:49:17 +01:00
parent 46ac55d950
commit 64ef63a056
25 changed files with 1088 additions and 1133 deletions
@@ -14,7 +14,7 @@ impl Vecs {
activity: &activity::Vecs,
exit: &Exit,
) -> Result<()> {
self.adj_inflation_rate.bps.height.compute_transform2(
self.inflation_rate.bps.height.compute_transform2(
starting_indexes.height,
&activity.liveliness.height,
&supply.inflation_rate.bps.height,
@@ -27,14 +27,14 @@ impl Vecs {
exit,
)?;
self.adj_tx_velocity_btc.height.compute_multiply(
self.tx_velocity_btc.height.compute_multiply(
starting_indexes.height,
&activity.activity_to_vaultedness_ratio.height,
&supply.velocity.btc.height,
exit,
)?;
self.adj_tx_velocity_usd.height.compute_multiply(
self.tx_velocity_usd.height.compute_multiply(
starting_indexes.height,
&activity.activity_to_vaultedness_ratio.height,
&supply.velocity.usd.height,
@@ -15,19 +15,19 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
adj_inflation_rate: PercentPerBlock::forced_import(
inflation_rate: PercentPerBlock::forced_import(
db,
"cointime_adj_inflation_rate",
version,
indexes,
)?,
adj_tx_velocity_btc: ComputedPerBlock::forced_import(
tx_velocity_btc: ComputedPerBlock::forced_import(
db,
"cointime_adj_tx_velocity_btc",
version,
indexes,
)?,
adj_tx_velocity_usd: ComputedPerBlock::forced_import(
tx_velocity_usd: ComputedPerBlock::forced_import(
db,
"cointime_adj_tx_velocity_usd",
version,
@@ -6,7 +6,7 @@ use crate::internal::{ComputedPerBlock, PercentPerBlock};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub adj_inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
pub adj_tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
pub adj_tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
pub tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
pub tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
}
@@ -29,7 +29,7 @@ impl Vecs {
exit,
)?;
self.reserve_risk.height.compute_divide(
self.value.height.compute_divide(
starting_indexes.height,
&prices.price.usd.height,
&self.hodl_bank,
@@ -15,7 +15,7 @@ impl Vecs {
Ok(Self {
vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?,
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
reserve_risk: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
value: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
})
}
}
@@ -6,7 +6,7 @@ use crate::internal::ComputedPerBlock;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub value: ComputedPerBlock<StoredF64, M>,
pub vocdd_median_1y: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
pub reserve_risk: ComputedPerBlock<StoredF64, M>,
}
@@ -32,6 +32,7 @@ pub struct AllCohortMetrics<M: StorageMode = Rw> {
pub unrealized: Box<UnrealizedFull<M>>,
#[traversable(wrap = "realized/sopr", rename = "adjusted")]
pub asopr: Box<AdjustedSopr<M>>,
#[traversable(flatten)]
pub relative: Box<RelativeForAll<M>>,
#[traversable(wrap = "supply", rename = "delta")]
@@ -22,6 +22,7 @@ pub struct BasicCohortMetrics<M: StorageMode = Rw> {
pub activity: Box<ActivityCore<M>>,
pub realized: Box<RealizedCore<M>>,
pub unrealized: Box<UnrealizedBase<M>>,
#[traversable(flatten)]
pub relative: Box<RelativeToAll<M>>,
}
@@ -20,6 +20,7 @@ pub struct CoreCohortMetrics<M: StorageMode = Rw> {
pub activity: Box<ActivityCore<M>>,
pub realized: Box<RealizedCore<M>>,
pub unrealized: Box<UnrealizedCore<M>>,
#[traversable(flatten)]
pub relative: Box<RelativeToAll<M>>,
}
@@ -28,6 +28,7 @@ pub struct ExtendedCohortMetrics<M: StorageMode = Rw> {
pub realized: Box<RealizedFull<M>>,
pub cost_basis: Box<CostBasis<M>>,
pub unrealized: Box<UnrealizedFull<M>>,
#[traversable(flatten)]
pub relative: Box<RelativeWithExtended<M>>,
#[traversable(wrap = "supply", rename = "delta")]
@@ -14,7 +14,9 @@ use crate::distribution::metrics::ImportConfig;
pub struct AdjustedSopr<M: StorageMode = Rw> {
pub value_created: ComputedPerBlock<Cents, M>,
pub value_destroyed: ComputedPerBlock<Cents, M>,
#[traversable(wrap = "value_created", rename = "sum")]
pub value_created_sum: RollingWindows<Cents, M>,
#[traversable(wrap = "value_destroyed", rename = "sum")]
pub value_destroyed_sum: RollingWindows<Cents, M>,
pub ratio: RollingWindows<StoredF64, M>,
}
@@ -47,7 +47,7 @@ pub struct RealizedCore<M: StorageMode = Rw> {
#[traversable(wrap = "cap", rename = "delta")]
pub cap_delta: FiatRollingDelta1m<Cents, CentsSigned, M>,
#[traversable(wrap = "loss", rename = "neg")]
#[traversable(wrap = "loss", rename = "negative")]
pub neg_loss: LazyPerBlock<Dollars, Cents>,
pub net_pnl: PerBlockWithSum24h<CentsSigned, M>,
pub sopr: RealizedSoprCore<M>,
@@ -32,9 +32,11 @@ pub struct RealizedProfit<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlock<Cents, M>,
pub value_destroyed: ComputedPerBlock<Cents, M>,
#[traversable(wrap = "value_created", rename = "sum")]
pub value_created_sum: RollingWindows<Cents, M>,
#[traversable(wrap = "value_destroyed", rename = "sum")]
pub value_destroyed_sum: RollingWindows<Cents, M>,
pub flow: LazyPerBlock<Dollars, Cents>,
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
#[traversable(rename = "sum")]
pub sum_extended: RollingWindowsFrom1w<Cents, M>,
}
@@ -44,7 +46,9 @@ pub struct RealizedLoss<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlock<Cents, M>,
pub value_destroyed: ComputedPerBlock<Cents, M>,
#[traversable(wrap = "value_created", rename = "sum")]
pub value_created_sum: RollingWindows<Cents, M>,
#[traversable(wrap = "value_destroyed", rename = "sum")]
pub value_destroyed_sum: RollingWindows<Cents, M>,
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
#[traversable(rename = "sum")]
@@ -53,8 +57,7 @@ pub struct RealizedLoss<M: StorageMode = Rw> {
#[derive(Traversable)]
pub struct RealizedGrossPnl<M: StorageMode = Rw> {
#[traversable(flatten)]
pub value: FiatPerBlock<Cents, M>,
pub raw: FiatPerBlock<Cents, M>,
pub sum: RollingWindows<Cents, M>,
pub sell_side_risk_ratio: PercentRollingWindows<BasisPoints32, M>,
}
@@ -68,15 +71,17 @@ pub struct RealizedNetPnl<M: StorageMode = Rw> {
pub delta: FiatRollingDelta1m<CentsSigned, CentsSigned, M>,
#[traversable(rename = "delta")]
pub delta_extended: FiatRollingDeltaExcept1m<CentsSigned, CentsSigned, M>,
#[traversable(wrap = "change_1m", rename = "rel_to_rcap")]
pub change_1m_rel_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
#[traversable(wrap = "change_1m", rename = "rel_to_mcap")]
pub change_1m_rel_to_mcap: PercentPerBlock<BasisPointsSigned32, M>,
}
#[derive(Traversable)]
pub struct RealizedSopr<M: StorageMode = Rw> {
#[traversable(rename = "value_created_sum")]
#[traversable(wrap = "value_created", rename = "sum")]
pub value_created_sum_extended: RollingWindowsFrom1w<Cents, M>,
#[traversable(rename = "value_destroyed_sum")]
#[traversable(wrap = "value_destroyed", rename = "sum")]
pub value_destroyed_sum_extended: RollingWindowsFrom1w<Cents, M>,
#[traversable(rename = "ratio")]
pub ratio_extended: RollingWindowsFrom1w<StoredF64, M>,
@@ -103,6 +108,7 @@ pub struct RealizedInvestor<M: StorageMode = Rw> {
pub price_ratio: RatioPerBlock<BasisPoints32, M>,
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
#[traversable(wrap = "cap", rename = "raw")]
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
pub price_ratio_percentiles: RatioPerBlockPercentiles<M>,
}
@@ -161,7 +167,7 @@ impl RealizedFull {
value_destroyed: profit_value_destroyed,
value_created_sum: cfg.import("profit_value_created", v1)?,
value_destroyed_sum: cfg.import("profit_value_destroyed", v1)?,
flow: profit_flow,
distribution_flow: profit_flow,
sum_extended: cfg.import("realized_profit", v1)?,
};
@@ -186,7 +192,7 @@ impl RealizedFull {
// Gross PnL
let gross_pnl = RealizedGrossPnl {
value: cfg.import("realized_gross_pnl", v0)?,
raw: cfg.import("realized_gross_pnl", v0)?,
sum: cfg.import("gross_pnl_sum", v1)?,
sell_side_risk_ratio: cfg.import("sell_side_risk_ratio", Version::new(2))?,
};
@@ -546,7 +552,7 @@ impl RealizedFull {
)?;
// Gross PnL
self.gross_pnl.value.cents.height.compute_add(
self.gross_pnl.raw.cents.height.compute_add(
starting_indexes.height,
&self.core.minimal.profit.raw.cents.height,
&self.core.minimal.loss.raw.cents.height,
@@ -556,7 +562,7 @@ impl RealizedFull {
self.gross_pnl.sum.compute_rolling_sum(
starting_indexes.height,
&window_starts,
&self.gross_pnl.value.cents.height,
&self.gross_pnl.raw.cents.height,
exit,
)?;
@@ -16,6 +16,7 @@ pub struct RelativeExtendedOwnPnl<M: StorageMode = Rw> {
pub unrealized_loss_rel_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "unrealized/net_pnl", rename = "rel_to_own_gross_pnl")]
pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentPerBlock<BasisPointsSigned32, M>,
}
impl RelativeExtendedOwnPnl {
@@ -11,9 +11,9 @@ use crate::{
/// Full relative metrics (sth/lth/all tier).
#[derive(Traversable)]
pub struct RelativeFull<M: StorageMode = Rw> {
#[traversable(wrap = "supply/in_profit", rename = "rel_to_own_supply")]
#[traversable(wrap = "unrealized/profit/supply", rename = "rel_to_own_supply")]
pub supply_in_profit_rel_to_own_supply: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "supply/in_loss", rename = "rel_to_own_supply")]
#[traversable(wrap = "unrealized/loss/supply", rename = "rel_to_own_supply")]
pub supply_in_loss_rel_to_own_supply: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "unrealized/profit", rename = "rel_to_market_cap")]
@@ -12,9 +12,9 @@ use crate::distribution::metrics::ImportConfig;
pub struct RelativeToAll<M: StorageMode = Rw> {
#[traversable(wrap = "supply", rename = "rel_to_circulating_supply")]
pub supply_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "supply/in_profit", rename = "rel_to_circulating_supply")]
#[traversable(wrap = "unrealized/profit/supply", rename = "rel_to_circulating_supply")]
pub supply_in_profit_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "supply/in_loss", rename = "rel_to_circulating_supply")]
#[traversable(wrap = "unrealized/loss/supply", rename = "rel_to_circulating_supply")]
pub supply_in_loss_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
}
@@ -25,7 +25,7 @@ pub struct UnrealizedCore<M: StorageMode = Rw> {
#[traversable(flatten)]
pub basic: UnrealizedBasic<M>,
#[traversable(wrap = "loss", rename = "neg")]
#[traversable(wrap = "loss", rename = "negative")]
pub neg_loss: LazyPerBlock<Dollars, Cents>,
pub net_pnl: FiatPerBlock<CentsSigned, M>,
}
@@ -8,7 +8,6 @@ use crate::internal::{AmountPerBlock, RollingWindow24hAmountPerBlock};
/// Amount per-block value (sats + cents) with 24h rolling sum (also amount).
#[derive(Traversable)]
pub struct AmountPerBlockWithSum24h<M: StorageMode = Rw> {
#[traversable(flatten)]
pub raw: AmountPerBlock<M>,
pub sum: RollingWindow24hAmountPerBlock<M>,
}
@@ -53,7 +53,6 @@ impl<C: CentsType> RollingWindow24hFiatPerBlock<C> {
/// Fiat per-block value (cents + usd) with 24h rolling sum (also fiat).
#[derive(Traversable)]
pub struct FiatPerBlockWithSum24h<C: CentsType, M: StorageMode = Rw> {
#[traversable(flatten)]
pub raw: FiatPerBlock<C, M>,
pub sum: RollingWindow24hFiatPerBlock<C, M>,
}
@@ -104,6 +104,32 @@ impl Vecs {
// Gini (per height)
gini::compute(&mut self.gini, distribution, starting_indexes, exit)?;
// RHODL Ratio: 1d-1w realized cap / 1y-2y realized cap
self.rhodl_ratio
.bps
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
starting_indexes.height,
&distribution
.utxo_cohorts
.age_range
._1d_to_1w
.metrics
.realized
.cap
.usd
.height,
&distribution
.utxo_cohorts
.age_range
._1y_to_2y
.metrics
.realized
.cap
.usd
.height,
exit,
)?;
// NVT: market_cap / tx_volume_24h
let market_cap = &distribution
.utxo_cohorts
@@ -8,7 +8,7 @@ use crate::{
internal::{ComputedPerBlock, RatioPerBlock, PercentPerBlock, Windows},
};
const VERSION: Version = Version::ONE;
const VERSION: Version = Version::new(2);
impl RsiChain {
fn forced_import(
@@ -117,6 +117,8 @@ impl Vecs {
let pi_cycle = RatioPerBlock::forced_import_raw(db, "pi_cycle", v, indexes)?;
let rhodl_ratio = RatioPerBlock::forced_import_raw(db, "rhodl_ratio", v, indexes)?;
Ok(Self {
puell_multiple: RatioPerBlock::forced_import_raw(
db,
@@ -131,6 +133,7 @@ impl Vecs {
pi_cycle,
macd,
gini,
rhodl_ratio,
})
}
}
@@ -42,4 +42,6 @@ pub struct Vecs<M: StorageMode = Rw> {
pub macd: Windows<MacdChain<M>>,
pub gini: PercentPerBlock<BasisPoints16, M>,
pub rhodl_ratio: RatioPerBlock<BasisPoints32, M>,
}