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

Migrate ERC20Votes to component #951

Merged
merged 40 commits into from
Apr 12, 2024

Conversation

ericnordelo
Copy link
Member

@ericnordelo ericnordelo commented Mar 22, 2024

Fixes #815

PR Checklist

  • Tests
  • Documentation
  • Added entry to CHANGELOG.md
  • Tried the feature on a public network

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.

The component migration looks really, really good!

I left some mostly small comments and questions—the most noteworthy, I think, is the idea of adding a default hook impl for ERC20 contracts in the ERC20 module. The benefit of this is that contracts can just import the default impl in their contract if there's no additional before/after_update logic (instead of recreating the impl that essentially does nothing). Let me know what you think

src/governance/utils/interfaces/votes.cairo Outdated Show resolved Hide resolved
src/utils/structs/checkpoint.cairo Outdated Show resolved Hide resolved
src/utils/structs/storage_array.cairo Outdated Show resolved Hide resolved
Comment on lines +106 to +110
/// Returns the checkpoint at given position.
fn at(self: @Trace, pos: u32) -> Checkpoint {
assert(pos < self.length(), 'Array overflow');
self.checkpoints.read_at(pos)
}
Copy link
Collaborator

@andrew-fleming andrew-fleming Apr 2, 2024

Choose a reason for hiding this comment

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

So I'm still in favor of unit testing all these functions. I know we concluded in the initial PR that tests are good but shouldn't be a priority (in this particular case). I vote we make an issue for it (after we merge this) so this doesn't get lost

Copy link
Member Author

Choose a reason for hiding this comment

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

We have time to add the unit tests before merging this PR. I will work on it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was working on this already, but I realized that these unit tests will most likely change when the native StorageArray (that Ariel mentioned is coming) arrives, at that point we will probably remove our own StorageArray implementation, and refactor Trace and Checkpoint from this. I lean toward creating the issue and waiting for the new storage array to come before adding the unit tests, since the module is already released, audited, and used in production. Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mmmm right. Yeah, creating an issue works for me

src/tests/token/test_erc721.cairo Show resolved Hide resolved
src/token/erc20/erc20.cairo Outdated Show resolved Hide resolved
src/utils/structs/storage_array.cairo Show resolved Hide resolved
src/tests/presets/test_erc20_votes.cairo Outdated Show resolved Hide resolved
src/token/erc20/extensions/erc20votes.cairo Outdated Show resolved Hide resolved
src/presets/erc20.cairo 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.

The empty hooks impl looks good! I left a comment and a question

src/presets/erc20_votes.cairo Outdated Show resolved Hide resolved
src/token/erc20/erc20.cairo Show resolved Hide resolved
src/token/erc20/extensions.cairo Outdated Show resolved Hide resolved
src/token/erc20/extensions/erc20_votes.cairo Outdated Show resolved Hide resolved
}

/// Required for hash computation.
impl SNIP12MetadataImpl of SNIP12Metadata {
Copy link
Member Author

Choose a reason for hiding this comment

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

@andrew-fleming even if we decide to use storage, I would need to update the SNIP12 utilities and add a component for that, and change the documentation. I still lean towards keeping the current implementation and removing the preset, but even if we decide to keep it, I think we should remove it for this PR, and add it again on the future after updating the SNIP12 implementations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could write an instructional blog post or guide on creating an ERC20Votes contract. We have the wizard, of course, but maybe a guide could help compliment it? I do agree though that removing the preset is the best approach right now

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.

LGTM! Left one tiny suggestion. Nice work :)

src/token/erc20/erc20.cairo Show resolved Hide resolved
@ericnordelo ericnordelo merged commit ec99fc3 into OpenZeppelin:main Apr 12, 2024
6 checks passed
Copy link

@Lookeren Lookeren left a comment

Choose a reason for hiding this comment

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

Л

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.

Migrate ERC20Votes to component
3 participants