Chapter 11

Building with Oracles

Integrating an oracle is rarely a one-line import. Production contracts must handle stale data, decimal scaling, paused feeds, and edge cases where the oracle is technically live but economically meaningless — such as a feed for a token whose only pool was drained hours ago.

Chainlink's AggregatorV3Interface exposes latestRoundData with price, timestamps, and round metadata. Similar interfaces exist across providers — read the vendor docs for pull models that require submitting proofs in the same transaction as your core logic.

Test on forks with historical crash blocks: March 2020, Terra unwind, FTX weekend, and any event that stressed your asset class. If your protocol only works when prices update every minute and never deviate more than five percent, document that assumption and enforce it in code.