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

Add MarketplaceHooks and MarketFee traits #27

Merged
merged 11 commits into from
Feb 17, 2023
Merged

Conversation

HashWarlock
Copy link

@HashWarlock HashWarlock commented Feb 13, 2023

Description

Currently the Market pallet has no way to check if the type of NFT can be sold (i.e. Stakepool v2 NFTs vs PhalaWorld Shell NFTs). To resolve this, there are an introduction to 2 new traits called MarketplaceHooks and MarketFee which will hold the standard market fee percentage constant in the MarketFee trait and the MarketplaceHooks will implement 3 functions called calculate_market_fee(amount) calculate_royalty_fee(amount, royalty_fee) and can_list_or_buy_in_market(collections_id, nft_id) that will help prevent NFTs from being listed that are not eligible for the marketplace.

Targets

  • add new traits MarketFee and MarketplaceHooks
  • implement Default for the traits in runtime
  • access control function in MarketplaceHooks trait
  • run integration tests
  • calculate new weights if needed

@HashWarlock HashWarlock marked this pull request as ready for review February 14, 2023 01:04
@@ -569,6 +569,9 @@ impl<T: Config>
nft_id: T::ItemId,
budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
// Check Lock to prevent locked NFTs from being burned. Owner must unlock the NFT before
// burning.
ensure!(!Pallet::<T>::is_locked(collection_id, nft_id), pallet_uniques::Error::<T>::Locked);

Choose a reason for hiding this comment

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

Nice design here! Can we add a collection-level lock?

Copy link
Author

Choose a reason for hiding this comment

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

We can do this with the pallet_uniques function.

		/// Disallow further unprivileged transfers for a whole collection.
		///
		/// Origin must be Signed and the sender should be the Freezer of the `collection`.
		///
		/// - `collection`: The collection to be frozen.
		///
		/// Emits `CollectionFrozen`.
		///
		/// Weight: `O(1)`
		#[pallet::call_index(9)]
		#[pallet::weight(T::WeightInfo::freeze_collection())]
		pub fn freeze_collection(
			origin: OriginFor<T>,
			collection: T::CollectionId,
		) -> DispatchResult {
			let origin = ensure_signed(origin)?;

			Collection::<T, I>::try_mutate(collection, |maybe_details| {
				let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
				ensure!(origin == details.freezer, Error::<T, I>::NoPermission);

				details.is_frozen = true;

				Self::deposit_event(Event::<T, I>::CollectionFrozen { collection });
				Ok(())
			})
		}

@HashWarlock
Copy link
Author

@jasl let me know if good to merge. Then can update the cargo in Phala-Network/khala-parachain#254

@jasl jasl merged commit a7e970c into polkadot-v0.9.37 Feb 17, 2023
@jasl
Copy link

jasl commented Feb 17, 2023

MERGED!

@HashWarlock HashWarlock deleted the market-fees branch March 9, 2023 21:33
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