Overview
PermissionedRegistry is a core contract that implements a tokenized, permission-based registry for ENS names. It combines ERC1155 token functionality with enhanced access control to manage name registrations, permissions, and hierarchical relationships. The contract uses a state machine model where names can be:- AVAILABLE: Not registered, can be registered
- RESERVED: Registered without an owner (placeholder state)
- REGISTERED: Fully registered with an owner and roles
Key Features
- ERC1155-based tokenization of names
- Role-based access control for name management
- Expiry-based registration system
- Hierarchical parent-child registry relationships
- Automatic token regeneration on role changes
- Support for subregistries and resolvers
Contract Information
Inherits:IRegistry, ERC1155Singleton, EnhancedAccessControl, IPermissionedRegistry, MetadataMixin
Interface ID: 0xafff3a63
State Structure
Entry
Internal storage structure for each registered name:Version ID for Enhanced Access Control. Incremented when the name is unregistered/burned.
Version ID for the ERC1155 token. Incremented when roles change or token is regenerated.
The subregistry contract address for this name, if any.
Unix timestamp when the registration expires.
The resolver contract address for this name.
Status
Enum representing registration status:AVAILABLE(0): Name is not registered or has expiredRESERVED(1): Name is registered but has no owner (expiry set, owner is address(0))REGISTERED(2): Name is fully registered with an owner
State
Complete state information for a name:Current registration status (AVAILABLE, RESERVED, or REGISTERED)
Registration expiration timestamp
Current owner address, or address(0) if AVAILABLE/RESERVED
Current token ID (includes version)
Current resource ID for access control
Constructor
HCA (Hierarchical Contract Address) factory for equivalence checking
Metadata provider for token URIs
Initial owner address to grant roles to
Role bitmap to grant to the initial owner
Registration Functions
register
Registers a new name or converts a reserved name to registered.The label to register (e.g., “alice” for alice.eth)
The address that will own the name. Use address(0) to create a RESERVED name.
The subregistry contract to set for this name
The resolver contract address
Roles to grant to the owner. Must be 0 if owner is address(0).
Expiration timestamp. For RESERVED names, use 0 to keep current expiry.
The token ID of the registered name
- Label must be valid size (1-255 bytes)
- If AVAILABLE: requires
ROLE_REGISTRARon root resource - If RESERVED: requires
ROLE_REGISTER_RESERVEDon root resource - Cannot overwrite REGISTERED names
- Expiry must be in the future
- If owner is address(0), roleBitmap must be 0
NameRegistered(if owner != address(0))NameReserved(if owner == address(0))TokenResourceSubregistryUpdated(if registry != address(0))ResolverUpdated(if resolver != address(0))
unregister
Deletes a registered or reserved name, setting its expiry to the current timestamp.The labelhash, token ID, or resource ID of the name to unregister
- Name must not be expired
- Caller must have
ROLE_UNREGISTERpermission
NameUnregistered
renew
Extends the expiration time of a registered or reserved name.The labelhash, token ID, or resource ID
The new expiration timestamp (must be greater than current expiry)
- Name must not be expired
- Caller must have
ROLE_RENEWpermission - New expiry must be greater than current expiry
ExpiryUpdated
Configuration Functions
setSubregistry
Sets or updates the subregistry for a name.The labelhash, token ID, or resource ID
The new subregistry contract address
- Name must not be expired
- Caller must have
ROLE_SET_SUBREGISTRYpermission
SubregistryUpdated
setResolver
Sets or updates the resolver for a name.The labelhash, token ID, or resource ID
The new resolver contract address
- Name must not be expired
- Caller must have
ROLE_SET_RESOLVERpermission
ResolverUpdated
setParent
Sets the canonical parent registry and label for this registry.The parent registry contract
The label of this registry in the parent (e.g., “eth”)
- Caller must have
ROLE_SET_PARENTon root resource
ParentUpdated
Access Control Functions
grantRoles
Grants roles to an account for a specific name.The labelhash, token ID, or resource ID
Bitmap of roles to grant
The address to grant roles to
Returns true if roles were granted
revokeRoles
Revokes roles from an account for a specific name.The labelhash, token ID, or resource ID
Bitmap of roles to revoke
The address to revoke roles from
Returns true if roles were revoked
Query Functions
getSubregistry
Returns the subregistry for a label.The label to query
The subregistry contract, or address(0) if none or expired
getResolver
Returns the resolver for a label.The label to query
The resolver address, or address(0) if none or expired
getParent
Returns the parent registry and label.The parent registry contract
The label in the parent registry
getExpiry
Returns the expiration timestamp for a name.The labelhash, token ID, or resource ID
The expiration timestamp
getResource
Converts any ID (labelhash, token ID, or resource) to the current resource ID.The labelhash, token ID, or resource ID
The current resource ID for access control
getTokenId
Converts any ID to the current token ID.The labelhash, token ID, or resource ID
The current token ID
getStatus
Returns the registration status of a name.The labelhash, token ID, or resource ID
AVAILABLE, RESERVED, or REGISTERED
getState
Returns complete state information for a name.The labelhash, token ID, or resource ID
Complete state including status, expiry, owner, tokenId, and resource
latestOwnerOf
Returns the latest owner of a token, even if expired.The token ID to query
The owner address, or address(0) if never owned
ownerOf
Returns the current owner of a token (respects expiry).The token ID to query
The owner address, or address(0) if expired or token ID is outdated
roles
Returns the role bitmap for an account.The labelhash, token ID, or resource ID
The account to query
Bitmap of roles held by the account
hasRoles
Checks if an account has specific roles.The labelhash, token ID, or resource ID
Bitmap of roles to check
The account to check
True if the account has all specified roles
Events
NameRegistered
Emitted when a name is registered with an owner.NameReserved
Emitted when a name is reserved without an owner.NameUnregistered
Emitted when a name is unregistered.ExpiryUpdated
Emitted when a name’s expiry is changed.SubregistryUpdated
Emitted when a name’s subregistry is changed.ResolverUpdated
Emitted when a name’s resolver is changed.TokenRegenerated
Emitted when a token is regenerated with a new ID due to role changes.ParentUpdated
Emitted when the parent registry is changed.TokenResource
Emitted to associate a token with an access control resource.Errors
NameAlreadyRegistered
NameAlreadyReserved
NameExpired
CannotReduceExpiration
CannotSetPastExpiration
TransferDisallowed
State Machine
The registry follows this state diagram:Notes
- Token IDs include version numbers and are regenerated when roles change
- Resource IDs for access control are separate from token IDs
- The “anyId” parameter in most functions accepts labelhash, token ID, or resource ID
- Admin roles can only be granted during registration, not afterward
- Transfers automatically transfer all roles to the new owner
- Transfers require
ROLE_CAN_TRANSFER_ADMIN