Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions contract/contracts/@eip2981/ERC2981Base.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
32 changes: 32 additions & 0 deletions contract/contracts/@eip2981/ERC2981ContractWideRoyalties.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions contract/contracts/@eip2981/IERC2981Royalties.sol
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 12 additions & 3 deletions contract/contracts/PixelAvatars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add /// @author Developer DAO to all files you edited?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noahliechti

For the ERC2981 was a code copied from a repo.

But what are your thinks if adding and @author tag on a code that wasn't originally created here?

/// @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;
Expand All @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
}