EUR0 Classical Oracle
High-Level Overview
The ClassicalOracle contract is used by DaoCollateral to fetch the price of external tokens. The price of tokens is used for minting and redeeming the right amount of EUR0. It is an upgradable contract.
Contract Summary
The logic contained in ClassicalOracle includes:
Initializing
tokenToOracleInfo
for each supported token with a ChainlinkV3Aggregator-compatible price feedConverting the price of the oracle of arbitrary decimals into wad (18 decimals)
Computing a quote (USD value) for a given token and amount of tokens
Making sure stablecoins haven’t depegged
Allowing the admin to set the maximum allowed price variation for stablecoins
Interacting with the aggregator to fetch the latest price and its number of decimals
Inherited Contracts
IOracle: Common interface used by other contracts and external service (e.g. the dApp) to interact with the ClassicalOracle. Ensures function signatures are the ones expected by these external actors.
Initializable: Allows to handle contract setup and upgrades.
Functionality Breakdown
After deploying the contract, the administrator should initialize the price feed for all supported collateral thanks to the initializeTokenOracle
function.
When another contract or external service calls getPrice
or getQuote
, the contract calls the virtual function _latestRoundData
passing the desired token as parameter. This function is implemented in ClassicalOracle and retrieves the associated price aggregator for this token, then calls decimals
and latestRoundData.
Functions Description
Public/External Functions
initializeTokenOracle(address token, address dataSource, uint64 timeout, bool isStablecoin): Registers a new supported token or updates the data source (price aggregator) for an existing token. The new price feed must have been last updated within the last
timeout
seconds. This check is only performed once. IfisStablecoin
is true, the depeg check will be enabled andgetPrice
/getQuote
will revert if the price is not around $1.getMaxDepegThreshold(): Returns the current maximum allowed price variation for stablecoins in basis points (e.g. with a value of 500,
getPrice
andgetQuote
will revert if the price of a stablecoin is outside the range $0.95-$1.05). View function.setMaxDepegThreshold(uint256 maxAuthorizedDepegPrice): Updates the maximum allowed price variation and emits a
SetMaxDepegThreshold
event. Nonpayable function. Reserved for admin use only.getPrice(address token): Returns the price of the given token scaled to 18 decimals (e.g. a return value of 3e18 means the token price is $3). Reverts if the token is a stablecoin and it’s outside of the allowed price variation range. View function.
getQuote(address token): Returns the USD value equivalent to the given amount of the given token (e.g. if the token price is $3, calling with 1e6 will return 3e6, no matter the number of decimals of the token). Reverts if the token is a stablecoin and it’s outside of the allowed price variation range. View function.
Last updated
Was this helpful?