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(sub0): nonfungibles pop-api + pallet implementation #353

Merged

Conversation

chungquantin
Copy link
Collaborator

@chungquantin chungquantin commented Oct 24, 2024

Nonfungible contracts size:

Original wasm size: 61.5K, Optimized: 21.7K

Description

In an effort to provide a unifying experience for developers to access runtime functionality for non-fungible tokens, APIs compliant to the PSP34 standard will be provided, as well as a set of extra functions (see Management). The interface as defined by this specification will be accessible for smart contracts via:

use pop_api::nonfungibles::<function>;

Note that the lack of version equals latest. As an example, the user could explicitly specify the version as:

use pop_api::v0::nonfungibles::<function>;

The PR includes changes made to the forked pallet-nfts following what has been discussed in the internal spec. Introducing two new pallets;

  • pallets/nfts: Changes made to the forked version to add new storage items AccountBalance and Allowances and update the following logic + unit tests to support the new storage items.
  • pallets/api/nonfungibles: Built on top of the pallet-nfts to expose READs and DISPATCHs for pop-api library.

The Nonfungible API provides the contract ability to mint / burn a new item, transfer and approve following the PSP34 Standard.
There are additional features to manage the Nonfungible such as create / destroy a collection, set / clear metadata, set / clear / approve / cancel_approve item attribute.

Becnhmarking:

  • Updated pallet-nfts weight file to cover AccountBalance read case.
  • Update approved_transfer, transfer and cancel_approval to count Allowances storage read.

@chungquantin chungquantin force-pushed the chungquantin/sub0-pallet_nfts branch from f20d191 to 11977d1 Compare October 28, 2024 17:08
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

Amazing work! Especially in the short amount of time.

I feel there has to be a way to reduce the amount of changes made throughout the repository. E.g. BoundedSlice implements the PartialEq trait which we might be able to use and therefore don't have to make the changes you made regarding the PartialEq. In addition, I think the changes in the api's pallet mock.rs are not required. This all makes the sub0 branch cleaner in terms of additional changes and reduces the amount of possible errors that can occur.

Not now, but the benchmark and weight results of destroy are incorrect. Just leaving this here for later reference, as well as the other comments starting with "Not now,"

For all, inluding the other comments, please be thoughtful on the amount of time spend as we want this to merge asap. It might also have to be rebased after the sponsorship gets merged.

The integration tests are passing apart from the event assertions for the fungibles, more specifically, in the transfer_works and approve_works test this event assertion is failing, there might be caused due to the accout mapping, unfortunately I couldn't figure it out. This shouildn't stop merging this PR though.

// TODO: Do we need another storage item to keep track of number of holders of a
// collection
let _ =
AccountBalance::<T, I>::clear_prefix(collection, collection_details.items, None);
Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

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

Not now, I think this is a storage write per account that is removed here. This means that we might need to add the amount of items in the collection in the witness data.

// collection
let _ =
AccountBalance::<T, I>::clear_prefix(collection, collection_details.items, None);
let _ = Allowances::<T, I>::clear_prefix((collection,), collection_details.items, None);
Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

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

Not now, this is not included in the benchmark function and needs to be accommodated for. This again should added to the witness data in some way.

This comment and the above give reason to change the destroying of a collection like done in pallet assets. This needs to be though out how this will look like and whether this improves things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -141,6 +124,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `Nfts::Attribute` (r:1001 w:1000)
/// Proof: `Nfts::Attribute` (`max_values`: None, `max_size`: Some(479), added: 2954, mode: `MaxEncodedLen`)
/// Storage: `Nfts::AccountBalance` (r:1 w:0)
Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

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

FYI: this showed me that there could be something wrong in the current implementation of destroy's benchmark logic. Always super valuable to see the changes in the weight results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -644,39 +641,41 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Nfts::CollectionConfigOf` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`)
/// Storage: `Nfts::ItemConfigOf` (r:1 w:0)
/// Proof: `Nfts::ItemConfigOf` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
/// Storage: `Nfts::AccountBalance` (r:2 w:2)
Copy link
Collaborator

@Daanvdplas Daanvdplas Oct 30, 2024

Choose a reason for hiding this comment

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

Not now, this is the counter argument for adding this storage map. Nothing to do now but important to re-evaluate later on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pallets/nfts/src/features/approvals.rs Outdated Show resolved Hide resolved
pallets/nfts/src/types.rs Outdated Show resolved Hide resolved
pallets/api/src/mock.rs Outdated Show resolved Hide resolved
pallets/api/src/nonfungibles/mod.rs Outdated Show resolved Hide resolved
pallets/api/src/nonfungibles/mod.rs Show resolved Hide resolved
pallets/api/src/nonfungibles/mod.rs Show resolved Hide resolved
@chungquantin chungquantin force-pushed the chungquantin/sub0-nonfungibles branch 2 times, most recently from 45ac5ca to 5bcdd66 Compare November 1, 2024 07:12
refactor: item metadata

fix: item metadata tests

test(nonfungibles): add mint and burn tests

refactor: non fungibles sub0 (#364)

Co-authored-by: Tin Chung <[email protected]>

fix: pallet tests + integration tests

refactor: remove unused types

refactor(nonfungibles): CollectionConfig parameter

chore: resolve review comments

refactor: item metadata

fix: item metadata tests

test(nonfungibles): add mint and burn tests

refactor: non fungibles sub0 (#364)

Co-authored-by: Tin Chung <[email protected]>

fix: pallet tests + integration tests

refactor: remove unused types

refactor(nonfungibles): CollectionConfig parameter

chore: remove unused code
@chungquantin chungquantin force-pushed the chungquantin/sub0-nonfungibles branch from e00f8be to 8745056 Compare November 1, 2024 11:18
@Daanvdplas Daanvdplas merged commit 3fa6003 into chungquantin/sub0-pallet_nfts Nov 1, 2024
9 of 12 checks passed
@Daanvdplas Daanvdplas deleted the chungquantin/sub0-nonfungibles branch November 1, 2024 14:22
Daanvdplas added a commit that referenced this pull request Nov 1, 2024
@Daanvdplas Daanvdplas mentioned this pull request Nov 19, 2024
12 tasks
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.

3 participants