跳到主要内容

JB721Hook

Git Source

Inherits: ERC721, IJB721Hook

When a project which uses this hook is paid, this hook may mint NFTs to the payer, depending on this hook's setup, the amount paid, and information specified by the payer. The project's owner can enable NFT cash outs. through this hook, allowing the NFT holders to burn their NFTs to reclaim funds from the project (in proportion to the NFT's price).

State Variables

DIRECTORY

The directory of terminals and controllers for projects.

IJBDirectory public immutable override DIRECTORY;

METADATA_ID_TARGET

The ID used when parsing metadata.

address public immutable override METADATA_ID_TARGET;

PROJECT_ID

The ID of the project that this contract is associated with.

uint256 public override PROJECT_ID;

Functions

constructor

constructor(IJBDirectory directory);

Parameters

NameTypeDescription
directoryIJBDirectoryA directory of terminals and controllers for projects.

beforePayRecordedWith

The data calculated before a payment is recorded in the terminal store. This data is provided to the terminal's pay(...) transaction.

Sets this contract as the pay hook. Part of IJBRulesetDataHook.

function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
public
view
virtual
override
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications);

Parameters

NameTypeDescription
contextJBBeforePayRecordedContextThe payment context passed to this contract by the pay(...) function.

Returns

NameTypeDescription
weightuint256The new weight to use, overriding the ruleset's weight.
hookSpecificationsJBPayHookSpecification[]The amount and data to send to pay hooks (this contract) instead of adding to the terminal's balance.

beforeCashOutRecordedWith

The data calculated before a cash out is recorded in the terminal store. This data is provided to the terminal's cashOutTokensOf(...) transaction.

Sets this contract as the cash out hook. Part of IJBRulesetDataHook.

This function is used for NFT cash outs, and will only be called if the project's ruleset has useDataHookForCashOut set to true.

function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
public
view
virtual
override
returns (
uint256 cashOutTaxRate,
uint256 cashOutCount,
uint256 totalSupply,
JBCashOutHookSpecification[] memory hookSpecifications
);

Parameters

NameTypeDescription
contextJBBeforeCashOutRecordedContextThe cash out context passed to this contract by the cashOutTokensOf(...) function.

Returns

NameTypeDescription
cashOutTaxRateuint256The cash out tax rate influencing the reclaim amount.
cashOutCountuint256The amount of tokens that should be considered cashed out.
totalSupplyuint256The total amount of tokens that are considered to be existing.
hookSpecificationsJBCashOutHookSpecification[]The amount and data to send to cash out hooks (this contract) instead of returning to the beneficiary.

hasMintPermissionFor

Required by the IJBRulesetDataHook interfaces. Return false to not leak any permissions.

function hasMintPermissionFor(uint256, address) external pure returns (bool);

cashOutWeightOf

Returns the cumulative cash out weight of the specified token IDs relative to the totalCashOutWeight.

function cashOutWeightOf(
uint256[] memory tokenIds,
JBBeforeCashOutRecordedContext calldata context
)
public
view
virtual
returns (uint256);

Parameters

NameTypeDescription
tokenIdsuint256[]The NFT token IDs to calculate the cumulative cash out weight of.
contextJBBeforeCashOutRecordedContextThe cash out context passed to this contract by the cashOutTokensOf(...) function.

Returns

NameTypeDescription
<none>uint256The cumulative cash out weight of the specified 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.

totalCashOutWeight

Calculates the cumulative cash out weight of all NFT token IDs.

function totalCashOutWeight(JBBeforeCashOutRecordedContext calldata context) public view virtual returns (uint256);

Parameters

NameTypeDescription
contextJBBeforeCashOutRecordedContextThe cash out context passed to this contract by the cashOutTokensOf(...) function.

Returns

NameTypeDescription
<none>uint256The total cumulative cash out weight of all NFT token IDs.

_initialize

Initializes the contract by associating it with a project and adding ERC721 details.

function _initialize(uint256 projectId, string memory name, string memory symbol) internal;

Parameters

NameTypeDescription
projectIduint256The ID of the project that this contract is associated with.
namestringThe name of the NFT collection.
symbolstringThe symbol representing the NFT collection.

afterPayRecordedWith

Mints one or more NFTs to the context.benficiary upon payment if conditions are met. Part of IJBPayHook.

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

function afterPayRecordedWith(JBAfterPayRecordedContext calldata context) external payable virtual override;

Parameters

NameTypeDescription
contextJBAfterPayRecordedContextThe payment context passed in by the terminal.

afterCashOutRecordedWith

Burns the specified NFTs upon token holder cash out, reclaiming funds from the project's balance for context.beneficiary. Part of IJBCashOutHook.

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

function afterCashOutRecordedWith(JBAfterCashOutRecordedContext calldata context) external payable virtual override;

Parameters

NameTypeDescription
contextJBAfterCashOutRecordedContextThe cash out context passed in by the terminal.

_didBurn

Executes after NFTs have been burned via cash out.

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

Parameters

NameTypeDescription
tokenIdsuint256[]The token IDs of the NFTs that were burned.

_processPayment

Process a received payment.

function _processPayment(JBAfterPayRecordedContext calldata context) internal virtual;

Parameters

NameTypeDescription
contextJBAfterPayRecordedContextThe payment context passed in by the terminal.

Errors

JB721Hook_InvalidPay

error JB721Hook_InvalidPay();

JB721Hook_InvalidCashOut

error JB721Hook_InvalidCashOut();

JB721Hook_UnauthorizedToken

error JB721Hook_UnauthorizedToken(uint256 tokenId, address holder);

JB721Hook_UnexpectedTokenCashedOut

error JB721Hook_UnexpectedTokenCashedOut();