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

feat: add erc1155 supply extension #418

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

feat: add erc1155 supply extension #418

wants to merge 32 commits into from

Conversation

0xNeshi
Copy link
Collaborator

@0xNeshi 0xNeshi commented Nov 22, 2024

Resolves #350

Built off of erc1155-supply. Due to major merge conflicts when trying to update the branch with main, decided to create a new branch and manually copy/paste the specific changes.

For the additional updates to the original, check out the commit messages.

PR Checklist

  • Tests
  • Documentation
  • Changelog

Copy link

netlify bot commented Nov 22, 2024

Deploy Preview for contracts-stylus ready!

Name Link
🔨 Latest commit 57b4555
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/6748bf93cfc2e50008a9ab90
😎 Deploy Preview https://deploy-preview-418--contracts-stylus.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@0xNeshi 0xNeshi marked this pull request as ready for review November 25, 2024 11:40
Copy link
Member

@qalisander qalisander left a comment

Choose a reason for hiding this comment

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

Good job! Looks good!
Left some comments, and will do the second review pass later.

Comment on lines +117 to +141
/// Grants or revokes permission to `operator`
/// to transfer the caller's tokens, according to `approved`.
///
/// Re-export of [`Erc1155::set_approval_for_all`]
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
/// * `operator` - Account to add to the set of authorized operators.
/// * `approved` - Flag that determines whether or not permission will be
/// granted to `operator`. If true, this means `operator` will be allowed
/// to manage `msg::sender()`'s assets.
///
/// # Errors
///
/// * If `operator` is `Address::ZERO`, then the error
/// [`erc1155::Error::InvalidOperator`] is returned.
///
/// # Requirements
///
/// * The `operator` cannot be the `Address::ZERO`.
///
/// # Events
///
/// Emits an [`erc1155::ApprovalForAll`] event.
Copy link
Member

@qalisander qalisander Nov 25, 2024

Choose a reason for hiding this comment

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

How about to implement IErc1155 trait here, to not copy paste doc comments from Erc1155. And for functions specific to supply extension like total_supply, exists and so on, just assume that user should expose them manually. Wdt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say that we should introduce IErc1155Supply trait that contains fns from both IErc1155 trait (re-exported due to limitation of single #[public] and required fns for Supply extension. Wdyt?

Copy link
Collaborator Author

@0xNeshi 0xNeshi Nov 27, 2024

Choose a reason for hiding this comment

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

@bidzyyys did I understand correctly, you mean something like:

pub trait IErc1155Supply {
  /// comment...
  fn total_supply
  /// comment...
  fn total_supply_all
  /// comment...
  fn exists
  
  // IErc1155 fns
  /// copy/pasted comment...
  fn balance_of
  /// copy/pasted comment...
  fn balance_of_batch
  
  // ...
}

Copy link
Member

@qalisander qalisander Nov 28, 2024

Choose a reason for hiding this comment

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

But in this case we should copy paste doc comments all over again..
That is why I'm a bit against it. In future stylus sdk version we should be able to implement more then one #[public] trait. But for now I would vote for implementing the parental trait IErc1155 for this extension.

contracts/src/token/erc1155/extensions/supply.rs Outdated Show resolved Hide resolved
contracts/src/token/erc1155/extensions/supply.rs Outdated Show resolved Hide resolved
contracts/src/token/erc1155/mod.rs Show resolved Hide resolved
Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

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

Passed first iteration.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if we need benches for each fn/contract, wdyt @qalisander?
I would say that for this contract we should check only totalSupply(uin256 id), totalSupply(), and exist(uint256 id), as the rest should be just re-export of base ERC-1155.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All functions that use the underlying _update should be benched IMO, as the logic is different in erc1155-supply from the one in vanilla erc1155

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is why I omitted benches for reexported getters and approval-related functions (they don't depend on the new _update)

Copy link
Member

@qalisander qalisander Nov 28, 2024

Choose a reason for hiding this comment

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

Idk. I see that having, that many benchmarks is not a big priority for now. Just to know how expensive or cheap a specific base contract is..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bidzyyys @qalisander wdyt is the best decision here then?

contracts/src/token/erc1155/extensions/supply.rs Outdated Show resolved Hide resolved

/// Returns the value of tokens of type `id` owned by `account`.
///
/// Re-export of [`Erc1155::balance_of`]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tbh as we have comments like re-export of [Erc1155::balance_of] I would say that we do not need to write all the docs in terms of arguments, errors, events, etc. IMHO devs will be able to check based on the links. Wdyt @0xNeshi @qalisander @ggonzalez94 ?

Copy link
Collaborator Author

@0xNeshi 0xNeshi Nov 27, 2024

Choose a reason for hiding this comment

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

While I am in favor of avoiding copy/pasting comments for reexported functions, I do think it is more practical from dev point of view to be able to see what a function does immediately, e.g. by hovering (instead of having to click another link).

I would be in favor of having a macro (or some other tool) that takes a path to the reexported function, and copy/pastes the comment for us - we keep our code clean, but all the nice comment-related benefits are still there (docs on hover over function), wdyt? 🤔

Comment on lines +117 to +141
/// Grants or revokes permission to `operator`
/// to transfer the caller's tokens, according to `approved`.
///
/// Re-export of [`Erc1155::set_approval_for_all`]
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
/// * `operator` - Account to add to the set of authorized operators.
/// * `approved` - Flag that determines whether or not permission will be
/// granted to `operator`. If true, this means `operator` will be allowed
/// to manage `msg::sender()`'s assets.
///
/// # Errors
///
/// * If `operator` is `Address::ZERO`, then the error
/// [`erc1155::Error::InvalidOperator`] is returned.
///
/// # Requirements
///
/// * The `operator` cannot be the `Address::ZERO`.
///
/// # Events
///
/// Emits an [`erc1155::ApprovalForAll`] event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say that we should introduce IErc1155Supply trait that contains fns from both IErc1155 trait (re-exported due to limitation of single #[public] and required fns for Supply extension. Wdyt?

docs/modules/ROOT/pages/erc1155-supply.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/erc1155-supply.adoc Outdated Show resolved Hide resolved
@0xNeshi
Copy link
Collaborator Author

0xNeshi commented Nov 28, 2024

@bidzyyys @qalisander does one of you know why the clippy CI step is registered as failing when all the individual steps are marked as "passed"?
Only warnings are shown in the logs

EDIT: moved the discussion to Slack

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.

[Feature]: ERC1155 Supply Extension
3 participants