Skip to main content

JBTiered721Delegate

Git Source

Inherits: JBOwnable, JB721Delegate, IJBTiered721Delegate

This delegate makes multiple NFT tiers with custom price floors available to a project's contributors upon payment, and allows project owners to enable NFT redemption for treasury assets based on the price floors of those NFTs.

State Variables​

_firstOwnerOf​

The first owner of each token ID, stored on first transfer out.

mapping(uint256 => address) internal _firstOwnerOf;

_packedPricingContext​

Info that contextualizes the pricing of tiers, packed into a uint256: currency in bits 0-47 (48 bits), pricing decimals in bits 48-95 (48 bits), and prices contract in bits 96-255 (160 bits).

uint256 internal _packedPricingContext;

codeOrigin​

The address of the original JBTiered721Delegate - used in initialize(...) to check if this is the original JBTiered721Delegate, and to revert initialization if it is.

address public override codeOrigin;

store​

The contract that stores and manages data for this contract's NFTs.

IJBTiered721DelegateStore public override store;

fundingCycleStore​

The contract storing all funding cycle configurations.

IJBFundingCycleStore public override fundingCycleStore;

creditsOf​

The amount each address has paid which did not go towards minting an NFT. These credits can be redeemed to mint NFTs.

mapping(address => uint256) public override creditsOf;

baseURI​

The common base for the tokenUris.

string public override baseURI;

contractURI​

Contract metadata uri.

string public override contractURI;

Functions​

firstOwnerOf​

The first owner of each token ID, which corresponds to the address that originally contributed to the project to receive the NFT.

function firstOwnerOf(uint256 _tokenId) external view override returns (address);

Parameters

NameTypeDescription
_tokenIduint256The ID of the token to get the first owner of.

Returns

NameTypeDescription
<none>addressThe first owner of the token.

pricingContext​

Info that contextualizes the pricing of tiers.

function pricingContext() external view override returns (uint256 currency, uint256 decimals, IJBPrices prices);

Returns

NameTypeDescription
currencyuint256The currency being used.
decimalsuint256The amount of decimals being used.
pricesIJBPricesThe prices contract being used to resolve currency discrepancies.

balanceOf​

The total number of tokens owned by an address across all tiers.

function balanceOf(address _owner) public view override returns (uint256 balance);

Parameters

NameTypeDescription
_owneraddressThe address to check the balance of.

Returns

NameTypeDescription
balanceuint256The number of tokens owned by the address across all tiers.

tokenURI​

The metadata URI of the provided token ID.

Defer to the tokenUriResolver if it is set. Otherwise, use the tokenUri corresponding with the token's tier.

function tokenURI(uint256 _tokenId) public view virtual override returns (string memory);

Parameters

NameTypeDescription
_tokenIduint256The ID of the token to get the metadata URI for.

Returns

NameTypeDescription
<none>stringThe token URI corresponding with the token's tier, or the tokenUriResolver URI if it is set.

redemptionWeightOf​

The cumulative redemption weight the given token IDs have compared to the _totalRedemptionWeight.

function redemptionWeightOf(uint256[] memory _tokenIds, JBRedeemParamsData calldata)
public
view
virtual
override
returns (uint256);

Parameters

NameTypeDescription
_tokenIdsuint256[]The IDs of the tokens to get the cumulative redemption weight of.
<none>JBRedeemParamsData

Returns

NameTypeDescription
<none>uint256The redemption weight of the _tokenIds.

totalRedemptionWeight​

The cumulative redemption weight across all token IDs.

function totalRedemptionWeight(JBRedeemParamsData calldata) public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256The cumulative redemption weight.

supportsInterface​

Indicates if this contract adheres to the specified interface.

See IERC165-supportsInterface.

function supportsInterface(bytes4 _interfaceId) public view override returns (bool);

Parameters

NameTypeDescription
_interfaceIdbytes4The ID of the interface to check for adherence to.

constructor​

constructor(
IJBDirectory _directory,
IJBOperatorStore _operatorStore,
bytes4 _payMetadataDelegateId,
bytes4 _redeemMetadataDelegateId
)
JBOwnable(_directory.projects(), _operatorStore)
JB721Delegate(_directory, _payMetadataDelegateId, _redeemMetadataDelegateId);

Parameters

NameTypeDescription
_directoryIJBDirectoryA directory of terminals and controllers for projects.
_operatorStoreIJBOperatorStoreA contract which stores operator assignments.
_payMetadataDelegateIdbytes4The 4bytes ID of this delegate, used for pay metadata parsing
_redeemMetadataDelegateIdbytes4The 4bytes ID of this delegate, used for redeem metadata parsing

initialize​

Initializes a cloned copy of the original JB721Delegate contract.

function initialize(
uint256 _projectId,
string memory _name,
string memory _symbol,
IJBFundingCycleStore _fundingCycleStore,
string memory _baseUri,
IJB721TokenUriResolver _tokenUriResolver,
string memory _contractUri,
JB721PricingParams memory _pricing,
IJBTiered721DelegateStore _store,
JBTiered721Flags memory _flags
) public override;

Parameters

NameTypeDescription
_projectIduint256The ID of the project this contract's functionality applies to.
_namestringThe name of the NFT collection distributed through this contract.
_symbolstringThe symbol that the NFT collection should be represented by.
_fundingCycleStoreIJBFundingCycleStoreA contract storing all funding cycle configurations.
_baseUristringA URI to use as a base for full token URIs.
_tokenUriResolverIJB721TokenUriResolverA contract responsible for resolving the token URI for each token ID.
_contractUristringA URI where this contract's metadata can be found.
_pricingJB721PricingParamsNFT tier pricing parameters according to which token distribution will be made. Must be sorted by contribution floor (from least to greatest).
_storeIJBTiered721DelegateStoreThe contract which stores the NFT's data.
_flagsJBTiered721FlagsA set of flags that help to define how this contract works.

mintFor​

Manually mint NFTs from the provided tiers .

function mintFor(uint16[] calldata _tierIds, address _beneficiary)
external
override
requirePermission(owner(), projectId, JB721Operations.MINT)
returns (uint256[] memory tokenIds);

Parameters

NameTypeDescription
_tierIdsuint16[]The IDs of the tiers to mint from.
_beneficiaryaddressThe address to mint to.

Returns

NameTypeDescription
tokenIdsuint256[]The IDs of the newly minted tokens.

mintReservesFor​

Mint reserved tokens within the tier for the provided value.

function mintReservesFor(JBTiered721MintReservesForTiersData[] calldata _mintReservesForTiersData) external override;

Parameters

NameTypeDescription
_mintReservesForTiersDataJBTiered721MintReservesForTiersData[]Contains information about how many reserved tokens to mint for each tier.

adjustTiers​

Adjust the tiers which are mintable through this contract, adhering to any locked tier constraints.

Only the contract's owner or an operator with ADJUST_TIERS can adjust the tiers.

function adjustTiers(JB721TierParams[] calldata _tiersToAdd, uint256[] calldata _tierIdsToRemove)
external
override
requirePermission(owner(), projectId, JB721Operations.ADJUST_TIERS);

Parameters

NameTypeDescription
_tiersToAddJB721TierParams[]An array of tier data to add.
_tierIdsToRemoveuint256[]An array of tier IDs to remove.

setMetadata​

Set a contract's URI metadata properties.

Only the contract's owner can set the URI metadata.

function setMetadata(
string calldata _baseUri,
string calldata _contractUri,
IJB721TokenUriResolver _tokenUriResolver,
uint256 _encodedIPFSUriTierId,
bytes32 _encodedIPFSUri
) external override requirePermission(owner(), projectId, JB721Operations.UPDATE_METADATA);

Parameters

NameTypeDescription
_baseUristringThe new base URI.
_contractUristringThe new contract URI.
_tokenUriResolverIJB721TokenUriResolverThe new URI resolver.
_encodedIPFSUriTierIduint256The ID of the tier to set the encoded IPFS URI of.
_encodedIPFSUribytes32The encoded IPFS URI to set.

mintReservesFor​

Mint reserved tokens within the provided tier.

Only currently outstanding reserved tokens can be minted.

function mintReservesFor(uint256 _tierId, uint256 _count) public override;

Parameters

NameTypeDescription
_tierIduint256The ID of the tier to mint from.
_countuint256The number of reserved tokens to mint.

_processPayment​

Mints for a given contribution to the beneficiary.

function _processPayment(JBDidPayData3_1_1 calldata _data) internal virtual override;

Parameters

NameTypeDescription
_dataJBDidPayData3_1_1The standard data passed when paying a Juicebox project.

_didBurn​

A function that runs when tokens are burned via redemption.

function _didBurn(uint256[] memory _tokenIds) internal virtual override;

Parameters

NameTypeDescription
_tokenIdsuint256[]The IDs of the tokens that were burned.

_mintAll​

Mints a token in all provided tiers.

function _mintAll(uint256 _amount, uint16[] memory _mintTierIds, address _beneficiary)
internal
returns (uint256 leftoverAmount);

Parameters

NameTypeDescription
_amountuint256The amount to base the mints on. The combined price floors of all tokens to be minted must fit within this amount.
_mintTierIdsuint16[]An array of tier IDs to be minted.
_beneficiaryaddressThe address to mint for.

Returns

NameTypeDescription
leftoverAmountuint256The amount leftover after the mint.

_beforeTokenTransfer​

Hook to register a token's first owner (if necessary) before transferring it.

function _beforeTokenTransfer(address _from, address _to, uint256 _tokenId) internal virtual override;

Parameters

NameTypeDescription
_fromaddressThe address to transfer the token from.
_toaddressThe address to transfer the token to.
_tokenIduint256The ID of the token being transferred.

_afterTokenTransfer​

Transfer voting units after the transfer of a token.

function _afterTokenTransfer(address _from, address _to, uint256 _tokenId) internal virtual override;

Parameters

NameTypeDescription
_fromaddressThe address to transfer the token from.
_toaddressThe address to transfer the token to.
_tokenIduint256The ID of the token being transferred.

_afterTokenTransferAccounting​

Custom hook to handle token/tier accounting, this way we can reuse the '_tier' instead of fetching it again.

function _afterTokenTransferAccounting(address _from, address _to, uint256 _tokenId, JB721Tier memory _tier)
internal
virtual;

Parameters

NameTypeDescription
_fromaddressThe address to transfer voting units from.
_toaddressThe address to transfer voting units to.
_tokenIduint256The ID of the token for which voting units are being transferred.
_tierJB721TierThe tier the token ID is part of.

Errors​

OVERSPENDING​

error OVERSPENDING();

RESERVED_TOKEN_MINTING_PAUSED​

error RESERVED_TOKEN_MINTING_PAUSED();

TRANSFERS_PAUSED​

error TRANSFERS_PAUSED();