// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)pragmasolidity ^0.8.1;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @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.
* ====
*/functionisContract(address account) internalviewreturns (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].
*/functionsendValue(addresspayable 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._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
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._
*/functionfunctionCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value
) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
(bool success, bytesmemory 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._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
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._
*/functionfunctionStaticCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
(bool success, bytesmemory 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._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
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._
*/functionfunctionDelegateCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
(bool success, bytesmemory 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._
*/functionverifyCallResultFromTarget(address target,
bool success,
bytesmemory returndata,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
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 contractrequire(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._
*/functionverifyCallResult(bool success,
bytesmemory returndata,
stringmemory errorMessage
) internalpurereturns (bytesmemory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function_revert(bytesmemory returndata, stringmemory errorMessage) privatepure{
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assembly/// @solidity memory-safe-assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Contract Source Code
File 2 of 23: BytesUtils.sol
//SPDX-License-Identifier: MITpragmasolidity ~0.8.17;libraryBytesUtils{
/*
* @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.
*/functionkeccak(bytesmemoryself,
uint256 offset,
uint256 len
) internalpurereturns (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.
*/functionnamehash(bytesmemoryself,
uint256 offset
) internalpurereturns (bytes32) {
(bytes32 labelhash, uint256 newOffset) = readLabel(self, offset);
if (labelhash ==bytes32(0)) {
require(offset ==self.length-1, "namehash: Junk at end of name");
returnbytes32(0);
}
returnkeccak256(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.
*/functionreadLabel(bytesmemoryself,
uint256 idx
) internalpurereturns (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;
}
}
Contract Source Code
File 3 of 23: Context.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^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.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 4 of 23: Controllable.sol
//SPDX-License-Identifier: MITpragmasolidity ~0.8.17;import"@openzeppelin/contracts/access/Ownable.sol";
contractControllableisOwnable{
mapping(address=>bool) public controllers;
eventControllerChanged(addressindexed controller, bool active);
functionsetController(address controller, bool active) publiconlyOwner{
controllers[controller] = active;
emit ControllerChanged(controller, active);
}
modifieronlyController() {
require(
controllers[msg.sender],
"Controllable: Caller is not a controller"
);
_;
}
}
Contract Source Code
File 5 of 23: ENS.sol
pragmasolidity >=0.8.4;interfaceENS{
// Logged when the owner of a node assigns a new owner to a subnode.eventNewOwner(bytes32indexed node, bytes32indexed label, address owner);
// Logged when the owner of a node transfers ownership to a new account.eventTransfer(bytes32indexed node, address owner);
// Logged when the resolver for a node changes.eventNewResolver(bytes32indexed node, address resolver);
// Logged when the TTL of a node changeseventNewTTL(bytes32indexed node, uint64 ttl);
// Logged when an operator is added or removed.eventApprovalForAll(addressindexed owner,
addressindexed operator,
bool approved
);
functionsetRecord(bytes32 node,
address owner,
address resolver,
uint64 ttl
) external;
functionsetSubnodeRecord(bytes32 node,
bytes32 label,
address owner,
address resolver,
uint64 ttl
) external;
functionsetSubnodeOwner(bytes32 node,
bytes32 label,
address owner
) externalreturns (bytes32);
functionsetResolver(bytes32 node, address resolver) external;
functionsetOwner(bytes32 node, address owner) external;
functionsetTTL(bytes32 node, uint64 ttl) external;
functionsetApprovalForAll(address operator, bool approved) external;
functionowner(bytes32 node) externalviewreturns (address);
functionresolver(bytes32 node) externalviewreturns (address);
functionttl(bytes32 node) externalviewreturns (uint64);
functionrecordExists(bytes32 node) externalviewreturns (bool);
functionisApprovedForAll(address owner,
address operator
) externalviewreturns (bool);
}
Contract Source Code
File 6 of 23: ERC1155Fuse.sol
//SPDX-License-Identifier: MITpragmasolidity ~0.8.17;import"@openzeppelin/contracts/utils/introspection/ERC165.sol";
import"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import"@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import"@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
import"@openzeppelin/contracts/utils/Address.sol";
/* This contract is a variation on ERC1155 with the additions of _setData, getData and _beforeTransfer and ownerOf. _setData and getData allows the use of the other 96 bits next to the address of the owner for extra data. We use this to store 'fuses' that control permissions that can be burnt. 32 bits are used for the fuses themselves and 64 bits are used for the expiry of the name. When a name has expired, its fuses will be be set back to 0 */abstractcontractERC1155FuseisERC165, IERC1155, IERC1155MetadataURI{
usingAddressforaddress;
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner,
addressindexed approved,
uint256indexed tokenId
);
mapping(uint256=>uint256) public _tokens;
// Mapping from owner to operator approvalsmapping(address=>mapping(address=>bool)) private _operatorApprovals;
// Mapping from token ID to approved addressmapping(uint256=>address) internal _tokenApprovals;
/**************************************************************************
* ERC721 methods
*************************************************************************/functionownerOf(uint256 id) publicviewvirtualreturns (address) {
(address owner, , ) = getData(id);
return owner;
}
/**
* @dev See {IERC721-approve}.
*/functionapprove(address to, uint256 tokenId) publicvirtual{
address owner = ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
msg.sender== owner || isApprovedForAll(owner, msg.sender),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/functiongetApproved(uint256 tokenId
) publicviewvirtualreturns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId
) publicviewvirtualoverride(ERC165, IERC165) returns (bool) {
return
interfaceId ==type(IERC1155).interfaceId||
interfaceId ==type(IERC1155MetadataURI).interfaceId||super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/functionbalanceOf(address account,
uint256 id
) publicviewvirtualoverridereturns (uint256) {
require(
account !=address(0),
"ERC1155: balance query for the zero address"
);
address owner = ownerOf(id);
if (owner == account) {
return1;
}
return0;
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/functionbalanceOfBatch(address[] memory accounts,
uint256[] memory ids
) publicviewvirtualoverridereturns (uint256[] memory) {
require(
accounts.length== ids.length,
"ERC1155: accounts and ids length mismatch"
);
uint256[] memory batchBalances =newuint256[](accounts.length);
for (uint256 i =0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/functionsetApprovalForAll(address operator,
bool approved
) publicvirtualoverride{
require(
msg.sender!= operator,
"ERC1155: setting approval status for self"
);
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/functionisApprovedForAll(address account,
address operator
) publicviewvirtualoverridereturns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev Returns the Name's owner address and fuses
*/functiongetData(uint256 tokenId
) publicviewvirtualreturns (address owner, uint32 fuses, uint64 expiry) {
uint256 t = _tokens[tokenId];
owner =address(uint160(t));
expiry =uint64(t >>192);
fuses =uint32(t >>160);
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 id,
uint256 amount,
bytesmemory data
) publicvirtualoverride{
require(to !=address(0), "ERC1155: transfer to the zero address");
require(
from==msg.sender|| isApprovedForAll(from, msg.sender),
"ERC1155: caller is not owner nor approved"
);
_transfer(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/functionsafeBatchTransferFrom(addressfrom,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytesmemory data
) publicvirtualoverride{
require(
ids.length== amounts.length,
"ERC1155: ids and amounts length mismatch"
);
require(to !=address(0), "ERC1155: transfer to the zero address");
require(
from==msg.sender|| isApprovedForAll(from, msg.sender),
"ERC1155: transfer caller is not owner nor approved"
);
for (uint256 i =0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
(address oldOwner, uint32 fuses, uint64 expiry) = getData(id);
_beforeTransfer(id, fuses, expiry);
require(
amount ==1&& oldOwner ==from,
"ERC1155: insufficient balance for transfer"
);
_setData(id, to, fuses, expiry);
}
emit TransferBatch(msg.sender, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(
msg.sender,
from,
to,
ids,
amounts,
data
);
}
/**************************************************************************
* Internal/private methods
*************************************************************************//**
* @dev Sets the Name's owner address and fuses
*/function_setData(uint256 tokenId,
address owner,
uint32 fuses,
uint64 expiry
) internalvirtual{
_tokens[tokenId] =uint256(uint160(owner)) |
(uint256(fuses) <<160) |
(uint256(expiry) <<192);
}
function_beforeTransfer(uint256 id,
uint32 fuses,
uint64 expiry
) internalvirtual;
function_clearOwnerAndFuses(address owner,
uint32 fuses,
uint64 expiry
) internalvirtualreturns (address, uint32);
function_mint(bytes32 node,
address owner,
uint32 fuses,
uint64 expiry
) internalvirtual{
uint256 tokenId =uint256(node);
(address oldOwner, uint32 oldFuses, uint64 oldExpiry) = getData(
uint256(node)
);
uint32 parentControlledFuses = (uint32(type(uint16).max) <<16) &
oldFuses;
if (oldExpiry > expiry) {
expiry = oldExpiry;
}
if (oldExpiry >=block.timestamp) {
fuses = fuses | parentControlledFuses;
}
require(oldOwner ==address(0), "ERC1155: mint of existing token");
require(owner !=address(0), "ERC1155: mint to the zero address");
require(
owner !=address(this),
"ERC1155: newOwner cannot be the NameWrapper contract"
);
_setData(tokenId, owner, fuses, expiry);
emit TransferSingle(msg.sender, address(0x0), owner, tokenId, 1);
_doSafeTransferAcceptanceCheck(
msg.sender,
address(0),
owner,
tokenId,
1,
""
);
}
function_burn(uint256 tokenId) internalvirtual{
(address oldOwner, uint32 fuses, uint64 expiry) = ERC1155Fuse.getData(
tokenId
);
(, fuses) = _clearOwnerAndFuses(oldOwner, fuses, expiry);
// Clear approvalsdelete _tokenApprovals[tokenId];
// Fuses and expiry are kept on burn
_setData(tokenId, address(0x0), fuses, expiry);
emit TransferSingle(msg.sender, oldOwner, address(0x0), tokenId, 1);
}
function_transfer(addressfrom,
address to,
uint256 id,
uint256 amount,
bytesmemory data
) internal{
(address oldOwner, uint32 fuses, uint64 expiry) = getData(id);
_beforeTransfer(id, fuses, expiry);
require(
amount ==1&& oldOwner ==from,
"ERC1155: insufficient balance for transfer"
);
if (oldOwner == to) {
return;
}
_setData(id, to, fuses, expiry);
emit TransferSingle(msg.sender, from, to, id, amount);
_doSafeTransferAcceptanceCheck(msg.sender, from, to, id, amount, data);
}
function_doSafeTransferAcceptanceCheck(address operator,
addressfrom,
address to,
uint256 id,
uint256 amount,
bytesmemory data
) private{
if (to.isContract()) {
try
IERC1155Receiver(to).onERC1155Received(
operator,
from,
id,
amount,
data
)
returns (bytes4 response) {
if (
response != IERC1155Receiver(to).onERC1155Received.selector
) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catchError(stringmemory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function_doSafeBatchTransferAcceptanceCheck(address operator,
addressfrom,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytesmemory data
) private{
if (to.isContract()) {
try
IERC1155Receiver(to).onERC1155BatchReceived(
operator,
from,
ids,
amounts,
data
)
returns (bytes4 response) {
if (
response !=
IERC1155Receiver(to).onERC1155BatchReceived.selector
) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catchError(stringmemory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
/* ERC721 internal functions *//**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/function_approve(address to, uint256 tokenId) internalvirtual{
_tokenApprovals[tokenId] = to;
emit Approval(ownerOf(tokenId), to, tokenId);
}
}
Contract Source Code
File 7 of 23: ERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)pragmasolidity ^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.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
Contract Source Code
File 8 of 23: ERC20Recoverable.sol
//SPDX-License-Identifier: MITpragmasolidity >=0.8.17 <0.9.0;import"@openzeppelin/contracts/access/Ownable.sol";
import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
@notice Contract is used to recover ERC20 tokens sent to the contract by mistake.
*/contractERC20RecoverableisOwnable{
/**
@notice Recover ERC20 tokens sent to the contract by mistake.
@dev The contract is Ownable and only the owner can call the recover function.
@param _to The address to send the tokens to.
@param _token The address of the ERC20 token to recover
@param _amount The amount of tokens to recover.
*/functionrecoverFunds(address _token,
address _to,
uint256 _amount
) externalonlyOwner{
IERC20(_token).transfer(_to, _amount);
}
}
Contract Source Code
File 9 of 23: IBaseRegistrar.sol
import"../registry/ENS.sol";
import"./IBaseRegistrar.sol";
import"@openzeppelin/contracts/token/ERC721/IERC721.sol";
interfaceIBaseRegistrarisIERC721{
eventControllerAdded(addressindexed controller);
eventControllerRemoved(addressindexed controller);
eventNameMigrated(uint256indexed id,
addressindexed owner,
uint256 expires
);
eventNameRegistered(uint256indexed id,
addressindexed owner,
uint256 expires
);
eventNameRenewed(uint256indexed id, uint256 expires);
// Authorises a controller, who can register and renew domains.functionaddController(address controller) external;
// Revoke controller permission for an address.functionremoveController(address controller) external;
// Set the resolver for the TLD this registrar manages.functionsetResolver(address resolver) external;
// Returns the expiration timestamp of the specified label hash.functionnameExpires(uint256 id) externalviewreturns (uint256);
// Returns true iff the specified name is available for registration.functionavailable(uint256 id) externalviewreturns (bool);
/**
* @dev Register a name.
*/functionregister(uint256 id,
address owner,
uint256 duration
) externalreturns (uint256);
functionrenew(uint256 id, uint256 duration) externalreturns (uint256);
/**
* @dev Reclaim ownership of a name in ENS, if you own it in the registrar.
*/functionreclaim(uint256 id, address owner) external;
}
Contract Source Code
File 10 of 23: IERC1155.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/interfaceIERC1155isIERC165{
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/eventTransferSingle(addressindexed operator, addressindexedfrom, addressindexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/eventTransferBatch(addressindexed operator,
addressindexedfrom,
addressindexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/eventApprovalForAll(addressindexed account, addressindexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/eventURI(string value, uint256indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/functionbalanceOf(address account, uint256 id) externalviewreturns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/functionbalanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
externalviewreturns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/functionsetApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/functionisApprovedForAll(address account, address operator) externalviewreturns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 id,
uint256 amount,
bytescalldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/functionsafeBatchTransferFrom(addressfrom,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytescalldata data
) external;
}
Contract Source Code
File 11 of 23: IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)pragmasolidity ^0.8.0;import"../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/interfaceIERC1155MetadataURIisIERC1155{
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/functionuri(uint256 id) externalviewreturns (stringmemory);
}
Contract Source Code
File 12 of 23: IERC1155Receiver.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/interfaceIERC1155ReceiverisIERC165{
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/functiononERC1155Received(address operator,
addressfrom,
uint256 id,
uint256 value,
bytescalldata data
) externalreturns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/functiononERC1155BatchReceived(address operator,
addressfrom,
uint256[] calldata ids,
uint256[] calldata values,
bytescalldata data
) externalreturns (bytes4);
}
Contract Source Code
File 13 of 23: IERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)pragmasolidity ^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}.
*/interfaceIERC165{
/**
* @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.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 14 of 23: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) externalreturns (bool);
}
Contract Source Code
File 15 of 23: IERC721.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/interfaceIERC721isIERC165{
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner, addressindexed approved, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/eventApprovalForAll(addressindexed owner, addressindexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/functionbalanceOf(address owner) externalviewreturns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functionownerOf(uint256 tokenId) externalviewreturns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId,
bytescalldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/functionapprove(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/functionsetApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functiongetApproved(uint256 tokenId) externalviewreturns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/functionisApprovedForAll(address owner, address operator) externalviewreturns (bool);
}
Contract Source Code
File 16 of 23: IERC721Receiver.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)pragmasolidity ^0.8.0;/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/interfaceIERC721Receiver{
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/functiononERC721Received(address operator,
addressfrom,
uint256 tokenId,
bytescalldata data
) externalreturns (bytes4);
}
//SPDX-License-Identifier: MITpragmasolidity ~0.8.17;import {ERC1155Fuse, IERC165, IERC1155MetadataURI} from"./ERC1155Fuse.sol";
import {Controllable} from"./Controllable.sol";
import {INameWrapper, CANNOT_UNWRAP, CANNOT_BURN_FUSES, CANNOT_TRANSFER, CANNOT_SET_RESOLVER, CANNOT_SET_TTL, CANNOT_CREATE_SUBDOMAIN, CANNOT_APPROVE, PARENT_CANNOT_CONTROL, CAN_DO_EVERYTHING, IS_DOT_ETH, CAN_EXTEND_EXPIRY, PARENT_CONTROLLED_FUSES, USER_SETTABLE_FUSES} from"./INameWrapper.sol";
import {INameWrapperUpgrade} from"./INameWrapperUpgrade.sol";
import {IMetadataService} from"./IMetadataService.sol";
import {ENS} from"../registry/ENS.sol";
import {IReverseRegistrar} from"../reverseRegistrar/IReverseRegistrar.sol";
import {ReverseClaimer} from"../reverseRegistrar/ReverseClaimer.sol";
import {IBaseRegistrar} from"../ethregistrar/IBaseRegistrar.sol";
import {IERC721Receiver} from"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import"@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {Ownable} from"@openzeppelin/contracts/access/Ownable.sol";
import {BytesUtils} from"./BytesUtils.sol";
import {ERC20Recoverable} from"../utils/ERC20Recoverable.sol";
errorUnauthorised(bytes32 node, address addr);
errorIncompatibleParent();
errorIncorrectTokenType();
errorLabelMismatch(bytes32 labelHash, bytes32 expectedLabelhash);
errorLabelTooShort();
errorLabelTooLong(string label);
errorIncorrectTargetOwner(address owner);
errorCannotUpgrade();
errorOperationProhibited(bytes32 node);
errorNameIsNotWrapped();
errorNameIsStillExpired();
contractNameWrapperisOwnable,
ERC1155Fuse,
INameWrapper,
Controllable,
IERC721Receiver,
ERC20Recoverable,
ReverseClaimer{
usingBytesUtilsforbytes;
ENS publicimmutable ens;
IBaseRegistrar publicimmutable registrar;
IMetadataService public metadataService;
mapping(bytes32=>bytes) public names;
stringpublicconstant name ="NameWrapper";
uint64privateconstant GRACE_PERIOD =90days;
bytes32privateconstant ETH_NODE =0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bytes32privateconstant ETH_LABELHASH =0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0;
bytes32privateconstant ROOT_NODE =0x0000000000000000000000000000000000000000000000000000000000000000;
INameWrapperUpgrade public upgradeContract;
uint64privateconstant MAX_EXPIRY =type(uint64).max;
constructor(
ENS _ens,
IBaseRegistrar _registrar,
IMetadataService _metadataService
) ReverseClaimer(_ens, msg.sender) {
ens = _ens;
registrar = _registrar;
metadataService = _metadataService;
/* Burn PARENT_CANNOT_CONTROL and CANNOT_UNWRAP fuses for ROOT_NODE and ETH_NODE and set expiry to max */
_setData(
uint256(ETH_NODE),
address(0),
uint32(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP),
MAX_EXPIRY
);
_setData(
uint256(ROOT_NODE),
address(0),
uint32(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP),
MAX_EXPIRY
);
names[ROOT_NODE] ="\x00";
names[ETH_NODE] ="\x03eth\x00";
}
functionsupportsInterface(bytes4 interfaceId
) publicviewvirtualoverride(ERC1155Fuse, INameWrapper) returns (bool) {
return
interfaceId ==type(INameWrapper).interfaceId||
interfaceId ==type(IERC721Receiver).interfaceId||super.supportsInterface(interfaceId);
}
/* ERC1155 Fuse *//**
* @notice Gets the owner of a name
* @param id Label as a string of the .eth domain to wrap
* @return owner The owner of the name
*/functionownerOf(uint256 id
) publicviewoverride(ERC1155Fuse, INameWrapper) returns (address owner) {
returnsuper.ownerOf(id);
}
/**
* @notice Gets the owner of a name
* @param id Namehash of the name
* @return operator Approved operator of a name
*/functiongetApproved(uint256 id
)
publicviewoverride(ERC1155Fuse, INameWrapper)
returns (address operator)
{
address owner = ownerOf(id);
if (owner ==address(0)) {
returnaddress(0);
}
returnsuper.getApproved(id);
}
/**
* @notice Approves an address for a name
* @param to address to approve
* @param tokenId name to approve
*/functionapprove(address to,
uint256 tokenId
) publicoverride(ERC1155Fuse, INameWrapper) {
(, uint32 fuses, ) = getData(tokenId);
if (fuses & CANNOT_APPROVE == CANNOT_APPROVE) {
revert OperationProhibited(bytes32(tokenId));
}
super.approve(to, tokenId);
}
/**
* @notice Gets the data for a name
* @param id Namehash of the name
* @return owner Owner of the name
* @return fuses Fuses of the name
* @return expiry Expiry of the name
*/functiongetData(uint256 id
)
publicviewoverride(ERC1155Fuse, INameWrapper)
returns (address owner, uint32 fuses, uint64 expiry)
{
(owner, fuses, expiry) =super.getData(id);
(owner, fuses) = _clearOwnerAndFuses(owner, fuses, expiry);
}
/* Metadata service *//**
* @notice Set the metadata service. Only the owner can do this
* @param _metadataService The new metadata service
*/functionsetMetadataService(
IMetadataService _metadataService
) publiconlyOwner{
metadataService = _metadataService;
}
/**
* @notice Get the metadata uri
* @param tokenId The id of the token
* @return string uri of the metadata service
*/functionuri(uint256 tokenId
)
publicviewoverride(INameWrapper, IERC1155MetadataURI)
returns (stringmemory)
{
return metadataService.uri(tokenId);
}
/**
* @notice Set the address of the upgradeContract of the contract. only admin can do this
* @dev The default value of upgradeContract is the 0 address. Use the 0 address at any time
* to make the contract not upgradable.
* @param _upgradeAddress address of an upgraded contract
*/functionsetUpgradeContract(
INameWrapperUpgrade _upgradeAddress
) publiconlyOwner{
if (address(upgradeContract) !=address(0)) {
registrar.setApprovalForAll(address(upgradeContract), false);
ens.setApprovalForAll(address(upgradeContract), false);
}
upgradeContract = _upgradeAddress;
if (address(upgradeContract) !=address(0)) {
registrar.setApprovalForAll(address(upgradeContract), true);
ens.setApprovalForAll(address(upgradeContract), true);
}
}
/**
* @notice Checks if msg.sender is the owner or operator of the owner of a name
* @param node namehash of the name to check
*/modifieronlyTokenOwner(bytes32 node) {
if (!canModifyName(node, msg.sender)) {
revert Unauthorised(node, msg.sender);
}
_;
}
/**
* @notice Checks if owner or operator of the owner
* @param node namehash of the name to check
* @param addr which address to check permissions for
* @return whether or not is owner or operator
*/functioncanModifyName(bytes32 node,
address addr
) publicviewreturns (bool) {
(address owner, uint32 fuses, uint64 expiry) = getData(uint256(node));
return
(owner == addr || isApprovedForAll(owner, addr)) &&!_isETH2LDInGracePeriod(fuses, expiry);
}
/**
* @notice Checks if owner/operator or approved by owner
* @param node namehash of the name to check
* @param addr which address to check permissions for
* @return whether or not is owner/operator or approved
*/functioncanExtendSubnames(bytes32 node,
address addr
) publicviewreturns (bool) {
(address owner, uint32 fuses, uint64 expiry) = getData(uint256(node));
return
(owner == addr ||
isApprovedForAll(owner, addr) ||
getApproved(uint256(node)) == addr) &&!_isETH2LDInGracePeriod(fuses, expiry);
}
/**
* @notice Wraps a .eth domain, creating a new token and sending the original ERC721 token to this contract
* @dev Can be called by the owner of the name on the .eth registrar or an authorised caller on the registrar
* @param label Label as a string of the .eth domain to wrap
* @param wrappedOwner Owner of the name in this contract
* @param ownerControlledFuses Initial owner-controlled fuses to set
* @param resolver Resolver contract address
*/functionwrapETH2LD(stringcalldata label,
address wrappedOwner,
uint16 ownerControlledFuses,
address resolver
) publicreturns (uint64 expiry) {
uint256 tokenId =uint256(keccak256(bytes(label)));
address registrant = registrar.ownerOf(tokenId);
if (
registrant !=msg.sender&&!registrar.isApprovedForAll(registrant, msg.sender)
) {
revert Unauthorised(
_makeNode(ETH_NODE, bytes32(tokenId)),
msg.sender
);
}
// transfer the token from the user to this contract
registrar.transferFrom(registrant, address(this), tokenId);
// transfer the ens record back to the new owner (this contract)
registrar.reclaim(tokenId, address(this));
expiry =uint64(registrar.nameExpires(tokenId)) + GRACE_PERIOD;
_wrapETH2LD(
label,
wrappedOwner,
ownerControlledFuses,
expiry,
resolver
);
}
/**
* @dev Registers a new .eth second-level domain and wraps it.
* Only callable by authorised controllers.
* @param label The label to register (Eg, 'foo' for 'foo.eth').
* @param wrappedOwner The owner of the wrapped name.
* @param duration The duration, in seconds, to register the name for.
* @param resolver The resolver address to set on the ENS registry (optional).
* @param ownerControlledFuses Initial owner-controlled fuses to set
* @return registrarExpiry The expiry date of the new name on the .eth registrar, in seconds since the Unix epoch.
*/functionregisterAndWrapETH2LD(stringcalldata label,
address wrappedOwner,
uint256 duration,
address resolver,
uint16 ownerControlledFuses
) externalonlyControllerreturns (uint256 registrarExpiry) {
uint256 tokenId =uint256(keccak256(bytes(label)));
registrarExpiry = registrar.register(tokenId, address(this), duration);
_wrapETH2LD(
label,
wrappedOwner,
ownerControlledFuses,
uint64(registrarExpiry) + GRACE_PERIOD,
resolver
);
}
/**
* @notice Renews a .eth second-level domain.
* @dev Only callable by authorised controllers.
* @param tokenId The hash of the label to register (eg, `keccak256('foo')`, for 'foo.eth').
* @param duration The number of seconds to renew the name for.
* @return expires The expiry date of the name on the .eth registrar, in seconds since the Unix epoch.
*/functionrenew(uint256 tokenId,
uint256 duration
) externalonlyControllerreturns (uint256 expires) {
bytes32 node = _makeNode(ETH_NODE, bytes32(tokenId));
uint256 registrarExpiry = registrar.renew(tokenId, duration);
// Do not set anything in wrapper if name is not wrappedtry registrar.ownerOf(tokenId) returns (address registrarOwner) {
if (
registrarOwner !=address(this) ||
ens.owner(node) !=address(this)
) {
return registrarExpiry;
}
} catch {
return registrarExpiry;
}
// Set expiry in Wrapperuint64 expiry =uint64(registrarExpiry) + GRACE_PERIOD;
// Use super to allow names expired on the wrapper, but not expired on the registrar to renew()
(address owner, uint32 fuses, ) =super.getData(uint256(node));
_setData(node, owner, fuses, expiry);
return registrarExpiry;
}
/**
* @notice Wraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
* @dev Can be called by the owner in the registry or an authorised caller in the registry
* @param name The name to wrap, in DNS format
* @param wrappedOwner Owner of the name in this contract
* @param resolver Resolver contract
*/functionwrap(bytescalldata name,
address wrappedOwner,
address resolver
) public{
(bytes32 labelhash, uint256 offset) = name.readLabel(0);
bytes32 parentNode = name.namehash(offset);
bytes32 node = _makeNode(parentNode, labelhash);
names[node] = name;
if (parentNode == ETH_NODE) {
revert IncompatibleParent();
}
address owner = ens.owner(node);
if (owner !=msg.sender&&!ens.isApprovedForAll(owner, msg.sender)) {
revert Unauthorised(node, msg.sender);
}
if (resolver !=address(0)) {
ens.setResolver(node, resolver);
}
ens.setOwner(node, address(this));
_wrap(node, name, wrappedOwner, 0, 0);
}
/**
* @notice Unwraps a .eth domain. e.g. vitalik.eth
* @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
* @param labelhash Labelhash of the .eth domain
* @param registrant Sets the owner in the .eth registrar to this address
* @param controller Sets the owner in the registry to this address
*/functionunwrapETH2LD(bytes32 labelhash,
address registrant,
address controller
) publiconlyTokenOwner(_makeNode(ETH_NODE, labelhash)) {
if (registrant ==address(this)) {
revert IncorrectTargetOwner(registrant);
}
_unwrap(_makeNode(ETH_NODE, labelhash), controller);
registrar.safeTransferFrom(
address(this),
registrant,
uint256(labelhash)
);
}
/**
* @notice Unwraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
* @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
* @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
* @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
* @param controller Sets the owner in the registry to this address
*/functionunwrap(bytes32 parentNode,
bytes32 labelhash,
address controller
) publiconlyTokenOwner(_makeNode(parentNode, labelhash)) {
if (parentNode == ETH_NODE) {
revert IncompatibleParent();
}
if (controller ==address(0x0) || controller ==address(this)) {
revert IncorrectTargetOwner(controller);
}
_unwrap(_makeNode(parentNode, labelhash), controller);
}
/**
* @notice Sets fuses of a name
* @param node Namehash of the name
* @param ownerControlledFuses Owner-controlled fuses to burn
* @return Old fuses
*/functionsetFuses(bytes32 node,
uint16 ownerControlledFuses
)
publiconlyTokenOwner(node)
operationAllowed(node, CANNOT_BURN_FUSES)
returns (uint32)
{
// owner protected by onlyTokenOwner
(address owner, uint32 oldFuses, uint64 expiry) = getData(
uint256(node)
);
_setFuses(node, owner, ownerControlledFuses | oldFuses, expiry, expiry);
return oldFuses;
}
/**
* @notice Extends expiry for a name
* @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
* @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
* @param expiry When the name will expire in seconds since the Unix epoch
* @return New expiry
*/functionextendExpiry(bytes32 parentNode,
bytes32 labelhash,
uint64 expiry
) publicreturns (uint64) {
bytes32 node = _makeNode(parentNode, labelhash);
if (!_isWrapped(node)) {
revert NameIsNotWrapped();
}
// this flag is used later, when checking fusesbool canExtendSubname = canExtendSubnames(parentNode, msg.sender);
// only allow the owner of the name or owner of the parent nameif (!canExtendSubname &&!canModifyName(node, msg.sender)) {
revert Unauthorised(node, msg.sender);
}
(address owner, uint32 fuses, uint64 oldExpiry) = getData(
uint256(node)
);
// Either CAN_EXTEND_EXPIRY must be set, or the caller must have permission to modify the parent nameif (!canExtendSubname && fuses & CAN_EXTEND_EXPIRY ==0) {
revert OperationProhibited(node);
}
// Max expiry is set to the expiry of the parent
(, , uint64 maxExpiry) = getData(uint256(parentNode));
expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
_setData(node, owner, fuses, expiry);
emit ExpiryExtended(node, expiry);
return expiry;
}
/**
* @notice Upgrades a domain of any kind. Could be a .eth name vitalik.eth, a DNSSEC name vitalik.xyz, or a subdomain
* @dev Can be called by the owner or an authorised caller
* @param name The name to upgrade, in DNS format
* @param extraData Extra data to pass to the upgrade contract
*/functionupgrade(bytescalldata name, bytescalldata extraData) public{
bytes32 node = name.namehash(0);
if (address(upgradeContract) ==address(0)) {
revert CannotUpgrade();
}
if (!canModifyName(node, msg.sender)) {
revert Unauthorised(node, msg.sender);
}
(address currentOwner, uint32 fuses, uint64 expiry) = getData(
uint256(node)
);
address approved = getApproved(uint256(node));
_burn(uint256(node));
upgradeContract.wrapFromUpgrade(
name,
currentOwner,
fuses,
expiry,
approved,
extraData
);
}
/**
/* @notice Sets fuses of a name that you own the parent of
* @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
* @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
* @param fuses Fuses to burn
* @param expiry When the name will expire in seconds since the Unix epoch
*/functionsetChildFuses(bytes32 parentNode,
bytes32 labelhash,
uint32 fuses,
uint64 expiry
) public{
bytes32 node = _makeNode(parentNode, labelhash);
_checkFusesAreSettable(node, fuses);
(address owner, uint32 oldFuses, uint64 oldExpiry) = getData(
uint256(node)
);
if (owner ==address(0) || ens.owner(node) !=address(this)) {
revert NameIsNotWrapped();
}
// max expiry is set to the expiry of the parent
(, uint32 parentFuses, uint64 maxExpiry) = getData(uint256(parentNode));
if (parentNode == ROOT_NODE) {
if (!canModifyName(node, msg.sender)) {
revert Unauthorised(node, msg.sender);
}
} else {
if (!canModifyName(parentNode, msg.sender)) {
revert Unauthorised(parentNode, msg.sender);
}
}
_checkParentFuses(node, fuses, parentFuses);
expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
// if PARENT_CANNOT_CONTROL has been burned and fuses have changedif (
oldFuses & PARENT_CANNOT_CONTROL !=0&&
oldFuses | fuses != oldFuses
) {
revert OperationProhibited(node);
}
fuses |= oldFuses;
_setFuses(node, owner, fuses, oldExpiry, expiry);
}
/**
* @notice Sets the subdomain owner in the registry and then wraps the subdomain
* @param parentNode Parent namehash of the subdomain
* @param label Label of the subdomain as a string
* @param owner New owner in the wrapper
* @param fuses Initial fuses for the wrapped subdomain
* @param expiry When the name will expire in seconds since the Unix epoch
* @return node Namehash of the subdomain
*/functionsetSubnodeOwner(bytes32 parentNode,
stringcalldata label,
address owner,
uint32 fuses,
uint64 expiry
) publiconlyTokenOwner(parentNode) returns (bytes32 node) {
bytes32 labelhash =keccak256(bytes(label));
node = _makeNode(parentNode, labelhash);
_checkCanCallSetSubnodeOwner(parentNode, node);
_checkFusesAreSettable(node, fuses);
bytesmemory name = _saveLabel(parentNode, node, label);
expiry = _checkParentFusesAndExpiry(parentNode, node, fuses, expiry);
if (!_isWrapped(node)) {
ens.setSubnodeOwner(parentNode, labelhash, address(this));
_wrap(node, name, owner, fuses, expiry);
} else {
_updateName(parentNode, node, label, owner, fuses, expiry);
}
}
/**
* @notice Sets the subdomain owner in the registry with records and then wraps the subdomain
* @param parentNode parent namehash of the subdomain
* @param label label of the subdomain as a string
* @param owner new owner in the wrapper
* @param resolver resolver contract in the registry
* @param ttl ttl in the registry
* @param fuses initial fuses for the wrapped subdomain
* @param expiry When the name will expire in seconds since the Unix epoch
* @return node Namehash of the subdomain
*/functionsetSubnodeRecord(bytes32 parentNode,
stringmemory label,
address owner,
address resolver,
uint64 ttl,
uint32 fuses,
uint64 expiry
) publiconlyTokenOwner(parentNode) returns (bytes32 node) {
bytes32 labelhash =keccak256(bytes(label));
node = _makeNode(parentNode, labelhash);
_checkCanCallSetSubnodeOwner(parentNode, node);
_checkFusesAreSettable(node, fuses);
_saveLabel(parentNode, node, label);
expiry = _checkParentFusesAndExpiry(parentNode, node, fuses, expiry);
if (!_isWrapped(node)) {
ens.setSubnodeRecord(
parentNode,
labelhash,
address(this),
resolver,
ttl
);
_storeNameAndWrap(parentNode, node, label, owner, fuses, expiry);
} else {
ens.setSubnodeRecord(
parentNode,
labelhash,
address(this),
resolver,
ttl
);
_updateName(parentNode, node, label, owner, fuses, expiry);
}
}
/**
* @notice Sets records for the name in the ENS Registry
* @param node Namehash of the name to set a record for
* @param owner New owner in the registry
* @param resolver Resolver contract
* @param ttl Time to live in the registry
*/functionsetRecord(bytes32 node,
address owner,
address resolver,
uint64 ttl
)
publiconlyTokenOwner(node)
operationAllowed(
node,
CANNOT_TRANSFER | CANNOT_SET_RESOLVER | CANNOT_SET_TTL
)
{
ens.setRecord(node, address(this), resolver, ttl);
if (owner ==address(0)) {
(, uint32 fuses, ) = getData(uint256(node));
if (fuses & IS_DOT_ETH == IS_DOT_ETH) {
revert IncorrectTargetOwner(owner);
}
_unwrap(node, address(0));
} else {
address oldOwner = ownerOf(uint256(node));
_transfer(oldOwner, owner, uint256(node), 1, "");
}
}
/**
* @notice Sets resolver contract in the registry
* @param node namehash of the name
* @param resolver the resolver contract
*/functionsetResolver(bytes32 node,
address resolver
) publiconlyTokenOwner(node) operationAllowed(node, CANNOT_SET_RESOLVER) {
ens.setResolver(node, resolver);
}
/**
* @notice Sets TTL in the registry
* @param node Namehash of the name
* @param ttl TTL in the registry
*/functionsetTTL(bytes32 node,
uint64 ttl
) publiconlyTokenOwner(node) operationAllowed(node, CANNOT_SET_TTL) {
ens.setTTL(node, ttl);
}
/**
* @dev Allows an operation only if none of the specified fuses are burned.
* @param node The namehash of the name to check fuses on.
* @param fuseMask A bitmask of fuses that must not be burned.
*/modifieroperationAllowed(bytes32 node, uint32 fuseMask) {
(, uint32 fuses, ) = getData(uint256(node));
if (fuses & fuseMask !=0) {
revert OperationProhibited(node);
}
_;
}
/**
* @notice Check whether a name can call setSubnodeOwner/setSubnodeRecord
* @dev Checks both CANNOT_CREATE_SUBDOMAIN and PARENT_CANNOT_CONTROL and whether not they have been burnt
* and checks whether the owner of the subdomain is 0x0 for creating or already exists for
* replacing a subdomain. If either conditions are true, then it is possible to call
* setSubnodeOwner
* @param parentNode Namehash of the parent name to check
* @param subnode Namehash of the subname to check
*/function_checkCanCallSetSubnodeOwner(bytes32 parentNode,
bytes32 subnode
) internalview{
(
address subnodeOwner,
uint32 subnodeFuses,
uint64 subnodeExpiry
) = getData(uint256(subnode));
// check if the registry owner is 0 and expired// check if the wrapper owner is 0 and expired// If either, then check parent fuses for CANNOT_CREATE_SUBDOMAINbool expired = subnodeExpiry <block.timestamp;
if (
expired &&// protects a name that has been unwrapped with PCC and doesn't allow the parent to take control by recreating it if unexpired
(subnodeOwner ==address(0) ||// protects a name that has been burnt and doesn't allow the parent to take control by recreating it if unexpired
ens.owner(subnode) ==address(0))
) {
(, uint32 parentFuses, ) = getData(uint256(parentNode));
if (parentFuses & CANNOT_CREATE_SUBDOMAIN !=0) {
revert OperationProhibited(subnode);
}
} else {
if (subnodeFuses & PARENT_CANNOT_CONTROL !=0) {
revert OperationProhibited(subnode);
}
}
}
/**
* @notice Checks all Fuses in the mask are burned for the node
* @param node Namehash of the name
* @param fuseMask The fuses you want to check
* @return Boolean of whether or not all the selected fuses are burned
*/functionallFusesBurned(bytes32 node,
uint32 fuseMask
) publicviewreturns (bool) {
(, uint32 fuses, ) = getData(uint256(node));
return fuses & fuseMask == fuseMask;
}
/**
* @notice Checks if a name is wrapped
* @param node Namehash of the name
* @return Boolean of whether or not the name is wrapped
*/functionisWrapped(bytes32 node) publicviewreturns (bool) {
bytesmemory name = names[node];
if (name.length==0) {
returnfalse;
}
(bytes32 labelhash, uint256 offset) = name.readLabel(0);
bytes32 parentNode = name.namehash(offset);
return isWrapped(parentNode, labelhash);
}
/**
* @notice Checks if a name is wrapped in a more gas efficient way
* @param parentNode Namehash of the name
* @param labelhash Namehash of the name
* @return Boolean of whether or not the name is wrapped
*/functionisWrapped(bytes32 parentNode,
bytes32 labelhash
) publicviewreturns (bool) {
bytes32 node = _makeNode(parentNode, labelhash);
bool wrapped = _isWrapped(node);
if (parentNode != ETH_NODE) {
return wrapped;
}
try registrar.ownerOf(uint256(labelhash)) returns (address owner) {
return owner ==address(this);
} catch {
returnfalse;
}
}
functiononERC721Received(address to,
address,
uint256 tokenId,
bytescalldata data
) publicreturns (bytes4) {
//check if it's the eth registrar ERC721if (msg.sender!=address(registrar)) {
revert IncorrectTokenType();
}
(
stringmemory label,
address owner,
uint16 ownerControlledFuses,
address resolver
) =abi.decode(data, (string, address, uint16, address));
bytes32 labelhash =bytes32(tokenId);
bytes32 labelhashFromData =keccak256(bytes(label));
if (labelhashFromData != labelhash) {
revert LabelMismatch(labelhashFromData, labelhash);
}
// transfer the ens record back to the new owner (this contract)
registrar.reclaim(uint256(labelhash), address(this));
uint64 expiry =uint64(registrar.nameExpires(tokenId)) + GRACE_PERIOD;
_wrapETH2LD(label, owner, ownerControlledFuses, expiry, resolver);
return IERC721Receiver(to).onERC721Received.selector;
}
/***** Internal functions */function_beforeTransfer(uint256 id,
uint32 fuses,
uint64 expiry
) internaloverride{
// For this check, treat .eth 2LDs as expiring at the start of the grace period.if (fuses & IS_DOT_ETH == IS_DOT_ETH) {
expiry -= GRACE_PERIOD;
}
if (expiry <block.timestamp) {
// Transferable if the name was not emancipatedif (fuses & PARENT_CANNOT_CONTROL !=0) {
revert("ERC1155: insufficient balance for transfer");
}
} else {
// Transferable if CANNOT_TRANSFER is unburnedif (fuses & CANNOT_TRANSFER !=0) {
revert OperationProhibited(bytes32(id));
}
}
// delete token approval if CANNOT_APPROVE has not been burntif (fuses & CANNOT_APPROVE ==0) {
delete _tokenApprovals[id];
}
}
function_clearOwnerAndFuses(address owner,
uint32 fuses,
uint64 expiry
) internalviewoverridereturns (address, uint32) {
if (expiry <block.timestamp) {
if (fuses & PARENT_CANNOT_CONTROL == PARENT_CANNOT_CONTROL) {
owner =address(0);
}
fuses =0;
}
return (owner, fuses);
}
function_makeNode(bytes32 node,
bytes32 labelhash
) privatepurereturns (bytes32) {
returnkeccak256(abi.encodePacked(node, labelhash));
}
function_addLabel(stringmemory label,
bytesmemory name
) internalpurereturns (bytesmemory ret) {
if (bytes(label).length<1) {
revert LabelTooShort();
}
if (bytes(label).length>255) {
revert LabelTooLong(label);
}
returnabi.encodePacked(uint8(bytes(label).length), label, name);
}
function_mint(bytes32 node,
address owner,
uint32 fuses,
uint64 expiry
) internaloverride{
_canFusesBeBurned(node, fuses);
(address oldOwner, , ) =super.getData(uint256(node));
if (oldOwner !=address(0)) {
// burn and unwrap old token of old owner
_burn(uint256(node));
emit NameUnwrapped(node, address(0));
}
super._mint(node, owner, fuses, expiry);
}
function_wrap(bytes32 node,
bytesmemory name,
address wrappedOwner,
uint32 fuses,
uint64 expiry
) internal{
_mint(node, wrappedOwner, fuses, expiry);
emit NameWrapped(node, name, wrappedOwner, fuses, expiry);
}
function_storeNameAndWrap(bytes32 parentNode,
bytes32 node,
stringmemory label,
address owner,
uint32 fuses,
uint64 expiry
) internal{
bytesmemory name = _addLabel(label, names[parentNode]);
_wrap(node, name, owner, fuses, expiry);
}
function_saveLabel(bytes32 parentNode,
bytes32 node,
stringmemory label
) internalreturns (bytesmemory) {
bytesmemory name = _addLabel(label, names[parentNode]);
names[node] = name;
return name;
}
function_updateName(bytes32 parentNode,
bytes32 node,
stringmemory label,
address owner,
uint32 fuses,
uint64 expiry
) internal{
(address oldOwner, uint32 oldFuses, uint64 oldExpiry) = getData(
uint256(node)
);
bytesmemory name = _addLabel(label, names[parentNode]);
if (names[node].length==0) {
names[node] = name;
}
_setFuses(node, oldOwner, oldFuses | fuses, oldExpiry, expiry);
if (owner ==address(0)) {
_unwrap(node, address(0));
} else {
_transfer(oldOwner, owner, uint256(node), 1, "");
}
}
// wrapper function for stack limitfunction_checkParentFusesAndExpiry(bytes32 parentNode,
bytes32 node,
uint32 fuses,
uint64 expiry
) internalviewreturns (uint64) {
(, , uint64 oldExpiry) = getData(uint256(node));
(, uint32 parentFuses, uint64 maxExpiry) = getData(uint256(parentNode));
_checkParentFuses(node, fuses, parentFuses);
return _normaliseExpiry(expiry, oldExpiry, maxExpiry);
}
function_checkParentFuses(bytes32 node,
uint32 fuses,
uint32 parentFuses
) internalpure{
bool isBurningParentControlledFuses = fuses & PARENT_CONTROLLED_FUSES !=0;
bool parentHasNotBurnedCU = parentFuses & CANNOT_UNWRAP ==0;
if (isBurningParentControlledFuses && parentHasNotBurnedCU) {
revert OperationProhibited(node);
}
}
function_normaliseExpiry(uint64 expiry,
uint64 oldExpiry,
uint64 maxExpiry
) privatepurereturns (uint64) {
// Expiry cannot be more than maximum allowed// .eth names will check registrar, non .eth check parentif (expiry > maxExpiry) {
expiry = maxExpiry;
}
// Expiry cannot be less than old expiryif (expiry < oldExpiry) {
expiry = oldExpiry;
}
return expiry;
}
function_wrapETH2LD(stringmemory label,
address wrappedOwner,
uint32 fuses,
uint64 expiry,
address resolver
) private{
bytes32 labelhash =keccak256(bytes(label));
bytes32 node = _makeNode(ETH_NODE, labelhash);
// hardcode dns-encoded eth string for gas savingsbytesmemory name = _addLabel(label, "\x03eth\x00");
names[node] = name;
_wrap(
node,
name,
wrappedOwner,
fuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH,
expiry
);
if (resolver !=address(0)) {
ens.setResolver(node, resolver);
}
}
function_unwrap(bytes32 node, address owner) private{
if (allFusesBurned(node, CANNOT_UNWRAP)) {
revert OperationProhibited(node);
}
// Burn token and fuse data
_burn(uint256(node));
ens.setOwner(node, owner);
emit NameUnwrapped(node, owner);
}
function_setFuses(bytes32 node,
address owner,
uint32 fuses,
uint64 oldExpiry,
uint64 expiry
) internal{
_setData(node, owner, fuses, expiry);
emit FusesSet(node, fuses);
if (expiry > oldExpiry) {
emit ExpiryExtended(node, expiry);
}
}
function_setData(bytes32 node,
address owner,
uint32 fuses,
uint64 expiry
) internal{
_canFusesBeBurned(node, fuses);
super._setData(uint256(node), owner, fuses, expiry);
}
function_canFusesBeBurned(bytes32 node, uint32 fuses) internalpure{
// If a non-parent controlled fuse is being burned, check PCC and CU are burntif (
fuses &~PARENT_CONTROLLED_FUSES !=0&&
fuses & (PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) !=
(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP)
) {
revert OperationProhibited(node);
}
}
function_checkFusesAreSettable(bytes32 node, uint32 fuses) internalpure{
if (fuses | USER_SETTABLE_FUSES != USER_SETTABLE_FUSES) {
// Cannot directly burn other non-user settable fusesrevert OperationProhibited(node);
}
}
function_isWrapped(bytes32 node) internalviewreturns (bool) {
return
ownerOf(uint256(node)) !=address(0) &&
ens.owner(node) ==address(this);
}
function_isETH2LDInGracePeriod(uint32 fuses,
uint64 expiry
) internalviewreturns (bool) {
return
fuses & IS_DOT_ETH == IS_DOT_ETH &&
expiry - GRACE_PERIOD <block.timestamp;
}
}
Contract Source Code
File 22 of 23: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)pragmasolidity ^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.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed 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.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
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.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
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) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}