Skip to main content

ENSSubdomainRegistrar

Description

This contract registers ENS subdomains under a parent domain specified in the initialization process and maintains ownership of the subdomain since only the resolver address is set. This contract must either be the domain node owner or an approved operator of the node owner. The default resolver being used is the one specified in the parent domain.

Implementation

public variable UPGRADE_REGISTRAR_PERMISSION_ID

The ID of the permission required to call the _authorizeUpgrade function.

bytes32 UPGRADE_REGISTRAR_PERMISSION_ID

public variable REGISTER_ENS_SUBDOMAIN_PERMISSION_ID

The ID of the permission required to call the registerSubnode and setDefaultResolver function.

bytes32 REGISTER_ENS_SUBDOMAIN_PERMISSION_ID

public variable ens

The ENS registry contract

contract ENS ens

public variable node

The namehash of the domain on which subdomains are registered.

bytes32 node

public variable resolver

The address of the ENS resolver resolving the names to an address.

address resolver

error AlreadyRegistered

Thrown if the subnode is already registered.

error AlreadyRegistered(bytes32 subnode, address nodeOwner)
InputTypeDescription
subnodebytes32The subnode namehash.
nodeOwneraddressThe node owner address.

error InvalidResolver

Thrown if node's resolver is invalid.

error InvalidResolver(bytes32 node, address resolver)
InputTypeDescription
nodebytes32The node namehash.
resolveraddressThe node resolver address.

public function constructor

constructor() public

Used to disallow initializing the implementation contract by an attacker for extra safety.

external function initialize

Initializes the component by

  • checking that the contract is the domain node owner or an approved operator
  • initializing the underlying component
  • registering the ERC-165 interface ID
  • setting the ENS contract, the domain node hash, and resolver.
function initialize(contract IDAO _managingDao, contract ENS _ens, bytes32 _node) external
InputTypeDescription
_managingDaocontract IDAOThe interface of the DAO managing the components permissions.
_enscontract ENSThe interface of the ENS registry to be used.
_nodebytes32The ENS parent domain node under which the subdomains are to be registered.

internal function _authorizeUpgrade

Internal method authorizing the upgrade of the contract via the upgradeability mechanism for UUPS proxies (see ERC-1822).

function _authorizeUpgrade(address) internal virtual

The caller must have the UPGRADE_REGISTRAR_PERMISSION_ID permission.

external function registerSubnode

Registers a new subdomain with this registrar as the owner and set the target address in the resolver.

function registerSubnode(bytes32 _label, address _targetAddress) external
InputTypeDescription
_labelbytes32The labelhash of the subdomain name.
_targetAddressaddressThe address to which the subdomain resolves.

It reverts with no message if this contract isn't the owner nor an approved operator for the given node.

external function setDefaultResolver

Sets the default resolver contract address that the subdomains being registered will use.

function setDefaultResolver(address _resolver) external
InputTypeDescription
_resolveraddressThe resolver contract to be used.
© 2024