Skip to main content

claimFor

Contract: JBTokenStore​‌

Interface: IJBTokenStore

Claims internally accounted for tokens into a holder's wallet.

Only a token holder, the owner of the token's project, or an operator specified by the token holder can claim its unclaimed tokens.

Definition

function claimFor(
address _holder,
uint256 _projectId,
uint256 _amount
) external override requirePermission(_holder, _projectId, JBOperations.CLAIM) { ... }
  • Arguments:
    • _holder is the owner of the tokens being claimed.
    • _projectId is the ID of the project whose tokens are being claimed.
    • _amount is the amount of tokens to claim.
  • Through the requirePermission modifier, the function is only accessible by the token holder, or from an operator that has been given the JBOperations.CLAIM permission by the token holder.
  • The function overrides a function definition from the IJBTokenStore interface.
  • The function does't return anything.

Body

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

    // Get a reference to the project's current token.
    IJBToken _token = tokenOf[_projectId];

    Internal references:

  2. Make sure the project has a token. If it doesn't, there's nowhere to claim tokens onto.

    // The project must have a token contract attached.
    if (_token == IJBToken(address(0))) revert TOKEN_NOT_FOUND();
  3. Get a reference to the amount of unclaimed project tokens the holder has.

    // Get a reference to the amount of unclaimed project tokens the holder has.
    uint256 _unclaimedBalance = unclaimedBalanceOf[_holder][_projectId];

    Internal references:

  4. Make sure the holder has enough tokens to claim.

    // There must be enough unlocked unclaimed tokens to claim.
    if (_unclaimedBalance < _amount) revert INSUFFICIENT_UNCLAIMED_TOKENS();
  5. Subtract from from the unclaimed project token balance of the holder and the unclaimed token total supply of the project.

    unchecked {
    // Subtract the claim amount from the holder's unclaimed project token balance.
    unclaimedBalanceOf[_holder][_projectId] = _unclaimedBalance - _amount;

    // Subtract the claim amount from the project's unclaimed total supply.
    unclaimedTotalSupplyOf[_projectId] = unclaimedTotalSupplyOf[_projectId] - _amount;
    }

    Internal references:

  6. Mint the tokens to the holder's wallet.

    // Mint the equivalent amount of the project's token for the holder.
    _token.mint(_projectId, _holder, _amount);

    External references:

  7. Emit a Claim event with the relevant parameters.

    emit Claim(_holder, _projectId, _unclaimedBalance, _amount, msg.sender);

    Event references: