mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 17:38:09 -07:00
global: snapshot
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -22,9 +21,9 @@ impl Vecs {
|
||||
self.burned
|
||||
.compute(scripts, mining, &blocks.count, prices, starting_indexes, exit)?;
|
||||
|
||||
// 2. Compute inflation rate at height level: (supply[h] - supply[1y_ago]) / supply[1y_ago] * 100
|
||||
// 2. Compute inflation rate: (supply[h] / supply[1y_ago]) - 1
|
||||
let circulating_supply = &distribution.utxo_cohorts.all.metrics.supply.total.sats;
|
||||
self.inflation.height.compute_rolling_percentage_change(
|
||||
self.inflation_rate.bps.height.compute_rolling_ratio_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1y_ago,
|
||||
&circulating_supply.height,
|
||||
@@ -35,10 +34,11 @@ impl Vecs {
|
||||
self.velocity
|
||||
.compute(blocks, transactions, distribution, starting_indexes, exit)?;
|
||||
|
||||
// 4. Compute cap growth rates at height level using 1y lookback
|
||||
// 4. Compute cap growth rates using 1y lookback
|
||||
self.market_cap_growth_rate
|
||||
.bps
|
||||
.height
|
||||
.compute_rolling_percentage_change(
|
||||
.compute_rolling_ratio_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1y_ago,
|
||||
&self.market_cap.height,
|
||||
@@ -46,20 +46,20 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
self.realized_cap_growth_rate
|
||||
.bps
|
||||
.height
|
||||
.compute_rolling_percentage_change(
|
||||
.compute_rolling_ratio_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1y_ago,
|
||||
&distribution.utxo_cohorts.all.metrics.realized.realized_cap.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// 5. Compute cap growth rate diff: market_cap_growth_rate - realized_cap_growth_rate
|
||||
self.cap_growth_rate_diff.height.compute_transform2(
|
||||
// 5. Compute cap growth rate diff: market - realized
|
||||
self.market_minus_realized_cap_growth_rate.height.compute_subtract(
|
||||
starting_indexes.height,
|
||||
&self.market_cap_growth_rate.height,
|
||||
&self.realized_cap_growth_rate.height,
|
||||
|(h, a, b, ..)| (h, StoredF32::from(*a - *b)),
|
||||
&self.market_cap_growth_rate.bps.height,
|
||||
&self.realized_cap_growth_rate.bps.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ use super::Vecs;
|
||||
use crate::{
|
||||
distribution, indexes,
|
||||
internal::{
|
||||
ComputedFromHeight, Identity, LazyFromHeight, LazyValueFromHeight, SatsToBitcoin,
|
||||
Bps32ToFloat, Bps32ToPercent, ComputedFromHeight, Identity, LazyFromHeight,
|
||||
LazyValueFromHeight, PercentFromHeight, SatsToBitcoin,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -40,8 +41,8 @@ impl Vecs {
|
||||
let burned = super::burned::Vecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
// Inflation rate
|
||||
let inflation =
|
||||
ComputedFromHeight::forced_import(&db, "inflation_rate", version, indexes)?;
|
||||
let inflation_rate =
|
||||
PercentFromHeight::forced_import::<Bps32ToFloat, Bps32ToPercent>(&db, "inflation_rate", version, indexes)?;
|
||||
|
||||
// Velocity
|
||||
let velocity = super::velocity::Vecs::forced_import(&db, version, indexes)?;
|
||||
@@ -54,31 +55,31 @@ impl Vecs {
|
||||
);
|
||||
|
||||
// Growth rates
|
||||
let market_cap_growth_rate = ComputedFromHeight::forced_import(
|
||||
let market_cap_growth_rate = PercentFromHeight::forced_import::<Bps32ToFloat, Bps32ToPercent>(
|
||||
&db,
|
||||
"market_cap_growth_rate",
|
||||
version + Version::ONE,
|
||||
indexes,
|
||||
)?;
|
||||
let realized_cap_growth_rate = ComputedFromHeight::forced_import(
|
||||
let realized_cap_growth_rate = PercentFromHeight::forced_import::<Bps32ToFloat, Bps32ToPercent>(
|
||||
&db,
|
||||
"realized_cap_growth_rate",
|
||||
version + Version::ONE,
|
||||
indexes,
|
||||
)?;
|
||||
let cap_growth_rate_diff =
|
||||
ComputedFromHeight::forced_import(&db, "cap_growth_rate_diff", version, indexes)?;
|
||||
let market_minus_realized_cap_growth_rate =
|
||||
ComputedFromHeight::forced_import(&db, "market_minus_realized_cap_growth_rate", version, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
circulating,
|
||||
burned,
|
||||
inflation,
|
||||
inflation_rate,
|
||||
velocity,
|
||||
market_cap,
|
||||
market_cap_growth_rate,
|
||||
realized_cap_growth_rate,
|
||||
cap_growth_rate_diff,
|
||||
market_minus_realized_cap_growth_rate,
|
||||
};
|
||||
|
||||
this.db.retain_regions(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, StoredF32};
|
||||
use brk_types::{BasisPointsSigned32, Dollars};
|
||||
use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use super::{burned, velocity};
|
||||
use crate::internal::{
|
||||
ComputedFromHeight, LazyFromHeight, LazyValueFromHeight,
|
||||
ComputedFromHeight, LazyFromHeight, LazyValueFromHeight, PercentFromHeight,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -14,10 +14,10 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
|
||||
pub circulating: LazyValueFromHeight,
|
||||
pub burned: burned::Vecs<M>,
|
||||
pub inflation: ComputedFromHeight<StoredF32, M>,
|
||||
pub inflation_rate: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub velocity: velocity::Vecs<M>,
|
||||
pub market_cap: LazyFromHeight<Dollars>,
|
||||
pub market_cap_growth_rate: ComputedFromHeight<StoredF32, M>,
|
||||
pub realized_cap_growth_rate: ComputedFromHeight<StoredF32, M>,
|
||||
pub cap_growth_rate_diff: ComputedFromHeight<StoredF32, M>,
|
||||
pub market_cap_growth_rate: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub realized_cap_growth_rate: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub market_minus_realized_cap_growth_rate: ComputedFromHeight<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
btc: ComputedFromHeight::forced_import(db, "btc_velocity", version, indexes)?,
|
||||
usd: ComputedFromHeight::forced_import(db, "usd_velocity", version, indexes)?,
|
||||
btc: ComputedFromHeight::forced_import(db, "velocity_btc", version, indexes)?,
|
||||
usd: ComputedFromHeight::forced_import(db, "velocity_usd", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user