Address Details
contract

0xf1852752B4EF6D97a94B29a7256ADF58A425e7bE

Contract Name
MedianDeltaBreaker
Creator
0x56fd3f–9b8d81 at 0x36f7ef–7f029e
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
1 Transactions
Transfers
0 Transfers
Gas Used
28,613
Last Balance Update
21371656
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
MedianDeltaBreaker




Optimization enabled
true
Compiler version
v0.5.17+commit.d19bba13




Optimization runs
10000
EVM Version
istanbul




Verified at
2023-03-10T06:56:50.583760Z

lib/mento-core/contracts/MedianDeltaBreaker.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import { IBreaker } from "./interfaces/IBreaker.sol";
import { WithCooldown } from "./common/breakers/WithCooldown.sol";
import { WithThreshold } from "./common/breakers/WithThreshold.sol";

import { ISortedOracles } from "./interfaces/ISortedOracles.sol";

import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol";

import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
import { FixidityLib } from "./common/FixidityLib.sol";

/**
 * @title   Median Delta Breaker
 * @notice  Breaker contract that will trigger when an updated oracle median rate changes
 *          more than a configured relative threshold from the previous one. If this
 *          breaker is triggered for a rate feed it should be set to no trading mode.
 */
contract MedianDeltaBreaker is IBreaker, WithCooldown, WithThreshold, Ownable {
  using SafeMath for uint256;
  using FixidityLib for FixidityLib.Fraction;

  /* ==================== State Variables ==================== */
  // Address of the Mento SortedOracles contract
  ISortedOracles public sortedOracles;

  // The previous median recorded for a ratefeed.
  mapping(address => uint256) public previousMedianRates;

  /* ==================== Constructor ==================== */

  constructor(
    uint256 _defaultCooldownTime,
    uint256 _defaultRateChangeThreshold,
    ISortedOracles _sortedOracles,
    address[] memory rateFeedIDs,
    uint256[] memory rateChangeThresholds,
    uint256[] memory cooldownTimes
  ) public {
    _transferOwnership(msg.sender);
    setSortedOracles(_sortedOracles);

    _setDefaultCooldownTime(_defaultCooldownTime);
    _setDefaultRateChangeThreshold(_defaultRateChangeThreshold);
    _setRateChangeThresholds(rateFeedIDs, rateChangeThresholds);
    _setCooldownTimes(rateFeedIDs, cooldownTimes);
  }

  /* ==================== Restricted Functions ==================== */

  /**
   * @notice Sets the cooldown time to the specified value for a rate feed.
   * @param rateFeedIDs the targeted rate feed.
   * @param cooldownTimes The new cooldownTime value.
   * @dev Should be set to 0 to force a manual reset.
   */
  function setCooldownTime(address[] calldata rateFeedIDs, uint256[] calldata cooldownTimes) external onlyOwner {
    _setCooldownTimes(rateFeedIDs, cooldownTimes);
  }

  /**
   * @notice Sets the cooldownTime to the specified value for a rate feed.
   * @param cooldownTime The new cooldownTime value.
   * @dev Should be set to 0 to force a manual reset.
   */
  function setDefaultCooldownTime(uint256 cooldownTime) external onlyOwner {
    _setDefaultCooldownTime(cooldownTime);
  }

  /**
   * @notice Sets rateChangeThreshold.
   * @param _defaultRateChangeThreshold The new rateChangeThreshold value.
   */
  function setDefaultRateChangeThreshold(uint256 _defaultRateChangeThreshold) external onlyOwner {
    _setDefaultRateChangeThreshold(_defaultRateChangeThreshold);
  }

  /**
   * @notice Configures rate feed to rate threshold pairs.
   * @param rateFeedIDs Collection of the addresses rate feeds.
   * @param rateChangeThresholds Collection of the rate thresholds.
   */
  function setRateChangeThresholds(address[] calldata rateFeedIDs, uint256[] calldata rateChangeThresholds)
    external
    onlyOwner
  {
    _setRateChangeThresholds(rateFeedIDs, rateChangeThresholds);
  }

  /**
   * @notice Sets the address of the sortedOracles contract.
   * @param _sortedOracles The new address of the sorted oracles contract.
   */
  function setSortedOracles(ISortedOracles _sortedOracles) public onlyOwner {
    require(address(_sortedOracles) != address(0), "SortedOracles address must be set");
    sortedOracles = _sortedOracles;
    emit SortedOraclesUpdated(address(_sortedOracles));
  }

  /* ==================== View Functions ==================== */

  /**
   * @notice  Check if the current median report rate for a rate feed change, relative
   *          to the last median report, is greater than the configured threshold.
   *          If the change is greater than the threshold the breaker will trip.
   * @param   rateFeedID The rate feed to be checked.
   * @return  triggerBreaker  A bool indicating whether or not this breaker
   *                          should be tripped for the rate feed.
   */
  function shouldTrigger(address rateFeedID) public returns (bool triggerBreaker) {
    (uint256 currentMedian, ) = sortedOracles.medianRate(rateFeedID);

    uint256 previousMedian = previousMedianRates[rateFeedID];
    previousMedianRates[rateFeedID] = currentMedian;

    if (previousMedian == 0) {
      // Previous median will be 0 the first time rate is checked.
      return false;
    }

    return exceedsThreshold(previousMedian, currentMedian, rateFeedID);
  }

  /**
   * @notice  Checks whether or not the conditions have been met
   *          for the specifed rate feed to be reset.
   * @return  resetBreaker A bool indicating whether or not
   *          this breaker can be reset for the given rate feed.
   */
  function shouldReset(address rateFeedID) external returns (bool resetBreaker) {
    return !shouldTrigger(rateFeedID);
  }
}
        

/lib/mento-core/contracts/common/FixidityLib.sol

pragma solidity ^0.5.13;

/**
 * @title FixidityLib
 * @author Gadi Guy, Alberto Cuesta Canada
 * @notice This library provides fixed point arithmetic with protection against
 * overflow.
 * All operations are done with uint256 and the operands must have been created
 * with any of the newFrom* functions, which shift the comma digits() to the
 * right and check for limits, or with wrap() which expects a number already
 * in the internal representation of a fraction.
 * When using this library be sure to use maxNewFixed() as the upper limit for
 * creation of fixed point numbers.
 * @dev All contained functions are pure and thus marked internal to be inlined
 * on consuming contracts at compile time for gas efficiency.
 */
library FixidityLib {
  struct Fraction {
    uint256 value;
  }

  /**
   * @notice Number of positions that the comma is shifted to the right.
   */
  function digits() internal pure returns (uint8) {
    return 24;
  }

  uint256 private constant FIXED1_UINT = 1000000000000000000000000;

  /**
   * @notice This is 1 in the fixed point units used in this library.
   * @dev Test fixed1() equals 10^digits()
   * Hardcoded to 24 digits.
   */
  function fixed1() internal pure returns (Fraction memory) {
    return Fraction(FIXED1_UINT);
  }

  /**
   * @notice Wrap a uint256 that represents a 24-decimal fraction in a Fraction
   * struct.
   * @param x Number that already represents a 24-decimal fraction.
   * @return A Fraction struct with contents x.
   */
  function wrap(uint256 x) internal pure returns (Fraction memory) {
    return Fraction(x);
  }

  /**
   * @notice Unwraps the uint256 inside of a Fraction struct.
   */
  function unwrap(Fraction memory x) internal pure returns (uint256) {
    return x.value;
  }

  /**
   * @notice The amount of decimals lost on each multiplication operand.
   * @dev Test mulPrecision() equals sqrt(fixed1)
   */
  function mulPrecision() internal pure returns (uint256) {
    return 1000000000000;
  }

  /**
   * @notice Maximum value that can be converted to fixed point. Optimize for deployment.
   * @dev
   * Test maxNewFixed() equals maxUint256() / fixed1()
   */
  function maxNewFixed() internal pure returns (uint256) {
    return 115792089237316195423570985008687907853269984665640564;
  }

  /**
   * @notice Converts a uint256 to fixed point Fraction
   * @dev Test newFixed(0) returns 0
   * Test newFixed(1) returns fixed1()
   * Test newFixed(maxNewFixed()) returns maxNewFixed() * fixed1()
   * Test newFixed(maxNewFixed()+1) fails
   */
  function newFixed(uint256 x) internal pure returns (Fraction memory) {
    require(x <= maxNewFixed(), "can't create fixidity number larger than maxNewFixed()");
    return Fraction(x * FIXED1_UINT);
  }

  /**
   * @notice Converts a uint256 in the fixed point representation of this
   * library to a non decimal. All decimal digits will be truncated.
   */
  function fromFixed(Fraction memory x) internal pure returns (uint256) {
    return x.value / FIXED1_UINT;
  }

  /**
   * @notice Converts two uint256 representing a fraction to fixed point units,
   * equivalent to multiplying dividend and divisor by 10^digits().
   * @param numerator numerator must be <= maxNewFixed()
   * @param denominator denominator must be <= maxNewFixed() and denominator can't be 0
   * @dev
   * Test newFixedFraction(1,0) fails
   * Test newFixedFraction(0,1) returns 0
   * Test newFixedFraction(1,1) returns fixed1()
   * Test newFixedFraction(1,fixed1()) returns 1
   */
  function newFixedFraction(uint256 numerator, uint256 denominator) internal pure returns (Fraction memory) {
    Fraction memory convertedNumerator = newFixed(numerator);
    Fraction memory convertedDenominator = newFixed(denominator);
    return divide(convertedNumerator, convertedDenominator);
  }

  /**
   * @notice Returns the integer part of a fixed point number.
   * @dev
   * Test integer(0) returns 0
   * Test integer(fixed1()) returns fixed1()
   * Test integer(newFixed(maxNewFixed())) returns maxNewFixed()*fixed1()
   */
  function integer(Fraction memory x) internal pure returns (Fraction memory) {
    return Fraction((x.value / FIXED1_UINT) * FIXED1_UINT); // Can't overflow
  }

  /**
   * @notice Returns the fractional part of a fixed point number.
   * In the case of a negative number the fractional is also negative.
   * @dev
   * Test fractional(0) returns 0
   * Test fractional(fixed1()) returns 0
   * Test fractional(fixed1()-1) returns 10^24-1
   */
  function fractional(Fraction memory x) internal pure returns (Fraction memory) {
    return Fraction(x.value - (x.value / FIXED1_UINT) * FIXED1_UINT); // Can't overflow
  }

  /**
   * @notice x+y.
   * @dev The maximum value that can be safely used as an addition operator is defined as
   * maxFixedAdd = maxUint256()-1 / 2, or
   * 57896044618658097711785492504343953926634992332820282019728792003956564819967.
   * Test add(maxFixedAdd,maxFixedAdd) equals maxFixedAdd + maxFixedAdd
   * Test add(maxFixedAdd+1,maxFixedAdd+1) throws
   */
  function add(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    uint256 z = x.value + y.value;
    require(z >= x.value, "add overflow detected");
    return Fraction(z);
  }

  /**
   * @notice x-y.
   * @dev
   * Test subtract(6, 10) fails
   */
  function subtract(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    require(x.value >= y.value, "substraction underflow detected");
    return Fraction(x.value - y.value);
  }

  /**
   * @notice x*y. If any of the operators is higher than the max multiplier value it
   * might overflow.
   * @dev The maximum value that can be safely used as a multiplication operator
   * (maxFixedMul) is calculated as sqrt(maxUint256()*fixed1()),
   * or 340282366920938463463374607431768211455999999999999
   * Test multiply(0,0) returns 0
   * Test multiply(maxFixedMul,0) returns 0
   * Test multiply(0,maxFixedMul) returns 0
   * Test multiply(fixed1()/mulPrecision(),fixed1()*mulPrecision()) returns fixed1()
   * Test multiply(maxFixedMul,maxFixedMul) is around maxUint256()
   * Test multiply(maxFixedMul+1,maxFixedMul+1) fails
   */
  // solhint-disable-next-line code-complexity
  function multiply(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    if (x.value == 0 || y.value == 0) return Fraction(0);
    if (y.value == FIXED1_UINT) return x;
    if (x.value == FIXED1_UINT) return y;

    // Separate into integer and fractional parts
    // x = x1 + x2, y = y1 + y2
    uint256 x1 = integer(x).value / FIXED1_UINT;
    uint256 x2 = fractional(x).value;
    uint256 y1 = integer(y).value / FIXED1_UINT;
    uint256 y2 = fractional(y).value;

    // (x1 + x2) * (y1 + y2) = (x1 * y1) + (x1 * y2) + (x2 * y1) + (x2 * y2)
    uint256 x1y1 = x1 * y1;
    if (x1 != 0) require(x1y1 / x1 == y1, "overflow x1y1 detected");

    // x1y1 needs to be multiplied back by fixed1
    // solhint-disable-next-line var-name-mixedcase
    uint256 fixed_x1y1 = x1y1 * FIXED1_UINT;
    if (x1y1 != 0) require(fixed_x1y1 / x1y1 == FIXED1_UINT, "overflow x1y1 * fixed1 detected");
    x1y1 = fixed_x1y1;

    uint256 x2y1 = x2 * y1;
    if (x2 != 0) require(x2y1 / x2 == y1, "overflow x2y1 detected");

    uint256 x1y2 = x1 * y2;
    if (x1 != 0) require(x1y2 / x1 == y2, "overflow x1y2 detected");

    x2 = x2 / mulPrecision();
    y2 = y2 / mulPrecision();
    uint256 x2y2 = x2 * y2;
    if (x2 != 0) require(x2y2 / x2 == y2, "overflow x2y2 detected");

    // result = fixed1() * x1 * y1 + x1 * y2 + x2 * y1 + x2 * y2 / fixed1();
    Fraction memory result = Fraction(x1y1);
    result = add(result, Fraction(x2y1)); // Add checks for overflow
    result = add(result, Fraction(x1y2)); // Add checks for overflow
    result = add(result, Fraction(x2y2)); // Add checks for overflow
    return result;
  }

  /**
   * @notice 1/x
   * @dev
   * Test reciprocal(0) fails
   * Test reciprocal(fixed1()) returns fixed1()
   * Test reciprocal(fixed1()*fixed1()) returns 1 // Testing how the fractional is truncated
   * Test reciprocal(1+fixed1()*fixed1()) returns 0 // Testing how the fractional is truncated
   * Test reciprocal(newFixedFraction(1, 1e24)) returns newFixed(1e24)
   */
  function reciprocal(Fraction memory x) internal pure returns (Fraction memory) {
    require(x.value != 0, "can't call reciprocal(0)");
    return Fraction((FIXED1_UINT * FIXED1_UINT) / x.value); // Can't overflow
  }

  /**
   * @notice x/y. If the dividend is higher than the max dividend value, it
   * might overflow. You can use multiply(x,reciprocal(y)) instead.
   * @dev The maximum value that can be safely used as a dividend (maxNewFixed) is defined as
   * divide(maxNewFixed,newFixedFraction(1,fixed1())) is around maxUint256().
   * This yields the value 115792089237316195423570985008687907853269984665640564.
   * Test maxNewFixed equals maxUint256()/fixed1()
   * Test divide(maxNewFixed,1) equals maxNewFixed*(fixed1)
   * Test divide(maxNewFixed+1,multiply(mulPrecision(),mulPrecision())) throws
   * Test divide(fixed1(),0) fails
   * Test divide(maxNewFixed,1) = maxNewFixed*(10^digits())
   * Test divide(maxNewFixed+1,1) throws
   */
  function divide(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    require(y.value != 0, "can't divide by 0");
    // solhint-disable-next-line var-name-mixedcase
    uint256 X = x.value * FIXED1_UINT;
    require(X / FIXED1_UINT == x.value, "overflow at divide");
    return Fraction(X / y.value);
  }

  /**
   * @notice x > y
   */
  function gt(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value > y.value;
  }

  /**
   * @notice x >= y
   */
  function gte(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value >= y.value;
  }

  /**
   * @notice x < y
   */
  function lt(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value < y.value;
  }

  /**
   * @notice x <= y
   */
  function lte(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value <= y.value;
  }

  /**
   * @notice x == y
   */
  function equals(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value == y.value;
  }

  /**
   * @notice x <= 1
   */
  function isProperFraction(Fraction memory x) internal pure returns (bool) {
    return lte(x, fixed1());
  }
}
          

/lib/mento-core/contracts/common/breakers/WithCooldown.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

/**
 * @title   Breaker With Cooldown
 * @notice  Utility portion of a Breaker contract which deals with the
 *          cooldown component.
 */
contract WithCooldown {
  /* ==================== Events ==================== */
  /**
   * @notice Emitted after the cooldownTime has been updated.
   * @param newCooldownTime The new cooldownTime of the breaker.
   */
  event DefaultCooldownTimeUpdated(uint256 newCooldownTime);

  /**
   * @notice Emitted after the cooldownTime has been updated.
   * @param rateFeedID The rateFeedID targeted.
   * @param newCooldownTime The new cooldownTime of the breaker.
   */
  event RateFeedCooldownTimeUpdated(address rateFeedID, uint256 newCooldownTime);

  /* ==================== State Variables ==================== */

  // The amount of time that must pass before the breaker can be reset for a rate feed.
  // Should be set to 0 to force a manual reset.
  uint256 public defaultCooldownTime;
  mapping(address => uint256) public rateFeedCooldownTime;

  /* ==================== View Functions ==================== */

  /**
   * @notice Get the cooldown time for a rateFeedID
   * @param rateFeedID the targeted rate feed.
   * @return the rate specific or default cooldown
   */
  function getCooldown(address rateFeedID) public view returns (uint256) {
    uint256 _rateFeedCooldownTime = rateFeedCooldownTime[rateFeedID];
    if (_rateFeedCooldownTime == 0) {
      return defaultCooldownTime;
    }
    return _rateFeedCooldownTime;
  }

  /* ==================== Internal Functions ==================== */

  /**
   * @notice Sets the cooldown time to the specified value for a rate feed.
   * @param rateFeedIDs the targeted rate feed.
   * @param cooldownTimes The new cooldownTime value.
   * @dev Should be set to 0 to force a manual reset.
   */
  function _setCooldownTimes(address[] memory rateFeedIDs, uint256[] memory cooldownTimes) internal {
    require(rateFeedIDs.length == cooldownTimes.length, "array length missmatch");
    for (uint256 i = 0; i < rateFeedIDs.length; i++) {
      require(rateFeedIDs[i] != address(0), "rate feed invalid");
      rateFeedCooldownTime[rateFeedIDs[i]] = cooldownTimes[i];
      emit RateFeedCooldownTimeUpdated(rateFeedIDs[i], cooldownTimes[i]);
    }
  }

  /**
   * @notice Sets the cooldownTime to the specified value for a rate feed.
   * @param cooldownTime The new cooldownTime value.
   * @dev Should be set to 0 to force a manual reset.
   */
  function _setDefaultCooldownTime(uint256 cooldownTime) internal {
    defaultCooldownTime = cooldownTime;
    emit DefaultCooldownTimeUpdated(cooldownTime);
  }
}
          

/lib/mento-core/contracts/common/breakers/WithThreshold.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import { FixidityLib } from "../FixidityLib.sol";
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
 * @title   Breaker With Thershold
 * @notice  Utility portion of a Breaker contract which deals with
 *          managing a threshold percentage and checking two values
 * .        against it.
 */
contract WithThreshold {
  using FixidityLib for FixidityLib.Fraction;
  using SafeMath for uint256;

  /* ==================== Events ==================== */

  // Emitted when the default rate threshold is updated.
  event DefaultRateChangeThresholdUpdated(uint256 defaultRateChangeThreshold);

  // Emitted when the rate threshold is updated.
  event RateChangeThresholdUpdated(address rateFeedID, uint256 rateChangeThreshold);

  /* ==================== State Variables ==================== */

  // The default allowed threshold for the median rate change as a Fixidity fraction.
  FixidityLib.Fraction public defaultRateChangeThreshold;

  // Maps rate feed to a threshold.
  mapping(address => FixidityLib.Fraction) public rateChangeThreshold;

  /* ==================== View Functions ==================== */

  /**
   * @notice Checks if a value is in a certain theshold of a given reference value.
   * @dev The reference value can be the previous median (MedianDeltaBreaker) or
   *      a static value (ValueDeltaBreaker), while the currentValue is usually
   *      the median after the most recent report.
   * @param referenceValue The reference value to check against.
   * @param currentValue The current value which is checked against the reference.
   * @param rateFeedID The specific rate ID to check threshold for.
   * @return  Returns a bool indicating whether or not the current rate
   *          is within the allowed threshold.
   */
  function exceedsThreshold(
    uint256 referenceValue,
    uint256 currentValue,
    address rateFeedID
  ) public view returns (bool) {
    uint256 allowedThreshold = defaultRateChangeThreshold.unwrap();
    uint256 rateSpecificThreshold = rateChangeThreshold[rateFeedID].unwrap();
    // checks if a given rate feed id has a threshold set and reassignes it
    if (rateSpecificThreshold != 0) allowedThreshold = rateSpecificThreshold;

    uint256 fixed1 = FixidityLib.fixed1().unwrap();

    uint256 maxPercent = uint256(fixed1).add(allowedThreshold);
    uint256 maxValue = (referenceValue.mul(maxPercent)).div(10**24);

    uint256 minPercent = uint256(fixed1).sub(allowedThreshold);
    uint256 minValue = (referenceValue.mul(minPercent)).div(10**24);

    return (currentValue < minValue || currentValue > maxValue);
  }

  /* ==================== Internal Functions ==================== */

  /**
   * @notice Sets rateChangeThreshold.
   * @param _defaultRateChangeThreshold The new rateChangeThreshold value.
   */
  function _setDefaultRateChangeThreshold(uint256 _defaultRateChangeThreshold) internal {
    defaultRateChangeThreshold = FixidityLib.wrap(_defaultRateChangeThreshold);
    require(defaultRateChangeThreshold.lt(FixidityLib.fixed1()), "value must be less than 1");
    emit DefaultRateChangeThresholdUpdated(_defaultRateChangeThreshold);
  }

  /**
   * @notice Configures rate feed to rate threshold pairs.
   * @param rateFeedIDs Collection of the addresses rate feeds.
   * @param rateChangeThresholds Collection of the rate thresholds.
   */
  function _setRateChangeThresholds(address[] memory rateFeedIDs, uint256[] memory rateChangeThresholds) internal {
    require(rateFeedIDs.length == rateChangeThresholds.length, "array length missmatch");
    for (uint256 i = 0; i < rateFeedIDs.length; i++) {
      require(rateFeedIDs[i] != address(0), "rate feed invalid");
      FixidityLib.Fraction memory _rateChangeThreshold = FixidityLib.wrap(rateChangeThresholds[i]);
      require(_rateChangeThreshold.lt(FixidityLib.fixed1()), "value must be less than 1");
      rateChangeThreshold[rateFeedIDs[i]] = _rateChangeThreshold;
      emit RateChangeThresholdUpdated(rateFeedIDs[i], rateChangeThresholds[i]);
    }
  }
}
          

/lib/mento-core/contracts/common/linkedlists/LinkedList.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
 * @title Maintains a doubly linked list keyed by bytes32.
 * @dev Following the `next` pointers will lead you to the head, rather than the tail.
 */
library LinkedList {
  using SafeMath for uint256;

  struct Element {
    bytes32 previousKey;
    bytes32 nextKey;
    bool exists;
  }

  struct List {
    bytes32 head;
    bytes32 tail;
    uint256 numElements;
    mapping(bytes32 => Element) elements;
  }

  /**
   * @notice Inserts an element into a doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   * @param previousKey The key of the element that comes before the element to insert.
   * @param nextKey The key of the element that comes after the element to insert.
   */
  function insert(
    List storage list,
    bytes32 key,
    bytes32 previousKey,
    bytes32 nextKey
  ) internal {
    require(key != bytes32(0), "Key must be defined");
    require(!contains(list, key), "Can't insert an existing element");
    require(previousKey != key && nextKey != key, "Key cannot be the same as previousKey or nextKey");

    Element storage element = list.elements[key];
    element.exists = true;

    if (list.numElements == 0) {
      list.tail = key;
      list.head = key;
    } else {
      require(previousKey != bytes32(0) || nextKey != bytes32(0), "Either previousKey or nextKey must be defined");

      element.previousKey = previousKey;
      element.nextKey = nextKey;

      if (previousKey != bytes32(0)) {
        require(contains(list, previousKey), "If previousKey is defined, it must exist in the list");
        Element storage previousElement = list.elements[previousKey];
        require(previousElement.nextKey == nextKey, "previousKey must be adjacent to nextKey");
        previousElement.nextKey = key;
      } else {
        list.tail = key;
      }

      if (nextKey != bytes32(0)) {
        require(contains(list, nextKey), "If nextKey is defined, it must exist in the list");
        Element storage nextElement = list.elements[nextKey];
        require(nextElement.previousKey == previousKey, "previousKey must be adjacent to nextKey");
        nextElement.previousKey = key;
      } else {
        list.head = key;
      }
    }

    list.numElements = list.numElements.add(1);
  }

  /**
   * @notice Inserts an element at the tail of the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   */
  function push(List storage list, bytes32 key) internal {
    insert(list, key, bytes32(0), list.tail);
  }

  /**
   * @notice Removes an element from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to remove.
   */
  function remove(List storage list, bytes32 key) internal {
    Element storage element = list.elements[key];
    require(key != bytes32(0) && contains(list, key), "key not in list");
    if (element.previousKey != bytes32(0)) {
      Element storage previousElement = list.elements[element.previousKey];
      previousElement.nextKey = element.nextKey;
    } else {
      list.tail = element.nextKey;
    }

    if (element.nextKey != bytes32(0)) {
      Element storage nextElement = list.elements[element.nextKey];
      nextElement.previousKey = element.previousKey;
    } else {
      list.head = element.previousKey;
    }

    delete list.elements[key];
    list.numElements = list.numElements.sub(1);
  }

  /**
   * @notice Updates an element in the list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @param previousKey The key of the element that comes before the updated element.
   * @param nextKey The key of the element that comes after the updated element.
   */
  function update(
    List storage list,
    bytes32 key,
    bytes32 previousKey,
    bytes32 nextKey
  ) internal {
    require(key != bytes32(0) && key != previousKey && key != nextKey && contains(list, key), "key on in list");
    remove(list, key);
    insert(list, key, previousKey, nextKey);
  }

  /**
   * @notice Returns whether or not a particular key is present in the sorted list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @return Whether or not the key is in the sorted list.
   */
  function contains(List storage list, bytes32 key) internal view returns (bool) {
    return list.elements[key].exists;
  }

  /**
   * @notice Returns the keys of the N elements at the head of the list.
   * @param list A storage pointer to the underlying list.
   * @param n The number of elements to return.
   * @return The keys of the N elements at the head of the list.
   * @dev Reverts if n is greater than the number of elements in the list.
   */
  function headN(List storage list, uint256 n) internal view returns (bytes32[] memory) {
    require(n <= list.numElements, "not enough elements");
    bytes32[] memory keys = new bytes32[](n);
    bytes32 key = list.head;
    for (uint256 i = 0; i < n; i = i.add(1)) {
      keys[i] = key;
      key = list.elements[key].previousKey;
    }
    return keys;
  }

  /**
   * @notice Gets all element keys from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @return All element keys from head to tail.
   */
  function getKeys(List storage list) internal view returns (bytes32[] memory) {
    return headN(list, list.numElements);
  }
}
          

/lib/mento-core/contracts/common/linkedlists/SortedLinkedList.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./LinkedList.sol";

/**
 * @title Maintains a sorted list of unsigned ints keyed by bytes32.
 */
library SortedLinkedList {
  using SafeMath for uint256;
  using LinkedList for LinkedList.List;

  struct List {
    LinkedList.List list;
    mapping(bytes32 => uint256) values;
  }

  /**
   * @notice Inserts an element into a doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   * @param value The element value.
   * @param lesserKey The key of the element less than the element to insert.
   * @param greaterKey The key of the element greater than the element to insert.
   */
  function insert(
    List storage list,
    bytes32 key,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) internal {
    require(key != bytes32(0) && key != lesserKey && key != greaterKey && !contains(list, key), "invalid key");
    require(
      (lesserKey != bytes32(0) || greaterKey != bytes32(0)) || list.list.numElements == 0,
      "greater and lesser key zero"
    );
    require(contains(list, lesserKey) || lesserKey == bytes32(0), "invalid lesser key");
    require(contains(list, greaterKey) || greaterKey == bytes32(0), "invalid greater key");
    (lesserKey, greaterKey) = getLesserAndGreater(list, value, lesserKey, greaterKey);
    list.list.insert(key, lesserKey, greaterKey);
    list.values[key] = value;
  }

  /**
   * @notice Removes an element from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to remove.
   */
  function remove(List storage list, bytes32 key) internal {
    list.list.remove(key);
    list.values[key] = 0;
  }

  /**
   * @notice Updates an element in the list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @param value The element value.
   * @param lesserKey The key of the element will be just left of `key` after the update.
   * @param greaterKey The key of the element will be just right of `key` after the update.
   * @dev Note that only one of "lesserKey" or "greaterKey" needs to be correct to reduce friction.
   */
  function update(
    List storage list,
    bytes32 key,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) internal {
    remove(list, key);
    insert(list, key, value, lesserKey, greaterKey);
  }

  /**
   * @notice Inserts an element at the tail of the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   */
  function push(List storage list, bytes32 key) internal {
    insert(list, key, 0, bytes32(0), list.list.tail);
  }

  /**
   * @notice Removes N elements from the head of the list and returns their keys.
   * @param list A storage pointer to the underlying list.
   * @param n The number of elements to pop.
   * @return The keys of the popped elements.
   */
  function popN(List storage list, uint256 n) internal returns (bytes32[] memory) {
    require(n <= list.list.numElements, "not enough elements");
    bytes32[] memory keys = new bytes32[](n);
    for (uint256 i = 0; i < n; i = i.add(1)) {
      bytes32 key = list.list.head;
      keys[i] = key;
      remove(list, key);
    }
    return keys;
  }

  /**
   * @notice Returns whether or not a particular key is present in the sorted list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @return Whether or not the key is in the sorted list.
   */
  function contains(List storage list, bytes32 key) internal view returns (bool) {
    return list.list.contains(key);
  }

  /**
   * @notice Returns the value for a particular key in the sorted list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @return The element value.
   */
  function getValue(List storage list, bytes32 key) internal view returns (uint256) {
    return list.values[key];
  }

  /**
   * @notice Gets all elements from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @return Array of all keys in the list.
   * @return Values corresponding to keys, which will be ordered largest to smallest.
   */
  function getElements(List storage list) internal view returns (bytes32[] memory, uint256[] memory) {
    bytes32[] memory keys = getKeys(list);
    uint256[] memory values = new uint256[](keys.length);
    for (uint256 i = 0; i < keys.length; i = i.add(1)) {
      values[i] = list.values[keys[i]];
    }
    return (keys, values);
  }

  /**
   * @notice Gets all element keys from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @return All element keys from head to tail.
   */
  function getKeys(List storage list) internal view returns (bytes32[] memory) {
    return list.list.getKeys();
  }

  /**
   * @notice Returns first N greatest elements of the list.
   * @param list A storage pointer to the underlying list.
   * @param n The number of elements to return.
   * @return The keys of the first n elements.
   * @dev Reverts if n is greater than the number of elements in the list.
   */
  function headN(List storage list, uint256 n) internal view returns (bytes32[] memory) {
    return list.list.headN(n);
  }

  /**
   * @notice Returns the keys of the elements greaterKey than and less than the provided value.
   * @param list A storage pointer to the underlying list.
   * @param value The element value.
   * @param lesserKey The key of the element which could be just left of the new value.
   * @param greaterKey The key of the element which could be just right of the new value.
   * @return The correct lesserKey keys.
   * @return The correct greaterKey keys.
   */
  function getLesserAndGreater(
    List storage list,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) private view returns (bytes32, bytes32) {
    // Check for one of the following conditions and fail if none are met:
    //   1. The value is less than the current lowest value
    //   2. The value is greater than the current greatest value
    //   3. The value is just greater than the value for `lesserKey`
    //   4. The value is just less than the value for `greaterKey`
    if (lesserKey == bytes32(0) && isValueBetween(list, value, lesserKey, list.list.tail)) {
      return (lesserKey, list.list.tail);
    } else if (greaterKey == bytes32(0) && isValueBetween(list, value, list.list.head, greaterKey)) {
      return (list.list.head, greaterKey);
    } else if (
      lesserKey != bytes32(0) && isValueBetween(list, value, lesserKey, list.list.elements[lesserKey].nextKey)
    ) {
      return (lesserKey, list.list.elements[lesserKey].nextKey);
    } else if (
      greaterKey != bytes32(0) && isValueBetween(list, value, list.list.elements[greaterKey].previousKey, greaterKey)
    ) {
      return (list.list.elements[greaterKey].previousKey, greaterKey);
    } else {
      require(false, "get lesser and greater failure");
    }
  }

  /**
   * @notice Returns whether or not a given element is between two other elements.
   * @param list A storage pointer to the underlying list.
   * @param value The element value.
   * @param lesserKey The key of the element whose value should be lesserKey.
   * @param greaterKey The key of the element whose value should be greaterKey.
   * @return True if the given element is between the two other elements.
   */
  function isValueBetween(
    List storage list,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) private view returns (bool) {
    bool isLesser = lesserKey == bytes32(0) || list.values[lesserKey] <= value;
    bool isGreater = greaterKey == bytes32(0) || list.values[greaterKey] >= value;
    return isLesser && isGreater;
  }
}
          

/lib/mento-core/contracts/common/linkedlists/SortedLinkedListWithMedian.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./LinkedList.sol";
import "./SortedLinkedList.sol";

/**
 * @title Maintains a sorted list of unsigned ints keyed by bytes32.
 */
library SortedLinkedListWithMedian {
  using SafeMath for uint256;
  using SortedLinkedList for SortedLinkedList.List;

  enum MedianAction {
    None,
    Lesser,
    Greater
  }

  enum MedianRelation {
    Undefined,
    Lesser,
    Greater,
    Equal
  }

  struct List {
    SortedLinkedList.List list;
    bytes32 median;
    mapping(bytes32 => MedianRelation) relation;
  }

  /**
   * @notice Inserts an element into a doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   * @param value The element value.
   * @param lesserKey The key of the element less than the element to insert.
   * @param greaterKey The key of the element greater than the element to insert.
   */
  function insert(
    List storage list,
    bytes32 key,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) internal {
    list.list.insert(key, value, lesserKey, greaterKey);
    LinkedList.Element storage element = list.list.list.elements[key];

    MedianAction action = MedianAction.None;
    if (list.list.list.numElements == 1) {
      list.median = key;
      list.relation[key] = MedianRelation.Equal;
    } else if (list.list.list.numElements % 2 == 1) {
      // When we have an odd number of elements, and the element that we inserted is less than
      // the previous median, we need to slide the median down one element, since we had previously
      // selected the greater of the two middle elements.
      if (element.previousKey == bytes32(0) || list.relation[element.previousKey] == MedianRelation.Lesser) {
        action = MedianAction.Lesser;
        list.relation[key] = MedianRelation.Lesser;
      } else {
        list.relation[key] = MedianRelation.Greater;
      }
    } else {
      // When we have an even number of elements, and the element that we inserted is greater than
      // the previous median, we need to slide the median up one element, since we always select
      // the greater of the two middle elements.
      if (element.nextKey == bytes32(0) || list.relation[element.nextKey] == MedianRelation.Greater) {
        action = MedianAction.Greater;
        list.relation[key] = MedianRelation.Greater;
      } else {
        list.relation[key] = MedianRelation.Lesser;
      }
    }
    updateMedian(list, action);
  }

  /**
   * @notice Removes an element from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to remove.
   */
  function remove(List storage list, bytes32 key) internal {
    MedianAction action = MedianAction.None;
    if (list.list.list.numElements == 0) {
      list.median = bytes32(0);
    } else if (list.list.list.numElements % 2 == 0) {
      // When we have an even number of elements, we always choose the higher of the two medians.
      // Thus, if the element we're removing is greaterKey than or equal to the median we need to
      // slide the median left by one.
      if (list.relation[key] == MedianRelation.Greater || list.relation[key] == MedianRelation.Equal) {
        action = MedianAction.Lesser;
      }
    } else {
      // When we don't have an even number of elements, we just choose the median value.
      // Thus, if the element we're removing is less than or equal to the median, we need to slide
      // median right by one.
      if (list.relation[key] == MedianRelation.Lesser || list.relation[key] == MedianRelation.Equal) {
        action = MedianAction.Greater;
      }
    }
    updateMedian(list, action);

    list.list.remove(key);
  }

  /**
   * @notice Updates an element in the list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @param value The element value.
   * @param lesserKey The key of the element will be just left of `key` after the update.
   * @param greaterKey The key of the element will be just right of `key` after the update.
   * @dev Note that only one of "lesserKey" or "greaterKey" needs to be correct to reduce friction.
   */
  function update(
    List storage list,
    bytes32 key,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) internal {
    remove(list, key);
    insert(list, key, value, lesserKey, greaterKey);
  }

  /**
   * @notice Inserts an element at the tail of the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @param key The key of the element to insert.
   */
  function push(List storage list, bytes32 key) internal {
    insert(list, key, 0, bytes32(0), list.list.list.tail);
  }

  /**
   * @notice Removes N elements from the head of the list and returns their keys.
   * @param list A storage pointer to the underlying list.
   * @param n The number of elements to pop.
   * @return The keys of the popped elements.
   */
  function popN(List storage list, uint256 n) internal returns (bytes32[] memory) {
    require(n <= list.list.list.numElements, "not enough elements");
    bytes32[] memory keys = new bytes32[](n);
    for (uint256 i = 0; i < n; i = i.add(1)) {
      bytes32 key = list.list.list.head;
      keys[i] = key;
      remove(list, key);
    }
    return keys;
  }

  /**
   * @notice Returns whether or not a particular key is present in the sorted list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @return Whether or not the key is in the sorted list.
   */
  function contains(List storage list, bytes32 key) internal view returns (bool) {
    return list.list.contains(key);
  }

  /**
   * @notice Returns the value for a particular key in the sorted list.
   * @param list A storage pointer to the underlying list.
   * @param key The element key.
   * @return The element value.
   */
  function getValue(List storage list, bytes32 key) internal view returns (uint256) {
    return list.list.values[key];
  }

  /**
   * @notice Returns the median value of the sorted list.
   * @param list A storage pointer to the underlying list.
   * @return The median value.
   */
  function getMedianValue(List storage list) internal view returns (uint256) {
    return getValue(list, list.median);
  }

  /**
   * @notice Returns the key of the first element in the list.
   * @param list A storage pointer to the underlying list.
   * @return The key of the first element in the list.
   */
  function getHead(List storage list) internal view returns (bytes32) {
    return list.list.list.head;
  }

  /**
   * @notice Returns the key of the median element in the list.
   * @param list A storage pointer to the underlying list.
   * @return The key of the median element in the list.
   */
  function getMedian(List storage list) internal view returns (bytes32) {
    return list.median;
  }

  /**
   * @notice Returns the key of the last element in the list.
   * @param list A storage pointer to the underlying list.
   * @return The key of the last element in the list.
   */
  function getTail(List storage list) internal view returns (bytes32) {
    return list.list.list.tail;
  }

  /**
   * @notice Returns the number of elements in the list.
   * @param list A storage pointer to the underlying list.
   * @return The number of elements in the list.
   */
  function getNumElements(List storage list) internal view returns (uint256) {
    return list.list.list.numElements;
  }

  /**
   * @notice Gets all elements from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @return Array of all keys in the list.
   * @return Values corresponding to keys, which will be ordered largest to smallest.
   * @return Array of relations to median of corresponding list elements.
   */
  function getElements(List storage list)
    internal
    view
    returns (
      bytes32[] memory,
      uint256[] memory,
      MedianRelation[] memory
    )
  {
    bytes32[] memory keys = getKeys(list);
    uint256[] memory values = new uint256[](keys.length);
    MedianRelation[] memory relations = new MedianRelation[](keys.length);
    for (uint256 i = 0; i < keys.length; i = i.add(1)) {
      values[i] = list.list.values[keys[i]];
      relations[i] = list.relation[keys[i]];
    }
    return (keys, values, relations);
  }

  /**
   * @notice Gets all element keys from the doubly linked list.
   * @param list A storage pointer to the underlying list.
   * @return All element keys from head to tail.
   */
  function getKeys(List storage list) internal view returns (bytes32[] memory) {
    return list.list.getKeys();
  }

  /**
   * @notice Moves the median pointer right or left of its current value.
   * @param list A storage pointer to the underlying list.
   * @param action Which direction to move the median pointer.
   */
  function updateMedian(List storage list, MedianAction action) private {
    LinkedList.Element storage previousMedian = list.list.list.elements[list.median];
    if (action == MedianAction.Lesser) {
      list.relation[list.median] = MedianRelation.Greater;
      list.median = previousMedian.previousKey;
    } else if (action == MedianAction.Greater) {
      list.relation[list.median] = MedianRelation.Lesser;
      list.median = previousMedian.nextKey;
    }
    list.relation[list.median] = MedianRelation.Equal;
  }
}
          

/lib/mento-core/contracts/interfaces/IBreaker.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

/**
 * @title Breaker Interface
 * @notice Defines the basic interface for a Breaker
 */
interface IBreaker {
  /**
   * @notice Emitted when the sortedOracles address is updated.
   * @param newSortedOracles The address of the new sortedOracles.
   */
  event SortedOraclesUpdated(address newSortedOracles);

  /**
   * @notice Retrieve the cooldown time for the breaker.
   * @param rateFeedID The rate feed to get the cooldown for
   * @return cooldown The amount of time that must pass before the breaker can reset.
   * @dev when cooldown is 0 auto reset will not be attempted.
   */
  function getCooldown(address rateFeedID) external view returns (uint256 cooldown);

  /**
   * @notice Check if the criteria have been met, by a specified rateFeedID, to trigger the breaker.
   * @param rateFeedID The address of the rate feed to run the check against.
   * @return triggerBreaker A boolean indicating whether or not the breaker
   *                        should be triggered for the given rate feed.
   */
  function shouldTrigger(address rateFeedID) external returns (bool triggerBreaker);

  /**
   * @notice Check if the criteria to automatically reset the breaker have been met.
   * @param rateFeedID The address of rate feed the criteria should be checked against.
   * @return resetBreaker A boolean indicating whether the breaker
   *                      should be reset for the given rate feed.
   * @dev Allows the definition of additional critera to check before reset.
   *      If no additional criteria is needed set to !shouldTrigger();
   */
  function shouldReset(address rateFeedID) external returns (bool resetBreaker);
}
          

/lib/mento-core/contracts/interfaces/ISortedOracles.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

import "../common/linkedlists/SortedLinkedListWithMedian.sol";

interface ISortedOracles {
  function addOracle(address, address) external;

  function removeOracle(
    address,
    address,
    uint256
  ) external;

  function report(
    address,
    uint256,
    address,
    address
  ) external;

  function removeExpiredReports(address, uint256) external;

  function isOldestReportExpired(address token) external view returns (bool, address);

  function numRates(address) external view returns (uint256);

  function medianRate(address) external view returns (uint256, uint256);

  function numTimestamps(address) external view returns (uint256);

  function medianTimestamp(address) external view returns (uint256);

  function getOracles(address) external view returns (address[] memory);

  function getTimestamps(address token)
    external
    view
    returns (
      address[] memory,
      uint256[] memory,
      SortedLinkedListWithMedian.MedianRelation[] memory
    );
}
          

/lib/mento-core/lib/openzeppelin-contracts/contracts/GSN/Context.sol

pragma solidity ^0.5.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
contract Context {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.
    constructor () internal { }
    // solhint-disable-previous-line no-empty-blocks

    function _msgSender() internal view returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
          

/lib/mento-core/lib/openzeppelin-contracts/contracts/math/SafeMath.sol

pragma solidity ^0.5.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when 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.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     *
     * _Available since v2.4.0._
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}
          

/lib/mento-core/lib/openzeppelin-contracts/contracts/ownership/Ownable.sol

pragma solidity ^0.5.0;

import "../GSN/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return _msgSender() == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
          

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[{"type":"uint256","name":"_defaultCooldownTime","internalType":"uint256"},{"type":"uint256","name":"_defaultRateChangeThreshold","internalType":"uint256"},{"type":"address","name":"_sortedOracles","internalType":"contract ISortedOracles"},{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"rateChangeThresholds","internalType":"uint256[]"},{"type":"uint256[]","name":"cooldownTimes","internalType":"uint256[]"}]},{"type":"event","name":"DefaultCooldownTimeUpdated","inputs":[{"type":"uint256","name":"newCooldownTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"DefaultRateChangeThresholdUpdated","inputs":[{"type":"uint256","name":"defaultRateChangeThreshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RateChangeThresholdUpdated","inputs":[{"type":"address","name":"rateFeedID","internalType":"address","indexed":false},{"type":"uint256","name":"rateChangeThreshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RateFeedCooldownTimeUpdated","inputs":[{"type":"address","name":"rateFeedID","internalType":"address","indexed":false},{"type":"uint256","name":"newCooldownTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"SortedOraclesUpdated","inputs":[{"type":"address","name":"newSortedOracles","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"defaultCooldownTime","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"value","internalType":"uint256"}],"name":"defaultRateChangeThreshold","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"exceedsThreshold","inputs":[{"type":"uint256","name":"referenceValue","internalType":"uint256"},{"type":"uint256","name":"currentValue","internalType":"uint256"},{"type":"address","name":"rateFeedID","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getCooldown","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOwner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"previousMedianRates","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"value","internalType":"uint256"}],"name":"rateChangeThreshold","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rateFeedCooldownTime","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"renounceOwnership","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setCooldownTime","inputs":[{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"cooldownTimes","internalType":"uint256[]"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setDefaultCooldownTime","inputs":[{"type":"uint256","name":"cooldownTime","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setDefaultRateChangeThreshold","inputs":[{"type":"uint256","name":"_defaultRateChangeThreshold","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setRateChangeThresholds","inputs":[{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"rateChangeThresholds","internalType":"uint256[]"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setSortedOracles","inputs":[{"type":"address","name":"_sortedOracles","internalType":"contract ISortedOracles"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"resetBreaker","internalType":"bool"}],"name":"shouldReset","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"triggerBreaker","internalType":"bool"}],"name":"shouldTrigger","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract ISortedOracles"}],"name":"sortedOracles","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}],"constant":false}]
              

Contract Creation Code

0x60806040523480156200001157600080fd5b50604051620020e2380380620020e2833981810160405260c08110156200003757600080fd5b8151602083015160408085015160608601805192519496939591949391820192846401000000008211156200006b57600080fd5b9083019060208201858111156200008157600080fd5b82518660208202830111640100000000821117156200009f57600080fd5b82525081516020918201928201910280838360005b83811015620000ce578181015183820152602001620000b4565b5050505090500160405260200180516040519392919084640100000000821115620000f857600080fd5b9083019060208201858111156200010e57600080fd5b82518660208202830111640100000000821117156200012c57600080fd5b82525081516020918201928201910280838360005b838110156200015b57818101518382015260200162000141565b50505050905001604052602001805160405193929190846401000000008211156200018557600080fd5b9083019060208201858111156200019b57600080fd5b8251866020820283011164010000000082111715620001b957600080fd5b82525081516020918201928201910280838360005b83811015620001e8578181015183820152602001620001ce565b50505050905001604052505050600062000207620002ca60201b60201c565b600480546001600160a01b0319166001600160a01b03831690811790915560405191925090600090600080516020620020a1833981519152908290a35062000258336001600160e01b03620002ce16565b6200026c846001600160e01b036200036016565b62000280866001600160e01b036200046016565b62000294856001600160e01b036200049b16565b620002a983836001600160e01b036200057916565b620002be83826001600160e01b03620007c716565b505050505050620009f1565b3390565b6001600160a01b038116620003155760405162461bcd60e51b81526004018080602001828103825260268152602001806200207b6026913960400191505060405180910390fd5b6004546040516001600160a01b03808416921690600080516020620020a183398151915290600090a3600480546001600160a01b0319166001600160a01b0392909216919091179055565b620003736001600160e01b036200096416565b620003c5576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166200040c5760405162461bcd60e51b8152600401808060200182810382526021815260200180620020c16021913960400191505060405180910390fd5b600580546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b620004b1816200099560201b620014ad1760201c565b51600255620004f1620004cf620009b1602090811b6200126517901c565b60408051602080820190925260025481529190620014c7620009d7821b17901c565b62000543576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b8051825114620005d0576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015620007c25760006001600160a01b0316838281518110620005f557fe5b60200260200101516001600160a01b031614156200064e576040805162461bcd60e51b81526020600482015260116024820152701c985d194819995959081a5b9d985b1a59607a1b604482015290519081900360640190fd5b62000658620009de565b620006828383815181106200066957fe5b60200260200101516200099560201b620014ad1760201c565b9050620006b26200069d620009b160201b620012651760201c565b82620009d760201b620014c71790919060201c565b62000704576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b80600360008685815181106200071657fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a3398483815181106200077957fe5b60200260200101518484815181106200078e57fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a150600101620005d3565b505050565b80518251146200081e576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015620007c25760006001600160a01b03168382815181106200084357fe5b60200260200101516001600160a01b031614156200089c576040805162461bcd60e51b81526020600482015260116024820152701c985d194819995959081a5b9d985b1a59607a1b604482015290519081900360640190fd5b818181518110620008a957fe5b602002602001015160016000858481518110620008c257fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c8382815181106200091c57fe5b60200260200101518383815181106200093157fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a160010162000821565b6004546000906001600160a01b0316620009866001600160e01b03620002ca16565b6001600160a01b031614905090565b6200099f620009de565b50604080516020810190915290815290565b620009bb620009de565b50604080516020810190915269d3c21bcecceda1000000815290565b5190511090565b6040518060200160405280600081525090565b61167a8062000a016000396000f3fe608060405234801561001057600080fd5b50600436106101515760003560e01c80635ac3ff70116100cd5780638da5cb5b11610081578063a44235cb11610066578063a44235cb146104fe578063f2fde38b14610506578063fd165f531461053957610151565b80638da5cb5b146104ee5780638f32d59b146104f657610151565b8063715018a6116100b2578063715018a614610474578063753d8c2f1461047c5780637dffc308146104bb57610151565b80635ac3ff701461041057806368b89d581461042d57610151565b80632e37ff73116101245780634afb215e116101095780634afb215e146102e85780634e510e881461031b57806353f5d6f1146103dd57610151565b80632e37ff73146102ad57806339b84ecf146102b557610151565b8063020323dd1461015657806305e047851461021a578063132e8aa7146102375780631893304f14610268575b600080fd5b6102186004803603604081101561016c57600080fd5b81019060208101813564010000000081111561018757600080fd5b82018360208201111561019957600080fd5b803590602001918460208302840111640100000000831117156101bb57600080fd5b9193909290916020810190356401000000008111156101d957600080fd5b8201836020820111156101eb57600080fd5b8035906020019184602083028401116401000000008311171561020d57600080fd5b50909250905061056c565b005b6102186004803603602081101561023057600080fd5b5035610638565b61023f61069d565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61029b6004803603602081101561027e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106b9565b60408051918252519081900360200190f35b61029b6106cb565b61029b600480360360208110156102cb57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106d1565b610218600480360360208110156102fe57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661070e565b6102186004803603604081101561033157600080fd5b81019060208101813564010000000081111561034c57600080fd5b82018360208201111561035e57600080fd5b8035906020019184602083028401116401000000008311171561038057600080fd5b91939092909160208101903564010000000081111561039e57600080fd5b8201836020820111156103b057600080fd5b803590602001918460208302840111640100000000831117156103d257600080fd5b509092509050610832565b61029b600480360360208110156103f357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166108f8565b6102186004803603602081101561042657600080fd5b503561090a565b6104606004803603602081101561044357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661096c565b604080519115158252519081900360200190f35b61021861097e565b6104606004803603606081101561049257600080fd5b508035906020810135906040013573ffffffffffffffffffffffffffffffffffffffff16610a46565b61029b600480360360208110156104d157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610b58565b61023f610b6a565b610460610b86565b61029b610bc6565b6102186004803603602081101561051c57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610bcc565b6104606004803603602081101561054f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610c2e565b610574610b86565b6105c5576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61063284848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808802828101820190935287825290935087925086918291850190849080828437600092019190915250610d1e92505050565b50505050565b610640610b86565b610691576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a81610f8a565b50565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60036020526000908152604090205481565b60005481565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604081205480610706575050600054610709565b90505b919050565b610716610b86565b610767576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166107b95760405162461bcd60e51b81526004018080602001828103825260218152602001806116256021913960400191505060405180910390fd5b6005805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b61083a610b86565b61088b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106328484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505060408051602080880282810182019093528782529093508792508691829185019084908082843760009201919091525061104592505050565b60016020526000908152604090205481565b610912610b86565b610963576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a81611226565b600061097782610c2e565b1592915050565b610986610b86565b6109d7576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60045460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b604080516020810190915260025481526000908190610a6490611261565b73ffffffffffffffffffffffffffffffffffffffff84166000908152600360209081526040808320815192830190915254815291925090610aa490611261565b90508015610ab0578091505b6000610ac2610abd611265565b611261565b90506000610ad6828563ffffffff61128916565b90506000610b0469d3c21bcecceda1000000610af88b8563ffffffff6112ec16565b9063ffffffff61134516565b90506000610b18848763ffffffff61138716565b90506000610b3a69d3c21bcecceda1000000610af88d8563ffffffff6112ec16565b9050808a1080610b495750828a115b9b9a5050505050505050505050565b60066020526000908152604090205481565b60045473ffffffffffffffffffffffffffffffffffffffff1690565b60045460009073ffffffffffffffffffffffffffffffffffffffff16610baa6113c9565b73ffffffffffffffffffffffffffffffffffffffff1614905090565b60025481565b610bd4610b86565b610c25576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a816113cd565b600554604080517fef90e1b000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528251600094859492169263ef90e1b0926024808301939192829003018186803b158015610ca157600080fd5b505afa158015610cb5573d6000803e3d6000fd5b505050506040513d6040811015610ccb57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff8416600090815260066020526040902080549082905590915080610d0b57600092505050610709565b610d16818386610a46565b949350505050565b8051825114610d74576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015610f8557600073ffffffffffffffffffffffffffffffffffffffff16838281518110610da457fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff161415610e15576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b610e1d6115ca565b610e39838381518110610e2c57fe5b60200260200101516114ad565b9050610e53610e46611265565b829063ffffffff6114c716565b610ea4576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b8060036000868581518110610eb557fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a339848381518110610f3157fe5b6020026020010151848481518110610f4557fe5b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff9094168452918301528051918290030190a150600101610d77565b505050565b610f93816114ad565b51600255610fbe610fa2611265565b604080516020810190915260025481529063ffffffff6114c716565b61100f576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b805182511461109b576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015610f8557600073ffffffffffffffffffffffffffffffffffffffff168382815181106110cb57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16141561113c576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b81818151811061114857fe5b60200260200101516001600085848151811061116057fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c8382815181106111d357fe5b60200260200101518383815181106111e757fe5b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff9094168452918301528051918290030190a160010161109e565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b5190565b61126d6115ca565b50604080516020810190915269d3c21bcecceda1000000815290565b6000828201838110156112e3576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000826112fb575060006112e6565b8282028284828161130857fe5b04146112e35760405162461bcd60e51b81526004018080602001828103825260218152602001806116046021913960400191505060405180910390fd5b60006112e383836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506114ce565b60006112e383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611570565b3390565b73ffffffffffffffffffffffffffffffffffffffff811661141f5760405162461bcd60e51b81526004018080602001828103825260268152602001806115de6026913960400191505060405180910390fd5b60045460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6114b56115ca565b50604080516020810190915290815290565b5190511090565b6000818361155a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561151f578181015183820152602001611507565b50505050905090810190601f16801561154c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161156657fe5b0495945050505050565b600081848411156115c25760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561151f578181015183820152602001611507565b505050900390565b604051806020016040528060008152509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77536f727465644f7261636c65732061646472657373206d75737420626520736574a265627a7a723158207d416410a53062143620a7540590449d2d2dc7004d028d71fa902976f7109f4064736f6c634300051100324f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573738be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0536f727465644f7261636c65732061646472657373206d7573742062652073657400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000efb84935239dacdecf7c5ba76d8de40b077b7b3300000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106101515760003560e01c80635ac3ff70116100cd5780638da5cb5b11610081578063a44235cb11610066578063a44235cb146104fe578063f2fde38b14610506578063fd165f531461053957610151565b80638da5cb5b146104ee5780638f32d59b146104f657610151565b8063715018a6116100b2578063715018a614610474578063753d8c2f1461047c5780637dffc308146104bb57610151565b80635ac3ff701461041057806368b89d581461042d57610151565b80632e37ff73116101245780634afb215e116101095780634afb215e146102e85780634e510e881461031b57806353f5d6f1146103dd57610151565b80632e37ff73146102ad57806339b84ecf146102b557610151565b8063020323dd1461015657806305e047851461021a578063132e8aa7146102375780631893304f14610268575b600080fd5b6102186004803603604081101561016c57600080fd5b81019060208101813564010000000081111561018757600080fd5b82018360208201111561019957600080fd5b803590602001918460208302840111640100000000831117156101bb57600080fd5b9193909290916020810190356401000000008111156101d957600080fd5b8201836020820111156101eb57600080fd5b8035906020019184602083028401116401000000008311171561020d57600080fd5b50909250905061056c565b005b6102186004803603602081101561023057600080fd5b5035610638565b61023f61069d565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61029b6004803603602081101561027e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106b9565b60408051918252519081900360200190f35b61029b6106cb565b61029b600480360360208110156102cb57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106d1565b610218600480360360208110156102fe57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661070e565b6102186004803603604081101561033157600080fd5b81019060208101813564010000000081111561034c57600080fd5b82018360208201111561035e57600080fd5b8035906020019184602083028401116401000000008311171561038057600080fd5b91939092909160208101903564010000000081111561039e57600080fd5b8201836020820111156103b057600080fd5b803590602001918460208302840111640100000000831117156103d257600080fd5b509092509050610832565b61029b600480360360208110156103f357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166108f8565b6102186004803603602081101561042657600080fd5b503561090a565b6104606004803603602081101561044357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661096c565b604080519115158252519081900360200190f35b61021861097e565b6104606004803603606081101561049257600080fd5b508035906020810135906040013573ffffffffffffffffffffffffffffffffffffffff16610a46565b61029b600480360360208110156104d157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610b58565b61023f610b6a565b610460610b86565b61029b610bc6565b6102186004803603602081101561051c57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610bcc565b6104606004803603602081101561054f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610c2e565b610574610b86565b6105c5576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61063284848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808802828101820190935287825290935087925086918291850190849080828437600092019190915250610d1e92505050565b50505050565b610640610b86565b610691576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a81610f8a565b50565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60036020526000908152604090205481565b60005481565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604081205480610706575050600054610709565b90505b919050565b610716610b86565b610767576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166107b95760405162461bcd60e51b81526004018080602001828103825260218152602001806116256021913960400191505060405180910390fd5b6005805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b61083a610b86565b61088b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106328484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505060408051602080880282810182019093528782529093508792508691829185019084908082843760009201919091525061104592505050565b60016020526000908152604090205481565b610912610b86565b610963576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a81611226565b600061097782610c2e565b1592915050565b610986610b86565b6109d7576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60045460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b604080516020810190915260025481526000908190610a6490611261565b73ffffffffffffffffffffffffffffffffffffffff84166000908152600360209081526040808320815192830190915254815291925090610aa490611261565b90508015610ab0578091505b6000610ac2610abd611265565b611261565b90506000610ad6828563ffffffff61128916565b90506000610b0469d3c21bcecceda1000000610af88b8563ffffffff6112ec16565b9063ffffffff61134516565b90506000610b18848763ffffffff61138716565b90506000610b3a69d3c21bcecceda1000000610af88d8563ffffffff6112ec16565b9050808a1080610b495750828a115b9b9a5050505050505050505050565b60066020526000908152604090205481565b60045473ffffffffffffffffffffffffffffffffffffffff1690565b60045460009073ffffffffffffffffffffffffffffffffffffffff16610baa6113c9565b73ffffffffffffffffffffffffffffffffffffffff1614905090565b60025481565b610bd4610b86565b610c25576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61069a816113cd565b600554604080517fef90e1b000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528251600094859492169263ef90e1b0926024808301939192829003018186803b158015610ca157600080fd5b505afa158015610cb5573d6000803e3d6000fd5b505050506040513d6040811015610ccb57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff8416600090815260066020526040902080549082905590915080610d0b57600092505050610709565b610d16818386610a46565b949350505050565b8051825114610d74576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015610f8557600073ffffffffffffffffffffffffffffffffffffffff16838281518110610da457fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff161415610e15576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b610e1d6115ca565b610e39838381518110610e2c57fe5b60200260200101516114ad565b9050610e53610e46611265565b829063ffffffff6114c716565b610ea4576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b8060036000868581518110610eb557fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a339848381518110610f3157fe5b6020026020010151848481518110610f4557fe5b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff9094168452918301528051918290030190a150600101610d77565b505050565b610f93816114ad565b51600255610fbe610fa2611265565b604080516020810190915260025481529063ffffffff6114c716565b61100f576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b805182511461109b576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015610f8557600073ffffffffffffffffffffffffffffffffffffffff168382815181106110cb57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16141561113c576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b81818151811061114857fe5b60200260200101516001600085848151811061116057fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c8382815181106111d357fe5b60200260200101518383815181106111e757fe5b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff9094168452918301528051918290030190a160010161109e565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b5190565b61126d6115ca565b50604080516020810190915269d3c21bcecceda1000000815290565b6000828201838110156112e3576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000826112fb575060006112e6565b8282028284828161130857fe5b04146112e35760405162461bcd60e51b81526004018080602001828103825260218152602001806116046021913960400191505060405180910390fd5b60006112e383836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506114ce565b60006112e383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611570565b3390565b73ffffffffffffffffffffffffffffffffffffffff811661141f5760405162461bcd60e51b81526004018080602001828103825260268152602001806115de6026913960400191505060405180910390fd5b60045460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6114b56115ca565b50604080516020810190915290815290565b5190511090565b6000818361155a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561151f578181015183820152602001611507565b50505050905090810190601f16801561154c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161156657fe5b0495945050505050565b600081848411156115c25760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561151f578181015183820152602001611507565b505050900390565b604051806020016040528060008152509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77536f727465644f7261636c65732061646472657373206d75737420626520736574a265627a7a723158207d416410a53062143620a7540590449d2d2dc7004d028d71fa902976f7109f4064736f6c63430005110032

External libraries

AddressLinkedList : 0x6200f54d73491d56b8d7a975c9ee18efb4d518df  
AddressSortedLinkedListWithMedian : 0xed477a99035d0c1e11369f1d7a4e587893cc002b