Skip to main content

JB721Delegate

Delegate that offers project contributors NFTs upon payment and the ability to redeem NFTs for treasury assets.


Git Source

Inherits: IJB721Delegate, IJBFundingCycleDataSource, IJBPayDelegate, IJBRedemptionDelegate, ERC721

Adheres to -

  • IJB721Delegate: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
  • IJBFundingCycleDataSource: Allows this contract to be attached to a funding cycle to have its methods called during regular protocol operations.
  • IJBPayDelegate: Allows this contract to receive callbacks when a project receives a payment. IJBRedemptionDelegate: Allows this contract to receive callbacks when a token holder redeems.

Inherits from -

  • ERC721: A standard definition for non-fungible tokens (NFTs).

State Variables

projectId

The ID of the project this contract's functionality applies to.

uint256 public override projectId;

directory

The directory of terminals and controllers for projects.

IJBDirectory public override directory;

Functions

payParams

Part of IJBFundingCycleDataSource, this function gets called when the project receives a payment. It will set itself as the delegate to get a callback from the terminal.

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

Parameters

NameTypeDescription
_dataJBPayParamsDataThe Juicebox standard project payment data.

Returns

NameTypeDescription
weightuint256The weight that tokens should get minted in accordance with.
memostringThe memo that should be forwarded to the event.
delegateAllocationsJBPayDelegateAllocation[]The amount to send to delegates instead of adding to the local balance.

redeemParams

Part of IJBFundingCycleDataSource, this function gets called when a project's token holders redeem.

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

Parameters

NameTypeDescription
_dataJBRedeemParamsDataThe Juicebox standard project redemption data.

Returns

NameTypeDescription
reclaimAmountuint256The amount that should be reclaimed from the treasury.
memostringThe memo that should be forwarded to the event.
delegateAllocationsJBRedemptionDelegateAllocation[]The amount to send to delegates instead of adding to the beneficiary.

redemptionWeightOf

The cumulative weight the given token IDs have in redemptions compared to the totalRedemptionWeight.

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

Parameters

NameTypeDescription
_tokenIdsuint256[]The IDs of the tokens to get the cumulative redemption weight of.
_dataJBRedeemParamsDataThe Juicebox standard project redemption data.

Returns

NameTypeDescription
<none>uint256The weight.

totalRedemptionWeight

The cumulative weight that all token IDs have in redemptions.

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

Parameters

NameTypeDescription
_dataJBRedeemParamsDataThe Juicebox standard project redemption data.

Returns

NameTypeDescription
<none>uint256The total weight.

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.

_initialize

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

Parameters

NameTypeDescription
_projectIduint256The ID of the project this contract's functionality applies to.
_directoryIJBDirectoryThe directory of terminals and controllers for projects.
_namestringThe name of the token.
_symbolstringThe symbol that the token should be represented by.

didPay

Part of IJBPayDelegate, this function gets called when the project receives a payment. It will mint an NFT to the contributor (_data.beneficiary) if conditions are met.

This function will revert if the contract calling is not one of the project's terminals.

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

Parameters

NameTypeDescription
_dataJBDidPayDataThe Juicebox standard project payment data.

didRedeem

Part of IJBRedeemDelegate, this function gets called when the token holder redeems. It will burn the specified NFTs to reclaim from the treasury to the _data.beneficiary.

This function will revert if the contract calling is not one of the project's terminals.

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

Parameters

NameTypeDescription
_dataJBDidRedeemDataThe Juicebox standard project redemption data.

_processPayment

Process a received payment.

function _processPayment(JBDidPayData calldata _data) internal virtual;

Parameters

NameTypeDescription
_dataJBDidPayDataThe Juicebox standard project payment data.

_didBurn

A function that will run when tokens are 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

error UNAUTHORIZED();

UNEXPECTED_TOKEN_REDEEMED

error UNEXPECTED_TOKEN_REDEEMED();

INVALID_REDEMPTION_METADATA

error INVALID_REDEMPTION_METADATA();