EIP2981TL

Git Source

Inherits: IEIP2981, ERC165

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

BASIS

uint256 public constant BASIS = 10_000;

_defaultRecipient

address private _defaultRecipient;

_defaultPercentage

uint256 private _defaultPercentage;

_tokenOverrides

mapping(uint256 => RoyaltySpec) private _tokenOverrides;

Functions

constructor

constructor(address defaultRecipient, uint256 defaultPercentage);

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(ERC165) 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;
}