global: snapshot

This commit is contained in:
nym21
2026-03-12 14:26:08 +01:00
parent c2135a7066
commit c83955eea7
12 changed files with 65 additions and 28 deletions

View File

@@ -127,6 +127,13 @@ impl AllCohortMetrics {
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
self.asopr.compute_rest_part2(
blocks,
starting_indexes,

View File

@@ -79,6 +79,13 @@ impl BasicCohortMetrics {
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
self.relative.compute(
starting_indexes.height,
&self.supply.core,

View File

@@ -141,6 +141,13 @@ impl CoreCohortMetrics {
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
self.relative.compute(
starting_indexes.height,
&self.supply.core,

View File

@@ -113,6 +113,13 @@ impl ExtendedCohortMetrics {
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
self.relative.compute(
starting_indexes.height,
&self.supply.core,

View File

@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
use crate::{blocks, prices};
use crate::distribution::metrics::{
ImportConfig, OutputsBase, RealizedMinimal, SupplyBase,
ImportConfig, OutputsBase, RealizedMinimal, SupplyBase, UnrealizedMinimal,
};
/// MinimalCohortMetrics: supply, outputs, realized cap/price/mvrv/profit/loss + value_created/destroyed.
@@ -21,6 +21,7 @@ pub struct MinimalCohortMetrics<M: StorageMode = Rw> {
pub supply: Box<SupplyBase<M>>,
pub outputs: Box<OutputsBase<M>>,
pub realized: Box<RealizedMinimal<M>>,
pub unrealized: Box<UnrealizedMinimal<M>>,
}
impl MinimalCohortMetrics {
@@ -30,6 +31,7 @@ impl MinimalCohortMetrics {
supply: Box::new(SupplyBase::forced_import(cfg)?),
outputs: Box::new(OutputsBase::forced_import(cfg)?),
realized: Box::new(RealizedMinimal::forced_import(cfg)?),
unrealized: Box::new(UnrealizedMinimal::forced_import(cfg)?),
})
}
@@ -105,6 +107,13 @@ impl MinimalCohortMetrics {
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
Ok(())
}
}

View File

@@ -78,6 +78,14 @@ impl TypeCohortMetrics {
&self.supply.total.btc.height,
exit,
)?;
self.unrealized.compute(
starting_indexes.height,
&prices.spot.cents.height,
&self.realized.price.cents.height,
exit,
)?;
Ok(())
}
}

View File

@@ -59,7 +59,7 @@ pub use relative::{
RelativeForAll, RelativeToAll, RelativeWithExtended,
};
pub use supply::{SupplyBase, SupplyCore, SupplyFull};
pub use unrealized::{UnrealizedBase, UnrealizedBasic, UnrealizedCore, UnrealizedFull, UnrealizedLike};
pub use unrealized::{UnrealizedBase, UnrealizedBasic, UnrealizedCore, UnrealizedFull, UnrealizedLike, UnrealizedMinimal};
use brk_cohort::Filter;
use brk_error::Result;

View File

@@ -1,7 +1,7 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, Height, Indexes, Sats, StoredF32,
BasisPoints32, Bitcoin, Cents, Height, Indexes, Sats, StoredF32,
Version,
};
use vecdb::{
@@ -13,7 +13,7 @@ use crate::{
distribution::state::{CohortState, CostBasisOps, RealizedOps},
internal::{
FiatPerBlock, FiatPerBlockWithSum24h, Identity, LazyPerBlock,
PerBlockWithSum24h, PriceWithRatioPerBlock, RatioPerBlock,
PerBlockWithSum24h, PriceWithRatioPerBlock,
},
prices,
};
@@ -27,7 +27,7 @@ pub struct RealizedSoprMinimal<M: StorageMode = Rw> {
}
/// Minimal realized metrics: cap (fiat), profit/loss (fiat + 24h sum),
/// price, mvrv, nupl, sopr (value_created/destroyed with 24h sums).
/// price, mvrv, sopr (value_created/destroyed with 24h sums).
#[derive(Traversable)]
pub struct RealizedMinimal<M: StorageMode = Rw> {
pub cap: FiatPerBlock<Cents, M>,
@@ -35,7 +35,6 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
pub loss: FiatPerBlockWithSum24h<Cents, M>,
pub price: PriceWithRatioPerBlock<M>,
pub mvrv: LazyPerBlock<StoredF32>,
pub nupl: RatioPerBlock<BasisPointsSigned32, M>,
pub sopr: RealizedSoprMinimal<M>,
}
@@ -53,15 +52,12 @@ impl RealizedMinimal {
&price.ratio,
);
let nupl = cfg.import("nupl", v1)?;
Ok(Self {
cap,
profit: cfg.import("realized_profit", v1)?,
loss: cfg.import("realized_loss", v1)?,
price,
mvrv,
nupl,
sopr: RealizedSoprMinimal {
value_created: cfg.import("value_created", v1)?,
value_destroyed: cfg.import("value_destroyed", v1)?,
@@ -180,23 +176,6 @@ impl RealizedMinimal {
)?)
})?;
self.nupl.bps.height.compute_transform2(
starting_indexes.height,
&prices.spot.cents.height,
&self.price.cents.height,
|(i, price, realized_price, ..)| {
let p = price.as_u128();
if p == 0 {
(i, BasisPointsSigned32::ZERO)
} else {
let rp = realized_price.as_u128();
let nupl_bps = ((p as i128 - rp as i128) * 10000) / p as i128;
(i, BasisPointsSigned32::from(nupl_bps as i32))
}
},
exit,
)?;
Ok(())
}
}

View File

@@ -1,6 +1,7 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Cents, Height, Indexes, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
@@ -9,9 +10,15 @@ use crate::{
internal::FiatPerBlockWithSum24h,
};
/// Basic unrealized metrics: unrealized profit/loss (fiat + 24h sums).
#[derive(Traversable)]
use super::UnrealizedMinimal;
/// Basic unrealized metrics: nupl + unrealized profit/loss (fiat + 24h sums).
#[derive(Deref, DerefMut, Traversable)]
pub struct UnrealizedBasic<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub minimal: UnrealizedMinimal<M>,
pub profit: FiatPerBlockWithSum24h<Cents, M>,
pub loss: FiatPerBlockWithSum24h<Cents, M>,
}
@@ -21,6 +28,7 @@ impl UnrealizedBasic {
let v1 = Version::ONE;
Ok(Self {
minimal: UnrealizedMinimal::forced_import(cfg)?,
profit: cfg.import("unrealized_profit", v1)?,
loss: cfg.import("unrealized_loss", v1)?,
})

View File

@@ -2,11 +2,13 @@ mod base;
mod basic;
mod core;
mod full;
mod minimal;
pub use self::core::UnrealizedCore;
pub use base::UnrealizedBase;
pub use basic::UnrealizedBasic;
pub use full::UnrealizedFull;
pub use minimal::UnrealizedMinimal;
use brk_error::Result;
use brk_types::{Height, Indexes};

View File

@@ -60,6 +60,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(skip)]
pub states_path: PathBuf,
#[traversable(wrap = "supply", rename = "state")]
pub supply_state: M::Stored<BytesVec<Height, SupplyState>>,
#[traversable(wrap = "addresses", rename = "indexes")]
pub any_address_indexes: AnyAddressIndexesVecs<M>,
@@ -69,6 +70,7 @@ pub struct Vecs<M: StorageMode = Rw> {
pub utxo_cohorts: UTXOCohorts<M>,
#[traversable(wrap = "cohorts", rename = "address")]
pub address_cohorts: AddressCohorts<M>,
#[traversable(wrap = "cointime")]
pub coinblocks_destroyed: ComputedPerBlockCumulative<StoredF64, M>,
pub addresses: AddressMetricsVecs<M>,

View File

@@ -42,6 +42,7 @@ pub struct Computer<M: StorageMode = Rw> {
pub market: Box<market::Vecs<M>>,
pub pools: Box<pools::Vecs<M>>,
pub prices: Box<prices::Vecs<M>>,
#[traversable(flatten)]
pub distribution: Box<distribution::Vecs<M>>,
pub supply: Box<supply::Vecs<M>>,
pub inputs: Box<inputs::Vecs<M>>,