Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Royalty Info External Traits #1173

Merged
merged 38 commits into from
Oct 23, 2024
Merged

Conversation

immrsd
Copy link
Member

@immrsd immrsd commented Oct 2, 2024

Fixes #1172

Key Changes:

  • Introduces IERC2981StateInfo and IERC2981Admin traits with ERC2981 external functions
  • Provides ready-made implementations (2 impl versions for IERC2981Admin: with Ownable or AccessControl)
  • Tests the new trait implementations

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.57%. Comparing base (7ac655c) to head (7c69560).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/token/src/common/erc2981/erc2981.cairo 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1173      +/-   ##
==========================================
- Coverage   91.89%   91.57%   -0.32%     
==========================================
  Files          47       47              
  Lines        1197     1223      +26     
==========================================
+ Hits         1100     1120      +20     
- Misses         97      103       +6     
Files with missing lines Coverage Δ
packages/token/src/common/erc2981/erc2981.cairo 86.79% <95.65%> (-9.51%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ac655c...7c69560. Read the comment docs.

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

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

Looking great @immrsd! This is certainly very helpful and the code looks neat. Left a few small suggestions but is pretty much ready to go.

packages/token/src/common/erc2981/interface.cairo Outdated Show resolved Hide resolved
packages/token/src/common/erc2981/erc2981.cairo Outdated Show resolved Hide resolved
packages/token/src/common/erc2981/erc2981.cairo Outdated Show resolved Hide resolved
packages/token/Scarb.toml Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/token_common.adoc Outdated Show resolved Hide resolved
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Very nice work! I appreciate that the features are opt in :) I left a few comments

Comment on lines 222 to 223
// Role for the admin responsible for managing royalty settings.
pub const ROYALTY_ADMIN_ROLE: felt252 = 'ROYALTY_ADMIN_ROLE';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Role for the admin responsible for managing royalty settings.
pub const ROYALTY_ADMIN_ROLE: felt252 = 'ROYALTY_ADMIN_ROLE';
// Role for the admin responsible for managing royalty settings.
pub const ROYALTY_ADMIN_ROLE: felt252 = selector!("ROYALTY_ADMIN_ROLE");

For consistency with how we've been calculating role ids

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw, what's the rationale behind that? From my point of view felt-strings would be a better choice since they are easier to work with (automatically decoded in block scanners) and the only drawback of 31 char limit is not actually bad for defining a role

And as an additional minor neat thing: no collision between two different roles can happen

Comment on lines 322 to 326
[.contract-item]
[[IERC2981AdminAccessControlImpl-ROYALTY_ADMIN_ROLE]]
==== `[.contract-item-name]#++ROYALTY_ADMIN_ROLE:++#++ felt252++` [.item-kind]#constant#

Role for the admin responsible for managing royalty settings.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Though this is only supposed to be used within the context of the impl, it's accessible from the base 2981 component. AFAIK we have't defined component constants in the other APIs so we should probably come up with something universal (if not now then sometime soon). I imagine we should have a dedicated constants block or something more intentional

Copy link
Member Author

@immrsd immrsd Oct 18, 2024

Choose a reason for hiding this comment

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

it's accessible from the base 2981 component

I think it's fine, the ERC2981AdminAccessControlImpl is accessible from the base component as well

What do you suggest in this case? Placing the role constant in a constants block this way?

//
// AccessControl-based admin functions
//

//
// Constants
//

// Role for the admin responsible for managing royalty settings.
pub const ROYALTY_ADMIN_ROLE: felt252 = selector!("ROYALTY_ADMIN_ROLE");

#[embeddable_as(ERC2981AdminAccessControlImpl)]
    impl ERC2981AdminAccessControl<
...

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

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

Left s couple of small suggestion but besides it looks ready to me.

CHANGELOG.md Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/token_common.adoc Outdated Show resolved Hide resolved
packages/token/src/common/erc2981/erc2981.cairo Outdated Show resolved Hide resolved
Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

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

LGTM!

@immrsd immrsd merged commit 8bc869b into OpenZeppelin:main Oct 23, 2024
8 checks passed
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.

ERC2981 External Traits
3 participants