--- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -20,7 +20,7 @@ ensure, fail, parameter_types, traits::{ Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, - Randomness, IsSubType, + Randomness, IsSubType, WithdrawReasons, }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, @@ -435,7 +435,9 @@ /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; - type CollectionCreationPrice: Get>; + type Currency: Currency; + type CollectionCreationPrice: Get<<::Currency as Currency>::Balance>; + type TreasuryAccountId: Get; } #[cfg(feature = "runtime-benchmarks")] @@ -663,6 +665,18 @@ // Anyone can create a collection let who = ensure_signed(origin)?; + let mut imbalance = <<::Currency as Currency>::PositiveImbalance>::zero(); + imbalance.subsume(<::Currency as Currency>::deposit_creating( + &T::TreasuryAccountId::get(), + T::CollectionCreationPrice::get(), + )); + ::Currency::settle( + &who, + imbalance, + WithdrawReasons::TRANSFER, + ExistenceRequirement::KeepAlive, + ).map_err(|_| Error::::NoPermission)?; + let decimal_points = match mode { CollectionMode::Fungible(points) => points, _ => 0 @@ -2537,10 +2551,7 @@ > { let tip = self.0; - let fee = match call.is_sub_type() { - Some(Call::create_collection(..)) => T::CollectionCreationPrice::get(), - _ => Self::traditional_fee(len, info, tip), - }; + let fee = Self::traditional_fee(len, info, tip); // Only mess with balances if fee is not zero. if fee.is_zero() { --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -24,7 +24,7 @@ create_runtime_str, generic, impl_opaque_keys, traits::{ Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, - IdentityLookup, NumberFor, Verify, + IdentityLookup, NumberFor, Verify, AccountIdConversion, }, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, @@ -510,7 +510,6 @@ parameter_types! { pub const MinVestedTransfer: Balance = 10 * UNIQUE; - pub const CollectionCreationPrice: Balance = 100 * UNIQUE; } impl pallet_vesting::Config for Runtime { @@ -521,11 +520,18 @@ type WeightInfo = (); } +parameter_types! { + pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account(); + pub const CollectionCreationPrice: Balance = 100 * UNIQUE; +} + /// Used for the module nft in `./nft.rs` impl pallet_nft::Config for Runtime { type Event = Event; type WeightInfo = nft_weights::WeightInfo; + type Currency = Balances; type CollectionCreationPrice = CollectionCreationPrice; + type TreasuryAccountId = TreasuryAccountId; } construct_runtime!(