mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 17:38:09 -07:00
global: big snapshot
This commit is contained in:
@@ -3,24 +3,19 @@ use brk_types::{Height, Indexes, Sats};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{blocks, mining, prices, scripts};
|
||||
use crate::{mining, prices, scripts};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
scripts: &scripts::Vecs,
|
||||
mining: &mining::Vecs,
|
||||
lookback: &blocks::LookbackVecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let window_starts = lookback.window_starts();
|
||||
|
||||
// 1. Compute opreturn supply - copy per-block opreturn values from scripts
|
||||
self.opreturn.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|height_vec| {
|
||||
@@ -59,12 +54,11 @@ impl Vecs {
|
||||
|
||||
// 2. Compute unspendable supply = opreturn + unclaimed_rewards + genesis (at height 0)
|
||||
// Get reference to opreturn height vec for computing unspendable
|
||||
let opreturn_height = &self.opreturn.base.sats.height;
|
||||
let unclaimed_height = &mining.rewards.unclaimed.base.sats.height;
|
||||
let opreturn_height = &self.opreturn.raw.sats.height;
|
||||
let unclaimed_height = &mining.rewards.unclaimed.raw.sats.height;
|
||||
|
||||
self.unspendable.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|height_vec| {
|
||||
|
||||
@@ -3,26 +3,29 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::AmountPerBlockCumulativeSum};
|
||||
use crate::{indexes, internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts}};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
opreturn: AmountPerBlockCumulativeSum::forced_import(
|
||||
opreturn: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"opreturn_supply",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
unspendable: AmountPerBlockCumulativeSum::forced_import(
|
||||
unspendable: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"unspendable_supply",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::AmountPerBlockCumulativeSum;
|
||||
use crate::internal::AmountPerBlockCumulativeWithSums;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub opreturn: AmountPerBlockCumulativeSum<M>,
|
||||
pub unspendable: AmountPerBlockCumulativeSum<M>,
|
||||
pub opreturn: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub unspendable: AmountPerBlockCumulativeWithSums<M>,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ impl Vecs {
|
||||
self.burned.compute(
|
||||
scripts,
|
||||
mining,
|
||||
&blocks.lookback,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
@@ -44,27 +43,16 @@ impl Vecs {
|
||||
self.velocity
|
||||
.compute(blocks, transactions, distribution, starting_indexes, exit)?;
|
||||
|
||||
// 4. Compute market cap delta (change + rate across 4 windows)
|
||||
let window_starts = blocks.lookback.window_starts();
|
||||
|
||||
self.market_cap_delta.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.market_cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// 5. market_cap_rate - realized_cap_rate per window
|
||||
// 4. market_cap_rate - realized_cap_rate per window
|
||||
let all_realized = &distribution.utxo_cohorts.all.metrics.realized;
|
||||
let mcr_arr = self.market_cap_delta.rate.0.as_array();
|
||||
let mcr_arr = self.market_cap_delta.rate.as_array();
|
||||
let diff_arr = self.market_minus_realized_cap_growth_rate.0.as_mut_array();
|
||||
|
||||
// 24h, 1w, 1y from extended; 1m from core delta
|
||||
let rcr_rates = [
|
||||
&all_realized.cap_delta_extended.rate._24h.bps.height,
|
||||
&all_realized.cap_delta_extended.rate._1w.bps.height,
|
||||
&all_realized.cap_delta.rate_1m.bps.height,
|
||||
&all_realized.cap_delta_extended.rate._1y.bps.height,
|
||||
&all_realized.cap.delta.rate._24h.bps.height,
|
||||
&all_realized.cap.delta.rate._1w.bps.height,
|
||||
&all_realized.cap.delta.rate._1m.bps.height,
|
||||
&all_realized.cap.delta.rate._1y.bps.height,
|
||||
];
|
||||
|
||||
for i in 0..4 {
|
||||
|
||||
@@ -6,9 +6,10 @@ use brk_types::Version;
|
||||
use crate::{
|
||||
cointime, distribution, indexes,
|
||||
internal::{
|
||||
FiatRollingDelta, LazyFiatPerBlock, LazyAmountPerBlock, PercentPerBlock,
|
||||
RollingWindows, finalize_db, open_db,
|
||||
CachedWindowStarts, LazyAmountPerBlock, LazyFiatPerBlock,
|
||||
LazyRollingDeltasFiatFromHeight, PercentPerBlock, RollingWindows, finalize_db, open_db,
|
||||
},
|
||||
supply::burned,
|
||||
};
|
||||
|
||||
use super::Vecs;
|
||||
@@ -22,18 +23,17 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
cointime: &cointime::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let db = open_db(parent, super::DB_NAME, 10_000_000)?;
|
||||
|
||||
let version = parent_version + VERSION;
|
||||
let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply;
|
||||
|
||||
// Circulating supply - lazy refs to distribution
|
||||
let circulating =
|
||||
LazyAmountPerBlock::identity("circulating_supply", &supply_metrics.total, version);
|
||||
|
||||
// Burned/unspendable supply - computed from scripts
|
||||
let burned = super::burned::Vecs::forced_import(&db, version, indexes)?;
|
||||
let burned = burned::Vecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
|
||||
// Inflation rate
|
||||
let inflation_rate =
|
||||
@@ -47,12 +47,13 @@ impl Vecs {
|
||||
LazyFiatPerBlock::from_computed("market_cap", version, &supply_metrics.total.cents);
|
||||
|
||||
// Market cap delta (change + rate across 4 windows)
|
||||
let market_cap_delta = FiatRollingDelta::forced_import(
|
||||
&db,
|
||||
let market_cap_delta = LazyRollingDeltasFiatFromHeight::new(
|
||||
"market_cap_delta",
|
||||
version + Version::new(3),
|
||||
&market_cap.cents.height,
|
||||
cached_starts,
|
||||
indexes,
|
||||
)?;
|
||||
);
|
||||
|
||||
let market_minus_realized_cap_growth_rate = RollingWindows::forced_import(
|
||||
&db,
|
||||
@@ -61,11 +62,8 @@ impl Vecs {
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let hodled_or_lost = LazyAmountPerBlock::identity(
|
||||
"hodled_or_lost_coins",
|
||||
&cointime.supply.vaulted,
|
||||
version,
|
||||
);
|
||||
let hodled_or_lost =
|
||||
LazyAmountPerBlock::identity("hodled_or_lost_coins", &cointime.supply.vaulted, version);
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
|
||||
@@ -4,7 +4,8 @@ use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use super::{burned, velocity};
|
||||
use crate::internal::{
|
||||
FiatRollingDelta, LazyFiatPerBlock, LazyAmountPerBlock, PercentPerBlock, RollingWindows,
|
||||
LazyFiatPerBlock, LazyAmountPerBlock, LazyRollingDeltasFiatFromHeight,
|
||||
PercentPerBlock, RollingWindows,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -18,7 +19,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub velocity: velocity::Vecs<M>,
|
||||
pub market_cap: LazyFiatPerBlock<Cents>,
|
||||
#[traversable(wrap = "market_cap", rename = "delta")]
|
||||
pub market_cap_delta: FiatRollingDelta<Cents, CentsSigned, M>,
|
||||
pub market_cap_delta: LazyRollingDeltasFiatFromHeight<Cents, CentsSigned, BasisPointsSigned32>,
|
||||
pub market_minus_realized_cap_growth_rate: RollingWindows<BasisPointsSigned32, M>,
|
||||
pub hodled_or_lost: LazyAmountPerBlock,
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Vecs {
|
||||
self.btc.height.compute_rolling_ratio(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback._1y,
|
||||
&transactions.volume.sent_sum.sats,
|
||||
&transactions.volume.sent_sum.raw.sats.height,
|
||||
&circulating_supply.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
@@ -30,7 +30,7 @@ impl Vecs {
|
||||
self.usd.height.compute_rolling_ratio(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback._1y,
|
||||
&transactions.volume.sent_sum.usd,
|
||||
&transactions.volume.sent_sum.raw.usd.height,
|
||||
&circulating_supply.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user