false
false

Contract Address Details

0x4374a050f808d1FF18bCcf73270daE3EdF8D0865

Contract Name
WitnetRequestFactoryDefault
Creator
0xbf58be–84de46 at 0x70af77–244511
Implementation
WitnetRequestFactoryDefault | 0x4374a050f808d1ff18bccf73270dae3edf8d0865
Balance
0 KCS ( )
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
44209916
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
WitnetRequestFactoryDefault




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




Optimization runs
200
EVM Version
london




Verified at
2023-08-01T09:39:02.841017Z

Constructor Arguments

0x0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc80000000000000000000000000000000000000000000000000000000000000001302e372e392d3636373030353600000000000000000000000000000000000000

Arg [0] (address) : 0x0000000e3a3d22d7510b36bdc88994dab11eadc8
Arg [1] (bool) : true
Arg [2] (bytes32) : 302e372e392d3636373030353600000000000000000000000000000000000000

              

/contracts/impls/core/WitnetRequestFactoryDefault.sol

// SPDX-License-Identifier: MIT

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

import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";

import "../../WitnetBytecodes.sol";
import "../../WitnetRequestFactory.sol";
import "../../data/WitnetRequestFactoryData.sol";
import "../../impls/WitnetUpgradableBase.sol";
import "../../patterns/Clonable.sol";
import "../../requests/WitnetRequest.sol";

contract WitnetRequestFactoryDefault
    is
        Clonable,
        WitnetRequest,
        WitnetRequestFactory,
        WitnetRequestFactoryData,
        WitnetUpgradableBase        
{
    using ERC165Checker for address;

    /// @notice Reference to Witnet Data Requests Bytecode Registry
    WitnetBytecodes immutable public override(IWitnetRequestFactory, WitnetRequestTemplate) registry;

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

    modifier onlyOnFactory {
        require(
            address(this) == __proxy()
                || address(this) == base(),
            "WitnetRequestFactoryDefault: not the factory"
        );
        _;
    }

    modifier onlyOnTemplates {
        require(
            __witnetRequestTemplate().tally != bytes32(0),
            "WitnetRequestFactoryDefault: not a WitnetRequestTemplate"
        );
        _;
    }

    constructor(
            WitnetBytecodes _registry,
            bool _upgradable,
            bytes32 _versionTag
        )
        WitnetUpgradableBase(
            _upgradable,
            _versionTag,
            "io.witnet.requests.factory"
        )
    {
        require(
            address(_registry).supportsInterface(type(WitnetBytecodes).interfaceId),
            "WitnetRequestFactoryDefault: uncompliant registry"
        );
        registry = _registry;
        // let logic contract be used as a factory, while avoiding further initializations:
        __proxiable().proxy = address(this);
        __proxiable().implementation = address(this);
        __witnetRequestFactory().owner = address(0);
    }

    function initializeWitnetRequestTemplate(
            bytes32[] calldata _retrievalsIds,
            bytes32 _aggregatorId,
            bytes32 _tallyId,
            uint16  _resultDataMaxSize
        )
        virtual public
        initializer
        returns (WitnetRequestTemplate)
    {
        // check that at least one retrieval is provided
        WitnetV2.RadonDataTypes _resultDataType;
        require(
            _retrievalsIds.length > 0,
            "WitnetRequestTemplate: no retrievals?"
        );
        // check that all retrievals exist in the registry,
        // and they all return the same data type
        bool _parameterized;
        for (uint _ix = 0; _ix < _retrievalsIds.length; _ix ++) {
            if (_ix == 0) {
                _resultDataType = registry.lookupRadonRetrievalResultDataType(_retrievalsIds[_ix]);
            } else {
                require(
                    _resultDataType == registry.lookupRadonRetrievalResultDataType(_retrievalsIds[_ix]),
                    "WitnetRequestTemplate: mismatching retrievals"
                );
            }
            if (!_parameterized) {
                // check whether at least one of the retrievals is parameterized
                _parameterized = registry.lookupRadonRetrievalArgsCount(_retrievalsIds[_ix]) > 0;
            }
        }
        // check that the aggregator and tally reducers actually exist in the registry
        registry.lookupRadonReducer(_aggregatorId);
        registry.lookupRadonReducer(_tallyId);
        {
            WitnetRequestTemplateSlot storage __data = __witnetRequestTemplate();
            __data.aggregator = _aggregatorId;
            __data.factory = WitnetRequestFactory(msg.sender);
            __data.parameterized = _parameterized;
            __data.resultDataType = _resultDataType;
            __data.resultDataMaxSize = _resultDataMaxSize;
            __data.retrievals = _retrievalsIds;
            __data.tally = _tallyId;
        }
        return WitnetRequestTemplate(address(this));
    }

    function initializeWitnetRequest(
            bytes32 _radHash,
            string[][] memory _args
        )
        virtual public
        initializer
        returns (address)
    {
        WitnetRequestSlot storage __data = __witnetRequest();
        __data.args = _args;
        __data.radHash = _radHash;
        __data.template = WitnetRequestTemplate(msg.sender);
        return address(this);
    }


    /// ===============================================================================================================
    /// --- IWitnetRequestFactory implementation ----------------------------------------------------------------------

    function buildRequestTemplate(
            bytes32[] memory _retrievals,
            bytes32 _aggregator,
            bytes32 _tally,
            uint16  _resultDataMaxSize
        )
        virtual override
        public
        onlyOnFactory
        returns (address _template)
    {
        bytes32 _salt = keccak256(
            // As to avoid template address collisions from:
            abi.encodePacked( 
                // - different factory major or mid versions:
                _WITNET_UPGRADABLE_VERSION,// TODO: once WitnetRequestTemplate interface is final: bytes4(_WITNET_UPGRADABLE_VERSION),
                // - different templates params:
                _retrievals, 
                _aggregator,
                _tally,
                _resultDataMaxSize
            )
        );
        _template = address(uint160(uint256(keccak256(
            abi.encodePacked(
                bytes1(0xff),
                address(this),
                _salt,
                keccak256(_cloneBytecode())
            )
        ))));
        if (_template.code.length == 0) {
            _template = address(WitnetRequestFactoryDefault(
                _cloneDeterministic(_salt)
            ).initializeWitnetRequestTemplate(
                _retrievals,
                _aggregator,
                _tally,
                _resultDataMaxSize
            ));
        }
        emit WitnetRequestTemplateBuilt(
            _template,
            WitnetRequestTemplate(_template).parameterized()
        );
    }

    function class() 
        virtual override(IWitnetRequestFactory, WitnetRequestTemplate)
        external view
        returns (bytes4)
    {
        if (
            address(this) == _SELF
                || address(this) == __proxy()
        ) {
            return type(WitnetRequestFactory).interfaceId;
        } else if (__witnetRequest().radHash != bytes32(0)) {
            return type(WitnetRequest).interfaceId;
        } else {
            return type(WitnetRequestTemplate).interfaceId;
        }
    }


    // ================================================================================================================
    // ---Overrides 'IERC165' -----------------------------------------------------------------------------------------

    /// @dev See {IERC165-supportsInterface}.
    function supportsInterface(bytes4 _interfaceId)
      public view
      virtual override
      returns (bool)
    {
        if (__witnetRequest().radHash != bytes32(0)) {
            return (
                _interfaceId == type(IWitnetRequest).interfaceId
                    || _interfaceId == type(WitnetRequest).interfaceId
                    || _interfaceId  == type(WitnetRequestTemplate).interfaceId
            );
        }
        else if (__witnetRequestTemplate().retrievals.length > 0) {
            return (_interfaceId == type(WitnetRequestTemplate).interfaceId);
        }
        else {
            return (
                _interfaceId == type(WitnetRequestFactory).interfaceId
                    || super.supportsInterface(_interfaceId)
            );
        }
    }


    // ================================================================================================================
    // --- Overrides 'Ownable2Step' -----------------------------------------------------------------------------------

    /// @notice Returns the address of the pending owner.
    function pendingOwner()
        public view
        virtual override
        returns (address)
    {
        return __witnetRequestFactory().pendingOwner;
    }

    /// @notice Returns the address of the current owner.
    function owner()
        public view
        virtual override
        returns (address)
    {
        return __witnetRequestFactory().owner;
    }

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

    /// @dev Transfers ownership of the contract to a new account (`_newOwner`) and deletes any pending owner.
    /// @dev Internal function without access restriction.
    function _transferOwnership(address _newOwner)
        internal
        virtual override
    {
        delete __witnetRequestFactory().pendingOwner;
        address _oldOwner = owner();
        if (_newOwner != _oldOwner) {
            __witnetRequestFactory().owner = _newOwner;
            emit OwnershipTransferred(_oldOwner, _newOwner);
        }
    }


    // ================================================================================================================
    // --- 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) 
        virtual override
        public
        onlyDelegateCalls
    {
        // WitnetRequest or WitnetRequestTemplate instances would already be initialized,
        // so only callable from proxies, in practice.

        address _owner = __witnetRequestFactory().owner;
        if (_owner == address(0)) {
            // set owner if none set yet
            _owner = msg.sender;
            __witnetRequestFactory().owner = _owner;
        } else {
            // only owner can initialize the proxy
            if (msg.sender != _owner) {
                revert WitnetUpgradableBase.OnlyOwner(_owner);
            }
        }

        if (__proxiable().proxy == address(0)) {
            // first initialization of the proxy
            __proxiable().proxy = address(this);
        }

        if (__proxiable().implementation != address(0)) {
            // same implementation cannot be initialized more than once:
            if(__proxiable().implementation == base()) {
                revert WitnetUpgradableBase.AlreadyUpgraded(base());
            }
        }        
        __proxiable().implementation = base();

        emit Upgraded(msg.sender, base(), codehash(), version());
    }

    /// Tells whether provided address could eventually upgrade the contract.
    function isUpgradableFrom(address _from) external view override returns (bool) {
        address _owner = __witnetRequestFactory().owner;
        return (
            // false if the WRB is intrinsically not upgradable, or `_from` is no owner
            isUpgradable()
                && _owner == _from
        );
    }


    // ================================================================================================================
    /// --- Clonable implementation and override ----------------------------------------------------------------------

    /// @notice Tells whether a WitnetRequest or a WitnetRequestTemplate has been properly initialized.
    /// @dev True only on WitnetRequest instances with some Radon SLA set.
    function initialized()
        virtual override(Clonable)
        public view
        returns (bool)
    {
        return (
            __witnetRequestTemplate().tally != bytes32(0)
                || __witnetRequest().radHash != bytes32(0)
        );
    }

    /// @notice Contract address to which clones will be re-directed.
    function self()
        virtual override
        public view
        returns (address)
    {
        return (__proxy() != address(0)
            ? __implementation()
            : base()
        );
    }


    /// ===============================================================================================================
    /// --- WitnetRequest implementation ------------------------------------------------------------------------------

    function bytecode()
        override
        external view
        returns (bytes memory)
    {
        return registry.bytecodeOf(__witnetRequest().radHash);
    }

    function template()
        override
        external view
        onlyDelegateCalls
        returns (WitnetRequestTemplate)
    {
        return __witnetRequest().template;
    }

    function args()
        override
        external view
        onlyDelegateCalls
        returns (string[][] memory)
    {
        return __witnetRequest().args;
    }

    function radHash()
        override
        external view
        onlyDelegateCalls
        returns (bytes32)
    {
        return __witnetRequest().radHash;
    }

    function version() 
        virtual override(WitnetRequestTemplate, WitnetUpgradableBase)
        public view
        returns (string memory)
    {
        return WitnetUpgradableBase.version();
    }


    /// ===============================================================================================================
    /// --- WitnetRequestTemplate implementation ----------------------------------------------------------------------

    function factory()
        override
        external view
        onlyDelegateCalls
        returns (WitnetRequestFactory)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.factory();
        } else {
            return __witnetRequestTemplate().factory;
        }
    }

    function aggregator()
        override
        external view
        onlyDelegateCalls
        returns (bytes32)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.aggregator();
        } else {
            return __witnetRequestTemplate().aggregator;
        }
    }

    function parameterized()
        override
        external view
        onlyDelegateCalls
        returns (bool)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.parameterized();
        } else {
            return __witnetRequestTemplate().parameterized;
        }
    }

    function resultDataMaxSize()
        override
        external view
        onlyDelegateCalls
        returns (uint16)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.resultDataMaxSize();
        } else {
            return __witnetRequestTemplate().resultDataMaxSize;
        }
    }

    function resultDataType() 
        override
        external view
        onlyDelegateCalls
        returns (WitnetV2.RadonDataTypes)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.resultDataType();
        } else {
            return __witnetRequestTemplate().resultDataType;
        }
    }

    function retrievals()
        override
        external view
        onlyDelegateCalls
        returns (bytes32[] memory)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.retrievals();
        } else {
            return __witnetRequestTemplate().retrievals;
        }

    }

    function tally()
        override
        external view
        onlyDelegateCalls
        returns (bytes32)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.tally();
        } else {
            return __witnetRequestTemplate().tally;
        }
    }

    function getRadonAggregator()
        override
        external view
        onlyDelegateCalls
        returns (WitnetV2.RadonReducer memory)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.getRadonAggregator();
        } else {
            return registry.lookupRadonReducer(
                __witnetRequestTemplate().aggregator
            );
        }
    }

    function getRadonRetrievalByIndex(uint256 _index) 
        override
        external view
        onlyDelegateCalls
        returns (WitnetV2.RadonRetrieval memory)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.getRadonRetrievalByIndex(_index);
        } else {
            require(
                _index < __witnetRequestTemplate().retrievals.length,
                "WitnetRequestTemplate: out of range"
            );
            return registry.lookupRadonRetrieval(
                __witnetRequestTemplate().retrievals[_index]
            );
        }
    }

    function getRadonRetrievalsCount() 
        override
        external view
        onlyDelegateCalls
        returns (uint256)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.getRadonRetrievalsCount();
        } else {
            return __witnetRequestTemplate().retrievals.length;
        }
    }

    function getRadonTally()
        override
        external view
        onlyDelegateCalls
        returns (WitnetV2.RadonReducer memory)
    {
        WitnetRequestTemplate _template = __witnetRequest().template;
        if (address(_template) != address(0)) {
            return _template.getRadonTally();
        } else {
            return registry.lookupRadonReducer(
                __witnetRequestTemplate().tally
            );
        }
    }

    function buildRequest(string[][] memory _args)
        virtual override
        public
        onlyDelegateCalls
        returns (address _request)
    {
        // if called on a WitnetRequest instance:
        if (address(__witnetRequest().template) != address(0)) {
            // ...surrogate to request's template
            return __witnetRequest().template.buildRequest(_args);
        }
        WitnetRequestTemplateSlot storage __data = __witnetRequestTemplate();
        bytes32 _radHash = registry.verifyRadonRequest(
            __data.retrievals,
            __data.aggregator,
            __data.tally,
            __data.resultDataMaxSize,
            _args
        );
        // the request address will be determined by the template's address,
        // the request's radHash and the factory's implementation version:
        bytes32 _salt;
        (_request, _salt) = _determineRequestAddressAndSalt(_radHash);
        if (_request.code.length == 0) {
            _request = WitnetRequestFactoryDefault(_cloneDeterministic(_salt))
                .initializeWitnetRequest(
                    _radHash,
                    _args
                );
        }
        emit WitnetRequestBuilt(_request, _radHash, _args);
    }

    function verifyRadonRequest(string[][] memory _args)
        virtual override
        public
        onlyDelegateCalls
        returns (bytes32 _radHash)
    {
        // if called on a WitnetRequest instance:
        if (address(__witnetRequest().template) != address(0)) {
            // ...surrogate to request's template
            return __witnetRequest().template.verifyRadonRequest(_args);
        }
        WitnetRequestTemplateSlot storage __data = __witnetRequestTemplate();
        _radHash = registry.verifyRadonRequest(
            __data.retrievals,
            __data.aggregator,
            __data.tally,
            __data.resultDataMaxSize,
            _args
        );
    }

    function _determineRequestAddressAndSalt(bytes32 _radHash)
        internal view
        returns (address, bytes32)
    {
        bytes32 _salt = keccak256(
            abi.encodePacked(
                _radHash, 
                bytes4(_WITNET_UPGRADABLE_VERSION)
            )
        );
        return (
            address(uint160(uint256(keccak256(
                abi.encodePacked(
                    bytes1(0xff),
                    address(this),
                    _salt,
                    keccak256(_cloneBytecode())
                )
            )))), _salt
        );
    }
}
        

/contracts/interfaces/V2/IWitnetRequestFactory.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "../../WitnetBytecodes.sol";

interface IWitnetRequestFactory {
    event WitnetRequestTemplateBuilt(address template, bool parameterized);
    function buildRequestTemplate(
            bytes32[] memory sourcesIds,
            bytes32 aggregatorId,
            bytes32 tallyId,
            uint16  resultDataMaxSize
        ) external returns (address template);
    function class() external view returns (bytes4);    
    function registry() external view returns (WitnetBytecodes);
}
          

/contracts/requests/WitnetRequest.sol

// SPDX-License-Identifier: MIT

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

import "./WitnetRequestTemplate.sol";

abstract contract WitnetRequest
    is
        WitnetRequestTemplate
{
    /// introspection methods
    function template() virtual external view returns (WitnetRequestTemplate);

    /// request-exclusive fields
    function args() virtual external view returns (string[][] memory);
    function bytecode() virtual external view returns (bytes memory);
    function radHash() virtual external view returns (bytes32);
}
          

@openzeppelin/contracts/utils/introspection/ERC165Checker.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/introspection/ERC165Checker.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface.
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return
            supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
            !supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
    }

    /**
     * @dev Returns a boolean array where each value corresponds to the
     * interfaces passed in and whether they're supported or not. This allows
     * you to batch check interfaces for a contract where your expectation
     * is that some interfaces may not be supported.
     *
     * See {IERC165-supportsInterface}.
     *
     * _Available since v3.4._
     */
    function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)
        internal
        view
        returns (bool[] memory)
    {
        // an array of booleans corresponding to interfaceIds and whether they're supported or not
        bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);

        // query support of ERC165 itself
        if (supportsERC165(account)) {
            // query support of each interface in interfaceIds
            for (uint256 i = 0; i < interfaceIds.length; i++) {
                interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
            }
        }

        return interfaceIdsSupported;
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
        // prepare call
        bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);

        // perform static call
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly {
            success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0x00)
        }

        return success && returnSize >= 0x20 && returnValue > 0;
    }
}
          

@openzeppelin/contracts/utils/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;
    }
}
          

/contracts/interfaces/V2/IWitnetBytecodes.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

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

interface IWitnetBytecodes {

    function bytecodeOf(bytes32 radHash) external view returns (bytes memory);
    function bytecodeOf(bytes32 radHash, bytes32 slahHash) external view returns (bytes memory);

    function hashOf(
            bytes32[] calldata sources,
            bytes32 aggregator,
            bytes32 tally,
            uint16 resultMaxSize,
            string[][] calldata args
        ) external pure returns (bytes32);
    function hashOf(bytes32 radHash, bytes32 slaHash) external pure returns (bytes32 drQueryHash);
    function hashWeightWitsOf(bytes32 radHash, bytes32 slaHash) external view returns (
            bytes32 drQueryHash,
            uint32  drQueryWeight,
            uint256 drQueryWits
        );

    function lookupDataProvider(uint256 index) external view returns (string memory, uint);
    function lookupDataProviderIndex(string calldata authority) external view returns (uint);
    function lookupDataProviderSources(uint256 index, uint256 offset, uint256 length) external view returns (bytes32[] memory);

    function lookupRadonReducer(bytes32 hash) external view returns (WitnetV2.RadonReducer memory);
    
    function lookupRadonRetrieval(bytes32 hash) external view returns (WitnetV2.RadonRetrieval memory);
    function lookupRadonRetrievalArgsCount(bytes32 hash) external view returns (uint8);
    function lookupRadonRetrievalResultDataType(bytes32 hash) external view returns (WitnetV2.RadonDataTypes);
    
    function lookupRadonRequestAggregator(bytes32 radHash) external view returns (WitnetV2.RadonReducer memory);
    function lookupRadonRequestResultMaxSize(bytes32 radHash) external view returns (uint256);
    function lookupRadonRequestResultDataType(bytes32 radHash) external view returns (WitnetV2.RadonDataTypes);
    function lookupRadonRequestSources(bytes32 radHash) external view returns (bytes32[] memory);
    function lookupRadonRequestSourcesCount(bytes32 radHash) external view returns (uint);
    function lookupRadonRequestTally(bytes32 radHash) external view returns (WitnetV2.RadonReducer memory);
    
    function lookupRadonSLA(bytes32 slaHash) external view returns (WitnetV2.RadonSLA memory);
    function lookupRadonSLAReward(bytes32 slaHash) external view returns (uint);
    
    function verifyRadonRetrieval(
            WitnetV2.DataRequestMethods requestMethod,
            string calldata requestSchema,
            string calldata requestAuthority,
            string calldata requestPath,
            string calldata requestQuery,
            string calldata requestBody,
            string[2][] calldata requestHeaders,
            bytes calldata requestRadonScript
        ) external returns (bytes32 hash);
    
    function verifyRadonReducer(WitnetV2.RadonReducer calldata reducer)
        external returns (bytes32 hash);
    
    function verifyRadonRequest(
            bytes32[] calldata sources,
            bytes32 aggregator,
            bytes32 tally,
            uint16 resultMaxSize,
            string[][] calldata args
        ) external returns (bytes32 radHash);
    
    function verifyRadonSLA(WitnetV2.RadonSLA calldata sla)
        external returns (bytes32 slaHash);

    function totalDataProviders() external view returns (uint);
   
}
          

/contracts/WitnetRequestFactory.sol

// SPDX-License-Identifier: MIT

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

import "./interfaces/V2/IWitnetRequestFactory.sol";

abstract contract WitnetRequestFactory
    is
        IWitnetRequestFactory
{}
          

/contracts/patterns/Ownable2Step.sol

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

@openzeppelin/contracts-upgradeable/utils/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);
        }
    }
}
          

/contracts/interfaces/IWitnetRequest.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title The Witnet Data Request basic interface.
/// @author The Witnet Foundation.
interface IWitnetRequest {
    
    /// @notice A `IWitnetRequest` is constructed around a `bytes` value containing 
    /// @notice a well-formed Witnet Data Request using Protocol Buffers.
    function bytecode() external view returns (bytes memory);

    /// @notice Returns SHA256 hash of Witnet Data Request as CBOR-encoded bytes.
    function hash() external view returns (bytes32);
}
          

/contracts/patterns/ERC165.sol

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

/contracts/requests/WitnetRequestTemplate.sol

// SPDX-License-Identifier: MIT

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

import "../WitnetRequestFactory.sol";

abstract contract WitnetRequestTemplate
{
    event WitnetRequestBuilt(address indexed request, bytes32 indexed radHash, string[][] args);

    function class() virtual external view returns (bytes4);
    function factory() virtual external view returns (WitnetRequestFactory);
    function registry() virtual external view returns (WitnetBytecodes);
    function version() virtual external view returns (string memory);

    function aggregator() virtual external view returns (bytes32);
    function parameterized() virtual external view returns (bool);
    function resultDataMaxSize() virtual external view returns (uint16);
    function resultDataType() virtual external view returns (WitnetV2.RadonDataTypes);
    function retrievals() virtual external view returns (bytes32[] memory);
    function tally() virtual external view returns (bytes32);
    
    function getRadonAggregator() virtual external view returns (WitnetV2.RadonReducer memory);
    function getRadonRetrievalByIndex(uint256) virtual external view returns (WitnetV2.RadonRetrieval memory);
    function getRadonRetrievalsCount() virtual external view returns (uint256);
    function getRadonTally() virtual external view returns (WitnetV2.RadonReducer memory);
    
    function buildRequest(string[][] calldata args) virtual external returns (address);
    function verifyRadonRequest(string[][] calldata args) virtual external returns (bytes32);
}
          

/contracts/patterns/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
        }
    }
}
          

@openzeppelin/contracts-upgradeable/proxy/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;
    }
}
          

/contracts/interfaces/V2/IWitnetBytecodesEvents.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

interface IWitnetBytecodesEvents {    
    event NewDataProvider(uint256 index);
    event NewRadonRetrievalHash(bytes32 hash);
    event NewRadonReducerHash(bytes32 hash);
    event NewRadHash(bytes32 hash);
    event NewSlaHash(bytes32 hash);
}
          

/contracts/data/WitnetRequestFactoryData.sol

// SPDX-License-Identifier: MIT

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

import "../requests/WitnetRequest.sol";

contract WitnetRequestFactoryData {

    bytes32 internal constant _WITNET_REQUEST_SLOTHASH =
        /* keccak256("io.witnet.data.request") */
        0xbf9e297db5f64cdb81cd821e7ad085f56008e0c6100f4ebf5e41ef6649322034;

    bytes32 internal constant _WITNET_REQUEST_FACTORY_SLOTHASH =
        /* keccak256("io.witnet.data.request.factory") */
        0xfaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e642;

    bytes32 internal constant _WITNET_REQUEST_TEMPLATE_SLOTHASH =
        /* keccak256("io.witnet.data.request.template") */
        0x50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afb;

    struct Slot {
        address owner;
        address pendingOwner;
    }

    struct WitnetRequestSlot {
        /// Array of string arguments passed upon initialization.
        string[][] args;
        /// Radon RAD hash.
        bytes32 radHash;
        /// Parent WitnetRequestTemplate contract.
        WitnetRequestTemplate template;
    }

    struct WitnetRequestTemplateSlot {
        /// @notice Aggregator reducer hash.
        bytes32 aggregator;
        /// @notice Parent IWitnetRequestFactory from which this template was built.
        WitnetRequestFactory factory;
        /// Whether any of the sources is parameterized.
        bool parameterized;
        /// @notice Tally reducer hash.
        bytes32 tally;
        /// @notice Array of retrievals hashes passed upon construction.
        bytes32[] retrievals;
        /// @notice Result data type.
        WitnetV2.RadonDataTypes resultDataType;
        /// @notice Result max size or rank (if variable type).
        uint16 resultDataMaxSize; 
    }

    function __witnetRequestFactory()
        internal pure
        returns (Slot storage ptr)
    {
        assembly {
            ptr.slot := _WITNET_REQUEST_FACTORY_SLOTHASH
        }
    }

    function __witnetRequest()
        internal pure
        returns (WitnetRequestSlot storage ptr)
    {
        assembly {
            ptr.slot := _WITNET_REQUEST_SLOTHASH
        }
    }

    function __witnetRequestTemplate()
        internal pure
        returns (WitnetRequestTemplateSlot storage ptr)
    {
        assembly {
            ptr.slot := _WITNET_REQUEST_TEMPLATE_SLOTHASH
        }
    }
}
          

/contracts/libs/Witnet.sol

// SPDX-License-Identifier: MIT

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

import "../interfaces/IWitnetRequest.sol";
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 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 Witnet-provided response metadata and 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, 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Script format errors =============================================================================================
            /// 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,
            /// Unallocated
            ScriptFormat0x04, ScriptFormat0x05, ScriptFormat0x06, ScriptFormat0x07, ScriptFormat0x08, ScriptFormat0x09,
            ScriptFormat0x0A, ScriptFormat0x0B, ScriptFormat0x0C, ScriptFormat0x0D, ScriptFormat0x0E, ScriptFormat0x0F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Complexity errors ================================================================================================
            /// 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,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Operator errors ===================================================================================================
            /// 0x20: The operator does not exist.
            UnsupportedOperator,
            /// Unallocated
            Operator0x21, Operator0x22, Operator0x23, Operator0x24, Operator0x25, Operator0x26, Operator0x27, Operator0x28,
            Operator0x29, Operator0x2A, Operator0x2B, Operator0x2C, Operator0x2D, Operator0x2E, Operator0x2F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Retrieval-specific errors =========================================================================================
            /// 0x30: At least one of the sources could not be retrieved, but returned HTTP error.
            HTTP,
            /// 0x31: Retrieval of at least one of the sources timed out.
            RetrievalTimeout,
            /// Unallocated
            Retrieval0x32, Retrieval0x33, Retrieval0x34, Retrieval0x35, Retrieval0x36, Retrieval0x37, Retrieval0x38, 
            Retrieval0x39, Retrieval0x3A, Retrieval0x3B, Retrieval0x3C, Retrieval0x3D, Retrieval0x3E, Retrieval0x3F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Math errors =======================================================================================================
            /// 0x40: Math operator caused an underflow.
            Underflow,
            /// 0x41: Math operator caused an overflow.
            Overflow,
            /// 0x42: Tried to divide by zero.
            DivisionByZero,
            /// Unallocated
            Math0x43, Math0x44, Math0x45, Math0x46, Math0x47, Math0x48, Math0x49, 
            Math0x4A, Math0x4B, Math0x4C, Math0x4D, Math0x4E, Math0x4F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Other errors ======================================================================================================
            /// 0x50: Received zero reveals
            NoReveals,
            /// 0x51: Insufficient consensus in tally precondition clause
            InsufficientConsensus,
            /// 0x52: Received zero commits
            InsufficientCommits,
            /// 0x53: Generic error during tally execution
            TallyExecution,
            /// Unallocated
            OtherError0x54, OtherError0x55, OtherError0x56, OtherError0x57, OtherError0x58, OtherError0x59,
            OtherError0x5A, OtherError0x5B, OtherError0x5C, OtherError0x5D, OtherError0x5E, OtherError0x5F,
            /// 0x60: Invalid reveal serialization (malformed reveals are converted to this value)
            MalformedReveal,
            /// Unallocated
            OtherError0x61, OtherError0x62, OtherError0x63, OtherError0x64, OtherError0x65, OtherError0x66,
            OtherError0x67, OtherError0x68, OtherError0x69, OtherError0x6A, OtherError0x6B, OtherError0x6C,
            OtherError0x6D, OtherError0x6E,OtherError0x6F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Access errors =====================================================================================================
            /// 0x70: Tried to access a value from an array using an index that is out of bounds
            ArrayIndexOutOfBounds,
            /// 0x71: Tried to access a value from a map using a key that does not exist
            MapKeyNotFound,
            /// Unallocated
            OtherError0x72, 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,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Bridge errors: errors that only belong in inter-client communication ==============================================
            /// 0xE0: Requests that cannot be parsed must always get this error as their result.
            /// However, this is not a valid result in a Tally transaction, because invalid requests
            /// are never included into blocks and therefore never get a Tally in response.
            BridgeMalformedRequest,
            /// 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
            BridgeOversizedResult,
            /// 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 should
        UnhandledIntercept
    }


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

    modifier _isError(Result memory result) {
        require(!result.success, "Witnet: no actual errors");
        _;
    }

    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();
    }


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

    /// @dev Witnet function that computes the hash of a CBOR-encoded Data Request.
    function hash(bytes memory _bytecode) internal view returns (bytes32) {
        if (
            block.chainid != 1101           // Polygon zkEVM mainnet
                && block.chainid != 1442    // Polygon zkEVM testnet
        ) {
            return sha256(_bytecode);
        } else {
            return keccak256(_bytecode);
        }
    }

    /// @dev Transform given bytes into a Witnet.Result instance.
    /// @param bytecode Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory bytecode)
        internal pure
        returns (Witnet.Result memory)
    {
        WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(bytecode);
        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);
            }
        }
    }


    /// ===============================================================================================================
    /// --- '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);
        }   
    }


    /// ===============================================================================================================
    /// --- 'uint8' 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);
    }


    /// ===============================================================================================================
    /// --- 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 ++;
            }
        }
    }
}
          

/contracts/libs/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);
    }
  }
 
}
          

@openzeppelin/contracts/access/Ownable2Step.sol

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

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.
 *
 * By default, the owner account will be the one that deploys the contract. 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() external {
        address sender = _msgSender();
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
        _transferOwnership(sender);
    }
}
          

@openzeppelin/contracts/utils/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);
}
          

/contracts/libs/WitnetV2.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./Witnet.sol";

library WitnetV2 {

    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(uint expected, uint actual);
    error RadonRequestMissingArgs(uint index, uint expected, uint actual);
    error RadonRequestResultsMismatch(uint index, uint8 read, uint8 expected);
    error RadonRequestTooHeavy(bytes bytecode, uint 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);

    function toEpoch(uint _timestamp) internal pure returns (uint) {
        return 1 + (_timestamp - 11111) / 15;
    }

    function toTimestamp(uint _epoch) internal pure returns (uint) {
        return 111111+ _epoch * 15;
    }

    struct Beacon {
        uint256 escrow;
        uint256 evmBlock;
        uint256 gasprice;
        address relayer;
        address slasher;
        uint256 superblockIndex;
        uint256 superblockRoot;        
    }

    enum BeaconStatus {
        Idle
    }

    struct Block {
        bytes32 blockHash;
        bytes32 drTxsRoot;
        bytes32 drTallyTxsRoot;
    }
    
    enum BlockStatus {
        Idle
    }

    struct DrPost {
        uint256 block;
        DrPostStatus status;
        DrPostRequest request;
        DrPostResponse response;
    }
    
    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct DrPostRequest {
        uint256 epoch;
        address requester;
        address reporter;
        bytes32 radHash;
        bytes32 slaHash;
        uint256 weiReward;
    }

    /// Data kept in EVM-storage containing Witnet-provided response metadata and result.
    struct DrPostResponse {
        address disputer;
        address reporter;
        uint256 escrowed;
        uint256 drCommitTxEpoch;
        uint256 drTallyTxEpoch;
        bytes32 drTallyTxHash;
        bytes   drTallyResultCborBytes;
    }

    enum DrPostStatus {
        Void,
        Deleted,
        Expired,
        Posted,
        Disputed,
        Reported,
        Finalized,
        Accepted,
        Rejected
    }

    struct DataProvider {
        string  authority;
        uint256 totalEndpoints;
        mapping (uint256 => bytes32) endpoints;
    }

    enum DataRequestMethods {
        /* 0 */ Unknown,
        /* 1 */ HttpGet,
        /* 2 */ Rng,
        /* 3 */ HttpPost
    }

    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
    }

    struct RadonFilter {
        RadonFilterOpcodes opcode;
        bytes args;
    }

    enum RadonFilterOpcodes {
        /* 0x00 */ GreaterThan,
        /* 0x01 */ LessThan,
        /* 0x02 */ Equals,
        /* 0x03 */ AbsoluteDeviation,
        /* 0x04 */ RelativeDeviation,
        /* 0x05 */ StandardDeviation,
        /* 0x06 */ Top,
        /* 0x07 */ Bottom,
        /* 0x08 */ Mode,
        /* 0x09 */ LessOrEqualThan
    }

    struct RadonReducer {
        RadonReducerOpcodes opcode;
        RadonFilter[] filters;
        bytes script;
    }

    enum RadonReducerOpcodes {
        /* 0x00 */ Minimum,
        /* 0x01 */ Maximum,
        /* 0x02 */ Mode,
        /* 0x03 */ AverageMean,
        /* 0x04 */ AverageMeanWeighted,
        /* 0x05 */ AverageMedian,
        /* 0x06 */ AverageMedianWeighted,
        /* 0x07 */ StandardDeviation,
        /* 0x08 */ AverageDeviation,
        /* 0x09 */ MedianDeviation,
        /* 0x0A */ MaximumDeviation,
        /* 0x0B */ ConcatenateAndHash
    }

    struct RadonRetrieval {
        uint8 argsCount;
        DataRequestMethods method;
        RadonDataTypes resultDataType;
        string url;
        string body;
        string[2][] headers;
        bytes script;
    }

    struct RadonSLA {
        uint numWitnesses;
        uint minConsensusPercentage;
        uint witnessReward;
        uint witnessCollateral;
        uint minerCommitRevealFee;
    }

    /// @notice Returns `true` if all witnessing parameters in `b` have same
    /// @notice value or greater than the ones in `a`.
    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
        );
    }

}
          

/contracts/impls/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 ++;
            }
        }
    }

}
          

/contracts/libs/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))
        }
      }
    }
  }

}
          

/contracts/impls/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
        }
    }

}
          

/contracts/patterns/ReentrancyGuard.sol

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

/contracts/patterns/Initializable.sol

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

@openzeppelin/contracts/access/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);
    }
}
          

/contracts/patterns/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); 
}
          

@openzeppelin/contracts/security/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;
    }
}
          

/contracts/interfaces/V2/IWitnetBytecodesErrors.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

interface IWitnetBytecodesErrors {
    error UnknownRadonRetrieval(bytes32 hash);
    error UnknownRadonReducer(bytes32 hash);
    error UnknownRadonRequest(bytes32 hash);
    error UnknownRadonSLA(bytes32 hash);  
}
          

/contracts/WitnetBytecodes.sol

// SPDX-License-Identifier: MIT

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

import "./interfaces/V2/IWitnetBytecodes.sol";
import "./interfaces/V2/IWitnetBytecodesErrors.sol";
import "./interfaces/V2/IWitnetBytecodesEvents.sol";

abstract contract WitnetBytecodes
    is
        IWitnetBytecodes,
        IWitnetBytecodesErrors,
        IWitnetBytecodesEvents
{}
          

@openzeppelin/contracts/utils/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;
    }
}
          

/contracts/patterns/Clonable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

import "./Initializable.sol";

abstract contract Clonable
    is
        Initializable
{
    address immutable internal _SELF = address(this);

    event Cloned(address indexed by, address indexed self, address indexed clone);

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

    modifier wasInitialized {
        require(initialized(), "Clonable: not initialized");
        _;
    }

    /// @notice Tells whether this contract is a clone of `self()`
    function cloned()
        public view
        returns (bool)
    {
        return (
            address(this) != self()
        );
    }

    /// @notice Tells whether this instance has been initialized.
    function initialized() virtual public view returns (bool);

    /// @notice Contract address to which clones will be re-directed.
    function self() virtual public view returns (address) {
        return _SELF;
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract
    /// behaviour while using its own EVM storage.
    /// @dev This function should always provide a new address, no matter how many times 
    /// @dev is actually called from the same `msg.sender`.
    /// @dev See https://eips.ethereum.org/EIPS/eip-1167.
    /// @dev See https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/.
    function _clone()
        internal
        returns (address _instance)
    {
        bytes memory ptr = _cloneBytecodePtr();
        assembly {
            // CREATE new instance:
            _instance := create(0, ptr, 0x37)
        }        
        require(_instance != address(0), "Clonable: CREATE failed");
        emit Cloned(msg.sender, self(), _instance);
    }

    /// @notice Returns minimal proxy's deploy bytecode.
    function _cloneBytecode()
        virtual internal view
        returns (bytes memory)
    {
        return abi.encodePacked(
            hex"3d602d80600a3d3981f3363d3d373d3d3d363d73",
            bytes20(self()),
            hex"5af43d82803e903d91602b57fd5bf3"
        );
    }

    /// @notice Returns mem pointer to minimal proxy's deploy bytecode.
    function _cloneBytecodePtr()
        virtual internal view
        returns (bytes memory ptr)
    {
        address _base = self();
        assembly {
            // ptr to free mem:
            ptr := mload(0x40)
            // begin minimal proxy construction bytecode:
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            // make minimal proxy delegate all calls to `self()`:
            mstore(add(ptr, 0x14), shl(0x60, _base))
            // end minimal proxy construction bytecode:
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
        }
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract 
    /// behaviour while using its own EVM storage.
    /// @dev This function uses the CREATE2 opcode and a `_salt` to deterministically deploy
    /// @dev the clone. Using the same `_salt` multiple times will revert, since
    /// @dev no contract can be deployed more than once at the same address.
    /// @dev See https://eips.ethereum.org/EIPS/eip-1167.
    /// @dev See https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/.
    function _cloneDeterministic(bytes32 _salt)
        virtual internal
        returns (address _instance)
    {
        bytes memory ptr = _cloneBytecodePtr();
        assembly {
            // CREATE2 new instance:
            _instance := create2(0, ptr, 0x37, _salt)
        }
        require(_instance != address(0), "Clonable: CREATE2 failed");
        emit Cloned(msg.sender, self(), _instance);
    }
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{},"evmVersion":"london"}
              

Contract ABI

[{"type":"constructor","inputs":[{"type":"address","name":"_registry","internalType":"contract WitnetBytecodes"},{"type":"bool","name":"_upgradable","internalType":"bool"},{"type":"bytes32","name":"_versionTag","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"aggregator","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string[][]","name":"","internalType":"string[][]"}],"name":"args","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"base","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"_request","internalType":"address"}],"name":"buildRequest","inputs":[{"type":"string[][]","name":"_args","internalType":"string[][]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"_template","internalType":"address"}],"name":"buildRequestTemplate","inputs":[{"type":"bytes32[]","name":"_retrievals","internalType":"bytes32[]"},{"type":"bytes32","name":"_aggregator","internalType":"bytes32"},{"type":"bytes32","name":"_tally","internalType":"bytes32"},{"type":"uint16","name":"_resultDataMaxSize","internalType":"uint16"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes","name":"","internalType":"bytes"}],"name":"bytecode","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"class","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"cloned","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"codehash","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetRequestFactory"}],"name":"factory","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct WitnetV2.RadonReducer","components":[{"type":"uint8"},{"type":"tuple[]","components":[{"type":"uint8"},{"type":"bytes"}]},{"type":"bytes"}]}],"name":"getRadonAggregator","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct WitnetV2.RadonRetrieval","components":[{"type":"uint8"},{"type":"uint8"},{"type":"uint8"},{"type":"string"},{"type":"string"},{"type":"string[2][]"},{"type":"bytes"}]}],"name":"getRadonRetrievalByIndex","inputs":[{"type":"uint256","name":"_index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRadonRetrievalsCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct WitnetV2.RadonReducer","components":[{"type":"uint8"},{"type":"tuple[]","components":[{"type":"uint8"},{"type":"bytes"}]},{"type":"bytes"}]}],"name":"getRadonTally","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"initializeWitnetRequest","inputs":[{"type":"bytes32","name":"_radHash","internalType":"bytes32"},{"type":"string[][]","name":"_args","internalType":"string[][]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"","internalType":"contract WitnetRequestTemplate"}],"name":"initializeWitnetRequestTemplate","inputs":[{"type":"bytes32[]","name":"_retrievalsIds","internalType":"bytes32[]"},{"type":"bytes32","name":"_aggregatorId","internalType":"bytes32"},{"type":"bytes32","name":"_tallyId","internalType":"bytes32"},{"type":"uint16","name":"_resultDataMaxSize","internalType":"uint16"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"initialized","inputs":[]},{"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":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"parameterized","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":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"radHash","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetBytecodes"}],"name":"registry","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint16","name":"","internalType":"uint16"}],"name":"resultDataMaxSize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"enum WitnetV2.RadonDataTypes"}],"name":"resultDataType","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"","internalType":"bytes32[]"}],"name":"retrievals","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"self","inputs":[]},{"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":"bytes32","name":"","internalType":"bytes32"}],"name":"tally","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetRequestTemplate"}],"name":"template","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"_newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"_radHash","internalType":"bytes32"}],"name":"verifyRadonRequest","inputs":[{"type":"string[][]","name":"_args","internalType":"string[][]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"version","inputs":[]},{"type":"event","name":"Cloned","inputs":[{"type":"address","name":"by","indexed":true},{"type":"address","name":"self","indexed":true},{"type":"address","name":"clone","indexed":true}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferStarted","inputs":[{"type":"address","name":"previousOwner","indexed":true},{"type":"address","name":"newOwner","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","indexed":true},{"type":"address","name":"newOwner","indexed":true}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"from","indexed":true},{"type":"address","name":"baseAddr","indexed":true},{"type":"bytes32","name":"baseCodehash","indexed":true},{"type":"string","name":"versionTag","indexed":false}],"anonymous":false},{"type":"event","name":"WitnetRequestBuilt","inputs":[{"type":"address","name":"request","indexed":true},{"type":"bytes32","name":"radHash","indexed":true},{"type":"string[][]","name":"args","indexed":false}],"anonymous":false},{"type":"event","name":"WitnetRequestTemplateBuilt","inputs":[{"type":"address","name":"template","indexed":false},{"type":"bool","name":"parameterized","indexed":false}],"anonymous":false},{"type":"error","name":"AlreadyUpgraded","inputs":[{"type":"address","name":"implementation","internalType":"address"}]},{"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":"fallback"}]
              

Contract Creation Code

0x610160604052306080523480156200001657600080fd5b50604051620046f0380380620046f083398101604081905262000039916200038b565b81816040518060400160405280601a81526020017f696f2e7769746e65742e72657175657374732e666163746f7279000000000000815250826200008c62000086620001cd60201b60201c565b620001d1565b3060a08190523f60c052151560e052600160025561010091909152805160209182012061012052620000d691506001600160a01b038516906000906200281b6200029f821b17901c565b620001415760405162461bcd60e51b815260206004820152603160248201527f5769746e657452657175657374466163746f727944656661756c743a20756e636044820152706f6d706c69616e7420726567697374727960781b606482015260840160405180910390fd5b50506001600160a01b0316610140527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd8054306001600160a01b031991821681179092557f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80548216909217909155600080516020620046d083398151915280549091169055620003e2565b3390565b7ffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e64380546001600160a01b0319169055600062000223600080516020620046d0833981519152546001600160a01b031690565b9050806001600160a01b0316826001600160a01b0316146200029b5781600080516020620046d083398151915280546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35b5050565b6000620002ac83620002c7565b8015620002c05750620002c0838362000300565b9392505050565b6000620002dc826301ffc9a760e01b62000300565b8015620002fa5750620002f8826001600160e01b031962000300565b155b92915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d9150600051905082801562000373575060208210155b8015620003805750600081115b979650505050505050565b600080600060608486031215620003a157600080fd5b83516001600160a01b0381168114620003b957600080fd5b60208501519093508015158114620003d057600080fd5b80925050604084015190509250925092565b60805160a05160c05160e05161010051610120516101405161419062000540600039600081816104560152818161083201528181610d1e015281816116010152818161187801528181611b2901528181611bd701528181611d0b01528181611de001528181611e6e0152818161211001526126fa015260006103c1015260008181612500015281816128b20152612a1c0152600081816103e5015261135e0152600081816104a5015261106b0152600081816103840152818161063201528181610748015281816108bf0152818161091a015281816109fa01528181610ab601528181610bd801528181610da101528181610e5b01528181610f9401528181610ff10152818161103b015281816110da015281816111d6015281816113ac01528181611420015281816114e8015281816117b60152818161190001528181611ffa0152818161223e0152612479015260006121b801526141906000f3fe608060405234801561001057600080fd5b50600436106102325760003560e01c80637104ddb211610130578063b0a41769116100b8578063d7e28aab1161007c578063d7e28aab1461052d578063db7c58b014610540578063e30c397814610553578063f09400021461055b578063f2fde38b1461056357610232565b8063b0a41769146104c9578063b42608da146104de578063bf7a0bd3146104f1578063bff852fa14610504578063c45a01551461052557610232565b80637d18db51116100ff5780637d18db51146104785780638ae940e11461048b5780638da5cb5b14610493578063a04daef01461049b578063a9e954b9146104a357610232565b80637104ddb214610439578063715018a61461044157806379ba5097146104495780637b1039991461045157610232565b8063410673e5116101be57806352d1902d1161018257806352d1902d146103bc5780635479d940146103e357806354fd4d50146104095780636b58960a1461041e5780636f2ddd931461043157610232565b8063410673e514610348578063439fab91146103505780634843f06c146103655780634e9b75b61461036d5780635001f3b51461038257610232565b80631eef9052116102055780631eef9052146102ed578063245a7bfc14610303578063265e84391461030b57806326f8a6d314610313578063341e11c81461032857610232565b806301ffc9a71461028d57806309e50249146102b557806310d02e47146102d0578063158ef93e146102e5575b60405162461bcd60e51b815260206004820152602560248201527f5769746e657455706772616461626c65426173653a206e6f7420696d706c656d604482015264195b9d195960da1b60648201526084015b60405180910390fd5b6102a061029b366004612f81565b610576565b60405190151581526020015b60405180910390f35b6102bd610626565b60405161ffff90911681526020016102ac565b6102d8610719565b6040516102ac9190613011565b6102a0610882565b6102f56108b3565b6040519081526020016102ac565b6102f561090e565b6102f56109ee565b61031b610aaa565b6040516102ac91906130eb565b61033b6103363660046130f9565b610b8d565b6040516102ac91906131a5565b6102f5610d95565b61036361035e366004613365565b610e51565b005b6102a06110ce565b6103756111ca565b6040516102ac919061344d565b7f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b0390911681526020016102ac565b6102f57f000000000000000000000000000000000000000000000000000000000000000081565b7f00000000000000000000000000000000000000000000000000000000000000006102a0565b610411611336565b6040516102ac9190613460565b6102a061042c366004613488565b611340565b6103a46113a0565b6103a4611404565b61036361144a565b61036361145e565b6103a47f000000000000000000000000000000000000000000000000000000000000000081565b6103a46104863660046135d9565b6114dc565b6102d8611787565b6103a46118af565b6102a06118d0565b7f00000000000000000000000000000000000000000000000000000000000000006102f5565b6104d16118f4565b6040516102ac9190613648565b6103a46104ec366004613676565b611a24565b6102f56104ff3660046135d9565b611fee565b61050c6121ab565b6040516001600160e01b031990911681526020016102ac565b6103a4612232565b6103a461053b36600461370f565b61232d565b6103a461054e366004613755565b61244a565b6103a46126d2565b6104116126f6565b610363610571366004613488565b612796565b600080610581612837565b60010154146105da576001600160e01b03198216637c94ad3160e11b14806105b957506001600160e01b0319821663cfcd387560e01b145b806105d457506001600160e01b0319821663acf2473560e01b145b92915050565b60008051602061409b833981519152541561060657506001600160e01b03191663acf2473560e01b1490565b6001600160e01b0319821615806105d457506105d48261285b565b919050565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036106705760405162461bcd60e51b815260040161028490613807565b600061067a612837565b600201546001600160a01b0316905080156106f757806001600160a01b03166309e502496040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613857565b91505090565b505060008051602061411b83398151915254610100900461ffff1690565b5090565b61073e6040805160608101909152806000815260200160608152602001606081525090565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036107865760405162461bcd60e51b815260040161028490613807565b6000610790612837565b600201546001600160a01b03169050801561080b57806001600160a01b03166310d02e476040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107e3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106f191908101906138b9565b6000805160206140fb83398151915254604051630d9e7e1960e21b815260048101919091527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690633679f864906024015b600060405180830381865afa1580156107e3573d6000803e3d6000fd5b6000805160206140bb833981519152546000901515806108ae575060006108a7612837565b6001015414155b905090565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036108fd5760405162461bcd60e51b815260040161028490613807565b610905612837565b60010154905090565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036109585760405162461bcd60e51b815260040161028490613807565b6000610962612837565b600201546001600160a01b0316905080156109d957806001600160a01b031663245a7bfc6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613a1a565b50506000805160206140fb8339815191525490565b60006001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610a385760405162461bcd60e51b815260040161028490613807565b6000610a42612837565b600201546001600160a01b031690508015610a9557806001600160a01b031663265e84396040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b505060008051602061409b8339815191525490565b60006001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610af45760405162461bcd60e51b815260040161028490613807565b6000610afe612837565b600201546001600160a01b031690508015610b7557806001600160a01b03166326f8a6d36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b51573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613a42565b505060008051602061411b8339815191525460ff1690565b610bce6040805160e0810190915260008082526020820190815260200160008152602001606081526020016060815260200160608152602001606081525090565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610c165760405162461bcd60e51b815260040161028490613807565b6000610c20612837565b600201546001600160a01b031690508015610caa57604051630683c23960e31b8152600481018490526001600160a01b0382169063341e11c8906024015b600060405180830381865afa158015610c7b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ca39190810190613b5b565b9392505050565b60008051602061409b833981519152548310610d145760405162461bcd60e51b815260206004820152602360248201527f5769746e65745265717565737454656d706c6174653a206f7574206f662072616044820152626e676560e81b6064820152608401610284565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016639dd487576000805160206140fb8339815191526003018581548110610d6657610d66613c66565b90600052602060002001546040518263ffffffff1660e01b8152600401610c5e91815260200190565b50919050565b60006001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610ddf5760405162461bcd60e51b815260040161028490613807565b6000610de9612837565b600201546001600160a01b031690508015610e3c57806001600160a01b031663410673e56040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b50506000805160206140bb8339815191525490565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610e995760405162461bcd60e51b815260040161028490613807565b60008051602061413b833981519152546001600160a01b031680610edf575060008051602061413b83398151915280546001600160a01b03191633908117909155610f13565b336001600160a01b03821614610f1357604051630543601560e11b81526001600160a01b0382166004820152602401610284565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd546001600160a01b0316610f74577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd80546001600160a01b031916301790555b6000805160206140db833981519152546001600160a01b03161561101e577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166000805160206140db833981519152546001600160a01b03160361101e576040516339cf62f760e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166004820152602401610284565b6000805160206140db83398151915280546001600160a01b0319167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169081179091557f000000000000000000000000000000000000000000000000000000000000000090337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f66110b5611336565b6040516110c29190613460565b60405180910390a45050565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036111185760405162461bcd60e51b815260040161028490613807565b6000611122612837565b600201546001600160a01b03169050801561119957806001600160a01b0316634843f06c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611175573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613c7c565b50507f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc54600160a01b900460ff1690565b60606001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036112145760405162461bcd60e51b815260040161028490613807565b61121c612837565b80546040805160208084028201810190925282815292919060009084015b8282101561132d57838290600052602060002001805480602002602001604051908101604052809291908181526020016000905b8282101561131a57838290600052602060002001805461128d90613c9e565b80601f01602080910402602001604051908101604052809291908181526020018280546112b990613c9e565b80156113065780601f106112db57610100808354040283529160200191611306565b820191906000526020600020905b8154815290600101906020018083116112e957829003601f168201915b50505050508152602001906001019061126e565b505050508152602001906001019061123a565b50505050905090565b60606108ae6128ab565b60008051602061413b833981519152546000906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000008015610ca35750826001600160a01b0316816001600160a01b0316149392505050565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036113ea5760405162461bcd60e51b815260040161028490613807565b6113f2612837565b600201546001600160a01b0316905090565b60008061140f6128d6565b6001600160a01b03160361144257507f000000000000000000000000000000000000000000000000000000000000000090565b6108ae6128ec565b611452612902565b61145c6000612961565b565b33806114686126d2565b6001600160a01b0316146114d05760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610284565b6114d981612961565b50565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036115265760405162461bcd60e51b815260040161028490613807565b6000611530612837565b600201546001600160a01b0316146115be5761154a612837565b60020154604051637d18db5160e01b81526001600160a01b0390911690637d18db519061157b90859060040161344d565b6020604051808303816000875af115801561159a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d49190613cd2565b6000805160206140fb83398151915280546000805160206140bb8339815191525460008051602061411b8339815191525460405163a4a7cecd60e01b81526000937f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169363a4a7cecd9361165a9360008051602061409b833981519152939291610100900461ffff16908b90600401613cef565b6020604051808303816000875af1158015611679573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169d9190613a1a565b905060006116aa82612a14565b90945090506001600160a01b0384163b60000361173d576116ca81612abf565b6001600160a01b031663d7e28aab83876040518363ffffffff1660e01b81526004016116f7929190613d67565b6020604051808303816000875af1158015611716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173a9190613cd2565b93505b81846001600160a01b03167f410c7975f3418de1a871bdcb16ea6c438f6a6c1e5799e704d4e32f53a405f22987604051611777919061344d565b60405180910390a3505050919050565b6117ac6040805160608101909152806000815260200160608152602001606081525090565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036117f45760405162461bcd60e51b815260040161028490613807565b60006117fe612837565b600201546001600160a01b03169050801561185157806001600160a01b0316638ae940e16040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107e3573d6000803e3d6000fd5b6000805160206140bb83398151915254604051630d9e7e1960e21b815260048101919091527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690633679f86490602401610865565b600060008051602061413b8339815191525b546001600160a01b0316919050565b60006118da611404565b6001600160a01b0316306001600160a01b03161415905090565b60606001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361193e5760405162461bcd60e51b815260040161028490613807565b6000611948612837565b600201546001600160a01b0316905080156119c357806001600160a01b031663b0a417696040518163ffffffff1660e01b8152600401600060405180830381865afa15801561199b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106f19190810190613d80565b60008051602061409b833981519152805460408051602080840282018101909252828152929190830182828015611a1957602002820191906000526020600020905b815481526020019060010190808311611a05575b505050505091505090565b600154600090600160a81b900460ff1615808015611a4d575060018054600160a01b900460ff16105b80611a6d5750303b158015611a6d575060018054600160a01b900460ff16145b611a895760405162461bcd60e51b815260040161028490613e05565b6001805460ff60a01b1916600160a01b1790558015611ab6576001805460ff60a81b1916600160a81b1790555b600086611b135760405162461bcd60e51b815260206004820152602560248201527f5769746e65745265717565737454656d706c6174653a206e6f2072657472696560448201526476616c733f60d81b6064820152608401610284565b6000805b88811015611dc95780600003611bd5577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a0e553368b8b84818110611b6857611b68613c66565b905060200201356040518263ffffffff1660e01b8152600401611b8d91815260200190565b602060405180830381865afa158015611baa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bce9190613a42565b9250611d02565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a0e553368b8b84818110611c1657611c16613c66565b905060200201356040518263ffffffff1660e01b8152600401611c3b91815260200190565b602060405180830381865afa158015611c58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c7c9190613a42565b6013811115611c8d57611c8d612fab565b836013811115611c9f57611c9f612fab565b14611d025760405162461bcd60e51b815260206004820152602d60248201527f5769746e65745265717565737454656d706c6174653a206d69736d617463686960448201526c6e672072657472696576616c7360981b6064820152608401610284565b81611db75760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b4ab01a58c8c85818110611d4a57611d4a613c66565b905060200201356040518263ffffffff1660e01b8152600401611d6f91815260200190565b602060405180830381865afa158015611d8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611db09190613e53565b60ff161191505b80611dc181613e6e565b915050611b17565b50604051630d9e7e1960e21b8152600481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690633679f86490602401600060405180830381865afa158015611e2f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e5791908101906138b9565b50604051630d9e7e1960e21b8152600481018790527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690633679f86490602401600060405180830381865afa158015611ebd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ee591908101906138b9565b506000805160206140fb8339815191528781557f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc80546001600160a81b0319163360ff60a01b191617600160a01b8415150217905560008051602061411b833981519152805484919060ff19166001836013811115611f6657611f66612fab565b021790555060048101805462ffff00191661010061ffff891602179055611f91600382018b8b612de8565b5060020186905550309250508015611fe4576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5095945050505050565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036120385760405162461bcd60e51b815260040161028490613807565b6000612042612837565b600201546001600160a01b0316146120d05761205c612837565b6002015460405163bf7a0bd360e01b81526001600160a01b039091169063bf7a0bd39061208d90859060040161344d565b6020604051808303816000875af11580156120ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d49190613a1a565b6000805160206140fb83398151915280546000805160206140bb8339815191525460008051602061411b8339815191525460405163a4a7cecd60e01b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169363a4a7cecd936121689360008051602061409b8339815191529361010090910461ffff16908a90600401613cef565b6020604051808303816000875af1158015612187573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca39190613a1a565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614806121fc57506121e76128d6565b6001600160a01b0316306001600160a01b0316145b156122075750600090565b6000612211612837565b6001015414612226575063cfcd387560e01b90565b5063acf2473560e01b90565b60006001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361227c5760405162461bcd60e51b815260040161028490613807565b6000612286612837565b600201546001600160a01b0316905080156122fd57806001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613cd2565b50507f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc546001600160a01b031690565b600154600090600160a81b900460ff1615808015612356575060018054600160a01b900460ff16105b806123765750303b158015612376575060018054600160a01b900460ff16145b6123925760405162461bcd60e51b815260040161028490613e05565b6001805460ff60a01b1916600160a01b17905580156123bf576001805460ff60a81b1916600160a81b1790555b60006123c9612837565b84519091506123de9082906020870190612e2f565b506001810185905560020180546001600160a01b031916331790553091508015612443576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5092915050565b60006124546128d6565b6001600160a01b0316306001600160a01b0316148061249b5750306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145b6124fc5760405162461bcd60e51b815260206004820152602c60248201527f5769746e657452657175657374466163746f727944656661756c743a206e6f7460448201526b2074686520666163746f727960a01b6064820152608401610284565b60007f000000000000000000000000000000000000000000000000000000000000000086868686604051602001612537959493929190613e95565b60405160208183030381529060405280519060200120905060ff60f81b308261255e612b82565b80516020918201206040516125769594939201613eec565b6040516020818303038152906040528051906020012060001c9150816001600160a01b03163b600003612623576125ac81612abf565b6001600160a01b031663b42608da878787876040518563ffffffff1660e01b81526004016125dd9493929190613f25565b6020604051808303816000875af11580156125fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126209190613cd2565b91505b7fa62c4b81238a0a302883bd74617034f93d86fe817895c2dfef53073876dae76782836001600160a01b0316634843f06c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612683573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a79190613c7c565b604080516001600160a01b03909316835290151560208301520160405180910390a150949350505050565b600060008051602061413b8339815191525b600101546001600160a01b0316919050565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632ebf5d5c61272f612837565b600101546040518263ffffffff1660e01b815260040161275191815260200190565b600060405180830381865afa15801561276e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526108ae9190810190613f58565b61279e612902565b7ffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e64380546001600160a01b0319166001600160a01b0383169081179091556127e36118af565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b600061282683612bfd565b8015610ca35750610ca38383612c30565b7fbf9e297db5f64cdb81cd821e7ad085f56008e0c6100f4ebf5e41ef664932203490565b60006001600160e01b03198216631a12e29960e21b148061288c57506001600160e01b0319821663d1ab0e8760e01b145b806105d457506301ffc9a760e01b6001600160e01b03198316146105d4565b60606108ae7f0000000000000000000000000000000000000000000000000000000000000000612cb9565b60006000805160206140db8339815191526126e4565b60006000805160206140db8339815191526118c1565b3361290b6118af565b6001600160a01b03161461145c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610284565b7ffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e64380546001600160a01b0319169055600061299a6118af565b9050806001600160a01b0316826001600160a01b031614612a10578160008051602061413b83398151915280546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35b5050565b6000806000837f0000000000000000000000000000000000000000000000000000000000000000604051602001612a5f9291909182526001600160e01b031916602082015260240190565b60405160208183030381529060405280519060200120905060ff60f81b3082612a86612b82565b8051602091820120604051612a9e9594939201613eec565b60408051601f19818403018152919052805160209091012094909350915050565b600080612aca612d5d565b9050826037826000f591506001600160a01b038216612b2b5760405162461bcd60e51b815260206004820152601860248201527f436c6f6e61626c653a2043524541544532206661696c656400000000000000006044820152606401610284565b816001600160a01b0316612b3d611404565b6001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a450919050565b6060612b8c611404565b60601b604051602001612be99190733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81526bffffffffffffffffffffffff199190911660148201526e5af43d82803e903d91602b57fd5bf360881b602882015260370190565b604051602081830303815290604052905090565b6000612c10826301ffc9a760e01b612c30565b80156105d45750612c29826001600160e01b0319612c30565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015612ca2575060208210155b8015612cae5750600081115b979650505050505050565b60606000612cc683612daf565b6001600160401b03811115612cdd57612cdd61324e565b6040519080825280601f01601f191660200182016040528015612d07576020820181803683370190505b50905060005b815181101561244357838160208110612d2857612d28613c66565b1a60f81b828281518110612d3e57612d3e613c66565b60200101906001600160f81b031916908160001a905350600101612d0d565b60606000612d69611404565b90506040519150733d602d80600a3d3981f3363d3d373d3d3d363d7360601b82528060601b60148301526e5af43d82803e903d91602b57fd5bf360881b60288301525090565b60005b602081101561062157818160208110612dcd57612dcd613c66565b1a60f81b6001600160f81b0319161561062157600101612db2565b828054828255906000526020600020908101928215612e23579160200282015b82811115612e23578235825591602001919060010190612e08565b50610715929150612e88565b828054828255906000526020600020908101928215612e7c579160200282015b82811115612e7c5782518051612e6c918491602090910190612e9d565b5091602001919060010190612e4f565b50610715929150612eef565b5b808211156107155760008155600101612e89565b828054828255906000526020600020908101928215612ee3579160200282015b82811115612ee35782518290612ed39082613fdb565b5091602001919060010190612ebd565b50610715929150612f0c565b80821115610715576000612f038282612f29565b50600101612eef565b80821115610715576000612f208282612f47565b50600101612f0c565b50805460008255906000526020600020908101906114d99190612f0c565b508054612f5390613c9e565b6000825580601f10612f63575050565b601f0160209004906000526020600020908101906114d99190612e88565b600060208284031215612f9357600080fd5b81356001600160e01b031981168114610ca357600080fd5b634e487b7160e01b600052602160045260246000fd5b60005b83811015612fdc578181015183820152602001612fc4565b50506000910152565b60008151808452612ffd816020860160208601612fc1565b601f01601f19169290920160200192915050565b60006020808352608083018451600c811061302e5761302e612fab565b80838601525081850151604060608187015282825180855260a08801915060a08160051b8901019450858401935060005b818110156130ae57888603609f1901835284518051600a811061308457613084612fab565b875287015187870185905261309b85880182612fe5565b965050938601939186019160010161305f565b505050860151858303601f1901606087015292506130ce90508183612fe5565b95945050505050565b601481106130e7576130e7612fab565b9052565b602081016105d482846130d7565b60006020828403121561310b57600080fd5b5035919050565b600481106130e7576130e7612fab565b600081518084526020808501808196508360051b810191508286016000805b86811015613197578385038a5282518560408101845b6002811015613182578882038352613170828551612fe5565b938a0193928a01929150600101613157565b509b88019b9650505091850191600101613141565b509298975050505050505050565b6020815260ff8251166020820152600060208301516131c76040840182613112565b5060408301516131da60608401826130d7565b50606083015160e060808401526131f5610100840182612fe5565b90506080840151601f19808584030160a08601526132138383612fe5565b925060a08601519150808584030160c08601526132308383613122565b925060c08601519150808584030160e0860152506130ce8282612fe5565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b03811182821017156132865761328661324e565b60405290565b604080519081016001600160401b03811182821017156132865761328661324e565b60405160e081016001600160401b03811182821017156132865761328661324e565b604051601f8201601f191681016001600160401b03811182821017156132f8576132f861324e565b604052919050565b60006001600160401b038211156133195761331961324e565b50601f01601f191660200190565b600061333a61333584613300565b6132d0565b905082815283838301111561334e57600080fd5b828260208301376000602084830101529392505050565b60006020828403121561337757600080fd5b81356001600160401b0381111561338d57600080fd5b8201601f8101841361339e57600080fd5b6133ad84823560208401613327565b949350505050565b600081518084526020808501808196506005915083821b81018387016000805b8781101561343e578484038b5282518051808652908801908886019080891b87018a01855b8281101561342857601f19898303018452613416828651612fe5565b948c0194938c019391506001016133fa565b509d8a019d9650505092870192506001016133d5565b50919998505050505050505050565b602081526000610ca360208301846133b5565b602081526000610ca36020830184612fe5565b6001600160a01b03811681146114d957600080fd5b60006020828403121561349a57600080fd5b8135610ca381613473565b60006001600160401b038211156134be576134be61324e565b5060051b60200190565b600082601f8301126134d957600080fd5b813560206134e9613335836134a5565b82815260059290921b8401810191818101908684111561350857600080fd5b8286015b848110156135ce5780356001600160401b038082111561352b57600080fd5b818901915089603f83011261353f57600080fd5b8582013561354f613335826134a5565b81815260059190911b830160400190878101908c83111561356f57600080fd5b604085015b838110156135bc5780358581111561358b57600080fd5b8601605f81018f1361359c57600080fd5b6135ae8f604083013560608401613327565b845250918901918901613574565b5087525050509284019250830161350c565b509695505050505050565b6000602082840312156135eb57600080fd5b81356001600160401b0381111561360157600080fd5b6133ad848285016134c8565b600081518084526020808501945080840160005b8381101561363d57815187529582019590820190600101613621565b509495945050505050565b602081526000610ca3602083018461360d565b61ffff811681146114d957600080fd5b80356106218161365b565b60008060008060006080868803121561368e57600080fd5b85356001600160401b03808211156136a557600080fd5b818801915088601f8301126136b957600080fd5b8135818111156136c857600080fd5b8960208260051b85010111156136dd57600080fd5b6020928301975095505086013592506040860135915060608601356137018161365b565b809150509295509295909350565b6000806040838503121561372257600080fd5b8235915060208301356001600160401b0381111561373f57600080fd5b61374b858286016134c8565b9150509250929050565b6000806000806080858703121561376b57600080fd5b84356001600160401b0381111561378157600080fd5b8501601f8101871361379257600080fd5b803560206137a2613335836134a5565b82815260059290921b8301810191818101908a8411156137c157600080fd5b938201935b838510156137df578435825293820193908201906137c6565b97505087013594505050604085013591506137fc6060860161366b565b905092959194509250565b60208082526030908201527f5769746e657452657175657374466163746f727944656661756c743a206e6f7460408201526f08184819195b1959d85d194818d85b1b60821b606082015260800190565b60006020828403121561386957600080fd5b8151610ca38161365b565b600082601f83011261388557600080fd5b815161389361333582613300565b8181528460208386010111156138a857600080fd5b6133ad826020830160208701612fc1565b600060208083850312156138cc57600080fd5b82516001600160401b03808211156138e357600080fd5b90840190606082870312156138f757600080fd5b6138ff613264565b8251600c811061390e57600080fd5b8152828401518281111561392157600080fd5b8301601f8101881361393257600080fd5b8051613940613335826134a5565b81815260059190911b8201860190868101908a83111561395f57600080fd5b8784015b838110156139e15780518781111561397a57600080fd5b85016040818e03601f190112156139915760008081fd5b61399961328c565b8a820151600a81106139ab5760008081fd5b81526040820151898111156139c05760008081fd5b6139ce8f8d83860101613874565b828d015250845250918801918801613963565b5080888601525050505060408301519350818411156139ff57600080fd5b613a0b87858501613874565b60408201529695505050505050565b600060208284031215613a2c57600080fd5b5051919050565b80516014811061062157600080fd5b600060208284031215613a5457600080fd5b610ca382613a33565b805160ff8116811461062157600080fd5b80516004811061062157600080fd5b600082601f830112613a8e57600080fd5b81516020613a9e613335836134a5565b82815260059290921b84018101918181019086841115613abd57600080fd5b8286015b848110156135ce5780516001600160401b0380821115613ae15760008081fd5b818901915089603f830112613af65760008081fd5b613afe61328c565b80606084018c811115613b115760008081fd5b8885015b81811015613b4957805185811115613b2d5760008081fd5b613b3b8f8c838a0101613874565b855250928901928901613b15565b50508652505050918301918301613ac1565b600060208284031215613b6d57600080fd5b81516001600160401b0380821115613b8457600080fd5b9083019060e08286031215613b9857600080fd5b613ba06132ae565b613ba983613a5d565b8152613bb760208401613a6e565b6020820152613bc860408401613a33565b6040820152606083015182811115613bdf57600080fd5b613beb87828601613874565b606083015250608083015182811115613c0357600080fd5b613c0f87828601613874565b60808301525060a083015182811115613c2757600080fd5b613c3387828601613a7d565b60a08301525060c083015182811115613c4b57600080fd5b613c5787828601613874565b60c08301525095945050505050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215613c8e57600080fd5b81518015158114610ca357600080fd5b600181811c90821680613cb257607f821691505b602082108103610d8f57634e487b7160e01b600052602260045260246000fd5b600060208284031215613ce457600080fd5b8151610ca381613473565b600060a0820160a0835280885480835260c08501915089600052602092508260002060005b82811015613d3057815484529284019260019182019101613d14565b505050878285015286604085015261ffff861660608501528381036080850152613d5a81866133b5565b9998505050505050505050565b8281526040602082015260006133ad60408301846133b5565b60006020808385031215613d9357600080fd5b82516001600160401b03811115613da957600080fd5b8301601f81018513613dba57600080fd5b8051613dc8613335826134a5565b81815260059190911b82018301908381019087831115613de757600080fd5b928401925b82841015612cae57835182529284019290840190613dec565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b600060208284031215613e6557600080fd5b610ca382613a5d565b600060018201613e8e57634e487b7160e01b600052601160045260246000fd5b5060010190565b85815260006020808301875182890160005b82811015613ec357815184529284019290840190600101613ea7565b5050509586528501939093525060f01b6001600160f01b03191660408301525060420192915050565b6001600160f81b031994909416845260609290921b6bffffffffffffffffffffffff191660018401526015830152603582015260550190565b608081526000613f38608083018761360d565b602083019590955250604081019290925261ffff16606090910152919050565b600060208284031215613f6a57600080fd5b81516001600160401b03811115613f8057600080fd5b6133ad84828501613874565b601f821115613fd657600081815260208120601f850160051c81016020861015613fb35750805b601f850160051c820191505b81811015613fd257828155600101613fbf565b5050505b505050565b81516001600160401b03811115613ff457613ff461324e565b614008816140028454613c9e565b84613f8c565b602080601f83116001811461403d57600084156140255750858301515b600019600386901b1c1916600185901b178555613fd2565b600085815260208120601f198616915b8281101561406c5788860151825594840194600190910190840161404d565b508582101561408a5787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fe50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afe50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afd360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afb50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e642a26469706673582212207da91c3316b3c39a796149cc40d4553cd8d426675a9b8033b6953988cc03237664736f6c63430008110033faf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e6420000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc80000000000000000000000000000000000000000000000000000000000000001302e372e392d3636373030353600000000000000000000000000000000000000

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106102325760003560e01c80637104ddb211610130578063b0a41769116100b8578063d7e28aab1161007c578063d7e28aab1461052d578063db7c58b014610540578063e30c397814610553578063f09400021461055b578063f2fde38b1461056357610232565b8063b0a41769146104c9578063b42608da146104de578063bf7a0bd3146104f1578063bff852fa14610504578063c45a01551461052557610232565b80637d18db51116100ff5780637d18db51146104785780638ae940e11461048b5780638da5cb5b14610493578063a04daef01461049b578063a9e954b9146104a357610232565b80637104ddb214610439578063715018a61461044157806379ba5097146104495780637b1039991461045157610232565b8063410673e5116101be57806352d1902d1161018257806352d1902d146103bc5780635479d940146103e357806354fd4d50146104095780636b58960a1461041e5780636f2ddd931461043157610232565b8063410673e514610348578063439fab91146103505780634843f06c146103655780634e9b75b61461036d5780635001f3b51461038257610232565b80631eef9052116102055780631eef9052146102ed578063245a7bfc14610303578063265e84391461030b57806326f8a6d314610313578063341e11c81461032857610232565b806301ffc9a71461028d57806309e50249146102b557806310d02e47146102d0578063158ef93e146102e5575b60405162461bcd60e51b815260206004820152602560248201527f5769746e657455706772616461626c65426173653a206e6f7420696d706c656d604482015264195b9d195960da1b60648201526084015b60405180910390fd5b6102a061029b366004612f81565b610576565b60405190151581526020015b60405180910390f35b6102bd610626565b60405161ffff90911681526020016102ac565b6102d8610719565b6040516102ac9190613011565b6102a0610882565b6102f56108b3565b6040519081526020016102ac565b6102f561090e565b6102f56109ee565b61031b610aaa565b6040516102ac91906130eb565b61033b6103363660046130f9565b610b8d565b6040516102ac91906131a5565b6102f5610d95565b61036361035e366004613365565b610e51565b005b6102a06110ce565b6103756111ca565b6040516102ac919061344d565b7f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08655b6040516001600160a01b0390911681526020016102ac565b6102f57f0b4d668cb5391f080c389e623c85725cc0657f72d6f1e3998f65e9322ff9a1c781565b7f00000000000000000000000000000000000000000000000000000000000000016102a0565b610411611336565b6040516102ac9190613460565b6102a061042c366004613488565b611340565b6103a46113a0565b6103a4611404565b61036361144a565b61036361145e565b6103a47f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc881565b6103a46104863660046135d9565b6114dc565b6102d8611787565b6103a46118af565b6102a06118d0565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4706102f5565b6104d16118f4565b6040516102ac9190613648565b6103a46104ec366004613676565b611a24565b6102f56104ff3660046135d9565b611fee565b61050c6121ab565b6040516001600160e01b031990911681526020016102ac565b6103a4612232565b6103a461053b36600461370f565b61232d565b6103a461054e366004613755565b61244a565b6103a46126d2565b6104116126f6565b610363610571366004613488565b612796565b600080610581612837565b60010154146105da576001600160e01b03198216637c94ad3160e11b14806105b957506001600160e01b0319821663cfcd387560e01b145b806105d457506001600160e01b0319821663acf2473560e01b145b92915050565b60008051602061409b833981519152541561060657506001600160e01b03191663acf2473560e01b1490565b6001600160e01b0319821615806105d457506105d48261285b565b919050565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036106705760405162461bcd60e51b815260040161028490613807565b600061067a612837565b600201546001600160a01b0316905080156106f757806001600160a01b03166309e502496040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613857565b91505090565b505060008051602061411b83398151915254610100900461ffff1690565b5090565b61073e6040805160608101909152806000815260200160608152602001606081525090565b6001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036107865760405162461bcd60e51b815260040161028490613807565b6000610790612837565b600201546001600160a01b03169050801561080b57806001600160a01b03166310d02e476040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107e3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106f191908101906138b9565b6000805160206140fb83398151915254604051630d9e7e1960e21b815260048101919091527f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031690633679f864906024015b600060405180830381865afa1580156107e3573d6000803e3d6000fd5b6000805160206140bb833981519152546000901515806108ae575060006108a7612837565b6001015414155b905090565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036108fd5760405162461bcd60e51b815260040161028490613807565b610905612837565b60010154905090565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036109585760405162461bcd60e51b815260040161028490613807565b6000610962612837565b600201546001600160a01b0316905080156109d957806001600160a01b031663245a7bfc6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613a1a565b50506000805160206140fb8339815191525490565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865163003610a385760405162461bcd60e51b815260040161028490613807565b6000610a42612837565b600201546001600160a01b031690508015610a9557806001600160a01b031663265e84396040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b505060008051602061409b8339815191525490565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865163003610af45760405162461bcd60e51b815260040161028490613807565b6000610afe612837565b600201546001600160a01b031690508015610b7557806001600160a01b03166326f8a6d36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b51573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613a42565b505060008051602061411b8339815191525460ff1690565b610bce6040805160e0810190915260008082526020820190815260200160008152602001606081526020016060815260200160608152602001606081525090565b6001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865163003610c165760405162461bcd60e51b815260040161028490613807565b6000610c20612837565b600201546001600160a01b031690508015610caa57604051630683c23960e31b8152600481018490526001600160a01b0382169063341e11c8906024015b600060405180830381865afa158015610c7b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ca39190810190613b5b565b9392505050565b60008051602061409b833981519152548310610d145760405162461bcd60e51b815260206004820152602360248201527f5769746e65745265717565737454656d706c6174653a206f7574206f662072616044820152626e676560e81b6064820152608401610284565b6001600160a01b037f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc816639dd487576000805160206140fb8339815191526003018581548110610d6657610d66613c66565b90600052602060002001546040518263ffffffff1660e01b8152600401610c5e91815260200190565b50919050565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865163003610ddf5760405162461bcd60e51b815260040161028490613807565b6000610de9612837565b600201546001600160a01b031690508015610e3c57806001600160a01b031663410673e56040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b5573d6000803e3d6000fd5b50506000805160206140bb8339815191525490565b6001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865163003610e995760405162461bcd60e51b815260040161028490613807565b60008051602061413b833981519152546001600160a01b031680610edf575060008051602061413b83398151915280546001600160a01b03191633908117909155610f13565b336001600160a01b03821614610f1357604051630543601560e11b81526001600160a01b0382166004820152602401610284565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd546001600160a01b0316610f74577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd80546001600160a01b031916301790555b6000805160206140db833981519152546001600160a01b03161561101e577f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08656001600160a01b03166000805160206140db833981519152546001600160a01b03160361101e576040516339cf62f760e11b81526001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d0865166004820152602401610284565b6000805160206140db83398151915280546001600160a01b0319167f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08656001600160a01b03169081179091557fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47090337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f66110b5611336565b6040516110c29190613460565b60405180910390a45050565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036111185760405162461bcd60e51b815260040161028490613807565b6000611122612837565b600201546001600160a01b03169050801561119957806001600160a01b0316634843f06c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611175573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613c7c565b50507f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc54600160a01b900460ff1690565b60606001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036112145760405162461bcd60e51b815260040161028490613807565b61121c612837565b80546040805160208084028201810190925282815292919060009084015b8282101561132d57838290600052602060002001805480602002602001604051908101604052809291908181526020016000905b8282101561131a57838290600052602060002001805461128d90613c9e565b80601f01602080910402602001604051908101604052809291908181526020018280546112b990613c9e565b80156113065780601f106112db57610100808354040283529160200191611306565b820191906000526020600020905b8154815290600101906020018083116112e957829003601f168201915b50505050508152602001906001019061126e565b505050508152602001906001019061123a565b50505050905090565b60606108ae6128ab565b60008051602061413b833981519152546000906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000018015610ca35750826001600160a01b0316816001600160a01b0316149392505050565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036113ea5760405162461bcd60e51b815260040161028490613807565b6113f2612837565b600201546001600160a01b0316905090565b60008061140f6128d6565b6001600160a01b03160361144257507f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d086590565b6108ae6128ec565b611452612902565b61145c6000612961565b565b33806114686126d2565b6001600160a01b0316146114d05760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610284565b6114d981612961565b50565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036115265760405162461bcd60e51b815260040161028490613807565b6000611530612837565b600201546001600160a01b0316146115be5761154a612837565b60020154604051637d18db5160e01b81526001600160a01b0390911690637d18db519061157b90859060040161344d565b6020604051808303816000875af115801561159a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d49190613cd2565b6000805160206140fb83398151915280546000805160206140bb8339815191525460008051602061411b8339815191525460405163a4a7cecd60e01b81526000937f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b03169363a4a7cecd9361165a9360008051602061409b833981519152939291610100900461ffff16908b90600401613cef565b6020604051808303816000875af1158015611679573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169d9190613a1a565b905060006116aa82612a14565b90945090506001600160a01b0384163b60000361173d576116ca81612abf565b6001600160a01b031663d7e28aab83876040518363ffffffff1660e01b81526004016116f7929190613d67565b6020604051808303816000875af1158015611716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173a9190613cd2565b93505b81846001600160a01b03167f410c7975f3418de1a871bdcb16ea6c438f6a6c1e5799e704d4e32f53a405f22987604051611777919061344d565b60405180910390a3505050919050565b6117ac6040805160608101909152806000815260200160608152602001606081525090565b6001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036117f45760405162461bcd60e51b815260040161028490613807565b60006117fe612837565b600201546001600160a01b03169050801561185157806001600160a01b0316638ae940e16040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107e3573d6000803e3d6000fd5b6000805160206140bb83398151915254604051630d9e7e1960e21b815260048101919091527f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031690633679f86490602401610865565b600060008051602061413b8339815191525b546001600160a01b0316919050565b60006118da611404565b6001600160a01b0316306001600160a01b03161415905090565b60606001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d086516300361193e5760405162461bcd60e51b815260040161028490613807565b6000611948612837565b600201546001600160a01b0316905080156119c357806001600160a01b031663b0a417696040518163ffffffff1660e01b8152600401600060405180830381865afa15801561199b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106f19190810190613d80565b60008051602061409b833981519152805460408051602080840282018101909252828152929190830182828015611a1957602002820191906000526020600020905b815481526020019060010190808311611a05575b505050505091505090565b600154600090600160a81b900460ff1615808015611a4d575060018054600160a01b900460ff16105b80611a6d5750303b158015611a6d575060018054600160a01b900460ff16145b611a895760405162461bcd60e51b815260040161028490613e05565b6001805460ff60a01b1916600160a01b1790558015611ab6576001805460ff60a81b1916600160a81b1790555b600086611b135760405162461bcd60e51b815260206004820152602560248201527f5769746e65745265717565737454656d706c6174653a206e6f2072657472696560448201526476616c733f60d81b6064820152608401610284565b6000805b88811015611dc95780600003611bd5577f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031663a0e553368b8b84818110611b6857611b68613c66565b905060200201356040518263ffffffff1660e01b8152600401611b8d91815260200190565b602060405180830381865afa158015611baa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bce9190613a42565b9250611d02565b7f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031663a0e553368b8b84818110611c1657611c16613c66565b905060200201356040518263ffffffff1660e01b8152600401611c3b91815260200190565b602060405180830381865afa158015611c58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c7c9190613a42565b6013811115611c8d57611c8d612fab565b836013811115611c9f57611c9f612fab565b14611d025760405162461bcd60e51b815260206004820152602d60248201527f5769746e65745265717565737454656d706c6174653a206d69736d617463686960448201526c6e672072657472696576616c7360981b6064820152608401610284565b81611db75760007f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031663b4ab01a58c8c85818110611d4a57611d4a613c66565b905060200201356040518263ffffffff1660e01b8152600401611d6f91815260200190565b602060405180830381865afa158015611d8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611db09190613e53565b60ff161191505b80611dc181613e6e565b915050611b17565b50604051630d9e7e1960e21b8152600481018890527f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031690633679f86490602401600060405180830381865afa158015611e2f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e5791908101906138b9565b50604051630d9e7e1960e21b8152600481018790527f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b031690633679f86490602401600060405180830381865afa158015611ebd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ee591908101906138b9565b506000805160206140fb8339815191528781557f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc80546001600160a81b0319163360ff60a01b191617600160a01b8415150217905560008051602061411b833981519152805484919060ff19166001836013811115611f6657611f66612fab565b021790555060048101805462ffff00191661010061ffff891602179055611f91600382018b8b612de8565b5060020186905550309250508015611fe4576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5095945050505050565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651630036120385760405162461bcd60e51b815260040161028490613807565b6000612042612837565b600201546001600160a01b0316146120d05761205c612837565b6002015460405163bf7a0bd360e01b81526001600160a01b039091169063bf7a0bd39061208d90859060040161344d565b6020604051808303816000875af11580156120ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d49190613a1a565b6000805160206140fb83398151915280546000805160206140bb8339815191525460008051602061411b8339815191525460405163a4a7cecd60e01b81527f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b03169363a4a7cecd936121689360008051602061409b8339815191529361010090910461ffff16908a90600401613cef565b6020604051808303816000875af1158015612187573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca39190613a1a565b6000306001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d08651614806121fc57506121e76128d6565b6001600160a01b0316306001600160a01b0316145b156122075750600090565b6000612211612837565b6001015414612226575063cfcd387560e01b90565b5063acf2473560e01b90565b60006001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d086516300361227c5760405162461bcd60e51b815260040161028490613807565b6000612286612837565b600201546001600160a01b0316905080156122fd57806001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f19190613cd2565b50507f50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afc546001600160a01b031690565b600154600090600160a81b900460ff1615808015612356575060018054600160a01b900460ff16105b806123765750303b158015612376575060018054600160a01b900460ff16145b6123925760405162461bcd60e51b815260040161028490613e05565b6001805460ff60a01b1916600160a01b17905580156123bf576001805460ff60a81b1916600160a81b1790555b60006123c9612837565b84519091506123de9082906020870190612e2f565b506001810185905560020180546001600160a01b031916331790553091508015612443576001805460ff60a81b191681556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5092915050565b60006124546128d6565b6001600160a01b0316306001600160a01b0316148061249b5750306001600160a01b037f0000000000000000000000004374a050f808d1ff18bccf73270dae3edf8d086516145b6124fc5760405162461bcd60e51b815260206004820152602c60248201527f5769746e657452657175657374466163746f727944656661756c743a206e6f7460448201526b2074686520666163746f727960a01b6064820152608401610284565b60007f302e372e392d363637303035360000000000000000000000000000000000000086868686604051602001612537959493929190613e95565b60405160208183030381529060405280519060200120905060ff60f81b308261255e612b82565b80516020918201206040516125769594939201613eec565b6040516020818303038152906040528051906020012060001c9150816001600160a01b03163b600003612623576125ac81612abf565b6001600160a01b031663b42608da878787876040518563ffffffff1660e01b81526004016125dd9493929190613f25565b6020604051808303816000875af11580156125fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126209190613cd2565b91505b7fa62c4b81238a0a302883bd74617034f93d86fe817895c2dfef53073876dae76782836001600160a01b0316634843f06c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612683573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a79190613c7c565b604080516001600160a01b03909316835290151560208301520160405180910390a150949350505050565b600060008051602061413b8339815191525b600101546001600160a01b0316919050565b60607f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc86001600160a01b0316632ebf5d5c61272f612837565b600101546040518263ffffffff1660e01b815260040161275191815260200190565b600060405180830381865afa15801561276e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526108ae9190810190613f58565b61279e612902565b7ffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e64380546001600160a01b0319166001600160a01b0383169081179091556127e36118af565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b600061282683612bfd565b8015610ca35750610ca38383612c30565b7fbf9e297db5f64cdb81cd821e7ad085f56008e0c6100f4ebf5e41ef664932203490565b60006001600160e01b03198216631a12e29960e21b148061288c57506001600160e01b0319821663d1ab0e8760e01b145b806105d457506301ffc9a760e01b6001600160e01b03198316146105d4565b60606108ae7f302e372e392d3636373030353600000000000000000000000000000000000000612cb9565b60006000805160206140db8339815191526126e4565b60006000805160206140db8339815191526118c1565b3361290b6118af565b6001600160a01b03161461145c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610284565b7ffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e64380546001600160a01b0319169055600061299a6118af565b9050806001600160a01b0316826001600160a01b031614612a10578160008051602061413b83398151915280546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35b5050565b6000806000837f302e372e392d3636373030353600000000000000000000000000000000000000604051602001612a5f9291909182526001600160e01b031916602082015260240190565b60405160208183030381529060405280519060200120905060ff60f81b3082612a86612b82565b8051602091820120604051612a9e9594939201613eec565b60408051601f19818403018152919052805160209091012094909350915050565b600080612aca612d5d565b9050826037826000f591506001600160a01b038216612b2b5760405162461bcd60e51b815260206004820152601860248201527f436c6f6e61626c653a2043524541544532206661696c656400000000000000006044820152606401610284565b816001600160a01b0316612b3d611404565b6001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a450919050565b6060612b8c611404565b60601b604051602001612be99190733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81526bffffffffffffffffffffffff199190911660148201526e5af43d82803e903d91602b57fd5bf360881b602882015260370190565b604051602081830303815290604052905090565b6000612c10826301ffc9a760e01b612c30565b80156105d45750612c29826001600160e01b0319612c30565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015612ca2575060208210155b8015612cae5750600081115b979650505050505050565b60606000612cc683612daf565b6001600160401b03811115612cdd57612cdd61324e565b6040519080825280601f01601f191660200182016040528015612d07576020820181803683370190505b50905060005b815181101561244357838160208110612d2857612d28613c66565b1a60f81b828281518110612d3e57612d3e613c66565b60200101906001600160f81b031916908160001a905350600101612d0d565b60606000612d69611404565b90506040519150733d602d80600a3d3981f3363d3d373d3d3d363d7360601b82528060601b60148301526e5af43d82803e903d91602b57fd5bf360881b60288301525090565b60005b602081101561062157818160208110612dcd57612dcd613c66565b1a60f81b6001600160f81b0319161561062157600101612db2565b828054828255906000526020600020908101928215612e23579160200282015b82811115612e23578235825591602001919060010190612e08565b50610715929150612e88565b828054828255906000526020600020908101928215612e7c579160200282015b82811115612e7c5782518051612e6c918491602090910190612e9d565b5091602001919060010190612e4f565b50610715929150612eef565b5b808211156107155760008155600101612e89565b828054828255906000526020600020908101928215612ee3579160200282015b82811115612ee35782518290612ed39082613fdb565b5091602001919060010190612ebd565b50610715929150612f0c565b80821115610715576000612f038282612f29565b50600101612eef565b80821115610715576000612f208282612f47565b50600101612f0c565b50805460008255906000526020600020908101906114d99190612f0c565b508054612f5390613c9e565b6000825580601f10612f63575050565b601f0160209004906000526020600020908101906114d99190612e88565b600060208284031215612f9357600080fd5b81356001600160e01b031981168114610ca357600080fd5b634e487b7160e01b600052602160045260246000fd5b60005b83811015612fdc578181015183820152602001612fc4565b50506000910152565b60008151808452612ffd816020860160208601612fc1565b601f01601f19169290920160200192915050565b60006020808352608083018451600c811061302e5761302e612fab565b80838601525081850151604060608187015282825180855260a08801915060a08160051b8901019450858401935060005b818110156130ae57888603609f1901835284518051600a811061308457613084612fab565b875287015187870185905261309b85880182612fe5565b965050938601939186019160010161305f565b505050860151858303601f1901606087015292506130ce90508183612fe5565b95945050505050565b601481106130e7576130e7612fab565b9052565b602081016105d482846130d7565b60006020828403121561310b57600080fd5b5035919050565b600481106130e7576130e7612fab565b600081518084526020808501808196508360051b810191508286016000805b86811015613197578385038a5282518560408101845b6002811015613182578882038352613170828551612fe5565b938a0193928a01929150600101613157565b509b88019b9650505091850191600101613141565b509298975050505050505050565b6020815260ff8251166020820152600060208301516131c76040840182613112565b5060408301516131da60608401826130d7565b50606083015160e060808401526131f5610100840182612fe5565b90506080840151601f19808584030160a08601526132138383612fe5565b925060a08601519150808584030160c08601526132308383613122565b925060c08601519150808584030160e0860152506130ce8282612fe5565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b03811182821017156132865761328661324e565b60405290565b604080519081016001600160401b03811182821017156132865761328661324e565b60405160e081016001600160401b03811182821017156132865761328661324e565b604051601f8201601f191681016001600160401b03811182821017156132f8576132f861324e565b604052919050565b60006001600160401b038211156133195761331961324e565b50601f01601f191660200190565b600061333a61333584613300565b6132d0565b905082815283838301111561334e57600080fd5b828260208301376000602084830101529392505050565b60006020828403121561337757600080fd5b81356001600160401b0381111561338d57600080fd5b8201601f8101841361339e57600080fd5b6133ad84823560208401613327565b949350505050565b600081518084526020808501808196506005915083821b81018387016000805b8781101561343e578484038b5282518051808652908801908886019080891b87018a01855b8281101561342857601f19898303018452613416828651612fe5565b948c0194938c019391506001016133fa565b509d8a019d9650505092870192506001016133d5565b50919998505050505050505050565b602081526000610ca360208301846133b5565b602081526000610ca36020830184612fe5565b6001600160a01b03811681146114d957600080fd5b60006020828403121561349a57600080fd5b8135610ca381613473565b60006001600160401b038211156134be576134be61324e565b5060051b60200190565b600082601f8301126134d957600080fd5b813560206134e9613335836134a5565b82815260059290921b8401810191818101908684111561350857600080fd5b8286015b848110156135ce5780356001600160401b038082111561352b57600080fd5b818901915089603f83011261353f57600080fd5b8582013561354f613335826134a5565b81815260059190911b830160400190878101908c83111561356f57600080fd5b604085015b838110156135bc5780358581111561358b57600080fd5b8601605f81018f1361359c57600080fd5b6135ae8f604083013560608401613327565b845250918901918901613574565b5087525050509284019250830161350c565b509695505050505050565b6000602082840312156135eb57600080fd5b81356001600160401b0381111561360157600080fd5b6133ad848285016134c8565b600081518084526020808501945080840160005b8381101561363d57815187529582019590820190600101613621565b509495945050505050565b602081526000610ca3602083018461360d565b61ffff811681146114d957600080fd5b80356106218161365b565b60008060008060006080868803121561368e57600080fd5b85356001600160401b03808211156136a557600080fd5b818801915088601f8301126136b957600080fd5b8135818111156136c857600080fd5b8960208260051b85010111156136dd57600080fd5b6020928301975095505086013592506040860135915060608601356137018161365b565b809150509295509295909350565b6000806040838503121561372257600080fd5b8235915060208301356001600160401b0381111561373f57600080fd5b61374b858286016134c8565b9150509250929050565b6000806000806080858703121561376b57600080fd5b84356001600160401b0381111561378157600080fd5b8501601f8101871361379257600080fd5b803560206137a2613335836134a5565b82815260059290921b8301810191818101908a8411156137c157600080fd5b938201935b838510156137df578435825293820193908201906137c6565b97505087013594505050604085013591506137fc6060860161366b565b905092959194509250565b60208082526030908201527f5769746e657452657175657374466163746f727944656661756c743a206e6f7460408201526f08184819195b1959d85d194818d85b1b60821b606082015260800190565b60006020828403121561386957600080fd5b8151610ca38161365b565b600082601f83011261388557600080fd5b815161389361333582613300565b8181528460208386010111156138a857600080fd5b6133ad826020830160208701612fc1565b600060208083850312156138cc57600080fd5b82516001600160401b03808211156138e357600080fd5b90840190606082870312156138f757600080fd5b6138ff613264565b8251600c811061390e57600080fd5b8152828401518281111561392157600080fd5b8301601f8101881361393257600080fd5b8051613940613335826134a5565b81815260059190911b8201860190868101908a83111561395f57600080fd5b8784015b838110156139e15780518781111561397a57600080fd5b85016040818e03601f190112156139915760008081fd5b61399961328c565b8a820151600a81106139ab5760008081fd5b81526040820151898111156139c05760008081fd5b6139ce8f8d83860101613874565b828d015250845250918801918801613963565b5080888601525050505060408301519350818411156139ff57600080fd5b613a0b87858501613874565b60408201529695505050505050565b600060208284031215613a2c57600080fd5b5051919050565b80516014811061062157600080fd5b600060208284031215613a5457600080fd5b610ca382613a33565b805160ff8116811461062157600080fd5b80516004811061062157600080fd5b600082601f830112613a8e57600080fd5b81516020613a9e613335836134a5565b82815260059290921b84018101918181019086841115613abd57600080fd5b8286015b848110156135ce5780516001600160401b0380821115613ae15760008081fd5b818901915089603f830112613af65760008081fd5b613afe61328c565b80606084018c811115613b115760008081fd5b8885015b81811015613b4957805185811115613b2d5760008081fd5b613b3b8f8c838a0101613874565b855250928901928901613b15565b50508652505050918301918301613ac1565b600060208284031215613b6d57600080fd5b81516001600160401b0380821115613b8457600080fd5b9083019060e08286031215613b9857600080fd5b613ba06132ae565b613ba983613a5d565b8152613bb760208401613a6e565b6020820152613bc860408401613a33565b6040820152606083015182811115613bdf57600080fd5b613beb87828601613874565b606083015250608083015182811115613c0357600080fd5b613c0f87828601613874565b60808301525060a083015182811115613c2757600080fd5b613c3387828601613a7d565b60a08301525060c083015182811115613c4b57600080fd5b613c5787828601613874565b60c08301525095945050505050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215613c8e57600080fd5b81518015158114610ca357600080fd5b600181811c90821680613cb257607f821691505b602082108103610d8f57634e487b7160e01b600052602260045260246000fd5b600060208284031215613ce457600080fd5b8151610ca381613473565b600060a0820160a0835280885480835260c08501915089600052602092508260002060005b82811015613d3057815484529284019260019182019101613d14565b505050878285015286604085015261ffff861660608501528381036080850152613d5a81866133b5565b9998505050505050505050565b8281526040602082015260006133ad60408301846133b5565b60006020808385031215613d9357600080fd5b82516001600160401b03811115613da957600080fd5b8301601f81018513613dba57600080fd5b8051613dc8613335826134a5565b81815260059190911b82018301908381019087831115613de757600080fd5b928401925b82841015612cae57835182529284019290840190613dec565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b600060208284031215613e6557600080fd5b610ca382613a5d565b600060018201613e8e57634e487b7160e01b600052601160045260246000fd5b5060010190565b85815260006020808301875182890160005b82811015613ec357815184529284019290840190600101613ea7565b5050509586528501939093525060f01b6001600160f01b03191660408301525060420192915050565b6001600160f81b031994909416845260609290921b6bffffffffffffffffffffffff191660018401526015830152603582015260550190565b608081526000613f38608083018761360d565b602083019590955250604081019290925261ffff16606090910152919050565b600060208284031215613f6a57600080fd5b81516001600160401b03811115613f8057600080fd5b6133ad84828501613874565b601f821115613fd657600081815260208120601f850160051c81016020861015613fb35750805b601f850160051c820191505b81811015613fd257828155600101613fbf565b5050505b505050565b81516001600160401b03811115613ff457613ff461324e565b614008816140028454613c9e565b84613f8c565b602080601f83116001811461403d57600084156140255750858301515b600019600386901b1c1916600185901b178555613fd2565b600085815260208120601f198616915b8281101561406c5788860151825594840194600190910190840161404d565b508582101561408a5787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fe50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afe50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afd360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afb50402db987be01ecf619cd3fb022cf52f861d188e7b779dd032a62d082276afffaf45a8ecd300851b566566df52ca7611b7a56d24a3449b86f4e21c71638e642a26469706673582212207da91c3316b3c39a796149cc40d4553cd8d426675a9b8033b6953988cc03237664736f6c63430008110033