EIP2981TLUpgradeable

Git Source

Inherits: IEIP2981, ERC165Upgradeable

Author: transientlabs.xyz

Abstract contract to define a default royalty spec while allowing for specific token overrides

Follows EIP-2981 (https://eips.ethereum.org/EIPS/eip-2981)

State Variables

EIP2981TLStorageLocation

bytes32 private constant EIP2981TLStorageLocation = 0xe9db8e9b56f2e28e12956850f386d9a4c1e886a4f584b61a10a9d0cacee70700;

BASIS

uint256 public constant BASIS = 10_000;

Functions

_getEIP2981TLStorage

function _getEIP2981TLStorage() private pure returns (EIP2981TLStorage storage $);

__EIP2981TL_init

Function to initialize the contract

function __EIP2981TL_init(address defaultRecipient, uint256 defaultPercentage) internal onlyInitializing;

Parameters

NameTypeDescription
defaultRecipientaddressThe default royalty payout address
defaultPercentageuint256The deafult royalty percentage, out of 10,000

__EIP2981TL_init_unchained

Unchained function to initialize the contract

function __EIP2981TL_init_unchained(address defaultRecipient, uint256 defaultPercentage) internal onlyInitializing;

Parameters

NameTypeDescription
defaultRecipientaddressThe default royalty payout address
defaultPercentageuint256The deafult royalty percentage, out of 10,000

_setDefaultRoyaltyInfo

Function to set default royalty info

function _setDefaultRoyaltyInfo(address newRecipient, uint256 newPercentage) internal;

Parameters

NameTypeDescription
newRecipientaddressThe new default royalty payout address
newPercentageuint256The new default royalty percentage, out of 10,000

_overrideTokenRoyaltyInfo

Function to override royalty spec on a specific token

function _overrideTokenRoyaltyInfo(uint256 tokenId, address newRecipient, uint256 newPercentage) internal;

Parameters

NameTypeDescription
tokenIduint256The token id to override royalty for
newRecipientaddressThe new royalty payout address
newPercentageuint256The new royalty percentage, out of 10,000

royaltyInfo

ERC165 bytes to add to interface array - set in parent contract implementing this standard bytes4(keccak256("royaltyInfo(uint256,uint256)")) == 0x2a55205a

function royaltyInfo(uint256 tokenId, uint256 salePrice)
    external
    view
    returns (address receiver, uint256 royaltyAmount);

Parameters

NameTypeDescription
tokenIduint256The NFT asset queried for royalty information
salePriceuint256The sale price of the NFT asset specified by tokenId

Returns

NameTypeDescription
receiveraddressAddress of who should be sent the royalty payment
royaltyAmountuint256The royalty payment amount for salePrice

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable) returns (bool);

getDefaultRoyaltyRecipientAndPercentage

Query the default royalty receiver and percentage.

function getDefaultRoyaltyRecipientAndPercentage() external view returns (address, uint256);

Returns

NameTypeDescription
<none>addressTuple containing the default royalty recipient and percentage out of 10_000
<none>uint256

Events

DefaultRoyaltyUpdate

Event to emit when the default roylaty is updated

event DefaultRoyaltyUpdate(address indexed sender, address newRecipient, uint256 newPercentage);

TokenRoyaltyOverride

Event to emit when a token royalty is overriden

event TokenRoyaltyOverride(
    address indexed sender, uint256 indexed tokenId, address newRecipient, uint256 newPercentage
);

Errors

ZeroAddressError

error if the recipient is set to address(0)

error ZeroAddressError();

MaxRoyaltyError

error if the royalty percentage is greater than to 100%

error MaxRoyaltyError();

Structs

RoyaltySpec

struct RoyaltySpec {
    address recipient;
    uint256 percentage;
}

EIP2981TLStorage

struct EIP2981TLStorage {
    address defaultRecipient;
    uint256 defaultPercentage;
    mapping(uint256 => RoyaltySpec) tokenOverrides;
}