diff --git a/Cargo.lock b/Cargo.lock index 94d824b59..121f933fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,9 +288,9 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitcoin" -version = "0.32.5" +version = "0.32.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6bc65742dea50536e35ad42492b234c27904a27f0abdcbce605015cb4ea026" +checksum = "ad8929a18b8e33ea6b3c09297b687baaa71fb1b97353243a3f1029fad5c59c5b" dependencies = [ "base58ck", "bech32", @@ -366,9 +366,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "block-buffer" @@ -433,6 +433,7 @@ dependencies = [ "clap", "clap_derive", "color-eyre", + "derive_deref", "fjall", "log", "rayon", @@ -679,9 +680,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.22" +version = "1.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1" +checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766" dependencies = [ "jobserver", "libc", @@ -1105,9 +1106,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", "windows-sys 0.59.0", @@ -1159,6 +1160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" dependencies = [ "crc32fast", + "libz-rs-sys", "miniz_oxide", ] @@ -1591,6 +1593,15 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +[[package]] +name = "libz-rs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6489ca9bd760fe9642d7644e827b0c9add07df89857b0416ee15c1cc1a3b8c5a" +dependencies = [ + "zlib-rs", +] + [[package]] name = "linux-raw-sys" version = "0.9.4" @@ -1800,15 +1811,15 @@ checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e" [[package]] name = "owo-colors" -version = "4.2.0" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564" +checksum = "26995317201fa17f3656c36716aed4a7c81743a9634ac4c99c0eeda495db0cec" [[package]] name = "oxc" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6adee1268a2077efca9b1c1f36fdc9d9be2986b70c26bfc648d686002dfc50dd" +checksum = "36e161476bfc4a98f1b451c11e29ba8bded86013387f619a635c9d201cb07664" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1849,9 +1860,9 @@ dependencies = [ [[package]] name = "oxc_allocator" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d64a116c5711ab4de5f6780627c9a88a61effc7e918db50a5943472ab5697164" +checksum = "2ffa6f20cba9bfb3486abc83c438f6a9278e4e030b6e9a16d2b5880132f96a1c" dependencies = [ "allocator-api2", "bumpalo", @@ -1863,9 +1874,9 @@ dependencies = [ [[package]] name = "oxc_ast" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a801811f4a51678fcb766049a54cf452033240fc7fbe036d356854c7350c9e" +checksum = "406a3454475f817e71a4b8fc0a92f04e149730bc4c07d0d1803d5fc9ef75c357" dependencies = [ "bitflags", "cow-utils", @@ -1880,9 +1891,9 @@ dependencies = [ [[package]] name = "oxc_ast_macros" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ce0ae699f31d2b03e251cc54a0226b1e6022bfa2012dc6074d858f23da154c" +checksum = "d894148693dad702ad668945908f8712fe260c23aaf69bbf9d63a8213a350cdd" dependencies = [ "proc-macro2", "quote", @@ -1891,9 +1902,9 @@ dependencies = [ [[package]] name = "oxc_ast_visit" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e96d753425812fb3ff3dee311f8b78a333e60fe235f74b99281f3c8bfbb7cd2" +checksum = "dba3ad9293c9eed98116a01ef008229895d9640d8a1abca12aa54fdc588a62f3" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1903,9 +1914,9 @@ dependencies = [ [[package]] name = "oxc_cfg" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74e353d71cadac4a92445380e76d511ce95622795e5bf64e0e644b0d71f56621" +checksum = "4cf77762b883cd93185b9b132c9bb4ad35084bbf3bc75cb8bcb6242c1eb6363c" dependencies = [ "bitflags", "itertools", @@ -1918,9 +1929,9 @@ dependencies = [ [[package]] name = "oxc_codegen" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b63fa7d6b53b7eb5eabb5d6c62146b2e661199e12ddf9b9849c915d502fec1" +checksum = "e3add299d3a1b4148e4ab85e59bb5c855fbfb2405a4719aad2a199a802495ba0" dependencies = [ "bitflags", "cow-utils", @@ -1939,15 +1950,15 @@ dependencies = [ [[package]] name = "oxc_data_structures" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48a633d6f98c3e66c4f46a28f2d6d90b826f66464c7ae74c3ad1c084cb5db4af" +checksum = "2fc6d1eb979f77be6685a7a67ee5d5124c66ef611c601a84327e7d339db69c41" [[package]] name = "oxc_diagnostics" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458d78cc5805fb9496d94b4906afc63a8e4d03cfd293cca8d77c048a1821141f" +checksum = "33ba161cb61925de34f40b11c1d0d2f20e1894d5333d12f7c455a66244453512" dependencies = [ "cow-utils", "oxc-miette", @@ -1955,9 +1966,9 @@ dependencies = [ [[package]] name = "oxc_ecmascript" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1190881a073f992e1b420c7fc9bf7fcdc73b7377a5bc188844873d44ec87e7" +checksum = "92c1827f0741fae82618b6129c7a3248e8334336879f4968cfce231dd65a9ebf" dependencies = [ "cow-utils", "num-bigint", @@ -1969,9 +1980,9 @@ dependencies = [ [[package]] name = "oxc_estree" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d6c5726456864b42e2ba570e1aceb4fccaef6c98edd2ed2b44ce9f27432373" +checksum = "c671fd76e9990c90762b7f7f7dd5c3038bf72e3295989b2a71ba11870a193b07" [[package]] name = "oxc_index" @@ -1981,9 +1992,9 @@ checksum = "2fa07b0cfa997730afed43705766ef27792873fdf5215b1391949fec678d2392" [[package]] name = "oxc_mangler" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8351243ef6acfe269da935764959443929541b4a681c5061a21ac807715ddd8e" +checksum = "db19decb6e6513cd16f607b7e0ae9c91a9ebeb29b56b182a75c351d062d78102" dependencies = [ "fixedbitset", "itertools", @@ -1998,9 +2009,9 @@ dependencies = [ [[package]] name = "oxc_minifier" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a11de372cdb1eed5c47ea485511b11d3e492ee321d10eb9c31d14e7398443233" +checksum = "8b3555895501f211ca317d254e11b68ab6b8d27d65160338c5f573d462e68919" dependencies = [ "cow-utils", "oxc_allocator", @@ -2020,9 +2031,9 @@ dependencies = [ [[package]] name = "oxc_parser" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec5d7bd6ced861f21f476ef3edca2b2c9b0775696dee4f370614aa06c4d4b767" +checksum = "959f68446d66542753f2fe081189b729ed89f8ed5302de1a522640ff42eba31e" dependencies = [ "bitflags", "cow-utils", @@ -2043,9 +2054,9 @@ dependencies = [ [[package]] name = "oxc_regular_expression" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a1d0d251aa32bbc1228cf2e67b016ed9cdb97f2144c2b1027f3dd0fa9d662a" +checksum = "db7f5710da3fea0f40aaba14d547c61ac30c2840fb5d6a1ea9887766b72310c9" dependencies = [ "oxc_allocator", "oxc_ast_macros", @@ -2058,9 +2069,9 @@ dependencies = [ [[package]] name = "oxc_semantic" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c1e25e8ce948cdfb8aef182e487074b931e449e7251d2df8442dde559644b8" +checksum = "425bec6c2ac20ff88573b8fbd87fc67aa97e49de9539979a98bcf79c37011077" dependencies = [ "itertools", "oxc_allocator", @@ -2094,9 +2105,9 @@ dependencies = [ [[package]] name = "oxc_span" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e04ea95e074243c7ee2f48bb8e7164c6b4f53afb6d1b61dd5d1c521c3c173f3e" +checksum = "cbc66dc0868f4492562d37733754ef147073410004a44551acb102cf2562f66b" dependencies = [ "compact_str", "oxc-miette", @@ -2107,9 +2118,9 @@ dependencies = [ [[package]] name = "oxc_syntax" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f3943f294bacbd1395143ee7d47f19080e35028bd3eaca829f154bd99e3a51" +checksum = "68bfa728cbbf2161b9afc3325addde64feeb39e8167a0ef1472ad1f0efbc9c48" dependencies = [ "bitflags", "cow-utils", @@ -2128,9 +2139,9 @@ dependencies = [ [[package]] name = "oxc_traverse" -version = "0.69.0" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afda4da5f89f3b40efe6a6501b3e52cc268508aafc01a0b4c8725c64f58dc492" +checksum = "528815f5909c4d1237f634f8482600dd08ac9293b3cc7839099f0f7abf327402" dependencies = [ "itoa", "oxc_allocator", @@ -3297,9 +3308,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "windows-core" -version = "0.61.0" +version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +checksum = "46ec44dc15085cea82cf9c78f85a9114c463a369786585ad2882d1ff0b0acf40" dependencies = [ "windows-implement", "windows-interface", @@ -3338,18 +3349,18 @@ checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" [[package]] name = "windows-result" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +checksum = "4b895b5356fc36103d0f64dd1e94dfa7ac5633f1c9dd6e80fe9ec4adef69e09d" dependencies = [ "windows-link", ] [[package]] name = "windows-strings" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +checksum = "2a7ab927b2637c19b3dbe0965e75d8f2d30bdd697a1516191cad2ec4df8fb28a" dependencies = [ "windows-link", ] @@ -3511,16 +3522,15 @@ dependencies = [ [[package]] name = "zip" -version = "2.6.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dcb24d0152526ae49b9b96c1dcf71850ca1e0b882e4e28ed898a93c41334744" +checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308" dependencies = [ "aes", "arbitrary", "bzip2", "constant_time_eq", "crc32fast", - "crossbeam-utils", "deflate64", "flate2", "getrandom 0.3.3", @@ -3537,6 +3547,12 @@ dependencies = [ "zstd", ] +[[package]] +name = "zlib-rs" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "868b928d7949e09af2f6086dfc1e01936064cc7a819253bce650d4e2a2d63ba8" + [[package]] name = "zopfli" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index d9914c6de..2dc0ce7d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ inherits = "release" [workspace.dependencies] axum = "0.8.4" -bitcoin = { version = "0.32.5", features = ["serde"] } +bitcoin = { version = "0.32.6", features = ["serde"] } bitcoincore-rpc = "0.19.0" brk_cli = { version = "0", path = "crates/brk_cli" } brk_computer = { version = "0", path = "crates/brk_computer" } diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml index 96e5a38c9..bd6372684 100644 --- a/crates/brk_computer/Cargo.toml +++ b/crates/brk_computer/Cargo.toml @@ -17,6 +17,7 @@ brk_vec = { workspace = true } clap = { workspace = true } clap_derive = { workspace = true } color-eyre = { workspace = true } +derive_deref = { workspace = true } fjall = { workspace = true } log = { workspace = true } rayon = { workspace = true } diff --git a/crates/brk_computer/src/lib.rs b/crates/brk_computer/src/lib.rs index c40f558bd..672478b3c 100644 --- a/crates/brk_computer/src/lib.rs +++ b/crates/brk_computer/src/lib.rs @@ -11,6 +11,7 @@ use brk_indexer::Indexer; pub use brk_parser::rpc; use brk_vec::{AnyCollectableVec, Compressed, Computation}; +mod states; mod stores; mod utils; mod vecs; diff --git a/crates/brk_computer/src/states/block.rs b/crates/brk_computer/src/states/block.rs new file mode 100644 index 000000000..53aeba6e6 --- /dev/null +++ b/crates/brk_computer/src/states/block.rs @@ -0,0 +1,8 @@ +#![allow(unused)] + +use brk_core::{Sats, StoredU32}; + +pub struct BlockState { + utxos: StoredU32, + value: Sats, +} diff --git a/crates/brk_computer/src/states/cohort.rs b/crates/brk_computer/src/states/cohort.rs new file mode 100644 index 000000000..7339ce75e --- /dev/null +++ b/crates/brk_computer/src/states/cohort.rs @@ -0,0 +1,155 @@ +#![allow(unused)] + +use brk_core::{Dollars, Sats, StoredUsize}; + +// Vecs ? probably +#[derive(Default)] +pub struct CohortStates { + pub realized_cap: Dollars, + pub supply: Sats, + pub utxo_count: StoredUsize, + // pub price_to_amount: PriceToValue, save it not rounded in fjall +} + +pub struct OneShotSats { + pub price_paid_state: PricePaidState, + pub unrealized_block_state: UnrealizedState, + pub unrealized_date_state: Option, +} + +pub struct UnrealizedState { + supply_in_profit: Sats, + // supply_in_loss: Sats, + unrealized_profit: Dollars, + unrealized_loss: Dollars, +} + +// Why option ? +#[derive(Default, Debug)] +pub struct PricePaidState { + pp_p5: Option, + pp_p10: Option, + pp_p15: Option, + pp_p20: Option, + pp_p25: Option, + pp_p30: Option, + pp_p35: Option, + pp_p40: Option, + pp_p45: Option, + pp_median: Option, + pp_p55: Option, + pp_p60: Option, + pp_p65: Option, + pp_p70: Option, + pp_p75: Option, + pp_p80: Option, + pp_p85: Option, + pp_p90: Option, + pp_p95: Option, + + processed_amount: Sats, +} + +pub struct PricePaidStateFull { + pp_p1: Option, + pp_p2: Option, + pp_p3: Option, + pp_p4: Option, + pp_p5: Option, + pp_p6: Option, + pp_p7: Option, + pp_p8: Option, + pp_p9: Option, + pp_p10: Option, + pp_p11: Option, + pp_p12: Option, + pp_p13: Option, + pp_p14: Option, + pp_p15: Option, + pp_p16: Option, + pp_p17: Option, + pp_p18: Option, + pp_p19: Option, + pp_p20: Option, + pp_p21: Option, + pp_p22: Option, + pp_p23: Option, + pp_p24: Option, + pp_p25: Option, + pp_p26: Option, + pp_p27: Option, + pp_p28: Option, + pp_p29: Option, + pp_p30: Option, + pp_p31: Option, + pp_p32: Option, + pp_p33: Option, + pp_p34: Option, + pp_p35: Option, + pp_p36: Option, + pp_p37: Option, + pp_p38: Option, + pp_p39: Option, + pp_p40: Option, + pp_p41: Option, + pp_p42: Option, + pp_p43: Option, + pp_p44: Option, + pp_p45: Option, + pp_p46: Option, + pp_p47: Option, + pp_p48: Option, + pp_p49: Option, + pp_p50: Option, + pp_p51: Option, + pp_p52: Option, + pp_p53: Option, + pp_p54: Option, + pp_p55: Option, + pp_p56: Option, + pp_p57: Option, + pp_p58: Option, + pp_p59: Option, + pp_p60: Option, + pp_p61: Option, + pp_p62: Option, + pp_p63: Option, + pp_p64: Option, + pp_p65: Option, + pp_p66: Option, + pp_p67: Option, + pp_p68: Option, + pp_p69: Option, + pp_p70: Option, + pp_p71: Option, + pp_p72: Option, + pp_p73: Option, + pp_p74: Option, + pp_p75: Option, + pp_p76: Option, + pp_p77: Option, + pp_p78: Option, + pp_p79: Option, + pp_p80: Option, + pp_p81: Option, + pp_p82: Option, + pp_p83: Option, + pp_p84: Option, + pp_p85: Option, + pp_p86: Option, + pp_p87: Option, + pp_p88: Option, + pp_p89: Option, + pp_p90: Option, + pp_p91: Option, + pp_p92: Option, + pp_p93: Option, + pp_p94: Option, + pp_p95: Option, + pp_p96: Option, + pp_p97: Option, + pp_p98: Option, + pp_p99: Option, + + processed_amount: Sats, +} diff --git a/crates/brk_computer/src/states/mod.rs b/crates/brk_computer/src/states/mod.rs new file mode 100644 index 000000000..5512ea589 --- /dev/null +++ b/crates/brk_computer/src/states/mod.rs @@ -0,0 +1,7 @@ +mod block; +mod cohort; +mod outputs; + +pub use block::*; +pub use cohort::*; +pub use outputs::*; diff --git a/crates/brk_computer/src/states/outputs.rs b/crates/brk_computer/src/states/outputs.rs new file mode 100644 index 000000000..5e2c1aa5d --- /dev/null +++ b/crates/brk_computer/src/states/outputs.rs @@ -0,0 +1,107 @@ +#![allow(unused)] + +#[derive(Default, Clone)] +pub struct Outputs { + pub all: T, + // pub by_term: OutputsByTerm, + // pub by_up_to: OutputsByUpTo, + // pub by_from: OutputsByFrom, + // pub by_range: OutputsByRange, + // pub by_epoch: OutputsByEpoch, + // pub by_size: OutputsBySize, + // pub by_value: OutputsByValue, +} + +#[derive(Default)] +pub struct OutputsByTerm { + pub short: T, + pub long: T, +} + +#[derive(Default)] +pub struct OutputsByUpTo { + pub _1d: T, + pub _1w: T, + pub _1m: T, + pub _2m: T, + pub _3m: T, + pub _4m: T, + pub _5m: T, + pub _6m: T, + pub _1y: T, + pub _2y: T, + pub _3y: T, + pub _5y: T, + pub _7y: T, + pub _10y: T, + pub _15y: T, +} + +#[derive(Default)] +pub struct OutputsByRange { + pub _1d_to_1w: T, + pub _1w_to_1m: T, + pub _1m_to_3m: T, + pub _3m_to_6m: T, + pub _6m_to_1y: T, + pub _1y_to_2y: T, + pub _2y_to_3y: T, + pub _3y_to_5y: T, + pub _5y_to_7y: T, + pub _7y_to_10y: T, + pub _10y_to_15y: T, +} + +#[derive(Default)] +pub struct OutputsByFrom { + pub _1y: T, + pub _2y: T, + pub _4y: T, + pub _10y: T, + pub _15y: T, +} + +#[derive(Default)] +pub struct OutputsByEpoch { + pub _1: T, + pub _2: T, + pub _3: T, + pub _4: T, + pub _5: T, +} + +#[derive(Default)] +pub struct OutputsBySize { + pub from_1_to_10: T, + pub from_10_to_100: T, + pub from_100_to_1_000: T, + pub from_1_000_to_10_000: T, + pub from_10000_to_100_000: T, + pub from_100_000_to_1_000_000: T, + pub from_1_000_000_to_10_000_000: T, + pub from_10_000_000_to_1btc: T, + pub from_1btc_to_10btc: T, + pub from_10btc_to_100btc: T, + pub from_100btc_to_1_000btc: T, + pub from_1_000btc_to_10_000btc: T, + pub from_10_000btc_to_100_000btc: T, + pub from_100_000btc: T, +} + +#[derive(Default)] +pub struct OutputsByValue { + pub up_to_1cent: T, + pub from_1c_to_10c: T, + pub from_10c_to_1d: T, + pub from_1d_to_10d: T, + pub from_10usd_to_100usd: T, + pub from_100usd_to_1_000usd: T, + pub from_1_000usd_to_10_000usd: T, + pub from_10_000usd_to_100_000usd: T, + pub from_100_000usd_to_1_000_000usd: T, + pub from_1_000_000usd_to_10_000_000usd: T, + pub from_10_000_000usd_to_100_000_000usd: T, + pub from_100_000_000usd_to_1_000_000_000usd: T, + pub from_1_000_000_000usd: T, + // ... +} diff --git a/crates/brk_computer/src/vecs/grouped/builder.rs b/crates/brk_computer/src/vecs/grouped/builder.rs index 1e8b3c6b0..74906ce3e 100644 --- a/crates/brk_computer/src/vecs/grouped/builder.rs +++ b/crates/brk_computer/src/vecs/grouped/builder.rs @@ -18,18 +18,18 @@ where I: StoredIndex, T: ComputedType, { - first: Option>, - average: Option>, - sum: Option>, - max: Option>, - _90p: Option>, - _75p: Option>, - median: Option>, - _25p: Option>, - _10p: Option>, - min: Option>, - last: Option>, - total: Option>, + first: Option>>, + average: Option>>, + sum: Option>>, + max: Option>>, + _90p: Option>>, + _75p: Option>>, + median: Option>>, + _25p: Option>>, + _10p: Option>>, + min: Option>>, + last: Option>>, + total: Option>>, } const VERSION: Version = Version::ZERO; @@ -76,64 +76,120 @@ where let s = Self { first: options.first.then(|| { - EagerVec::forced_import(&maybe_prefix("first"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_prefix("first"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), last: options.last.then(|| { - EagerVec::forced_import( - &path.join(format!("{key}_to_{name}")), - version + Version::ZERO, - compressed, + Box::new( + EagerVec::forced_import( + &path.join(format!("{key}_to_{name}")), + version + Version::ZERO, + compressed, + ) + .unwrap(), ) - .unwrap() }), min: options.min.then(|| { - EagerVec::forced_import(&maybe_suffix("min"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("min"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), max: options.max.then(|| { - EagerVec::forced_import(&maybe_suffix("max"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("max"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), median: options.median.then(|| { - EagerVec::forced_import( - &maybe_suffix("median"), - version + Version::ZERO, - compressed, + Box::new( + EagerVec::forced_import( + &maybe_suffix("median"), + version + Version::ZERO, + compressed, + ) + .unwrap(), ) - .unwrap() }), average: options.average.then(|| { - EagerVec::forced_import( - &maybe_suffix("average"), - version + Version::ZERO, - compressed, + Box::new( + EagerVec::forced_import( + &maybe_suffix("average"), + version + Version::ZERO, + compressed, + ) + .unwrap(), ) - .unwrap() }), sum: options.sum.then(|| { - EagerVec::forced_import(&maybe_suffix("sum"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("sum"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), total: options.total.then(|| { - EagerVec::forced_import(&prefix("total"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import(&prefix("total"), version + Version::ZERO, compressed) + .unwrap(), + ) }), _90p: options._90p.then(|| { - EagerVec::forced_import(&maybe_suffix("90p"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("90p"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), _75p: options._75p.then(|| { - EagerVec::forced_import(&maybe_suffix("75p"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("75p"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), _25p: options._25p.then(|| { - EagerVec::forced_import(&maybe_suffix("25p"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("25p"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), _10p: options._10p.then(|| { - EagerVec::forced_import(&maybe_suffix("10p"), version + Version::ZERO, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &maybe_suffix("10p"), + version + Version::ZERO, + compressed, + ) + .unwrap(), + ) }), }; @@ -480,88 +536,88 @@ where )) } - pub fn unwrap_first(&mut self) -> &mut EagerVec { - self.first.as_mut().unwrap() + pub fn unwrap_first(&self) -> &EagerVec { + self.first.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_average(&mut self) -> &mut EagerVec { - self.average.as_mut().unwrap() + pub fn unwrap_average(&self) -> &EagerVec { + self.average.as_ref().unwrap() } - pub fn unwrap_sum(&mut self) -> &mut EagerVec { - self.sum.as_mut().unwrap() + pub fn unwrap_sum(&self) -> &EagerVec { + self.sum.as_ref().unwrap() } - pub fn unwrap_max(&mut self) -> &mut EagerVec { - self.max.as_mut().unwrap() + pub fn unwrap_max(&self) -> &EagerVec { + self.max.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_90p(&mut self) -> &mut EagerVec { - self._90p.as_mut().unwrap() + pub fn unwrap_90p(&self) -> &EagerVec { + self._90p.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_75p(&mut self) -> &mut EagerVec { - self._75p.as_mut().unwrap() + pub fn unwrap_75p(&self) -> &EagerVec { + self._75p.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_median(&mut self) -> &mut EagerVec { - self.median.as_mut().unwrap() + pub fn unwrap_median(&self) -> &EagerVec { + self.median.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_25p(&mut self) -> &mut EagerVec { - self._25p.as_mut().unwrap() + pub fn unwrap_25p(&self) -> &EagerVec { + self._25p.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_10p(&mut self) -> &mut EagerVec { - self._10p.as_mut().unwrap() + pub fn unwrap_10p(&self) -> &EagerVec { + self._10p.as_ref().unwrap() } - pub fn unwrap_min(&mut self) -> &mut EagerVec { - self.min.as_mut().unwrap() + pub fn unwrap_min(&self) -> &EagerVec { + self.min.as_ref().unwrap() } - pub fn unwrap_last(&mut self) -> &mut EagerVec { - self.last.as_mut().unwrap() + pub fn unwrap_last(&self) -> &EagerVec { + self.last.as_ref().unwrap() } #[allow(unused)] - pub fn unwrap_total(&mut self) -> &mut EagerVec { - self.total.as_mut().unwrap() + pub fn unwrap_total(&self) -> &EagerVec { + self.total.as_ref().unwrap() } pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { let mut v: Vec<&dyn AnyCollectableVec> = vec![]; if let Some(first) = self.first.as_ref() { - v.push(first); + v.push(first.as_ref()); } if let Some(last) = self.last.as_ref() { - v.push(last); + v.push(last.as_ref()); } if let Some(min) = self.min.as_ref() { - v.push(min); + v.push(min.as_ref()); } if let Some(max) = self.max.as_ref() { - v.push(max); + v.push(max.as_ref()); } if let Some(median) = self.median.as_ref() { - v.push(median); + v.push(median.as_ref()); } if let Some(average) = self.average.as_ref() { - v.push(average); + v.push(average.as_ref()); } if let Some(sum) = self.sum.as_ref() { - v.push(sum); + v.push(sum.as_ref()); } if let Some(total) = self.total.as_ref() { - v.push(total); + v.push(total.as_ref()); } if let Some(_90p) = self._90p.as_ref() { - v.push(_90p); + v.push(_90p.as_ref()); } if let Some(_75p) = self._75p.as_ref() { - v.push(_75p); + v.push(_75p.as_ref()); } if let Some(_25p) = self._25p.as_ref() { - v.push(_25p); + v.push(_25p.as_ref()); } if let Some(_10p) = self._10p.as_ref() { - v.push(_10p); + v.push(_10p.as_ref()); } v diff --git a/crates/brk_computer/src/vecs/grouped/from_height.rs b/crates/brk_computer/src/vecs/grouped/from_height.rs index de2a62755..3d20840b1 100644 --- a/crates/brk_computer/src/vecs/grouped/from_height.rs +++ b/crates/brk_computer/src/vecs/grouped/from_height.rs @@ -16,7 +16,7 @@ pub struct ComputedVecsFromHeight where T: ComputedType + PartialOrd, { - pub height: Option>, + pub height: Option>>, pub height_extra: ComputedVecBuilder, pub dateindex: ComputedVecBuilder, pub weekindex: ComputedVecBuilder, @@ -46,8 +46,14 @@ where let version = VERSION + version; let height = compute_source.then(|| { - EagerVec::forced_import(&path.join(format!("height_to_{name}")), version, compressed) - .unwrap() + Box::new( + EagerVec::forced_import( + &path.join(format!("height_to_{name}")), + version, + compressed, + ) + .unwrap(), + ) }); let height_extra = ComputedVecBuilder::forced_import( @@ -137,7 +143,7 @@ where exit, )?; } else { - let height = self.height.as_ref().unwrap(); + let height = self.height.as_ref().unwrap().as_ref(); self.height_extra .extend(starting_indexes.height, height, exit)?; @@ -206,7 +212,7 @@ where [ self.height .as_ref() - .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), + .map_or(vec![], |v| vec![v.as_ref() as &dyn AnyCollectableVec]), self.height_extra.vecs(), self.dateindex.vecs(), self.weekindex.vecs(), diff --git a/crates/brk_computer/src/vecs/grouped/from_txindex.rs b/crates/brk_computer/src/vecs/grouped/from_txindex.rs index 5839c5a3b..b98164b1c 100644 --- a/crates/brk_computer/src/vecs/grouped/from_txindex.rs +++ b/crates/brk_computer/src/vecs/grouped/from_txindex.rs @@ -19,7 +19,7 @@ pub struct ComputedVecsFromTxindex where T: ComputedType + PartialOrd, { - pub txindex: Option>, + pub txindex: Option>>, pub height: ComputedVecBuilder, pub dateindex: ComputedVecBuilder, pub weekindex: ComputedVecBuilder, @@ -49,12 +49,14 @@ where let version = VERSION + version; let txindex = compute_source.then(|| { - EagerVec::forced_import( - &path.join(format!("txindex_to_{name}")), - version, - compressed, + Box::new( + EagerVec::forced_import( + &path.join(format!("txindex_to_{name}")), + version, + compressed, + ) + .unwrap(), ) - .unwrap() }); let height = ComputedVecBuilder::forced_import(path, name, version, compressed, options)?; @@ -132,7 +134,7 @@ where exit, )?; } else { - let txindex = self.txindex.as_ref().unwrap(); + let txindex = self.txindex.as_ref().unwrap().as_ref(); self.height.compute( starting_indexes.height, @@ -206,7 +208,7 @@ where [ self.txindex .as_ref() - .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), + .map_or(vec![], |v| vec![v.as_ref() as &dyn AnyCollectableVec]), self.height.vecs(), self.dateindex.vecs(), self.weekindex.vecs(), diff --git a/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs index 0e833ce48..451472cbc 100644 --- a/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs @@ -51,6 +51,7 @@ pub struct ComputedRatioVecsFromDateIndex { pub ratio_m1sd_as_price: ComputedVecsFromDateIndex, pub ratio_m2sd_as_price: ComputedVecsFromDateIndex, pub ratio_m3sd_as_price: ComputedVecsFromDateIndex, + pub ratio_zscore: ComputedVecsFromDateIndex, } const VERSION: Version = Version::ZERO; @@ -75,217 +76,224 @@ impl ComputedRatioVecsFromDateIndex { ratio: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_sma"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_1w_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1w_sma"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_1m_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1m_sma"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_1y_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_sma"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_sma_momentum_oscillator"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_standard_deviation: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_standard_deviation"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99_9: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_9"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99_5: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_5"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p1: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p0_5: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_5"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p0_1: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_1"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p1sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p2sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p2sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p3sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p3sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m1sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m1sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m2sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m2sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m3sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m3sd"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_9_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_5_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_5_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_1_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p2sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p3sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m1sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m2sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, compressed, options, )?, ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m3sd_as_price"), - VERSION + version + Version::TWO, + VERSION + version + Version::ZERO, + compressed, + options, + )?, + ratio_zscore: ComputedVecsFromDateIndex::forced_import( + path, + &format!("{name}_ratio_zscore"), + VERSION + version + Version::ZERO, compressed, options, )?, @@ -426,7 +434,6 @@ impl ComputedRatioVecsFromDateIndex { )?; let ratio_version = self.ratio.dateindex.version(); - self.mut_ratio_vecs() .iter_mut() .try_for_each(|v| -> Result<()> { @@ -811,6 +818,27 @@ impl ComputedRatioVecsFromDateIndex { }, )?; + self.ratio_zscore.compute( + indexer, + indexes, + starting_indexes, + exit, + |vec, _, _, starting_indexes, exit| { + let mut sma_iter = self.ratio_sma.dateindex.into_iter(); + let mut sd_iter = self.ratio_standard_deviation.dateindex.into_iter(); + vec.compute_transform( + starting_indexes.dateindex, + &self.ratio.dateindex, + |(i, ratio, ..)| { + let sma = sma_iter.unwrap_get_inner(i); + let sd = sd_iter.unwrap_get_inner(i); + (i, (ratio - sma) / sd) + }, + exit, + ) + }, + )?; + Ok(()) } @@ -866,6 +894,7 @@ impl ComputedRatioVecsFromDateIndex { self.ratio_m1sd_as_price.vecs(), self.ratio_m2sd_as_price.vecs(), self.ratio_m3sd_as_price.vecs(), + self.ratio_zscore.vecs(), ] .concat() } diff --git a/crates/brk_computer/src/vecs/grouped/value_from_height.rs b/crates/brk_computer/src/vecs/grouped/value_from_height.rs index 4220e9248..1e3352cdc 100644 --- a/crates/brk_computer/src/vecs/grouped/value_from_height.rs +++ b/crates/brk_computer/src/vecs/grouped/value_from_height.rs @@ -129,14 +129,14 @@ impl ComputedValueVecsFromHeight { |v, _, _, starting_indexes, exit| { v.compute_from_sats( starting_indexes.height, - self.sats.height.as_ref().unwrap(), + self.sats.height.as_ref().unwrap().as_ref(), exit, ) }, )?; } - let txindex = self.bitcoin.height.as_ref().unwrap(); + let txindex = self.bitcoin.height.as_ref().unwrap().as_ref(); let price = &fetched.as_ref().unwrap().chainindexes_to_close.height; if let Some(dollars) = self.dollars.as_mut() { diff --git a/crates/brk_computer/src/vecs/indexes.rs b/crates/brk_computer/src/vecs/indexes.rs index 1ac39b049..0e4f021f5 100644 --- a/crates/brk_computer/src/vecs/indexes.rs +++ b/crates/brk_computer/src/vecs/indexes.rs @@ -11,7 +11,7 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{ AnyCollectableVec, CloneableAnyIterableVec, Compressed, Computation, ComputedVec, - ComputedVecFrom1, EagerVec, VecIterator, Version, + ComputedVecFrom1, ComputedVecFrom2, EagerVec, StoredIndex, VecIterator, Version, }; #[derive(Clone)] @@ -53,6 +53,7 @@ pub struct Vecs { pub opreturnindex_to_opreturnindex: ComputedVecFrom1, pub outputindex_to_outputindex: ComputedVecFrom1, + pub outputindex_to_txindex: EagerVec, pub p2aindex_to_p2aindex: ComputedVecFrom1, pub p2msindex_to_p2msindex: ComputedVecFrom1, pub p2pk33index_to_p2pk33index: @@ -70,6 +71,10 @@ pub struct Vecs { pub quarterindex_to_quarterindex: ComputedVecFrom1, pub txindex_to_height: EagerVec, + pub txindex_to_input_count: + ComputedVecFrom2, + pub txindex_to_output_count: + ComputedVecFrom2, pub txindex_to_txindex: ComputedVecFrom1, pub unknownoutputindex_to_unknownoutputindex: ComputedVecFrom1, @@ -121,6 +126,52 @@ impl Vecs { |index, _| Some(index), )?; + let txindex_to_input_count = ComputedVec::forced_import_or_init_from_2( + computation, + path, + "txindex_to_input_count", + Version::ZERO, + compressed, + indexer.vecs().txindex_to_first_inputindex.boxed_clone(), + indexer.vecs().inputindex_to_outputindex.boxed_clone(), + |index: TxIndex, txindex_to_first_inputindex_iter, inputindex_to_outputindex_iter| { + let txindex = index.unwrap_to_usize(); + txindex_to_first_inputindex_iter + .next_at(txindex) + .map(|(_, start)| { + let start = usize::from(start.into_inner()); + let end = txindex_to_first_inputindex_iter + .next_at(txindex + 1) + .map(|(_, v)| usize::from(v.into_inner())) + .unwrap_or_else(|| inputindex_to_outputindex_iter.len()); + StoredUsize::from((start..end).count()) + }) + }, + )?; + + let txindex_to_output_count = ComputedVec::forced_import_or_init_from_2( + computation, + path, + "txindex_to_output_count", + Version::ZERO, + compressed, + indexer.vecs().txindex_to_first_outputindex.boxed_clone(), + indexer.vecs().outputindex_to_value.boxed_clone(), + |index: TxIndex, txindex_to_first_outputindex_iter, outputindex_to_value_iter| { + let txindex = index.unwrap_to_usize(); + txindex_to_first_outputindex_iter + .next_at(txindex) + .map(|(_, start)| { + let start = usize::from(start.into_inner()); + let end = txindex_to_first_outputindex_iter + .next_at(txindex + 1) + .map(|(_, v)| usize::from(v.into_inner())) + .unwrap_or_else(|| outputindex_to_value_iter.len()); + StoredUsize::from((start..end).count()) + }) + }, + )?; + let p2pk33index_to_p2pk33index = ComputedVec::forced_import_or_init_from_1( computation, path, @@ -479,6 +530,8 @@ impl Vecs { quarterindex_to_first_monthindex, quarterindex_to_quarterindex, txindex_to_txindex, + txindex_to_input_count, + txindex_to_output_count, unknownoutputindex_to_unknownoutputindex, weekindex_to_first_dateindex, weekindex_to_weekindex, @@ -545,6 +598,11 @@ impl Vecs { Version::ZERO, compressed, )?, + outputindex_to_txindex: EagerVec::forced_import( + &path.join("outputindex_to_txindex"), + Version::ZERO, + compressed, + )?, }) } @@ -563,6 +621,13 @@ impl Vecs { self.outputindex_to_outputindex .compute_if_necessary(starting_indexes.outputindex, exit)?; + self.outputindex_to_txindex.compute_inverse_less_to_more( + starting_indexes.txindex, + &indexer_vecs.txindex_to_first_outputindex, + &self.txindex_to_output_count, + exit, + )?; + self.p2pk33index_to_p2pk33index .compute_if_necessary(starting_indexes.p2pk33index, exit)?; @@ -993,6 +1058,8 @@ impl Vecs { &self.quarterindex_to_quarterindex, &self.txindex_to_height, &self.txindex_to_txindex, + &self.txindex_to_input_count, + &self.txindex_to_output_count, &self.unknownoutputindex_to_unknownoutputindex, &self.weekindex_to_dateindex_count, &self.weekindex_to_first_dateindex, @@ -1001,6 +1068,7 @@ impl Vecs { &self.yearindex_to_first_monthindex, &self.yearindex_to_monthindex_count, &self.yearindex_to_yearindex, + &self.outputindex_to_txindex, ] } } diff --git a/crates/brk_computer/src/vecs/mod.rs b/crates/brk_computer/src/vecs/mod.rs index 6be2d54ef..5a22e522f 100644 --- a/crates/brk_computer/src/vecs/mod.rs +++ b/crates/brk_computer/src/vecs/mod.rs @@ -13,6 +13,7 @@ pub mod indexes; pub mod market; pub mod mining; pub mod transactions; +pub mod utxos; pub use indexes::Indexes; @@ -24,6 +25,7 @@ pub struct Vecs { pub mining: mining::Vecs, pub market: market::Vecs, pub transactions: transactions::Vecs, + // pub utxos: utxos::Vecs, pub fetched: Option, } @@ -47,6 +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)?, transactions: transactions::Vecs::forced_import( path, indexer, diff --git a/crates/brk_computer/src/vecs/transactions.rs b/crates/brk_computer/src/vecs/transactions.rs index 6fef32281..68d235680 100644 --- a/crates/brk_computer/src/vecs/transactions.rs +++ b/crates/brk_computer/src/vecs/transactions.rs @@ -9,7 +9,8 @@ use brk_indexer::Indexer; use brk_parser::bitcoin; use brk_vec::{ AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Compressed, Computation, - ComputedVec, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, StoredIndex, Version, + ComputedVec, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, StoredIndex, VecIterator, + Version, }; use super::{ @@ -73,18 +74,15 @@ pub struct Vecs { pub indexes_to_unknownoutput_count: ComputedVecsFromHeight, pub inputindex_to_value: ComputedVecFrom2, - pub txindex_to_input_count: - ComputedVecFrom2, pub indexes_to_input_count: ComputedVecsFromTxindex, pub txindex_to_is_coinbase: ComputedVecFrom2, - pub txindex_to_output_count: - ComputedVecFrom2, pub indexes_to_output_count: ComputedVecsFromTxindex, pub txindex_to_vsize: ComputedVecFrom1, pub txindex_to_weight: ComputedVecFrom2, pub txindex_to_fee: ComputedVecFrom2, pub txindex_to_feerate: ComputedVecFrom2, + pub indexes_to_utxo_count: ComputedVecsFromHeight, } impl Vecs { @@ -196,29 +194,6 @@ impl Vecs { }, )?; - let txindex_to_input_count = ComputedVec::forced_import_or_init_from_2( - computation, - path, - "txindex_to_input_count", - Version::ZERO, - compressed, - indexer.vecs().txindex_to_first_inputindex.boxed_clone(), - indexer.vecs().inputindex_to_outputindex.boxed_clone(), - |index: TxIndex, txindex_to_first_inputindex_iter, inputindex_to_outputindex_iter| { - let txindex = index.unwrap_to_usize(); - txindex_to_first_inputindex_iter - .next_at(txindex) - .map(|(_, start)| { - let start = usize::from(start.into_inner()); - let end = txindex_to_first_inputindex_iter - .next_at(txindex + 1) - .map(|(_, v)| usize::from(v.into_inner())) - .unwrap_or_else(|| inputindex_to_outputindex_iter.len()); - StoredUsize::from((start..end).count()) - }) - }, - )?; - let txindex_to_input_value = ComputedVec::forced_import_or_init_from_3( computation, path, @@ -226,7 +201,7 @@ impl Vecs { Version::ZERO, compressed, indexer.vecs().txindex_to_first_inputindex.boxed_clone(), - txindex_to_input_count.boxed_clone(), + indexes.txindex_to_input_count.boxed_clone(), inputindex_to_value.boxed_clone(), |index: TxIndex, txindex_to_first_inputindex_iter, @@ -268,29 +243,6 @@ impl Vecs { // .add_total(), // )?; - let txindex_to_output_count = ComputedVec::forced_import_or_init_from_2( - computation, - path, - "txindex_to_output_count", - Version::ZERO, - compressed, - indexer.vecs().txindex_to_first_outputindex.boxed_clone(), - indexer.vecs().outputindex_to_value.boxed_clone(), - |index: TxIndex, txindex_to_first_outputindex_iter, outputindex_to_value_iter| { - let txindex = index.unwrap_to_usize(); - txindex_to_first_outputindex_iter - .next_at(txindex) - .map(|(_, start)| { - let start = usize::from(start.into_inner()); - let end = txindex_to_first_outputindex_iter - .next_at(txindex + 1) - .map(|(_, v)| usize::from(v.into_inner())) - .unwrap_or_else(|| outputindex_to_value_iter.len()); - StoredUsize::from((start..end).count()) - }) - }, - )?; - let txindex_to_output_value = ComputedVec::forced_import_or_init_from_3( computation, path, @@ -298,7 +250,7 @@ impl Vecs { Version::ZERO, compressed, indexer.vecs().txindex_to_first_outputindex.boxed_clone(), - txindex_to_output_count.boxed_clone(), + indexes.txindex_to_output_count.boxed_clone(), indexer.vecs().outputindex_to_value.boxed_clone(), |index: TxIndex, txindex_to_first_outputindex_iter, @@ -680,6 +632,14 @@ impl Vecs { .add_sum() .add_total(), )?, + indexes_to_utxo_count: ComputedVecsFromHeight::forced_import( + path, + "utxo_count_bis", + true, + Version::TWO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, txindex_to_is_coinbase, inputindex_to_value, // indexes_to_input_value, @@ -690,8 +650,6 @@ impl Vecs { txindex_to_feerate, txindex_to_vsize, txindex_to_weight, - txindex_to_input_count, - txindex_to_output_count, }) } @@ -723,7 +681,7 @@ impl Vecs { indexes, starting_indexes, exit, - Some(&self.txindex_to_input_count), + Some(&indexes.txindex_to_input_count), )?; self.indexes_to_output_count.compute_rest( @@ -731,7 +689,7 @@ impl Vecs { indexes, starting_indexes, exit, - Some(&self.txindex_to_output_count), + Some(&indexes.txindex_to_output_count), )?; let compute_indexes_to_tx_vany = @@ -851,7 +809,7 @@ impl Vecs { |vec, indexer, _, starting_indexes, exit| { let mut txindex_to_first_outputindex_iter = indexer.vecs().txindex_to_first_outputindex.iter(); - let mut txindex_to_output_count_iter = self.txindex_to_output_count.iter(); + let mut txindex_to_output_count_iter = indexes.txindex_to_output_count.iter(); let mut outputindex_to_value_iter = indexer.vecs().outputindex_to_value.iter(); vec.compute_transform( starting_indexes.height, @@ -886,7 +844,12 @@ impl Vecs { self.indexes_to_fee.sats.height.unwrap_sum().iter(); vec.compute_transform( starting_indexes.height, - self.indexes_to_coinbase.sats.height.as_ref().unwrap(), + self.indexes_to_coinbase + .sats + .height + .as_ref() + .unwrap() + .as_ref(), |(height, subsidy, ..)| { let fees = indexes_to_fee_sum_iter.unwrap_get_inner(height); (height, subsidy.checked_sub(fees).unwrap()) @@ -1076,6 +1039,58 @@ impl Vecs { }, )?; + self.indexes_to_utxo_count.compute_all( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + let mut input_count_iter = self + .indexes_to_input_count + .height + .unwrap_total() + .into_iter(); + let mut opreturn_count_iter = self + .indexes_to_opreturn_count + .height_extra + .unwrap_total() + .into_iter(); + v.compute_transform( + starting_indexes.height, + self.indexes_to_output_count.height.unwrap_total(), + |(h, output_count, ..)| { + let input_count = input_count_iter.unwrap_get_inner(h); + let opreturn_count = opreturn_count_iter.unwrap_get_inner(h); + let block_count = usize::from(h + 1_usize); + // -1 > genesis output is unspendable + let mut utxo_count = + *output_count - (*input_count - block_count) - *opreturn_count - 1; + + // txid dup: e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468 + // Block 91_722 https://mempool.space/block/00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e + // Block 91_880 https://mempool.space/block/00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721 + // + // txid dup: d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599 + // Block 91_812 https://mempool.space/block/00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f + // Block 91_842 https://mempool.space/block/00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec + // + // Warning: Dups invalidate the previous coinbase according to + // https://chainquery.com/bitcoin-cli/gettxoutsetinfo + + if h >= Height::new(91_842) { + utxo_count -= 1; + } + if h >= Height::new(91_880) { + utxo_count -= 1; + } + + (h, StoredUsize::from(utxo_count)) + }, + exit, + ) + }, + )?; + Ok(()) } @@ -1085,10 +1100,8 @@ impl Vecs { &self.inputindex_to_value as &dyn AnyCollectableVec, &self.txindex_to_fee, &self.txindex_to_feerate, - &self.txindex_to_input_count, &self.txindex_to_input_value, &self.txindex_to_is_coinbase, - &self.txindex_to_output_count, &self.txindex_to_output_value, &self.txindex_to_vsize, &self.txindex_to_weight, @@ -1117,6 +1130,7 @@ impl Vecs { self.indexes_to_tx_vsize.vecs(), self.indexes_to_tx_weight.vecs(), self.indexes_to_unknownoutput_count.vecs(), + self.indexes_to_utxo_count.vecs(), ] .concat() } diff --git a/crates/brk_computer/src/vecs/utxos.rs b/crates/brk_computer/src/vecs/utxos.rs new file mode 100644 index 000000000..1a7354a97 --- /dev/null +++ b/crates/brk_computer/src/vecs/utxos.rs @@ -0,0 +1,181 @@ +use std::{fs, path::Path}; + +use brk_core::{CheckedSub, Dollars, Height, Sats, StoredUsize}; +use brk_exit::Exit; +use brk_indexer::Indexer; +use brk_vec::{ + AnyCollectableVec, AnyVec, BaseVecIterator, Compressed, Computation, EagerVec, StoredIndex, + VecIterator, Version, +}; +use derive_deref::{Deref, DerefMut}; + +use crate::states::{CohortStates, Outputs}; + +use super::{ + Indexes, + grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, + indexes, transactions, +}; + +#[derive(Clone, Deref, DerefMut)] +pub struct Vecs(Outputs); + +#[derive(Clone)] +pub struct Vecs_ { + pub height_to_realized_cap: EagerVec, + pub indexes_to_realized_cap: ComputedVecsFromHeight, + pub height_to_supply: EagerVec, + pub indexes_to_supply: ComputedVecsFromHeight, + pub height_to_utxo_count: EagerVec, + pub indexes_to_utxo_count: ComputedVecsFromHeight, +} + +const VERSION: Version = Version::ZERO; + +impl Vecs { + pub fn forced_import( + path: &Path, + _computation: Computation, + compressed: Compressed, + ) -> color_eyre::Result { + fs::create_dir_all(path)?; + + Ok(Self(Outputs { + all: Vecs_ { + height_to_realized_cap: EagerVec::forced_import( + &path.join("height_to_realized_cap"), + VERSION + Version::ZERO, + compressed, + )?, + indexes_to_realized_cap: ComputedVecsFromHeight::forced_import( + path, + "realized_cap", + false, + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + height_to_supply: EagerVec::forced_import( + &path.join("height_to_supply"), + VERSION + Version::ZERO, + compressed, + )?, + indexes_to_supply: ComputedVecsFromHeight::forced_import( + path, + "supply", + false, + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + height_to_utxo_count: EagerVec::forced_import( + &path.join("height_to_utxo_count"), + VERSION + Version::new(111), + compressed, + )?, + indexes_to_utxo_count: ComputedVecsFromHeight::forced_import( + path, + "utxo_count", + false, + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + }, + })) + } + + pub fn compute( + &mut self, + indexer: &Indexer, + indexes: &indexes::Vecs, + transactions: &transactions::Vecs, + starting_indexes: &Indexes, + exit: &Exit, + ) -> color_eyre::Result<()> { + let indexer_vecs = indexer.vecs(); + + let height_to_first_outputindex = &indexer_vecs.height_to_first_outputindex; + let height_to_first_inputindex = &indexer_vecs.height_to_first_inputindex; + let height_to_output_count = transactions.indexes_to_output_count.height.unwrap_last(); + let height_to_input_count = transactions.indexes_to_input_count.height.unwrap_last(); + let inputindex_to_outputindex = &indexer_vecs.inputindex_to_outputindex; + let outputindex_to_value = &indexer_vecs.outputindex_to_value; + let txindex_to_height = &indexes.txindex_to_height; + let outputindex_to_txindex = &indexes.outputindex_to_txindex; + + let mut height_to_first_outputindex_iter = height_to_first_outputindex.into_iter(); + let mut height_to_first_inputindex_iter = height_to_first_inputindex.into_iter(); + let mut height_to_output_count_iter = height_to_output_count.into_iter(); + let mut height_to_input_count_iter = height_to_input_count.into_iter(); + let mut inputindex_to_outputindex_iter = inputindex_to_outputindex.into_iter(); + let mut outputindex_to_value_iter = outputindex_to_value.into_iter(); + let mut txindex_to_height_iter = txindex_to_height.into_iter(); + let mut outputindex_to_txindex_iter = outputindex_to_txindex.into_iter(); + + let base_version = Version::ZERO + + height_to_first_outputindex.version() + + height_to_first_inputindex.version() + + height_to_output_count.version() + + height_to_input_count.version() + + inputindex_to_outputindex.version() + + outputindex_to_value.version() + + txindex_to_height.version() + + outputindex_to_txindex.version(); + + let height_to_realized_cap = &mut self.0.all.height_to_realized_cap; + let height_to_supply = &mut self.0.all.height_to_supply; + let height_to_utxo_count = &mut self.0.all.height_to_utxo_count; + + height_to_realized_cap.validate_computed_version_or_reset_file( + base_version + height_to_realized_cap.inner_version(), + )?; + height_to_supply.validate_computed_version_or_reset_file( + base_version + height_to_supply.inner_version(), + )?; + height_to_utxo_count.validate_computed_version_or_reset_file( + base_version + height_to_utxo_count.inner_version(), + )?; + + let starting_height = [ + height_to_realized_cap.len(), + height_to_supply.len(), + height_to_utxo_count.len(), + ] + .into_iter() + .map(Height::from) + .min() + .unwrap() + .min(starting_indexes.height); + + let mut states = CohortStates::default(); + + if let Some(prev_height) = starting_height.checked_sub(Height::new(1)) { + states.realized_cap = height_to_realized_cap + .into_iter() + .unwrap_get_inner(prev_height); + states.supply = height_to_supply.into_iter().unwrap_get_inner(prev_height); + states.utxo_count = height_to_utxo_count + .into_iter() + .unwrap_get_inner(prev_height); + } + + (starting_height.unwrap_to_usize()..height_to_first_outputindex_iter.len()) + .map(Height::from) + .try_for_each(|height| -> color_eyre::Result<()> { + let first_outputindex = height_to_first_outputindex_iter.unwrap_get_inner(height); + let first_inputindex = height_to_first_inputindex_iter.unwrap_get_inner(height); + let output_count = height_to_output_count_iter.unwrap_get_inner(height); + let input_count = height_to_input_count_iter.unwrap_get_inner(height); + + Ok(()) + })?; + + Ok(()) + } + + pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { + // [].concat() + vec![] + } +} diff --git a/crates/brk_core/src/structs/stored_f32.rs b/crates/brk_core/src/structs/stored_f32.rs index 005f1bdb1..595fdf02f 100644 --- a/crates/brk_core/src/structs/stored_f32.rs +++ b/crates/brk_core/src/structs/stored_f32.rs @@ -90,6 +90,13 @@ impl Div for StoredF32 { } } +impl Div for StoredF32 { + type Output = Self; + fn div(self, rhs: StoredF32) -> Self::Output { + Self::from(self.0 / rhs.0) + } +} + impl Mul for StoredF32 { type Output = Self; fn mul(self, rhs: usize) -> Self::Output { diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index a61dfbb5a..83cc22ada 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -744,18 +744,10 @@ impl Indexer { self.vecs.as_ref().unwrap() } - pub fn mut_vecs(&mut self) -> &mut Vecs { - self.vecs.as_mut().unwrap() - } - pub fn stores(&self) -> &Stores { self.stores.as_ref().unwrap() } - pub fn mut_stores(&mut self) -> &mut Stores { - self.stores.as_mut().unwrap() - } - pub fn keyspace(&self) -> &TransactionalKeyspace { &self.stores().keyspace } diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index 432cc1444..2ea6c30aa 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -84,9 +84,8 @@ impl Parser { thread::spawn(move || { let xor_bytes = xor_bytes; - blk_index_to_blk_path - .range(blk_index..) - .try_for_each(move |(blk_index, blk_path)| { + let _ = blk_index_to_blk_path.range(blk_index..).try_for_each( + move |(blk_index, blk_path)| { let mut xor_i = XORIndex::default(); let blk_index = *blk_index; @@ -139,7 +138,8 @@ impl Parser { } ControlFlow::Continue(()) - }); + }, + ); }); thread::spawn(move || { @@ -177,7 +177,7 @@ impl Parser { // Sending in bulk to not lock threads in standby drain_and_send(&mut bulk) - }); + })?; drain_and_send(&mut bulk) }); @@ -187,7 +187,7 @@ impl Parser { let mut future_blocks = BTreeMap::default(); - recv_block + let _ = recv_block .iter() .try_for_each(|(blk_metadata, block)| -> ControlFlow<(), _> { let hash = block.block_hash(); diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 4ce498f5d..484bc8b27 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -23,9 +23,9 @@ color-eyre = { workspace = true } jiff = { workspace = true } log = { workspace = true } minreq = { workspace = true } -oxc = { version = "0.69.0", features = ["codegen", "minifier"] } +oxc = { version = "0.70.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 = "2.6.1" +zip = "3.0.0" tracing = "0.1.41" diff --git a/crates/brk_server/src/files/file.rs b/crates/brk_server/src/files/file.rs index 1c88f1e4f..0e66ac775 100644 --- a/crates/brk_server/src/files/file.rs +++ b/crates/brk_server/src/files/file.rs @@ -38,7 +38,7 @@ fn any_handler( .expect("Should never reach here is websites_path is None") .join(app_state.website.to_folder_name()); - let response = if let Some(path) = path.as_ref() { + if let Some(path) = path.as_ref() { let path = path.0.replace("..", "").replace("\\", ""); let mut path = website_path.join(&path); @@ -62,9 +62,7 @@ fn any_handler( path_to_response(&headers, &path) } else { path_to_response(&headers, &website_path.join("index.html")) - }; - - response + } } fn path_to_response(headers: &HeaderMap, path: &Path) -> Response { diff --git a/websites/kibo.money/scripts/main.js b/websites/kibo.money/scripts/main.js index 737172d3c..83e0bb3e5 100644 --- a/websites/kibo.money/scripts/main.js +++ b/websites/kibo.money/scripts/main.js @@ -44,7 +44,8 @@ * "constant" | * "cagr" | * "vB" | - * "performance" + * "performance" | + * "zscore" * } Unit */ @@ -691,6 +692,8 @@ function createUtils() { unit = "Index"; } else if (id === "0" || id === "1" || id === "50" || id === "100") { unit = "constant"; + } else if (id.endsWith("zscore")) { + unit = "zscore"; } else if (id.endsWith("cagr")) { unit = "cagr"; } else if (id.endsWith("returns")) { diff --git a/websites/kibo.money/scripts/options.js b/websites/kibo.money/scripts/options.js index c9dd5851d..d15bfc14c 100644 --- a/websites/kibo.money/scripts/options.js +++ b/websites/kibo.money/scripts/options.js @@ -628,6 +628,16 @@ function createPartialOptions(colors) { }, }, }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-sma-ratio-zscore`, + title: "Score", + type: "Baseline", + options: { + createPriceLine: { + value: 0, + }, + }, + }), ], })), ], @@ -833,6 +843,106 @@ function createPartialOptions(colors) { }, ], }, + { + name: "Mining", + tree: [ + { + name: "Supply", + title: "Circulating Supply", + bottom: [ + createBaseSeries({ + key: "total-subsidy-in-btc", + name: "Mined", + }), + ], + }, + { + name: "Coinbase", + title: "Coinbase", + bottom: [ + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "coinbase", + name: "Coinbase", + }), + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "coinbase-in-btc", + name: "Coinbase", + }), + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "coinbase-in-usd", + name: "Coinbase", + }), + ], + }, + { + name: "Subsidy", + title: "Subsidy", + bottom: [ + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "subsidy", + name: "Subsidy", + }), + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "subsidy-in-btc", + name: "Subsidy", + }), + ...createBaseAverageSumTotalMinMaxPercentilesSeries({ + key: "subsidy-in-usd", + name: "Subsidy", + }), + ], + }, + { + name: "Fee", + title: "Transaction Fee", + bottom: [ + ...createAverageSumTotalMinMaxPercentilesSeries("fee"), + ...createAverageSumTotalMinMaxPercentilesSeries("fee-in-btc"), + ...createAverageSumTotalMinMaxPercentilesSeries("fee-in-usd"), + ], + }, + { + name: "Feerate", + title: "Transaction Fee Rate", + bottom: [ + createAverageSeries({ concat: "feerate" }), + ...createMinMaxPercentilesSeries({ + concat: "feerate", + }), + ], + }, + { + name: "Difficulty", + title: "Difficulty", + bottom: [ + createBaseSeries({ + key: "difficulty", + name: "Value", + }), + ], + }, + { + name: "Difficulty Epoch", + title: "Difficulty Epoch", + bottom: [ + createBaseSeries({ + key: "difficultyepoch", + name: "Epoch", + }), + ], + }, + { + name: "Halving Epoch", + title: "Halving Epoch", + bottom: [ + createBaseSeries({ + key: "halvingepoch", + name: "Epoch", + }), + ], + }, + ], + }, { name: "Block", tree: [ @@ -988,6 +1098,16 @@ function createPartialOptions(colors) { }), ], }, + { + name: "Unspent Count", + title: "Unspent Transaction Output Count", + bottom: [ + createBaseSeries({ + key: "utxo-count-bis", + name: "total", + }), + ], + }, // { // name: "Value", // title: "Transaction Output Value", @@ -1215,106 +1335,6 @@ function createPartialOptions(colors) { }, ], }, - { - name: "Mining", - tree: [ - { - name: "Supply", - title: "Circulating Supply", - bottom: [ - createBaseSeries({ - key: "total-subsidy-in-btc", - name: "Mined", - }), - ], - }, - { - name: "Coinbase", - title: "Coinbase", - bottom: [ - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "coinbase", - name: "Coinbase", - }), - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "coinbase-in-btc", - name: "Coinbase", - }), - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "coinbase-in-usd", - name: "Coinbase", - }), - ], - }, - { - name: "Subsidy", - title: "Subsidy", - bottom: [ - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "subsidy", - name: "Subsidy", - }), - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "subsidy-in-btc", - name: "Subsidy", - }), - ...createBaseAverageSumTotalMinMaxPercentilesSeries({ - key: "subsidy-in-usd", - name: "Subsidy", - }), - ], - }, - { - name: "Fee", - title: "Transaction Fee", - bottom: [ - ...createAverageSumTotalMinMaxPercentilesSeries("fee"), - ...createAverageSumTotalMinMaxPercentilesSeries("fee-in-btc"), - ...createAverageSumTotalMinMaxPercentilesSeries("fee-in-usd"), - ], - }, - { - name: "Feerate", - title: "Transaction Fee Rate", - bottom: [ - createAverageSeries({ concat: "feerate" }), - ...createMinMaxPercentilesSeries({ - concat: "feerate", - }), - ], - }, - { - name: "Difficulty", - title: "Difficulty", - bottom: [ - createBaseSeries({ - key: "difficulty", - name: "Value", - }), - ], - }, - { - name: "Difficulty Epoch", - title: "Difficulty Epoch", - bottom: [ - createBaseSeries({ - key: "difficultyepoch", - name: "Epoch", - }), - ], - }, - { - name: "Halving Epoch", - title: "Halving Epoch", - bottom: [ - createBaseSeries({ - key: "halvingepoch", - name: "Epoch", - }), - ], - }, - ], - }, ], }, { diff --git a/websites/kibo.money/scripts/vecid-to-indexes.js b/websites/kibo.money/scripts/vecid-to-indexes.js index ed6ceda57..cfd5fe54f 100644 --- a/websites/kibo.money/scripts/vecid-to-indexes.js +++ b/websites/kibo.money/scripts/vecid-to-indexes.js @@ -97,6 +97,7 @@ export function createVecIdToIndexes() { "13d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "13d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "13d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "13d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -129,6 +130,7 @@ export function createVecIdToIndexes() { "144d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "144d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1d-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -166,6 +168,7 @@ export function createVecIdToIndexes() { "1m-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1m-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -202,6 +205,7 @@ export function createVecIdToIndexes() { "1w-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1w-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -238,6 +242,7 @@ export function createVecIdToIndexes() { "1y-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1y-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "200w-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "200w-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "200w-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -270,6 +275,7 @@ export function createVecIdToIndexes() { "200w-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "200w-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "200w-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "200w-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -302,6 +308,7 @@ export function createVecIdToIndexes() { "21d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "21d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -340,6 +347,7 @@ export function createVecIdToIndexes() { "2y-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -372,6 +380,7 @@ export function createVecIdToIndexes() { "34d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "34d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "3m-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "3m-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "3m-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -420,6 +429,7 @@ export function createVecIdToIndexes() { "4y-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "4y-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "4y-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "50": [DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -453,6 +463,7 @@ export function createVecIdToIndexes() { "55d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "55d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "5y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "5y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "5y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -501,6 +512,7 @@ export function createVecIdToIndexes() { "89d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "89d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "89d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "89d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -533,6 +545,7 @@ export function createVecIdToIndexes() { "8d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8d-sma-ratio-zscore": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -976,7 +989,7 @@ export function createVecIdToIndexes() { "tx-weight-median": [Height], "tx-weight-min": [DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "txid": [TxIndex], - "txindex": [EmptyOutputIndex, OpReturnIndex, P2MSIndex, TxIndex, UnknownOutputIndex], + "txindex": [EmptyOutputIndex, OpReturnIndex, OutputIndex, P2MSIndex, TxIndex, UnknownOutputIndex], "txindex-count": [Height], "txversion": [TxIndex], "unknownoutput-count": [Height], @@ -990,6 +1003,7 @@ export function createVecIdToIndexes() { "unknownoutput-count-min": [DateIndex, DecadeIndex, DifficultyEpoch, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "unknownoutput-count-sum": [DateIndex, DecadeIndex, DifficultyEpoch, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "unknownoutputindex": [UnknownOutputIndex], + "utxo-count-bis": [DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "value": [InputIndex, OutputIndex], "vbytes": [Height], "vsize": [TxIndex],