Files
openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721Royalty.sol
2023-06-30 18:40:55 +02:00

48 lines
1.8 KiB
Solidity

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Royalty.sol)
pragma solidity ^0.8.19;
import {ERC721} from "../ERC721.sol";
import {ERC2981} from "../../common/ERC2981.sol";
import {ERC165} from "../../../utils/introspection/ERC165.sol";
/**
* @dev Extension of ERC721 with the ERC2981 NFT Royalty Standard, a standardized way to retrieve royalty payment
* information.
*
* Royalty information can be specified globally for all token ids via {ERC2981-_setDefaultRoyalty}, and/or individually for
* specific token ids via {ERC2981-_setTokenRoyalty}. The latter takes precedence over the first.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*
* _Available since v4.5._
*/
abstract contract ERC721Royalty is ERC2981, ERC721 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC2981) returns (bool) {
return super.supportsInterface(interfaceId);
}
/**
* @dev See {ERC721-_update}. This override additionally clears the royalty information for the token.
*/
function _update(
address to,
uint256 tokenId,
function(address, address, uint256) view constraints
) internal virtual override returns (address) {
address from = super._update(to, tokenId, constraints);
if (to == address(0)) {
_resetTokenRoyalty(tokenId);
}
return from;
}
}