Trading Dev AcademyFree quant education

Free lesson · On-chain markets

Stale oracle health versus executable collateral value

Open interactive lessonPractice calculationsExplore labs

Start with the idea

A contract may report sufficient collateral using an old reference while a real sale of that collateral would no longer cover the debt.

Symbols, units & horizon
  • q: collateral token units
  • P_o: oracle USD/token available at the block
  • P_s: separately labeled attainable/stress USD/token
  • τ: liquidation threshold fraction
  • D: debt USD
  • H: health ratios at the same decision checkpoint

When and why to use this

Build a causal lending replay that exposes oracle lag and liquidation timing.

A contract may report sufficient collateral using an old reference while a real sale of that collateral would no longer cover the debt.

Compare protocol health using its actual oracle with a separate economic stress mark. Neither should silently replace the other in a historical simulation: the protocol could act only on the value it had.

A replay needs price observation time, oracle publication time, block inclusion and strategy decision time. Using a future oracle update at an earlier block creates look-ahead bias.

Horacle=qPoτD,Hstress=qPsτD
Model assumptions, derivation and arithmetic

Stale oracle health versus executable collateral value

  1. Compute collateral health from the price actually available to the contract.
  2. Repeat using the separately declared economic stress price.
  3. Interpret the difference as timing/valuation exposure, without assuming the contract could observe future information.
Work it by hand

100 tokens, oracle $100, stress price $75, threshold .8, debt $7,000: oracle health=8000/7000≈1.142857; stress health=6000/7000≈.857143.

Apply it in a strategy

  • Build a causal lending replay that exposes oracle lag and liquidation timing.
  • Record the input timestamp, executable quantity, currency and horizon. Reconcile the result with a cash-flow or state table.
  • Stress this failure condition: A later revised price cannot be used as if it were known at an earlier on-chain decision.

Research deliverable

Build and explain a stale oracle health versus executable collateral value worksheet. Build a causal lending replay that exposes oracle lag and liquidation timing.

Evidence boundary: Synthetic arithmetic and scenarios illustrate mechanics. They are not historical returns, a paper replication, or evidence of an executable edge. Research sources and their access limitations are recorded at the end of this module.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Python 3.10+; standard library unless NumPy is imported below.
# Inputs and outputs use the units defined in this lesson. Synthetic teaching example.
def dual_health(tokens,oracle_price,stress_price,threshold,debt):
    if min(tokens,oracle_price,stress_price)<0 or not 0<=threshold<=1 or debt<=0: raise ValueError("Invalid collateral values")
    return tokens*oracle_price*threshold/debt,tokens*stress_price*threshold/debt

print(dual_health(100,100,75,.8,7000))

Continue learning

On-Chain Markets: Data, Oracles and Execution — all lessons
  1. Raw token amounts and economic event types
  2. Transaction gas in a reporting currency
  3. Minimum output and ordering risk
  4. Time-weighted reference prices
  5. Stale oracle health versus executable collateral value
  6. Bridge fragmentation and capital lock-up
  7. Inclusion, finality and conditional loss scenarios
  8. A reproducible on-chain economics study

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations