Skip to main content

JBProjectHandles

Git Source

Inherits: IJBProjectHandles, ERC2771Context

JBProjectHandles allows Juicebox project owners to associate their project with an ENS node. If that ENS node has a matching text record which points back to the project, clients will treat that ENS node as the project's handle.

By convention, clients read the juicebox text field of the ENS node with the format chainId:projectId. For example, project ID #5 on Optimism mainnet would be represented by a juicebox text record of 10:5.

State Variables

TEXT_KEY

The key of the ENS text record which points back to a project.

string public constant override TEXT_KEY = "juicebox";

ENS_REGISTRY

The ENS registry contract address.

Same on Ethereum mainnet and most of its testnets.

ENS public constant override ENS_REGISTRY = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);

_ensNamePartsOf

A private mapping storing ENS name parts set by different owner addresses for different projects.

The ensParts ["jbx", "dao", "foo"] represents foo.dao.jbx.eth.

mapping(uint256 chainId => mapping(uint256 projectId => mapping(address setter => string[] ensParts))) private
_ensNamePartsOf;

Functions

constructor

constructor(address trustedForwarder) ERC2771Context(trustedForwarder);

Parameters

NameTypeDescription
trustedForwarderaddressThe trusted forwarder for the ERC2771Context.

ensNamePartsOf

The parts of the stored ENS name of a project.

function ensNamePartsOf(
uint256 chainId,
uint256 projectId,
address setter
)
external
view
override
returns (string[] memory);

Parameters

NameTypeDescription
chainIduint256The chain ID of the network on which the project ID exists.
projectIduint256The ID of the project to get the ENS name of.
setteraddressThe address that set the requested record in this contract.

Returns

NameTypeDescription
<none>string[]The parts of the ENS name parts of a project.

handleOf

Returns a project's verified handle. If the handle isn't verified, returns the empty string.

The ENS record text record with the TEXT_KEY record containing chainId:projectId.

function handleOf(uint256 chainId, uint256 projectId, address setter) external view override returns (string memory);

Parameters

NameTypeDescription
chainIduint256The chain ID of the network the project is on.
projectIduint256The ID of the project to get the handle of.
setteraddressThe address which set the requested handle. This should be the project's current owner.

Returns

NameTypeDescription
<none>stringhandle The project's verified handle.

_contextSuffixLength

ERC-2771 specifies the context as being a single address (20 bytes).

function _contextSuffixLength() internal view virtual override returns (uint256);

_formatHandle

Formats ENS name parts into a handle.

function _formatHandle(string[] memory ensNameParts) internal pure returns (string memory handle);

Parameters

NameTypeDescription
ensNamePartsstring[]The ENS name parts to format into a handle.

Returns

NameTypeDescription
handlestringThe formatted ENS handle.

_namehash

Returns a namehash for an ENS name.

See https://eips.ethereum.org/EIPS/eip-137.

function _namehash(string[] memory ensNameParts) internal pure returns (bytes32 namehash);

Parameters

NameTypeDescription
ensNamePartsstring[]The parts of an ENS name to hash.

Returns

NameTypeDescription
namehashbytes32The namehash for an ENS name parts.

_msgSender

Returns the sender, prefered to use over msg.sender

function _msgSender() internal view override returns (address sender);

Returns

NameTypeDescription
senderaddressthe sender address of this call.

_msgData

Returns the calldata, prefered to use over msg.data

function _msgData() internal view override returns (bytes calldata);

Returns

NameTypeDescription
<none>bytescalldata the msg.data of this call

setEnsNamePartsFor

Point from a Juicebox project to an ENS node.

The parts ["jbx", "dao", "foo"] represents foo.dao.jbx.eth.

The project's owner must call this function to set its ENS name parts.

function setEnsNamePartsFor(uint256 chainId, uint256 projectId, string[] memory parts) external override;

Parameters

NameTypeDescription
chainIduint256The chain ID of the network the project is on.
projectIduint256The ID of the project to set an ENS handle for.
partsstring[]The parts of the ENS domain to use as the project handle, excluding the trailing .eth.

Errors

JBProjectHandles_EmptyNamePart

error JBProjectHandles_EmptyNamePart(string[] parts);

JBProjectHandles_InvalidNamePart

error JBProjectHandles_InvalidNamePart(string part);

JBProjectHandles_NoParts

error JBProjectHandles_NoParts();