setFor
Contract: JBTokenStore
Interface: IJBTokenStore
- Step by step
- Code
- Errors
- Events
- Bug bounty
Set a project's token if not already set.
Only a project's owner or operator can set its token.
This contract must have access to all of the token's IJBToken
interface functions.
Can't change to a token that's currently being used by another project.
Definition
function setFor(uint256 _projectId, IJBToken _token)
external
override
requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.SET_TOKEN) { ... }
- Arguments:
_projectId
is the ID of the project to which the set token belongs._token
is the new token.
- Through the
requirePermission
modifier, the function is only accessible by the project's owner, or from an operator that has been given theJBOperations.SET_TOKEN
permission by the project owner for the provided_projectId
. - The function overrides a function definition from the
IJBTokenStore
interface. - The function doesn't return anything.
Body
-
Make sure a token was provided.
// Can't set to the zero address.
if (_token == IJBToken(address(0))) revert EMPTY_TOKEN(); -
Make sure the project doesn't already have a token.
// Can't set token if already set.
if (tokenOf[_projectId] != IJBToken(address(0))) revert ALREADY_SET();Internal references:
-
Make sure the token has 18 decimals.
// Can't change to a token that doesn't use 18 decimals.
if (_token.decimals() != 18) revert TOKENS_MUST_HAVE_18_DECIMALS();External references:
-
Store the provided token as the token of the project.
// Store the new token.
tokenOf[_projectId] = _token;Internal references:
-
Emit a
Set
event with the relevant parameters.emit Set(_projectId, _token, msg.sender);
Event references:
/**
@notice
Set a project's token if not already set.
@dev
Only a project's owner or operator can set its token.
@param _projectId The ID of the project to which the set token belongs.
@param _token The new token.
*/
function setFor(uint256 _projectId, IJBToken _token)
external
override
requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.SET_TOKEN)
{
// Can't set to the zero address.
if (_token == IJBToken(address(0))) revert EMPTY_TOKEN();
// Can't set token if already set.
if (tokenOf[_projectId] != IJBToken(address(0))) revert ALREADY_SET();
// Can't change to a token that doesn't use 18 decimals.
if (_token.decimals() != 18) revert TOKENS_MUST_HAVE_18_DECIMALS();
// Store the new token.
tokenOf[_projectId] = _token;
emit Set(_projectId, _token, msg.sender);
}
String | Description |
---|---|
EMPTY_TOKEN | Thrown if no token was provided. |
ALREADY_SET | Thrown if the project already has a token set. |
TOKENS_MUST_HAVE_18_DECIMALS | Thrown if the token does not use 18 decimal fixed point accounting. |
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 |