Comment on page
Chainlink Oracle Adapter
The ChainlinkOracleAdapter is a contract that uses Chainlink to retrieve price data for various assets. It supports all X / ETH feeds as well as WBTC and WETH.
The ChainlinkOracleAdapter contract is an implementation of the IBasePriceOracle interface and it uses Chainlink's feed registry to retrieve prices of assets. The contract takes in the address of the feed registry and the addresses of wrapped native assets (e.g. WETH and WBTC) as input in its constructor.
The contract has a
getPricefunction that retrieves the price of a particular asset. It first checks if the asset is supported by calling the
supportsAssetfunction. It then retrieves the feed for the asset from the feed registry and checks if the price update is within the allowed staleness period (i.e. 24 hours). If the price update is within the allowed staleness period, it retrieves the latest price from the feed and returns it. If the price update is outside the allowed staleness period, it throws an error.
The contract has a
supportsAssetfunction that checks if a particular asset is supported by the oracle. It first checks if the quote asset is either WETH or ETH and not disabled. It then checks if the base asset is equal to WBTC and converts it to BTC if it is. It then retrieves the feed for the base asset and quote asset from the feed registry and checks if the feed exists. If the feed exists, it returns true, indicating that the asset is supported by the oracle.
The contract also has a
setAssetStatusfunction that enables or disables a particular asset. This function can only be called by the contract owner and it checks if the asset is supported by calling the
supportsAssetfunction. If the asset is supported, it updates the disabled assets mapping with the new status of the asset.