Skip to content
Verified contractPartialBUSL-1.1

FluidGenericOracle

Address0xee67381c58dd624e5cc91e9b8fa9287e233b36ac
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.21

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.21+commit.d9974bed
Language
solidity
Optimization
Yes, 10,000,000 runs
EVM version
paris
License
BUSL-1.1
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
22,352,784
Creation transaction
0x1b4239aff2…044d84ed13

contracts/oracle/oracles/genericOracle.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { FluidOracle } from "../fluidOracle.sol";
import { FluidGenericOracleBase } from "./genericOracleBase.sol";

/// @notice generic configurable Oracle
/// combines up to 4 hops from sources such as
///  - an existing IFluidOracle (e.g. ContractRate)
///  - Redstone
///  - Chainlink
contract FluidGenericOracle is FluidOracle, FluidGenericOracleBase {
    constructor(
        string memory infoName_,
        uint8 targetDecimals_,
        OracleHopSource[] memory sources_
    ) FluidOracle(infoName_, targetDecimals_) FluidGenericOracleBase(sources_) {}

    /// @inheritdoc FluidOracle
    function getExchangeRateOperate() public view virtual override returns (uint256 exchangeRate_) {
        exchangeRate_ = _getHopsExchangeRate(true);
    }

    /// @inheritdoc FluidOracle
    function getExchangeRateLiquidate() public view virtual override returns (uint256 exchangeRate_) {
        exchangeRate_ = _getHopsExchangeRate(false);
    }

    /// @inheritdoc FluidOracle
    function getExchangeRate() public view virtual override returns (uint256 exchangeRate_) {
        exchangeRate_ = _getHopsExchangeRate(false);
    }
}

contracts/oracle/error.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

contract Error {
    error FluidOracleError(uint256 errorId_);
}

contracts/oracle/errorTypes.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

library ErrorTypes {
    /***********************************|
    |           FluidOracleL2           | 
    |__________________________________*/

    /// @notice thrown when sequencer on a L2 has an outage and grace period has not yet passed.
    uint256 internal constant FluidOracleL2__SequencerOutage = 60000;

    /***********************************|
    |     UniV3CheckCLRSOracle          | 
    |__________________________________*/

    /// @notice thrown when the delta between main price source and check rate source is exceeding the allowed delta
    uint256 internal constant UniV3CheckCLRSOracle__InvalidPrice = 60001;

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant UniV3CheckCLRSOracle__InvalidParams = 60002;

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant UniV3CheckCLRSOracle__ExchangeRateZero = 60003;

    /***********************************|
    |           FluidOracle             | 
    |__________________________________*/

    /// @notice thrown when an invalid info name is passed into a fluid oracle (e.g. not set or too long)
    uint256 internal constant FluidOracle__InvalidInfoName = 60010;

    /***********************************|
    |            sUSDe Oracle           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant SUSDeOracle__InvalidParams = 60102;

    /***********************************|
    |           Pendle Oracle           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant PendleOracle__InvalidParams = 60201;

    /// @notice thrown when the Pendle market Oracle has not been initialized yet
    uint256 internal constant PendleOracle__MarketNotInitialized = 60202;

    /// @notice thrown when the Pendle market does not have 18 decimals
    uint256 internal constant PendleOracle__MarketInvalidDecimals = 60203;

    /// @notice thrown when the Pendle market returns an unexpected price
    uint256 internal constant PendleOracle__InvalidPrice = 60204;

    /***********************************|
    |    CLRS2UniV3CheckCLRSOracleL2    | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant CLRS2UniV3CheckCLRSOracleL2__ExchangeRateZero = 60301;

    /***********************************|
    |    Ratio2xFallbackCLRSOracleL2    | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant Ratio2xFallbackCLRSOracleL2__ExchangeRateZero = 60311;

    /***********************************|
    |            WeETHsOracle           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant WeETHsOracle__InvalidParams = 60321;

    /***********************************|
    |        DexSmartColOracle          | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant DexSmartColOracle__InvalidParams = 60331;

    /// @notice thrown when smart col is not enabled
    uint256 internal constant DexSmartColOracle__SmartColNotEnabled = 60332;

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant DexSmartColOracle__ExchangeRateZero = 60333;

    /***********************************|
    |        DexSmartDebtOracle         | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant DexSmartDebtOracle__InvalidParams = 60341;

    /// @notice thrown when smart debt is not enabled
    uint256 internal constant DexSmartDebtOracle__SmartDebtNotEnabled = 60342;

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant DexSmartDebtOracle__ExchangeRateZero = 60343;

    /***********************************|
    |            CappedRate           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant CappedRate__InvalidParams = 60351;

    /// @notice thrown when caller is not authorized
    uint256 internal constant CappedRate__Unauthorized = 60352;

    /// @notice thrown when minimum diff for triggering update on the stared rate is not reached
    uint256 internal constant CappedRate__MinUpdateDiffNotReached = 60353;

    /// @notice thrown when the external rate source returns 0 for the new rate
    uint256 internal constant CappedRate__NewRateZero = 60354;

    /// @notice thrown when the new rate source does not fit in 192 bit storage uint, should never happen.
    uint256 internal constant CappedRate__StorageOverflow = 60355;

    /***********************************|
    |            sUSDs Oracle           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant SUSDsOracle__InvalidParams = 60361;

    /***********************************|
    |            Peg Oracle             | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant PegOracle__InvalidParams = 60371;

    /***********************************|
    |              DexOracle            | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant DexOracle__InvalidParams = 60381;

    /// @notice thrown when the exchange rate is zero, even after all possible fallbacks depending on config
    uint256 internal constant DexOracle__ExchangeRateZero = 60382;

    /***********************************|
    |           GenericOracle           | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant GenericOracle__InvalidParams = 60401;

    /// @notice thrown when reaching an unexepcted config state
    uint256 internal constant GenericOracle__UnexpectedConfig = 60402;

    /// @notice thrown when the exchange rate is zero
    uint256 internal constant GenericOracle__RateZero = 60403;

    /***********************************|
    |          Chainlink Oracle         | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant ChainlinkOracle__InvalidParams = 61001;

    /***********************************|
    |          UniswapV3 Oracle         | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant UniV3Oracle__InvalidParams = 62001;

    /// @notice thrown when constructor is called with invalid ordered seconds agos values
    uint256 internal constant UniV3Oracle__InvalidSecondsAgos = 62002;

    /// @notice thrown when constructor is called with invalid delta values > 100%
    uint256 internal constant UniV3Oracle__InvalidDeltas = 62003;

    /***********************************|
    |            WstETh Oracle          | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant WstETHOracle__InvalidParams = 63001;

    /***********************************|
    |           Redstone Oracle         | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant RedstoneOracle__InvalidParams = 64001;

    /***********************************|
    |          Fallback Oracle          | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant FallbackOracle__InvalidParams = 65001;

    /***********************************|
    |       FallbackCLRSOracle          | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even for the fallback oracle source (if enabled)
    uint256 internal constant FallbackCLRSOracle__ExchangeRateZero = 66001;

    /***********************************|
    |         WstETHCLRSOracle          | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even for the fallback oracle source (if enabled)
    uint256 internal constant WstETHCLRSOracle__ExchangeRateZero = 67001;

    /***********************************|
    |        CLFallbackUniV3Oracle      | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even for the uniV3 rate
    uint256 internal constant CLFallbackUniV3Oracle__ExchangeRateZero = 68001;

    /***********************************|
    |  WstETHCLRS2UniV3CheckCLRSOracle  | 
    |__________________________________*/

    /// @notice thrown when the exchange rate is zero, even for the uniV3 rate
    uint256 internal constant WstETHCLRS2UniV3CheckCLRSOracle__ExchangeRateZero = 69001;

    /***********************************|
    |             WeETh Oracle          | 
    |__________________________________*/

    /// @notice thrown when an invalid parameter is passed to a method
    uint256 internal constant WeETHOracle__InvalidParams = 70001;
}

contracts/oracle/fluidOracle.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { IFluidOracle } from "./interfaces/iFluidOracle.sol";
import { ErrorTypes } from "./errorTypes.sol";
import { Error as OracleError } from "./error.sol";

/// @title   FluidOracle
/// @notice  Base contract that any Fluid Oracle must implement
abstract contract FluidOracle is IFluidOracle, OracleError {
    /// @dev short helper string to easily identify the oracle. E.g. token symbols
    //
    // using a bytes32 because string can not be immutable.
    bytes32 private immutable _infoName;

    /// @dev target decimals of the oracle when scaling to 1e27. E.g. for ETH / USDC it would be 15
    /// because diff of ETH decimals to 1e27 is 9, and USDC has 6 decimals, so 6+9 = 15, e.g. 2029,047772120364926
    /// For USDC / ETH: 21 + 18 = 39, e.g. 0,000492842018675092636829357843847601646
    uint8 private immutable _targetDecimals;

    constructor(string memory infoName_, uint8 targetDecimals_) {
        if (bytes(infoName_).length > 32 || bytes(infoName_).length == 0) {
            revert FluidOracleError(ErrorTypes.FluidOracle__InvalidInfoName);
        }

        if (targetDecimals_ < 15 || targetDecimals_ > 39) {
            revert FluidOracleError(ErrorTypes.GenericOracle__InvalidParams);
        }
        _targetDecimals = targetDecimals_;

        // convert string to bytes32
        bytes32 infoNameBytes32_;
        assembly {
            infoNameBytes32_ := mload(add(infoName_, 32))
        }
        _infoName = infoNameBytes32_;
    }

    /// @inheritdoc IFluidOracle
    function targetDecimals() external view returns (uint8) {
        return _targetDecimals;
    }

    /// @inheritdoc IFluidOracle
    function infoName() external view returns (string memory) {
        // convert bytes32 to string
        uint256 length_;
        while (length_ < 32 && _infoName[length_] != 0) {
            length_++;
        }
        bytes memory infoNameBytes_ = new bytes(length_);
        for (uint256 i; i < length_; i++) {
            infoNameBytes_[i] = _infoName[i];
        }
        return string(infoNameBytes_);
    }

    /// @inheritdoc IFluidOracle
    function getExchangeRate() external view virtual returns (uint256 exchangeRate_);

    /// @inheritdoc IFluidOracle
    function getExchangeRateOperate() external view virtual returns (uint256 exchangeRate_);

    /// @inheritdoc IFluidOracle
    function getExchangeRateLiquidate() external view virtual returns (uint256 exchangeRate_);
}

contracts/oracle/interfaces/external/IChainlinkAggregatorV3.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

/// from https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
/// Copyright (c) 2018 SmartContract ChainLink, Ltd.

interface IChainlinkAggregatorV3 {
    /// @notice represents the number of decimals the aggregator responses represent.
    function decimals() external view returns (uint8);

    function description() external view returns (string memory);

    function version() external view returns (uint256);

    function getRoundData(
        uint80 _roundId
    )
        external
        view
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

    function latestRoundData()
        external
        view
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

contracts/oracle/interfaces/iFluidCappedRate.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { IFluidOracle } from "./iFluidOracle.sol";

interface IFluidCappedRate is IFluidOracle {
    /// @notice Get the operate() exchange rate for debt asset side, with no cap upwards and capped decrease
    function getExchangeRateOperateDebt() external view returns (uint256 exchangeRate_);

    /// @notice Get the liquidate() exchange rate for debt asset side, with max APR cap upwards, and capped decrease
    function getExchangeRateLiquidateDebt() external view returns (uint256 exchangeRate_);

    /// @notice Retrieves the center price for use in a Fluid dex pool
    /// @dev This function is marked as non-constant (potentially state-changing) to allow flexibility in price fetching mechanisms.
    ///      While typically used as a read-only operation, this design permits write operations if needed for certain token pairs
    ///      (e.g., fetching up-to-date exchange rates that may require state changes).
    /// @return price_ The current price ratio of token1 to token0, expressed with 27 decimal places
    function centerPrice() external returns (uint256 price_);
}

contracts/oracle/interfaces/iFluidOracle.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

interface IFluidOracle {
    /// @dev Deprecated. Use `getExchangeRateOperate()` and `getExchangeRateLiquidate()` instead. Only implemented for
    ///      backwards compatibility.
    function getExchangeRate() external view returns (uint256 exchangeRate_);

    /// @notice Get the `exchangeRate_` between the underlying asset and the peg asset in 1e27 for operates
    function getExchangeRateOperate() external view returns (uint256 exchangeRate_);

    /// @notice Get the `exchangeRate_` between the underlying asset and the peg asset in 1e27 for liquidations
    function getExchangeRateLiquidate() external view returns (uint256 exchangeRate_);

    /// @notice helper string to easily identify the oracle. E.g. token symbols
    function infoName() external view returns (string memory);

    /// @notice target decimals of the returned oracle rate when scaling to 1e27. E.g. for ETH / USDC it would be 15
    /// because diff of ETH decimals to 1e27 is 9, and USDC has 6 decimals, so 6+9 = 15, e.g. 2029,047772120364926
    /// For USDC / ETH: 21 + 18 = 39, e.g. 0,000492842018675092636829357843847601646
    function targetDecimals() external view returns (uint8);
}

contracts/oracle/libraries/oracleUtils.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

/// @title Oracle utils library
/// @notice implements common utility methods for Fluid Oracles
library OracleUtils {
    /// @dev The scaler for max delta point math (100%)
    uint256 internal constant HUNDRED_PERCENT_DELTA_SCALER = 10_000;
    /// @dev output precision of rates
    uint256 internal constant RATE_OUTPUT_DECIMALS = 27;

    /// @dev checks if `mainSourceRate_` is within a `maxDeltaPercent_` of `checkSourceRate_`. Returns true if so.
    function isRateOutsideDelta(
        uint256 mainSourceRate_,
        uint256 checkSourceRate_,
        uint256 maxDeltaPercent_
    ) internal pure returns (bool) {
        uint256 offset_ = (checkSourceRate_ * maxDeltaPercent_) / HUNDRED_PERCENT_DELTA_SCALER;
        return (mainSourceRate_ > (checkSourceRate_ + offset_) || mainSourceRate_ < (checkSourceRate_ - offset_));
    }
}

contracts/oracle/oracles/genericOracleBase.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { ErrorTypes } from "../errorTypes.sol";
import { Error as OracleError } from "../error.sol";
import { ChainlinkSourceReader } from "../sourceReaders/chainlinkSourceReader.sol";
import { FluidSourceReader } from "../sourceReaders/fluidSourceReader.sol";
import { FluidDebtSourceReader } from "../sourceReaders/fluidDebtSourceReader.sol";
import { OracleUtils } from "../libraries/oracleUtils.sol";

abstract contract GenericOracleStructs {
    enum SourceType {
        Fluid, // 0, e.g. FluidCappedRate col asset side or some other IFluidOracle
        Redstone, // 1
        Chainlink, // 2
        UniV3Checked, // 3
        FluidDebt // 4 FluidCappedRate debt asset side methods
        // DO NOT add a rate source like ERC4626 here, any external contract source should ALWAYS be filtered through a FluidCappedRate contract
    }

    struct OracleHopSource {
        address source;
        bool invertRate;
        uint256 multiplier;
        uint256 divisor;
        SourceType sourceType; // e.g. FLUID, REDSTONE, UNIV3CHECKED, CHAINLINK
    }
}

/// @notice generic configurable Oracle Base
/// combines up to 4 hops from sources such as
///  - an existing IFluidOracle (e.g. ContractRate)
///  - Redstone
///  - Chainlink
abstract contract FluidGenericOracleBase is
    OracleError,
    GenericOracleStructs,
    ChainlinkSourceReader,
    FluidSourceReader,
    FluidDebtSourceReader
{
    address internal immutable _SOURCE1;
    bool internal immutable _SOURCE1_INVERT;
    uint256 internal immutable _SOURCE1_MULTIPLIER;
    uint256 internal immutable _SOURCE1_DIVISOR;
    SourceType internal immutable _SOURCE1_TYPE;

    address internal immutable _SOURCE2;
    bool internal immutable _SOURCE2_INVERT;
    uint256 internal immutable _SOURCE2_MULTIPLIER;
    uint256 internal immutable _SOURCE2_DIVISOR;
    SourceType internal immutable _SOURCE2_TYPE;

    address internal immutable _SOURCE3;
    bool internal immutable _SOURCE3_INVERT;
    uint256 internal immutable _SOURCE3_MULTIPLIER;
    uint256 internal immutable _SOURCE3_DIVISOR;
    SourceType internal immutable _SOURCE3_TYPE;

    address internal immutable _SOURCE4;
    bool internal immutable _SOURCE4_INVERT;
    uint256 internal immutable _SOURCE4_MULTIPLIER;
    uint256 internal immutable _SOURCE4_DIVISOR;
    SourceType internal immutable _SOURCE4_TYPE;

    address internal immutable _SOURCE5;
    bool internal immutable _SOURCE5_INVERT;
    uint256 internal immutable _SOURCE5_MULTIPLIER;
    uint256 internal immutable _SOURCE5_DIVISOR;
    SourceType internal immutable _SOURCE5_TYPE;

    constructor(OracleHopSource[] memory sources_) {
        if (sources_.length == 0 || sources_.length > 5) {
            revert FluidOracleError(ErrorTypes.GenericOracle__InvalidParams);
        }

        _verifyOracleHopSource(sources_[0]);
        _SOURCE1 = sources_[0].source;
        _SOURCE1_INVERT = sources_[0].invertRate;
        _SOURCE1_MULTIPLIER = sources_[0].multiplier;
        _SOURCE1_DIVISOR = sources_[0].divisor;
        _SOURCE1_TYPE = sources_[0].sourceType;

        if (sources_.length > 1) {
            _verifyOracleHopSource(sources_[1]);
            _SOURCE2 = sources_[1].source;
            _SOURCE2_INVERT = sources_[1].invertRate;
            _SOURCE2_MULTIPLIER = sources_[1].multiplier;
            _SOURCE2_DIVISOR = sources_[1].divisor;
            _SOURCE2_TYPE = sources_[1].sourceType;
        }

        if (sources_.length > 2) {
            _verifyOracleHopSource(sources_[2]);
            _SOURCE3 = sources_[2].source;
            _SOURCE3_INVERT = sources_[2].invertRate;
            _SOURCE3_MULTIPLIER = sources_[2].multiplier;
            _SOURCE3_DIVISOR = sources_[2].divisor;
            _SOURCE3_TYPE = sources_[2].sourceType;
        }

        if (sources_.length > 3) {
            _verifyOracleHopSource(sources_[3]);
            _SOURCE4 = sources_[3].source;
            _SOURCE4_INVERT = sources_[3].invertRate;
            _SOURCE4_MULTIPLIER = sources_[3].multiplier;
            _SOURCE4_DIVISOR = sources_[3].divisor;
            _SOURCE4_TYPE = sources_[3].sourceType;
        }

        if (sources_.length > 4) {
            _verifyOracleHopSource(sources_[4]);
            _SOURCE5 = sources_[4].source;
            _SOURCE5_INVERT = sources_[4].invertRate;
            _SOURCE5_MULTIPLIER = sources_[4].multiplier;
            _SOURCE5_DIVISOR = sources_[4].divisor;
            _SOURCE5_TYPE = sources_[4].sourceType;
        }
    }

    /// @dev verifies a hop source config
    function _verifyOracleHopSource(OracleHopSource memory source_) internal view virtual {
        if (
            address(source_.source) == address(0) ||
            source_.sourceType == SourceType.UniV3Checked ||
            source_.divisor == 0 ||
            source_.multiplier == 0 ||
            source_.divisor > 1e40 ||
            source_.multiplier > 1e40
        ) {
            revert FluidOracleError(ErrorTypes.GenericOracle__InvalidParams);
        }
    }

    /// @dev reads the exchange rate for a hop source
    function _readSource(
        address source_,
        SourceType sourceType_,
        bool isOperate_
    ) internal view virtual returns (uint256 rate_) {
        if (sourceType_ == SourceType.Redstone || sourceType_ == SourceType.Chainlink) {
            rate_ = _readChainlinkSource(source_);
        } else if (sourceType_ == SourceType.Fluid) {
            rate_ = _readFluidSource(source_, isOperate_);
        } else if (sourceType_ == SourceType.FluidDebt) {
            rate_ = _readFluidDebtSource(source_, isOperate_);
        } else {
            // should never happen because of config checks in constructor
            revert FluidOracleError(ErrorTypes.GenericOracle__UnexpectedConfig);
        }
    }

    /// @dev gets the exchange rate for a single configured hop
    function _getExchangeRateForHop(
        uint256 curHopsRate_,
        bool isOperate_,
        OracleHopSource memory source_
    ) internal view virtual returns (uint256 rate_) {
        rate_ = _readSource(source_.source, source_.sourceType, isOperate_);

        // scale to 1e27
        rate_ = (rate_ * source_.multiplier) / source_.divisor;

        if (source_.invertRate && rate_ > 0) {
            rate_ = (10 ** (OracleUtils.RATE_OUTPUT_DECIMALS * 2)) / uint256(rate_);
        }

        rate_ = (curHopsRate_ * rate_) / (10 ** OracleUtils.RATE_OUTPUT_DECIMALS); // combine with current hops rate
    }

    /// @dev gets the exchange rate combined for all configured hops
    function _getHopsExchangeRate(bool isOperate_) internal view returns (uint256 rate_) {
        rate_ = _getExchangeRateForHop(
            (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
            isOperate_,
            OracleHopSource(_SOURCE1, _SOURCE1_INVERT, _SOURCE1_MULTIPLIER, _SOURCE1_DIVISOR, _SOURCE1_TYPE)
        );
        if (rate_ == 0) {
            revert FluidOracleError(ErrorTypes.GenericOracle__RateZero);
        }
        if (address(_SOURCE2) == address(0) && _SOURCE2_TYPE != SourceType.UniV3Checked) {
            return rate_;
        }

        // 2 hops -> return rate of hop 1 combined with hop 2
        rate_ = _getExchangeRateForHop(
            rate_,
            isOperate_,
            OracleHopSource(_SOURCE2, _SOURCE2_INVERT, _SOURCE2_MULTIPLIER, _SOURCE2_DIVISOR, _SOURCE2_TYPE)
        );
        if (rate_ == 0) {
            revert FluidOracleError(ErrorTypes.GenericOracle__RateZero);
        }
        if (address(_SOURCE3) == address(0) && _SOURCE3_TYPE != SourceType.UniV3Checked) {
            return rate_;
        }

        // 3 hops -> return rate of hop 1 combined with hop 2 & hop 3
        rate_ = _getExchangeRateForHop(
            rate_,
            isOperate_,
            OracleHopSource(_SOURCE3, _SOURCE3_INVERT, _SOURCE3_MULTIPLIER, _SOURCE3_DIVISOR, _SOURCE3_TYPE)
        );
        if (rate_ == 0) {
            revert FluidOracleError(ErrorTypes.GenericOracle__RateZero);
        }
        if (address(_SOURCE4) == address(0) && _SOURCE4_TYPE != SourceType.UniV3Checked) {
            return rate_;
        }

        // 4 hops -> return rate of hop 1 combined with hop 2, hop 3 & hop 4
        rate_ = _getExchangeRateForHop(
            rate_,
            isOperate_,
            OracleHopSource(_SOURCE4, _SOURCE4_INVERT, _SOURCE4_MULTIPLIER, _SOURCE4_DIVISOR, _SOURCE4_TYPE)
        );
        if (rate_ == 0) {
            revert FluidOracleError(ErrorTypes.GenericOracle__RateZero);
        }
        if (address(_SOURCE5) == address(0) && _SOURCE5_TYPE != SourceType.UniV3Checked) {
            return rate_;
        }

        // 5 hops -> return rate of hop 1 combined with hop 2, hop 3, hop 4 & hop 5
        rate_ = _getExchangeRateForHop(
            rate_,
            isOperate_,
            OracleHopSource(_SOURCE5, _SOURCE5_INVERT, _SOURCE5_MULTIPLIER, _SOURCE5_DIVISOR, _SOURCE5_TYPE)
        );
        if (rate_ == 0) {
            revert FluidOracleError(ErrorTypes.GenericOracle__RateZero);
        }
    }

    /// @notice Returns the exchange rate for each hop.
    /// @return rateSource1Operate_ The exchange rate for hop 1 during operate.
    /// @return rateSource1Liquidate_ The exchange rate for hop 1 during liquidate.
    /// @return rateSource2Operate_ The exchange rate for hop 2 during operate.
    /// @return rateSource2Liquidate_ The exchange rate for hop 2 during liquidate.
    /// @return rateSource3Operate_ The exchange rate for hop 3 during operate.
    /// @return rateSource3Liquidate_ The exchange rate for hop 3 during liquidate.
    /// @return rateSource4Operate_ The exchange rate for hop 4 during operate.
    /// @return rateSource4Liquidate_ The exchange rate for hop 4 during liquidate.
    /// @return rateSource5Operate_ The exchange rate for hop 5 during operate.
    /// @return rateSource5Liquidate_ The exchange rate for hop 5 during liquidate.
    function getHopExchangeRates()
        public
        view
        returns (
            uint256 rateSource1Operate_,
            uint256 rateSource1Liquidate_,
            uint256 rateSource2Operate_,
            uint256 rateSource2Liquidate_,
            uint256 rateSource3Operate_,
            uint256 rateSource3Liquidate_,
            uint256 rateSource4Operate_,
            uint256 rateSource4Liquidate_,
            uint256 rateSource5Operate_,
            uint256 rateSource5Liquidate_
        )
    {
        rateSource1Operate_ = _getExchangeRateForHop(
            (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
            true,
            OracleHopSource(_SOURCE1, _SOURCE1_INVERT, _SOURCE1_MULTIPLIER, _SOURCE1_DIVISOR, _SOURCE1_TYPE)
        );
        rateSource1Liquidate_ = _getExchangeRateForHop(
            (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
            false,
            OracleHopSource(_SOURCE1, _SOURCE1_INVERT, _SOURCE1_MULTIPLIER, _SOURCE1_DIVISOR, _SOURCE1_TYPE)
        );

        if (address(_SOURCE2) != address(0) || _SOURCE2_TYPE == SourceType.UniV3Checked) {
            rateSource2Operate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                true,
                OracleHopSource(_SOURCE2, _SOURCE2_INVERT, _SOURCE2_MULTIPLIER, _SOURCE2_DIVISOR, _SOURCE2_TYPE)
            );
            rateSource2Liquidate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                false,
                OracleHopSource(_SOURCE2, _SOURCE2_INVERT, _SOURCE2_MULTIPLIER, _SOURCE2_DIVISOR, _SOURCE2_TYPE)
            );
        }

        if (address(_SOURCE3) != address(0) || _SOURCE3_TYPE == SourceType.UniV3Checked) {
            rateSource3Operate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                true,
                OracleHopSource(_SOURCE3, _SOURCE3_INVERT, _SOURCE3_MULTIPLIER, _SOURCE3_DIVISOR, _SOURCE3_TYPE)
            );
            rateSource3Liquidate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                false,
                OracleHopSource(_SOURCE3, _SOURCE3_INVERT, _SOURCE3_MULTIPLIER, _SOURCE3_DIVISOR, _SOURCE3_TYPE)
            );
        }

        if (address(_SOURCE4) != address(0) || _SOURCE4_TYPE == SourceType.UniV3Checked) {
            rateSource4Operate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                true,
                OracleHopSource(_SOURCE4, _SOURCE4_INVERT, _SOURCE4_MULTIPLIER, _SOURCE4_DIVISOR, _SOURCE4_TYPE)
            );
            rateSource4Liquidate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                false,
                OracleHopSource(_SOURCE4, _SOURCE4_INVERT, _SOURCE4_MULTIPLIER, _SOURCE4_DIVISOR, _SOURCE4_TYPE)
            );
        }

        if (address(_SOURCE5) != address(0) || _SOURCE5_TYPE == SourceType.UniV3Checked) {
            rateSource5Operate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                true,
                OracleHopSource(_SOURCE5, _SOURCE5_INVERT, _SOURCE5_MULTIPLIER, _SOURCE5_DIVISOR, _SOURCE5_TYPE)
            );
            rateSource5Liquidate_ = _getExchangeRateForHop(
                (10 ** OracleUtils.RATE_OUTPUT_DECIMALS),
                false,
                OracleHopSource(_SOURCE5, _SOURCE5_INVERT, _SOURCE5_MULTIPLIER, _SOURCE5_DIVISOR, _SOURCE5_TYPE)
            );
        }
    }

    /// @notice Returns the configured OracleHopSources
    function getOracleHopSources() public view returns (OracleHopSource[] memory sources_) {
        sources_ = new OracleHopSource[](5);
        sources_[0] = OracleHopSource(_SOURCE1, _SOURCE1_INVERT, _SOURCE1_MULTIPLIER, _SOURCE1_DIVISOR, _SOURCE1_TYPE);
        sources_[1] = OracleHopSource(_SOURCE2, _SOURCE2_INVERT, _SOURCE2_MULTIPLIER, _SOURCE2_DIVISOR, _SOURCE2_TYPE);
        sources_[2] = OracleHopSource(_SOURCE3, _SOURCE3_INVERT, _SOURCE3_MULTIPLIER, _SOURCE3_DIVISOR, _SOURCE3_TYPE);
        sources_[3] = OracleHopSource(_SOURCE4, _SOURCE4_INVERT, _SOURCE4_MULTIPLIER, _SOURCE4_DIVISOR, _SOURCE4_TYPE);
        sources_[4] = OracleHopSource(_SOURCE5, _SOURCE5_INVERT, _SOURCE5_MULTIPLIER, _SOURCE5_DIVISOR, _SOURCE5_TYPE);
    }
}

contracts/oracle/sourceReaders/chainlinkSourceReader.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { IChainlinkAggregatorV3 } from "../interfaces/external/IChainlinkAggregatorV3.sol";

abstract contract ChainlinkSourceReader {
    function _readChainlinkSource(address feed_) internal view returns (uint256 rate_) {
        try IChainlinkAggregatorV3(feed_).latestRoundData() returns (
            uint80,
            int256 exchangeRate_,
            uint256,
            uint256,
            uint80
        ) {
            // Return the price in `OracleUtils.RATE_OUTPUT_DECIMALS`
            return uint256(exchangeRate_);
        } catch {}
    }
}

contracts/oracle/sourceReaders/fluidDebtSourceReader.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { IFluidCappedRate } from "../interfaces/iFluidCappedRate.sol";

abstract contract FluidDebtSourceReader {
    function _readFluidDebtSource(address oracle_, bool isOperate_) internal view returns (uint256 rate_) {
        if (isOperate_) {
            try IFluidCappedRate(oracle_).getExchangeRateOperateDebt() returns (uint256 exchangeRate_) {
                return exchangeRate_;
            } catch {}
        } else {
            try IFluidCappedRate(oracle_).getExchangeRateLiquidateDebt() returns (uint256 exchangeRate_) {
                return exchangeRate_;
            } catch {}
        }
    }
}

contracts/oracle/sourceReaders/fluidSourceReader.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { IFluidOracle } from "../interfaces/iFluidOracle.sol";

abstract contract FluidSourceReader {
    function _readFluidSource(address oracle_, bool isOperate_) internal view returns (uint256 rate_) {
        if (isOperate_) {
            try IFluidOracle(oracle_).getExchangeRateOperate() returns (uint256 exchangeRate_) {
                return exchangeRate_;
            } catch {}
        } else {
            try IFluidOracle(oracle_).getExchangeRateLiquidate() returns (uint256 exchangeRate_) {
                return exchangeRate_;
            } catch {}
        }
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 10000000,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.