PriceFeed
https://github.com/Into-the-Fathom/fathom-stablecoin-smart-contracts/blob/master/contracts/main/price-feeders/CentralizedOraclePriceFeed.sol
The CentralizedOraclePriceFeed
contract utilizes a centralized oracle source to fetch the latest prices of assets. It introduces a delay in price updates to mitigate the risks associated with price manipulation and flash loan attacks. The delayed price update ensures that fetched prices do not immediately affect the system, providing a buffer to detect and react to potential price anomalies.
CentralizedOraclePriceFeed
is named centralized because it utilizes Oracle data that can be fetched from off-chain centralized sources (like Chainlink, Supra, and other oracles), not from pure onchain (DEX) data. Oracles themselves can be decentralized, and CentralizedOraclePriceFeed
isn't responsible for the quality of the data.
Storage Variables
oracle
: Address of the centralized oracle contract (address
). This oracle provides the latest price data.accessControlConfig
: Address of the access control contract (IAccessControlConfig
). It is used to manage roles and permissions within the contract.latestPrice
: Latest fetched price information stored asPriceInfo
, which includes the price and the timestamp of the last update.delayedPrice
: The price that is currently being used by the system, delayed by a certain period defined bytimeDelay
.timeDelay
: The delay period (in seconds) that determines how long fetched price data must wait before being considered valid within the system.priceLife
: The duration (in seconds) for which a price is considered valid after being updated.poolId
: Identifier for the specific pool or asset that this price feed pertains to.
Functions
setOracle(address _oracle)
: Updates the oracle address. This function can only be called by the owner or governance role.setTimeDelay(uint256 _seconds)
: Sets the time delay for the price update. This can only be adjusted by the owner or governance role.setPriceLife(uint256 _seconds)
: Sets the duration for which a price is considered valid.retrivePrice()
: Fetches the latest price from the oracle and updates the price information in the contract.
Events
LogSetTimeDelay(address indexed _caller, uint256 _seconds)
: Emitted when the time delay is updated.LogSetPriceLife(address indexed _caller, uint256 _second)
: Emitted when the price life duration is updated.LogPeekPriceFailed(address indexed _caller, string _reason)
: Emitted if fetching the latest price fails.
Last updated