From dfe5148f17e240ad7c51542312d13ad6837b470b Mon Sep 17 00:00:00 2001 From: nym21 Date: Fri, 26 Sep 2025 00:04:14 +0200 Subject: [PATCH] bitview: reorg part 5 --- Cargo.lock | 69 +- crates/brk_cli/src/bridge.rs | 6 +- crates/brk_mcp/Cargo.toml | 5 +- crates/brk_mcp/src/lib.rs | 2 +- .../scripts/core/{chart.js => chart/index.js} | 21 +- websites/bitview/scripts/core/chart/oklch.js | 100 ++ websites/bitview/scripts/core/colors.js | 101 -- .../bitview/scripts/core/options/partial.js | 935 +++++++++--------- websites/bitview/scripts/core/serde.js | 68 +- websites/bitview/scripts/core/timing.js | 12 - websites/bitview/scripts/entry.js | 3 +- websites/bitview/scripts/lazy.js | 17 +- websites/bitview/scripts/main.js | 48 +- websites/packages/brk/.gitignore | 2 + websites/packages/brk/idle.js | 11 + .../core/api.js => packages/brk/index.js} | 99 +- websites/packages/brk/serde.js | 64 ++ websites/packages/brk/standalone.js | 4 + websites/packages/brk/types.js | 9 + .../{wrapper.js => index.js} | 2 - .../solidjs-signals/{wrapper.js => index.js} | 1 - 21 files changed, 769 insertions(+), 810 deletions(-) rename websites/bitview/scripts/core/{chart.js => chart/index.js} (98%) create mode 100644 websites/bitview/scripts/core/chart/oklch.js create mode 100644 websites/packages/brk/.gitignore create mode 100644 websites/packages/brk/idle.js rename websites/{bitview/scripts/core/api.js => packages/brk/index.js} (75%) create mode 100644 websites/packages/brk/serde.js create mode 100644 websites/packages/brk/standalone.js create mode 100644 websites/packages/brk/types.js rename websites/packages/modern-screenshot/{wrapper.js => index.js} (97%) rename websites/packages/solidjs-signals/{wrapper.js => index.js} (99%) diff --git a/Cargo.lock b/Cargo.lock index 74d0afc91..51119a6ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,9 +182,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "async-compression" -version = "0.4.30" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "977eb15ea9efd848bb8a4a1a2500347ed7f0bf794edf0dc3ddcf439f43d36b23" +checksum = "9611ec0b6acea03372540509035db2f7f1e9f04da5d27728436fa994033c00a0" dependencies = [ "compression-codecs", "compression-core", @@ -656,6 +656,7 @@ dependencies = [ "brk_interface", "brk_rmcp", "log", + "serde_json", ] [[package]] @@ -674,9 +675,9 @@ dependencies = [ [[package]] name = "brk_rmcp" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5788307976c7fbc3b549b56c70fd6b1893d609e08e82d470d6938b748742cf54" +checksum = "ac54fb0335b049bce158a31900681dd6b328d5cd3640e76c478c1067eb50fc79" dependencies = [ "base64 0.22.1", "brk_rmcp-macros", @@ -704,9 +705,9 @@ dependencies = [ [[package]] name = "brk_rmcp-macros" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b49ac541e14b18e43696144176faeabc547ce198cb10d575c13fcc6245d337c" +checksum = "241b6c6ee464ae951e152122567e4fd5e4443ee1ed484bd575530de3afb72f99" dependencies = [ "darling", "proc-macro2", @@ -1560,12 +1561,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071" dependencies = [ "powerfmt", - "serde", + "serde_core", ] [[package]] @@ -2475,14 +2476,23 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.80" +version = "0.3.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852f13bec5eba4ba9afbeb93fd7c13fe56147f055939ae21c43a29a0ecb2702e" +checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" dependencies = [ "once_cell", "wasm-bindgen", ] +[[package]] +name = "json-escape-simd" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a1f7d5786a4cb0f4e0f862b562a0e085b5bfa23a4f0dc05e7b823ed4e4d791f" +dependencies = [ + "anyhow", +] + [[package]] name = "json-strip-comments" version = "3.0.1" @@ -2532,9 +2542,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.175" +version = "0.2.176" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" [[package]] name = "libredox" @@ -3193,9 +3203,9 @@ dependencies = [ [[package]] name = "oxc_resolver" -version = "11.8.2" +version = "11.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c4a4d746f42bac28538163952aa66da2f0ea781a0708772d8ad3f6fc066963" +checksum = "c553f3d6a88eb57513b4bb6b8387ab71c7701721ecd242b673ffeb3dc99cfd08" dependencies = [ "cfg-if", "indexmap 2.11.4", @@ -3238,11 +3248,12 @@ dependencies = [ [[package]] name = "oxc_sourcemap" -version = "4.1.2" +version = "4.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87a91923e9269b32c91cd956596f9c3bd24b60a89df5c815abb2812a0ffa8b7b" +checksum = "f6194c58467a15d9dcb5cb852fcad312af57fd46fabd419fae87fcf801f83702" dependencies = [ "base64-simd", + "json-escape-simd", "rustc-hash", "serde", "serde_json", @@ -4502,9 +4513,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.22.0" +version = "3.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", "getrandom 0.3.3", @@ -5131,9 +5142,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.103" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab10a69fbd0a177f5f649ad4d8d3305499c42bab9aef2f7ff592d0ec8f833819" +checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" dependencies = [ "cfg-if", "once_cell", @@ -5144,9 +5155,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.103" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb702423545a6007bbc368fde243ba47ca275e549c8a28617f56f6ba53b1d1c" +checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" dependencies = [ "bumpalo", "log", @@ -5158,9 +5169,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.103" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc65f4f411d91494355917b605e1480033152658d71f722a90647f56a70c88a0" +checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5168,9 +5179,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.103" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc003a991398a8ee604a401e194b6b3a39677b3173d6e74495eb51b82e99a32" +checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" dependencies = [ "proc-macro2", "quote", @@ -5181,9 +5192,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.103" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "293c37f4efa430ca14db3721dfbe48d8c33308096bd44d80ebaa775ab71ba1cf" +checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" dependencies = [ "unicode-ident", ] diff --git a/crates/brk_cli/src/bridge.rs b/crates/brk_cli/src/bridge.rs index 4b407dc4b..e467df158 100644 --- a/crates/brk_cli/src/bridge.rs +++ b/crates/brk_cli/src/bridge.rs @@ -29,7 +29,7 @@ impl Bridge for Interface<'static> { fs::create_dir_all(&path)?; - generate_vecs_file(self, &path)?; + generate_metrics_file(self, &path)?; generate_pools_file(&path) } } @@ -70,8 +70,8 @@ return /** @type {const} */ ({ fs::write(path, contents) } -fn generate_vecs_file(interface: &Interface<'static>, parent: &Path) -> io::Result<()> { - let path = parent.join(Path::new("vecs.js")); +fn generate_metrics_file(interface: &Interface<'static>, parent: &Path) -> io::Result<()> { + let path = parent.join(Path::new("metrics.js")); let indexes = Index::all(); diff --git a/crates/brk_mcp/Cargo.toml b/crates/brk_mcp/Cargo.toml index d9ce8657c..e3b0646cd 100644 --- a/crates/brk_mcp/Cargo.toml +++ b/crates/brk_mcp/Cargo.toml @@ -12,8 +12,9 @@ build = "build.rs" [dependencies] axum = { workspace = true } brk_interface = { workspace = true } -log = { workspace = true } -brk_rmcp = { version = "0.6.0", features = [ +brk_rmcp = { version = "0.7.1", features = [ "transport-worker", "transport-streamable-http-server", ] } +log = { workspace = true } +serde_json = { workspace = true } diff --git a/crates/brk_mcp/src/lib.rs b/crates/brk_mcp/src/lib.rs index ef258690b..0e6e0978d 100644 --- a/crates/brk_mcp/src/lib.rs +++ b/crates/brk_mcp/src/lib.rs @@ -3,7 +3,7 @@ use brk_interface::{IdParam, Interface, PaginatedIndexParam, PaginationParam, Params}; use brk_rmcp::{ ErrorData as McpError, RoleServer, ServerHandler, - handler::server::{router::tool::ToolRouter, tool::Parameters}, + handler::server::{router::tool::ToolRouter, wrapper::Parameters}, model::*, service::RequestContext, tool, tool_handler, tool_router, diff --git a/websites/bitview/scripts/core/chart.js b/websites/bitview/scripts/core/chart/index.js similarity index 98% rename from websites/bitview/scripts/core/chart.js rename to websites/bitview/scripts/core/chart/index.js index 5f97178c5..5fb06d7c4 100644 --- a/websites/bitview/scripts/core/chart.js +++ b/websites/bitview/scripts/core/chart/index.js @@ -1,4 +1,4 @@ -/** @import { IChartApi, ISeriesApi as _ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData as _BaselineData, HistogramData as _HistogramData, SeriesType, IPaneApi, LineSeriesPartialOptions as _LineSeriesPartialOptions, HistogramSeriesPartialOptions as _HistogramSeriesPartialOptions, BaselineSeriesPartialOptions as _BaselineSeriesPartialOptions, CandlestickSeriesPartialOptions as _CandlestickSeriesPartialOptions, WhitespaceData, DeepPartial, ChartOptions, Time, LineData as _LineData } from '../packages/lightweight-charts/5.0.8/dist/typings' */ +/** @import { IChartApi, ISeriesApi as _ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData as _BaselineData, HistogramData as _HistogramData, SeriesType, IPaneApi, LineSeriesPartialOptions as _LineSeriesPartialOptions, HistogramSeriesPartialOptions as _HistogramSeriesPartialOptions, BaselineSeriesPartialOptions as _BaselineSeriesPartialOptions, CandlestickSeriesPartialOptions as _CandlestickSeriesPartialOptions, WhitespaceData, DeepPartial, ChartOptions, Time, LineData as _LineData } from '../../packages/lightweight-charts/5.0.8/dist/typings' */ import { createChart, @@ -7,20 +7,18 @@ import { LineSeries, BaselineSeries, // } from "../packages/lightweight-charts/5.0.8/dist/lightweight-charts.standalone.development.mjs"; -} from "../packages/lightweight-charts/5.0.8/dist/lightweight-charts.standalone.production.mjs"; +} from "../../packages/lightweight-charts/5.0.8/dist/lightweight-charts.standalone.production.mjs"; import { createHorizontalChoiceField, createLabeledInput, createSpanName, -} from "./dom"; -import { createOklchToRGBA } from "./colors"; -import { throttle } from "./timing"; -import { serdeBool } from "./serde"; +} from "../dom"; +import { createOklchToRGBA } from "./oklch"; +import { throttle } from "../timing"; +import { serdeBool } from "../serde"; /** - * @typedef {[number, number, number, number]} OHLCTuple - * * @typedef {Object} Valued * @property {number} value * @@ -1003,7 +1001,7 @@ function numberToShortUSFormat(value, digits) { return numberToUSFormat(value, Math.min(1, digits || 10)); } else if (absoluteValue < 1_000_000) { return numberToUSFormat(value, 0); - } else if (absoluteValue >= 900_000_000_000_000_000_000_000) { + } else if (absoluteValue >= 1_000_000_000_000_000_000_000) { return "Inf."; } @@ -1015,11 +1013,6 @@ function numberToShortUSFormat(value, digits) { const modulused = log % 3; - // return `${numberToUSFormat( - // value / (1_000_000 * 1_000 ** letterIndex), - // 3, - // )}${letter}`; - if (modulused === 0) { return `${numberToUSFormat( value / (1_000_000 * 1_000 ** letterIndex), diff --git a/websites/bitview/scripts/core/chart/oklch.js b/websites/bitview/scripts/core/chart/oklch.js new file mode 100644 index 000000000..a2ed84141 --- /dev/null +++ b/websites/bitview/scripts/core/chart/oklch.js @@ -0,0 +1,100 @@ +export function createOklchToRGBA() { + { + /** + * + * @param {readonly [number, number, number, number, number, number, number, number, number]} A + * @param {readonly [number, number, number]} B + * @returns + */ + function multiplyMatrices(A, B) { + return /** @type {const} */ ([ + A[0] * B[0] + A[1] * B[1] + A[2] * B[2], + A[3] * B[0] + A[4] * B[1] + A[5] * B[2], + A[6] * B[0] + A[7] * B[1] + A[8] * B[2], + ]); + } + /** + * @param {readonly [number, number, number]} param0 + */ + function oklch2oklab([l, c, h]) { + return /** @type {const} */ ([ + l, + isNaN(h) ? 0 : c * Math.cos((h * Math.PI) / 180), + isNaN(h) ? 0 : c * Math.sin((h * Math.PI) / 180), + ]); + } + /** + * @param {readonly [number, number, number]} rgb + */ + function srgbLinear2rgb(rgb) { + return rgb.map((c) => + Math.abs(c) > 0.0031308 + ? (c < 0 ? -1 : 1) * (1.055 * Math.abs(c) ** (1 / 2.4) - 0.055) + : 12.92 * c, + ); + } + /** + * @param {readonly [number, number, number]} lab + */ + function oklab2xyz(lab) { + const LMSg = multiplyMatrices( + /** @type {const} */ ([ + 1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586, + -0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092, + ]), + lab, + ); + const LMS = /** @type {[number, number, number]} */ ( + LMSg.map((val) => val ** 3) + ); + return multiplyMatrices( + /** @type {const} */ ([ + 1.2268798758459243, -0.5578149944602171, 0.2813910456659647, + -0.0405757452148008, 1.112286803280317, -0.0717110580655164, + -0.0763729366746601, -0.4214933324022432, 1.5869240198367816, + ]), + LMS, + ); + } + /** + * @param {readonly [number, number, number]} xyz + */ + function xyz2rgbLinear(xyz) { + return multiplyMatrices( + [ + 3.2409699419045226, -1.537383177570094, -0.4986107602930034, + -0.9692436362808796, 1.8759675015077202, 0.04155505740717559, + 0.05563007969699366, -0.20397695888897652, 1.0569715142428786, + ], + xyz, + ); + } + + /** @param {string} oklch */ + return function (oklch) { + oklch = oklch.replace("oklch(", ""); + oklch = oklch.replace(")", ""); + let splitOklch = oklch.split(" / "); + let alpha = 1; + if (splitOklch.length === 2) { + alpha = Number(splitOklch.pop()?.replace("%", "")) / 100; + } + splitOklch = oklch.split(" "); + const lch = splitOklch.map((v, i) => { + if (!i && v.includes("%")) { + return Number(v.replace("%", "")) / 100; + } else { + return Number(v); + } + }); + const rgb = srgbLinear2rgb( + xyz2rgbLinear( + oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch))), + ), + ).map((v) => { + return Math.max(Math.min(Math.round(v * 255), 255), 0); + }); + return [...rgb, alpha]; + }; + } +} diff --git a/websites/bitview/scripts/core/colors.js b/websites/bitview/scripts/core/colors.js index 09842380f..6069546aa 100644 --- a/websites/bitview/scripts/core/colors.js +++ b/websites/bitview/scripts/core/colors.js @@ -114,104 +114,3 @@ export function createColors(dark) { * @typedef {Colors["orange"]} Color * @typedef {keyof Colors} ColorName */ - -export function createOklchToRGBA() { - { - /** - * - * @param {readonly [number, number, number, number, number, number, number, number, number]} A - * @param {readonly [number, number, number]} B - * @returns - */ - function multiplyMatrices(A, B) { - return /** @type {const} */ ([ - A[0] * B[0] + A[1] * B[1] + A[2] * B[2], - A[3] * B[0] + A[4] * B[1] + A[5] * B[2], - A[6] * B[0] + A[7] * B[1] + A[8] * B[2], - ]); - } - /** - * @param {readonly [number, number, number]} param0 - */ - function oklch2oklab([l, c, h]) { - return /** @type {const} */ ([ - l, - isNaN(h) ? 0 : c * Math.cos((h * Math.PI) / 180), - isNaN(h) ? 0 : c * Math.sin((h * Math.PI) / 180), - ]); - } - /** - * @param {readonly [number, number, number]} rgb - */ - function srgbLinear2rgb(rgb) { - return rgb.map((c) => - Math.abs(c) > 0.0031308 - ? (c < 0 ? -1 : 1) * (1.055 * Math.abs(c) ** (1 / 2.4) - 0.055) - : 12.92 * c, - ); - } - /** - * @param {readonly [number, number, number]} lab - */ - function oklab2xyz(lab) { - const LMSg = multiplyMatrices( - /** @type {const} */ ([ - 1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586, - -0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092, - ]), - lab, - ); - const LMS = /** @type {[number, number, number]} */ ( - LMSg.map((val) => val ** 3) - ); - return multiplyMatrices( - /** @type {const} */ ([ - 1.2268798758459243, -0.5578149944602171, 0.2813910456659647, - -0.0405757452148008, 1.112286803280317, -0.0717110580655164, - -0.0763729366746601, -0.4214933324022432, 1.5869240198367816, - ]), - LMS, - ); - } - /** - * @param {readonly [number, number, number]} xyz - */ - function xyz2rgbLinear(xyz) { - return multiplyMatrices( - [ - 3.2409699419045226, -1.537383177570094, -0.4986107602930034, - -0.9692436362808796, 1.8759675015077202, 0.04155505740717559, - 0.05563007969699366, -0.20397695888897652, 1.0569715142428786, - ], - xyz, - ); - } - - /** @param {string} oklch */ - return function (oklch) { - oklch = oklch.replace("oklch(", ""); - oklch = oklch.replace(")", ""); - let splitOklch = oklch.split(" / "); - let alpha = 1; - if (splitOklch.length === 2) { - alpha = Number(splitOklch.pop()?.replace("%", "")) / 100; - } - splitOklch = oklch.split(" "); - const lch = splitOklch.map((v, i) => { - if (!i && v.includes("%")) { - return Number(v.replace("%", "")) / 100; - } else { - return Number(v); - } - }); - const rgb = srgbLinear2rgb( - xyz2rgbLinear( - oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch))), - ), - ).map((v) => { - return Math.max(Math.min(Math.round(v * 255), 255), 0); - }); - return [...rgb, alpha]; - }; - } -} diff --git a/websites/bitview/scripts/core/options/partial.js b/websites/bitview/scripts/core/options/partial.js index 4a4b83815..894dd2587 100644 --- a/websites/bitview/scripts/core/options/partial.js +++ b/websites/bitview/scripts/core/options/partial.js @@ -468,7 +468,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { const utxosUnderAmount = underAmount.map( ({ id, name, title, color }) => /** @type {const} */ ({ - metric: `utxos_${id}`, + id: `utxos_${id}`, name, title: `UTXOs ${title}`, color, @@ -545,12 +545,12 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ); const type = /** @type {const} */ ([ - ["p2pk65", "Pay To Long Public Key", "red"], - ["p2pk33", "Pay To Short Public Key", "orange"], - ["p2pkh", "Pay To Public Key Hash", "yellow"], + ["p2pk65", "Pay To Long Public id", "red"], + ["p2pk33", "Pay To Short Public id", "orange"], + ["p2pkh", "Pay To Public id Hash", "yellow"], ["p2ms_outputs", "Pay To Bare Multisig", "lime"], ["p2sh", "Pay To Script Hash", "green"], - ["p2wpkh", "Pay To Witness Public Key Hash", "teal"], + ["p2wpkh", "Pay To Witness Public id Hash", "teal"], ["p2wsh", "Pay To Witness Script Hash", "blue"], ["p2tr", "Pay To Taproot", "indigo"], ["p2a", "Pay To Anchor", "purple"], @@ -572,11 +572,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ["active_price", "Active", "rose"], ["cointime_price", "cointime", "yellow"], ]).map( - ([id, name, colorKey]) => + ([metric, name, colorKey]) => /** @type {const} */ ({ - id, + metric, name, - title: id.replace(/_/g, " "), + title: metric.replace(/_/g, " "), color: colors[colorKey], }), ); @@ -589,7 +589,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ["thermo", "emerald"], ]).map(([id, colorKey]) => { return /** @type {const} */ ({ - id: `${id}_cap`, + metric: `${id}_cap`, name: id, title: `${id} Capitalization`, color: colors[colorKey], @@ -681,14 +681,12 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { } /** - * @param {Object} args - * @param {MetricAverageBase} args.metric - * @param {string} [args.title] + * @param {MetricAverageBase} metric */ - function createAverageSeries({ metric, title = "" }) { + function createAverageSeries(metric) { return /** @satisfies {AnyFetchedSeriesBlueprint} */ ({ metric: `${metric}_avg`, - title: `Average ${title}`, + title: "Average", }); } @@ -750,51 +748,49 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { } /** - * @param {Object} args - * @param {MetricMinBase & MetricMaxBase & MetricPct90Base & MetricPct75Base & MetricMedianBase & MetricPct25Base & MetricPct10Base} args.metric - * @param {string} [args.title] + * @param {MetricMinBase & MetricMaxBase & MetricPct90Base & MetricPct75Base & MetricMedianBase & MetricPct25Base & MetricPct10Base} metric */ - function createMinMaxPercentilesSeries({ metric, title = "" }) { + function createMinMaxPercentilesSeries(metric) { return /** @satisfies {AnyFetchedSeriesBlueprint[]} */ ([ { metric: `${metric}_max`, - title: `Max ${title}`, + title: "Max", color: colors.pink, defaultActive: false, }, { metric: `${metric}_min`, - title: `Min ${title}`, + title: "Min", color: colors.green, defaultActive: false, }, { metric: `${metric}_median`, - title: `Median ${title}`, + title: "Median", color: colors.amber, defaultActive: false, }, { metric: `${metric}_pct75`, - title: `pct75 ${title}`, + title: "pct75", color: colors.red, defaultActive: false, }, { metric: `${metric}_pct25`, - title: `pct25 ${title}`, + title: "pct25", color: colors.yellow, defaultActive: false, }, { metric: `${metric}_pct90`, - title: `pct90 ${title}`, + title: "pct90", color: colors.rose, defaultActive: false, }, { metric: `${metric}_pct10`, - title: `pct10 ${title}`, + title: "pct10", color: colors.lime, defaultActive: false, }, @@ -807,7 +803,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { function createSumCumulativeMinMaxPercentilesSeries(metric) { return [ ...createSumCumulativeSeries({ metric }), - ...createMinMaxPercentilesSeries({ metric }), + ...createMinMaxPercentilesSeries(metric), ]; } @@ -816,7 +812,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { */ function createAverageSumCumulativeMinMaxPercentilesSeries(metric) { return [ - createAverageSeries({ metric }), + createAverageSeries(metric), ...createSumCumulativeMinMaxPercentilesSeries(metric), ]; } @@ -1193,7 +1189,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { * @property {string} args.name * @property {string} args.title * @property {Color} args.color - * @property {"" | CohortId} args.key + * @property {"" | CohortId} args.id */ /** @@ -1205,11 +1201,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { /** * @template {"" | CohortId} T - * @param {T} key + * @param {T} id */ - const applySuffixIfNeeded = (key) => - key !== "" - ? /** @type {Exclude<"" | `${T}_`, "_">} */ (`${key}_`) + const fixId = (id) => + id !== "" + ? /** @type {Exclude<"" | `${T}_`, "_">} */ (`${id}_`) : /** @type {const} */ (""); /** @@ -1230,65 +1226,65 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ? { name: "supply", title: `Supply ${title}`, - bottom: list.flatMap(({ color, name, id: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}supply`, + metric: `${id}supply`, name: "Supply", color: colors.default, }), createBaseSeries({ - metric: `${key}supply_btc`, + metric: `${id}supply_btc`, name: "Supply", color: colors.default, }), createBaseSeries({ - metric: `${key}supply_usd`, + metric: `${id}supply_usd`, name: "Supply", color: colors.default, }), - ...(key + ...(id ? [ createBaseSeries({ - metric: `${key}supply_rel_to_circulating_supply`, + metric: `${id}supply_rel_to_circulating_supply`, name: "Supply", color: colors.default, }), ] : []), createBaseSeries({ - metric: `${key}supply_in_profit`, + metric: `${id}supply_in_profit`, name: "In Profit", color: colors.green, }), createBaseSeries({ - metric: `${key}supply_in_profit_btc`, + metric: `${id}supply_in_profit_btc`, name: "In Profit", color: colors.green, }), createBaseSeries({ - metric: `${key}supply_in_profit_usd`, + metric: `${id}supply_in_profit_usd`, name: "In Profit", color: colors.green, }), createBaseSeries({ - metric: `${key}supply_in_loss`, + metric: `${id}supply_in_loss`, name: "In Loss", color: colors.red, }), createBaseSeries({ - metric: `${key}supply_in_loss_btc`, + metric: `${id}supply_in_loss_btc`, name: "In Loss", color: colors.red, }), createBaseSeries({ - metric: `${key}supply_in_loss_usd`, + metric: `${id}supply_in_loss_usd`, name: "In Loss", color: colors.red, }), createBaseSeries({ - metric: `${key}supply_half`, + metric: `${id}supply_half`, name: "half", color: colors.gray, options: { @@ -1296,7 +1292,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, }), createBaseSeries({ - metric: `${key}supply_half_btc`, + metric: `${id}supply_half_btc`, name: useGroupName ? name : "half", color: "list" in args ? color : colors.gray, options: { @@ -1304,34 +1300,34 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, }), createBaseSeries({ - metric: `${key}supply_half_usd`, + metric: `${id}supply_half_usd`, name: useGroupName ? name : "half", color: "list" in args ? color : colors.gray, options: { lineStyle: 4, }, }), - ...(key + ...(id ? [ createBaseSeries({ - metric: `${key}supply_in_profit_rel_to_circulating_supply`, + metric: `${id}supply_in_profit_rel_to_circulating_supply`, name: "In Profit", color: colors.green, }), createBaseSeries({ - metric: `${key}supply_in_loss_rel_to_circulating_supply`, + metric: `${id}supply_in_loss_rel_to_circulating_supply`, name: "In Loss", color: colors.red, }), ] : []), createBaseSeries({ - metric: `${key}supply_in_profit_rel_to_own_supply`, + metric: `${id}supply_in_profit_rel_to_own_supply`, name: "In Profit", color: colors.green, }), createBaseSeries({ - metric: `${key}supply_in_loss_rel_to_own_supply`, + metric: `${id}supply_in_loss_rel_to_own_supply`, name: "In Loss", color: colors.red, }), @@ -1354,27 +1350,27 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "total", title: `Supply ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}supply`, + metric: `${id}supply`, name, color, }), createBaseSeries({ - metric: `${key}supply_btc`, + metric: `${id}supply_btc`, name, color, }), createBaseSeries({ - metric: `${key}supply_usd`, + metric: `${id}supply_usd`, name, color, }), - key + id ? createBaseSeries({ - metric: `${key}supply_rel_to_circulating_supply`, + metric: `${id}supply_rel_to_circulating_supply`, name, color, }) @@ -1390,28 +1386,28 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "in profit", title: `Supply In Profit ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}supply_in_profit`, + metric: `${id}supply_in_profit`, name, color, }), createBaseSeries({ - metric: `${key}supply_in_profit_btc`, + metric: `${id}supply_in_profit_btc`, name, color, }), createBaseSeries({ - metric: `${key}supply_in_profit_usd`, + metric: `${id}supply_in_profit_usd`, name, color, }), - ...(key + ...(id ? [ createBaseSeries({ - metric: `${key}supply_in_profit_rel_to_circulating_supply`, + metric: `${id}supply_in_profit_rel_to_circulating_supply`, name, color, }), @@ -1423,28 +1419,28 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "in loss", title: `Supply In loss ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}supply_in_loss`, + metric: `${id}supply_in_loss`, name, color, }), createBaseSeries({ - metric: `${key}supply_in_loss_btc`, + metric: `${id}supply_in_loss_btc`, name, color, }), createBaseSeries({ - metric: `${key}supply_in_loss_usd`, + metric: `${id}supply_in_loss_usd`, name, color, }), - ...(key + ...(id ? [ createBaseSeries({ - metric: `${key}supply_in_loss_rel_to_circulating_supply`, + metric: `${id}supply_in_loss_rel_to_circulating_supply`, name, color, }), @@ -1458,47 +1454,43 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "utxo count", title: `UTXO Count ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}utxo_count`, + metric: `${id}utxo_count`, name: useGroupName ? name : "Count", color, }), ]); }), }, - ...(list.filter( - ({ key }) => - `${applySuffixIfNeeded(key)}addr_count` in metricToIndexes, - ).length > ("list" in args ? 1 : 0) + ...(list.filter(({ id }) => `${fixId(id)}addr_count` in metricToIndexes) + .length > ("list" in args ? 1 : 0) ? !("list" in args) || list.filter( - ({ key }) => - `${applySuffixIfNeeded(key)}empty_addr_count` in - metricToIndexes, + ({ id }) => `${fixId(id)}empty_addr_count` in metricToIndexes, ).length <= 1 ? [ { name: "address count", title: `Address Count ${title}`, - bottom: list.flatMap(({ name, color, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ name, color, id: _id }) => { + const id = fixId(_id); return [ - ...(`${key}addr_count` in metricToIndexes + ...(`${id}addr_count` in metricToIndexes ? /** @type {const} */ ([ createBaseSeries({ - metric: `${key}addr_count`, + metric: `${id}addr_count`, name: useGroupName ? name : "Loaded", color: useGroupName ? color : colors.orange, }), ]) : []), - ...(`${key}empty_addr_count` in metricToIndexes + ...(`${id}empty_addr_count` in metricToIndexes ? /** @type {const} */ ([ createBaseSeries({ - metric: `${key}empty_addr_count`, + metric: `${id}empty_addr_count`, name: "Empty", color: colors.gray, defaultActive: false, @@ -1518,15 +1510,14 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Loaded Address Count ${title}`, bottom: list .filter( - ({ key }) => - `${applySuffixIfNeeded(key)}addr_count` in - metricToIndexes, + ({ id }) => + `${fixId(id)}addr_count` in metricToIndexes, ) - .flatMap(({ name, color, key: _key }) => { - const key = applySuffixIfNeeded(_key); + .flatMap(({ name, color, id: _id }) => { + const id = fixId(_id); return [ createBaseSeries({ - metric: `${key}addr_count`, + metric: `${id}addr_count`, name, color, }), @@ -1534,9 +1525,8 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }), }, ...(list.filter( - ({ key }) => - `${applySuffixIfNeeded(key)}empty_addr_count` in - metricToIndexes, + ({ id }) => + `${fixId(id)}empty_addr_count` in metricToIndexes, ).length ? [ { @@ -1544,15 +1534,15 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Empty Address Count ${title}`, bottom: list .filter( - ({ key }) => - `${applySuffixIfNeeded(key)}empty_addr_count` in + ({ id }) => + `${fixId(id)}empty_addr_count` in metricToIndexes, ) - .flatMap(({ name, color, key: _key }) => { - const key = applySuffixIfNeeded(_key); + .flatMap(({ name, color, id: _id }) => { + const id = fixId(_id); return [ createBaseSeries({ - metric: `${key}empty_addr_count`, + metric: `${id}empty_addr_count`, name, color, }), @@ -1573,9 +1563,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Price", title: `Realized Price ${title}`, - top: list.map(({ color, name, key }) => + top: list.map(({ color, name, id }) => createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}realized_price`, + metric: `${fixId(id)}realized_price`, name, color, }), @@ -1585,9 +1575,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Ratio", title: `Realized Price Ratio ${title}`, bottom: [ - ...list.map(({ color, name, key }) => + ...list.map(({ color, name, id }) => createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}realized_price_ratio`, + metric: `${fixId(id)}realized_price_ratio`, name, color, }), @@ -1601,7 +1591,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ] : createPriceWithRatioOptions({ title: `Realized Price ${title}`, - metric: `${applySuffixIfNeeded(args.key)}realized_price`, + metric: `${fixId(args.id)}realized_price`, name: "price", legend: "realized", color: args.color, @@ -1609,11 +1599,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "capitalization", title: `Realized Capitalization ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_cap`, + metric: `${id}realized_cap`, name: useGroupName ? name : "Capitalization", color, }), @@ -1621,7 +1611,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${key}realized_cap_30d_delta`, + metric: `${id}realized_cap_30d_delta`, title: "30d change", defaultActive: false, }), @@ -1632,11 +1622,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ] : []), ...(!("list" in args) && - `${key}realized_cap_rel_to_own_market_cap` in metricToIndexes + `${id}realized_cap_rel_to_own_market_cap` in metricToIndexes ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${key}realized_cap_rel_to_own_market_cap`, + metric: `${id}realized_cap_rel_to_own_market_cap`, title: "ratio", options: { baseValue: { price: 100 } }, colors: [colors.red, colors.green], @@ -1658,22 +1648,22 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Realized Profit And Loss ${title}`, bottom: [ createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}realized_profit`, + metric: `${fixId(args.id)}realized_profit`, name: "Profit", color: colors.green, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}realized_loss`, + metric: `${fixId(args.id)}realized_loss`, name: "Loss", color: colors.red, defaultActive: false, }), - ...(`${applySuffixIfNeeded(args.key)}realized_profit_to_loss_ratio` in + ...(`${fixId(args.id)}realized_profit_to_loss_ratio` in metricToIndexes ? [ createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}realized_profit_to_loss_ratio`, name: "proft / loss", color: colors.yellow, @@ -1681,46 +1671,46 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ] : []), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}total_realized_pnl`, + metric: `${fixId(args.id)}total_realized_pnl`, name: "Total", color: colors.default, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}neg_realized_loss`, + metric: `${fixId(args.id)}neg_realized_loss`, name: "Negative Loss", color: colors.red, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}realized_profit_cumulative`, + metric: `${fixId(args.id)}realized_profit_cumulative`, name: "Cumulative Profit", color: colors.green, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}realized_loss_cumulative`, + metric: `${fixId(args.id)}realized_loss_cumulative`, name: "Cumulative Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}neg_realized_loss_cumulative`, + metric: `${fixId(args.id)}neg_realized_loss_cumulative`, name: "Cumulative Negative Loss", color: colors.red, defaultActive: false, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}realized_profit_rel_to_realized_cap`, title: "Profit", color: colors.green, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}realized_loss_rel_to_realized_cap`, title: "Loss", color: colors.red, @@ -1737,45 +1727,45 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Net pnl", title: `Net Realized Profit And Loss ${title}`, - bottom: list.flatMap(({ color, name, key }) => [ + bottom: list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_realized_pnl`, + metric: `${fixId(id)}net_realized_pnl`, title: "Raw", }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_realized_pnl_cumulative`, + metric: `${fixId(id)}net_realized_pnl_cumulative`, title: "Cumulative", defaultActive: false, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta`, title: "cumulative 30d change", defaultActive: false, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_rel_to_realized_cap`, title: "Raw", }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap`, title: "cumulative 30d change", defaultActive: false, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta_rel_to_market_cap`, title: "cumulative 30d change", }), @@ -1793,9 +1783,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "sopr", title: `Spent Output Profit Ratio ${title}`, - bottom: list.flatMap(({ color, name, key }) => { - const soprKey = `${applySuffixIfNeeded(key)}sopr`; - const asoprKey = `${applySuffixIfNeeded(key)}adjusted_sopr`; + bottom: list.flatMap(({ color, name, id }) => { + const soprKey = `${fixId(id)}sopr`; + const asoprKey = `${fixId(id)}adjusted_sopr`; return [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", @@ -1892,17 +1882,17 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "profit", title: `Realized Profit ${title}`, bottom: [ - ...list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + ...list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_profit`, + metric: `${id}realized_profit`, name, color, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${key}realized_profit_rel_to_realized_cap`, + metric: `${id}realized_profit_rel_to_realized_cap`, title: name, color, }), @@ -1917,17 +1907,17 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "loss", title: `Realized Loss ${title}`, bottom: [ - ...list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + ...list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_loss`, + metric: `${id}realized_loss`, name, color, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${key}realized_loss_rel_to_realized_cap`, + metric: `${id}realized_loss_rel_to_realized_cap`, title: name, color, }), @@ -1942,19 +1932,19 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Total pnl", title: `Total Realized Profit And Loss Loss ${title}`, bottom: [ - ...list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + ...list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}total_realized_pnl`, + metric: `${id}total_realized_pnl`, name, color, }), - ...(`${key}realized_profit_to_loss_ratio` in + ...(`${id}realized_profit_to_loss_ratio` in metricToIndexes ? [ createBaseSeries({ - metric: `${key}realized_profit_to_loss_ratio`, + metric: `${id}realized_profit_to_loss_ratio`, name, color, }), @@ -1968,17 +1958,17 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Net pnl", title: `Net Realized Profit And Loss ${title}`, bottom: [ - ...list.flatMap(({ color, name, key }) => [ + ...list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_realized_pnl`, + metric: `${fixId(id)}net_realized_pnl`, title: name, color, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_rel_to_realized_cap`, title: name, color, @@ -1998,11 +1988,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "profit", title: `Cumulative Realized Profit ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_profit_cumulative`, + metric: `${id}realized_profit_cumulative`, name, color, }), @@ -2012,11 +2002,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "loss", title: `Cumulative Realized Loss ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_loss_cumulative`, + metric: `${id}realized_loss_cumulative`, name, color, }), @@ -2027,10 +2017,10 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Net pnl", title: `Cumulative Net Realized Profit And Loss ${title}`, bottom: [ - ...list.flatMap(({ color, name, key }) => [ + ...list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_realized_pnl_cumulative`, + metric: `${fixId(id)}net_realized_pnl_cumulative`, title: name, color, defaultActive: false, @@ -2045,27 +2035,27 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Net pnl 30d change", title: `Cumulative Net Realized Profit And Loss 30 Day Change ${title}`, bottom: [ - ...list.flatMap(({ color, name, key }) => [ + ...list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta`, title: name, color, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap`, title: name, color, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_realized_pnl_cumulative_30d_delta_rel_to_market_cap`, title: name, color, @@ -2091,10 +2081,10 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Normal", title: `Spent Output Profit Ratio ${title}`, bottom: [ - ...list.flatMap(({ color, name, key }) => [ + ...list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}sopr`, + metric: `${fixId(id)}sopr`, title: name, color, }), @@ -2107,12 +2097,12 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, ...(() => { const reducedList = list - .map(({ color, name, key }) => ({ + .map(({ color, name, id }) => ({ color, name, - metric: `${applySuffixIfNeeded(key)}adjusted_sopr`, + metric: `${fixId(id)}adjusted_sopr`, })) - .filter(({ key }) => key in metricToIndexes); + .filter(({ metric }) => metric in metricToIndexes); return reducedList.length ? [ @@ -2121,10 +2111,10 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Adjusted Spent Output Profit Ratio ${title}`, bottom: [ ...reducedList.flatMap( - ({ color, name, key }) => [ + ({ color, name, metric }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key, + metric, title: name, color, }), @@ -2146,28 +2136,28 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Sell Side Risk", title: `Sell Side Risk Ratio ${title}`, bottom: !("list" in args) - ? list.flatMap(({ key }) => [ + ? list.flatMap(({ id }) => [ createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}sell_side_risk_ratio`, + metric: `${fixId(id)}sell_side_risk_ratio`, name: "raw", color: colors.orange, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}sell_side_risk_ratio_7d_ema`, + metric: `${fixId(id)}sell_side_risk_ratio_7d_ema`, name: "7d ema", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}sell_side_risk_ratio_30d_ema`, + metric: `${fixId(id)}sell_side_risk_ratio_30d_ema`, name: "30d ema", color: colors.rose, defaultActive: false, }), ]) - : list.flatMap(({ color, name, key }) => [ + : list.flatMap(({ color, name, id }) => [ createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}sell_side_risk_ratio`, + metric: `${fixId(id)}sell_side_risk_ratio`, name, color: color, }), @@ -2181,9 +2171,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "created", title: `value created ${title}`, - bottom: list.flatMap(({ color, name, key }) => { - const normalKey = `${applySuffixIfNeeded(key)}value_created`; - const adjKey = `${applySuffixIfNeeded(key)}adjusted_value_created`; + bottom: list.flatMap(({ color, name, id }) => { + const normalKey = `${fixId(id)}value_created`; + const adjKey = `${fixId(id)}adjusted_value_created`; return [ createBaseSeries({ metric: normalKey, @@ -2205,11 +2195,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "destroyed", title: `value destroyed ${title}`, - bottom: list.flatMap(({ color, name, key }) => { - const normalKey = `${applySuffixIfNeeded(key)}value_destroyed`; - const adjKey = `${applySuffixIfNeeded( - key, - )}adjusted_value_destroyed`; + bottom: list.flatMap(({ color, name, id }) => { + const normalKey = `${fixId(id)}value_destroyed`; + const adjKey = `${fixId(id)}adjusted_value_destroyed`; return [ createBaseSeries({ metric: normalKey, @@ -2236,9 +2224,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Normal", title: `Value Created ${title}`, - bottom: list.flatMap(({ color, name, key }) => [ + bottom: list.flatMap(({ color, name, id }) => [ createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}value_created`, + metric: `${fixId(id)}value_created`, name, color, }), @@ -2246,21 +2234,23 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, ...(() => { const reducedList = list - .map(({ color, name, key }) => ({ + .map(({ color, name, id }) => ({ color, name, - metric: `${applySuffixIfNeeded(key)}adjusted_value_created`, + metric: `${fixId(id)}adjusted_value_created`, })) - .filter(({ key }) => key in metricToIndexes); + .filter( + ({ metric }) => metric in metricToIndexes, + ); return reducedList.length ? [ { name: "Adjusted", title: `Adjusted value created ${title}`, bottom: reducedList.map( - ({ color, name, key }) => + ({ color, name, metric }) => createBaseSeries({ - key, + metric, name, color, }), @@ -2277,9 +2267,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Normal", title: `Value destroyed ${title}`, - bottom: list.flatMap(({ color, name, key }) => [ + bottom: list.flatMap(({ color, name, id }) => [ createBaseSeries({ - metric: `${applySuffixIfNeeded(key)}value_destroyed`, + metric: `${fixId(id)}value_destroyed`, name, color, }), @@ -2287,21 +2277,23 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, ...(() => { const reducedList = list - .map(({ color, name, key }) => ({ + .map(({ color, name, id }) => ({ color, name, - metric: `${applySuffixIfNeeded(key)}adjusted_value_destroyed`, + metric: `${fixId(id)}adjusted_value_destroyed`, })) - .filter(({ key }) => key in metricToIndexes); + .filter( + ({ metric }) => metric in metricToIndexes, + ); return reducedList.length ? [ { name: "Adjusted", title: `Adjusted value destroyed ${title}`, bottom: reducedList.map( - ({ color, name, key }) => + ({ color, name, metric }) => createBaseSeries({ - key, + metric, name, color, }), @@ -2327,71 +2319,71 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Unrealized Profit And Loss ${title}`, bottom: [ createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}total_unrealized_pnl`, + metric: `${fixId(args.id)}total_unrealized_pnl`, name: "total", color: colors.default, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}unrealized_profit`, + metric: `${fixId(args.id)}unrealized_profit`, name: "Profit", color: colors.green, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}unrealized_loss`, + metric: `${fixId(args.id)}unrealized_loss`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}neg_unrealized_loss`, + metric: `${fixId(args.id)}neg_unrealized_loss`, name: "Negative Loss", color: colors.red, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_profit_rel_to_market_cap`, name: "Profit", color: colors.green, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_loss_rel_to_market_cap`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}neg_unrealized_loss_rel_to_market_cap`, name: "Negative Loss", color: colors.red, }), - ...(`${applySuffixIfNeeded( - args.key, + ...(`${fixId( + args.id, )}unrealized_profit_rel_to_own_market_cap` in metricToIndexes ? [ createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_profit_rel_to_own_market_cap`, name: "Profit", color: colors.green, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_loss_rel_to_own_market_cap`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}neg_unrealized_loss_rel_to_own_market_cap`, name: "Negative Loss", color: colors.red, @@ -2405,29 +2397,29 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }), ] : []), - ...(`${applySuffixIfNeeded( - args.key, + ...(`${fixId( + args.id, )}unrealized_profit_rel_to_own_total_unrealized_pnl` in metricToIndexes ? [ createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_profit_rel_to_own_total_unrealized_pnl`, name: "Profit", color: colors.green, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}unrealized_loss_rel_to_own_total_unrealized_pnl`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded( - args.key, + metric: `${fixId( + args.id, )}neg_unrealized_loss_rel_to_own_total_unrealized_pnl`, name: "Negative Loss", color: colors.red, @@ -2456,11 +2448,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "profit", title: `Unrealized Profit ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}unrealized_profit`, + metric: `${id}unrealized_profit`, name, color, }), @@ -2470,11 +2462,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "loss", title: `Unrealized Loss ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}unrealized_loss`, + metric: `${id}unrealized_loss`, name, color, }), @@ -2484,11 +2476,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "total pnl", title: `Unrealized Total Profit And Loss ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}total_unrealized_pnl`, + metric: `${id}total_unrealized_pnl`, name, color, }), @@ -2500,27 +2492,26 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Net pnl", title: `Net Unrealized Profit And Loss ${title}`, bottom: [ - ...list.flatMap(({ color, name, key }) => [ + ...list.flatMap(({ color, name, id }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_unrealized_pnl`, + metric: `${fixId(id)}net_unrealized_pnl`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded(key)}net_unrealized_pnl_rel_to_market_cap`, + metric: `${fixId(id)}net_unrealized_pnl_rel_to_market_cap`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), - ...(`${applySuffixIfNeeded( - key, - )}net_unrealized_pnl_rel_to_own_market_cap` in metricToIndexes + ...(`${fixId(id)}net_unrealized_pnl_rel_to_own_market_cap` in + metricToIndexes ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_unrealized_pnl_rel_to_own_market_cap`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, @@ -2530,15 +2521,15 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }), ] : []), - ...(`${applySuffixIfNeeded( - key, + ...(`${fixId( + id, )}net_unrealized_pnl_rel_to_own_total_unrealized_pnl` in metricToIndexes ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - metric: `${applySuffixIfNeeded( - key, + metric: `${fixId( + id, )}net_unrealized_pnl_rel_to_own_total_unrealized_pnl`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, @@ -2567,11 +2558,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Average", title: `Average Cost Basis ${title}`, - top: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + top: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}realized_price`, + metric: `${id}realized_price`, name, color: color, }), @@ -2581,11 +2572,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Min", title: `Min Cost Basis ${title}`, - top: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + top: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}min_price_paid`, + metric: `${id}min_price_paid`, name, color: color, }), @@ -2595,11 +2586,11 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Max", title: `Max Cost Basis ${title}`, - top: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + top: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}max_price_paid`, + metric: `${id}max_price_paid`, name, color: color, }), @@ -2615,21 +2606,20 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Costs Basis ${title}`, top: [ createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}realized_price`, + metric: `${fixId(args.id)}realized_price`, name: "Average", color: args.color, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}min_price_paid`, + metric: `${fixId(args.id)}min_price_paid`, name: "Min", color: colors.green, - // defaultActive: false, + defaultActive: false, }), createBaseSeries({ - metric: `${applySuffixIfNeeded(args.key)}max_price_paid`, + metric: `${fixId(args.id)}max_price_paid`, name: "Max", color: colors.red, - // defaultActive: false, }), ], }, @@ -2637,27 +2627,27 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Coins Destroyed", title: `Coins Destroyed ${title}`, - bottom: list.flatMap(({ color, name, key: _key }) => { - const key = applySuffixIfNeeded(_key); + bottom: list.flatMap(({ color, name, id: _id }) => { + const id = fixId(_id); return /** @type {const} */ ([ createBaseSeries({ - metric: `${key}coinblocks_destroyed`, + metric: `${id}coinblocks_destroyed`, name: useGroupName ? name : "sum", color, }), createBaseSeries({ - metric: `${key}coinblocks_destroyed_cumulative`, + metric: `${id}coinblocks_destroyed_cumulative`, name: useGroupName ? name : "cumulative", color, defaultActive: false, }), createBaseSeries({ - metric: `${key}coindays_destroyed`, + metric: `${id}coindays_destroyed`, name: useGroupName ? name : "sum", color, }), createBaseSeries({ - metric: `${key}coindays_destroyed_cumulative`, + metric: `${id}coindays_destroyed_cumulative`, name: useGroupName ? name : "cumulative", color, defaultActive: false, @@ -2750,18 +2740,18 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Compare", title: `Market Price ${nameAddon} Moving Averages`, - top: averages.map(({ days, key, name, color }) => + top: averages.map(({ days, id, name, color }) => createBaseSeries({ - metric: `price_${key}_${metricAddon}`, - name: key, + metric: `price_${id}_${metricAddon}`, + name: id, color, }), ), }, - ...averages.map(({ key, name, color }) => ({ + ...averages.map(({ id, name, color }) => ({ name, tree: createPriceWithRatioOptions({ - metric: `price_${key}_${metricAddon}`, + metric: `price_${id}_${metricAddon}`, name, title: `${name} Market Price ${nameAddon} Moving Average`, legend: "average", @@ -2774,45 +2764,49 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Performance", tree: /** @type {const} */ ([ - { name: "1 Day", metric: "1d" }, - { name: "1 Week", metric: "1w" }, - { name: "1 Month", metric: "1m" }, - { name: "3 Month", metric: "3m" }, - { name: "6 Month", metric: "6m" }, - { name: "1 Year", metric: "1y" }, - { name: "2 Year", metric: "2y" }, - { name: "3 Year", metric: "3y" }, - { name: "4 Year", metric: "4y" }, - { name: "5 Year", metric: "5y" }, - { name: "6 Year", metric: "6y" }, - { name: "8 Year", metric: "8y" }, - { name: "10 Year", metric: "10y" }, - ]).map(({ name, metric }) => ({ - name, - title: `${name} Performance`, - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${metric}_price_returns`, - title: "Returns", - type: "Baseline", - }), - createPriceLine({ - unit: "percentage", - }), - ...(`${metric}_cagr` in metricToIndexes - ? [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${metric}_cagr`, - title: "cagr", - type: "Baseline", - }), - createPriceLine({ - unit: "percentage", - }), - ] - : []), - ], - })), + "1d", + "1w", + "1m", + "3m", + "6m", + "1y", + "2y", + "3y", + "4y", + "5y", + "6y", + "8y", + "10y", + ]).map((id) => { + const name = periodIdToName(id, true); + const cagr = `${id}_cagr`; + return { + name, + title: `${name} Performance`, + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_price_returns`, + title: "Returns", + type: "Baseline", + }), + createPriceLine({ + unit: "percentage", + }), + ...(cagr in metricToIndexes + ? [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: cagr, + title: "cagr", + type: "Baseline", + }), + createPriceLine({ + unit: "percentage", + }), + ] + : []), + ], + }; + }), }, { name: "Indicators", @@ -2934,103 +2928,104 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "DCA vs Lump sum", tree: [ .../** @type {const} */ ([ - { name: "1 Week", key: "1w" }, - { name: "1 Month", key: "1m" }, - { name: "3 Month", key: "3m" }, - { name: "6 Month", key: "6m" }, - { name: "1 Year", key: "1y" }, - ]).map( - ({ name, key }) => - /** @satisfies {PartialChartOption} */ ({ - name, - title: `${name} DCA vs Lump Sum Returns`, - top: [ - createBaseSeries({ - metric: `${key}_dca_avg_price`, - name: `dca`, - color: colors.orange, - }), - createBaseSeries({ - metric: `price_${key}_ago`, - name: `lump sum`, - color: colors.cyan, - }), - ], - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_dca_returns`, - title: "dca", - type: "Baseline", - colors: [colors.yellow, colors.pink], - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_price_returns`, - title: "lump sum", - type: "Baseline", - }), - createPriceLine({ - unit: "percentage", - }), - ], - }), - ), - .../** @type {const} */ ([ - { name: "2 Year", metric: "2y" }, - { name: "3 Year", metric: "3y" }, - { name: "4 Year", metric: "4y" }, - { name: "5 Year", metric: "5y" }, - { name: "6 Year", metric: "6y" }, - { name: "8 Year", metric: "8y" }, - { name: "10 Year", metric: "10y" }, - ]).map( - ({ name, key }) => - /** @satisfies {PartialChartOption} */ ({ - name, - title: `${name} DCA vs Lump Sum Returns`, - top: [ - createBaseSeries({ - metric: `${key}_dca_avg_price`, - name: `dca`, - color: colors.orange, - }), - createBaseSeries({ - metric: `price_${key}_ago`, - name: `lump sum`, - color: colors.cyan, - }), - ], - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_dca_returns`, - title: "dca", - type: "Baseline", - colors: [colors.yellow, colors.pink], - }), + "1w", + "1m", + "3m", + "6m", + "1y", + ]).map((id) => { + const name = periodIdToName(id, true); - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_price_returns`, - title: "lump sum", - type: "Baseline", - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_dca_cagr`, - title: "dca cagr", - type: "Baseline", - colors: [colors.yellow, colors.pink], - defaultActive: false, - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - metric: `${key}_cagr`, - title: "lump sum cagr", - type: "Baseline", - defaultActive: false, - }), - createPriceLine({ - unit: "percentage", - }), - ], - }), - ), + return /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} DCA vs Lump Sum Returns`, + top: [ + createBaseSeries({ + metric: `${id}_dca_avg_price`, + name: `dca`, + color: colors.orange, + }), + createBaseSeries({ + metric: `price_${id}_ago`, + name: `lump sum`, + color: colors.cyan, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_dca_returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_price_returns`, + title: "lump sum", + type: "Baseline", + }), + createPriceLine({ + unit: "percentage", + }), + ], + }); + }), + .../** @type {const} */ ([ + "2y", + "3y", + "4y", + "5y", + "6y", + "8y", + "10y", + ]).map((id) => { + const name = periodIdToName(id, true); + return /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} DCA vs Lump Sum Returns`, + top: [ + createBaseSeries({ + metric: `${id}_dca_avg_price`, + name: `dca`, + color: colors.orange, + }), + createBaseSeries({ + metric: `price_${id}_ago`, + name: `lump sum`, + color: colors.cyan, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_dca_returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_price_returns`, + title: "lump sum", + type: "Baseline", + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_dca_cagr`, + title: "dca cagr", + type: "Baseline", + colors: [colors.yellow, colors.pink], + defaultActive: false, + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + metric: `${id}_cagr`, + title: "lump sum cagr", + type: "Baseline", + defaultActive: false, + }), + createPriceLine({ + unit: "percentage", + }), + ], + }); + }), ], }, { @@ -3127,10 +3122,8 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { metric: "interval", name: "Interval", }), - createAverageSeries({ concat: "block_interval" }), - ...createMinMaxPercentilesSeries({ - concat: "block_interval", - }), + createAverageSeries("block_interval"), + ...createMinMaxPercentilesSeries("block_interval"), createPriceLine({ unit: "secs", name: "Target", @@ -3154,10 +3147,6 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { metric: "weight", name: "raw", }), - // createBaseSeries({ - // metric: "weight", - // name: "Weight", - // }), ...createAverageSumCumulativeMinMaxPercentilesSeries( "block_size", ), @@ -3224,16 +3213,10 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Size", title: "Transaction Size", bottom: [ - createAverageSeries({ - concat: "tx_weight", - }), - ...createMinMaxPercentilesSeries({ - concat: "tx_weight", - }), - createAverageSeries({ concat: "tx_vsize" }), - ...createMinMaxPercentilesSeries({ - concat: "tx_vsize", - }), + createAverageSeries("tx_weight"), + ...createMinMaxPercentilesSeries("tx_weight"), + createAverageSeries("tx_vsize"), + ...createMinMaxPercentilesSeries("tx_vsize"), ], }, { @@ -3245,7 +3228,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { [colors.lime, colors.green], ].flatMap(([sumColor, cumulativeColor], index) => createSumCumulativeSeries({ - concat: `tx_v${index + 1}`, + metric: `tx_v${index + 1}`, common: `v${index + 1}`, sumColor, cumulativeColor, @@ -3286,13 +3269,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Count", title: "Transaction Input Count", bottom: [ - createAverageSeries({ concat: "input_count" }), - createCumulativeSeries({ - concat: "input_count", - }), - ...createMinMaxPercentilesSeries({ - concat: "input_count", - }), + createAverageSeries("input_count"), + createCumulativeSeries({ metric: "input_count" }), + ...createMinMaxPercentilesSeries("input_count"), ], }, { @@ -3322,13 +3301,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Count", title: "Transaction Output Count", bottom: [ - createAverageSeries({ concat: "output_count" }), - createCumulativeSeries({ - concat: "output_count", - }), - ...createMinMaxPercentilesSeries({ - concat: "output_count", - }), + createAverageSeries("output_count"), + createCumulativeSeries({ metric: "output_count" }), + ...createMinMaxPercentilesSeries("output_count"), ], }, { @@ -3463,13 +3438,13 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: "Unclaimed Rewards", bottom: [ ...createSumCumulativeSeries({ - concat: "unclaimed_rewards", + metric: "unclaimed_rewards", }), ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_btc", + metric: "unclaimed_rewards_btc", }), ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_usd", + metric: "unclaimed_rewards_usd", }), ], }, @@ -3499,10 +3474,8 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Feerate", title: "Transaction Fee Rate", bottom: [ - createAverageSeries({ concat: "fee_rate" }), - ...createMinMaxPercentilesSeries({ - concat: "fee_rate", - }), + createAverageSeries("fee_rate"), + ...createMinMaxPercentilesSeries("fee_rate"), ], }, { @@ -3679,8 +3652,8 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { }, { name: "Pools", - tree: Object.entries(pools).map(([_key, name]) => { - const key = /** @type {Pool} */ (_key); + tree: Object.entries(pools).map(([_id, name]) => { + const id = /** @type {Pool} */ (_id); return { name, tree: [ @@ -3689,29 +3662,29 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Mining Dominance of ${name}`, bottom: [ createBaseSeries({ - metric: `${key}_1d_dominance`, + metric: `${id}_1d_dominance`, name: "1d", color: colors.rose, defaultActive: false, }), createBaseSeries({ - metric: `${key}_1w_dominance`, + metric: `${id}_1w_dominance`, name: "1w", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${key}_1m_dominance`, + metric: `${id}_1m_dominance`, name: "1m", }), createBaseSeries({ - metric: `${key}_1y_dominance`, + metric: `${id}_1y_dominance`, name: "1y", color: colors.lime, defaultActive: false, }), createBaseSeries({ - metric: `${key}_dominance`, + metric: `${id}_dominance`, name: "all time", color: colors.teal, defaultActive: false, @@ -3723,28 +3696,28 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Blocks mined by ${name}`, bottom: [ createBaseSeries({ - metric: `${key}_blocks_mined`, + metric: `${id}_blocks_mined`, name: "Sum", }), createBaseSeries({ - metric: `${key}_blocks_mined_cumulative`, + metric: `${id}_blocks_mined_cumulative`, name: "Cumulative", color: colors.blue, }), createBaseSeries({ - metric: `${key}_1w_blocks_mined`, + metric: `${id}_1w_blocks_mined`, name: "1w Sum", color: colors.red, defaultActive: false, }), createBaseSeries({ - metric: `${key}_1m_blocks_mined`, + metric: `${id}_1m_blocks_mined`, name: "1m Sum", color: colors.pink, defaultActive: false, }), createBaseSeries({ - metric: `${key}_1y_blocks_mined`, + metric: `${id}_1y_blocks_mined`, name: "1y Sum", color: colors.purple, defaultActive: false, @@ -3773,19 +3746,19 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ].flatMap( ({ metricAddon, sumColor, cumulativeColor }) => [ ...createSumCumulativeSeries({ - concat: `${key}_${metricAddon}`, + metric: `${id}_${metricAddon}`, common: metricAddon, sumColor, cumulativeColor, }), ...createSumCumulativeSeries({ - concat: `${key}_${metricAddon}_btc`, + metric: `${id}_${metricAddon}_btc`, common: metricAddon, sumColor, cumulativeColor, }), ...createSumCumulativeSeries({ - concat: `${key}_${metricAddon}_usd`, + metric: `${id}_${metricAddon}_usd`, common: metricAddon, sumColor, cumulativeColor, @@ -3798,7 +3771,7 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { title: `Days since ${name} mined a block`, bottom: [ createBaseSeries({ - metric: `${key}_days_since_block`, + metric: `${id}_days_since_block`, name: "Since block", }), ], @@ -4023,18 +3996,18 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { { name: "Compare", title: "Compare Cointime Prices", - top: cointimePrices.map(({ key, name, color }) => + top: cointimePrices.map(({ metric, name, color }) => createBaseSeries({ - key, + metric, name, color, }), ), }, - ...cointimePrices.map(({ key, name, color, title }) => ({ + ...cointimePrices.map(({ metric, name, color, title }) => ({ name, tree: createPriceWithRatioOptions({ - metric: key, + metric, legend: name, color, name, @@ -4060,9 +4033,9 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { name: "Realized", color: colors.orange, }), - ...cointimeCapitalizations.map(({ key, name, color }) => + ...cointimeCapitalizations.map(({ metric, name, color }) => createBaseSeries({ - key, + metric, name, color, }), @@ -4070,12 +4043,12 @@ export function createPartialOptions({ env, colors, metricToIndexes, pools }) { ], }, ...cointimeCapitalizations.map( - ({ key, name, color, title }) => ({ + ({ metric, name, color, title }) => ({ name, title, bottom: [ createBaseSeries({ - key, + metric, name, color, }), diff --git a/websites/bitview/scripts/core/serde.js b/websites/bitview/scripts/core/serde.js index a3e289488..17895e042 100644 --- a/websites/bitview/scripts/core/serde.js +++ b/websites/bitview/scripts/core/serde.js @@ -101,9 +101,9 @@ export const serdeBool = { * @param {string} v */ deserialize(v) { - if (v === "true") { + if (v === "true" || v === "1") { return true; - } else if (v === "false") { + } else if (v === "false" || v === "0") { return false; } else { throw "deser bool err"; @@ -111,70 +111,6 @@ export const serdeBool = { }, }; -export const serdeIndex = { - /** - * @param {Index} v - */ - serialize(v) { - switch (v) { - case /** @satisfies {DateIndex} */ (0): - return "dateindex"; - case /** @satisfies {DecadeIndex} */ (1): - return "decadeindex"; - case /** @satisfies {DifficultyEpoch} */ (2): - return "difficultyepoch"; - case /** @satisfies {EmptyOutputIndex} */ (3): - return "emptyoutputindex"; - case /** @satisfies {HalvingEpoch} */ (4): - return "halvingepoch"; - case /** @satisfies {Height} */ (5): - return "height"; - case /** @satisfies {InputIndex} */ (6): - return "inputindex"; - case /** @satisfies {MonthIndex} */ (7): - return "monthindex"; - case /** @satisfies {OpReturnIndex} */ (8): - return "opreturnindex"; - case /** @satisfies {OutputIndex} */ (9): - return "outputindex"; - case /** @satisfies {P2AAddressIndex} */ (10): - return "p2aaddressindex"; - case /** @satisfies {P2MSOutputIndex} */ (11): - return "p2msoutputindex"; - case /** @satisfies {P2PK33AddressIndex} */ (12): - return "p2pk33addressindex"; - case /** @satisfies {P2PK65AddressIndex} */ (13): - return "p2pk65addressindex"; - case /** @satisfies {P2PKHAddressIndex} */ (14): - return "p2pkhaddressindex"; - case /** @satisfies {P2SHAddressIndex} */ (15): - return "p2shaddressindex"; - case /** @satisfies {P2TRAddressIndex} */ (16): - return "p2traddressindex"; - case /** @satisfies {P2WPKHAddressIndex} */ (17): - return "p2wpkhaddressindex"; - case /** @satisfies {P2WSHAddressIndex} */ (18): - return "p2wshaddressindex"; - case /** @satisfies {QuarterIndex} */ (19): - return "quarterindex"; - case /** @satisfies {SemesterIndex} */ (20): - return "semesterindex"; - case /** @satisfies {TxIndex} */ (21): - return "txindex"; - case /** @satisfies {UnknownOutputIndex} */ (22): - return "unknownoutputindex"; - case /** @satisfies {WeekIndex} */ (23): - return "weekindex"; - case /** @satisfies {YearIndex} */ (24): - return "yearindex"; - case /** @satisfies {LoadedAddressIndex} */ (25): - return "loadedaddressindex"; - case /** @satisfies {EmptyAddressIndex} */ (26): - return "emptyaddressindex"; - } - }, -}; - export const serdeChartableIndex = { /** * @param {number} v diff --git a/websites/bitview/scripts/core/timing.js b/websites/bitview/scripts/core/timing.js index fc8b92611..7cb3fd4f4 100644 --- a/websites/bitview/scripts/core/timing.js +++ b/websites/bitview/scripts/core/timing.js @@ -36,15 +36,3 @@ export function throttle(callback, wait = 1000) { } }; } - -/** - * @param {VoidFunction} callback - * @param {number} [timeout = 1] - */ -export function runWhenIdle(callback, timeout = 1) { - if ("requestIdleCallback" in window) { - requestIdleCallback(callback); - } else { - setTimeout(callback, timeout); - } -} diff --git a/websites/bitview/scripts/entry.js b/websites/bitview/scripts/entry.js index 7cb51af46..f6231ba83 100644 --- a/websites/bitview/scripts/entry.js +++ b/websites/bitview/scripts/entry.js @@ -1,6 +1,6 @@ /** * - * @import { Valued, SingleValueData, CandlestickData, OHLCTuple, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions, CreateChartElement, Chart } from "./core/chart" + * @import { Valued, SingleValueData, CandlestickData, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions, CreateChartElement, Chart } from "./core/chart/index" * * @import * as _ from "./packages/leeoniya-ufuzzy/1.0.19/dist/uFuzzy.d.ts" * @@ -26,7 +26,6 @@ * @typedef {typeof import("./core/utils")} Utilities * @typedef {typeof import("./core/env")["default"]} Env * @typedef {typeof import("./core/elements")["default"]} Elements - * @typedef {string} Metric */ // DO NOT CHANGE, Exact format is expected in `brk_bundler` diff --git a/websites/bitview/scripts/lazy.js b/websites/bitview/scripts/lazy.js index 500ccd9f3..308c1aaf9 100644 --- a/websites/bitview/scripts/lazy.js +++ b/websites/bitview/scripts/lazy.js @@ -1,12 +1,10 @@ const imports = { async signals() { - return import("./packages/solidjs-signals/wrapper.js").then( - (d) => d.default, - ); + return import("./packages/solidjs-signals/index.js").then((d) => d.default); }, async chart() { return window.document.fonts.ready.then(() => - import("./core/chart.js").then((d) => d.default), + import("./core/chart/index.js").then((d) => d.default), ); }, async leanQr() { @@ -18,18 +16,15 @@ const imports = { ); }, async modernScreenshot() { - return import("./packages/modern-screenshot/wrapper.js").then((d) => d); + return import("./packages/modern-screenshot/index.js").then((d) => d); + }, + async brk() { + return import("./packages/brk/index.js").then((d) => d); }, async options() { return import("./core/options/full.js").then((d) => d); }, - async vecs() { - return import("./bridge/vecs.js").then((d) => d); - }, - async pools() { - return import("./bridge/pools.js").then((d) => d); - }, }; /** diff --git a/websites/bitview/scripts/main.js b/websites/bitview/scripts/main.js index 8ee65c8a4..2576b5454 100644 --- a/websites/bitview/scripts/main.js +++ b/websites/bitview/scripts/main.js @@ -91,25 +91,13 @@ function initFrameSelectors() { } initFrameSelectors(); -Promise.all([ - packages.signals(), - packages.vecs(), - packages.pools(), - packages.options(), -]).then( - ([ - signals, - { createMetricToIndexes, VERSION }, - { createPools }, - { initOptions }, - ]) => +Promise.all([packages.signals(), packages.brk(), packages.options()]).then( + ([signals, { initOptions }]) => signals.createRoot(() => { const owner = signals.getOwner(); console.log(`VERSION = ${VERSION}`); - const metricToIndexes = createMetricToIndexes(); - if (env.localhost) { Object.keys(metricToIndexes).forEach((metric) => { serdeUnit.deserialize(metric); @@ -135,22 +123,22 @@ Promise.all([ const qrcode = signals.createSignal(/** @type {string | null} */ (null)); - function createLastHeightResource() { - const lastHeight = signals.createSignal(0); - function fetchLastHeight() { - utils.api.fetchLast( - (h) => { - lastHeight.set(h); - }, - /** @satisfies {Height} */ (5), - "height", - ); - } - fetchLastHeight(); - setInterval(fetchLastHeight, 10_000); - return lastHeight; - } - const lastHeight = createLastHeightResource(); + // function createLastHeightResource() { + // const lastHeight = signals.createSignal(0); + // function fetchLastHeight() { + // utils.api.fetchLast( + // (h) => { + // lastHeight.set(h); + // }, + // /** @satisfies {Height} */ (5), + // "height", + // ); + // } + // fetchLastHeight(); + // setInterval(fetchLastHeight, 10_000); + // return lastHeight; + // } + // const lastHeight = createLastHeightResource(); const webSockets = createWebSockets(signals); diff --git a/websites/packages/brk/.gitignore b/websites/packages/brk/.gitignore new file mode 100644 index 000000000..f11b74313 --- /dev/null +++ b/websites/packages/brk/.gitignore @@ -0,0 +1,2 @@ +pools.js +metrics.js diff --git a/websites/packages/brk/idle.js b/websites/packages/brk/idle.js new file mode 100644 index 000000000..22dcee191 --- /dev/null +++ b/websites/packages/brk/idle.js @@ -0,0 +1,11 @@ +/** + * @param {VoidFunction} callback + * @param {number} [timeout = 1] + */ +export function runWhenIdle(callback, timeout = 1) { + if ("requestIdleCallback" in window) { + requestIdleCallback(callback); + } else { + setTimeout(callback, timeout); + } +} diff --git a/websites/bitview/scripts/core/api.js b/websites/packages/brk/index.js similarity index 75% rename from websites/bitview/scripts/core/api.js rename to websites/packages/brk/index.js index 44b4a57fb..d44a38db3 100644 --- a/websites/bitview/scripts/core/api.js +++ b/websites/packages/brk/index.js @@ -1,15 +1,19 @@ import { serdeIndex } from "./serde"; -import { runWhenIdle } from "./timing"; +import { runWhenIdle } from "./idle"; +import { createPools } from "./pools"; +import { createMetricToIndexes } from "./metrics"; + +const localhost = window.location.hostname === "localhost"; /** * @param {Signals} signals - * @param {Utilities} utils - * @param {Env} env - * @param {MetricToIndexes} metricToIndexes */ -export function createVecsResources(signals, utils, env, metricToIndexes) { +export default function (signals) { const owner = signals.getOwner(); + const pools = createPools(); + const metricToIndexes = createMetricToIndexes(); + const defaultFrom = -10_000; const defaultTo = undefined; @@ -30,17 +34,15 @@ export function createVecsResources(signals, utils, env, metricToIndexes) { /** * @template {number | OHLCTuple} [T=number] - * @param {Index} index * @param {Metric} metric + * @param {Index} index */ - function createVecResource(index, metric) { - if (env.localhost && !(metric in metricToIndexes)) { + function createMetricResource(metric, index) { + if (localhost && !(metric in metricToIndexes)) { throw Error(`${metric} not recognized`); } return signals.runWithOwner(owner, () => { - /** @typedef {T extends number ? SingleValueData : CandlestickData} Value */ - const fetchedRecord = signals.createSignal( /** @type {Map}>} */ ( new Map() @@ -85,7 +87,7 @@ export function createVecsResources(signals, utils, env, metricToIndexes) { } fetched.loading = true; const res = /** @type {T[] | null} */ ( - await api.fetchVec( + await fetchVec( (values) => { if (values.length || !fetched.vec()) { fetched.vec.set(values); @@ -105,23 +107,23 @@ export function createVecsResources(signals, utils, env, metricToIndexes) { }); } - /** @type {Map>>} */ + /** @type {Map>>} */ const map = new Map(); - const vecs = { + const metrics = { /** * @template {number | OHLCTuple} [T=number] - * @param {Index} index * @param {Metric} metric + * @param {Index} index */ - getOrCreate(index, metric) { - const key = `${index},${metric}`; + getOrCreate(metric, index) { + const key = `${metric}/${index}`; const found = map.get(key); if (found) { return found; } - const vec = createVecResource(index, metric); + const vec = createMetricResource(index, metric); if (!vec) throw Error("vec is undefined"); map.set(key, /** @type {any} */ (vec)); return vec; @@ -130,10 +132,10 @@ export function createVecsResources(signals, utils, env, metricToIndexes) { defaultFetchedKey, }; - return vecs; + return { metrics, pools }; } -/** @typedef {ReturnType} VecsResources */ -/** @typedef {ReturnType} VecResource */ +// /** @typedef {ReturnType} VecsResources */ +// /** @typedef {ReturnType} VecResource */ const CACHE_NAME = "api"; const API_VECS_PREFIX = "/api/vecs"; @@ -142,9 +144,8 @@ const API_VECS_PREFIX = "/api/vecs"; * @template T * @param {(value: T) => void} callback * @param {string} path - * @param {boolean} [mustBeArray] */ -async function fetchApi(callback, path, mustBeArray) { +async function fetchApi(callback, path) { const url = `${API_VECS_PREFIX}${path}`; /** @type {T | null} */ @@ -184,9 +185,7 @@ async function fetchApi(callback, path, mustBeArray) { let fetchedJson = /** @type {T | null} */ (null); try { const f = await fetchedResponse.json(); - fetchedJson = /** @type {T} */ ( - mustBeArray && !Array.isArray(f) ? [f] : f - ); + fetchedJson = /** @type {T} */ (f); } catch (_) { return cachedJson; } @@ -249,33 +248,23 @@ function genPath(index, metric, from, to) { return path; } -export const api = { - /** - * @param {Index} index - * @param {Metric} metric - * @param {number} from - */ - genUrl(index, metric, from) { - return `${API_VECS_PREFIX}${genPath(index, metric, from)}`; - }, - /** - * @template {number | OHLCTuple} [T=number] - * @param {(v: T[]) => void} callback - * @param {Index} index - * @param {Metric} metric - * @param {number} [from] - * @param {number} [to] - */ - fetchVec(callback, index, metric, from, to) { - return fetchApi(callback, genPath(index, metric, from, to), true); - }, - /** - * @template {number | OHLCTuple} [T=number] - * @param {(v: T) => void} callback - * @param {Index} index - * @param {Metric} metric - */ - fetchLast(callback, index, metric) { - return fetchApi(callback, genPath(index, metric, -1)); - }, -}; +// /** +// * @template {number | OHLCTuple} [T=number] +// * @param {(v: T[]) => void} callback +// * @param {Index} index +// * @param {Metric} metric +// * @param {number} [from] +// * @param {number} [to] +// */ +// function fetchMetric(callback, index, metric, from, to) { +// return fetchApi(callback, genPath(index, metric, from, to)); +// } + +// /** +// * @param {Index} index +// * @param {Metric} metric +// * @param {number} from +// */ +// function genUrl(index, metric, from) { +// return `${API_VECS_PREFIX}${genPath(index, metric, from)}`; +// } diff --git a/websites/packages/brk/serde.js b/websites/packages/brk/serde.js new file mode 100644 index 000000000..c467a87fa --- /dev/null +++ b/websites/packages/brk/serde.js @@ -0,0 +1,64 @@ +// Should be generated by server +export const serdeIndex = { + /** + * @param {Index} v + */ + serialize(v) { + switch (v) { + case /** @satisfies {DateIndex} */ (0): + return "dateindex"; + case /** @satisfies {DecadeIndex} */ (1): + return "decadeindex"; + case /** @satisfies {DifficultyEpoch} */ (2): + return "difficultyepoch"; + case /** @satisfies {EmptyOutputIndex} */ (3): + return "emptyoutputindex"; + case /** @satisfies {HalvingEpoch} */ (4): + return "halvingepoch"; + case /** @satisfies {Height} */ (5): + return "height"; + case /** @satisfies {InputIndex} */ (6): + return "inputindex"; + case /** @satisfies {MonthIndex} */ (7): + return "monthindex"; + case /** @satisfies {OpReturnIndex} */ (8): + return "opreturnindex"; + case /** @satisfies {OutputIndex} */ (9): + return "outputindex"; + case /** @satisfies {P2AAddressIndex} */ (10): + return "p2aaddressindex"; + case /** @satisfies {P2MSOutputIndex} */ (11): + return "p2msoutputindex"; + case /** @satisfies {P2PK33AddressIndex} */ (12): + return "p2pk33addressindex"; + case /** @satisfies {P2PK65AddressIndex} */ (13): + return "p2pk65addressindex"; + case /** @satisfies {P2PKHAddressIndex} */ (14): + return "p2pkhaddressindex"; + case /** @satisfies {P2SHAddressIndex} */ (15): + return "p2shaddressindex"; + case /** @satisfies {P2TRAddressIndex} */ (16): + return "p2traddressindex"; + case /** @satisfies {P2WPKHAddressIndex} */ (17): + return "p2wpkhaddressindex"; + case /** @satisfies {P2WSHAddressIndex} */ (18): + return "p2wshaddressindex"; + case /** @satisfies {QuarterIndex} */ (19): + return "quarterindex"; + case /** @satisfies {SemesterIndex} */ (20): + return "semesterindex"; + case /** @satisfies {TxIndex} */ (21): + return "txindex"; + case /** @satisfies {UnknownOutputIndex} */ (22): + return "unknownoutputindex"; + case /** @satisfies {WeekIndex} */ (23): + return "weekindex"; + case /** @satisfies {YearIndex} */ (24): + return "yearindex"; + case /** @satisfies {LoadedAddressIndex} */ (25): + return "loadedaddressindex"; + case /** @satisfies {EmptyAddressIndex} */ (26): + return "emptyaddressindex"; + } + }, +}; diff --git a/websites/packages/brk/standalone.js b/websites/packages/brk/standalone.js new file mode 100644 index 000000000..227cfc353 --- /dev/null +++ b/websites/packages/brk/standalone.js @@ -0,0 +1,4 @@ +import signals from "../solidjs-signals/index"; +import brk from "./index"; + +export default () => brk(signals); diff --git a/websites/packages/brk/types.js b/websites/packages/brk/types.js new file mode 100644 index 000000000..e3dce8294 --- /dev/null +++ b/websites/packages/brk/types.js @@ -0,0 +1,9 @@ +/** + * @import { Signal, Signals, Accessor } from "../solidjs-signals/index"; + * + * @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, WeekIndex, SemesterIndex, YearIndex, MetricToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex, EmptyAddressIndex, LoadedAddressIndex } from "./metrics" + * + * @typedef {[number, number, number, number]} OHLCTuple + * + * @typedef {any} Metric + */ diff --git a/websites/packages/modern-screenshot/wrapper.js b/websites/packages/modern-screenshot/index.js similarity index 97% rename from websites/packages/modern-screenshot/wrapper.js rename to websites/packages/modern-screenshot/index.js index 82be8ddb4..59cf714ae 100644 --- a/websites/packages/modern-screenshot/wrapper.js +++ b/websites/packages/modern-screenshot/index.js @@ -5,8 +5,6 @@ const iphone = userAgent.includes("iphone"); const ipad = userAgent.includes("ipad"); const ios = iphone || ipad; -console.log({ ios }); - /** * @param {Object} args * @param {Element} args.element diff --git a/websites/packages/solidjs-signals/wrapper.js b/websites/packages/solidjs-signals/index.js similarity index 99% rename from websites/packages/solidjs-signals/wrapper.js rename to websites/packages/solidjs-signals/index.js index 282b88d57..e8f94bb95 100644 --- a/websites/packages/solidjs-signals/wrapper.js +++ b/websites/packages/solidjs-signals/index.js @@ -1,4 +1,3 @@ - /** * @import { SignalOptions } from "./0.4.11/dist/types/core/core" * @import { getOwner as GetOwner, onCleanup as OnCleanup } from "./0.4.11/dist/types/core/owner"