Address Details
contract

0x49349F92D2B17d491e42C8fdB02D19f072F9B5D9

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




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




Optimization runs
10000
Verified at
2023-09-05T14:32:22.169401Z

lib/mento-core-2.2.0/contracts/oracles/breakers/MedianDeltaBreaker.sol

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

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

import { FixidityLib } from "../../common/FixidityLib.sol";
import { IBreaker } from "../../interfaces/IBreaker.sol";
import { ISortedOracles } from "../../interfaces/ISortedOracles.sol";

import { WithCooldown } from "./WithCooldown.sol";
import { WithThreshold } from "./WithThreshold.sol";

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

  /* ==================== Events ==================== */
  event SmoothingFactorSet(address rateFeedId, uint256 smoothingFactor);
  event BreakerBoxUpdated(address breakerBox);

  event MedianRateEMAReset(address rateFeedID);

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

  // Address of the BreakerBox contract
  address public breakerBox;

  // Default smoothing factor for EMA as a Fixidity value
  uint256 public constant DEFAULT_SMOOTHING_FACTOR = 1e24;

  // Smoothing factor per rate feed
  mapping(address => FixidityLib.Fraction) public smoothingFactors;

  // EMA of the median rates per rate feed
  mapping(address => uint256) public medianRatesEMA;

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

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

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

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

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

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

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

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

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

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

  /*
   * @notice Sets the smoothing factor for a rate feed.
   * @param rateFeedID The rate feed to be updated.
   * @param smoothingFactor The new smoothingFactor value.
   */
  function setSmoothingFactor(address rateFeedID, uint256 newSmoothingFactor) external onlyOwner {
    FixidityLib.Fraction memory _newSmoothingFactor = FixidityLib.wrap(newSmoothingFactor);
    require(_newSmoothingFactor.lte(FixidityLib.fixed1()), "Smoothing factor must be <= 1");
    smoothingFactors[rateFeedID] = _newSmoothingFactor;
    emit SmoothingFactorSet(rateFeedID, newSmoothingFactor);
  }

  /**
   * @notice Resets the median rates EMA for a rate feed.
   * @param rateFeedID the targeted rate feed.
   * @dev Should be called when the breaker is disabled for a rate feed.
   */
  function resetMedianRateEMA(address rateFeedID) external onlyOwner {
    require(rateFeedID != address(0), "RateFeed address must be set");
    medianRatesEMA[rateFeedID] = 0;
    emit MedianRateEMAReset(rateFeedID);
  }

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

  /**
   * @notice  Get the smoothing factor for a rate feed.
   * @param   rateFeedID The rate feed to be checked.
   * @return  smoothingFactor The smoothingFactor for the rate feed.
   */
  function getSmoothingFactor(address rateFeedID) public view returns (uint256) {
    uint256 factor = smoothingFactors[rateFeedID].unwrap();
    if (factor == 0) {
      return DEFAULT_SMOOTHING_FACTOR;
    }
    return factor;
  }

  /**
   * @notice  Check if the current median report rate for a rate feed change, relative
   *          to the last median report, is greater than the configured threshold.
   *          If the change is greater than the threshold the breaker will be triggered.
   * @param   rateFeedID The rate feed to be checked.
   * @return  triggerBreaker  A bool indicating whether or not this breaker
   *                          should be tripped for the rate feed.
   */
  function shouldTrigger(address rateFeedID) public returns (bool triggerBreaker) {
    require(msg.sender == breakerBox, "Caller must be the BreakerBox contract");

    (uint256 currentMedian, ) = sortedOracles.medianRate(rateFeedID);

    uint256 previousRatesEMA = medianRatesEMA[rateFeedID];
    if (previousRatesEMA == 0) {
      // Previous recorded EMA will be 0 the first time this rate feed is checked.
      medianRatesEMA[rateFeedID] = currentMedian;
      return false;
    }

    FixidityLib.Fraction memory smoothingFactor = FixidityLib.wrap(getSmoothingFactor(rateFeedID));
    medianRatesEMA[rateFeedID] = FixidityLib
      .wrap(currentMedian)
      .multiply(smoothingFactor)
      .add(FixidityLib.wrap(previousRatesEMA).multiply(FixidityLib.fixed1().subtract(smoothingFactor)))
      .unwrap();

    return exceedsThreshold(previousRatesEMA, currentMedian, rateFeedID);
  }

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

/lib/mento-core-2.0.0/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-2.0.0/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-2.0.0/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;
    }
}
          

/lib/mento-core-2.2.0/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-2.2.0/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-2.2.0/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-2.2.0/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-2.2.0/contracts/interfaces/IBreaker.sol

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

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

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

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

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

/lib/mento-core-2.2.0/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-2.2.0/contracts/oracles/breakers/WithCooldown.sol

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

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

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

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

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

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

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

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

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

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

/lib/mento-core-2.2.0/contracts/oracles/breakers/WithThreshold.sol

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Compiler Settings

{"remappings":[":celo-foundry/=lib/celo-foundry/src/",":contracts/=contracts/",":ds-test/=lib/celo-foundry/lib/forge-std/lib/ds-test/src/",":forge-std-next/=lib/mento-core-2.2.0/lib/forge-std-next/src/",":forge-std/=lib/celo-foundry/lib/forge-std/src/",":mento-core-2.0.0/=lib/mento-core-2.0.0/contracts/",":mento-core-2.1.0/=lib/mento-core-2.1.0/contracts/",":mento-core-2.2.0/=lib/mento-core-2.2.0/contracts/",":openzeppelin-contracts-next/=lib/mento-core-2.2.0/lib/openzeppelin-contracts-next/",":openzeppelin-contracts-upgradeable/=lib/mento-core-2.2.0/lib/openzeppelin-contracts-upgradeable/",":openzeppelin-contracts/=lib/mento-core-2.0.0/lib/openzeppelin-contracts/contracts/",":openzeppelin-solidity/=lib/mento-core-2.0.0/lib/openzeppelin-contracts/",":test/=lib/mento-core-2.0.0/test/"],"optimizer":{"runs":10000,"enabled":true},"libraries":{"AddressSortedLinkedListWithMedian":"0xed477a99035d0c1e11369f1d7a4e587893cc002b","AddressLinkedList":"0x6200f54d73491d56b8d7a975c9ee18efb4d518df"},"compilationTarget":{"lib/mento-core-2.2.0/contracts/oracles/breakers/MedianDeltaBreaker.sol":"MedianDeltaBreaker"}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"uint256","name":"_defaultCooldownTime","internalType":"uint256"},{"type":"uint256","name":"_defaultRateChangeThreshold","internalType":"uint256"},{"type":"address","name":"_sortedOracles","internalType":"contract ISortedOracles"},{"type":"address","name":"_breakerBox","internalType":"address"},{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"rateChangeThresholds","internalType":"uint256[]"},{"type":"uint256[]","name":"cooldownTimes","internalType":"uint256[]"}]},{"type":"event","name":"BreakerBoxUpdated","inputs":[{"type":"address","name":"breakerBox","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"DefaultCooldownTimeUpdated","inputs":[{"type":"uint256","name":"newCooldownTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"DefaultRateChangeThresholdUpdated","inputs":[{"type":"uint256","name":"defaultRateChangeThreshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"MedianRateEMAReset","inputs":[{"type":"address","name":"rateFeedID","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RateChangeThresholdUpdated","inputs":[{"type":"address","name":"rateFeedID","internalType":"address","indexed":false},{"type":"uint256","name":"rateChangeThreshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RateFeedCooldownTimeUpdated","inputs":[{"type":"address","name":"rateFeedID","internalType":"address","indexed":false},{"type":"uint256","name":"newCooldownTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"SmoothingFactorSet","inputs":[{"type":"address","name":"rateFeedId","internalType":"address","indexed":false},{"type":"uint256","name":"smoothingFactor","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"SortedOraclesUpdated","inputs":[{"type":"address","name":"newSortedOracles","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"DEFAULT_SMOOTHING_FACTOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"breakerBox","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"defaultCooldownTime","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"value","internalType":"uint256"}],"name":"defaultRateChangeThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"exceedsThreshold","inputs":[{"type":"uint256","name":"referenceValue","internalType":"uint256"},{"type":"uint256","name":"currentValue","internalType":"uint256"},{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getCooldown","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getSmoothingFactor","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOwner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"medianRatesEMA","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"value","internalType":"uint256"}],"name":"rateChangeThreshold","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rateFeedCooldownTime","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","name":"resetMedianRateEMA","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","name":"setBreakerBox","inputs":[{"type":"address","name":"_breakerBox","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","name":"setCooldownTime","inputs":[{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"cooldownTimes","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","name":"setDefaultCooldownTime","inputs":[{"type":"uint256","name":"cooldownTime","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","name":"setDefaultRateChangeThreshold","inputs":[{"type":"uint256","name":"_defaultRateChangeThreshold","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","name":"setRateChangeThresholds","inputs":[{"type":"address[]","name":"rateFeedIDs","internalType":"address[]"},{"type":"uint256[]","name":"rateChangeThresholds","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","name":"setSmoothingFactor","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"},{"type":"uint256","name":"newSmoothingFactor","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","name":"setSortedOracles","inputs":[{"type":"address","name":"_sortedOracles","internalType":"contract ISortedOracles"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"resetBreaker","internalType":"bool"}],"name":"shouldReset","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"triggerBreaker","internalType":"bool"}],"name":"shouldTrigger","inputs":[{"type":"address","name":"rateFeedID","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"value","internalType":"uint256"}],"name":"smoothingFactors","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ISortedOracles"}],"name":"sortedOracles","inputs":[]},{"type":"function","stateMutability":"nonpayable","name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
              

Contract Creation Code

0x60806040523480156200001157600080fd5b5060405162002b4938038062002b49833981810160405260e08110156200003757600080fd5b81516020830151604080850151606086015160808701805193519597949692959194919392820192846401000000008211156200007357600080fd5b9083019060208201858111156200008957600080fd5b8251866020820283011164010000000082111715620000a757600080fd5b82525081516020918201928201910280838360005b83811015620000d6578181015183820152602001620000bc565b50505050905001604052602001805160405193929190846401000000008211156200010057600080fd5b9083019060208201858111156200011657600080fd5b82518660208202830111640100000000821117156200013457600080fd5b82525081516020918201928201910280838360005b838110156200016357818101518382015260200162000149565b50505050905001604052602001805160405193929190846401000000008211156200018d57600080fd5b908301906020820185811115620001a357600080fd5b8251866020820283011164010000000082111715620001c157600080fd5b82525081516020918201928201910280838360005b83811015620001f0578181015183820152602001620001d6565b5050505090500160405250505060006200020f620002e760201b60201c565b600480546001600160a01b0319166001600160a01b0383169081179091556040519192509060009060008051602062002b08833981519152908290a35062000260336001600160e01b03620002eb16565b62000274856001600160e01b036200037d16565b62000288846001600160e01b036200046c16565b6200029c876001600160e01b036200057016565b620002b0866001600160e01b03620005ab16565b620002c583836001600160e01b036200068916565b620002da83826001600160e01b03620008d716565b5050505050505062000b01565b3390565b6001600160a01b038116620003325760405162461bcd60e51b815260040180806020018281038252602681526020018062002ac26026913960400191505060405180910390fd5b6004546040516001600160a01b0380841692169060008051602062002b0883398151915290600090a3600480546001600160a01b0319166001600160a01b0392909216919091179055565b620003906001600160e01b0362000a7416565b620003d1576040805162461bcd60e51b8152602060048201819052602482015260008051602062002ae8833981519152604482015290519081900360640190fd5b6001600160a01b038116620004185760405162461bcd60e51b815260040180806020018281038252602181526020018062002b286021913960400191505060405180910390fd5b600580546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b6200047f6001600160e01b0362000a7416565b620004c0576040805162461bcd60e51b8152602060048201819052602482015260008051602062002ae8833981519152604482015290519081900360640190fd5b6001600160a01b0381166200051c576040805162461bcd60e51b815260206004820152601e60248201527f427265616b6572426f782061646472657373206d757374206265207365740000604482015290519081900360640190fd5b600680546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f21921b3b46ef2c939e85d6a14410c6e3b9ce132b66e944357ff4f789f68e00e29181900360200190a150565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b620005c18162000aa560201b620014dc1760201c565b5160025562000601620005df62000ac1602090811b620014f617901c565b6040805160208082019092526002548152919062001d6062000ae7821b17901c565b62000653576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b8051825114620006e0576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015620008d25760006001600160a01b03168382815181106200070557fe5b60200260200101516001600160a01b031614156200075e576040805162461bcd60e51b81526020600482015260116024820152701c985d194819995959081a5b9d985b1a59607a1b604482015290519081900360640190fd5b6200076862000aee565b620007928383815181106200077957fe5b602002602001015162000aa560201b620014dc1760201c565b9050620007c2620007ad62000ac160201b620014f61760201c565b8262000ae760201b62001d601790919060201c565b62000814576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b80600360008685815181106200082657fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a3398483815181106200088957fe5b60200260200101518484815181106200089e57fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a150600101620006e3565b505050565b80518251146200092e576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b8251811015620008d25760006001600160a01b03168382815181106200095357fe5b60200260200101516001600160a01b03161415620009ac576040805162461bcd60e51b81526020600482015260116024820152701c985d194819995959081a5b9d985b1a59607a1b604482015290519081900360640190fd5b818181518110620009b957fe5b602002602001015160016000858481518110620009d257fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c83828151811062000a2c57fe5b602002602001015183838151811062000a4157fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a160010162000931565b6004546000906001600160a01b031662000a966001600160e01b03620002e716565b6001600160a01b031614905090565b62000aaf62000aee565b50604080516020810190915290815290565b62000acb62000aee565b50604080516020810190915269d3c21bcecceda1000000815290565b5190511090565b6040518060200160405280600081525090565b611fb18062000b116000396000f3fe608060405234801561001057600080fd5b50600436106101ae5760003560e01c806353f5d6f1116100ee5780638da5cb5b11610097578063bfc7c45011610071578063bfc7c450146105a1578063f2fde38b146105c7578063f414c5e4146105ed578063fd165f53146105f5576101ae565b80638da5cb5b146105895780638f32d59b14610591578063a44235cb14610599576101ae565b8063715018a6116100c8578063715018a614610529578063753d8c2f146105315780638c54acdc14610563576101ae565b806353f5d6f1146104ac5780635ac3ff70146104d257806368b89d58146104ef576101ae565b806313df95c91161015b5780633151e220116101355780633151e2201461037257806339b84ecf1461039e5780634afb215e146103c45780634e510e88146103ea576101ae565b806313df95c91461031e5780631893304f146103445780632e37ff731461036a576101ae565b80630c62541e1161018c5780630c62541e146102ba5780630f42151f146102d4578063132e8aa7146102fa576101ae565b8063020323dd146101b3578063040bbd351461027757806305e047851461029d575b600080fd5b610275600480360360408110156101c957600080fd5b8101906020810181356401000000008111156101e457600080fd5b8201836020820111156101f657600080fd5b8035906020019184602083028401116401000000008311171561021857600080fd5b91939092909160208101903564010000000081111561023657600080fd5b82018360208201111561024857600080fd5b8035906020019184602083028401116401000000008311171561026a57600080fd5b50909250905061061b565b005b6102756004803603602081101561028d57600080fd5b50356001600160a01b03166106e7565b610275600480360360208110156102b357600080fd5b5035610807565b6102c261086c565b60408051918252519081900360200190f35b6102c2600480360360208110156102ea57600080fd5b50356001600160a01b031661087a565b61030261088c565b604080516001600160a01b039092168252519081900360200190f35b6102c26004803603602081101561033457600080fd5b50356001600160a01b031661089b565b6102c26004803603602081101561035a57600080fd5b50356001600160a01b03166108ee565b6102c2610900565b6102756004803603604081101561038857600080fd5b506001600160a01b038135169060200135610906565b6102c2600480360360208110156103b457600080fd5b50356001600160a01b0316610a36565b610275600480360360208110156103da57600080fd5b50356001600160a01b0316610a5e565b6102756004803603604081101561040057600080fd5b81019060208101813564010000000081111561041b57600080fd5b82018360208201111561042d57600080fd5b8035906020019184602083028401116401000000008311171561044f57600080fd5b91939092909160208101903564010000000081111561046d57600080fd5b82018360208201111561047f57600080fd5b803590602001918460208302840111640100000000831117156104a157600080fd5b509092509050610b68565b6102c2600480360360208110156104c257600080fd5b50356001600160a01b0316610c2e565b610275600480360360208110156104e857600080fd5b5035610c40565b6105156004803603602081101561050557600080fd5b50356001600160a01b0316610ca2565b604080519115158252519081900360200190f35b610275610cb4565b6105156004803603606081101561054757600080fd5b50803590602081013590604001356001600160a01b0316610d6f565b6102c26004803603602081101561057957600080fd5b50356001600160a01b0316610e74565b610302610e86565b610515610e95565b6102c2610ebb565b610275600480360360208110156105b757600080fd5b50356001600160a01b0316610ec1565b610275600480360360208110156105dd57600080fd5b50356001600160a01b0316610fc8565b61030261102a565b6105156004803603602081101561060b57600080fd5b50356001600160a01b0316611039565b610623610e95565b610674576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106e1848480806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250506040805160208088028281018201909352878252909350879250869182918501908490808284376000920191909152506111f292505050565b50505050565b6106ef610e95565b610740576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03811661079b576040805162461bcd60e51b815260206004820152601e60248201527f427265616b6572426f782061646472657373206d757374206265207365740000604482015290519081900360640190fd5b600680546001600160a01b0383167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f21921b3b46ef2c939e85d6a14410c6e3b9ce132b66e944357ff4f789f68e00e29181900360200190a150565b61080f610e95565b610860576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6108698161141d565b50565b69d3c21bcecceda100000081565b60086020526000908152604090205481565b6005546001600160a01b031681565b6001600160a01b0381166000908152600760209081526040808320815192830190915254815281906108cc906114d8565b9050806108e65769d3c21bcecceda10000009150506108e9565b90505b919050565b60036020526000908152604090205481565b60005481565b61090e610e95565b61095f576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610967611edb565b610970826114dc565b905061098a61097d6114f6565b829063ffffffff61151a16565b6109db576040805162461bcd60e51b815260206004820152601d60248201527f536d6f6f7468696e6720666163746f72206d757374206265203c3d2031000000604482015290519081900360640190fd5b6001600160a01b038316600081815260076020908152604091829020845190558151928352820184905280517f6024a1181d4b6670f0122b1101b175bd17051e91a5b57e85972a9187c3f9721c9281900390910190a1505050565b6001600160a01b038116600090815260016020526040812054806108e65750506000546108e9565b610a66610e95565b610ab7576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610afc5760405162461bcd60e51b8152600401808060200182810382526021815260200180611f5c6021913960400191505060405180910390fd5b600580546001600160a01b0383167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b610b70610e95565b610bc1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106e18484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505060408051602080880282810182019093528782529093508792508691829185019084908082843760009201919091525061152792505050565b60016020526000908152604090205481565b610c48610e95565b610c99576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610869816116c7565b6000610cad82611039565b1592915050565b610cbc610e95565b610d0d576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6004546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b604080516020810190915260025481526000908190610d8d906114d8565b6001600160a01b0384166000908152600360209081526040808320815192830190915254815291925090610dc0906114d8565b90508015610dcc578091505b6000610dde610dd96114f6565b6114d8565b90506000610df2828563ffffffff61170216565b90506000610e2069d3c21bcecceda1000000610e148b8563ffffffff61176316565b9063ffffffff6117bc16565b90506000610e34848763ffffffff6117fe16565b90506000610e5669d3c21bcecceda1000000610e148d8563ffffffff61176316565b9050808a1080610e655750828a115b9b9a5050505050505050505050565b60076020526000908152604090205481565b6004546001600160a01b031690565b6004546000906001600160a01b0316610eac611840565b6001600160a01b031614905090565b60025481565b610ec9610e95565b610f1a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610f75576040805162461bcd60e51b815260206004820152601c60248201527f52617465466565642061646472657373206d7573742062652073657400000000604482015290519081900360640190fd5b6001600160a01b038116600081815260086020908152604080832092909255815192835290517f76d186fb6f7faabecd3480fe1bc33d485f376eaed587ac952f4f2e9aca4c29319281900390910190a150565b610fd0610e95565b611021576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61086981611844565b6006546001600160a01b031681565b6006546000906001600160a01b031633146110855760405162461bcd60e51b8152600401808060200182810382526026815260200180611f366026913960400191505060405180910390fd5b600554604080517fef90e1b00000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301528251600094919091169263ef90e1b09260248082019391829003018186803b1580156110ea57600080fd5b505afa1580156110fe573d6000803e3d6000fd5b505050506040513d604081101561111457600080fd5b50516001600160a01b0384166000908152600860205260409020549091508061115b57506001600160a01b03831660009081526008602052604081209190915590506108e9565b611163611edb565b61117461116f8661089b565b6114dc565b90506111c5610dd96111ac6111978461118b6114f6565b9063ffffffff6118fd16565b6111a0866114dc565b9063ffffffff61197516565b6111b9846111a0886114dc565b9063ffffffff611ce716565b6001600160a01b0386166000908152600860205260409020556111e9828487610d6f565b95945050505050565b8051825114611248576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b82518110156114185760006001600160a01b031683828151811061126b57fe5b60200260200101516001600160a01b031614156112cf576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b6112d7611edb565b6112f38383815181106112e657fe5b60200260200101516114dc565b905061130d6113006114f6565b829063ffffffff611d6016565b61135e576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b806003600086858151811061136f57fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a3398483815181106113d157fe5b60200260200101518484815181106113e557fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a15060010161124b565b505050565b611426816114dc565b516002556114516114356114f6565b604080516020810190915260025481529063ffffffff611d6016565b6114a2576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b5190565b6114e4611edb565b50604080516020810190915290815290565b6114fe611edb565b50604080516020810190915269d3c21bcecceda1000000815290565b8051825111155b92915050565b805182511461157d576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b82518110156114185760006001600160a01b03168382815181106115a057fe5b60200260200101516001600160a01b03161415611604576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b81818151811061161057fe5b60200260200101516001600085848151811061162857fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c83828151811061168157fe5b602002602001015183838151811061169557fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a1600101611580565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b60008282018381101561175c576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b60008261177257506000611521565b8282028284828161177f57fe5b041461175c5760405162461bcd60e51b8152600401808060200182810382526021815260200180611f156021913960400191505060405180910390fd5b600061175c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611d67565b600061175c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611e09565b3390565b6001600160a01b0381166118895760405162461bcd60e51b8152600401808060200182810382526026815260200180611eef6026913960400191505060405180910390fd5b6004546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b611905611edb565b81518351101561195c576040805162461bcd60e51b815260206004820152601f60248201527f737562737472616374696f6e20756e646572666c6f7720646574656374656400604482015290519081900360640190fd5b5060408051602081019091528151835103815292915050565b61197d611edb565b8251158061198a57508151155b156119a45750604080516020810190915260008152611521565b815169d3c21bcecceda100000014156119be575081611521565b825169d3c21bcecceda100000014156119d8575080611521565b600069d3c21bcecceda10000006119ee85611e63565b51816119f657fe5b0490506000611a0485611e98565b519050600069d3c21bcecceda1000000611a1d86611e63565b5181611a2557fe5b0490506000611a3386611e98565b5190508382028415611a9c5782858281611a4957fe5b0414611a9c576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207831793120646574656374656400000000000000000000604482015290519081900360640190fd5b69d3c21bcecceda100000081028115611b165769d3c21bcecceda1000000828281611ac357fe5b0414611b16576040805162461bcd60e51b815260206004820152601f60248201527f6f766572666c6f772078317931202a2066697865643120646574656374656400604482015290519081900360640190fd5b9050808484028515611b7f5784868281611b2c57fe5b0414611b7f576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207832793120646574656374656400000000000000000000604482015290519081900360640190fd5b8684028715611be55784888281611b9257fe5b0414611be5576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207831793220646574656374656400000000000000000000604482015290519081900360640190fd5b611bed611ed2565b8781611bf557fe5b049650611c00611ed2565b8581611c0857fe5b0494508685028715611c715785888281611c1e57fe5b0414611c71576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207832793220646574656374656400000000000000000000604482015290519081900360640190fd5b611c79611edb565b6040518060200160405280878152509050611ca281604051806020016040528087815250611ce7565b9050611cbc81604051806020016040528086815250611ce7565b9050611cd681604051806020016040528085815250611ce7565b9d9c50505050505050505050505050565b611cef611edb565b8151835190810190811015611d4b576040805162461bcd60e51b815260206004820152601560248201527f616464206f766572666c6f772064657465637465640000000000000000000000604482015290519081900360640190fd5b60408051602081019091529081529392505050565b5190511090565b60008183611df35760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611db8578181015183820152602001611da0565b50505050905090810190601f168015611de55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611dff57fe5b0495945050505050565b60008184841115611e5b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611db8578181015183820152602001611da0565b505050900390565b611e6b611edb565b604051806020016040528069d3c21bcecceda100000080856000015181611e8e57fe5b0402905292915050565b611ea0611edb565b604051806020016040528069d3c21bcecceda100000080856000015181611ec357fe5b95519504029093039092525090565b64e8d4a5100090565b604051806020016040528060008152509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7743616c6c6572206d7573742062652074686520427265616b6572426f7820636f6e7472616374536f727465644f7261636c65732061646472657373206d75737420626520736574a265627a7a723158207a2eb89744c25c339de9fe8f267099b95edbfaab1b116140e038913dcc16d60464736f6c634300051100324f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65728be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0536f727465644f7261636c65732061646472657373206d7573742062652073657400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000efb84935239dacdecf7c5ba76d8de40b077b7b33000000000000000000000000303ed1df62fa067659b586ebee8de0ece824ab3900000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106101ae5760003560e01c806353f5d6f1116100ee5780638da5cb5b11610097578063bfc7c45011610071578063bfc7c450146105a1578063f2fde38b146105c7578063f414c5e4146105ed578063fd165f53146105f5576101ae565b80638da5cb5b146105895780638f32d59b14610591578063a44235cb14610599576101ae565b8063715018a6116100c8578063715018a614610529578063753d8c2f146105315780638c54acdc14610563576101ae565b806353f5d6f1146104ac5780635ac3ff70146104d257806368b89d58146104ef576101ae565b806313df95c91161015b5780633151e220116101355780633151e2201461037257806339b84ecf1461039e5780634afb215e146103c45780634e510e88146103ea576101ae565b806313df95c91461031e5780631893304f146103445780632e37ff731461036a576101ae565b80630c62541e1161018c5780630c62541e146102ba5780630f42151f146102d4578063132e8aa7146102fa576101ae565b8063020323dd146101b3578063040bbd351461027757806305e047851461029d575b600080fd5b610275600480360360408110156101c957600080fd5b8101906020810181356401000000008111156101e457600080fd5b8201836020820111156101f657600080fd5b8035906020019184602083028401116401000000008311171561021857600080fd5b91939092909160208101903564010000000081111561023657600080fd5b82018360208201111561024857600080fd5b8035906020019184602083028401116401000000008311171561026a57600080fd5b50909250905061061b565b005b6102756004803603602081101561028d57600080fd5b50356001600160a01b03166106e7565b610275600480360360208110156102b357600080fd5b5035610807565b6102c261086c565b60408051918252519081900360200190f35b6102c2600480360360208110156102ea57600080fd5b50356001600160a01b031661087a565b61030261088c565b604080516001600160a01b039092168252519081900360200190f35b6102c26004803603602081101561033457600080fd5b50356001600160a01b031661089b565b6102c26004803603602081101561035a57600080fd5b50356001600160a01b03166108ee565b6102c2610900565b6102756004803603604081101561038857600080fd5b506001600160a01b038135169060200135610906565b6102c2600480360360208110156103b457600080fd5b50356001600160a01b0316610a36565b610275600480360360208110156103da57600080fd5b50356001600160a01b0316610a5e565b6102756004803603604081101561040057600080fd5b81019060208101813564010000000081111561041b57600080fd5b82018360208201111561042d57600080fd5b8035906020019184602083028401116401000000008311171561044f57600080fd5b91939092909160208101903564010000000081111561046d57600080fd5b82018360208201111561047f57600080fd5b803590602001918460208302840111640100000000831117156104a157600080fd5b509092509050610b68565b6102c2600480360360208110156104c257600080fd5b50356001600160a01b0316610c2e565b610275600480360360208110156104e857600080fd5b5035610c40565b6105156004803603602081101561050557600080fd5b50356001600160a01b0316610ca2565b604080519115158252519081900360200190f35b610275610cb4565b6105156004803603606081101561054757600080fd5b50803590602081013590604001356001600160a01b0316610d6f565b6102c26004803603602081101561057957600080fd5b50356001600160a01b0316610e74565b610302610e86565b610515610e95565b6102c2610ebb565b610275600480360360208110156105b757600080fd5b50356001600160a01b0316610ec1565b610275600480360360208110156105dd57600080fd5b50356001600160a01b0316610fc8565b61030261102a565b6105156004803603602081101561060b57600080fd5b50356001600160a01b0316611039565b610623610e95565b610674576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106e1848480806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250506040805160208088028281018201909352878252909350879250869182918501908490808284376000920191909152506111f292505050565b50505050565b6106ef610e95565b610740576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03811661079b576040805162461bcd60e51b815260206004820152601e60248201527f427265616b6572426f782061646472657373206d757374206265207365740000604482015290519081900360640190fd5b600680546001600160a01b0383167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f21921b3b46ef2c939e85d6a14410c6e3b9ce132b66e944357ff4f789f68e00e29181900360200190a150565b61080f610e95565b610860576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6108698161141d565b50565b69d3c21bcecceda100000081565b60086020526000908152604090205481565b6005546001600160a01b031681565b6001600160a01b0381166000908152600760209081526040808320815192830190915254815281906108cc906114d8565b9050806108e65769d3c21bcecceda10000009150506108e9565b90505b919050565b60036020526000908152604090205481565b60005481565b61090e610e95565b61095f576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610967611edb565b610970826114dc565b905061098a61097d6114f6565b829063ffffffff61151a16565b6109db576040805162461bcd60e51b815260206004820152601d60248201527f536d6f6f7468696e6720666163746f72206d757374206265203c3d2031000000604482015290519081900360640190fd5b6001600160a01b038316600081815260076020908152604091829020845190558151928352820184905280517f6024a1181d4b6670f0122b1101b175bd17051e91a5b57e85972a9187c3f9721c9281900390910190a1505050565b6001600160a01b038116600090815260016020526040812054806108e65750506000546108e9565b610a66610e95565b610ab7576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610afc5760405162461bcd60e51b8152600401808060200182810382526021815260200180611f5c6021913960400191505060405180910390fd5b600580546001600160a01b0383167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f590fd633a008765ce9e65e8081adfba311e99e11b958a5ecb5000ea3355f73539181900360200190a150565b610b70610e95565b610bc1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106e18484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505060408051602080880282810182019093528782529093508792508691829185019084908082843760009201919091525061152792505050565b60016020526000908152604090205481565b610c48610e95565b610c99576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610869816116c7565b6000610cad82611039565b1592915050565b610cbc610e95565b610d0d576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6004546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b604080516020810190915260025481526000908190610d8d906114d8565b6001600160a01b0384166000908152600360209081526040808320815192830190915254815291925090610dc0906114d8565b90508015610dcc578091505b6000610dde610dd96114f6565b6114d8565b90506000610df2828563ffffffff61170216565b90506000610e2069d3c21bcecceda1000000610e148b8563ffffffff61176316565b9063ffffffff6117bc16565b90506000610e34848763ffffffff6117fe16565b90506000610e5669d3c21bcecceda1000000610e148d8563ffffffff61176316565b9050808a1080610e655750828a115b9b9a5050505050505050505050565b60076020526000908152604090205481565b6004546001600160a01b031690565b6004546000906001600160a01b0316610eac611840565b6001600160a01b031614905090565b60025481565b610ec9610e95565b610f1a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610f75576040805162461bcd60e51b815260206004820152601c60248201527f52617465466565642061646472657373206d7573742062652073657400000000604482015290519081900360640190fd5b6001600160a01b038116600081815260086020908152604080832092909255815192835290517f76d186fb6f7faabecd3480fe1bc33d485f376eaed587ac952f4f2e9aca4c29319281900390910190a150565b610fd0610e95565b611021576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61086981611844565b6006546001600160a01b031681565b6006546000906001600160a01b031633146110855760405162461bcd60e51b8152600401808060200182810382526026815260200180611f366026913960400191505060405180910390fd5b600554604080517fef90e1b00000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301528251600094919091169263ef90e1b09260248082019391829003018186803b1580156110ea57600080fd5b505afa1580156110fe573d6000803e3d6000fd5b505050506040513d604081101561111457600080fd5b50516001600160a01b0384166000908152600860205260409020549091508061115b57506001600160a01b03831660009081526008602052604081209190915590506108e9565b611163611edb565b61117461116f8661089b565b6114dc565b90506111c5610dd96111ac6111978461118b6114f6565b9063ffffffff6118fd16565b6111a0866114dc565b9063ffffffff61197516565b6111b9846111a0886114dc565b9063ffffffff611ce716565b6001600160a01b0386166000908152600860205260409020556111e9828487610d6f565b95945050505050565b8051825114611248576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b82518110156114185760006001600160a01b031683828151811061126b57fe5b60200260200101516001600160a01b031614156112cf576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b6112d7611edb565b6112f38383815181106112e657fe5b60200260200101516114dc565b905061130d6113006114f6565b829063ffffffff611d6016565b61135e576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b806003600086858151811061136f57fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600082015181600001559050507fb4610b016800a84a54beff5837e8c18d5deb15ebe20fc28f30b55fb7f183a3398483815181106113d157fe5b60200260200101518484815181106113e557fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a15060010161124b565b505050565b611426816114dc565b516002556114516114356114f6565b604080516020810190915260025481529063ffffffff611d6016565b6114a2576040805162461bcd60e51b815260206004820152601960248201527f76616c7565206d757374206265206c657373207468616e203100000000000000604482015290519081900360640190fd5b6040805182815290517fd6eda16822202898d222eeb6da8466a309a480c9319d82df117db598af244c0d9181900360200190a150565b5190565b6114e4611edb565b50604080516020810190915290815290565b6114fe611edb565b50604080516020810190915269d3c21bcecceda1000000815290565b8051825111155b92915050565b805182511461157d576040805162461bcd60e51b815260206004820152601660248201527f6172726179206c656e677468206d6973736d6174636800000000000000000000604482015290519081900360640190fd5b60005b82518110156114185760006001600160a01b03168382815181106115a057fe5b60200260200101516001600160a01b03161415611604576040805162461bcd60e51b815260206004820152601160248201527f72617465206665656420696e76616c6964000000000000000000000000000000604482015290519081900360640190fd5b81818151811061161057fe5b60200260200101516001600085848151811061162857fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055507f1b2e9cb68f822fa2031c648b0d701fdd3f5330d9c60f3e9f0ca3a5c9e2f6285c83828151811061168157fe5b602002602001015183838151811061169557fe5b602090810291909101810151604080516001600160a01b039094168452918301528051918290030190a1600101611580565b60008190556040805182815290517f9f54ba8283224283655cf1e247079a40dc4c214c156638f09c1c45f59502d7a29181900360200190a150565b60008282018381101561175c576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b60008261177257506000611521565b8282028284828161177f57fe5b041461175c5760405162461bcd60e51b8152600401808060200182810382526021815260200180611f156021913960400191505060405180910390fd5b600061175c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611d67565b600061175c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611e09565b3390565b6001600160a01b0381166118895760405162461bcd60e51b8152600401808060200182810382526026815260200180611eef6026913960400191505060405180910390fd5b6004546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b611905611edb565b81518351101561195c576040805162461bcd60e51b815260206004820152601f60248201527f737562737472616374696f6e20756e646572666c6f7720646574656374656400604482015290519081900360640190fd5b5060408051602081019091528151835103815292915050565b61197d611edb565b8251158061198a57508151155b156119a45750604080516020810190915260008152611521565b815169d3c21bcecceda100000014156119be575081611521565b825169d3c21bcecceda100000014156119d8575080611521565b600069d3c21bcecceda10000006119ee85611e63565b51816119f657fe5b0490506000611a0485611e98565b519050600069d3c21bcecceda1000000611a1d86611e63565b5181611a2557fe5b0490506000611a3386611e98565b5190508382028415611a9c5782858281611a4957fe5b0414611a9c576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207831793120646574656374656400000000000000000000604482015290519081900360640190fd5b69d3c21bcecceda100000081028115611b165769d3c21bcecceda1000000828281611ac357fe5b0414611b16576040805162461bcd60e51b815260206004820152601f60248201527f6f766572666c6f772078317931202a2066697865643120646574656374656400604482015290519081900360640190fd5b9050808484028515611b7f5784868281611b2c57fe5b0414611b7f576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207832793120646574656374656400000000000000000000604482015290519081900360640190fd5b8684028715611be55784888281611b9257fe5b0414611be5576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207831793220646574656374656400000000000000000000604482015290519081900360640190fd5b611bed611ed2565b8781611bf557fe5b049650611c00611ed2565b8581611c0857fe5b0494508685028715611c715785888281611c1e57fe5b0414611c71576040805162461bcd60e51b815260206004820152601660248201527f6f766572666c6f77207832793220646574656374656400000000000000000000604482015290519081900360640190fd5b611c79611edb565b6040518060200160405280878152509050611ca281604051806020016040528087815250611ce7565b9050611cbc81604051806020016040528086815250611ce7565b9050611cd681604051806020016040528085815250611ce7565b9d9c50505050505050505050505050565b611cef611edb565b8151835190810190811015611d4b576040805162461bcd60e51b815260206004820152601560248201527f616464206f766572666c6f772064657465637465640000000000000000000000604482015290519081900360640190fd5b60408051602081019091529081529392505050565b5190511090565b60008183611df35760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611db8578181015183820152602001611da0565b50505050905090810190601f168015611de55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611dff57fe5b0495945050505050565b60008184841115611e5b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611db8578181015183820152602001611da0565b505050900390565b611e6b611edb565b604051806020016040528069d3c21bcecceda100000080856000015181611e8e57fe5b0402905292915050565b611ea0611edb565b604051806020016040528069d3c21bcecceda100000080856000015181611ec357fe5b95519504029093039092525090565b64e8d4a5100090565b604051806020016040528060008152509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7743616c6c6572206d7573742062652074686520427265616b6572426f7820636f6e7472616374536f727465644f7261636c65732061646472657373206d75737420626520736574a265627a7a723158207a2eb89744c25c339de9fe8f267099b95edbfaab1b116140e038913dcc16d60464736f6c63430005110032

External libraries

AddressLinkedList : 0x6200f54d73491d56b8d7a975c9ee18efb4d518df  
AddressSortedLinkedListWithMedian : 0xed477a99035d0c1e11369f1d7a4e587893cc002b