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

ERC2981 (Royalty Info) for Cairo #413

Merged
merged 35 commits into from
Dec 2, 2024

Conversation

immrsd
Copy link
Contributor

@immrsd immrsd commented Nov 27, 2024

  • Add support for ERC2981 (RoyaltyInfo) to ERC721 and ERC1155
  • Support uint Cairo types in input fields
  • Support constants in trait implementations
image

@immrsd immrsd self-assigned this Nov 27, 2024
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.

The changes look great @immrsd. We should think of a way to group imports together, but that's out of the scope of this PR.

Copy link
Contributor

@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.

Nice work, @immrsd! Overall, the PR looks good to me. I left a few questions and comments

packages/ui/src/cairo/inject-hyperlinks.ts Show resolved Hide resolved
Comment on lines +76 to +77
<RoyaltyInfoSection bind:opts={opts.royaltyInfo} errors={errors} />

Copy link
Contributor

Choose a reason for hiding this comment

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

The window is getting pretty crowded with all the features. Maybe we should consider doing something like having a dropdown menu that opens when the box is checked for votes and royalty? Outside of this PR's scope though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, we should consider that

On the other hand, the Cairo control panels are still more concise that the Solidity ones and if we decide to go with that approach it may make sense to also apply it to the Solidity version

packages/core-cairo/src/set-royalty-info.ts Outdated Show resolved Hide resolved
packages/core-cairo/src/utils/convert-strings.ts Outdated Show resolved Hide resolved
Copy link
Member

@ericglau ericglau left a comment

Choose a reason for hiding this comment

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

Thanks @immrsd, this looks great! Just a few comments.

packages/ui/src/cairo/RoyaltyInfoSection.svelte Outdated Show resolved Hide resolved
packages/ui/src/cairo/inject-hyperlinks.ts Show resolved Hide resolved
packages/core-cairo/src/set-royalty-info.ts Outdated Show resolved Hide resolved
packages/core-cairo/src/contract.ts Outdated Show resolved Hide resolved
packages/core-cairo/src/contract.ts Outdated Show resolved Hide resolved
Comment on lines 15 to 19
export const enabledDefaults: RoyaltyInfoOptions = {
enabled: true,
defaultRoyaltyFraction: '10',
feeDenominator: DEFAULT_FEE_DENOMINATOR.toString()
};
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is only used in generate/erc{1155,721}.ts, which has generator functions for testing different possible combinations. In this case:

  • rename or add a comment to make it more clear that these values are just for testing
  • generate/erc{1155,721}.ts should use an array of the different combinations to test with

For example, define something like the following:

Suggested change
export const enabledDefaults: RoyaltyInfoOptions = {
enabled: true,
defaultRoyaltyFraction: '10',
feeDenominator: DEFAULT_FEE_DENOMINATOR.toString()
};
export const testRoyaltyInfoOptions = [
{
enabled: false,
defaultRoyaltyFraction: '10', // these should be ignored since enabled is false
feeDenominator: DEFAULT_FEE_DENOMINATOR.toString(),
},
{
enabled: true,
defaultRoyaltyFraction: '100',
feeDenominator: DEFAULT_FEE_DENOMINATOR.toString(),
},
{
enabled: true,
defaultRoyaltyFraction: '10000',
feeDenominator: '100000',
];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this is the desired approach, so I've added 3 different options. The only problem is that now instead of 800 generated contracts we have 2000. That shouldn't be a problem, but as a result Scarb compiler required more than 100 GB of RAM at some point during compilation. I've barely managed to compile all the contracts and it took more than 30 minutes

Scarb compiler is not yet well-optimized and this behaviour shouldn't be normal. We should look into it, it seems that some compilation steps that should be O(1) are in fact O(n). Although, I reckon it shouldn't be in the scope of this PR

Screenshot 2024-11-29 at 09 10 36

packages/core-cairo/src/generate/erc1155.ts Outdated Show resolved Hide resolved
packages/core-cairo/src/generate/erc721.ts Outdated Show resolved Hide resolved
packages/core-cairo/src/set-royalty-info.ts Outdated Show resolved Hide resolved
Copy link
Member

@ericglau ericglau left a comment

Choose a reason for hiding this comment

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

It would be good to add some tests in packages/core-cairo/src/erc721.test.ts and packages/core-cairo/src/erc1155.test.ts so that their snapshots are included.

Can you also bump the version in packages/core-cairo/package.json?

The rest LGTM, thanks!

Copy link

socket-security bot commented Dec 2, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@nomicfoundation/[email protected] environment Transitive: eval, filesystem, network, shell, unsafe +775 226 MB kanej
npm/@openzeppelin/[email protected] filesystem Transitive: environment, eval, network, unsafe +78 17.8 MB ericglau

🚮 Removed packages: npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

Copy link

socket-security bot commented Dec 2, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/[email protected]

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@immrsd
Copy link
Contributor Author

immrsd commented Dec 2, 2024

Updated the test project

It would be good to add some tests in packages/core-cairo/src/erc721.test.ts and packages/core-cairo/src/erc1155.test.ts so that their snapshots are included.

Can you also bump the version in packages/core-cairo/package.json?

The rest LGTM, thanks!

Addressed and added tests for royalty info feature for ERC721 and ERC1155

@ericglau
Copy link
Member

ericglau commented Dec 2, 2024

@SocketSecurity ignore npm/[email protected]

Unrelated to this PR.

@immrsd immrsd merged commit 2bf262c into OpenZeppelin:master Dec 2, 2024
9 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.

4 participants