ERC-2981
ERC2981
Authors: Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC2981.sol), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/common/ERC2981.sol), Ninfa.io removed unused code
Simple ERC2981 NFT Royalty Standard implementation.
State Variables
_ERC2981_MASTER_SLOT_SEED
*The default royalty info is given by:
let packed := sload(_ERC2981_MASTER_SLOT_SEED)
let receiver := shr(96, packed)
let royaltyFraction := xor(packed, shl(96, receiver))The per token royalty info is given by.
mstore(0x00, tokenId)
mstore(0x20, _ERC2981_MASTER_SLOT_SEED)
let packed := sload(keccak256(0x00, 0x40))
let receiver := shr(96, packed)
let royaltyFraction := xor(packed, shl(96, receiver))
```*
```solidity
uint256 private constant _ERC2981_MASTER_SLOT_SEED = 0xaa4ec00224afccfdb7;Functions
_feeDenominator
Checks that _feeDenominator is non-zero.
Returns the denominator for the royalty amount. Defaults to 10000, which represents fees in basis points. Override this function to return a custom amount if needed.
royaltyInfo
Returns the receiver and royaltyAmount for tokenId sold at salePrice. It first attempts to read the per-token royalty information for the given tokenId by computing a storage slot using the tokenId and a predefined constant (_ERC2981_MASTER_SLOT_SEED). If no specific royalty information is found for the tokenId (i.e., the receiver address is zero), it then reads the default royalty information stored at the slot determined by _ERC2981_MASTER_SLOT_SEED directly.
_setDefaultRoyalty
*Sets the default royalty receiver and feeNumerator. Sets the default royalty receiver and amount, which stores the information in a packed format in the slot determined by _ERC2981_MASTER_SLOT_SEED. This default royalty information is then used by the royaltyInfo function whenever a specific token does not have its royalty information set. Requirements:
receivermust not be the zero address.feeNumeratormust not be greater than the fee denominator.*
_setTokenRoyalty
*Sets the royalty receiver and feeNumerator for tokenId. Requirements:
receivermust not be the zero address.feeNumeratormust not be greater than the fee denominator.*
_resetTokenRoyalty
Sets the royalty receiver and feeNumerator for tokenId to zero.
Errors
RoyaltyOverflow
The royalty fee numerator exceeds the fee denominator.
RoyaltyReceiverIsZeroAddress
The royalty receiver cannot be the zero address.
Last updated