false
false
100

Contract Address Details

0x2d2793c77927bcFE2847F24F43D27CfBAe687826

Contract Name
WitnetPriceFeedsBypassV20
Creator
0xf121b7–f0694d at 0x55c0c7–72bf74
Balance
0 KAVA ( )
Tokens
Fetching tokens...
Transactions
Fetching transactions...
Transfers
Fetching transfers...
Gas Used
Fetching gas used...
Last Balance Update
11603301
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
WitnetPriceFeedsBypassV20




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




Optimization runs
200
EVM Version
london




Verified at
2024-05-23T12:55:51.614365Z

Constructor Arguments

0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11110000000000000000000000000000000000000000000000000000000000000001302e372e31382d34336162303631000000000000000000000000000000000000

Arg [0] (address) : 0x1111aba2164acdc6d291b08dfb374280035e1111
Arg [1] (bool) : true
Arg [2] (bytes32) : 302e372e31382d34336162303631000000000000000000000000000000000000

              

project:/contracts/impls/apps/WitnetPriceFeedsBypassV20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "../../impls/WitnetUpgradableBase.sol";
import "../../interfaces/V2/IWitnetPriceFeeds.sol";

abstract contract WitnetPriceFeedsV07 {
    function supportedFeeds() virtual external view returns (bytes4[] memory, string[] memory, bytes32[] memory);
}

abstract contract WitnetPriceFeedsV20 {
    function isUpgradableFrom(address) virtual external view returns (bool);
    function latestUpdateResponseStatus(bytes4) virtual external view returns (WitnetV2.ResponseStatus);
    function owner() virtual external view returns (address);
    function requestUpdate(bytes4) virtual external payable returns (uint256);
    function specs() virtual external view returns (bytes4);
}

/// @title Witnet Price Feeds surrogate bypass implementation to V2.0 
/// @author The Witnet Foundation
contract WitnetPriceFeedsBypassV20
    is
        WitnetUpgradableBase
{
    using Witnet for bytes4;
    WitnetPriceFeedsV20 immutable public surrogate;

    constructor (
            WitnetPriceFeedsV20 _surrogate,
            bool _upgradable,
            bytes32 _versionTag
        )
        WitnetUpgradableBase(
            _upgradable,
            _versionTag,
            "io.witnet.proxiable.router"
        )
    {
        _require(
            address(_surrogate).code.length > 0
                && _surrogate.specs() == type(IWitnetPriceFeeds).interfaceId,
            "uncompliant surrogate"
        );
        surrogate = _surrogate;
    }

    // solhint-disable-next-line payable-fallback
    fallback() virtual override external { /* solhint-disable no-complex-fallback */
        address _surrogate = address(surrogate);
        assembly { /* solhint-disable avoid-low-level-calls */
            // Gas optimized surrogate call to the 'surrogate' immutable contract.
            // Note: `msg.data`, `msg.sender` and `msg.value` will be passed over 
            //       to actual implementation of `msg.sig` within `implementation` contract.
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize())
            let result := call(gas(), _surrogate, 0, ptr, calldatasize(), 0, 0)
            let size := returndatasize()
            returndatacopy(ptr, 0, size)
            switch result
                case 0  { 
                    // pass back revert message:
                    revert(ptr, size) 
                }
                default {
                  // pass back same data as returned by 'implementation' contract:
                  return(ptr, size) 
                }
        }
    }

    function class() public pure returns (string memory) {
        return type(WitnetPriceFeedsBypassV20).name;
    }

    
    // ================================================================================================================
    // --- Overrides 'Upgradeable' -------------------------------------------------------------------------------------

    function owner() public view override returns (address) {
        return surrogate.owner();
    }
   
    
    // ================================================================================================================
    // --- Overrides 'Upgradeable' ------------------------------------------------------------------------------------

    /// @notice Re-initialize contract's storage context upon a new upgrade from a proxy.
    /// @dev Must fail when trying to upgrade to same logic contract more than once.
    function initialize(bytes memory) 
        public override
        onlyDelegateCalls // => we don't want the logic base contract to be ever initialized
    {
        if (
            __proxiable().proxy == address(0)
                && __proxiable().implementation == address(0)
        ) {
            // a proxy is being initialized for the first time...
            __proxiable().proxy = address(this);
            _transferOwnership(msg.sender);
        } else {
            // only the owner can initialize:
            if (msg.sender != owner()) {
                _revert("not the owner");
            }
        }
        
        // Check that new implentation hasn't actually been initialized already:
        _require(
            __proxiable().implementation != base(),
            "already initialized"
        );
        
        (bytes4[] memory _id4s,,) = WitnetPriceFeedsV07(address(this)).supportedFeeds();
        for (uint _ix = 0; _ix < _id4s.length; _ix ++) {
            // Check that all supported price feeds under current implementation
            // are actually supported under the surrogate immutable instance,
            // and that none of them is currently in pending status:
            WitnetV2.ResponseStatus _status = surrogate.latestUpdateResponseStatus(_id4s[_ix]);
            _require(
                _status == WitnetV2.ResponseStatus.Ready 
                    || _status == WitnetV2.ResponseStatus.Error
                    || _status == WitnetV2.ResponseStatus.Delivered,
                string(abi.encodePacked(
                    "unconsolidated feed: 0x",
                    _id4s[_ix].toHexString()
                ))
            );
        }

        // Set new implementation as initialized:
        __proxiable().implementation = base();

        // Emit event:
        emit Upgraded(msg.sender, base(), codehash(), version());
    }

    function isUpgradableFrom(address _from) external view override returns (bool) {
        return surrogate.isUpgradableFrom(_from);
    }


    // ================================================================================================================
    // --- Partial interception of 'IWitnetFeeds' ---------------------------------------------------------------------

    function estimateUpdateBaseFee(bytes4, uint256 _gasPrice, uint256) public view returns (uint256) {
        return abi.decode(
            _staticcall(abi.encodeWithSignature(
                "estimateUpdateBaseFee(uint256)", 
                _gasPrice
            )),
            (uint256)
        );
    }

    function estimateUpdateBaseFee(bytes4, uint256 _gasPrice, uint256, bytes32) external view returns (uint256) {
        return abi.decode(
            _staticcall(abi.encodeWithSignature(
                "estimateUpdateBaseFee(uint256)", 
                _gasPrice
            )),
            (uint256)
        );
    }

    function latestResponse(bytes4 _feedId) public view returns (Witnet.Response memory) {
        WitnetV2.Response memory _responseV2 = abi.decode(
            _staticcall(abi.encodeWithSignature(
                "lastValidResponse(bytes4)",
                _feedId
            )),
            (WitnetV2.Response)
        );
        return Witnet.Response({
            reporter: _responseV2.reporter,
            timestamp: uint256(_responseV2.resultTimestamp),
            drTxHash: _responseV2.resultTallyHash,
            cborBytes: _responseV2.resultCborBytes
        });
    }

    function latestResult(bytes4 _feedId) public view returns (Witnet.Result memory) {
        return Witnet.resultFromCborBytes(
            latestResponse(_feedId).cborBytes
        );
    }

    function latestUpdateRequest(bytes4 _feedId) external view returns (Witnet.Request memory) {
        WitnetV2.Request memory _requestV2 = abi.decode(
            _staticcall(abi.encodeWithSignature(
                "latestUpdateRequest(bytes4)", 
                _feedId
            )),
            (WitnetV2.Request)
        );
        return Witnet.Request({
            addr: address(0),
            slaHash: abi.decode(abi.encode(_requestV2.witnetSLA), (bytes32)),
            radHash: _requestV2.witnetRAD,
            gasprice: tx.gasprice,
            reward: uint256(_requestV2.evmReward)
        });
    }
    
    function latestUpdateResponse(bytes4 _feedId) external view returns (Witnet.Response memory) {
        WitnetV2.Response memory _responseV2 = abi.decode(
            _staticcall(abi.encodeWithSignature(
                "latestUpdateResponse(bytes4)", 
                _feedId
            )),
            (WitnetV2.Response)
        );
        return Witnet.Response({
            reporter: _responseV2.reporter,
            timestamp: uint256(_responseV2.resultTimestamp),
            drTxHash: bytes32(_responseV2.resultTallyHash),
            cborBytes: _responseV2.resultCborBytes
        });
    }
    
    function latestUpdateResultStatus(bytes4 _feedId) external view returns (Witnet.ResultStatus) {
        WitnetV2.ResponseStatus _status = abi.decode(
            _staticcall(abi.encodeWithSignature(
                "latestUpdateResponseStatus(bytes4)", 
                _feedId
            )),
            (WitnetV2.ResponseStatus)
        );
        if (_status == WitnetV2.ResponseStatus.Finalizing) {
            return Witnet.ResultStatus.Awaiting;
        } else {
            return Witnet.ResultStatus(uint8(_status));
        }
    }

    function lookupBytecode(bytes4 _feedId) external view returns (bytes memory) {
        return abi.decode(
            _staticcall(abi.encodeWithSignature(
                "lookupWitnetBytecode(bytes4)", 
                _feedId
            )),
            ((bytes))
        );
    }
    
    function lookupRadHash(bytes4 _feedId) external view returns (bytes32) {
        return abi.decode(
            _staticcall(abi.encodeWithSignature(
                "lookupWitnetRadHash(bytes4)", 
                _feedId
            )),
            (bytes32)
        );
    }

    function requestUpdate(bytes4 _feedId) external payable returns (uint256 _usedFunds) {
        _usedFunds = surrogate.requestUpdate{
            value: msg.value
        }(
            _feedId
        );
        if (_usedFunds < msg.value) {
            // transfer back unused funds:
            payable(msg.sender).transfer(msg.value - _usedFunds);
        }
    }
    
    function requestUpdate(bytes4, bytes32) external payable returns (uint256) {
        _revert("deprecated");
    }


    // ================================================================================================================
    // --- Partial interception of 'IWitnetFeedsAdmin' ----------------------------------------------------------------

    function settleDefaultRadonSLA(Witnet.RadonSLA calldata _slaV1) external {
        _require(
            Witnet.isValid(_slaV1),
            "invalid SLA"
        );
        __call(abi.encodeWithSignature(
            "settleDefaultRadonSLA((uint8,uint64))", 
            WitnetV2.RadonSLA({
                committeeSize: _slaV1.numWitnesses,
                witnessingFeeNanoWit: _slaV1.witnessCollateral / _slaV1.numWitnesses
            })
        ));
    }

    
    // ================================================================================================================
    // --- Internal methods -------------------------------------------------------------------------------------------

    function _require(bool _condition, string memory _message) internal pure {
        if (!_condition) {
            _revert(_message);
        }
    }

    function _revert(string memory _reason) internal pure {
        revert(
            string(abi.encodePacked(
                class(),
                ": ",
                _reason
            ))
        );
    }

    function _staticcall(bytes memory _encodedCall) internal view returns (bytes memory _returnData) {
        bool _success;
        (_success, _returnData) = address(surrogate).staticcall(_encodedCall);
        _require(
            _success,
            string(abi.encodePacked(
                "cannot surrogate static call: 0x",
                msg.sig.toHexString()
            ))
        );
    }

    function __call(bytes memory _encodedCall) internal returns (bytes memory _returnData) {
        bool _success;
        (_success, _returnData) = address(surrogate).call(_encodedCall);
        _require(
            _success,
            string(abi.encodePacked(
                "cannot surrogate call: 0x",
                msg.sig.toHexString()
            ))
        );
    }

}
        

/Upgradeable.sol

// SPDX-License-Identifier: MIT

/* solhint-disable var-name-mixedcase */

pragma solidity >=0.6.0 <0.9.0;

import "./Initializable.sol";
import "./Proxiable.sol";

abstract contract Upgradeable is Initializable, Proxiable {

    address internal immutable _BASE;
    bytes32 internal immutable _CODEHASH;
    bool internal immutable _UPGRADABLE;

    modifier onlyDelegateCalls virtual {
        require(
            address(this) != _BASE,
            "Upgradeable: not a delegate call"
        );
        _;
    }

    /// Emitted every time the contract gets upgraded.
    /// @param from The address who ordered the upgrading. Namely, the WRB operator in "trustable" implementations.
    /// @param baseAddr The address of the new implementation contract.
    /// @param baseCodehash The EVM-codehash of the new implementation contract.
    /// @param versionTag Ascii-encoded version literal with which the implementation deployer decided to tag it.
    event Upgraded(
        address indexed from,
        address indexed baseAddr,
        bytes32 indexed baseCodehash,
        string  versionTag
    );

    constructor (bool _isUpgradable) {
        address _base = address(this);
        bytes32 _codehash;        
        assembly {
            _codehash := extcodehash(_base)
        }
        _BASE = _base;
        _CODEHASH = _codehash;
        _UPGRADABLE = _isUpgradable;
    }

    /// @dev Retrieves base contract. Differs from address(this) when called via delegate-proxy pattern.
    function base() public view returns (address) {
        return _BASE;
    }

    /// @dev Retrieves the immutable codehash of this contract, even if invoked as delegatecall.
    function codehash() public view returns (bytes32) {
        return _CODEHASH;
    }

    /// @dev Determines whether the logic of this contract is potentially upgradable.
    function isUpgradable() public view returns (bool) {
        return _UPGRADABLE;
    }

    /// @dev Tells whether provided address could eventually upgrade the contract.
    function isUpgradableFrom(address from) virtual external view returns (bool);

    /// @notice Re-initialize contract's storage context upon a new upgrade from a proxy.    
    /// @dev Must fail when trying to upgrade to same logic contract more than once.
    function initialize(bytes memory) virtual external;

    /// @dev Retrieves human-redable named version of current implementation.
    function version() virtual public view returns (string memory); 
}
          

/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
          

/Proxiable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

abstract contract Proxiable {
    /// @dev Complying with EIP-1822: Universal Upgradeable Proxy Standard (UUPS)
    /// @dev See https://eips.ethereum.org/EIPS/eip-1822.
    function proxiableUUID() virtual external view returns (bytes32);

    struct ProxiableSlot {
        address implementation;
        address proxy;
    }

    function __implementation() internal view returns (address) {
        return __proxiable().implementation;
    }

    function __proxy() internal view returns (address) {
        return __proxiable().proxy;
    }

    function __proxiable() internal pure returns (ProxiableSlot storage proxiable) {
        assembly {
            // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
            proxiable.slot := 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
        }
    }
}
          

/Ownable2Step.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert("Ownable2Step: caller is not the new owner");
        }
        _transferOwnership(sender);
    }
}
          

/Ownable.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
          

/Initializable.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
          

/ERC165.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
          

/WitnetV2.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./Witnet.sol";

library WitnetV2 {

    /// Struct containing both request and response data related to every query posted to the Witnet Request Board
    struct Query {
        Request request;
        Response response;
    }

    /// Possible status of a Witnet query.
    enum QueryStatus {
        Unknown,
        Posted,
        Reported,
        Finalized
    }

    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct Request {
        address requester;              // EVM address from which the request was posted.
        uint24  gasCallback;            // Max callback gas limit upon response, if a callback is required.
        uint72  evmReward;              // EVM amount in wei eventually to be paid to the legit result reporter.
        bytes   witnetBytecode;         // Optional: Witnet Data Request bytecode to be solved by the Witnet blockchain.
        bytes32 witnetRAD;              // Optional: Previously verified hash of the Witnet Data Request to be solved.
        Witnet.RadonSLA witnetSLA;    // Minimum Service-Level parameters to be committed by the Witnet blockchain. 
    }

    /// Response metadata and result as resolved by the Witnet blockchain.
    struct Response {
        address reporter;               // EVM address from which the Data Request result was reported.
        uint64  finality;               // EVM block number at which the reported data will be considered to be finalized.
        uint32  resultTimestamp;        // Unix timestamp (seconds) at which the data request was resolved in the Witnet blockchain.
        bytes32 resultTallyHash;        // Unique hash of the commit/reveal act in the Witnet blockchain that resolved the data request.
        bytes   resultCborBytes;        // CBOR-encode result to the request, as resolved in the Witnet blockchain.
    }

    /// Response status from a requester's point of view.
    enum ResponseStatus {
        Void,
        Awaiting,
        Ready,
        Error,
        Finalizing,
        Delivered
    }

    struct RadonSLA {
        /// @notice Number of nodes in the Witnet blockchain that will take part in solving the data request. 
        uint8   committeeSize;
        
        /// @notice Fee in $nanoWIT paid to every node in the Witnet blockchain involved in solving the data request.
        /// @dev Witnet nodes participating as witnesses will have to stake as collateral 100x this amount.
        uint64  witnessingFeeNanoWit;
    }

    
    /// ===============================================================================================================
    /// --- 'WitnetV2.RadonSLA' helper methods ------------------------------------------------------------------------

    function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b) 
        internal pure returns (bool)
    {
        return (a.committeeSize >= b.committeeSize);
    }
     
    function isValid(RadonSLA calldata sla) internal pure returns (bool) {
        return (
            sla.witnessingFeeNanoWit > 0 
                && sla.committeeSize > 0 && sla.committeeSize <= 127
                // v1.7.x requires witnessing collateral to be greater or equal to 20 WIT:
                && sla.witnessingFeeNanoWit * 100 >= 20 * 10 ** 9 
        );
    }

    function toV1(RadonSLA memory self) internal pure returns (Witnet.RadonSLA memory) {
        return Witnet.RadonSLA({
            numWitnesses: self.committeeSize,
            minConsensusPercentage: 51,
            witnessReward: self.witnessingFeeNanoWit,
            witnessCollateral: self.witnessingFeeNanoWit * 100,
            minerCommitRevealFee: self.witnessingFeeNanoWit / self.committeeSize
        });
    }

    function nanoWitTotalFee(RadonSLA storage self) internal view returns (uint64) {
        return self.witnessingFeeNanoWit * (self.committeeSize + 3);
    }


    /// ===============================================================================================================
    /// --- P-RNG generators ------------------------------------------------------------------------------------------

    /// Generates a pseudo-random uint32 number uniformly distributed within the range `[0 .. range)`, based on
    /// the given `nonce` and `seed` values. 
    function randomUint32(uint32 range, uint256 nonce, bytes32 seed)
        internal pure 
        returns (uint32) 
    {
        uint256 _number = uint256(
            keccak256(
                abi.encode(seed, nonce)
            )
        ) & uint256(2 ** 224 - 1);
        return uint32((_number * range) >> 224);
    }


    /// ===============================================================================================================
    /// --- Runtime Custom errors -------------------------------------------------------------------------------------

    error IndexOutOfBounds(uint256 index, uint256 range);
    error InsufficientBalance(uint256 weiBalance, uint256 weiExpected);
    error InsufficientFee(uint256 weiProvided, uint256 weiExpected);
    error Unauthorized(address violator);

    error RadonFilterMissingArgs(uint8 opcode);

    error RadonRequestNoSources();
    error RadonRequestSourcesArgsMismatch(uint256 expected, uint256 actual);
    error RadonRequestMissingArgs(uint256 index, uint256 expected, uint256 actual);
    error RadonRequestResultsMismatch(uint256 index, uint8 read, uint8 expected);
    error RadonRequestTooHeavy(bytes bytecode, uint256 weight);

    error RadonSlaNoReward();
    error RadonSlaNoWitnesses();
    error RadonSlaTooManyWitnesses(uint256 numWitnesses);
    error RadonSlaConsensusOutOfRange(uint256 percentage);
    error RadonSlaLowCollateral(uint256 witnessCollateral);

    error UnsupportedDataRequestMethod(uint8 method, string schema, string body, string[2][] headers);
    error UnsupportedRadonDataType(uint8 datatype, uint256 maxlength);
    error UnsupportedRadonFilterOpcode(uint8 opcode);
    error UnsupportedRadonFilterArgs(uint8 opcode, bytes args);
    error UnsupportedRadonReducerOpcode(uint8 opcode);
    error UnsupportedRadonReducerScript(uint8 opcode, bytes script, uint256 offset);
    error UnsupportedRadonScript(bytes script, uint256 offset);
    error UnsupportedRadonScriptOpcode(bytes script, uint256 cursor, uint8 opcode);
    error UnsupportedRadonTallyScript(bytes32 hash);
}
          

/WitnetCBOR.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./WitnetBuffer.sol";

/// @title A minimalistic implementation of “RFC 7049 Concise Binary Object Representation”
/// @notice This library leverages a buffer-like structure for step-by-step decoding of bytes so as to minimize
/// the gas cost of decoding them into a useful native type.
/// @dev Most of the logic has been borrowed from Patrick Gansterer’s cbor.js library: https://github.com/paroga/cbor-js
/// @author The Witnet Foundation.

library WitnetCBOR {

  using WitnetBuffer for WitnetBuffer.Buffer;
  using WitnetCBOR for WitnetCBOR.CBOR;

  /// Data struct following the RFC-7049 standard: Concise Binary Object Representation.
  struct CBOR {
      WitnetBuffer.Buffer buffer;
      uint8 initialByte;
      uint8 majorType;
      uint8 additionalInformation;
      uint64 len;
      uint64 tag;
  }

  uint8 internal constant MAJOR_TYPE_INT = 0;
  uint8 internal constant MAJOR_TYPE_NEGATIVE_INT = 1;
  uint8 internal constant MAJOR_TYPE_BYTES = 2;
  uint8 internal constant MAJOR_TYPE_STRING = 3;
  uint8 internal constant MAJOR_TYPE_ARRAY = 4;
  uint8 internal constant MAJOR_TYPE_MAP = 5;
  uint8 internal constant MAJOR_TYPE_TAG = 6;
  uint8 internal constant MAJOR_TYPE_CONTENT_FREE = 7;

  uint32 internal constant UINT32_MAX = type(uint32).max;
  uint64 internal constant UINT64_MAX = type(uint64).max;
  
  error EmptyArray();
  error InvalidLengthEncoding(uint length);
  error UnexpectedMajorType(uint read, uint expected);
  error UnsupportedPrimitive(uint primitive);
  error UnsupportedMajorType(uint unexpected);  

  modifier isMajorType(
      WitnetCBOR.CBOR memory cbor,
      uint8 expected
  ) {
    if (cbor.majorType != expected) {
      revert UnexpectedMajorType(cbor.majorType, expected);
    }
    _;
  }

  modifier notEmpty(WitnetBuffer.Buffer memory buffer) {
    if (buffer.data.length == 0) {
      revert WitnetBuffer.EmptyBuffer();
    }
    _;
  }

  function eof(CBOR memory cbor)
    internal pure
    returns (bool)
  {
    return cbor.buffer.cursor >= cbor.buffer.data.length;
  }

  /// @notice Decode a CBOR structure from raw bytes.
  /// @dev This is the main factory for CBOR instances, which can be later decoded into native EVM types.
  /// @param bytecode Raw bytes representing a CBOR-encoded value.
  /// @return A `CBOR` instance containing a partially decoded value.
  function fromBytes(bytes memory bytecode)
    internal pure
    returns (CBOR memory)
  {
    WitnetBuffer.Buffer memory buffer = WitnetBuffer.Buffer(bytecode, 0);
    return fromBuffer(buffer);
  }

  /// @notice Decode a CBOR structure from raw bytes.
  /// @dev This is an alternate factory for CBOR instances, which can be later decoded into native EVM types.
  /// @param buffer A Buffer structure representing a CBOR-encoded value.
  /// @return A `CBOR` instance containing a partially decoded value.
  function fromBuffer(WitnetBuffer.Buffer memory buffer)
    internal pure
    notEmpty(buffer)
    returns (CBOR memory)
  {
    uint8 initialByte;
    uint8 majorType = 255;
    uint8 additionalInformation;
    uint64 tag = UINT64_MAX;
    uint256 len;
    bool isTagged = true;
    while (isTagged) {
      // Extract basic CBOR properties from input bytes
      initialByte = buffer.readUint8();
      len ++;
      majorType = initialByte >> 5;
      additionalInformation = initialByte & 0x1f;
      // Early CBOR tag parsing.
      if (majorType == MAJOR_TYPE_TAG) {
        uint _cursor = buffer.cursor;
        tag = readLength(buffer, additionalInformation);
        len += buffer.cursor - _cursor;
      } else {
        isTagged = false;
      }
    }
    if (majorType > MAJOR_TYPE_CONTENT_FREE) {
      revert UnsupportedMajorType(majorType);
    }
    return CBOR(
      buffer,
      initialByte,
      majorType,
      additionalInformation,
      uint64(len),
      tag
    );
  }

  function fork(WitnetCBOR.CBOR memory self)
    internal pure
    returns (WitnetCBOR.CBOR memory)
  {
    return CBOR({
      buffer: self.buffer.fork(),
      initialByte: self.initialByte,
      majorType: self.majorType,
      additionalInformation: self.additionalInformation,
      len: self.len,
      tag: self.tag
    });
  }

  function settle(CBOR memory self)
      internal pure
      returns (WitnetCBOR.CBOR memory)
  {
    if (!self.eof()) {
      return fromBuffer(self.buffer);
    } else {
      return self;
    }
  }

  function skip(CBOR memory self)
      internal pure
      returns (WitnetCBOR.CBOR memory)
  {
    if (
      self.majorType == MAJOR_TYPE_INT
        || self.majorType == MAJOR_TYPE_NEGATIVE_INT
        || (
          self.majorType == MAJOR_TYPE_CONTENT_FREE 
            && self.additionalInformation >= 25
            && self.additionalInformation <= 27
        )
    ) {
      self.buffer.cursor += self.peekLength();
    } else if (
        self.majorType == MAJOR_TYPE_STRING
          || self.majorType == MAJOR_TYPE_BYTES
    ) {
      uint64 len = readLength(self.buffer, self.additionalInformation);
      self.buffer.cursor += len;
    } else if (
      self.majorType == MAJOR_TYPE_ARRAY
        || self.majorType == MAJOR_TYPE_MAP
    ) { 
      self.len = readLength(self.buffer, self.additionalInformation);      
    } else if (
       self.majorType != MAJOR_TYPE_CONTENT_FREE
        || (
          self.additionalInformation != 20
            && self.additionalInformation != 21
        )
    ) {
      revert("WitnetCBOR.skip: unsupported major type");
    }
    return self;
  }

  function peekLength(CBOR memory self)
    internal pure
    returns (uint64)
  {
    if (self.additionalInformation < 24) {
      return 0;
    } else if (self.additionalInformation < 28) {
      return uint64(1 << (self.additionalInformation - 24));
    } else {
      revert InvalidLengthEncoding(self.additionalInformation);
    }
  }

  function readArray(CBOR memory self)
    internal pure
    isMajorType(self, MAJOR_TYPE_ARRAY)
    returns (CBOR[] memory items)
  {
    // read array's length and move self cursor forward to the first array element:
    uint64 len = readLength(self.buffer, self.additionalInformation);
    items = new CBOR[](len + 1);
    for (uint ix = 0; ix < len; ix ++) {
      // settle next element in the array:
      self = self.settle();
      // fork it and added to the list of items to be returned:
      items[ix] = self.fork();
      if (self.majorType == MAJOR_TYPE_ARRAY) {
        CBOR[] memory _subitems = self.readArray();
        // move forward to the first element after inner array:
        self = _subitems[_subitems.length - 1];
      } else if (self.majorType == MAJOR_TYPE_MAP) {
        CBOR[] memory _subitems = self.readMap();
        // move forward to the first element after inner map:
        self = _subitems[_subitems.length - 1];
      } else {
        // move forward to the next element:
        self.skip();
      }
    }
    // return self cursor as extra item at the end of the list,
    // as to optimize recursion when jumping over nested arrays:
    items[len] = self;
  }

  function readMap(CBOR memory self)
    internal pure
    isMajorType(self, MAJOR_TYPE_MAP)
    returns (CBOR[] memory items)
  {
    // read number of items within the map and move self cursor forward to the first inner element:
    uint64 len = readLength(self.buffer, self.additionalInformation) * 2;
    items = new CBOR[](len + 1);
    for (uint ix = 0; ix < len; ix ++) {
      // settle next element in the array:
      self = self.settle();
      // fork it and added to the list of items to be returned:
      items[ix] = self.fork();
      if (ix % 2 == 0 && self.majorType != MAJOR_TYPE_STRING) {
        revert UnexpectedMajorType(self.majorType, MAJOR_TYPE_STRING);
      } else if (self.majorType == MAJOR_TYPE_ARRAY || self.majorType == MAJOR_TYPE_MAP) {
        CBOR[] memory _subitems = (self.majorType == MAJOR_TYPE_ARRAY
            ? self.readArray()
            : self.readMap()
        );
        // move forward to the first element after inner array or map:
        self = _subitems[_subitems.length - 1];
      } else {
        // move forward to the next element:
        self.skip();
      }
    }
    // return self cursor as extra item at the end of the list,
    // as to optimize recursion when jumping over nested arrays:
    items[len] = self;
  }

  /// Reads the length of the settle CBOR item from a buffer, consuming a different number of bytes depending on the
  /// value of the `additionalInformation` argument.
  function readLength(
      WitnetBuffer.Buffer memory buffer,
      uint8 additionalInformation
    ) 
    internal pure
    returns (uint64)
  {
    if (additionalInformation < 24) {
      return additionalInformation;
    }
    if (additionalInformation == 24) {
      return buffer.readUint8();
    }
    if (additionalInformation == 25) {
      return buffer.readUint16();
    }
    if (additionalInformation == 26) {
      return buffer.readUint32();
    }
    if (additionalInformation == 27) {
      return buffer.readUint64();
    }
    if (additionalInformation == 31) {
      return UINT64_MAX;
    }
    revert InvalidLengthEncoding(additionalInformation);
  }

  /// @notice Read a `CBOR` structure into a native `bool` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as a `bool` value.
  function readBool(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (bool)
  {
    if (cbor.additionalInformation == 20) {
      return false;
    } else if (cbor.additionalInformation == 21) {
      return true;
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `bytes` value.
  /// @param cbor An instance of `CBOR`.
  /// @return output The value represented by the input, as a `bytes` value.   
  function readBytes(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_BYTES)
    returns (bytes memory output)
  {
    cbor.len = readLength(
      cbor.buffer,
      cbor.additionalInformation
    );
    if (cbor.len == UINT32_MAX) {
      // These checks look repetitive but the equivalent loop would be more expensive.
      uint32 length = uint32(_readIndefiniteStringLength(
        cbor.buffer,
        cbor.majorType
      ));
      if (length < UINT32_MAX) {
        output = abi.encodePacked(cbor.buffer.read(length));
        length = uint32(_readIndefiniteStringLength(
          cbor.buffer,
          cbor.majorType
        ));
        if (length < UINT32_MAX) {
          output = abi.encodePacked(
            output,
            cbor.buffer.read(length)
          );
        }
      }
    } else {
      return cbor.buffer.read(uint32(cbor.len));
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed16` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`
  /// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int128` value.
  function readFloat16(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int32)
  {
    if (cbor.additionalInformation == 25) {
      return cbor.buffer.readFloat16();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed32` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `fixed64`
  /// use cases. In other words, the output of this method is 10^9 times the actual value, encoded into an `int`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int` value.
  function readFloat32(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int)
  {
    if (cbor.additionalInformation == 26) {
      return cbor.buffer.readFloat32();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed64` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `fixed64`
  /// use cases. In other words, the output of this method is 10^15 times the actual value, encoded into an `int`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int` value.
  function readFloat64(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int)
  {
    if (cbor.additionalInformation == 27) {
      return cbor.buffer.readFloat64();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int128[]` value whose inner values follow the same convention 
  /// @notice as explained in `decodeFixed16`.
  /// @param cbor An instance of `CBOR`.
  function readFloat16Array(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (int32[] memory values)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      values = new int32[](length);
      for (uint64 i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        values[i] = readFloat16(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int128` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int128` value.
  function readInt(CBOR memory cbor)
    internal pure
    returns (int)
  {
    if (cbor.majorType == 1) {
      uint64 _value = readLength(
        cbor.buffer,
        cbor.additionalInformation
      );
      return int(-1) - int(uint(_value));
    } else if (cbor.majorType == 0) {
      // Any `uint64` can be safely casted to `int128`, so this method supports majorType 1 as well so as to have offer
      // a uniform API for positive and negative numbers
      return int(readUint(cbor));
    }
    else {
      revert UnexpectedMajorType(cbor.majorType, 1);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int[]` value.
  /// @param cbor instance of `CBOR`.
  /// @return array The value represented by the input, as an `int[]` value.
  function readIntArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (int[] memory array)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      array = new int[](length);
      for (uint i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        array[i] = readInt(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `string` value.
  /// @param cbor An instance of `CBOR`.
  /// @return text The value represented by the input, as a `string` value.
  function readString(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_STRING)
    returns (string memory text)
  {
    cbor.len = readLength(cbor.buffer, cbor.additionalInformation);
    if (cbor.len == UINT64_MAX) {
      bool _done;
      while (!_done) {
        uint64 length = _readIndefiniteStringLength(
          cbor.buffer,
          cbor.majorType
        );
        if (length < UINT64_MAX) {
          text = string(abi.encodePacked(
            text,
            cbor.buffer.readText(length / 4)
          ));
        } else {
          _done = true;
        }
      }
    } else {
      return string(cbor.buffer.readText(cbor.len));
    }
  }

  /// @notice Decode a `CBOR` structure into a native `string[]` value.
  /// @param cbor An instance of `CBOR`.
  /// @return strings The value represented by the input, as an `string[]` value.
  function readStringArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (string[] memory strings)
  {
    uint length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      strings = new string[](length);
      for (uint i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        strings[i] = readString(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `uint64` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `uint64` value.
  function readUint(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_INT)
    returns (uint)
  {
    return readLength(
      cbor.buffer,
      cbor.additionalInformation
    );
  }

  /// @notice Decode a `CBOR` structure into a native `uint64[]` value.
  /// @param cbor An instance of `CBOR`.
  /// @return values The value represented by the input, as an `uint64[]` value.
  function readUintArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (uint[] memory values)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      values = new uint[](length);
      for (uint ix = 0; ix < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        values[ix] = readUint(item);
        unchecked {
          ix ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }  

  /// Read the length of a CBOR indifinite-length item (arrays, maps, byte strings and text) from a buffer, consuming
  /// as many bytes as specified by the first byte.
  function _readIndefiniteStringLength(
      WitnetBuffer.Buffer memory buffer,
      uint8 majorType
    )
    private pure
    returns (uint64 len)
  {
    uint8 initialByte = buffer.readUint8();
    if (initialByte == 0xff) {
      return UINT64_MAX;
    }
    len = readLength(
      buffer,
      initialByte & 0x1f
    );
    if (len >= UINT64_MAX) {
      revert InvalidLengthEncoding(len);
    } else if (majorType != (initialByte >> 5)) {
      revert UnexpectedMajorType((initialByte >> 5), majorType);
    }
  }
 
}
          

/WitnetBuffer.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

/// @title A convenient wrapper around the `bytes memory` type that exposes a buffer-like interface
/// @notice The buffer has an inner cursor that tracks the final offset of every read, i.e. any subsequent read will
/// start with the byte that goes right after the last one in the previous read.
/// @dev `uint32` is used here for `cursor` because `uint16` would only enable seeking up to 8KB, which could in some
/// theoretical use cases be exceeded. Conversely, `uint32` supports up to 512MB, which cannot credibly be exceeded.
/// @author The Witnet Foundation.
library WitnetBuffer {

  error EmptyBuffer();
  error IndexOutOfBounds(uint index, uint range);
  error MissingArgs(uint expected, uint given);

  /// Iterable bytes buffer.
  struct Buffer {
      bytes data;
      uint cursor;
  }

  // Ensures we access an existing index in an array
  modifier withinRange(uint index, uint _range) {
    if (index > _range) {
      revert IndexOutOfBounds(index, _range);
    }
    _;
  }

  /// @notice Concatenate undefinite number of bytes chunks.
  /// @dev Faster than looping on `abi.encodePacked(output, _buffs[ix])`.
  function concat(bytes[] memory _buffs)
    internal pure
    returns (bytes memory output)
  {
    unchecked {
      uint destinationPointer;
      uint destinationLength;
      assembly {
        // get safe scratch location
        output := mload(0x40)
        // set starting destination pointer
        destinationPointer := add(output, 32)
      }      
      for (uint ix = 1; ix <= _buffs.length; ix ++) {  
        uint source;
        uint sourceLength;
        uint sourcePointer;        
        assembly {
          // load source length pointer
          source := mload(add(_buffs, mul(ix, 32)))
          // load source length
          sourceLength := mload(source)
          // sets source memory pointer
          sourcePointer := add(source, 32)
        }
        memcpy(
          destinationPointer,
          sourcePointer,
          sourceLength
        );
        assembly {          
          // increase total destination length
          destinationLength := add(destinationLength, sourceLength)
          // sets destination memory pointer
          destinationPointer := add(destinationPointer, sourceLength)
        }
      }
      assembly {
        // protect output bytes
        mstore(output, destinationLength)
        // set final output length
        mstore(0x40, add(mload(0x40), add(destinationLength, 32)))
      }
    }
  }

  function fork(WitnetBuffer.Buffer memory buffer)
    internal pure
    returns (WitnetBuffer.Buffer memory)
  {
    return Buffer(
      buffer.data,
      buffer.cursor
    );
  }

  function mutate(
      WitnetBuffer.Buffer memory buffer,
      uint length,
      bytes memory pokes
    )
    internal pure
    withinRange(length, buffer.data.length - buffer.cursor + 1)
  {
    bytes[] memory parts = new bytes[](3);
    parts[0] = peek(
      buffer,
      0,
      buffer.cursor
    );
    parts[1] = pokes;
    parts[2] = peek(
      buffer,
      buffer.cursor + length,
      buffer.data.length - buffer.cursor - length
    );
    buffer.data = concat(parts);
  }

  /// @notice Read and consume the next byte from the buffer.
  /// @param buffer An instance of `Buffer`.
  /// @return The next byte in the buffer counting from the cursor position.
  function next(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor, buffer.data.length)
    returns (bytes1)
  {
    // Return the byte at the position marked by the cursor and advance the cursor all at once
    return buffer.data[buffer.cursor ++];
  }

  function peek(
      WitnetBuffer.Buffer memory buffer,
      uint offset,
      uint length
    )
    internal pure
    withinRange(offset + length, buffer.data.length)
    returns (bytes memory)
  {
    bytes memory data = buffer.data;
    bytes memory peeks = new bytes(length);
    uint destinationPointer;
    uint sourcePointer;
    assembly {
      destinationPointer := add(peeks, 32)
      sourcePointer := add(add(data, 32), offset)
    }
    memcpy(
      destinationPointer,
      sourcePointer,
      length
    );
    return peeks;
  }

  // @notice Extract bytes array from buffer starting from current cursor.
  /// @param buffer An instance of `Buffer`.
  /// @param length How many bytes to peek from the Buffer.
  // solium-disable-next-line security/no-assign-params
  function peek(
      WitnetBuffer.Buffer memory buffer,
      uint length
    )
    internal pure
    withinRange(length, buffer.data.length - buffer.cursor)
    returns (bytes memory)
  {
    return peek(
      buffer,
      buffer.cursor,
      length
    );
  }

  /// @notice Read and consume a certain amount of bytes from the buffer.
  /// @param buffer An instance of `Buffer`.
  /// @param length How many bytes to read and consume from the buffer.
  /// @return output A `bytes memory` containing the first `length` bytes from the buffer, counting from the cursor position.
  function read(Buffer memory buffer, uint length)
    internal pure
    withinRange(buffer.cursor + length, buffer.data.length)
    returns (bytes memory output)
  {
    // Create a new `bytes memory destination` value
    output = new bytes(length);
    // Early return in case that bytes length is 0
    if (length > 0) {
      bytes memory input = buffer.data;
      uint offset = buffer.cursor;
      // Get raw pointers for source and destination
      uint sourcePointer;
      uint destinationPointer;
      assembly {
        sourcePointer := add(add(input, 32), offset)
        destinationPointer := add(output, 32)
      }
      // Copy `length` bytes from source to destination
      memcpy(
        destinationPointer,
        sourcePointer,
        length
      );
      // Move the cursor forward by `length` bytes
      seek(
        buffer,
        length,
        true
      );
    }
  }
  
  /// @notice Read and consume the next 2 bytes from the buffer as an IEEE 754-2008 floating point number enclosed in an
  /// `int32`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `float16`
  /// use cases. In other words, the integer output of this method is 10,000 times the actual value. The input bytes are
  /// expected to follow the 16-bit base-2 format (a.k.a. `binary16`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int32` value of the next 4 bytes in the buffer counting from the cursor position.
  function readFloat16(Buffer memory buffer)
    internal pure
    returns (int32 result)
  {
    uint32 value = readUint16(buffer);
    // Get bit at position 0
    uint32 sign = value & 0x8000;
    // Get bits 1 to 5, then normalize to the [-15, 16] range so as to counterweight the IEEE 754 exponent bias
    int32 exponent = (int32(value & 0x7c00) >> 10) - 15;
    // Get bits 6 to 15
    int32 fraction = int32(value & 0x03ff);
    // Add 2^10 to the fraction if exponent is not -15
    if (exponent != -15) {
      fraction |= 0x400;
    } else if (exponent == 16) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat16: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 1024)`
    if (exponent >= 0) {
      result = int32(int(
        int(1 << uint256(int256(exponent)))
          * 10000
          * fraction
      ) >> 10);
    } else {
      result = int32(int(
        int(fraction)
          * 10000
          / int(1 << uint(int(- exponent)))
      ) >> 10);
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  /// @notice Consume the next 4 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `float32`
  /// use cases. In other words, the integer output of this method is 10^9 times the actual value. The input bytes are
  /// expected to follow the 64-bit base-2 format (a.k.a. `binary32`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
  function readFloat32(Buffer memory buffer)
    internal pure
    returns (int result)
  {
    uint value = readUint32(buffer);
    // Get bit at position 0
    uint sign = value & 0x80000000;
    // Get bits 1 to 8, then normalize to the [-127, 128] range so as to counterweight the IEEE 754 exponent bias
    int exponent = (int(value & 0x7f800000) >> 23) - 127;
    // Get bits 9 to 31
    int fraction = int(value & 0x007fffff);
    // Add 2^23 to the fraction if exponent is not -127
    if (exponent != -127) {
      fraction |= 0x800000;
    } else if (exponent == 128) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat32: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 2^23)`
    if (exponent >= 0) {
      result = (
        int(1 << uint(exponent))
          * (10 ** 9)
          * fraction
      ) >> 23;
    } else {
      result = (
        fraction 
          * (10 ** 9)
          / int(1 << uint(-exponent)) 
      ) >> 23;
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  /// @notice Consume the next 8 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `float64`
  /// use cases. In other words, the integer output of this method is 10^15 times the actual value. The input bytes are
  /// expected to follow the 64-bit base-2 format (a.k.a. `binary64`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
  function readFloat64(Buffer memory buffer)
    internal pure
    returns (int result)
  {
    uint value = readUint64(buffer);
    // Get bit at position 0
    uint sign = value & 0x8000000000000000;
    // Get bits 1 to 12, then normalize to the [-1023, 1024] range so as to counterweight the IEEE 754 exponent bias
    int exponent = (int(value & 0x7ff0000000000000) >> 52) - 1023;
    // Get bits 6 to 15
    int fraction = int(value & 0x000fffffffffffff);
    // Add 2^52 to the fraction if exponent is not -1023
    if (exponent != -1023) {
      fraction |= 0x10000000000000;
    } else if (exponent == 1024) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat64: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 1024)`
    if (exponent >= 0) {
      result = (
        int(1 << uint(exponent))
          * (10 ** 15)
          * fraction
      ) >> 52;
    } else {
      result = (
        fraction 
          * (10 ** 15)
          / int(1 << uint(-exponent)) 
      ) >> 52;
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  // Read a text string of a given length from a buffer. Returns a `bytes memory` value for the sake of genericness,
  /// but it can be easily casted into a string with `string(result)`.
  // solium-disable-next-line security/no-assign-params
  function readText(
      WitnetBuffer.Buffer memory buffer,
      uint64 length
    )
    internal pure
    returns (bytes memory text)
  {
    text = new bytes(length);
    unchecked {
      for (uint64 index = 0; index < length; index ++) {
        uint8 char = readUint8(buffer);
        if (char & 0x80 != 0) {
          if (char < 0xe0) {
            char = (char & 0x1f) << 6
              | (readUint8(buffer) & 0x3f);
            length -= 1;
          } else if (char < 0xf0) {
            char  = (char & 0x0f) << 12
              | (readUint8(buffer) & 0x3f) << 6
              | (readUint8(buffer) & 0x3f);
            length -= 2;
          } else {
            char = (char & 0x0f) << 18
              | (readUint8(buffer) & 0x3f) << 12
              | (readUint8(buffer) & 0x3f) << 6  
              | (readUint8(buffer) & 0x3f);
            length -= 3;
          }
        }
        text[index] = bytes1(char);
      }
      // Adjust text to actual length:
      assembly {
        mstore(text, length)
      }
    }
  }

  /// @notice Read and consume the next byte from the buffer as an `uint8`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint8` value of the next byte in the buffer counting from the cursor position.
  function readUint8(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor, buffer.data.length)
    returns (uint8 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 1), offset))
    }
    buffer.cursor ++;
  }

  /// @notice Read and consume the next 2 bytes from the buffer as an `uint16`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint16` value of the next 2 bytes in the buffer counting from the cursor position.
  function readUint16(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 2, buffer.data.length)
    returns (uint16 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 2), offset))
    }
    buffer.cursor += 2;
  }

  /// @notice Read and consume the next 4 bytes from the buffer as an `uint32`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint32` value of the next 4 bytes in the buffer counting from the cursor position.
  function readUint32(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 4, buffer.data.length)
    returns (uint32 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 4), offset))
    }
    buffer.cursor += 4;
  }

  /// @notice Read and consume the next 8 bytes from the buffer as an `uint64`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint64` value of the next 8 bytes in the buffer counting from the cursor position.
  function readUint64(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 8, buffer.data.length)
    returns (uint64 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 8), offset))
    }
    buffer.cursor += 8;
  }

  /// @notice Read and consume the next 16 bytes from the buffer as an `uint128`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint128` value of the next 16 bytes in the buffer counting from the cursor position.
  function readUint128(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 16, buffer.data.length)
    returns (uint128 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 16), offset))
    }
    buffer.cursor += 16;
  }

  /// @notice Read and consume the next 32 bytes from the buffer as an `uint256`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint256` value of the next 32 bytes in the buffer counting from the cursor position.
  function readUint256(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 32, buffer.data.length)
    returns (uint256 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 32), offset))
    }
    buffer.cursor += 32;
  }

  /// @notice Count number of required parameters for given bytes arrays
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input Bytes array containing strings.
  /// @param count Highest wildcard index found, plus 1.
  function argsCountOf(bytes memory input)
    internal pure
    returns (uint8 count)
  {
    if (input.length < 3) {
      return 0;
    }
    unchecked {
      uint ix = 0; 
      uint length = input.length - 2;
      for (; ix < length; ) {
        if (
          input[ix] == bytes1("\\")
            && input[ix + 2] == bytes1("\\")
            && input[ix + 1] >= bytes1("0")
            && input[ix + 1] <= bytes1("9")
        ) {
          uint8 ax = uint8(uint8(input[ix + 1]) - uint8(bytes1("0")) + 1);
          if (ax > count) {
            count = ax;
          }
          ix += 3;
        } else {
          ix ++;
        }
      }
    }
  }

  /// @notice Replace bytecode indexed wildcards by correspondent substrings.
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input Bytes array containing strings.
  /// @param args Array of substring values for replacing indexed wildcards.
  /// @return output Resulting bytes array after replacing all wildcards.
  /// @return hits Total number of replaced wildcards.
  function replace(bytes memory input, string[] memory args)
    internal pure
    returns (bytes memory output, uint hits)
  {
    uint ix = 0; uint lix = 0;
    uint inputLength;
    uint inputPointer;
    uint outputLength;
    uint outputPointer;    
    uint source;
    uint sourceLength;
    uint sourcePointer;

    if (input.length < 3) {
      return (input, 0);
    }
    
    assembly {
      // set starting input pointer
      inputPointer := add(input, 32)
      // get safe output location
      output := mload(0x40)
      // set starting output pointer
      outputPointer := add(output, 32)
    }         

    unchecked {
      uint length = input.length - 2;
      for (; ix < length; ) {
        if (
          input[ix] == bytes1("\\")
            && input[ix + 2] == bytes1("\\")
            && input[ix + 1] >= bytes1("0")
            && input[ix + 1] <= bytes1("9")
        ) {
          inputLength = (ix - lix);
          if (ix > lix) {
            memcpy(
              outputPointer,
              inputPointer,
              inputLength
            );
            inputPointer += inputLength + 3;
            outputPointer += inputLength;
          } else {
            inputPointer += 3;
          }
          uint ax = uint(uint8(input[ix + 1]) - uint8(bytes1("0")));
          if (ax >= args.length) {
            revert MissingArgs(ax + 1, args.length);
          }
          assembly {
            source := mload(add(args, mul(32, add(ax, 1))))
            sourceLength := mload(source)
            sourcePointer := add(source, 32)      
          }        
          memcpy(
            outputPointer,
            sourcePointer,
            sourceLength
          );
          outputLength += inputLength + sourceLength;
          outputPointer += sourceLength;
          ix += 3;
          lix = ix;
          hits ++;
        } else {
          ix ++;
        }
      }
      ix = input.length;    
    }
    if (outputLength > 0) {
      if (ix > lix ) {
        memcpy(
          outputPointer,
          inputPointer,
          ix - lix
        );
        outputLength += (ix - lix);
      }
      assembly {
        // set final output length
        mstore(output, outputLength)
        // protect output bytes
        mstore(0x40, add(mload(0x40), add(outputLength, 32)))
      }
    }
    else {
      return (input, 0);
    }
  }

  /// @notice Replace string indexed wildcards by correspondent substrings.
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input String potentially containing wildcards.
  /// @param args Array of substring values for replacing indexed wildcards.
  /// @return output Resulting string after replacing all wildcards.
  function replace(string memory input, string[] memory args)
    internal pure
    returns (string memory)
  {
    (bytes memory _outputBytes, ) = replace(bytes(input), args);
    return string(_outputBytes);
  }

  /// @notice Move the inner cursor of the buffer to a relative or absolute position.
  /// @param buffer An instance of `Buffer`.
  /// @param offset How many bytes to move the cursor forward.
  /// @param relative Whether to count `offset` from the last position of the cursor (`true`) or the beginning of the
  /// buffer (`true`).
  /// @return The final position of the cursor (will equal `offset` if `relative` is `false`).
  // solium-disable-next-line security/no-assign-params
  function seek(
      Buffer memory buffer,
      uint offset,
      bool relative
    )
    internal pure
    withinRange(offset, buffer.data.length)
    returns (uint)
  {
    // Deal with relative offsets
    if (relative) {
      offset += buffer.cursor;
    }
    buffer.cursor = offset;
    return offset;
  }

  /// @notice Move the inner cursor a number of bytes forward.
  /// @dev This is a simple wrapper around the relative offset case of `seek()`.
  /// @param buffer An instance of `Buffer`.
  /// @param relativeOffset How many bytes to move the cursor forward.
  /// @return The final position of the cursor.
  function seek(
      Buffer memory buffer,
      uint relativeOffset
    )
    internal pure
    returns (uint)
  {
    return seek(
      buffer,
      relativeOffset,
      true
    );
  }

  /// @notice Copy bytes from one memory address into another.
  /// @dev This function was borrowed from Nick Johnson's `solidity-stringutils` lib, and reproduced here under the terms
  /// of [Apache License 2.0](https://github.com/Arachnid/solidity-stringutils/blob/master/LICENSE).
  /// @param dest Address of the destination memory.
  /// @param src Address to the source memory.
  /// @param len How many bytes to copy.
  // solium-disable-next-line security/no-assign-params
  function memcpy(
      uint dest,
      uint src,
      uint len
    )
    private pure
  {
    unchecked {
      // Copy word-length chunks while possible
      for (; len >= 32; len -= 32) {
        assembly {
          mstore(dest, mload(src))
        }
        dest += 32;
        src += 32;
      }
      if (len > 0) {
        // Copy remaining bytes
        uint _mask = 256 ** (32 - len) - 1;
        assembly {
          let srcpart := and(mload(src), not(_mask))
          let destpart := and(mload(dest), _mask)
          mstore(dest, or(destpart, srcpart))
        }
      }
    }
  }

}
          

/Witnet.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./WitnetCBOR.sol";

library Witnet {

    using WitnetBuffer for WitnetBuffer.Buffer;
    using WitnetCBOR for WitnetCBOR.CBOR;
    using WitnetCBOR for WitnetCBOR.CBOR[];

    /// Struct containing both request and response data related to every query posted to the Witnet Request Board
    struct Query {
        Request request;
        Response response;
        address from;      // Address from which the request was posted.
    }

    /// Possible status of a Witnet query.
    enum QueryStatus {
        Unknown,
        Posted,
        Reported,
        Deleted
    }

    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct Request {
        address addr;       // Address of the (deprecated) IWitnetRequest contract containing Witnet data request raw bytecode.
        bytes32 slaHash;    // Radon SLA hash of the Witnet data request.
        bytes32 radHash;    // Radon radHash of the Witnet data request.
        uint256 gasprice;   // Minimum gas price the DR resolver should pay on the solving tx.
        uint256 reward;     // Escrowed reward to be paid to the DR resolver.
    }

    /// Data kept in EVM-storage containing the Witnet-provided response metadata and CBOR-encoded result.
    struct Response {
        address reporter;       // Address from which the result was reported.
        uint256 timestamp;      // Timestamp of the Witnet-provided result.
        bytes32 drTxHash;       // Hash of the Witnet transaction that solved the queried Data Request.
        bytes   cborBytes;      // Witnet-provided result CBOR-bytes to the queried Data Request.
    }

    /// Data struct containing the Witnet-provided result to a Data Request.
    struct Result {
        bool success;           // Flag stating whether the request could get solved successfully, or not.
        WitnetCBOR.CBOR value;  // Resulting value, in CBOR-serialized bytes.
    }

    /// Final query's result status from a requester's point of view.
    enum ResultStatus {
        Void,
        Awaiting,
        Ready,
        Error
    }

    /// Data struct describing an error when trying to fetch a Witnet-provided result to a Data Request.
    struct ResultError {
        ResultErrorCodes code;
        string reason;
    }

    enum ResultErrorCodes {
        /// 0x00: Unknown error. Something went really bad!
        Unknown, 
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Source-specific format error sub-codes ============================================================================
        /// 0x01: At least one of the source scripts is not a valid CBOR-encoded value.
        SourceScriptNotCBOR, 
        /// 0x02: The CBOR value decoded from a source script is not an Array.
        SourceScriptNotArray,
        /// 0x03: The Array value decoded form a source script is not a valid Data Request.
        SourceScriptNotRADON,
        /// 0x04: The request body of at least one data source was not properly formated.
        SourceRequestBody,
        /// 0x05: The request headers of at least one data source was not properly formated.
        SourceRequestHeaders,
        /// 0x06: The request URL of at least one data source was not properly formated.
        SourceRequestURL,
        /// Unallocated
        SourceFormat0x07, SourceFormat0x08, SourceFormat0x09, SourceFormat0x0A, SourceFormat0x0B, SourceFormat0x0C,
        SourceFormat0x0D, SourceFormat0x0E, SourceFormat0x0F, 
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Complexity error sub-codes ========================================================================================
        /// 0x10: The request contains too many sources.
        RequestTooManySources,
        /// 0x11: The script contains too many calls.
        ScriptTooManyCalls,
        /// Unallocated
        Complexity0x12, Complexity0x13, Complexity0x14, Complexity0x15, Complexity0x16, Complexity0x17, Complexity0x18,
        Complexity0x19, Complexity0x1A, Complexity0x1B, Complexity0x1C, Complexity0x1D, Complexity0x1E, Complexity0x1F,

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Lack of support error sub-codes ===================================================================================
        /// 0x20: Some Radon operator code was found that is not supported (1+ args).
        UnsupportedOperator,
        /// 0x21: Some Radon filter opcode is not currently supported (1+ args).
        UnsupportedFilter,
        /// 0x22: Some Radon request type is not currently supported (1+ args).
        UnsupportedHashFunction,
        /// 0x23: Some Radon reducer opcode is not currently supported (1+ args)
        UnsupportedReducer,
        /// 0x24: Some Radon hash function is not currently supported (1+ args).
        UnsupportedRequestType, 
        /// 0x25: Some Radon encoding function is not currently supported (1+ args).
        UnsupportedEncodingFunction,
        /// Unallocated
        Operator0x26, Operator0x27, 
        /// 0x28: Wrong number (or type) of arguments were passed to some Radon operator.
        WrongArguments,
        /// Unallocated
        Operator0x29, Operator0x2A, Operator0x2B, Operator0x2C, Operator0x2D, Operator0x2E, Operator0x2F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Retrieve-specific circumstantial error sub-codes ================================================================================
        /// 0x30: A majority of data sources returned an HTTP status code other than 200 (1+ args):
        HttpErrors,
        /// 0x31: A majority of data sources timed out:
        RetrievalsTimeout,
        /// Unallocated
        RetrieveCircumstance0x32, RetrieveCircumstance0x33, RetrieveCircumstance0x34, RetrieveCircumstance0x35,
        RetrieveCircumstance0x36, RetrieveCircumstance0x37, RetrieveCircumstance0x38, RetrieveCircumstance0x39,
        RetrieveCircumstance0x3A, RetrieveCircumstance0x3B, RetrieveCircumstance0x3C, RetrieveCircumstance0x3D,
        RetrieveCircumstance0x3E, RetrieveCircumstance0x3F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Scripting-specific runtime error sub-code =========================================================================
        /// 0x40: Math operator caused an underflow.
        MathUnderflow,
        /// 0x41: Math operator caused an overflow.
        MathOverflow,
        /// 0x42: Math operator tried to divide by zero.
        MathDivisionByZero,            
        /// 0x43:Wrong input to subscript call.
        WrongSubscriptInput,
        /// 0x44: Value cannot be extracted from input binary buffer.
        BufferIsNotValue,
        /// 0x45: Value cannot be decoded from expected type.
        Decode,
        /// 0x46: Unexpected empty array.
        EmptyArray,
        /// 0x47: Value cannot be encoded to expected type.
        Encode,
        /// 0x48: Failed to filter input values (1+ args).
        Filter,
        /// 0x49: Failed to hash input value.
        Hash,
        /// 0x4A: Mismatching array ranks.
        MismatchingArrays,
        /// 0x4B: Failed to process non-homogenous array.
        NonHomegeneousArray,
        /// 0x4C: Failed to parse syntax of some input value, or argument.
        Parse,
        /// 0x4E: Parsing logic limits were exceeded.
        ParseOverflow,
        /// 0x4F: Unallocated
        ScriptError0x4F,
    
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Actual first-order result error codes =============================================================================
        /// 0x50: Not enough reveals were received in due time:
        InsufficientReveals,
        /// 0x51: No actual reveal majority was reached on tally stage:
        InsufficientMajority,
        /// 0x52: Not enough commits were received before tally stage:
        InsufficientCommits,
        /// 0x53: Generic error during tally execution (to be deprecated after WIP #0028)
        TallyExecution,
        /// 0x54: A majority of data sources could either be temporarily unresponsive or failing to report the requested data:
        CircumstantialFailure,
        /// 0x55: At least one data source is inconsistent when queried through multiple transports at once:
        InconsistentSources,
        /// 0x56: Any one of the (multiple) Retrieve, Aggregate or Tally scripts were badly formated:
        MalformedDataRequest,
        /// 0x57: Values returned from a majority of data sources don't match the expected schema:
        MalformedResponses,
        /// Unallocated:    
        OtherError0x58, OtherError0x59, OtherError0x5A, OtherError0x5B, OtherError0x5C, OtherError0x5D, OtherError0x5E, 
        /// 0x5F: Size of serialized tally result exceeds allowance:
        OversizedTallyResult,

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Inter-stage runtime error sub-codes ===============================================================================
        /// 0x60: Data aggregation reveals could not get decoded on the tally stage:
        MalformedReveals,
        /// 0x61: The result to data aggregation could not get encoded:
        EncodeReveals,  
        /// 0x62: A mode tie ocurred when calculating some mode value on the aggregation or the tally stage:
        ModeTie, 
        /// Unallocated:
        OtherError0x63, OtherError0x64, OtherError0x65, OtherError0x66, OtherError0x67, OtherError0x68, OtherError0x69, 
        OtherError0x6A, OtherError0x6B, OtherError0x6C, OtherError0x6D, OtherError0x6E, OtherError0x6F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Runtime access error sub-codes ====================================================================================
        /// 0x70: Tried to access a value from an array using an index that is out of bounds (1+ args):
        ArrayIndexOutOfBounds,
        /// 0x71: Tried to access a value from a map using a key that does not exist (1+ args):
        MapKeyNotFound,
        /// 0X72: Tried to extract value from a map using a JSON Path that returns no values (+1 args):
        JsonPathNotFound,
        /// Unallocated:
        OtherError0x73, OtherError0x74, OtherError0x75, OtherError0x76, OtherError0x77, OtherError0x78, 
        OtherError0x79, OtherError0x7A, OtherError0x7B, OtherError0x7C, OtherError0x7D, OtherError0x7E, OtherError0x7F, 
        OtherError0x80, OtherError0x81, OtherError0x82, OtherError0x83, OtherError0x84, OtherError0x85, OtherError0x86, 
        OtherError0x87, OtherError0x88, OtherError0x89, OtherError0x8A, OtherError0x8B, OtherError0x8C, OtherError0x8D, 
        OtherError0x8E, OtherError0x8F, OtherError0x90, OtherError0x91, OtherError0x92, OtherError0x93, OtherError0x94, 
        OtherError0x95, OtherError0x96, OtherError0x97, OtherError0x98, OtherError0x99, OtherError0x9A, OtherError0x9B,
        OtherError0x9C, OtherError0x9D, OtherError0x9E, OtherError0x9F, OtherError0xA0, OtherError0xA1, OtherError0xA2, 
        OtherError0xA3, OtherError0xA4, OtherError0xA5, OtherError0xA6, OtherError0xA7, OtherError0xA8, OtherError0xA9, 
        OtherError0xAA, OtherError0xAB, OtherError0xAC, OtherError0xAD, OtherError0xAE, OtherError0xAF, OtherError0xB0,
        OtherError0xB1, OtherError0xB2, OtherError0xB3, OtherError0xB4, OtherError0xB5, OtherError0xB6, OtherError0xB7,
        OtherError0xB8, OtherError0xB9, OtherError0xBA, OtherError0xBB, OtherError0xBC, OtherError0xBD, OtherError0xBE,
        OtherError0xBF, OtherError0xC0, OtherError0xC1, OtherError0xC2, OtherError0xC3, OtherError0xC4, OtherError0xC5,
        OtherError0xC6, OtherError0xC7, OtherError0xC8, OtherError0xC9, OtherError0xCA, OtherError0xCB, OtherError0xCC,
        OtherError0xCD, OtherError0xCE, OtherError0xCF, OtherError0xD0, OtherError0xD1, OtherError0xD2, OtherError0xD3,
        OtherError0xD4, OtherError0xD5, OtherError0xD6, OtherError0xD7, OtherError0xD8, OtherError0xD9, OtherError0xDA,
        OtherError0xDB, OtherError0xDC, OtherError0xDD, OtherError0xDE, OtherError0xDF,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Inter-client generic error codes ==================================================================================
        /// Data requests that cannot be relayed into the Witnet blockchain should be reported
        /// with one of these errors. 
        /// 0xE0: Requests that cannot be parsed must always get this error as their result.
        BridgeMalformedDataRequest,
        /// 0xE1: Witnesses exceeds 100
        BridgePoorIncentives,
        /// 0xE2: The request is rejected on the grounds that it may cause the submitter to spend or stake an
        /// amount of value that is unjustifiably high when compared with the reward they will be getting
        BridgeOversizedTallyResult,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Unallocated =======================================================================================================
        OtherError0xE3, OtherError0xE4, OtherError0xE5, OtherError0xE6, OtherError0xE7, OtherError0xE8, OtherError0xE9,
        OtherError0xEA, OtherError0xEB, OtherError0xEC, OtherError0xED, OtherError0xEE, OtherError0xEF, OtherError0xF0,
        OtherError0xF1, OtherError0xF2, OtherError0xF3, OtherError0xF4, OtherError0xF5, OtherError0xF6, OtherError0xF7,
        OtherError0xF8, OtherError0xF9, OtherError0xFA, OtherError0xFB, OtherError0xFC, OtherError0xFD, OtherError0xFE,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// 0xFF: Some tally error is not intercepted but it should (0+ args)
        UnhandledIntercept
    }

    function isCircumstantial(ResultErrorCodes self) internal pure returns (bool) {
        return (self == ResultErrorCodes.CircumstantialFailure);
    }

    function lackOfConsensus(ResultErrorCodes self) internal pure returns (bool) {
        return (
            self == ResultErrorCodes.InsufficientCommits
                || self == ResultErrorCodes.InsufficientMajority
                || self == ResultErrorCodes.InsufficientReveals
        );
    }

    function isRetriable(ResultErrorCodes self) internal pure returns (bool) {
        return (
            lackOfConsensus(self)
                || isCircumstantial(self)
                || poorIncentives(self)
        );
    }

    function poorIncentives(ResultErrorCodes self) internal pure returns (bool) {
        return (
            self == ResultErrorCodes.OversizedTallyResult
                || self == ResultErrorCodes.InsufficientCommits
                || self == ResultErrorCodes.BridgePoorIncentives
                || self == ResultErrorCodes.BridgeOversizedTallyResult
        );
    }
    

    /// Possible Radon data request methods that can be used within a Radon Retrieval. 
    enum RadonDataRequestMethods {
        /* 0 */ Unknown,
        /* 1 */ HttpGet,
        /* 2 */ RNG,
        /* 3 */ HttpPost,
        /* 4 */ HttpHead
    }

    /// Possible types either processed by Witnet Radon Scripts or included within results to Witnet Data Requests.
    enum RadonDataTypes {
        /* 0x00 */ Any, 
        /* 0x01 */ Array,
        /* 0x02 */ Bool,
        /* 0x03 */ Bytes,
        /* 0x04 */ Integer,
        /* 0x05 */ Float,
        /* 0x06 */ Map,
        /* 0x07 */ String,
        Unused0x08, Unused0x09, Unused0x0A, Unused0x0B,
        Unused0x0C, Unused0x0D, Unused0x0E, Unused0x0F,
        /* 0x10 */ Same,
        /* 0x11 */ Inner,
        /* 0x12 */ Match,
        /* 0x13 */ Subscript
    }

    /// Structure defining some data filtering that can be applied at the Aggregation or the Tally stages
    /// within a Witnet Data Request resolution workflow.
    struct RadonFilter {
        RadonFilterOpcodes opcode;
        bytes args;
    }

    /// Filtering methods currently supported on the Witnet blockchain. 
    enum RadonFilterOpcodes {
        /* 0x00 */ Reserved0x00, //GreaterThan,
        /* 0x01 */ Reserved0x01, //LessThan,
        /* 0x02 */ Reserved0x02, //Equals,
        /* 0x03 */ Reserved0x03, //AbsoluteDeviation,
        /* 0x04 */ Reserved0x04, //RelativeDeviation
        /* 0x05 */ StandardDeviation,
        /* 0x06 */ Reserved0x06, //Top,
        /* 0x07 */ Reserved0x07, //Bottom,
        /* 0x08 */ Mode,
        /* 0x09 */ Reserved0x09  //LessOrEqualThan
    }

    /// Structure defining the array of filters and reducting function to be applied at either the Aggregation
    /// or the Tally stages within a Witnet Data Request resolution workflow.
    struct RadonReducer {
        RadonReducerOpcodes opcode;
        RadonFilter[] filters;
        bytes script;
    }

    /// Reducting functions currently supported on the Witnet blockchain.
    enum RadonReducerOpcodes {
        /* 0x00 */ Reserved0x00, //Minimum,
        /* 0x01 */ Reserved0x01, //Maximum,
        /* 0x02 */ Mode,
        /* 0x03 */ AverageMean,
        /* 0x04 */ Reserved0x04, //AverageMeanWeighted,
        /* 0x05 */ AverageMedian,
        /* 0x06 */ Reserved0x06, //AverageMedianWeighted,
        /* 0x07 */ StandardDeviation,
        /* 0x08 */ Reserved0x08, //AverageDeviation,
        /* 0x09 */ Reserved0x09, //MedianDeviation,
        /* 0x0A */ Reserved0x10, //MaximumDeviation,
        /* 0x0B */ ConcatenateAndHash
    }

    /// Structure containing all the parameters that fully describe a Witnet Radon Retrieval within a Witnet Data Request.
    struct RadonRetrieval {
        uint8 argsCount;
        RadonDataRequestMethods method;
        RadonDataTypes resultDataType;
        string url;
        string body;
        string[2][] headers;
        bytes script;
    }

    /// Structure containing the Retrieve-Attestation-Delivery parts of a Witnet Data Request.
    struct RadonRAD {
        RadonRetrieval[] retrieve;
        RadonReducer aggregate;
        RadonReducer tally;
    }

    /// Structure containing the Service Level Aggreement parameters of a Witnet Data Request.
    struct RadonSLA {
        uint8 numWitnesses;
        uint8 minConsensusPercentage;
        uint64 witnessReward;
        uint64 witnessCollateral;
        uint64 minerCommitRevealFee;
    }


    /// ===============================================================================================================
    /// --- 'Witnet.RadonSLA' helper methods ------------------------------------------------------------------------

    function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b) 
        internal pure returns (bool)
    {
        return (
            a.numWitnesses >= b.numWitnesses
                && a.minConsensusPercentage >= b.minConsensusPercentage
                && a.witnessReward >= b.witnessReward
                && a.witnessCollateral >= b.witnessCollateral
                && a.minerCommitRevealFee >= b.minerCommitRevealFee
        );
    }
    
    function isValid(RadonSLA calldata sla) internal pure returns (bool) {
        return (
            sla.numWitnesses > 0
                && sla.numWitnesses <= 127
                && sla.minConsensusPercentage >= 51
                && sla.witnessReward > 0
                && sla.witnessCollateral > 20 * 10 ** 9
                && sla.witnessCollateral / sla.witnessReward <= 125
        );
    }


    /// ===============================================================================================================
    /// --- 'uint*' helper methods ------------------------------------------------------------------------------------

    /// @notice Convert a `uint8` into a 2 characters long `string` representing its two less significant hexadecimal values.
    function toHexString(uint8 _u)
        internal pure
        returns (string memory)
    {
        bytes memory b2 = new bytes(2);
        uint8 d0 = uint8(_u / 16) + 48;
        uint8 d1 = uint8(_u % 16) + 48;
        if (d0 > 57)
            d0 += 7;
        if (d1 > 57)
            d1 += 7;
        b2[0] = bytes1(d0);
        b2[1] = bytes1(d1);
        return string(b2);
    }

    /// @notice Convert a `uint8` into a 1, 2 or 3 characters long `string` representing its.
    /// three less significant decimal values.
    function toString(uint8 _u)
        internal pure
        returns (string memory)
    {
        if (_u < 10) {
            bytes memory b1 = new bytes(1);
            b1[0] = bytes1(uint8(_u) + 48);
            return string(b1);
        } else if (_u < 100) {
            bytes memory b2 = new bytes(2);
            b2[0] = bytes1(uint8(_u / 10) + 48);
            b2[1] = bytes1(uint8(_u % 10) + 48);
            return string(b2);
        } else {
            bytes memory b3 = new bytes(3);
            b3[0] = bytes1(uint8(_u / 100) + 48);
            b3[1] = bytes1(uint8(_u % 100 / 10) + 48);
            b3[2] = bytes1(uint8(_u % 10) + 48);
            return string(b3);
        }
    }

    /// @notice Convert a `uint` into a string` representing its value.
    function toString(uint v)
        internal pure 
        returns (string memory)
    {
        uint maxlength = 100;
        bytes memory reversed = new bytes(maxlength);
        uint i = 0;
        do {
            uint8 remainder = uint8(v % 10);
            v = v / 10;
            reversed[i ++] = bytes1(48 + remainder);
        } while (v != 0);
        bytes memory buf = new bytes(i);
        for (uint j = 1; j <= i; j ++) {
            buf[j - 1] = reversed[i - j];
        }
        return string(buf);
    }


    /// ===============================================================================================================
    /// --- 'bytes' helper methods ------------------------------------------------------------------------------------

    /// @dev Transform given bytes into a Witnet.Result instance.
    /// @param cborBytes Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory cborBytes)
        internal pure
        returns (Witnet.Result memory)
    {
        WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(cborBytes);
        return _resultFromCborValue(cborValue);
    }

    function toAddress(bytes memory _value) internal pure returns (address) {
        return address(toBytes20(_value));
    }

    function toBytes4(bytes memory _value) internal pure returns (bytes4) {
        return bytes4(toFixedBytes(_value, 4));
    }
    
    function toBytes20(bytes memory _value) internal pure returns (bytes20) {
        return bytes20(toFixedBytes(_value, 20));
    }
    
    function toBytes32(bytes memory _value) internal pure returns (bytes32) {
        return toFixedBytes(_value, 32);
    }

    function toFixedBytes(bytes memory _value, uint8 _numBytes)
        internal pure
        returns (bytes32 _bytes32)
    {
        assert(_numBytes <= 32);
        unchecked {
            uint _len = _value.length > _numBytes ? _numBytes : _value.length;
            for (uint _i = 0; _i < _len; _i ++) {
                _bytes32 |= bytes32(_value[_i] & 0xff) >> (_i * 8);
            }
        }
    }


    /// ===============================================================================================================
    /// --- 'bytes4' helper methods -----------------------------------------------------------------------------------

    function toHexString(bytes4 word) internal pure returns (string memory) {
        return string(abi.encodePacked(
            toHexString(uint8(bytes1(word))),
            toHexString(uint8(bytes1(word << 8))),
            toHexString(uint8(bytes1(word << 16))),
            toHexString(uint8(bytes1(word << 24)))
        ));
    }


    /// ===============================================================================================================
    /// --- 'string' helper methods -----------------------------------------------------------------------------------

    function toLowerCase(string memory str)
        internal pure
        returns (string memory)
    {
        bytes memory lowered = new bytes(bytes(str).length);
        unchecked {
            for (uint i = 0; i < lowered.length; i ++) {
                uint8 char = uint8(bytes(str)[i]);
                if (char >= 65 && char <= 90) {
                    lowered[i] = bytes1(char + 32);
                } else {
                    lowered[i] = bytes1(char);
                }
            }
        }
        return string(lowered);
    }

    /// @notice Converts bytes32 into string.
    function toString(bytes32 _bytes32)
        internal pure
        returns (string memory)
    {
        bytes memory _bytes = new bytes(_toStringLength(_bytes32));
        for (uint _i = 0; _i < _bytes.length;) {
            _bytes[_i] = _bytes32[_i];
            unchecked {
                _i ++;
            }
        }
        return string(_bytes);
    }

    function tryUint(string memory str)
        internal pure
        returns (uint res, bool)
    {
        unchecked {
            for (uint256 i = 0; i < bytes(str).length; i++) {
                if (
                    (uint8(bytes(str)[i]) - 48) < 0
                        || (uint8(bytes(str)[i]) - 48) > 9
                ) {
                    return (0, false);
                }
                res += (uint8(bytes(str)[i]) - 48) * 10 ** (bytes(str).length - i - 1);
            }
            return (res, true);
        }
    }
    

    /// ===============================================================================================================
    /// --- 'Witnet.Result' helper methods ----------------------------------------------------------------------------

    modifier _isReady(Result memory result) {
        require(result.success, "Witnet: tried to decode value from errored result.");
        _;
    }

    /// @dev Decode an address from the Witnet.Result's CBOR value.
    function asAddress(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (address)
    {
        if (result.value.majorType == uint8(WitnetCBOR.MAJOR_TYPE_BYTES)) {
            return toAddress(result.value.readBytes());
        } else {
            // TODO
            revert("WitnetLib: reading address from string not yet supported.");
        }
    }

    /// @dev Decode a `bool` value from the Witnet.Result's CBOR value.
    function asBool(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bool)
    {
        return result.value.readBool();
    }

    /// @dev Decode a `bytes` value from the Witnet.Result's CBOR value.
    function asBytes(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns(bytes memory)
    {
        return result.value.readBytes();
    }

    /// @dev Decode a `bytes4` value from the Witnet.Result's CBOR value.
    function asBytes4(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bytes4)
    {
        return toBytes4(asBytes(result));
    }

    /// @dev Decode a `bytes32` value from the Witnet.Result's CBOR value.
    function asBytes32(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bytes32)
    {
        return toBytes32(asBytes(result));
    }

    /// @notice Returns the Witnet.Result's unread CBOR value.
    function asCborValue(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (WitnetCBOR.CBOR memory)
    {
        return result.value;
    }

    /// @notice Decode array of CBOR values from the Witnet.Result's CBOR value. 
    function asCborArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (WitnetCBOR.CBOR[] memory)
    {
        return result.value.readArray();
    }

    /// @dev Decode a fixed16 (half-precision) numeric value from the Witnet.Result's CBOR value.
    /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values.
    /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`.
    /// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
    function asFixed16(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int32)
    {
        return result.value.readFloat16();
    }

    /// @dev Decode an array of fixed16 values from the Witnet.Result's CBOR value.
    function asFixed16Array(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int32[] memory)
    {
        return result.value.readFloat16Array();
    }

    /// @dev Decode an `int64` value from the Witnet.Result's CBOR value.
    function asInt(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int)
    {
        return result.value.readInt();
    }

    /// @dev Decode an array of integer numeric values from a Witnet.Result as an `int[]` array.
    /// @param result An instance of Witnet.Result.
    /// @return The `int[]` decoded from the Witnet.Result.
    function asIntArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int[] memory)
    {
        return result.value.readIntArray();
    }

    /// @dev Decode a `string` value from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `string` decoded from the Witnet.Result.
    function asText(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns(string memory)
    {
        return result.value.readString();
    }

    /// @dev Decode an array of strings from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `string[]` decoded from the Witnet.Result.
    function asTextArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (string[] memory)
    {
        return result.value.readStringArray();
    }

    /// @dev Decode a `uint64` value from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `uint` decoded from the Witnet.Result.
    function asUint(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (uint)
    {
        return result.value.readUint();
    }

    /// @dev Decode an array of `uint64` values from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `uint[]` decoded from the Witnet.Result.
    function asUintArray(Witnet.Result memory result)
        internal pure
        returns (uint[] memory)
    {
        return result.value.readUintArray();
    }


    /// ===============================================================================================================
    /// --- Witnet library private methods ----------------------------------------------------------------------------

    /// @dev Decode a CBOR value into a Witnet.Result instance.
    function _resultFromCborValue(WitnetCBOR.CBOR memory cbor)
        private pure
        returns (Witnet.Result memory)    
    {
        // Witnet uses CBOR tag 39 to represent RADON error code identifiers.
        // [CBOR tag 39] Identifiers for CBOR: https://github.com/lucas-clemente/cbor-specs/blob/master/id.md
        bool success = cbor.tag != 39;
        return Witnet.Result(success, cbor);
    }

    /// @dev Calculate length of string-equivalent to given bytes32.
    function _toStringLength(bytes32 _bytes32)
        private pure
        returns (uint _length)
    {
        for (; _length < 32; ) {
            if (_bytes32[_length] == 0) {
                break;
            }
            unchecked {
                _length ++;
            }
        }
    }
}
          

/V2/IWitnetPriceSolver.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "../../libs/WitnetV2.sol";

interface IWitnetPriceSolver {
    struct Price {
        uint value;
        uint timestamp;
        bytes32 drTxHash;
        Witnet.ResultStatus status;
    }
    function class() external pure returns (bytes4);
    function delegator() external view returns (address);
    function solve(bytes4 feedId) external view returns (Price memory);
    function validate(bytes4 feedId, string[] calldata initdata) external;
}
          

/V2/IWitnetPriceFeeds.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./IWitnetPriceSolver.sol";

interface IWitnetPriceFeeds {   
    
    /// ======================================================================================================
    /// --- IFeeds extension ---------------------------------------------------------------------------------
    
    function lookupDecimals(bytes4 feedId) external view returns (uint8);    
    function lookupPriceSolver(bytes4 feedId) external view returns (
            IWitnetPriceSolver solverAddress, 
            string[] memory solverDeps
        );

    /// ======================================================================================================
    /// --- IWitnetFeeds extension ---------------------------------------------------------------------------

    function latestPrice(bytes4 feedId) external view returns (IWitnetPriceSolver.Price memory);
    function latestPrices(bytes4[] calldata feedIds)  external view returns (IWitnetPriceSolver.Price[] memory);
}
          

/WitnetUpgradableBase.sol

// SPDX-License-Identifier: MIT
// solhint-disable var-name-mixedcase
// solhint-disable payable-fallback

pragma solidity >=0.8.0 <0.9.0;

import "../patterns/ERC165.sol";
import "../patterns/Ownable2Step.sol";
import "../patterns/ReentrancyGuard.sol";
import "../patterns/Upgradeable.sol";

import "./WitnetProxy.sol";

/// @title Witnet Request Board base contract, with an Upgradeable (and Destructible) touch.
/// @author The Witnet Foundation.
abstract contract WitnetUpgradableBase
    is
        ERC165,
        Ownable2Step,
        Upgradeable, 
        ReentrancyGuard
{
    bytes32 internal immutable _WITNET_UPGRADABLE_VERSION;

    error AlreadyUpgraded(address implementation);
    error NotCompliant(bytes4 interfaceId);
    error NotUpgradable(address self);
    error OnlyOwner(address owner);

    constructor(
            bool _upgradable,
            bytes32 _versionTag,
            string memory _proxiableUUID
        )
        Upgradeable(_upgradable)
    {
        _WITNET_UPGRADABLE_VERSION = _versionTag;
        proxiableUUID = keccak256(bytes(_proxiableUUID));
    }
    
    /// @dev Reverts if proxy delegatecalls to unexistent method.
    fallback() virtual external {
        revert("WitnetUpgradableBase: not implemented");
    }


    // ================================================================================================================
    // --- Overrides IERC165 interface --------------------------------------------------------------------------------

    /// @dev See {IERC165-supportsInterface}.
    function supportsInterface(bytes4 _interfaceId)
      public view
      virtual override
      returns (bool)
    {
        return _interfaceId == type(Ownable2Step).interfaceId
            || _interfaceId == type(Upgradeable).interfaceId
            || super.supportsInterface(_interfaceId);
    }

    
    // ================================================================================================================
    // --- Overrides 'Proxiable' --------------------------------------------------------------------------------------

    /// @dev Gets immutable "heritage blood line" (ie. genotype) as a Proxiable, and eventually Upgradeable, contract.
    ///      If implemented as an Upgradeable touch, upgrading this contract to another one with a different 
    ///      `proxiableUUID()` value should fail.
    bytes32 public immutable override proxiableUUID;


    // ================================================================================================================
    // --- Overrides 'Upgradeable' --------------------------------------------------------------------------------------

    /// Retrieves human-readable version tag of current implementation.
    function version() public view virtual override returns (string memory) {
        return _toString(_WITNET_UPGRADABLE_VERSION);
    }


    // ================================================================================================================
    // --- Internal methods -------------------------------------------------------------------------------------------

    /// Converts bytes32 into string.
    function _toString(bytes32 _bytes32)
        internal pure
        returns (string memory)
    {
        bytes memory _bytes = new bytes(_toStringLength(_bytes32));
        for (uint _i = 0; _i < _bytes.length;) {
            _bytes[_i] = _bytes32[_i];
            unchecked {
                _i ++;
            }
        }
        return string(_bytes);
    }

    // Calculate length of string-equivalent to given bytes32.
    function _toStringLength(bytes32 _bytes32)
        internal pure
        returns (uint _length)
    {
        for (; _length < 32; ) {
            if (_bytes32[_length] == 0) {
                break;
            }
            unchecked {
                _length ++;
            }
        }
    }

}
          

/WitnetProxy.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../patterns/Upgradeable.sol";

/// @title WitnetProxy: upgradable delegate-proxy contract. 
/// @author The Witnet Foundation.
contract WitnetProxy {

    /// Event emitted every time the implementation gets updated.
    event Upgraded(address indexed implementation);  

    /// Constructor with no params as to ease eventual support of Singleton pattern (i.e. ERC-2470).
    constructor () {}

    receive() virtual external payable {}

    /// Payable fallback accepts delegating calls to payable functions.  
    fallback() external payable { /* solhint-disable no-complex-fallback */
        address _implementation = implementation();
        assembly { /* solhint-disable avoid-low-level-calls */
            // Gas optimized delegate call to 'implementation' contract.
            // Note: `msg.data`, `msg.sender` and `msg.value` will be passed over 
            //       to actual implementation of `msg.sig` within `implementation` contract.
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize())
            let result := delegatecall(gas(), _implementation, ptr, calldatasize(), 0, 0)
            let size := returndatasize()
            returndatacopy(ptr, 0, size)
            switch result
                case 0  { 
                    // pass back revert message:
                    revert(ptr, size) 
                }
                default {
                  // pass back same data as returned by 'implementation' contract:
                  return(ptr, size) 
                }
        }
    }

    /// Returns proxy's current implementation address.
    function implementation() public view returns (address) {
        return __proxySlot().implementation;
    }

    /// Upgrades the `implementation` address.
    /// @param _newImplementation New implementation address.
    /// @param _initData Raw data with which new implementation will be initialized.
    /// @return Returns whether new implementation would be further upgradable, or not.
    function upgradeTo(address _newImplementation, bytes memory _initData)
        public returns (bool)
    {
        // New implementation cannot be null:
        require(_newImplementation != address(0), "WitnetProxy: null implementation");

        address _oldImplementation = implementation();
        if (_oldImplementation != address(0)) {
            // New implementation address must differ from current one:
            require(_newImplementation != _oldImplementation, "WitnetProxy: nothing to upgrade");

            // Assert whether current implementation is intrinsically upgradable:
            try Upgradeable(_oldImplementation).isUpgradable() returns (bool _isUpgradable) {
                require(_isUpgradable, "WitnetProxy: not upgradable");
            } catch {
                revert("WitnetProxy: unable to check upgradability");
            }

            // Assert whether current implementation allows `msg.sender` to upgrade the proxy:
            (bool _wasCalled, bytes memory _result) = _oldImplementation.delegatecall(
                abi.encodeWithSignature(
                    "isUpgradableFrom(address)",
                    msg.sender
                )
            );
            require(_wasCalled, "WitnetProxy: not compliant");
            require(abi.decode(_result, (bool)), "WitnetProxy: not authorized");
            require(
                Upgradeable(_oldImplementation).proxiableUUID() == Upgradeable(_newImplementation).proxiableUUID(),
                "WitnetProxy: proxiableUUIDs mismatch"
            );
        }

        // Initialize new implementation within proxy-context storage:
        (bool _wasInitialized,) = _newImplementation.delegatecall(
            abi.encodeWithSignature(
                "initialize(bytes)",
                _initData
            )
        );
        require(_wasInitialized, "WitnetProxy: unable to initialize");

        // If all checks and initialization pass, update implementation address:
        __proxySlot().implementation = _newImplementation;
        emit Upgraded(_newImplementation);

        // Asserts new implementation complies w/ minimal implementation of Upgradeable interface:
        try Upgradeable(_newImplementation).isUpgradable() returns (bool _isUpgradable) {
            return _isUpgradable;
        }
        catch {
            revert ("WitnetProxy: not compliant");
        }
    }

    /// @dev Complying with EIP-1967, retrieves storage struct containing proxy's current implementation address.
    function __proxySlot() private pure returns (Proxiable.ProxiableSlot storage _slot) {
        assembly {
            // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
            _slot.slot := 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
        }
    }

}
          

/AddressUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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
     * ====
     *
     * [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://diligence.consensys.net/posts/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.5.11/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 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);
        }
    }
}
          

/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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]
 * ```
 * 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 Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
          

/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
          

/introspection/ERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
          

/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
          

/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
          

/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
          

Compiler Settings

{"remappings":[],"optimizer":{"runs":200,"enabled":true},"metadata":{"bytecodeHash":"ipfs"},"libraries":{},"evmVersion":"london","compilationTarget":{"project:/contracts/impls/apps/WitnetPriceFeedsBypassV20.sol":"WitnetPriceFeedsBypassV20"}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_surrogate","internalType":"contract WitnetPriceFeedsV20"},{"type":"bool","name":"_upgradable","internalType":"bool"},{"type":"bytes32","name":"_versionTag","internalType":"bytes32"}]},{"type":"error","name":"AlreadyUpgraded","inputs":[{"type":"address","name":"implementation","internalType":"address"}]},{"type":"error","name":"EmptyBuffer","inputs":[]},{"type":"error","name":"IndexOutOfBounds","inputs":[{"type":"uint256","name":"index","internalType":"uint256"},{"type":"uint256","name":"range","internalType":"uint256"}]},{"type":"error","name":"InvalidLengthEncoding","inputs":[{"type":"uint256","name":"length","internalType":"uint256"}]},{"type":"error","name":"NotCompliant","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"error","name":"NotUpgradable","inputs":[{"type":"address","name":"self","internalType":"address"}]},{"type":"error","name":"OnlyOwner","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"error","name":"UnsupportedMajorType","inputs":[{"type":"uint256","name":"unexpected","internalType":"uint256"}]},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferStarted","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"baseAddr","internalType":"address","indexed":true},{"type":"bytes32","name":"baseCodehash","internalType":"bytes32","indexed":true},{"type":"string","name":"versionTag","internalType":"string","indexed":false}],"anonymous":false},{"type":"fallback","stateMutability":"nonpayable"},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"base","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"class","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"codehash","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimateUpdateBaseFee","inputs":[{"type":"bytes4","name":"","internalType":"bytes4"},{"type":"uint256","name":"_gasPrice","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimateUpdateBaseFee","inputs":[{"type":"bytes4","name":"","internalType":"bytes4"},{"type":"uint256","name":"_gasPrice","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isUpgradable","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isUpgradableFrom","inputs":[{"type":"address","name":"_from","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct Witnet.Response","components":[{"type":"address","name":"reporter","internalType":"address"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes32","name":"drTxHash","internalType":"bytes32"},{"type":"bytes","name":"cborBytes","internalType":"bytes"}]}],"name":"latestResponse","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct Witnet.Result","components":[{"type":"bool","name":"success","internalType":"bool"},{"type":"tuple","name":"value","internalType":"struct WitnetCBOR.CBOR","components":[{"type":"tuple","name":"buffer","internalType":"struct WitnetBuffer.Buffer","components":[{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256","name":"cursor","internalType":"uint256"}]},{"type":"uint8","name":"initialByte","internalType":"uint8"},{"type":"uint8","name":"majorType","internalType":"uint8"},{"type":"uint8","name":"additionalInformation","internalType":"uint8"},{"type":"uint64","name":"len","internalType":"uint64"},{"type":"uint64","name":"tag","internalType":"uint64"}]}]}],"name":"latestResult","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct Witnet.Request","components":[{"type":"address","name":"addr","internalType":"address"},{"type":"bytes32","name":"slaHash","internalType":"bytes32"},{"type":"bytes32","name":"radHash","internalType":"bytes32"},{"type":"uint256","name":"gasprice","internalType":"uint256"},{"type":"uint256","name":"reward","internalType":"uint256"}]}],"name":"latestUpdateRequest","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct Witnet.Response","components":[{"type":"address","name":"reporter","internalType":"address"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes32","name":"drTxHash","internalType":"bytes32"},{"type":"bytes","name":"cborBytes","internalType":"bytes"}]}],"name":"latestUpdateResponse","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"enum Witnet.ResultStatus"}],"name":"latestUpdateResultStatus","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes","name":"","internalType":"bytes"}],"name":"lookupBytecode","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"lookupRadHash","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pendingOwner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"requestUpdate","inputs":[{"type":"bytes4","name":"","internalType":"bytes4"},{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"_usedFunds","internalType":"uint256"}],"name":"requestUpdate","inputs":[{"type":"bytes4","name":"_feedId","internalType":"bytes4"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"settleDefaultRadonSLA","inputs":[{"type":"tuple","name":"_slaV1","internalType":"struct Witnet.RadonSLA","components":[{"type":"uint8","name":"numWitnesses","internalType":"uint8"},{"type":"uint8","name":"minConsensusPercentage","internalType":"uint8"},{"type":"uint64","name":"witnessReward","internalType":"uint64"},{"type":"uint64","name":"witnessCollateral","internalType":"uint64"},{"type":"uint64","name":"minerCommitRevealFee","internalType":"uint64"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"_interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetPriceFeedsV20"}],"name":"surrogate","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"version","inputs":[]}]
              

Contract Creation Code

0x6101406040523480156200001257600080fd5b5060405162002e4738038062002e478339810160408190526200003591620002a6565b81816040518060400160405280601a81526020017f696f2e7769746e65742e70726f786961626c652e726f757465720000000000008152508262000088620000826200019a60201b60201c565b6200019e565b3060808190523f60a052151560c052600160025560e09190915280516020909101206101005250620001856001600160a01b0384163b158015906200014b575063346916ef60e11b6001600160e01b031916846001600160a01b031663adb7c3f76040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000119573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200013f9190620002fd565b6001600160e01b031916145b60408051808201909152601581527f756e636f6d706c69616e7420737572726f6761746500000000000000000000006020820152620001c8565b50506001600160a01b031661012052620003cc565b3390565b600180546001600160a01b0319169055620001c581620001dd602090811b620013cd17901c565b50565b81620001d957620001d9816200022d565b5050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051808201909152601981527f5769746e657450726963654665656473427970617373563230000000000000006020820152816040516020016200027592919062000356565b60408051601f198184030181529082905262461bcd60e51b82526200029d9160040162000397565b60405180910390fd5b600080600060608486031215620002bc57600080fd5b83516001600160a01b0381168114620002d457600080fd5b60208501519093508015158114620002eb57600080fd5b80925050604084015190509250925092565b6000602082840312156200031057600080fd5b81516001600160e01b0319811681146200032957600080fd5b9392505050565b60005b838110156200034d57818101518382015260200162000333565b50506000910152565b600083516200036a81846020880162000330565b6101d160f51b90830190815283516200038b81600284016020880162000330565b01600201949350505050565b6020815260008251806020840152620003b881604085016020870162000330565b601f01601f19169190910160400192915050565b60805160a05160c05160e05161010051610120516129de62000469600039600081816101ae01528181610573015281816106c301528181610a6a01528181610d96015281816110ca0152818161148b01526117ac0152600061033001526000610d4b015260006103610152600081816104fb0152610c230152600081816102e6015281816107fa015281816109640152610bf301526129de6000f3fe60806040526004361061019c5760003560e01c806383b816f0116100ec578063bff852fa1161008a578063d3471e3411610064578063d3471e34146105b5578063e13c11c4146105d5578063e30c397814610602578063f2fde38b146106205761019c565b8063bff852fa1461051f578063c27ef34f14610561578063d1842942146105955761019c565b806390937580116100c6578063909375801461047f57806396fd2e981461049f578063a80c5bc0146104bf578063a9e954b9146104ec5761019c565b806383b816f0146103e457806389a87b16146104045780638da5cb5b1461046a5761019c565b80635001f3b51161015957806354fd4d501161013357806354fd4d50146103855780636b58960a1461039a578063715018a6146103ba57806379ba5097146103cf5761019c565b80635001f3b5146102d757806352d1902d1461031e5780635479d940146103525761019c565b806301ffc9a7146101f45780633917ecfd146102295780633e088e121461024a57806340eb7a071461025d578063439fab911461028a57806348765643146102aa575b3480156101a857600080fd5b506040517f000000000000000000000000000000000000000000000000000000000000000090366000823760008036836000865af13d806000843e8180156101ee578184f35b8184fd5b005b34801561020057600080fd5b5061021461020f366004611de6565b610640565b60405190151581526020015b60405180910390f35b61023c610237366004611e03565b610692565b604051908152602001610220565b61023c610258366004611de6565b6106bf565b34801561026957600080fd5b5061027d610278366004611de6565b610798565b6040516102209190611e7f565b34801561029657600080fd5b506101f26102a5366004611f49565b6107f0565b3480156102b657600080fd5b506102ca6102c5366004611de6565b610c86565b6040516102209190611fc8565b3480156102e357600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b039091168152602001610220565b34801561032a57600080fd5b5061023c7f000000000000000000000000000000000000000000000000000000000000000081565b34801561035e57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610214565b34801561039157600080fd5b5061027d610d44565b3480156103a657600080fd5b506102146103b536600461201e565b610d74565b3480156103c657600080fd5b506101f2610e03565b3480156103db57600080fd5b506101f2610e17565b3480156103f057600080fd5b506101f26103ff36600461203b565b610e91565b34801561041057600080fd5b5061042461041f366004611de6565b610f73565b604051610220919081516001600160a01b031681526020808301519082015260408083015190820152606080830151908201526080918201519181019190915260a00190565b34801561047657600080fd5b506103066110c6565b34801561048b57600080fd5b5061023c61049a366004611de6565b61114a565b3480156104ab57600080fd5b5061023c6104ba36600461204d565b6111a2565b3480156104cb57600080fd5b506104df6104da366004611de6565b611205565b604051610220919061209e565b3480156104f857600080fd5b507f000000000000000000000000000000000000000000000000000000000000000061023c565b34801561052b57600080fd5b5060408051808201909152601981527805769746e65745072696365466565647342797061737356323603c1b602082015261027d565b34801561056d57600080fd5b506103067f000000000000000000000000000000000000000000000000000000000000000081565b3480156105a157600080fd5b5061023c6105b03660046120c6565b6112af565b3480156105c157600080fd5b506102ca6105d0366004611de6565b6112e2565b3480156105e157600080fd5b506105f56105f0366004611de6565b61134a565b60405161022091906120fb565b34801561060e57600080fd5b506001546001600160a01b0316610306565b34801561062c57600080fd5b506101f261063b36600461201e565b611367565b60006001600160e01b03198216631a12e29960e21b148061067157506001600160e01b0319821663d1ab0e8760e01b145b8061068c57506301ffc9a760e01b6001600160e01b03198316145b92915050565b600061068c6040518060400160405280600a81526020016919195c1c9958d85d195960b21b81525061141d565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633e088e1234846040518363ffffffff1660e01b815260040161070e919061219c565b60206040518083038185885af115801561072c573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061075191906121b1565b90503481101561079357336108fc61076983346121e0565b6040518115909202916000818181858888f19350505050158015610791573d6000803e3d6000fd5b505b919050565b60606107dd826040516024016107ae919061219c565b60408051601f198184030181529190526020810180516001600160e01b031663013bfbe760e61b179052611485565b80602001905181019061068c9190612243565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361086d5760405162461bcd60e51b815260206004820181905260248201527f5570677261646561626c653a206e6f7420612064656c65676174652063616c6c60448201526064015b60405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd546001600160a01b03161580156108cd57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b0316155b15610911577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd80546001600160a01b0319163017905561090c3361152f565b61095f565b6109196110c6565b6001600160a01b0316336001600160a01b03161461095f5761095f6040518060400160405280600d81526020016c3737ba103a34329037bbb732b960991b81525061141d565b6109ee7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54604080518082019091526013815272185b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60208201526001600160a01b03909116919091141590611548565b6000306001600160a01b0316630306732e6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610a2e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610a569190810190612394565b5050905060005b8151811015610bc35760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f14cb812848481518110610aa957610aa961247c565b60200260200101516040518263ffffffff1660e01b8152600401610acd919061219c565b602060405180830381865afa158015610aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0e9190612492565b9050610bb06002826005811115610b2757610b27612088565b1480610b4457506003826005811115610b4257610b42612088565b145b80610b6057506005826005811115610b5e57610b5e612088565b145b610b8c858581518110610b7557610b7561247c565b60200260200101516001600160e01b031916611556565b604051602001610b9c91906124b3565b604051602081830303815290604052611548565b5080610bbb816124f8565b915050610a5d565b507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169081179091557f000000000000000000000000000000000000000000000000000000000000000090337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f6610c6d610d44565b604051610c7a9190611e7f565b60405180910390a45050565b60408051608081018252600080825260208201819052918101919091526060808201526000610cee83604051602401610cbf919061219c565b60408051601f198184030181529190526020810180516001600160e01b031663f9b4a27f60e01b179052611485565b806020019051810190610d019190612526565b604080516080808201835283516001600160a01b031682528284015163ffffffff1660208301526060808501519383019390935290920151908201529392505050565b6060610d6f7f00000000000000000000000000000000000000000000000000000000000000006115bd565b905090565b6040516335ac4b0560e11b81526001600160a01b0382811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690636b58960a90602401602060405180830381865afa158015610ddf573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068c91906125de565b610e0b611668565b610e15600061152f565b565b60015433906001600160a01b03168114610e855760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610864565b610e8e8161152f565b50565b610ec6610e9d826116c7565b6040518060400160405280600b81526020016a696e76616c696420534c4160a81b815250611548565b60408051808201909152610f6f9080610ee2602085018561260f565b60ff168152602090810190610ef99085018561260f565b60ff16610f0c608086016060870161262c565b610f16919061265f565b6001600160401b03908116909152604051825160ff16602482015260209092015116604482015260640160408051601f198184030181529190526020810180516001600160e01b031663fae91a5160e01b1790526117a6565b5050565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101919091526000610fe383604051602401610fb4919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166344d43d8b60e11b179052611485565b806020019051810190610ff69190612719565b90506040518060a0016040528060006001600160a01b031681526020018260a001516040516020016110749190600060a08201905060ff835116825260ff602084015116602083015260408301516001600160401b038082166040850152806060860151166060850152806080860151166080850152505092915050565b60405160208183030381529060405280602001905181019061109691906121b1565b8152602001826080015181526020013a8152602001826040015168ffffffffffffffffff16815250915050919050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611126573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6f91906127e1565b600061118f82604051602401611160919061219c565b60408051601f198184030181529190526020810180516001600160e01b0316638df3fdfd60e01b179052611485565b80602001905181019061068c91906121b1565b60006111e9846040516024016111ba91815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663603269b960e11b179052611485565b8060200190518101906111fc91906121b1565b95945050505050565b60008061124b8360405160240161121c919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166378a65c0960e11b179052611485565b80602001905181019061125e9190612492565b9050600481600581111561127457611274612088565b036112825750600192915050565b80600581111561129457611294612088565b60ff1660038111156112a8576112a8612088565b9392505050565b60006112c7836040516024016111ba91815260200190565b8060200190518101906112da91906121b1565b949350505050565b60408051608081018252600080825260208201819052918101919091526060808201526000610cee8360405160240161131b919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166334d1c78d60e21b179052611485565b611352611d68565b61068c61135e83610c86565b60600151611852565b61136f611668565b600180546001600160a01b0319166001600160a01b0383169081179091556113956110c6565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051808201909152601981527805769746e65745072696365466565647342797061737356323603c1b60208201528160405160200161145f9291906127fe565b60408051601f198184030181529082905262461bcd60e51b825261086491600401611e7f565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836040516114c1919061283b565b600060405180830381855afa9150503d80600081146114fc576040519150601f19603f3d011682016040523d82523d6000602084013e611501565b606091505b50925090506107918161151f6001600160e01b031960003516611556565b604051602001610b9c9190612857565b600180546001600160a01b0319169055610e8e816113cd565b81610f6f57610f6f8161141d565b60606115648260f81c611870565b61157460ff60f085901c16611870565b61158460ff60e886901c16611870565b61159460ff60e087901c16611870565b6040516020016115a7949392919061289c565b6040516020818303038152906040529050919050565b606060006115ca83611962565b6001600160401b038111156115e1576115e1611e92565b6040519080825280601f01601f19166020018201604052801561160b576020820181803683370190505b50905060005b81518110156116615783816020811061162c5761162c61247c565b1a60f81b8282815181106116425761164261247c565b60200101906001600160f81b031916908160001a905350600101611611565b5092915050565b336116716110c6565b6001600160a01b031614610e155760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610864565b6000806116d7602084018461260f565b60ff161180156116f75750607f6116f1602084018461260f565b60ff1611155b801561171657506033611710604084016020850161260f565b60ff1610155b801561173a5750600061172f606084016040850161262c565b6001600160401b0316115b801561176257506404a817c800611757608084016060850161262c565b6001600160401b0316115b801561068c5750607d61177b606084016040850161262c565b61178b608085016060860161262c565b611795919061265f565b6001600160401b0316111592915050565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836040516117e2919061283b565b6000604051808303816000865af19150503d806000811461181f576040519150601f19603f3d011682016040523d82523d6000602084013e611824565b606091505b5092509050610791816118426001600160e01b031960003516611556565b604051602001610b9c91906128f3565b61185a611d68565b60006118658361199b565b90506112a8816119c0565b6040805160028082528183019092526060916000919060208201818036833701905050905060006118a2601085612938565b6118ad90603061295a565b905060006118bc601086612973565b6118c790603061295a565b905060398260ff1611156118e3576118e060078361295a565b91505b60398160ff1611156118fd576118fa60078261295a565b90505b8160f81b836000815181106119145761191461247c565b60200101906001600160f81b031916908160001a9053508060f81b836001815181106119425761194261247c565b60200101906001600160f81b031916908160001a90535091949350505050565b60005b6020811015610793578181602081106119805761198061247c565b1a60f81b6001600160f81b0319161561079357600101611965565b6119a3611d89565b60408051808201909152828152600060208201526112a8816119f4565b6119c8611d68565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b6119fc611d89565b8151518290600003611a21576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611aa457611a4189611b14565b955081611a4d816124f8565b6007600589901c169650601f881695509250506005198501611a9c576020890151611a788a86611b76565b9350808a60200151611a8a91906121e0565b611a949084612995565b925050611a32565b506000611a32565b600760ff86161115611ace5760405163bd2ac87960e01b815260ff86166004820152602401610864565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b6000816020015182600001515180821115611b4c576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051808301600101519550908190611b69826124f8565b8152505050505050919050565b600060188260ff161015611b8e575060ff811661068c565b8160ff16601803611bac57611ba283611b14565b60ff16905061068c565b8160ff16601903611bcb57611bc083611c3e565b61ffff16905061068c565b8160ff16601a03611bec57611bdf83611caa565b63ffffffff16905061068c565b8160ff16601b03611c0757611c0083611d09565b905061068c565b8160ff16601f03611c2057506001600160401b0361068c565b604051636d785b1360e01b815260ff83166004820152602401610864565b600081602001516002611c519190612995565b82515180821115611c7f576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600281840181015196509091611c9d8284612995565b9052509395945050505050565b600081602001516004611cbd9190612995565b82515180821115611ceb576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600481840181015196509091611c9d8284612995565b600081602001516008611d1c9190612995565b82515180821115611d4a576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600881840181015196509091611c9d8284612995565b6040518060400160405280600015158152602001611d84611d89565b905290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b6001600160e01b031981168114610e8e57600080fd5b600060208284031215611df857600080fd5b81356112a881611dd0565b60008060408385031215611e1657600080fd5b8235611e2181611dd0565b946020939093013593505050565b60005b83811015611e4a578181015183820152602001611e32565b50506000910152565b60008151808452611e6b816020860160208601611e2f565b601f01601f19169290920160200192915050565b6020815260006112a86020830184611e53565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b0381118282101715611eca57611eca611e92565b60405290565b60405160c081016001600160401b0381118282101715611eca57611eca611e92565b604051601f8201601f191681016001600160401b0381118282101715611f1a57611f1a611e92565b604052919050565b60006001600160401b03821115611f3b57611f3b611e92565b50601f01601f191660200190565b600060208284031215611f5b57600080fd5b81356001600160401b03811115611f7157600080fd5b8201601f81018413611f8257600080fd5b8035611f95611f9082611f22565b611ef2565b818152856020838501011115611faa57600080fd5b81602084016020830137600091810160200191909152949350505050565b6020815260018060a01b0382511660208201526020820151604082015260408201516060820152600060608301516080808401526112da60a0840182611e53565b6001600160a01b0381168114610e8e57600080fd5b60006020828403121561203057600080fd5b81356112a881612009565b600060a0828403121561079157600080fd5b6000806000806080858703121561206357600080fd5b843561206e81611dd0565b966020860135965060408601359560600135945092505050565b634e487b7160e01b600052602160045260246000fd5b60208101600483106120c057634e487b7160e01b600052602160045260246000fd5b91905290565b6000806000606084860312156120db57600080fd5b83356120e681611dd0565b95602085013595506040909401359392505050565b6020815281511515602082015260006020830151604080840152805160c0606085015280516040610120860152612136610160860182611e53565b6020928301516101408701529183015160ff1660808601525060408201519061216460a086018360ff169052565b606083015160ff1660c086015260808301516001600160401b0380821660e088015260a09094015193841661010087015291506111fc565b6001600160e01b031991909116815260200190565b6000602082840312156121c357600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561068c5761068c6121ca565b6000612201611f9084611f22565b905082815283838301111561221557600080fd5b6112a8836020830184611e2f565b600082601f83011261223457600080fd5b6112a8838351602085016121f3565b60006020828403121561225557600080fd5b81516001600160401b0381111561226b57600080fd5b6112da84828501612223565b60006001600160401b0382111561229057612290611e92565b5060051b60200190565b600082601f8301126122ab57600080fd5b815160206122bb611f9083612277565b82815260059290921b840181019181810190868411156122da57600080fd5b8286015b8481101561232e5780516001600160401b038111156122fd5760008081fd5b8701603f8101891361230f5760008081fd5b6123208986830151604084016121f3565b8452509183019183016122de565b509695505050505050565b600082601f83011261234a57600080fd5b8151602061235a611f9083612277565b82815260059290921b8401810191818101908684111561237957600080fd5b8286015b8481101561232e578051835291830191830161237d565b6000806000606084860312156123a957600080fd5b83516001600160401b03808211156123c057600080fd5b818601915086601f8301126123d457600080fd5b815160206123e4611f9083612277565b82815260059290921b8401810191818101908a84111561240357600080fd5b948201945b8386101561242a57855161241b81611dd0565b82529482019490820190612408565b9189015191975090935050508082111561244357600080fd5b61244f8783880161229a565b9350604086015191508082111561246557600080fd5b5061247286828701612339565b9150509250925092565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156124a457600080fd5b8151600681106112a857600080fd5b7f756e636f6e736f6c69646174656420666565643a2030780000000000000000008152600082516124eb816017850160208701611e2f565b9190910160170192915050565b60006001820161250a5761250a6121ca565b5060010190565b6001600160401b0381168114610e8e57600080fd5b60006020828403121561253857600080fd5b81516001600160401b038082111561254f57600080fd5b9083019060a0828603121561256357600080fd5b61256b611ea8565b825161257681612009565b8152602083015161258681612511565b6020820152604083015163ffffffff811681146125a257600080fd5b6040820152606083810151908201526080830151828111156125c357600080fd5b6125cf87828601612223565b60808301525095945050505050565b6000602082840312156125f057600080fd5b815180151581146112a857600080fd5b60ff81168114610e8e57600080fd5b60006020828403121561262157600080fd5b81356112a881612600565b60006020828403121561263e57600080fd5b81356112a881612511565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b038084168061267957612679612649565b92169190910492915050565b805168ffffffffffffffffff8116811461079357600080fd5b600060a082840312156126b057600080fd5b6126b8611ea8565b905081516126c581612600565b815260208201516126d581612600565b602082015260408201516126e881612511565b604082015260608201516126fb81612511565b6060820152608082015161270e81612511565b608082015292915050565b60006020828403121561272b57600080fd5b81516001600160401b038082111561274257600080fd5b90830190610140828603121561275757600080fd5b61275f611ed0565b825161276a81612009565b8152602083015162ffffff8116811461278257600080fd5b602082015261279360408401612685565b60408201526060830151828111156127aa57600080fd5b6127b687828601612223565b606083015250608083015160808201526127d38660a0850161269e565b60a082015295945050505050565b6000602082840312156127f357600080fd5b81516112a881612009565b60008351612810818460208801611e2f565b6101d160f51b908301908152835161282f816002840160208801611e2f565b01600201949350505050565b6000825161284d818460208701611e2f565b9190910192915050565b7f63616e6e6f7420737572726f67617465207374617469632063616c6c3a20307881526000825161288f816020850160208701611e2f565b9190910160200192915050565b600085516128ae818460208a01611e2f565b8551908301906128c2818360208a01611e2f565b85519101906128d5818360208901611e2f565b84519101906128e8818360208801611e2f565b019695505050505050565b7f63616e6e6f7420737572726f676174652063616c6c3a2030780000000000000081526000825161292b816019850160208701611e2f565b9190910160190192915050565b600060ff83168061294b5761294b612649565b8060ff84160491505092915050565b60ff818116838216019081111561068c5761068c6121ca565b600060ff83168061298657612986612649565b8060ff84160691505092915050565b8082018082111561068c5761068c6121ca56fea264697066735822122022f63e134e6a7b59b25710a186a72320f56adb8ccc2b1c3cd89efff75d7b322f64736f6c634300081100330000000000000000000000001111aba2164acdc6d291b08dfb374280035e11110000000000000000000000000000000000000000000000000000000000000001302e372e31382d34336162303631000000000000000000000000000000000000

Deployed ByteCode

0x60806040526004361061019c5760003560e01c806383b816f0116100ec578063bff852fa1161008a578063d3471e3411610064578063d3471e34146105b5578063e13c11c4146105d5578063e30c397814610602578063f2fde38b146106205761019c565b8063bff852fa1461051f578063c27ef34f14610561578063d1842942146105955761019c565b806390937580116100c6578063909375801461047f57806396fd2e981461049f578063a80c5bc0146104bf578063a9e954b9146104ec5761019c565b806383b816f0146103e457806389a87b16146104045780638da5cb5b1461046a5761019c565b80635001f3b51161015957806354fd4d501161013357806354fd4d50146103855780636b58960a1461039a578063715018a6146103ba57806379ba5097146103cf5761019c565b80635001f3b5146102d757806352d1902d1461031e5780635479d940146103525761019c565b806301ffc9a7146101f45780633917ecfd146102295780633e088e121461024a57806340eb7a071461025d578063439fab911461028a57806348765643146102aa575b3480156101a857600080fd5b506040517f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e111190366000823760008036836000865af13d806000843e8180156101ee578184f35b8184fd5b005b34801561020057600080fd5b5061021461020f366004611de6565b610640565b60405190151581526020015b60405180910390f35b61023c610237366004611e03565b610692565b604051908152602001610220565b61023c610258366004611de6565b6106bf565b34801561026957600080fd5b5061027d610278366004611de6565b610798565b6040516102209190611e7f565b34801561029657600080fd5b506101f26102a5366004611f49565b6107f0565b3480156102b657600080fd5b506102ca6102c5366004611de6565b610c86565b6040516102209190611fc8565b3480156102e357600080fd5b507f0000000000000000000000002d2793c77927bcfe2847f24f43d27cfbae6878265b6040516001600160a01b039091168152602001610220565b34801561032a57600080fd5b5061023c7fe7e7a186634600a97186e15d36005affc564f1035fcdaeaf224d24d0ecd41ee681565b34801561035e57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000001610214565b34801561039157600080fd5b5061027d610d44565b3480156103a657600080fd5b506102146103b536600461201e565b610d74565b3480156103c657600080fd5b506101f2610e03565b3480156103db57600080fd5b506101f2610e17565b3480156103f057600080fd5b506101f26103ff36600461203b565b610e91565b34801561041057600080fd5b5061042461041f366004611de6565b610f73565b604051610220919081516001600160a01b031681526020808301519082015260408083015190820152606080830151908201526080918201519181019190915260a00190565b34801561047657600080fd5b506103066110c6565b34801561048b57600080fd5b5061023c61049a366004611de6565b61114a565b3480156104ab57600080fd5b5061023c6104ba36600461204d565b6111a2565b3480156104cb57600080fd5b506104df6104da366004611de6565b611205565b604051610220919061209e565b3480156104f857600080fd5b507fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47061023c565b34801561052b57600080fd5b5060408051808201909152601981527805769746e65745072696365466565647342797061737356323603c1b602082015261027d565b34801561056d57600080fd5b506103067f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e111181565b3480156105a157600080fd5b5061023c6105b03660046120c6565b6112af565b3480156105c157600080fd5b506102ca6105d0366004611de6565b6112e2565b3480156105e157600080fd5b506105f56105f0366004611de6565b61134a565b60405161022091906120fb565b34801561060e57600080fd5b506001546001600160a01b0316610306565b34801561062c57600080fd5b506101f261063b36600461201e565b611367565b60006001600160e01b03198216631a12e29960e21b148061067157506001600160e01b0319821663d1ab0e8760e01b145b8061068c57506301ffc9a760e01b6001600160e01b03198316145b92915050565b600061068c6040518060400160405280600a81526020016919195c1c9958d85d195960b21b81525061141d565b60007f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11116001600160a01b0316633e088e1234846040518363ffffffff1660e01b815260040161070e919061219c565b60206040518083038185885af115801561072c573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061075191906121b1565b90503481101561079357336108fc61076983346121e0565b6040518115909202916000818181858888f19350505050158015610791573d6000803e3d6000fd5b505b919050565b60606107dd826040516024016107ae919061219c565b60408051601f198184030181529190526020810180516001600160e01b031663013bfbe760e61b179052611485565b80602001905181019061068c9190612243565b6001600160a01b037f0000000000000000000000002d2793c77927bcfe2847f24f43d27cfbae68782616300361086d5760405162461bcd60e51b815260206004820181905260248201527f5570677261646561626c653a206e6f7420612064656c65676174652063616c6c60448201526064015b60405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd546001600160a01b03161580156108cd57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b0316155b15610911577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd80546001600160a01b0319163017905561090c3361152f565b61095f565b6109196110c6565b6001600160a01b0316336001600160a01b03161461095f5761095f6040518060400160405280600d81526020016c3737ba103a34329037bbb732b960991b81525061141d565b6109ee7f0000000000000000000000002d2793c77927bcfe2847f24f43d27cfbae6878266001600160a01b03167f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54604080518082019091526013815272185b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60208201526001600160a01b03909116919091141590611548565b6000306001600160a01b0316630306732e6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610a2e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610a569190810190612394565b5050905060005b8151811015610bc35760007f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11116001600160a01b031663f14cb812848481518110610aa957610aa961247c565b60200260200101516040518263ffffffff1660e01b8152600401610acd919061219c565b602060405180830381865afa158015610aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0e9190612492565b9050610bb06002826005811115610b2757610b27612088565b1480610b4457506003826005811115610b4257610b42612088565b145b80610b6057506005826005811115610b5e57610b5e612088565b145b610b8c858581518110610b7557610b7561247c565b60200260200101516001600160e01b031916611556565b604051602001610b9c91906124b3565b604051602081830303815290604052611548565b5080610bbb816124f8565b915050610a5d565b507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319167f0000000000000000000000002d2793c77927bcfe2847f24f43d27cfbae6878266001600160a01b03169081179091557fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47090337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f6610c6d610d44565b604051610c7a9190611e7f565b60405180910390a45050565b60408051608081018252600080825260208201819052918101919091526060808201526000610cee83604051602401610cbf919061219c565b60408051601f198184030181529190526020810180516001600160e01b031663f9b4a27f60e01b179052611485565b806020019051810190610d019190612526565b604080516080808201835283516001600160a01b031682528284015163ffffffff1660208301526060808501519383019390935290920151908201529392505050565b6060610d6f7f302e372e31382d343361623036310000000000000000000000000000000000006115bd565b905090565b6040516335ac4b0560e11b81526001600160a01b0382811660048301526000917f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e111190911690636b58960a90602401602060405180830381865afa158015610ddf573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068c91906125de565b610e0b611668565b610e15600061152f565b565b60015433906001600160a01b03168114610e855760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610864565b610e8e8161152f565b50565b610ec6610e9d826116c7565b6040518060400160405280600b81526020016a696e76616c696420534c4160a81b815250611548565b60408051808201909152610f6f9080610ee2602085018561260f565b60ff168152602090810190610ef99085018561260f565b60ff16610f0c608086016060870161262c565b610f16919061265f565b6001600160401b03908116909152604051825160ff16602482015260209092015116604482015260640160408051601f198184030181529190526020810180516001600160e01b031663fae91a5160e01b1790526117a6565b5050565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101919091526000610fe383604051602401610fb4919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166344d43d8b60e11b179052611485565b806020019051810190610ff69190612719565b90506040518060a0016040528060006001600160a01b031681526020018260a001516040516020016110749190600060a08201905060ff835116825260ff602084015116602083015260408301516001600160401b038082166040850152806060860151166060850152806080860151166080850152505092915050565b60405160208183030381529060405280602001905181019061109691906121b1565b8152602001826080015181526020013a8152602001826040015168ffffffffffffffffff16815250915050919050565b60007f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11116001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611126573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6f91906127e1565b600061118f82604051602401611160919061219c565b60408051601f198184030181529190526020810180516001600160e01b0316638df3fdfd60e01b179052611485565b80602001905181019061068c91906121b1565b60006111e9846040516024016111ba91815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663603269b960e11b179052611485565b8060200190518101906111fc91906121b1565b95945050505050565b60008061124b8360405160240161121c919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166378a65c0960e11b179052611485565b80602001905181019061125e9190612492565b9050600481600581111561127457611274612088565b036112825750600192915050565b80600581111561129457611294612088565b60ff1660038111156112a8576112a8612088565b9392505050565b60006112c7836040516024016111ba91815260200190565b8060200190518101906112da91906121b1565b949350505050565b60408051608081018252600080825260208201819052918101919091526060808201526000610cee8360405160240161131b919061219c565b60408051601f198184030181529190526020810180516001600160e01b03166334d1c78d60e21b179052611485565b611352611d68565b61068c61135e83610c86565b60600151611852565b61136f611668565b600180546001600160a01b0319166001600160a01b0383169081179091556113956110c6565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051808201909152601981527805769746e65745072696365466565647342797061737356323603c1b60208201528160405160200161145f9291906127fe565b60408051601f198184030181529082905262461bcd60e51b825261086491600401611e7f565b606060007f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11116001600160a01b0316836040516114c1919061283b565b600060405180830381855afa9150503d80600081146114fc576040519150601f19603f3d011682016040523d82523d6000602084013e611501565b606091505b50925090506107918161151f6001600160e01b031960003516611556565b604051602001610b9c9190612857565b600180546001600160a01b0319169055610e8e816113cd565b81610f6f57610f6f8161141d565b60606115648260f81c611870565b61157460ff60f085901c16611870565b61158460ff60e886901c16611870565b61159460ff60e087901c16611870565b6040516020016115a7949392919061289c565b6040516020818303038152906040529050919050565b606060006115ca83611962565b6001600160401b038111156115e1576115e1611e92565b6040519080825280601f01601f19166020018201604052801561160b576020820181803683370190505b50905060005b81518110156116615783816020811061162c5761162c61247c565b1a60f81b8282815181106116425761164261247c565b60200101906001600160f81b031916908160001a905350600101611611565b5092915050565b336116716110c6565b6001600160a01b031614610e155760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610864565b6000806116d7602084018461260f565b60ff161180156116f75750607f6116f1602084018461260f565b60ff1611155b801561171657506033611710604084016020850161260f565b60ff1610155b801561173a5750600061172f606084016040850161262c565b6001600160401b0316115b801561176257506404a817c800611757608084016060850161262c565b6001600160401b0316115b801561068c5750607d61177b606084016040850161262c565b61178b608085016060860161262c565b611795919061265f565b6001600160401b0316111592915050565b606060007f0000000000000000000000001111aba2164acdc6d291b08dfb374280035e11116001600160a01b0316836040516117e2919061283b565b6000604051808303816000865af19150503d806000811461181f576040519150601f19603f3d011682016040523d82523d6000602084013e611824565b606091505b5092509050610791816118426001600160e01b031960003516611556565b604051602001610b9c91906128f3565b61185a611d68565b60006118658361199b565b90506112a8816119c0565b6040805160028082528183019092526060916000919060208201818036833701905050905060006118a2601085612938565b6118ad90603061295a565b905060006118bc601086612973565b6118c790603061295a565b905060398260ff1611156118e3576118e060078361295a565b91505b60398160ff1611156118fd576118fa60078261295a565b90505b8160f81b836000815181106119145761191461247c565b60200101906001600160f81b031916908160001a9053508060f81b836001815181106119425761194261247c565b60200101906001600160f81b031916908160001a90535091949350505050565b60005b6020811015610793578181602081106119805761198061247c565b1a60f81b6001600160f81b0319161561079357600101611965565b6119a3611d89565b60408051808201909152828152600060208201526112a8816119f4565b6119c8611d68565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b6119fc611d89565b8151518290600003611a21576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611aa457611a4189611b14565b955081611a4d816124f8565b6007600589901c169650601f881695509250506005198501611a9c576020890151611a788a86611b76565b9350808a60200151611a8a91906121e0565b611a949084612995565b925050611a32565b506000611a32565b600760ff86161115611ace5760405163bd2ac87960e01b815260ff86166004820152602401610864565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b6000816020015182600001515180821115611b4c576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051808301600101519550908190611b69826124f8565b8152505050505050919050565b600060188260ff161015611b8e575060ff811661068c565b8160ff16601803611bac57611ba283611b14565b60ff16905061068c565b8160ff16601903611bcb57611bc083611c3e565b61ffff16905061068c565b8160ff16601a03611bec57611bdf83611caa565b63ffffffff16905061068c565b8160ff16601b03611c0757611c0083611d09565b905061068c565b8160ff16601f03611c2057506001600160401b0361068c565b604051636d785b1360e01b815260ff83166004820152602401610864565b600081602001516002611c519190612995565b82515180821115611c7f576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600281840181015196509091611c9d8284612995565b9052509395945050505050565b600081602001516004611cbd9190612995565b82515180821115611ceb576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600481840181015196509091611c9d8284612995565b600081602001516008611d1c9190612995565b82515180821115611d4a576040516363a056dd60e01b81526004810183905260248101829052604401610864565b8351602085018051600881840181015196509091611c9d8284612995565b6040518060400160405280600015158152602001611d84611d89565b905290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b6001600160e01b031981168114610e8e57600080fd5b600060208284031215611df857600080fd5b81356112a881611dd0565b60008060408385031215611e1657600080fd5b8235611e2181611dd0565b946020939093013593505050565b60005b83811015611e4a578181015183820152602001611e32565b50506000910152565b60008151808452611e6b816020860160208601611e2f565b601f01601f19169290920160200192915050565b6020815260006112a86020830184611e53565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b0381118282101715611eca57611eca611e92565b60405290565b60405160c081016001600160401b0381118282101715611eca57611eca611e92565b604051601f8201601f191681016001600160401b0381118282101715611f1a57611f1a611e92565b604052919050565b60006001600160401b03821115611f3b57611f3b611e92565b50601f01601f191660200190565b600060208284031215611f5b57600080fd5b81356001600160401b03811115611f7157600080fd5b8201601f81018413611f8257600080fd5b8035611f95611f9082611f22565b611ef2565b818152856020838501011115611faa57600080fd5b81602084016020830137600091810160200191909152949350505050565b6020815260018060a01b0382511660208201526020820151604082015260408201516060820152600060608301516080808401526112da60a0840182611e53565b6001600160a01b0381168114610e8e57600080fd5b60006020828403121561203057600080fd5b81356112a881612009565b600060a0828403121561079157600080fd5b6000806000806080858703121561206357600080fd5b843561206e81611dd0565b966020860135965060408601359560600135945092505050565b634e487b7160e01b600052602160045260246000fd5b60208101600483106120c057634e487b7160e01b600052602160045260246000fd5b91905290565b6000806000606084860312156120db57600080fd5b83356120e681611dd0565b95602085013595506040909401359392505050565b6020815281511515602082015260006020830151604080840152805160c0606085015280516040610120860152612136610160860182611e53565b6020928301516101408701529183015160ff1660808601525060408201519061216460a086018360ff169052565b606083015160ff1660c086015260808301516001600160401b0380821660e088015260a09094015193841661010087015291506111fc565b6001600160e01b031991909116815260200190565b6000602082840312156121c357600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561068c5761068c6121ca565b6000612201611f9084611f22565b905082815283838301111561221557600080fd5b6112a8836020830184611e2f565b600082601f83011261223457600080fd5b6112a8838351602085016121f3565b60006020828403121561225557600080fd5b81516001600160401b0381111561226b57600080fd5b6112da84828501612223565b60006001600160401b0382111561229057612290611e92565b5060051b60200190565b600082601f8301126122ab57600080fd5b815160206122bb611f9083612277565b82815260059290921b840181019181810190868411156122da57600080fd5b8286015b8481101561232e5780516001600160401b038111156122fd5760008081fd5b8701603f8101891361230f5760008081fd5b6123208986830151604084016121f3565b8452509183019183016122de565b509695505050505050565b600082601f83011261234a57600080fd5b8151602061235a611f9083612277565b82815260059290921b8401810191818101908684111561237957600080fd5b8286015b8481101561232e578051835291830191830161237d565b6000806000606084860312156123a957600080fd5b83516001600160401b03808211156123c057600080fd5b818601915086601f8301126123d457600080fd5b815160206123e4611f9083612277565b82815260059290921b8401810191818101908a84111561240357600080fd5b948201945b8386101561242a57855161241b81611dd0565b82529482019490820190612408565b9189015191975090935050508082111561244357600080fd5b61244f8783880161229a565b9350604086015191508082111561246557600080fd5b5061247286828701612339565b9150509250925092565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156124a457600080fd5b8151600681106112a857600080fd5b7f756e636f6e736f6c69646174656420666565643a2030780000000000000000008152600082516124eb816017850160208701611e2f565b9190910160170192915050565b60006001820161250a5761250a6121ca565b5060010190565b6001600160401b0381168114610e8e57600080fd5b60006020828403121561253857600080fd5b81516001600160401b038082111561254f57600080fd5b9083019060a0828603121561256357600080fd5b61256b611ea8565b825161257681612009565b8152602083015161258681612511565b6020820152604083015163ffffffff811681146125a257600080fd5b6040820152606083810151908201526080830151828111156125c357600080fd5b6125cf87828601612223565b60808301525095945050505050565b6000602082840312156125f057600080fd5b815180151581146112a857600080fd5b60ff81168114610e8e57600080fd5b60006020828403121561262157600080fd5b81356112a881612600565b60006020828403121561263e57600080fd5b81356112a881612511565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b038084168061267957612679612649565b92169190910492915050565b805168ffffffffffffffffff8116811461079357600080fd5b600060a082840312156126b057600080fd5b6126b8611ea8565b905081516126c581612600565b815260208201516126d581612600565b602082015260408201516126e881612511565b604082015260608201516126fb81612511565b6060820152608082015161270e81612511565b608082015292915050565b60006020828403121561272b57600080fd5b81516001600160401b038082111561274257600080fd5b90830190610140828603121561275757600080fd5b61275f611ed0565b825161276a81612009565b8152602083015162ffffff8116811461278257600080fd5b602082015261279360408401612685565b60408201526060830151828111156127aa57600080fd5b6127b687828601612223565b606083015250608083015160808201526127d38660a0850161269e565b60a082015295945050505050565b6000602082840312156127f357600080fd5b81516112a881612009565b60008351612810818460208801611e2f565b6101d160f51b908301908152835161282f816002840160208801611e2f565b01600201949350505050565b6000825161284d818460208701611e2f565b9190910192915050565b7f63616e6e6f7420737572726f67617465207374617469632063616c6c3a20307881526000825161288f816020850160208701611e2f565b9190910160200192915050565b600085516128ae818460208a01611e2f565b8551908301906128c2818360208a01611e2f565b85519101906128d5818360208901611e2f565b84519101906128e8818360208801611e2f565b019695505050505050565b7f63616e6e6f7420737572726f676174652063616c6c3a2030780000000000000081526000825161292b816019850160208701611e2f565b9190910160190192915050565b600060ff83168061294b5761294b612649565b8060ff84160491505092915050565b60ff818116838216019081111561068c5761068c6121ca565b600060ff83168061298657612986612649565b8060ff84160691505092915050565b8082018082111561068c5761068c6121ca56fea264697066735822122022f63e134e6a7b59b25710a186a72320f56adb8ccc2b1c3cd89efff75d7b322f64736f6c63430008110033