Skip to content

Commit

Permalink
feat: CollectNFT now implements EIP-2981 royalty standard
Browse files Browse the repository at this point in the history
  • Loading branch information
donosonaumczuk committed Aug 20, 2022
1 parent 8f00a6f commit 6369189
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions contracts/core/CollectNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
pragma solidity 0.8.10;

import {ICollectNFT} from '../interfaces/ICollectNFT.sol';
import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import {ILensHub} from '../interfaces/ILensHub.sol';
import {Errors} from '../libraries/Errors.sol';
import {Events} from '../libraries/Events.sol';
import {LensNFTBase} from './base/LensNFTBase.sol';
import {ERC721Enumerable} from './base/ERC721Enumerable.sol';

/**
* @title CollectNFT
Expand All @@ -24,11 +26,18 @@ contract CollectNFT is LensNFTBase, ICollectNFT {

bool private _initialized;

uint256 internal _royaltyBasisPoints;

// bytes4(keccak256('royaltyInfo(uint256,uint256)')) == 0x2a55205a
bytes4 internal constant INTERFACE_ID_ERC2981 = 0x2a55205a;
uint16 internal constant BASIS_POINTS = 10000;

// We create the CollectNFT with the pre-computed HUB address before deploying the hub proxy in order
// to initialize the hub proxy at construction.
constructor(address hub) {
if (hub == address(0)) revert Errors.InitParamsInvalid();
HUB = hub;
_royaltyBasisPoints = 1000; // 10% of royalties
_initialized = true;
}

Expand Down Expand Up @@ -67,6 +76,58 @@ contract CollectNFT is LensNFTBase, ICollectNFT {
return ILensHub(HUB).getContentURI(_profileId, _pubId);
}

/**
* @notice Changes the royalty percentage for secondary sales. Can only be called publication's
* profile owner.
*
* @param royaltyBasisPoints The royalty percentage meassured in basis points. Each basis point
* represents 0.01%.
*/
function setRoyalty(uint256 royaltyBasisPoints) external {
if (IERC721(HUB).ownerOf(_profileId) == msg.sender) {
if (royaltyBasisPoints > BASIS_POINTS) {
revert Errors.InvalidParameter();
} else {
_royaltyBasisPoints = royaltyBasisPoints;
}
} else {
revert Errors.NotProfileOwner();
}
}

/**
* @notice Called with the sale price to determine how much royalty
* is owed and to whom.
*
* @param tokenId The token ID of the NFT queried for royalty information.
* @param salePrice The sale price of the NFT specified.
* @return A tuple with the address who should receive the royalties and the royalty
* payment amount for the given sale price.
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address, uint256)
{
return (
IERC721(HUB).ownerOf(_profileId),
(salePrice * _royaltyBasisPoints) / BASIS_POINTS
);
}

/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Enumerable)
returns (bool)
{
return interfaceId == INTERFACE_ID_ERC2981 || super.supportsInterface(interfaceId);
}

/**
* @dev Upon transfers, we emit the transfer event in the hub.
*/
Expand Down

0 comments on commit 6369189

Please sign in to comment.