DelayedOracle
Inherits: IBaseOracle, IDelayedOracle
Transforms a price feed into a delayed price feed with a step function
Requires an external mechanism to call updateResult every updateDelay
seconds
State Variables
priceSource
Address of the non-delayed price source
Assumes that the price source is a valid IBaseOracle
IBaseOracle public priceSource;
symbol
Symbol of the quote: token / baseToken (e.g. 'ETH / USD')
string public symbol;
updateDelay
The delay in seconds that should elapse between updates
uint256 public updateDelay;
lastUpdateTime
The timestamp of the last update
uint256 public lastUpdateTime;
_currentFeed
The current valid price feed storage struct
Feed internal _currentFeed;
_nextFeed
The next valid price feed storage struct
Feed internal _nextFeed;
Functions
constructor
constructor(IBaseOracle _priceSource, uint256 _updateDelay);
Parameters
Name | Type | Description |
---|---|---|
_priceSource | IBaseOracle | The address of the non-delayed price source |
_updateDelay | uint256 | The delay in seconds that should elapse between updates |
updateResult
Updates the current price with the last next price, and reads the next price feed
Will revert if the delay since last update has not elapsed
function updateResult() external returns (bool _success);
Returns
Name | Type | Description |
---|---|---|
_success | bool | Whether the update was successful or not |
getResultWithValidity
Fetch the latest oracle result and whether it is valid or not
This method should never revert
function getResultWithValidity() external view returns (uint256 _result, bool _validity);
read
Fetch the latest oracle result
Will revert if is the price feed is invalid
function read() external view returns (uint256 _result);
shouldUpdate
Indicates if a delay has passed since the last update
function shouldUpdate() external view returns (bool _ok);
Returns
Name | Type | Description |
---|---|---|
_ok | bool | Whether the oracle should be updated or not |
getNextResultWithValidity
The next valid price feed, taking effect at the next updateResult call
function getNextResultWithValidity() external view returns (uint256 _result, bool _validity);
Returns
Name | Type | Description |
---|---|---|
_result | uint256 | The value in 18 decimals format of the next price feed |
_validity | bool | Whether the next price feed is valid or not |
_getPriceSourceResult
Internal view function that queries the standard price source
function _getPriceSourceResult() internal view returns (uint256 _priceFeedValue, bool _hasValidValue);
_delayHasElapsed
Internal view function that returns whether the delay between calls has been passed
function _delayHasElapsed() internal view returns (bool _ok);