PRIV ProtocolPRIV Docs
Contracts

PriceOracle

Chainlink-powered PRIV/USD price oracle with TWAP fallback, staleness checks, and manual override for emergency situations.

Overview

PriceOracle provides reliable PRIV/USD price data for the protocol. It uses Chainlink as the primary price source with an optional Uniswap V3 TWAP fallback. Circuit breakers (staleness checks, deviation monitoring, and pause functionality) protect against oracle failures.

PropertyValue
ContractPriceOracle
Address (Base Sepolia)0x3cD9d4f195d8c9ffb1D9B21A839A66B033BE1f34
Chainlink FeedETH/USD (0x4adC67d868ec962f5cb0A13a4FD8bBcDB1Cf80D3)
Price Decimals8 (Chainlink standard)
Staleness Threshold5 min -- 24 hours (configurable)
Deviation Threshold0.5% -- 20% (configurable)
Manual Override Duration24 hours max
NetworkBase (Chain ID: 8453)

Price Resolution

The oracle resolves price through a priority cascade:

  1. Manual override -- If active and within 24 hours of being set, returns the override price (source = 2).
  2. Chainlink feed -- If the latest round is complete and data is fresher than the staleness threshold (source = 0).
  3. TWAP fallback -- If Chainlink is stale and TWAP is enabled via a Uniswap V3 pool (source = 1).
  4. Revert -- If no valid source is available, the call reverts with NoValidPriceSource.

Key Functions

getPrice

Returns the current PRIV/USD price using the priority cascade above.

function getPrice() external view returns (uint256 price, uint8 source)

usdToPriv / privToUsd

Convert between USD (6 decimals) and PRIV (18 decimals) using the current oracle price.

function usdToPriv(uint256 usdAmount) external view returns (uint256 privAmount)
function privToUsd(uint256 privAmount) external view returns (uint256 usdAmount)

isHealthy

Reports whether the oracle is operating normally and the deviation between Chainlink and TWAP sources.

function isHealthy() external view returns (bool healthy, uint256 deviation)

Admin Functions

FunctionDescription
setChainlinkFeed(address)Update Chainlink price feed address
setTWAPSource(address, bool)Set Uniswap V3 pool for TWAP and enable/disable
setManualPriceOverride(uint256)Emergency price override (8 decimals, 0 to disable)
setDeviationThreshold(uint256)Adjust max deviation between sources (50--2000 bps)
setStalenessThreshold(uint256)Adjust max data age (5 min -- 24 hours)
pause() / unpause()Circuit breaker for emergency stops

Security

  • Round validation: Rejects incomplete Chainlink rounds (answeredInRound < roundId).
  • Non-positive price rejection: Reverts on zero or negative Chainlink answers.
  • Manual override auto-expiry: Override automatically expires after 24 hours to prevent stale manual prices from persisting.
  • Bounds on all thresholds: Staleness, deviation, and TWAP period all have enforced min/max ranges.

Source Code

View on GitHub