跳到主要内容

_distributeReservedTokensOf

Distributes all outstanding reserved tokens for a project.

Definition

function _distributeReservedTokensOf(uint256 _projectId, string memory _memo)
internal
returns (uint256 tokenCount) { ... }
  • Arguments:
    • _projectId is the ID of the project to which the reserved tokens belong.
    • _memo is a memo to pass along to the emitted event.
  • The resulting function is internal to this contract and its inheriters.
  • The function returns the amount of reserved tokens that were minted.

Body

  1. Keep a reference to the token store.

    // Keep a reference to the token store.
    IJBTokenStore _tokenStore = tokenStore;

    Internal references:

  2. Get a reference to the current funding cycle of the project.

    // Get the current funding cycle to read the reserved rate from.
    JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);

    Internal references:

    External references:

  3. Get a reference to the current total supply of tokens issued for the project.

    // Get a reference to new total supply of tokens before minting reserved tokens.
    uint256 _totalTokens = _tokenStore.totalSupplyOf(_projectId);

    External references:

  4. Get a reference to the current amount of reserved tokens given the current state of the tracker, the current funding cycle's reserved rate, and the current total token supply.

    // Get a reference to the number of tokens that need to be minted.
    tokenCount = _reservedTokenAmountFrom(
    _processedTokenTrackerOf[_projectId],
    _fundingCycle.reservedRate(),
    _totalTokens
    );

    Library references:

    Internal references:

  5. Set the tracker to be equal to the new current total token supply, which is the amount stored plus the amount that will be minted and distributed.

    // Set the tracker to be the new total supply.
    _processedTokenTrackerOf[_projectId] = SafeCast.toInt256(_totalTokens + tokenCount);

    Library references:

    Internal references:

  6. Get a reference to the project's owner.

    // Get a reference to the project owner.
    address _owner = projects.ownerOf(_projectId);

    Internal references:

    External references:

  7. If there are outstanding reserved tokens, distribute them to reserved token splits. Get a reference to any leftover amount after the splits are settled.

    // Distribute tokens to splits and get a reference to the leftover amount to mint after all splits have gotten their share.
    uint256 _leftoverTokenCount = tokenCount == 0
    ? 0
    : _distributeToReservedTokenSplitsOf(
    _projectId,
    _fundingCycle.configuration,
    JBSplitsGroups.RESERVED_TOKENS,
    tokenCount
    );

    Library references:

    Internal references:

  8. If there are any leftover reserved tokens, mint them for the project's owner.

    // Mint any leftover tokens to the project owner.
    if (_leftoverTokenCount > 0)
    _tokenStore.mintFor(_owner, _projectId, _leftoverTokenCount, false);

    External references:

  9. Emit a DistributeReservedTokens event with the relevant parameters.

    emit DistributeReservedTokens(
    _fundingCycle.configuration,
    _fundingCycle.number,
    _projectId,
    _owner,
    tokenCount,
    _leftoverTokenCount,
    _memo,
    msg.sender
    );

    Event references: