Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- SelfRegistry
- Optimization enabled
- true
- Compiler version
- v0.8.17+commit.8df45f5f
- Optimization runs
- 1000
- EVM Version
- default
- Verified at
- 2024-08-01T12:53:28.998004Z
Constructor Arguments
0x00000000000000000000000081bc85f329cdb28936fbb239f734ae495121f9a6000000000000000000000000709944a48caf83535e43471680fda4905fb3920a000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e5
Arg [0] (address) : 0x81bc85f329cdb28936fbb239f734ae495121f9a6
Arg [1] (address) : 0x709944a48caf83535e43471680fda4905fb3920a
Arg [2] (address) : 0x241364bbd08701330bdc810baaa10cf8df1710e5
contracts/api3-server-v1/SelfRegistry.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../vendor/@openzeppelin/contracts@4.9.5/access/Ownable.sol"; import "../utils/ExtendedSelfMulticall.sol"; import "./interfaces/IAirseekerRegistry.sol"; import "./interfaces/IBeaconUpdatesWithSignedData.sol"; import "./AirseekerRegistry.sol"; import "./Api3ServerV1.sol"; import "../vendor/@openzeppelin/contracts@4.8.2/utils/cryptography/ECDSA.sol"; contract SelfRegistry is Ownable, ExtendedSelfMulticall { /// @notice AirseekerRegistry contract address address public immutable airseekerRegistry; address public immutable api3ServerV1; address public immutable airnodeAddress; uint256 public constant MAXIMUM_DATA_FEET_UPDATE_AGE = 5 minutes; using ECDSA for bytes32; /// @param owner_ Owner address /// @param api3ServerV1_ Api3ServerV1 contract address constructor( address owner_, address api3ServerV1_, address airnodeAddress_ ) { require(owner_ != address(0), "Owner address zero"); _transferOwnership(owner_); api3ServerV1 = api3ServerV1_; airnodeAddress = airnodeAddress_; airseekerRegistry = address( new AirseekerRegistry{salt: bytes32(0)}( address(this), api3ServerV1_ ) ); } /// @notice Overriden to be disabled function renounceOwnership() public pure override(Ownable) { revert("Ownership cannot be renounced"); } /// @notice Overriden to be disabled function transferOwnership(address) public pure override(Ownable) { revert("Ownership cannot be transferred"); } /// @notice Returns the owner address /// @return Owner address function owner() public view override(Ownable) returns (address) { return super.owner(); } function checkTimestamp(uint32 timestamp) private view returns (bool) { return block.timestamp - MAXIMUM_DATA_FEET_UPDATE_AGE <= timestamp; } /// @notice Called by the owner to set the data feed ID to be activated /// @param dataFeedId Data feed ID function setDataFeedIdToBeActivated( bytes32 dataFeedId, uint256 timestamp, bytes calldata signature ) external { require( ( keccak256( abi.encodePacked( dataFeedId, timestamp, block.chainid, address(this), this.setDataFeedIdToBeActivated.selector ) ).toEthSignedMessageHash() ).recover(signature) == airnodeAddress, "Signature mismatch" ); require( checkTimestamp(uint32(timestamp)), "Old timestamps are not allowed" ); IAirseekerRegistry(airseekerRegistry).setDataFeedIdToBeActivated( dataFeedId ); } /// @notice Called by the owner to set the data feed ID to be deactivated /// @param dataFeedId Data feed ID function setDataFeedIdToBeDeactivated( bytes32 dataFeedId, uint256 timestamp, bytes calldata signature ) external { require( ( keccak256( abi.encodePacked( dataFeedId, timestamp, block.chainid, address(this), this.setDataFeedIdToBeDeactivated.selector ) ).toEthSignedMessageHash() ).recover(signature) == airnodeAddress, "Signature mismatch" ); require( checkTimestamp(uint32(timestamp)), "Old timestamps are not allowed" ); IAirseekerRegistry(airseekerRegistry).setDataFeedIdToBeDeactivated( dataFeedId ); } /// @notice Called by the owner to set the signed API URL for the Airnode. /// The signed API must implement the specific interface that Airseeker /// expects. /// @param airnode Airnode address /// @param signedApiUrl Signed API URL function setSignedApiUrl( address airnode, string calldata signedApiUrl ) external { IAirseekerRegistry(airseekerRegistry).setSignedApiUrl( airnode, signedApiUrl ); } /// @notice Called by the owner to set the data feed ID update parameters. /// The update parameters must be encoded in a format that Airseeker /// expects. /// @param dataFeedId Data feed ID /// @param updateParameters Update parameters function setDataFeedIdUpdateParameters( bytes32 dataFeedId, uint256 timestamp, bytes calldata updateParameters, bytes calldata signature ) external { require( ( keccak256( abi.encodePacked( dataFeedId, updateParameters, timestamp, block.chainid, address(this), this.setDataFeedIdUpdateParameters.selector ) ).toEthSignedMessageHash() ).recover(signature) == airnodeAddress, "Signature mismatch" ); require( checkTimestamp(uint32(timestamp)), "Old timestamps are not allowed" ); IAirseekerRegistry(airseekerRegistry).setDataFeedIdUpdateParameters( dataFeedId, updateParameters ); } /// @notice Registers the data feed. In the case that the data feed is a /// Beacon, the details should be the ABI-encoded Airnode address and /// template ID. In the case that the data feed is a Beacon set, the /// details should be the ABI-encoded Airnode addresses array and template /// IDs array. /// @param dataFeedDetails Data feed details /// @return dataFeedId Data feed ID function registerDataFeed( uint256 timestamp, bytes calldata dataFeedDetails, bytes calldata signature ) external returns (bytes32 dataFeedId) { require( ( keccak256( abi.encodePacked( dataFeedDetails, timestamp, block.chainid, address(this), this.registerDataFeed.selector ) ).toEthSignedMessageHash() ).recover(signature) == airnodeAddress, "Signature mismatch" ); require( checkTimestamp(uint32(timestamp)), "Old timestamps are not allowed" ); return IAirseekerRegistry(airseekerRegistry).registerDataFeed( dataFeedDetails ); } /// @notice Returns the number of active data feeds identified by a data /// feed ID or dAPI name /// @return Active data feed count function activeDataFeedCount() external view returns (uint256) { return IAirseekerRegistry(airseekerRegistry).activeDataFeedCount(); } /// @notice Updates a Beacon using data signed by the Airnode /// @dev The signed data here is intentionally very general for practical /// reasons. It is less demanding on the signer to have data signed once /// and use that everywhere. /// @param airnode Airnode address /// @param templateId Template ID /// @param timestamp Signature timestamp /// @param data Update data (an `int256` encoded in contract ABI) /// @param signature Template ID, timestamp and the update data signed by /// the Airnode /// @return beaconId Updated Beacon ID function updateBeaconWithSignedData( address airnode, bytes32 templateId, uint256 timestamp, bytes calldata data, bytes calldata signature ) external returns (bytes32 beaconId) { return IBeaconUpdatesWithSignedData(api3ServerV1) .updateBeaconWithSignedData( airnode, templateId, timestamp, data, signature ); } }
contracts/api3-server-v1/interfaces/IOevDapiServer.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IOevDataFeedServer.sol"; import "./IDapiServer.sol"; interface IOevDapiServer is IOevDataFeedServer, IDapiServer {}
contracts/vendor/@openzeppelin/contracts@4.9.5/access/Ownable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.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. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling 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/api3-server-v1/AirseekerRegistry.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../vendor/@openzeppelin/contracts@4.9.5/access/Ownable.sol"; import "../utils/ExtendedSelfMulticall.sol"; import "./interfaces/IAirseekerRegistry.sol"; import "../vendor/@openzeppelin/contracts@4.9.5/utils/structs/EnumerableSet.sol"; import "./interfaces/IApi3ServerV1.sol"; /// @title A contract where active data feeds and their specs are registered by /// the contract owner for the Airseeker that serves them to refer to /// @notice Airseeker is an application that pushes API provider-signed data to /// chain when certain conditions are met so that the data feeds served on the /// Api3ServerV1 contract are updated according to the respective specs. In /// other words, this contract is an on-chain configuration file for an /// Airseeker (or multiple Airseekers in a setup with redundancy). /// The Airseeker must know which data feeds are active (and thus need to be /// updated), the constituting Airnode (the oracle node that API providers /// operate to sign data) addresses and request template IDs, what the /// respective on-chain data feed values are, what the update parameters are, /// and the URL of the signed APIs (from which Airseeker can fetch signed data) /// that are hosted by the respective API providers. /// The contract owner is responsible with leaving the state of this contract /// in a way that Airseeker expects. For example, if a dAPI name is activated /// without registering the respective data feed, the Airseeker will not have /// access to the data that it needs to execute updates. contract AirseekerRegistry is Ownable, ExtendedSelfMulticall, IAirseekerRegistry { using EnumerableSet for EnumerableSet.Bytes32Set; /// @notice Maximum number of Beacons in a Beacon set that can be /// registered /// @dev Api3ServerV1 introduces the concept of a Beacon, which is a /// single-source data feed. Api3ServerV1 allows Beacons to be read /// individually, or arbitrary combinations of them to be aggregated /// on-chain to form multiple-source data feeds, which are called Beacon /// sets. This contract does not support Beacon sets that consist of more /// than `MAXIMUM_BEACON_COUNT_IN_SET` Beacons to be registered. uint256 public constant override MAXIMUM_BEACON_COUNT_IN_SET = 21; /// @notice Maximum encoded update parameters length uint256 public constant override MAXIMUM_UPDATE_PARAMETERS_LENGTH = 1024; /// @notice Maximum signed API URL length uint256 public constant override MAXIMUM_SIGNED_API_URL_LENGTH = 256; /// @notice Api3ServerV1 contract address address public immutable override api3ServerV1; /// @notice Airnode address to signed API URL /// @dev An Airseeker can be configured to refer to additional signed APIs /// than the ones whose URLs are stored in this contract for redundancy mapping(address => string) public override airnodeToSignedApiUrl; /// @notice Data feed ID to encoded details mapping(bytes32 => bytes) public override dataFeedIdToDetails; // Api3ServerV1 uses Beacon IDs (see the `deriveBeaconId()` implementation) // and Beacon set IDs (see the `deriveBeaconSetId()` implementation) to // address data feeds. We use data feed ID as a general term to refer to a // Beacon ID/Beacon set ID. // A data feed ID is immutable (i.e., it always points to the same Beacon // or Beacon set). Api3ServerV1 allows a dAPI name to be pointed to a data // feed ID by privileged accounts to implement a mutable data feed // addressing scheme. // If the data feed ID or dAPI name should be used to read a data feed // depends on the use case. To support both schemes, AirseekerRegistry // allows data feeds specs to be defined with either the data feed ID or // the dAPI name. EnumerableSet.Bytes32Set private activeDataFeedIds; EnumerableSet.Bytes32Set private activeDapiNames; // Considering that the update parameters are typically reused between data // feeds, a hash map is used to avoid storing the same update parameters // redundantly mapping(bytes32 => bytes32) private dataFeedIdToUpdateParametersHash; mapping(bytes32 => bytes32) private dapiNameToUpdateParametersHash; mapping(bytes32 => bytes) private updateParametersHashToValue; // Length of abi.encode(address, bytes32) uint256 private constant DATA_FEED_DETAILS_LENGTH_FOR_SINGLE_BEACON = 32 + 32; // Length of abi.encode(address[2], bytes32[2]) uint256 private constant DATA_FEED_DETAILS_LENGTH_FOR_BEACON_SET_WITH_TWO_BEACONS = 32 + 32 + (32 + 2 * 32) + (32 + 2 * 32); // Length of // abi.encode(address[MAXIMUM_BEACON_COUNT_IN_SET], bytes32[MAXIMUM_BEACON_COUNT_IN_SET]) uint256 private constant MAXIMUM_DATA_FEED_DETAILS_LENGTH = 32 + 32 + (32 + MAXIMUM_BEACON_COUNT_IN_SET * 32) + (32 + MAXIMUM_BEACON_COUNT_IN_SET * 32); /// @dev Reverts if the data feed ID is zero /// @param dataFeedId Data feed ID modifier onlyNonZeroDataFeedId(bytes32 dataFeedId) { require(dataFeedId != bytes32(0), "Data feed ID zero"); _; } /// @dev Reverts if the dAPI name is zero /// @param dapiName dAPI name modifier onlyNonZeroDapiName(bytes32 dapiName) { require(dapiName != bytes32(0), "dAPI name zero"); _; } /// @dev Reverts if the update parameters are too long /// @param updateParameters Update parameters modifier onlyValidUpdateParameters(bytes calldata updateParameters) { require( updateParameters.length <= MAXIMUM_UPDATE_PARAMETERS_LENGTH, "Update parameters too long" ); _; } /// @param owner_ Owner address /// @param api3ServerV1_ Api3ServerV1 contract address constructor(address owner_, address api3ServerV1_) { require(owner_ != address(0), "Owner address zero"); require(api3ServerV1_ != address(0), "Api3ServerV1 address zero"); _transferOwnership(owner_); api3ServerV1 = api3ServerV1_; } /// @notice Returns the owner address /// @return Owner address function owner() public view override(Ownable, IOwnable) returns (address) { return super.owner(); } /// @notice Overriden to be disabled function renounceOwnership() public pure override(Ownable, IOwnable) { revert("Ownership cannot be renounced"); } /// @notice Overriden to be disabled function transferOwnership( address ) public pure override(Ownable, IOwnable) { revert("Ownership cannot be transferred"); } /// @notice Called by the owner to set the data feed ID to be activated /// @param dataFeedId Data feed ID function setDataFeedIdToBeActivated( bytes32 dataFeedId ) external override onlyOwner onlyNonZeroDataFeedId(dataFeedId) { if (activeDataFeedIds.add(dataFeedId)) { emit ActivatedDataFeedId(dataFeedId); } } /// @notice Called by the owner to set the dAPI name to be activated /// @param dapiName dAPI name function setDapiNameToBeActivated( bytes32 dapiName ) external override onlyOwner onlyNonZeroDapiName(dapiName) { if (activeDapiNames.add(dapiName)) { emit ActivatedDapiName(dapiName); } } /// @notice Called by the owner to set the data feed ID to be deactivated /// @param dataFeedId Data feed ID function setDataFeedIdToBeDeactivated( bytes32 dataFeedId ) external override onlyOwner onlyNonZeroDataFeedId(dataFeedId) { if (activeDataFeedIds.remove(dataFeedId)) { emit DeactivatedDataFeedId(dataFeedId); } } /// @notice Called by the owner to set the dAPI name to be deactivated /// @param dapiName dAPI name function setDapiNameToBeDeactivated( bytes32 dapiName ) external override onlyOwner onlyNonZeroDapiName(dapiName) { if (activeDapiNames.remove(dapiName)) { emit DeactivatedDapiName(dapiName); } } /// @notice Called by the owner to set the data feed ID update parameters. /// The update parameters must be encoded in a format that Airseeker /// expects. /// @param dataFeedId Data feed ID /// @param updateParameters Update parameters function setDataFeedIdUpdateParameters( bytes32 dataFeedId, bytes calldata updateParameters ) external override onlyOwner onlyNonZeroDataFeedId(dataFeedId) onlyValidUpdateParameters(updateParameters) { bytes32 updateParametersHash = keccak256(updateParameters); if ( dataFeedIdToUpdateParametersHash[dataFeedId] != updateParametersHash ) { dataFeedIdToUpdateParametersHash[dataFeedId] = updateParametersHash; if ( updateParametersHashToValue[updateParametersHash].length != updateParameters.length ) { updateParametersHashToValue[ updateParametersHash ] = updateParameters; } emit UpdatedDataFeedIdUpdateParameters( dataFeedId, updateParameters ); } } /// @notice Called by the owner to set the dAPI name update parameters. /// The update parameters must be encoded in a format that Airseeker /// expects. /// @param dapiName dAPI name /// @param updateParameters Update parameters function setDapiNameUpdateParameters( bytes32 dapiName, bytes calldata updateParameters ) external override onlyOwner onlyNonZeroDapiName(dapiName) onlyValidUpdateParameters(updateParameters) { bytes32 updateParametersHash = keccak256(updateParameters); if (dapiNameToUpdateParametersHash[dapiName] != updateParametersHash) { dapiNameToUpdateParametersHash[dapiName] = updateParametersHash; if ( updateParametersHashToValue[updateParametersHash].length != updateParameters.length ) { updateParametersHashToValue[ updateParametersHash ] = updateParameters; } emit UpdatedDapiNameUpdateParameters(dapiName, updateParameters); } } /// @notice Called by the owner to set the signed API URL for the Airnode. /// The signed API must implement the specific interface that Airseeker /// expects. /// @param airnode Airnode address /// @param signedApiUrl Signed API URL function setSignedApiUrl( address airnode, string calldata signedApiUrl ) external override onlyOwner { require(airnode != address(0), "Airnode address zero"); require( abi.encodePacked(signedApiUrl).length <= MAXIMUM_SIGNED_API_URL_LENGTH, "Signed API URL too long" ); if ( keccak256(abi.encodePacked(airnodeToSignedApiUrl[airnode])) != keccak256(abi.encodePacked(signedApiUrl)) ) { airnodeToSignedApiUrl[airnode] = signedApiUrl; emit UpdatedSignedApiUrl(airnode, signedApiUrl); } } /// @notice Registers the data feed. In the case that the data feed is a /// Beacon, the details should be the ABI-encoded Airnode address and /// template ID. In the case that the data feed is a Beacon set, the /// details should be the ABI-encoded Airnode addresses array and template /// IDs array. /// @param dataFeedDetails Data feed details /// @return dataFeedId Data feed ID function registerDataFeed( bytes calldata dataFeedDetails ) external override returns (bytes32 dataFeedId) { uint256 dataFeedDetailsLength = dataFeedDetails.length; if ( dataFeedDetailsLength == DATA_FEED_DETAILS_LENGTH_FOR_SINGLE_BEACON ) { // dataFeedId maps to a Beacon (address airnode, bytes32 templateId) = abi.decode( dataFeedDetails, (address, bytes32) ); require(airnode != address(0), "Airnode address zero"); dataFeedId = deriveBeaconId(airnode, templateId); } else if ( dataFeedDetailsLength >= DATA_FEED_DETAILS_LENGTH_FOR_BEACON_SET_WITH_TWO_BEACONS ) { require( dataFeedDetailsLength <= MAXIMUM_DATA_FEED_DETAILS_LENGTH, "Data feed details too long" ); (address[] memory airnodes, bytes32[] memory templateIds) = abi .decode(dataFeedDetails, (address[], bytes32[])); require( abi.encode(airnodes, templateIds).length == dataFeedDetailsLength, "Data feed details trail" ); uint256 beaconCount = airnodes.length; require( beaconCount == templateIds.length, "Parameter length mismatch" ); bytes32[] memory beaconIds = new bytes32[](beaconCount); for (uint256 ind = 0; ind < beaconCount; ind++) { require(airnodes[ind] != address(0), "Airnode address zero"); beaconIds[ind] = deriveBeaconId( airnodes[ind], templateIds[ind] ); } dataFeedId = deriveBeaconSetId(beaconIds); } else { revert("Data feed details too short"); } if (dataFeedIdToDetails[dataFeedId].length != dataFeedDetailsLength) { dataFeedIdToDetails[dataFeedId] = dataFeedDetails; emit RegisteredDataFeed(dataFeedId, dataFeedDetails); } } /// @notice In an imaginary array consisting of the the active data feed /// IDs and active dAPI names, picks the index-th identifier, and returns /// all data about the respective data feed that is available. Whenever /// data is not available (including the case where index does not /// correspond to an active data feed), returns empty values. /// @dev Airseeker uses this function to get all the data it needs about an /// active data feed with a single RPC call /// @param index Index /// @return dataFeedId Data feed ID /// @return dapiName dAPI name (`bytes32(0)` if the active data feed is /// identified by a data feed ID) /// @return dataFeedDetails Data feed details /// @return dataFeedValue Data feed value read from Api3ServerV1 /// @return dataFeedTimestamp Data feed timestamp read from Api3ServerV1 /// @return beaconValues Beacon values read from Api3ServerV1 /// @return beaconTimestamps Beacon timestamps read from Api3ServerV1 /// @return updateParameters Update parameters /// @return signedApiUrls Signed API URLs of the Beacon Airnodes function activeDataFeed( uint256 index ) external view override returns ( bytes32 dataFeedId, bytes32 dapiName, bytes memory dataFeedDetails, int224 dataFeedValue, uint32 dataFeedTimestamp, int224[] memory beaconValues, uint32[] memory beaconTimestamps, bytes memory updateParameters, string[] memory signedApiUrls ) { uint256 activeDataFeedIdsLength = activeDataFeedIdCount(); if (index < activeDataFeedIdsLength) { dataFeedId = activeDataFeedIds.at(index); updateParameters = dataFeedIdToUpdateParameters(dataFeedId); } else if (index < activeDataFeedIdsLength + activeDapiNames.length()) { dapiName = activeDapiNames.at(index - activeDataFeedIdsLength); dataFeedId = IApi3ServerV1(api3ServerV1).dapiNameHashToDataFeedId( keccak256(abi.encodePacked(dapiName)) ); updateParameters = dapiNameToUpdateParameters(dapiName); } if (dataFeedId != bytes32(0)) { dataFeedDetails = dataFeedIdToDetails[dataFeedId]; (dataFeedValue, dataFeedTimestamp) = IApi3ServerV1(api3ServerV1) .dataFeeds(dataFeedId); } if (dataFeedDetails.length != 0) { if ( dataFeedDetails.length == DATA_FEED_DETAILS_LENGTH_FOR_SINGLE_BEACON ) { beaconValues = new int224[](1); beaconTimestamps = new uint32[](1); signedApiUrls = new string[](1); (address airnode, bytes32 templateId) = abi.decode( dataFeedDetails, (address, bytes32) ); (beaconValues[0], beaconTimestamps[0]) = IApi3ServerV1( api3ServerV1 ).dataFeeds(deriveBeaconId(airnode, templateId)); signedApiUrls[0] = airnodeToSignedApiUrl[airnode]; } else { (address[] memory airnodes, bytes32[] memory templateIds) = abi .decode(dataFeedDetails, (address[], bytes32[])); uint256 beaconCount = airnodes.length; beaconValues = new int224[](beaconCount); beaconTimestamps = new uint32[](beaconCount); signedApiUrls = new string[](beaconCount); for (uint256 ind = 0; ind < beaconCount; ind++) { (beaconValues[ind], beaconTimestamps[ind]) = IApi3ServerV1( api3ServerV1 ).dataFeeds( deriveBeaconId(airnodes[ind], templateIds[ind]) ); signedApiUrls[ind] = airnodeToSignedApiUrl[airnodes[ind]]; } } } } /// @notice Returns the number of active data feeds identified by a data /// feed ID or dAPI name /// @return Active data feed count function activeDataFeedCount() external view override returns (uint256) { return activeDataFeedIdCount() + activeDapiNameCount(); } /// @notice Returns the number of active data feeds identified by a data /// feed ID /// @return Active data feed ID count function activeDataFeedIdCount() public view override returns (uint256) { return activeDataFeedIds.length(); } /// @notice Returns the number of active data feeds identified by a dAPI /// name /// @return Active dAPI name count function activeDapiNameCount() public view override returns (uint256) { return activeDapiNames.length(); } /// @notice Data feed ID to update parameters /// @param dataFeedId Data feed ID /// @return updateParameters Update parameters function dataFeedIdToUpdateParameters( bytes32 dataFeedId ) public view override returns (bytes memory updateParameters) { updateParameters = updateParametersHashToValue[ dataFeedIdToUpdateParametersHash[dataFeedId] ]; } /// @notice dAPI name to update parameters /// @param dapiName dAPI name /// @return updateParameters Update parameters function dapiNameToUpdateParameters( bytes32 dapiName ) public view override returns (bytes memory updateParameters) { updateParameters = updateParametersHashToValue[ dapiNameToUpdateParametersHash[dapiName] ]; } /// @notice Returns if the data feed with ID is registered /// @param dataFeedId Data feed ID /// @return If the data feed with ID is registered function dataFeedIsRegistered( bytes32 dataFeedId ) external view override returns (bool) { return dataFeedIdToDetails[dataFeedId].length != 0; } /// @notice Derives the Beacon ID from the Airnode address and template ID /// @param airnode Airnode address /// @param templateId Template ID /// @return beaconId Beacon ID function deriveBeaconId( address airnode, bytes32 templateId ) private pure returns (bytes32 beaconId) { beaconId = keccak256(abi.encodePacked(airnode, templateId)); } /// @notice Derives the Beacon set ID from the Beacon IDs /// @param beaconIds Beacon IDs /// @return beaconSetId Beacon set ID function deriveBeaconSetId( bytes32[] memory beaconIds ) private pure returns (bytes32 beaconSetId) { beaconSetId = keccak256(abi.encode(beaconIds)); } }
contracts/access/interfaces/IAccessControlRegistry.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../vendor/@openzeppelin/contracts@4.8.2/access/IAccessControl.sol"; import "../../utils/interfaces/ISelfMulticall.sol"; interface IAccessControlRegistry is IAccessControl, ISelfMulticall { event InitializedManager( bytes32 indexed rootRole, address indexed manager, address sender ); event InitializedRole( bytes32 indexed role, bytes32 indexed adminRole, string description, address sender ); function initializeManager(address manager) external; function initializeRoleAndGrantToSender( bytes32 adminRole, string calldata description ) external returns (bytes32 role); }
contracts/vendor/@openzeppelin/contracts@4.9.5/utils/Context.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (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; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
contracts/utils/ExtendedSelfMulticall.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "./SelfMulticall.sol"; import "./interfaces/IExtendedSelfMulticall.sol"; /// @title Contract that extends SelfMulticall to fetch some of the global /// variables /// @notice Available global variables are limited to the ones that Airnode /// tends to need contract ExtendedSelfMulticall is SelfMulticall, IExtendedSelfMulticall { /// @notice Returns the chain ID /// @return Chain ID function getChainId() external view override returns (uint256) { return block.chainid; } /// @notice Returns the account balance /// @param account Account address /// @return Account balance function getBalance( address account ) external view override returns (uint256) { return account.balance; } /// @notice Returns if the account contains bytecode /// @dev An account not containing any bytecode does not indicate that it /// is an EOA or it will not contain any bytecode in the future. /// Contract construction and `SELFDESTRUCT` updates the bytecode at the /// end of the transaction. /// @return If the account contains bytecode function containsBytecode( address account ) external view override returns (bool) { return account.code.length > 0; } /// @notice Returns the current block number /// @return Current block number function getBlockNumber() external view override returns (uint256) { return block.number; } /// @notice Returns the current block timestamp /// @return Current block timestamp function getBlockTimestamp() external view override returns (uint256) { return block.timestamp; } /// @notice Returns the current block basefee /// @return Current block basefee function getBlockBasefee() external view override returns (uint256) { return block.basefee; } }
contracts/utils/SelfMulticall.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./interfaces/ISelfMulticall.sol"; /// @title Contract that enables calls to the inheriting contract to be batched /// @notice Implements two ways of batching, one requires none of the calls to /// revert and the other tolerates individual calls reverting /// @dev This implementation uses delegatecall for individual function calls. /// Since delegatecall is a message call, it can only be made to functions that /// are externally visible. This means that a contract cannot multicall its own /// functions that use internal/private visibility modifiers. /// Refer to OpenZeppelin's Multicall.sol for a similar implementation. contract SelfMulticall is ISelfMulticall { /// @notice Batches calls to the inheriting contract and reverts as soon as /// one of the batched calls reverts /// @param data Array of calldata of batched calls /// @return returndata Array of returndata of batched calls function multicall( bytes[] calldata data ) external override returns (bytes[] memory returndata) { uint256 callCount = data.length; returndata = new bytes[](callCount); for (uint256 ind = 0; ind < callCount; ) { bool success; // solhint-disable-next-line avoid-low-level-calls (success, returndata[ind]) = address(this).delegatecall(data[ind]); if (!success) { bytes memory returndataWithRevertData = returndata[ind]; if (returndataWithRevertData.length > 0) { // Adapted from OpenZeppelin's Address.sol // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndataWithRevertData) revert( add(32, returndataWithRevertData), returndata_size ) } } else { revert("Multicall: No revert string"); } } unchecked { ind++; } } } /// @notice Batches calls to the inheriting contract but does not revert if /// any of the batched calls reverts /// @param data Array of calldata of batched calls /// @return successes Array of success conditions of batched calls /// @return returndata Array of returndata of batched calls function tryMulticall( bytes[] calldata data ) external override returns (bool[] memory successes, bytes[] memory returndata) { uint256 callCount = data.length; successes = new bool[](callCount); returndata = new bytes[](callCount); for (uint256 ind = 0; ind < callCount; ) { // solhint-disable-next-line avoid-low-level-calls (successes[ind], returndata[ind]) = address(this).delegatecall( data[ind] ); unchecked { ind++; } } } }
contracts/api3-server-v1/interfaces/IBeaconUpdatesWithSignedData.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IDataFeedServer.sol"; interface IBeaconUpdatesWithSignedData is IDataFeedServer { function updateBeaconWithSignedData( address airnode, bytes32 templateId, uint256 timestamp, bytes calldata data, bytes calldata signature ) external returns (bytes32 beaconId); }
contracts/api3-server-v1/OevDapiServer.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "./OevDataFeedServer.sol"; import "./DapiServer.sol"; import "./interfaces/IOevDapiServer.sol"; /// @title Contract that serves OEV dAPIs contract OevDapiServer is OevDataFeedServer, DapiServer, IOevDapiServer { /// @param _accessControlRegistry AccessControlRegistry contract address /// @param _adminRoleDescription Admin role description /// @param _manager Manager address constructor( address _accessControlRegistry, string memory _adminRoleDescription, address _manager ) DapiServer(_accessControlRegistry, _adminRoleDescription, _manager) {} /// @notice Reads the data feed as the OEV proxy with dAPI name hash /// @param dapiNameHash dAPI name hash /// @return value Data feed value /// @return timestamp Data feed timestamp function _readDataFeedWithDapiNameHashAsOevProxy( bytes32 dapiNameHash ) internal view returns (int224 value, uint32 timestamp) { bytes32 dataFeedId = dapiNameHashToDataFeedId[dapiNameHash]; require(dataFeedId != bytes32(0), "dAPI name not set"); DataFeed storage oevDataFeed = _oevProxyToIdToDataFeed[msg.sender][ dataFeedId ]; DataFeed storage dataFeed = _dataFeeds[dataFeedId]; if (oevDataFeed.timestamp > dataFeed.timestamp) { (value, timestamp) = (oevDataFeed.value, oevDataFeed.timestamp); } else { (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } require(timestamp > 0, "Data feed not initialized"); } }
contracts/api3-server-v1/BeaconUpdatesWithSignedData.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "./DataFeedServer.sol"; import "./interfaces/IBeaconUpdatesWithSignedData.sol"; import "../vendor/@openzeppelin/contracts@4.8.2/utils/cryptography/ECDSA.sol"; /// @title Contract that updates Beacons using signed data contract BeaconUpdatesWithSignedData is DataFeedServer, IBeaconUpdatesWithSignedData { using ECDSA for bytes32; /// @notice Updates a Beacon using data signed by the Airnode /// @dev The signed data here is intentionally very general for practical /// reasons. It is less demanding on the signer to have data signed once /// and use that everywhere. /// @param airnode Airnode address /// @param templateId Template ID /// @param timestamp Signature timestamp /// @param data Update data (an `int256` encoded in contract ABI) /// @param signature Template ID, timestamp and the update data signed by /// the Airnode /// @return beaconId Updated Beacon ID function updateBeaconWithSignedData( address airnode, bytes32 templateId, uint256 timestamp, bytes calldata data, bytes calldata signature ) external override returns (bytes32 beaconId) { require( ( keccak256(abi.encodePacked(templateId, timestamp, data)) .toEthSignedMessageHash() ).recover(signature) == airnode, "Signature mismatch" ); beaconId = deriveBeaconId(airnode, templateId); int224 updatedValue = processBeaconUpdate(beaconId, timestamp, data); emit UpdatedBeaconWithSignedData( beaconId, updatedValue, uint32(timestamp) ); } }
contracts/api3-server-v1/OevDataFeedServer.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "./DataFeedServer.sol"; import "./interfaces/IOevDataFeedServer.sol"; import "../vendor/@openzeppelin/contracts@4.8.2/utils/cryptography/ECDSA.sol"; import "./proxies/interfaces/IOevProxy.sol"; /// @title Contract that serves OEV Beacons and Beacon sets /// @notice OEV Beacons and Beacon sets can be updated by the winner of the /// respective OEV auctions. The beneficiary can withdraw the proceeds from /// this contract. contract OevDataFeedServer is DataFeedServer, IOevDataFeedServer { using ECDSA for bytes32; /// @notice Data feed with ID specific to the OEV proxy /// @dev This implies that an update as a result of an OEV auction only /// affects contracts that read through the respective proxy that the /// auction was being held for mapping(address => mapping(bytes32 => DataFeed)) internal _oevProxyToIdToDataFeed; /// @notice Accumulated OEV auction proceeds for the specific proxy mapping(address => uint256) public override oevProxyToBalance; /// @notice Updates a data feed that the OEV proxy reads using the /// aggregation signed by the absolute majority of the respective Airnodes /// for the specific bid /// @dev For when the data feed being updated is a Beacon set, an absolute /// majority of the Airnodes that power the respective Beacons must sign /// the aggregated value and timestamp. While doing so, the Airnodes should /// refer to data signed to update an absolute majority of the respective /// Beacons. The Airnodes should require the data to be fresh enough (e.g., /// at most 2 minutes-old), and tightly distributed around the resulting /// aggregation (e.g., within 1% deviation), and reject to provide an OEV /// proxy data feed update signature if these are not satisfied. /// @param oevProxy OEV proxy that reads the data feed /// @param dataFeedId Data feed ID /// @param updateId Update ID /// @param timestamp Signature timestamp /// @param data Update data (an `int256` encoded in contract ABI) /// @param packedOevUpdateSignatures Packed OEV update signatures, which /// include the Airnode address, template ID and these signed with the OEV /// update hash function updateOevProxyDataFeedWithSignedData( address oevProxy, bytes32 dataFeedId, bytes32 updateId, uint256 timestamp, bytes calldata data, bytes[] calldata packedOevUpdateSignatures ) external payable override onlyValidTimestamp(timestamp) { require( timestamp > _oevProxyToIdToDataFeed[oevProxy][dataFeedId].timestamp, "Does not update timestamp" ); bytes32 oevUpdateHash = keccak256( abi.encodePacked( block.chainid, address(this), oevProxy, dataFeedId, updateId, timestamp, data, msg.sender, msg.value ) ); int224 updatedValue = decodeFulfillmentData(data); uint32 updatedTimestamp = uint32(timestamp); uint256 beaconCount = packedOevUpdateSignatures.length; if (beaconCount > 1) { bytes32[] memory beaconIds = new bytes32[](beaconCount); uint256 validSignatureCount; for (uint256 ind = 0; ind < beaconCount; ) { bool signatureIsNotOmitted; ( signatureIsNotOmitted, beaconIds[ind] ) = unpackAndValidateOevUpdateSignature( oevUpdateHash, packedOevUpdateSignatures[ind] ); if (signatureIsNotOmitted) { unchecked { validSignatureCount++; } } unchecked { ind++; } } // "Greater than or equal to" is not enough because full control // of aggregation requires an absolute majority require( validSignatureCount > beaconCount / 2, "Not enough signatures" ); require( dataFeedId == deriveBeaconSetId(beaconIds), "Beacon set ID mismatch" ); emit UpdatedOevProxyBeaconSetWithSignedData( dataFeedId, oevProxy, updateId, updatedValue, updatedTimestamp ); } else if (beaconCount == 1) { { ( bool signatureIsNotOmitted, bytes32 beaconId ) = unpackAndValidateOevUpdateSignature( oevUpdateHash, packedOevUpdateSignatures[0] ); require(signatureIsNotOmitted, "Missing signature"); require(dataFeedId == beaconId, "Beacon ID mismatch"); } emit UpdatedOevProxyBeaconWithSignedData( dataFeedId, oevProxy, updateId, updatedValue, updatedTimestamp ); } else { revert("Did not specify any Beacons"); } _oevProxyToIdToDataFeed[oevProxy][dataFeedId] = DataFeed({ value: updatedValue, timestamp: updatedTimestamp }); oevProxyToBalance[oevProxy] += msg.value; } /// @notice Withdraws the balance of the OEV proxy to the respective /// beneficiary account /// @dev This does not require the caller to be the beneficiary because we /// expect that in most cases, the OEV beneficiary will be a contract that /// will not be able to make arbitrary calls. Our choice can be worked /// around by implementing a beneficiary proxy. /// @param oevProxy OEV proxy function withdraw(address oevProxy) external override { address oevBeneficiary = IOevProxy(oevProxy).oevBeneficiary(); require(oevBeneficiary != address(0), "Beneficiary address zero"); uint256 balance = oevProxyToBalance[oevProxy]; require(balance != 0, "OEV proxy balance zero"); oevProxyToBalance[oevProxy] = 0; emit Withdrew(oevProxy, oevBeneficiary, balance); // solhint-disable-next-line avoid-low-level-calls (bool success, ) = oevBeneficiary.call{value: balance}(""); require(success, "Withdrawal reverted"); } /// @notice Reads the data feed as the OEV proxy with ID /// @param dataFeedId Data feed ID /// @return value Data feed value /// @return timestamp Data feed timestamp function _readDataFeedWithIdAsOevProxy( bytes32 dataFeedId ) internal view returns (int224 value, uint32 timestamp) { DataFeed storage oevDataFeed = _oevProxyToIdToDataFeed[msg.sender][ dataFeedId ]; DataFeed storage dataFeed = _dataFeeds[dataFeedId]; if (oevDataFeed.timestamp > dataFeed.timestamp) { (value, timestamp) = (oevDataFeed.value, oevDataFeed.timestamp); } else { (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } require(timestamp > 0, "Data feed not initialized"); } /// @notice Called privately to unpack and validate the OEV update /// signature /// @param oevUpdateHash OEV update hash /// @param packedOevUpdateSignature Packed OEV update signature, which /// includes the Airnode address, template ID and these signed with the OEV /// update hash /// @return signatureIsNotOmitted If the signature is omitted in /// `packedOevUpdateSignature` /// @return beaconId Beacon ID function unpackAndValidateOevUpdateSignature( bytes32 oevUpdateHash, bytes calldata packedOevUpdateSignature ) private pure returns (bool signatureIsNotOmitted, bytes32 beaconId) { (address airnode, bytes32 templateId, bytes memory signature) = abi .decode(packedOevUpdateSignature, (address, bytes32, bytes)); beaconId = deriveBeaconId(airnode, templateId); if (signature.length != 0) { require( ( keccak256(abi.encodePacked(oevUpdateHash, templateId)) .toEthSignedMessageHash() ).recover(signature) == airnode, "Signature mismatch" ); signatureIsNotOmitted = true; } } }
contracts/api3-server-v1/proxies/interfaces/IOevProxy.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IOevProxy { function oevBeneficiary() external view returns (address); }
contracts/utils/interfaces/ISelfMulticall.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ISelfMulticall { function multicall( bytes[] calldata data ) external returns (bytes[] memory returndata); function tryMulticall( bytes[] calldata data ) external returns (bool[] memory successes, bytes[] memory returndata); }
contracts/api3-server-v1/interfaces/IDataFeedServer.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/interfaces/IExtendedSelfMulticall.sol"; interface IDataFeedServer is IExtendedSelfMulticall { event UpdatedBeaconWithSignedData( bytes32 indexed beaconId, int224 value, uint32 timestamp ); event UpdatedBeaconSetWithBeacons( bytes32 indexed beaconSetId, int224 value, uint32 timestamp ); function updateBeaconSetWithBeacons( bytes32[] memory beaconIds ) external returns (bytes32 beaconSetId); }
contracts/api3-server-v1/interfaces/IDapiServer.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../access/interfaces/IAccessControlRegistryAdminnedWithManager.sol"; import "./IDataFeedServer.sol"; interface IDapiServer is IAccessControlRegistryAdminnedWithManager, IDataFeedServer { event SetDapiName( bytes32 indexed dataFeedId, bytes32 indexed dapiName, address sender ); function setDapiName(bytes32 dapiName, bytes32 dataFeedId) external; function dapiNameToDataFeedId( bytes32 dapiName ) external view returns (bytes32); // solhint-disable-next-line func-name-mixedcase function DAPI_NAME_SETTER_ROLE_DESCRIPTION() external view returns (string memory); function dapiNameSetterRole() external view returns (bytes32); function dapiNameHashToDataFeedId( bytes32 dapiNameHash ) external view returns (bytes32 dataFeedId); }
contracts/access/interfaces/IAccessControlRegistryAdminned.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/interfaces/ISelfMulticall.sol"; interface IAccessControlRegistryAdminned is ISelfMulticall { function accessControlRegistry() external view returns (address); function adminRoleDescription() external view returns (string memory); }
contracts/api3-server-v1/aggregation/QuickSelect.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contract to be inherited by contracts that will calculate the index /// of the k-th and optionally (k+1)-th largest elements in the array /// @notice Uses quickselect, which operates in-place, i.e., the array provided /// as the argument will be modified. contract Quickselect { /// @notice Returns the index of the k-th largest element in the array /// @param array Array in which k-th largest element will be searched /// @param k K /// @return indK Index of the k-th largest element function quickselectK( int256[] memory array, uint256 k ) internal pure returns (uint256 indK) { uint256 arrayLength = array.length; assert(arrayLength > 0); unchecked { (indK, ) = quickselect(array, 0, arrayLength - 1, k, false); } } /// @notice Returns the index of the k-th and (k+1)-th largest elements in /// the array /// @param array Array in which k-th and (k+1)-th largest elements will be /// searched /// @param k K /// @return indK Index of the k-th largest element /// @return indKPlusOne Index of the (k+1)-th largest element function quickselectKPlusOne( int256[] memory array, uint256 k ) internal pure returns (uint256 indK, uint256 indKPlusOne) { uint256 arrayLength = array.length; assert(arrayLength > 1); unchecked { (indK, indKPlusOne) = quickselect( array, 0, arrayLength - 1, k, true ); } } /// @notice Returns the index of the k-th largest element in the specified /// section of the (potentially unsorted) array /// @param array Array in which K will be searched for /// @param lo Starting index of the section of the array that K will be /// searched in /// @param hi Last index of the section of the array that K will be /// searched in /// @param k K /// @param selectKPlusOne If the index of the (k+1)-th largest element is /// to be returned /// @return indK Index of the k-th largest element /// @return indKPlusOne Index of the (k+1)-th largest element (only set if /// `selectKPlusOne` is `true`) function quickselect( int256[] memory array, uint256 lo, uint256 hi, uint256 k, bool selectKPlusOne ) private pure returns (uint256 indK, uint256 indKPlusOne) { if (lo == hi) { return (k, 0); } uint256 indPivot = partition(array, lo, hi); if (k < indPivot) { unchecked { (indK, ) = quickselect(array, lo, indPivot - 1, k, false); } } else if (k > indPivot) { unchecked { (indK, ) = quickselect(array, indPivot + 1, hi, k, false); } } else { indK = indPivot; } // Since Quickselect ends in the array being partitioned around the // k-th largest element, we can continue searching towards right for // the (k+1)-th largest element, which is useful in calculating the // median of an array with even length if (selectKPlusOne) { unchecked { indKPlusOne = indK + 1; } uint256 i; unchecked { i = indKPlusOne + 1; } uint256 arrayLength = array.length; for (; i < arrayLength; ) { if (array[i] < array[indKPlusOne]) { indKPlusOne = i; } unchecked { i++; } } } } /// @notice Partitions the array into two around a pivot /// @param array Array that will be partitioned /// @param lo Starting index of the section of the array that will be /// partitioned /// @param hi Last index of the section of the array that will be /// partitioned /// @return pivotInd Pivot index function partition( int256[] memory array, uint256 lo, uint256 hi ) private pure returns (uint256 pivotInd) { if (lo == hi) { return lo; } int256 pivot = array[lo]; uint256 i = lo; unchecked { pivotInd = hi + 1; } while (true) { do { unchecked { i++; } } while (i < array.length && array[i] < pivot); do { unchecked { pivotInd--; } } while (array[pivotInd] > pivot); if (i >= pivotInd) { (array[lo], array[pivotInd]) = (array[pivotInd], array[lo]); return pivotInd; } (array[i], array[pivotInd]) = (array[pivotInd], array[i]); } } }
contracts/api3-server-v1/interfaces/IOevDataFeedServer.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IDataFeedServer.sol"; interface IOevDataFeedServer is IDataFeedServer { event UpdatedOevProxyBeaconWithSignedData( bytes32 indexed beaconId, address indexed proxy, bytes32 indexed updateId, int224 value, uint32 timestamp ); event UpdatedOevProxyBeaconSetWithSignedData( bytes32 indexed beaconSetId, address indexed proxy, bytes32 indexed updateId, int224 value, uint32 timestamp ); event Withdrew( address indexed oevProxy, address oevBeneficiary, uint256 amount ); function updateOevProxyDataFeedWithSignedData( address oevProxy, bytes32 dataFeedId, bytes32 updateId, uint256 timestamp, bytes calldata data, bytes[] calldata packedOevUpdateSignatures ) external payable; function withdraw(address oevProxy) external; function oevProxyToBalance( address oevProxy ) external view returns (uint256 balance); }
contracts/access/AccessControlRegistryAdminned.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/SelfMulticall.sol"; import "./RoleDeriver.sol"; import "./interfaces/IAccessControlRegistryAdminned.sol"; import "./interfaces/IAccessControlRegistry.sol"; /// @title Contract to be inherited by contracts whose adminship functionality /// will be implemented using AccessControlRegistry contract AccessControlRegistryAdminned is SelfMulticall, RoleDeriver, IAccessControlRegistryAdminned { /// @notice AccessControlRegistry contract address address public immutable override accessControlRegistry; /// @notice Admin role description string public override adminRoleDescription; bytes32 internal immutable adminRoleDescriptionHash; /// @dev Contracts deployed with the same admin role descriptions will have /// the same roles, meaning that granting an account a role will authorize /// it in multiple contracts. Unless you want your deployed contract to /// share the role configuration of another contract, use a unique admin /// role description. /// @param _accessControlRegistry AccessControlRegistry contract address /// @param _adminRoleDescription Admin role description constructor( address _accessControlRegistry, string memory _adminRoleDescription ) { require(_accessControlRegistry != address(0), "ACR address zero"); require( bytes(_adminRoleDescription).length > 0, "Admin role description empty" ); accessControlRegistry = _accessControlRegistry; adminRoleDescription = _adminRoleDescription; adminRoleDescriptionHash = keccak256( abi.encodePacked(_adminRoleDescription) ); } /// @notice Derives the admin role for the specific manager address /// @param manager Manager address /// @return adminRole Admin role function _deriveAdminRole( address manager ) internal view returns (bytes32 adminRole) { adminRole = _deriveRole( _deriveRootRole(manager), adminRoleDescriptionHash ); } }
contracts/api3-server-v1/DataFeedServer.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../utils/ExtendedSelfMulticall.sol"; import "./aggregation/Median.sol"; import "./interfaces/IDataFeedServer.sol"; import "../vendor/@openzeppelin/contracts@4.8.2/utils/cryptography/ECDSA.sol"; /// @title Contract that serves Beacons and Beacon sets /// @notice A Beacon is a live data feed addressed by an ID, which is derived /// from an Airnode address and a template ID. This is suitable where the more /// recent data point is always more favorable, e.g., in the context of an /// asset price data feed. Beacons can also be seen as one-Airnode data feeds /// that can be used individually or combined to build Beacon sets. contract DataFeedServer is ExtendedSelfMulticall, Median, IDataFeedServer { using ECDSA for bytes32; // Airnodes serve their fulfillment data along with timestamps. This // contract casts the reported data to `int224` and the timestamp to // `uint32`, which works until year 2106. struct DataFeed { int224 value; uint32 timestamp; } /// @notice Data feed with ID mapping(bytes32 => DataFeed) internal _dataFeeds; /// @dev Reverts if the timestamp is from more than 1 hour in the future modifier onlyValidTimestamp(uint256 timestamp) virtual { unchecked { require( timestamp < block.timestamp + 1 hours, "Timestamp not valid" ); } _; } /// @notice Updates the Beacon set using the current values of its Beacons /// @dev As an oddity, this function still works if some of the IDs in /// `beaconIds` belong to Beacon sets rather than Beacons. This can be used /// to implement hierarchical Beacon sets. /// @param beaconIds Beacon IDs /// @return beaconSetId Beacon set ID function updateBeaconSetWithBeacons( bytes32[] memory beaconIds ) public override returns (bytes32 beaconSetId) { (int224 updatedValue, uint32 updatedTimestamp) = aggregateBeacons( beaconIds ); beaconSetId = deriveBeaconSetId(beaconIds); DataFeed storage beaconSet = _dataFeeds[beaconSetId]; if (beaconSet.timestamp == updatedTimestamp) { require( beaconSet.value != updatedValue, "Does not update Beacon set" ); } _dataFeeds[beaconSetId] = DataFeed({ value: updatedValue, timestamp: updatedTimestamp }); emit UpdatedBeaconSetWithBeacons( beaconSetId, updatedValue, updatedTimestamp ); } /// @notice Reads the data feed with ID /// @param dataFeedId Data feed ID /// @return value Data feed value /// @return timestamp Data feed timestamp function _readDataFeedWithId( bytes32 dataFeedId ) internal view returns (int224 value, uint32 timestamp) { DataFeed storage dataFeed = _dataFeeds[dataFeedId]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); require(timestamp > 0, "Data feed not initialized"); } /// @notice Derives the Beacon ID from the Airnode address and template ID /// @param airnode Airnode address /// @param templateId Template ID /// @return beaconId Beacon ID function deriveBeaconId( address airnode, bytes32 templateId ) internal pure returns (bytes32 beaconId) { beaconId = keccak256(abi.encodePacked(airnode, templateId)); } /// @notice Derives the Beacon set ID from the Beacon IDs /// @dev Notice that `abi.encode()` is used over `abi.encodePacked()` /// @param beaconIds Beacon IDs /// @return beaconSetId Beacon set ID function deriveBeaconSetId( bytes32[] memory beaconIds ) internal pure returns (bytes32 beaconSetId) { beaconSetId = keccak256(abi.encode(beaconIds)); } /// @notice Called privately to process the Beacon update /// @param beaconId Beacon ID /// @param timestamp Timestamp used in the signature /// @param data Fulfillment data (an `int256` encoded in contract ABI) /// @return updatedBeaconValue Updated Beacon value function processBeaconUpdate( bytes32 beaconId, uint256 timestamp, bytes calldata data ) internal onlyValidTimestamp(timestamp) returns (int224 updatedBeaconValue) { updatedBeaconValue = decodeFulfillmentData(data); require( timestamp > _dataFeeds[beaconId].timestamp, "Does not update timestamp" ); _dataFeeds[beaconId] = DataFeed({ value: updatedBeaconValue, timestamp: uint32(timestamp) }); } /// @notice Called privately to decode the fulfillment data /// @param data Fulfillment data (an `int256` encoded in contract ABI) /// @return decodedData Decoded fulfillment data function decodeFulfillmentData( bytes memory data ) internal pure returns (int224) { require(data.length == 32, "Data length not correct"); int256 decodedData = abi.decode(data, (int256)); require( decodedData >= type(int224).min && decodedData <= type(int224).max, "Value typecasting error" ); return int224(decodedData); } /// @notice Called privately to aggregate the Beacons and return the result /// @param beaconIds Beacon IDs /// @return value Aggregation value /// @return timestamp Aggregation timestamp function aggregateBeacons( bytes32[] memory beaconIds ) internal view returns (int224 value, uint32 timestamp) { uint256 beaconCount = beaconIds.length; require(beaconCount > 1, "Specified less than two Beacons"); int256[] memory values = new int256[](beaconCount); int256[] memory timestamps = new int256[](beaconCount); for (uint256 ind = 0; ind < beaconCount; ) { DataFeed storage dataFeed = _dataFeeds[beaconIds[ind]]; values[ind] = dataFeed.value; timestamps[ind] = int256(uint256(dataFeed.timestamp)); unchecked { ind++; } } value = int224(median(values)); timestamp = uint32(uint256(median(timestamps))); } }
contracts/vendor/@openzeppelin/contracts@4.8.2/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
contracts/vendor/@openzeppelin/contracts@4.8.2/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
contracts/api3-server-v1/interfaces/IAirseekerRegistry.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../access/interfaces/IOwnable.sol"; import "../../utils/interfaces/IExtendedSelfMulticall.sol"; interface IAirseekerRegistry is IOwnable, IExtendedSelfMulticall { event ActivatedDataFeedId(bytes32 indexed dataFeedId); event ActivatedDapiName(bytes32 indexed dapiName); event DeactivatedDataFeedId(bytes32 indexed dataFeedId); event DeactivatedDapiName(bytes32 indexed dapiName); event UpdatedDataFeedIdUpdateParameters( bytes32 indexed dataFeedId, bytes updateParameters ); event UpdatedDapiNameUpdateParameters( bytes32 indexed dapiName, bytes updateParameters ); event UpdatedSignedApiUrl(address indexed airnode, string signedApiUrl); event RegisteredDataFeed(bytes32 indexed dataFeedId, bytes dataFeedDetails); function setDataFeedIdToBeActivated(bytes32 dataFeedId) external; function setDapiNameToBeActivated(bytes32 dapiName) external; function setDataFeedIdToBeDeactivated(bytes32 dataFeedId) external; function setDapiNameToBeDeactivated(bytes32 dapiName) external; function setDataFeedIdUpdateParameters( bytes32 dataFeedId, bytes calldata updateParameters ) external; function setDapiNameUpdateParameters( bytes32 dapiName, bytes calldata updateParameters ) external; function setSignedApiUrl( address airnode, string calldata signedApiUrl ) external; function registerDataFeed( bytes calldata dataFeedDetails ) external returns (bytes32 dataFeedId); function activeDataFeed( uint256 index ) external view returns ( bytes32 dataFeedId, bytes32 dapiName, bytes memory dataFeedDetails, int224 dataFeedValue, uint32 dataFeedTimestamp, int224[] memory beaconValues, uint32[] memory beaconTimestamps, bytes memory updateParameters, string[] memory signedApiUrls ); function activeDataFeedCount() external view returns (uint256); function activeDataFeedIdCount() external view returns (uint256); function activeDapiNameCount() external view returns (uint256); function dataFeedIdToUpdateParameters( bytes32 dataFeedId ) external view returns (bytes memory updateParameters); function dapiNameToUpdateParameters( bytes32 dapiName ) external view returns (bytes memory updateParameters); function dataFeedIsRegistered( bytes32 dataFeedId ) external view returns (bool); function MAXIMUM_BEACON_COUNT_IN_SET() external view returns (uint256); function MAXIMUM_UPDATE_PARAMETERS_LENGTH() external view returns (uint256); function MAXIMUM_SIGNED_API_URL_LENGTH() external view returns (uint256); function api3ServerV1() external view returns (address); function airnodeToSignedApiUrl( address airnode ) external view returns (string memory signedApiUrl); function dataFeedIdToDetails( bytes32 dataFeedId ) external view returns (bytes memory dataFeedDetails); }
contracts/api3-server-v1/interfaces/IApi3ServerV1.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IOevDapiServer.sol"; import "./IBeaconUpdatesWithSignedData.sol"; interface IApi3ServerV1 is IOevDapiServer, IBeaconUpdatesWithSignedData { function readDataFeedWithId( bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); function readDataFeedWithDapiNameHash( bytes32 dapiNameHash ) external view returns (int224 value, uint32 timestamp); function readDataFeedWithIdAsOevProxy( bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); function readDataFeedWithDapiNameHashAsOevProxy( bytes32 dapiNameHash ) external view returns (int224 value, uint32 timestamp); function dataFeeds( bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); function oevProxyToIdToDataFeed( address proxy, bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); }
contracts/access/interfaces/IOwnable.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IOwnable { function owner() external view returns (address); function renounceOwnership() external; function transferOwnership(address newOwner) external; }
contracts/api3-server-v1/DapiServer.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../access/AccessControlRegistryAdminnedWithManager.sol"; import "./DataFeedServer.sol"; import "./interfaces/IDapiServer.sol"; /// @title Contract that serves dAPIs mapped to Beacons and Beacon sets /// @notice Beacons and Beacon sets are addressed by immutable IDs. Although /// this is trust-minimized, it requires users to manage the ID of the data /// feed they are using. For when the user does not want to do this, dAPIs can /// be used as an abstraction layer. By using a dAPI, the user delegates this /// responsibility to dAPI management. It is important for dAPI management to /// be restricted by consensus rules (by using a multisig or a DAO) and similar /// trustless security mechanisms. contract DapiServer is AccessControlRegistryAdminnedWithManager, DataFeedServer, IDapiServer { /// @notice dAPI name setter role description string public constant override DAPI_NAME_SETTER_ROLE_DESCRIPTION = "dAPI name setter"; /// @notice dAPI name setter role bytes32 public immutable override dapiNameSetterRole; /// @notice dAPI name hash mapped to the data feed ID mapping(bytes32 => bytes32) public override dapiNameHashToDataFeedId; /// @param _accessControlRegistry AccessControlRegistry contract address /// @param _adminRoleDescription Admin role description /// @param _manager Manager address constructor( address _accessControlRegistry, string memory _adminRoleDescription, address _manager ) AccessControlRegistryAdminnedWithManager( _accessControlRegistry, _adminRoleDescription, _manager ) { dapiNameSetterRole = _deriveRole( _deriveAdminRole(manager), DAPI_NAME_SETTER_ROLE_DESCRIPTION ); } /// @notice Sets the data feed ID the dAPI name points to /// @dev While a data feed ID refers to a specific Beacon or Beacon set, /// dAPI names provide a more abstract interface for convenience. This /// means a dAPI name that was pointing to a Beacon can be pointed to a /// Beacon set, then another Beacon set, etc. /// @param dapiName Human-readable dAPI name /// @param dataFeedId Data feed ID the dAPI name will point to function setDapiName( bytes32 dapiName, bytes32 dataFeedId ) external override { require(dapiName != bytes32(0), "dAPI name zero"); require( msg.sender == manager || IAccessControlRegistry(accessControlRegistry).hasRole( dapiNameSetterRole, msg.sender ), "Sender cannot set dAPI name" ); dapiNameHashToDataFeedId[ keccak256(abi.encodePacked(dapiName)) ] = dataFeedId; emit SetDapiName(dataFeedId, dapiName, msg.sender); } /// @notice Returns the data feed ID the dAPI name is set to /// @param dapiName dAPI name /// @return Data feed ID function dapiNameToDataFeedId( bytes32 dapiName ) external view override returns (bytes32) { return dapiNameHashToDataFeedId[keccak256(abi.encodePacked(dapiName))]; } /// @notice Reads the data feed with dAPI name hash /// @param dapiNameHash dAPI name hash /// @return value Data feed value /// @return timestamp Data feed timestamp function _readDataFeedWithDapiNameHash( bytes32 dapiNameHash ) internal view returns (int224 value, uint32 timestamp) { bytes32 dataFeedId = dapiNameHashToDataFeedId[dapiNameHash]; require(dataFeedId != bytes32(0), "dAPI name not set"); DataFeed storage dataFeed = _dataFeeds[dataFeedId]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); require(timestamp > 0, "Data feed not initialized"); } }
contracts/vendor/@openzeppelin/contracts@4.8.2/utils/math/Math.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
contracts/access/AccessControlRegistryAdminnedWithManager.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./AccessControlRegistryAdminned.sol"; import "./interfaces/IAccessControlRegistryAdminnedWithManager.sol"; /// @title Contract to be inherited by contracts with manager whose adminship /// functionality will be implemented using AccessControlRegistry /// @notice The manager address here is expected to belong to an /// AccessControlRegistry user that is a multisig/DAO contract AccessControlRegistryAdminnedWithManager is AccessControlRegistryAdminned, IAccessControlRegistryAdminnedWithManager { /// @notice Address of the manager that manages the related /// AccessControlRegistry roles /// @dev The mutability of the manager role can be implemented by /// designating an OwnableCallForwarder contract as the manager. The /// ownership of this contract can then be transferred, effectively /// transferring managership. address public immutable override manager; /// @notice Admin role /// @dev Since `manager` is immutable, so is `adminRole` bytes32 public immutable override adminRole; /// @param _accessControlRegistry AccessControlRegistry contract address /// @param _adminRoleDescription Admin role description /// @param _manager Manager address constructor( address _accessControlRegistry, string memory _adminRoleDescription, address _manager ) AccessControlRegistryAdminned( _accessControlRegistry, _adminRoleDescription ) { require(_manager != address(0), "Manager address zero"); manager = _manager; adminRole = _deriveAdminRole(_manager); } }
contracts/access/interfaces/IAccessControlRegistryAdminnedWithManager.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IAccessControlRegistryAdminned.sol"; interface IAccessControlRegistryAdminnedWithManager is IAccessControlRegistryAdminned { function manager() external view returns (address); function adminRole() external view returns (bytes32); }
contracts/access/RoleDeriver.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contract to be inherited by contracts that will derive /// AccessControlRegistry roles /// @notice If a contract interfaces with AccessControlRegistry and needs to /// derive roles, it should inherit this contract instead of re-implementing /// the logic contract RoleDeriver { /// @notice Derives the root role of the manager /// @param manager Manager address /// @return rootRole Root role function _deriveRootRole( address manager ) internal pure returns (bytes32 rootRole) { rootRole = keccak256(abi.encodePacked(manager)); } /// @notice Derives the role using its admin role and description /// @dev This implies that roles adminned by the same role cannot have the /// same description /// @param adminRole Admin role /// @param description Human-readable description of the role /// @return role Role function _deriveRole( bytes32 adminRole, string memory description ) internal pure returns (bytes32 role) { role = _deriveRole(adminRole, keccak256(abi.encodePacked(description))); } /// @notice Derives the role using its admin role and description hash /// @dev This implies that roles adminned by the same role cannot have the /// same description /// @param adminRole Admin role /// @param descriptionHash Hash of the human-readable description of the /// role /// @return role Role function _deriveRole( bytes32 adminRole, bytes32 descriptionHash ) internal pure returns (bytes32 role) { role = keccak256(abi.encodePacked(adminRole, descriptionHash)); } }
contracts/vendor/@openzeppelin/contracts@4.9.5/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ```solidity * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
contracts/vendor/@openzeppelin/contracts@4.8.2/access/IAccessControl.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
contracts/api3-server-v1/Api3ServerV1.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "./OevDapiServer.sol"; import "./BeaconUpdatesWithSignedData.sol"; import "./interfaces/IApi3ServerV1.sol"; /// @title First version of the contract that API3 uses to serve data feeds /// @notice Api3ServerV1 serves data feeds in the form of Beacons, Beacon sets, /// dAPIs, with optional OEV support for all of these. /// The base Beacons are only updateable using signed data, and the Beacon sets /// are updateable based on the Beacons, optionally using PSP. OEV proxy /// Beacons and Beacon sets are updateable using OEV-signed data. /// Api3ServerV1 does not support Beacons to be updated using RRP or PSP. contract Api3ServerV1 is OevDapiServer, BeaconUpdatesWithSignedData, IApi3ServerV1 { /// @param _accessControlRegistry AccessControlRegistry contract address /// @param _adminRoleDescription Admin role description /// @param _manager Manager address constructor( address _accessControlRegistry, string memory _adminRoleDescription, address _manager ) OevDapiServer(_accessControlRegistry, _adminRoleDescription, _manager) {} /// @notice Reads the data feed with ID /// @param dataFeedId Data feed ID /// @return value Data feed value /// @return timestamp Data feed timestamp function readDataFeedWithId( bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { return _readDataFeedWithId(dataFeedId); } /// @notice Reads the data feed with dAPI name hash /// @param dapiNameHash dAPI name hash /// @return value Data feed value /// @return timestamp Data feed timestamp function readDataFeedWithDapiNameHash( bytes32 dapiNameHash ) external view override returns (int224 value, uint32 timestamp) { return _readDataFeedWithDapiNameHash(dapiNameHash); } /// @notice Reads the data feed as the OEV proxy with ID /// @param dataFeedId Data feed ID /// @return value Data feed value /// @return timestamp Data feed timestamp function readDataFeedWithIdAsOevProxy( bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { return _readDataFeedWithIdAsOevProxy(dataFeedId); } /// @notice Reads the data feed as the OEV proxy with dAPI name hash /// @param dapiNameHash dAPI name hash /// @return value Data feed value /// @return timestamp Data feed timestamp function readDataFeedWithDapiNameHashAsOevProxy( bytes32 dapiNameHash ) external view override returns (int224 value, uint32 timestamp) { return _readDataFeedWithDapiNameHashAsOevProxy(dapiNameHash); } function dataFeeds( bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { DataFeed storage dataFeed = _dataFeeds[dataFeedId]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } function oevProxyToIdToDataFeed( address proxy, bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { DataFeed storage dataFeed = _oevProxyToIdToDataFeed[proxy][dataFeedId]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } }
contracts/api3-server-v1/aggregation/Sort.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contract to be inherited by contracts that will sort an array using /// an unrolled implementation /// @notice The operation will be in-place, i.e., the array provided as the /// argument will be modified. contract Sort { uint256 internal constant MAX_SORT_LENGTH = 9; /// @notice Sorts the array /// @param array Array to be sorted function sort(int256[] memory array) internal pure { uint256 arrayLength = array.length; require(arrayLength <= MAX_SORT_LENGTH, "Array too long to sort"); // Do a binary search if (arrayLength < 6) { // Possible lengths: 1, 2, 3, 4, 5 if (arrayLength < 4) { // Possible lengths: 1, 2, 3 if (arrayLength == 3) { // Length: 3 swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 0, 1); } else if (arrayLength == 2) { // Length: 2 swapIfFirstIsLarger(array, 0, 1); } // Do nothing for Length: 1 } else { // Possible lengths: 4, 5 if (arrayLength == 5) { // Length: 5 swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 0, 2); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 0, 3); swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 1, 2); } else { // Length: 4 swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 0, 2); swapIfFirstIsLarger(array, 1, 2); } } } else { // Possible lengths: 6, 7, 8, 9 if (arrayLength < 8) { // Possible lengths: 6, 7 if (arrayLength == 7) { // Length: 7 swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 5, 6); swapIfFirstIsLarger(array, 0, 2); swapIfFirstIsLarger(array, 4, 6); swapIfFirstIsLarger(array, 3, 5); swapIfFirstIsLarger(array, 2, 6); swapIfFirstIsLarger(array, 1, 5); swapIfFirstIsLarger(array, 0, 4); swapIfFirstIsLarger(array, 2, 5); swapIfFirstIsLarger(array, 0, 3); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 4, 5); } else { // Length: 6 swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 4, 5); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 3, 5); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 0, 2); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 2, 3); } } else { // Possible lengths: 8, 9 if (arrayLength == 9) { // Length: 9 swapIfFirstIsLarger(array, 1, 8); swapIfFirstIsLarger(array, 2, 7); swapIfFirstIsLarger(array, 3, 6); swapIfFirstIsLarger(array, 4, 5); swapIfFirstIsLarger(array, 1, 4); swapIfFirstIsLarger(array, 5, 8); swapIfFirstIsLarger(array, 0, 2); swapIfFirstIsLarger(array, 6, 7); swapIfFirstIsLarger(array, 2, 6); swapIfFirstIsLarger(array, 7, 8); swapIfFirstIsLarger(array, 0, 3); swapIfFirstIsLarger(array, 4, 5); swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 3, 5); swapIfFirstIsLarger(array, 6, 7); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 1, 3); swapIfFirstIsLarger(array, 5, 7); swapIfFirstIsLarger(array, 4, 6); swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 5, 6); swapIfFirstIsLarger(array, 7, 8); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 4, 5); } else { // Length: 8 swapIfFirstIsLarger(array, 0, 7); swapIfFirstIsLarger(array, 1, 6); swapIfFirstIsLarger(array, 2, 5); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 0, 3); swapIfFirstIsLarger(array, 4, 7); swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 5, 6); swapIfFirstIsLarger(array, 0, 1); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 4, 5); swapIfFirstIsLarger(array, 6, 7); swapIfFirstIsLarger(array, 3, 5); swapIfFirstIsLarger(array, 2, 4); swapIfFirstIsLarger(array, 1, 2); swapIfFirstIsLarger(array, 3, 4); swapIfFirstIsLarger(array, 5, 6); swapIfFirstIsLarger(array, 2, 3); swapIfFirstIsLarger(array, 4, 5); swapIfFirstIsLarger(array, 3, 4); } } } } /// @notice Swaps two elements of an array if the first element is greater /// than the second /// @param array Array whose elements are to be swapped /// @param ind1 Index of the first element /// @param ind2 Index of the second element function swapIfFirstIsLarger( int256[] memory array, uint256 ind1, uint256 ind2 ) private pure { if (array[ind1] > array[ind2]) { (array[ind1], array[ind2]) = (array[ind2], array[ind1]); } } }
contracts/api3-server-v1/aggregation/Median.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./Sort.sol"; import "./QuickSelect.sol"; /// @title Contract to be inherited by contracts that will calculate the median /// of an array /// @notice The operation will be in-place, i.e., the array provided as the /// argument will be modified. contract Median is Sort, Quickselect { /// @notice Returns the median of the array /// @dev Uses an unrolled sorting implementation for shorter arrays and /// quickselect for longer arrays for gas cost efficiency /// @param array Array whose median is to be calculated /// @return Median of the array function median(int256[] memory array) internal pure returns (int256) { uint256 arrayLength = array.length; if (arrayLength <= MAX_SORT_LENGTH) { sort(array); if (arrayLength % 2 == 1) { return array[arrayLength / 2]; } else { assert(arrayLength != 0); unchecked { return average( array[arrayLength / 2 - 1], array[arrayLength / 2] ); } } } else { if (arrayLength % 2 == 1) { return array[quickselectK(array, arrayLength / 2)]; } else { uint256 mid1; uint256 mid2; unchecked { (mid1, mid2) = quickselectKPlusOne( array, arrayLength / 2 - 1 ); } return average(array[mid1], array[mid2]); } } } /// @notice Averages two signed integers without overflowing /// @param x Integer x /// @param y Integer y /// @return Average of integers x and y function average(int256 x, int256 y) private pure returns (int256) { unchecked { int256 averageRoundedDownToNegativeInfinity = (x >> 1) + (y >> 1) + (x & y & 1); // If the average rounded down to negative infinity is negative // (i.e., its 256th sign bit is set), and one of (x, y) is even and // the other one is odd (i.e., the 1st bit of their xor is set), // add 1 to round the average down to zero instead. // We will typecast the signed integer to unsigned to logical-shift // int256(uint256(signedInt)) >> 255 ~= signedInt >>> 255 return averageRoundedDownToNegativeInfinity + (int256( (uint256(averageRoundedDownToNegativeInfinity) >> 255) ) & (x ^ y)); } } }
contracts/utils/interfaces/IExtendedSelfMulticall.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ISelfMulticall.sol"; interface IExtendedSelfMulticall is ISelfMulticall { function getChainId() external view returns (uint256); function getBalance(address account) external view returns (uint256); function containsBytecode(address account) external view returns (bool); function getBlockNumber() external view returns (uint256); function getBlockTimestamp() external view returns (uint256); function getBlockBasefee() external view returns (uint256); }
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata","devdoc","userdoc","storageLayout","evm.gasEstimates"],"":["ast"]}},"optimizer":{"runs":1000,"enabled":true},"metadata":{"useLiteralContent":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"owner_","internalType":"address"},{"type":"address","name":"api3ServerV1_","internalType":"address"},{"type":"address","name":"airnodeAddress_","internalType":"address"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAXIMUM_DATA_FEET_UPDATE_AGE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"activeDataFeedCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"airnodeAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"airseekerRegistry","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"api3ServerV1","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"containsBytecode","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBalance","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBlockBasefee","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBlockNumber","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBlockTimestamp","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getChainId","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes[]","name":"returndata","internalType":"bytes[]"}],"name":"multicall","inputs":[{"type":"bytes[]","name":"data","internalType":"bytes[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"}],"name":"registerDataFeed","inputs":[{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"dataFeedDetails","internalType":"bytes"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"pure","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setDataFeedIdToBeActivated","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setDataFeedIdToBeDeactivated","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setDataFeedIdUpdateParameters","inputs":[{"type":"bytes32","name":"dataFeedId","internalType":"bytes32"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"updateParameters","internalType":"bytes"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSignedApiUrl","inputs":[{"type":"address","name":"airnode","internalType":"address"},{"type":"string","name":"signedApiUrl","internalType":"string"}]},{"type":"function","stateMutability":"pure","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool[]","name":"successes","internalType":"bool[]"},{"type":"bytes[]","name":"returndata","internalType":"bytes[]"}],"name":"tryMulticall","inputs":[{"type":"bytes[]","name":"data","internalType":"bytes[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"beaconId","internalType":"bytes32"}],"name":"updateBeaconWithSignedData","inputs":[{"type":"address","name":"airnode","internalType":"address"},{"type":"bytes32","name":"templateId","internalType":"bytes32"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"bytes","name":"signature","internalType":"bytes"}]}]
Contract Creation Code
0x60e06040523480156200001157600080fd5b506040516200492c3803806200492c83398101604081905262000034916200018c565b6200003f3362000111565b6001600160a01b0383166200008f5760405162461bcd60e51b81526020600482015260126024820152714f776e65722061646472657373207a65726f60701b604482015260640160405180910390fd5b6200009a8362000111565b6001600160a01b0380831660a052811660c05260405160009030908490620000c29062000161565b6001600160a01b039283168152911660208201526040018190604051809103906000f5905080158015620000fa573d6000803e3d6000fd5b506001600160a01b031660805250620001d6915050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b612c7c8062001cb083390190565b80516001600160a01b03811681146200018757600080fd5b919050565b600080600060608486031215620001a257600080fd5b620001ad846200016f565b9250620001bd602085016200016f565b9150620001cd604085016200016f565b90509250925092565b60805160a05160c051611a5d62000253600039600081816103030152818161043e0152818161080d015281816109f40152610e160152600081816101bb01526103ac0152600081816102420152818161063a0152818161097f01528181610b8901528181610c1101528181610f8601526110820152611a5d6000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c80636b664980116100d8578063ac9650d81161008c578063f2fde38b11610066578063f2fde38b14610338578063f8b2cb4f1461034b578063fba8f22f1461036657600080fd5b8063ac9650d8146102de578063d0bdd66c146102fe578063d34c4e771461032557600080fd5b8063796b89b9116100bd578063796b89b9146102bf5780638da5cb5b146102c55780638f634751146102d657600080fd5b80636b664980146102a4578063715018a6146102b757600080fd5b806342cbb15c1161013a57806353130e261161011457806353130e261461023d5780635989eaeb14610264578063685f550d1461029157600080fd5b806342cbb15c14610210578063437b9116146102165780634dcc19fe1461023757600080fd5b80632d6a744e1161016b5780632d6a744e146101b65780633408e470146101f55780633a8b8018146101fb57600080fd5b80631a0a0b3e146101875780632276bbe5146101ad575b600080fd5b61019a610195366004611404565b610379565b6040519081526020015b60405180910390f35b61019a61012c81565b6101dd7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101a4565b4661019a565b61020e610209366004611498565b61043c565b005b4361019a565b6102296102243660046114eb565b6106a5565b6040516101a49291906115e5565b4861019a565b6101dd7f000000000000000000000000000000000000000000000000000000000000000081565b610281610272366004611634565b6001600160a01b03163b151590565b60405190151581526020016101a4565b61020e61029f366004611656565b61080b565b61020e6102b2366004611498565b6109f2565b61020e610bc0565b4261019a565b6000546001600160a01b03166101dd565b61019a610c0d565b6102f16102ec3660046114eb565b610c91565b6040516101a491906116d9565b6101dd7f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103333660046116ec565b610e12565b61020e610346366004611634565b61100a565b61019a610359366004611634565b6001600160a01b03163190565b61020e610374366004611766565b611052565b6040517f1a0a0b3e0000000000000000000000000000000000000000000000000000000081526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631a0a0b3e906103ed908b908b908b908b908b908b908b906004016117e2565b6020604051808303816000875af115801561040c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104309190611832565b98975050505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661056683838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051602081018b90529081018990524660608083019190915230901b6bffffffffffffffffffffffff191660808201527f3a8b8018000000000000000000000000000000000000000000000000000000006094820152610560925060980190505b60408051601f1981840301815282825280516020918201207f19457468657265756d205369676e6564204d6573736167653a0a33320000000084830152603c8085019190915282518085039091018152605c909301909152815191012090565b906110f2565b6001600160a01b0316146105b65760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064015b60405180910390fd5b6105bf83611118565b61060b5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517fb07a0c2f000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b07a0c2f906024015b600060405180830381600087803b15801561068757600080fd5b505af115801561069b573d6000803e3d6000fd5b5050505050505050565b606080828067ffffffffffffffff8111156106c2576106c261184b565b6040519080825280602002602001820160405280156106eb578160200160208202803683370190505b5092508067ffffffffffffffff8111156107075761070761184b565b60405190808252806020026020018201604052801561073a57816020015b60608152602001906001900390816107255790505b50915060005b81811015610802573086868381811061075b5761075b611861565b905060200281019061076d9190611877565b60405161077b9291906118be565b600060405180830381855af49150503d80600081146107b6576040519150601f19603f3d011682016040523d82523d6000602084013e6107bb565b606091505b508583815181106107ce576107ce611861565b602002602001018584815181106107e7576107e7611861565b60209081029190910101919091529015159052600101610740565b50509250929050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166108af83838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604051610560925061050091508b908a908a908d90469030907f685f550d00000000000000000000000000000000000000000000000000000000906020016118ce565b6001600160a01b0316146108fa5760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b61090385611118565b61094f5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f1761c2190000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631761c219906109b890899088908890600401611933565b600060405180830381600087803b1580156109d257600080fd5b505af11580156109e6573d6000803e3d6000fd5b50505050505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610aba83838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051602081018b90529081018990524660608083019190915230901b6bffffffffffffffffffffffff191660808201527f6b66498000000000000000000000000000000000000000000000000000000000609482015261056092506098019050610500565b6001600160a01b031614610b055760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b610b0e83611118565b610b5a5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f91af2411000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906391af24119060240161066d565b60405162461bcd60e51b815260206004820152601d60248201527f4f776e6572736869702063616e6e6f742062652072656e6f756e63656400000060448201526064016105ad565b905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638f6347516040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c089190611832565b6060818067ffffffffffffffff811115610cad57610cad61184b565b604051908082528060200260200182016040528015610ce057816020015b6060815260200190600190039081610ccb5790505b50915060005b81811015610e0a57600030868684818110610d0357610d03611861565b9050602002810190610d159190611877565b604051610d239291906118be565b600060405180830381855af49150503d8060008114610d5e576040519150601f19603f3d011682016040523d82523d6000602084013e610d63565b606091505b50858481518110610d7657610d76611861565b6020908102919091010152905080610e01576000848381518110610d9c57610d9c611861565b60200260200101519050600081511115610db95780518082602001fd5b60405162461bcd60e51b815260206004820152601b60248201527f4d756c746963616c6c3a204e6f2072657665727420737472696e67000000000060448201526064016105ad565b50600101610ce6565b505092915050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610eb684848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604051610560925061050091508a908a908d90469030907fd34c4e770000000000000000000000000000000000000000000000000000000090602001611956565b6001600160a01b031614610f015760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b610f0a86611118565b610f565760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f5d8681940000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690635d86819490610fbd90889088906004016119b1565b6020604051808303816000875af1158015610fdc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110009190611832565b9695505050505050565b60405162461bcd60e51b815260206004820152601f60248201527f4f776e6572736869702063616e6e6f74206265207472616e736665727265640060448201526064016105ad565b6040517ffba8f22f0000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063fba8f22f906110bb908690869086906004016119cd565b600060405180830381600087803b1580156110d557600080fd5b505af11580156110e9573d6000803e3d6000fd5b50505050505050565b60008060006111018585611135565b9150915061110e8161117a565b5090505b92915050565b600063ffffffff821661112d61012c426119f0565b111592915050565b600080825160410361116b5760208301516040840151606085015160001a61115f878285856112e2565b94509450505050611173565b506000905060025b9250929050565b600081600481111561118e5761118e611a11565b036111965750565b60018160048111156111aa576111aa611a11565b036111f75760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016105ad565b600281600481111561120b5761120b611a11565b036112585760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016105ad565b600381600481111561126c5761126c611a11565b036112df5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f756500000000000000000000000000000000000000000000000000000000000060648201526084016105ad565b50565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611319575060009050600361139d565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561136d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166113965760006001925092505061139d565b9150600090505b94509492505050565b80356001600160a01b03811681146113bd57600080fd5b919050565b60008083601f8401126113d457600080fd5b50813567ffffffffffffffff8111156113ec57600080fd5b60208301915083602082850101111561117357600080fd5b600080600080600080600060a0888a03121561141f57600080fd5b611428886113a6565b96506020880135955060408801359450606088013567ffffffffffffffff8082111561145357600080fd5b61145f8b838c016113c2565b909650945060808a013591508082111561147857600080fd5b506114858a828b016113c2565b989b979a50959850939692959293505050565b600080600080606085870312156114ae57600080fd5b8435935060208501359250604085013567ffffffffffffffff8111156114d357600080fd5b6114df878288016113c2565b95989497509550505050565b600080602083850312156114fe57600080fd5b823567ffffffffffffffff8082111561151657600080fd5b818501915085601f83011261152a57600080fd5b81358181111561153957600080fd5b8660208260051b850101111561154e57600080fd5b60209290920196919550909350505050565b600081518084526020808501808196508360051b810191508286016000805b868110156115d7578385038a5282518051808752835b818110156115b0578281018901518882018a01528801611595565b5086810188018490529a87019a601f01601f1916909501860194509185019160010161157f565b509298975050505050505050565b604080825283519082018190526000906020906060840190828701845b82811015611620578151151584529284019290840190600101611602565b505050838103828501526110008186611560565b60006020828403121561164657600080fd5b61164f826113a6565b9392505050565b6000806000806000806080878903121561166f57600080fd5b8635955060208701359450604087013567ffffffffffffffff8082111561169557600080fd5b6116a18a838b016113c2565b909650945060608901359150808211156116ba57600080fd5b506116c789828a016113c2565b979a9699509497509295939492505050565b60208152600061164f6020830184611560565b60008060008060006060868803121561170457600080fd5b85359450602086013567ffffffffffffffff8082111561172357600080fd5b61172f89838a016113c2565b9096509450604088013591508082111561174857600080fd5b50611755888289016113c2565b969995985093965092949392505050565b60008060006040848603121561177b57600080fd5b611784846113a6565b9250602084013567ffffffffffffffff8111156117a057600080fd5b6117ac868287016113c2565b9497909650939450505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6001600160a01b038816815286602082015285604082015260a06060820152600061181160a0830186886117b9565b82810360808401526118248185876117b9565b9a9950505050505050505050565b60006020828403121561184457600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261188e57600080fd5b83018035915067ffffffffffffffff8211156118a957600080fd5b60200191503681900382131561117357600080fd5b8183823760009101908152919050565b8781528587602083013760209501948501939093526040840191909152606090811b6bffffffffffffffffffffffff1916908301527fffffffff0000000000000000000000000000000000000000000000000000000016607482015260780192915050565b83815260406020820152600061194d6040830184866117b9565b95945050505050565b85878237909401928352602083019190915260601b6bffffffffffffffffffffffff191660408201527fffffffff00000000000000000000000000000000000000000000000000000000919091166054820152605801919050565b6020815260006119c56020830184866117b9565b949350505050565b6001600160a01b038416815260406020820152600061194d6040830184866117b9565b8181038181111561111257634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fdfea264697066735822122074d962a8b33a2a2f7b0c9b9871e8b3dcef743013392c7765c902dd6cff4a2c5e64736f6c6343000811003360a06040523480156200001157600080fd5b5060405162002c7c38038062002c7c833981016040819052620000349162000173565b6200003f3362000106565b6001600160a01b038216620000905760405162461bcd60e51b81526020600482015260126024820152714f776e65722061646472657373207a65726f60701b60448201526064015b60405180910390fd5b6001600160a01b038116620000e85760405162461bcd60e51b815260206004820152601960248201527f4170693353657276657256312061646472657373207a65726f00000000000000604482015260640162000087565b620000f38262000106565b6001600160a01b031660805250620001ab565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146200016e57600080fd5b919050565b600080604083850312156200018757600080fd5b620001928362000156565b9150620001a26020840162000156565b90509250929050565b608051612a99620001e36000396000818161025e01528181611327015281816114b7015281816115cb01526118b60152612a996000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c8063796b89b91161010f578063be3cc74d116100a2578063ddb2575211610071578063ddb2575214610420578063f2fde38b14610433578063f8b2cb4f14610446578063fba8f22f1461046157600080fd5b8063be3cc74d146103ca578063d23bab14146103dd578063d3cc6647146103f0578063d4a66d921461041857600080fd5b80638f634751116100de5780638f6347511461037c57806391af241114610384578063ac9650d814610397578063b07a0c2f146103b757600080fd5b8063796b89b91461033f5780637a821819146103455780637ca50e85146103585780638da5cb5b1461036b57600080fd5b806342cbb15c116101875780635d868194116101565780635d868194146103095780636e85b69a1461031c578063715018a61461032f578063773f2edc1461033757600080fd5b806342cbb15c146102af578063437b9116146102b55780634dcc19fe146102d65780635989eaeb146102dc57600080fd5b80632d6a744e116101c35780632d6a744e146102595780633408e4701461029857806336b7840d1461029e5780633aad52b9146102a757600080fd5b8063074244ce146101f5578063085df6ab146102115780631761c219146102315780632412a9cb14610246575b600080fd5b6101fe61010081565b6040519081526020015b60405180910390f35b61022461021f366004611f36565b610474565b6040516102089190611fa0565b61024461023f366004611ffc565b61050e565b005b610244610254366004612048565b610679565b6102807f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610208565b466101fe565b6101fe61040081565b6101fe601581565b436101fe565b6102c86102c3366004612061565b610700565b60405161020892919061212e565b486101fe565b6102f96102ea366004611f36565b6001600160a01b03163b151590565b6040519015158152602001610208565b6101fe610317366004612187565b610866565b61022461032a366004612048565b610cec565b610244610d05565b6101fe610d4d565b426101fe565b6102f9610353366004612048565b610d5e565b610224610366366004612048565b610d80565b6000546001600160a01b0316610280565b6101fe610e2f565b610244610392366004612048565b610e4b565b6103aa6103a5366004612061565b610ed3565b60405161020891906121c9565b6102446103c5366004612048565b611054565b6102446103d8366004612048565b6110dd565b6102446103eb366004611ffc565b611163565b6104036103fe366004612048565b6112b4565b60405161020899989796959493929190612272565b6101fe611ac8565b61022461042e366004612048565b611ad4565b610244610441366004611f36565b611afe565b6101fe610454366004611f36565b6001600160a01b03163190565b61024461046f366004612331565b611b46565b6001602052600090815260409020805461048d9061236d565b80601f01602080910402602001604051908101604052809291908181526020018280546104b99061236d565b80156105065780601f106104db57610100808354040283529160200191610506565b820191906000526020600020905b8154815290600101906020018083116104e957829003601f168201915b505050505081565b610516611cef565b828061055d5760405162461bcd60e51b8152602060048201526011602482015270446174612066656564204944207a65726f60781b60448201526064015b60405180910390fd5b82826104008111156105b15760405162461bcd60e51b815260206004820152601a60248201527f55706461746520706172616d657465727320746f6f206c6f6e670000000000006044820152606401610554565b600085856040516105c39291906123a7565b60405180910390209050806007600089815260200190815260200160002054146106705760008781526007602090815260408083208490558383526009909152902080548691906106139061236d565b90501461063557600081815260096020526040902061063386888361241b565b505b867f0aea1ab3b222f6786a08c16b8f93ba421dfe07d2511afa7250ec3e9163b0b4208787604051610667929190612505565b60405180910390a25b50505050505050565b610681611cef565b80806106c05760405162461bcd60e51b815260206004820152600e60248201526d64415049206e616d65207a65726f60901b6044820152606401610554565b6106cb600583611d4b565b156106fc5760405182907ff9f5c4d39275e5bd5f3c5c8c55bc35400693aeb978d180b545f88580dc4e1e7790600090a25b5050565b606080828067ffffffffffffffff81111561071d5761071d6123b7565b604051908082528060200260200182016040528015610746578160200160208202803683370190505b5092508067ffffffffffffffff811115610762576107626123b7565b60405190808252806020026020018201604052801561079557816020015b60608152602001906001900390816107805790505b50915060005b8181101561085d57308686838181106107b6576107b6612521565b90506020028101906107c89190612537565b6040516107d69291906123a7565b600060405180830381855af49150503d8060008114610811576040519150601f19603f3d011682016040523d82523d6000602084013e610816565b606091505b5085838151811061082957610829612521565b6020026020010185848151811061084257610842612521565b6020908102919091010191909152901515905260010161079b565b50509250929050565b600081603f198101610925576000806108818587018761257e565b90925090506001600160a01b0382166108dc5760405162461bcd60e51b815260206004820152601460248201527f4169726e6f64652061646472657373207a65726f0000000000000000000000006044820152606401610554565b60408051606084901b6bffffffffffffffffffffffff19166020808301919091526034808301859052835180840390910181526054909201909252805191012093505050610c6d565b6101008110610c255761093a601560206125c0565b6109459060206125d7565b610951601560206125c0565b61095c9060206125d7565b6109679060406125d7565b61097191906125d7565b8111156109c05760405162461bcd60e51b815260206004820152601a60248201527f4461746120666565642064657461696c7320746f6f206c6f6e670000000000006044820152606401610554565b6000806109cf858701876126aa565b915091508282826040516020016109e792919061279c565b6040516020818303038152906040525114610a445760405162461bcd60e51b815260206004820152601760248201527f4461746120666565642064657461696c7320747261696c0000000000000000006044820152606401610554565b815181518114610a965760405162461bcd60e51b815260206004820152601960248201527f506172616d65746572206c656e677468206d69736d61746368000000000000006044820152606401610554565b60008167ffffffffffffffff811115610ab157610ab16123b7565b604051908082528060200260200182016040528015610ada578160200160208202803683370190505b50905060005b82811015610c105760006001600160a01b0316858281518110610b0557610b05612521565b60200260200101516001600160a01b031603610b635760405162461bcd60e51b815260206004820152601460248201527f4169726e6f64652061646472657373207a65726f0000000000000000000000006044820152606401610554565b610be1858281518110610b7857610b78612521565b6020026020010151858381518110610b9257610b92612521565b60200260200101516040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b828281518110610bf357610bf3612521565b602090810291909101015280610c08816127f2565b915050610ae0565b50610c1a81611d60565b955050505050610c6d565b60405162461bcd60e51b815260206004820152601b60248201527f4461746120666565642064657461696c7320746f6f2073686f727400000000006044820152606401610554565b60008281526002602052604090208054829190610c899061236d565b905014610ce5576000828152600260205260409020610ca984868361241b565b50817f4fe18adb29a4bae727e770ff666414a639679c10704d95f308a220b9a1b7477c8585604051610cdc929190612505565b60405180910390a25b5092915050565b6002602052600090815260409020805461048d9061236d565b60405162461bcd60e51b815260206004820152601d60248201527f4f776e6572736869702063616e6e6f742062652072656e6f756e6365640000006044820152606401610554565b6000610d596003611d90565b905090565b60008181526002602052604081208054610d779061236d565b15159392505050565b600081815260076020908152604080832054835260099091529020805460609190610daa9061236d565b80601f0160208091040260200160405190810160405280929190818152602001828054610dd69061236d565b8015610e235780601f10610df857610100808354040283529160200191610e23565b820191906000526020600020905b815481529060010190602001808311610e0657829003601f168201915b50505050509050919050565b6000610e39611ac8565b610e41610d4d565b610d5991906125d7565b610e53611cef565b8080610e955760405162461bcd60e51b8152602060048201526011602482015270446174612066656564204944207a65726f60781b6044820152606401610554565b610ea0600383611d4b565b156106fc5760405182907e58637e39931c35fef05bbfd96b3881a0301ada925534f93fbfd5544df032cd90600090a25050565b6060818067ffffffffffffffff811115610eef57610eef6123b7565b604051908082528060200260200182016040528015610f2257816020015b6060815260200190600190039081610f0d5790505b50915060005b8181101561104c57600030868684818110610f4557610f45612521565b9050602002810190610f579190612537565b604051610f659291906123a7565b600060405180830381855af49150503d8060008114610fa0576040519150601f19603f3d011682016040523d82523d6000602084013e610fa5565b606091505b50858481518110610fb857610fb8612521565b6020908102919091010152905080611043576000848381518110610fde57610fde612521565b60200260200101519050600081511115610ffb5780518082602001fd5b60405162461bcd60e51b815260206004820152601b60248201527f4d756c746963616c6c3a204e6f2072657665727420737472696e6700000000006044820152606401610554565b50600101610f28565b505092915050565b61105c611cef565b808061109e5760405162461bcd60e51b8152602060048201526011602482015270446174612066656564204944207a65726f60781b6044820152606401610554565b6110a9600383611d9a565b156106fc5760405182907f0b7c1d36481aee25427040847eb1bb0fe4419a9daf1a3daa7a2ed118a20128bf90600090a25050565b6110e5611cef565b80806111245760405162461bcd60e51b815260206004820152600e60248201526d64415049206e616d65207a65726f60901b6044820152606401610554565b61112f600583611d9a565b156106fc5760405182907f240586c4e7a24b6151c6cbee3daebf773eae2e14f003cf24b204cc164c3066a790600090a25050565b61116b611cef565b82806111aa5760405162461bcd60e51b815260206004820152600e60248201526d64415049206e616d65207a65726f60901b6044820152606401610554565b82826104008111156111fe5760405162461bcd60e51b815260206004820152601a60248201527f55706461746520706172616d657465727320746f6f206c6f6e670000000000006044820152606401610554565b600085856040516112109291906123a7565b60405180910390209050806008600089815260200190815260200160002054146106705760008781526008602090815260408083208490558383526009909152902080548691906112609061236d565b90501461128257600081815260096020526040902061128086888361241b565b505b867f3ebb9b0f7d1ab582553a43d38e03a3533602282ff4fc10f5073d0b67d990dbfd8787604051610667929190612505565b600080606060008060608060608060006112cc610d4d565b9050808b10156112f3576112e160038c611da6565b99506112ec8a610d80565b92506113ea565b6112fd6005611d90565b61130790826125d7565b8b10156113ea5761132361131b828d61280b565b600590611da6565b98507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663472c22f18a60405160200161136791815260200190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b815260040161139b91815260200190565b602060405180830381865afa1580156113b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113dc919061281e565b99506113e789611ad4565b92505b89156115325760008a815260026020526040902080546114099061236d565b80601f01602080910402602001604051908101604052809291908181526020018280546114359061236d565b80156114825780601f1061145757610100808354040283529160200191611482565b820191906000526020600020905b81548152906001019060200180831161146557829003601f168201915b50506040517f67a7cfb7000000000000000000000000000000000000000000000000000000008152600481018f9052939b50507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316926367a7cfb7925060240190506040805180830381865afa158015611508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061152c9190612837565b90975095505b875115611aba5760408851036117b2576040805160018082528183019092529060208083019080368337505060408051600180825281830190925292975090506020808301908036833701905050604080516001808252818301909252919550816020015b6060815260200190600190039081611597579050509150600080898060200190518101906115c59190612880565b915091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166367a7cfb761164484846040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b6040518263ffffffff1660e01b815260040161166291815260200190565b6040805180830381865afa15801561167e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a29190612837565b886000815181106116b5576116b5612521565b60200260200101886000815181106116cf576116cf612521565b63ffffffff909316602093840291909101830152601b9290920b9091526001600160a01b0383166000908152600190915260409020805461170f9061236d565b80601f016020809104026020016040519081016040528092919081815260200182805461173b9061236d565b80156117885780601f1061175d57610100808354040283529160200191611788565b820191906000526020600020905b81548152906001019060200180831161176b57829003601f168201915b5050505050846000815181106117a0576117a0612521565b60200260200101819052505050611aba565b600080898060200190518101906117c99190612909565b815191935091508067ffffffffffffffff8111156117e9576117e96123b7565b604051908082528060200260200182016040528015611812578160200160208202803683370190505b5097508067ffffffffffffffff81111561182e5761182e6123b7565b604051908082528060200260200182016040528015611857578160200160208202803683370190505b5096508067ffffffffffffffff811115611873576118736123b7565b6040519080825280602002602001820160405280156118a657816020015b60608152602001906001900390816118915790505b50945060005b81811015611ab5577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166367a7cfb76119128684815181106118f8576118f8612521565b6020026020010151868581518110610b9257610b92612521565b6040518263ffffffff1660e01b815260040161193091815260200190565b6040805180830381865afa15801561194c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119709190612837565b8a838151811061198257611982612521565b602002602001018a848151811061199b5761199b612521565b602002602001018263ffffffff1663ffffffff1681525082601b0b601b0b8152505050600160008583815181106119d4576119d4612521565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000208054611a079061236d565b80601f0160208091040260200160405190810160405280929190818152602001828054611a339061236d565b8015611a805780601f10611a5557610100808354040283529160200191611a80565b820191906000526020600020905b815481529060010190602001808311611a6357829003601f168201915b5050505050868281518110611a9757611a97612521565b60200260200101819052508080611aad906127f2565b9150506118ac565b505050505b509193959799909294969850565b6000610d596005611d90565b600081815260086020908152604080832054835260099091529020805460609190610daa9061236d565b60405162461bcd60e51b815260206004820152601f60248201527f4f776e6572736869702063616e6e6f74206265207472616e73666572726564006044820152606401610554565b611b4e611cef565b6001600160a01b038316611ba45760405162461bcd60e51b815260206004820152601460248201527f4169726e6f64652061646472657373207a65726f0000000000000000000000006044820152606401610554565b6101008282604051602001611bba9291906123a7565b604051602081830303815290604052511115611c185760405162461bcd60e51b815260206004820152601760248201527f5369676e6564204150492055524c20746f6f206c6f6e670000000000000000006044820152606401610554565b8181604051602001611c2b9291906123a7565b60408051601f1981840301815282825280516020918201206001600160a01b038716600090815260018352929092209192611c679291016129c4565b6040516020818303038152906040528051906020012014611cea576001600160a01b0383166000908152600160205260409020611ca582848361241b565b50826001600160a01b03167f1de1502db80e21e5a66f15b7adabc8c7c32f1fa1a0b7c51dbe01f4e50fe65c498383604051611ce1929190612505565b60405180910390a25b505050565b6000546001600160a01b03163314611d495760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610554565b565b6000611d578383611db2565b90505b92915050565b600081604051602001611d739190612a3a565b604051602081830303815290604052805190602001209050919050565b6000611d5a825490565b6000611d578383611ea5565b6000611d578383611ef4565b60008181526001830160205260408120548015611e9b576000611dd660018361280b565b8554909150600090611dea9060019061280b565b9050818114611e4f576000866000018281548110611e0a57611e0a612521565b9060005260206000200154905080876000018481548110611e2d57611e2d612521565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080611e6057611e60612a4d565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611d5a565b6000915050611d5a565b6000818152600183016020526040812054611eec57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155611d5a565b506000611d5a565b6000826000018281548110611f0b57611f0b612521565b9060005260206000200154905092915050565b6001600160a01b0381168114611f3357600080fd5b50565b600060208284031215611f4857600080fd5b8135611f5381611f1e565b9392505050565b6000815180845260005b81811015611f8057602081850181015186830182015201611f64565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000611d576020830184611f5a565b60008083601f840112611fc557600080fd5b50813567ffffffffffffffff811115611fdd57600080fd5b602083019150836020828501011115611ff557600080fd5b9250929050565b60008060006040848603121561201157600080fd5b83359250602084013567ffffffffffffffff81111561202f57600080fd5b61203b86828701611fb3565b9497909650939450505050565b60006020828403121561205a57600080fd5b5035919050565b6000806020838503121561207457600080fd5b823567ffffffffffffffff8082111561208c57600080fd5b818501915085601f8301126120a057600080fd5b8135818111156120af57600080fd5b8660208260051b85010111156120c457600080fd5b60209290920196919550909350505050565b600082825180855260208086019550808260051b84010181860160005b8481101561212157601f1986840301895261210f838351611f5a565b988401989250908301906001016120f3565b5090979650505050505050565b604080825283519082018190526000906020906060840190828701845b8281101561216957815115158452928401929084019060010161214b565b5050508381038285015261217d81866120d6565b9695505050505050565b6000806020838503121561219a57600080fd5b823567ffffffffffffffff8111156121b157600080fd5b6121bd85828601611fb3565b90969095509350505050565b602081526000611d5760208301846120d6565b600081518084526020808501945080840160005b8381101561221257815163ffffffff16875295820195908201906001016121f0565b509495945050505050565b600081518084526020808501808196508360051b8101915082860160005b85811015612265578284038952612253848351611f5a565b9885019893509084019060010161223b565b5091979650505050505050565b60006101208b835260208b818501528160408501526122938285018c611f5a565b601b8b810b606087015263ffffffff8b16608087015285820360a08701528951808352838b019450909183019060005b818110156122e1578551840b835294840194918401916001016122c3565b505085810360c08701526122f5818a6121dc565b935050505082810360e084015261230c8186611f5a565b9050828103610100840152612321818561221d565b9c9b505050505050505050505050565b60008060006040848603121561234657600080fd5b833561235181611f1e565b9250602084013567ffffffffffffffff81111561202f57600080fd5b600181811c9082168061238157607f821691505b6020821081036123a157634e487b7160e01b600052602260045260246000fd5b50919050565b8183823760009101908152919050565b634e487b7160e01b600052604160045260246000fd5b601f821115611cea57600081815260208120601f850160051c810160208610156123f45750805b601f850160051c820191505b8181101561241357828155600101612400565b505050505050565b67ffffffffffffffff831115612433576124336123b7565b61244783612441835461236d565b836123cd565b6000601f84116001811461247b57600085156124635750838201355b600019600387901b1c1916600186901b1783556124d5565b600083815260209020601f19861690835b828110156124ac578685013582556020948501946001909201910161248c565b50868210156124c95760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6020815260006125196020830184866124dc565b949350505050565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261254e57600080fd5b83018035915067ffffffffffffffff82111561256957600080fd5b602001915036819003821315611ff557600080fd5b6000806040838503121561259157600080fd5b823561259c81611f1e565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417611d5a57611d5a6125aa565b80820180821115611d5a57611d5a6125aa565b604051601f8201601f1916810167ffffffffffffffff81118282101715612613576126136123b7565b604052919050565b600067ffffffffffffffff821115612635576126356123b7565b5060051b60200190565b600082601f83011261265057600080fd5b813560206126656126608361261b565b6125ea565b82815260059290921b8401810191818101908684111561268457600080fd5b8286015b8481101561269f5780358352918301918301612688565b509695505050505050565b600080604083850312156126bd57600080fd5b823567ffffffffffffffff808211156126d557600080fd5b818501915085601f8301126126e957600080fd5b813560206126f96126608361261b565b82815260059290921b8401810191818101908984111561271857600080fd5b948201945b8386101561273f57853561273081611f1e565b8252948201949082019061271d565b9650508601359250508082111561275557600080fd5b506127628582860161263f565b9150509250929050565b600081518084526020808501945080840160005b8381101561221257815187529582019590820190600101612780565b604080825283519082018190526000906020906060840190828701845b828110156127de5781516001600160a01b0316845292840192908401906001016127b9565b5050508381038285015261217d818661276c565b600060018201612804576128046125aa565b5060010190565b81810381811115611d5a57611d5a6125aa565b60006020828403121561283057600080fd5b5051919050565b6000806040838503121561284a57600080fd5b825180601b0b811461285b57600080fd5b602084015190925063ffffffff8116811461287557600080fd5b809150509250929050565b6000806040838503121561289357600080fd5b825161289e81611f1e565b6020939093015192949293505050565b600082601f8301126128bf57600080fd5b815160206128cf6126608361261b565b82815260059290921b840181019181810190868411156128ee57600080fd5b8286015b8481101561269f57805183529183019183016128f2565b6000806040838503121561291c57600080fd5b825167ffffffffffffffff8082111561293457600080fd5b818501915085601f83011261294857600080fd5b815160206129586126608361261b565b82815260059290921b8401810191818101908984111561297757600080fd5b948201945b8386101561299e57855161298f81611f1e565b8252948201949082019061297c565b918801519196509093505050808211156129b757600080fd5b50612762858286016128ae565b60008083546129d28161236d565b600182811680156129ea57600181146129ff57612a2e565b60ff1984168752821515830287019450612a2e565b8760005260208060002060005b85811015612a255781548a820152908401908201612a0c565b50505082870194505b50929695505050505050565b602081526000611d57602083018461276c565b634e487b7160e01b600052603160045260246000fdfea26469706673582212202d2355529b21fa1cea229167772a21d13bd67bbc950d4d21698af126d4a8f18364736f6c6343000811003300000000000000000000000081bc85f329cdb28936fbb239f734ae495121f9a6000000000000000000000000709944a48caf83535e43471680fda4905fb3920a000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e5
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106101825760003560e01c80636b664980116100d8578063ac9650d81161008c578063f2fde38b11610066578063f2fde38b14610338578063f8b2cb4f1461034b578063fba8f22f1461036657600080fd5b8063ac9650d8146102de578063d0bdd66c146102fe578063d34c4e771461032557600080fd5b8063796b89b9116100bd578063796b89b9146102bf5780638da5cb5b146102c55780638f634751146102d657600080fd5b80636b664980146102a4578063715018a6146102b757600080fd5b806342cbb15c1161013a57806353130e261161011457806353130e261461023d5780635989eaeb14610264578063685f550d1461029157600080fd5b806342cbb15c14610210578063437b9116146102165780634dcc19fe1461023757600080fd5b80632d6a744e1161016b5780632d6a744e146101b65780633408e470146101f55780633a8b8018146101fb57600080fd5b80631a0a0b3e146101875780632276bbe5146101ad575b600080fd5b61019a610195366004611404565b610379565b6040519081526020015b60405180910390f35b61019a61012c81565b6101dd7f000000000000000000000000709944a48caf83535e43471680fda4905fb3920a81565b6040516001600160a01b0390911681526020016101a4565b4661019a565b61020e610209366004611498565b61043c565b005b4361019a565b6102296102243660046114eb565b6106a5565b6040516101a49291906115e5565b4861019a565b6101dd7f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f81565b610281610272366004611634565b6001600160a01b03163b151590565b60405190151581526020016101a4565b61020e61029f366004611656565b61080b565b61020e6102b2366004611498565b6109f2565b61020e610bc0565b4261019a565b6000546001600160a01b03166101dd565b61019a610c0d565b6102f16102ec3660046114eb565b610c91565b6040516101a491906116d9565b6101dd7f000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e581565b61019a6103333660046116ec565b610e12565b61020e610346366004611634565b61100a565b61019a610359366004611634565b6001600160a01b03163190565b61020e610374366004611766565b611052565b6040517f1a0a0b3e0000000000000000000000000000000000000000000000000000000081526000906001600160a01b037f000000000000000000000000709944a48caf83535e43471680fda4905fb3920a1690631a0a0b3e906103ed908b908b908b908b908b908b908b906004016117e2565b6020604051808303816000875af115801561040c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104309190611832565b98975050505050505050565b7f000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e56001600160a01b031661056683838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051602081018b90529081018990524660608083019190915230901b6bffffffffffffffffffffffff191660808201527f3a8b8018000000000000000000000000000000000000000000000000000000006094820152610560925060980190505b60408051601f1981840301815282825280516020918201207f19457468657265756d205369676e6564204d6573736167653a0a33320000000084830152603c8085019190915282518085039091018152605c909301909152815191012090565b906110f2565b6001600160a01b0316146105b65760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064015b60405180910390fd5b6105bf83611118565b61060b5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517fb07a0c2f000000000000000000000000000000000000000000000000000000008152600481018590527f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f6001600160a01b03169063b07a0c2f906024015b600060405180830381600087803b15801561068757600080fd5b505af115801561069b573d6000803e3d6000fd5b5050505050505050565b606080828067ffffffffffffffff8111156106c2576106c261184b565b6040519080825280602002602001820160405280156106eb578160200160208202803683370190505b5092508067ffffffffffffffff8111156107075761070761184b565b60405190808252806020026020018201604052801561073a57816020015b60608152602001906001900390816107255790505b50915060005b81811015610802573086868381811061075b5761075b611861565b905060200281019061076d9190611877565b60405161077b9291906118be565b600060405180830381855af49150503d80600081146107b6576040519150601f19603f3d011682016040523d82523d6000602084013e6107bb565b606091505b508583815181106107ce576107ce611861565b602002602001018584815181106107e7576107e7611861565b60209081029190910101919091529015159052600101610740565b50509250929050565b7f000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e56001600160a01b03166108af83838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604051610560925061050091508b908a908a908d90469030907f685f550d00000000000000000000000000000000000000000000000000000000906020016118ce565b6001600160a01b0316146108fa5760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b61090385611118565b61094f5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f1761c2190000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f1690631761c219906109b890899088908890600401611933565b600060405180830381600087803b1580156109d257600080fd5b505af11580156109e6573d6000803e3d6000fd5b50505050505050505050565b7f000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e56001600160a01b0316610aba83838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051602081018b90529081018990524660608083019190915230901b6bffffffffffffffffffffffff191660808201527f6b66498000000000000000000000000000000000000000000000000000000000609482015261056092506098019050610500565b6001600160a01b031614610b055760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b610b0e83611118565b610b5a5760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f91af2411000000000000000000000000000000000000000000000000000000008152600481018590527f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f6001600160a01b0316906391af24119060240161066d565b60405162461bcd60e51b815260206004820152601d60248201527f4f776e6572736869702063616e6e6f742062652072656e6f756e63656400000060448201526064016105ad565b905090565b60007f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f6001600160a01b0316638f6347516040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c089190611832565b6060818067ffffffffffffffff811115610cad57610cad61184b565b604051908082528060200260200182016040528015610ce057816020015b6060815260200190600190039081610ccb5790505b50915060005b81811015610e0a57600030868684818110610d0357610d03611861565b9050602002810190610d159190611877565b604051610d239291906118be565b600060405180830381855af49150503d8060008114610d5e576040519150601f19603f3d011682016040523d82523d6000602084013e610d63565b606091505b50858481518110610d7657610d76611861565b6020908102919091010152905080610e01576000848381518110610d9c57610d9c611861565b60200260200101519050600081511115610db95780518082602001fd5b60405162461bcd60e51b815260206004820152601b60248201527f4d756c746963616c6c3a204e6f2072657665727420737472696e67000000000060448201526064016105ad565b50600101610ce6565b505092915050565b60007f000000000000000000000000241364bbd08701330bdc810baaa10cf8df1710e56001600160a01b0316610eb684848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604051610560925061050091508a908a908d90469030907fd34c4e770000000000000000000000000000000000000000000000000000000090602001611956565b6001600160a01b031614610f015760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016105ad565b610f0a86611118565b610f565760405162461bcd60e51b815260206004820152601e60248201527f4f6c642074696d657374616d707320617265206e6f7420616c6c6f776564000060448201526064016105ad565b6040517f5d8681940000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f1690635d86819490610fbd90889088906004016119b1565b6020604051808303816000875af1158015610fdc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110009190611832565b9695505050505050565b60405162461bcd60e51b815260206004820152601f60248201527f4f776e6572736869702063616e6e6f74206265207472616e736665727265640060448201526064016105ad565b6040517ffba8f22f0000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000006af029d791d6c1011d30d7d45cbc27b6ed053e1f169063fba8f22f906110bb908690869086906004016119cd565b600060405180830381600087803b1580156110d557600080fd5b505af11580156110e9573d6000803e3d6000fd5b50505050505050565b60008060006111018585611135565b9150915061110e8161117a565b5090505b92915050565b600063ffffffff821661112d61012c426119f0565b111592915050565b600080825160410361116b5760208301516040840151606085015160001a61115f878285856112e2565b94509450505050611173565b506000905060025b9250929050565b600081600481111561118e5761118e611a11565b036111965750565b60018160048111156111aa576111aa611a11565b036111f75760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016105ad565b600281600481111561120b5761120b611a11565b036112585760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016105ad565b600381600481111561126c5761126c611a11565b036112df5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f756500000000000000000000000000000000000000000000000000000000000060648201526084016105ad565b50565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611319575060009050600361139d565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561136d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166113965760006001925092505061139d565b9150600090505b94509492505050565b80356001600160a01b03811681146113bd57600080fd5b919050565b60008083601f8401126113d457600080fd5b50813567ffffffffffffffff8111156113ec57600080fd5b60208301915083602082850101111561117357600080fd5b600080600080600080600060a0888a03121561141f57600080fd5b611428886113a6565b96506020880135955060408801359450606088013567ffffffffffffffff8082111561145357600080fd5b61145f8b838c016113c2565b909650945060808a013591508082111561147857600080fd5b506114858a828b016113c2565b989b979a50959850939692959293505050565b600080600080606085870312156114ae57600080fd5b8435935060208501359250604085013567ffffffffffffffff8111156114d357600080fd5b6114df878288016113c2565b95989497509550505050565b600080602083850312156114fe57600080fd5b823567ffffffffffffffff8082111561151657600080fd5b818501915085601f83011261152a57600080fd5b81358181111561153957600080fd5b8660208260051b850101111561154e57600080fd5b60209290920196919550909350505050565b600081518084526020808501808196508360051b810191508286016000805b868110156115d7578385038a5282518051808752835b818110156115b0578281018901518882018a01528801611595565b5086810188018490529a87019a601f01601f1916909501860194509185019160010161157f565b509298975050505050505050565b604080825283519082018190526000906020906060840190828701845b82811015611620578151151584529284019290840190600101611602565b505050838103828501526110008186611560565b60006020828403121561164657600080fd5b61164f826113a6565b9392505050565b6000806000806000806080878903121561166f57600080fd5b8635955060208701359450604087013567ffffffffffffffff8082111561169557600080fd5b6116a18a838b016113c2565b909650945060608901359150808211156116ba57600080fd5b506116c789828a016113c2565b979a9699509497509295939492505050565b60208152600061164f6020830184611560565b60008060008060006060868803121561170457600080fd5b85359450602086013567ffffffffffffffff8082111561172357600080fd5b61172f89838a016113c2565b9096509450604088013591508082111561174857600080fd5b50611755888289016113c2565b969995985093965092949392505050565b60008060006040848603121561177b57600080fd5b611784846113a6565b9250602084013567ffffffffffffffff8111156117a057600080fd5b6117ac868287016113c2565b9497909650939450505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6001600160a01b038816815286602082015285604082015260a06060820152600061181160a0830186886117b9565b82810360808401526118248185876117b9565b9a9950505050505050505050565b60006020828403121561184457600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261188e57600080fd5b83018035915067ffffffffffffffff8211156118a957600080fd5b60200191503681900382131561117357600080fd5b8183823760009101908152919050565b8781528587602083013760209501948501939093526040840191909152606090811b6bffffffffffffffffffffffff1916908301527fffffffff0000000000000000000000000000000000000000000000000000000016607482015260780192915050565b83815260406020820152600061194d6040830184866117b9565b95945050505050565b85878237909401928352602083019190915260601b6bffffffffffffffffffffffff191660408201527fffffffff00000000000000000000000000000000000000000000000000000000919091166054820152605801919050565b6020815260006119c56020830184866117b9565b949350505050565b6001600160a01b038416815260406020820152600061194d6040830184866117b9565b8181038181111561111257634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fdfea264697066735822122074d962a8b33a2a2f7b0c9b9871e8b3dcef743013392c7765c902dd6cff4a2c5e64736f6c63430008110033