diff --git a/pallets/gated-marketplace/src/functions.rs b/pallets/gated-marketplace/src/functions.rs index e8eca812..c5db0622 100644 --- a/pallets/gated-marketplace/src/functions.rs +++ b/pallets/gated-marketplace/src/functions.rs @@ -2,10 +2,14 @@ use super::*; use crate::types::*; use frame_support::pallet_prelude::*; use frame_support::sp_io::hashing::blake2_256; +use frame_support::traits::tokens::AssetId; use pallet_rbac::types::*; use scale_info::prelude::vec; // vec![] macro use sp_runtime::sp_std::vec::Vec; // vec primitive -use frame_system::pallet_prelude::*; + +use frame_support::traits::fungibles::Transfer; +use frame_support::traits::Currency; +use frame_support::traits::ExistenceRequirement::KeepAlive; use frame_support::traits::Time; use sp_runtime::Permill; use sp_runtime::traits::StaticLookup; @@ -239,15 +243,9 @@ impl Pallet { Ok(()) } - - pub fn self_enroll( - account: T::AccountId, - marketplace_id: [u8; 32], - ) -> DispatchResult { - - //since users can self-enroll, the caller of this function must validate + pub fn self_enroll(account: T::AccountId, marketplace_id: [u8; 32]) -> DispatchResult { + //since users can self-enroll, the caller of this function must validate //that the user is indeed the owner of the address by using ensure_signed - //ensure the account is not already in the marketplace ensure!( @@ -261,10 +259,13 @@ impl Pallet { // ensure the marketplace exist ensure!(>::contains_key(marketplace_id), Error::::MarketplaceNotFound); - - Self::insert_in_auth_market_lists(account.clone(), MarketplaceRole::Participant, marketplace_id)?; + Self::insert_in_auth_market_lists( + account.clone(), + MarketplaceRole::Participant, + marketplace_id, + )?; Self::deposit_event(Event::AuthorityAdded(account, MarketplaceRole::Participant)); - + Ok(()) } @@ -375,6 +376,7 @@ impl Pallet { collection_id, item_id, creator: authority.clone(), + // might require a storage migration price, fee: price * Permill::deconstruct(marketplace.sell_fee).into() / 1_000_000u32.into(), percentage: Permill::from_percent(percentage), @@ -439,7 +441,7 @@ impl Pallet { &marketplace_id, authority.clone(), &collection_id, - &item_id + &item_id, )?; //Get asset id @@ -469,6 +471,7 @@ impl Pallet { collection_id, item_id, creator: authority.clone(), + // TODO: evaluate if the change will require a storage migration price, fee: price * Permill::deconstruct(marketplace.buy_fee).into() / 1_000_000u32.into(), percentage: Permill::from_percent(percentage), @@ -537,7 +540,7 @@ impl Pallet { //ensure user has enough balance to create the offer let total_amount_buyer = pallet_mapped_assets::Pallet::::balance(asset_id.clone(), buyer.clone()); //ensure the buyer has enough balance to buy the item - ensure!(total_amount_buyer > offer_data.price, Error::::NotEnoughBalance); + //ensure!(total_amount_buyer > offer_data.price, Error::::NotEnoughBalance); let marketplace = >::get(offer_data.marketplace_id).ok_or(Error::::OfferNotFound)?; @@ -646,7 +649,7 @@ impl Pallet { //ensure user has enough balance to create the offer let total_amount_buyer = pallet_mapped_assets::Pallet::::balance(asset_id.clone(), offer_data.creator.clone()); //ensure the buy_offer_creator has enough balance to buy the item - ensure!(total_amount_buyer > offer_data.price, Error::::NotEnoughBalance); + //ensure!(total_amount_buyer > offer_data.price, Error::::NotEnoughBalance); let marketplace = >::get(offer_data.marketplace_id).ok_or(Error::::OfferNotFound)?; @@ -941,7 +944,10 @@ impl Pallet { // ensure the origin is authorized to block users Self::is_authorized(authority.clone(), &marketplace_id, Permission::BlockUser)?; // ensure the user is not already a participant of the marketplace - ensure!(!Self::has_any_role(user.clone(), &marketplace_id), Error::::UserAlreadyParticipant); + ensure!( + !Self::has_any_role(user.clone(), &marketplace_id), + Error::::UserAlreadyParticipant + ); // ensure the user is not already blocked ensure!( !Self::is_user_blocked(user.clone(), marketplace_id), @@ -968,7 +974,10 @@ impl Pallet { // ensure the origin is authorized to block users Self::is_authorized(authority.clone(), &marketplace_id, Permission::BlockUser)?; // ensure the user is not already a participant of the marketplace - ensure!(!Self::has_any_role(user.clone(), &marketplace_id), Error::::UserAlreadyParticipant); + ensure!( + !Self::has_any_role(user.clone(), &marketplace_id), + Error::::UserAlreadyParticipant + ); // ensure the user is blocked ensure!(Self::is_user_blocked(user.clone(), marketplace_id), Error::::UserIsNotBlocked); @@ -1008,7 +1017,11 @@ impl Pallet { /// Let us know if the selected account has at least one role in the marketplace. fn has_any_role(account: T::AccountId, marketplace_id: &[u8; 32]) -> bool { let pallet_id = Self::pallet_id(); - ::Rbac::does_user_have_any_role_in_scope(account, pallet_id, marketplace_id) + ::Rbac::does_user_have_any_role_in_scope( + account, + pallet_id, + marketplace_id, + ) } ///Lets us know if the selected user is an admin. diff --git a/pallets/gated-marketplace/src/lib.rs b/pallets/gated-marketplace/src/lib.rs index dda36916..b1ac91c8 100644 --- a/pallets/gated-marketplace/src/lib.rs +++ b/pallets/gated-marketplace/src/lib.rs @@ -14,7 +14,10 @@ pub mod types; #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; - use frame_support::traits::{Currency, Time}; + use frame_support::traits::{ + tokens::fungibles::{Inspect, Transfer}, + Currency, Time, + }; use frame_system::pallet_prelude::*; use sp_runtime::traits::Scale; use sp_runtime::Permill; @@ -23,10 +26,12 @@ pub mod pallet { use crate::types::*; use pallet_rbac::types::RoleBasedAccessControl; - - pub type BalanceOf = <::Currency as Currency< - ::AccountId, - >>::Balance; + //pub type BalanceOf = <::Currency as Currency< + // ::AccountId, + //>>::Balance; + // TODO: replace BalanceOf with the mapped assets one + pub type BalanceOf = + <::MappedAssets as Inspect<::AccountId>>::Balance; #[pallet::config] pub trait Config: frame_system::Config + pallet_fruniques::Config + pallet_mapped_assets::Config { @@ -69,6 +74,8 @@ pub mod pallet { type MaxBlockedUsersPerMarket: Get; type Rbac: RoleBasedAccessControl; + + type MappedAssets: Transfer + Inspect; } #[pallet::pallet] diff --git a/parachain-runtime/Cargo.toml b/parachain-runtime/Cargo.toml index 0cbe2bac..b1331e0d 100644 --- a/parachain-runtime/Cargo.toml +++ b/parachain-runtime/Cargo.toml @@ -45,13 +45,11 @@ frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", d frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.38" } # Local Pallets -pallet-template = { default-features = false, path = "../pallets/template" } -pallet-fruniques = { version = "0.1.0-dev", default-features = false, path = "../pallets/fruniques" } -pallet-bitcoin-vaults = { default-features = false, path = "../pallets/bitcoin-vaults" } -pallet-gated-marketplace = { default-features = false, path = "../pallets/gated-marketplace" } -pallet-rbac = { default-features = false, path = "../pallets/rbac" } -pallet-confidential-docs = { default-features = false, path = "../pallets/confidential-docs" } -pallet-fund-admin = { default-features = false, path = "../pallets/fund-admin" } +pallet-bitcoin-vaults = { path = "../pallets/bitcoin-vaults", default-features = false } +pallet-fruniques = { path = "../pallets/fruniques", default-features = false } +pallet-gated-marketplace = { path = "../pallets/gated-marketplace", default-features = false } +pallet-rbac = { path = "../pallets/rbac", default-features = false } +pallet-confidential-docs = { path = "../pallets/confidential-docs", default-features = false } pallet-mapped-assets = { path = "../pallets/mapped-assets",default-features = false } # Prebuilt Pallets pallet-alliance = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } diff --git a/parachain-runtime/src/lib.rs b/parachain-runtime/src/lib.rs index f7c6c606..0d6d0c2f 100644 --- a/parachain-runtime/src/lib.rs +++ b/parachain-runtime/src/lib.rs @@ -22,6 +22,7 @@ use sp_runtime::{ ApplyExtrinsicResult, MultiSignature, }; +use pallet_mapped_assets::DefaultCallback; use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -819,6 +820,33 @@ impl pallet_confidential_docs::Config for Runtime { type MaxMemberGroups = MaxMemberGroups; } +parameter_types! { + pub const MappedMaxReserves: u32 = 200; +} + +impl pallet_mapped_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = u128; + type AssetId = u32; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type AssetAccountDeposit = ConstU128; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = StringLimit; + type Freezer = (); + type Extra = (); + type WeightInfo = (); + type MaxReserves = MappedMaxReserves; + type ReserveIdentifier = u32; + type RemoveItemsLimit = RemoveItemsLimit; + type AssetIdParameter = u32; + type CallbackHandle = DefaultCallback; +} + impl pallet_remark::Config for Runtime { type WeightInfo = pallet_remark::weights::SubstrateWeight; type RuntimeEvent = RuntimeEvent; @@ -1042,6 +1070,7 @@ impl pallet_gated_marketplace::Config for Runtime { type Timestamp = Timestamp; type Moment = Moment; type Rbac = RBAC; + type MappedAssets = MappedAssets; } impl pallet_mapped_assets::Config for Runtime { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a14fce12..004516d6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -662,6 +662,7 @@ impl pallet_gated_marketplace::Config for Runtime { type Timestamp = Timestamp; type Moment = Moment; type Rbac = RBAC; + type MappedAssets = MappedAssets; } parameter_types! { @@ -748,7 +749,6 @@ impl pallet_mapped_assets::Config for Runtime { type CallbackHandle = DefaultCallback; } - parameter_types! { pub const MaxScopesPerPallet: u32 = 1000; pub const MaxRolesPerPallet: u32 = 50;