_distributeReservedTokensOf
- Step by step
 - Code
 - Events
 - Bug bounty
 
Distributes all outstanding reserved tokens for a project.
Definitionβ
function _distributeReservedTokensOf(uint256 _projectId, string memory _memo)
  internal
  returns (uint256 tokenCount) { ... }
- Arguments:
_projectIdis the ID of the project to which the reserved tokens belong._memois 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β
- 
Keep a reference to the token store.
// Keep a reference to the token store.
IJBTokenStore _tokenStore = tokenStore;Internal references:
 - 
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:
 - 
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:
 - 
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:
JBFundingCycleMetadataResolver.reservedRate(...)
Internal references:
 - 
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:
SafeCast.toInt256(...)
Internal references:
 - 
Get a reference to the project's owner.
// Get a reference to the project owner.
address _owner = projects.ownerOf(_projectId);Internal references:
External references:
 - 
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:
JBSplitsGroups.RESERVED_TOKENS
Internal references:
 - 
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:
 - 
Emit a
DistributeReservedTokensevent with the relevant parameters.emit DistributeReservedTokens(
_fundingCycle.configuration,
_fundingCycle.number,
_projectId,
_owner,
tokenCount,
_leftoverTokenCount,
_memo,
msg.sender
);Event references:
 
/**
  @notice
  Distributes all outstanding reserved tokens for a project.
  @param _projectId The ID of the project to which the reserved tokens belong.
  @param _memo A memo to pass along to the emitted event.
  @return tokenCount The amount of minted reserved tokens.
*/
function _distributeReservedTokensOf(uint256 _projectId, string memory _memo)
  internal
  returns (uint256 tokenCount)
{
  // Keep a reference to the token store.
  IJBTokenStore _tokenStore = tokenStore;
  // Get the current funding cycle to read the reserved rate from.
  JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
  // Get a reference to new total supply of tokens before minting reserved tokens.
  uint256 _totalTokens = _tokenStore.totalSupplyOf(_projectId);
  // Get a reference to the number of tokens that need to be minted.
  tokenCount = _reservedTokenAmountFrom(
    _processedTokenTrackerOf[_projectId],
    _fundingCycle.reservedRate(),
    _totalTokens
  );
  // Set the tracker to be the new total supply.
  _processedTokenTrackerOf[_projectId] = SafeCast.toInt256(_totalTokens + tokenCount);
  // Get a reference to the project owner.
  address _owner = projects.ownerOf(_projectId);
  // 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
      );
  // Mint any leftover tokens to the project owner.
  if (_leftoverTokenCount > 0)
    _tokenStore.mintFor(_owner, _projectId, _leftoverTokenCount, false);
  emit DistributeReservedTokens(
    _fundingCycle.configuration,
    _fundingCycle.number,
    _projectId,
    _owner,
    tokenCount,
    _leftoverTokenCount,
    _memo,
    msg.sender
  );
}
| Name | Data | 
|---|---|
DistributeReservedTokens | 
  | 
| Category | Description | Reward | 
|---|---|---|
| Optimization | Help make this operation more efficient. | 0.5ETH | 
| Low severity | Identify a vulnerability in this operation that could lead to an inconvenience for a user of the protocol or for a protocol developer. | 1ETH | 
| High severity | Identify a vulnerability in this operation that could lead to data corruption or loss of funds. | 5+ETH |