RoyaltyFacet
Returns royalty information for tokens
- Implements ERC-2981
royaltyInfofunction for external querying. - Accesses royalty data via diamond storage.
- Supports token-specific and default royalty configurations.
- Self-contained, no external dependencies beyond diamond storage access.
Overview
This facet implements ERC-2981 royalty information retrieval for tokens within a diamond. It provides an external function to query royalty details based on token ID and sale price, falling back to default royalty settings if token-specific royalties are not defined. This facet enables standard royalty distribution mechanisms for NFTs.
Storage
RoyaltyInfo
RoyaltyStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.erc2981")) |
FEE_DENOMINATOR | uint96 | (Value: 10000) |
Functions
royaltyInfo
Returns royalty information for a given token and sale price. Returns token-specific royalty if set, otherwise falls back to default royalty. Royalty amount is calculated as a percentage of the sale price using basis points. Implements the ERC-2981 royaltyInfo function.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The NFT asset queried for royalty information. |
_salePrice | uint256 | The sale price of the NFT asset specified by _tokenId. |
Returns:
| Property | Type | Description |
|---|---|---|
receiver | address | The address designated to receive the royalty payment. |
royaltyAmount | uint256 | The royalty payment amount for _salePrice. |
Best Practices
- Initialize default royalty information during diamond setup.
- Ensure the
RoyaltyStoragestruct is correctly placed in diamond storage. - Verify compatibility with the ERC-2981 standard for downstream integrations.
Security Considerations
Follow standard Solidity security practices. The royaltyInfo function is a view function and does not modify state. Input validation for _tokenId and _salePrice is implicitly handled by Solidity's type system. Ensure correct initialization of default royalties to prevent unintended distribution.