Overview
S Balance
0 S
S Value
-More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
270116 | 25 days ago | Contract Creation | 0 S |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x2E787629...23ce8303b The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
Api3ServerV1OevExtension
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../vendor/@openzeppelin/[email protected]/security/ReentrancyGuard.sol"; import "../access/AccessControlRegistryAdminnedWithManager.sol"; import "./DataFeedServer.sol"; import "./interfaces/IApi3ServerV1OevExtension.sol"; import "../vendor/@openzeppelin/[email protected]/utils/Address.sol"; import "../vendor/@openzeppelin/[email protected]/utils/cryptography/ECDSA.sol"; import "./interfaces/IApi3ServerV1.sol"; import "./interfaces/IApi3ServerV1OevExtensionOevBidPayer.sol"; /// @title Api3ServerV1 extension for OEV support /// @notice Api3ServerV1 contract supports base data feeds and OEV /// functionality. This contract implements the updated OEV design, and thus /// supersedes the OEV-related portion of Api3ServerV1. As before, the users /// are intended to read API3 data feeds through a standardized proxy, which /// abstracts this change away. contract Api3ServerV1OevExtension is ReentrancyGuard, AccessControlRegistryAdminnedWithManager, DataFeedServer, IApi3ServerV1OevExtension { using ECDSA for bytes32; struct LastPaidBid { address updater; uint32 signedDataTimestampCutoff; } /// @notice Withdrawer role description string public constant override WITHDRAWER_ROLE_DESCRIPTION = "Withdrawer"; /// @notice Auctioneer role description string public constant override AUCTIONEER_ROLE_DESCRIPTION = "Auctioneer"; /// @notice Withdrawer role bytes32 public immutable override withdrawerRole; /// @notice Auctioneer role bytes32 public immutable override auctioneerRole; /// @notice Api3ServerV1 contract address address public immutable override api3ServerV1; /// @notice Returns the parameters of the last paid bid for the dApp with /// ID mapping(uint256 => LastPaidBid) public override dappIdToLastPaidBid; bytes32 private constant OEV_BID_PAYMENT_CALLBACK_SUCCESS = keccak256("Api3ServerV1OevExtensionOevBidPayer.onOevBidPayment"); /// @param accessControlRegistry_ AccessControlRegistry contract address /// @param adminRoleDescription_ Admin role description /// @param manager_ Manager address /// @param api3ServerV1_ Api3ServerV1 address constructor( address accessControlRegistry_, string memory adminRoleDescription_, address manager_, address api3ServerV1_ ) AccessControlRegistryAdminnedWithManager( accessControlRegistry_, adminRoleDescription_, manager_ ) { require(api3ServerV1_ != address(0), "Api3ServerV1 address zero"); api3ServerV1 = api3ServerV1_; withdrawerRole = _deriveRole( _deriveAdminRole(manager_), WITHDRAWER_ROLE_DESCRIPTION ); auctioneerRole = _deriveRole( _deriveAdminRole(manager_), AUCTIONEER_ROLE_DESCRIPTION ); } /// @dev Used to receive the bid amount in the OEV bid payment callback receive() external payable {} /// @notice Called by the contract manager or a withdrawer to withdraw the /// accumulated OEV auction proceeds /// @dev This function has a reentrancy guard to prevent it from being /// called in an OEV bid payment callback /// @param recipient Recipient address /// @param amount Amount function withdraw( address recipient, uint256 amount ) external override nonReentrant { require(recipient != address(0), "Recipient address zero"); require(amount != 0, "Amount zero"); require( msg.sender == manager || IAccessControlRegistry(accessControlRegistry).hasRole( withdrawerRole, msg.sender ), "Sender cannot withdraw" ); (bool success, ) = recipient.call{value: amount}(""); require(success, "Withdrawal reverted"); emit Withdrew(recipient, amount, msg.sender); } /// @notice An OEV auction bid specifies a dApp ID, a signed data timestamp /// cut-off, a bid amount and an updater account. To award the winning bid, /// an auctioneer signs a message that includes the hash of these /// parameters and publishes it. Then, the updater account calls this /// function to pay the bid amount and claim the privilege to execute /// updates for the dApp with ID using the signed data whose timestamps are /// limited by the cut-off. At least the bid amount must be sent to this /// contract with empty calldata in the `onOevBidPayment` callback, which /// will be checked upon succesful return. /// As a result of the reentrancy guard, nesting OEV bid payments is not /// allowed. /// @param dappId dApp ID /// @param bidAmount Bid amount /// @param signedDataTimestampCutoff Signed data timestamp cut-off /// @param signature Signature provided by an auctioneer /// @param data Data that will be passed through the callback function payOevBid( uint256 dappId, uint256 bidAmount, uint32 signedDataTimestampCutoff, bytes calldata signature, bytes calldata data ) external override nonReentrant { require(dappId != 0, "dApp ID zero"); require(signedDataTimestampCutoff != 0, "Cut-off zero"); // It is intended for the auction periods to be in the order of a // minute. To prevent erroneously large cut-off timestamps from causing // an irreversible state change to the contract, we do not allow // cut-off values that are too far in the future. require( signedDataTimestampCutoff < block.timestamp + 1 hours, "Cut-off too far in the future" ); address auctioneer = ( keccak256( abi.encodePacked( block.chainid, dappId, msg.sender, bidAmount, signedDataTimestampCutoff ) ).toEthSignedMessageHash() ).recover(signature); require( IAccessControlRegistry(accessControlRegistry).hasRole( auctioneerRole, auctioneer ), "Signature mismatch" ); require( dappIdToLastPaidBid[dappId].signedDataTimestampCutoff < signedDataTimestampCutoff, "Cut-off not more recent" ); dappIdToLastPaidBid[dappId] = LastPaidBid({ updater: msg.sender, signedDataTimestampCutoff: signedDataTimestampCutoff }); uint256 balanceBefore = address(this).balance; require( IApi3ServerV1OevExtensionOevBidPayer(msg.sender).onOevBidPayment( bidAmount, data ) == OEV_BID_PAYMENT_CALLBACK_SUCCESS, "OEV bid payment callback failed" ); require( address(this).balance - balanceBefore >= bidAmount, "OEV bid payment amount short" ); emit PaidOevBid( dappId, msg.sender, bidAmount, signedDataTimestampCutoff, auctioneer ); } /// @notice Called by the current updater of the dApp with ID to update the /// OEV data feed specific to the dApp /// @param dappId dApp ID /// @param signedData Signed data (see `_updateDappOevDataFeed()` for /// details) /// @return baseDataFeedId Base data feed ID /// @return updatedValue Updated value /// @return updatedTimestamp Updated timestamp function updateDappOevDataFeed( uint256 dappId, bytes[] calldata signedData ) external override returns ( bytes32 baseDataFeedId, int224 updatedValue, uint32 updatedTimestamp ) { LastPaidBid storage lastPaidBid = dappIdToLastPaidBid[dappId]; require( msg.sender == lastPaidBid.updater, "Sender not last bid updater" ); ( baseDataFeedId, updatedValue, updatedTimestamp ) = _updateDappOevDataFeed( dappId, lastPaidBid.signedDataTimestampCutoff, signedData ); emit UpdatedDappOevDataFeed( dappId, msg.sender, baseDataFeedId, updatedValue, updatedTimestamp ); } /// @notice Called by the zero address to simulate an OEV data feed update /// @dev The intended flow is for a searcher to do a static multicall to /// this function and `simulateExternalCall()` to check if the current /// signed data lets them extract OEV. If so, the searcher stores this data /// and places a bid on OevAuctionHouse. If they win the auction, they pay /// the bid and use the stored signed data with `updateDappOevDataFeed()` /// to extract OEV. /// @param dappId dApp ID /// @param signedData Signed data (see `_updateDappOevDataFeed()` for /// details) /// @return baseDataFeedId Base data feed ID /// @return updatedValue Updated value /// @return updatedTimestamp Updated timestamp function simulateDappOevDataFeedUpdate( uint256 dappId, bytes[] calldata signedData ) external override returns ( bytes32 baseDataFeedId, int224 updatedValue, uint32 updatedTimestamp ) { require(msg.sender == address(0), "Sender address not zero"); ( baseDataFeedId, updatedValue, updatedTimestamp ) = _updateDappOevDataFeed(dappId, type(uint256).max, signedData); } /// @notice Called by the zero address to simulate an external call /// @dev The most basic usage of this is in a static multicall that calls /// `simulateDappOevDataFeedUpdate()` multiple times to update the relevant /// feeds, followed by an external call to the liquidator contract of the /// searcher, which is built to return the revenue from the liquidation. /// The returned value would then be used to determine the bid amount. /// @param target Target address of the external call /// @param data Calldata of the external call /// @return Returndata of the external call function simulateExternalCall( address target, bytes calldata data ) external override returns (bytes memory) { require(msg.sender == address(0), "Sender address not zero"); return Address.functionCall(target, data); } /// @notice Value of the OEV data feed specific to the dApp, intended for /// informational purposes. The dApps are strongly recommended to use the /// standardized proxies to read data feeds. /// @param dappId dApp ID /// @param dataFeedId Data feed ID /// @return value Data feed value /// @return timestamp Data feed timestamp function oevDataFeed( uint256 dappId, bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { DataFeed storage dataFeed = _dataFeeds[ keccak256(abi.encodePacked(dappId, dataFeedId)) ]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } /// @notice Updates OEV data feed specific to the dApp with the signed data /// @dev This function replicates the guarantees of base feed updates, /// which makes OEV updates exactly as secure as base feed updates. The /// main difference between base feed updates and OEV feed updates is that /// the signature for OEV updates use the hash of the respective template /// ID (while the base feed updates use the template ID as is). /// @param dappId dApp ID /// @param signedDataTimestampCutoff Signed data timestamp cut-off /// @param signedData Signed data that is a bytes array. Each item in the /// array is the Airnode address, template ID, data feed timestamp, data /// feed value and signature belonging to each Beacon. Similar to base feed /// updates, OEV feed updates allow individual Beacon updates to be omitted /// (in this case by leaving the signature empty) in case signed data for /// some of the Beacons is not available. /// @return baseDataFeedId Base data feed ID /// @return updatedValue Updated value /// @return updatedTimestamp Updated timestamp function _updateDappOevDataFeed( uint256 dappId, uint256 signedDataTimestampCutoff, bytes[] calldata signedData ) private returns ( bytes32 baseDataFeedId, int224 updatedValue, uint32 updatedTimestamp ) { uint256 beaconCount = signedData.length; require(beaconCount > 0, "Signed data empty"); if (beaconCount == 1) { ( address airnode, bytes32 templateId, uint256 timestamp, bytes memory data, bytes memory signature ) = abi.decode( signedData[0], (address, bytes32, uint256, bytes, bytes) ); baseDataFeedId = deriveBeaconId(airnode, templateId); // Each base feed has an OEV equivalent specific to each dApp. The // ID of these OEV feeds are simply the dApp ID and the base data // feed ID hashed together, independent from if the base feed is a // Beacon or Beacon set. bytes32 oevBeaconId = keccak256( abi.encodePacked(dappId, baseDataFeedId) ); // The signature cannot be omitted for a single Beacon require( ( keccak256( abi.encodePacked( keccak256(abi.encodePacked(templateId)), timestamp, data ) ).toEthSignedMessageHash() ).recover(signature) == airnode, "Signature mismatch" ); require( timestamp <= signedDataTimestampCutoff, "Timestamp exceeds cut-off" ); require( timestamp > _dataFeeds[oevBeaconId].timestamp, "Does not update timestamp" ); updatedValue = decodeFulfillmentData(data); updatedTimestamp = uint32(timestamp); // We do not need to check if the base feed has a larger timestamp, // as the proxy will prefer the base feed if it has a larger // timestamp anyway _dataFeeds[oevBeaconId] = DataFeed({ value: updatedValue, timestamp: updatedTimestamp }); } else { bytes32[] memory baseBeaconIds = new bytes32[](beaconCount); bytes32[] memory oevBeaconIds = new bytes32[](beaconCount); for (uint256 ind = 0; ind < beaconCount; ind++) { ( address airnode, bytes32 templateId, uint256 timestamp, bytes memory data, bytes memory signature ) = abi.decode( signedData[ind], (address, bytes32, uint256, bytes, bytes) ); baseBeaconIds[ind] = deriveBeaconId(airnode, templateId); // We also store individual Beacons of an OEV feed to make sure // that their timestamps are not reduced by OEV updates oevBeaconIds[ind] = keccak256( abi.encodePacked(dappId, baseBeaconIds[ind]) ); if (signature.length != 0) { require( ( keccak256( abi.encodePacked( keccak256(abi.encodePacked(templateId)), timestamp, data ) ).toEthSignedMessageHash() ).recover(signature) == airnode, "Signature mismatch" ); require( timestamp <= signedDataTimestampCutoff, "Timestamp exceeds cut-off" ); require( timestamp > _dataFeeds[oevBeaconIds[ind]].timestamp, "Does not update timestamp" ); _dataFeeds[oevBeaconIds[ind]] = DataFeed({ value: decodeFulfillmentData(data), timestamp: uint32(timestamp) }); } // Without the following bit, an OEV update would effectively // be able to reduce the timestamps of individual Beacons of a // Beacon set. ( int224 baseBeaconValue, uint32 baseBeaconTimestamp ) = IApi3ServerV1(api3ServerV1).dataFeeds(baseBeaconIds[ind]); if ( baseBeaconTimestamp > _dataFeeds[oevBeaconIds[ind]].timestamp ) { // Carrying over base feed values to OEV feeds is fine // because they are secured by identical guarantees _dataFeeds[oevBeaconIds[ind]] = DataFeed({ value: baseBeaconValue, timestamp: baseBeaconTimestamp }); } } baseDataFeedId = deriveBeaconSetId(baseBeaconIds); (updatedValue, updatedTimestamp) = aggregateBeacons(oevBeaconIds); bytes32 oevBeaconSetId = keccak256( abi.encodePacked(dappId, baseDataFeedId) ); DataFeed storage oevBeaconSet = _dataFeeds[oevBeaconSetId]; if (oevBeaconSet.timestamp == updatedTimestamp) { require( oevBeaconSet.value != updatedValue, "Does not update Beacon set" ); } _dataFeeds[oevBeaconSetId] = DataFeed({ value: updatedValue, timestamp: updatedTimestamp }); } } }
// 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 ); } }
// 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); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../vendor/@openzeppelin/[email protected]/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); }
// 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); }
// 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); }
// 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)); } }
// 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)); } } }
// 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]); } } }
// 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]); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../utils/ExtendedSelfMulticall.sol"; import "./aggregation/Median.sol"; import "./interfaces/IDataFeedServer.sol"; import "../vendor/@openzeppelin/[email protected]/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))); } }
// 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); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../access/interfaces/IAccessControlRegistryAdminnedWithManager.sol"; import "../interfaces/IDataFeedServer.sol"; interface IApi3ServerV1OevExtension is IAccessControlRegistryAdminnedWithManager, IDataFeedServer { event Withdrew(address recipient, uint256 amount, address sender); event PaidOevBid( uint256 indexed dappId, address indexed updater, uint256 bidAmount, uint256 signedDataTimestampCutoff, address auctioneer ); event UpdatedDappOevDataFeed( uint256 indexed dappId, address indexed updater, bytes32 dataFeedId, int224 updatedValue, uint32 updatedTimestamp ); function withdraw(address recipient, uint256 amount) external; function payOevBid( uint256 dappId, uint256 bidAmount, uint32 signedDataTimestampCutoff, bytes calldata signature, bytes calldata data ) external; function updateDappOevDataFeed( uint256 dappId, bytes[] calldata signedData ) external returns ( bytes32 baseDataFeedId, int224 updatedValue, uint32 updatedTimestamp ); function simulateDappOevDataFeedUpdate( uint256 dappId, bytes[] calldata signedData ) external returns ( bytes32 baseDataFeedId, int224 updatedValue, uint32 updatedTimestamp ); function simulateExternalCall( address target, bytes calldata data ) external returns (bytes memory); function oevDataFeed( uint256 dappId, bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); // solhint-disable-next-line func-name-mixedcase function WITHDRAWER_ROLE_DESCRIPTION() external view returns (string memory); // solhint-disable-next-line func-name-mixedcase function AUCTIONEER_ROLE_DESCRIPTION() external view returns (string memory); function withdrawerRole() external view returns (bytes32); function auctioneerRole() external view returns (bytes32); function api3ServerV1() external view returns (address); function dappIdToLastPaidBid( uint256 dappId ) external view returns (address updater, uint32 endTimestamp); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Interface that OEV bid payers (i.e., contracts that call /// `payOevBid()` of Api3ServerV1OevExtension) must implement interface IApi3ServerV1OevExtensionOevBidPayer { /// @notice Called back by Api3ServerV1OevExtension after an OEV bid payer /// has called `payOevBid()` of Api3ServerV1OevExtension. During the /// callback, the OEV bid payer will be allowed to update the OEV feeds /// of the respective dApp. Before returning, the OEV bid payer must ensure /// that at least the bid amount has been sent to Api3ServerV1OevExtension. /// The returndata must start with the keccak256 hash of /// "Api3ServerV1OevExtensionOevBidPayer.onOevBidPayment". /// @param bidAmount Bid amount /// @param data Data that is passed through the callback /// @return oevBidPaymentCallbackSuccess OEV bid payment callback success /// code function onOevBidPayment( uint256 bidAmount, bytes calldata data ) external returns (bytes32 oevBidPaymentCallbackSuccess); }
// 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); }
// 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); }
// 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); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IOevDataFeedServer.sol"; import "./IDapiServer.sol"; interface IOevDapiServer is IOevDataFeedServer, IDapiServer {}
// 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); }
// 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; } }
// 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); }
// 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); }
// 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++; } } } }
// 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// 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)); } }
// 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); } } }
// 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); } }
{ "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"accessControlRegistry_","type":"address"},{"internalType":"string","name":"adminRoleDescription_","type":"string"},{"internalType":"address","name":"manager_","type":"address"},{"internalType":"address","name":"api3ServerV1_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"dappId","type":"uint256"},{"indexed":true,"internalType":"address","name":"updater","type":"address"},{"indexed":false,"internalType":"uint256","name":"bidAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"signedDataTimestampCutoff","type":"uint256"},{"indexed":false,"internalType":"address","name":"auctioneer","type":"address"}],"name":"PaidOevBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"beaconSetId","type":"bytes32"},{"indexed":false,"internalType":"int224","name":"value","type":"int224"},{"indexed":false,"internalType":"uint32","name":"timestamp","type":"uint32"}],"name":"UpdatedBeaconSetWithBeacons","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"beaconId","type":"bytes32"},{"indexed":false,"internalType":"int224","name":"value","type":"int224"},{"indexed":false,"internalType":"uint32","name":"timestamp","type":"uint32"}],"name":"UpdatedBeaconWithSignedData","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"dappId","type":"uint256"},{"indexed":true,"internalType":"address","name":"updater","type":"address"},{"indexed":false,"internalType":"bytes32","name":"dataFeedId","type":"bytes32"},{"indexed":false,"internalType":"int224","name":"updatedValue","type":"int224"},{"indexed":false,"internalType":"uint32","name":"updatedTimestamp","type":"uint32"}],"name":"UpdatedDappOevDataFeed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Withdrew","type":"event"},{"inputs":[],"name":"AUCTIONEER_ROLE_DESCRIPTION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWER_ROLE_DESCRIPTION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accessControlRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adminRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adminRoleDescription","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"api3ServerV1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"auctioneerRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"containsBytecode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"dappIdToLastPaidBid","outputs":[{"internalType":"address","name":"updater","type":"address"},{"internalType":"uint32","name":"signedDataTimestampCutoff","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockBasefee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getChainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"returndata","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"dappId","type":"uint256"},{"internalType":"bytes32","name":"dataFeedId","type":"bytes32"}],"name":"oevDataFeed","outputs":[{"internalType":"int224","name":"value","type":"int224"},{"internalType":"uint32","name":"timestamp","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"dappId","type":"uint256"},{"internalType":"uint256","name":"bidAmount","type":"uint256"},{"internalType":"uint32","name":"signedDataTimestampCutoff","type":"uint32"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"payOevBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"dappId","type":"uint256"},{"internalType":"bytes[]","name":"signedData","type":"bytes[]"}],"name":"simulateDappOevDataFeedUpdate","outputs":[{"internalType":"bytes32","name":"baseDataFeedId","type":"bytes32"},{"internalType":"int224","name":"updatedValue","type":"int224"},{"internalType":"uint32","name":"updatedTimestamp","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"simulateExternalCall","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"tryMulticall","outputs":[{"internalType":"bool[]","name":"successes","type":"bool[]"},{"internalType":"bytes[]","name":"returndata","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"beaconIds","type":"bytes32[]"}],"name":"updateBeaconSetWithBeacons","outputs":[{"internalType":"bytes32","name":"beaconSetId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"dappId","type":"uint256"},{"internalType":"bytes[]","name":"signedData","type":"bytes[]"}],"name":"updateDappOevDataFeed","outputs":[{"internalType":"bytes32","name":"baseDataFeedId","type":"bytes32"},{"internalType":"int224","name":"updatedValue","type":"int224"},{"internalType":"uint32","name":"updatedTimestamp","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawerRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Deployed Bytecode
0x6080604052600436106101985760003560e01c80635989eaeb116100e15780639f4165221161008a578063f1939bd011610064578063f1939bd0146105a1578063f3fef3a3146105ea578063f77294091461060a578063f8b2cb4f1461062a57600080fd5b80639f416522146104fc578063ac9650d814610540578063e8597c371461056d57600080fd5b8063796b89b9116100bb578063796b89b91461044157806391526c361461045457806396bb5dbd1461049357600080fd5b80635989eaeb1461039e57806359e5c6b9146103d85780635ae64712146103f857600080fd5b80633408e47011610143578063481c6a751161011d578063481c6a75146103355780634c8f1d8d146103695780634dcc19fe1461038b57600080fd5b80633408e470146102e157806342cbb15c146102f4578063437b91161461030757600080fd5b80631be8d01f116101745780631be8d01f1461022d5780631ce9ae07146102615780632d6a744e146102ad57600080fd5b80629f2f3c146101a4578062aae33f146101eb57806306c84a9f1461020b57600080fd5b3661019f57005b600080fd5b3480156101b057600080fd5b506101d87f864b3b046ae71ee2ef8138aade220e4679107f4beedc4c001f294a609dfc35cf81565b6040519081526020015b60405180910390f35b3480156101f757600080fd5b506101d861020636600461308b565b610652565b34801561021757600080fd5b5061022b610226366004613185565b61077f565b005b34801561023957600080fd5b506101d87f7a8a4120044d66f587aa953b05230e4fe2e5604517a01b1981a1f89fb9863db181565b34801561026d57600080fd5b506102957f000000000000000000000000cd7df573b0f0bb4f2f8dfff6650cde8c7743173081565b6040516001600160a01b0390911681526020016101e2565b3480156102b957600080fd5b506102957f0000000000000000000000003ee097b82e270d82f829e5742cc16b7686247ff281565b3480156102ed57600080fd5b50466101d8565b34801561030057600080fd5b50436101d8565b34801561031357600080fd5b50610327610322366004613260565b610cd2565b6040516101e2929190613338565b34801561034157600080fd5b506102957f000000000000000000000000ef455205966486f52f7951ba4c3517239b03683581565b34801561037557600080fd5b5061037e610e38565b6040516101e29190613391565b34801561039757600080fd5b50486101d8565b3480156103aa57600080fd5b506103c86103b93660046133b9565b6001600160a01b03163b151590565b60405190151581526020016101e2565b3480156103e457600080fd5b5061037e6103f33660046133d6565b610ec6565b34801561040457600080fd5b5061037e6040518060400160405280600a81526020017f41756374696f6e6565720000000000000000000000000000000000000000000081525081565b34801561044d57600080fd5b50426101d8565b34801561046057600080fd5b5061047461046f36600461342b565b610f60565b60408051601b9390930b835263ffffffff9091166020830152016101e2565b34801561049f57600080fd5b506104d86104ae36600461344d565b6003602052600090815260409020546001600160a01b03811690600160a01b900463ffffffff1682565b604080516001600160a01b03909316835263ffffffff9091166020830152016101e2565b34801561050857600080fd5b5061051c610517366004613466565b610fc8565b60408051938452601b9290920b602084015263ffffffff16908201526060016101e2565b34801561054c57600080fd5b5061056061055b366004613260565b6110ae565b6040516101e291906134a5565b34801561057957600080fd5b506101d87f3f3dbd056b7a78613ffe16aa0b387c96dcab786ad33ac8ffca48c513afaeae6781565b3480156105ad57600080fd5b5061037e6040518060400160405280600a81526020017f576974686472617765720000000000000000000000000000000000000000000081525081565b3480156105f657600080fd5b5061022b6106053660046134b8565b61122f565b34801561061657600080fd5b5061051c610625366004613466565b611503565b34801561063657600080fd5b506101d86106453660046133b9565b6001600160a01b03163190565b600080600061066084611572565b9150915061066d84611714565b600081815260026020526040902080549194509063ffffffff808416600160e01b90920416036106f3578054601b84810b91900b036106f35760405162461bcd60e51b815260206004820152601a60248201527f446f6573206e6f742075706461746520426561636f6e2073657400000000000060448201526064015b60405180910390fd5b604080518082018252601b85900b80825263ffffffff858116602080850182815260008b81526002835287902095519051909316600160e01b026001600160e01b0390931692909217909355835191825281019190915285917fb7712be6248d021e8c56ac9613c09491354a4d0f4ad0b7db1a664b35be4b2349910160405180910390a2505050919050565b610787611744565b866000036107d75760405162461bcd60e51b815260206004820152600c60248201527f64417070204944207a65726f000000000000000000000000000000000000000060448201526064016106ea565b8463ffffffff1660000361082d5760405162461bcd60e51b815260206004820152600c60248201527f4375742d6f6666207a65726f000000000000000000000000000000000000000060448201526064016106ea565b61083942610e106134fa565b8563ffffffff161061088d5760405162461bcd60e51b815260206004820152601d60248201527f4375742d6f666620746f6f2066617220696e207468652066757475726500000060448201526064016106ea565b600061094e85858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080514660208201529081018d905233606090811b6bffffffffffffffffffffffff191690820152607481018c905260e08b901b7fffffffff00000000000000000000000000000000000000000000000000000000166094820152610948925060980190505b6040516020818303038152906040528051906020012061179d565b906117d8565b604051632474521560e21b81527f7a8a4120044d66f587aa953b05230e4fe2e5604517a01b1981a1f89fb9863db160048201526001600160a01b0380831660248301529192507f000000000000000000000000cd7df573b0f0bb4f2f8dfff6650cde8c77431730909116906391d1485490604401602060405180830381865afa1580156109df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a03919061350d565b610a445760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016106ea565b60008881526003602052604090205463ffffffff808816600160a01b9092041610610ab15760405162461bcd60e51b815260206004820152601760248201527f4375742d6f6666206e6f74206d6f726520726563656e7400000000000000000060448201526064016106ea565b6040805180820182523380825263ffffffff808a16602080850191825260008e81526003909152859020935184549151909216600160a01b027fffffffffffffffff0000000000000000000000000000000000000000000000009091166001600160a01b0392909216919091171790915590517fd146024d00000000000000000000000000000000000000000000000000000000815247917fc93bcf85bbd7fbf9ac5747cb223742d6648693af4b713698044bb8a37851e9f79163d146024d90610b83908c908990899060040161352f565b6020604051808303816000875af1158015610ba2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc69190613565565b14610c135760405162461bcd60e51b815260206004820152601f60248201527f4f455620626964207061796d656e742063616c6c6261636b206661696c65640060448201526064016106ea565b87610c1e824761357e565b1015610c6c5760405162461bcd60e51b815260206004820152601c60248201527f4f455620626964207061796d656e7420616d6f756e742073686f72740000000060448201526064016106ea565b6040805189815263ffffffff891660208201526001600160a01b03841681830152905133918b917f39b24cbe33ddb28dc22abcbaf14bf7f5544cc9c886c49dbb2f0d30e9dd1448949181900360600190a35050610cc96001600055565b50505050505050565b606080828067ffffffffffffffff811115610cef57610cef613044565b604051908082528060200260200182016040528015610d18578160200160208202803683370190505b5092508067ffffffffffffffff811115610d3457610d34613044565b604051908082528060200260200182016040528015610d6757816020015b6060815260200190600190039081610d525790505b50915060005b81811015610e2f5730868683818110610d8857610d88613591565b9050602002810190610d9a91906135a7565b604051610da89291906135ee565b600060405180830381855af49150503d8060008114610de3576040519150601f19603f3d011682016040523d82523d6000602084013e610de8565b606091505b50858381518110610dfb57610dfb613591565b60200260200101858481518110610e1457610e14613591565b60209081029190910101919091529015159052600101610d6d565b50509250929050565b60018054610e45906135fe565b80601f0160208091040260200160405190810160405280929190818152602001828054610e71906135fe565b8015610ebe5780601f10610e9357610100808354040283529160200191610ebe565b820191906000526020600020905b815481529060010190602001808311610ea157829003601f168201915b505050505081565b60603315610f165760405162461bcd60e51b815260206004820152601760248201527f53656e6465722061646472657373206e6f74207a65726f00000000000000000060448201526064016106ea565b610f568484848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506117fe92505050565b90505b9392505050565b6000806000600260008686604051602001610f85929190918252602082015260400190565b60408051808303601f1901815291815281516020928301208352908201929092520160002054601b81900b96600160e01b90910463ffffffff1695509350505050565b60008381526003602052604081208054829182916001600160a01b031633146110335760405162461bcd60e51b815260206004820152601b60248201527f53656e646572206e6f74206c617374206269642075706461746572000000000060448201526064016106ea565b805461104f908890600160a01b900463ffffffff168888611842565b60408051848152601b84900b602082015263ffffffff83168183015290519397509195509350339189917ff775a9e1e1719e1dfecea2021e4b9861ac4d02846df440c4cba17e3ce855f913919081900360600190a35093509350939050565b6060818067ffffffffffffffff8111156110ca576110ca613044565b6040519080825280602002602001820160405280156110fd57816020015b60608152602001906001900390816110e85790505b50915060005b818110156112275760003086868481811061112057611120613591565b905060200281019061113291906135a7565b6040516111409291906135ee565b600060405180830381855af49150503d806000811461117b576040519150601f19603f3d011682016040523d82523d6000602084013e611180565b606091505b5085848151811061119357611193613591565b602090810291909101015290508061121e5760008483815181106111b9576111b9613591565b602002602001015190506000815111156111d65780518082602001fd5b60405162461bcd60e51b815260206004820152601b60248201527f4d756c746963616c6c3a204e6f2072657665727420737472696e67000000000060448201526064016106ea565b50600101611103565b505092915050565b611237611744565b6001600160a01b03821661128d5760405162461bcd60e51b815260206004820152601660248201527f526563697069656e742061646472657373207a65726f0000000000000000000060448201526064016106ea565b806000036112dd5760405162461bcd60e51b815260206004820152600b60248201527f416d6f756e74207a65726f00000000000000000000000000000000000000000060448201526064016106ea565b336001600160a01b037f000000000000000000000000ef455205966486f52f7951ba4c3517239b0368351614806113bd5750604051632474521560e21b81527f3f3dbd056b7a78613ffe16aa0b387c96dcab786ad33ac8ffca48c513afaeae6760048201523360248201527f000000000000000000000000cd7df573b0f0bb4f2f8dfff6650cde8c774317306001600160a01b0316906391d1485490604401602060405180830381865afa158015611399573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113bd919061350d565b6114095760405162461bcd60e51b815260206004820152601660248201527f53656e6465722063616e6e6f742077697468647261770000000000000000000060448201526064016106ea565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611456576040519150601f19603f3d011682016040523d82523d6000602084013e61145b565b606091505b50509050806114ac5760405162461bcd60e51b815260206004820152601360248201527f5769746864726177616c2072657665727465640000000000000000000000000060448201526064016106ea565b604080516001600160a01b038516815260208101849052338183015290517fff79f55e9fae054ff094d9e06f631119716d818f9f8ea9b5b2adf5679f6c12e09181900360600190a1506114ff6001600055565b5050565b6000808033156115555760405162461bcd60e51b815260206004820152601760248201527f53656e6465722061646472657373206e6f74207a65726f00000000000000000060448201526064016106ea565b611563866000198787611842565b91989097509095509350505050565b80516000908190600181116115c95760405162461bcd60e51b815260206004820152601f60248201527f537065636966696564206c657373207468616e2074776f20426561636f6e730060448201526064016106ea565b60008167ffffffffffffffff8111156115e4576115e4613044565b60405190808252806020026020018201604052801561160d578160200160208202803683370190505b50905060008267ffffffffffffffff81111561162b5761162b613044565b604051908082528060200260200182016040528015611654578160200160208202803683370190505b50905060005b838110156116f55760006002600089848151811061167a5761167a613591565b602090810291909101810151825281019190915260400160002080548551919250601b0b908590849081106116b1576116b1613591565b602090810291909101015280548351600160e01b90910463ffffffff16908490849081106116e1576116e1613591565b60209081029190910101525060010161165a565b506116ff8261216c565b945061170a8161216c565b9350505050915091565b6000816040516020016117279190613632565b604051602081830303815290604052805190602001209050919050565b6002600054036117965760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016106ea565b6002600055565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01611727565b60008060006117e785856122be565b915091506117f481612303565b5090505b92915050565b6060610f59838360006040518060400160405280601e81526020017f416464726573733a206c6f772d6c6576656c2063616c6c206661696c6564000081525061246b565b6000808083806118945760405162461bcd60e51b815260206004820152601160248201527f5369676e6564206461746120656d70747900000000000000000000000000000060448201526064016106ea565b80600103611b185760008060008060008a8a60008181106118b7576118b7613591565b90506020028101906118c991906135a7565b8101906118d691906136e6565b9450945094509450945061192c85856040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b985060008d8a60405160200161194c929190918252602082015260400190565b604051602081830303815290604052805190602001209050856001600160a01b03166119b2836109488860405160200161198891815260200190565b60405160208183030381529060405280519060200120888860405160200161092d93929190613770565b6001600160a01b0316146119fd5760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016106ea565b8c841115611a4d5760405162461bcd60e51b815260206004820152601960248201527f54696d657374616d702065786365656473206375742d6f66660000000000000060448201526064016106ea565b600081815260026020526040902054600160e01b900463ffffffff168411611ab75760405162461bcd60e51b815260206004820152601960248201527f446f6573206e6f74207570646174652074696d657374616d700000000000000060448201526064016106ea565b611ac08361255f565b604080518082018252601b83900b815263ffffffff80881660208084019182526000968752600290529290942090519151909316600160e01b026001600160e01b039091161790915597509195506121619350505050565b60008167ffffffffffffffff811115611b3357611b33613044565b604051908082528060200260200182016040528015611b5c578160200160208202803683370190505b50905060008267ffffffffffffffff811115611b7a57611b7a613044565b604051908082528060200260200182016040528015611ba3578160200160208202803683370190505b50905060005b8381101561204d5760008060008060008d8d87818110611bcb57611bcb613591565b9050602002810190611bdd91906135a7565b810190611bea91906136e6565b94509450945094509450611c4085856040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b888781518110611c5257611c52613591565b6020026020010181815250508f888781518110611c7157611c71613591565b6020026020010151604051602001611c93929190918252602082015260400190565b60405160208183030381529060405280519060200120878781518110611cbb57611cbb613591565b6020908102919091010152805115611ebe57846001600160a01b0316611d1b8261094887604051602001611cf191815260200190565b60405160208183030381529060405280519060200120878760405160200161092d93929190613770565b6001600160a01b031614611d665760405162461bcd60e51b81526020600482015260126024820152710a6d2cedcc2e8eae4ca40dad2e6dac2e8c6d60731b60448201526064016106ea565b8e831115611db65760405162461bcd60e51b815260206004820152601960248201527f54696d657374616d702065786365656473206375742d6f66660000000000000060448201526064016106ea565b60026000888881518110611dcc57611dcc613591565b602090810291909101810151825281019190915260400160002054600160e01b900463ffffffff168311611e425760405162461bcd60e51b815260206004820152601960248201527f446f6573206e6f74207570646174652074696d657374616d700000000000000060448201526064016106ea565b6040518060400160405280611e568461255f565b601b0b81526020018463ffffffff1681525060026000898981518110611e7e57611e7e613591565b6020908102919091018101518252818101929092526040016000208251929091015163ffffffff16600160e01b026001600160e01b039092169190911790555b6000807f0000000000000000000000003ee097b82e270d82f829e5742cc16b7686247ff26001600160a01b03166367a7cfb78b8a81518110611f0257611f02613591565b60200260200101516040518263ffffffff1660e01b8152600401611f2891815260200190565b6040805180830381865afa158015611f44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f68919061379d565b91509150600260008a8a81518110611f8257611f82613591565b60200260200101518152602001908152602001600020600001601c9054906101000a900463ffffffff1663ffffffff168163ffffffff16111561203357604051806040016040528083601b0b81526020018263ffffffff16815250600260008b8b81518110611ff357611ff3613591565b6020908102919091018101518252818101929092526040016000208251929091015163ffffffff16600160e01b026001600160e01b039092169190911790555b505050505050508080612045906137dd565b915050611ba9565b5061205782611714565b955061206281611572565b60408051602081018e9052908101899052919650945060009060600160408051601f19818403018152918152815160209283012060008181526002909352912080549192509063ffffffff808816600160e01b9092041603612115578054601b88810b91900b036121155760405162461bcd60e51b815260206004820152601a60248201527f446f6573206e6f742075706461746520426561636f6e2073657400000000000060448201526064016106ea565b50604080518082018252601b88900b815263ffffffff80881660208084019182526000958652600290529290932090519151909216600160e01b026001600160e01b0390911617905550505b509450945094915050565b80516000906009811161223e5761218283612662565b61218d60028261380c565b6001036121c057826121a0600283613820565b815181106121b0576121b0613591565b6020026020010151915050919050565b806000036121d0576121d0613834565b610f598360016002840403815181106121eb576121eb613591565b60200260200101518460028481612204576122046137f6565b048151811061221557612215613591565b6020026020010151600182811d82821d01838316919091160160ff81901c838318160192915050565b61224960028261380c565b60010361226557826121a081612260600285613820565b612b70565b6000806122788560016002860403612b9d565b80925081935050506122af85838151811061229557612295613591565b602002602001015186838151811061221557612215613591565b95945050505050565b50919050565b60008082516041036122f45760208301516040840151606085015160001a6122e887828585612bd2565b945094505050506122fc565b506000905060025b9250929050565b60008160048111156123175761231761384a565b0361231f5750565b60018160048111156123335761233361384a565b036123805760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016106ea565b60028160048111156123945761239461384a565b036123e15760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016106ea565b60038160048111156123f5576123f561384a565b036124685760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f756500000000000000000000000000000000000000000000000000000000000060648201526084016106ea565b50565b6060824710156124e35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016106ea565b600080866001600160a01b031685876040516124ff9190613860565b60006040518083038185875af1925050503d806000811461253c576040519150601f19603f3d011682016040523d82523d6000602084013e612541565b606091505b509150915061255287838387612c96565b925050505b949350505050565b600081516020146125b25760405162461bcd60e51b815260206004820152601760248201527f44617461206c656e677468206e6f7420636f727265637400000000000000000060448201526064016106ea565b6000828060200190518101906125c89190613565565b90507fffffffff80000000000000000000000000000000000000000000000000000000811280159061261657507b7fffffffffffffffffffffffffffffffffffffffffffffffffffffff8113155b6117f85760405162461bcd60e51b815260206004820152601760248201527f56616c7565207479706563617374696e67206572726f7200000000000000000060448201526064016106ea565b805160098111156126b55760405162461bcd60e51b815260206004820152601660248201527f417272617920746f6f206c6f6e6720746f20736f72740000000000000000000060448201526064016106ea565b60068110156127bc57600481101561270b57806003036126f6576126dc8260006001612d0f565b6126e98260016002612d0f565b6114ff8260006001612d0f565b806002036114ff576114ff8260006001612d0f565b80600503612788576127208260016002612d0f565b61272d8260036004612d0f565b61273a8260016003612d0f565b6127478260006002612d0f565b6127548260026004612d0f565b6127618260006003612d0f565b61276e8260006001612d0f565b61277b8260026003612d0f565b6114ff8260016002612d0f565b6127958260006001612d0f565b6127a28260026003612d0f565b6127af8260016003612d0f565b61277b8260006002612d0f565b6008811015612939578060070361289d576127da8260016002612d0f565b6127e78260036004612d0f565b6127f48260056006612d0f565b6128018260006002612d0f565b61280e8260046006612d0f565b61281b8260036005612d0f565b6128288260026006612d0f565b6128358260016005612d0f565b6128428260006004612d0f565b61284f8260026005612d0f565b61285c8260006003612d0f565b6128698260026004612d0f565b6128768260016003612d0f565b6128838260006001612d0f565b6128908260026003612d0f565b6114ff8260046005612d0f565b6128aa8260006001612d0f565b6128b78260026003612d0f565b6128c48260046005612d0f565b6128d18260016003612d0f565b6128de8260036005612d0f565b6128eb8260016003612d0f565b6128f88260026004612d0f565b6129058260006002612d0f565b6129128260026004612d0f565b61291f8260036004612d0f565b61292c8260016002612d0f565b6114ff8260026003612d0f565b80600903612a6c5761294e8260016008612d0f565b61295b8260026007612d0f565b6129688260036006612d0f565b6129758260046005612d0f565b6129828260016004612d0f565b61298f8260056008612d0f565b61299c8260006002612d0f565b6129a98260066007612d0f565b6129b68260026006612d0f565b6129c38260076008612d0f565b6129d08260006003612d0f565b6129dd8260046005612d0f565b6129ea8260006001612d0f565b6129f78260036005612d0f565b612a048260066007612d0f565b612a118260026004612d0f565b612a1e8260016003612d0f565b612a2b8260056007612d0f565b612a388260046006612d0f565b612a458260016002612d0f565b612a528260036004612d0f565b612a5f8260056006612d0f565b6128838260076008612d0f565b612a798260006007612d0f565b612a868260016006612d0f565b612a938260026005612d0f565b612aa08260036004612d0f565b612aad8260006003612d0f565b612aba8260046007612d0f565b612ac78260016002612d0f565b612ad48260056006612d0f565b612ae18260006001612d0f565b612aee8260026003612d0f565b612afb8260046005612d0f565b612b088260066007612d0f565b612b158260036005612d0f565b612b228260026004612d0f565b612b2f8260016002612d0f565b612b3c8260036004612d0f565b612b498260056006612d0f565b612b568260026003612d0f565b612b638260046005612d0f565b6114ff8260036004612d0f565b815160009080612b8257612b82613834565b612b9484600060018403866000612dbd565b50949350505050565b8151600090819060018111612bb457612bb4613834565b612bc685600060018403876001612dbd565b90969095509350505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115612c095750600090506003612c8d565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612c5d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612c8657600060019250925050612c8d565b9150600090505b94509492505050565b60608315612d05578251600003612cfe576001600160a01b0385163b612cfe5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016106ea565b5081612557565b6125578383612e93565b828181518110612d2157612d21613591565b6020026020010151838381518110612d3b57612d3b613591565b60200260200101511315612db857828181518110612d5b57612d5b613591565b6020026020010151838381518110612d7557612d75613591565b6020026020010151848481518110612d8f57612d8f613591565b60200260200101858481518110612da857612da8613591565b6020908102919091010191909152525b505050565b600080848603612dd257508290506000612e89565b6000612ddf888888612ebd565b905080851015612e0257612dfa888860018403886000612dbd565b509250612e1f565b80851115612e1b57612dfa888260010188886000612dbd565b8092505b8315612e8757875160018401925060028401905b80821015612e8457898481518110612e4d57612e4d613591565b60200260200101518a8381518110612e6757612e67613591565b60200260200101511215612e79578193505b600190910190612e33565b50505b505b9550959350505050565b815115612ea35781518083602001fd5b8060405162461bcd60e51b81526004016106ea9190613391565b6000818303612ecd575081610f59565b6000848481518110612ee157612ee1613591565b6020026020010151905060008490508360010192505b855160019091019081108015612f25575081868281518110612f1b57612f1b613591565b6020026020010151125b612ef7575b82806001900393505081868481518110612f4657612f46613591565b602002602001015113612f2a57828110612fd157858381518110612f6c57612f6c613591565b6020026020010151868681518110612f8657612f86613591565b6020026020010151878781518110612fa057612fa0613591565b60200260200101888681518110612fb957612fb9613591565b60200260200101828152508281525050505050610f59565b858381518110612fe357612fe3613591565b6020026020010151868281518110612ffd57612ffd613591565b602002602001015187838151811061301757613017613591565b6020026020010188868151811061303057613030613591565b602090810291909101019190915252612ef7565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561308357613083613044565b604052919050565b6000602080838503121561309e57600080fd5b823567ffffffffffffffff808211156130b657600080fd5b818501915085601f8301126130ca57600080fd5b8135818111156130dc576130dc613044565b8060051b91506130ed84830161305a565b818152918301840191848101908884111561310757600080fd5b938501935b838510156131255784358252938501939085019061310c565b98975050505050505050565b63ffffffff8116811461246857600080fd5b60008083601f84011261315557600080fd5b50813567ffffffffffffffff81111561316d57600080fd5b6020830191508360208285010111156122fc57600080fd5b600080600080600080600060a0888a0312156131a057600080fd5b873596506020880135955060408801356131b981613131565b9450606088013567ffffffffffffffff808211156131d657600080fd5b6131e28b838c01613143565b909650945060808a01359150808211156131fb57600080fd5b506132088a828b01613143565b989b979a50959850939692959293505050565b60008083601f84011261322d57600080fd5b50813567ffffffffffffffff81111561324557600080fd5b6020830191508360208260051b85010111156122fc57600080fd5b6000806020838503121561327357600080fd5b823567ffffffffffffffff81111561328a57600080fd5b612bc68582860161321b565b60005b838110156132b1578181015183820152602001613299565b50506000910152565b600081518084526132d2816020860160208601613296565b601f01601f19169290920160200192915050565b6000815180845260208085019450848260051b860182860160005b8581101561332b5783830389526133198383516132ba565b98850198925090840190600101613301565b5090979650505050505050565b604080825283519082018190526000906020906060840190828701845b82811015613373578151151584529284019290840190600101613355565b5050508381038285015261338781866132e6565b9695505050505050565b602081526000610f5960208301846132ba565b6001600160a01b038116811461246857600080fd5b6000602082840312156133cb57600080fd5b8135610f59816133a4565b6000806000604084860312156133eb57600080fd5b83356133f6816133a4565b9250602084013567ffffffffffffffff81111561341257600080fd5b61341e86828701613143565b9497909650939450505050565b6000806040838503121561343e57600080fd5b50508035926020909101359150565b60006020828403121561345f57600080fd5b5035919050565b60008060006040848603121561347b57600080fd5b83359250602084013567ffffffffffffffff81111561349957600080fd5b61341e8682870161321b565b602081526000610f5960208301846132e6565b600080604083850312156134cb57600080fd5b82356134d6816133a4565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b808201808211156117f8576117f86134e4565b60006020828403121561351f57600080fd5b81518015158114610f5957600080fd5b83815260406020820152816040820152818360608301376000818301606090810191909152601f909201601f1916010192915050565b60006020828403121561357757600080fd5b5051919050565b818103818111156117f8576117f86134e4565b634e487b7160e01b600052603260045260246000fd5b6000808335601e198436030181126135be57600080fd5b83018035915067ffffffffffffffff8211156135d957600080fd5b6020019150368190038213156122fc57600080fd5b8183823760009101908152919050565b600181811c9082168061361257607f821691505b6020821081036122b857634e487b7160e01b600052602260045260246000fd5b6020808252825182820181905260009190848201906040850190845b8181101561366a5783518352928401929184019160010161364e565b50909695505050505050565b600082601f83011261368757600080fd5b813567ffffffffffffffff8111156136a1576136a1613044565b6136b4601f8201601f191660200161305a565b8181528460208386010111156136c957600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156136fe57600080fd5b8535613709816133a4565b94506020860135935060408601359250606086013567ffffffffffffffff8082111561373457600080fd5b61374089838a01613676565b9350608088013591508082111561375657600080fd5b5061376388828901613676565b9150509295509295909350565b8381528260208201526000825161378e816040850160208701613296565b91909101604001949350505050565b600080604083850312156137b057600080fd5b825180601b0b81146137c157600080fd5b60208401519092506137d281613131565b809150509250929050565b6000600182016137ef576137ef6134e4565b5060010190565b634e487b7160e01b600052601260045260246000fd5b60008261381b5761381b6137f6565b500690565b60008261382f5761382f6137f6565b500490565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b60008251613872818460208701613296565b919091019291505056fea26469706673582212204ccab876dd8e5b8c1dbe3ebd5d905d28ef151d9fec708c8a83d36f8e6bd94e4964736f6c63430008110033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.