global: snapshot

This commit is contained in:
nym21
2026-01-10 18:43:18 +01:00
parent 3bc0615000
commit 6f45ec13f3
311 changed files with 6916 additions and 7664 deletions

View File

@@ -8,7 +8,19 @@ import { Unit } from "../utils/units.js";
* @returns {PartialOptionsGroup}
*/
export function createChainSection(ctx) {
const { colors, brk, s, createPriceLine } = ctx;
const {
colors,
brk,
s,
createPriceLine,
fromSizePattern,
fromFullnessPattern,
fromFeeRatePattern,
fromCoinbasePattern,
fromValuePattern,
fromBlockCountWithUnit,
fromIntervalPattern,
} = ctx;
const {
blocks,
transactions,
@@ -20,409 +32,6 @@ export function createChainSection(ctx) {
supply,
} = brk.tree;
/**
* Create sum/cumulative series from a BlockCountPattern
* @template T
* @param {BlockCountPattern<T>} pattern
* @param {string} name
* @param {Color} [sumColor]
* @param {Color} [cumulativeColor]
* @param {Unit} unit
*/
const fromBlockCount = (pattern, name, unit, sumColor, cumulativeColor) => [
s({
metric: pattern.sum,
name: `${name} sum`,
color: sumColor,
unit,
}),
s({
metric: pattern.cumulative,
name: `${name} cumulative`,
color: cumulativeColor ?? colors.blue,
unit,
defaultActive: false,
}),
];
/**
* Create series from BlockSizePattern (has average, min, max, percentiles)
* @template T
* @param {BlockSizePattern<T>} pattern
* @param {string} name
* @param {Unit} unit
*/
const fromBlockSize = (pattern, name, unit) => [
s({ metric: pattern.average, name: `${name} avg`, unit }),
s({
metric: pattern.sum,
name: `${name} sum`,
color: colors.blue,
unit,
defaultActive: false,
}),
s({
metric: pattern.cumulative,
name: `${name} cumulative`,
color: colors.indigo,
unit,
defaultActive: false,
}),
s({
metric: pattern.min,
name: `${name} min`,
color: colors.red,
unit,
defaultActive: false,
}),
s({
metric: pattern.max,
name: `${name} max`,
color: colors.green,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct10,
name: `${name} pct10`,
color: colors.rose,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct25,
name: `${name} pct25`,
color: colors.pink,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.median,
name: `${name} median`,
color: colors.purple,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct75,
name: `${name} pct75`,
color: colors.violet,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct90,
name: `${name} pct90`,
color: colors.fuchsia,
unit,
defaultActive: false,
}),
];
/**
* Create series from CountPattern2 (has distribution with percentiles, no height index on cumulative)
* @template T
* @param {CountPattern2<T>} pattern
* @param {string} name
* @param {Unit} unit
*/
const fromCountPattern2 = (pattern, name, unit) => [
s({ metric: pattern.average, name: `${name} Average`, unit }),
s({
metric: pattern.sum,
name: `${name} sum`,
color: colors.blue,
unit,
defaultActive: false,
}),
s({
metric: pattern.cumulative,
name: `${name} cumulative`,
color: colors.indigo,
unit,
defaultActive: false,
}),
s({
metric: pattern.min,
name: `${name} min`,
color: colors.red,
unit,
defaultActive: false,
}),
s({
metric: pattern.max,
name: `${name} max`,
color: colors.green,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct10,
name: `${name} pct10`,
color: colors.rose,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct25,
name: `${name} pct25`,
color: colors.pink,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.median,
name: `${name} median`,
color: colors.purple,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct75,
name: `${name} pct75`,
color: colors.violet,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct90,
name: `${name} pct90`,
color: colors.fuchsia,
unit,
defaultActive: false,
}),
];
/**
* Create series from BlockIntervalPattern (has average, min, max, percentiles)
* @template T
* @param {BlockIntervalPattern<T>} pattern
* @param {string} name
* @param {Unit} unit
*/
const fromBlockInterval = (pattern, name, unit) => [
s({ metric: pattern.average, name: `${name} avg`, unit }),
s({
metric: pattern.min,
name: `${name} min`,
color: colors.red,
unit,
defaultActive: false,
}),
s({
metric: pattern.max,
name: `${name} max`,
color: colors.green,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct10,
name: `${name} pct10`,
color: colors.rose,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct25,
name: `${name} pct25`,
color: colors.pink,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.median,
name: `${name} median`,
color: colors.purple,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct75,
name: `${name} pct75`,
color: colors.violet,
unit,
defaultActive: false,
}),
s({
metric: pattern.percentiles.pct90,
name: `${name} pct90`,
color: colors.fuchsia,
unit,
defaultActive: false,
}),
];
/**
* Create series from DollarsPattern (has base, cumulative)
* @template T
* @param {DollarsPattern<T>} pattern
* @param {string} name
* @param {Unit} unit
* @param {Color} [sumColor]
* @param {Color} [cumulativeColor]
*/
const fromBitcoin = (pattern, name, unit, sumColor, cumulativeColor) => [
s({ metric: pattern.base, name: `${name}`, color: sumColor, unit }),
s({
metric: pattern.cumulative,
name: `${name} cumulative`,
color: cumulativeColor ?? colors.blue,
unit,
defaultActive: false,
}),
];
/**
* Create series from CoinbasePattern (has sats, bitcoin, dollars as BitcoinPattern)
* BitcoinPattern has .base and .cumulative (no .sum)
* @param {CoinbasePattern} pattern
* @param {string} name
* @param {Color} sumColor
* @param {Color} cumulativeColor
*/
const fromCoinbase = (pattern, name, sumColor, cumulativeColor) => [
s({
metric: pattern.sats.base,
name: `${name}`,
color: sumColor,
unit: Unit.sats,
}),
s({
metric: pattern.sats.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.sats,
defaultActive: false,
}),
s({
metric: pattern.bitcoin.base,
name: `${name}`,
color: sumColor,
unit: Unit.btc,
}),
s({
metric: pattern.bitcoin.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.btc,
defaultActive: false,
}),
s({
metric: pattern.dollars.base,
name: `${name}`,
color: sumColor,
unit: Unit.usd,
}),
s({
metric: pattern.dollars.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.usd,
defaultActive: false,
}),
];
/**
* Create series from ValuePattern (has sats, bitcoin, dollars as BlockCountPattern)
* BlockCountPattern has .base, .sum, and .cumulative
* @param {ValuePattern} pattern
* @param {string} name
* @param {Color} sumColor
* @param {Color} cumulativeColor
*/
const fromValuePattern = (pattern, name, sumColor, cumulativeColor) => [
s({
metric: pattern.sats.sum,
name: `${name}`,
color: sumColor,
unit: Unit.sats,
}),
s({
metric: pattern.sats.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.sats,
defaultActive: false,
}),
s({
metric: pattern.bitcoin.sum,
name: `${name}`,
color: sumColor,
unit: Unit.btc,
}),
s({
metric: pattern.bitcoin.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.btc,
defaultActive: false,
}),
s({
metric: pattern.dollars.sum,
name: `${name}`,
color: sumColor,
unit: Unit.usd,
}),
s({
metric: pattern.dollars.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.usd,
defaultActive: false,
}),
];
/**
* Create series from RewardPattern (has .base as Indexes2<Sats>, plus bitcoin/dollars as BlockCountPattern, sats as SatsPattern)
* Note: SatsPattern only has cumulative and sum, so we use pattern.base for raw sats
* @param {RewardPattern} pattern
* @param {string} name
* @param {Color} sumColor
* @param {Color} cumulativeColor
*/
const fromRewardPattern = (pattern, name, sumColor, cumulativeColor) => [
s({
metric: pattern.base,
name: `${name}`,
color: sumColor,
unit: Unit.sats,
}),
s({
metric: pattern.sats.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.sats,
defaultActive: false,
}),
s({
metric: pattern.bitcoin.sum,
name: `${name}`,
color: sumColor,
unit: Unit.btc,
}),
s({
metric: pattern.bitcoin.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.btc,
defaultActive: false,
}),
s({
metric: pattern.dollarsSource,
name: `${name}`,
color: sumColor,
unit: Unit.usd,
}),
s({
metric: pattern.dollars.cumulative,
name: `${name} cumulative`,
color: cumulativeColor,
unit: Unit.usd,
defaultActive: false,
}),
];
// Build pools tree dynamically
const poolEntries = Object.entries(pools.vecs);
const poolsTree = poolEntries.map(([key, pool]) => {
@@ -503,19 +112,9 @@ export function createChainSection(ctx) {
name: "Rewards",
title: `Rewards collected by ${poolName}`,
bottom: [
...fromValuePattern(
pool.coinbase,
"coinbase",
colors.orange,
colors.red,
),
...fromRewardPattern(
pool.subsidy,
"subsidy",
colors.lime,
colors.emerald,
),
...fromRewardPattern(pool.fee, "fee", colors.cyan, colors.indigo),
...fromValuePattern(pool.coinbase, "coinbase", colors.orange, colors.red),
...fromValuePattern(pool.subsidy, "subsidy", colors.lime, colors.emerald),
...fromValuePattern(pool.fee, "fee", colors.cyan, colors.indigo),
],
},
{
@@ -544,7 +143,7 @@ export function createChainSection(ctx) {
name: "Count",
title: "Block Count",
bottom: [
...fromBlockCount(blocks.count.blockCount, "Block", Unit.count),
...fromBlockCountWithUnit(blocks.count.blockCount, "Block", Unit.count),
s({
metric: blocks.count.blockCountTarget,
name: "Target",
@@ -579,16 +178,7 @@ export function createChainSection(ctx) {
name: "Interval",
title: "Block Interval",
bottom: [
s({
metric: blocks.interval.interval,
name: "Interval",
unit: Unit.secs,
}),
...fromBlockInterval(
blocks.interval.blockInterval,
"Interval",
Unit.secs,
),
...fromIntervalPattern(blocks.interval, "Interval", Unit.secs),
createPriceLine({ unit: Unit.secs, name: "Target", number: 600 }),
],
},
@@ -596,19 +186,9 @@ export function createChainSection(ctx) {
name: "Size",
title: "Block Size",
bottom: [
s({
metric: blocks.size.vbytes,
name: "vbytes raw",
unit: Unit.vb,
}),
s({
metric: indexed.block.weight,
name: "weight raw",
unit: Unit.wu,
}),
...fromBlockSize(blocks.size.blockSize, "size", Unit.bytes),
...fromBlockSize(blocks.weight.blockWeight, "weight", Unit.wu),
...fromBlockSize(blocks.size.blockVbytes, "vbytes", Unit.vb),
...fromSizePattern(blocks.size, "Size", Unit.bytes),
...fromFullnessPattern(blocks.vbytes, "Vbytes", Unit.vb),
...fromFullnessPattern(blocks.weight, "Weight", Unit.wu),
],
},
],
@@ -621,7 +201,7 @@ export function createChainSection(ctx) {
{
name: "Count",
title: "Transaction Count",
bottom: fromBitcoin(
bottom: fromFullnessPattern(
transactions.count.txCount,
"Count",
Unit.count,
@@ -632,7 +212,7 @@ export function createChainSection(ctx) {
title: "Transaction Volume",
bottom: [
s({
metric: transactions.volume.sentSum.sats.sum,
metric: transactions.volume.sentSum.sats,
name: "Sent",
unit: Unit.sats,
}),
@@ -647,21 +227,21 @@ export function createChainSection(ctx) {
unit: Unit.usd,
}),
s({
metric: transactions.volume.annualizedVolume,
metric: transactions.volume.annualizedVolume.sats,
name: "annualized",
color: colors.red,
unit: Unit.sats,
defaultActive: false,
}),
s({
metric: transactions.volume.annualizedVolumeBtc,
metric: transactions.volume.annualizedVolume.bitcoin,
name: "annualized",
color: colors.red,
unit: Unit.btc,
defaultActive: false,
}),
s({
metric: transactions.volume.annualizedVolumeUsd,
metric: transactions.volume.annualizedVolume.dollars,
name: "annualized",
color: colors.lime,
unit: Unit.usd,
@@ -673,35 +253,17 @@ export function createChainSection(ctx) {
name: "Size",
title: "Transaction Size",
bottom: [
...fromBlockInterval(transactions.size.weight, "weight", Unit.wu),
...fromBlockInterval(transactions.size.vsize, "vsize", Unit.vb),
...fromFeeRatePattern(transactions.size.weight, "weight", Unit.wu),
...fromFeeRatePattern(transactions.size.vsize, "vsize", Unit.vb),
],
},
{
name: "Versions",
title: "Transaction Versions",
bottom: [
...fromBlockCount(
transactions.versions.v1,
"v1",
Unit.count,
colors.orange,
colors.red,
),
...fromBlockCount(
transactions.versions.v2,
"v2",
Unit.count,
colors.cyan,
colors.blue,
),
...fromBlockCount(
transactions.versions.v3,
"v3",
Unit.count,
colors.lime,
colors.green,
),
...fromBlockCountWithUnit(transactions.versions.v1, "v1", Unit.count, colors.orange, colors.red),
...fromBlockCountWithUnit(transactions.versions.v2, "v2", Unit.count, colors.cyan, colors.blue),
...fromBlockCountWithUnit(transactions.versions.v3, "v3", Unit.count, colors.lime, colors.green),
],
},
{
@@ -742,7 +304,7 @@ export function createChainSection(ctx) {
{
name: "Count",
title: "Transaction Input Count",
bottom: [...fromCountPattern2(inputs.count, "Input", Unit.count)],
bottom: [...fromSizePattern(inputs.count, "Input", Unit.count)],
},
{
name: "Speed",
@@ -765,7 +327,13 @@ export function createChainSection(ctx) {
{
name: "Count",
title: "Transaction Output Count",
bottom: [...fromCountPattern2(outputs.count, "Output", Unit.count)],
bottom: [
...fromSizePattern(
outputs.count.totalCount,
"Output",
Unit.count,
),
],
},
{
name: "Speed",
@@ -781,23 +349,13 @@ export function createChainSection(ctx) {
],
},
// UTXO
{
name: "UTXO",
tree: [
{
name: "Count",
title: "UTXO Count",
bottom: [
s({
metric: mergeMetricPatterns(
outputs.count.utxoCount.base,
outputs.count.utxoCount.sum,
),
name: "Count",
unit: Unit.count,
}),
],
bottom: fromFullnessPattern(outputs.count.utxoCount, "Count", Unit.count),
},
],
},
@@ -806,12 +364,7 @@ export function createChainSection(ctx) {
{
name: "Coinbase",
title: "Coinbase Rewards",
bottom: fromCoinbase(
blocks.rewards.coinbase,
"Coinbase",
colors.orange,
colors.red,
),
bottom: fromCoinbasePattern(blocks.rewards.coinbase, "Coinbase"),
},
// Subsidy
@@ -819,12 +372,7 @@ export function createChainSection(ctx) {
name: "Subsidy",
title: "Block Subsidy",
bottom: [
...fromCoinbase(
blocks.rewards.subsidy,
"Subsidy",
colors.lime,
colors.emerald,
),
...fromCoinbasePattern(blocks.rewards.subsidy, "Subsidy"),
s({
metric: blocks.rewards.subsidyDominance,
name: "Dominance",
@@ -893,8 +441,9 @@ export function createChainSection(ctx) {
title: "Fee Rate",
bottom: [
s({
metric: transactions.fees.feeRate.base,
name: "Rate",
metric: transactions.fees.feeRate.median,
name: "Median",
color: colors.purple,
unit: Unit.feeRate,
}),
s({
@@ -902,12 +451,7 @@ export function createChainSection(ctx) {
name: "Average",
color: colors.blue,
unit: Unit.feeRate,
}),
s({
metric: transactions.fees.feeRate.percentiles.median,
name: "Median",
color: colors.purple,
unit: Unit.feeRate,
defaultActive: false,
}),
s({
metric: transactions.fees.feeRate.min,
@@ -924,28 +468,28 @@ export function createChainSection(ctx) {
defaultActive: false,
}),
s({
metric: transactions.fees.feeRate.percentiles.pct10,
metric: transactions.fees.feeRate.pct10,
name: "pct10",
color: colors.rose,
unit: Unit.feeRate,
defaultActive: false,
}),
s({
metric: transactions.fees.feeRate.percentiles.pct25,
metric: transactions.fees.feeRate.pct25,
name: "pct25",
color: colors.pink,
unit: Unit.feeRate,
defaultActive: false,
}),
s({
metric: transactions.fees.feeRate.percentiles.pct75,
metric: transactions.fees.feeRate.pct75,
name: "pct75",
color: colors.violet,
unit: Unit.feeRate,
defaultActive: false,
}),
s({
metric: transactions.fees.feeRate.percentiles.pct90,
metric: transactions.fees.feeRate.pct90,
name: "pct90",
color: colors.fuchsia,
unit: Unit.feeRate,
@@ -1004,22 +548,19 @@ export function createChainSection(ctx) {
title: "Network Difficulty",
bottom: [
s({
metric: blocks.mining.difficulty,
metric: blocks.difficulty.raw,
name: "Difficulty",
unit: Unit.difficulty,
}),
s({
metric: mergeMetricPatterns(
blocks.mining.difficultyAdjustment.base,
blocks.mining.difficultyAdjustment.rest,
),
metric: blocks.difficulty.adjustment,
name: "Adjustment",
color: colors.orange,
unit: Unit.percentage,
defaultActive: false,
}),
s({
metric: blocks.mining.difficultyAsHash,
metric: blocks.difficulty.asHash,
name: "As hash",
color: colors.default,
unit: Unit.hashRate,
@@ -1027,14 +568,14 @@ export function createChainSection(ctx) {
options: { lineStyle: 1 },
}),
s({
metric: blocks.difficulty.blocksBeforeNextDifficultyAdjustment,
metric: blocks.difficulty.blocksBeforeNextAdjustment,
name: "Blocks until adj.",
color: colors.indigo,
unit: Unit.blocks,
defaultActive: false,
}),
s({
metric: blocks.difficulty.daysBeforeNextDifficultyAdjustment,
metric: blocks.difficulty.daysBeforeNextAdjustment,
name: "Days until adj.",
color: colors.purple,
unit: Unit.days,
@@ -1134,7 +675,7 @@ export function createChainSection(ctx) {
unit: Unit.days,
}),
s({
metric: blocks.halving.halvingepoch,
metric: blocks.halving.epoch,
name: "Halving epoch",
color: colors.purple,
unit: Unit.epoch,
@@ -1173,8 +714,8 @@ export function createChainSection(ctx) {
{
name: "Outputs",
title: "OP_RETURN Outputs",
bottom: fromBitcoin(
scripts.count.opreturnCount,
bottom: fromFullnessPattern(
scripts.count.opreturn,
"Count",
Unit.count,
),
@@ -1190,10 +731,7 @@ export function createChainSection(ctx) {
title: "Inflation Rate",
bottom: [
s({
metric: mergeMetricPatterns(
supply.inflation.indexes.dateindex,
supply.inflation.indexes.rest,
),
metric: supply.inflation,
name: "Rate",
unit: Unit.percentage,
}),

View File

@@ -322,7 +322,7 @@ function createCostBasisSection(ctx, list, useGroupName, title) {
title: `Min Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.minCostBasis,
metric: tree.costBasis.min,
name: useGroupName ? name : "Min",
color,
unit: Unit.usd,
@@ -334,7 +334,7 @@ function createCostBasisSection(ctx, list, useGroupName, title) {
title: `Max Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.maxCostBasis,
metric: tree.costBasis.max,
name: useGroupName ? name : "Max",
color,
unit: Unit.usd,
@@ -355,7 +355,7 @@ function createCostBasisSection(ctx, list, useGroupName, title) {
* @returns {PartialOptionsTree}
*/
function createActivitySection(ctx, list, useGroupName, title) {
const { s, brk } = ctx;
const { s } = ctx;
return [
{

View File

@@ -14,19 +14,19 @@ export function createSingleSupplySeries(ctx, cohort) {
return [
s({
metric: tree.supply.supply.sats,
metric: tree.supply.total.sats,
name: "Supply",
color: colors.default,
unit: Unit.sats,
}),
s({
metric: tree.supply.supply.bitcoin,
metric: tree.supply.total.bitcoin,
name: "Supply",
color: colors.default,
unit: Unit.btc,
}),
s({
metric: tree.supply.supply.dollars,
metric: tree.supply.total.dollars,
name: "Supply",
color: colors.default,
unit: Unit.usd,
@@ -78,21 +78,21 @@ export function createSingleSupplySeries(ctx, cohort) {
unit: Unit.usd,
}),
s({
metric: tree.supply.supplyHalf.sats,
metric: tree.supply.halved.sats,
name: "half",
color: colors.gray,
unit: Unit.sats,
options: { lineStyle: 4 },
}),
s({
metric: tree.supply.supplyHalf.bitcoin,
metric: tree.supply.halved.bitcoin,
name: "half",
color: colors.gray,
unit: Unit.btc,
options: { lineStyle: 4 },
}),
s({
metric: tree.supply.supplyHalf.dollars,
metric: tree.supply.halved.dollars,
name: "half",
color: colors.gray,
unit: Unit.usd,
@@ -147,9 +147,9 @@ export function createGroupedSupplyTotalSeries(ctx, list) {
const constant100 = brk.tree.constants.constant100;
return list.flatMap(({ color, name, tree }) => [
s({ metric: tree.supply.supply.sats, name, color, unit: Unit.sats }),
s({ metric: tree.supply.supply.bitcoin, name, color, unit: Unit.btc }),
s({ metric: tree.supply.supply.dollars, name, color, unit: Unit.usd }),
s({ metric: tree.supply.total.sats, name, color, unit: Unit.sats }),
s({ metric: tree.supply.total.bitcoin, name, color, unit: Unit.btc }),
s({ metric: tree.supply.total.dollars, name, color, unit: Unit.usd }),
"supplyRelToCirculatingSupply" in tree.relative
? s({
metric: tree.relative.supplyRelToCirculatingSupply,
@@ -255,7 +255,7 @@ export function createUtxoCountSeries(ctx, list, useGroupName) {
return list.flatMap(({ color, name, tree }) => [
s({
metric: tree.supply.utxoCount,
metric: tree.outputs.utxoCount,
name: useGroupName ? name : "Count",
color,
unit: Unit.count,
@@ -351,13 +351,13 @@ export function createCostBasisMinMaxSeries(ctx, list, useGroupName) {
return list.flatMap(({ color, name, tree }) => [
s({
metric: tree.costBasis.minCostBasis,
metric: tree.costBasis.min,
name: useGroupName ? `${name} min` : "Min",
color,
unit: Unit.usd,
}),
s({
metric: tree.costBasis.maxCostBasis,
metric: tree.costBasis.max,
name: useGroupName ? `${name} max` : "Max",
color,
unit: Unit.usd,

View File

@@ -298,7 +298,7 @@ function createRealizedCapWithExtras(ctx, list, args, useGroupName) {
* @returns {PartialOptionsTree}
*/
function createRealizedPnlSection(ctx, args, title) {
const { colors, s, brk } = ctx;
const { colors, s } = ctx;
const { tree } = args;
return [
@@ -307,19 +307,13 @@ function createRealizedPnlSection(ctx, args, title) {
title: `Realized Profit And Loss ${title}`,
bottom: [
s({
metric: mergeMetricPatterns(
tree.realized.realizedProfit.base,
tree.realized.realizedProfit.sum,
),
metric: tree.realized.realizedProfit.sum,
name: "Profit",
color: colors.green,
unit: Unit.usd,
}),
s({
metric: mergeMetricPatterns(
tree.realized.realizedLoss.base,
tree.realized.realizedLoss.sum,
),
metric: tree.realized.realizedLoss.sum,
name: "Loss",
color: colors.red,
defaultActive: false,
@@ -437,7 +431,7 @@ function createCostBasisSectionWithPercentiles(ctx, list, useGroupName, title) {
title: `Min Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.minCostBasis,
metric: tree.costBasis.min,
name: useGroupName ? name : "Min",
color,
unit: Unit.usd,
@@ -449,7 +443,7 @@ function createCostBasisSectionWithPercentiles(ctx, list, useGroupName, title) {
title: `Max Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.maxCostBasis,
metric: tree.costBasis.max,
name: useGroupName ? name : "Max",
color,
unit: Unit.usd,
@@ -486,7 +480,7 @@ function createCostBasisSectionBasic(ctx, list, useGroupName, title) {
title: `Min Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.minCostBasis,
metric: tree.costBasis.min,
name: useGroupName ? name : "Min",
color,
unit: Unit.usd,
@@ -498,7 +492,7 @@ function createCostBasisSectionBasic(ctx, list, useGroupName, title) {
title: `Max Cost Basis ${title}`,
top: list.map(({ color, name, tree }) =>
s({
metric: tree.costBasis.maxCostBasis,
metric: tree.costBasis.max,
name: useGroupName ? name : "Max",
color,
unit: Unit.usd,
@@ -519,7 +513,7 @@ function createCostBasisSectionBasic(ctx, list, useGroupName, title) {
* @returns {PartialOptionsTree}
*/
function createActivitySection(ctx, list, useGroupName, title) {
const { s, brk } = ctx;
const { s } = ctx;
return [
{
@@ -530,10 +524,7 @@ function createActivitySection(ctx, list, useGroupName, title) {
title: `Coinblocks Destroyed ${title}`,
bottom: list.flatMap(({ color, name, tree }) => [
s({
metric: mergeMetricPatterns(
tree.activity.coinblocksDestroyed.base,
tree.activity.coinblocksDestroyed.sum,
),
metric: tree.activity.coinblocksDestroyed.sum,
name: useGroupName ? name : "Coinblocks",
color,
unit: Unit.coinblocks,
@@ -545,10 +536,7 @@ function createActivitySection(ctx, list, useGroupName, title) {
title: `Coindays Destroyed ${title}`,
bottom: list.flatMap(({ color, name, tree }) => [
s({
metric: mergeMetricPatterns(
tree.activity.coindaysDestroyed.base,
tree.activity.coindaysDestroyed.sum,
),
metric: tree.activity.coindaysDestroyed.sum,
name: useGroupName ? name : "Coindays",
color,
unit: Unit.coindays,

View File

@@ -273,7 +273,7 @@ export function createCointimeSection(ctx) {
title: "Compare Cointime Capitalizations",
bottom: [
s({
metric: supply.marketCap.height,
metric: supply.marketCap,
name: "Market",
color: colors.default,
unit: Unit.usd,
@@ -295,7 +295,7 @@ export function createCointimeSection(ctx) {
bottom: [
s({ metric, name, color, unit: Unit.usd }),
s({
metric: supply.marketCap.height,
metric: supply.marketCap,
name: "Market",
color: colors.default,
unit: Unit.usd,
@@ -318,19 +318,19 @@ export function createCointimeSection(ctx) {
bottom: [
// All supply (different pattern structure)
s({
metric: all.supply.supply.sats,
metric: all.supply.total.sats,
name: "All",
color: colors.orange,
unit: Unit.sats,
}),
s({
metric: all.supply.supply.bitcoin,
metric: all.supply.total.bitcoin,
name: "All",
color: colors.orange,
unit: Unit.btc,
}),
s({
metric: all.supply.supply.dollars,
metric: all.supply.total.dollars,
name: "All",
color: colors.orange,
unit: Unit.usd,
@@ -432,10 +432,7 @@ export function createCointimeSection(ctx) {
title: "Cointime-Adjusted Inflation Rate",
bottom: [
s({
metric: mergeMetricPatterns(
supply.inflation.indexes.dateindex,
supply.inflation.indexes.rest,
),
metric: supply.inflation,
name: "Base",
color: colors.orange,
unit: Unit.percentage,
@@ -454,7 +451,7 @@ export function createCointimeSection(ctx) {
title: "Cointime-Adjusted Transactions Velocity",
bottom: [
s({
metric: supply.velocity.btc.dateindex,
metric: supply.velocity.btc,
name: "BTC",
color: colors.orange,
unit: Unit.ratio,
@@ -466,10 +463,7 @@ export function createCointimeSection(ctx) {
unit: Unit.ratio,
}),
s({
metric: mergeMetricPatterns(
supply.velocity.usd.dateindex,
supply.velocity.usd.rest,
),
metric: supply.velocity.usd,
name: "USD",
color: colors.emerald,
unit: Unit.ratio,

View File

@@ -3,7 +3,7 @@
/**
* Get constant pattern by number dynamically from tree
* Examples: 0 → constant0, 38.2 → constant382, -1 → constantMinus1
* @param {BrkClient["tree"]["computed"]["constants"]} constants
* @param {BrkClient["tree"]["constants"]} constants
* @param {number} num
* @returns {AnyMetricPattern}
*/
@@ -22,7 +22,7 @@ export function getConstant(constants, num) {
/**
* Create a price line series (horizontal reference line)
* @param {Object} args
* @param {BrkClient["tree"]["computed"]["constants"]} args.constants
* @param {BrkClient["tree"]["constants"]} args.constants
* @param {Colors} args.colors
* @param {number} [args.number]
* @param {string} [args.name]
@@ -59,7 +59,7 @@ export function createPriceLine({
/**
* Create multiple price lines from an array of numbers
* @param {Object} args
* @param {BrkClient["tree"]["computed"]["constants"]} args.constants
* @param {BrkClient["tree"]["constants"]} args.constants
* @param {Colors} args.colors
* @param {number[]} args.numbers
* @param {Unit} args.unit

View File

@@ -1,4 +1,16 @@
import { s, fromBlockCount, fromBitcoin, fromBlockSize } from "./series.js";
import {
s,
fromBlockCount,
fromBitcoin,
fromBlockSize,
fromSizePattern,
fromFullnessPattern,
fromFeeRatePattern,
fromCoinbasePattern,
fromValuePattern,
fromBlockCountWithUnit,
fromIntervalPattern,
} from "./series.js";
import { createPriceLine, createPriceLines, line } from "./constants.js";
/**
@@ -23,6 +35,20 @@ export function createContext({ colors, brk }) {
fromBitcoin(colors, pattern, title, color),
fromBlockSize: (pattern, title, color) =>
fromBlockSize(colors, pattern, title, color),
fromSizePattern: (pattern, title, unit) =>
fromSizePattern(colors, pattern, title, unit),
fromFullnessPattern: (pattern, title, unit) =>
fromFullnessPattern(colors, pattern, title, unit),
fromFeeRatePattern: (pattern, title, unit) =>
fromFeeRatePattern(colors, pattern, title, unit),
fromCoinbasePattern: (pattern, title) =>
fromCoinbasePattern(colors, pattern, title),
fromValuePattern: (pattern, title, sumColor, cumulativeColor) =>
fromValuePattern(colors, pattern, title, sumColor, cumulativeColor),
fromBlockCountWithUnit: (pattern, title, unit, sumColor, cumulativeColor) =>
fromBlockCountWithUnit(colors, pattern, title, unit, sumColor, cumulativeColor),
fromIntervalPattern: (pattern, title, unit, color) =>
fromIntervalPattern(colors, pattern, title, unit, color),
createPriceLine: (args) => createPriceLine({ constants, colors, ...args }),
createPriceLines: (args) =>

View File

@@ -42,10 +42,7 @@ export function createMarketSection(ctx) {
title: "Market Capitalization",
bottom: [
s({
metric: brk.mergeMetricPatterns(
supply.marketCap.height,
supply.marketCap.indexes,
),
metric: supply.marketCap,
name: "Capitalization",
unit: Unit.usd,
}),

View File

@@ -1,5 +1,7 @@
/** Series helpers for creating chart series blueprints */
import { Unit } from "../utils/units.js";
/**
* Create a single series from a tree accessor
* @param {Object} args
@@ -32,13 +34,7 @@ export function s({ metric, name, color, defaultActive, unit, options }) {
*/
export function fromBlockCount(colors, pattern, title, color) {
return [
{ metric: pattern.base, title, color: color ?? colors.default },
{
metric: pattern.sum,
title: `${title} (sum)`,
color: colors.red,
defaultActive: false,
},
{ metric: pattern.sum, title, color: color ?? colors.default },
{
metric: pattern.cumulative,
title: `${title} (cum.)`,
@@ -49,9 +45,9 @@ export function fromBlockCount(colors, pattern, title, color) {
}
/**
* Create series from a DollarsPattern ({ base, sum, cumulative, average, min, max, percentiles.* })
* Create series from a FullnessPattern ({ base, sum, cumulative, average, min, max, percentiles })
* @param {Colors} colors
* @param {DollarsPattern<any>} pattern
* @param {FullnessPattern<any>} pattern
* @param {string} title
* @param {Color} [color]
* @returns {AnyFetchedSeriesBlueprint[]}
@@ -85,31 +81,31 @@ export function fromBitcoin(colors, pattern, title, color) {
defaultActive: false,
},
{
metric: pattern.percentiles.median,
metric: pattern.median,
title: "Median",
color: colors.amber,
defaultActive: false,
},
{
metric: pattern.percentiles.pct75,
metric: pattern.pct75,
title: "pct75",
color: colors.red,
defaultActive: false,
},
{
metric: pattern.percentiles.pct25,
metric: pattern.pct25,
title: "pct25",
color: colors.yellow,
defaultActive: false,
},
{
metric: pattern.percentiles.pct90,
metric: pattern.pct90,
title: "pct90",
color: colors.rose,
defaultActive: false,
},
{
metric: pattern.percentiles.pct10,
metric: pattern.pct10,
title: "pct10",
color: colors.lime,
defaultActive: false,
@@ -118,9 +114,9 @@ export function fromBitcoin(colors, pattern, title, color) {
}
/**
* Create series from a BlockSizePattern ({ sum, cumulative, avg, min, max, distribution.percentiles.* })
* Create series from a SizePattern ({ sum, cumulative, average, min, max, percentiles })
* @param {Colors} colors
* @param {BlockSizePattern<any>} pattern
* @param {SizePattern<any>} pattern
* @param {string} title
* @param {Color} [color]
* @returns {AnyFetchedSeriesBlueprint[]}
@@ -148,34 +144,377 @@ export function fromBlockSize(colors, pattern, title, color) {
defaultActive: false,
},
{
metric: pattern.distribution.percentiles.median,
metric: pattern.median,
title: "Median",
color: colors.amber,
defaultActive: false,
},
{
metric: pattern.distribution.percentiles.pct75,
metric: pattern.pct75,
title: "pct75",
color: colors.red,
defaultActive: false,
},
{
metric: pattern.distribution.percentiles.pct25,
metric: pattern.pct25,
title: "pct25",
color: colors.yellow,
defaultActive: false,
},
{
metric: pattern.distribution.percentiles.pct90,
metric: pattern.pct90,
title: "pct90",
color: colors.rose,
defaultActive: false,
},
{
metric: pattern.distribution.percentiles.pct10,
metric: pattern.pct10,
title: "pct10",
color: colors.lime,
defaultActive: false,
},
];
}
/**
* Create series from a SizePattern ({ average, sum, cumulative, min, max, percentiles })
* @param {Colors} colors
* @param {SizePattern<any>} pattern
* @param {string} title
* @param {Unit} unit
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromSizePattern(colors, pattern, title, unit) {
return [
{ metric: pattern.average, title: `${title} avg`, unit },
{
metric: pattern.sum,
title: `${title} sum`,
color: colors.blue,
unit,
defaultActive: false,
},
{
metric: pattern.cumulative,
title: `${title} cumulative`,
color: colors.indigo,
unit,
defaultActive: false,
},
{
metric: pattern.min,
title: `${title} min`,
color: colors.red,
unit,
defaultActive: false,
},
{
metric: pattern.max,
title: `${title} max`,
color: colors.green,
unit,
defaultActive: false,
},
{
metric: pattern.pct10,
title: `${title} pct10`,
color: colors.rose,
unit,
defaultActive: false,
},
{
metric: pattern.pct25,
title: `${title} pct25`,
color: colors.pink,
unit,
defaultActive: false,
},
{
metric: pattern.median,
title: `${title} median`,
color: colors.purple,
unit,
defaultActive: false,
},
{
metric: pattern.pct75,
title: `${title} pct75`,
color: colors.violet,
unit,
defaultActive: false,
},
{
metric: pattern.pct90,
title: `${title} pct90`,
color: colors.fuchsia,
unit,
defaultActive: false,
},
];
}
/**
* Create series from a FullnessPattern ({ base, average, sum, cumulative, min, max, percentiles })
* @param {Colors} colors
* @param {FullnessPattern<any>} pattern
* @param {string} title
* @param {Unit} unit
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromFullnessPattern(colors, pattern, title, unit) {
return [
{ metric: pattern.base, title, unit },
{
metric: pattern.average,
title: `${title} avg`,
color: colors.purple,
unit,
defaultActive: false,
},
{
metric: pattern.sum,
title: `${title} sum`,
color: colors.blue,
unit,
defaultActive: false,
},
{
metric: pattern.cumulative,
title: `${title} cumulative`,
color: colors.indigo,
unit,
defaultActive: false,
},
{
metric: pattern.min,
title: `${title} min`,
color: colors.red,
unit,
defaultActive: false,
},
{
metric: pattern.max,
title: `${title} max`,
color: colors.green,
unit,
defaultActive: false,
},
{
metric: pattern.pct10,
title: `${title} pct10`,
color: colors.rose,
unit,
defaultActive: false,
},
{
metric: pattern.pct25,
title: `${title} pct25`,
color: colors.pink,
unit,
defaultActive: false,
},
{
metric: pattern.median,
title: `${title} median`,
color: colors.violet,
unit,
defaultActive: false,
},
{
metric: pattern.pct75,
title: `${title} pct75`,
color: colors.fuchsia,
unit,
defaultActive: false,
},
{
metric: pattern.pct90,
title: `${title} pct90`,
color: colors.amber,
unit,
defaultActive: false,
},
];
}
/**
* Create series from a FeeRatePattern ({ average, min, max, percentiles })
* @param {Colors} colors
* @param {FeeRatePattern<any>} pattern
* @param {string} title
* @param {Unit} unit
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromFeeRatePattern(colors, pattern, title, unit) {
return [
{ metric: pattern.average, title: `${title} avg`, unit },
{
metric: pattern.min,
title: `${title} min`,
color: colors.red,
unit,
defaultActive: false,
},
{
metric: pattern.max,
title: `${title} max`,
color: colors.green,
unit,
defaultActive: false,
},
{
metric: pattern.pct10,
title: `${title} pct10`,
color: colors.rose,
unit,
defaultActive: false,
},
{
metric: pattern.pct25,
title: `${title} pct25`,
color: colors.pink,
unit,
defaultActive: false,
},
{
metric: pattern.median,
title: `${title} median`,
color: colors.purple,
unit,
defaultActive: false,
},
{
metric: pattern.pct75,
title: `${title} pct75`,
color: colors.violet,
unit,
defaultActive: false,
},
{
metric: pattern.pct90,
title: `${title} pct90`,
color: colors.fuchsia,
unit,
defaultActive: false,
},
];
}
/**
* Create series from a CoinbasePattern ({ sats, bitcoin, dollars } each as FullnessPattern)
* @param {Colors} colors
* @param {CoinbasePattern} pattern
* @param {string} title
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromCoinbasePattern(colors, pattern, title) {
return [
...fromFullnessPattern(colors, pattern.sats, title, Unit.sats),
...fromFullnessPattern(colors, pattern.bitcoin, title, Unit.btc),
...fromFullnessPattern(colors, pattern.dollars, title, Unit.usd),
];
}
/**
* Create series from a ValuePattern ({ sats, bitcoin, dollars } each as BlockCountPattern with sum + cumulative)
* @param {Colors} colors
* @param {ValuePattern} pattern
* @param {string} title
* @param {Color} [sumColor]
* @param {Color} [cumulativeColor]
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromValuePattern(colors, pattern, title, sumColor, cumulativeColor) {
return [
{
metric: pattern.sats.sum,
title,
color: sumColor,
unit: Unit.sats,
},
{
metric: pattern.sats.cumulative,
title: `${title} cumulative`,
color: cumulativeColor ?? colors.blue,
unit: Unit.sats,
defaultActive: false,
},
{
metric: pattern.bitcoin.sum,
title,
color: sumColor,
unit: Unit.btc,
},
{
metric: pattern.bitcoin.cumulative,
title: `${title} cumulative`,
color: cumulativeColor ?? colors.blue,
unit: Unit.btc,
defaultActive: false,
},
{
metric: pattern.dollars.sum,
title,
color: sumColor,
unit: Unit.usd,
},
{
metric: pattern.dollars.cumulative,
title: `${title} cumulative`,
color: cumulativeColor ?? colors.blue,
unit: Unit.usd,
defaultActive: false,
},
];
}
/**
* Create sum/cumulative series from a BlockCountPattern with explicit unit and colors
* @param {Colors} colors
* @param {BlockCountPattern<any>} pattern
* @param {string} title
* @param {Unit} unit
* @param {Color} [sumColor]
* @param {Color} [cumulativeColor]
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromBlockCountWithUnit(colors, pattern, title, unit, sumColor, cumulativeColor) {
return [
{
metric: pattern.sum,
title: `${title} sum`,
color: sumColor,
unit,
},
{
metric: pattern.cumulative,
title: `${title} cumulative`,
color: cumulativeColor ?? colors.blue,
unit,
defaultActive: false,
},
];
}
/**
* Create series from an IntervalPattern (base + average/min/max/median/percentiles, no sum/cumulative)
* @param {Colors} colors
* @param {IntervalPattern} pattern
* @param {string} title
* @param {Unit} unit
* @param {Color} [color]
* @returns {AnyFetchedSeriesBlueprint[]}
*/
export function fromIntervalPattern(colors, pattern, title, unit, color) {
return [
{ metric: pattern.base, title, color, unit },
{ metric: pattern.average, title: `${title} avg`, color: colors.purple, unit, defaultActive: false },
{ metric: pattern.min, title: `${title} min`, color: colors.red, unit, defaultActive: false },
{ metric: pattern.max, title: `${title} max`, color: colors.green, unit, defaultActive: false },
{ metric: pattern.median, title: `${title} median`, color: colors.violet, unit, defaultActive: false },
{ metric: pattern.pct10, title: `${title} pct10`, color: colors.rose, unit, defaultActive: false },
{ metric: pattern.pct25, title: `${title} pct25`, color: colors.pink, unit, defaultActive: false },
{ metric: pattern.pct75, title: `${title} pct75`, color: colors.fuchsia, unit, defaultActive: false },
{ metric: pattern.pct90, title: `${title} pct90`, color: colors.amber, unit, defaultActive: false },
];
}

View File

@@ -170,8 +170,15 @@
* @property {BrkClient} brk
* @property {(args: { metric: AnyMetricPattern, name: string, unit: Unit, color?: Color, defaultActive?: boolean, options?: LineSeriesPartialOptions }) => AnyFetchedSeriesBlueprint} s
* @property {(pattern: BlockCountPattern<any>, title: string, color?: Color) => AnyFetchedSeriesBlueprint[]} fromBlockCount
* @property {(pattern: DollarsPattern<any>, title: string, color?: Color) => AnyFetchedSeriesBlueprint[]} fromBitcoin
* @property {(pattern: BlockSizePattern<any>, title: string, color?: Color) => AnyFetchedSeriesBlueprint[]} fromBlockSize
* @property {(pattern: FullnessPattern<any>, title: string, color?: Color) => AnyFetchedSeriesBlueprint[]} fromBitcoin
* @property {(pattern: SizePattern<any>, title: string, color?: Color) => AnyFetchedSeriesBlueprint[]} fromBlockSize
* @property {(pattern: SizePattern<any>, title: string, unit: Unit) => AnyFetchedSeriesBlueprint[]} fromSizePattern
* @property {(pattern: FullnessPattern<any>, title: string, unit: Unit) => AnyFetchedSeriesBlueprint[]} fromFullnessPattern
* @property {(pattern: FeeRatePattern<any>, title: string, unit: Unit) => AnyFetchedSeriesBlueprint[]} fromFeeRatePattern
* @property {(pattern: CoinbasePattern, title: string) => AnyFetchedSeriesBlueprint[]} fromCoinbasePattern
* @property {(pattern: ValuePattern, title: string, sumColor?: Color, cumulativeColor?: Color) => AnyFetchedSeriesBlueprint[]} fromValuePattern
* @property {(pattern: BlockCountPattern<any>, title: string, unit: Unit, sumColor?: Color, cumulativeColor?: Color) => AnyFetchedSeriesBlueprint[]} fromBlockCountWithUnit
* @property {(pattern: IntervalPattern, title: string, unit: Unit, color?: Color) => AnyFetchedSeriesBlueprint[]} fromIntervalPattern
* @property {(args: { number?: number, name?: string, defaultActive?: boolean, lineStyle?: LineStyle, color?: Color, unit: Unit }) => FetchedLineSeriesBlueprint} createPriceLine
* @property {(args: { numbers: number[], unit: Unit }) => FetchedLineSeriesBlueprint[]} createPriceLines
* @property {(args: { constant: AnyMetricPattern, name: string, unit: Unit, color?: Color, lineStyle?: number, defaultActive?: boolean }) => FetchedLineSeriesBlueprint} line