Skip to main content

JB721Delegate

Git Source

Inherits: ERC721, IJB721Delegate, IJBFundingCycleDataSource3_1_1, IJBPayDelegate3_1_1, IJBRedemptionDelegate3_1_1

This delegate makes NFTs available to a project's contributors upon payment, and allows project owners to enable NFT redemption for treasury assets.

State Variables

directory

The directory of terminals and controllers for projects.

IJBDirectory public immutable override directory;

payMetadataDelegateId

The 4bytes ID of this delegate, used for pay metadata parsing

bytes4 public immutable override payMetadataDelegateId;

redeemMetadataDelegateId

The 4bytes ID of this delegate, used for redeem metadata parsing

bytes4 public immutable override redeemMetadataDelegateId;

projectId

The Juicebox project ID this contract's functionality applies to.

uint256 public override projectId;

Functions

payParams

This function gets called when the project receives a payment. It sets this contract as the delegate to get a callback from the terminal. Part of IJBFundingCycleDataSource.

function payParams(JBPayParamsData calldata _data)
public
view
virtual
override
returns (uint256 weight, string memory memo, JBPayDelegateAllocation3_1_1[] memory delegateAllocations);

Parameters

NameTypeDescription
_dataJBPayParamsDataThe Juicebox standard project payment data.

Returns

NameTypeDescription
weightuint256The weight that tokens should get minted in accordance with.
memostringA memo to be forwarded to the event.
delegateAllocationsJBPayDelegateAllocation3_1_1[]Amount to be sent to delegates instead of adding to local balance.

redeemParams

This function gets called when the project's (NFT) token holders redeem. Part of IJBFundingCycleDataSource.

function redeemParams(JBRedeemParamsData calldata _data)
public
view
virtual
override
returns (
uint256 reclaimAmount,
string memory memo,
JBRedemptionDelegateAllocation3_1_1[] memory delegateAllocations
);

Parameters

NameTypeDescription
_dataJBRedeemParamsDataStandard Juicebox project redemption data.

Returns

NameTypeDescription
reclaimAmountuint256Amount to be reclaimed from the treasury.
memostringA memo to be forwarded to the event.
delegateAllocationsJBRedemptionDelegateAllocation3_1_1[]Amount to be sent to delegates instead of being added to the beneficiary.

redemptionWeightOf

Returns the cumulative redemption weight of the given token IDs relative to the totalRedemptionWeight.

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

Parameters

NameTypeDescription
_tokenIdsuint256[]The token IDs to calculate the cumulative redemption weight for.
_dataJBRedeemParamsDataStandard Juicebox project redemption data.

Returns

NameTypeDescription
<none>uint256The cumulative redemption weight of the specified token IDs.

totalRedemptionWeight

Calculates the cumulative redemption weight of all token IDs.

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

Parameters

NameTypeDescription
_dataJBRedeemParamsDataStandard Juicebox project redemption data.

Returns

NameTypeDescription
<none>uint256Total cumulative redemption weight of all token IDs.

supportsInterface

Indicates if this contract adheres to the specified interface.

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 _interfaceId) public view virtual override(ERC721, IERC165) returns (bool);

Parameters

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

constructor

constructor(IJBDirectory _directory, bytes4 _payMetadataDelegateId, bytes4 _redeemMetadataDelegateId);

Parameters

NameTypeDescription
_directoryIJBDirectoryA directory of terminals and controllers for projects.
_payMetadataDelegateIdbytes4The 4bytes ID of this delegate, used for pay metadata parsing
_redeemMetadataDelegateIdbytes4The 4bytes ID of this delegate, used for redeem metadata parsing

_initialize

Initializes the contract with project details and ERC721 token details.

function _initialize(uint256 _projectId, string memory _name, string memory _symbol) internal;

Parameters

NameTypeDescription
_projectIduint256The ID of the project this contract's functionality applies to.
_namestringThe name of the token.
_symbolstringThe symbol representing the token.

didPay

Mints an NFT to the contributor (_data.beneficiary) upon project payment if conditions are met. Part of IJBPayDelegate.

Reverts if the calling contract is not one of the project's terminals.

function didPay(JBDidPayData3_1_1 calldata _data) external payable virtual override;

Parameters

NameTypeDescription
_dataJBDidPayData3_1_1Standard Juicebox project payment data.

didRedeem

Burns specified NFTs upon token holder redemption, reclaiming funds from the project's balance to _data.beneficiary. Part of IJBRedeemDelegate.

Reverts if the calling contract is not one of the project's terminals.

function didRedeem(JBDidRedeemData3_1_1 calldata _data) external payable virtual override;

Parameters

NameTypeDescription
_dataJBDidRedeemData3_1_1Standard Juicebox project redemption data.

_processPayment

Process a received payment.

function _processPayment(JBDidPayData3_1_1 calldata _data) internal virtual;

Parameters

NameTypeDescription
_dataJBDidPayData3_1_1Standard Juicebox project payment data.

_didBurn

Executes after tokens have been burned via redemption.

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

Parameters

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

Errors

INVALID_PAYMENT_EVENT

error INVALID_PAYMENT_EVENT();

INVALID_REDEMPTION_EVENT

error INVALID_REDEMPTION_EVENT();

UNAUTHORIZED_TOKEN

error UNAUTHORIZED_TOKEN(uint256 _tokenId);

UNEXPECTED_TOKEN_REDEEMED

error UNEXPECTED_TOKEN_REDEEMED();

INVALID_REDEMPTION_METADATA

error INVALID_REDEMPTION_METADATA();