Skip to content

Conversation

@aapsi
Copy link
Contributor

@aapsi aapsi commented Oct 26, 2025

Add ERC-2981 NFT Royalty Standard Implementation

Summary

This PR implements the ERC-2981 NFT Royalty Standard using Compose's diamond storage pattern. The implementation provides a read-only facet with the standard royaltyInfo() function, along with a comprehensive library containing setter functions for configuring royalties.

What's Included

  • ERC2981Facet.sol - Facet with royaltyInfo(uint256 _tokenId, uint256 _salePrice) query function
  • LibERC2981.sol - Library with internal functions for:
    • setDefaultRoyalty() - Set default royalty for all tokens
    • deleteDefaultRoyalty() - Remove default royalty configuration
    • setTokenRoyalty() - Set per-token royalty (overrides default)
    • resetTokenRoyalty() - Reset token to use default royalty
  • IERC2981.sol - Interface with ERC-2981 function signature and custom errors
  • Full test suite (pending - see below)

Implementation Details

Follows Compose Conventions:

  • Diamond storage pattern with keccak256("compose.erc2981")
  • ERC-8042 compliant storage annotation
  • No inheritance, constructors, or modifiers
  • Proper error definitions matching ERC-6093 style
  • Comprehensive NatSpec documentation

ERC-2981 Compliant:

  • Implements required royaltyInfo() function
  • Percentage-based calculation using 10000 basis points
  • Supports both default and per-token royalty configurations
  • Returns (address receiver, uint256 royaltyAmount) as specified

Question for Maintainers ( @mudgen @maxnorm @panditdhamdhere @Haroldwonder ): Access Control Pattern

The library provides internal setter functions, but the facet intentionally does not expose these as external functions yet. This allows the maintainers to decide on the appropriate access control pattern.

the relavant issue is : Add ERC-2981 royalties facet #42

@github-actions
Copy link

github-actions bot commented Oct 26, 2025

Coverage Report

Coverage

Metric Coverage Details
Lines 40% 423/1045 lines
Functions 55% 101/183 functions
Branches 25% 45/177 branches

Last updated: Mon, 27 Oct 2025 05:53:40 GMT for commit c95c69a

Implements the ERC-2981 standard for NFT royalty information using Compose's diamond storage pattern. This implementation provides:

- ERC2981Facet with royaltyInfo() query function
- LibERC2981 library with internal setter functions for royalty configuration
- Support for both default and per-token royalty settings
- IERC2981 interface with custom errors

Note: External setter functions are intentionally omitted from the facet to allow maintainers to decide on the appropriate access control pattern (e.g., owner-only, role-based, or public with token ownership checks).

Tests will be added once the final contract design and access control approach are confirmed.
@aapsi aapsi force-pushed the erc2981-implementation branch from 4deed08 to 52c9f4a Compare October 26, 2025 20:44
Copy link
Contributor

@mudgen mudgen left a comment

Choose a reason for hiding this comment

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

Looking good! Good job.

Can you please rename the files and facet and library name, etc. Replace ERC2981 in the names of things to Royalty. For example instead of LibERC2981 change it to LibRoyalty. Change ERC2981Facet to RoyaltyFacet. But continue using the standard errors with their current names.

Also can you please put these files in the token folder, and take the Lib file out of the libraries file and delete the libraries file.

Definitely have it in the comments that this is an implementation of ERC-2981.

aapsi added 2 commits October 27, 2025 11:11
Introduce LibRoyalty library and RoyaltyFacet contract to implement the ERC-2981 NFT royalty standard.
@aapsi
Copy link
Contributor Author

aapsi commented Oct 27, 2025

@mudgen @panditdhamdhere Done! I've made all the requested changes:

Renaming

  • ERC2981FacetRoyaltyFacet
  • LibERC2981LibRoyalty
  • ERC2981StorageRoyaltyStorage
  • Error names remain unchanged

File Structure

  • Files moved to src/token/Royalty/ (flat structure)
  • Removed the libraries/ subfolder
  • Old src/ERC2981/ directory deleted

Documentation

  • Added comments in both files noting "This is an implementation of the ERC-2981 NFT Royalty Standard"

All logic remains 100% identical - only names and file locations changed.

@aapsi aapsi marked this pull request as ready for review October 27, 2025 07:08
Copy link
Collaborator

@maxnorm maxnorm left a comment

Choose a reason for hiding this comment

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

Everything looks good. Thanks for the great work @aapsi !

For your previous question, you can leave it like that. Access control isn't define by Compose. Doing that will break our goal of reusable composition

For any custom logic/restriction, the user of Compose will create it's own facet using the core function of the lib while wrapping it with their custom needs.

The diamond will look like this:

royaltyInfo() -> RoyaltyFacet
setDefaultRoyalty() -> CustomFacet

By using the lib in their custom facets, the users are playing with the same storage location as the RoyaltyFacet from Compose

@aapsi
Copy link
Contributor Author

aapsi commented Oct 27, 2025

@maxnorm Thank you for the response!! This solidifies my understanding of the Compose and it's goal.

@maxnorm
Copy link
Collaborator

maxnorm commented Oct 27, 2025

You can also refer to the new section Understanding Facets and Libraries in the README that explain it in more details

Thanks to you for your great contribution!

@maxnorm maxnorm merged commit 36f735d into Perfect-Abstractions:main Oct 27, 2025
3 checks passed
JackieXu pushed a commit to JackieXu/Compose that referenced this pull request Nov 6, 2025
…entation

Add ERC-2981 NFT Royalty Standard implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants