AnchoredOracle
Inherits: BaseAdapter
Author: Storm Labs (https://storm-labs.xyz/)
PriceOracle that chains two PriceOracles.
Euler's experimental implementation was used as a reference: https://github.com/euler-xyz/euler-price-oracle/blob/experiments/src/aggregator/AnchoredOracle.sol
State Variables
_MAX_DIVERGENCE_LOWER_BOUND
The lower bound for maxDivergence
, 0.1%.
uint256 internal constant _MAX_DIVERGENCE_LOWER_BOUND = 0.001e18;
_MAX_DIVERGENCE_UPPER_BOUND
The upper bound for maxDivergence
, 50%.
uint256 internal constant _MAX_DIVERGENCE_UPPER_BOUND = 0.5e18;
_WAD
The denominator for maxDivergence
.
uint256 internal constant _WAD = 1e18;
name
The name of the oracle.
string public constant name = "AnchoredOracle";
primaryOracle
The address of the primary oracle.
address public immutable primaryOracle;
anchorOracle
The address of the anchor oracle.
address public immutable anchorOracle;
maxDivergence
The maximum divergence allowed, denominated in _WAD.
uint256 public immutable maxDivergence;
Functions
constructor
Deploys an AnchoredOracle contract.
constructor(address _primaryOracle, address _anchorOracle, uint256 _maxDivergence) payable;
Parameters
Name | Type | Description |
---|---|---|
_primaryOracle | address | The address of the primary oracle used for obtaining price quotes. |
_anchorOracle | address | The address of the anchor oracle used for validating price quotes. |
_maxDivergence | uint256 | The maximum allowed divergence between the primary and anchor oracle prices, denominated in _WAD. |
_getQuote
Retrieves a price quote from the primaryOracle
and ensures that anchorOracle
price does not diverge by
more than +/- the percent threshold. For example with a 50% threshold, a primary quote of 10 would check that
the anchor is between 5 and 15.
function _getQuote(uint256 inAmount, address base, address quote) internal view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
inAmount | uint256 | The amount of base token to be converted. |
base | address | The token for which the price is being determined. |
quote | address | The token against which the price is measured. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The price quote from the primaryOracle . |