-
Notifications
You must be signed in to change notification settings - Fork 41
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
[Feature]: ERC2981 contract #508
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for contracts-stylus canceled.
|
@0xNeshi In the OpenZeppelin Solidity Contracts codebase, ERC-2981 functions were implemented separately under Contracts/Token/Common/ERC2981.sol. |
Good catch! You can continue working the way you started, I think it will be easy to move the contract file if necessary. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many missing changes/tests/docs. See examples of other extension PRs for inspiration on what needs to be added, e.g. Erc1155Burnable
Ok I'll check it out and fix it |
@0xNeshi Should I fix this PR or wait?
|
Hey @18aaddy , the team talked about this internally and we'd actually want to have Ping us we you need us to clarify anything or if you need any help! |
Ok I'll work on it |
5610195
to
8a2592a
Compare
@0xNeshi Can you review? I've made this PR for ERC2981 contract and I'll open a new one for the ERC721Royalty extension. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @18aaddy!
Please adjust docs to rest of our contracts, e.g.:
- Start each error with
*
etc. - Make sure each fn argument is described in Rust docs
- Get rid of links like
{_setTokenRoyalty}
and use proper Rust docs links
Also please:
- Remove
interface_id
fromIErc2981
trait definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good work! Below are mostly nits
//! royalty payment information. | ||
//! | ||
//! Royalty information can be specified globally for all token ids via | ||
//! {_setDefaultRoyalty}, and/or individually for specific token ids via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to link to actual Rust functions (see other contracts' docs for examples)
//! IMPORTANT: ERC-2981 only specifies a way to signal royalty information and | ||
//! does not enforce its payment. | ||
//! | ||
//! See `<https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments>` in the ERC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! See `<https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments>` in the ERC. | |
//! See <https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments> in the ERC. |
I don't think you need backticks
/// Indicates an error for Invalid Token Royalty. Occurs when | ||
/// fee_numerator > denominator | ||
#[derive(Debug)] | ||
#[allow(missing_docs)] | ||
error ERC2981InvalidTokenRoyalty(uint256 tokenId, uint256 numerator, uint256 denominator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have certain conventions that should be followed:
- Use the same error message in the
sol!
macro that we use in thepub enum Error
below it. - Error arguments should be documented (e.g. see error docs for Erc1155)
- use Rust's snake_case for argument names even in
sol!
macro. - nit:
fee_numerator
doesn't exist;numerator
does
/// Struct for Royalty Information for tokens. | ||
/// | ||
/// # Fields | ||
/// | ||
/// * `receiver` - The receiver address for royalty | ||
/// * `royalty_fraction` - Fraction of royalty for receiver | ||
#[storage] | ||
#[derive(Erase)] | ||
pub struct RoyaltyInfo { | ||
receiver: StorageAddress, | ||
royalty_fraction: StorageU96, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove # Fields
section and move each fields docs above the respective fields
royalty_fraction: StorageU96, | ||
} | ||
|
||
/// State of an ERC2981 contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// State of an ERC2981 contract. | |
/// State of an [`Erc2981`] contract. |
/// Function to change the denominator with which to interpret the fee set | ||
/// in _setTokenRoyalty and _setDefaultRoyalty as a fraction of the sale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Function to change the denominator with which to interpret the fee set | |
/// in _setTokenRoyalty and _setDefaultRoyalty as a fraction of the sale | |
/// Changes the denominator with which to interpret the fee set | |
/// in _setTokenRoyalty and _setDefaultRoyalty as a fraction of the sale |
nit: it's obviously a function. Update all relevant comments the same way.
Also this should link to the actual Rust functions
receiver: Address, | ||
fee_numerator: U96, | ||
) -> Result<(), Error> { | ||
let denominator: U256 = U256::from(self._fee_denominator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make the conversion when emitting the error, when actually necessary
/// | ||
/// # Arguments | ||
/// | ||
/// * `&mut self` - Write access to the contract's state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing token_id
const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); | ||
const DAVE: Address = address!("0BB78F7e7132d1651B4Fd884B7624394e92156F1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to hardcode addresses. In the current motsu version you can list addresses/accounts that you need in the test fn signature
@@ -0,0 +1,514 @@ | |||
//! Implementation of the NFT Royalty Standard, a standardized way to retrieve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Missing CHANGELOG entry.
- Missing *.adoc files, see Solidity version here.
- Missing e2e tests - add at least happy flow for
Erc2981::royalty_info
Towards #358
PR Checklist