Skip to main content

JBTokens

Git Source

Inherits: JBControlled, IJBTokens

Manages minting, burning, and balances of projects' tokens and token credits.

Token balances can either be ERC-20s or token credits. This contract manages these two representations and allows credit -> ERC-20 claiming.

The total supply of a project's tokens and the balance of each account are calculated in this contract.

An ERC-20 contract must be set by a project's owner for ERC-20 claiming to become available. Projects can bring their own IJBToken if they prefer.

State Variables​

TOKEN​

A reference to the token implementation that'll be cloned as projects deploy their own tokens.

IJBToken public immutable TOKEN;

creditBalanceOf​

Each holder's credit balance for each project.

mapping(address holder => mapping(uint256 projectId => uint256)) public override creditBalanceOf;

projectIdOf​

Each token's project.

mapping(IJBToken token => uint256) public override projectIdOf;

tokenOf​

Each project's attached token contract.

mapping(uint256 projectId => IJBToken) public override tokenOf;

totalCreditSupplyOf​

The total supply of credits for each project.

mapping(uint256 projectId => uint256) public override totalCreditSupplyOf;

Functions​

constructor​

constructor(IJBDirectory directory, IJBToken token) JBControlled(directory);

Parameters

NameTypeDescription
directoryIJBDirectoryA contract storing directories of terminals and controllers for each project.
tokenIJBTokenThe implementation of the token contract that project can deploy.

totalBalanceOf​

The total balance a holder has for a specified project, including both tokens and token credits.

function totalBalanceOf(address holder, uint256 projectId) external view override returns (uint256 balance);

Parameters

NameTypeDescription
holderaddressThe holder to get a balance for.
projectIduint256The project to get the _holders balance for.

Returns

NameTypeDescription
balanceuint256The combined token and token credit balance of the `_holder

totalSupplyOf​

The total supply for a specific project, including both tokens and token credits.

function totalSupplyOf(uint256 projectId) public view override returns (uint256 totalSupply);

Parameters

NameTypeDescription
projectIduint256The ID of the project to get the total supply of.

Returns

NameTypeDescription
totalSupplyuint256The total supply of the project's tokens and token credits.

burnFrom​

Burns (destroys) credits or tokens.

Credits are burned first, then tokens are burned.

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

function burnFrom(address holder, uint256 projectId, uint256 count) external override onlyControllerOf(projectId);

Parameters

NameTypeDescription
holderaddressThe address that owns the tokens which are being burned.
projectIduint256The ID of the project to the burned tokens belong to.
countuint256The number of tokens to burn.

claimTokensFor​

Redeem credits to claim tokens into a holder's wallet.

Only a project's controller can claim that project's tokens.

function claimTokensFor(
address holder,
uint256 projectId,
uint256 count,
address beneficiary
)
external
override
onlyControllerOf(projectId);

Parameters

NameTypeDescription
holderaddressThe owner of the credits being redeemed.
projectIduint256The ID of the project whose tokens are being claimed.
countuint256The number of tokens to claim.
beneficiaryaddressThe account into which the claimed tokens will go.

deployERC20For​

Deploys an ERC-20 token for a project. It will be used when claiming tokens.

Deploys a project's ERC-20 token contract.

Only a project's controller can deploy its token.

function deployERC20For(
uint256 projectId,
string calldata name,
string calldata symbol,
bytes32 salt
)
external
override
onlyControllerOf(projectId)
returns (IJBToken token);

Parameters

NameTypeDescription
projectIduint256The ID of the project to deploy an ERC-20 token for.
namestringThe ERC-20's name.
symbolstringThe ERC-20's symbol.
saltbytes32The salt used for ERC-1167 clone deployment. Pass a non-zero salt for deterministic deployment based on msg.sender and the TOKEN implementation address.

Returns

NameTypeDescription
tokenIJBTokenThe address of the token that was deployed.

mintFor​

Mint (create) new tokens or credits.

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

function mintFor(
address holder,
uint256 projectId,
uint256 count
)
external
override
onlyControllerOf(projectId)
returns (IJBToken token);

Parameters

NameTypeDescription
holderaddressThe address receiving the new tokens.
projectIduint256The ID of the project to which the tokens belong.
countuint256The number of tokens to mint.

Returns

NameTypeDescription
tokenIJBTokenThe address of the token that was minted, if the project has a token.

setTokenFor​

Set a project's token if not already set.

Only a project's controller can set its token.

function setTokenFor(uint256 projectId, IJBToken token) external override onlyControllerOf(projectId);

Parameters

NameTypeDescription
projectIduint256The ID of the project to set the token of.
tokenIJBTokenThe new token's address.

transferCreditsFrom​

Allows a holder to transfer credits to another account.

Only a project's controller can transfer credits for that project.

function transferCreditsFrom(
address holder,
uint256 projectId,
address recipient,
uint256 count
)
external
override
onlyControllerOf(projectId);

Parameters

NameTypeDescription
holderaddressThe address to transfer credits from.
projectIduint256The ID of the project whose credits are being transferred.
recipientaddressThe recipient of the credits.
countuint256The number of token credits to transfer.

Errors​

JBTokens_EmptyName​

error JBTokens_EmptyName();

JBTokens_EmptySymbol​

error JBTokens_EmptySymbol();

JBTokens_EmptyToken​

error JBTokens_EmptyToken();

JBTokens_InsufficientCredits​

error JBTokens_InsufficientCredits(uint256 count, uint256 creditBalance);

JBTokens_InsufficientTokensToBurn​

error JBTokens_InsufficientTokensToBurn(uint256 count, uint256 tokenBalance);

JBTokens_OverflowAlert​

error JBTokens_OverflowAlert(uint256 value, uint256 limit);

JBTokens_ProjectAlreadyHasToken​

error JBTokens_ProjectAlreadyHasToken(IJBToken token);

JBTokens_TokenAlreadyBeingUsed​

error JBTokens_TokenAlreadyBeingUsed(uint256 projectId);

JBTokens_TokenCantBeAdded​

error JBTokens_TokenCantBeAdded(uint256 projectId);

JBTokens_TokenNotFound​

error JBTokens_TokenNotFound();

JBTokens_TokensMustHave18Decimals​

error JBTokens_TokensMustHave18Decimals(uint256 decimals);