Contract Name:
UniversalResolver
Contract Source Code:
<i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// 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);
}
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
pragma solidity >=0.8.4;
interface ENS {
// Logged when the owner of a node assigns a new owner to a subnode.
event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
// Logged when the owner of a node transfers ownership to a new account.
event Transfer(bytes32 indexed node, address owner);
// Logged when the resolver for a node changes.
event NewResolver(bytes32 indexed node, address resolver);
// Logged when the TTL of a node changes
event NewTTL(bytes32 indexed node, uint64 ttl);
// Logged when an operator is added or removed.
event ApprovalForAll(
address indexed owner,
address indexed operator,
bool approved
);
function setRecord(
bytes32 node,
address owner,
address resolver,
uint64 ttl
) external;
function setSubnodeRecord(
bytes32 node,
bytes32 label,
address owner,
address resolver,
uint64 ttl
) external;
function setSubnodeOwner(
bytes32 node,
bytes32 label,
address owner
) external returns (bytes32);
function setResolver(bytes32 node, address resolver) external;
function setOwner(bytes32 node, address owner) external;
function setTTL(bytes32 node, uint64 ttl) external;
function setApprovalForAll(address operator, bool approved) external;
function owner(bytes32 node) external view returns (address);
function resolver(bytes32 node) external view returns (address);
function ttl(bytes32 node) external view returns (uint64);
function recordExists(bytes32 node) external view returns (bool);
function isApprovedForAll(
address owner,
address operator
) external view returns (bool);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "./profiles/IABIResolver.sol";
import "./profiles/IAddressResolver.sol";
import "./profiles/IAddrResolver.sol";
import "./profiles/IContentHashResolver.sol";
import "./profiles/IDNSRecordResolver.sol";
import "./profiles/IDNSZoneResolver.sol";
import "./profiles/IInterfaceResolver.sol";
import "./profiles/INameResolver.sol";
import "./profiles/IPubkeyResolver.sol";
import "./profiles/ITextResolver.sol";
import "./profiles/IExtendedResolver.sol";
/**
* A generic resolver interface which includes all the functions including the ones deprecated
*/
interface Resolver is
IERC165,
IABIResolver,
IAddressResolver,
IAddrResolver,
IContentHashResolver,
IDNSRecordResolver,
IDNSZoneResolver,
IInterfaceResolver,
INameResolver,
IPubkeyResolver,
ITextResolver,
IExtendedResolver
{
/* Deprecated events */
event ContentChanged(bytes32 indexed node, bytes32 hash);
function setABI(
bytes32 node,
uint256 contentType,
bytes calldata data
) external;
function setAddr(bytes32 node, address addr) external;
function setAddr(bytes32 node, uint256 coinType, bytes calldata a) external;
function setContenthash(bytes32 node, bytes calldata hash) external;
function setDnsrr(bytes32 node, bytes calldata data) external;
function setName(bytes32 node, string calldata _name) external;
function setPubkey(bytes32 node, bytes32 x, bytes32 y) external;
function setText(
bytes32 node,
string calldata key,
string calldata value
) external;
function setInterface(
bytes32 node,
bytes4 interfaceID,
address implementer
) external;
function multicall(
bytes[] calldata data
) external returns (bytes[] memory results);
function multicallWithNodeCheck(
bytes32 nodehash,
bytes[] calldata data
) external returns (bytes[] memory results);
/* Deprecated functions */
function content(bytes32 node) external view returns (bytes32);
function multihash(bytes32 node) external view returns (bytes memory);
function setContent(bytes32 node, bytes32 hash) external;
function setMultihash(bytes32 node, bytes calldata hash) external;
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IABIResolver {
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
/**
* Returns the ABI associated with an ENS node.
* Defined in EIP205.
* @param node The ENS node to query
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
* @return contentType The content type of the return value
* @return data The ABI data
*/
function ABI(
bytes32 node,
uint256 contentTypes
) external view returns (uint256, bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/**
* Interface for the legacy (ETH-only) addr function.
*/
interface IAddrResolver {
event AddrChanged(bytes32 indexed node, address a);
/**
* Returns the address associated with an ENS node.
* @param node The ENS node to query.
* @return The associated address.
*/
function addr(bytes32 node) external view returns (address payable);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/**
* Interface for the new (multicoin) addr function.
*/
interface IAddressResolver {
event AddressChanged(
bytes32 indexed node,
uint256 coinType,
bytes newAddress
);
function addr(
bytes32 node,
uint256 coinType
) external view returns (bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IContentHashResolver {
event ContenthashChanged(bytes32 indexed node, bytes hash);
/**
* Returns the contenthash associated with an ENS node.
* @param node The ENS node to query.
* @return The associated contenthash.
*/
function contenthash(bytes32 node) external view returns (bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IDNSRecordResolver {
// DNSRecordChanged is emitted whenever a given node/name/resource's RRSET is updated.
event DNSRecordChanged(
bytes32 indexed node,
bytes name,
uint16 resource,
bytes record
);
// DNSRecordDeleted is emitted whenever a given node/name/resource's RRSET is deleted.
event DNSRecordDeleted(bytes32 indexed node, bytes name, uint16 resource);
/**
* Obtain a DNS record.
* @param node the namehash of the node for which to fetch the record
* @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
* @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
* @return the DNS record in wire format if present, otherwise empty
*/
function dnsRecord(
bytes32 node,
bytes32 name,
uint16 resource
) external view returns (bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IDNSZoneResolver {
// DNSZonehashChanged is emitted whenever a given node's zone hash is updated.
event DNSZonehashChanged(
bytes32 indexed node,
bytes lastzonehash,
bytes zonehash
);
/**
* zonehash obtains the hash for the zone.
* @param node The ENS node to query.
* @return The associated contenthash.
*/
function zonehash(bytes32 node) external view returns (bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IExtendedResolver {
function resolve(
bytes memory name,
bytes memory data
) external view returns (bytes memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IInterfaceResolver {
event InterfaceChanged(
bytes32 indexed node,
bytes4 indexed interfaceID,
address implementer
);
/**
* Returns the address of a contract that implements the specified interface for this name.
* If an implementer has not been set for this interfaceID and name, the resolver will query
* the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
* contract implements EIP165 and returns `true` for the specified interfaceID, its address
* will be returned.
* @param node The ENS node to query.
* @param interfaceID The EIP 165 interface ID to check for.
* @return The address that implements this interface, or 0 if the interface is unsupported.
*/
function interfaceImplementer(
bytes32 node,
bytes4 interfaceID
) external view returns (address);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface INameResolver {
event NameChanged(bytes32 indexed node, string name);
/**
* Returns the name associated with an ENS node, for reverse records.
* Defined in EIP181.
* @param node The ENS node to query.
* @return The associated name.
*/
function name(bytes32 node) external view returns (string memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IPubkeyResolver {
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
/**
* Returns the SECP256k1 public key associated with an ENS node.
* Defined in EIP 619.
* @param node The ENS node to query
* @return x The X coordinate of the curve point for the public key.
* @return y The Y coordinate of the curve point for the public key.
*/
function pubkey(bytes32 node) external view returns (bytes32 x, bytes32 y);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface ITextResolver {
event TextChanged(
bytes32 indexed node,
string indexed indexedKey,
string key,
string value
);
/**
* Returns the text data associated with an ENS node and key.
* @param node The ENS node to query.
* @param key The text data key to query.
* @return The associated text data.
*/
function text(
bytes32 node,
string calldata key
) external view returns (string memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
library HexUtils {
/**
* @dev Attempts to parse bytes32 from a hex string
* @param str The string to parse
* @param idx The offset to start parsing at
* @param lastIdx The (exclusive) last index in `str` to consider. Use `str.length` to scan the whole string.
*/
function hexStringToBytes32(
bytes memory str,
uint256 idx,
uint256 lastIdx
) internal pure returns (bytes32 r, bool valid) {
valid = true;
assembly {
// check that the index to read to is not past the end of the string
if gt(lastIdx, mload(str)) {
revert(0, 0)
}
function getHex(c) -> ascii {
// chars 48-57: 0-9
if and(gt(c, 47), lt(c, 58)) {
ascii := sub(c, 48)
leave
}
// chars 65-70: A-F
if and(gt(c, 64), lt(c, 71)) {
ascii := add(sub(c, 65), 10)
leave
}
// chars 97-102: a-f
if and(gt(c, 96), lt(c, 103)) {
ascii := add(sub(c, 97), 10)
leave
}
// invalid char
ascii := 0xff
}
let ptr := add(str, 32)
for {
let i := idx
} lt(i, lastIdx) {
i := add(i, 2)
} {
let byte1 := getHex(byte(0, mload(add(ptr, i))))
let byte2 := getHex(byte(0, mload(add(ptr, add(i, 1)))))
// if either byte is invalid, set invalid and break loop
if or(eq(byte1, 0xff), eq(byte2, 0xff)) {
valid := false
break
}
let combined := or(shl(4, byte1), byte2)
r := or(shl(8, r), combined)
}
}
}
/**
* @dev Attempts to parse an address from a hex string
* @param str The string to parse
* @param idx The offset to start parsing at
* @param lastIdx The (exclusive) last index in `str` to consider. Use `str.length` to scan the whole string.
*/
function hexToAddress(
bytes memory str,
uint256 idx,
uint256 lastIdx
) internal pure returns (address, bool) {
if (lastIdx - idx < 40) return (address(0x0), false);
(bytes32 r, bool valid) = hexStringToBytes32(str, idx, lastIdx);
return (address(uint160(uint256(r))), valid);
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
library LowLevelCallUtils {
using Address for address;
/**
* @dev Makes a static call to the specified `target` with `data`. Return data can be fetched with
* `returnDataSize` and `readReturnData`.
* @param target The address to staticcall.
* @param data The data to pass to the call.
* @return success True if the call succeeded, or false if it reverts.
*/
function functionStaticCall(
address target,
bytes memory data
) internal view returns (bool success) {
require(
target.isContract(),
"LowLevelCallUtils: static call to non-contract"
);
assembly {
success := staticcall(
gas(),
target,
add(data, 32),
mload(data),
0,
0
)
}
}
/**
* @dev Returns the size of the return data of the most recent external call.
*/
function returnDataSize() internal pure returns (uint256 len) {
assembly {
len := returndatasize()
}
}
/**
* @dev Reads return data from the most recent external call.
* @param offset Offset into the return data.
* @param length Number of bytes to return.
*/
function readReturnData(
uint256 offset,
uint256 length
) internal pure returns (bytes memory data) {
data = new bytes(length);
assembly {
returndatacopy(add(data, 32), offset, length)
}
}
/**
* @dev Reverts with the return data from the most recent external call.
*/
function propagateRevert() internal pure {
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {BytesUtils} from "../wrapper/BytesUtils.sol";
library NameEncoder {
using BytesUtils for bytes;
function dnsEncodeName(
string memory name
) internal pure returns (bytes memory dnsName, bytes32 node) {
uint8 labelLength = 0;
bytes memory bytesName = bytes(name);
uint256 length = bytesName.length;
dnsName = new bytes(length + 2);
node = 0;
if (length == 0) {
dnsName[0] = 0;
return (dnsName, node);
}
// use unchecked to save gas since we check for an underflow
// and we check for the length before the loop
unchecked {
for (uint256 i = length - 1; i >= 0; i--) {
if (bytesName[i] == ".") {
dnsName[i + 1] = bytes1(labelLength);
node = keccak256(
abi.encodePacked(
node,
bytesName.keccak(i + 1, labelLength)
)
);
labelLength = 0;
} else {
labelLength += 1;
dnsName[i + 1] = bytesName[i];
}
if (i == 0) {
break;
}
}
}
node = keccak256(
abi.encodePacked(node, bytesName.keccak(0, labelLength))
);
dnsName[0] = bytes1(labelLength);
return (dnsName, node);
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.17 <0.9.0;
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {LowLevelCallUtils} from "./LowLevelCallUtils.sol";
import {ENS} from "../registry/ENS.sol";
import {IExtendedResolver} from "../resolvers/profiles/IExtendedResolver.sol";
import {Resolver, INameResolver, IAddrResolver} from "../resolvers/Resolver.sol";
import {NameEncoder} from "./NameEncoder.sol";
import {BytesUtils} from "../wrapper/BytesUtils.sol";
import {HexUtils} from "./HexUtils.sol";
error OffchainLookup(
address sender,
string[] urls,
bytes callData,
bytes4 callbackFunction,
bytes extraData
);
struct MulticallData {
bytes name;
bytes[] data;
string[] gateways;
bytes4 callbackFunction;
address resolver;
bytes metaData;
bool[] failures;
}
struct OffchainLookupCallData {
address sender;
string[] urls;
bytes callData;
}
struct OffchainLookupExtraData {
bytes4 callbackFunction;
bytes data;
}
interface BatchGateway {
function query(
OffchainLookupCallData[] memory data
) external returns (bool[] memory failures, bytes[] memory responses);
}
/**
* The Universal Resolver is a contract that handles the work of resolving a name entirely onchain,
* making it possible to make a single smart contract call to resolve an ENS name.
*/
contract UniversalResolver is ERC165, Ownable {
using Address for address;
using NameEncoder for string;
using BytesUtils for bytes;
using HexUtils for bytes;
string[] public batchGatewayURLs;
ENS public immutable registry;
constructor(address _registry, string[] memory _urls) {
registry = ENS(_registry);
batchGatewayURLs = _urls;
}
function setGatewayURLs(string[] memory _urls) public onlyOwner {
batchGatewayURLs = _urls;
}
/**
* @dev Performs ENS name resolution for the supplied name and resolution data.
* @param name The name to resolve, in normalised and DNS-encoded form.
* @param data The resolution data, as specified in ENSIP-10.
* @return The result of resolving the name.
*/
function resolve(
bytes calldata name,
bytes memory data
) external view returns (bytes memory, address) {
return
_resolveSingle(
name,
data,
batchGatewayURLs,
this.resolveSingleCallback.selector,
""
);
}
function resolve(
bytes calldata name,
bytes[] memory data
) external view returns (bytes[] memory, address) {
return resolve(name, data, batchGatewayURLs);
}
function resolve(
bytes calldata name,
bytes memory data,
string[] memory gateways
) external view returns (bytes memory, address) {
return
_resolveSingle(
name,
data,
gateways,
this.resolveSingleCallback.selector,
""
);
}
function resolve(
bytes calldata name,
bytes[] memory data,
string[] memory gateways
) public view returns (bytes[] memory, address) {
return
_resolve(name, data, gateways, this.resolveCallback.selector, "");
}
function _resolveSingle(
bytes calldata name,
bytes memory data,
string[] memory gateways,
bytes4 callbackFunction,
bytes memory metaData
) public view returns (bytes memory, address) {
bytes[] memory dataArr = new bytes[](1);
dataArr[0] = data;
(bytes[] memory results, address resolver) = _resolve(
name,
dataArr,
gateways,
callbackFunction,
metaData
);
return (results[0], resolver);
}
function _resolve(
bytes calldata name,
bytes[] memory data,
string[] memory gateways,
bytes4 callbackFunction,
bytes memory metaData
) internal view returns (bytes[] memory results, address resolverAddress) {
(Resolver resolver, ) = findResolver(name);
resolverAddress = address(resolver);
if (resolverAddress == address(0)) {
return (results, address(0));
}
results = _multicall(
MulticallData(
name,
data,
gateways,
callbackFunction,
resolverAddress,
metaData,
new bool[](data.length)
)
);
}
function reverse(
bytes calldata reverseName
) external view returns (string memory, address, address, address) {
return reverse(reverseName, batchGatewayURLs);
}
/**
* @dev Performs ENS name reverse resolution for the supplied reverse name.
* @param reverseName The reverse name to resolve, in normalised and DNS-encoded form. e.g. b6E040C9ECAaE172a89bD561c5F73e1C48d28cd9.addr.reverse
* @return The resolved name, the resolved address, the reverse resolver address, and the resolver address.
*/
function reverse(
bytes calldata reverseName,
string[] memory gateways
) public view returns (string memory, address, address, address) {
bytes memory encodedCall = abi.encodeCall(
INameResolver.name,
reverseName.namehash(0)
);
(
bytes memory resolvedReverseData,
address reverseResolverAddress
) = _resolveSingle(
reverseName,
encodedCall,
gateways,
this.reverseCallback.selector,
""
);
return
getForwardDataFromReverse(
resolvedReverseData,
reverseResolverAddress,
gateways
);
}
function getForwardDataFromReverse(
bytes memory resolvedReverseData,
address reverseResolverAddress,
string[] memory gateways
) internal view returns (string memory, address, address, address) {
string memory resolvedName = abi.decode(resolvedReverseData, (string));
(bytes memory encodedName, bytes32 namehash) = resolvedName
.dnsEncodeName();
bytes memory encodedCall = abi.encodeCall(IAddrResolver.addr, namehash);
bytes memory metaData = abi.encode(
resolvedName,
reverseResolverAddress
);
(bytes memory resolvedData, address resolverAddress) = this
._resolveSingle(
encodedName,
encodedCall,
gateways,
this.reverseCallback.selector,
metaData
);
address resolvedAddress = abi.decode(resolvedData, (address));
return (
resolvedName,
resolvedAddress,
reverseResolverAddress,
resolverAddress
);
}
function resolveSingleCallback(
bytes calldata response,
bytes calldata extraData
) external view returns (bytes memory, address) {
(bytes[] memory results, address resolver, , ) = _resolveCallback(
response,
extraData,
this.resolveSingleCallback.selector
);
return (results[0], resolver);
}
function resolveCallback(
bytes calldata response,
bytes calldata extraData
) external view returns (bytes[] memory, address) {
(bytes[] memory results, address resolver, , ) = _resolveCallback(
response,
extraData,
this.resolveCallback.selector
);
return (results, resolver);
}
function reverseCallback(
bytes calldata response,
bytes calldata extraData
) external view returns (string memory, address, address, address) {
(
bytes[] memory resolvedData,
address resolverAddress,
string[] memory gateways,
bytes memory metaData
) = _resolveCallback(
response,
extraData,
this.reverseCallback.selector
);
if (metaData.length > 0) {
(string memory resolvedName, address reverseResolverAddress) = abi
.decode(metaData, (string, address));
address resolvedAddress = abi.decode(resolvedData[0], (address));
return (
resolvedName,
resolvedAddress,
reverseResolverAddress,
resolverAddress
);
}
return
getForwardDataFromReverse(
resolvedData[0],
resolverAddress,
gateways
);
}
function supportsInterface(
bytes4 interfaceId
) public view virtual override returns (bool) {
return
interfaceId == type(IExtendedResolver).interfaceId ||
super.supportsInterface(interfaceId);
}
function _resolveCallback(
bytes calldata response,
bytes calldata extraData,
bytes4 callbackFunction
)
internal
view
returns (bytes[] memory, address, string[] memory, bytes memory)
{
MulticallData memory multicallData;
multicallData.callbackFunction = callbackFunction;
(bool[] memory failures, bytes[] memory responses) = abi.decode(
response,
(bool[], bytes[])
);
OffchainLookupExtraData[] memory extraDatas;
(
multicallData.resolver,
multicallData.gateways,
multicallData.metaData,
extraDatas
) = abi.decode(
extraData,
(address, string[], bytes, OffchainLookupExtraData[])
);
require(responses.length <= extraDatas.length);
multicallData.data = new bytes[](extraDatas.length);
multicallData.failures = new bool[](extraDatas.length);
uint256 offchainCount = 0;
for (uint256 i = 0; i < extraDatas.length; i++) {
if (extraDatas[i].callbackFunction == bytes4(0)) {
// This call did not require an offchain lookup; use the previous input data.
multicallData.data[i] = extraDatas[i].data;
} else {
if (failures[offchainCount]) {
multicallData.failures[i] = true;
multicallData.data[i] = responses[offchainCount];
} else {
multicallData.data[i] = abi.encodeWithSelector(
extraDatas[i].callbackFunction,
responses[offchainCount],
extraDatas[i].data
);
}
offchainCount = offchainCount + 1;
}
}
return (
_multicall(multicallData),
multicallData.resolver,
multicallData.gateways,
multicallData.metaData
);
}
/**
* @dev Makes a call to `target` with `data`. If the call reverts with an `OffchainLookup` error, wraps
* the error with the data necessary to continue the request where it left off.
* @param target The address to call.
* @param data The data to call `target` with.
* @return offchain Whether the call reverted with an `OffchainLookup` error.
* @return returnData If `target` did not revert, contains the return data from the call to `target`. Otherwise, contains a `OffchainLookupCallData` struct.
* @return extraData If `target` did not revert, is empty. Otherwise, contains a `OffchainLookupExtraData` struct.
* @return result Whether the call succeeded.
*/
function callWithOffchainLookupPropagation(
address target,
bytes memory data
)
internal
view
returns (
bool offchain,
bytes memory returnData,
OffchainLookupExtraData memory extraData,
bool result
)
{
result = LowLevelCallUtils.functionStaticCall(address(target), data);
uint256 size = LowLevelCallUtils.returnDataSize();
if (result) {
return (
false,
LowLevelCallUtils.readReturnData(0, size),
extraData,
true
);
}
// Failure
if (size >= 4) {
bytes memory errorId = LowLevelCallUtils.readReturnData(0, 4);
// Offchain lookup. Decode the revert message and create our own that nests it.
bytes memory revertData = LowLevelCallUtils.readReturnData(
4,
size - 4
);
if (bytes4(errorId) == OffchainLookup.selector) {
(
address wrappedSender,
string[] memory wrappedUrls,
bytes memory wrappedCallData,
bytes4 wrappedCallbackFunction,
bytes memory wrappedExtraData
) = abi.decode(
revertData,
(address, string[], bytes, bytes4, bytes)
);
if (wrappedSender == target) {
returnData = abi.encode(
OffchainLookupCallData(
wrappedSender,
wrappedUrls,
wrappedCallData
)
);
extraData = OffchainLookupExtraData(
wrappedCallbackFunction,
wrappedExtraData
);
return (true, returnData, extraData, false);
}
} else {
returnData = revertData;
return (false, returnData, extraData, false);
}
}
}
/**
* @dev Finds a resolver by recursively querying the registry, starting at the longest name and progressively
* removing labels until it finds a result.
* @param name The name to resolve, in DNS-encoded and normalised form.
* @return The Resolver responsible for this name, and the namehash of the full name.
*/
function findResolver(
bytes calldata name
) public view returns (Resolver, bytes32) {
(address resolver, bytes32 labelhash) = findResolver(name, 0);
return (Resolver(resolver), labelhash);
}
function findResolver(
bytes calldata name,
uint256 offset
) internal view returns (address, bytes32) {
uint256 labelLength = uint256(uint8(name[offset]));
if (labelLength == 0) {
return (address(0), bytes32(0));
}
uint256 nextLabel = offset + labelLength + 1;
bytes32 labelHash;
if (
labelLength == 66 &&
// 0x5b == '['
name[offset + 1] == 0x5b &&
// 0x5d == ']'
name[nextLabel - 1] == 0x5d
) {
// Encrypted label
(labelHash, ) = bytes(name[offset + 2:nextLabel - 1])
.hexStringToBytes32(0, 64);
} else {
labelHash = keccak256(name[offset + 1:nextLabel]);
}
(address parentresolver, bytes32 parentnode) = findResolver(
name,
nextLabel
);
bytes32 node = keccak256(abi.encodePacked(parentnode, labelHash));
address resolver = registry.resolver(node);
if (resolver != address(0)) {
return (resolver, node);
}
return (parentresolver, node);
}
function _hasExtendedResolver(
address resolver
) internal view returns (bool) {
try
Resolver(resolver).supportsInterface(
type(IExtendedResolver).interfaceId
)
returns (bool supported) {
return supported;
} catch {
return false;
}
}
function _multicall(
MulticallData memory multicallData
) internal view returns (bytes[] memory results) {
uint256 length = multicallData.data.length;
uint256 offchainCount = 0;
OffchainLookupCallData[]
memory callDatas = new OffchainLookupCallData[](length);
OffchainLookupExtraData[]
memory extraDatas = new OffchainLookupExtraData[](length);
results = new bytes[](length);
bool isCallback = multicallData.name.length == 0;
bool hasExtendedResolver = _hasExtendedResolver(multicallData.resolver);
for (uint256 i = 0; i < length; i++) {
bytes memory item = multicallData.data[i];
bool failure = multicallData.failures[i];
if (failure) {
results[i] = item;
continue;
}
if (!isCallback && hasExtendedResolver) {
item = abi.encodeCall(
IExtendedResolver.resolve,
(multicallData.name, item)
);
}
(
bool offchain,
bytes memory returnData,
OffchainLookupExtraData memory extraData,
bool success
) = callWithOffchainLookupPropagation(multicallData.resolver, item);
if (offchain) {
callDatas[offchainCount] = abi.decode(
returnData,
(OffchainLookupCallData)
);
extraDatas[i] = extraData;
offchainCount += 1;
continue;
}
if (success && hasExtendedResolver) {
// if this is a successful resolve() call, unwrap the result
returnData = abi.decode(returnData, (bytes));
}
results[i] = returnData;
extraDatas[i].data = multicallData.data[i];
}
if (offchainCount == 0) {
return results;
}
// Trim callDatas if offchain data exists
assembly {
mstore(callDatas, offchainCount)
}
revert OffchainLookup(
address(this),
multicallData.gateways,
abi.encodeWithSelector(BatchGateway.query.selector, callDatas),
multicallData.callbackFunction,
abi.encode(
multicallData.resolver,
multicallData.gateways,
multicallData.metaData,
extraDatas
)
);
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;
library BytesUtils {
/*
* @dev Returns the keccak-256 hash of a byte range.
* @param self The byte string to hash.
* @param offset The position to start hashing at.
* @param len The number of bytes to hash.
* @return The hash of the byte range.
*/
function keccak(
bytes memory self,
uint256 offset,
uint256 len
) internal pure returns (bytes32 ret) {
require(offset + len <= self.length);
assembly {
ret := keccak256(add(add(self, 32), offset), len)
}
}
/**
* @dev Returns the ENS namehash of a DNS-encoded name.
* @param self The DNS-encoded name to hash.
* @param offset The offset at which to start hashing.
* @return The namehash of the name.
*/
function namehash(
bytes memory self,
uint256 offset
) internal pure returns (bytes32) {
(bytes32 labelhash, uint256 newOffset) = readLabel(self, offset);
if (labelhash == bytes32(0)) {
require(offset == self.length - 1, "namehash: Junk at end of name");
return bytes32(0);
}
return
keccak256(abi.encodePacked(namehash(self, newOffset), labelhash));
}
/**
* @dev Returns the keccak-256 hash of a DNS-encoded label, and the offset to the start of the next label.
* @param self The byte string to read a label from.
* @param idx The index to read a label at.
* @return labelhash The hash of the label at the specified index, or 0 if it is the last label.
* @return newIdx The index of the start of the next label.
*/
function readLabel(
bytes memory self,
uint256 idx
) internal pure returns (bytes32 labelhash, uint256 newIdx) {
require(idx < self.length, "readLabel: Index out of bounds");
uint256 len = uint256(uint8(self[idx]));
if (len > 0) {
labelhash = keccak(self, idx + 1, len);
} else {
labelhash = bytes32(0);
}
newIdx = idx + len + 1;
}
}