TokenHandleRegistry

Git Source

Inherits: ITokenHandleRegistry

Author: Lens Protocol

This contract is used to link a token with a handle.

State Variables

LENS_HUB

address immutable LENS_HUB;

LENS_HANDLES

address immutable LENS_HANDLES;

EIP1271_MAGIC_VALUE

bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;

handleToToken

mapping(bytes32 handle => RegistryTypes.Token token) handleToToken;

tokenToHandle

mapping(bytes32 token => RegistryTypes.Handle handle) tokenToHandle;

nonces

mapping(address signer => uint256 nonce) public nonces;

Functions

constructor

constructor(address lensHub, address lensHandles);
function migrationLink(uint256 handleId, uint256 profileId) external;

Links a handle NFT with a profile NFT. Linking means a connection between the two NFTs is created, and the handle NFT can be used to resolve the profile NFT or vice versa.

*In the first version of the registry, the NFT contracts are hard-coded:

  • Handle is hard-coded to be of the .lens namespace
  • Token is hard-coded to be of the Lens Protocol Profile In future versions, the registry will be more flexible and allow for different namespaces and tokens, so this function might be deprecated and replaced with a new one accepting addresses of the handle and token contracts.*
function link(uint256 handleId, uint256 profileId) external;

Parameters

NameTypeDescription
handleIduint256ID of the .lens namespace handle NFT
profileIduint256ID of the Lens Protocol Profile NFT

linkWithSig

function linkWithSig(uint256 handleId, uint256 profileId, Types.EIP712Signature calldata signature) external;
function _link(uint256 handleId, uint256 profileId, address transactionExecutor) private;

_validateLinkSignature

function _validateLinkSignature(Types.EIP712Signature calldata signature, uint256 handleId, uint256 profileId)
    internal;

_validateUnlinkSignature

function _validateUnlinkSignature(Types.EIP712Signature calldata signature, uint256 handleId, uint256 profileId)
    internal;

_validateRecoveredAddress

Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.

function _validateRecoveredAddress(bytes32 digest, Types.EIP712Signature calldata signature) private view;

_calculateDigest

Calculates EIP712 digest based on the current DOMAIN_SEPARATOR.

function _calculateDigest(bytes32 hashedMessage) private view returns (bytes32);

Parameters

NameTypeDescription
hashedMessagebytes32The message hash from which the digest should be calculated.

Returns

NameTypeDescription
<none>bytes32bytes32 A 32-byte output representing the EIP712 digest.

calculateDomainSeparator

function calculateDomainSeparator() internal view returns (bytes32);

Unlinks a handle NFT from a profile NFT.

*In the first version of the registry, the contracts are hard-coded:

  • Handle is hard-coded to be of the .lens namespace
  • Token is hard-coded to be of the Lens Protocol Profile In future versions, the registry will be more flexible and allow for different namespaces and tokens, so this function might be deprecated and replaced with a new one accepting addresses of the handle and token contracts.*
function unlink(uint256 handleId, uint256 profileId) external;

Parameters

NameTypeDescription
handleIduint256ID of the .lens namespace handle NFT
profileIduint256ID of the Lens Protocol Profile NFT

unlinkWithSig

function unlinkWithSig(uint256 handleId, uint256 profileId, Types.EIP712Signature calldata signature) external;
function _unlink(uint256 handleId, uint256 profileId, address transactionExecutor) private;

resolve

Resolves a handle NFT to a profile NFT.

*In the first version of the registry, the contracts are hard-coded:

  • Handle is hard-coded to be of the .lens namespace
  • Token is hard-coded to be of the Lens Protocol Profile In future versions, the registry will be more flexible and allow for different namespaces and tokens, so this function might be deprecated and replaced with a new one.*
function resolve(uint256 handleId) external view returns (uint256);

Parameters

NameTypeDescription
handleIduint256ID of the .lens namespace handle NFT

Returns

NameTypeDescription
<none>uint256tokenId ID of the Lens Protocol Profile NFT

getDefaultHandle

Gets a default handle for a profile NFT (aka reverse resolution).

*In the first version of the registry, the contracts are hard-coded:

  • Handle is hard-coded to be of the .lens namespace
  • Token is hard-coded to be of the Lens Protocol Profile In future versions, the registry will be more flexible and allow for different namespaces and tokens, so this function might be deprecated and replaced with a new one.*
function getDefaultHandle(uint256 profileId) external view returns (uint256);

Parameters

NameTypeDescription
profileIduint256

Returns

NameTypeDescription
<none>uint256handleId ID of the .lens namespace handle NFT

_resolveHandleToToken

INTERNAL FUNCTIONS ///

function _resolveHandleToToken(RegistryTypes.Handle memory handle)
    internal
    view
    returns (RegistryTypes.Token storage);

_resolveTokenToHandle

function _resolveTokenToHandle(RegistryTypes.Token memory token) internal view returns (RegistryTypes.Handle storage);

_executeLinkage

function _executeLinkage(
    RegistryTypes.Handle memory handle,
    RegistryTypes.Token memory token,
    address transactionExecutor
) internal;

_deleteTokenToHandleLinkageIfAny

function _deleteTokenToHandleLinkageIfAny(RegistryTypes.Handle memory handle, address transactionExecutor) internal;

_deleteHandleToTokenLinkageIfAny

function _deleteHandleToTokenLinkageIfAny(RegistryTypes.Token memory token, address transactionExecutor) internal;

_executeUnlinkage

function _executeUnlinkage(
    RegistryTypes.Handle memory handle,
    RegistryTypes.Token memory token,
    address transactionExecutor
) internal;

_handleHash

function _handleHash(RegistryTypes.Handle memory handle) internal pure returns (bytes32);

_tokenHash

function _tokenHash(RegistryTypes.Token memory token) internal pure returns (bytes32);

_getNonceIncrementAndEmitEvent

This fetches a signer's current nonce and increments it so it's ready for the next meta-tx. Also emits the NonceUpdated event.

function _getNonceIncrementAndEmitEvent(address signer) private returns (uint256);

Parameters

NameTypeDescription
signeraddressThe address to get and increment the nonce for.

Returns

NameTypeDescription
<none>uint256uint256 The current nonce for the given signer prior to being incremented.