Skip to main content
Standard DIA price oracles return the price together with the UNIX timestamp of its last update. The oracle does not revert when a price is old: if updates stop or are paused, it keeps returning the last stored price. Your contract is responsible for deciding whether that price is recent enough to use.
Always check the timestamp of an oracle response. Using a price without checking its age can expose your protocol to stale-price attacks, such as borrowing, liquidating or swapping against an outdated value.

Why a price can be stale

  • Heartbeat interval. Oracles update on a price deviation or a heartbeat, whichever comes first. Between updates the stored price ages normally.
  • Market conditions. A feed can hold its last price during unusual market conditions.
  • Market hours. Real-world asset feeds (stocks, ETFs, FX, commodities) may not update while their markets are closed.
  • Infrastructure issues. An unfunded gas wallet, network congestion or a cross-chain delivery delay can delay updates.

Set a maximum delay

Define the maximum age of a price your protocol accepts. There is no single correct value: update settings differ per oracle, so base it on your oracle’s heartbeat plus a buffer for network delays.
  • Do not set it below the heartbeat, or valid prices will be rejected between updates.
  • Set it per asset. A volatile token needs a tighter limit than a stablecoin.
  • For RWA feeds, decide how your protocol behaves when the market is closed: pause the affected actions, or accept the last close for a defined period.
  • If you don’t know your oracle’s heartbeat, contact the DIA team.

Check the timestamp

The checks below go inside your contract’s functions. Each one first confirms the timestamp is not ahead of the current block, then checks its age, so a small clock difference between chains reverts with a clear message instead of an arithmetic error.

Using getValue

getValue returns the price first, then the timestamp.

Using push or pull oracles

Push and pull oracles store prices in the updates mapping. Note the return order: timestamp first, then price.

Using the DIA Solidity library

getPriceIfNotOlderThan returns the price and a flag that is false when the price is older than maxTimePassed.
See getValue Method for the full library reference.

Using the AggregatorV3Interface adapter

Check the updatedAt value returned by latestRoundData().

What to do when the price is stale

Revert, pause the affected function, or switch to a fallback source. Never silently continue with the stale value. If the key has never been updated, the oracle returns 0 for both price and timestamp. The timestamp check above rejects this case, but you can also add require(price > 0) as an extra safeguard.