Expand description
Pure on-chain BTC/USD price oracle.
Detects round-dollar transaction patterns ($1, $5, $10, … $10,000) in Bitcoin block outputs to derive the current price without any exchange data.
Behavior changes by height along two independent axes, each in its own module:
- EMA regime (
config): belowSTART_HEIGHT_SLOWprices come from the baked pre-oracle tape. From there toSTART_HEIGHT_FASTa slow cold-start EMA runs with a shape-anchoring restoring force. AtSTART_HEIGHT_FASTit switches to a fast EMA that tracks mature-market volatility. - Output filter (
filter): belowPaymentFilter::MODERN_TX_OUTPUT_FANOUT_CAP_START_HEIGHTbatch-payout transactions are capped strictly. Above it the cap relaxes but still drops very large fan-outs.
The two boundaries differ on purpose. The EMA must hand off to fast before the 2020 crash, while the output cap helps the thin pre-2020 mix for longer and still prevents modern fan-out clusters from dominating one EMA slot.
Structs§
- Config
- Oracle
- Payment
Filter - Round-dollar payment filter.
Constants§
- BINS_
PER_ DECADE - NUM_
BINS - START_
HEIGHT_ FAST - Height where the oracle switches slow -> fast EMA (
default). The regimes are complementary: slow resists the round-USD half-price drift that locks fast below here, while fast tracks the 2018-2019 crashes that lock slow. - START_
HEIGHT_ SLOW - First height the oracle computes on-chain, with the slow cold-start EMA
(
slow). Below it, prices come frompre_oracle_prices_from. - VERSION
- Oracle algorithm version. Bump on any change that alters computed prices so downstream consumers can invalidate cached results.
Functions§
- bin_
to_ cents - Converts a fractional bin to a USD price in cents. For a $D output at price P: sats = D * 1e8 / P, so P = 10^(10 - bin/200) dollars, where 10 = log10($100 reference * 1e8 sats/BTC).
- cents_
to_ bin - Converts a USD price in cents to a fractional bin (inverse of bin_to_cents).
- pre_
oracle_ price_ cents - Baked pre-oracle price at
height, orNoneonce on-chain oracle prices start. - pre_
oracle_ prices_ from - Baked pre-oracle prices starting at
start_height, as a one-pass iterator. - sats_
to_ bin - Maps a satoshi value to its log-scale bin index. bin = round(log10(sats) * BINS_PER_DECADE).
- seed_
bin - Initial reference bin for processing height START_HEIGHT_SLOW.
- seed_
price_ cents - Baked exchange price for the block immediately before on-chain oracle prices start.
Type Aliases§
- Histogram
Ema - Smoothed EMA over the window, one
f64per bin. The stencil search reads it, never serialized (projected toHistogramEmaCompactfor the wire). - Histogram
EmaCompact - Quantized
u16projection ofHistogramEmafor thehistogram/ema/*wire. - Histogram
Raw - Per-bin integer counts on the oracle log scale: used for both oracle-eligible payment histograms and unfiltered output histograms.