跳到主要内容

setFor

Contract: JBTokenStore​‌

Interface: IJBTokenStore

Set a project's token if not already set.

Only a project's owner or operator can set its token.

This contract must have access to all of the token's IJBToken interface functions.

Can't change to a token that's currently being used by another project.

Definition

function setFor(uint256 _projectId, IJBToken _token)
external
override
requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.SET_TOKEN) { ... }
  • Arguments:
    • _projectId is the ID of the project to which the set token belongs.
    • _token is the new token.
  • Through the requirePermission modifier, the function is only accessible by the project's owner, or from an operator that has been given the JBOperations.SET_TOKEN permission by the project owner for the provided _projectId.
  • The function overrides a function definition from the IJBTokenStore interface.
  • The function doesn't return anything.

Body

  1. Make sure a token was provided.

    // Can't set to the zero address.
    if (_token == IJBToken(address(0))) revert EMPTY_TOKEN();
  2. Make sure the project doesn't already have a token.

    // Can't set token if already set.
    if (tokenOf[_projectId] != IJBToken(address(0))) revert ALREADY_SET();

    Internal references:

  3. Make sure the token has 18 decimals.

    // Can't change to a token that doesn't use 18 decimals.
    if (_token.decimals() != 18) revert TOKENS_MUST_HAVE_18_DECIMALS();

    External references:

  4. Store the provided token as the token of the project.

    // Store the new token.
    tokenOf[_projectId] = _token;

    Internal references:

  5. Emit a Set event with the relevant parameters.

    emit Set(_projectId, _token, msg.sender);

    Event references: