Files
zeekayandHanzo Dev 9864cb54a1 oracle: fill the empty slot — a justified price, or a refusal
pkg/oracle has been an empty directory while pkg/source sat unimported, so this
repo could FETCH a price and had nowhere to decide whether one may be believed.
The service answers from CoinGecko alone behind an hour cache, which is right for
a ticker and wrong for money: one upstream is one outage and one bad tick away
from valuing everything, and an hour-old BTC quote is routinely tens of dollars
stale (measured: $24.36 against the venues).

Every one of these REFUSES rather than falling back — fewer than two independent
sources answered, they disagree by more than 2%, or a source answered <= 0. One
error for all of them, because a caller's only correct response to any is to not
act and retry; distinguishing them invites handling one by acting anyway. New()
refuses a duplicate venue name at construction: two entries for one exchange
satisfy the COUNT while providing one opinion, which is the property MinSources
is meant to buy.

The median takes the LOWER middle, so with two sources it is the minimum. A venue
quoting high can never pull a price above what the conservative venue said.

Prices are MICRO-CENTS. XRP at $1.04295 and TON at $1.3412 become $1.04 and $1.34
as whole cents — 0.28% and 0.09% off on every use. Whole cents are precise enough
for BTC and nowhere near it for a sub-dollar coin, and precision cannot depend on
which asset is being priced. The float64 in source.Quote costs at most one
micro-cent per whole unit (~1e-10 dollars on a realistic deposit); the bound is
stated in microCents() rather than assumed, and carrying the venue's decimal
string through source.Quote would remove it.

Batch-shaped because source.Fetch is. An id that cannot be justified is OMITTED
rather than zero — a zero price is a number, and a number is something a caller
uses by accident.

Tests stub the venues so the JUDGEMENT is what is asserted, plus a live probe
(PRICE_LIVE=1) over bitcoin/ripple/the-open-network. The live one earned its keep
immediately: its BTC sanity floor was written as $100,000 instead of $1,000 and
failed against a correct price.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-09 09:29:47 -07:00
..