MATIC Price: $0.70 (-0.12%)
Gas: 144 GWei
 

Overview

MATIC Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 MATIC

MATIC Value

$0.00

Sponsored

Transaction Hash
Method
Block
From
To
Value
Add Asset For Re...319934912022-08-17 11:09:50607 days ago1660734590IN
0xBa116c6f...cDD1455C7
0 MATIC0.0074728100
Add Asset For Re...319934782022-08-17 11:09:24607 days ago1660734564IN
0xBa116c6f...cDD1455C7
0 MATIC0.0091828100
Add Quote Assets...319934722022-08-17 11:09:12607 days ago1660734552IN
0xBa116c6f...cDD1455C7
0 MATIC0.0074781100
Add Quote Assets...319934642022-08-17 11:08:52607 days ago1660734532IN
0xBa116c6f...cDD1455C7
0 MATIC0.0074781100
Add Quote Assets...319934592022-08-17 11:08:42607 days ago1660734522IN
0xBa116c6f...cDD1455C7
0 MATIC0.0091881100
Add Signed Price...319934532022-08-17 11:08:30607 days ago1660734510IN
0xBa116c6f...cDD1455C7
0 MATIC0.0091904100
0x60a06040319933812022-08-17 11:05:10607 days ago1660734310IN
 Create: CheckedPriceOracle
0 MATIC0.1971071100

Parent Txn Hash Block From To Value
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CheckedPriceOracle

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Unlicense license
File 1 of 16 : CheckedPriceOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "Math.sol";
import "SafeCast.sol";
import "EnumerableSet.sol";

import "IUSDPriceOracle.sol";
import "IRelativePriceOracle.sol";
import "IUSDBatchPriceOracle.sol";
import "EnumerableExtensions.sol";

import "Governable.sol";

import "Errors.sol";
import "FixedPoint.sol";

contract CheckedPriceOracle is IUSDBatchPriceOracle, Governable {
    using EnumerableSet for EnumerableSet.AddressSet;

    using FixedPoint for uint256;
    using SafeCast for uint256;
    using SafeCast for int256;

    uint256 public constant MAX_ABSOLUTE_WETH_DEVIATION = 50e18;
    uint256 public constant INITIAL_RELATIVE_EPSILON = 0.02e18;
    uint256 public constant MAX_RELATIVE_EPSILON = 0.1e18;

    address public immutable wethAddress;

    IUSDPriceOracle public usdOracle;
    IRelativePriceOracle public relativeOracle;

    uint256 public relativeEpsilon;

    EnumerableSet.AddressSet internal trustedSignerPriceOracles;

    /// This list is going to be used for the twaps to be input into the price level checks.
    /// These are the addresses of the assets to be paired with ETH e.g. USDC or USDT
    EnumerableSet.AddressSet internal quoteAssetsForPriceLevelTWAPS;

    /// @dev This list is used to check if the relative price of the tokens are consistent
    EnumerableSet.AddressSet internal assetsForRelativePriceCheck;

    event USDOracleUpdated(address indexed oracle);
    event RelativeOracleUpdated(address indexed oracle);

    event PriceLevelTWAPQuoteAssetAdded(address _addressToAdd);
    event PriceLevelTWAPQuoteAssetRemoved(address _addressToRemove);

    event AssetForRelativePriceCheckAdded(address _addressToAdd);
    event AssetForRelativePriceCheckRemoved(address _addressToRemove);

    event TrustedSignerOracleAdded(address _addressToAdd);
    event TrustedSignerOracleRemoved(address _addressToRemove);

    /// _usdOracle is for Chainlink
    constructor(
        address _usdOracle,
        address _relativeOracle,
        address _wethAddress
    ) {
        require(_usdOracle != address(0), Errors.INVALID_ARGUMENT);
        require(_relativeOracle != address(0), Errors.INVALID_ARGUMENT);
        usdOracle = IUSDPriceOracle(_usdOracle);
        relativeOracle = IRelativePriceOracle(_relativeOracle);
        relativeEpsilon = INITIAL_RELATIVE_EPSILON;
        wethAddress = _wethAddress;
    }

    function setUSDOracle(address _usdOracle) external governanceOnly {
        usdOracle = IUSDPriceOracle(_usdOracle);
        emit USDOracleUpdated(_usdOracle);
    }

    function setRelativeOracle(address _relativeOracle) external governanceOnly {
        relativeOracle = IRelativePriceOracle(_relativeOracle);
        emit RelativeOracleUpdated(_relativeOracle);
    }

    function addSignedPriceSource(address _signedAssetToAdd) external governanceOnly {
        trustedSignerPriceOracles.add(_signedAssetToAdd);
        emit TrustedSignerOracleAdded(_signedAssetToAdd);
    }

    function removeSignedPriceSource(address _signedAssetToRemove) external governanceOnly {
        trustedSignerPriceOracles.remove(_signedAssetToRemove);
        emit TrustedSignerOracleRemoved(_signedAssetToRemove);
    }

    function listSignedPriceSource() external view returns (address[] memory) {
        return trustedSignerPriceOracles.values();
    }

    function addQuoteAssetsForPriceLevelTwap(address _quoteAssetToAdd) external governanceOnly {
        quoteAssetsForPriceLevelTWAPS.add(_quoteAssetToAdd);
        emit PriceLevelTWAPQuoteAssetAdded(_quoteAssetToAdd);
    }

    function listQuoteAssetsForPriceLevelTwap() external view returns (address[] memory) {
        return quoteAssetsForPriceLevelTWAPS.values();
    }

    function removeQuoteAssetsForPriceLevelTwap(address _quoteAssetToRemove)
        external
        governanceOnly
    {
        quoteAssetsForPriceLevelTWAPS.remove(_quoteAssetToRemove);
        emit PriceLevelTWAPQuoteAssetRemoved(_quoteAssetToRemove);
    }

    function addAssetForRelativePriceCheck(address assetToAdd) external governanceOnly {
        assetsForRelativePriceCheck.add(assetToAdd);
        emit AssetForRelativePriceCheckAdded(assetToAdd);
    }

    function listAssetForRelativePriceCheck() external view returns (address[] memory) {
        return assetsForRelativePriceCheck.values();
    }

    function removeAssetForRelativePriceCheck(address assetToRemove) external governanceOnly {
        assetsForRelativePriceCheck.remove(assetToRemove);
        emit AssetForRelativePriceCheckRemoved(assetToRemove);
    }

    function batchRelativePriceCheck(address[] memory tokenAddresses, uint256[] memory prices)
        internal
        view
        returns (uint256[] memory)
    {
        uint256[] memory priceLevelTwaps = new uint256[](quoteAssetsForPriceLevelTWAPS.length());

        uint256 k;
        for (uint256 i = 0; i < tokenAddresses.length; i++) {
            bool couldCheck = false;

            for (uint256 j = 0; j < assetsForRelativePriceCheck.length(); j++) {
                address assetForCheck = assetsForRelativePriceCheck.at(j);
                if (
                    tokenAddresses[i] == assetForCheck ||
                    !relativeOracle.isPairSupported(tokenAddresses[i], assetForCheck)
                ) {
                    continue;
                }

                uint256 relativePrice = relativeOracle.getRelativePrice(
                    tokenAddresses[i],
                    assetForCheck
                );

                if (
                    tokenAddresses[i] == wethAddress &&
                    quoteAssetsForPriceLevelTWAPS.contains(assetForCheck)
                ) {
                    priceLevelTwaps[k] = relativePrice;
                    k++;
                } else if (
                    assetForCheck == wethAddress &&
                    quoteAssetsForPriceLevelTWAPS.contains(tokenAddresses[i])
                ) {
                    priceLevelTwaps[k] = FixedPoint.ONE.divDown(relativePrice);
                    k++;
                }

                uint256 assetForCheckPrice = _findPrice(assetForCheck, tokenAddresses, prices);
                _ensureRelativePriceConsistency(prices[i], assetForCheckPrice, relativePrice);

                couldCheck = true;
                break;
            }

            require(couldCheck, Errors.ASSET_NOT_SUPPORTED);
        }

        uint256[] memory foundTwaps = new uint256[](k);
        for (uint256 i = 0; i < k; i++) {
            foundTwaps[i] = priceLevelTwaps[i];
        }

        return foundTwaps;
    }

    //NB this is expected to be queried for ALL asset prices in the reserve
    /// @inheritdoc IUSDBatchPriceOracle
    function getPricesUSD(address[] memory tokenAddresses)
        public
        view
        override
        returns (uint256[] memory)
    {
        require(tokenAddresses.length > 0, Errors.INVALID_ARGUMENT);

        uint256[] memory prices = new uint256[](tokenAddresses.length);

        /// Will start with this being the WETH/USD price, this can be modified later if desired.
        uint256 priceLevel;

        for (uint256 i = 0; i < tokenAddresses.length; i++) {
            prices[i] = usdOracle.getPriceUSD(tokenAddresses[i]);
            if (tokenAddresses[i] == wethAddress) {
                priceLevel = prices[i];
            }
        }

        if (priceLevel == 0) {
            priceLevel = usdOracle.getPriceUSD(wethAddress);
        }

        uint256[] memory priceLevelTwaps = batchRelativePriceCheck(tokenAddresses, prices);

        uint256 numberOfTrustedSignerOracles = trustedSignerPriceOracles.length();
        uint256[] memory signedPrices = new uint256[](numberOfTrustedSignerOracles);

        for (uint256 i = 0; i < numberOfTrustedSignerOracles; i++) {
            IUSDPriceOracle oracle = IUSDPriceOracle(trustedSignerPriceOracles.at(i));
            signedPrices[i] = oracle.getPriceUSD(wethAddress);
        }

        _checkPriceLevel(priceLevel, signedPrices, priceLevelTwaps);

        return prices;
    }

    function setRelativeMaxEpsilon(uint256 _relativeEpsilon) external governanceOnly {
        require(_relativeEpsilon > 0, Errors.INVALID_ARGUMENT);
        require(_relativeEpsilon < MAX_RELATIVE_EPSILON, Errors.INVALID_ARGUMENT);

        relativeEpsilon = _relativeEpsilon;
    }

    function _checkPriceLevel(
        uint256 priceLevel,
        uint256[] memory signedPrices,
        uint256[] memory priceLevelTwaps
    ) internal view {
        uint256 trueWETH = getRobustWETHPrice(signedPrices, priceLevelTwaps);
        uint256 absolutePriceDifference = priceLevel.absSub(trueWETH);
        require(
            absolutePriceDifference <= MAX_ABSOLUTE_WETH_DEVIATION,
            Errors.ROOT_PRICE_NOT_GROUNDED
        );
    }

    function _ensureRelativePriceConsistency(
        uint256 aUSDPrice,
        uint256 bUSDPrice,
        uint256 abPrice
    ) internal view {
        uint256 abPriceFromUSD = aUSDPrice.divDown(bUSDPrice);
        uint256 priceDifference = abPrice.absSub(abPriceFromUSD);
        uint256 relativePriceDifference = priceDifference.divDown(abPrice);

        require(relativePriceDifference <= relativeEpsilon, Errors.STALE_PRICE);
    }

    function _computeMinOrSecondMin(uint256[] memory twapPrices) internal pure returns (uint256) {
        // min if there are two, or the 2nd min if more than two
        uint256 min = twapPrices[0];
        uint256 secondMin = 2**256 - 1;
        for (uint256 i = 1; i < twapPrices.length; i++) {
            if (twapPrices[i] < min) {
                secondMin = min;
                min = twapPrices[i];
            } else if ((twapPrices[i] < secondMin)) {
                secondMin = twapPrices[i];
            }
        }
        if (twapPrices.length == 1) {
            return twapPrices[0];
        } else if (twapPrices.length == 2) {
            return min;
        } else {
            return secondMin;
        }
    }

    function _findPrice(
        address target,
        address[] memory tokenAddresses,
        uint256[] memory prices
    ) internal view returns (uint256) {
        for (uint256 i = 0; i < tokenAddresses.length; i++) {
            if (tokenAddresses[i] == target) {
                return prices[i];
            }
        }
        return usdOracle.getPriceUSD(target);
    }

    function _sort(uint256[] memory data) internal view returns (uint256[] memory) {
        _quickSort(data, int256(0), int256(data.length - 1));
        return data;
    }

    function _quickSort(
        uint256[] memory arr,
        int256 left,
        int256 right
    ) internal view {
        int256 i = left;
        int256 j = right;
        if (i == j) return;
        uint256 pivot = arr[uint256(left + (right - left) / 2)];
        while (i <= j) {
            while (arr[uint256(i)] < pivot) i++;
            while (pivot < arr[uint256(j)]) j--;
            if (i <= j) {
                (arr[uint256(i)], arr[uint256(j)]) = (arr[uint256(j)], arr[uint256(i)]);
                i++;
                j--;
            }
        }
        if (left < j) _quickSort(arr, left, j);
        if (i < right) _quickSort(arr, i, right);
    }

    function _median(uint256[] memory array) internal view returns (uint256) {
        _sort(array);
        return
            array.length % 2 == 0
                ? Math.average(array[array.length / 2 - 1], array[array.length / 2])
                : array[array.length / 2];
    }

    /// @notice this function provides an estimate of the true WETH price.
    /// 1. Find the minimum TWAP price (or second minumum if >2 TWAP prices) from a given array.
    /// 2. Add this to an array of signed prices
    /// 3. Compute the median of this array
    /// @param signedPrices an array of prices from trusted providers (e.g. Chainlink, Coinbase, OKEx ETH/USD price)
    /// @param twapPrices an array of Time Weighted Moving Average ETH/stablecoin prices
    function getRobustWETHPrice(uint256[] memory signedPrices, uint256[] memory twapPrices)
        public
        view
        returns (uint256)
    {
        uint256 minTWAP;
        if (twapPrices.length == 0) {
            return _median(signedPrices);
        } else {
            minTWAP = _computeMinOrSecondMin(twapPrices);
            uint256[] memory prices = new uint256[](signedPrices.length + 1);
            prices[prices.length - 1] = minTWAP;
            for (uint256 i = 0; i < prices.length - 1; i++) {
                prices[i] = signedPrices[i];
            }
            return _median(prices);
        }
    }
}

File 2 of 16 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a / b + (a % b == 0 ? 0 : 1);
    }
}

File 2 of 16 : SafeCast.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 2 of 16 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastvalue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastvalue;
                // Update the index for the moved value
                set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}

File 2 of 16 : IUSDPriceOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IUSDPriceOracle {
    /// @notice Quotes the USD price of `tokenAddress`
    /// The quoted price is always scaled with 18 decimals regardless of the
    /// source used for the oracle.
    /// @param tokenAddress the asset of which the price is to be quoted
    /// @return the USD price of the asset
    function getPriceUSD(address tokenAddress) external view returns (uint256);
}

File 2 of 16 : IRelativePriceOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IRelativePriceOracle {
    /// @notice Quotes the price of `baseToken` relative to `quoteToken`
    /// The quoted price is always scaled with 18 decimals regardless of the
    /// source used for the oracle.
    /// @param baseToken the token of which the price is to be quoted
    /// @param quoteToken the token used to denominate the price
    /// @return the number of units of quote token per base token
    function getRelativePrice(address baseToken, address quoteToken)
        external
        view
        returns (uint256);

    /// @notice Returns whether the oracle currently supports prices
    /// for `baseToken` relative to `quoteToken`
    function isPairSupported(address baseToken, address quoteToken) external view returns (bool);
}

File 2 of 16 : IUSDBatchPriceOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IUSDBatchPriceOracle {
    /// @notice Quotes the USD price of `baseAssets`
    /// The quoted prices is always scaled with 18 decimals regardless of the
    /// source used for the oracle.
    /// @param baseAssets the assets of which the price is to be quoted
    /// @return the USD prices of the asset
    function getPricesUSD(address[] memory baseAssets) external view returns (uint256[] memory);
}

File 2 of 16 : EnumerableExtensions.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "EnumerableSet.sol";
import "EnumerableMap.sol";
import "EnumerableMapping.sol";

library EnumerableExtensions {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.Bytes32Set;
    using EnumerableMap for EnumerableMap.UintToAddressMap;
    using EnumerableMapping for EnumerableMapping.AddressToAddressMap;
    using EnumerableMapping for EnumerableMapping.AddressToUintMap;

    // AddressSet

    function toArray(EnumerableSet.AddressSet storage addresses)
        internal
        view
        returns (address[] memory)
    {
        uint256 len = addresses.length();
        address[] memory result = new address[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = addresses.at(i);
        }
        return result;
    }

    // Bytes32Set

    function toArray(EnumerableSet.Bytes32Set storage values)
        internal
        view
        returns (bytes32[] memory)
    {
        uint256 len = values.length();
        bytes32[] memory result = new bytes32[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = values.at(i);
        }
        return result;
    }

    // AddressToAddressMap

    function keyAt(EnumerableMapping.AddressToAddressMap storage map, uint256 index)
        internal
        view
        returns (address)
    {
        (address key, ) = map.at(index);
        return key;
    }

    function valueAt(EnumerableMapping.AddressToAddressMap storage map, uint256 index)
        internal
        view
        returns (address)
    {
        (, address value) = map.at(index);
        return value;
    }

    function keysArray(EnumerableMapping.AddressToAddressMap storage map)
        internal
        view
        returns (address[] memory)
    {
        uint256 len = map.length();
        address[] memory result = new address[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = keyAt(map, i);
        }
        return result;
    }

    function valuesArray(EnumerableMapping.AddressToAddressMap storage map)
        internal
        view
        returns (address[] memory)
    {
        uint256 len = map.length();
        address[] memory result = new address[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = valueAt(map, i);
        }
        return result;
    }

    // AddressToUintMap

    function keyAt(EnumerableMapping.AddressToUintMap storage map, uint256 index)
        internal
        view
        returns (address)
    {
        (address key, ) = map.at(index);
        return key;
    }

    function valueAt(EnumerableMapping.AddressToUintMap storage map, uint256 index)
        internal
        view
        returns (uint256)
    {
        (, uint256 value) = map.at(index);
        return value;
    }

    function keysArray(EnumerableMapping.AddressToUintMap storage map)
        internal
        view
        returns (address[] memory)
    {
        uint256 len = map.length();
        address[] memory result = new address[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = keyAt(map, i);
        }
        return result;
    }

    function valuesArray(EnumerableMapping.AddressToUintMap storage map)
        internal
        view
        returns (uint256[] memory)
    {
        uint256 len = map.length();
        uint256[] memory result = new uint256[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = valueAt(map, i);
        }
        return result;
    }

    // EnumerableMap.UintToAddressMap

    function valueAt(EnumerableMap.UintToAddressMap storage map, uint256 index)
        internal
        view
        returns (address)
    {
        (, address value) = map.at(index);
        return value;
    }

    function valuesArray(EnumerableMap.UintToAddressMap storage map)
        internal
        view
        returns (address[] memory)
    {
        uint256 len = map.length();
        address[] memory result = new address[](len);
        for (uint256 i = 0; i < len; i++) {
            result[i] = valueAt(map, i);
        }
        return result;
    }
}

File 2 of 16 : EnumerableMap.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "EnumerableSet.sol";

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
 * supported.
 */
library EnumerableMap {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct Map {
        // Storage of keys
        EnumerableSet.Bytes32Set _keys;
        mapping(bytes32 => bytes32) _values;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function _set(
        Map storage map,
        bytes32 key,
        bytes32 value
    ) private returns (bool) {
        map._values[key] = value;
        return map._keys.add(key);
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function _remove(Map storage map, bytes32 key) private returns (bool) {
        delete map._values[key];
        return map._keys.remove(key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function _contains(Map storage map, bytes32 key) private view returns (bool) {
        return map._keys.contains(key);
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function _length(Map storage map) private view returns (uint256) {
        return map._keys.length();
    }

    /**
     * @dev Returns the key-value pair stored at position `index` in the map. O(1).
     *
     * Note that there are no guarantees on the ordering of entries inside the
     * array, and it may change when more entries are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
        bytes32 key = map._keys.at(index);
        return (key, map._values[key]);
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
        bytes32 value = map._values[key];
        if (value == bytes32(0)) {
            return (_contains(map, key), bytes32(0));
        } else {
            return (true, value);
        }
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function _get(Map storage map, bytes32 key) private view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || _contains(map, key), "EnumerableMap: nonexistent key");
        return value;
    }

    /**
     * @dev Same as {_get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {_tryGet}.
     */
    function _get(
        Map storage map,
        bytes32 key,
        string memory errorMessage
    ) private view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || _contains(map, key), errorMessage);
        return value;
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        UintToAddressMap storage map,
        uint256 key,
        address value
    ) internal returns (bool) {
        return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
        return _remove(map._inner, bytes32(key));
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
        return _contains(map._inner, bytes32(key));
    }

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToAddressMap storage map) internal view returns (uint256) {
        return _length(map._inner);
    }

    /**
     * @dev Returns the element stored at position `index` in the set. O(1).
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (uint256(key), address(uint160(uint256(value))));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        UintToAddressMap storage map,
        uint256 key,
        string memory errorMessage
    ) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
    }
}

File 2 of 16 : EnumerableMapping.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "EnumerableSet.sol";

library EnumerableMapping {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // Code take from contracts/utils/structs/EnumerableMap.sol
    // because the helper functions are private

    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct Map {
        // Storage of keys
        EnumerableSet.Bytes32Set _keys;
        mapping(bytes32 => bytes32) _values;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function _set(
        Map storage map,
        bytes32 key,
        bytes32 value
    ) private returns (bool) {
        map._values[key] = value;
        return map._keys.add(key);
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function _remove(Map storage map, bytes32 key) private returns (bool) {
        delete map._values[key];
        return map._keys.remove(key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function _contains(Map storage map, bytes32 key) private view returns (bool) {
        return map._keys.contains(key);
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function _length(Map storage map) private view returns (uint256) {
        return map._keys.length();
    }

    /**
     * @dev Returns the key-value pair stored at position `index` in the map. O(1).
     *
     * Note that there are no guarantees on the ordering of entries inside the
     * array, and it may change when more entries are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
        bytes32 key = map._keys.at(index);
        return (key, map._values[key]);
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
        bytes32 value = map._values[key];
        if (value == bytes32(0)) {
            return (_contains(map, key), bytes32(0));
        } else {
            return (true, value);
        }
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function _get(Map storage map, bytes32 key) private view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || _contains(map, key), "EnumerableMap: nonexistent key");
        return value;
    }

    // AddressToAddressMap

    struct AddressToAddressMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        AddressToAddressMap storage map,
        address key,
        address value
    ) internal returns (bool) {
        return _set(map._inner, bytes32(uint256(uint160(key))), bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(AddressToAddressMap storage map, address key) internal returns (bool) {
        return _remove(map._inner, bytes32(uint256(uint160(key))));
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(AddressToAddressMap storage map, address key) internal view returns (bool) {
        return _contains(map._inner, bytes32(uint256(uint160(key))));
    }

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(AddressToAddressMap storage map) internal view returns (uint256) {
        return _length(map._inner);
    }

    /**
     * @dev Returns the element stored at position `index` in the set. O(1).
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressToAddressMap storage map, uint256 index)
        internal
        view
        returns (address, address)
    {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (address(uint160(uint256(key))), address(uint160(uint256(value))));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(AddressToAddressMap storage map, address key)
        internal
        view
        returns (bool, address)
    {
        (bool success, bytes32 value) = _tryGet(map._inner, bytes32(uint256(uint160(key))));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(AddressToAddressMap storage map, address key) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(uint256(uint160(key)))))));
    }

    // AddressToUintMap

    struct AddressToUintMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        AddressToUintMap storage map,
        address key,
        uint256 value
    ) internal returns (bool) {
        return _set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(AddressToUintMap storage map, address key) internal returns (bool) {
        return _remove(map._inner, bytes32(uint256(uint160(key))));
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
        return _contains(map._inner, bytes32(uint256(uint160(key))));
    }

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(AddressToUintMap storage map) internal view returns (uint256) {
        return _length(map._inner);
    }

    /**
     * @dev Returns the element stored at position `index` in the set. O(1).
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressToUintMap storage map, uint256 index)
        internal
        view
        returns (address, uint256)
    {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (address(uint160(uint256(key))), uint256(value));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(AddressToUintMap storage map, address key)
        internal
        view
        returns (bool, uint256)
    {
        (bool success, bytes32 value) = _tryGet(map._inner, bytes32(uint256(uint160(key))));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
        return uint256(_get(map._inner, bytes32(uint256(uint160(key)))));
    }

    // Bytes32ToUIntMap

    struct Bytes32ToUIntMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        Bytes32ToUIntMap storage map,
        bytes32 key,
        uint256 value
    ) internal returns (bool) {
        return _set(map._inner, key, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Bytes32ToUIntMap storage map, bytes32 key) internal returns (bool) {
        return _remove(map._inner, key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Bytes32ToUIntMap storage map, bytes32 key) internal view returns (bool) {
        return _contains(map._inner, key);
    }

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(Bytes32ToUIntMap storage map) internal view returns (uint256) {
        return _length(map._inner);
    }

    /**
     * @dev Returns the element stored at position `index` in the set. O(1).
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32ToUIntMap storage map, uint256 index)
        internal
        view
        returns (bytes32, uint256)
    {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (key, uint256(value));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(Bytes32ToUIntMap storage map, bytes32 key)
        internal
        view
        returns (bool, uint256)
    {
        (bool success, bytes32 value) = _tryGet(map._inner, key);
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToUIntMap storage map, bytes32 key) internal view returns (uint256) {
        return uint256(_get(map._inner, key));
    }
}

File 2 of 16 : Governable.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "GovernableBase.sol";

contract Governable is GovernableBase {
    constructor() {
        governor = msg.sender;
        emit GovernorChanged(address(0), msg.sender);
    }
}

File 2 of 16 : GovernableBase.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "Errors.sol";
import "IGovernable.sol";

contract GovernableBase is IGovernable {
    address public override governor;
    address public override pendingGovernor;

    modifier governanceOnly() {
        require(msg.sender == governor, Errors.NOT_AUTHORIZED);
        _;
    }

    /// @inheritdoc IGovernable
    function changeGovernor(address newGovernor) external override governanceOnly {
        require(address(newGovernor) != address(0), Errors.INVALID_ARGUMENT);
        pendingGovernor = newGovernor;
        emit GovernorChangeRequested(newGovernor);
    }

    /// @inheritdoc IGovernable
    function acceptGovernance() external override {
        require(msg.sender == pendingGovernor, Errors.NOT_AUTHORIZED);
        address currentGovernor = governor;
        governor = pendingGovernor;
        pendingGovernor = address(0);
        emit GovernorChanged(currentGovernor, msg.sender);
    }
}

File 2 of 16 : Errors.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

/// @notice Defines different errors emitted by Gyroscope contracts
library Errors {
    string public constant TOKEN_AND_AMOUNTS_LENGTH_DIFFER = "1";
    string public constant TOO_MUCH_SLIPPAGE = "2";
    string public constant EXCHANGER_NOT_FOUND = "3";
    string public constant POOL_IDS_NOT_FOUND = "4";
    string public constant WOULD_UNBALANCE_GYROSCOPE = "5";
    string public constant VAULT_ALREADY_EXISTS = "6";
    string public constant VAULT_NOT_FOUND = "7";

    string public constant X_OUT_OF_BOUNDS = "20";
    string public constant Y_OUT_OF_BOUNDS = "21";
    string public constant PRODUCT_OUT_OF_BOUNDS = "22";
    string public constant INVALID_EXPONENT = "23";
    string public constant OUT_OF_BOUNDS = "24";
    string public constant ZERO_DIVISION = "25";
    string public constant ADD_OVERFLOW = "26";
    string public constant SUB_OVERFLOW = "27";
    string public constant MUL_OVERFLOW = "28";
    string public constant DIV_INTERNAL = "29";

    // User errors
    string public constant NOT_AUTHORIZED = "30";
    string public constant INVALID_ARGUMENT = "31";
    string public constant KEY_NOT_FOUND = "32";
    string public constant KEY_FROZEN = "33";
    string public constant INSUFFICIENT_BALANCE = "34";
    string public constant INVALID_ASSET = "35";

    // Oracle related errors
    string public constant ASSET_NOT_SUPPORTED = "40";
    string public constant STALE_PRICE = "41";
    string public constant NEGATIVE_PRICE = "42";
    string public constant INVALID_MESSAGE = "43";
    string public constant TOO_MUCH_VOLATILITY = "44";
    string public constant WETH_ADDRESS_NOT_FIRST = "44";
    string public constant ROOT_PRICE_NOT_GROUNDED = "45";
    string public constant NOT_ENOUGH_TWAPS = "46";
    string public constant ZERO_PRICE_TWAP = "47";
    string public constant INVALID_NUMBER_WEIGHTS = "48";

    //Vault safety check related errors
    string public constant A_VAULT_HAS_ALL_STABLECOINS_OFF_PEG = "51";
    string public constant NOT_SAFE_TO_MINT = "52";
    string public constant NOT_SAFE_TO_REDEEM = "53";
    string public constant AMOUNT_AND_PRICE_LENGTH_DIFFER = "54";
    string public constant TOKEN_PRICES_TOO_SMALL = "55";
    string public constant TRYING_TO_REDEEM_MORE_THAN_VAULT_CONTAINS = "56";
    string public constant CALLER_NOT_MOTHERBOARD = "57";
    string public constant CALLER_NOT_RESERVE_MANAGER = "58";

    string public constant VAULT_FLOW_TOO_HIGH = "60";
    string public constant OPERATION_SUCCEEDS_BUT_SAFETY_MODE_ACTIVATED = "61";
    string public constant ORACLE_GUARDIAN_TIME_LIMIT = "62";
    string public constant NOT_ENOUGH_FLOW_DATA = "63";
}

File 2 of 16 : IGovernable.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IGovernable {
    /// @notice Emmited when the governor is changed
    event GovernorChanged(address oldGovernor, address newGovernor);

    /// @notice Emmited when the governor is change is requested
    event GovernorChangeRequested(address newGovernor);

    /// @notice Returns the current governor
    function governor() external view returns (address);

    /// @notice Returns the pending governor
    function pendingGovernor() external view returns (address);

    /// @notice Changes the governor
    /// can only be called by the current governor
    function changeGovernor(address newGovernor) external;

    /// @notice Called by the pending governor to approve the change
    function acceptGovernance() external;
}

File 2 of 16 : FixedPoint.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.8.4;

import "LogExpMath.sol";
import "Errors.sol";

/* solhint-disable private-vars-leading-underscore */

library FixedPoint {
    uint256 internal constant ONE = 1e18; // 18 decimal places
    uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)

    // Minimum base for the power function when the exponent is 'free' (larger than ONE).
    uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18;

    function absSub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a - b : b - a;
    }

    function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 product = a * b;

        return product / ONE;
    }

    function mulUp(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 product = a * b;

        if (product == 0) {
            return 0;
        } else {
            // The traditional divUp formula is:
            // divUp(x, y) := (x + y - 1) / y
            // To avoid intermediate overflow in the addition, we distribute the division and get:
            // divUp(x, y) := (x - 1) / y + 1
            // Note that this requires x != 0, which we already tested for.

            return ((product - 1) / ONE) + 1;
        }
    }

    function squareUp(uint256 a) internal pure returns (uint256) {
        return mulUp(a, a);
    }

    function squareDown(uint256 a) internal pure returns (uint256) {
        return mulDown(a, a);
    }

    function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, Errors.ZERO_DIVISION);

        if (a == 0) {
            return 0;
        } else {
            uint256 aInflated = a * ONE;

            return aInflated / b;
        }
    }

    function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, Errors.ZERO_DIVISION);

        if (a == 0) {
            return 0;
        } else {
            uint256 aInflated = a * ONE;

            // The traditional divUp formula is:
            // divUp(x, y) := (x + y - 1) / y
            // To avoid intermediate overflow in the addition, we distribute the division and get:
            // divUp(x, y) := (x - 1) / y + 1
            // Note that this requires x != 0, which we already tested for.

            unchecked {
                return ((aInflated - 1) / b) + 1;
            }
        }
    }

    /**
     * @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above
     * the true value (that is, the error function expected - actual is always positive).
     */
    function powDown(uint256 x, uint256 y) internal pure returns (uint256) {
        uint256 raw = LogExpMath.pow(x, y);
        uint256 maxError = mulUp(raw, MAX_POW_RELATIVE_ERROR) + 1;

        if (raw < maxError) {
            return 0;
        } else {
            return raw - maxError;
        }
    }

    /**
     * @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below
     * the true value (that is, the error function expected - actual is always negative).
     */
    function powUp(uint256 x, uint256 y) internal pure returns (uint256) {
        uint256 raw = LogExpMath.pow(x, y);
        uint256 maxError = mulUp(raw, MAX_POW_RELATIVE_ERROR) + 1;

        return raw + maxError;
    }

    /**
     * @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1.
     *
     * Useful when computing the complement for values with some level of relative error, as it strips this error and
     * prevents intermediate negative values.
     */
    function complement(uint256 x) internal pure returns (uint256) {
        return (x < ONE) ? (ONE - x) : 0;
    }

    /**
     * @dev returns the minimum between x and y
     */
    function min(uint256 x, uint256 y) internal pure returns (uint256) {
        return x < y ? x : y;
    }

    /**
     * @dev returns the maximum between x and y
     */
    function max(uint256 x, uint256 y) internal pure returns (uint256) {
        return x > y ? x : y;
    }

    /**
     * @notice This is taken from the Balancer V1 code base.
     * Computes a**b where a is a scaled fixed-point number and b is an integer
     * The computation is performed in O(log n)
     */
    function intPowDown(uint256 base, uint256 exp) internal pure returns (uint256) {
        uint256 result = FixedPoint.ONE;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = mulDown(result, base);
            }
            exp /= 2;
            base = mulDown(base, base);
        }
        return result;
    }
}

File 2 of 16 : LogExpMath.sol
// SPDX-License-Identifier: MIT
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.

// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pragma solidity ^0.8.4;

import "Errors.sol";

/* solhint-disable */

/**
 * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
 *
 * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
 * exponentiation and logarithm (where the base is Euler's number).
 *
 * @author Fernando Martinelli - @fernandomartinelli
 * @author Sergio Yuhjtman - @sergioyuhjtman
 * @author Daniel Fernandez - @dmf7z
 */
library LogExpMath {
    // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
    // two numbers, and multiply by ONE when dividing them.

    // All arguments and return values are 18 decimal fixed point numbers.
    int256 constant ONE_18 = 1e18;

    // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
    // case of ln36, 36 decimals.
    int256 constant ONE_20 = 1e20;
    int256 constant ONE_36 = 1e36;

    // The domain of natural exponentiation is bound by the word size and number of decimals used.
    //
    // Because internally the result will be stored using 20 decimals, the largest possible result is
    // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
    // The smallest possible result is 10^(-18), which makes largest negative argument
    // ln(10^(-18)) = -41.446531673892822312.
    // We use 130.0 and -41.0 to have some safety margin.
    int256 constant MAX_NATURAL_EXPONENT = 130e18;
    int256 constant MIN_NATURAL_EXPONENT = -41e18;

    // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
    // 256 bit integer.
    int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
    int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;

    uint256 constant MILD_EXPONENT_BOUND = 2**254 / uint256(ONE_20);

    // 18 decimal constants
    int256 constant x0 = 128000000000000000000; // 2ˆ7
    int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
    int256 constant x1 = 64000000000000000000; // 2ˆ6
    int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)

    // 20 decimal constants
    int256 constant x2 = 3200000000000000000000; // 2ˆ5
    int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)
    int256 constant x3 = 1600000000000000000000; // 2ˆ4
    int256 constant a3 = 888611052050787263676000000; // eˆ(x3)
    int256 constant x4 = 800000000000000000000; // 2ˆ3
    int256 constant a4 = 298095798704172827474000; // eˆ(x4)
    int256 constant x5 = 400000000000000000000; // 2ˆ2
    int256 constant a5 = 5459815003314423907810; // eˆ(x5)
    int256 constant x6 = 200000000000000000000; // 2ˆ1
    int256 constant a6 = 738905609893065022723; // eˆ(x6)
    int256 constant x7 = 100000000000000000000; // 2ˆ0
    int256 constant a7 = 271828182845904523536; // eˆ(x7)
    int256 constant x8 = 50000000000000000000; // 2ˆ-1
    int256 constant a8 = 164872127070012814685; // eˆ(x8)
    int256 constant x9 = 25000000000000000000; // 2ˆ-2
    int256 constant a9 = 128402541668774148407; // eˆ(x9)
    int256 constant x10 = 12500000000000000000; // 2ˆ-3
    int256 constant a10 = 113314845306682631683; // eˆ(x10)
    int256 constant x11 = 6250000000000000000; // 2ˆ-4
    int256 constant a11 = 106449445891785942956; // eˆ(x11)

    /**
     * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
     *
     * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
     */
    function pow(uint256 x, uint256 y) internal pure returns (uint256) {
        unchecked {
            if (y == 0) {
                // We solve the 0^0 indetermination by making it equal one.
                return uint256(ONE_18);
            }

            if (x == 0) {
                return 0;
            }

            // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
            // arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
            // x^y = exp(y * ln(x)).

            // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
            require(x < 2**255, Errors.X_OUT_OF_BOUNDS);
            int256 x_int256 = int256(x);

            // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
            // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.

            // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
            require(y < MILD_EXPONENT_BOUND, Errors.Y_OUT_OF_BOUNDS);
            int256 y_int256 = int256(y);

            int256 logx_times_y;
            if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
                int256 ln_36_x = _ln_36(x_int256);

                // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
                // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
                // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
                // (downscaled) last 18 decimals.
                logx_times_y = ((ln_36_x / ONE_18) *
                    y_int256 +
                    ((ln_36_x % ONE_18) * y_int256) /
                    ONE_18);
            } else {
                logx_times_y = _ln(x_int256) * y_int256;
            }
            logx_times_y /= ONE_18;

            // Finally, we compute exp(y * ln(x)) to arrive at x^y
            require(
                MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
                Errors.PRODUCT_OUT_OF_BOUNDS
            );

            return uint256(exp(logx_times_y));
        }
    }

    /**
     * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
     *
     * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
     */
    function exp(int256 x) internal pure returns (int256) {
        require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, Errors.INVALID_EXPONENT);
        unchecked {
            if (x < 0) {
                // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
                // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).
                // Fixed point division requires multiplying by ONE_18.
                return ((ONE_18 * ONE_18) / exp(-x));
            }

            // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
            // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
            // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
            // decomposition.
            // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
            // decomposition, which will be lower than the smallest x_n.
            // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
            // We mutate x by subtracting x_n, making it the remainder of the decomposition.

            // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
            // intermediate overflows. Instead we store them as plain integers, with 0 decimals.
            // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
            // decomposition.

            // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
            // it and compute the accumulated product.

            int256 firstAN;
            if (x >= x0) {
                x -= x0;
                firstAN = a0;
            } else if (x >= x1) {
                x -= x1;
                firstAN = a1;
            } else {
                firstAN = 1; // One with no decimal places
            }

            // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
            // smaller terms.
            x *= 100;

            // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
            // one. Recall that fixed point multiplication requires dividing by ONE_20.
            int256 product = ONE_20;

            if (x >= x2) {
                x -= x2;
                product = (product * a2) / ONE_20;
            }
            if (x >= x3) {
                x -= x3;
                product = (product * a3) / ONE_20;
            }
            if (x >= x4) {
                x -= x4;
                product = (product * a4) / ONE_20;
            }
            if (x >= x5) {
                x -= x5;
                product = (product * a5) / ONE_20;
            }
            if (x >= x6) {
                x -= x6;
                product = (product * a6) / ONE_20;
            }
            if (x >= x7) {
                x -= x7;
                product = (product * a7) / ONE_20;
            }
            if (x >= x8) {
                x -= x8;
                product = (product * a8) / ONE_20;
            }
            if (x >= x9) {
                x -= x9;
                product = (product * a9) / ONE_20;
            }

            // x10 and x11 are unnecessary here since we have high enough precision already.

            // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
            // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).

            int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.
            int256 term; // Each term in the sum, where the nth term is (x^n / n!).

            // The first term is simply x.
            term = x;
            seriesSum += term;

            // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
            // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.

            term = ((term * x) / ONE_20) / 2;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 3;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 4;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 5;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 6;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 7;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 8;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 9;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 10;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 11;
            seriesSum += term;

            term = ((term * x) / ONE_20) / 12;
            seriesSum += term;

            // 12 Taylor terms are sufficient for 18 decimal precision.

            // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
            // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
            // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
            // and then drop two digits to return an 18 decimal value.

            return (((product * seriesSum) / ONE_20) * firstAN) / 100;
        }
    }

    /**
     * @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument.
     */
    function log(int256 arg, int256 base) internal pure returns (int256) {
        unchecked {
            // This performs a simple base change: log(arg, base) = ln(arg) / ln(base).

            // Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
            // upscaling.

            int256 logBase;
            if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) {
                logBase = _ln_36(base);
            } else {
                logBase = _ln(base) * ONE_18;
            }

            int256 logArg;
            if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) {
                logArg = _ln_36(arg);
            } else {
                logArg = _ln(arg) * ONE_18;
            }

            // When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
            return (logArg * ONE_18) / logBase;
        }
    }

    /**
     * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
     */
    function ln(int256 a) internal pure returns (int256) {
        unchecked {
            // The real natural logarithm is not defined for negative numbers or zero.
            require(a > 0, Errors.OUT_OF_BOUNDS);
            if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {
                return _ln_36(a) / ONE_18;
            } else {
                return _ln(a);
            }
        }
    }

    /**
     * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
     */
    function _ln(int256 a) private pure returns (int256) {
        unchecked {
            if (a < ONE_18) {
                // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
                // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.
                // Fixed point division requires multiplying by ONE_18.
                return (-_ln((ONE_18 * ONE_18) / a));
            }

            // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
            // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
            // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
            // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
            // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
            // decomposition, which will be lower than the smallest a_n.
            // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
            // We mutate a by subtracting a_n, making it the remainder of the decomposition.

            // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
            // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
            // ONE_18 to convert them to fixed point.
            // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
            // by it and compute the accumulated sum.

            int256 sum = 0;
            if (a >= a0 * ONE_18) {
                a /= a0; // Integer, not fixed point division
                sum += x0;
            }

            if (a >= a1 * ONE_18) {
                a /= a1; // Integer, not fixed point division
                sum += x1;
            }

            // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
            sum *= 100;
            a *= 100;

            // Because further a_n are  20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.

            if (a >= a2) {
                a = (a * ONE_20) / a2;
                sum += x2;
            }

            if (a >= a3) {
                a = (a * ONE_20) / a3;
                sum += x3;
            }

            if (a >= a4) {
                a = (a * ONE_20) / a4;
                sum += x4;
            }

            if (a >= a5) {
                a = (a * ONE_20) / a5;
                sum += x5;
            }

            if (a >= a6) {
                a = (a * ONE_20) / a6;
                sum += x6;
            }

            if (a >= a7) {
                a = (a * ONE_20) / a7;
                sum += x7;
            }

            if (a >= a8) {
                a = (a * ONE_20) / a8;
                sum += x8;
            }

            if (a >= a9) {
                a = (a * ONE_20) / a9;
                sum += x9;
            }

            if (a >= a10) {
                a = (a * ONE_20) / a10;
                sum += x10;
            }

            if (a >= a11) {
                a = (a * ONE_20) / a11;
                sum += x11;
            }

            // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
            // that converges rapidly for values of `a` close to one - the same one used in ln_36.
            // Let z = (a - 1) / (a + 1).
            // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))

            // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
            // division by ONE_20.
            int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);
            int256 z_squared = (z * z) / ONE_20;

            // num is the numerator of the series: the z^(2 * n + 1) term
            int256 num = z;

            // seriesSum holds the accumulated sum of each term in the series, starting with the initial z
            int256 seriesSum = num;

            // In each step, the numerator is multiplied by z^2
            num = (num * z_squared) / ONE_20;
            seriesSum += num / 3;

            num = (num * z_squared) / ONE_20;
            seriesSum += num / 5;

            num = (num * z_squared) / ONE_20;
            seriesSum += num / 7;

            num = (num * z_squared) / ONE_20;
            seriesSum += num / 9;

            num = (num * z_squared) / ONE_20;
            seriesSum += num / 11;

            // 6 Taylor terms are sufficient for 36 decimal precision.

            // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
            seriesSum *= 2;

            // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
            // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
            // value.

            return (sum + seriesSum) / 100;
        }
    }

    /**
     * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
     * for x close to one.
     *
     * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
     */
    function _ln_36(int256 x) private pure returns (int256) {
        unchecked {
            // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
            // worthwhile.

            // First, we transform x to a 36 digit fixed point value.
            x *= ONE_18;

            // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
            // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))

            // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
            // division by ONE_36.
            int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);
            int256 z_squared = (z * z) / ONE_36;

            // num is the numerator of the series: the z^(2 * n + 1) term
            int256 num = z;

            // seriesSum holds the accumulated sum of each term in the series, starting with the initial z
            int256 seriesSum = num;

            // In each step, the numerator is multiplied by z^2
            num = (num * z_squared) / ONE_36;
            seriesSum += num / 3;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 5;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 7;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 9;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 11;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 13;

            num = (num * z_squared) / ONE_36;
            seriesSum += num / 15;

            // 8 Taylor terms are sufficient for 36 decimal precision.

            // All that remains is multiplying by 2 (non fixed point).
            return seriesSum * 2;
        }
    }

    function sqrt(uint256 x) internal pure returns (uint256) {
        return pow(x, uint256(ONE_18) / 2);
    }
}

Settings
{
  "evmVersion": "istanbul",
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "libraries": {
    "CheckedPriceOracle.sol": {}
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_usdOracle","type":"address"},{"internalType":"address","name":"_relativeOracle","type":"address"},{"internalType":"address","name":"_wethAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToAdd","type":"address"}],"name":"AssetForRelativePriceCheckAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToRemove","type":"address"}],"name":"AssetForRelativePriceCheckRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newGovernor","type":"address"}],"name":"GovernorChangeRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldGovernor","type":"address"},{"indexed":false,"internalType":"address","name":"newGovernor","type":"address"}],"name":"GovernorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToAdd","type":"address"}],"name":"PriceLevelTWAPQuoteAssetAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToRemove","type":"address"}],"name":"PriceLevelTWAPQuoteAssetRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oracle","type":"address"}],"name":"RelativeOracleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToAdd","type":"address"}],"name":"TrustedSignerOracleAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressToRemove","type":"address"}],"name":"TrustedSignerOracleRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oracle","type":"address"}],"name":"USDOracleUpdated","type":"event"},{"inputs":[],"name":"INITIAL_RELATIVE_EPSILON","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_ABSOLUTE_WETH_DEVIATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_RELATIVE_EPSILON","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetToAdd","type":"address"}],"name":"addAssetForRelativePriceCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_quoteAssetToAdd","type":"address"}],"name":"addQuoteAssetsForPriceLevelTwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signedAssetToAdd","type":"address"}],"name":"addSignedPriceSource","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newGovernor","type":"address"}],"name":"changeGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"}],"name":"getPricesUSD","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"signedPrices","type":"uint256[]"},{"internalType":"uint256[]","name":"twapPrices","type":"uint256[]"}],"name":"getRobustWETHPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listAssetForRelativePriceCheck","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listQuoteAssetsForPriceLevelTwap","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listSignedPriceSource","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingGovernor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"relativeEpsilon","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"relativeOracle","outputs":[{"internalType":"contract IRelativePriceOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"assetToRemove","type":"address"}],"name":"removeAssetForRelativePriceCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_quoteAssetToRemove","type":"address"}],"name":"removeQuoteAssetsForPriceLevelTwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signedAssetToRemove","type":"address"}],"name":"removeSignedPriceSource","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_relativeEpsilon","type":"uint256"}],"name":"setRelativeMaxEpsilon","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_relativeOracle","type":"address"}],"name":"setRelativeOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_usdOracle","type":"address"}],"name":"setUSDOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdOracle","outputs":[{"internalType":"contract IUSDPriceOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wethAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a06040523480156200001157600080fd5b506040516200234038038062002340833981016040819052620000349162000175565b600080546001600160a01b0319163390811782556040805192835260208301919091527fde4b3f61490b74c0ed6237523974fe299126bbbf8a8a7482fd220104c59b0c84910160405180910390a1604080518082019091526002815261333160f01b60208201526001600160a01b038416620000ce5760405162461bcd60e51b8152600401620000c59190620001bf565b60405180910390fd5b50604080518082019091526002815261333160f01b60208201526001600160a01b038316620001125760405162461bcd60e51b8152600401620000c59190620001bf565b50600280546001600160a01b03199081166001600160a01b0395861617909155600380549091169284169290921790915566470de4df8200006004551660805262000217565b80516001600160a01b03811681146200017057600080fd5b919050565b6000806000606084860312156200018b57600080fd5b620001968462000158565b9250620001a66020850162000158565b9150620001b66040850162000158565b90509250925092565b600060208083528351808285015260005b81811015620001ee57858101830151858201604001528201620001d0565b8181111562000201576000604083870101525b50601f01601f1916929092016040019392505050565b6080516120ea620002566000396000818161021e01528181610603015281816106a3015281816107ac0152818161115201526111e701526120ea6000f3fe608060405234801561001057600080fd5b50600436106101735760003560e01c8063a0b90f00116100de578063e181896011610097578063e4c0aaf411610071578063e4c0aaf414610324578063e4dd02c314610337578063e72a49d01461034a578063e7f9e3201461035957600080fd5b8063e1818960146102f5578063e3056a34146102fe578063e3a076211461031157600080fd5b8063a0b90f0014610296578063a7ed2a79146102a9578063b55b3f1b146102b9578063c8a4271f146102c7578063d8f4a0aa146102da578063e0dcd3c3146102ed57600080fd5b80634f0e0ef3116101305780634f0e0ef31461021957806357ae33891461024057806364b450901461025357806375ceebd014610268578063765aff1e1461027b5780637cd8c1d01461028357600080fd5b80630317ca7c146101785780630c340a241461018d578063238efcbc146101bd5780632af31283146101c55780632e191ed7146101e5578063442aae7914610206575b600080fd5b61018b610186366004611bcb565b61036c565b005b6000546101a0906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61018b610407565b6101d86101d3366004611c51565b6104b0565b6040516101b49190611cee565b6101f86101f3366004611d98565b61086a565b6040519081526020016101b4565b6003546101a0906001600160a01b031681565b6101a07f000000000000000000000000000000000000000000000000000000000000000081565b61018b61024e366004611dfc565b610989565b61025b610a4e565b6040516101b49190611e15565b61018b610276366004611bcb565b610a5f565b61025b610aea565b61018b610291366004611bcb565b610af6565b61018b6102a4366004611bcb565b610b81565b6101f86802b5e3af16b188000081565b6101f866470de4df82000081565b6002546101a0906001600160a01b031681565b61018b6102e8366004611bcb565b610c11565b61025b610c9c565b6101f860045481565b6001546101a0906001600160a01b031681565b61018b61031f366004611bcb565b610ca8565b61018b610332366004611bcb565b610d33565b61018b610345366004611bcb565b610e08565b6101f867016345785d8a000081565b61018b610367366004611bcb565b610e93565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b031633146103ba5760405162461bcd60e51b81526004016103b19190611e56565b60405180910390fd5b506103c6600982610f23565b506040516001600160a01b03821681527f150f6605e7fc997b9ef5bed4e904eef6e3f887a080d2f7010632435b47f67adc906020015b60405180910390a150565b600154604080518082019091526002815261033360f41b6020820152906001600160a01b0316331461044c5760405162461bcd60e51b81526004016103b19190611e56565b5060008054600180546001600160a01b03198084166001600160a01b03808416919091179095551690556040805192909116808352336020840152917fde4b3f61490b74c0ed6237523974fe299126bbbf8a8a7482fd220104c59b0c8491016103fc565b6060600082511160405180604001604052806002815260200161333160f01b815250906104f05760405162461bcd60e51b81526004016103b19190611e56565b506000825167ffffffffffffffff81111561050d5761050d611be6565b604051908082528060200260200182016040528015610536578160200160208202803683370190505b5090506000805b84518110156106835760025485516001600160a01b0390911690635708447d9087908490811061056f5761056f611eab565b60200260200101516040518263ffffffff1660e01b81526004016105a291906001600160a01b0391909116815260200190565b602060405180830381865afa1580156105bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105e39190611ec1565b8382815181106105f5576105f5611eab565b6020026020010181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031685828151811061063d5761063d611eab565b60200260200101516001600160a01b031614156106715782818151811061066657610666611eab565b602002602001015191505b8061067b81611ef0565b91505061053d565b508061071a57600254604051635708447d60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015290911690635708447d90602401602060405180830381865afa1580156106f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107179190611ec1565b90505b60006107268584610f3f565b9050600061073460056113d4565b905060008167ffffffffffffffff81111561075157610751611be6565b60405190808252806020026020018201604052801561077a578160200160208202803683370190505b50905060005b828110156108535760006107956005836113de565b604051635708447d60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015291925090821690635708447d90602401602060405180830381865afa1580156107ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108239190611ec1565b83838151811061083557610835611eab565b6020908102919091010152508061084b81611ef0565b915050610780565b5061085f8482856113ea565b509295945050505050565b6000808251600014156108885761088084611454565b915050610983565b61089183611501565b90506000845160016108a39190611f0b565b67ffffffffffffffff8111156108bb576108bb611be6565b6040519080825280602002602001820160405280156108e4578160200160208202803683370190505b5090508181600183516108f79190611f23565b8151811061090757610907611eab565b60200260200101818152505060005b600182516109249190611f23565b8110156109745785818151811061093d5761093d611eab565b602002602001015182828151811061095757610957611eab565b60209081029190910101528061096c81611ef0565b915050610916565b5061097e81611454565b925050505b92915050565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b031633146109ce5760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b602082015281610a065760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b602082015267016345785d8a00008210610a485760405162461bcd60e51b81526004016103b19190611e56565b50600455565b6060610a5a6005611608565b905090565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610aa45760405162461bcd60e51b81526004016103b19190611e56565b50610ab0600582610f23565b506040516001600160a01b03821681527fb7f10b8974f181778e2544b4188359b499da116029e96c6a05bed5cdecee1064906020016103fc565b6060610a5a6009611608565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610b3b5760405162461bcd60e51b81526004016103b19190611e56565b50610b47600982611615565b506040516001600160a01b03821681527fa67cac4de4567bfe36d7fa182b8455fd3e7d1b80c45191dd2b6dd5310a353066906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610bc65760405162461bcd60e51b81526004016103b19190611e56565b50600280546001600160a01b0319166001600160a01b0383169081179091556040517f8bdf8e573e1e6b8aba457bd2a4fed210b28b0ed18344a7c4bb4bd1e87f6e1fb790600090a250565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610c565760405162461bcd60e51b81526004016103b19190611e56565b50610c62600782611615565b506040516001600160a01b03821681527f612ac93ad02ac7669d13be8835bb33d5c6d42bb4c46f0cdb717681ebd2b64557906020016103fc565b6060610a5a6007611608565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610ced5760405162461bcd60e51b81526004016103b19190611e56565b50610cf9600582611615565b506040516001600160a01b03821681527f8696120fb7656955ec406c2959998de0aa9798518606d5afb5f36789f522dfea906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610d785760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b60208201526001600160a01b038216610db95760405162461bcd60e51b81526004016103b19190611e56565b50600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f67235ba2e63c748a35b95c4f92a3bbc2a1389938170a5ce6c9add5d0b03a314a906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610e4d5760405162461bcd60e51b81526004016103b19190611e56565b50610e59600782610f23565b506040516001600160a01b03821681527ffab625e04bc6eeef38aaf5c2e48b1f1953cf5183297f4115f0da9e906d4bf3ac906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610ed85760405162461bcd60e51b81526004016103b19190611e56565b50600380546001600160a01b0319166001600160a01b0383169081179091556040517f99e4ac532391c2555b226b3d66f3d643e9256788b0c246834c1aaebfad90bd0190600090a250565b6000610f38836001600160a01b03841661162a565b9392505050565b60606000610f4d60076113d4565b67ffffffffffffffff811115610f6557610f65611be6565b604051908082528060200260200182016040528015610f8e578160200160208202803683370190505b5090506000805b855181101561132e576000805b610fac60096113d4565b8110156112e1576000610fc06009836113de565b9050806001600160a01b0316898581518110610fde57610fde611eab565b60200260200101516001600160a01b0316148061109d575060035489516001600160a01b0390911690639446994a908b908790811061101f5761101f611eab565b6020026020010151836040518363ffffffff1660e01b815260040161105a9291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015611077573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109b9190611f3a565b155b156110a857506112cf565b60035489516000916001600160a01b031690639b56e6a7908c90889081106110d2576110d2611eab565b6020026020010151846040518363ffffffff1660e01b815260040161110d9291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa15801561112a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114e9190611ec1565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168a868151811061118c5761118c611eab565b60200260200101516001600160a01b03161480156111b057506111b0600783611679565b156111e557808787815181106111c8576111c8611eab565b6020908102919091010152856111dd81611ef0565b965050611290565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614801561124e575061124e8a868151811061123657611236611eab565b6020026020010151600761167990919063ffffffff16565b1561129057611265670de0b6b3a76400008261169b565b87878151811061127757611277611eab565b60209081029190910101528561128c81611ef0565b9650505b600061129d838c8c611703565b90506112c38a87815181106112b4576112b4611eab565b602002602001015182846117ee565b600194505050506112e1565b806112d981611ef0565b915050610fa2565b50604080518082019091526002815261034360f41b6020820152816113195760405162461bcd60e51b81526004016103b19190611e56565b5050808061132690611ef0565b915050610f95565b5060008167ffffffffffffffff81111561134a5761134a611be6565b604051908082528060200260200182016040528015611373578160200160208202803683370190505b50905060005b828110156113ca5783818151811061139357611393611eab565b60200260200101518282815181106113ad576113ad611eab565b6020908102919091010152806113c281611ef0565b915050611379565b5095945050505050565b6000610983825490565b6000610f388383611860565b60006113f6838361086a565b90506000611404858361188a565b90506802b5e3af16b188000081111560405180604001604052806002815260200161343560f01b8152509061144c5760405162461bcd60e51b81526004016103b19190611e56565b505050505050565b600061145f826118ad565b506002825161146e9190611f72565b1561149f5781600283516114829190611f86565b8151811061149257611492611eab565b6020026020010151610983565b610983826001600285516114b39190611f86565b6114bd9190611f23565b815181106114cd576114cd611eab565b602002602001015183600285516114e49190611f86565b815181106114f4576114f4611eab565b60200260200101516118cc565b6000808260008151811061151757611517611eab565b6020908102919091010151905060001960015b84518110156115c8578285828151811061154657611546611eab565b602002602001015110156115785782915084818151811061156957611569611eab565b602002602001015192506115b6565b8185828151811061158b5761158b611eab565b602002602001015110156115b6578481815181106115ab576115ab611eab565b602002602001015191505b806115c081611ef0565b91505061152a565b508351600114156115f757836000815181106115e6576115e6611eab565b602002602001015192505050919050565b835160021415610f38575092915050565b60606000610f38836118e7565b6000610f38836001600160a01b038416611943565b600081815260018301602052604081205461167157508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610983565b506000610983565b6001600160a01b03811660009081526001830160205260408120541515610f38565b604080518082019091526002815261323560f01b6020820152600090826116d55760405162461bcd60e51b81526004016103b19190611e56565b50826116e357506000610983565b60006116f7670de0b6b3a764000085611f9a565b90506108808382611f86565b6000805b835181101561177757846001600160a01b031684828151811061172c5761172c611eab565b60200260200101516001600160a01b031614156117655782818151811061175557611755611eab565b6020026020010151915050610f38565b8061176f81611ef0565b915050611707565b50600254604051635708447d60e01b81526001600160a01b03868116600483015290911690635708447d90602401602060405180830381865afa1580156117c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e69190611ec1565b949350505050565b60006117fa848461169b565b90506000611808838361188a565b90506000611816828561169b565b905060045481111560405180604001604052806002815260200161343160f01b815250906118575760405162461bcd60e51b81526004016103b19190611e56565b50505050505050565b600082600001828154811061187757611877611eab565b9060005260206000200154905092915050565b6000818310156118a35761189e8383611f23565b610f38565b610f388284611f23565b60606118c8826000600185516118c39190611f23565b611a36565b5090565b60006118db6002848418611f86565b610f3890848416611f0b565b60608160000180548060200260200160405190810160405280929190818152602001828054801561193757602002820191906000526020600020905b815481526020019060010190808311611923575b50505050509050919050565b60008181526001830160205260408120548015611a2c576000611967600183611f23565b855490915060009061197b90600190611f23565b90508181146119e057600086600001828154811061199b5761199b611eab565b90600052602060002001549050808760000184815481106119be576119be611eab565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806119f1576119f1611fb9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610983565b6000915050610983565b818180821415611a47575050505050565b6000856002611a568787611fcf565b611a60919061200e565b611a6a908761203c565b81518110611a7a57611a7a611eab565b602002602001015190505b818313611b89575b80868481518110611aa057611aa0611eab565b60200260200101511015611ac05782611ab88161207d565b935050611a8d565b858281518110611ad257611ad2611eab565b6020026020010151811015611af35781611aeb81612096565b925050611ac0565b818313611b8457858281518110611b0c57611b0c611eab565b6020026020010151868481518110611b2657611b26611eab565b6020026020010151878581518110611b4057611b40611eab565b60200260200101888581518110611b5957611b59611eab565b60209081029190910101919091525282611b728161207d565b9350508180611b8090612096565b9250505b611a85565b81851215611b9c57611b9c868684611a36565b8383121561144c5761144c868486611a36565b80356001600160a01b0381168114611bc657600080fd5b919050565b600060208284031215611bdd57600080fd5b610f3882611baf565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611c2557611c25611be6565b604052919050565b600067ffffffffffffffff821115611c4757611c47611be6565b5060051b60200190565b60006020808385031215611c6457600080fd5b823567ffffffffffffffff811115611c7b57600080fd5b8301601f81018513611c8c57600080fd5b8035611c9f611c9a82611c2d565b611bfc565b81815260059190911b82018301908381019087831115611cbe57600080fd5b928401925b82841015611ce357611cd484611baf565b82529284019290840190611cc3565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611d2657835183529284019291840191600101611d0a565b50909695505050505050565b600082601f830112611d4357600080fd5b81356020611d53611c9a83611c2d565b82815260059290921b84018101918181019086841115611d7257600080fd5b8286015b84811015611d8d5780358352918301918301611d76565b509695505050505050565b60008060408385031215611dab57600080fd5b823567ffffffffffffffff80821115611dc357600080fd5b611dcf86838701611d32565b93506020850135915080821115611de557600080fd5b50611df285828601611d32565b9150509250929050565b600060208284031215611e0e57600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b81811015611d265783516001600160a01b031683529284019291840191600101611e31565b600060208083528351808285015260005b81811015611e8357858101830151858201604001528201611e67565b81811115611e95576000604083870101525b50601f01601f1916929092016040019392505050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215611ed357600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000600019821415611f0457611f04611eda565b5060010190565b60008219821115611f1e57611f1e611eda565b500190565b600082821015611f3557611f35611eda565b500390565b600060208284031215611f4c57600080fd5b81518015158114610f3857600080fd5b634e487b7160e01b600052601260045260246000fd5b600082611f8157611f81611f5c565b500690565b600082611f9557611f95611f5c565b500490565b6000816000190483118215151615611fb457611fb4611eda565b500290565b634e487b7160e01b600052603160045260246000fd5b60008083128015600160ff1b850184121615611fed57611fed611eda565b6001600160ff1b038401831381161561200857612008611eda565b50500390565b60008261201d5761201d611f5c565b600160ff1b82146000198414161561203757612037611eda565b500590565b600080821280156001600160ff1b038490038513161561205e5761205e611eda565b600160ff1b839003841281161561207757612077611eda565b50500190565b60006001600160ff1b03821415611f0457611f04611eda565b6000600160ff1b8214156120ac576120ac611eda565b50600019019056fea26469706673582212201ffb62773936144e9fd659ec66cc4411e89df92320563e4e3ea736b9c8a11a5764736f6c634300080a003300000000000000000000000071242644944a33b7e92ebcbd144d292030365f7f00000000000000000000000066105fda19535ee800c9fdc8b1688d41bfce76a50000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f619

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101735760003560e01c8063a0b90f00116100de578063e181896011610097578063e4c0aaf411610071578063e4c0aaf414610324578063e4dd02c314610337578063e72a49d01461034a578063e7f9e3201461035957600080fd5b8063e1818960146102f5578063e3056a34146102fe578063e3a076211461031157600080fd5b8063a0b90f0014610296578063a7ed2a79146102a9578063b55b3f1b146102b9578063c8a4271f146102c7578063d8f4a0aa146102da578063e0dcd3c3146102ed57600080fd5b80634f0e0ef3116101305780634f0e0ef31461021957806357ae33891461024057806364b450901461025357806375ceebd014610268578063765aff1e1461027b5780637cd8c1d01461028357600080fd5b80630317ca7c146101785780630c340a241461018d578063238efcbc146101bd5780632af31283146101c55780632e191ed7146101e5578063442aae7914610206575b600080fd5b61018b610186366004611bcb565b61036c565b005b6000546101a0906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61018b610407565b6101d86101d3366004611c51565b6104b0565b6040516101b49190611cee565b6101f86101f3366004611d98565b61086a565b6040519081526020016101b4565b6003546101a0906001600160a01b031681565b6101a07f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f61981565b61018b61024e366004611dfc565b610989565b61025b610a4e565b6040516101b49190611e15565b61018b610276366004611bcb565b610a5f565b61025b610aea565b61018b610291366004611bcb565b610af6565b61018b6102a4366004611bcb565b610b81565b6101f86802b5e3af16b188000081565b6101f866470de4df82000081565b6002546101a0906001600160a01b031681565b61018b6102e8366004611bcb565b610c11565b61025b610c9c565b6101f860045481565b6001546101a0906001600160a01b031681565b61018b61031f366004611bcb565b610ca8565b61018b610332366004611bcb565b610d33565b61018b610345366004611bcb565b610e08565b6101f867016345785d8a000081565b61018b610367366004611bcb565b610e93565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b031633146103ba5760405162461bcd60e51b81526004016103b19190611e56565b60405180910390fd5b506103c6600982610f23565b506040516001600160a01b03821681527f150f6605e7fc997b9ef5bed4e904eef6e3f887a080d2f7010632435b47f67adc906020015b60405180910390a150565b600154604080518082019091526002815261033360f41b6020820152906001600160a01b0316331461044c5760405162461bcd60e51b81526004016103b19190611e56565b5060008054600180546001600160a01b03198084166001600160a01b03808416919091179095551690556040805192909116808352336020840152917fde4b3f61490b74c0ed6237523974fe299126bbbf8a8a7482fd220104c59b0c8491016103fc565b6060600082511160405180604001604052806002815260200161333160f01b815250906104f05760405162461bcd60e51b81526004016103b19190611e56565b506000825167ffffffffffffffff81111561050d5761050d611be6565b604051908082528060200260200182016040528015610536578160200160208202803683370190505b5090506000805b84518110156106835760025485516001600160a01b0390911690635708447d9087908490811061056f5761056f611eab565b60200260200101516040518263ffffffff1660e01b81526004016105a291906001600160a01b0391909116815260200190565b602060405180830381865afa1580156105bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105e39190611ec1565b8382815181106105f5576105f5611eab565b6020026020010181815250507f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6196001600160a01b031685828151811061063d5761063d611eab565b60200260200101516001600160a01b031614156106715782818151811061066657610666611eab565b602002602001015191505b8061067b81611ef0565b91505061053d565b508061071a57600254604051635708447d60e01b81526001600160a01b037f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6198116600483015290911690635708447d90602401602060405180830381865afa1580156106f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107179190611ec1565b90505b60006107268584610f3f565b9050600061073460056113d4565b905060008167ffffffffffffffff81111561075157610751611be6565b60405190808252806020026020018201604052801561077a578160200160208202803683370190505b50905060005b828110156108535760006107956005836113de565b604051635708447d60e01b81526001600160a01b037f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6198116600483015291925090821690635708447d90602401602060405180830381865afa1580156107ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108239190611ec1565b83838151811061083557610835611eab565b6020908102919091010152508061084b81611ef0565b915050610780565b5061085f8482856113ea565b509295945050505050565b6000808251600014156108885761088084611454565b915050610983565b61089183611501565b90506000845160016108a39190611f0b565b67ffffffffffffffff8111156108bb576108bb611be6565b6040519080825280602002602001820160405280156108e4578160200160208202803683370190505b5090508181600183516108f79190611f23565b8151811061090757610907611eab565b60200260200101818152505060005b600182516109249190611f23565b8110156109745785818151811061093d5761093d611eab565b602002602001015182828151811061095757610957611eab565b60209081029190910101528061096c81611ef0565b915050610916565b5061097e81611454565b925050505b92915050565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b031633146109ce5760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b602082015281610a065760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b602082015267016345785d8a00008210610a485760405162461bcd60e51b81526004016103b19190611e56565b50600455565b6060610a5a6005611608565b905090565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610aa45760405162461bcd60e51b81526004016103b19190611e56565b50610ab0600582610f23565b506040516001600160a01b03821681527fb7f10b8974f181778e2544b4188359b499da116029e96c6a05bed5cdecee1064906020016103fc565b6060610a5a6009611608565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610b3b5760405162461bcd60e51b81526004016103b19190611e56565b50610b47600982611615565b506040516001600160a01b03821681527fa67cac4de4567bfe36d7fa182b8455fd3e7d1b80c45191dd2b6dd5310a353066906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610bc65760405162461bcd60e51b81526004016103b19190611e56565b50600280546001600160a01b0319166001600160a01b0383169081179091556040517f8bdf8e573e1e6b8aba457bd2a4fed210b28b0ed18344a7c4bb4bd1e87f6e1fb790600090a250565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610c565760405162461bcd60e51b81526004016103b19190611e56565b50610c62600782611615565b506040516001600160a01b03821681527f612ac93ad02ac7669d13be8835bb33d5c6d42bb4c46f0cdb717681ebd2b64557906020016103fc565b6060610a5a6007611608565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610ced5760405162461bcd60e51b81526004016103b19190611e56565b50610cf9600582611615565b506040516001600160a01b03821681527f8696120fb7656955ec406c2959998de0aa9798518606d5afb5f36789f522dfea906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610d785760405162461bcd60e51b81526004016103b19190611e56565b50604080518082019091526002815261333160f01b60208201526001600160a01b038216610db95760405162461bcd60e51b81526004016103b19190611e56565b50600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f67235ba2e63c748a35b95c4f92a3bbc2a1389938170a5ce6c9add5d0b03a314a906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610e4d5760405162461bcd60e51b81526004016103b19190611e56565b50610e59600782610f23565b506040516001600160a01b03821681527ffab625e04bc6eeef38aaf5c2e48b1f1953cf5183297f4115f0da9e906d4bf3ac906020016103fc565b600054604080518082019091526002815261033360f41b6020820152906001600160a01b03163314610ed85760405162461bcd60e51b81526004016103b19190611e56565b50600380546001600160a01b0319166001600160a01b0383169081179091556040517f99e4ac532391c2555b226b3d66f3d643e9256788b0c246834c1aaebfad90bd0190600090a250565b6000610f38836001600160a01b03841661162a565b9392505050565b60606000610f4d60076113d4565b67ffffffffffffffff811115610f6557610f65611be6565b604051908082528060200260200182016040528015610f8e578160200160208202803683370190505b5090506000805b855181101561132e576000805b610fac60096113d4565b8110156112e1576000610fc06009836113de565b9050806001600160a01b0316898581518110610fde57610fde611eab565b60200260200101516001600160a01b0316148061109d575060035489516001600160a01b0390911690639446994a908b908790811061101f5761101f611eab565b6020026020010151836040518363ffffffff1660e01b815260040161105a9291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015611077573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109b9190611f3a565b155b156110a857506112cf565b60035489516000916001600160a01b031690639b56e6a7908c90889081106110d2576110d2611eab565b6020026020010151846040518363ffffffff1660e01b815260040161110d9291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa15801561112a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114e9190611ec1565b90507f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6196001600160a01b03168a868151811061118c5761118c611eab565b60200260200101516001600160a01b03161480156111b057506111b0600783611679565b156111e557808787815181106111c8576111c8611eab565b6020908102919091010152856111dd81611ef0565b965050611290565b7f0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6196001600160a01b0316826001600160a01b031614801561124e575061124e8a868151811061123657611236611eab565b6020026020010151600761167990919063ffffffff16565b1561129057611265670de0b6b3a76400008261169b565b87878151811061127757611277611eab565b60209081029190910101528561128c81611ef0565b9650505b600061129d838c8c611703565b90506112c38a87815181106112b4576112b4611eab565b602002602001015182846117ee565b600194505050506112e1565b806112d981611ef0565b915050610fa2565b50604080518082019091526002815261034360f41b6020820152816113195760405162461bcd60e51b81526004016103b19190611e56565b5050808061132690611ef0565b915050610f95565b5060008167ffffffffffffffff81111561134a5761134a611be6565b604051908082528060200260200182016040528015611373578160200160208202803683370190505b50905060005b828110156113ca5783818151811061139357611393611eab565b60200260200101518282815181106113ad576113ad611eab565b6020908102919091010152806113c281611ef0565b915050611379565b5095945050505050565b6000610983825490565b6000610f388383611860565b60006113f6838361086a565b90506000611404858361188a565b90506802b5e3af16b188000081111560405180604001604052806002815260200161343560f01b8152509061144c5760405162461bcd60e51b81526004016103b19190611e56565b505050505050565b600061145f826118ad565b506002825161146e9190611f72565b1561149f5781600283516114829190611f86565b8151811061149257611492611eab565b6020026020010151610983565b610983826001600285516114b39190611f86565b6114bd9190611f23565b815181106114cd576114cd611eab565b602002602001015183600285516114e49190611f86565b815181106114f4576114f4611eab565b60200260200101516118cc565b6000808260008151811061151757611517611eab565b6020908102919091010151905060001960015b84518110156115c8578285828151811061154657611546611eab565b602002602001015110156115785782915084818151811061156957611569611eab565b602002602001015192506115b6565b8185828151811061158b5761158b611eab565b602002602001015110156115b6578481815181106115ab576115ab611eab565b602002602001015191505b806115c081611ef0565b91505061152a565b508351600114156115f757836000815181106115e6576115e6611eab565b602002602001015192505050919050565b835160021415610f38575092915050565b60606000610f38836118e7565b6000610f38836001600160a01b038416611943565b600081815260018301602052604081205461167157508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610983565b506000610983565b6001600160a01b03811660009081526001830160205260408120541515610f38565b604080518082019091526002815261323560f01b6020820152600090826116d55760405162461bcd60e51b81526004016103b19190611e56565b50826116e357506000610983565b60006116f7670de0b6b3a764000085611f9a565b90506108808382611f86565b6000805b835181101561177757846001600160a01b031684828151811061172c5761172c611eab565b60200260200101516001600160a01b031614156117655782818151811061175557611755611eab565b6020026020010151915050610f38565b8061176f81611ef0565b915050611707565b50600254604051635708447d60e01b81526001600160a01b03868116600483015290911690635708447d90602401602060405180830381865afa1580156117c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e69190611ec1565b949350505050565b60006117fa848461169b565b90506000611808838361188a565b90506000611816828561169b565b905060045481111560405180604001604052806002815260200161343160f01b815250906118575760405162461bcd60e51b81526004016103b19190611e56565b50505050505050565b600082600001828154811061187757611877611eab565b9060005260206000200154905092915050565b6000818310156118a35761189e8383611f23565b610f38565b610f388284611f23565b60606118c8826000600185516118c39190611f23565b611a36565b5090565b60006118db6002848418611f86565b610f3890848416611f0b565b60608160000180548060200260200160405190810160405280929190818152602001828054801561193757602002820191906000526020600020905b815481526020019060010190808311611923575b50505050509050919050565b60008181526001830160205260408120548015611a2c576000611967600183611f23565b855490915060009061197b90600190611f23565b90508181146119e057600086600001828154811061199b5761199b611eab565b90600052602060002001549050808760000184815481106119be576119be611eab565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806119f1576119f1611fb9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610983565b6000915050610983565b818180821415611a47575050505050565b6000856002611a568787611fcf565b611a60919061200e565b611a6a908761203c565b81518110611a7a57611a7a611eab565b602002602001015190505b818313611b89575b80868481518110611aa057611aa0611eab565b60200260200101511015611ac05782611ab88161207d565b935050611a8d565b858281518110611ad257611ad2611eab565b6020026020010151811015611af35781611aeb81612096565b925050611ac0565b818313611b8457858281518110611b0c57611b0c611eab565b6020026020010151868481518110611b2657611b26611eab565b6020026020010151878581518110611b4057611b40611eab565b60200260200101888581518110611b5957611b59611eab565b60209081029190910101919091525282611b728161207d565b9350508180611b8090612096565b9250505b611a85565b81851215611b9c57611b9c868684611a36565b8383121561144c5761144c868486611a36565b80356001600160a01b0381168114611bc657600080fd5b919050565b600060208284031215611bdd57600080fd5b610f3882611baf565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611c2557611c25611be6565b604052919050565b600067ffffffffffffffff821115611c4757611c47611be6565b5060051b60200190565b60006020808385031215611c6457600080fd5b823567ffffffffffffffff811115611c7b57600080fd5b8301601f81018513611c8c57600080fd5b8035611c9f611c9a82611c2d565b611bfc565b81815260059190911b82018301908381019087831115611cbe57600080fd5b928401925b82841015611ce357611cd484611baf565b82529284019290840190611cc3565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611d2657835183529284019291840191600101611d0a565b50909695505050505050565b600082601f830112611d4357600080fd5b81356020611d53611c9a83611c2d565b82815260059290921b84018101918181019086841115611d7257600080fd5b8286015b84811015611d8d5780358352918301918301611d76565b509695505050505050565b60008060408385031215611dab57600080fd5b823567ffffffffffffffff80821115611dc357600080fd5b611dcf86838701611d32565b93506020850135915080821115611de557600080fd5b50611df285828601611d32565b9150509250929050565b600060208284031215611e0e57600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b81811015611d265783516001600160a01b031683529284019291840191600101611e31565b600060208083528351808285015260005b81811015611e8357858101830151858201604001528201611e67565b81811115611e95576000604083870101525b50601f01601f1916929092016040019392505050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215611ed357600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000600019821415611f0457611f04611eda565b5060010190565b60008219821115611f1e57611f1e611eda565b500190565b600082821015611f3557611f35611eda565b500390565b600060208284031215611f4c57600080fd5b81518015158114610f3857600080fd5b634e487b7160e01b600052601260045260246000fd5b600082611f8157611f81611f5c565b500690565b600082611f9557611f95611f5c565b500490565b6000816000190483118215151615611fb457611fb4611eda565b500290565b634e487b7160e01b600052603160045260246000fd5b60008083128015600160ff1b850184121615611fed57611fed611eda565b6001600160ff1b038401831381161561200857612008611eda565b50500390565b60008261201d5761201d611f5c565b600160ff1b82146000198414161561203757612037611eda565b500590565b600080821280156001600160ff1b038490038513161561205e5761205e611eda565b600160ff1b839003841281161561207757612077611eda565b50500190565b60006001600160ff1b03821415611f0457611f04611eda565b6000600160ff1b8214156120ac576120ac611eda565b50600019019056fea26469706673582212201ffb62773936144e9fd659ec66cc4411e89df92320563e4e3ea736b9c8a11a5764736f6c634300080a0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000071242644944a33b7e92ebcbd144d292030365f7f00000000000000000000000066105fda19535ee800c9fdc8b1688d41bfce76a50000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f619

-----Decoded View---------------
Arg [0] : _usdOracle (address): 0x71242644944a33B7e92EbcBd144D292030365f7f
Arg [1] : _relativeOracle (address): 0x66105fdA19535Ee800c9FDC8b1688d41BfCE76a5
Arg [2] : _wethAddress (address): 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000071242644944a33b7e92ebcbd144d292030365f7f
Arg [1] : 00000000000000000000000066105fda19535ee800c9fdc8b1688d41bfce76a5
Arg [2] : 0000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f619


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.