diff --git a/contract/contracts/@eip2981/ERC2981Base.sol b/contract/contracts/@eip2981/ERC2981Base.sol new file mode 100644 index 0000000..9e0d7e9 --- /dev/null +++ b/contract/contracts/@eip2981/ERC2981Base.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GNU General Public License v3.0 +pragma solidity ^0.8.10; + +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; + +import "./IERC2981Royalties.sol"; + +/// @dev This is a contract used to add ERC2981 support to ERC721 and 1155 +abstract contract ERC2981Base is ERC165, IERC2981Royalties { + struct RoyaltyInfo { + address recipient; + uint24 amount; + } + + /// @inheritdoc ERC165 + function supportsInterface(bytes4 interfaceId) + public + view + virtual + override + returns (bool) + { + return + interfaceId == type(IERC2981Royalties).interfaceId || + super.supportsInterface(interfaceId); + } +} diff --git a/contract/contracts/@eip2981/ERC2981ContractWideRoyalties.sol b/contract/contracts/@eip2981/ERC2981ContractWideRoyalties.sol new file mode 100644 index 0000000..ec52e8a --- /dev/null +++ b/contract/contracts/@eip2981/ERC2981ContractWideRoyalties.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GNU General Public License v3.0 +pragma solidity ^0.8.10; + +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; + +import "./ERC2981Base.sol"; + +/// @dev This is a contract used to add ERC2981 support to ERC721 and 1155 +/// @dev This implementation has the same royalties for each and every tokens +abstract contract ERC2981ContractWideRoyalties is ERC2981Base { + RoyaltyInfo private _royalties; + + /// @dev Sets token royalties + /// @param recipient recipient of the royalties + /// @param value percentage (using 2 decimals - 10000 = 100, 0 = 0) + function _setRoyalties(address recipient, uint256 value) internal { + require(value <= 10000, "ERC2981Royalties: Too high"); + _royalties = RoyaltyInfo(recipient, uint24(value)); + } + + /// @inheritdoc IERC2981Royalties + function royaltyInfo(uint256, uint256 value) + external + view + override + returns (address receiver, uint256 royaltyAmount) + { + RoyaltyInfo memory royalties = _royalties; + receiver = royalties.recipient; + royaltyAmount = (value * royalties.amount) / 10000; + } +} diff --git a/contract/contracts/@eip2981/IERC2981Royalties.sol b/contract/contracts/@eip2981/IERC2981Royalties.sol new file mode 100644 index 0000000..eabf3e5 --- /dev/null +++ b/contract/contracts/@eip2981/IERC2981Royalties.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GNU General Public License v3.0 +pragma solidity ^0.8.10; + +/// @title IERC2981Royalties +/// @dev Interface for the ERC2981 - Token Royalty standard +interface IERC2981Royalties { + /// @notice Called with the sale price to determine how much royalty is owed and to whom. + /// @param _tokenId - the NFT asset queried for royalty information + /// @param _value - the sale price of the NFT asset specified by _tokenId + /// @return _receiver - address of who should be sent the royalty payment + /// @return _royaltyAmount - the royalty payment amount for value sale price + function royaltyInfo(uint256 _tokenId, uint256 _value) + external + view + returns (address _receiver, uint256 _royaltyAmount); +} diff --git a/contract/contracts/PixelAvatars.sol b/contract/contracts/PixelAvatars.sol index e905636..aba069b 100644 --- a/contract/contracts/PixelAvatars.sol +++ b/contract/contracts/PixelAvatars.sol @@ -5,13 +5,15 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "./@eip2981/ERC2981ContractWideRoyalties.sol"; /// @author Developer DAO /// @title The Pixel Avatar smart contract that is compliant to ERC721 standard and is upgradeable contract PixelAvatars is ERC721EnumerableUpgradeable, ReentrancyGuardUpgradeable, - OwnableUpgradeable + OwnableUpgradeable, + ERC2981ContractWideRoyalties { string public baseURI; uint256 public mintPrice; @@ -29,6 +31,8 @@ contract PixelAvatars is __ERC721_init("Pixel Avatars", "PXLDEV"); __Ownable_init(); + setRoyalties(1000); // On initialize set 10% royalty fee + baseURI = "ipfs://QmZdT5R5XGQVwGnnpiS6dGjUHZh6z8JjpuHhsqcLMMeWiC/"; mintPrice = 12 ether; @@ -37,8 +41,9 @@ contract PixelAvatars is // mintPrice = 0.01 ether; } - function _baseURI() internal view virtual override returns (string memory) { - return baseURI; + /// @param amount The amount of royalties to be set + function setRoyalties(uint256 amount) external onlyOwner { + _setRoyalties(msg.sender, amount); } function setBaseURI(string memory _newBaseURI) external onlyOwner { @@ -103,4 +108,8 @@ contract PixelAvatars is function withdraw() external onlyOwner { payable(msg.sender).transfer(address(this).balance); } + + function _baseURI() internal view virtual override returns (string memory) { + return baseURI; + } }