global: utxos part 6

This commit is contained in:
nym21
2025-05-23 17:52:01 +02:00
parent e002a61a19
commit 2883f88de6
23 changed files with 3351 additions and 941 deletions
Generated
+46 -66
View File
@@ -127,12 +127,12 @@ dependencies = [
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
version = "3.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa"
dependencies = [
"anstyle",
"once_cell",
"once_cell_polyfill",
"windows-sys 0.59.0",
]
@@ -845,21 +845,6 @@ dependencies = [
"libc",
]
[[package]]
name = "crc"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675"
dependencies = [
"crc-catalog",
]
[[package]]
name = "crc-catalog"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]]
name = "crc32fast"
version = "1.4.2"
@@ -1113,7 +1098,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
dependencies = [
"libc",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -1399,9 +1384,9 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.11"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2"
checksum = "cf9f1e950e0d9d1d3c47184416723cf29c0d1f93bd8cccf37e4beb6b44f31710"
dependencies = [
"bytes",
"futures-util",
@@ -1522,7 +1507,7 @@ dependencies = [
"portable-atomic",
"portable-atomic-util",
"serde",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -1595,6 +1580,26 @@ version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "liblzma"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66352d7a8ac12d4877b6e6ea5a9b7650ee094257dc40889955bea5bc5b08c1d0"
dependencies = [
"liblzma-sys",
]
[[package]]
name = "liblzma-sys"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5839bad90c3cc2e0b8c4ed8296b80e86040240f81d46b9c0e9bc8dd51ddd3af1"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "libz-rs-sys"
version = "0.5.0"
@@ -1656,27 +1661,6 @@ version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5"
[[package]]
name = "lzma-rs"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
dependencies = [
"byteorder",
"crc",
]
[[package]]
name = "lzma-sys"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "matchit"
version = "0.8.4"
@@ -1805,6 +1789,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "outref"
version = "0.5.2"
@@ -2527,7 +2517,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -2554,9 +2544,9 @@ dependencies = [
[[package]]
name = "rustversion"
version = "1.0.20"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
[[package]]
name = "ryu"
@@ -2882,7 +2872,7 @@ dependencies = [
"getrandom 0.3.3",
"once_cell",
"rustix",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -3315,9 +3305,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "windows-core"
version = "0.61.1"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46ec44dc15085cea82cf9c78f85a9114c463a369786585ad2882d1ff0b0acf40"
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [
"windows-implement",
"windows-interface",
@@ -3356,18 +3346,18 @@ checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
[[package]]
name = "windows-result"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b895b5356fc36103d0f64dd1e94dfa7ac5633f1c9dd6e80fe9ec4adef69e09d"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.4.1"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a7ab927b2637c19b3dbe0965e75d8f2d30bdd697a1516191cad2ec4df8fb28a"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [
"windows-link",
]
@@ -3478,15 +3468,6 @@ version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
[[package]]
name = "xz2"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
dependencies = [
"lzma-sys",
]
[[package]]
name = "zerocopy"
version = "0.8.25"
@@ -3529,9 +3510,9 @@ dependencies = [
[[package]]
name = "zip"
version = "3.0.0"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308"
checksum = "153a6fff49d264c4babdcfa6b4d534747f520e56e8f0f384f3b808c4b64cc1fd"
dependencies = [
"aes",
"arbitrary",
@@ -3543,12 +3524,11 @@ dependencies = [
"getrandom 0.3.3",
"hmac",
"indexmap 2.9.0",
"lzma-rs",
"liblzma",
"memchr",
"pbkdf2",
"sha1",
"time",
"xz2",
"zeroize",
"zopfli",
"zstd",
+5 -7
View File
@@ -20,14 +20,14 @@ impl Add<BlockState> for BlockState {
}
impl AddAssign<&BlockState> for BlockState {
fn add_assign(&mut self, rhs: &BlockState) {
fn add_assign(&mut self, rhs: &Self) {
self.supply += &rhs.supply;
}
}
impl SubAssign for BlockState {
fn sub_assign(&mut self, rhs: Self) {
self.supply -= rhs.supply;
impl SubAssign<&BlockState> for BlockState {
fn sub_assign(&mut self, rhs: &Self) {
self.supply -= &rhs.supply;
}
}
@@ -56,9 +56,7 @@ impl<'a> From<ReceivedBlockStateData<'a>> for BlockState {
.for_each(|spendable_block_state| {
block_state.supply += &spendable_block_state.0;
});
block_state.supply.value += received.unspendable.unknown.0.value;
block_state.supply.utxos +=
received.unspendable.empty.0.utxos + received.unspendable.unknown.0.utxos;
block_state.supply.utxos += received.unspendable.empty.0.utxos;
block_state
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ use brk_core::{Bitcoin, CheckedSub, Dollars};
use super::SupplyState;
// Vecs ? probably
#[derive(Default, Clone)]
#[derive(Debug, Default, Clone)]
pub struct CohortState {
pub supply: SupplyState,
pub realized_cap: Option<Dollars>,
@@ -18,7 +18,7 @@ impl CohortState {
}
}
pub fn decrement(&mut self, supply_state: SupplyState, price: Option<Dollars>) {
pub fn decrement(&mut self, supply_state: &SupplyState, price: Option<Dollars>) {
if let Some(realized_cap) = self.realized_cap.as_mut() {
*realized_cap = realized_cap
.checked_sub(price.unwrap() * Bitcoin::from(supply_state.value))
@@ -15,6 +15,7 @@ pub struct OutputsBySpendableType<T> {
pub p2wsh: T,
pub p2tr: T,
pub p2a: T,
pub unknown: T,
}
impl<T> OutputsBySpendableType<T> {
@@ -29,6 +30,7 @@ impl<T> OutputsBySpendableType<T> {
OutputType::P2WSH => &self.p2wsh,
OutputType::P2TR => &self.p2tr,
OutputType::P2A => &self.p2a,
OutputType::Unknown => &self.unknown,
_ => unreachable!(),
}
}
@@ -44,11 +46,12 @@ impl<T> OutputsBySpendableType<T> {
OutputType::P2WSH => &mut self.p2wsh,
OutputType::P2TR => &mut self.p2tr,
OutputType::P2A => &mut self.p2a,
OutputType::Unknown => &mut self.unknown,
_ => unreachable!(),
}
}
pub fn as_vec(&self) -> [&T; 9] {
pub fn as_vec(&self) -> [&T; 10] {
[
&self.p2pk65,
&self.p2pk33,
@@ -59,10 +62,11 @@ impl<T> OutputsBySpendableType<T> {
&self.p2wsh,
&self.p2tr,
&self.p2a,
&self.unknown,
]
}
pub fn as_mut_vec(&mut self) -> [&mut T; 9] {
pub fn as_mut_vec(&mut self) -> [&mut T; 10] {
[
&mut self.p2pk65,
&mut self.p2pk33,
@@ -73,10 +77,11 @@ impl<T> OutputsBySpendableType<T> {
&mut self.p2wsh,
&mut self.p2tr,
&mut self.p2a,
&mut self.unknown,
]
}
pub fn as_typed_vec(&self) -> [(OutputType, &T); 9] {
pub fn as_typed_vec(&self) -> [(OutputType, &T); 10] {
[
(OutputType::P2PK65, &self.p2pk65),
(OutputType::P2PK33, &self.p2pk33),
@@ -87,12 +92,13 @@ impl<T> OutputsBySpendableType<T> {
(OutputType::P2WSH, &self.p2wsh),
(OutputType::P2TR, &self.p2tr),
(OutputType::P2A, &self.p2a),
(OutputType::Unknown, &self.unknown),
]
}
}
impl<T> OutputsBySpendableType<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 9] {
pub fn vecs(&self) -> [&T; 10] {
[
&self.p2pk65.1,
&self.p2pk33.1,
@@ -103,6 +109,7 @@ impl<T> OutputsBySpendableType<(OutputFilter, T)> {
&self.p2wsh.1,
&self.p2tr.1,
&self.p2a.1,
&self.unknown.1,
]
}
}
@@ -119,6 +126,7 @@ impl<T> From<OutputsBySpendableType<T>> for OutputsBySpendableType<(OutputFilter
p2wsh: (OutputFilter::Type(OutputType::P2WSH), value.p2wsh),
p2tr: (OutputFilter::Type(OutputType::P2TR), value.p2tr),
p2a: (OutputFilter::Type(OutputType::P2A), value.p2a),
unknown: (OutputFilter::Type(OutputType::Unknown), value.unknown),
}
}
}
@@ -37,9 +37,9 @@ impl<T> OutputsByType<T> {
OutputType::P2WSH => &mut self.spendable.p2wsh,
OutputType::P2TR => &mut self.spendable.p2tr,
OutputType::P2A => &mut self.spendable.p2a,
OutputType::Unknown => &mut self.spendable.unknown,
OutputType::OpReturn => &mut self.unspendable.op_return,
OutputType::Empty => &mut self.unspendable.empty,
OutputType::Unknown => &mut self.unspendable.unknown,
}
}
@@ -4,7 +4,7 @@
pub struct OutputsByUnspendableType<T> {
pub op_return: T,
pub empty: T,
pub unknown: T,
// pub unknown: T,
}
impl<T> OutputsByUnspendableType<T> {
@@ -33,8 +33,12 @@ impl<T> OutputsByUnspendableType<T> {
// .collect::<Vec<_>>()
// }
pub fn as_vec(&self) -> [&T; 3] {
[&self.op_return, &self.empty, &self.unknown]
pub fn as_vec(&self) -> [&T; 2] {
[
&self.op_return,
&self.empty,
// &self.unknown
]
}
// pub fn as_mut_vec(&mut self) -> [&mut T; 3] {
@@ -2,7 +2,7 @@ use std::ops::Range;
use brk_core::{HalvingEpoch, OutputType, Sats};
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum OutputFilter {
All,
To(usize),
+95 -94
View File
@@ -37,13 +37,13 @@ pub struct Outputs<T> {
pub all: T,
pub by_term: OutputsByTerm<T>,
// pub by_up_to: OutputsByUpTo<T>,
// pub by_from: OutputsByFrom<T>,
pub by_from: OutputsByFrom<T>,
// pub by_range: OutputsByRange<T>,
// pub by_epoch: OutputsByEpoch<T>,
// pub by_size: OutputsBySize<T>,
pub by_epoch: OutputsByEpoch<T>,
pub by_size: OutputsBySize<T>,
// // Needs whole UTXO set, TODO later
// // pub by_value: OutputsByValue<T>,
// pub by_spendable_type: OutputsBySpendableType<T>,
pub by_spendable_type: OutputsBySpendableType<T>,
}
impl<T> Outputs<T> {
@@ -52,12 +52,12 @@ impl<T> Outputs<T> {
.into_iter()
.chain(self.by_term.as_mut_vec())
// .chain(self.by_up_to.as_mut_vec())
// .chain(self.by_from.as_mut_vec())
.chain(self.by_from.as_mut_vec())
// .chain(self.by_range.as_mut_vec())
// .chain(self.by_epoch.as_mut_vec())
// .chain(self.by_size.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
.chain(self.by_size.as_mut_vec())
// // .chain(self.by_value.as_mut_vec())
// .chain(self.by_spendable_type.as_mut_vec())
.chain(self.by_spendable_type.as_mut_vec())
.collect::<Vec<_>>()
}
}
@@ -73,9 +73,9 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
self.by_term
.as_mut_vec()
.into_par_iter()
// .chain(self.by_up_to.as_mut_vec())
// .chain(self.by_from.as_mut_vec())
// .chain(self.by_range.as_mut_vec())
// .chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
// .chain(self.by_range.as_mut_vec())
.for_each(|(filter, v)| {
let state = &mut v.state;
@@ -107,7 +107,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
if is && !was {
state.increment(&block_state.supply, block_state.price);
} else if was && !is {
state.decrement(block_state.supply.clone(), block_state.price);
state.decrement(&block_state.supply, block_state.price);
}
ControlFlow::Continue(())
@@ -124,10 +124,10 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.by_term
.as_mut_vec()
.into_iter()
// .chain(self.by_up_to.as_mut_vec())
// .chain(self.by_from.as_mut_vec())
// .chain(self.by_range.as_mut_vec())
// .chain(self.by_epoch.as_mut_vec())
// .chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
// .chain(self.by_range.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
.collect::<Vec<_>>();
let last_timestamp = chain_state.last().unwrap().timestamp;
@@ -143,41 +143,41 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.timestamp
.difference_in_days_between(last_timestamp);
self.all.1.state.decrement(supply_state.clone(), price);
self.all.1.state.decrement(&supply_state, price);
// by_spendable_type.as_typed_vec().into_iter().for_each(
// |(output_type, (supply_state, _))| {
// self.by_spendable_type
// .get_mut(output_type)
// .1
// .state
// .decrement(supply_state.clone(), price)
// },
// );
by_spendable_type.as_typed_vec().into_iter().for_each(
|(output_type, (supply_state, _))| {
self.by_spendable_type
.get_mut(output_type)
.1
.state
.decrement(supply_state, price)
},
);
// by_spendable_type
// .as_vec()
// .into_iter()
// .flat_map(|(_, sats_received)| sats_received.iter())
// .for_each(|sats| {
// let sats = *sats;
// self.by_size
// .as_mut_vec()
// .iter_mut()
// .filter(|(filter, _)| match filter {
// OutputFilter::Size(range) => range.contains(&sats),
// _ => unreachable!(),
// })
// .for_each(|(_, vec)| {
// vec.state.decrement(
// SupplyState {
// utxos: 1,
// value: sats,
// },
// price,
// );
// });
// });
by_spendable_type
.as_vec()
.into_iter()
.flat_map(|(_, sats_received)| sats_received.iter())
.for_each(|sats| {
let sats = *sats;
self.by_size
.as_mut_vec()
.iter_mut()
.filter(|(filter, _)| match filter {
OutputFilter::Size(range) => range.contains(&sats),
_ => unreachable!(),
})
.for_each(|(_, vec)| {
vec.state.decrement(
&SupplyState {
utxos: 1,
value: sats,
},
price,
);
});
});
time_based_vecs
.iter_mut()
@@ -189,7 +189,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
_ => unreachable!(),
})
.for_each(|(_, vecs)| {
vecs.state.decrement(supply_state.clone(), price);
vecs.state.decrement(&supply_state, price);
});
});
}
@@ -205,7 +205,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
[
&mut self.all.1,
&mut self.by_term.short.1,
// &mut self.by_epoch.mut_vec_from_height(height).1,
&mut self.by_epoch.mut_vec_from_height(height).1,
// Skip from and range as can't receive in the past
]
.into_iter()
@@ -214,43 +214,44 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
v.state.increment(&supply_state, price);
});
// let mut by_size = self.by_size.as_mut_vec();
let mut by_size = self.by_size.as_mut_vec();
// received
// .spendable
// .as_vec()
// .into_iter()
// .flat_map(|(_, sats_received)| sats_received.iter())
// .for_each(|sats| {
// let sats = *sats;
// by_size
// .iter_mut()
// .filter(|(filter, _)| match filter {
// OutputFilter::Size(range) => range.contains(&sats),
// _ => unreachable!(),
// })
// .for_each(|(_, vec)| {
// vec.state.increment(
// &SupplyState {
// utxos: 1,
// value: sats,
// },
// price,
// );
// });
// });
received
.spendable
.as_vec()
.into_iter()
.flat_map(|(_, sats_received)| sats_received.iter())
.for_each(|sats| {
let sats = *sats;
// self.by_spendable_type
// .as_mut_vec()
// .into_iter()
// .for_each(|(filter, vecs)| {
// let output_type = match filter {
// OutputFilter::Type(output_type) => *output_type,
// _ => unreachable!(),
// };
// vecs.state
// .increment(&received.spendable.get(output_type).0, price)
// });
by_size
.iter_mut()
.filter(|(filter, _)| match filter {
OutputFilter::Size(range) => range.contains(&sats),
_ => unreachable!(),
})
.for_each(|(_, vec)| {
vec.state.increment(
&SupplyState {
utxos: 1,
value: sats,
},
price,
);
});
});
self.by_spendable_type
.as_mut_vec()
.into_iter()
.for_each(|(filter, vecs)| {
let output_type = match filter {
OutputFilter::Type(output_type) => *output_type,
_ => unreachable!(),
};
vecs.state
.increment(&received.spendable.get(output_type).0, price)
});
}
}
@@ -260,12 +261,12 @@ impl<T> Outputs<(OutputFilter, T)> {
.into_iter()
.chain(self.by_term.vecs())
// .chain(self.by_up_to.vecs())
// .chain(self.by_from.vecs())
.chain(self.by_from.vecs())
// .chain(self.by_range.vecs())
// .chain(self.by_epoch.vecs())
// .chain(self.by_size.vecs())
.chain(self.by_epoch.vecs())
.chain(self.by_size.vecs())
// // .chain(self.by_value.vecs())
// .chain(self.by_spendable_type.vecs())
.chain(self.by_spendable_type.vecs())
.collect::<Vec<_>>()
}
}
@@ -276,13 +277,13 @@ impl<T> From<Outputs<T>> for Outputs<(OutputFilter, T)> {
all: (OutputFilter::All, value.all),
by_term: OutputsByTerm::from(value.by_term),
// by_up_to: OutputsByUpTo::from(value.by_up_to),
// by_from: OutputsByFrom::from(value.by_from),
by_from: OutputsByFrom::from(value.by_from),
// by_range: OutputsByRange::from(value.by_range),
// by_epoch: OutputsByEpoch::from(value.by_epoch),
// by_size: OutputsBySize::from(value.by_size),
by_epoch: OutputsByEpoch::from(value.by_epoch),
by_size: OutputsBySize::from(value.by_size),
// // Needs whole UTXO set, TODO later
// // by_value: OutputsByValue<T>,
// by_spendable_type: OutputsBySpendableType::from(value.by_spendable_type),
by_spendable_type: OutputsBySpendableType::from(value.by_spendable_type),
}
}
}
+2 -2
View File
@@ -27,8 +27,8 @@ impl AddAssign<&SupplyState> for SupplyState {
}
}
impl SubAssign for SupplyState {
fn sub_assign(&mut self, rhs: Self) {
impl SubAssign<&SupplyState> for SupplyState {
fn sub_assign(&mut self, rhs: &Self) {
self.utxos = self.utxos.checked_sub(rhs.utxos).unwrap();
self.value = self.value.checked_sub(rhs.value).unwrap();
}
@@ -103,9 +103,7 @@ where
)?;
let height: Option<&EagerVec<Height, T>> = None;
self.compute_rest(indexes, starting_indexes, exit, height)?;
Ok(())
self.compute_rest(indexes, starting_indexes, exit, height)
}
pub fn compute_rest(
@@ -18,7 +18,7 @@ use super::{ComputedVecsFromDateIndex, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct ComputedRatioVecsFromDateIndex {
pub price: ComputedVecsFromDateIndex<Dollars>,
pub price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio: ComputedVecsFromDateIndex<StoredF32>,
pub ratio_sma: ComputedVecsFromDateIndex<StoredF32>,
@@ -60,19 +60,22 @@ impl ComputedRatioVecsFromDateIndex {
pub fn forced_import(
path: &Path,
name: &str,
// _compute_source: bool,
compute_source: bool,
version: Version,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
Ok(Self {
price: ComputedVecsFromDateIndex::forced_import(
path,
name,
VERSION + version,
compressed,
options,
)?,
price: compute_source.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
name,
VERSION + version,
compressed,
options,
)
.unwrap()
}),
ratio: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio"),
@@ -300,7 +303,7 @@ impl ComputedRatioVecsFromDateIndex {
})
}
pub fn compute<F>(
pub fn compute_all<F>(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
@@ -319,8 +322,34 @@ impl ComputedRatioVecsFromDateIndex {
) -> Result<()>,
{
self.price
.as_mut()
.unwrap()
.compute(indexer, indexes, starting_indexes, exit, compute)?;
let date_to_price_opt: Option<&EagerVec<DateIndex, Dollars>> = None;
self.compute_rest(
indexer,
indexes,
fetched,
starting_indexes,
exit,
date_to_price_opt,
)
}
pub fn compute_rest(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: &fetched::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
date_to_price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> color_eyre::Result<()> {
let date_to_price = date_to_price_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
});
let closes = &fetched.timeindexes_to_close.dateindex;
self.ratio.compute(
@@ -329,7 +358,7 @@ impl ComputedRatioVecsFromDateIndex {
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
let mut price = self.price.dateindex.into_iter();
let mut price = date_to_price.iter();
v.compute_transform(
starting_indexes.dateindex,
closes,
@@ -590,6 +619,10 @@ impl ComputedRatioVecsFromDateIndex {
self.ratio_m3sd
.compute_rest(indexes, starting_indexes, exit)?;
let date_to_price = date_to_price_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
});
self.ratio_p99_as_price.compute(
indexer,
indexes,
@@ -599,7 +632,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p99.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -618,7 +651,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p99_5.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -637,7 +670,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p99_9.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -656,7 +689,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p1.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -675,7 +708,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p0_5.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -694,7 +727,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p0_1.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -713,7 +746,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p1sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -732,7 +765,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p2sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -751,7 +784,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_p3sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -770,7 +803,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_m1sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -789,7 +822,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_m2sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -808,7 +841,7 @@ impl ComputedRatioVecsFromDateIndex {
let mut iter = self.ratio_m3sd.dateindex.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&self.price.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
(i, price * multiplier)
@@ -862,7 +895,7 @@ impl ComputedRatioVecsFromDateIndex {
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
[
self.price.vecs(),
self.price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio.vecs(),
self.ratio_sma.vecs(),
self.ratio_1w_sma.vecs(),
+14 -1
View File
@@ -209,6 +209,7 @@ impl Vecs {
indexes_to_1w_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"1w_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -216,6 +217,7 @@ impl Vecs {
indexes_to_8d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"8d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -223,6 +225,7 @@ impl Vecs {
indexes_to_13d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"13d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -230,6 +233,7 @@ impl Vecs {
indexes_to_21d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"21d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -237,6 +241,7 @@ impl Vecs {
indexes_to_1m_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"1m_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -244,6 +249,7 @@ impl Vecs {
indexes_to_34d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"34d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -251,6 +257,7 @@ impl Vecs {
indexes_to_55d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"55d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -258,6 +265,7 @@ impl Vecs {
indexes_to_89d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"89d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -265,6 +273,7 @@ impl Vecs {
indexes_to_144d_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"144d_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -272,6 +281,7 @@ impl Vecs {
indexes_to_1y_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"1y_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -279,6 +289,7 @@ impl Vecs {
indexes_to_2y_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"2y_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -286,6 +297,7 @@ impl Vecs {
indexes_to_200w_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"200w_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -293,6 +305,7 @@ impl Vecs {
indexes_to_4y_sma: ComputedRatioVecsFromDateIndex::forced_import(
path,
"4y_sma",
true,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
@@ -1622,7 +1635,7 @@ impl Vecs {
.into_iter()
.for_each(|(vecs, sma)| {
s.spawn(move || -> color_eyre::Result<()> {
vecs.compute(
vecs.compute_all(
indexer,
indexes,
fetched,
+11 -11
View File
@@ -25,7 +25,7 @@ pub struct Vecs {
pub mining: mining::Vecs,
pub market: market::Vecs,
pub transactions: transactions::Vecs,
// pub utxos: utxos::Vecs,
pub utxos: utxos::Vecs,
pub fetched: Option<fetched::Vecs>,
}
@@ -49,7 +49,7 @@ impl Vecs {
mining: mining::Vecs::forced_import(path, computation, compressed)?,
constants: constants::Vecs::forced_import(path, computation, compressed)?,
market: market::Vecs::forced_import(path, computation, compressed)?,
// utxos: utxos::Vecs::forced_import(path, computation, compressed, fetched.as_ref())?,
utxos: utxos::Vecs::forced_import(path, computation, compressed, fetched.as_ref())?,
transactions: transactions::Vecs::forced_import(
path,
indexer,
@@ -110,14 +110,14 @@ impl Vecs {
)?;
}
// self.utxos.compute(
// indexer,
// &self.indexes,
// &self.transactions,
// self.fetched.as_ref(),
// &starting_indexes,
// exit,
// )?;
self.utxos.compute(
indexer,
&self.indexes,
&self.transactions,
self.fetched.as_ref(),
&starting_indexes,
exit,
)?;
Ok(())
}
@@ -130,7 +130,7 @@ impl Vecs {
self.mining.vecs(),
self.market.vecs(),
self.transactions.vecs(),
// self.utxos.vecs(),
self.utxos.vecs(),
self.fetched.as_ref().map_or(vec![], |v| v.vecs()),
]
.into_iter()
+115 -26
View File
@@ -12,7 +12,8 @@ use crate::{
vecs::{
Indexes, fetched,
grouped::{
ComputedValueVecsFromHeight, ComputedVecsFromHeight, StorableVecGeneatorOptions,
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
StorableVecGeneatorOptions,
},
indexes,
},
@@ -30,6 +31,9 @@ pub struct Vecs {
pub indexes_to_supply: ComputedValueVecsFromHeight,
pub height_to_utxo_count: EagerVec<Height, StoredUsize>,
pub indexes_to_utxo_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_realized_price: Option<ComputedVecsFromHeight<Dollars>>,
pub indexes_to_realized_price_extra: Option<ComputedRatioVecsFromDateIndex>,
}
impl Vecs {
@@ -38,6 +42,7 @@ impl Vecs {
cohort_name: Option<&str>,
_computation: Computation,
compressed: Compressed,
version: Version,
fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
@@ -48,15 +53,20 @@ impl Vecs {
let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}"));
let mut state = CohortState::default();
if compute_dollars {
state.realized_cap = Some(Dollars::ZERO);
}
Ok(Self {
starting_height: Height::ZERO,
state: CohortState::default(),
state,
height_to_realized_cap: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("realized_cap"),
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
)
.unwrap()
@@ -66,7 +76,7 @@ impl Vecs {
path,
&suffix("realized_cap"),
false,
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)
@@ -75,14 +85,14 @@ impl Vecs {
height_to_supply: EagerVec::forced_import(
path,
&suffix("supply"),
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
)?,
indexes_to_supply: ComputedValueVecsFromHeight::forced_import(
path,
&suffix("supply"),
false,
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
compute_dollars,
@@ -90,22 +100,45 @@ impl Vecs {
height_to_utxo_count: EagerVec::forced_import(
path,
&suffix("utxo_count"),
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
)?,
indexes_to_utxo_count: ComputedVecsFromHeight::forced_import(
path,
&suffix("utxo_count"),
false,
VERSION + Version::ZERO,
VERSION + Version::ZERO + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
indexes_to_realized_price: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_price"),
true,
VERSION + Version::ZERO + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)
.unwrap()
}),
indexes_to_realized_price_extra: compute_dollars.then(|| {
ComputedRatioVecsFromDateIndex::forced_import(
path,
&suffix("realized_price"),
false,
VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)
.unwrap()
}),
})
}
pub fn init(&mut self, starting_indexes: &Indexes) -> Height {
self.starting_height = [
pub fn starting_height(&self) -> Height {
[
self.height_to_supply.len(),
self.height_to_utxo_count.len(),
self.height_to_realized_cap
@@ -116,29 +149,33 @@ impl Vecs {
.map(Height::from)
.min()
.unwrap()
.min(starting_indexes.height);
}
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
if let Some(prev_height) = self.starting_height.checked_sub(Height::new(1)) {
self.state.supply.value = self
.height_to_supply
.into_iter()
.unwrap_get_inner(prev_height);
self.state.supply.utxos = *self
.height_to_utxo_count
.into_iter()
.unwrap_get_inner(prev_height);
pub fn init(&mut self, starting_height: Height) {
if starting_height > self.starting_height() {
unreachable!()
}
self.starting_height = starting_height;
if let Some(prev_height) = starting_height.checked_sub(Height::new(1)) {
self.state.supply.value = self
.height_to_supply
.into_iter()
.unwrap_get_inner(prev_height);
self.state.supply.utxos = *self
.height_to_utxo_count
.into_iter()
.unwrap_get_inner(prev_height);
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
self.state.realized_cap = Some(
height_to_realized_cap
.into_iter()
.unwrap_get_inner(prev_height),
);
} else {
self.state.realized_cap = Some(Dollars::ZERO);
}
}
self.starting_height
}
pub fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
@@ -157,10 +194,15 @@ impl Vecs {
base_version + height_to_realized_cap.inner_version(),
)?;
}
Ok(())
}
pub fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()> {
if self.starting_height > height {
return Ok(());
}
self.height_to_supply
.forced_push_at(height, self.state.supply.value, exit)?;
@@ -173,7 +215,10 @@ impl Vecs {
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
height_to_realized_cap.forced_push_at(
height,
self.state.realized_cap.unwrap(),
self.state.realized_cap.unwrap_or_else(|| {
dbg!(&self.state);
panic!();
}),
exit,
)?;
}
@@ -225,6 +270,41 @@ impl Vecs {
)?;
}
if let Some(indexes_to_realized_price) = self.indexes_to_realized_price.as_mut() {
indexes_to_realized_price.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
vec.compute_divide(
starting_indexes.height,
self.height_to_realized_cap.as_ref().unwrap(),
&**self.indexes_to_supply.bitcoin.height.as_ref().unwrap(),
exit,
)
},
)?;
}
if let Some(indexes_to_realized_price_extra) = self.indexes_to_realized_price_extra.as_mut()
{
indexes_to_realized_price_extra.compute_rest(
indexer,
indexes,
fetched.as_ref().unwrap(),
starting_indexes,
exit,
Some(
self.indexes_to_realized_price
.as_ref()
.unwrap()
.dateindex
.unwrap_last(),
),
)?;
}
Ok(())
}
@@ -242,6 +322,12 @@ impl Vecs {
self.indexes_to_realized_cap
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.indexes_to_realized_price
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.indexes_to_realized_price_extra
.as_ref()
.map_or(vec![], |v| v.vecs()),
]
.into_iter()
.flatten()
@@ -261,6 +347,9 @@ impl Clone for Vecs {
indexes_to_supply: self.indexes_to_supply.clone(),
height_to_utxo_count: self.height_to_utxo_count.clone(),
indexes_to_utxo_count: self.indexes_to_utxo_count.clone(),
indexes_to_realized_price: self.indexes_to_realized_price.clone(),
indexes_to_realized_price_extra: self.indexes_to_realized_price_extra.clone(),
}
}
}
File diff suppressed because it is too large Load Diff
+6
View File
@@ -186,3 +186,9 @@ impl CheckedSub for Dollars {
.map(Dollars::from)
}
}
impl CheckedSub<usize> for Dollars {
fn checked_sub(self, rhs: usize) -> Option<Self> {
Some(Self(self.0 - rhs as f64))
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ use std::fmt::{self, Debug};
use color_eyre::eyre::eyre;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Index {
DateIndex,
DecadeIndex,
+1 -1
View File
@@ -39,7 +39,7 @@ impl<'a> VecTrees<'a> {
dbg!(&name, split[0], index.to_string());
panic!();
}
let key = split[1..].join("_").to_string().replace("_", "-");
let key = split[1..].join("_to_").to_string().replace("_", "-");
let prev = self
.id_to_index_to_vec
.entry(key.clone())
+1 -1
View File
@@ -27,5 +27,5 @@ oxc = { version = "0.71.0", features = ["codegen", "minifier"] }
serde = { workspace = true }
tokio = { version = "1.45.0", features = ["full"] }
tower-http = { version = "0.6.4", features = ["compression-full", "trace"] }
zip = "3.0.0"
zip = "4.0.0"
tracing = "0.1.41"
+11 -10
View File
@@ -57,15 +57,15 @@ impl DTS for Query<'static> {
contents += "\n\nexport function createVecIdToIndexes() {\n";
contents += &indexes
.iter()
.enumerate()
.map(|(i_of_i, i)| {
// let lowered = i.to_string().to_lowercase();
format!(" const {i} = /** @satisfies {{{i}}} */ ({i_of_i});",)
})
.collect::<Vec<_>>()
.join("\n");
// contents += &indexes
// .iter()
// .enumerate()
// .map(|(i_of_i, i)| {
// // let lowered = i.to_string().to_lowercase();
// format!(" const {i} = /** @satisfies {{{i}}} */ ({i_of_i});",)
// })
// .collect::<Vec<_>>()
// .join("\n");
contents += "\n\n return /** @type {const} */ ({\n";
@@ -75,7 +75,8 @@ impl DTS for Query<'static> {
.for_each(|(id, index_to_vec)| {
let indexes = index_to_vec
.keys()
.map(|i| i.to_string())
.map(|i| (*i as u8).to_string())
// .map(|i| i.to_string())
.collect::<Vec<_>>()
.join(", ");
+11 -6
View File
@@ -688,11 +688,7 @@ function createUtils() {
function vecidToUnit(id) {
/** @type {Unit} */
let unit;
if (id.includes("index") || id.includes("height") || id.includes("epoch")) {
unit = "Index";
} else if (id === "0" || id === "1" || id === "50" || id === "100") {
unit = "constant";
} else if (id.endsWith("zscore")) {
if (id.endsWith("zscore")) {
unit = "zscore";
} else if (id.endsWith("cagr")) {
unit = "cagr";
@@ -741,7 +737,8 @@ function createUtils() {
id.includes("subsidy") ||
id.endsWith("stack") ||
id.includes("supply") ||
id.includes("rewards")
id.includes("rewards") ||
id.includes("realized-cap")
) {
unit = "Sats";
} else if (
@@ -764,6 +761,14 @@ function createUtils() {
unit = "Date";
} else if (id.includes("timestamp")) {
unit = "Timestamp";
} else if (
id.includes("index") ||
id.includes("height") ||
id.includes("epoch")
) {
unit = "Index";
} else if (id === "0" || id === "1" || id === "50" || id === "100") {
unit = "constant";
} else if (id.includes("difficulty")) {
unit = "Difficulty";
} else if (id.includes("-size")) {
+603 -268
View File
@@ -342,6 +342,303 @@ function createPartialOptions(colors) {
];
}
/**
* @typedef {"-ratio"} RatioCapSuffix
* @typedef {EndsWith<RatioCapSuffix>} VecIdRatioCap
* @typedef {WithoutSuffix<VecIdRatioCap, RatioCapSuffix>} VecIdRatioCapBase
*/
/**
*
* @param {Object} args
* @param {string} args.name
* @param {string} args.title
* @param {VecIdRatioCapBase} args.key
* @param {Color} [args.color]
*/
function createPriceWithRatio({ name, title, key, color }) {
return {
name,
title,
top: [
createBaseSeries({
key,
name: "Average",
color,
}),
createBaseSeries({
key: `${key}-ratio-p1sd-as-price`,
name: "+1σ",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p2sd-as-price`,
name: "+2σ",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p3sd-as-price`,
name: "+3σ",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m1sd-as-price`,
name: "1σ",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m2sd-as-price`,
name: "2σ",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m3sd-as-price`,
name: "3σ",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99-as-price`,
name: "p99",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99-5-as-price`,
name: "p99.5",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99-9-as-price`,
name: "p99.9",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p1-as-price`,
name: "p1",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p0-5-as-price`,
name: "p0.5",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p0-1-as-price`,
name: "p0.1",
color: colors.violet,
defaultActive: false,
}),
],
bottom: [
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-ratio`,
title: "Ratio",
type: "Baseline",
options: {
baseValue: { price: 1 },
createPriceLine: {
value: 1,
},
},
}),
createBaseSeries({
key: `${key}-ratio-sma`,
name: "sma",
color: colors.yellow,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p1sd`,
name: "+1σ",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p2sd`,
name: "+2σ",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p3sd`,
name: "+3σ",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m1sd`,
name: "1σ",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m2sd`,
name: "2σ",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-m3sd`,
name: "3σ",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99`,
name: "p99",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99-5`,
name: "p99.5",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p99-9`,
name: "p99.9",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p1`,
name: "p1",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p0-5`,
name: "p0.5",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-p0-1`,
name: "p0.1",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-1w-sma`,
name: "1w sma",
color: colors.fuchsia,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-1m-sma`,
name: "1m sma",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-ratio-1y-sma`,
name: "1y sma",
color: colors.rose,
defaultActive: false,
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-ratio-1y-sma-momentum-oscillator`,
title: "1Y Momentum",
type: "Baseline",
options: {
createPriceLine: {
value: 0,
},
},
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-ratio-zscore`,
title: "Score",
type: "Baseline",
options: {
createPriceLine: {
value: 0,
},
},
}),
],
};
}
/**
* @typedef {"-realized-cap"} RealizedCapSuffix
* @typedef {EndsWith<RealizedCapSuffix>} VecIdRealizedCap
* @typedef {WithoutSuffix<VecIdRealizedCap, RealizedCapSuffix>} VecIdRealizedCapBase
*/
/**
*
* @param {Object} args
* @param {string} args.name
* @param {string} args.title
* @param {"" | VecIdRealizedCapBase} args.key
*/
function createUTXOGroupFolder({ name, title, key: _key }) {
const key = _key
? /** @type {const} */ (`${_key}-`)
: /** @type {const} */ ("");
return /** @satisfies {PartialOptionsGroup} */ ({
name: name || "all",
tree: [
{
name: "supply",
title: `${title} Supply`,
bottom: [
createBaseSeries({
key: `${key}supply`,
name: "Supply",
}),
createBaseSeries({
key: `${key}supply-in-btc`,
name: "Supply",
}),
createBaseSeries({
key: `${key}supply-in-usd`,
name: "Supply",
}),
],
},
{
name: "utxo count",
title: `${title} UTXO Count`,
bottom: [
createBaseSeries({
key: `${key}utxo-count`,
name: "Count",
}),
],
},
{
name: "realized cap",
title: `${title} Realized Capitalization`,
bottom: [
createBaseSeries({
key: `${key}realized-cap`,
name: "Realized Cap",
}),
],
},
createPriceWithRatio({
key: `${key}realized-price`,
name: "realized price",
title: `${title} Realized Price`,
}),
],
});
}
return [
{
name: "Charts",
@@ -445,218 +742,14 @@ function createPartialOptions(colors) {
}),
),
},
...averages.map(({ key, name }) => ({
name,
title: `${name} Market Price Moving Average`,
top: [
createBaseSeries({
key: `${key}-sma`,
name: "Average",
color: colors[`_${key}`],
}),
createBaseSeries({
key: `${key}-sma-ratio-p1sd-as-price`,
name: "+1σ",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p2sd-as-price`,
name: "+2σ",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p3sd-as-price`,
name: "+3σ",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m1sd-as-price`,
name: "1σ",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m2sd-as-price`,
name: "2σ",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m3sd-as-price`,
name: "3σ",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99-as-price`,
name: "p99",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99-5-as-price`,
name: "p99.5",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99-9-as-price`,
name: "p99.9",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p1-as-price`,
name: "p1",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p0-5-as-price`,
name: "p0.5",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p0-1-as-price`,
name: "p0.1",
color: colors.violet,
defaultActive: false,
}),
],
bottom: [
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-sma-ratio`,
title: "Ratio",
type: "Baseline",
options: {
baseValue: { price: 1 },
createPriceLine: {
value: 1,
},
},
}),
createBaseSeries({
key: `${key}-sma-ratio-sma`,
name: "sma",
color: colors.yellow,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p1sd`,
name: "+1σ",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p2sd`,
name: "+2σ",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p3sd`,
name: "+3σ",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m1sd`,
name: "1σ",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m2sd`,
name: "2σ",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-m3sd`,
name: "3σ",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99`,
name: "p99",
color: colors.orange,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99-5`,
name: "p99.5",
color: colors.red,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p99-9`,
name: "p99.9",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p1`,
name: "p1",
color: colors.cyan,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p0-5`,
name: "p0.5",
color: colors.blue,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-p0-1`,
name: "p0.1",
color: colors.violet,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-1w-sma`,
name: "1w sma",
color: colors.fuchsia,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-1m-sma`,
name: "1m sma",
color: colors.pink,
defaultActive: false,
}),
createBaseSeries({
key: `${key}-sma-ratio-1y-sma`,
name: "1y sma",
color: colors.rose,
defaultActive: false,
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-sma-ratio-1y-sma-momentum-oscillator`,
title: "1Y Momentum",
type: "Baseline",
options: {
createPriceLine: {
value: 0,
},
},
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
key: `${key}-sma-ratio-zscore`,
title: "Score",
type: "Baseline",
options: {
createPriceLine: {
value: 0,
},
},
}),
],
})),
...averages.map(({ key, name }) =>
createPriceWithRatio({
key: `${key}-sma`,
name,
title: `${name} Market Price Moving Average`,
color: colors[`_${key}`],
}),
),
],
},
{
@@ -1373,62 +1466,304 @@ function createPartialOptions(colors) {
{
name: "UTXOs",
tree: [
// {
// name: "supply",
// title: "Supply",
// bottom: [
// createBaseSeries({
// key: "supply",
// name: "Supply",
// }),
// createBaseSeries({
// key: "supply-in-btc",
// name: "Supply",
// }),
// createBaseSeries({
// key: "supply-in-usd",
// name: "Supply",
// }),
// ],
// },
// {
// name: "unspendable supply",
// title: "Unspendable Supply",
// bottom: [
// createBaseSeries({
// key: "unspendable-supply",
// name: "Supply",
// }),
// createBaseSeries({
// key: "unspendable-supply-in-btc",
// name: "Supply",
// }),
// createBaseSeries({
// key: "unspendable-supply-in-usd",
// name: "Supply",
// }),
// ],
// },
// {
// name: "count",
// title: "UTXO Count",
// bottom: [
// createBaseSeries({
// key: "utxo-count",
// name: "Count",
// }),
// ],
// },
// {
// name: "realized cap",
// title: "Realized Capitalization",
// bottom: [
// createBaseSeries({
// key: "realized-cap",
// name: "Realized Cap",
// }),
// ],
// },
createUTXOGroupFolder({
key: "",
name: "",
title: "",
}),
{
name: "term",
tree: [
createUTXOGroupFolder({
key: "sth",
name: "short",
title: "Short Term Holders",
}),
createUTXOGroupFolder({
key: "lth",
name: "long",
title: "Long Term Holders",
}),
],
},
{
name: "From",
tree: [
createUTXOGroupFolder({
key: "from-1d",
name: "1d",
title: "From 1 Day",
}),
createUTXOGroupFolder({
key: "from-1w",
name: "1w",
title: "From 1 Week",
}),
createUTXOGroupFolder({
key: "from-1m",
name: "1m",
title: "From 1 Month",
}),
createUTXOGroupFolder({
key: "from-2m",
name: "2m",
title: "From 2 Months",
}),
createUTXOGroupFolder({
key: "from-3m",
name: "3m",
title: "From 3 Months",
}),
createUTXOGroupFolder({
key: "from-4m",
name: "4m",
title: "From 4 Months",
}),
createUTXOGroupFolder({
key: "from-5m",
name: "5m",
title: "From 5 Months",
}),
createUTXOGroupFolder({
key: "from-6m",
name: "6m",
title: "From 6 Months",
}),
createUTXOGroupFolder({
key: "from-1y",
name: "1y",
title: "From 1 Year",
}),
createUTXOGroupFolder({
key: "from-2y",
name: "2y",
title: "From 2 Years",
}),
createUTXOGroupFolder({
key: "from-3y",
name: "3y",
title: "From 3 Years",
}),
createUTXOGroupFolder({
key: "from-4y",
name: "4y",
title: "From 4 Years",
}),
createUTXOGroupFolder({
key: "from-5y",
name: "5y",
title: "From 5 Years",
}),
createUTXOGroupFolder({
key: "from-6y",
name: "6y",
title: "From 6 Years",
}),
createUTXOGroupFolder({
key: "from-7y",
name: "7y",
title: "From 7 Years",
}),
createUTXOGroupFolder({
key: "from-8y",
name: "8y",
title: "From 8 Years",
}),
createUTXOGroupFolder({
key: "from-10y",
name: "10y",
title: "From 10 Years",
}),
createUTXOGroupFolder({
key: "from-15y",
name: "15y",
title: "From 15 Years",
}),
],
},
{
name: "Epoch",
tree: [
createUTXOGroupFolder({
key: "epoch-0",
name: "0",
title: "Epoch 0",
}),
createUTXOGroupFolder({
key: "epoch-1",
name: "1",
title: "Epoch 1",
}),
createUTXOGroupFolder({
key: "epoch-2",
name: "2",
title: "Epoch 2",
}),
createUTXOGroupFolder({
key: "epoch-3",
name: "3",
title: "Epoch 3",
}),
createUTXOGroupFolder({
key: "epoch-4",
name: "4",
title: "Epoch 4",
}),
],
},
{
name: "size",
tree: [
createUTXOGroupFolder({
key: "from-1sat-10sats",
name: "1sat..10sats",
title: "UTXOs from 1 sat to 10 sats",
}),
createUTXOGroupFolder({
key: "from-10sats-100sats",
name: "10sat..100sats",
title: "UTXOs from 10 sats to 100 sats",
}),
createUTXOGroupFolder({
key: "from-100sats-1-000sats",
name: "100sat..1_000sats",
title: "UTXOs from 100 sats to 1,000 sats",
}),
createUTXOGroupFolder({
key: "from-1-000sats-10-000sats",
name: "1_000sat..10_000sats",
title: "UTXOs from 1,000 sats to 10,000 sats",
}),
createUTXOGroupFolder({
key: "from-10-000sats-100-000sats",
name: "10_000sat..100_000sats",
title: "UTXOs from 10,000 sats to 100,000 sats",
}),
createUTXOGroupFolder({
key: "from-100-000sats-1-000-000sats",
name: "100_000sat..1_000_000sats",
title: "UTXOs from 100,000 sats to 1,000,000 sats",
}),
createUTXOGroupFolder({
key: "from-1-000-000sats-10-000-000sats",
name: "1_000_000sat..10_000_000sats",
title: "UTXOs from 1,000,000 sats to 10,000,000 sats",
}),
createUTXOGroupFolder({
key: "from-10-000-000sats-1btc",
name: "10_000_000sat..1btc",
title: "UTXOs from 10,000,000 sats to 1 BTC",
}),
createUTXOGroupFolder({
key: "from-1btc-10btc",
name: "1btc..10btc",
title: "UTXOs from 1 BTC to 10 BTC",
}),
createUTXOGroupFolder({
key: "from-10btc-100btc",
name: "10btc..100btc",
title: "UTXOs from 10 BTC to 100 BTC",
}),
createUTXOGroupFolder({
key: "from-100btc-1-000btc",
name: "100btc..1_000btc",
title: "UTXOs from 100 BTC to 1,000 BTC",
}),
createUTXOGroupFolder({
key: "from-1-000btc-10-000btc",
name: "1_000btc..10_000btc",
title: "UTXOs from 1,000 BTC to 10,000 BTC",
}),
createUTXOGroupFolder({
key: "from-10-000btc-100-000btc",
name: "10_000btc..100_000btc",
title: "UTXOs from 10,000 BTC to 100,000 BTC",
}),
createUTXOGroupFolder({
key: "from-100-000btc",
name: "100_000btc..inf",
title: "UTXOs from 100,000 BTC",
}),
],
},
{
name: "type",
tree: [
createUTXOGroupFolder({
key: "p2pk65",
name: "p2pk65",
title: "Pay To Long Public Key",
}),
createUTXOGroupFolder({
key: "p2pk33",
name: "p2pk33",
title: "Pay To Short Public Key",
}),
createUTXOGroupFolder({
key: "p2pkh",
name: "p2pkh",
title: "Pay To Public Key Hash",
}),
createUTXOGroupFolder({
key: "p2ms",
name: "p2ms",
title: "Pay To Bare Multisig",
}),
createUTXOGroupFolder({
key: "p2sh",
name: "p2sh",
title: "Pay To Script Hash",
}),
createUTXOGroupFolder({
key: "p2wpkh",
name: "p2wpkh",
title: "Pay To Witness Public Key Hash",
}),
createUTXOGroupFolder({
key: "p2wsh",
name: "p2wsh",
title: "Pay To Witness Script Hash",
}),
createUTXOGroupFolder({
key: "p2tr",
name: "p2tr",
title: "Pay To Taproot",
}),
createUTXOGroupFolder({
key: "p2a",
name: "p2a",
title: "Pay To Anchor",
}),
createUTXOGroupFolder({
key: "unknown",
name: "unknown",
title: "Pay To Unknown",
}),
],
},
{
name: "Unspendable",
tree: [
{
name: "supply",
title: "Unspendable Supply",
bottom: [
createBaseSeries({
key: "unspendable-supply",
name: "Supply",
}),
createBaseSeries({
key: "unspendable-supply-in-btc",
name: "Supply",
}),
createBaseSeries({
key: "unspendable-supply-in-usd",
name: "Supply",
}),
],
},
],
},
],
},
],
File diff suppressed because it is too large Load Diff