bitview: reorg part 4 + remove breakeven metrics

This commit is contained in:
nym21
2025-09-24 23:58:41 +02:00
parent 2279aa8f18
commit 0d5b792c57
7 changed files with 823 additions and 1643 deletions
+3 -299
View File
@@ -24,7 +24,6 @@ pub struct Vecs {
pub height_to_supply: EagerVec<Height, Sats>,
pub height_to_utxo_count: EagerVec<Height, StoredU64>,
// Single
pub dateindex_to_supply_breakeven: Option<EagerVec<DateIndex, Sats>>,
pub dateindex_to_supply_in_loss: Option<EagerVec<DateIndex, Sats>>,
pub dateindex_to_supply_in_profit: Option<EagerVec<DateIndex, Sats>>,
pub dateindex_to_unrealized_loss: Option<EagerVec<DateIndex, Dollars>>,
@@ -35,7 +34,6 @@ pub struct Vecs {
pub height_to_min_price_paid: Option<EagerVec<Height, Dollars>>,
pub height_to_realized_loss: Option<EagerVec<Height, Dollars>>,
pub height_to_realized_profit: Option<EagerVec<Height, Dollars>>,
pub height_to_supply_breakeven: Option<EagerVec<Height, Sats>>,
pub height_to_supply_in_loss: Option<EagerVec<Height, Sats>>,
pub height_to_supply_in_profit: Option<EagerVec<Height, Sats>>,
pub height_to_unrealized_loss: Option<EagerVec<Height, Dollars>>,
@@ -129,24 +127,17 @@ pub struct Vecs {
pub indexes_to_realized_profit_rel_to_realized_cap: Option<ComputedVecsFromHeight<StoredF32>>,
pub indexes_to_realized_loss_rel_to_realized_cap: Option<ComputedVecsFromHeight<StoredF32>>,
pub indexes_to_net_realized_pnl_rel_to_realized_cap: Option<ComputedVecsFromHeight<StoredF32>>,
pub height_to_supply_breakeven_value: Option<ComputedHeightValueVecs>,
pub height_to_supply_in_loss_value: Option<ComputedHeightValueVecs>,
pub height_to_supply_in_profit_value: Option<ComputedHeightValueVecs>,
pub indexes_to_supply_breakeven: Option<ComputedValueVecsFromDateIndex>,
pub indexes_to_supply_in_loss: Option<ComputedValueVecsFromDateIndex>,
pub indexes_to_supply_in_profit: Option<ComputedValueVecsFromDateIndex>,
pub height_to_supply_breakeven_rel_to_own_supply: Option<EagerVec<Height, StoredF64>>,
pub height_to_supply_in_loss_rel_to_own_supply: Option<EagerVec<Height, StoredF64>>,
pub height_to_supply_in_profit_rel_to_own_supply: Option<EagerVec<Height, StoredF64>>,
pub indexes_to_supply_breakeven_rel_to_own_supply: Option<ComputedVecsFromDateIndex<StoredF64>>,
pub indexes_to_supply_in_loss_rel_to_own_supply: Option<ComputedVecsFromDateIndex<StoredF64>>,
pub indexes_to_supply_in_profit_rel_to_own_supply: Option<ComputedVecsFromDateIndex<StoredF64>>,
pub indexes_to_supply_rel_to_circulating_supply: Option<ComputedVecsFromHeight<StoredF64>>,
pub height_to_supply_breakeven_rel_to_circulating_supply: Option<EagerVec<Height, StoredF64>>,
pub height_to_supply_in_loss_rel_to_circulating_supply: Option<EagerVec<Height, StoredF64>>,
pub height_to_supply_in_profit_rel_to_circulating_supply: Option<EagerVec<Height, StoredF64>>,
pub indexes_to_supply_breakeven_rel_to_circulating_supply:
Option<ComputedVecsFromDateIndex<StoredF64>>,
pub indexes_to_supply_in_loss_rel_to_circulating_supply:
Option<ComputedVecsFromDateIndex<StoredF64>>,
pub indexes_to_supply_in_profit_rel_to_circulating_supply:
@@ -191,16 +182,6 @@ impl Vecs {
.unwrap()
});
let dateindex_to_supply_breakeven = compute_dollars.then(|| {
EagerVec::forced_import(
db,
&suffix("supply_breakeven"),
version + Version::ZERO,
format,
)
.unwrap()
});
let dateindex_to_supply_in_loss = compute_dollars.then(|| {
EagerVec::forced_import(
db,
@@ -257,31 +238,6 @@ impl Vecs {
.unwrap()
}),
dateindex_to_supply_in_profit,
height_to_supply_breakeven: compute_dollars.then(|| {
EagerVec::forced_import(
db,
&suffix("supply_breakeven"),
version + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_supply_breakeven: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import(
db,
&suffix("supply_breakeven"),
dateindex_to_supply_breakeven
.as_ref()
.map(|v| v.boxed_clone())
.into(),
version + Version::ZERO,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)
.unwrap()
}),
dateindex_to_supply_breakeven,
height_to_supply_in_loss: compute_dollars.then(|| {
EagerVec::forced_import(
db,
@@ -1125,17 +1081,6 @@ impl Vecs {
)
.unwrap()
}),
height_to_supply_breakeven_value: compute_dollars.then(|| {
ComputedHeightValueVecs::forced_import(
db,
&suffix("supply_breakeven"),
Source::None,
version + Version::ZERO,
format,
compute_dollars,
)
.unwrap()
}),
height_to_supply_in_loss_value: compute_dollars.then(|| {
ComputedHeightValueVecs::forced_import(
db,
@@ -1158,15 +1103,6 @@ impl Vecs {
)
.unwrap()
}),
height_to_supply_breakeven_rel_to_own_supply: compute_dollars.then(|| {
EagerVec::forced_import(
db,
&suffix("supply_breakeven_rel_to_own_supply"),
version + Version::ONE,
format,
)
.unwrap()
}),
height_to_supply_in_loss_rel_to_own_supply: compute_dollars.then(|| {
EagerVec::forced_import(
db,
@@ -1185,17 +1121,6 @@ impl Vecs {
)
.unwrap()
}),
indexes_to_supply_breakeven_rel_to_own_supply: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&suffix("supply_breakeven_rel_to_own_supply"),
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
indexes_to_supply_in_loss_rel_to_own_supply: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
@@ -1229,17 +1154,6 @@ impl Vecs {
)
.unwrap()
}),
height_to_supply_breakeven_rel_to_circulating_supply: (compute_rel_to_all
&& compute_dollars)
.then(|| {
EagerVec::forced_import(
db,
&suffix("supply_breakeven_rel_to_circulating_supply"),
version + Version::ONE,
format,
)
.unwrap()
}),
height_to_supply_in_loss_rel_to_circulating_supply: (compute_rel_to_all
&& compute_dollars)
.then(|| {
@@ -1262,19 +1176,6 @@ impl Vecs {
)
.unwrap()
}),
indexes_to_supply_breakeven_rel_to_circulating_supply: (compute_rel_to_all
&& compute_dollars)
.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&suffix("supply_breakeven_rel_to_circulating_supply"),
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
indexes_to_supply_in_loss_rel_to_circulating_supply: (compute_rel_to_all
&& compute_dollars)
.then(|| {
@@ -1406,9 +1307,6 @@ impl Vecs {
self.height_to_supply_in_loss
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_supply_breakeven
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_unrealized_profit
.as_ref()
.map_or(usize::MAX, |v| v.len()),
@@ -1551,17 +1449,6 @@ impl Vecs {
.validate_computed_version_or_reset(
base_version + height_to_supply_in_loss_inner_version,
)?;
let height_to_supply_breakeven_inner_version = self
.height_to_supply_breakeven
.as_ref()
.unwrap()
.inner_version();
self.height_to_supply_breakeven
.as_mut()
.unwrap()
.validate_computed_version_or_reset(
base_version + height_to_supply_breakeven_inner_version,
)?;
let height_to_unrealized_profit_inner_version = self
.height_to_unrealized_profit
.as_ref()
@@ -1606,17 +1493,6 @@ impl Vecs {
.validate_computed_version_or_reset(
base_version + dateindex_to_supply_in_loss_inner_version,
)?;
let dateindex_to_supply_breakeven_inner_version = self
.dateindex_to_supply_breakeven
.as_ref()
.unwrap()
.inner_version();
self.dateindex_to_supply_breakeven
.as_mut()
.unwrap()
.validate_computed_version_or_reset(
base_version + dateindex_to_supply_breakeven_inner_version,
)?;
let dateindex_to_unrealized_profit_inner_version = self
.dateindex_to_unrealized_profit
.as_ref()
@@ -1790,10 +1666,6 @@ impl Vecs {
let (height_unrealized_state, date_unrealized_state) =
state.compute_unrealized_states(height_price, date_price.unwrap());
self.height_to_supply_breakeven
.as_mut()
.unwrap()
.forced_push_at(height, height_unrealized_state.supply_breakeven, exit)?;
self.height_to_supply_in_profit
.as_mut()
.unwrap()
@@ -1814,10 +1686,6 @@ impl Vecs {
if let Some(date_unrealized_state) = date_unrealized_state {
let dateindex = dateindex.unwrap();
self.dateindex_to_supply_breakeven
.as_mut()
.unwrap()
.forced_push_at(dateindex, date_unrealized_state.supply_breakeven, exit)?;
self.dateindex_to_supply_in_profit
.as_mut()
.unwrap()
@@ -1877,10 +1745,6 @@ impl Vecs {
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_supply_breakeven
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_unrealized_profit
.as_mut()
.unwrap()
@@ -1897,10 +1761,6 @@ impl Vecs {
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.dateindex_to_supply_breakeven
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.dateindex_to_unrealized_profit
.as_mut()
.unwrap()
@@ -2085,18 +1945,6 @@ impl Vecs {
.as_slice(),
exit,
)?;
self.height_to_supply_breakeven
.as_mut()
.unwrap()
.compute_sum_of_others(
starting_indexes.height,
others
.iter()
.map(|v| v.height_to_supply_breakeven.as_ref().unwrap())
.collect::<Vec<_>>()
.as_slice(),
exit,
)?;
self.height_to_unrealized_profit
.as_mut()
.unwrap()
@@ -2145,18 +1993,6 @@ impl Vecs {
.as_slice(),
exit,
)?;
self.dateindex_to_supply_breakeven
.as_mut()
.unwrap()
.compute_sum_of_others(
starting_indexes.dateindex,
others
.iter()
.map(|v| v.dateindex_to_supply_breakeven.as_ref().unwrap())
.collect::<Vec<_>>()
.as_slice(),
exit,
)?;
self.dateindex_to_unrealized_profit
.as_mut()
.unwrap()
@@ -2588,15 +2424,6 @@ impl Vecs {
exit,
Some(self.dateindex_to_supply_in_loss.as_ref().unwrap()),
)?;
self.indexes_to_supply_breakeven
.as_mut()
.unwrap()
.compute_rest(
price,
starting_indexes,
exit,
Some(self.dateindex_to_supply_breakeven.as_ref().unwrap()),
)?;
self.indexes_to_unrealized_profit
.as_mut()
.unwrap()
@@ -3109,15 +2936,6 @@ impl Vecs {
Ok(())
})?;
self.height_to_supply_breakeven_value
.as_mut()
.unwrap()
.compute_rest(
price,
starting_indexes,
exit,
Some(self.height_to_supply_breakeven.as_ref().unwrap()),
)?;
self.height_to_supply_in_loss_value
.as_mut()
.unwrap()
@@ -3136,19 +2954,6 @@ impl Vecs {
exit,
Some(self.height_to_supply_in_profit.as_ref().unwrap()),
)?;
self.height_to_supply_breakeven_rel_to_own_supply
.as_mut()
.unwrap()
.compute_percentage(
starting_indexes.height,
&self
.height_to_supply_breakeven_value
.as_ref()
.unwrap()
.bitcoin,
&self.height_to_supply_value.bitcoin,
exit,
)?;
self.height_to_supply_in_loss_rel_to_own_supply
.as_mut()
.unwrap()
@@ -3175,24 +2980,6 @@ impl Vecs {
&self.height_to_supply_value.bitcoin,
exit,
)?;
self.indexes_to_supply_breakeven_rel_to_own_supply
.as_mut()
.unwrap()
.compute_all(starting_indexes, exit, |v| {
v.compute_percentage(
starting_indexes.dateindex,
self.indexes_to_supply_breakeven
.as_ref()
.unwrap()
.bitcoin
.dateindex
.as_ref()
.unwrap(),
self.indexes_to_supply.bitcoin.dateindex.as_ref().unwrap(),
exit,
)?;
Ok(())
})?;
self.indexes_to_supply_in_loss_rel_to_own_supply
.as_mut()
.unwrap()
@@ -3283,20 +3070,11 @@ impl Vecs {
Ok(())
})?;
if let Some(height_to_supply_breakeven_rel_to_circulating_supply) = self
.height_to_supply_breakeven_rel_to_circulating_supply
if self
.height_to_supply_in_profit_rel_to_circulating_supply
.as_mut()
.is_some()
{
height_to_supply_breakeven_rel_to_circulating_supply.compute_percentage(
starting_indexes.height,
&self
.height_to_supply_breakeven_value
.as_ref()
.unwrap()
.bitcoin,
height_to_supply,
exit,
)?;
self.height_to_supply_in_loss_rel_to_circulating_supply
.as_mut()
.unwrap()
@@ -3323,24 +3101,6 @@ impl Vecs {
height_to_supply,
exit,
)?;
self.indexes_to_supply_breakeven_rel_to_circulating_supply
.as_mut()
.unwrap()
.compute_all(starting_indexes, exit, |v| {
v.compute_percentage(
starting_indexes.dateindex,
self.indexes_to_supply_breakeven
.as_ref()
.unwrap()
.bitcoin
.dateindex
.as_ref()
.unwrap(),
dateindex_to_supply,
exit,
)?;
Ok(())
})?;
self.indexes_to_supply_in_loss_rel_to_circulating_supply
.as_mut()
.unwrap()
@@ -3555,13 +3315,6 @@ impl Vecs {
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.dateindex_to_supply_breakeven
.iter()
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.dateindex_to_supply_in_loss
@@ -3695,34 +3448,6 @@ impl Vecs {
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.height_to_supply_breakeven
.iter()
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.height_to_supply_breakeven_rel_to_circulating_supply
.iter()
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.height_to_supply_breakeven_rel_to_own_supply
.iter()
.map(|v| v as &dyn AnyCollectableVec),
),
);
iter = Box::new(
iter.chain(
self.height_to_supply_breakeven_value
.iter()
.flat_map(|v| v.iter_any_collectable()),
),
);
iter = Box::new(iter.chain(self.height_to_supply_half_value.iter_any_collectable()));
iter = Box::new(
iter.chain(
@@ -4064,27 +3789,6 @@ impl Vecs {
),
);
iter = Box::new(iter.chain(self.indexes_to_supply.iter_any_collectable()));
iter = Box::new(
iter.chain(
self.indexes_to_supply_breakeven
.iter()
.flat_map(|v| v.iter_any_collectable()),
),
);
iter = Box::new(
iter.chain(
self.indexes_to_supply_breakeven_rel_to_circulating_supply
.iter()
.flat_map(|v| v.iter_any_collectable()),
),
);
iter = Box::new(
iter.chain(
self.indexes_to_supply_breakeven_rel_to_own_supply
.iter()
.flat_map(|v| v.iter_any_collectable()),
),
);
iter = Box::new(iter.chain(self.indexes_to_supply_half.iter_any_collectable()));
iter = Box::new(
iter.chain(
@@ -257,10 +257,11 @@ impl CohortState {
let update_state =
|price: Dollars, current_price: Dollars, sats: Sats, state: &mut UnrealizedState| {
match price.cmp(&current_price) {
Ordering::Less => {
let cmp = price.cmp(&current_price);
match cmp {
Ordering::Equal | Ordering::Less => {
state.supply_in_profit += sats;
if price > Dollars::ZERO && current_price > Dollars::ZERO {
if !cmp.is_eq() && price > Dollars::ZERO && current_price > Dollars::ZERO {
let diff = current_price.checked_sub(price).unwrap();
// Add back once in a while to verify, but generally not needed
// if diff <= Dollars::ZERO {
@@ -282,9 +283,6 @@ impl CohortState {
state.unrealized_loss += diff * sats;
}
}
Ordering::Equal => {
state.supply_breakeven += sats;
}
}
};
@@ -3,7 +3,6 @@ use brk_structs::{Dollars, Sats};
#[derive(Debug, Default, Clone)]
pub struct UnrealizedState {
pub supply_in_profit: Sats,
pub supply_breakeven: Sats,
pub supply_in_loss: Sats,
pub unrealized_profit: Dollars,
pub unrealized_loss: Dollars,
@@ -12,7 +11,6 @@ pub struct UnrealizedState {
impl UnrealizedState {
pub const NAN: Self = Self {
supply_in_profit: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::NAN,
unrealized_loss: Dollars::NAN,
@@ -20,7 +18,6 @@ impl UnrealizedState {
pub const ZERO: Self = Self {
supply_in_profit: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::ZERO,
unrealized_loss: Dollars::ZERO,
File diff suppressed because it is too large Load Diff
-1
View File
@@ -320,7 +320,6 @@ export const serdeUnit = {
v === "sent" ||
v === "annualized_volume" ||
v.endsWith("supply_half") ||
v.endsWith("supply_breakeven") ||
v.endsWith("supply_in_profit") ||
v.endsWith("supply_in_loss") ||
v.endsWith("stack") ||
+1 -1
View File
@@ -1,6 +1,6 @@
/**
*
* @import { Valued, SingleValueData, CandlestickData, OHLCTuple, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions, CreateChartElement, Chart } from "./core/chart"
* @import { Valued, SingleValueData, CandlestickData, OHLCTuple, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions, CreateChartElement, Chart } from "./core/chart"
*
* @import * as _ from "./packages/leeoniya-ufuzzy/1.0.19/dist/uFuzzy.d.ts"
*
@@ -95,18 +95,22 @@ export function init({
function createCube() {
const cubeElement = window.document.createElement("div");
cubeElement.classList.add("cube");
const rightFaceElement = window.document.createElement("div");
rightFaceElement.classList.add("face");
rightFaceElement.classList.add("right");
cubeElement.append(rightFaceElement);
const leftFaceElement = window.document.createElement("div");
leftFaceElement.classList.add("face");
leftFaceElement.classList.add("left");
cubeElement.append(leftFaceElement);
const topFaceElement = window.document.createElement("div");
topFaceElement.classList.add("face");
topFaceElement.classList.add("top");
cubeElement.append(topFaceElement);
return {
cubeElement,
leftFaceElement,