global: snapshot

This commit is contained in:
nym21
2026-03-01 12:46:07 +01:00
parent e10013fd2c
commit 7bf0220f25
35 changed files with 1450 additions and 2044 deletions

View File

@@ -867,6 +867,30 @@ impl RealizedBase {
exit,
)?;
self.lower_price_band.usd.height.compute_transform2(
starting_indexes.height,
&self.realized_price.usd.height,
&self.investor_price.usd.height,
|(i, rp, ip, ..)| {
let rp = f64::from(rp);
let ip = f64::from(ip);
(i, Dollars::from(rp * rp / ip))
},
exit,
)?;
self.upper_price_band.usd.height.compute_transform2(
starting_indexes.height,
&self.investor_price.usd.height,
&self.realized_price.usd.height,
|(i, ip, rp, ..)| {
let ip = f64::from(ip);
let rp = f64::from(rp);
(i, Dollars::from(ip * ip / rp))
},
exit,
)?;
self.realized_cap_30d_delta.height.compute_rolling_change(
starting_indexes.height,
&blocks.count.height_1m_ago,

View File

@@ -1,11 +1,12 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64, Version};
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
use crate::internal::{
ComputedFromHeightLast,
ComputedFromHeightLast, LazyFromHeightLast,
NegPercentageDollarsF32, PercentageDollarsF32, PercentageSatsF64,
StoredF32Identity,
};
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
@@ -24,7 +25,7 @@ pub struct RelativeBase<M: StorageMode = Rw> {
pub unrealized_loss_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
pub neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
pub net_unrealized_pnl_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
pub nupl: ComputedFromHeightLast<StoredF32, M>,
pub nupl: LazyFromHeightLast<StoredF32, StoredF32>,
// === Invested Capital in Profit/Loss as % of Realized Cap ===
pub invested_capital_in_profit_pct: ComputedFromHeightLast<StoredF32, M>,
@@ -36,6 +37,17 @@ impl RelativeBase {
let v1 = Version::ONE;
let v2 = Version::new(2);
let net_unrealized_pnl_rel_to_market_cap = ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("net_unrealized_pnl_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
)?;
let nupl = LazyFromHeightLast::from_computed::<StoredF32Identity>(
&cfg.name("nupl"),
cfg.version + v2,
net_unrealized_pnl_rel_to_market_cap.height.read_only_boxed_clone(),
&net_unrealized_pnl_rel_to_market_cap,
);
Ok(Self {
supply_in_profit_rel_to_own_supply: ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("supply_in_profit_rel_to_own_supply"), cfg.version + v1, cfg.indexes,
@@ -52,12 +64,8 @@ impl RelativeBase {
neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("neg_unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
)?,
net_unrealized_pnl_rel_to_market_cap: ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("net_unrealized_pnl_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
)?,
nupl: ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("nupl"), cfg.version + v2, cfg.indexes,
)?,
net_unrealized_pnl_rel_to_market_cap,
nupl,
invested_capital_in_profit_pct: ComputedFromHeightLast::forced_import(
cfg.db, &cfg.name("invested_capital_in_profit_pct"), cfg.version, cfg.indexes,
)?,
@@ -100,10 +108,6 @@ impl RelativeBase {
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
max_from, &unrealized.net_unrealized_pnl.height, market_cap, exit,
)?;
self.nupl
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
max_from, &unrealized.net_unrealized_pnl.height, market_cap, exit,
)?;
self.invested_capital_in_profit_pct
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
max_from, &unrealized.invested_capital_in_profit.height, &realized.realized_cap.height, exit,