View Source: contracts/PriceFeed.sol
↗ Extends: PriceFeedStorage, IPriceFeed
PriceFeed
The PriceFeed relies upon a main oracle and a secondary as a fallback in case of error
Events
event LastGoodPriceUpdated(uint256 _lastGoodPrice);
event PriceFeedBroken(uint8 index, address priceFeedAddress);
event PriceFeedUpdated(uint8 index, address newPriceFeedAddress);
- setAddresses(address _mainPriceFeed, address _backupPriceFeed)
- fetchPrice()
- setAddress(uint8 _index, address _newPriceFeed)
- _storePrice(uint256 _currentPrice)
function setAddresses(address _mainPriceFeed, address _backupPriceFeed) external nonpayable onlyOwner
Arguments
Name | Type | Description |
---|---|---|
_mainPriceFeed | address | |
_backupPriceFeed | address |
Source Code
function setAddresses(address _mainPriceFeed, address _backupPriceFeed) external onlyOwner {
uint256 latestPrice = setAddress(0, _mainPriceFeed);
setAddress(1, _backupPriceFeed);
_storePrice(latestPrice);
}
Returns the latest price obtained from the Oracle. Called by Zero functions that require a current price. It uses the main price feed and fallback to the backup one in case of an error. If both fail return the last good price seen.
function fetchPrice() external nonpayable
returns(uint256)
Source Code
function fetchPrice() external override returns (uint256) {
for (uint8 index = 0; index < 2; index++) {
(uint256 price, bool success) = priceFeeds[index].latestAnswer();
if (success) {
_storePrice(price);
return price;
} else {
emit PriceFeedBroken(index, address(priceFeeds[index]));
}
}
return lastGoodPrice;
}
Allows users to setup the main and the backup price feeds
function setAddress(uint8 _index, address _newPriceFeed) public nonpayable onlyOwner
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_index | uint8 | the oracle to be configured |
_newPriceFeed | address | address where an IExternalPriceFeed implementation is located |
Returns
price the latest price of the inserted price feed
Source Code
function setAddress(uint8 _index, address _newPriceFeed) public onlyOwner returns (uint256) {
require(_index < priceFeeds.length, "Out of bounds when setting the price feed");
checkContract(_newPriceFeed);
priceFeeds[_index] = IExternalPriceFeed(_newPriceFeed);
(uint256 price, bool success) = priceFeeds[_index].latestAnswer();
require(success, "PriceFeed: Price feed must be working");
emit PriceFeedUpdated(_index, _newPriceFeed);
return price;
}
function _storePrice(uint256 _currentPrice) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
_currentPrice | uint256 |
Source Code
function _storePrice(uint256 _currentPrice) internal {
lastGoodPrice = _currentPrice;
emit LastGoodPriceUpdated(_currentPrice);
}
- ActivePool
- ActivePoolStorage
- BaseMath
- BorrowerOperations
- BorrowerOperationsScript
- BorrowerOperationsStorage
- BorrowerWrappersScript
- CheckContract
- CollSurplusPool
- CollSurplusPoolStorage
- console
- Context
- DefaultPool
- DefaultPoolStorage
- DocsCover
- DSAuth
- DSAuthEvents
- DSAuthority
- DSNote
- DSProxy
- DSProxyCache
- DSProxyFactory
- ERC20
- ETHTransferScript
- FeeDistributor
- FeeDistributorStorage
- GasPool
- HintHelpers
- HintHelpersStorage
- IActivePool
- IBalanceRedirectPresale
- IBorrowerOperations
- ICollSurplusPool
- IDefaultPool
- IERC20
- IERC2612
- IExternalPriceFeed
- IFeeDistributor
- IFeeSharingProxy
- ILiquityBase
- ILiquityBaseParams
- IMasset
- IMoCBaseOracle
- Initializable
- IPool
- IPriceFeed
- IRSKOracle
- ISortedTroves
- IStabilityPool
- ITroveManager
- IWrbtc
- IZUSDToken
- LiquityBase
- LiquityBaseParams
- LiquityMath
- LiquitySafeMath128
- MoCMedianizer
- MultiTroveGetter
- MultiTroveGetterStorage
- NueToken
- Ownable
- PriceFeed
- PriceFeedStorage
- ProxiableContract
- ProxiableContract2
- Proxy
- RskOracle
- SafeMath
- SortedTroves
- SortedTrovesStorage
- StabilityPool
- StabilityPoolScript
- StabilityPoolStorage
- Storage
- Storage2
- TokenScript
- TroveManager
- TroveManagerBase
- TroveManagerBase1MinuteBootstrap
- TroveManagerRedeemOps
- TroveManagerScript
- TroveManagerStorage
- UpgradableProxy
- ZUSDToken
- ZUSDTokenStorage