Skip to main content

mintFor

Contract: JBTokenStore​‌

Interface: IJBTokenStore

Mint new project tokens.

Only a project's current controller can mint its tokens.

Definition

function mintFor(
address _holder,
uint256 _projectId,
uint256 _amount,
bool _preferClaimedTokens
) external override onlyController(_projectId) { ... }
  • Arguments:
    • _holder is the address receiving the new tokens.
    • _projectId is the ID of the project to which the tokens belong.
    • _amount is the amount of tokens to mint.
    • _preferClaimedTokens is a flag indicating whether there's a preference for minted tokens to be claimed automatically into the _holders wallet if the project currently has a token contract attached.
  • 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. 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. Check if tokens should be minted using the internal accounting mechanism, or if they should be claimed into the holder's wallet. Tokens should be claimed if the project has issued tokens, and if the _preferClaimedTokens flag is true. The internal accounting mechanism uses less gas, and tokens issued using it can later be claimed into the holders wallet by anyone who submits a claimFor transaction.

    // Save a reference to whether there exists a token and the caller prefers these claimed tokens.
    bool _shouldClaimTokens = _preferClaimedTokens && _token != IJBToken(address(0));
  3. If claimed tokens should be minted, mint the project's token into the holders wallet. Otherwise increment the holder's balance or the unclaimed tokens for the project, and the total supply of unclaimed tokens for the project.

    if (_shouldClaimTokens)
    // If tokens should be claimed, mint tokens into the holder's wallet.
    _token.mint(_projectId, _holder, _amount);
    else {
    // Otherwise, add the tokens to the unclaimed balance and total supply.
    unclaimedBalanceOf[_holder][_projectId] = unclaimedBalanceOf[_holder][_projectId] + _amount;
    unclaimedTotalSupplyOf[_projectId] = unclaimedTotalSupplyOf[_projectId] + _amount;
    }

    Internal references:

    External references:

  4. Make sure the mint doesn't cause an accounting overflow.

    // The total supply can't exceed the maximum value storable in a int256.
    if (totalSupplyOf(_projectId) > type(uint224).max) revert OVERFLOW_ALERT();

    Internal references:

  5. Emit a Mint event with the relevant parameters.

    emit Mint(_holder, _projectId, _amount, _shouldClaimTokens, _preferClaimedTokens, msg.sender);

    Event references: