diff --git a/crates/brk_computer/src/distribution/metrics/activity/base.rs b/crates/brk_computer/src/distribution/metrics/activity/base.rs index 07a60d29b..6a1ea67d3 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/base.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/base.rs @@ -16,8 +16,8 @@ pub struct ActivityBase { impl ActivityBase { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/activity/full.rs b/crates/brk_computer/src/distribution/metrics/activity/full.rs index 519c6c953..db58e09c3 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/full.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/full.rs @@ -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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/activity/mod.rs b/crates/brk_computer/src/distribution/metrics/activity/mod.rs index 17a3cd90b..10f131f7f 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/mod.rs @@ -1,5 +1,5 @@ mod base; mod full; -pub use base::*; -pub use full::*; +pub use base::ActivityBase; +pub use full::ActivityFull; diff --git a/crates/brk_computer/src/distribution/metrics/cohort/all.rs b/crates/brk_computer/src/distribution/metrics/cohort/all.rs index 2b6aa5d67..8898526b1 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/all.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/all.rs @@ -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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/cohort/basic.rs b/crates/brk_computer/src/distribution/metrics/cohort/basic.rs index 86ac19b67..5bb468575 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/basic.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/basic.rs @@ -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 { pub relative: Box>, } -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 { diff --git a/crates/brk_computer/src/distribution/metrics/cohort/extended.rs b/crates/brk_computer/src/distribution/metrics/cohort/extended.rs index a7833dd3b..56e2cd63e 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/extended.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/extended.rs @@ -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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/cohort/minimal.rs b/crates/brk_computer/src/distribution/metrics/cohort/minimal.rs index a00abff5c..e86ff91e5 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/minimal.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/minimal.rs @@ -52,8 +52,8 @@ pub struct MinimalCohortMetrics { impl MinimalUnrealized { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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 { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/cohort/mod.rs b/crates/brk_computer/src/distribution/metrics/cohort/mod.rs index e2f6eaf67..55c950bc6 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/mod.rs @@ -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; diff --git a/crates/brk_computer/src/distribution/metrics/config.rs b/crates/brk_computer/src/distribution/metrics/config.rs index b420979f7..f1bf371ef 100644 --- a/crates/brk_computer/src/distribution/metrics/config.rs +++ b/crates/brk_computer/src/distribution/metrics/config.rs @@ -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; +} + +/// 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::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } + } + )+ + }; +} + +// Non-generic types +impl_config_import!( + ValueFromHeight, + ValueFromHeightCumulative, + ValueFromHeightChange, + ComputedFromHeightRatio, + RollingEmas2w, + PercentFromHeight, + PercentFromHeight, + PercentFromHeight, + PercentRollingWindows, + PercentRollingEmas1w1m, + Price>, +); + +// Generic types (macro_rules can't parse generic bounds, so written out) +impl ConfigImport for ComputedFromHeight { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for ComputedFromHeightCumulative { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for ComputedFromHeightCumulativeSum { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for RollingWindows { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for RollingEmas1w1m { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for FiatFromHeight { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) + } +} +impl ConfigImport for BytesVec { + fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { + 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( + pub(crate) fn import( &self, suffix: &str, offset: Version, - ) -> Result> { - ComputedFromHeight::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_cumulative( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - ComputedFromHeightCumulative::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_cumulative_sum( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - 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::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::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_fiat( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - 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::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::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::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_price( - &self, - suffix: &str, - offset: Version, - ) -> Result>> { - 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::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_bytes( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - Ok(BytesVec::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - )?) - } - - pub(crate) fn import_rolling( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - 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::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::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) - } - - pub(crate) fn import_emas_1w_1m( - &self, - suffix: &str, - offset: Version, - ) -> Result> { - 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::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::forced_import( - self.db, - &self.name(suffix), - self.version + offset, - self.indexes, - ) + ) -> Result { + T::config_import(self, suffix, offset) } } diff --git a/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs b/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs index 42a9bcd63..adaace583 100644 --- a/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs +++ b/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs @@ -23,8 +23,8 @@ pub struct CostBasisBase { impl CostBasisBase { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs b/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs index 79ae3654e..1434bda00 100644 --- a/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs @@ -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; diff --git a/crates/brk_computer/src/distribution/metrics/mod.rs b/crates/brk_computer/src/distribution/metrics/mod.rs index bb5c770c0..5f4a1280a 100644 --- a/crates/brk_computer/src/distribution/metrics/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/mod.rs @@ -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; diff --git a/crates/brk_computer/src/distribution/metrics/outputs.rs b/crates/brk_computer/src/distribution/metrics/outputs.rs index 028b7f5ec..8c4fe809d 100644 --- a/crates/brk_computer/src/distribution/metrics/outputs.rs +++ b/crates/brk_computer/src/distribution/metrics/outputs.rs @@ -18,8 +18,8 @@ impl OutputsMetrics { /// Import output metrics from database. pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs index 5d15c8140..2a9ae8ae8 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs @@ -25,15 +25,15 @@ pub struct RealizedAdjusted { impl RealizedAdjusted { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/realized/base.rs b/crates/brk_computer/src/distribution/metrics/realized/base.rs index 937b76ec0..5a7a5fe48 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/base.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/base.rs @@ -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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/realized/full.rs b/crates/brk_computer/src/distribution/metrics/realized/full.rs index 5cfe679a8..c302d64a0 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/full.rs @@ -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 = + cfg.import("profit_value_destroyed", v0)?; + let loss_value_created = cfg.import("loss_value_created", v0)?; + let loss_value_destroyed: ComputedFromHeight = + cfg.import("loss_value_destroyed", v0)?; let capitulation_flow = LazyFromHeight::from_computed::( &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, diff --git a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs index 2f2fb8418..78dcb7fd1 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs @@ -29,7 +29,8 @@ pub struct RealizedMinimal { impl RealizedMinimal { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { - let realized_cap_cents = cfg.import_computed("realized_cap_cents", Version::ZERO)?; + let realized_cap_cents: ComputedFromHeight = + cfg.import("realized_cap_cents", Version::ZERO)?; let realized_cap = LazyFromHeight::from_computed::( &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::, BasisPoints32>( &cfg.name("mvrv"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/realized/mod.rs b/crates/brk_computer/src/distribution/metrics/realized/mod.rs index cfb332d9d..80db494ae 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/mod.rs @@ -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; diff --git a/crates/brk_computer/src/distribution/metrics/relative/base.rs b/crates/brk_computer/src/distribution/metrics/relative/base.rs index 200a27235..2015d5e4d 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/base.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/base.rs @@ -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 = + cfg.import("net_unrealized_pnl_rel_to_market_cap", Version::new(3))?; let nupl = LazyFromHeight::from_computed::( &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, }) } diff --git a/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs b/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs index 42692ff9a..4994d8cb1 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs @@ -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))?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs b/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs index 39277599c..26dce8054 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs @@ -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))?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/relative/full.rs b/crates/brk_computer/src/distribution/metrics/relative/full.rs index 76262d8ae..62adc02b2 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/full.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/full.rs @@ -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, )?, diff --git a/crates/brk_computer/src/distribution/metrics/relative/mod.rs b/crates/brk_computer/src/distribution/metrics/relative/mod.rs index ab1c022ea..2e57889ba 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/mod.rs @@ -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; diff --git a/crates/brk_computer/src/distribution/metrics/relative/to_all.rs b/crates/brk_computer/src/distribution/metrics/relative/to_all.rs index 0bbce8c45..c4116c2e6 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/to_all.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/to_all.rs @@ -19,11 +19,11 @@ impl RelativeToAll { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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)?, }) } diff --git a/crates/brk_computer/src/distribution/metrics/supply.rs b/crates/brk_computer/src/distribution/metrics/supply.rs index f42cdd1e9..48c23220f 100644 --- a/crates/brk_computer/src/distribution/metrics/supply.rs +++ b/crates/brk_computer/src/distribution/metrics/supply.rs @@ -24,7 +24,7 @@ pub struct SupplyMetrics { impl SupplyMetrics { /// Import supply metrics from database. pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { - 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, diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/base.rs b/crates/brk_computer/src/distribution/metrics/unrealized/base.rs index caad9be02..1faf752e5 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/base.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/base.rs @@ -37,11 +37,11 @@ pub struct UnrealizedBase { impl UnrealizedBase { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { 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 = cfg.import("unrealized_loss", v0)?; let neg_unrealized_loss = LazyFromHeight::from_computed::( &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, diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs index 3732a861f..c8264aba6 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs @@ -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, diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/mod.rs b/crates/brk_computer/src/distribution/metrics/unrealized/mod.rs index 17a3cd90b..fef954c35 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/mod.rs @@ -1,5 +1,5 @@ mod base; mod full; -pub use base::*; -pub use full::*; +pub use base::UnrealizedBase; +pub use full::UnrealizedFull;