Address Details
contract

0xE0023406f56B58F9Df998495050CC5CAcfD4b3F9

Contract Name
SortedOracles
Creator
0x56fd3f–9b8d81 at 0xe40a43–bad4cc
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
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
21371662
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
SortedOracles




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




Optimization runs
10000
EVM Version
istanbul




Verified at
2023-03-10T07:02:30.468966Z

lib/mento-core/contracts/SortedOracles.sol

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

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

import "./interfaces/ISortedOracles.sol";
import "./common/interfaces/ICeloVersionedContract.sol";
import "./interfaces/IBreakerBox.sol";

import "./common/FixidityLib.sol";
import "./common/Initializable.sol";
import "./common/linkedlists/AddressSortedLinkedListWithMedian.sol";
import "./common/linkedlists/SortedLinkedListWithMedian.sol";

/**
 * @title   SortedOracles
 *
 * @notice  This contract stores a collection of exchange rate reports between mento
 *          collateral assets and other currencies. The most recent exchange rates
 *          are gathered off-chain by oracles, who then use the `report` function to
 *          submit the rates to this contract. Before submitting a rate report, an
 *          oracle's address must be added to the `isOracle` mapping for a specific
 *          rateFeedId, with the flag set to true. While submitting a report requires
 *          an address to be added to the mapping, no additional permissions are needed
 *          to read the reports, the calculated median rate, or the list of oracles.
 *
 * @dev     A unique rateFeedId identifies each exchange rate. In the initial implementation
 *          of this contract, the rateFeedId was set as the address of the mento stable
 *          asset contract that used the rate. However, this implementation has since
 *          been updated, and the rateFeedId now refers to an address derived from the
 *          concatenation of the mento collateral asset and the currency symbols' hash.
 *          This change enables the contract to store multiple exchange rates for a
 *          single stable asset. As a result of this change, there may be instances
 *          where the term "token" is used in the contract code. These useages of the term
 *          "token" are actually referring to the rateFeedId. You can refer to the Mento
 *          protocol documentation to learn more about the rateFeedId and how it is derived.
 *
 */
contract SortedOracles is ISortedOracles, ICeloVersionedContract, Ownable, Initializable {
  using SafeMath for uint256;
  using AddressSortedLinkedListWithMedian for SortedLinkedListWithMedian.List;
  using FixidityLib for FixidityLib.Fraction;

  uint256 private constant FIXED1_UINT = 1e24;

  // Maps a rateFeedID to a sorted list of report values.
  mapping(address => SortedLinkedListWithMedian.List) private rates;
  // Maps a rateFeedID to a sorted list of report timestamps.
  mapping(address => SortedLinkedListWithMedian.List) private timestamps;
  mapping(address => mapping(address => bool)) public isOracle;
  mapping(address => address[]) public oracles;

  // `reportExpirySeconds` is the fallback value used to determine reporting
  // frequency. Initially it was the _only_ value but we later introduced
  // the per token mapping in `tokenReportExpirySeconds`. If a token
  // doesn't have a value in the mapping (i.e. it's 0), the fallback is used.
  // See: #getTokenReportExpirySeconds
  uint256 public reportExpirySeconds;
  // Maps a rateFeedId to its report expiry time in seconds.
  mapping(address => uint256) public tokenReportExpirySeconds;

  IBreakerBox public breakerBox;

  event OracleAdded(address indexed token, address indexed oracleAddress);
  event OracleRemoved(address indexed token, address indexed oracleAddress);
  event OracleReported(address indexed token, address indexed oracle, uint256 timestamp, uint256 value);
  event OracleReportRemoved(address indexed token, address indexed oracle);
  event MedianUpdated(address indexed token, uint256 value);
  event ReportExpirySet(uint256 reportExpiry);
  event TokenReportExpirySet(address token, uint256 reportExpiry);
  event BreakerBoxUpdated(address indexed newBreakerBox);

  modifier onlyOracle(address token) {
    require(isOracle[token][msg.sender], "sender was not an oracle for token addr");
    _;
  }

  /**
   * @notice Returns the storage, major, minor, and patch version of the contract.
   * @return Storage version of the contract.
   * @return Major version of the contract.
   * @return Minor version of the contract.
   * @return Patch version of the contract.
   */
  function getVersionNumber()
    external
    pure
    returns (
      uint256,
      uint256,
      uint256,
      uint256
    )
  {
    return (1, 1, 2, 1);
  }

  /**
   * @notice Sets initialized == true on implementation contracts
   * @param test Set to true to skip implementation initialization
   */
  constructor(bool test) public Initializable(test) {}

  /**
   * @notice Used in place of the constructor to allow the contract to be upgradable via proxy.
   * @param _reportExpirySeconds The number of seconds before a report is considered expired.
   */
  function initialize(uint256 _reportExpirySeconds) external initializer {
    _transferOwnership(msg.sender);
    setReportExpiry(_reportExpirySeconds);
  }

  /**
   * @notice Sets the report expiry parameter.
   * @param _reportExpirySeconds The number of seconds before a report is considered expired.
   */
  function setReportExpiry(uint256 _reportExpirySeconds) public onlyOwner {
    require(_reportExpirySeconds > 0, "report expiry seconds must be > 0");
    require(_reportExpirySeconds != reportExpirySeconds, "reportExpirySeconds hasn't changed");
    reportExpirySeconds = _reportExpirySeconds;
    emit ReportExpirySet(_reportExpirySeconds);
  }

  /**
   * @notice Sets the report expiry parameter for a rateFeedId.
   * @param _token The rateFeedId for which the expiry is to be set.
   * @param _reportExpirySeconds The number of seconds before a report is considered expired.
   */
  function setTokenReportExpiry(address _token, uint256 _reportExpirySeconds) external onlyOwner {
    require(_reportExpirySeconds > 0, "report expiry seconds must be > 0");
    require(_reportExpirySeconds != tokenReportExpirySeconds[_token], "token reportExpirySeconds hasn't changed");
    tokenReportExpirySeconds[_token] = _reportExpirySeconds;
    emit TokenReportExpirySet(_token, _reportExpirySeconds);
  }

  /**
   * @notice Sets the address of the BreakerBox.
   * @param newBreakerBox The new BreakerBox address.
   */
  function setBreakerBox(IBreakerBox newBreakerBox) public onlyOwner {
    require(address(newBreakerBox) != address(0), "BreakerBox address must be set");
    breakerBox = newBreakerBox;
    emit BreakerBoxUpdated(address(newBreakerBox));
  }

  /**
   * @notice Adds a new Oracle for a specified rate feed.
   * @param token The rateFeedId that the specified oracle is permitted to report.
   * @param oracleAddress The address of the oracle.
   */
  function addOracle(address token, address oracleAddress) external onlyOwner {
    // solhint-disable-next-line reason-string
    require(
      token != address(0) && oracleAddress != address(0) && !isOracle[token][oracleAddress],
      "token addr was null or oracle addr was null or oracle addr is already an oracle for token addr"
    );
    isOracle[token][oracleAddress] = true;
    oracles[token].push(oracleAddress);
    emit OracleAdded(token, oracleAddress);
  }

  /**
   * @notice Removes an Oracle from a specified rate feed.
   * @param token The rateFeedId that the specified oracle is no longer permitted to report.
   * @param oracleAddress The address of the oracle.
   * @param index The index of `oracleAddress` in the list of oracles.
   */
  function removeOracle(
    address token,
    address oracleAddress,
    uint256 index
  ) external onlyOwner {
    // solhint-disable-next-line reason-string
    require(
      token != address(0) &&
        oracleAddress != address(0) &&
        oracles[token].length > index &&
        oracles[token][index] == oracleAddress,
      "token addr null or oracle addr null or index of token oracle not mapped to oracle addr"
    );
    isOracle[token][oracleAddress] = false;
    oracles[token][index] = oracles[token][oracles[token].length.sub(1)];
    oracles[token].length = oracles[token].length.sub(1);
    if (reportExists(token, oracleAddress)) {
      removeReport(token, oracleAddress);
    }
    emit OracleRemoved(token, oracleAddress);
  }

  /**
   * @notice Removes a report that is expired.
   * @param token The rateFeedId of the report to be removed.
   * @param n The number of expired reports to remove, at most (deterministic upper gas bound).
   */
  function removeExpiredReports(address token, uint256 n) external {
    require(
      token != address(0) && n < timestamps[token].getNumElements(),
      "token addr null or trying to remove too many reports"
    );
    for (uint256 i = 0; i < n; i = i.add(1)) {
      (bool isExpired, address oldestAddress) = isOldestReportExpired(token);
      if (isExpired) {
        removeReport(token, oldestAddress);
      } else {
        break;
      }
    }
  }

  /**
   * @notice Check if last report is expired.
   * @param token The rateFeedId of the reports to be checked.
   * @return bool A bool indicating if the last report is expired.
   * @return address Oracle address of the last report.
   */
  function isOldestReportExpired(address token) public view returns (bool, address) {
    // solhint-disable-next-line reason-string
    require(token != address(0));
    address oldest = timestamps[token].getTail();
    uint256 timestamp = timestamps[token].getValue(oldest);
    // solhint-disable-next-line not-rely-on-time
    if (now.sub(timestamp) >= getTokenReportExpirySeconds(token)) {
      return (true, oldest);
    }
    return (false, oldest);
  }

  /**
   * @notice Updates an oracle value and the median.
   * @param token The rateFeedId for the rate that is being reported.
   * @param value The number of stable asset that equate to one unit of collateral asset, for the
   *              specified rateFeedId, expressed as a fixidity value.
   * @param lesserKey The element which should be just left of the new oracle value.
   * @param greaterKey The element which should be just right of the new oracle value.
   * @dev Note that only one of `lesserKey` or `greaterKey` needs to be correct to reduce friction.
   */
  function report(
    address token,
    uint256 value,
    address lesserKey,
    address greaterKey
  ) external onlyOracle(token) {
    uint256 originalMedian = rates[token].getMedianValue();
    if (rates[token].contains(msg.sender)) {
      rates[token].update(msg.sender, value, lesserKey, greaterKey);

      // Rather than update the timestamp, we remove it and re-add it at the
      // head of the list later. The reason for this is that we need to handle
      // a few different cases:
      //   1. This oracle is the only one to report so far. lesserKey = address(0)
      //   2. Other oracles have reported since this one's last report. lesserKey = getHead()
      //   3. Other oracles have reported, but the most recent is this one.
      //      lesserKey = key immediately after getHead()
      //
      // However, if we just remove this timestamp, timestamps[token].getHead()
      // does the right thing in all cases.
      timestamps[token].remove(msg.sender);
    } else {
      rates[token].insert(msg.sender, value, lesserKey, greaterKey);
    }
    timestamps[token].insert(
      msg.sender,
      // solhint-disable-next-line not-rely-on-time
      now,
      timestamps[token].getHead(),
      address(0)
    );
    emit OracleReported(token, msg.sender, now, value);
    uint256 newMedian = rates[token].getMedianValue();
    if (newMedian != originalMedian) {
      emit MedianUpdated(token, newMedian);
    }

    if (address(breakerBox) != address(0)) {
      breakerBox.checkAndSetBreakers(token);
    }
  }

  /**
   * @notice Returns the number of rates that are currently stored for a specifed rateFeedId.
   * @param token The rateFeedId for which to retrieve the number of rates.
   * @return uint256 The number of reported oracle rates stored for the given rateFeedId.
   */
  function numRates(address token) public view returns (uint256) {
    return rates[token].getNumElements();
  }

  /**
   * @notice Returns the median of the currently stored rates for a specified rateFeedId.
   * @param token The rateFeedId of the rates for which the median value is being retrieved.
   * @return uint256 The median exchange rate for rateFeedId.
   * @return fixidity
   */
  function medianRate(address token) external view returns (uint256, uint256) {
    return (rates[token].getMedianValue(), numRates(token) == 0 ? 0 : FIXED1_UINT);
  }

  /**
   * @notice Gets all elements from the doubly linked list.
   * @param token The rateFeedId for which the collateral asset exchange rate is being reported.
   * @return keys Keys of nn unpacked list of elements from largest to smallest.
   * @return values Values of an unpacked list of elements from largest to smallest.
   * @return relations Relations of an unpacked list of elements from largest to smallest.
   */
  function getRates(address token)
    external
    view
    returns (
      address[] memory,
      uint256[] memory,
      SortedLinkedListWithMedian.MedianRelation[] memory
    )
  {
    return rates[token].getElements();
  }

  /**
   * @notice Returns the number of timestamps.
   * @param token The rateFeedId for which the collateral asset exchange rate is being reported.
   * @return uint256 The number of oracle report timestamps for the specified rateFeedId.
   */
  function numTimestamps(address token) public view returns (uint256) {
    return timestamps[token].getNumElements();
  }

  /**
   * @notice Returns the median timestamp.
   * @param token The rateFeedId for which the collateral asset exchange rate is being reported.
   * @return uint256 The median report timestamp for the specified rateFeedId.
   */
  function medianTimestamp(address token) external view returns (uint256) {
    return timestamps[token].getMedianValue();
  }

  /**
   * @notice Gets all elements from the doubly linked list.
   * @param token The rateFeedId for which the collateral asset exchange rate is being reported.
   * @return keys Keys of nn unpacked list of elements from largest to smallest.
   * @return values Values of an unpacked list of elements from largest to smallest.
   * @return relations Relations of an unpacked list of elements from largest to smallest.
   */
  function getTimestamps(address token)
    external
    view
    returns (
      address[] memory,
      uint256[] memory,
      SortedLinkedListWithMedian.MedianRelation[] memory
    )
  {
    return timestamps[token].getElements();
  }

  /**
   * @notice Checks if a report exists for a specified rateFeedId from a given oracle.
   * @param token The rateFeedId to be checked.
   * @param oracle The oracle whose report should be checked.
   * @return bool True if a report exists, false otherwise.
   */
  function reportExists(address token, address oracle) internal view returns (bool) {
    return rates[token].contains(oracle) && timestamps[token].contains(oracle);
  }

  /**
   * @notice Returns the list of oracles for a speficied rateFeedId.
   * @param token The rateFeedId whose oracles should be returned.
   * @return address[] A list of oracles for the given rateFeedId.
   */
  function getOracles(address token) external view returns (address[] memory) {
    return oracles[token];
  }

  /**
   * @notice Returns the expiry for specified rateFeedId if it exists, if not the default is returned.
   * @param token The rateFeedId.
   * @return The report expiry in seconds.
   */
  function getTokenReportExpirySeconds(address token) public view returns (uint256) {
    if (tokenReportExpirySeconds[token] == 0) {
      return reportExpirySeconds;
    }

    return tokenReportExpirySeconds[token];
  }

  /**
   * @notice Removes an oracle value and updates the median.
   * @param token The rateFeedId for which the collateral asset exchange rate is being reported.
   * @param oracle The oracle whose value should be removed.
   * @dev This can be used to delete elements for oracles that have been removed.
   * However, a > 1 elements reports list should always be maintained
   */
  function removeReport(address token, address oracle) private {
    if (numTimestamps(token) == 1 && reportExists(token, oracle)) return;
    uint256 originalMedian = rates[token].getMedianValue();
    rates[token].remove(oracle);
    timestamps[token].remove(oracle);
    emit OracleReportRemoved(token, oracle);
    uint256 newMedian = rates[token].getMedianValue();
    if (newMedian != originalMedian) {
      emit MedianUpdated(token, newMedian);
    }
  }
}
        

/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/Initializable.sol

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

contract Initializable {
  bool public initialized;

  constructor(bool testingDeployment) public {
    if (!testingDeployment) {
      initialized = true;
    }
  }

  modifier initializer() {
    require(!initialized, "contract already initialized");
    initialized = true;
    _;
  }
}
          

/lib/mento-core/contracts/common/interfaces/ICeloVersionedContract.sol

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

interface ICeloVersionedContract {
  /**
   * @notice Returns the storage, major, minor, and patch version of the contract.
   * @return Storage version of the contract.
   * @return Major version of the contract.
   * @return Minor version of the contract.
   * @return Patch version of the contract.
   */
  function getVersionNumber()
    external
    pure
    returns (
      uint256,
      uint256,
      uint256,
      uint256
    );
}
          

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

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

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

import "./SortedLinkedListWithMedian.sol";

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

  function toBytes(address a) public pure returns (bytes32) {
    return bytes32(uint256(a) << 96);
  }

  function toAddress(bytes32 b) public pure returns (address) {
    return address(uint256(b) >> 96);
  }

  /**
   * @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(
    SortedLinkedListWithMedian.List storage list,
    address key,
    uint256 value,
    address lesserKey,
    address greaterKey
  ) public {
    list.insert(toBytes(key), value, toBytes(lesserKey), toBytes(greaterKey));
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list, address key) public {
    list.remove(toBytes(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(
    SortedLinkedListWithMedian.List storage list,
    address key,
    uint256 value,
    address lesserKey,
    address greaterKey
  ) public {
    list.update(toBytes(key), value, toBytes(lesserKey), toBytes(greaterKey));
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list, address key) public view returns (bool) {
    return list.contains(toBytes(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(SortedLinkedListWithMedian.List storage list, address key) public view returns (uint256) {
    return list.getValue(toBytes(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(SortedLinkedListWithMedian.List storage list) public view returns (uint256) {
    return list.getValue(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(SortedLinkedListWithMedian.List storage list) external view returns (address) {
    return toAddress(list.getHead());
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list) external view returns (address) {
    return toAddress(list.getMedian());
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list) external view returns (address) {
    return toAddress(list.getTail());
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list) external view returns (uint256) {
    return list.getNumElements();
  }

  /**
   * @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(SortedLinkedListWithMedian.List storage list)
    public
    view
    returns (
      address[] memory,
      uint256[] memory,
      SortedLinkedListWithMedian.MedianRelation[] memory
    )
  {
    bytes32[] memory byteKeys = list.getKeys();
    address[] memory keys = new address[](byteKeys.length);
    uint256[] memory values = new uint256[](byteKeys.length);
    // prettier-ignore
    SortedLinkedListWithMedian.MedianRelation[] memory relations =
      new SortedLinkedListWithMedian.MedianRelation[](keys.length);
    for (uint256 i = 0; i < byteKeys.length; i = i.add(1)) {
      keys[i] = toAddress(byteKeys[i]);
      values[i] = list.getValue(byteKeys[i]);
      relations[i] = list.relation[byteKeys[i]];
    }
    return (keys, values, relations);
  }
}
          

/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/IBreakerBox.sol

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

/**
 * @title Breaker Box Interface
 * @notice Defines the basic interface for the Breaker Box
 */
interface IBreakerBox {
  /**
   * @dev Used to track additional info about
   *      the current trading mode a specific rate feed ID is in.
   *      LastUpdatedTime helps to check cooldown.
   *      LastUpdatedBlock helps to determine if check should be executed.
   */
  struct TradingModeInfo {
    uint64 tradingMode;
    uint64 lastUpdatedTime;
    uint128 lastUpdatedBlock;
  }

  /**
   * @notice Emitted when a new breaker is added to the breaker box.
   * @param breaker The address of the new breaker.
   */
  event BreakerAdded(address indexed breaker);

  /**
   * @notice Emitted when a breaker is removed from the breaker box.
   * @param breaker The address of the breaker that was removed.
   */
  event BreakerRemoved(address indexed breaker);

  /**
   * @notice Emitted when a breaker is tripped by a rate feed.
   * @param breaker The address of the breaker that was tripped.
   * @param rateFeedID The address of the rate feed.
   */
  event BreakerTripped(address indexed breaker, address indexed rateFeedID);

  /**
   * @notice Emitted when a new rate feed is added to the breaker box.
   * @param rateFeedID The address of the rate feed that was added.
   */
  event RateFeedAdded(address indexed rateFeedID);

  /**
   * @notice Emitted when a rate feed is removed from the breaker box.
   * @param rateFeedID The rate feed that was removed.
   */
  event RateFeedRemoved(address indexed rateFeedID);

  /**
   * @notice Emitted when the trading mode for a rate feed is updated
   * @param rateFeedID The address of the rataFeedID.
   * @param tradingMode The new trading mode of the rate feed.
   */
  event TradingModeUpdated(address indexed rateFeedID, uint256 tradingMode);

  /**
   * @notice Emitted after a reset attempt is successful.
   * @param rateFeedID The address of the rate feed.
   * @param breaker The address of the breaker.
   */
  event ResetSuccessful(address indexed rateFeedID, address indexed breaker);

  /**
   * @notice  Emitted after a reset attempt fails when the
   *          rate feed fails the breakers reset criteria.
   * @param rateFeedID The address of the rate feed.
   * @param breaker The address of the breaker.
   */
  event ResetAttemptCriteriaFail(address indexed rateFeedID, address indexed breaker);

  /**
   * @notice Emitted after a reset attempt fails when cooldown time has not elapsed.
   * @param rateFeedID The address of the rate feed.
   * @param breaker The address of the breaker.
   */
  event ResetAttemptNotCool(address indexed rateFeedID, address indexed breaker);

  /**
   * @notice Emitted when the sortedOracles address is updated.
   * @param newSortedOracles The address of the new sortedOracles.
   */
  event SortedOraclesUpdated(address indexed newSortedOracles);

  /**
   * @notice Emitted when the breaker is enabled or disabled for a rate feed.
   * @param breaker The address of the breaker.
   * @param rateFeedID The address of the rate feed.
   * @param status Indicating the status.
   */
  event BreakerStatusUpdated(address breaker, address rateFeedID, bool status);

  /**
   * @notice Retrives an ordered array of all breaker addresses.
   */
  function getBreakers() external view returns (address[] memory);

  /**
   * @notice Checks if a breaker with the specified address has been added to the breaker box.
   * @param breaker The address of the breaker to check;
   * @return A bool indicating whether or not the breaker has been added.
   */
  function isBreaker(address breaker) external view returns (bool);

  /**
   * @notice Checks breakers for the rateFeedID and sets correct trading mode
   * if any breakers are tripped or need to be reset.
   * @param rateFeedID The registryId of the rateFeedID to run checks for.
   */
  function checkAndSetBreakers(address rateFeedID) external;

  /**
   * @notice Gets the trading mode for the specified rateFeedID.
   * @param rateFeedID The address of the rateFeedID to retrieve the trading mode for.
   */
  function getRateFeedTradingMode(address rateFeedID) external view returns (uint256 tradingMode);
}
          

/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":"bool","name":"test","internalType":"bool"}]},{"type":"event","name":"BreakerBoxUpdated","inputs":[{"type":"address","name":"newBreakerBox","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"MedianUpdated","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OracleAdded","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"oracleAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OracleRemoved","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"oracleAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OracleReportRemoved","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"oracle","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OracleReported","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"oracle","internalType":"address","indexed":true},{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false},{"type":"uint256","name":"value","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":"ReportExpirySet","inputs":[{"type":"uint256","name":"reportExpiry","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenReportExpirySet","inputs":[{"type":"address","name":"token","internalType":"address","indexed":false},{"type":"uint256","name":"reportExpiry","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"addOracle","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"oracleAddress","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract IBreakerBox"}],"name":"breakerBox","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getOracles","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"address[]"},{"type":"uint256[]","name":"","internalType":"uint256[]"},{"type":"uint8[]","name":"","internalType":"enum SortedLinkedListWithMedian.MedianRelation[]"}],"name":"getRates","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"address[]"},{"type":"uint256[]","name":"","internalType":"uint256[]"},{"type":"uint8[]","name":"","internalType":"enum SortedLinkedListWithMedian.MedianRelation[]"}],"name":"getTimestamps","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokenReportExpirySeconds","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"pure","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getVersionNumber","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"initialize","inputs":[{"type":"uint256","name":"_reportExpirySeconds","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"initialized","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"address","name":"","internalType":"address"}],"name":"isOldestReportExpired","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOracle","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","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":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"medianRate","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"medianTimestamp","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"numRates","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"numTimestamps","inputs":[{"type":"address","name":"token","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"oracles","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"removeExpiredReports","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"n","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"removeOracle","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"oracleAddress","internalType":"address"},{"type":"uint256","name":"index","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"renounceOwnership","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"report","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"address","name":"lesserKey","internalType":"address"},{"type":"address","name":"greaterKey","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"reportExpirySeconds","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setBreakerBox","inputs":[{"type":"address","name":"newBreakerBox","internalType":"contract IBreakerBox"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setReportExpiry","inputs":[{"type":"uint256","name":"_reportExpirySeconds","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setTokenReportExpiry","inputs":[{"type":"address","name":"_token","internalType":"address"},{"type":"uint256","name":"_reportExpirySeconds","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenReportExpirySeconds","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}],"constant":false}]
              

Contract Creation Code

0x60806040523480156200001157600080fd5b5060405162002ba638038062002ba6833981810160405260208110156200003757600080fd5b50518060006200004f6001600160e01b03620000bb16565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35080620000b3576000805460ff60a01b1916600160a01b1790555b5050620000bf565b3390565b612ad780620000cf6000396000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c80638e749281116100f9578063ef90e1b011610097578063f414c5e411610071578063f414c5e41461068f578063fc20935d14610697578063fe4b84df146106c3578063ffe736bf146106e0576101c4565b8063ef90e1b0146105fc578063f0ca4adb1461063b578063f2fde38b14610669576101c4565b8063b9292158116100d3578063b929215814610567578063bbc66a941461058d578063dd34ca3b146105b3578063ebc1d6bb146105df576101c4565b80638e749281146104bd5780638f32d59b14610533578063a00a8b2c1461053b576101c4565b806353a57297116101665780636deb6799116101405780636deb67991461042f578063715018a61461045557806380e507441461045d5780638da5cb5b14610499576101c4565b806353a57297146103a557806354255be0146103db5780636dd6ef0c14610409576101c4565b8063158ef93e116101a2578063158ef93e1461032d5780632e86bc0114610349578063370c998e1461036f578063493a353c1461039d576101c4565b806302f55b61146101c9578063040bbd35146102cd578063071b48fc146102f5575b600080fd5b6101ef600480360360208110156101df57600080fd5b50356001600160a01b0316610729565b60405180806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b8381101561023757818101518382015260200161021f565b50505050905001848103835286818151815260200191508051906020019060200280838360005b8381101561027657818101518382015260200161025e565b50505050905001848103825285818151815260200191508051906020019060200280838360005b838110156102b557818101518382015260200161029d565b50505050905001965050505050505060405180910390f35b6102f3600480360360208110156102e357600080fd5b50356001600160a01b03166109b3565b005b61031b6004803603602081101561030b57600080fd5b50356001600160a01b0316610ac9565b60408051918252519081900360200190f35b610335610b7e565b604080519115158252519081900360200190f35b61031b6004803603602081101561035f57600080fd5b50356001600160a01b0316610b9f565b6103356004803603604081101561038557600080fd5b506001600160a01b0381358116916020013516610bb1565b61031b610bd1565b6102f3600480360360608110156103bb57600080fd5b506001600160a01b03813581169160208101359091169060400135610bd7565b6103e3610e7a565b604080519485526020850193909352838301919091526060830152519081900360800190f35b61031b6004803603602081101561041f57600080fd5b50356001600160a01b0316610e86565b61031b6004803603602081101561044557600080fd5b50356001600160a01b0316610f07565b6102f3610f49565b6102f36004803603608081101561047357600080fd5b506001600160a01b03813581169160208101359160408201358116916060013516611004565b6104a1611702565b604080516001600160a01b039092168252519081900360200190f35b6104e3600480360360208110156104d357600080fd5b50356001600160a01b0316611712565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561051f578181015183820152602001610507565b505050509050019250505060405180910390f35b610335611788565b6104a16004803603604081101561055157600080fd5b506001600160a01b0381351690602001356117ac565b6101ef6004803603602081101561057d57600080fd5b50356001600160a01b03166117e1565b61031b600480360360208110156105a357600080fd5b50356001600160a01b0316611867565b6102f3600480360360408110156105c957600080fd5b506001600160a01b0381351690602001356118e8565b6102f3600480360360208110156105f557600080fd5b5035611a3f565b6106226004803603602081101561061257600080fd5b50356001600160a01b0316611b53565b6040805192835260208301919091528051918290030190f35b6102f36004803603604081101561065157600080fd5b506001600160a01b0381358116916020013516611c2d565b6102f36004803603602081101561067f57600080fd5b50356001600160a01b0316611dd1565b6104a1611e36565b6102f3600480360360408110156106ad57600080fd5b506001600160a01b038135169060200135611e45565b6102f3600480360360208110156106d957600080fd5b5035611f8d565b610706600480360360208110156106f657600080fd5b50356001600160a01b031661204e565b6040805192151583526001600160a01b0390911660208301528051918290030190f35b6001600160a01b03811660009081526001602052604080822081517f6cfa3873000000000000000000000000000000000000000000000000000000008152600481019190915290516060928392839273ed477a99035d0c1e11369f1d7a4e587893cc002b92636cfa38739260248082019391829003018186803b1580156107af57600080fd5b505af41580156107c3573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052606081101561080a57600080fd5b810190808051604051939291908464010000000082111561082a57600080fd5b90830190602082018581111561083f57600080fd5b825186602082028301116401000000008211171561085c57600080fd5b82525081516020918201928201910280838360005b83811015610889578181015183820152602001610871565b50505050905001604052602001805160405193929190846401000000008211156108b257600080fd5b9083019060208201858111156108c757600080fd5b82518660208202830111640100000000821117156108e457600080fd5b82525081516020918201928201910280838360005b838110156109115781810151838201526020016108f9565b505050509050016040526020018051604051939291908464010000000082111561093a57600080fd5b90830190602082018581111561094f57600080fd5b825186602082028301116401000000008211171561096c57600080fd5b82525081516020918201928201910280838360005b83811015610999578181015183820152602001610981565b505050509050016040525050509250925092509193909250565b6109bb611788565b610a0c576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610a67576040805162461bcd60e51b815260206004820152601e60248201527f427265616b6572426f782061646472657373206d757374206265207365740000604482015290519081900360640190fd5b600780547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040517f21921b3b46ef2c939e85d6a14410c6e3b9ce132b66e944357ff4f789f68e00e290600090a250565b6001600160a01b038116600090815260026020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b158015610b4a57600080fd5b505af4158015610b5e573d6000803e3d6000fd5b505050506040513d6020811015610b7457600080fd5b505190505b919050565b60005474010000000000000000000000000000000000000000900460ff1681565b60066020526000908152604090205481565b600360209081526000928352604080842090915290825290205460ff1681565b60055481565b610bdf611788565b610c30576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03831615801590610c5057506001600160a01b03821615155b8015610c7357506001600160a01b03831660009081526004602052604090205481105b8015610cba57506001600160a01b03838116600090815260046020526040902080549184169183908110610ca357fe5b6000918252602090912001546001600160a01b0316145b610cf55760405162461bcd60e51b815260040180806020018281038252605681526020018061295d6056913960600191505060405180910390fd5b6001600160a01b038084166000818152600360209081526040808320948716835293815283822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690559181526004909152208054610d5e90600163ffffffff61220416565b81548110610d6857fe5b60009182526020808320909101546001600160a01b03868116845260049092526040909220805491909216919083908110610d9f57fe5b600091825260208083209190910180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03948516179055918516815260049091526040902054610df9906001612204565b6001600160a01b0384166000908152600460205260409020610e1b90826128c5565b50610e26838361224d565b15610e3557610e3583836123cc565b816001600160a01b0316836001600160a01b03167f6dc84b66cc948d847632b9d829f7cb1cb904fbf2c084554a9bc22ad9d845334060405160405180910390a3505050565b60018060028190919293565b6001600160a01b038116600090815260026020908152604080832081517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c39260248082019391829003018186803b158015610b4a57600080fd5b6001600160a01b038116600090815260066020526040812054610f2d5750600554610b79565b506001600160a01b031660009081526006602052604090205490565b610f51611788565b610fa2576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b6001600160a01b0384166000908152600360209081526040808320338452909152902054849060ff166110685760405162461bcd60e51b81526004018080602001828103825260278152602001806129b36027913960400191505060405180910390fd5b6001600160a01b038516600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b1580156110e957600080fd5b505af41580156110fd573d6000803e3d6000fd5b505050506040513d602081101561111357600080fd5b50516001600160a01b03871660009081526001602090815260409182902082517f95073a790000000000000000000000000000000000000000000000000000000081526004810191909152336024820152915192935073ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a79926044808201939291829003018186803b1580156111a157600080fd5b505af41580156111b5573d6000803e3d6000fd5b505050506040513d60208110156111cb57600080fd5b505115611329576001600160a01b0380871660009081526001602052604080822081517f832a2147000000000000000000000000000000000000000000000000000000008152600481019190915233602482015260448101899052878416606482015292861660848401525173ed477a99035d0c1e11369f1d7a4e587893cc002b9263832a21479260a4808301939192829003018186803b15801561126f57600080fd5b505af4158015611283573d6000803e3d6000fd5b505050506001600160a01b03861660009081526002602052604080822081517fc1e728e90000000000000000000000000000000000000000000000000000000081526004810191909152336024820152905173ed477a99035d0c1e11369f1d7a4e587893cc002b9263c1e728e99260448082019391829003018186803b15801561130c57600080fd5b505af4158015611320573d6000803e3d6000fd5b505050506113df565b6001600160a01b0380871660009081526001602052604080822081517fd4a09272000000000000000000000000000000000000000000000000000000008152600481019190915233602482015260448101899052878416606482015292861660848401525173ed477a99035d0c1e11369f1d7a4e587893cc002b9263d4a092729260a4808301939192829003018186803b1580156113c657600080fd5b505af41580156113da573d6000803e3d6000fd5b505050505b6001600160a01b03861660009081526002602090815260409182902082517f0944c59400000000000000000000000000000000000000000000000000000000815260048101829052925173ed477a99035d0c1e11369f1d7a4e587893cc002b9363d4a0927293339242928792630944c59492602480840193829003018186803b15801561146b57600080fd5b505af415801561147f573d6000803e3d6000fd5b505050506040513d602081101561149557600080fd5b5051604080517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b16815260048101959095526001600160a01b0393841660248601526044850192909252919091166064830152600060848301819052905160a480840193829003018186803b15801561151257600080fd5b505af4158015611526573d6000803e3d6000fd5b5050604080514281526020810189905281513394506001600160a01b038b1693507f7cebb17173a9ed273d2b7538f64395c0ebf352ff743f1cf8ce66b437a6144213929181900390910190a36001600160a01b038616600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b1580156115f357600080fd5b505af4158015611607573d6000803e3d6000fd5b505050506040513d602081101561161d57600080fd5b50519050818114611668576040805182815290516001600160a01b038916917fa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41919081900360200190a25b6007546001600160a01b0316156116f957600754604080517fab02e6c00000000000000000000000000000000000000000000000000000000081526001600160a01b038a811660048301529151919092169163ab02e6c091602480830192600092919082900301818387803b1580156116e057600080fd5b505af11580156116f4573d6000803e3d6000fd5b505050505b50505050505050565b6000546001600160a01b03165b90565b6001600160a01b03811660009081526004602090815260409182902080548351818402810184019094528084526060939283018282801561177c57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161175e575b50505050509050919050565b600080546001600160a01b031661179d612718565b6001600160a01b031614905090565b600460205281600052604060002081815481106117c557fe5b6000918252602090912001546001600160a01b03169150829050565b6001600160a01b03811660009081526002602052604080822081517f6cfa3873000000000000000000000000000000000000000000000000000000008152600481019190915290516060928392839273ed477a99035d0c1e11369f1d7a4e587893cc002b92636cfa38739260248082019391829003018186803b1580156107af57600080fd5b6001600160a01b038116600090815260016020908152604080832081517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c39260248082019391829003018186803b158015610b4a57600080fd5b6001600160a01b038216158015906119ad57506001600160a01b03821660009081526002602090815260409182902082517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152915173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c3926024808301939192829003018186803b15801561197e57600080fd5b505af4158015611992573d6000803e3d6000fd5b505050506040513d60208110156119a857600080fd5b505181105b6119e85760405162461bcd60e51b81526004018080602001828103825260348152602001806129296034913960400191505060405180910390fd5b60005b81811015611a3a576000806119ff8561204e565b915091508115611a1857611a1385826123cc565b611a1f565b5050611a3a565b50611a33905081600163ffffffff61271c16565b90506119eb565b505050565b611a47611788565b611a98576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60008111611ad75760405162461bcd60e51b8152600401808060200182810382526021815260200180612a826021913960400191505060405180910390fd5b600554811415611b185760405162461bcd60e51b8152600401808060200182810382526022815260200180612a606022913960400191505060405180910390fd5b60058190556040805182815290517fc68a9b88effd8a11611ff410efbc83569f0031b7bc70dd455b61344c7f0a042f9181900360200190a150565b6001600160a01b038116600090815260016020908152604080832081517f59d556a800000000000000000000000000000000000000000000000000000000815260048101919091529051839273ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248083019392829003018186803b158015611bd657600080fd5b505af4158015611bea573d6000803e3d6000fd5b505050506040513d6020811015611c0057600080fd5b5051611c0b84611867565b15611c205769d3c21bcecceda1000000611c23565b60005b915091505b915091565b611c35611788565b611c86576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03821615801590611ca657506001600160a01b03811615155b8015611cd857506001600160a01b0380831660009081526003602090815260408083209385168352929052205460ff16155b611d135760405162461bcd60e51b815260040180806020018281038252605e8152602001806129da605e913960600191505060405180910390fd5b6001600160a01b03808316600081815260036020908152604080832094861680845294825280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660019081179091558484526004835281842080549182018155845291832090910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001685179055517f828d2be040dede7698182e08dfa8bfbd663c879aee772509c4a2bd961d0ed43f9190a35050565b611dd9611788565b611e2a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b611e3381612776565b50565b6007546001600160a01b031681565b611e4d611788565b611e9e576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60008111611edd5760405162461bcd60e51b8152600401808060200182810382526021815260200180612a826021913960400191505060405180910390fd5b6001600160a01b038216600090815260066020526040902054811415611f345760405162461bcd60e51b8152600401808060200182810382526028815260200180612a386028913960400191505060405180910390fd5b6001600160a01b0382166000818152600660209081526040918290208490558151928352820183905280517ff8324c8592dfd9991ee3e717351afe0a964605257959e3d99b0eb3d45bff94229281900390910190a15050565b60005474010000000000000000000000000000000000000000900460ff1615611ffd576040805162461bcd60e51b815260206004820152601c60248201527f636f6e747261637420616c726561647920696e697469616c697a656400000000604482015290519081900360640190fd5b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000017905561204533612776565b611e3381611a3f565b6000806001600160a01b03831661206457600080fd5b6001600160a01b038316600090815260026020908152604080832081517fd938ec7b0000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b9263d938ec7b9260248082019391829003018186803b1580156120e557600080fd5b505af41580156120f9573d6000803e3d6000fd5b505050506040513d602081101561210f57600080fd5b50516001600160a01b03808616600090815260026020908152604080832081517f7c6bb8620000000000000000000000000000000000000000000000000000000081526004810191909152938516602485015251939450909273ed477a99035d0c1e11369f1d7a4e587893cc002b92637c6bb862926044808301939192829003018186803b1580156121a057600080fd5b505af41580156121b4573d6000803e3d6000fd5b505050506040513d60208110156121ca57600080fd5b505190506121d785610f07565b6121e7428363ffffffff61220416565b106121f85750600192509050611c28565b50600092509050915091565b600061224683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061282e565b9392505050565b6001600160a01b03808316600090815260016020908152604080832081517f95073a790000000000000000000000000000000000000000000000000000000081526004810191909152938516602485015251919273ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a7992604480840193919291829003018186803b1580156122da57600080fd5b505af41580156122ee573d6000803e3d6000fd5b505050506040513d602081101561230457600080fd5b5051801561224657506001600160a01b0380841660009081526002602090815260409182902082517f95073a7900000000000000000000000000000000000000000000000000000000815260048101919091529285166024840152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a79926044808301939192829003018186803b15801561239957600080fd5b505af41580156123ad573d6000803e3d6000fd5b505050506040513d60208110156123c357600080fd5b50519392505050565b6123d582610e86565b60011480156123e957506123e9828261224d565b156123f357612714565b6001600160a01b038216600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b15801561247457600080fd5b505af4158015612488573d6000803e3d6000fd5b505050506040513d602081101561249e57600080fd5b50516001600160a01b0380851660009081526001602052604080822081517fc1e728e9000000000000000000000000000000000000000000000000000000008152600481019190915292861660248401525192935073ed477a99035d0c1e11369f1d7a4e587893cc002b9263c1e728e9926044808201939291829003018186803b15801561252b57600080fd5b505af415801561253f573d6000803e3d6000fd5b5050506001600160a01b0380851660009081526002602052604080822081517fc1e728e9000000000000000000000000000000000000000000000000000000008152600481019190915292861660248401525173ed477a99035d0c1e11369f1d7a4e587893cc002b935063c1e728e9926044808201939291829003018186803b1580156125cb57600080fd5b505af41580156125df573d6000803e3d6000fd5b50506040516001600160a01b038086169350861691507fe21a44017b6fa1658d84e937d56ff408501facdb4ff7427c479ac460d76f789390600090a36001600160a01b038316600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b15801561269c57600080fd5b505af41580156126b0573d6000803e3d6000fd5b505050506040513d60208110156126c657600080fd5b50519050818114612711576040805182815290516001600160a01b038616917fa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41919081900360200190a25b50505b5050565b3390565b600082820183811015612246576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6001600160a01b0381166127bb5760405162461bcd60e51b81526004018080602001828103825260268152602001806129036026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b600081848411156128bd5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561288257818101518382015260200161286a565b50505050905090810190601f1680156128af5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b815481835581811115611a3a57600083815260209020611a3a91810190830161170f91905b808211156128fe57600081556001016128ea565b509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373746f6b656e2061646472206e756c6c206f7220747279696e6720746f2072656d6f766520746f6f206d616e79207265706f727473746f6b656e2061646472206e756c6c206f72206f7261636c652061646472206e756c6c206f7220696e646578206f6620746f6b656e206f7261636c65206e6f74206d617070656420746f206f7261636c65206164647273656e64657220776173206e6f7420616e206f7261636c6520666f7220746f6b656e2061646472746f6b656e206164647220776173206e756c6c206f72206f7261636c65206164647220776173206e756c6c206f72206f7261636c65206164647220697320616c726561647920616e206f7261636c6520666f7220746f6b656e2061646472746f6b656e207265706f72744578706972795365636f6e6473206861736e2774206368616e6765647265706f72744578706972795365636f6e6473206861736e2774206368616e6765647265706f727420657870697279207365636f6e6473206d757374206265203e2030a265627a7a72315820f8f61cb1481ca4c44fb1f15abaedee325084fda65944e9e7bd5be86816056e7e64736f6c634300051100320000000000000000000000000000000000000000000000000000000000000000

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106101c45760003560e01c80638e749281116100f9578063ef90e1b011610097578063f414c5e411610071578063f414c5e41461068f578063fc20935d14610697578063fe4b84df146106c3578063ffe736bf146106e0576101c4565b8063ef90e1b0146105fc578063f0ca4adb1461063b578063f2fde38b14610669576101c4565b8063b9292158116100d3578063b929215814610567578063bbc66a941461058d578063dd34ca3b146105b3578063ebc1d6bb146105df576101c4565b80638e749281146104bd5780638f32d59b14610533578063a00a8b2c1461053b576101c4565b806353a57297116101665780636deb6799116101405780636deb67991461042f578063715018a61461045557806380e507441461045d5780638da5cb5b14610499576101c4565b806353a57297146103a557806354255be0146103db5780636dd6ef0c14610409576101c4565b8063158ef93e116101a2578063158ef93e1461032d5780632e86bc0114610349578063370c998e1461036f578063493a353c1461039d576101c4565b806302f55b61146101c9578063040bbd35146102cd578063071b48fc146102f5575b600080fd5b6101ef600480360360208110156101df57600080fd5b50356001600160a01b0316610729565b60405180806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b8381101561023757818101518382015260200161021f565b50505050905001848103835286818151815260200191508051906020019060200280838360005b8381101561027657818101518382015260200161025e565b50505050905001848103825285818151815260200191508051906020019060200280838360005b838110156102b557818101518382015260200161029d565b50505050905001965050505050505060405180910390f35b6102f3600480360360208110156102e357600080fd5b50356001600160a01b03166109b3565b005b61031b6004803603602081101561030b57600080fd5b50356001600160a01b0316610ac9565b60408051918252519081900360200190f35b610335610b7e565b604080519115158252519081900360200190f35b61031b6004803603602081101561035f57600080fd5b50356001600160a01b0316610b9f565b6103356004803603604081101561038557600080fd5b506001600160a01b0381358116916020013516610bb1565b61031b610bd1565b6102f3600480360360608110156103bb57600080fd5b506001600160a01b03813581169160208101359091169060400135610bd7565b6103e3610e7a565b604080519485526020850193909352838301919091526060830152519081900360800190f35b61031b6004803603602081101561041f57600080fd5b50356001600160a01b0316610e86565b61031b6004803603602081101561044557600080fd5b50356001600160a01b0316610f07565b6102f3610f49565b6102f36004803603608081101561047357600080fd5b506001600160a01b03813581169160208101359160408201358116916060013516611004565b6104a1611702565b604080516001600160a01b039092168252519081900360200190f35b6104e3600480360360208110156104d357600080fd5b50356001600160a01b0316611712565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561051f578181015183820152602001610507565b505050509050019250505060405180910390f35b610335611788565b6104a16004803603604081101561055157600080fd5b506001600160a01b0381351690602001356117ac565b6101ef6004803603602081101561057d57600080fd5b50356001600160a01b03166117e1565b61031b600480360360208110156105a357600080fd5b50356001600160a01b0316611867565b6102f3600480360360408110156105c957600080fd5b506001600160a01b0381351690602001356118e8565b6102f3600480360360208110156105f557600080fd5b5035611a3f565b6106226004803603602081101561061257600080fd5b50356001600160a01b0316611b53565b6040805192835260208301919091528051918290030190f35b6102f36004803603604081101561065157600080fd5b506001600160a01b0381358116916020013516611c2d565b6102f36004803603602081101561067f57600080fd5b50356001600160a01b0316611dd1565b6104a1611e36565b6102f3600480360360408110156106ad57600080fd5b506001600160a01b038135169060200135611e45565b6102f3600480360360208110156106d957600080fd5b5035611f8d565b610706600480360360208110156106f657600080fd5b50356001600160a01b031661204e565b6040805192151583526001600160a01b0390911660208301528051918290030190f35b6001600160a01b03811660009081526001602052604080822081517f6cfa3873000000000000000000000000000000000000000000000000000000008152600481019190915290516060928392839273ed477a99035d0c1e11369f1d7a4e587893cc002b92636cfa38739260248082019391829003018186803b1580156107af57600080fd5b505af41580156107c3573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052606081101561080a57600080fd5b810190808051604051939291908464010000000082111561082a57600080fd5b90830190602082018581111561083f57600080fd5b825186602082028301116401000000008211171561085c57600080fd5b82525081516020918201928201910280838360005b83811015610889578181015183820152602001610871565b50505050905001604052602001805160405193929190846401000000008211156108b257600080fd5b9083019060208201858111156108c757600080fd5b82518660208202830111640100000000821117156108e457600080fd5b82525081516020918201928201910280838360005b838110156109115781810151838201526020016108f9565b505050509050016040526020018051604051939291908464010000000082111561093a57600080fd5b90830190602082018581111561094f57600080fd5b825186602082028301116401000000008211171561096c57600080fd5b82525081516020918201928201910280838360005b83811015610999578181015183820152602001610981565b505050509050016040525050509250925092509193909250565b6109bb611788565b610a0c576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610a67576040805162461bcd60e51b815260206004820152601e60248201527f427265616b6572426f782061646472657373206d757374206265207365740000604482015290519081900360640190fd5b600780547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040517f21921b3b46ef2c939e85d6a14410c6e3b9ce132b66e944357ff4f789f68e00e290600090a250565b6001600160a01b038116600090815260026020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b158015610b4a57600080fd5b505af4158015610b5e573d6000803e3d6000fd5b505050506040513d6020811015610b7457600080fd5b505190505b919050565b60005474010000000000000000000000000000000000000000900460ff1681565b60066020526000908152604090205481565b600360209081526000928352604080842090915290825290205460ff1681565b60055481565b610bdf611788565b610c30576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03831615801590610c5057506001600160a01b03821615155b8015610c7357506001600160a01b03831660009081526004602052604090205481105b8015610cba57506001600160a01b03838116600090815260046020526040902080549184169183908110610ca357fe5b6000918252602090912001546001600160a01b0316145b610cf55760405162461bcd60e51b815260040180806020018281038252605681526020018061295d6056913960600191505060405180910390fd5b6001600160a01b038084166000818152600360209081526040808320948716835293815283822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690559181526004909152208054610d5e90600163ffffffff61220416565b81548110610d6857fe5b60009182526020808320909101546001600160a01b03868116845260049092526040909220805491909216919083908110610d9f57fe5b600091825260208083209190910180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03948516179055918516815260049091526040902054610df9906001612204565b6001600160a01b0384166000908152600460205260409020610e1b90826128c5565b50610e26838361224d565b15610e3557610e3583836123cc565b816001600160a01b0316836001600160a01b03167f6dc84b66cc948d847632b9d829f7cb1cb904fbf2c084554a9bc22ad9d845334060405160405180910390a3505050565b60018060028190919293565b6001600160a01b038116600090815260026020908152604080832081517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c39260248082019391829003018186803b158015610b4a57600080fd5b6001600160a01b038116600090815260066020526040812054610f2d5750600554610b79565b506001600160a01b031660009081526006602052604090205490565b610f51611788565b610fa2576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b6001600160a01b0384166000908152600360209081526040808320338452909152902054849060ff166110685760405162461bcd60e51b81526004018080602001828103825260278152602001806129b36027913960400191505060405180910390fd5b6001600160a01b038516600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b1580156110e957600080fd5b505af41580156110fd573d6000803e3d6000fd5b505050506040513d602081101561111357600080fd5b50516001600160a01b03871660009081526001602090815260409182902082517f95073a790000000000000000000000000000000000000000000000000000000081526004810191909152336024820152915192935073ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a79926044808201939291829003018186803b1580156111a157600080fd5b505af41580156111b5573d6000803e3d6000fd5b505050506040513d60208110156111cb57600080fd5b505115611329576001600160a01b0380871660009081526001602052604080822081517f832a2147000000000000000000000000000000000000000000000000000000008152600481019190915233602482015260448101899052878416606482015292861660848401525173ed477a99035d0c1e11369f1d7a4e587893cc002b9263832a21479260a4808301939192829003018186803b15801561126f57600080fd5b505af4158015611283573d6000803e3d6000fd5b505050506001600160a01b03861660009081526002602052604080822081517fc1e728e90000000000000000000000000000000000000000000000000000000081526004810191909152336024820152905173ed477a99035d0c1e11369f1d7a4e587893cc002b9263c1e728e99260448082019391829003018186803b15801561130c57600080fd5b505af4158015611320573d6000803e3d6000fd5b505050506113df565b6001600160a01b0380871660009081526001602052604080822081517fd4a09272000000000000000000000000000000000000000000000000000000008152600481019190915233602482015260448101899052878416606482015292861660848401525173ed477a99035d0c1e11369f1d7a4e587893cc002b9263d4a092729260a4808301939192829003018186803b1580156113c657600080fd5b505af41580156113da573d6000803e3d6000fd5b505050505b6001600160a01b03861660009081526002602090815260409182902082517f0944c59400000000000000000000000000000000000000000000000000000000815260048101829052925173ed477a99035d0c1e11369f1d7a4e587893cc002b9363d4a0927293339242928792630944c59492602480840193829003018186803b15801561146b57600080fd5b505af415801561147f573d6000803e3d6000fd5b505050506040513d602081101561149557600080fd5b5051604080517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b16815260048101959095526001600160a01b0393841660248601526044850192909252919091166064830152600060848301819052905160a480840193829003018186803b15801561151257600080fd5b505af4158015611526573d6000803e3d6000fd5b5050604080514281526020810189905281513394506001600160a01b038b1693507f7cebb17173a9ed273d2b7538f64395c0ebf352ff743f1cf8ce66b437a6144213929181900390910190a36001600160a01b038616600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b1580156115f357600080fd5b505af4158015611607573d6000803e3d6000fd5b505050506040513d602081101561161d57600080fd5b50519050818114611668576040805182815290516001600160a01b038916917fa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41919081900360200190a25b6007546001600160a01b0316156116f957600754604080517fab02e6c00000000000000000000000000000000000000000000000000000000081526001600160a01b038a811660048301529151919092169163ab02e6c091602480830192600092919082900301818387803b1580156116e057600080fd5b505af11580156116f4573d6000803e3d6000fd5b505050505b50505050505050565b6000546001600160a01b03165b90565b6001600160a01b03811660009081526004602090815260409182902080548351818402810184019094528084526060939283018282801561177c57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161175e575b50505050509050919050565b600080546001600160a01b031661179d612718565b6001600160a01b031614905090565b600460205281600052604060002081815481106117c557fe5b6000918252602090912001546001600160a01b03169150829050565b6001600160a01b03811660009081526002602052604080822081517f6cfa3873000000000000000000000000000000000000000000000000000000008152600481019190915290516060928392839273ed477a99035d0c1e11369f1d7a4e587893cc002b92636cfa38739260248082019391829003018186803b1580156107af57600080fd5b6001600160a01b038116600090815260016020908152604080832081517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c39260248082019391829003018186803b158015610b4a57600080fd5b6001600160a01b038216158015906119ad57506001600160a01b03821660009081526002602090815260409182902082517f6eafa6c30000000000000000000000000000000000000000000000000000000081526004810191909152915173ed477a99035d0c1e11369f1d7a4e587893cc002b92636eafa6c3926024808301939192829003018186803b15801561197e57600080fd5b505af4158015611992573d6000803e3d6000fd5b505050506040513d60208110156119a857600080fd5b505181105b6119e85760405162461bcd60e51b81526004018080602001828103825260348152602001806129296034913960400191505060405180910390fd5b60005b81811015611a3a576000806119ff8561204e565b915091508115611a1857611a1385826123cc565b611a1f565b5050611a3a565b50611a33905081600163ffffffff61271c16565b90506119eb565b505050565b611a47611788565b611a98576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60008111611ad75760405162461bcd60e51b8152600401808060200182810382526021815260200180612a826021913960400191505060405180910390fd5b600554811415611b185760405162461bcd60e51b8152600401808060200182810382526022815260200180612a606022913960400191505060405180910390fd5b60058190556040805182815290517fc68a9b88effd8a11611ff410efbc83569f0031b7bc70dd455b61344c7f0a042f9181900360200190a150565b6001600160a01b038116600090815260016020908152604080832081517f59d556a800000000000000000000000000000000000000000000000000000000815260048101919091529051839273ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248083019392829003018186803b158015611bd657600080fd5b505af4158015611bea573d6000803e3d6000fd5b505050506040513d6020811015611c0057600080fd5b5051611c0b84611867565b15611c205769d3c21bcecceda1000000611c23565b60005b915091505b915091565b611c35611788565b611c86576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03821615801590611ca657506001600160a01b03811615155b8015611cd857506001600160a01b0380831660009081526003602090815260408083209385168352929052205460ff16155b611d135760405162461bcd60e51b815260040180806020018281038252605e8152602001806129da605e913960600191505060405180910390fd5b6001600160a01b03808316600081815260036020908152604080832094861680845294825280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660019081179091558484526004835281842080549182018155845291832090910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001685179055517f828d2be040dede7698182e08dfa8bfbd663c879aee772509c4a2bd961d0ed43f9190a35050565b611dd9611788565b611e2a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b611e3381612776565b50565b6007546001600160a01b031681565b611e4d611788565b611e9e576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60008111611edd5760405162461bcd60e51b8152600401808060200182810382526021815260200180612a826021913960400191505060405180910390fd5b6001600160a01b038216600090815260066020526040902054811415611f345760405162461bcd60e51b8152600401808060200182810382526028815260200180612a386028913960400191505060405180910390fd5b6001600160a01b0382166000818152600660209081526040918290208490558151928352820183905280517ff8324c8592dfd9991ee3e717351afe0a964605257959e3d99b0eb3d45bff94229281900390910190a15050565b60005474010000000000000000000000000000000000000000900460ff1615611ffd576040805162461bcd60e51b815260206004820152601c60248201527f636f6e747261637420616c726561647920696e697469616c697a656400000000604482015290519081900360640190fd5b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000017905561204533612776565b611e3381611a3f565b6000806001600160a01b03831661206457600080fd5b6001600160a01b038316600090815260026020908152604080832081517fd938ec7b0000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b9263d938ec7b9260248082019391829003018186803b1580156120e557600080fd5b505af41580156120f9573d6000803e3d6000fd5b505050506040513d602081101561210f57600080fd5b50516001600160a01b03808616600090815260026020908152604080832081517f7c6bb8620000000000000000000000000000000000000000000000000000000081526004810191909152938516602485015251939450909273ed477a99035d0c1e11369f1d7a4e587893cc002b92637c6bb862926044808301939192829003018186803b1580156121a057600080fd5b505af41580156121b4573d6000803e3d6000fd5b505050506040513d60208110156121ca57600080fd5b505190506121d785610f07565b6121e7428363ffffffff61220416565b106121f85750600192509050611c28565b50600092509050915091565b600061224683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061282e565b9392505050565b6001600160a01b03808316600090815260016020908152604080832081517f95073a790000000000000000000000000000000000000000000000000000000081526004810191909152938516602485015251919273ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a7992604480840193919291829003018186803b1580156122da57600080fd5b505af41580156122ee573d6000803e3d6000fd5b505050506040513d602081101561230457600080fd5b5051801561224657506001600160a01b0380841660009081526002602090815260409182902082517f95073a7900000000000000000000000000000000000000000000000000000000815260048101919091529285166024840152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926395073a79926044808301939192829003018186803b15801561239957600080fd5b505af41580156123ad573d6000803e3d6000fd5b505050506040513d60208110156123c357600080fd5b50519392505050565b6123d582610e86565b60011480156123e957506123e9828261224d565b156123f357612714565b6001600160a01b038216600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b15801561247457600080fd5b505af4158015612488573d6000803e3d6000fd5b505050506040513d602081101561249e57600080fd5b50516001600160a01b0380851660009081526001602052604080822081517fc1e728e9000000000000000000000000000000000000000000000000000000008152600481019190915292861660248401525192935073ed477a99035d0c1e11369f1d7a4e587893cc002b9263c1e728e9926044808201939291829003018186803b15801561252b57600080fd5b505af415801561253f573d6000803e3d6000fd5b5050506001600160a01b0380851660009081526002602052604080822081517fc1e728e9000000000000000000000000000000000000000000000000000000008152600481019190915292861660248401525173ed477a99035d0c1e11369f1d7a4e587893cc002b935063c1e728e9926044808201939291829003018186803b1580156125cb57600080fd5b505af41580156125df573d6000803e3d6000fd5b50506040516001600160a01b038086169350861691507fe21a44017b6fa1658d84e937d56ff408501facdb4ff7427c479ac460d76f789390600090a36001600160a01b038316600090815260016020908152604080832081517f59d556a80000000000000000000000000000000000000000000000000000000081526004810191909152905173ed477a99035d0c1e11369f1d7a4e587893cc002b926359d556a89260248082019391829003018186803b15801561269c57600080fd5b505af41580156126b0573d6000803e3d6000fd5b505050506040513d60208110156126c657600080fd5b50519050818114612711576040805182815290516001600160a01b038616917fa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41919081900360200190a25b50505b5050565b3390565b600082820183811015612246576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6001600160a01b0381166127bb5760405162461bcd60e51b81526004018080602001828103825260268152602001806129036026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b600081848411156128bd5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561288257818101518382015260200161286a565b50505050905090810190601f1680156128af5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b815481835581811115611a3a57600083815260209020611a3a91810190830161170f91905b808211156128fe57600081556001016128ea565b509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373746f6b656e2061646472206e756c6c206f7220747279696e6720746f2072656d6f766520746f6f206d616e79207265706f727473746f6b656e2061646472206e756c6c206f72206f7261636c652061646472206e756c6c206f7220696e646578206f6620746f6b656e206f7261636c65206e6f74206d617070656420746f206f7261636c65206164647273656e64657220776173206e6f7420616e206f7261636c6520666f7220746f6b656e2061646472746f6b656e206164647220776173206e756c6c206f72206f7261636c65206164647220776173206e756c6c206f72206f7261636c65206164647220697320616c726561647920616e206f7261636c6520666f7220746f6b656e2061646472746f6b656e207265706f72744578706972795365636f6e6473206861736e2774206368616e6765647265706f72744578706972795365636f6e6473206861736e2774206368616e6765647265706f727420657870697279207365636f6e6473206d757374206265203e2030a265627a7a72315820f8f61cb1481ca4c44fb1f15abaedee325084fda65944e9e7bd5be86816056e7e64736f6c63430005110032

External libraries

AddressLinkedList : 0x6200f54d73491d56b8d7a975c9ee18efb4d518df  
AddressSortedLinkedListWithMedian : 0xed477a99035d0c1e11369f1d7a4e587893cc002b