Skip to content

UniV3CheckCLRSOracle ​

Git Source

Inherits:FluidOracle, UniV3OracleImpl, FallbackOracleImpl

Gets the exchange rate between the underlying asset and the peg asset by using: the price from a UniV3 pool (compared against 3 TWAPs) and (optionally) comparing it against a Chainlink or Redstone price (one of Chainlink or Redstone being the main source and the other one the fallback source). Alternatively it can also use Chainlink / Redstone as main price and use UniV3 as check price.

*The process for getting the aggregate oracle price is:

  1. Fetch the UniV3 TWAPS, the latest interval is used as the current price
  2. Verify this price is within an acceptable DELTA from the Uniswap TWAPS e.g.: a. 240 to 60s b. 60 to 15s c. 15 to 1s (last block) d. 1 to 0s (current)
  3. (unless UniV3 only mode): Verify this price is within an acceptable DELTA from the Chainlink / Redstone Oracle
  4. If it passes all checks, return the price. Otherwise use fallbacks, usually to Chainlink. In extreme edge-cases revert.*

For UniV3 with check mode, if fetching the check price fails, the UniV3 rate is used directly.

State Variables ​

_RATE_CHECK_MAX_DELTA_PERCENT ​

Rate check oracle delta percent in 1e2 percent. If current uniswap price is out of this delta, current price fetching reverts.

solidity
uint256 internal immutable _RATE_CHECK_MAX_DELTA_PERCENT;

_RATE_SOURCE ​

*which oracle to use as final rate source:

  • 1 = UniV3 ONLY (no check),
  • 2 = UniV3 with Chainlink / Redstone check
  • 3 = Chainlink / Redstone with UniV3 used as check.*
solidity
uint8 internal immutable _RATE_SOURCE;

Functions ​

constructor ​

solidity
constructor(string memory infoName_, UniV3CheckCLRSConstructorParams memory params_)
    UniV3OracleImpl(params_.uniV3Params)
    FallbackOracleImpl(params_.fallbackMainSource, params_.chainlinkParams, params_.redstoneOracle)
    FluidOracle(infoName_);

getExchangeRateOperate ​

solidity
function getExchangeRateOperate() public view virtual override returns (uint256 exchangeRate_);

getExchangeRateLiquidate ​

solidity
function getExchangeRateLiquidate() public view virtual override returns (uint256 exchangeRate_);

getExchangeRate ​

solidity
function getExchangeRate() public view virtual override returns (uint256 exchangeRate_);

uniV3CheckOracleData ​

returns all oracle related data as utility for easy off-chain / block explorer use in a single view method

solidity
function uniV3CheckOracleData()
    public
    view
    returns (uint256 rateCheckMaxDelta_, uint256 rateSource_, uint256 fallbackMainSource_);

_getExchangeRate ​

solidity
function _getExchangeRate() internal view returns (uint256 exchangeRate_);

Structs ​

UniV3CheckCLRSConstructorParams ​

solidity
struct UniV3CheckCLRSConstructorParams {
    UniV3ConstructorParams uniV3Params;
    ChainlinkConstructorParams chainlinkParams;
    RedstoneOracleData redstoneOracle;
    uint8 rateSource;
    uint8 fallbackMainSource;
    uint256 rateCheckMaxDeltaPercent;
}