Skip to main content

changeFor

Contract: JBTokenStore​‌

Interface: IJBTokenStore

Swap the current project's token for another, and transfer ownership of the current token to another address if needed.

Only a project's current controller can change 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 changeFor(
uint256 _projectId,
IJBToken _token,
address _newOwner
) external override onlyController(_projectId) { ... }
  • Arguments:
    • _projectId is the ID of the project to which the changed token belongs.
    • _token is the new token. Send an empty address to remove the project's current token without adding a new one, if claiming tokens isn't currency required by the project
    • _newOwner is an address to transfer the current token's ownership to. This is optional, but it cannot be done later.
  • Through the onlyController modifier, the function can only be accessed by the controller of the _projectId.
  • The function overrides a function definition from the IJBTokenStore interface.
  • The function doesn't return anything.

Body

  1. Make sure claiming isn't required if removing the token.

    // Can't remove the project's token if the project requires claiming tokens.
    if (_token == IJBToken(address(0)) && requireClaimFor[_projectId])
    revert CANT_REMOVE_TOKEN_IF_ITS_REQUIRED();

    Internal references:

  2. Make sure the token being changed to isn't being used by another project.

    // Can't change to a token already in use.
    if (projectOf[_token] != 0) revert TOKEN_ALREADY_IN_USE();

    Internal references:

  3. Make sure the token has 18 decimals.

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

    External references:

  4. Get a reference to the project's current token.

    // Get a reference to the current token for the project.
    oldToken = tokenOf[_projectId];

    Internal references:

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

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

    Internal references:

  6. Store the project the new token is being used for.

    // Store the project for the new token.
    if (_token != IJBToken(address(0)))
    projectOf[_token] = _projectId;

    Internal references:

  7. Reset the project for the project's old token.

    // Reset the project for the old token.
    projectOf[oldToken] = 0;

    Internal references:

  8. If there's a current token and a new owner address was provided, transfer the ownership of the current token from this contract to the new owner.

    // If there's a current token and a new owner was provided, transfer ownership of the old token to the new owner.
    if (_newOwner != address(0) && oldToken != IJBToken(address(0)))
    oldToken.transferOwnership(_projectId, _newOwner);

    External references:

  9. Emit a Change event with the relevant parameters.

    emit Change(_projectId, _token, oldToken, _newOwner, msg.sender);

    Event references: