Skip to main content

Crate brk_oracle

Crate brk_oracle 

Source
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:

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
HistogramEma
HistogramEmaCompact
HistogramRaw
Oracle
PaymentFilter
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 from pre_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, or None once 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.