global: snapshot

This commit is contained in:
nym21
2026-03-07 00:25:20 +01:00
parent 9507eb3de5
commit 011e49e1cc
28 changed files with 256 additions and 395 deletions

View File

@@ -16,8 +16,8 @@ pub struct ActivityBase<M: StorageMode = Rw> {
impl ActivityBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
sent: cfg.import_value_cumulative("sent", Version::ZERO)?,
sent_ema: cfg.import_emas_2w("sent", Version::ZERO)?,
sent: cfg.import("sent", Version::ZERO)?,
sent_ema: cfg.import("sent", Version::ZERO)?,
})
}

View File

@@ -26,8 +26,8 @@ impl ActivityFull {
Ok(Self {
base: ActivityBase::forced_import(cfg)?,
coinblocks_destroyed: cfg
.import_cumulative_sum("coinblocks_destroyed", Version::ONE)?,
coindays_destroyed: cfg.import_cumulative_sum("coindays_destroyed", Version::ONE)?,
.import("coinblocks_destroyed", Version::ONE)?,
coindays_destroyed: cfg.import("coindays_destroyed", Version::ONE)?,
})
}

View File

@@ -1,5 +1,5 @@
mod base;
mod full;
pub use base::*;
pub use full::*;
pub use base::ActivityBase;
pub use full::ActivityFull;

View File

@@ -59,8 +59,8 @@ impl AllCohortMetrics {
unrealized: Box::new(unrealized),
adjusted: Box::new(adjusted),
relative: Box::new(relative),
dormancy: cfg.import_computed("dormancy", Version::ONE)?,
velocity: cfg.import_computed("velocity", Version::ONE)?,
dormancy: cfg.import("dormancy", Version::ONE)?,
velocity: cfg.import("velocity", Version::ONE)?,
})
}

View File

@@ -1,13 +1,13 @@
use brk_cohort::Filter;
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Indexes, Sats};
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use brk_types::{Dollars, Height, Indexes, Sats, Version};
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
use crate::{blocks, prices};
use crate::distribution::metrics::{
ActivityFull, CostBasisBase, ImportConfig, OutputsMetrics, RealizedBase,
ActivityFull, CohortMetricsBase, CostBasisBase, ImportConfig, OutputsMetrics, RealizedBase,
RelativeWithRelToAll, SupplyMetrics, UnrealizedFull,
};
@@ -26,7 +26,26 @@ pub struct BasicCohortMetrics<M: StorageMode = Rw> {
pub relative: Box<RelativeWithRelToAll<M>>,
}
impl_cohort_metrics_base!(BasicCohortMetrics, base_cost_basis);
impl CohortMetricsBase for BasicCohortMetrics {
impl_cohort_metrics_base!(@accessors);
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
self.supply.validate_computed_versions(base_version)?;
self.activity.validate_computed_versions(base_version)?;
Ok(())
}
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
vecs.extend(self.supply.collect_vecs_mut());
vecs.extend(self.outputs.collect_vecs_mut());
vecs.extend(self.activity.collect_vecs_mut());
vecs.extend(self.realized.collect_vecs_mut());
vecs.extend(self.cost_basis.collect_vecs_mut());
vecs.extend(self.unrealized.collect_vecs_mut());
vecs
}
}
impl BasicCohortMetrics {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {

View File

@@ -49,8 +49,8 @@ impl ExtendedCohortMetrics {
cost_basis: Box::new(CostBasisWithExtended::forced_import(cfg)?),
unrealized: Box::new(unrealized),
relative: Box::new(relative),
dormancy: cfg.import_computed("dormancy", Version::ONE)?,
velocity: cfg.import_computed("velocity", Version::ONE)?,
dormancy: cfg.import("dormancy", Version::ONE)?,
velocity: cfg.import("velocity", Version::ONE)?,
})
}

View File

@@ -52,8 +52,8 @@ pub struct MinimalCohortMetrics<M: StorageMode = Rw> {
impl MinimalUnrealized {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
supply_in_profit: cfg.import_value("supply_in_profit", Version::ZERO)?,
supply_in_loss: cfg.import_value("supply_in_loss", Version::ZERO)?,
supply_in_profit: cfg.import("supply_in_profit", Version::ZERO)?,
supply_in_loss: cfg.import("supply_in_loss", Version::ZERO)?,
})
}
@@ -117,9 +117,9 @@ impl MinimalRelative {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
supply_in_profit_rel_to_own_supply: cfg
.import_percent_bp16("supply_in_profit_rel_to_own_supply", Version::ONE)?,
.import("supply_in_profit_rel_to_own_supply", Version::ONE)?,
supply_in_loss_rel_to_own_supply: cfg
.import_percent_bp16("supply_in_loss_rel_to_own_supply", Version::ONE)?,
.import("supply_in_loss_rel_to_own_supply", Version::ONE)?,
})
}

View File

@@ -5,9 +5,9 @@ mod extended;
mod extended_adjusted;
mod minimal;
pub use all::*;
pub use basic::*;
pub use core::*;
pub use extended::*;
pub use extended_adjusted::*;
pub use minimal::*;
pub use all::AllCohortMetrics;
pub use basic::BasicCohortMetrics;
pub use core::CoreCohortMetrics;
pub use extended::ExtendedCohortMetrics;
pub use extended_adjusted::ExtendedAdjustedCohortMetrics;
pub use minimal::MinimalCohortMetrics;

View File

@@ -1,6 +1,8 @@
use brk_cohort::Filter;
use brk_error::Result;
use brk_types::{BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, Height, Version};
use brk_types::{
BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, Height, Version,
};
use schemars::JsonSchema;
use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
@@ -15,6 +17,80 @@ use crate::{
},
};
/// Trait for types importable via `ImportConfig::import`.
pub(crate) trait ConfigImport: Sized {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self>;
}
/// Implement `ConfigImport` for types whose `forced_import` takes `(db, name, version, indexes)`.
macro_rules! impl_config_import {
($($type:ty),+ $(,)?) => {
$(
impl ConfigImport for $type {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
)+
};
}
// Non-generic types
impl_config_import!(
ValueFromHeight,
ValueFromHeightCumulative,
ValueFromHeightChange,
ComputedFromHeightRatio,
RollingEmas2w,
PercentFromHeight<BasisPoints16>,
PercentFromHeight<BasisPoints32>,
PercentFromHeight<BasisPointsSigned32>,
PercentRollingWindows<BasisPoints32>,
PercentRollingEmas1w1m<BasisPoints32>,
Price<ComputedFromHeight<Cents>>,
);
// Generic types (macro_rules can't parse generic bounds, so written out)
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeight<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulative<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulativeSum<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindows<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: NumericValue + JsonSchema> ConfigImport for RollingEmas1w1m<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<C: CentsType> ConfigImport for FiatFromHeight<C> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: BytesVecValue> ConfigImport for BytesVec<Height, T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Ok(Self::forced_import(
cfg.db,
&cfg.name(suffix),
cfg.version + offset,
)?)
}
}
#[derive(Clone, Copy)]
pub struct ImportConfig<'a> {
pub db: &'a Database,
@@ -35,228 +111,11 @@ impl<'a> ImportConfig<'a> {
}
}
pub(crate) fn import_computed<T: NumericValue + JsonSchema>(
pub(crate) fn import<T: ConfigImport>(
&self,
suffix: &str,
offset: Version,
) -> Result<ComputedFromHeight<T>> {
ComputedFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_cumulative<T: NumericValue + JsonSchema>(
&self,
suffix: &str,
offset: Version,
) -> Result<ComputedFromHeightCumulative<T>> {
ComputedFromHeightCumulative::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_cumulative_sum<T: NumericValue + JsonSchema>(
&self,
suffix: &str,
offset: Version,
) -> Result<ComputedFromHeightCumulativeSum<T>> {
ComputedFromHeightCumulativeSum::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_percent_bp16(
&self,
suffix: &str,
offset: Version,
) -> Result<PercentFromHeight<BasisPoints16>> {
PercentFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_percent_bps32(
&self,
suffix: &str,
offset: Version,
) -> Result<PercentFromHeight<BasisPointsSigned32>> {
PercentFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_fiat<C: CentsType>(
&self,
suffix: &str,
offset: Version,
) -> Result<FiatFromHeight<C>> {
FiatFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_value(&self, suffix: &str, offset: Version) -> Result<ValueFromHeight> {
ValueFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_value_cumulative(
&self,
suffix: &str,
offset: Version,
) -> Result<ValueFromHeightCumulative> {
ValueFromHeightCumulative::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_value_change(
&self,
suffix: &str,
offset: Version,
) -> Result<ValueFromHeightChange> {
ValueFromHeightChange::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_price(
&self,
suffix: &str,
offset: Version,
) -> Result<Price<ComputedFromHeight<Cents>>> {
Price::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_ratio(
&self,
suffix: &str,
offset: Version,
) -> Result<ComputedFromHeightRatio> {
ComputedFromHeightRatio::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_bytes<T: BytesVecValue>(
&self,
suffix: &str,
offset: Version,
) -> Result<BytesVec<Height, T>> {
Ok(BytesVec::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
)?)
}
pub(crate) fn import_rolling<T: NumericValue + JsonSchema>(
&self,
suffix: &str,
offset: Version,
) -> Result<RollingWindows<T>> {
RollingWindows::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_percent_bp32(
&self,
suffix: &str,
offset: Version,
) -> Result<PercentFromHeight<BasisPoints32>> {
PercentFromHeight::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_percent_rolling_bp32(
&self,
suffix: &str,
offset: Version,
) -> Result<PercentRollingWindows<BasisPoints32>> {
PercentRollingWindows::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_emas_1w_1m<T: NumericValue + JsonSchema>(
&self,
suffix: &str,
offset: Version,
) -> Result<RollingEmas1w1m<T>> {
RollingEmas1w1m::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_percent_emas_1w_1m_bp32(
&self,
suffix: &str,
offset: Version,
) -> Result<PercentRollingEmas1w1m<BasisPoints32>> {
PercentRollingEmas1w1m::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
}
pub(crate) fn import_emas_2w(&self, suffix: &str, offset: Version) -> Result<RollingEmas2w> {
RollingEmas2w::forced_import(
self.db,
&self.name(suffix),
self.version + offset,
self.indexes,
)
) -> Result<T> {
T::config_import(self, suffix, offset)
}
}

View File

@@ -23,8 +23,8 @@ pub struct CostBasisBase<M: StorageMode = Rw> {
impl CostBasisBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
min: cfg.import_price("cost_basis_min", Version::ZERO)?,
max: cfg.import_price("cost_basis_max", Version::ZERO)?,
min: cfg.import("cost_basis_min", Version::ZERO)?,
max: cfg.import("cost_basis_max", Version::ZERO)?,
})
}

View File

@@ -1,9 +1,7 @@
mod base;
mod extended;
mod with_extended;
pub use base::*;
pub use extended::*;
pub use with_extended::*;
pub use base::CostBasisBase;
pub use extended::CostBasisExtended;
pub use with_extended::CostBasisWithExtended;

View File

@@ -13,36 +13,14 @@ mod activity;
/// DRY macro for `CohortMetricsBase` impl on cohort metric types.
///
/// All types share the same 13 accessor methods and common `collect_all_vecs_mut` shape.
/// Two variants handle the cost basis difference:
/// Two variants handle extended cost basis types that need direct field access
/// (bypassing Deref to call methods on concrete `RealizedFull`):
///
/// - `base_cost_basis`: `CostBasisBase` only (no percentiles, no cost_basis version check)
/// - `extended_cost_basis`: `CostBasisWithExtended` (percentiles + cost_basis version check)
/// - `deref_extended_cost_basis`: Deref wrapper delegating to `self.inner` (avoids DerefMut borrow conflicts)
///
/// The `@accessors` helper is also used directly by `BasicCohortMetrics`.
macro_rules! impl_cohort_metrics_base {
($type:ident, base_cost_basis) => {
impl $crate::distribution::metrics::CohortMetricsBase for $type {
impl_cohort_metrics_base!(@accessors);
fn validate_computed_versions(&mut self, base_version: brk_types::Version) -> brk_error::Result<()> {
self.supply.validate_computed_versions(base_version)?;
self.activity.validate_computed_versions(base_version)?;
Ok(())
}
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn vecdb::AnyStoredVec> {
let mut vecs: Vec<&mut dyn vecdb::AnyStoredVec> = Vec::new();
vecs.extend(self.supply.collect_vecs_mut());
vecs.extend(self.outputs.collect_vecs_mut());
vecs.extend(self.activity.collect_vecs_mut());
vecs.extend(self.realized.collect_vecs_mut());
vecs.extend(self.cost_basis.collect_vecs_mut());
vecs.extend(self.unrealized.collect_vecs_mut());
vecs
}
}
};
($type:ident, extended_cost_basis) => {
impl $crate::distribution::metrics::CohortMetricsBase for $type {
impl_cohort_metrics_base!(@accessors);
@@ -280,15 +258,20 @@ mod relative;
mod supply;
mod unrealized;
pub use activity::*;
pub use cohort::*;
pub use config::*;
pub use cost_basis::*;
pub use outputs::*;
pub use realized::*;
pub use relative::*;
pub use supply::*;
pub use unrealized::*;
pub use activity::{ActivityBase, ActivityFull};
pub use cohort::{
AllCohortMetrics, BasicCohortMetrics, CoreCohortMetrics, ExtendedAdjustedCohortMetrics,
ExtendedCohortMetrics, MinimalCohortMetrics,
};
pub use config::ImportConfig;
pub use cost_basis::{CostBasisBase, CostBasisExtended, CostBasisWithExtended};
pub use outputs::OutputsMetrics;
pub use realized::{RealizedAdjusted, RealizedBase, RealizedFull, RealizedMinimal};
pub use relative::{
RelativeBaseWithRelToAll, RelativeForAll, RelativeWithExtended, RelativeWithRelToAll,
};
pub use supply::SupplyMetrics;
pub use unrealized::{UnrealizedBase, UnrealizedFull};
use brk_cohort::Filter;
use brk_error::Result;

View File

@@ -18,8 +18,8 @@ impl OutputsMetrics {
/// Import output metrics from database.
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
utxo_count: cfg.import_computed("utxo_count", Version::ZERO)?,
utxo_count_change_1m: cfg.import_computed("utxo_count_change_1m", Version::ZERO)?,
utxo_count: cfg.import("utxo_count", Version::ZERO)?,
utxo_count_change_1m: cfg.import("utxo_count_change_1m", Version::ZERO)?,
})
}

View File

@@ -25,15 +25,15 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
impl RealizedAdjusted {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(RealizedAdjusted {
adjusted_value_created: cfg.import_computed("adjusted_value_created", Version::ZERO)?,
adjusted_value_created: cfg.import("adjusted_value_created", Version::ZERO)?,
adjusted_value_destroyed: cfg
.import_computed("adjusted_value_destroyed", Version::ZERO)?,
.import("adjusted_value_destroyed", Version::ZERO)?,
adjusted_value_created_sum: cfg
.import_rolling("adjusted_value_created", Version::ONE)?,
.import("adjusted_value_created", Version::ONE)?,
adjusted_value_destroyed_sum: cfg
.import_rolling("adjusted_value_destroyed", Version::ONE)?,
adjusted_sopr: cfg.import_rolling("adjusted_sopr", Version::ONE)?,
adjusted_sopr_ema: cfg.import_emas_1w_1m("adjusted_sopr_24h", Version::ONE)?,
.import("adjusted_value_destroyed", Version::ONE)?,
adjusted_sopr: cfg.import("adjusted_sopr", Version::ONE)?,
adjusted_sopr_ema: cfg.import("adjusted_sopr_24h", Version::ONE)?,
})
}

View File

@@ -76,26 +76,26 @@ impl RealizedBase {
cfg.indexes,
);
let realized_profit_ema_1w = cfg.import_computed("realized_profit_ema_1w", v0)?;
let realized_loss_ema_1w = cfg.import_computed("realized_loss_ema_1w", v0)?;
let realized_profit_ema_1w = cfg.import("realized_profit_ema_1w", v0)?;
let realized_loss_ema_1w = cfg.import("realized_loss_ema_1w", v0)?;
let net_realized_pnl = cfg.import_cumulative("net_realized_pnl", v0)?;
let net_realized_pnl_ema_1w = cfg.import_computed("net_realized_pnl_ema_1w", v0)?;
let gross_pnl = cfg.import_fiat("realized_gross_pnl", v0)?;
let net_realized_pnl = cfg.import("net_realized_pnl", v0)?;
let net_realized_pnl_ema_1w = cfg.import("net_realized_pnl_ema_1w", v0)?;
let gross_pnl = cfg.import("realized_gross_pnl", v0)?;
let realized_profit_rel_to_realized_cap =
cfg.import_percent_bp32("realized_profit_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_profit_rel_to_realized_cap", Version::new(2))?;
let realized_loss_rel_to_realized_cap =
cfg.import_percent_bp32("realized_loss_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_loss_rel_to_realized_cap", Version::new(2))?;
let net_realized_pnl_rel_to_realized_cap =
cfg.import_percent_bps32("net_realized_pnl_rel_to_realized_cap", Version::new(2))?;
cfg.import("net_realized_pnl_rel_to_realized_cap", Version::new(2))?;
let value_created = cfg.import_computed("value_created", v0)?;
let value_destroyed = cfg.import_computed("value_destroyed", v0)?;
let value_created_sum = cfg.import_rolling("value_created", v1)?;
let value_destroyed_sum = cfg.import_rolling("value_destroyed", v1)?;
let sopr = cfg.import_rolling("sopr", v1)?;
let sopr_24h_ema = cfg.import_emas_1w_1m("sopr_24h", v1)?;
let value_created = cfg.import("value_created", v0)?;
let value_destroyed = cfg.import("value_destroyed", v0)?;
let value_created_sum = cfg.import("value_created", v1)?;
let value_destroyed_sum = cfg.import("value_destroyed", v1)?;
let sopr = cfg.import("sopr", v1)?;
let sopr_24h_ema = cfg.import("sopr_24h", v1)?;
let realized_price_ratio_percentiles =
ComputedFromHeightRatioPercentiles::forced_import(
@@ -107,7 +107,7 @@ impl RealizedBase {
Ok(Self {
minimal,
realized_cap_change_1m: cfg.import_computed("realized_cap_change_1m", v0)?,
realized_cap_change_1m: cfg.import("realized_cap_change_1m", v0)?,
neg_realized_loss,
net_realized_pnl,
net_realized_pnl_ema_1w,
@@ -124,10 +124,10 @@ impl RealizedBase {
sopr,
sopr_24h_ema,
realized_price_ratio_percentiles,
sent_in_profit: cfg.import_value_cumulative("sent_in_profit", v0)?,
sent_in_loss: cfg.import_value_cumulative("sent_in_loss", v0)?,
sent_in_profit_ema: cfg.import_emas_2w("sent_in_profit", v0)?,
sent_in_loss_ema: cfg.import_emas_2w("sent_in_loss", v0)?,
sent_in_profit: cfg.import("sent_in_profit", v0)?,
sent_in_loss: cfg.import("sent_in_loss", v0)?,
sent_in_profit_ema: cfg.import("sent_in_profit", v0)?,
sent_in_loss_ema: cfg.import("sent_in_loss", v0)?,
})
}

View File

@@ -82,10 +82,12 @@ impl RealizedFull {
let core = RealizedBase::forced_import(cfg)?;
let profit_value_created = cfg.import_computed("profit_value_created", v0)?;
let profit_value_destroyed = cfg.import_computed("profit_value_destroyed", v0)?;
let loss_value_created = cfg.import_computed("loss_value_created", v0)?;
let loss_value_destroyed = cfg.import_computed("loss_value_destroyed", v0)?;
let profit_value_created = cfg.import("profit_value_created", v0)?;
let profit_value_destroyed: ComputedFromHeight<Cents> =
cfg.import("profit_value_destroyed", v0)?;
let loss_value_created = cfg.import("loss_value_created", v0)?;
let loss_value_destroyed: ComputedFromHeight<Cents> =
cfg.import("loss_value_destroyed", v0)?;
let capitulation_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
&cfg.name("capitulation_flow"),
@@ -100,24 +102,24 @@ impl RealizedFull {
&profit_value_destroyed,
);
let gross_pnl_sum = cfg.import_rolling("gross_pnl_sum", Version::ONE)?;
let gross_pnl_sum = cfg.import("gross_pnl_sum", Version::ONE)?;
let investor_price = cfg.import_price("investor_price", v0)?;
let investor_price_ratio = cfg.import_ratio("investor_price", v0)?;
let lower_price_band = cfg.import_price("lower_price_band", v0)?;
let upper_price_band = cfg.import_price("upper_price_band", v0)?;
let investor_price = cfg.import("investor_price", v0)?;
let investor_price_ratio = cfg.import("investor_price", v0)?;
let lower_price_band = cfg.import("lower_price_band", v0)?;
let upper_price_band = cfg.import("upper_price_band", v0)?;
let cap_raw = cfg.import_bytes("cap_raw", v0)?;
let investor_cap_raw = cfg.import_bytes("investor_cap_raw", v0)?;
let cap_raw = cfg.import("cap_raw", v0)?;
let investor_cap_raw = cfg.import("investor_cap_raw", v0)?;
let sell_side_risk_ratio =
cfg.import_percent_rolling_bp32("sell_side_risk_ratio", Version::new(2))?;
cfg.import("sell_side_risk_ratio", Version::new(2))?;
let sell_side_risk_ratio_24h_ema =
cfg.import_percent_emas_1w_1m_bp32("sell_side_risk_ratio_24h", Version::new(2))?;
cfg.import("sell_side_risk_ratio_24h", Version::new(2))?;
let peak_regret = cfg.import_cumulative("realized_peak_regret", Version::new(2))?;
let peak_regret = cfg.import("realized_peak_regret", Version::new(2))?;
let peak_regret_rel_to_realized_cap =
cfg.import_percent_bp32("realized_peak_regret_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_peak_regret_rel_to_realized_cap", Version::new(2))?;
let realized_price_name = cfg.name("realized_price");
let realized_price_version = cfg.version + v1;
@@ -133,11 +135,11 @@ impl RealizedFull {
capitulation_flow,
profit_flow,
gross_pnl_sum,
net_pnl_change_1m: cfg.import_computed("net_pnl_change_1m", Version::new(3))?,
net_pnl_change_1m: cfg.import("net_pnl_change_1m", Version::new(3))?,
net_pnl_change_1m_rel_to_realized_cap: cfg
.import_percent_bps32("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
.import("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
net_pnl_change_1m_rel_to_market_cap: cfg
.import_percent_bps32("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
.import("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
investor_price,
investor_price_ratio,
lower_price_band,
@@ -149,11 +151,11 @@ impl RealizedFull {
peak_regret,
peak_regret_rel_to_realized_cap,
realized_cap_rel_to_own_market_cap: cfg
.import_percent_bp32("realized_cap_rel_to_own_market_cap", v1)?,
realized_profit_sum: cfg.import_rolling("realized_profit", v1)?,
realized_loss_sum: cfg.import_rolling("realized_loss", v1)?,
.import("realized_cap_rel_to_own_market_cap", v1)?,
realized_profit_sum: cfg.import("realized_profit", v1)?,
realized_loss_sum: cfg.import("realized_loss", v1)?,
realized_profit_to_loss_ratio: cfg
.import_rolling("realized_profit_to_loss_ratio", v1)?,
.import("realized_profit_to_loss_ratio", v1)?,
realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import(
cfg.db,
&realized_price_name,

View File

@@ -29,7 +29,8 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
impl RealizedMinimal {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let realized_cap_cents = cfg.import_computed("realized_cap_cents", Version::ZERO)?;
let realized_cap_cents: ComputedFromHeight<Cents> =
cfg.import("realized_cap_cents", Version::ZERO)?;
let realized_cap = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
&cfg.name("realized_cap"),
cfg.version,
@@ -37,11 +38,12 @@ impl RealizedMinimal {
&realized_cap_cents,
);
let realized_profit = cfg.import_cumulative("realized_profit", Version::ZERO)?;
let realized_loss = cfg.import_cumulative("realized_loss", Version::ZERO)?;
let realized_profit = cfg.import("realized_profit", Version::ZERO)?;
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
let realized_price = cfg.import_price("realized_price", Version::ONE)?;
let realized_price_ratio = cfg.import_ratio("realized_price", Version::ONE)?;
let realized_price = cfg.import("realized_price", Version::ONE)?;
let realized_price_ratio: ComputedFromHeightRatio =
cfg.import("realized_price", Version::ONE)?;
let mvrv = LazyFromHeight::from_lazy::<Identity<StoredF32>, BasisPoints32>(
&cfg.name("mvrv"),
cfg.version,

View File

@@ -3,7 +3,7 @@ mod base;
mod full;
mod minimal;
pub use adjusted::*;
pub use base::*;
pub use full::*;
pub use minimal::*;
pub use adjusted::RealizedAdjusted;
pub use base::RealizedBase;
pub use full::RealizedFull;
pub use minimal::RealizedMinimal;

View File

@@ -30,8 +30,8 @@ impl RelativeBase {
let v1 = Version::ONE;
let v2 = Version::new(2);
let net_unrealized_pnl_rel_to_market_cap =
cfg.import_percent_bps32("net_unrealized_pnl_rel_to_market_cap", Version::new(3))?;
let net_unrealized_pnl_rel_to_market_cap: PercentFromHeight<BasisPointsSigned32> =
cfg.import("net_unrealized_pnl_rel_to_market_cap", Version::new(3))?;
let nupl = LazyFromHeight::from_computed::<Bps32ToFloat>(
&cfg.name("nupl"),
@@ -45,16 +45,16 @@ impl RelativeBase {
Ok(Self {
supply_in_profit_rel_to_own_supply: cfg
.import_percent_bp16("supply_in_profit_rel_to_own_supply", v1)?,
.import("supply_in_profit_rel_to_own_supply", v1)?,
supply_in_loss_rel_to_own_supply: cfg
.import_percent_bp16("supply_in_loss_rel_to_own_supply", v1)?,
.import("supply_in_loss_rel_to_own_supply", v1)?,
unrealized_profit_rel_to_market_cap: cfg
.import_percent_bp16("unrealized_profit_rel_to_market_cap", v2)?,
.import("unrealized_profit_rel_to_market_cap", v2)?,
unrealized_loss_rel_to_market_cap: cfg
.import_percent_bp16("unrealized_loss_rel_to_market_cap", v2)?,
.import("unrealized_loss_rel_to_market_cap", v2)?,
net_unrealized_pnl_rel_to_market_cap,
neg_unrealized_loss_rel_to_market_cap: cfg
.import_percent_bps32("neg_unrealized_loss_rel_to_market_cap", Version::new(3))?,
.import("neg_unrealized_loss_rel_to_market_cap", Version::new(3))?,
nupl,
})
}

View File

@@ -24,13 +24,13 @@ impl RelativeExtendedOwnMarketCap {
Ok(Self {
unrealized_profit_rel_to_own_market_cap: cfg
.import_percent_bp16("unrealized_profit_rel_to_own_market_cap", v2)?,
.import("unrealized_profit_rel_to_own_market_cap", v2)?,
unrealized_loss_rel_to_own_market_cap: cfg
.import_percent_bp32("unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
.import("unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
neg_unrealized_loss_rel_to_own_market_cap: cfg
.import_percent_bps32("neg_unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
.import("neg_unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
net_unrealized_pnl_rel_to_own_market_cap: cfg
.import_percent_bps32("net_unrealized_pnl_rel_to_own_market_cap", Version::new(3))?,
.import("net_unrealized_pnl_rel_to_own_market_cap", Version::new(3))?,
})
}

View File

@@ -24,13 +24,13 @@ impl RelativeExtendedOwnPnl {
Ok(Self {
unrealized_profit_rel_to_own_gross_pnl: cfg
.import_percent_bp16("unrealized_profit_rel_to_own_gross_pnl", v1)?,
.import("unrealized_profit_rel_to_own_gross_pnl", v1)?,
unrealized_loss_rel_to_own_gross_pnl: cfg
.import_percent_bp16("unrealized_loss_rel_to_own_gross_pnl", v1)?,
.import("unrealized_loss_rel_to_own_gross_pnl", v1)?,
neg_unrealized_loss_rel_to_own_gross_pnl: cfg
.import_percent_bps32("neg_unrealized_loss_rel_to_own_gross_pnl", Version::new(2))?,
.import("neg_unrealized_loss_rel_to_own_gross_pnl", Version::new(2))?,
net_unrealized_pnl_rel_to_own_gross_pnl: cfg
.import_percent_bps32("net_unrealized_pnl_rel_to_own_gross_pnl", Version::new(3))?,
.import("net_unrealized_pnl_rel_to_own_gross_pnl", Version::new(3))?,
})
}

View File

@@ -32,11 +32,11 @@ impl RelativeFull {
Ok(Self {
base,
invested_capital_in_profit_rel_to_realized_cap: cfg.import_percent_bp16(
invested_capital_in_profit_rel_to_realized_cap: cfg.import(
"invested_capital_in_profit_rel_to_realized_cap",
Version::ZERO,
)?,
invested_capital_in_loss_rel_to_realized_cap: cfg.import_percent_bp16(
invested_capital_in_loss_rel_to_realized_cap: cfg.import(
"invested_capital_in_loss_rel_to_realized_cap",
Version::ZERO,
)?,

View File

@@ -3,19 +3,17 @@ mod extended_own_market_cap;
mod extended_own_pnl;
mod for_all;
mod full;
mod to_all;
mod with_extended;
mod with_rel_to_all;
mod with_rel_to_all_base;
pub use base::*;
pub use extended_own_market_cap::*;
pub use extended_own_pnl::*;
pub use for_all::*;
pub use full::*;
pub use to_all::*;
pub use with_extended::*;
pub use with_rel_to_all::*;
pub use with_rel_to_all_base::*;
pub use base::RelativeBase;
pub use extended_own_market_cap::RelativeExtendedOwnMarketCap;
pub use extended_own_pnl::RelativeExtendedOwnPnl;
pub use for_all::RelativeForAll;
pub use full::RelativeFull;
pub use to_all::RelativeToAll;
pub use with_extended::RelativeWithExtended;
pub use with_rel_to_all::RelativeWithRelToAll;
pub use with_rel_to_all_base::RelativeBaseWithRelToAll;

View File

@@ -19,11 +19,11 @@ impl RelativeToAll {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
supply_rel_to_circulating_supply: cfg
.import_percent_bp16("supply_rel_to_circulating_supply", Version::ONE)?,
.import("supply_rel_to_circulating_supply", Version::ONE)?,
supply_in_profit_rel_to_circulating_supply: cfg
.import_percent_bp16("supply_in_profit_rel_to_circulating_supply", Version::ONE)?,
.import("supply_in_profit_rel_to_circulating_supply", Version::ONE)?,
supply_in_loss_rel_to_circulating_supply: cfg
.import_percent_bp16("supply_in_loss_rel_to_circulating_supply", Version::ONE)?,
.import("supply_in_loss_rel_to_circulating_supply", Version::ONE)?,
})
}

View File

@@ -24,7 +24,7 @@ pub struct SupplyMetrics<M: StorageMode = Rw> {
impl SupplyMetrics {
/// Import supply metrics from database.
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let supply = cfg.import_value("supply", Version::ZERO)?;
let supply = cfg.import("supply", Version::ZERO)?;
let supply_halved = LazyValueFromHeight::from_block_source::<
HalveSats,
@@ -33,7 +33,7 @@ impl SupplyMetrics {
HalveDollars,
>(&cfg.name("supply_halved"), &supply, cfg.version);
let change_1m = cfg.import_value_change("supply_change_1m", Version::ZERO)?;
let change_1m = cfg.import("supply_change_1m", Version::ZERO)?;
Ok(Self {
total: supply,

View File

@@ -37,11 +37,11 @@ pub struct UnrealizedBase<M: StorageMode = Rw> {
impl UnrealizedBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let v0 = Version::ZERO;
let supply_in_profit = cfg.import_value("supply_in_profit", v0)?;
let supply_in_loss = cfg.import_value("supply_in_loss", v0)?;
let supply_in_profit = cfg.import("supply_in_profit", v0)?;
let supply_in_loss = cfg.import("supply_in_loss", v0)?;
let unrealized_profit = cfg.import_fiat("unrealized_profit", v0)?;
let unrealized_loss = cfg.import_fiat("unrealized_loss", v0)?;
let unrealized_profit = cfg.import("unrealized_profit", v0)?;
let unrealized_loss: FiatFromHeight<Cents> = cfg.import("unrealized_loss", v0)?;
let neg_unrealized_loss = LazyFromHeight::from_computed::<NegCentsUnsignedToDollars>(
&cfg.name("neg_unrealized_loss"),
@@ -50,9 +50,9 @@ impl UnrealizedBase {
&unrealized_loss.cents,
);
let gross_pnl = cfg.import_fiat("unrealized_gross_pnl", v0)?;
let gross_pnl = cfg.import("unrealized_gross_pnl", v0)?;
let net_unrealized_pnl = cfg.import_fiat("net_unrealized_pnl", v0)?;
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", v0)?;
Ok(Self {
supply_in_profit,

View File

@@ -47,18 +47,18 @@ impl UnrealizedFull {
let base = UnrealizedBase::forced_import(cfg)?;
let invested_capital_in_profit = cfg.import_fiat("invested_capital_in_profit", v0)?;
let invested_capital_in_loss = cfg.import_fiat("invested_capital_in_loss", v0)?;
let invested_capital_in_profit = cfg.import("invested_capital_in_profit", v0)?;
let invested_capital_in_loss = cfg.import("invested_capital_in_loss", v0)?;
let invested_capital_in_profit_raw =
cfg.import_bytes("invested_capital_in_profit_raw", v0)?;
let invested_capital_in_loss_raw = cfg.import_bytes("invested_capital_in_loss_raw", v0)?;
let investor_cap_in_profit_raw = cfg.import_bytes("investor_cap_in_profit_raw", v0)?;
let investor_cap_in_loss_raw = cfg.import_bytes("investor_cap_in_loss_raw", v0)?;
cfg.import("invested_capital_in_profit_raw", v0)?;
let invested_capital_in_loss_raw = cfg.import("invested_capital_in_loss_raw", v0)?;
let investor_cap_in_profit_raw = cfg.import("investor_cap_in_profit_raw", v0)?;
let investor_cap_in_loss_raw = cfg.import("investor_cap_in_loss_raw", v0)?;
let pain_index = cfg.import_fiat("pain_index", v0)?;
let greed_index = cfg.import_fiat("greed_index", v0)?;
let net_sentiment = cfg.import_fiat("net_sentiment", Version::ONE)?;
let pain_index = cfg.import("pain_index", v0)?;
let greed_index = cfg.import("greed_index", v0)?;
let net_sentiment = cfg.import("net_sentiment", Version::ONE)?;
Ok(Self {
base,

View File

@@ -1,5 +1,5 @@
mod base;
mod full;
pub use base::*;
pub use full::*;
pub use base::UnrealizedBase;
pub use full::UnrealizedFull;