Fix stale oracle_cash reference in ORACLE_SCALE comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakob Notland 2026-06-09 13:28:55 +02:00
parent 7c196faf87
commit 8b10473b9f
2 changed files with 7 additions and 6 deletions

View file

@ -54,17 +54,19 @@ pub fn dec_to_f64_bounded(d: Decimal) -> f64 {
}
pub const SATS_PER_BCH: i64 = 100_000_000;
/// On-chain Delphi oracle scale: prices are stored in cents
/// (e.g. $384.24 → 38424). Same unit as the oracles.cash feed.
/// Oracle prices are stored in cents (38424 = $384.24). Divide by 100 to get USD.
pub const ORACLE_SCALE: i64 = 100;
pub async fn usd_per_bch_at_or_before(oracle_pool: &SqlitePool, ts: i64) -> anyhow::Result<Decimal> {
pub async fn usd_per_bch_at_or_before(
oracle_pool: &SqlitePool,
ts: i64,
) -> anyhow::Result<Decimal> {
let entry = get_closest(oracle_pool, &None, ts)
.await?
.ok_or_else(|| anyhow::anyhow!("No oracle price found for timestamp {ts}"))?;
let price = Decimal::from_i64(entry.oracle_price)
.ok_or_else(|| anyhow::anyhow!("Oracle price out of Decimal range: {}", entry.oracle_price))?;
let price = Decimal::from_i64(entry.oracle_price).ok_or_else(|| {
anyhow::anyhow!("Oracle price out of Decimal range: {}", entry.oracle_price)
})?;
Ok(price / Decimal::from_i64(ORACLE_SCALE).unwrap())
}

View file

@ -259,4 +259,3 @@ pub async fn oracle_cash_history(
CACHE_AGGREGATE,
))
}