global: refactor

This commit is contained in:
nym21
2026-04-22 22:23:39 +02:00
parent c5b16e7048
commit 84e924b77e
63 changed files with 726 additions and 257 deletions

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::AmountPerBlock};
use crate::{indexes, internal::ValuePerBlock};
impl Vecs {
pub(crate) fn forced_import(
@@ -12,8 +12,8 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
vaulted: AmountPerBlock::forced_import(db, "vaulted_supply", version, indexes)?,
active: AmountPerBlock::forced_import(db, "active_supply", version, indexes)?,
vaulted: ValuePerBlock::forced_import(db, "vaulted_supply", version, indexes)?,
active: ValuePerBlock::forced_import(db, "active_supply", version, indexes)?,
})
}
}

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlock;
use crate::internal::ValuePerBlock;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub vaulted: AmountPerBlock<M>,
pub active: AmountPerBlock<M>,
pub vaulted: ValuePerBlock<M>,
pub active: ValuePerBlock<M>,
}

View File

@@ -3,7 +3,7 @@ use brk_types::{Height, Sats};
use derive_more::{Deref, DerefMut};
use vecdb::ReadableVec;
use crate::internal::AmountPerBlock;
use crate::internal::ValuePerBlock;
use super::vecs::ExposedAddrSupplyVecs;
@@ -24,7 +24,7 @@ impl From<(&ExposedAddrSupplyVecs, Height)> for AddrTypeToExposedSupply {
fn from((vecs, starting_height): (&ExposedAddrSupplyVecs, Height)) -> Self {
if let Some(prev_height) = starting_height.decremented() {
let read =
|v: &AmountPerBlock| -> Sats { v.sats.height.collect_one(prev_height).unwrap() };
|v: &ValuePerBlock| -> Sats { v.sats.height.collect_one(prev_height).unwrap() };
Self(ByAddrType {
p2pk65: read(&vecs.by_addr_type.p2pk65),
p2pk33: read(&vecs.by_addr_type.p2pk33),

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, Rw, StorageMode};
use crate::{
indexes,
internal::{AmountPerBlock, WithAddrTypes},
internal::{ValuePerBlock, WithAddrTypes},
};
/// Exposed address supply (sats/btc/cents/usd) — `all` + per-address-type.
@@ -15,7 +15,7 @@ use crate::{
/// post-hoc from sats × spot price.
#[derive(Deref, DerefMut, Traversable)]
pub struct ExposedAddrSupplyVecs<M: StorageMode = Rw>(
#[traversable(flatten)] pub WithAddrTypes<AmountPerBlock<M>>,
#[traversable(flatten)] pub WithAddrTypes<ValuePerBlock<M>>,
);
impl ExposedAddrSupplyVecs {
@@ -24,7 +24,7 @@ impl ExposedAddrSupplyVecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self(WithAddrTypes::<AmountPerBlock>::forced_import(
Ok(Self(WithAddrTypes::<ValuePerBlock>::forced_import(
db,
"exposed_supply",
version,

View File

@@ -25,7 +25,7 @@ use crate::{
state::UTXOCohortState,
},
indexes,
internal::{AmountPerBlockCumulativeRolling, WindowStartVec, Windows},
internal::{ValuePerBlockCumulativeRolling, WindowStartVec, Windows},
prices,
};
@@ -50,7 +50,7 @@ pub struct UTXOCohorts<M: StorageMode = Rw> {
#[traversable(rename = "type")]
pub type_: SpendableType<UTXOCohortVecs<TypeCohortMetrics<M>>>,
pub profitability: ProfitabilityMetrics<M>,
pub matured: AgeRange<AmountPerBlockCumulativeRolling<M>>,
pub matured: AgeRange<ValuePerBlockCumulativeRolling<M>>,
#[traversable(skip)]
pub(super) caches: UTXOCohortsTransientState,
}
@@ -264,8 +264,8 @@ impl UTXOCohorts<Rw> {
let prefix = CohortContext::Utxo.prefix();
let matured = AgeRange::try_new(&|_f: Filter,
name: &'static str|
-> Result<AmountPerBlockCumulativeRolling> {
AmountPerBlockCumulativeRolling::forced_import(
-> Result<ValuePerBlockCumulativeRolling> {
ValuePerBlockCumulativeRolling::forced_import(
db,
&format!("{prefix}_{name}_matured_supply"),
v,

View File

@@ -9,7 +9,7 @@ use crate::{
metrics::ImportConfig,
state::{CohortState, CostBasisOps, RealizedOps},
},
internal::{AmountPerBlockCumulativeRolling, PerBlockCumulativeRolling},
internal::{ValuePerBlockCumulativeRolling, PerBlockCumulativeRolling},
prices,
};
@@ -24,9 +24,9 @@ pub struct ActivityCore<M: StorageMode = Rw> {
pub coindays_destroyed: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
#[traversable(wrap = "transfer_volume", rename = "in_profit")]
pub transfer_volume_in_profit: AmountPerBlockCumulativeRolling<M>,
pub transfer_volume_in_profit: ValuePerBlockCumulativeRolling<M>,
#[traversable(wrap = "transfer_volume", rename = "in_loss")]
pub transfer_volume_in_loss: AmountPerBlockCumulativeRolling<M>,
pub transfer_volume_in_loss: ValuePerBlockCumulativeRolling<M>,
}
impl ActivityCore {

View File

@@ -8,13 +8,13 @@ use crate::{
metrics::ImportConfig,
state::{CohortState, CostBasisOps, RealizedOps},
},
internal::AmountPerBlockCumulativeRolling,
internal::ValuePerBlockCumulativeRolling,
prices,
};
#[derive(Traversable)]
pub struct ActivityMinimal<M: StorageMode = Rw> {
pub transfer_volume: AmountPerBlockCumulativeRolling<M>,
pub transfer_volume: ValuePerBlockCumulativeRolling<M>,
}
impl ActivityMinimal {

View File

@@ -7,7 +7,7 @@ use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
use crate::{
indexes,
internal::{
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, CentsType,
ValuePerBlock, ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, FiatType,
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue, PerBlock,
PerBlockCumulativeRolling, PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
@@ -35,8 +35,8 @@ macro_rules! impl_config_import {
// Non-generic types
impl_config_import!(
AmountPerBlock,
AmountPerBlockCumulative,
ValuePerBlock,
ValuePerBlockCumulative,
PriceWithRatioPerBlock,
PriceWithRatioExtendedPerBlock,
RatioPerBlock<BasisPoints32>,
@@ -79,7 +79,7 @@ impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindow24hPerBlock<T>
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl ConfigImport for AmountPerBlockCumulativeRolling {
impl ConfigImport for ValuePerBlockCumulativeRolling {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(
cfg.db,
@@ -90,7 +90,7 @@ impl ConfigImport for AmountPerBlockCumulativeRolling {
)
}
}
impl<C: CentsType> ConfigImport for FiatPerBlockCumulativeWithSums<C> {
impl<C: FiatType> ConfigImport for FiatPerBlockCumulativeWithSums<C> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(
cfg.db,
@@ -106,7 +106,7 @@ impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindowsFrom1w<T> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<C: CentsType> ConfigImport for FiatPerBlock<C> {
impl<C: FiatType> ConfigImport for FiatPerBlock<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)
}

View File

@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
use crate::{
indexes,
internal::{
AmountPerBlock, AmountPerBlockWithDeltas, PerBlock, RatioPerBlock, WindowStartVec, Windows,
ValuePerBlock, ValuePerBlockWithDeltas, PerBlock, RatioPerBlock, WindowStartVec, Windows,
},
prices,
};
@@ -20,7 +20,7 @@ pub struct WithSth<All, Sth = All> {
#[derive(Traversable)]
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
pub supply: WithSth<AmountPerBlockWithDeltas<M>, AmountPerBlock<M>>,
pub supply: WithSth<ValuePerBlockWithDeltas<M>, ValuePerBlock<M>>,
pub realized_cap: WithSth<PerBlock<Dollars, M>>,
pub unrealized_pnl: WithSth<PerBlock<Dollars, M>>,
pub nupl: RatioPerBlock<BasisPointsSigned32, M>,
@@ -47,14 +47,14 @@ impl ProfitabilityBucket {
) -> Result<Self> {
Ok(Self {
supply: WithSth {
all: AmountPerBlockWithDeltas::forced_import(
all: ValuePerBlockWithDeltas::forced_import(
db,
&format!("{name}_supply"),
version,
indexes,
cached_starts,
)?,
sth: AmountPerBlock::forced_import(
sth: ValuePerBlock::forced_import(
db,
&format!("{name}_sth_supply"),
version,

View File

@@ -11,7 +11,7 @@ use crate::{
blocks,
distribution::state::{CohortState, CostBasisData, RealizedState, WithCapital},
internal::{
AmountPerBlockCumulativeRolling, FiatPerBlockCumulativeWithSums, PercentPerBlock,
ValuePerBlockCumulativeRolling, FiatPerBlockCumulativeWithSums, PercentPerBlock,
PercentRollingWindows, PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
RatioPerBlockPercentiles, RatioPerBlockStdDevBands, RatioSma, RollingWindows,
@@ -243,7 +243,7 @@ impl RealizedFull {
starting_indexes: &Indexes,
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
activity_transfer_volume: &AmountPerBlockCumulativeRolling,
activity_transfer_volume: &ValuePerBlockCumulativeRolling,
exit: &Exit,
) -> Result<()> {
self.core.compute_rest_part2(

View File

@@ -3,15 +3,15 @@ use brk_traversable::Traversable;
use brk_types::{Height, Sats, StoredU64, Version};
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
use crate::{indexes, internal::AmountPerBlock, prices};
use crate::{indexes, internal::ValuePerBlock, prices};
/// Average amount held per UTXO and per funded address.
///
/// `utxo = supply / utxo_count`, `addr = supply / funded_addr_count`.
#[derive(Traversable)]
pub struct AvgAmountMetrics<M: StorageMode = Rw> {
pub utxo: AmountPerBlock<M>,
pub addr: AmountPerBlock<M>,
pub utxo: ValuePerBlock<M>,
pub addr: ValuePerBlock<M>,
}
impl AvgAmountMetrics {
@@ -29,8 +29,8 @@ impl AvgAmountMetrics {
}
};
Ok(Self {
utxo: AmountPerBlock::forced_import(db, &name("avg_utxo_amount"), version, indexes)?,
addr: AmountPerBlock::forced_import(db, &name("avg_addr_amount"), version, indexes)?,
utxo: ValuePerBlock::forced_import(db, &name("avg_utxo_amount"), version, indexes)?,
addr: ValuePerBlock::forced_import(db, &name("avg_addr_amount"), version, indexes)?,
})
}

View File

@@ -9,7 +9,7 @@ use crate::{
};
use crate::internal::{
AmountPerBlock, LazyRollingDeltasFromHeight, PercentPerBlock, RatioSatsBp16,
LazyRollingDeltasAmountFromHeight, PercentPerBlock, RatioSatsBp16, ValuePerBlock,
};
use crate::distribution::metrics::ImportConfig;
@@ -17,17 +17,17 @@ use crate::distribution::metrics::ImportConfig;
/// Base supply metrics: total supply + dominance (share of circulating).
#[derive(Traversable)]
pub struct SupplyBase<M: StorageMode = Rw> {
pub total: AmountPerBlock<M>,
pub delta: LazyRollingDeltasFromHeight<Sats, SatsSigned, BasisPointsSigned32>,
pub total: ValuePerBlock<M>,
pub delta: LazyRollingDeltasAmountFromHeight<Sats, SatsSigned, BasisPointsSigned32>,
#[traversable(rename = "dominance")]
pub dominance: PercentPerBlock<BasisPoints16, M>,
}
impl SupplyBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let supply: AmountPerBlock = cfg.import("supply", Version::ZERO)?;
let supply: ValuePerBlock = cfg.import("supply", Version::ZERO)?;
let delta = LazyRollingDeltasFromHeight::new(
let delta = LazyRollingDeltasAmountFromHeight::new(
&cfg.name("supply_delta"),
cfg.version + Version::ONE,
&supply.sats.height,

View File

@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{distribution::state::UnrealizedState, prices};
use crate::internal::{
AmountPerBlock, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyAmountPerBlock,
ValuePerBlock, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyValuePerBlock,
};
use crate::distribution::metrics::ImportConfig;
@@ -22,9 +22,9 @@ pub struct SupplyCore<M: StorageMode = Rw> {
#[traversable(flatten)]
pub base: SupplyBase<M>,
pub half: LazyAmountPerBlock,
pub in_profit: AmountPerBlock<M>,
pub in_loss: AmountPerBlock<M>,
pub half: LazyValuePerBlock,
pub in_profit: ValuePerBlock<M>,
pub in_loss: ValuePerBlock<M>,
}
impl SupplyCore {
@@ -32,7 +32,7 @@ impl SupplyCore {
let v0 = Version::ZERO;
let base = SupplyBase::forced_import(cfg)?;
let half = LazyAmountPerBlock::from_block_source::<
let half = LazyValuePerBlock::from_block_source::<
HalveSats,
HalveSatsToBitcoin,
HalveCents,

View File

@@ -1,5 +1,4 @@
pub(crate) mod algo;
mod amount;
mod block_walker;
mod cache_budget;
mod containers;
@@ -9,9 +8,9 @@ mod per_block;
mod per_tx;
mod traits;
mod transform;
mod value;
mod with_addr_types;
pub(crate) use amount::*;
pub(crate) use block_walker::*;
pub(crate) use cache_budget::*;
pub(crate) use containers::*;
@@ -20,4 +19,5 @@ pub(crate) use per_block::*;
pub(crate) use per_tx::*;
pub(crate) use traits::*;
pub use transform::*;
pub(crate) use value::*;
pub(crate) use with_addr_types::*;

View File

@@ -12,27 +12,27 @@ use crate::{
};
/// Trait that associates a cents type with its transform to Dollars.
pub trait CentsType: NumericValue + JsonSchema {
pub trait FiatType: NumericValue + JsonSchema {
type ToDollars: UnaryTransform<Self, Dollars>;
}
impl CentsType for Cents {
impl FiatType for Cents {
type ToDollars = CentsUnsignedToDollars;
}
impl CentsType for CentsSigned {
impl FiatType for CentsSigned {
type ToDollars = CentsSignedToDollars;
}
/// Height-indexed fiat monetary value: cents (eager, integer) + usd (lazy, float).
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
#[derive(Traversable)]
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
pub struct FiatPerBlock<C: FiatType, M: StorageMode = Rw> {
pub usd: LazyPerBlock<Dollars, C>,
pub cents: PerBlock<C, M>,
}
impl<C: CentsType> FiatPerBlock<C> {
impl<C: FiatType> FiatPerBlock<C> {
pub(crate) fn forced_import(
db: &Database,
name: &str,

View File

@@ -5,16 +5,16 @@ use vecdb::{
Database, EagerVec, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw, StorageMode,
};
use super::CentsType;
use super::FiatType;
/// Raw per-block fiat data: cents (stored) + usd (lazy), no resolutions.
#[derive(Traversable)]
pub struct FiatBlock<C: CentsType, M: StorageMode = Rw> {
pub struct FiatBlock<C: FiatType, M: StorageMode = Rw> {
pub usd: LazyVecFrom1<Height, Dollars, Height, C>,
pub cents: M::Stored<EagerVec<PcoVec<Height, C>>>,
}
impl<C: CentsType> FiatBlock<C> {
impl<C: FiatType> FiatBlock<C> {
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
let cents: EagerVec<PcoVec<Height, C>> =
EagerVec::forced_import(db, &format!("{name}_cents"), version)?;

View File

@@ -6,18 +6,18 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{
CentsType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight, WindowStartVec, Windows,
FiatType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight, WindowStartVec, Windows,
},
};
#[derive(Traversable)]
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
pub struct FiatPerBlockCumulativeWithSums<C: FiatType, M: StorageMode = Rw> {
pub block: FiatBlock<C, M>,
pub cumulative: FiatPerBlock<C, M>,
pub sum: LazyRollingSumsFiatFromHeight<C>,
}
impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
impl<C: FiatType> FiatPerBlockCumulativeWithSums<C> {
pub(crate) fn forced_import(
db: &Database,
name: &str,

View File

@@ -9,13 +9,13 @@ use crate::{
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
};
use super::{CentsType, FiatPerBlockCumulativeWithSums};
use super::{FiatType, FiatPerBlockCumulativeWithSums};
#[derive(Deref, DerefMut, Traversable)]
pub struct FiatPerBlockCumulativeWithSumsAndDeltas<C, CS, B, M: StorageMode = Rw>
where
C: CentsType + Into<f64>,
CS: CentsType + From<f64>,
C: FiatType + Into<f64>,
CS: FiatType + From<f64>,
B: BpsType + From<f64>,
{
#[deref]
@@ -27,8 +27,8 @@ where
impl<C, CS, B> FiatPerBlockCumulativeWithSumsAndDeltas<C, CS, B>
where
C: CentsType + Into<f64>,
CS: CentsType + From<f64>,
C: FiatType + Into<f64>,
CS: FiatType + From<f64>,
B: BpsType + From<f64>,
{
pub(crate) fn forced_import(

View File

@@ -2,17 +2,17 @@ use brk_traversable::Traversable;
use brk_types::{Dollars, Version};
use vecdb::ReadableCloneableVec;
use crate::internal::{CentsType, Identity, LazyPerBlock, NumericValue, PerBlock};
use crate::internal::{FiatType, Identity, LazyPerBlock, NumericValue, PerBlock};
/// Lazy fiat: both cents and usd are lazy views of a stored source.
/// Zero extra stored vecs.
#[derive(Clone, Traversable)]
pub struct LazyFiatPerBlock<C: CentsType> {
pub struct LazyFiatPerBlock<C: FiatType> {
pub usd: LazyPerBlock<Dollars, C>,
pub cents: LazyPerBlock<C, C>,
}
impl<C: CentsType> LazyFiatPerBlock<C> {
impl<C: FiatType> LazyFiatPerBlock<C> {
pub(crate) fn from_computed(name: &str, version: Version, source: &PerBlock<C>) -> Self
where
C: NumericValue,

View File

@@ -6,24 +6,24 @@ use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneab
use crate::{
indexes,
internal::{
CentsType, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight, Resolutions,
FiatType, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight, Resolutions,
WindowStartVec, Windows,
},
};
#[derive(Clone, Traversable)]
pub struct LazyRollingSumFiatFromHeight<C: CentsType> {
pub struct LazyRollingSumFiatFromHeight<C: FiatType> {
pub usd: LazyPerBlock<Dollars, C>,
pub cents: LazyRollingSumFromHeight<C>,
}
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct LazyRollingSumsFiatFromHeight<C: CentsType>(
pub struct LazyRollingSumsFiatFromHeight<C: FiatType>(
pub Windows<LazyRollingSumFiatFromHeight<C>>,
);
impl<C: CentsType> LazyRollingSumsFiatFromHeight<C> {
impl<C: FiatType> LazyRollingSumsFiatFromHeight<C> {
pub fn new(
name: &str,
version: Version,

View File

@@ -10,13 +10,13 @@ use crate::{
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
};
use super::{CentsType, FiatPerBlock};
use super::{FiatType, FiatPerBlock};
#[derive(Deref, DerefMut, Traversable)]
pub struct FiatPerBlockWithDeltas<C, CS, B, M: StorageMode = Rw>
where
C: CentsType + Into<f64>,
CS: CentsType + From<f64>,
C: FiatType + Into<f64>,
CS: FiatType + From<f64>,
B: BpsType + From<f64>,
{
#[deref]
@@ -28,8 +28,8 @@ where
impl<C, CS, B> FiatPerBlockWithDeltas<C, CS, B>
where
C: CentsType + JsonSchema + Into<f64>,
CS: CentsType + From<f64>,
C: FiatType + JsonSchema + Into<f64>,
CS: FiatType + From<f64>,
B: BpsType + From<f64>,
{
pub(crate) fn forced_import(

View File

@@ -1,4 +1,3 @@
mod amount;
mod computed;
mod fiat;
mod lazy;
@@ -8,8 +7,8 @@ mod price;
mod ratio;
mod rolling;
mod stddev;
mod value;
pub use amount::*;
pub use computed::*;
pub use fiat::*;
pub use lazy::*;
@@ -19,3 +18,4 @@ pub use price::*;
pub use ratio::*;
pub use rolling::*;
pub use stddev::*;
pub use value::*;

View File

@@ -1,5 +1,5 @@
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, StoredF32, Version};
use brk_types::{Bitcoin, Dollars, Height, StoredF32, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{
@@ -10,8 +10,8 @@ use vecdb::{
use crate::{
indexes,
internal::{
BpsType, CentsType, DerivedResolutions, LazyPerBlock, NumericValue, Percent, Resolutions,
WindowStartVec, Windows,
AmountType, BpsType, DerivedResolutions, FiatType, LazyPerBlock, NumericValue, Percent,
Resolutions, WindowStartVec, Windows,
},
};
@@ -160,6 +160,152 @@ where
}
}
// ---------------------------------------------------------------------------
// Amount delta types (sats change + lazy BTC + rate)
// ---------------------------------------------------------------------------
/// Single-slot amount delta change: sats delta + lazy BTC.
#[derive(Clone, Traversable)]
pub struct LazyDeltaAmountFromHeight<S, C>
where
S: VecValue,
C: AmountType,
{
pub btc: LazyPerBlock<Bitcoin, C>,
pub sats: LazyDeltaFromHeight<S, C, DeltaChange>,
}
/// Lazy amount rolling deltas for all 4 windows.
///
/// Tree shape: `absolute._24h.{sats,btc}/...`, `rate._24h/...` — mirrors
/// `LazyRollingDeltasFiatFromHeight` but stores sats instead of cents and
/// derives a lazy BTC view alongside (free, since sats → btc is a scalar
/// transform).
#[derive(Clone, Traversable)]
pub struct LazyRollingDeltasAmountFromHeight<S, C, B>
where
S: VecValue,
C: AmountType,
B: BpsType,
{
pub absolute: Windows<LazyDeltaAmountFromHeight<S, C>>,
pub rate: Windows<LazyDeltaPercentFromHeight<S, B>>,
}
impl<S, C, B> LazyRollingDeltasAmountFromHeight<S, C, B>
where
S: VecValue + Into<f64>,
C: AmountType + From<f64>,
B: BpsType + From<f64>,
{
pub fn new(
name: &str,
version: Version,
source: &(impl ReadableCloneableVec<Height, S> + 'static),
cached_starts: &Windows<&WindowStartVec>,
indexes: &indexes::Vecs,
) -> Self {
let src = source.read_only_boxed_clone();
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
let full_name = format!("{name}_{suffix}");
let cached = cached_start.read_only_clone();
let starts_version = cached.version();
// Absolute change (sats): source[h] - source[ago] as C (via f64)
let sats_name = format!("{full_name}_sats");
let change_vec = LazyDeltaVec::<Height, S, C, DeltaChange>::new(
&sats_name,
version,
src.clone(),
starts_version,
{
let cached = cached.clone();
move || cached.cached()
},
);
let change_resolutions =
Resolutions::forced_import(&sats_name, change_vec.clone(), version, indexes);
let sats = LazyDeltaFromHeight {
height: change_vec,
resolutions: Box::new(change_resolutions),
};
// Absolute change (btc): lazy from sats delta
let btc = LazyPerBlock {
height: LazyVecFrom1::transformed::<C::ToBitcoin>(
&full_name,
version,
sats.height.read_only_boxed_clone(),
),
resolutions: Box::new(DerivedResolutions::from_derived_computed::<C::ToBitcoin>(
&full_name,
version,
&sats.resolutions,
)),
};
let absolute = LazyDeltaAmountFromHeight { btc, sats };
// Rate BPS: (source[h] - source[ago]) / source[ago] as B (via f64)
let rate_bps_name = format!("{full_name}_rate_bps");
let rate_vec = LazyDeltaVec::<Height, S, B, DeltaRate>::new(
&rate_bps_name,
version,
src.clone(),
starts_version,
move || cached.cached(),
);
let rate_resolutions =
Resolutions::forced_import(&rate_bps_name, rate_vec.clone(), version, indexes);
let bps = LazyDeltaFromHeight {
height: rate_vec,
resolutions: Box::new(rate_resolutions),
};
let rate_ratio_name = format!("{full_name}_rate_ratio");
let ratio = LazyPerBlock {
height: LazyVecFrom1::transformed::<B::ToRatio>(
&rate_ratio_name,
version,
bps.height.read_only_boxed_clone(),
),
resolutions: Box::new(DerivedResolutions::from_derived_computed::<B::ToRatio>(
&rate_ratio_name,
version,
&bps.resolutions,
)),
};
let rate_name = format!("{full_name}_rate");
let percent = LazyPerBlock {
height: LazyVecFrom1::transformed::<B::ToPercent>(
&rate_name,
version,
bps.height.read_only_boxed_clone(),
),
resolutions: Box::new(DerivedResolutions::from_derived_computed::<B::ToPercent>(
&rate_name,
version,
&bps.resolutions,
)),
};
let rate = LazyDeltaPercentFromHeight(Percent {
bps,
ratio,
percent,
});
(absolute, rate)
};
let (absolute, rate) = cached_starts.map_with_suffix(make_slot).unzip();
Self { absolute, rate }
}
}
// ---------------------------------------------------------------------------
// Fiat delta types (cents change + lazy USD + rate)
// ---------------------------------------------------------------------------
@@ -169,7 +315,7 @@ where
pub struct LazyDeltaFiatFromHeight<S, C>
where
S: VecValue,
C: CentsType,
C: FiatType,
{
pub usd: LazyPerBlock<Dollars, C>,
pub cents: LazyDeltaFromHeight<S, C, DeltaChange>,
@@ -184,7 +330,7 @@ where
pub struct LazyRollingDeltasFiatFromHeight<S, C, B>
where
S: VecValue,
C: CentsType,
C: FiatType,
B: BpsType,
{
pub absolute: Windows<LazyDeltaFiatFromHeight<S, C>>,
@@ -194,7 +340,7 @@ where
impl<S, C, B> LazyRollingDeltasFiatFromHeight<S, C, B>
where
S: VecValue + Into<f64>,
C: CentsType + From<f64>,
C: FiatType + From<f64>,
B: BpsType + From<f64>,
{
pub fn new(

View File

@@ -1,23 +1,40 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
use vecdb::{Database, Exit, ReadableCloneableVec, Rw, StorageMode};
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, SatsSigned, Version};
use schemars::JsonSchema;
use vecdb::{Database, Exit, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
use crate::{
indexes,
internal::{CentsUnsignedToDollars, LazyPerBlock, PerBlock, SatsToBitcoin, SatsToCents},
internal::{
CentsUnsignedToDollars, LazyPerBlock, NumericValue, PerBlock, SatsSignedToBitcoin,
SatsToBitcoin, SatsToCents,
},
prices,
};
/// Trait that associates a sats type with its transform to Bitcoin.
pub trait AmountType: NumericValue + JsonSchema {
type ToBitcoin: UnaryTransform<Self, Bitcoin>;
}
impl AmountType for Sats {
type ToBitcoin = SatsToBitcoin;
}
impl AmountType for SatsSigned {
type ToBitcoin = SatsSignedToBitcoin;
}
#[derive(Traversable)]
pub struct AmountPerBlock<M: StorageMode = Rw> {
pub struct ValuePerBlock<M: StorageMode = Rw> {
pub btc: LazyPerBlock<Bitcoin, Sats>,
pub sats: PerBlock<Sats, M>,
pub usd: LazyPerBlock<Dollars, Cents>,
pub cents: PerBlock<Cents, M>,
}
impl AmountPerBlock {
impl ValuePerBlock {
pub(crate) fn forced_import(
db: &Database,
name: &str,

View File

@@ -13,14 +13,14 @@ use crate::{
/// Raw per-block amount data: sats + cents (stored), btc + usd (lazy), no resolutions.
#[derive(Traversable)]
pub struct AmountBlock<M: StorageMode = Rw> {
pub struct ValueBlock<M: StorageMode = Rw> {
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
pub sats: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
pub usd: LazyVecFrom1<Height, Dollars, Height, Cents>,
pub cents: M::Stored<EagerVec<PcoVec<Height, Cents>>>,
}
impl AmountBlock {
impl ValueBlock {
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
let sats: EagerVec<PcoVec<Height, Sats>> =
EagerVec::forced_import(db, &format!("{name}_sats"), version)?;

View File

@@ -5,19 +5,19 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{AmountBlock, AmountPerBlock},
internal::{ValueBlock, ValuePerBlock},
prices,
};
#[derive(Traversable)]
pub struct AmountPerBlockCumulative<M: StorageMode = Rw> {
pub block: AmountBlock<M>,
pub cumulative: AmountPerBlock<M>,
pub struct ValuePerBlockCumulative<M: StorageMode = Rw> {
pub block: ValueBlock<M>,
pub cumulative: ValuePerBlock<M>,
}
const VERSION: Version = Version::ONE;
impl AmountPerBlockCumulative {
impl ValuePerBlockCumulative {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -27,8 +27,8 @@ impl AmountPerBlockCumulative {
let v = version + VERSION;
Ok(Self {
block: AmountBlock::forced_import(db, name, v)?,
cumulative: AmountPerBlock::forced_import(
block: ValueBlock::forced_import(db, name, v)?,
cumulative: ValuePerBlock::forced_import(
db,
&format!("{name}_cumulative"),
v,

View File

@@ -7,25 +7,25 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
AmountPerBlockCumulative, LazyRollingAvgsAmountFromHeight, LazyRollingSumsAmountFromHeight,
ValuePerBlockCumulative, LazyRollingAvgsAmountFromHeight, LazyRollingSumsAmountFromHeight,
WindowStartVec, Windows,
},
prices,
};
#[derive(Deref, DerefMut, Traversable)]
pub struct AmountPerBlockCumulativeRolling<M: StorageMode = Rw> {
pub struct ValuePerBlockCumulativeRolling<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: AmountPerBlockCumulative<M>,
pub inner: ValuePerBlockCumulative<M>,
pub sum: LazyRollingSumsAmountFromHeight,
pub average: LazyRollingAvgsAmountFromHeight,
}
const VERSION: Version = Version::TWO;
impl AmountPerBlockCumulativeRolling {
impl ValuePerBlockCumulativeRolling {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -35,7 +35,7 @@ impl AmountPerBlockCumulativeRolling {
) -> Result<Self> {
let v = version + VERSION;
let inner = AmountPerBlockCumulative::forced_import(db, name, v, indexes)?;
let inner = ValuePerBlockCumulative::forced_import(db, name, v, indexes)?;
let sum = LazyRollingSumsAmountFromHeight::new(
&format!("{name}_sum"),
v,

View File

@@ -7,25 +7,25 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
AmountPerBlockCumulativeRolling, RollingDistributionAmountPerBlock, WindowStartVec,
ValuePerBlockCumulativeRolling, RollingDistributionValuePerBlock, WindowStartVec,
WindowStarts, Windows,
},
prices,
};
#[derive(Deref, DerefMut, Traversable)]
pub struct AmountPerBlockFull<M: StorageMode = Rw> {
pub struct ValuePerBlockFull<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: AmountPerBlockCumulativeRolling<M>,
pub inner: ValuePerBlockCumulativeRolling<M>,
#[traversable(flatten)]
pub distribution: RollingDistributionAmountPerBlock<M>,
pub distribution: RollingDistributionValuePerBlock<M>,
}
const VERSION: Version = Version::TWO;
impl AmountPerBlockFull {
impl ValuePerBlockFull {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -36,8 +36,8 @@ impl AmountPerBlockFull {
let v = version + VERSION;
let inner =
AmountPerBlockCumulativeRolling::forced_import(db, name, v, indexes, cached_starts)?;
let distribution = RollingDistributionAmountPerBlock::forced_import(db, name, v, indexes)?;
ValuePerBlockCumulativeRolling::forced_import(db, name, v, indexes, cached_starts)?;
let distribution = RollingDistributionValuePerBlock::forced_import(db, name, v, indexes)?;
Ok(Self {
inner,

View File

@@ -1,4 +1,4 @@
//! Lazy value wrapper for AmountPerBlock - all transforms are lazy.
//! Lazy value wrapper for ValuePerBlock - all transforms are lazy.
use brk_traversable::Traversable;
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
@@ -6,22 +6,22 @@ use derive_more::{Deref, DerefMut};
use vecdb::UnaryTransform;
use crate::internal::{
AmountPerBlock, Identity, LazyAmount, LazyAmountDerivedResolutions, SatsToBitcoin,
ValuePerBlock, Identity, LazyValue, LazyValueDerivedResolutions, SatsToBitcoin,
};
/// Lazy value wrapper with height + all derived last transforms from AmountPerBlock.
/// Lazy value wrapper with height + all derived last transforms from ValuePerBlock.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyAmountPerBlock {
pub struct LazyValuePerBlock {
#[traversable(flatten)]
pub height: LazyAmount<Height>,
pub height: LazyValue<Height>,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub resolutions: Box<LazyAmountDerivedResolutions>,
pub resolutions: Box<LazyValueDerivedResolutions>,
}
impl LazyAmountPerBlock {
impl LazyValuePerBlock {
pub(crate) fn from_block_source<
SatsTransform,
BitcoinTransform,
@@ -29,7 +29,7 @@ impl LazyAmountPerBlock {
DollarsTransform,
>(
name: &str,
source: &AmountPerBlock,
source: &ValuePerBlock,
version: Version,
) -> Self
where
@@ -38,14 +38,14 @@ impl LazyAmountPerBlock {
CentsTransform: UnaryTransform<Cents, Cents>,
DollarsTransform: UnaryTransform<Dollars, Dollars>,
{
let height = LazyAmount::from_block_source::<
let height = LazyValue::from_block_source::<
SatsTransform,
BitcoinTransform,
CentsTransform,
DollarsTransform,
>(name, source, version);
let resolutions = LazyAmountDerivedResolutions::from_block_source::<
let resolutions = LazyValueDerivedResolutions::from_block_source::<
SatsTransform,
BitcoinTransform,
CentsTransform,
@@ -58,7 +58,7 @@ impl LazyAmountPerBlock {
}
}
pub(crate) fn identity(name: &str, source: &AmountPerBlock, version: Version) -> Self {
pub(crate) fn identity(name: &str, source: &ValuePerBlock, version: Version) -> Self {
Self::from_block_source::<Identity<Sats>, SatsToBitcoin, Identity<Cents>, Identity<Dollars>>(
name, source, version,
)

View File

@@ -2,17 +2,17 @@ use brk_traversable::Traversable;
use brk_types::{Bitcoin, Cents, Dollars, Sats, Version};
use vecdb::UnaryTransform;
use crate::internal::{AmountPerBlock, DerivedResolutions};
use crate::internal::{ValuePerBlock, DerivedResolutions};
#[derive(Clone, Traversable)]
pub struct LazyAmountDerivedResolutions {
pub struct LazyValueDerivedResolutions {
pub btc: DerivedResolutions<Bitcoin, Sats>,
pub sats: DerivedResolutions<Sats, Sats>,
pub usd: DerivedResolutions<Dollars, Dollars>,
pub cents: DerivedResolutions<Cents, Cents>,
}
impl LazyAmountDerivedResolutions {
impl LazyValueDerivedResolutions {
pub(crate) fn from_block_source<
SatsTransform,
BitcoinTransform,
@@ -20,7 +20,7 @@ impl LazyAmountDerivedResolutions {
DollarsTransform,
>(
name: &str,
source: &AmountPerBlock,
source: &ValuePerBlock,
version: Version,
) -> Self
where

View File

@@ -7,7 +7,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
AmountPerBlock, DistributionStats, WindowStarts, Windows,
ValuePerBlock, DistributionStats, WindowStarts, Windows,
algo::compute_rolling_distribution_from_starts,
},
};
@@ -18,11 +18,11 @@ use crate::{
/// Series: `{name}_average_24h`, `{name}_max_24h`, etc.
#[derive(Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct RollingDistributionAmountPerBlock<M: StorageMode = Rw>(
pub DistributionStats<Windows<AmountPerBlock<M>>>,
pub struct RollingDistributionValuePerBlock<M: StorageMode = Rw>(
pub DistributionStats<Windows<ValuePerBlock<M>>>,
);
impl RollingDistributionAmountPerBlock {
impl RollingDistributionValuePerBlock {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -31,7 +31,7 @@ impl RollingDistributionAmountPerBlock {
) -> Result<Self> {
Ok(Self(DistributionStats::try_from_fn(|stat_suffix| {
Windows::try_from_fn(|window_suffix| {
AmountPerBlock::forced_import(
ValuePerBlock::forced_import(
db,
&format!("{name}_{stat_suffix}_{window_suffix}"),
version,

View File

@@ -6,19 +6,19 @@ use vecdb::{Database, Rw, StorageMode};
use crate::{
indexes,
internal::{AmountPerBlock, LazyRollingDeltasFromHeight, WindowStartVec, Windows},
internal::{LazyRollingDeltasAmountFromHeight, ValuePerBlock, WindowStartVec, Windows},
};
#[derive(Deref, DerefMut, Traversable)]
pub struct AmountPerBlockWithDeltas<M: StorageMode = Rw> {
pub struct ValuePerBlockWithDeltas<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: AmountPerBlock<M>,
pub delta: LazyRollingDeltasFromHeight<Sats, SatsSigned, BasisPointsSigned32>,
pub inner: ValuePerBlock<M>,
pub delta: LazyRollingDeltasAmountFromHeight<Sats, SatsSigned, BasisPointsSigned32>,
}
impl AmountPerBlockWithDeltas {
impl ValuePerBlockWithDeltas {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -26,9 +26,9 @@ impl AmountPerBlockWithDeltas {
indexes: &indexes::Vecs,
cached_starts: &Windows<&WindowStartVec>,
) -> Result<Self> {
let inner = AmountPerBlock::forced_import(db, name, version, indexes)?;
let inner = ValuePerBlock::forced_import(db, name, version, indexes)?;
let delta = LazyRollingDeltasFromHeight::new(
let delta = LazyRollingDeltasAmountFromHeight::new(
&format!("{name}_delta"),
version + Version::ONE,
&inner.sats.height,

View File

@@ -17,7 +17,7 @@ pub use bps::{
pub use currency::{
AvgCentsToUsd, AvgSatsToBtc, CentsSignedToDollars, CentsSubtractToCentsSigned,
CentsTimesTenths, CentsUnsignedToDollars, CentsUnsignedToSats, DollarsToSatsFract,
NegCentsUnsignedToDollars, SatsToBitcoin, SatsToCents,
NegCentsUnsignedToDollars, SatsSignedToBitcoin, SatsToBitcoin, SatsToCents,
};
pub use derived::{
Days1, Days7, Days30, Days365, DaysToYears, PriceTimesRatioBp32Cents, PriceTimesRatioCents,

View File

@@ -2,20 +2,20 @@ use brk_traversable::Traversable;
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecIndex};
use crate::internal::AmountPerBlock;
use crate::internal::ValuePerBlock;
/// Fully lazy value type at height level.
///
/// All fields are lazy transforms from existing sources - no storage.
#[derive(Clone, Traversable)]
pub struct LazyAmount<I: VecIndex> {
pub struct LazyValue<I: VecIndex> {
pub btc: LazyVecFrom1<I, Bitcoin, I, Sats>,
pub sats: LazyVecFrom1<I, Sats, I, Sats>,
pub usd: LazyVecFrom1<I, Dollars, I, Dollars>,
pub cents: LazyVecFrom1<I, Cents, I, Cents>,
}
impl LazyAmount<Height> {
impl LazyValue<Height> {
pub(crate) fn from_block_source<
SatsTransform,
BitcoinTransform,
@@ -23,7 +23,7 @@ impl LazyAmount<Height> {
DollarsTransform,
>(
name: &str,
source: &AmountPerBlock,
source: &ValuePerBlock,
version: Version,
) -> Self
where

View File

@@ -13,7 +13,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, WritableVec}
use crate::{indexes, prices};
use super::{
AmountPerBlock, BpsType, NumericValue, PerBlock, PerBlockCumulativeRolling, PercentPerBlock,
ValuePerBlock, BpsType, NumericValue, PerBlock, PerBlockCumulativeRolling, PercentPerBlock,
WindowStartVec, Windows,
};
@@ -176,16 +176,16 @@ where
}
}
impl WithAddrTypes<AmountPerBlock> {
impl WithAddrTypes<ValuePerBlock> {
pub(crate) fn forced_import(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let all = AmountPerBlock::forced_import(db, name, version, indexes)?;
let all = ValuePerBlock::forced_import(db, name, version, indexes)?;
let by_addr_type = ByAddrType::new_with_name(|type_name| {
AmountPerBlock::forced_import(db, &format!("{type_name}_{name}"), version, indexes)
ValuePerBlock::forced_import(db, &format!("{type_name}_{name}"), version, indexes)
})?;
Ok(Self { all, by_addr_type })
}

View File

@@ -9,7 +9,7 @@ use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs};
use crate::{
indexes,
internal::{
AmountPerBlock, PercentPerBlock, Price,
ValuePerBlock, PercentPerBlock, Price,
db_utils::{finalize_db, open_db},
},
};
@@ -23,7 +23,7 @@ impl Vecs {
let db = open_db(parent_path, super::DB_NAME, 50_000)?;
let version = parent_version;
let stack = ByDcaPeriod::try_new(|name, _days| {
AmountPerBlock::forced_import(&db, &format!("dca_stack_{name}"), version, indexes)
ValuePerBlock::forced_import(&db, &format!("dca_stack_{name}"), version, indexes)
})?;
let cost_basis = ByDcaPeriod::try_new(|name, _days| {
@@ -39,7 +39,7 @@ impl Vecs {
})?;
let lump_sum_stack = ByDcaPeriod::try_new(|name, _days| {
AmountPerBlock::forced_import(&db, &format!("lump_sum_stack_{name}"), version, indexes)
ValuePerBlock::forced_import(&db, &format!("lump_sum_stack_{name}"), version, indexes)
})?;
let lump_sum_return = ByDcaPeriod::try_new(|name, _days| {
@@ -52,7 +52,7 @@ impl Vecs {
})?;
let class_stack = ByDcaClass::try_new(|name, _year, _day1| {
AmountPerBlock::forced_import(&db, &format!("dca_stack_{name}"), version, indexes)
ValuePerBlock::forced_import(&db, &format!("dca_stack_{name}"), version, indexes)
})?;
let class_cost_basis = ByDcaClass::try_new(|name, _year, _day1| {

View File

@@ -3,21 +3,21 @@ use brk_types::{BasisPointsSigned32, Cents, Height, Sats};
use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode};
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod};
use crate::internal::{AmountPerBlock, PerBlock, PercentPerBlock, Price};
use crate::internal::{ValuePerBlock, PerBlock, PercentPerBlock, Price};
#[derive(Traversable)]
pub struct PeriodVecs<M: StorageMode = Rw> {
pub dca_stack: ByDcaPeriod<AmountPerBlock<M>>,
pub dca_stack: ByDcaPeriod<ValuePerBlock<M>>,
pub dca_cost_basis: ByDcaPeriod<Price<PerBlock<Cents, M>>>,
pub dca_return: ByDcaPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
pub dca_cagr: ByDcaCagr<PercentPerBlock<BasisPointsSigned32, M>>,
pub lump_sum_stack: ByDcaPeriod<AmountPerBlock<M>>,
pub lump_sum_stack: ByDcaPeriod<ValuePerBlock<M>>,
pub lump_sum_return: ByDcaPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
}
#[derive(Traversable)]
pub struct ClassVecs<M: StorageMode = Rw> {
pub dca_stack: ByDcaClass<AmountPerBlock<M>>,
pub dca_stack: ByDcaClass<ValuePerBlock<M>>,
pub dca_cost_basis: ByDcaClass<Price<PerBlock<Cents, M>>>,
pub dca_return: ByDcaClass<PercentPerBlock<BasisPointsSigned32, M>>,
}

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
indexes,
internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull,
LazyPercentCumulativeRolling, OneMinusBp16, PercentCumulativeRolling, RatioRollingWindows,
WindowStartVec, Windows,
},
@@ -29,23 +29,23 @@ impl Vecs {
);
Ok(Self {
coinbase: AmountPerBlockCumulativeRolling::forced_import(
coinbase: ValuePerBlockCumulativeRolling::forced_import(
db,
"coinbase",
version,
indexes,
cached_starts,
)?,
subsidy: AmountPerBlockCumulativeRolling::forced_import(
subsidy: ValuePerBlockCumulativeRolling::forced_import(
db,
"subsidy",
version,
indexes,
cached_starts,
)?,
fees: AmountPerBlockFull::forced_import(db, "fees", version, indexes, cached_starts)?,
fees: ValuePerBlockFull::forced_import(db, "fees", version, indexes, cached_starts)?,
output_volume: EagerVec::forced_import(db, "output_volume", version)?,
unclaimed: AmountPerBlockCumulative::forced_import(
unclaimed: ValuePerBlockCumulative::forced_import(
db,
"unclaimed_rewards",
version,

View File

@@ -3,17 +3,17 @@ use brk_types::{BasisPoints16, BasisPoints32, Height, Sats};
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
use crate::internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull,
LazyPercentCumulativeRolling, PercentCumulativeRolling, RatioRollingWindows,
};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub coinbase: AmountPerBlockCumulativeRolling<M>,
pub subsidy: AmountPerBlockCumulativeRolling<M>,
pub fees: AmountPerBlockFull<M>,
pub coinbase: ValuePerBlockCumulativeRolling<M>,
pub subsidy: ValuePerBlockCumulativeRolling<M>,
pub fees: ValuePerBlockFull<M>,
pub output_volume: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
pub unclaimed: AmountPerBlockCumulative<M>,
pub unclaimed: ValuePerBlockCumulative<M>,
#[traversable(wrap = "fees", rename = "dominance")]
pub fee_dominance: PercentCumulativeRolling<BasisPoints16, M>,
#[traversable(wrap = "subsidy", rename = "dominance")]

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::AmountPerBlockCumulative};
use crate::{indexes, internal::ValuePerBlockCumulative};
impl Vecs {
pub(crate) fn forced_import(
@@ -12,7 +12,7 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
op_return: AmountPerBlockCumulative::forced_import(
op_return: ValuePerBlockCumulative::forced_import(
db,
"op_return_value",
version,

View File

@@ -1,9 +1,9 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulative;
use crate::internal::ValuePerBlockCumulative;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub op_return: AmountPerBlockCumulative<M>,
pub op_return: ValuePerBlockCumulative<M>,
}

View File

@@ -7,7 +7,7 @@ use vecdb::{BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, Versi
use crate::{
blocks, indexes,
internal::{
AmountPerBlockCumulativeRolling, MaskSats, PercentRollingWindows, RatioU64Bp16,
ValuePerBlockCumulativeRolling, MaskSats, PercentRollingWindows, RatioU64Bp16,
WindowStartVec, Windows,
},
mining, prices,
@@ -22,7 +22,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub base: minor::Vecs<M>,
pub rewards: AmountPerBlockCumulativeRolling<M>,
pub rewards: ValuePerBlockCumulativeRolling<M>,
#[traversable(rename = "dominance")]
pub dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
}
@@ -39,7 +39,7 @@ impl Vecs {
let base = minor::Vecs::forced_import(db, slug, version, indexes, cached_starts)?;
let rewards = AmountPerBlockCumulativeRolling::forced_import(
let rewards = ValuePerBlockCumulativeRolling::forced_import(
db,
&suffix("rewards"),
version,

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::AmountPerBlockCumulative};
use crate::{indexes, internal::ValuePerBlockCumulative};
impl Vecs {
pub(crate) fn forced_import(
@@ -12,7 +12,7 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
total: AmountPerBlockCumulative::forced_import(
total: ValuePerBlockCumulative::forced_import(
db,
"unspendable_supply",
version,

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulative;
use crate::internal::ValuePerBlockCumulative;
#[derive(Traversable)]
#[traversable(transparent)]
pub struct Vecs<M: StorageMode = Rw> {
pub total: AmountPerBlockCumulative<M>,
pub total: ValuePerBlockCumulative<M>,
}

View File

@@ -6,7 +6,7 @@ use brk_types::Version;
use crate::{
cointime, distribution, indexes,
internal::{
LazyAmountPerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
LazyValuePerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
RollingWindows, WindowStartVec, Windows,
db_utils::{finalize_db, open_db},
},
@@ -32,7 +32,7 @@ impl Vecs {
let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply;
let circulating =
LazyAmountPerBlock::identity("circulating_supply", &supply_metrics.total, version);
LazyValuePerBlock::identity("circulating_supply", &supply_metrics.total, version);
let burned = burned::Vecs::forced_import(&db, version, indexes)?;
@@ -63,7 +63,7 @@ impl Vecs {
indexes,
)?;
let hodled_or_lost = LazyAmountPerBlock::identity(
let hodled_or_lost = LazyValuePerBlock::identity(
"hodled_or_lost_supply",
&cointime.supply.vaulted,
version,

View File

@@ -4,7 +4,7 @@ use vecdb::{Database, Rw, StorageMode};
use super::{burned, velocity};
use crate::internal::{
LazyAmountPerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
LazyValuePerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
RollingWindows,
};
@@ -13,7 +13,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(skip)]
pub(crate) db: Database,
pub circulating: LazyAmountPerBlock,
pub circulating: LazyValuePerBlock,
pub burned: burned::Vecs<M>,
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
pub velocity: velocity::Vecs<M>,
@@ -21,5 +21,5 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(wrap = "market_cap", rename = "delta")]
pub market_cap_delta: LazyRollingDeltasFiatFromHeight<Cents, CentsSigned, BasisPointsSigned32>,
pub market_minus_realized_cap_growth_rate: RollingWindows<BasisPointsSigned32, M>,
pub hodled_or_lost: LazyAmountPerBlock,
pub hodled_or_lost: LazyValuePerBlock,
}

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{AmountPerBlockCumulativeRolling, PerBlock, WindowStartVec, Windows},
internal::{ValuePerBlockCumulativeRolling, PerBlock, WindowStartVec, Windows},
};
impl Vecs {
@@ -17,7 +17,7 @@ impl Vecs {
) -> Result<Self> {
let v = version + Version::TWO;
Ok(Self {
transfer_volume: AmountPerBlockCumulativeRolling::forced_import(
transfer_volume: ValuePerBlockCumulativeRolling::forced_import(
db,
"transfer_volume_bis",
version,

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::StoredF32;
use vecdb::{Rw, StorageMode};
use crate::internal::{AmountPerBlockCumulativeRolling, PerBlock, Windows};
use crate::internal::{ValuePerBlockCumulativeRolling, PerBlock, Windows};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub transfer_volume: AmountPerBlockCumulativeRolling<M>,
pub transfer_volume: ValuePerBlockCumulativeRolling<M>,
pub tx_per_sec: Windows<PerBlock<StoredF32, M>>,
}