Address Details
contract

0x41fdEd6845D19c7236D2C3FB53FE5bCd503542AD

Contract Name
MentoAdapterCeloV2
Creator
0x30e9cc–d5dd73 at 0x6e6661–7cbb80
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
28635219
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
MentoAdapterCeloV2




Optimization enabled
true
Compiler version
v0.8.17+commit.8df45f5f




Optimization runs
10000
EVM Version
london




Verified at
2023-12-12T09:48:23.468948Z

contracts/mentoCeloMainnet/MentoAdapterCeloV2.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

import {MentoAdapterCeloV1} from "./MentoAdapterCeloV1.sol";

contract MentoAdapterCeloV2 is MentoAdapterCeloV1 {
  function getDataFeedsCount() public view virtual override returns (uint256) {
    return 7;
  }

  function getTokenDetailsAtIndex(uint256 tokenIndex) public view virtual override returns (bytes32 dataFeedId, address tokenAddress) {
    if (tokenIndex == 0) {
      return (bytes32("CELO"), 0x765DE816845861e75A25fCA122bb6898B8B1282a);
    } else if (tokenIndex == 1) {
      return (bytes32("CELO/EUR"), 0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73);
    } else if (tokenIndex == 2) {
      return (bytes32("CELO/BRL"), 0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787);
    } else if (tokenIndex == 3) {
      return (bytes32("USDC"), 0xA1A8003936862E7a15092A91898D69fa8bCE290c);
    } else if (tokenIndex == 4) {
      return (bytes32("USDC/EUR"), 0x206B25Ea01E188Ee243131aFdE526bA6E131a016);
    } else if (tokenIndex == 5) {
      return (bytes32("USDC/BRL"), 0x25F21A1f97607Edf6852339fad709728cffb9a9d);
    } else if (tokenIndex == 6) {
      return (bytes32("EUROC/EUR"), 0x26076B9702885d475ac8c3dB3Bd9F250Dc5A318B);
    } else {
      revert TokenNotFoundForIndex(tokenIndex);
    }
  }
}
        

/contracts/utils/math/SafeMath.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // 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 (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @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) {
        return a + b;
    }

    /**
     * @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 a - b;
    }

    /**
     * @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) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting 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 a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting 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.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * 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, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
          

/contracts-upgradeable/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
          

/contracts-upgradeable/utils/AddressUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
          

/evm-connector/contracts/core/CalldataExtractor.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "./RedstoneConstants.sol";

/**
 * @title The base contract with the main logic of data extraction from calldata
 * @author The Redstone Oracles team
 * @dev This contract was created to reuse the same logic in the RedstoneConsumerBase
 * and the ProxyConnector contracts
 */
contract CalldataExtractor is RedstoneConstants {
  using SafeMath for uint256;

  error DataPackageTimestampMustNotBeZero();
  error DataPackageTimestampsMustBeEqual();
  error RedstonePayloadMustHaveAtLeastOneDataPackage();

  function extractTimestampsAndAssertAllAreEqual() public pure returns (uint256 extractedTimestamp) {
    uint256 calldataNegativeOffset = _extractByteSizeOfUnsignedMetadata();
    uint256 dataPackagesCount = _extractDataPackagesCountFromCalldata(calldataNegativeOffset);

    if (dataPackagesCount == 0) {
      revert RedstonePayloadMustHaveAtLeastOneDataPackage();
    }

    calldataNegativeOffset += DATA_PACKAGES_COUNT_BS;
    for (uint256 dataPackageIndex = 0; dataPackageIndex < dataPackagesCount; dataPackageIndex++) {
      uint256 dataPackageByteSize = _getDataPackageByteSize(calldataNegativeOffset);

      // Extracting timestamp for the current data package
      uint48 dataPackageTimestamp; // uint48, because timestamp uses 6 bytes
      uint256 timestampNegativeOffset = (calldataNegativeOffset + TIMESTAMP_NEGATIVE_OFFSET_IN_DATA_PACKAGE_WITH_STANDARD_SLOT_BS);
      uint256 timestampOffset = msg.data.length - timestampNegativeOffset;
      assembly {
        dataPackageTimestamp := calldataload(timestampOffset)
      }

      if (dataPackageTimestamp == 0) {
        revert DataPackageTimestampMustNotBeZero();
      }

      if (extractedTimestamp == 0) {
        extractedTimestamp = dataPackageTimestamp;
      } else if (dataPackageTimestamp != extractedTimestamp) {
        revert DataPackageTimestampsMustBeEqual();
      }

      calldataNegativeOffset += dataPackageByteSize;
    }
  }

  function _getDataPackageByteSize(uint256 calldataNegativeOffset) internal pure returns (uint256) {
    (
      uint256 dataPointsCount,
      uint256 eachDataPointValueByteSize
    ) = _extractDataPointsDetailsForDataPackage(calldataNegativeOffset);

    return
      dataPointsCount *
      (DATA_POINT_SYMBOL_BS + eachDataPointValueByteSize) +
      DATA_PACKAGE_WITHOUT_DATA_POINTS_BS;
  }

  function _extractByteSizeOfUnsignedMetadata() internal pure returns (uint256) {
    // Checking if the calldata ends with the RedStone marker
    bool hasValidRedstoneMarker;
    assembly {
      let calldataLast32Bytes := calldataload(sub(calldatasize(), STANDARD_SLOT_BS))
      hasValidRedstoneMarker := eq(
        REDSTONE_MARKER_MASK,
        and(calldataLast32Bytes, REDSTONE_MARKER_MASK)
      )
    }
    if (!hasValidRedstoneMarker) {
      revert CalldataMustHaveValidPayload();
    }

    // Using uint24, because unsigned metadata byte size number has 3 bytes
    uint24 unsignedMetadataByteSize;
    if (REDSTONE_MARKER_BS_PLUS_STANDARD_SLOT_BS > msg.data.length) {
      revert CalldataOverOrUnderFlow();
    }
    assembly {
      unsignedMetadataByteSize := calldataload(
        sub(calldatasize(), REDSTONE_MARKER_BS_PLUS_STANDARD_SLOT_BS)
      )
    }
    uint256 calldataNegativeOffset = unsignedMetadataByteSize
      + UNSIGNED_METADATA_BYTE_SIZE_BS
      + REDSTONE_MARKER_BS;
    if (calldataNegativeOffset + DATA_PACKAGES_COUNT_BS > msg.data.length) {
      revert IncorrectUnsignedMetadataSize();
    }
    return calldataNegativeOffset;
  }

  // We return uint16, because unsigned metadata byte size number has 2 bytes
  function _extractDataPackagesCountFromCalldata(uint256 calldataNegativeOffset)
    internal
    pure
    returns (uint16 dataPackagesCount)
  {
    uint256 calldataNegativeOffsetWithStandardSlot = calldataNegativeOffset + STANDARD_SLOT_BS;
    if (calldataNegativeOffsetWithStandardSlot > msg.data.length) {
      revert CalldataOverOrUnderFlow();
    }
    assembly {
      dataPackagesCount := calldataload(
        sub(calldatasize(), calldataNegativeOffsetWithStandardSlot)
      )
    }
    return dataPackagesCount;
  }

  function _extractDataPointValueAndDataFeedId(
    uint256 calldataNegativeOffsetForDataPackage,
    uint256 defaultDataPointValueByteSize,
    uint256 dataPointIndex
  ) internal pure virtual returns (bytes32 dataPointDataFeedId, uint256 dataPointValue) {
    uint256 negativeOffsetToDataPoints = calldataNegativeOffsetForDataPackage + DATA_PACKAGE_WITHOUT_DATA_POINTS_BS;
    uint256 dataPointNegativeOffset = negativeOffsetToDataPoints.add(
      (1 + dataPointIndex).mul((defaultDataPointValueByteSize + DATA_POINT_SYMBOL_BS))
    );
    uint256 dataPointCalldataOffset = msg.data.length.sub(dataPointNegativeOffset);
    assembly {
      dataPointDataFeedId := calldataload(dataPointCalldataOffset)
      dataPointValue := calldataload(add(dataPointCalldataOffset, DATA_POINT_SYMBOL_BS))
    }
  }

  function _extractDataPointsDetailsForDataPackage(uint256 calldataNegativeOffsetForDataPackage)
    internal
    pure
    returns (uint256 dataPointsCount, uint256 eachDataPointValueByteSize)
  {
    // Using uint24, because data points count byte size number has 3 bytes
    uint24 dataPointsCount_;

    // Using uint32, because data point value byte size has 4 bytes
    uint32 eachDataPointValueByteSize_;

    // Extract data points count
    uint256 negativeCalldataOffset = calldataNegativeOffsetForDataPackage + SIG_BS;
    uint256 calldataOffset = msg.data.length.sub(negativeCalldataOffset + STANDARD_SLOT_BS);
    assembly {
      dataPointsCount_ := calldataload(calldataOffset)
    }

    // Extract each data point value size
    calldataOffset = calldataOffset.sub(DATA_POINTS_COUNT_BS);
    assembly {
      eachDataPointValueByteSize_ := calldataload(calldataOffset)
    }

    // Prepare returned values
    dataPointsCount = dataPointsCount_;
    eachDataPointValueByteSize = eachDataPointValueByteSize_;
  }
}
          

/evm-connector/contracts/core/RedstoneConstants.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.4;

/**
 * @title The base contract with helpful constants
 * @author The Redstone Oracles team
 * @dev It mainly contains redstone-related values, which improve readability
 * of other contracts (e.g. CalldataExtractor and RedstoneConsumerBase)
 */
contract RedstoneConstants {
  // === Abbreviations ===
  // BS - Bytes size
  // PTR - Pointer (memory location)
  // SIG - Signature

  // Solidity and YUL constants
  uint256 internal constant STANDARD_SLOT_BS = 32;
  uint256 internal constant FREE_MEMORY_PTR = 0x40;
  uint256 internal constant BYTES_ARR_LEN_VAR_BS = 32;
  uint256 internal constant FUNCTION_SIGNATURE_BS = 4;
  uint256 internal constant REVERT_MSG_OFFSET = 68; // Revert message structure described here: https://ethereum.stackexchange.com/a/66173/106364
  uint256 internal constant STRING_ERR_MESSAGE_MASK = 0x08c379a000000000000000000000000000000000000000000000000000000000;

  // RedStone protocol consts
  uint256 internal constant SIG_BS = 65;
  uint256 internal constant TIMESTAMP_BS = 6;
  uint256 internal constant DATA_PACKAGES_COUNT_BS = 2;
  uint256 internal constant DATA_POINTS_COUNT_BS = 3;
  uint256 internal constant DATA_POINT_VALUE_BYTE_SIZE_BS = 4;
  uint256 internal constant DATA_POINT_SYMBOL_BS = 32;
  uint256 internal constant DEFAULT_DATA_POINT_VALUE_BS = 32;
  uint256 internal constant UNSIGNED_METADATA_BYTE_SIZE_BS = 3;
  uint256 internal constant REDSTONE_MARKER_BS = 9; // byte size of 0x000002ed57011e0000
  uint256 internal constant REDSTONE_MARKER_MASK = 0x0000000000000000000000000000000000000000000000000002ed57011e0000;

  // Derived values (based on consts)
  uint256 internal constant TIMESTAMP_NEGATIVE_OFFSET_IN_DATA_PACKAGE_WITH_STANDARD_SLOT_BS = 104; // SIG_BS + DATA_POINTS_COUNT_BS + DATA_POINT_VALUE_BYTE_SIZE_BS + STANDARD_SLOT_BS
  uint256 internal constant DATA_PACKAGE_WITHOUT_DATA_POINTS_BS = 78; // DATA_POINT_VALUE_BYTE_SIZE_BS + TIMESTAMP_BS + DATA_POINTS_COUNT_BS + SIG_BS
  uint256 internal constant DATA_PACKAGE_WITHOUT_DATA_POINTS_AND_SIG_BS = 13; // DATA_POINT_VALUE_BYTE_SIZE_BS + TIMESTAMP_BS + DATA_POINTS_COUNT_BS
  uint256 internal constant REDSTONE_MARKER_BS_PLUS_STANDARD_SLOT_BS = 41; // REDSTONE_MARKER_BS + STANDARD_SLOT_BS

  // Error messages
  error CalldataOverOrUnderFlow();
  error IncorrectUnsignedMetadataSize();
  error InsufficientNumberOfUniqueSigners(uint256 receivedSignersCount, uint256 requiredSignersCount);
  error EachSignerMustProvideTheSameValue();
  error EmptyCalldataPointersArr();
  error InvalidCalldataPointer();
  error CalldataMustHaveValidPayload();
  error SignerNotAuthorised(address receivedSigner);
}
          

/evm-connector/contracts/core/RedstoneConsumerBase.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "./RedstoneConstants.sol";
import "./RedstoneDefaultsLib.sol";
import "./CalldataExtractor.sol";
import "../libs/BitmapLib.sol";
import "../libs/SignatureLib.sol";

/**
 * @title The base contract with the main Redstone logic
 * @author The Redstone Oracles team
 * @dev Do not use this contract directly in consumer contracts, take a
 * look at `RedstoneConsumerNumericBase` and `RedstoneConsumerBytesBase` instead
 */
abstract contract RedstoneConsumerBase is CalldataExtractor {
  using SafeMath for uint256;

  error GetDataServiceIdNotImplemented();

  /* ========== VIRTUAL FUNCTIONS (MAY BE OVERRIDDEN IN CHILD CONTRACTS) ========== */

  /**
   * @dev This function must be implemented by the child consumer contract.
   * It should return dataServiceId which DataServiceWrapper will use if not provided explicitly .
   * If not overridden, value will always have to be provided explicitly in DataServiceWrapper.
   * @return dataServiceId being consumed by contract
   */
  function getDataServiceId() public view virtual returns (string memory) {
    revert GetDataServiceIdNotImplemented();
  }

  /**
   * @dev This function must be implemented by the child consumer contract.
   * It should return a unique index for a given signer address if the signer
   * is authorised, otherwise it should revert
   * @param receivedSigner The address of a signer, recovered from ECDSA signature
   * @return Unique index for a signer in the range [0..255]
   */
  function getAuthorisedSignerIndex(address receivedSigner) public view virtual returns (uint8);

  /**
   * @dev This function may be overridden by the child consumer contract.
   * It should validate the timestamp against the current time (block.timestamp)
   * It should revert with a helpful message if the timestamp is not valid
   * @param receivedTimestampMilliseconds Timestamp extracted from calldata
   */
  function validateTimestamp(uint256 receivedTimestampMilliseconds) public view virtual {
    RedstoneDefaultsLib.validateTimestamp(receivedTimestampMilliseconds);
  }

  /**
   * @dev This function should be overridden by the child consumer contract.
   * @return The minimum required value of unique authorised signers
   */
  function getUniqueSignersThreshold() public view virtual returns (uint8) {
    return 1;
  }

  /**
   * @dev This function may be overridden by the child consumer contract.
   * It should aggregate values from different signers to a single uint value.
   * By default, it calculates the median value
   * @param values An array of uint256 values from different signers
   * @return Result of the aggregation in the form of a single number
   */
  function aggregateValues(uint256[] memory values) public view virtual returns (uint256) {
    return RedstoneDefaultsLib.aggregateValues(values);
  }

  /* ========== FUNCTIONS WITH IMPLEMENTATION (CAN NOT BE OVERRIDDEN) ========== */

  /**
   * @dev This is an internal helpful function for secure extraction oracle values
   * from the tx calldata. Security is achieved by signatures verification, timestamp
   * validation, and aggregating values from different authorised signers into a
   * single numeric value. If any of the required conditions (e.g. too old timestamp or
   * insufficient number of authorised signers) do not match, the function will revert.
   *
   * Note! You should not call this function in a consumer contract. You can use
   * `getOracleNumericValuesFromTxMsg` or `getOracleNumericValueFromTxMsg` instead.
   *
   * @param dataFeedIds An array of unique data feed identifiers
   * @return An array of the extracted and verified oracle values in the same order
   * as they are requested in dataFeedIds array
   */
  function _securelyExtractOracleValuesFromTxMsg(bytes32[] memory dataFeedIds)
    internal
    view
    returns (uint256[] memory)
  {
    // Initializing helpful variables and allocating memory
    uint256[] memory uniqueSignerCountForDataFeedIds = new uint256[](dataFeedIds.length);
    uint256[] memory signersBitmapForDataFeedIds = new uint256[](dataFeedIds.length);
    uint256[][] memory valuesForDataFeeds = new uint256[][](dataFeedIds.length);
    for (uint256 i = 0; i < dataFeedIds.length; i++) {
      // The line below is commented because newly allocated arrays are filled with zeros
      // But we left it for better readability
      // signersBitmapForDataFeedIds[i] = 0; // <- setting to an empty bitmap
      valuesForDataFeeds[i] = new uint256[](getUniqueSignersThreshold());
    }

    // Extracting the number of data packages from calldata
    uint256 calldataNegativeOffset = _extractByteSizeOfUnsignedMetadata();
    uint256 dataPackagesCount = _extractDataPackagesCountFromCalldata(calldataNegativeOffset);
    calldataNegativeOffset += DATA_PACKAGES_COUNT_BS;

    // Saving current free memory pointer
    uint256 freeMemPtr;
    assembly {
      freeMemPtr := mload(FREE_MEMORY_PTR)
    }

    // Data packages extraction in a loop
    for (uint256 dataPackageIndex = 0; dataPackageIndex < dataPackagesCount; dataPackageIndex++) {
      // Extract data package details and update calldata offset
      uint256 dataPackageByteSize = _extractDataPackage(
        dataFeedIds,
        uniqueSignerCountForDataFeedIds,
        signersBitmapForDataFeedIds,
        valuesForDataFeeds,
        calldataNegativeOffset
      );
      calldataNegativeOffset += dataPackageByteSize;

      // Shifting memory pointer back to the "safe" value
      assembly {
        mstore(FREE_MEMORY_PTR, freeMemPtr)
      }
    }

    // Validating numbers of unique signers and calculating aggregated values for each dataFeedId
    return _getAggregatedValues(valuesForDataFeeds, uniqueSignerCountForDataFeedIds);
  }

  /**
   * @dev This is a private helpful function, which extracts data for a data package based
   * on the given negative calldata offset, verifies them, and in the case of successful
   * verification updates the corresponding data package values in memory
   *
   * @param dataFeedIds an array of unique data feed identifiers
   * @param uniqueSignerCountForDataFeedIds an array with the numbers of unique signers
   * for each data feed
   * @param signersBitmapForDataFeedIds an array of signer bitmaps for data feeds
   * @param valuesForDataFeeds 2-dimensional array, valuesForDataFeeds[i][j] contains
   * j-th value for the i-th data feed
   * @param calldataNegativeOffset negative calldata offset for the given data package
   *
   * @return An array of the aggregated values
   */
  function _extractDataPackage(
    bytes32[] memory dataFeedIds,
    uint256[] memory uniqueSignerCountForDataFeedIds,
    uint256[] memory signersBitmapForDataFeedIds,
    uint256[][] memory valuesForDataFeeds,
    uint256 calldataNegativeOffset
  ) private view returns (uint256) {
    uint256 signerIndex;

    (
      uint256 dataPointsCount,
      uint256 eachDataPointValueByteSize
    ) = _extractDataPointsDetailsForDataPackage(calldataNegativeOffset);

    // We use scopes to resolve problem with too deep stack
    {
      uint48 extractedTimestamp;
      address signerAddress;
      bytes32 signedHash;
      bytes memory signedMessage;
      uint256 signedMessageBytesCount;

      signedMessageBytesCount = dataPointsCount.mul(eachDataPointValueByteSize + DATA_POINT_SYMBOL_BS)
        + DATA_PACKAGE_WITHOUT_DATA_POINTS_AND_SIG_BS; //DATA_POINT_VALUE_BYTE_SIZE_BS + TIMESTAMP_BS + DATA_POINTS_COUNT_BS

      uint256 timestampCalldataOffset = msg.data.length.sub(
        calldataNegativeOffset + TIMESTAMP_NEGATIVE_OFFSET_IN_DATA_PACKAGE_WITH_STANDARD_SLOT_BS);

      uint256 signedMessageCalldataOffset = msg.data.length.sub(
        calldataNegativeOffset + SIG_BS + signedMessageBytesCount);

      assembly {
        // Extracting the signed message
        signedMessage := extractBytesFromCalldata(
          signedMessageCalldataOffset,
          signedMessageBytesCount
        )

        // Hashing the signed message
        signedHash := keccak256(add(signedMessage, BYTES_ARR_LEN_VAR_BS), signedMessageBytesCount)

        // Extracting timestamp
        extractedTimestamp := calldataload(timestampCalldataOffset)

        function initByteArray(bytesCount) -> ptr {
          ptr := mload(FREE_MEMORY_PTR)
          mstore(ptr, bytesCount)
          ptr := add(ptr, BYTES_ARR_LEN_VAR_BS)
          mstore(FREE_MEMORY_PTR, add(ptr, bytesCount))
        }

        function extractBytesFromCalldata(offset, bytesCount) -> extractedBytes {
          let extractedBytesStartPtr := initByteArray(bytesCount)
          calldatacopy(
            extractedBytesStartPtr,
            offset,
            bytesCount
          )
          extractedBytes := sub(extractedBytesStartPtr, BYTES_ARR_LEN_VAR_BS)
        }
      }

      // Validating timestamp
      validateTimestamp(extractedTimestamp);

      // Verifying the off-chain signature against on-chain hashed data
      signerAddress = SignatureLib.recoverSignerAddress(
        signedHash,
        calldataNegativeOffset + SIG_BS
      );
      signerIndex = getAuthorisedSignerIndex(signerAddress);
    }

    // Updating helpful arrays
    {
      bytes32 dataPointDataFeedId;
      uint256 dataPointValue;
      for (uint256 dataPointIndex = 0; dataPointIndex < dataPointsCount; dataPointIndex++) {
        // Extracting data feed id and value for the current data point
        (dataPointDataFeedId, dataPointValue) = _extractDataPointValueAndDataFeedId(
          calldataNegativeOffset,
          eachDataPointValueByteSize,
          dataPointIndex
        );

        for (
          uint256 dataFeedIdIndex = 0;
          dataFeedIdIndex < dataFeedIds.length;
          dataFeedIdIndex++
        ) {
          if (dataPointDataFeedId == dataFeedIds[dataFeedIdIndex]) {
            uint256 bitmapSignersForDataFeedId = signersBitmapForDataFeedIds[dataFeedIdIndex];

            if (
              !BitmapLib.getBitFromBitmap(bitmapSignersForDataFeedId, signerIndex) && /* current signer was not counted for current dataFeedId */
              uniqueSignerCountForDataFeedIds[dataFeedIdIndex] < getUniqueSignersThreshold()
            ) {
              // Increase unique signer counter
              uniqueSignerCountForDataFeedIds[dataFeedIdIndex]++;

              // Add new value
              valuesForDataFeeds[dataFeedIdIndex][
                uniqueSignerCountForDataFeedIds[dataFeedIdIndex] - 1
              ] = dataPointValue;

              // Update signers bitmap
              signersBitmapForDataFeedIds[dataFeedIdIndex] = BitmapLib.setBitInBitmap(
                bitmapSignersForDataFeedId,
                signerIndex
              );
            }

            // Breaking, as there couldn't be several indexes for the same feed ID
            break;
          }
        }
      }
    }

    // Return total data package byte size
    return
      DATA_PACKAGE_WITHOUT_DATA_POINTS_BS +
      (eachDataPointValueByteSize + DATA_POINT_SYMBOL_BS) *
      dataPointsCount;
  }

  /**
   * @dev This is a private helpful function, which aggregates values from different
   * authorised signers for the given arrays of values for each data feed
   *
   * @param valuesForDataFeeds 2-dimensional array, valuesForDataFeeds[i][j] contains
   * j-th value for the i-th data feed
   * @param uniqueSignerCountForDataFeedIds an array with the numbers of unique signers
   * for each data feed
   *
   * @return An array of the aggregated values
   */
  function _getAggregatedValues(
    uint256[][] memory valuesForDataFeeds,
    uint256[] memory uniqueSignerCountForDataFeedIds
  ) private view returns (uint256[] memory) {
    uint256[] memory aggregatedValues = new uint256[](valuesForDataFeeds.length);
    uint256 uniqueSignersThreshold = getUniqueSignersThreshold();

    for (uint256 dataFeedIndex = 0; dataFeedIndex < valuesForDataFeeds.length; dataFeedIndex++) {
      if (uniqueSignerCountForDataFeedIds[dataFeedIndex] < uniqueSignersThreshold) {
        revert InsufficientNumberOfUniqueSigners(
          uniqueSignerCountForDataFeedIds[dataFeedIndex],
          uniqueSignersThreshold);
      }
      uint256 aggregatedValueForDataFeedId = aggregateValues(valuesForDataFeeds[dataFeedIndex]);
      aggregatedValues[dataFeedIndex] = aggregatedValueForDataFeedId;
    }

    return aggregatedValues;
  }
}
          

/evm-connector/contracts/core/RedstoneConsumerNumericBase.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.4;

import "./RedstoneConsumerBase.sol";

/**
 * @title The base contract for Redstone consumers' contracts that allows to
 * securely calculate numeric redstone oracle values
 * @author The Redstone Oracles team
 * @dev This contract can extend other contracts to allow them
 * securely fetch Redstone oracle data from transactions calldata
 */
abstract contract RedstoneConsumerNumericBase is RedstoneConsumerBase {
  /**
   * @dev This function can be used in a consumer contract to securely extract an
   * oracle value for a given data feed id. Security is achieved by
   * signatures verification, timestamp validation, and aggregating values
   * from different authorised signers into a single numeric value. If any of the
   * required conditions do not match, the function will revert.
   * Note! This function expects that tx calldata contains redstone payload in the end
   * Learn more about redstone payload here: https://github.com/redstone-finance/redstone-oracles-monorepo/tree/main/packages/evm-connector#readme
   * @param dataFeedId bytes32 value that uniquely identifies the data feed
   * @return Extracted and verified numeric oracle value for the given data feed id
   */
  function getOracleNumericValueFromTxMsg(bytes32 dataFeedId)
    internal
    view
    virtual
    returns (uint256)
  {
    bytes32[] memory dataFeedIds = new bytes32[](1);
    dataFeedIds[0] = dataFeedId;
    return getOracleNumericValuesFromTxMsg(dataFeedIds)[0];
  }

  /**
   * @dev This function can be used in a consumer contract to securely extract several
   * numeric oracle values for a given array of data feed ids. Security is achieved by
   * signatures verification, timestamp validation, and aggregating values
   * from different authorised signers into a single numeric value. If any of the
   * required conditions do not match, the function will revert.
   * Note! This function expects that tx calldata contains redstone payload in the end
   * Learn more about redstone payload here: https://github.com/redstone-finance/redstone-oracles-monorepo/tree/main/packages/evm-connector#readme
   * @param dataFeedIds An array of unique data feed identifiers
   * @return An array of the extracted and verified oracle values in the same order
   * as they are requested in the dataFeedIds array
   */
  function getOracleNumericValuesFromTxMsg(bytes32[] memory dataFeedIds)
    internal
    view
    virtual
    returns (uint256[] memory)
  {
    return _securelyExtractOracleValuesFromTxMsg(dataFeedIds);
  }

  /**
   * @dev This function works similarly to the `getOracleNumericValuesFromTxMsg` with the
   * only difference that it allows to request oracle data for an array of data feeds
   * that may contain duplicates
   * 
   * @param dataFeedIdsWithDuplicates An array of data feed identifiers (duplicates are allowed)
   * @return An array of the extracted and verified oracle values in the same order
   * as they are requested in the dataFeedIdsWithDuplicates array
   */
  function getOracleNumericValuesWithDuplicatesFromTxMsg(bytes32[] memory dataFeedIdsWithDuplicates) internal view returns (uint256[] memory) {
    // Building an array without duplicates
    bytes32[] memory dataFeedIdsWithoutDuplicates = new bytes32[](dataFeedIdsWithDuplicates.length);
    bool alreadyIncluded;
    uint256 uniqueDataFeedIdsCount = 0;

    for (uint256 indexWithDup = 0; indexWithDup < dataFeedIdsWithDuplicates.length; indexWithDup++) {
      // Checking if current element is already included in `dataFeedIdsWithoutDuplicates`
      alreadyIncluded = false;
      for (uint256 indexWithoutDup = 0; indexWithoutDup < uniqueDataFeedIdsCount; indexWithoutDup++) {
        if (dataFeedIdsWithoutDuplicates[indexWithoutDup] == dataFeedIdsWithDuplicates[indexWithDup]) {
          alreadyIncluded = true;
          break;
        }
      }

      // Adding if not included
      if (!alreadyIncluded) {
        dataFeedIdsWithoutDuplicates[uniqueDataFeedIdsCount] = dataFeedIdsWithDuplicates[indexWithDup];
        uniqueDataFeedIdsCount++;
      }
    }

    // Overriding dataFeedIdsWithoutDuplicates.length
    // Equivalent to: dataFeedIdsWithoutDuplicates.length = uniqueDataFeedIdsCount;
    assembly {
      mstore(dataFeedIdsWithoutDuplicates, uniqueDataFeedIdsCount)
    }

    // Requesting oracle values (without duplicates)
    uint256[] memory valuesWithoutDuplicates = getOracleNumericValuesFromTxMsg(dataFeedIdsWithoutDuplicates);

    // Preparing result values array
    uint256[] memory valuesWithDuplicates = new uint256[](dataFeedIdsWithDuplicates.length);
    for (uint256 indexWithDup = 0; indexWithDup < dataFeedIdsWithDuplicates.length; indexWithDup++) {
      for (uint256 indexWithoutDup = 0; indexWithoutDup < dataFeedIdsWithoutDuplicates.length; indexWithoutDup++) {
        if (dataFeedIdsWithDuplicates[indexWithDup] == dataFeedIdsWithoutDuplicates[indexWithoutDup]) {
          valuesWithDuplicates[indexWithDup] = valuesWithoutDuplicates[indexWithoutDup];
          break;
        }
      }
    }

    return valuesWithDuplicates;
  }
}
          

/evm-connector/contracts/core/RedstoneDefaultsLib.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.4;

import "../libs/NumericArrayLib.sol";

/**
 * @title Default implementations of virtual redstone consumer base functions
 * @author The Redstone Oracles team
 */
library RedstoneDefaultsLib {
  uint256 constant DEFAULT_MAX_DATA_TIMESTAMP_DELAY_SECONDS = 3 minutes;
  uint256 constant DEFAULT_MAX_DATA_TIMESTAMP_AHEAD_SECONDS = 1 minutes;

  error TimestampFromTooLongFuture(uint256 receivedTimestampSeconds, uint256 blockTimestamp);
  error TimestampIsTooOld(uint256 receivedTimestampSeconds, uint256 blockTimestamp);

  function validateTimestamp(uint256 receivedTimestampMilliseconds) internal view {
    // Getting data timestamp from future seems quite unlikely
    // But we've already spent too much time with different cases
    // Where block.timestamp was less than dataPackage.timestamp.
    // Some blockchains may case this problem as well.
    // That's why we add MAX_BLOCK_TIMESTAMP_DELAY
    // and allow data "from future" but with a small delay
    uint256 receivedTimestampSeconds = receivedTimestampMilliseconds / 1000;

    if (block.timestamp < receivedTimestampSeconds) {
      if ((receivedTimestampSeconds - block.timestamp) > DEFAULT_MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
        revert TimestampFromTooLongFuture(receivedTimestampSeconds, block.timestamp);
      }
    } else if ((block.timestamp - receivedTimestampSeconds) > DEFAULT_MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
      revert TimestampIsTooOld(receivedTimestampSeconds, block.timestamp);
    }
  }

  function aggregateValues(uint256[] memory values) internal pure returns (uint256) {
    return NumericArrayLib.pickMedian(values);
  }
}
          

/evm-connector/contracts/libs/BitmapLib.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

library BitmapLib {
  function setBitInBitmap(uint256 bitmap, uint256 bitIndex) internal pure returns (uint256) {
    return bitmap | (1 << bitIndex);
  }

  function getBitFromBitmap(uint256 bitmap, uint256 bitIndex) internal pure returns (bool) {
    uint256 bitAtIndex = bitmap & (1 << bitIndex);
    return bitAtIndex > 0;
  }
}
          

/evm-connector/contracts/libs/NumericArrayLib.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

library NumericArrayLib {
  // This function sort array in memory using bubble sort algorithm,
  // which performs even better than quick sort for small arrays

  uint256 constant BYTES_ARR_LEN_VAR_BS = 32;
  uint256 constant UINT256_VALUE_BS = 32;

  error CanNotPickMedianOfEmptyArray();

  // This function modifies the array
  function pickMedian(uint256[] memory arr) internal pure returns (uint256) {
    if (arr.length == 0) {
      revert CanNotPickMedianOfEmptyArray();
    }
    sort(arr);
    uint256 middleIndex = arr.length / 2;
    if (arr.length % 2 == 0) {
      uint256 sum = SafeMath.add(arr[middleIndex - 1], arr[middleIndex]);
      return sum / 2;
    } else {
      return arr[middleIndex];
    }
  }

  function sort(uint256[] memory arr) internal pure {
    assembly {
      let arrLength := mload(arr)
      let valuesPtr := add(arr, BYTES_ARR_LEN_VAR_BS)
      let endPtr := add(valuesPtr, mul(arrLength, UINT256_VALUE_BS))
      for {
        let arrIPtr := valuesPtr
      } lt(arrIPtr, endPtr) {
        arrIPtr := add(arrIPtr, UINT256_VALUE_BS) // arrIPtr += 32
      } {
        for {
          let arrJPtr := valuesPtr
        } lt(arrJPtr, arrIPtr) {
          arrJPtr := add(arrJPtr, UINT256_VALUE_BS) // arrJPtr += 32
        } {
          let arrI := mload(arrIPtr)
          let arrJ := mload(arrJPtr)
          if lt(arrI, arrJ) {
            mstore(arrIPtr, arrJ)
            mstore(arrJPtr, arrI)
          }
        }
      }
    }
  }
}
          

/evm-connector/contracts/libs/SignatureLib.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

library SignatureLib {
  uint256 constant ECDSA_SIG_R_BS = 32;
  uint256 constant ECDSA_SIG_S_BS = 32;

  function recoverSignerAddress(bytes32 signedHash, uint256 signatureCalldataNegativeOffset)
    internal
    pure
    returns (address)
  {
    bytes32 r;
    bytes32 s;
    uint8 v;
    assembly {
      let signatureCalldataStartPos := sub(calldatasize(), signatureCalldataNegativeOffset)
      r := calldataload(signatureCalldataStartPos)
      signatureCalldataStartPos := add(signatureCalldataStartPos, ECDSA_SIG_R_BS)
      s := calldataload(signatureCalldataStartPos)
      signatureCalldataStartPos := add(signatureCalldataStartPos, ECDSA_SIG_S_BS)
      v := byte(0, calldataload(signatureCalldataStartPos)) // last byte of the signature memory array
    }
    return ecrecover(signedHash, v, r, s);
  }
}
          

/mentoCeloMainnet/MentoAdapterCeloV1.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

import {MentoAdapterPrimaryProd} from "mento-redstone-oracles-monorepo-789f66c/packages/on-chain-relayer/contracts/custom-integrations/mento/data-services/MentoAdapterPrimaryProd.sol";
import {ISortedOracles} from "mento-redstone-oracles-monorepo-789f66c/packages/on-chain-relayer/contracts/custom-integrations/mento/ISortedOracles.sol";

contract MentoAdapterCeloV1 is MentoAdapterPrimaryProd {

  function getSortedOracles() public view virtual override returns (ISortedOracles sortedOracles) {
    return ISortedOracles(0xefB84935239dAcdecF7c5bA76d8dE40b077B7b33);
  }

  function getDataFeedsCount() public view virtual override returns (uint256) {
    return 3;
  }

  function getTokenDetailsAtIndex(uint256 tokenIndex) public view virtual override returns (bytes32 dataFeedId, address tokenAddress) {
    if (tokenIndex == 0) {
      return (bytes32("CELO"), 0x765DE816845861e75A25fCA122bb6898B8B1282a);
    } else if (tokenIndex == 1) {
      return (bytes32("CELO/EUR"), 0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73);
    } else if (tokenIndex == 2) {
      return (bytes32("CELO/BRL"), 0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787);
    } else {
      revert TokenNotFoundForIndex(tokenIndex);
    }
  }
}
          

/packages/on-chain-relayer/contracts/core/IRedstoneAdapter.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

/**
 * @title Interface of RedStone adapter
 * @author The Redstone Oracles team
 */
interface IRedstoneAdapter {

  /**
   * @notice Updates values of all data feeds supported by the Adapter contract
   * @dev This function requires an attached redstone payload to the transaction calldata.
   * It also requires each data package to have exactly the same timestamp
   * @param dataPackagesTimestamp Timestamp of each signed data package in the redstone payload
   */
  function updateDataFeedsValues(uint256 dataPackagesTimestamp) external;


  /**
   * @notice Returns the latest properly reported value of the data feed
   * @param dataFeedId The identifier of the requested data feed
   * @return value The latest value of the given data feed
   */
  function getValueForDataFeed(bytes32 dataFeedId) external view returns (uint256);

  /**
   * @notice Returns the latest properly reported values for several data feeds
   * @param requestedDataFeedIds The array of identifiers for the requested feeds
   * @return values Values of the requested data feeds in the corresponding order
   */
  function getValuesForDataFeeds(bytes32[] memory requestedDataFeedIds) external view returns (uint256[] memory);

  /**
   * @notice Returns data timestamp from the latest update
   * @dev It's virtual, because its implementation can sometimes be different
   * (e.g. SinglePriceFeedAdapterWithClearing)
   * @return lastDataTimestamp Timestamp of the latest reported data packages
   */
  function getDataTimestampFromLatestUpdate() external view returns (uint256 lastDataTimestamp);

  /**
   * @notice Returns block timestamp of the latest successful update
   * @return blockTimestamp The block timestamp of the latest successful update
   */
  function getBlockTimestampFromLatestUpdate() external view returns (uint256 blockTimestamp);


  /**
   * @notice Returns timestamps of the latest successful update
   * @return dataTimestamp timestamp (usually in milliseconds) from the signed data packages
   * @return blockTimestamp timestamp of the block when the update has happened
   */
  function getTimestampsFromLatestUpdate() external view returns (uint128 dataTimestamp, uint128 blockTimestamp);

  /**
   * @notice Returns identifiers of all data feeds supported by the Adapter contract
   * @return An array of data feed identifiers
   */
  function getDataFeedIds() external view returns (bytes32[] memory);

  /**
   * @notice Returns the unique index of the given data feed
   * @param dataFeedId The data feed identifier
   * @return index The index of the data feed
   */
  function getDataFeedIndex(bytes32 dataFeedId) external view returns (uint256);

  /**
   * @notice Returns minimal required interval (usually in seconds) between subsequent updates
   * @return interval The required interval between updates
   */
  function getMinIntervalBetweenUpdates() external view returns (uint256);

  /**
   * @notice Reverts if the proposed timestamp of data packages it too old or too new
   * comparing to the block.timestamp. It also ensures that the proposed timestamp is newer
   * Then the one from the previous update
   * @param dataPackagesTimestamp The proposed timestamp (usually in milliseconds)
   */
  function validateProposedDataPackagesTimestamp(uint256 dataPackagesTimestamp) external view;

  /**
   * @notice Reverts if the updater is not authorised
   * @dev This function should revert if msg.sender is not allowed to update data feed values
   * @param updater The address of the proposed updater
   */
  function requireAuthorisedUpdater(address updater) external view;
}
          

/packages/on-chain-relayer/contracts/core/RedstoneAdapterBase.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

import {RedstoneConsumerNumericBase, RedstoneDefaultsLib} from "@redstone-finance/evm-connector/contracts/core/RedstoneConsumerNumericBase.sol";
import {IRedstoneAdapter} from "./IRedstoneAdapter.sol";

/**
 * @title Core logic of Redstone Adapter Contract
 * @author The Redstone Oracles team
 * @dev This contract is used to repeatedly push Redstone data to blockchain storage
 * More details here: https://docs.redstone.finance/docs/smart-contract-devs/get-started/redstone-classic
 *
 * Key details about the contract:
 * - Values for data feeds can be updated using the `updateDataFeedsValues` function
 * - All data feeds must be updated within a single call, partial updates are not allowed
 * - There is a configurable minimum interval between updates
 * - Updaters can be restricted by overriding `requireAuthorisedUpdater` function
 * - The contract is designed to force values validation, by default it prevents returning zero values
 * - All data packages in redstone payload must have the same timestamp,
 *    equal to `dataPackagesTimestamp` argument of the `updateDataFeedsValues` function
 * - Block timestamp abstraction - even though we call it blockTimestamp in many places,
 *    it's possible to have a custom logic here, e.g. use block number instead of a timestamp
 */
abstract contract RedstoneAdapterBase is RedstoneConsumerNumericBase, IRedstoneAdapter {
  // We don't use storage variables to avoid potential problems with upgradable contracts
  bytes32 internal constant LATEST_UPDATE_TIMESTAMPS_STORAGE_LOCATION = 0x3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe2; // keccak256("RedStone.lastUpdateTimestamp");
  uint256 internal constant MIN_INTERVAL_BETWEEN_UPDATES = 3 seconds;
  uint256 internal constant BITS_COUNT_IN_16_BYTES = 128;
  uint256 internal constant MAX_NUMBER_FOR_128_BITS = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;

  error DataTimestampShouldBeNewerThanBefore(
    uint256 receivedDataTimestampMilliseconds,
    uint256 lastDataTimestampMilliseconds
  );

  error MinIntervalBetweenUpdatesHasNotPassedYet(
    uint256 currentBlockTimestamp,
    uint256 lastUpdateTimestamp,
    uint256 minIntervalBetweenUpdates
  );

  error DataPackageTimestampMismatch(uint256 expectedDataTimestamp, uint256 dataPackageTimestamp);

  error DataFeedValueCannotBeZero(bytes32 dataFeedId);

  error DataFeedIdNotFound(bytes32 dataFeedId);

  error DataTimestampIsTooBig(uint256 dataTimestamp);

  error BlockTimestampIsTooBig(uint256 blockTimestamp);

  /**
   * @notice Reverts if the updater is not authorised
   * @dev This function should revert if msg.sender is not allowed to update data feed values
   * @param updater The address of the proposed updater
   */
  function requireAuthorisedUpdater(address updater) public view virtual {
    // By default, anyone can update data feed values, but it can be overridden
  }

  /**
   * @notice Returns identifiers of all data feeds supported by the Adapter contract
   * @dev this function must be implemented in derived contracts
   * @return An array of data feed identifiers
   */
  function getDataFeedIds() public view virtual returns (bytes32[] memory);

  /**
   * @notice Returns the unique index of the given data feed
   * @dev This function can (and should) be overriden to reduce gas
   * costs of other functions
   * @param dataFeedId The data feed identifier
   * @return index The index of the data feed
   */
  function getDataFeedIndex(bytes32 dataFeedId) public view virtual returns (uint256) {
    bytes32[] memory dataFeedIds = getDataFeedIds();
    for (uint256 i = 0; i < dataFeedIds.length;) {
      if (dataFeedIds[i] == dataFeedId) {
        return i;
      }
      unchecked { i++; } // reduces gas costs
    }
    revert DataFeedIdNotFound(dataFeedId);
  }

  /**
   * @notice Updates values of all data feeds supported by the Adapter contract
   * @dev This function requires an attached redstone payload to the transaction calldata.
   * It also requires each data package to have exactly the same timestamp
   * @param dataPackagesTimestamp Timestamp of each signed data package in the redstone payload
   */
  function updateDataFeedsValues(uint256 dataPackagesTimestamp) public {
    requireAuthorisedUpdater(msg.sender);
    _assertMinIntervalBetweenUpdatesPassed();
    validateProposedDataPackagesTimestamp(dataPackagesTimestamp);
    _saveTimestampsOfCurrentUpdate(dataPackagesTimestamp);

    bytes32[] memory dataFeedsIdsArray = getDataFeedIds();

    // It will trigger timestamp validation for each data package
    uint256[] memory oracleValues = getOracleNumericValuesFromTxMsg(dataFeedsIdsArray);

    _validateAndUpdateDataFeedsValues(dataFeedsIdsArray, oracleValues);
  }
  
  /**
   * @dev Note! This function is not called directly, it's called for each data package    .
   * in redstone payload and just verifies if each data package has the same timestamp
   * as the one that was saved in the storage
   * @param receivedTimestampMilliseconds Timestamp from a data package
   */
  function validateTimestamp(uint256 receivedTimestampMilliseconds) public view virtual override {
    // It means that we are in the special view context and we can skip validation of the
    // timestamp. It can be useful for calling view functions, as they can not modify the contract
    // state to pass the timestamp validation below
    if (msg.sender == address(0)) {
      return;
    }

    uint256 expectedDataPackageTimestamp = getDataTimestampFromLatestUpdate();
    if (receivedTimestampMilliseconds != expectedDataPackageTimestamp) {
      revert DataPackageTimestampMismatch(
        expectedDataPackageTimestamp,
        receivedTimestampMilliseconds
      );
    }
  }

  /**
   * @dev This function should be implemented by the actual contract
   * and should contain the logic of values validation and reporting.
   * Usually, values reporting is based on saving them to the contract storage,
   * e.g. in PriceFeedsAdapter, but some custom implementations (e.g. GMX keeper adapter
   * or Mento Sorted Oracles adapter) may handle values updating in a different way
   * @param dataFeedIdsArray Array of the data feeds identifiers (it will always be all data feed ids)
   * @param values The reported values that should be validated and reported
   */
  function _validateAndUpdateDataFeedsValues(bytes32[] memory dataFeedIdsArray, uint256[] memory values) internal virtual;

  /**
   * @dev This function reverts if not enough time passed since the latest update
   */
  function _assertMinIntervalBetweenUpdatesPassed() private view {
    uint256 currentBlockTimestamp = getBlockTimestamp();
    uint256 blockTimestampFromLatestUpdate = getBlockTimestampFromLatestUpdate();
    uint256 minIntervalBetweenUpdates = getMinIntervalBetweenUpdates();
    if (currentBlockTimestamp < blockTimestampFromLatestUpdate + minIntervalBetweenUpdates) {
      revert MinIntervalBetweenUpdatesHasNotPassedYet(
        currentBlockTimestamp,
        blockTimestampFromLatestUpdate,
        minIntervalBetweenUpdates
      );
    }
  }

  /**
   * @notice Returns minimal required interval (usually in seconds) between subsequent updates
   * @dev You can override this function to change the required interval between udpates.
   * Please do not set it to 0, as it may open many attack vectors
   * @return interval The required interval between updates
   */
  function getMinIntervalBetweenUpdates() public view virtual returns (uint256) {
    return MIN_INTERVAL_BETWEEN_UPDATES;
  }

  /**
   * @notice Reverts if the proposed timestamp of data packages it too old or too new
   * comparing to the block.timestamp. It also ensures that the proposed timestamp is newer
   * Then the one from the previous update
   * @param dataPackagesTimestamp The proposed timestamp (usually in milliseconds)
   */
  function validateProposedDataPackagesTimestamp(uint256 dataPackagesTimestamp) public view {
    _preventUpdateWithOlderDataPackages(dataPackagesTimestamp);
    validateDataPackagesTimestampOnce(dataPackagesTimestamp);
  }


  /**
   * @notice Reverts if the proposed timestamp of data packages it too old or too new
   * comparing to the current block timestamp
   * @param dataPackagesTimestamp The proposed timestamp (usually in milliseconds)
   */
  function validateDataPackagesTimestampOnce(uint256 dataPackagesTimestamp) public view virtual {
    uint256 receivedTimestampSeconds = dataPackagesTimestamp / 1000;

    (uint256 maxDataAheadSeconds, uint256 maxDataDelaySeconds) = getAllowedTimestampDiffsInSeconds();

    uint256 blockTimestamp = getBlockTimestamp();

    if (blockTimestamp < receivedTimestampSeconds) {
      if ((receivedTimestampSeconds - blockTimestamp) > maxDataAheadSeconds) {
        revert RedstoneDefaultsLib.TimestampFromTooLongFuture(receivedTimestampSeconds, blockTimestamp);
      }
    } else if ((blockTimestamp - receivedTimestampSeconds) > maxDataDelaySeconds) {
      revert RedstoneDefaultsLib.TimestampIsTooOld(receivedTimestampSeconds, blockTimestamp);
    }
  }

  /**
   * @dev This function can be overriden, e.g. to use block.number instead of block.timestamp
   * It can be useful in some L2 chains, as sometimes their different blocks can have the same timestamp
   * @return timestamp Timestamp or Block number or any other number that can identify time in the context
   * of the given blockchain
   */
  function getBlockTimestamp() public view virtual returns (uint256) {
    return block.timestamp;
  }

  /**
   * @dev Helpful function for getting values for timestamp validation
   * @return  maxDataAheadSeconds Max allowed number of seconds ahead of block.timrstamp
   * @return  maxDataDelaySeconds Max allowed number of seconds for data delay
   */
  function getAllowedTimestampDiffsInSeconds() public view virtual returns (uint256 maxDataAheadSeconds, uint256 maxDataDelaySeconds) {
    maxDataAheadSeconds = RedstoneDefaultsLib.DEFAULT_MAX_DATA_TIMESTAMP_AHEAD_SECONDS;
    maxDataDelaySeconds = RedstoneDefaultsLib.DEFAULT_MAX_DATA_TIMESTAMP_DELAY_SECONDS;
  }

  /**
   * @dev Reverts if proposed data packages are not newer than the ones used previously
   * @param dataPackagesTimestamp Timestamp od the data packages (usually in milliseconds)
   */
  function _preventUpdateWithOlderDataPackages(uint256 dataPackagesTimestamp) internal view {
    uint256 dataTimestampFromLatestUpdate = getDataTimestampFromLatestUpdate();

    if (dataPackagesTimestamp <= dataTimestampFromLatestUpdate) {
      revert DataTimestampShouldBeNewerThanBefore(
        dataPackagesTimestamp,
        dataTimestampFromLatestUpdate
      );
    }
  }

  /**
   * @notice Returns data timestamp from the latest update
   * @dev It's virtual, because its implementation can sometimes be different
   * (e.g. SinglePriceFeedAdapterWithClearing)
   * @return lastDataTimestamp Timestamp of the latest reported data packages
   */
  function getDataTimestampFromLatestUpdate() public view virtual returns (uint256 lastDataTimestamp) {
    (lastDataTimestamp, ) = getTimestampsFromLatestUpdate();
  }

  /**
   * @notice Returns block timestamp of the latest successful update
   * @return blockTimestamp The block timestamp of the latest successful update
   */
  function getBlockTimestampFromLatestUpdate() public view returns (uint256 blockTimestamp) {
    (, blockTimestamp) = getTimestampsFromLatestUpdate();
  }

  /**
   * @dev Returns 2 timestamps packed into a single uint256 number
   * @return packedTimestamps a single uin256 number with 2 timestamps
   */
  function getPackedTimestampsFromLatestUpdate() public view returns (uint256 packedTimestamps) {
    assembly {
      packedTimestamps := sload(LATEST_UPDATE_TIMESTAMPS_STORAGE_LOCATION)
    }
  }

  /**
   * @notice Returns timestamps of the latest successful update
   * @return dataTimestamp timestamp (usually in milliseconds) from the signed data packages
   * @return blockTimestamp timestamp of the block when the update has happened
   */
  function getTimestampsFromLatestUpdate() public view virtual returns (uint128 dataTimestamp, uint128 blockTimestamp) {
    return _unpackTimestamps(getPackedTimestampsFromLatestUpdate());
  }


  /**
   * @dev A helpful function to unpack 2 timestamps from one uin256 number
   * @param packedTimestamps a single uin256 number
   * @return dataTimestamp fetched from left 128 bits
   * @return blockTimestamp fetched from right 128 bits
   */
  function _unpackTimestamps(uint256 packedTimestamps) internal pure returns (uint128 dataTimestamp, uint128 blockTimestamp) {
    dataTimestamp = uint128(packedTimestamps >> 128); // left 128 bits
    blockTimestamp = uint128(packedTimestamps); // right 128 bits
  }


  /**
   * @dev Logic of saving timestamps of the current update
   * By default, it stores packed timestamps in one storage slot (32 bytes)
   * to minimise gas costs
   * But it can be overriden (e.g. in SinglePriceFeedAdapter)
   * @param   dataPackagesTimestamp  .
   */
  function _saveTimestampsOfCurrentUpdate(uint256 dataPackagesTimestamp) internal virtual {
    uint256 blockTimestamp = getBlockTimestamp();

    if (blockTimestamp > MAX_NUMBER_FOR_128_BITS) {
      revert BlockTimestampIsTooBig(blockTimestamp);
    }

    if (dataPackagesTimestamp > MAX_NUMBER_FOR_128_BITS) {
      revert DataTimestampIsTooBig(dataPackagesTimestamp);
    }

    assembly {
      let timestamps := or(shl(BITS_COUNT_IN_16_BYTES, dataPackagesTimestamp), blockTimestamp)
      sstore(LATEST_UPDATE_TIMESTAMPS_STORAGE_LOCATION, timestamps)
    }
  }

  /**
   * @notice Returns the latest properly reported value of the data feed
   * @param dataFeedId The identifier of the requested data feed
   * @return value The latest value of the given data feed
   */
  function getValueForDataFeed(bytes32 dataFeedId) public view returns (uint256) {
    getDataFeedIndex(dataFeedId); // will revert if data feed id is not supported

    // "unsafe" here means "without validation"
    uint256 valueForDataFeed = getValueForDataFeedUnsafe(dataFeedId);

    validateDataFeedValue(dataFeedId, valueForDataFeed);
    return valueForDataFeed;
  }

  /**
   * @notice Returns the latest properly reported values for several data feeds
   * @param dataFeedIds The array of identifiers for the requested feeds
   * @return values Values of the requested data feeds in the corresponding order
   */
  function getValuesForDataFeeds(bytes32[] memory dataFeedIds) public view returns (uint256[] memory) {
    uint256[] memory values = getValuesForDataFeedsUnsafe(dataFeedIds);
    for (uint256 i = 0; i < dataFeedIds.length;) {
      bytes32 dataFeedId = dataFeedIds[i];
      getDataFeedIndex(dataFeedId); // will revert if data feed id is not supported
      validateDataFeedValue(dataFeedId, values[i]);
      unchecked { i++; } // reduces gas costs
    }
    return values;
  }


  /**
   * @dev Reverts if proposed value for the proposed data feed id is invalid
   * By default, it just checks if the value is not equal to 0, but it can be extended
   * @param dataFeedId The data feed identifier
   * @param valueForDataFeed Proposed value for the data feed
   */
  function validateDataFeedValue(bytes32 dataFeedId, uint256 valueForDataFeed) public pure virtual {
    if (valueForDataFeed == 0) {
      revert DataFeedValueCannotBeZero(dataFeedId);
    }
  }

  /**
   * @dev [HIGH RISK] Returns the latest value for a given data feed without validation
   * Important! Using this function instead of `getValueForDataFeed` may cause
   * significant risk for your smart contracts
   * @param dataFeedId The data feed identifier
   * @return dataFeedValue Unvalidated value of the latest successful update
   */
  function getValueForDataFeedUnsafe(bytes32 dataFeedId) public view virtual returns (uint256);

  /**
   * @notice [HIGH RISK] Returns the latest properly reported values for several data feeds without validation
   * Important! Using this function instead of `getValuesForDataFeeds` may cause
   * significant risk for your smart contracts
   * @param requestedDataFeedIds The array of identifiers for the requested feeds
   * @return values Unvalidated values of the requested data feeds in the corresponding order
   */
  function getValuesForDataFeedsUnsafe(bytes32[] memory requestedDataFeedIds) public view virtual returns (uint256[] memory values) {
    values = new uint256[](requestedDataFeedIds.length);
    for (uint256 i = 0; i < requestedDataFeedIds.length;) {
      values[i] = getValueForDataFeedUnsafe(requestedDataFeedIds[i]);
      unchecked { i++; } // reduces gas costs
    }
    return values;
  }
}
          

/packages/on-chain-relayer/contracts/custom-integrations/mento/ISortedOracles.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.14;

import {SortedLinkedListWithMedian} from "./linkedlists/SortedLinkedListWithMedian.sol";

/**
 * @title Simplified interface of the SortedOracles contract
 * @author The Mento team (modified by the Redstone team)
 * @dev Some functions were removed to simplify implementation
 * of the mock SortedOracles contract. Interfaces of the functions
 * below are identical with the original ISortedOracles interface
 */
interface ISortedOracles {
  function report(address, uint256, address, address) external;

  function removeExpiredReports(address, uint256) external;

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

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

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

/packages/on-chain-relayer/contracts/custom-integrations/mento/MentoAdapterBase.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ISortedOracles} from "./ISortedOracles.sol";
import {RedstoneAdapterBase} from "../../core/RedstoneAdapterBase.sol";

/**
 * @title Redstone oracles adapter for the Mento SortedOracles contract
 * @author The Redstone Oracles team
 * @dev This contract should be whitelisted as an oracle client in the
 * SortedOracles contract. It allows anyone to push signed oracle data
 * to report them in the Mento SortedOracles contract. It is ownable,
 * the owner can manage delivered data feeds and corresponding token
 * addresses.
 *
 */
abstract contract MentoAdapterBase is RedstoneAdapterBase, Initializable {
  error TokenNotFoundForIndex(uint256 tokenIndex);

  struct DataFeedDetails {
    bytes32 dataFeedId;
    address tokenAddress;
  }

  // RedStone provides values with 8 decimals
  // Mento sorted oracles expect 24 decimals (24 - 8 = 16)
  uint256 internal constant PRICE_MULTIPLIER = 1e16;

  // 68 = 4 (fun selector) + 32 (proposedTimestamp) + 32 (size of one array element)
  uint256 internal constant INITIAL_CALLDATA_OFFSET = 68;
  uint256 internal constant LOCATION_IN_SORTED_LIST_BYTE_SIZE = 64;

  struct LocationInSortedLinkedList {
    address lesserKey;
    address greaterKey;
  }

  /**
   * @dev Helpful function for upgradable contracts
   */
  function initialize() public initializer {
    // We don't have storage variables, but we keep this function
    // Because it is used for contract setup in upgradable contracts
  }

  // This function must be overriden
  function getSortedOracles()
    public
    view
    virtual
    returns (ISortedOracles sortedOracles);

  /**
   * @notice Used for getting proposed values from RedStone's data packages
   * @param dataFeedIds An array of data feed identifiers
   * @return values The normalized values for corresponding data feeds
   */
  function getNormalizedOracleValuesFromTxCalldata(
    bytes32[] calldata dataFeedIds
  ) public view returns (uint256[] memory) {
    uint256[] memory values = getOracleNumericValuesFromTxMsg(dataFeedIds);
    for (uint256 i = 0; i < values.length; ) {
      values[i] = normalizeRedstoneValueForMento(values[i]);
      unchecked {
        i++;
      } // reduces gas costs
    }
    return values;
  }

  /**
   * @notice Helpful function to simplify the mento relayer implementation
   */
  function updatePriceValuesAndCleanOldReports(
    uint256 proposedTimestamp,
    LocationInSortedLinkedList[] calldata locationsInSortedLinkedLists
  ) external {
    updatePriceValues(proposedTimestamp, locationsInSortedLinkedLists);
    removeAllExpiredReports();
  }

  function removeAllExpiredReports() public {
    uint256 tokensLength = getDataFeedsCount();
    ISortedOracles sortedOracles = getSortedOracles();
    for (uint256 tokenIndex = 0; tokenIndex < tokensLength; ) {
      (, address tokenAddress) = getTokenDetailsAtIndex(tokenIndex);
      uint256 curNumberOfReports = sortedOracles.numTimestamps(tokenAddress);
      if (curNumberOfReports > 0) {
        sortedOracles.removeExpiredReports(
          tokenAddress,
          curNumberOfReports - 1
        );
      }
      unchecked {
        tokenIndex++;
      } // reduces gas costs
    }
  }

  function normalizeRedstoneValueForMento(
    uint256 valueFromRedstone
  ) public pure returns (uint256) {
    return PRICE_MULTIPLIER * valueFromRedstone;
  }

  function convertMentoValueToRedstoneValue(
    uint256 mentoValue
  ) public pure returns (uint256) {
    return mentoValue / PRICE_MULTIPLIER;
  }

  /**
   * @notice Extracts Redstone's oracle values from calldata, verifying signatures
   * and timestamps, and reports it to the SortedOracles contract
   * @param proposedTimestamp Timestamp that should be lesser or equal to each
   * timestamp from the signed data packages in calldata
   * @param locationsInSortedLinkedLists The array of locations in linked list for reported values
   */
  function updatePriceValues(
    uint256 proposedTimestamp,
    LocationInSortedLinkedList[] calldata locationsInSortedLinkedLists
  ) public {
    locationsInSortedLinkedLists; // This argument is used later (extracted from calldata)
    updateDataFeedsValues(proposedTimestamp);
  }

  function _validateAndUpdateDataFeedsValues(
    bytes32[] memory dataFeedIds,
    uint256[] memory values
  ) internal override {
    LocationInSortedLinkedList[]
      memory locationsInSortedList = extractLinkedListLocationsFromCalldata();
    for (uint256 dataFeedIndex = 0; dataFeedIndex < dataFeedIds.length; ) {
      (, address tokenAddress) = getTokenDetailsAtIndex(dataFeedIndex);
      uint256 priceValue = normalizeRedstoneValueForMento(
        values[dataFeedIndex]
      );
      LocationInSortedLinkedList memory location = locationsInSortedList[
        dataFeedIndex
      ];

      getSortedOracles().report(
        tokenAddress,
        priceValue,
        location.lesserKey,
        location.greaterKey
      );

      unchecked {
        dataFeedIndex++;
      } // reduces gas costs
    }
  }

  function extractLinkedListLocationsFromCalldata()
    private
    pure
    returns (LocationInSortedLinkedList[] memory locationsInSortedList)
  {
    uint256 calldataOffset = INITIAL_CALLDATA_OFFSET;
    uint256 arrayLength = abi.decode(
      msg.data[calldataOffset:calldataOffset + STANDARD_SLOT_BS],
      (uint256)
    );

    calldataOffset += STANDARD_SLOT_BS;

    locationsInSortedList = new LocationInSortedLinkedList[](arrayLength);
    for (uint256 i = 0; i < arrayLength; ) {
      locationsInSortedList[i] = abi.decode(
        msg.data[calldataOffset:calldataOffset +
          LOCATION_IN_SORTED_LIST_BYTE_SIZE],
        (LocationInSortedLinkedList)
      );
      calldataOffset += LOCATION_IN_SORTED_LIST_BYTE_SIZE;
      unchecked {
        i++;
      } // reduces gas costs
    }
  }

  function getDataFeedIds() public view override returns (bytes32[] memory) {
    uint256 dataFeedsCount = getDataFeedsCount();
    bytes32[] memory dataFeedIds = new bytes32[](dataFeedsCount);
    for (uint256 dataFeedIndex = 0; dataFeedIndex < dataFeedsCount; ) {
      (dataFeedIds[dataFeedIndex], ) = getTokenDetailsAtIndex(dataFeedIndex);
      unchecked {
        dataFeedIndex++;
      } // reduces gas costs
    }

    return dataFeedIds;
  }

  // This function is used by mento relayer
  function getDataFeeds() public view returns (DataFeedDetails[] memory) {
    uint256 dataFeedsCount = getDataFeedsCount();
    DataFeedDetails[] memory dataFeeds = new DataFeedDetails[](dataFeedsCount);
    for (uint256 dataFeedIndex = 0; dataFeedIndex < dataFeedsCount; ) {
      (bytes32 dataFeedId, address tokenAddress) = getTokenDetailsAtIndex(
        dataFeedIndex
      );
      dataFeeds[dataFeedIndex] = DataFeedDetails({
        dataFeedId: dataFeedId,
        tokenAddress: tokenAddress
      });
      unchecked {
        dataFeedIndex++;
      } // reduces gas costs
    }
    return dataFeeds;
  }

  // This function must be overriden in the child contract
  function getTokenDetailsAtIndex(
    uint256 tokenIndex
  ) public view virtual returns (bytes32 dataFeedId, address tokenAddress);

  // This function must be overriden in the child contract
  function getDataFeedsCount() public view virtual returns (uint256);

  function getTokenIndexByDataFeedId(
    bytes32 dataFeedId
  ) public view virtual returns (uint256) {
    uint256 dataFeedsCount = getDataFeedsCount();
    for (uint256 dataFeedIndex = 0; dataFeedIndex < dataFeedsCount; ) {
      (bytes32 dataFeedIdAtIndex, ) = getTokenDetailsAtIndex(dataFeedIndex);
      if (dataFeedId == dataFeedIdAtIndex) {
        return dataFeedIndex;
      }
      unchecked {
        dataFeedIndex++;
      } // reduces gas costs
    }

    revert DataFeedIdNotFound(dataFeedId);
  }

  // [HIGH RISK] Using this function directly may cause significant risk
  function getValueForDataFeedUnsafe(
    bytes32 dataFeedId
  ) public view override returns (uint256) {
    uint256 tokenIndex = getTokenIndexByDataFeedId(dataFeedId);
    (, address tokenAddress) = getTokenDetailsAtIndex(tokenIndex);
    (uint256 medianRate, ) = getSortedOracles().medianRate(tokenAddress);
    return convertMentoValueToRedstoneValue(medianRate);
  }
}
          

/packages/on-chain-relayer/contracts/custom-integrations/mento/data-services/MentoAdapterPrimaryProd.sol

// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.14;

import {MentoAdapterBase} from "../MentoAdapterBase.sol";

abstract contract MentoAdapterPrimaryProd is MentoAdapterBase {
  function getUniqueSignersThreshold() public view virtual override returns (uint8) {
    return 2;
  }

  function getAuthorisedSignerIndex(
    address signerAddress
  ) public view virtual override returns (uint8) {
    if (signerAddress == 0x8BB8F32Df04c8b654987DAaeD53D6B6091e3B774) {
      return 0;
    } else if (signerAddress == 0xdEB22f54738d54976C4c0fe5ce6d408E40d88499) {
      return 1;
    } else if (signerAddress == 0x51Ce04Be4b3E32572C4Ec9135221d0691Ba7d202) {
      return 2;
    } else if (signerAddress == 0xDD682daEC5A90dD295d14DA4b0bec9281017b5bE) {
      return 3;
    } else if (signerAddress == 0x9c5AE89C4Af6aA32cE58588DBaF90d18a855B6de) {
      return 4;
    } else {
      revert SignerNotAuthorised(signerAddress);
    }
  }
}
          

/packages/on-chain-relayer/contracts/custom-integrations/mento/linkedlists/LinkedList.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

/**
 * @title Maintains a doubly linked list keyed by bytes32.
 * @author The Mento team (the code modified by the RedStone team)
 * @dev The code has been slightly modified to be compatible with ^0.8.0 version
 * 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);
  }
}
          

/packages/on-chain-relayer/contracts/custom-integrations/mento/linkedlists/SortedLinkedList.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./LinkedList.sol";

/**
 * @title Maintains a sorted list of unsigned ints keyed by bytes32.
 * @author The Mento team (the code modified by the RedStone team)
 * @dev The code has been slightly modified to be compatible with ^0.8.0 version
 */
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 correctLesserValue The correct lesserKey keys.
   * @return correctGreaterValue The correct greaterKey keys.
   */
  function getLesserAndGreater(
    List storage list,
    uint256 value,
    bytes32 lesserKey,
    bytes32 greaterKey
  ) private view returns (bytes32 correctLesserValue, bytes32 correctGreaterValue) {
    // 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;
  }
}
          

/packages/on-chain-relayer/contracts/custom-integrations/mento/linkedlists/SortedLinkedListWithMedian.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.14;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./LinkedList.sol";
import "./SortedLinkedList.sol";

/**
 * @title Maintains a sorted list of unsigned ints keyed by bytes32.
 * @author The Mento team (the code modified by the RedStone team)
 * @dev The code has been slightly modified to be compatible with ^0.8.0 version
 */
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;
  }
}
          

Compiler Settings

{"remappings":[],"optimizer":{"runs":10000,"enabled":true},"metadata":{"bytecodeHash":"ipfs"},"libraries":{},"evmVersion":"london","compilationTarget":{"contracts/mentoCeloMainnet/MentoAdapterCeloV2.sol":"MentoAdapterCeloV2"}}
              

Contract ABI

[{"type":"error","name":"BlockTimestampIsTooBig","inputs":[{"type":"uint256","name":"blockTimestamp","internalType":"uint256"}]},{"type":"error","name":"CalldataMustHaveValidPayload","inputs":[]},{"type":"error","name":"CalldataOverOrUnderFlow","inputs":[]},{"type":"error","name":"CanNotPickMedianOfEmptyArray","inputs":[]},{"type":"error","name":"DataFeedIdNotFound","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"error","name":"DataFeedValueCannotBeZero","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"error","name":"DataPackageTimestampMismatch","inputs":[{"type":"uint256","name":"expectedDataTimestamp","internalType":"uint256"},{"type":"uint256","name":"dataPackageTimestamp","internalType":"uint256"}]},{"type":"error","name":"DataPackageTimestampMustNotBeZero","inputs":[]},{"type":"error","name":"DataPackageTimestampsMustBeEqual","inputs":[]},{"type":"error","name":"DataTimestampIsTooBig","inputs":[{"type":"uint256","name":"dataTimestamp","internalType":"uint256"}]},{"type":"error","name":"DataTimestampShouldBeNewerThanBefore","inputs":[{"type":"uint256","name":"receivedDataTimestampMilliseconds","internalType":"uint256"},{"type":"uint256","name":"lastDataTimestampMilliseconds","internalType":"uint256"}]},{"type":"error","name":"EachSignerMustProvideTheSameValue","inputs":[]},{"type":"error","name":"EmptyCalldataPointersArr","inputs":[]},{"type":"error","name":"GetDataServiceIdNotImplemented","inputs":[]},{"type":"error","name":"IncorrectUnsignedMetadataSize","inputs":[]},{"type":"error","name":"InsufficientNumberOfUniqueSigners","inputs":[{"type":"uint256","name":"receivedSignersCount","internalType":"uint256"},{"type":"uint256","name":"requiredSignersCount","internalType":"uint256"}]},{"type":"error","name":"InvalidCalldataPointer","inputs":[]},{"type":"error","name":"MinIntervalBetweenUpdatesHasNotPassedYet","inputs":[{"type":"uint256","name":"currentBlockTimestamp","internalType":"uint256"},{"type":"uint256","name":"lastUpdateTimestamp","internalType":"uint256"},{"type":"uint256","name":"minIntervalBetweenUpdates","internalType":"uint256"}]},{"type":"error","name":"RedstonePayloadMustHaveAtLeastOneDataPackage","inputs":[]},{"type":"error","name":"SignerNotAuthorised","inputs":[{"type":"address","name":"receivedSigner","internalType":"address"}]},{"type":"error","name":"TimestampFromTooLongFuture","inputs":[{"type":"uint256","name":"receivedTimestampSeconds","internalType":"uint256"},{"type":"uint256","name":"blockTimestamp","internalType":"uint256"}]},{"type":"error","name":"TimestampIsTooOld","inputs":[{"type":"uint256","name":"receivedTimestampSeconds","internalType":"uint256"},{"type":"uint256","name":"blockTimestamp","internalType":"uint256"}]},{"type":"error","name":"TokenNotFoundForIndex","inputs":[{"type":"uint256","name":"tokenIndex","internalType":"uint256"}]},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"aggregateValues","inputs":[{"type":"uint256[]","name":"values","internalType":"uint256[]"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"convertMentoValueToRedstoneValue","inputs":[{"type":"uint256","name":"mentoValue","internalType":"uint256"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"extractedTimestamp","internalType":"uint256"}],"name":"extractTimestampsAndAssertAllAreEqual","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"maxDataAheadSeconds","internalType":"uint256"},{"type":"uint256","name":"maxDataDelaySeconds","internalType":"uint256"}],"name":"getAllowedTimestampDiffsInSeconds","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"getAuthorisedSignerIndex","inputs":[{"type":"address","name":"signerAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBlockTimestamp","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"blockTimestamp","internalType":"uint256"}],"name":"getBlockTimestampFromLatestUpdate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"","internalType":"bytes32[]"}],"name":"getDataFeedIds","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getDataFeedIndex","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct MentoAdapterBase.DataFeedDetails[]","components":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"address","name":"tokenAddress","internalType":"address"}]}],"name":"getDataFeeds","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getDataFeedsCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"getDataServiceId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"lastDataTimestamp","internalType":"uint256"}],"name":"getDataTimestampFromLatestUpdate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getMinIntervalBetweenUpdates","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"getNormalizedOracleValuesFromTxCalldata","inputs":[{"type":"bytes32[]","name":"dataFeedIds","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"packedTimestamps","internalType":"uint256"}],"name":"getPackedTimestampsFromLatestUpdate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"sortedOracles","internalType":"contract ISortedOracles"}],"name":"getSortedOracles","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint128","name":"dataTimestamp","internalType":"uint128"},{"type":"uint128","name":"blockTimestamp","internalType":"uint128"}],"name":"getTimestampsFromLatestUpdate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"address","name":"tokenAddress","internalType":"address"}],"name":"getTokenDetailsAtIndex","inputs":[{"type":"uint256","name":"tokenIndex","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokenIndexByDataFeedId","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"getUniqueSignersThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getValueForDataFeed","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getValueForDataFeedUnsafe","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"getValuesForDataFeeds","inputs":[{"type":"bytes32[]","name":"dataFeedIds","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"values","internalType":"uint256[]"}],"name":"getValuesForDataFeedsUnsafe","inputs":[{"type":"bytes32[]","name":"requestedDataFeedIds","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"normalizeRedstoneValueForMento","inputs":[{"type":"uint256","name":"valueFromRedstone","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAllExpiredReports","inputs":[]},{"type":"function","stateMutability":"view","outputs":[],"name":"requireAuthorisedUpdater","inputs":[{"type":"address","name":"updater","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateDataFeedsValues","inputs":[{"type":"uint256","name":"dataPackagesTimestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updatePriceValues","inputs":[{"type":"uint256","name":"proposedTimestamp","internalType":"uint256"},{"type":"tuple[]","name":"locationsInSortedLinkedLists","internalType":"struct MentoAdapterBase.LocationInSortedLinkedList[]","components":[{"type":"address","name":"lesserKey","internalType":"address"},{"type":"address","name":"greaterKey","internalType":"address"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updatePriceValuesAndCleanOldReports","inputs":[{"type":"uint256","name":"proposedTimestamp","internalType":"uint256"},{"type":"tuple[]","name":"locationsInSortedLinkedLists","internalType":"struct MentoAdapterBase.LocationInSortedLinkedList[]","components":[{"type":"address","name":"lesserKey","internalType":"address"},{"type":"address","name":"greaterKey","internalType":"address"}]}]},{"type":"function","stateMutability":"pure","outputs":[],"name":"validateDataFeedValue","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"uint256","name":"valueForDataFeed","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[],"name":"validateDataPackagesTimestampOnce","inputs":[{"type":"uint256","name":"dataPackagesTimestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[],"name":"validateProposedDataPackagesTimestamp","inputs":[{"type":"uint256","name":"dataPackagesTimestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[],"name":"validateTimestamp","inputs":[{"type":"uint256","name":"receivedTimestampMilliseconds","internalType":"uint256"}]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50612820806100206000396000f3fe608060405234801561001057600080fd5b506004361061025c5760003560e01c8063aef2f16511610145578063d41f63b3116100bd578063f50b2efe1161008c578063fa182aff11610071578063fa182aff146104fb578063fba031581461050e578063fd1f4bef1461051657600080fd5b8063f50b2efe146104e1578063f90c4924146104f457600080fd5b8063d41f63b314610477578063d77b226e1461048a578063dbe19307146104c7578063e9eaee73146104ce57600080fd5b8063bb1f29b711610114578063c274583a116100f9578063c274583a14610448578063c84618b51461045d578063d149c0d71461047057600080fd5b8063bb1f29b714610422578063c14c92041461043557600080fd5b8063aef2f165146103b6578063b0f106b0146103cb578063b1fcc5cf146103fc578063b24ebfcc1461040f57600080fd5b80636dafaf6a116101d85780638129fc1c116101a75780639900aec11161018c5780639900aec114610370578063a8b940e614610392578063ada11457146103a357600080fd5b80638129fc1c14610355578063971b9c031461035d57600080fd5b80636dafaf6a1461032a5780636f6cfcc91461033d578063796b89b9146103475780637a02bdf11461034d57600080fd5b80633ce142f51161022f57806355a547d51161021457806355a547d5146102ef57806355d12458146102f75780636668316a1461031757600080fd5b80633ce142f5146102b757806344e02982146102dc57600080fd5b806311dc1e75146102615780631415013d146102875780631b2758ee1461029a578063270ab8c0146102a2575b600080fd5b61027461026f366004612243565b61053d565b6040519081526020015b60405180910390f35b610274610295366004612243565b610556565b6102746105c5565b6102aa6105e7565b60405161027e919061225c565b6102ca6102c53660046122e5565b6106a2565b60405160ff909116815260200161027e565b6102746102ea366004612243565b610810565b610274610833565b61030a6103053660046123a2565b610996565b60405161027e9190612438565b610274610325366004612243565b610a37565b610274610338366004612243565b610b16565b610345610b5e565b005b42610274565b610274610ce6565b610345610d08565b61030a61036b3660046123a2565b610e91565b60405173efb84935239dacdecf7c5ba76d8de40b077b7b33815260200161027e565b6103456103a03660046122e5565b50565b6103456103b1366004612243565b610f00565b60408051603c815260b460208201520161027e565b6103d3610f12565b604080516fffffffffffffffffffffffffffffffff93841681529290911660208301520161027e565b61034561040a36600461247c565b610f50565b61027461041d3660046123a2565b610f91565b610345610430366004612243565b610f9c565b610345610443366004612243565b61105f565b61045061109c565b60405161027e919061249e565b61027461046b366004612243565b6110d0565b6003610274565b61034561048536600461250a565b6110e3565b61049d610498366004612243565b6110ec565b6040805192835273ffffffffffffffffffffffffffffffffffffffff90911660208301520161027e565b6007610274565b6103456104dc36600461250a565b61130e565b6103456104ef366004612243565b611321565b60026102ca565b61030a610509366004612589565b611378565b61030a611415565b7f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe254610274565b600061055082662386f26fc1000061262d565b92915050565b60006007815b8181101561058a57600061056f826110ec565b50905080850361058157509392505050565b5060010161055c565b506040517f93829403000000000000000000000000000000000000000000000000000000008152600481018490526024015b60405180910390fd5b60006105cf610f12565b6fffffffffffffffffffffffffffffffff1692915050565b60408051600780825261010082019092526060919060009082816020015b604080518082019091526000808252602082015281526020019060019003908161060557905050905060005b8281101561069b57600080610645836110ec565b9150915060405180604001604052808381526020018273ffffffffffffffffffffffffffffffffffffffff1681525084848151811061068657610686612644565b60209081029190910101525050600101610631565b5092915050565b600073ffffffffffffffffffffffffffffffffffffffff8216738bb8f32df04c8b654987daaed53d6b6091e3b774036106dd57506000919050565b73ffffffffffffffffffffffffffffffffffffffff821673deb22f54738d54976c4c0fe5ce6d408e40d884990361071657506001919050565b73ffffffffffffffffffffffffffffffffffffffff82167351ce04be4b3e32572c4ec9135221d0691ba7d2020361074f57506002919050565b73ffffffffffffffffffffffffffffffffffffffff821673dd682daec5a90dd295d14da4b0bec9281017b5be0361078857506003919050565b73ffffffffffffffffffffffffffffffffffffffff8216739c5ae89c4af6aa32ce58588dbaf90d18a855b6de036107c157506004919050565b6040517fec459bc000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201526024016105bc565b919050565b600061081b82610b16565b50600061082783610a37565b90506105508382610f50565b60008061083e611478565b9050600061084b826115ad565b61ffff1690508060000361088b576040517f8552ff3c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610896600283612673565b915060005b818110156109905760006108ae84611600565b90506000806108be606887612673565b905060006108cc8236612686565b9050803592508265ffffffffffff16600003610914576040517f336dc9d000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8760000361092c578265ffffffffffff16975061096d565b878365ffffffffffff161461096d576040517fd9d1f46500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109778488612673565b965050505050808061098890612699565b91505061089b565b50505090565b6060815167ffffffffffffffff8111156109b2576109b2612300565b6040519080825280602002602001820160405280156109db578160200160208202803683370190505b50905060005b8251811015610a3157610a0c8382815181106109ff576109ff612644565b6020026020010151610a37565b828281518110610a1e57610a1e612644565b60209081029190910101526001016109e1565b50919050565b600080610a4383610556565b90506000610a50826110ec565b9150506000610a7073efb84935239dacdecf7c5ba76d8de40b077b7b3390565b6040517fef90e1b000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152919091169063ef90e1b0906024016040805180830381865afa158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0191906126d1565b509050610b0d816110d0565b95945050505050565b600080610b21611415565b905060005b815181101561058a5783828281518110610b4257610b42612644565b602002602001015103610b56579392505050565b600101610b26565b600773efb84935239dacdecf7c5ba76d8de40b077b7b3360005b82811015610ce1576000610b8b826110ec565b6040517f6dd6ef0c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80831660048301529193506000925090851690636dd6ef0c90602401602060405180830381865afa158015610bff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2391906126f5565b90508015610cd75773ffffffffffffffffffffffffffffffffffffffff841663dd34ca3b83610c53600185612686565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401600060405180830381600087803b158015610cbe57600080fd5b505af1158015610cd2573d6000803e3d6000fd5b505050505b5050600101610b78565b505050565b6000610cf0610f12565b506fffffffffffffffffffffffffffffffff16919050565b600054610100900460ff1615808015610d285750600054600160ff909116105b80610d425750303b158015610d42575060005460ff166001145b610dce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016105bc565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610e2c57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b80156103a057600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b60606000610e9e83610996565b905060005b835181101561069b576000848281518110610ec057610ec0612644565b60200260200101519050610ed381610b16565b50610ef781848481518110610eea57610eea612644565b6020026020010151610f50565b50600101610ea3565b610f098161163c565b6103a081610f9c565b600080610f48610f407f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe25490565b608081901c91565b915091509091565b80600003610f8d576040517f0565ce2a000000000000000000000000000000000000000000000000000000008152600481018390526024016105bc565b5050565b60006105508261168b565b6000610faa6103e88361273d565b9050603c60b4428381101561100b5782610fc48286612686565b1115611006576040517fb6b0916d00000000000000000000000000000000000000000000000000000000815260048101859052602481018290526044016105bc565b611058565b816110168583612686565b1115611058576040517f0321d0b500000000000000000000000000000000000000000000000000000000815260048101859052602481018290526044016105bc565b5050505050565b611067611696565b61107081610f00565b611079816116f9565b6000611083611415565b90506000611090826117bf565b9050610ce182826117ca565b60606040517f608b530700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610550662386f26fc100008361273d565b610ce18361105f565b6000808260000361113557507f43454c4f000000000000000000000000000000000000000000000000000000009273765de816845861e75a25fca122bb6898b8b1282a92509050565b8260010361117b57507f43454c4f2f4555520000000000000000000000000000000000000000000000009273d8763cba276a3738e6de85b4b3bf5fded6d6ca7392509050565b826002036111c157507f43454c4f2f42524c0000000000000000000000000000000000000000000000009273e8537a3d056da446677b9e9d6c5db704eaab478792509050565b8260030361120757507f55534443000000000000000000000000000000000000000000000000000000009273a1a8003936862e7a15092a91898d69fa8bce290c92509050565b8260040361124d57507f555344432f4555520000000000000000000000000000000000000000000000009273206b25ea01e188ee243131afde526ba6e131a01692509050565b8260050361129357507f555344432f42524c000000000000000000000000000000000000000000000000927325f21a1f97607edf6852339fad709728cffb9a9d92509050565b826006036112d957507f4555524f432f4555520000000000000000000000000000000000000000000000927326076b9702885d475ac8c3db3bd9f250dc5a318b92509050565b6040517f332dbea9000000000000000000000000000000000000000000000000000000008152600481018490526024016105bc565b6113198383836110e3565b610ce1610b5e565b336113295750565b6000611333610ce6565b9050808214610f8d576040517f6bc11ec500000000000000000000000000000000000000000000000000000000815260048101829052602481018390526044016105bc565b606060006113b88484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506117bf92505050565b905060005b815181101561140d576113e88282815181106113db576113db612644565b602002602001015161053d565b8282815181106113fa576113fa612644565b60209081029190910101526001016113bd565b509392505050565b604080516007808252610100820190925260609190600090826020820160e08036833701905050905060005b8281101561069b57611452816110ec565b5082828151811061146557611465612644565b6020908102919091010152600101611441565b60006602ed57011e00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0360135811614806114e0576040517fe7764c9e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000366029111561151d576040517f5796f78a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd736013560006009611556600362ffffff8516612673565b6115609190612673565b90503661156e600283612673565b11156115a6576040517fc30a7bd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b9392505050565b6000806115bb602084612673565b9050368111156115f7576040517f5796f78a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b36033592915050565b600080600061160e846118f6565b9092509050604e611620826020612673565b61162a908461262d565b6116349190612673565b949350505050565b6000611646610ce6565b9050808211610f8d576040517fef05deba00000000000000000000000000000000000000000000000000000000815260048101839052602481018290526044016105bc565b60006105508261194d565b4260006116a16105c5565b905060036116af8183612673565b831015610ce1576040517f83b3f5c40000000000000000000000000000000000000000000000000000000081526004810184905260248101839052604481018290526064016105bc565b426fffffffffffffffffffffffffffffffff811115611747576040517f70db678f000000000000000000000000000000000000000000000000000000008152600481018290526024016105bc565b6fffffffffffffffffffffffffffffffff821115611794576040517f5cbfa8a1000000000000000000000000000000000000000000000000000000008152600481018390526024016105bc565b60809190911b177f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe255565b606061055082611a31565b60006117d4611bf5565b905060005b83518110156118f05760006117ed826110ec565b91505060006118078584815181106113db576113db612644565b9050600084848151811061181d5761181d612644565b6020026020010151905061184273efb84935239dacdecf7c5ba76d8de40b077b7b3390565b815160208301516040517f80e5074400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015260248201879052928316604482015290821660648201529116906380e5074490608401600060405180830381600087803b1580156118c957600080fd5b505af11580156118dd573d6000803e3d6000fd5b5050600190950194506117d99350505050565b50505050565b600080808080611907604187612673565b90506000611920611919602084612673565b3690611cf9565b803594509050611931816003611cf9565b62ffffff9490941697933563ffffffff16965092945050505050565b6000815160000361198a576040517f9e198af900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61199382611d05565b6000600283516119a3919061273d565b9050600283516119b39190612751565b600003611a0f576000611a02846119cb600185612686565b815181106119db576119db612644565b60200260200101518584815181106119f5576119f5612644565b6020026020010151611d4d565b905061163460028261273d565b828181518110611a2157611a21612644565b6020026020010151915050919050565b60606000825167ffffffffffffffff811115611a4f57611a4f612300565b604051908082528060200260200182016040528015611a78578160200160208202803683370190505b5090506000835167ffffffffffffffff811115611a9757611a97612300565b604051908082528060200260200182016040528015611ac0578160200160208202803683370190505b5090506000845167ffffffffffffffff811115611adf57611adf612300565b604051908082528060200260200182016040528015611b1257816020015b6060815260200190600190039081611afd5790505b50905060005b8551811015611b6f57604080516002808252606082018352909160208301908036833701905050828281518110611b5157611b51612644565b60200260200101819052508080611b6790612699565b915050611b18565b506000611b7a611478565b90506000611b87826115ad565b61ffff169050611b98600283612673565b60405190925060005b82811015611bde576000611bb88a89898989611d59565b9050611bc48186612673565b945082604052508080611bd690612699565b915050611ba1565b50611be98487612010565b98975050505050505050565b606060446000808236611c09602083612673565b92611c1693929190612765565b810190611c239190612243565b9050611c30602083612673565b91508067ffffffffffffffff811115611c4b57611c4b612300565b604051908082528060200260200182016040528015611c9057816020015b6040805180820190915260008082526020820152815260200190600190039081611c695790505b50925060005b818110156109905760008336611cad604083612673565b92611cba93929190612765565b810190611cc7919061278f565b848281518110611cd957611cd9612644565b6020908102919091010152611cef604084612673565b9250600101611c96565b60006115a68284612686565b8051602082016020820281019150805b828110156118f057815b81811015611d44578151815180821015611d3a578084528183525b5050602001611d1f565b50602001611d15565b60006115a68284612673565b600080600080611d68856118f6565b909250905060008080606081600d611d8b611d84602089612673565b8990612142565b611d959190612673565b90506000611da761191960688d612673565b90506000611dc483611dba60418f612673565b6119199190612673565b9050611dd08382611de3565b9350826020850120945081359650611e25565b604080518381526020818501810190925260009101838382377fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0019392505050565b611e368765ffffffffffff16611321565b611e4a85611e4560418f612673565b61214e565b9550611e55866106a2565b60ff1699505050505050505060008060005b84811015611fdd57611e7a8885836121e4565b909350915060005b8c51811015611fca578c8181518110611e9d57611e9d612644565b60200260200101518403611fb85760008b8281518110611ebf57611ebf612644565b60200260200101519050611ed881896001901b16151590565b158015611f015750600260ff168d8381518110611ef757611ef7612644565b6020026020010151105b15611fb2578c8281518110611f1857611f18612644565b602002602001018051809190611f2d90612699565b81525050838b8381518110611f4457611f44612644565b602002602001015160018f8581518110611f6057611f60612644565b6020026020010151611f729190612686565b81518110611f8257611f82612644565b60209081029190910101526001881b81178c8381518110611fa557611fa5612644565b6020026020010181815250505b50611fca565b80611fc281612699565b915050611e82565b5080611fd581612699565b915050611e67565b50505081602082611fee9190612673565b611ff8919061262d565b61200390604e612673565b9998505050505050505050565b60606000835167ffffffffffffffff81111561202e5761202e612300565b604051908082528060200260200182016040528015612057578160200160208202803683370190505b509050600260005b8551811015612138578185828151811061207b5761207b612644565b602002602001015110156120e15784818151811061209b5761209b612644565b6020026020010151826040517f2b13aef50000000000000000000000000000000000000000000000000000000081526004016105bc929190918252602082015260400190565b60006121058783815181106120f8576120f8612644565b6020026020010151610f91565b90508084838151811061211a5761211a612644565b6020908102919091010152508061213081612699565b91505061205f565b5090949350505050565b60006115a6828461262d565b60408051600080825260208083018085528690523685900380850135831a948401859052803560608501819052910135608084018190529193909260019060a0016020604051602081039080840390855afa1580156121b1573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00151979650505050505050565b600080806121f3604e87612673565b90506000612220612219612208602089612673565b612213886001612673565b90612142565b8390611d4d565b9050600061222e3683611cf9565b80359960209091013598509650505050505050565b60006020828403121561225557600080fd5b5035919050565b602080825282518282018190526000919060409081850190868401855b828110156122b45781518051855286015173ffffffffffffffffffffffffffffffffffffffff16868501529284019290850190600101612279565b5091979650505050505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461080b57600080fd5b6000602082840312156122f757600080fd5b6115a6826122c1565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561237657612376612300565b604052919050565b600067ffffffffffffffff82111561239857612398612300565b5060051b60200190565b600060208083850312156123b557600080fd5b823567ffffffffffffffff8111156123cc57600080fd5b8301601f810185136123dd57600080fd5b80356123f06123eb8261237e565b61232f565b81815260059190911b8201830190838101908783111561240f57600080fd5b928401925b8284101561242d57833582529284019290840190612414565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561247057835183529284019291840191600101612454565b50909695505050505050565b6000806040838503121561248f57600080fd5b50508035926020909101359150565b600060208083528351808285015260005b818110156124cb578581018301518582016040015282016124af565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b60008060006040848603121561251f57600080fd5b83359250602084013567ffffffffffffffff8082111561253e57600080fd5b818601915086601f83011261255257600080fd5b81358181111561256157600080fd5b8760208260061b850101111561257657600080fd5b6020830194508093505050509250925092565b6000806020838503121561259c57600080fd5b823567ffffffffffffffff808211156125b457600080fd5b818501915085601f8301126125c857600080fd5b8135818111156125d757600080fd5b8660208260051b85010111156125ec57600080fd5b60209290920196919550909350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610550576105506125fe565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80820180821115610550576105506125fe565b81810381811115610550576105506125fe565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036126ca576126ca6125fe565b5060010190565b600080604083850312156126e457600080fd5b505080516020909101519092909150565b60006020828403121561270757600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60008261274c5761274c61270e565b500490565b6000826127605761276061270e565b500690565b6000808585111561277557600080fd5b8386111561278257600080fd5b5050820193919092039150565b6000604082840312156127a157600080fd5b6040516040810181811067ffffffffffffffff821117156127c4576127c4612300565b6040526127d0836122c1565b81526127de602084016122c1565b6020820152939250505056fea26469706673582212209f4afb558124773c1898144e46b0ab63f29805131500b12c491545c83b6c3f6a64736f6c63430008110033

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061025c5760003560e01c8063aef2f16511610145578063d41f63b3116100bd578063f50b2efe1161008c578063fa182aff11610071578063fa182aff146104fb578063fba031581461050e578063fd1f4bef1461051657600080fd5b8063f50b2efe146104e1578063f90c4924146104f457600080fd5b8063d41f63b314610477578063d77b226e1461048a578063dbe19307146104c7578063e9eaee73146104ce57600080fd5b8063bb1f29b711610114578063c274583a116100f9578063c274583a14610448578063c84618b51461045d578063d149c0d71461047057600080fd5b8063bb1f29b714610422578063c14c92041461043557600080fd5b8063aef2f165146103b6578063b0f106b0146103cb578063b1fcc5cf146103fc578063b24ebfcc1461040f57600080fd5b80636dafaf6a116101d85780638129fc1c116101a75780639900aec11161018c5780639900aec114610370578063a8b940e614610392578063ada11457146103a357600080fd5b80638129fc1c14610355578063971b9c031461035d57600080fd5b80636dafaf6a1461032a5780636f6cfcc91461033d578063796b89b9146103475780637a02bdf11461034d57600080fd5b80633ce142f51161022f57806355a547d51161021457806355a547d5146102ef57806355d12458146102f75780636668316a1461031757600080fd5b80633ce142f5146102b757806344e02982146102dc57600080fd5b806311dc1e75146102615780631415013d146102875780631b2758ee1461029a578063270ab8c0146102a2575b600080fd5b61027461026f366004612243565b61053d565b6040519081526020015b60405180910390f35b610274610295366004612243565b610556565b6102746105c5565b6102aa6105e7565b60405161027e919061225c565b6102ca6102c53660046122e5565b6106a2565b60405160ff909116815260200161027e565b6102746102ea366004612243565b610810565b610274610833565b61030a6103053660046123a2565b610996565b60405161027e9190612438565b610274610325366004612243565b610a37565b610274610338366004612243565b610b16565b610345610b5e565b005b42610274565b610274610ce6565b610345610d08565b61030a61036b3660046123a2565b610e91565b60405173efb84935239dacdecf7c5ba76d8de40b077b7b33815260200161027e565b6103456103a03660046122e5565b50565b6103456103b1366004612243565b610f00565b60408051603c815260b460208201520161027e565b6103d3610f12565b604080516fffffffffffffffffffffffffffffffff93841681529290911660208301520161027e565b61034561040a36600461247c565b610f50565b61027461041d3660046123a2565b610f91565b610345610430366004612243565b610f9c565b610345610443366004612243565b61105f565b61045061109c565b60405161027e919061249e565b61027461046b366004612243565b6110d0565b6003610274565b61034561048536600461250a565b6110e3565b61049d610498366004612243565b6110ec565b6040805192835273ffffffffffffffffffffffffffffffffffffffff90911660208301520161027e565b6007610274565b6103456104dc36600461250a565b61130e565b6103456104ef366004612243565b611321565b60026102ca565b61030a610509366004612589565b611378565b61030a611415565b7f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe254610274565b600061055082662386f26fc1000061262d565b92915050565b60006007815b8181101561058a57600061056f826110ec565b50905080850361058157509392505050565b5060010161055c565b506040517f93829403000000000000000000000000000000000000000000000000000000008152600481018490526024015b60405180910390fd5b60006105cf610f12565b6fffffffffffffffffffffffffffffffff1692915050565b60408051600780825261010082019092526060919060009082816020015b604080518082019091526000808252602082015281526020019060019003908161060557905050905060005b8281101561069b57600080610645836110ec565b9150915060405180604001604052808381526020018273ffffffffffffffffffffffffffffffffffffffff1681525084848151811061068657610686612644565b60209081029190910101525050600101610631565b5092915050565b600073ffffffffffffffffffffffffffffffffffffffff8216738bb8f32df04c8b654987daaed53d6b6091e3b774036106dd57506000919050565b73ffffffffffffffffffffffffffffffffffffffff821673deb22f54738d54976c4c0fe5ce6d408e40d884990361071657506001919050565b73ffffffffffffffffffffffffffffffffffffffff82167351ce04be4b3e32572c4ec9135221d0691ba7d2020361074f57506002919050565b73ffffffffffffffffffffffffffffffffffffffff821673dd682daec5a90dd295d14da4b0bec9281017b5be0361078857506003919050565b73ffffffffffffffffffffffffffffffffffffffff8216739c5ae89c4af6aa32ce58588dbaf90d18a855b6de036107c157506004919050565b6040517fec459bc000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201526024016105bc565b919050565b600061081b82610b16565b50600061082783610a37565b90506105508382610f50565b60008061083e611478565b9050600061084b826115ad565b61ffff1690508060000361088b576040517f8552ff3c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610896600283612673565b915060005b818110156109905760006108ae84611600565b90506000806108be606887612673565b905060006108cc8236612686565b9050803592508265ffffffffffff16600003610914576040517f336dc9d000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8760000361092c578265ffffffffffff16975061096d565b878365ffffffffffff161461096d576040517fd9d1f46500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109778488612673565b965050505050808061098890612699565b91505061089b565b50505090565b6060815167ffffffffffffffff8111156109b2576109b2612300565b6040519080825280602002602001820160405280156109db578160200160208202803683370190505b50905060005b8251811015610a3157610a0c8382815181106109ff576109ff612644565b6020026020010151610a37565b828281518110610a1e57610a1e612644565b60209081029190910101526001016109e1565b50919050565b600080610a4383610556565b90506000610a50826110ec565b9150506000610a7073efb84935239dacdecf7c5ba76d8de40b077b7b3390565b6040517fef90e1b000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152919091169063ef90e1b0906024016040805180830381865afa158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0191906126d1565b509050610b0d816110d0565b95945050505050565b600080610b21611415565b905060005b815181101561058a5783828281518110610b4257610b42612644565b602002602001015103610b56579392505050565b600101610b26565b600773efb84935239dacdecf7c5ba76d8de40b077b7b3360005b82811015610ce1576000610b8b826110ec565b6040517f6dd6ef0c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80831660048301529193506000925090851690636dd6ef0c90602401602060405180830381865afa158015610bff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2391906126f5565b90508015610cd75773ffffffffffffffffffffffffffffffffffffffff841663dd34ca3b83610c53600185612686565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401600060405180830381600087803b158015610cbe57600080fd5b505af1158015610cd2573d6000803e3d6000fd5b505050505b5050600101610b78565b505050565b6000610cf0610f12565b506fffffffffffffffffffffffffffffffff16919050565b600054610100900460ff1615808015610d285750600054600160ff909116105b80610d425750303b158015610d42575060005460ff166001145b610dce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016105bc565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610e2c57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b80156103a057600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b60606000610e9e83610996565b905060005b835181101561069b576000848281518110610ec057610ec0612644565b60200260200101519050610ed381610b16565b50610ef781848481518110610eea57610eea612644565b6020026020010151610f50565b50600101610ea3565b610f098161163c565b6103a081610f9c565b600080610f48610f407f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe25490565b608081901c91565b915091509091565b80600003610f8d576040517f0565ce2a000000000000000000000000000000000000000000000000000000008152600481018390526024016105bc565b5050565b60006105508261168b565b6000610faa6103e88361273d565b9050603c60b4428381101561100b5782610fc48286612686565b1115611006576040517fb6b0916d00000000000000000000000000000000000000000000000000000000815260048101859052602481018290526044016105bc565b611058565b816110168583612686565b1115611058576040517f0321d0b500000000000000000000000000000000000000000000000000000000815260048101859052602481018290526044016105bc565b5050505050565b611067611696565b61107081610f00565b611079816116f9565b6000611083611415565b90506000611090826117bf565b9050610ce182826117ca565b60606040517f608b530700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610550662386f26fc100008361273d565b610ce18361105f565b6000808260000361113557507f43454c4f000000000000000000000000000000000000000000000000000000009273765de816845861e75a25fca122bb6898b8b1282a92509050565b8260010361117b57507f43454c4f2f4555520000000000000000000000000000000000000000000000009273d8763cba276a3738e6de85b4b3bf5fded6d6ca7392509050565b826002036111c157507f43454c4f2f42524c0000000000000000000000000000000000000000000000009273e8537a3d056da446677b9e9d6c5db704eaab478792509050565b8260030361120757507f55534443000000000000000000000000000000000000000000000000000000009273a1a8003936862e7a15092a91898d69fa8bce290c92509050565b8260040361124d57507f555344432f4555520000000000000000000000000000000000000000000000009273206b25ea01e188ee243131afde526ba6e131a01692509050565b8260050361129357507f555344432f42524c000000000000000000000000000000000000000000000000927325f21a1f97607edf6852339fad709728cffb9a9d92509050565b826006036112d957507f4555524f432f4555520000000000000000000000000000000000000000000000927326076b9702885d475ac8c3db3bd9f250dc5a318b92509050565b6040517f332dbea9000000000000000000000000000000000000000000000000000000008152600481018490526024016105bc565b6113198383836110e3565b610ce1610b5e565b336113295750565b6000611333610ce6565b9050808214610f8d576040517f6bc11ec500000000000000000000000000000000000000000000000000000000815260048101829052602481018390526044016105bc565b606060006113b88484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506117bf92505050565b905060005b815181101561140d576113e88282815181106113db576113db612644565b602002602001015161053d565b8282815181106113fa576113fa612644565b60209081029190910101526001016113bd565b509392505050565b604080516007808252610100820190925260609190600090826020820160e08036833701905050905060005b8281101561069b57611452816110ec565b5082828151811061146557611465612644565b6020908102919091010152600101611441565b60006602ed57011e00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0360135811614806114e0576040517fe7764c9e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000366029111561151d576040517f5796f78a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd736013560006009611556600362ffffff8516612673565b6115609190612673565b90503661156e600283612673565b11156115a6576040517fc30a7bd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b9392505050565b6000806115bb602084612673565b9050368111156115f7576040517f5796f78a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b36033592915050565b600080600061160e846118f6565b9092509050604e611620826020612673565b61162a908461262d565b6116349190612673565b949350505050565b6000611646610ce6565b9050808211610f8d576040517fef05deba00000000000000000000000000000000000000000000000000000000815260048101839052602481018290526044016105bc565b60006105508261194d565b4260006116a16105c5565b905060036116af8183612673565b831015610ce1576040517f83b3f5c40000000000000000000000000000000000000000000000000000000081526004810184905260248101839052604481018290526064016105bc565b426fffffffffffffffffffffffffffffffff811115611747576040517f70db678f000000000000000000000000000000000000000000000000000000008152600481018290526024016105bc565b6fffffffffffffffffffffffffffffffff821115611794576040517f5cbfa8a1000000000000000000000000000000000000000000000000000000008152600481018390526024016105bc565b60809190911b177f3d01e4d77237ea0f771f1786da4d4ff757fcba6a92933aa53b1dcef2d6bd6fe255565b606061055082611a31565b60006117d4611bf5565b905060005b83518110156118f05760006117ed826110ec565b91505060006118078584815181106113db576113db612644565b9050600084848151811061181d5761181d612644565b6020026020010151905061184273efb84935239dacdecf7c5ba76d8de40b077b7b3390565b815160208301516040517f80e5074400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015260248201879052928316604482015290821660648201529116906380e5074490608401600060405180830381600087803b1580156118c957600080fd5b505af11580156118dd573d6000803e3d6000fd5b5050600190950194506117d99350505050565b50505050565b600080808080611907604187612673565b90506000611920611919602084612673565b3690611cf9565b803594509050611931816003611cf9565b62ffffff9490941697933563ffffffff16965092945050505050565b6000815160000361198a576040517f9e198af900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61199382611d05565b6000600283516119a3919061273d565b9050600283516119b39190612751565b600003611a0f576000611a02846119cb600185612686565b815181106119db576119db612644565b60200260200101518584815181106119f5576119f5612644565b6020026020010151611d4d565b905061163460028261273d565b828181518110611a2157611a21612644565b6020026020010151915050919050565b60606000825167ffffffffffffffff811115611a4f57611a4f612300565b604051908082528060200260200182016040528015611a78578160200160208202803683370190505b5090506000835167ffffffffffffffff811115611a9757611a97612300565b604051908082528060200260200182016040528015611ac0578160200160208202803683370190505b5090506000845167ffffffffffffffff811115611adf57611adf612300565b604051908082528060200260200182016040528015611b1257816020015b6060815260200190600190039081611afd5790505b50905060005b8551811015611b6f57604080516002808252606082018352909160208301908036833701905050828281518110611b5157611b51612644565b60200260200101819052508080611b6790612699565b915050611b18565b506000611b7a611478565b90506000611b87826115ad565b61ffff169050611b98600283612673565b60405190925060005b82811015611bde576000611bb88a89898989611d59565b9050611bc48186612673565b945082604052508080611bd690612699565b915050611ba1565b50611be98487612010565b98975050505050505050565b606060446000808236611c09602083612673565b92611c1693929190612765565b810190611c239190612243565b9050611c30602083612673565b91508067ffffffffffffffff811115611c4b57611c4b612300565b604051908082528060200260200182016040528015611c9057816020015b6040805180820190915260008082526020820152815260200190600190039081611c695790505b50925060005b818110156109905760008336611cad604083612673565b92611cba93929190612765565b810190611cc7919061278f565b848281518110611cd957611cd9612644565b6020908102919091010152611cef604084612673565b9250600101611c96565b60006115a68284612686565b8051602082016020820281019150805b828110156118f057815b81811015611d44578151815180821015611d3a578084528183525b5050602001611d1f565b50602001611d15565b60006115a68284612673565b600080600080611d68856118f6565b909250905060008080606081600d611d8b611d84602089612673565b8990612142565b611d959190612673565b90506000611da761191960688d612673565b90506000611dc483611dba60418f612673565b6119199190612673565b9050611dd08382611de3565b9350826020850120945081359650611e25565b604080518381526020818501810190925260009101838382377fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0019392505050565b611e368765ffffffffffff16611321565b611e4a85611e4560418f612673565b61214e565b9550611e55866106a2565b60ff1699505050505050505060008060005b84811015611fdd57611e7a8885836121e4565b909350915060005b8c51811015611fca578c8181518110611e9d57611e9d612644565b60200260200101518403611fb85760008b8281518110611ebf57611ebf612644565b60200260200101519050611ed881896001901b16151590565b158015611f015750600260ff168d8381518110611ef757611ef7612644565b6020026020010151105b15611fb2578c8281518110611f1857611f18612644565b602002602001018051809190611f2d90612699565b81525050838b8381518110611f4457611f44612644565b602002602001015160018f8581518110611f6057611f60612644565b6020026020010151611f729190612686565b81518110611f8257611f82612644565b60209081029190910101526001881b81178c8381518110611fa557611fa5612644565b6020026020010181815250505b50611fca565b80611fc281612699565b915050611e82565b5080611fd581612699565b915050611e67565b50505081602082611fee9190612673565b611ff8919061262d565b61200390604e612673565b9998505050505050505050565b60606000835167ffffffffffffffff81111561202e5761202e612300565b604051908082528060200260200182016040528015612057578160200160208202803683370190505b509050600260005b8551811015612138578185828151811061207b5761207b612644565b602002602001015110156120e15784818151811061209b5761209b612644565b6020026020010151826040517f2b13aef50000000000000000000000000000000000000000000000000000000081526004016105bc929190918252602082015260400190565b60006121058783815181106120f8576120f8612644565b6020026020010151610f91565b90508084838151811061211a5761211a612644565b6020908102919091010152508061213081612699565b91505061205f565b5090949350505050565b60006115a6828461262d565b60408051600080825260208083018085528690523685900380850135831a948401859052803560608501819052910135608084018190529193909260019060a0016020604051602081039080840390855afa1580156121b1573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00151979650505050505050565b600080806121f3604e87612673565b90506000612220612219612208602089612673565b612213886001612673565b90612142565b8390611d4d565b9050600061222e3683611cf9565b80359960209091013598509650505050505050565b60006020828403121561225557600080fd5b5035919050565b602080825282518282018190526000919060409081850190868401855b828110156122b45781518051855286015173ffffffffffffffffffffffffffffffffffffffff16868501529284019290850190600101612279565b5091979650505050505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461080b57600080fd5b6000602082840312156122f757600080fd5b6115a6826122c1565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561237657612376612300565b604052919050565b600067ffffffffffffffff82111561239857612398612300565b5060051b60200190565b600060208083850312156123b557600080fd5b823567ffffffffffffffff8111156123cc57600080fd5b8301601f810185136123dd57600080fd5b80356123f06123eb8261237e565b61232f565b81815260059190911b8201830190838101908783111561240f57600080fd5b928401925b8284101561242d57833582529284019290840190612414565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561247057835183529284019291840191600101612454565b50909695505050505050565b6000806040838503121561248f57600080fd5b50508035926020909101359150565b600060208083528351808285015260005b818110156124cb578581018301518582016040015282016124af565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b60008060006040848603121561251f57600080fd5b83359250602084013567ffffffffffffffff8082111561253e57600080fd5b818601915086601f83011261255257600080fd5b81358181111561256157600080fd5b8760208260061b850101111561257657600080fd5b6020830194508093505050509250925092565b6000806020838503121561259c57600080fd5b823567ffffffffffffffff808211156125b457600080fd5b818501915085601f8301126125c857600080fd5b8135818111156125d757600080fd5b8660208260051b85010111156125ec57600080fd5b60209290920196919550909350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610550576105506125fe565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80820180821115610550576105506125fe565b81810381811115610550576105506125fe565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036126ca576126ca6125fe565b5060010190565b600080604083850312156126e457600080fd5b505080516020909101519092909150565b60006020828403121561270757600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60008261274c5761274c61270e565b500490565b6000826127605761276061270e565b500690565b6000808585111561277557600080fd5b8386111561278257600080fd5b5050820193919092039150565b6000604082840312156127a157600080fd5b6040516040810181811067ffffffffffffffff821117156127c4576127c4612300565b6040526127d0836122c1565b81526127de602084016122c1565b6020820152939250505056fea26469706673582212209f4afb558124773c1898144e46b0ab63f29805131500b12c491545c83b6c3f6a64736f6c63430008110033