mintFor
Contract: JBTokenStore
Interface: IJBTokenStore
- Step by step
- Code
- Errors
- Events
- Bug bounty
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_holder
s 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
-
Get a reference to the project's current token.
// Get a reference to the project's current token.
IJBToken _token = tokenOf[_projectId];Internal references:
-
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 aclaimFor
transaction.// Save a reference to whether there exists a token and the caller prefers these claimed tokens.
bool _shouldClaimTokens = _preferClaimedTokens && _token != IJBToken(address(0)); -
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:
-
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:
-
Emit a
Mint
event with the relevant parameters.emit Mint(_holder, _projectId, _amount, _shouldClaimTokens, _preferClaimedTokens, msg.sender);
Event references:
/**
@notice
Mint new project tokens.
@dev
Only a project's current controller can mint its tokens.
@param _holder The address receiving the new tokens.
@param _projectId The ID of the project to which the tokens belong.
@param _amount The amount of tokens to mint.
@param _preferClaimedTokens A flag indicating whether there's a preference for minted tokens to be claimed automatically into the `_holder`s wallet if the project currently has a token contract attached.
*/
function mintFor(
address _holder,
uint256 _projectId,
uint256 _amount,
bool _preferClaimedTokens
) external override onlyController(_projectId) {
// Get a reference to the project's current token.
IJBToken _token = tokenOf[_projectId];
// Save a reference to whether there exists a token and the caller prefers these claimed tokens.
bool _shouldClaimTokens = _preferClaimedTokens && _token != IJBToken(address(0));
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;
}
// The total supply can't exceed the maximum value storable in a int256.
if (totalSupplyOf(_projectId) > type(uint224).max) revert OVERFLOW_ALERT();
emit Mint(_holder, _projectId, _amount, _shouldClaimTokens, _preferClaimedTokens, msg.sender);
}
String | Description |
---|---|
OVERFLOW_ALERT | Thrown if the mint leads to overflowed accounting. |
Name | Data |
---|---|
Mint |
|
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 |