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.
Overview
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.
Getting the price
The contract has a getPrice
function that retrieves the price of a particular asset. It first checks if the asset is supported by calling the supportsAsset
function. 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.
Supported assets
The contract has a supportsAsset
function 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 setAssetStatus
function 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 supportsAsset
function. If the asset is supported, it updates the disabled assets mapping with the new status of the asset.
Last updated