1use super::*;
21use crate::macros::*;
22use alloc::{vec, vec::Vec};
23use codec::{DecodeWithMemTracking, EncodeLike};
24use enumflags2::{bitflags, BitFlags};
25use frame_support::{
26 pallet_prelude::{BoundedVec, MaxEncodedLen},
27 traits::Get,
28 BoundedBTreeMap, BoundedBTreeSet,
29};
30use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter};
31
32pub type BlockNumberFor<T, I = ()> =
33 <<T as Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
34
35pub type DepositBalanceOf<T, I = ()> =
37 <<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
38pub type CollectionDetailsFor<T, I> =
40 CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
41pub type ApprovalsOf<T, I = ()> = BoundedBTreeMap<
43 <T as SystemConfig>::AccountId,
44 Option<BlockNumberFor<T, I>>,
45 <T as Config<I>>::ApprovalsLimit,
46>;
47pub type ItemAttributesApprovals<T, I = ()> =
49 BoundedBTreeSet<<T as SystemConfig>::AccountId, <T as Config<I>>::ItemAttributesApprovalsLimit>;
50pub type ItemDepositOf<T, I> = ItemDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
52pub type AttributeDepositOf<T, I> =
54 AttributeDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
55pub type ItemMetadataDepositOf<T, I> =
57 ItemMetadataDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
58pub type ItemDetailsFor<T, I> =
60 ItemDetails<<T as SystemConfig>::AccountId, ItemDepositOf<T, I>, ApprovalsOf<T, I>>;
61pub type BalanceOf<T, I = ()> =
63 <<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
64pub type ItemPrice<T, I = ()> = BalanceOf<T, I>;
66pub type ItemTipOf<T, I = ()> = ItemTip<
68 <T as Config<I>>::CollectionId,
69 <T as Config<I>>::ItemId,
70 <T as SystemConfig>::AccountId,
71 BalanceOf<T, I>,
72>;
73pub type CollectionConfigFor<T, I = ()> =
75 CollectionConfig<BalanceOf<T, I>, BlockNumberFor<T, I>, <T as Config<I>>::CollectionId>;
76pub type PreSignedMintOf<T, I = ()> = PreSignedMint<
78 <T as Config<I>>::CollectionId,
79 <T as Config<I>>::ItemId,
80 <T as SystemConfig>::AccountId,
81 BlockNumberFor<T, I>,
82 BalanceOf<T, I>,
83>;
84pub type PreSignedAttributesOf<T, I = ()> = PreSignedAttributes<
86 <T as Config<I>>::CollectionId,
87 <T as Config<I>>::ItemId,
88 <T as SystemConfig>::AccountId,
89 BlockNumberFor<T, I>,
90>;
91
92#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
94pub struct CollectionDetails<AccountId, DepositBalance> {
95 pub owner: AccountId,
97 pub owner_deposit: DepositBalance,
100 pub items: u32,
102 pub item_metadatas: u32,
104 pub item_configs: u32,
106 pub attributes: u32,
108}
109
110#[derive(
112 Copy,
113 Clone,
114 Encode,
115 Decode,
116 DecodeWithMemTracking,
117 Eq,
118 PartialEq,
119 RuntimeDebug,
120 TypeInfo,
121 MaxEncodedLen,
122)]
123pub struct DestroyWitness {
124 #[codec(compact)]
126 pub item_metadatas: u32,
127 #[codec(compact)]
129 pub item_configs: u32,
130 #[codec(compact)]
132 pub attributes: u32,
133}
134
135impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
136 pub fn destroy_witness(&self) -> DestroyWitness {
137 DestroyWitness {
138 item_metadatas: self.item_metadatas,
139 item_configs: self.item_configs,
140 attributes: self.attributes,
141 }
142 }
143}
144
145#[derive(
147 Clone, Encode, Decode, DecodeWithMemTracking, Default, Eq, PartialEq, RuntimeDebug, TypeInfo,
148)]
149pub struct MintWitness<ItemId, Balance> {
150 pub owned_item: Option<ItemId>,
152 pub mint_price: Option<Balance>,
154}
155
156#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
158pub struct ItemDetails<AccountId, Deposit, Approvals> {
159 pub owner: AccountId,
161 pub approvals: Approvals,
163 pub deposit: Deposit,
166}
167
168#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
170pub struct ItemDeposit<DepositBalance, AccountId> {
171 pub account: AccountId,
173 pub amount: DepositBalance,
175}
176
177#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
179#[scale_info(skip_type_params(StringLimit))]
180#[codec(mel_bound(Deposit: MaxEncodedLen))]
181pub struct CollectionMetadata<Deposit, StringLimit: Get<u32>> {
182 pub deposit: Deposit,
186 pub data: BoundedVec<u8, StringLimit>,
190}
191
192#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
194#[scale_info(skip_type_params(StringLimit))]
195pub struct ItemMetadata<Deposit, StringLimit: Get<u32>> {
196 pub deposit: Deposit,
200 pub data: BoundedVec<u8, StringLimit>,
204}
205
206#[derive(
208 Clone,
209 Encode,
210 Decode,
211 DecodeWithMemTracking,
212 Eq,
213 PartialEq,
214 RuntimeDebug,
215 TypeInfo,
216 MaxEncodedLen,
217)]
218pub struct ItemTip<CollectionId, ItemId, AccountId, Amount> {
219 pub collection: CollectionId,
221 pub item: ItemId,
223 pub receiver: AccountId,
225 pub amount: Amount,
227}
228
229#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
231pub struct PendingSwap<CollectionId, ItemId, ItemPriceWithDirection, Deadline> {
232 pub desired_collection: CollectionId,
234 pub desired_item: Option<ItemId>,
236 pub price: Option<ItemPriceWithDirection>,
238 pub deadline: Deadline,
240}
241
242#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
244pub struct AttributeDeposit<DepositBalance, AccountId> {
245 pub account: Option<AccountId>,
247 pub amount: DepositBalance,
249}
250
251#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
253pub struct ItemMetadataDeposit<DepositBalance, AccountId> {
254 pub account: Option<AccountId>,
256 pub amount: DepositBalance,
258}
259
260#[derive(
262 Clone,
263 Encode,
264 Decode,
265 DecodeWithMemTracking,
266 Eq,
267 PartialEq,
268 RuntimeDebug,
269 TypeInfo,
270 MaxEncodedLen,
271)]
272pub enum PriceDirection {
273 Send,
275 Receive,
277}
278
279#[derive(
281 Clone,
282 Encode,
283 Decode,
284 DecodeWithMemTracking,
285 Eq,
286 PartialEq,
287 RuntimeDebug,
288 TypeInfo,
289 MaxEncodedLen,
290)]
291pub struct PriceWithDirection<Amount> {
292 pub amount: Amount,
294 pub direction: PriceDirection,
296}
297
298#[bitflags]
300#[repr(u64)]
301#[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
302pub enum CollectionSetting {
303 TransferableItems,
305 UnlockedMetadata,
307 UnlockedAttributes,
309 UnlockedMaxSupply,
311 DepositRequired,
313}
314
315#[derive(Clone, Copy, PartialEq, Eq, Default, RuntimeDebug)]
317pub struct CollectionSettings(pub BitFlags<CollectionSetting>);
318
319impl CollectionSettings {
320 pub fn all_enabled() -> Self {
321 Self(BitFlags::EMPTY)
322 }
323 pub fn get_disabled(&self) -> BitFlags<CollectionSetting> {
324 self.0
325 }
326 pub fn is_disabled(&self, setting: CollectionSetting) -> bool {
327 self.0.contains(setting)
328 }
329 pub fn from_disabled(settings: BitFlags<CollectionSetting>) -> Self {
330 Self(settings)
331 }
332}
333
334impl_codec_bitflags!(CollectionSettings, u64, CollectionSetting);
335impl DecodeWithMemTracking for CollectionSettings {}
338
339#[derive(
343 Clone,
344 Copy,
345 Encode,
346 Decode,
347 DecodeWithMemTracking,
348 Eq,
349 PartialEq,
350 RuntimeDebug,
351 TypeInfo,
352 MaxEncodedLen,
353)]
354pub enum MintType<CollectionId> {
355 Issuer,
357 Public,
359 HolderOf(CollectionId),
361}
362
363#[derive(
365 Clone,
366 Copy,
367 Encode,
368 Decode,
369 DecodeWithMemTracking,
370 Eq,
371 PartialEq,
372 RuntimeDebug,
373 TypeInfo,
374 MaxEncodedLen,
375)]
376pub struct MintSettings<Price, BlockNumber, CollectionId> {
377 pub mint_type: MintType<CollectionId>,
379 pub price: Option<Price>,
381 pub start_block: Option<BlockNumber>,
383 pub end_block: Option<BlockNumber>,
385 pub default_item_settings: ItemSettings,
387}
388
389impl<Price, BlockNumber, CollectionId> Default for MintSettings<Price, BlockNumber, CollectionId> {
390 fn default() -> Self {
391 Self {
392 mint_type: MintType::Issuer,
393 price: None,
394 start_block: None,
395 end_block: None,
396 default_item_settings: ItemSettings::all_enabled(),
397 }
398 }
399}
400
401#[derive(
403 Clone,
404 Encode,
405 Decode,
406 DecodeWithMemTracking,
407 Eq,
408 PartialEq,
409 RuntimeDebug,
410 scale_info::TypeInfo,
411 MaxEncodedLen,
412)]
413pub enum AttributeNamespace<AccountId> {
414 Pallet,
416 CollectionOwner,
418 ItemOwner,
420 Account(AccountId),
422}
423
424#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, RuntimeDebug, TypeInfo)]
426pub struct CancelAttributesApprovalWitness {
427 pub account_attributes: u32,
429}
430
431#[derive(
433 Clone,
434 Encode,
435 Decode,
436 DecodeWithMemTracking,
437 Eq,
438 PartialEq,
439 RuntimeDebug,
440 TypeInfo,
441 MaxEncodedLen,
442)]
443pub enum PalletAttributes<CollectionId> {
444 UsedToClaim(CollectionId),
446 TransferDisabled,
448}
449
450#[derive(
452 Clone,
453 Copy,
454 Decode,
455 DecodeWithMemTracking,
456 Default,
457 Encode,
458 MaxEncodedLen,
459 PartialEq,
460 RuntimeDebug,
461 TypeInfo,
462)]
463pub struct CollectionConfig<Price, BlockNumber, CollectionId> {
464 pub settings: CollectionSettings,
466 pub max_supply: Option<u32>,
468 pub mint_settings: MintSettings<Price, BlockNumber, CollectionId>,
470}
471
472impl<Price, BlockNumber, CollectionId> CollectionConfig<Price, BlockNumber, CollectionId> {
473 pub fn is_setting_enabled(&self, setting: CollectionSetting) -> bool {
474 !self.settings.is_disabled(setting)
475 }
476 pub fn has_disabled_setting(&self, setting: CollectionSetting) -> bool {
477 self.settings.is_disabled(setting)
478 }
479 pub fn enable_setting(&mut self, setting: CollectionSetting) {
480 self.settings.0.remove(setting);
481 }
482 pub fn disable_setting(&mut self, setting: CollectionSetting) {
483 self.settings.0.insert(setting);
484 }
485}
486
487#[bitflags]
489#[repr(u64)]
490#[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
491pub enum ItemSetting {
492 Transferable,
494 UnlockedMetadata,
496 UnlockedAttributes,
498}
499
500#[derive(Clone, Copy, PartialEq, Eq, Default, RuntimeDebug)]
502pub struct ItemSettings(pub BitFlags<ItemSetting>);
503
504impl ItemSettings {
505 pub fn all_enabled() -> Self {
506 Self(BitFlags::EMPTY)
507 }
508 pub fn get_disabled(&self) -> BitFlags<ItemSetting> {
509 self.0
510 }
511 pub fn is_disabled(&self, setting: ItemSetting) -> bool {
512 self.0.contains(setting)
513 }
514 pub fn from_disabled(settings: BitFlags<ItemSetting>) -> Self {
515 Self(settings)
516 }
517}
518
519impl_codec_bitflags!(ItemSettings, u64, ItemSetting);
520impl DecodeWithMemTracking for ItemSettings {}
523
524#[derive(
526 Encode,
527 Decode,
528 DecodeWithMemTracking,
529 Default,
530 PartialEq,
531 RuntimeDebug,
532 Clone,
533 Copy,
534 MaxEncodedLen,
535 TypeInfo,
536)]
537pub struct ItemConfig {
538 pub settings: ItemSettings,
540}
541
542impl ItemConfig {
543 pub fn is_setting_enabled(&self, setting: ItemSetting) -> bool {
544 !self.settings.is_disabled(setting)
545 }
546 pub fn has_disabled_setting(&self, setting: ItemSetting) -> bool {
547 self.settings.is_disabled(setting)
548 }
549 pub fn has_disabled_settings(&self) -> bool {
550 !self.settings.get_disabled().is_empty()
551 }
552 pub fn enable_setting(&mut self, setting: ItemSetting) {
553 self.settings.0.remove(setting);
554 }
555 pub fn disable_setting(&mut self, setting: ItemSetting) {
556 self.settings.0.insert(setting);
557 }
558}
559
560#[bitflags]
562#[repr(u64)]
563#[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
564pub enum PalletFeature {
565 Trading,
567 Attributes,
569 Approvals,
571 Swaps,
573}
574
575#[derive(Default, RuntimeDebug)]
577pub struct PalletFeatures(pub BitFlags<PalletFeature>);
578
579impl PalletFeatures {
580 pub fn all_enabled() -> Self {
581 Self(BitFlags::EMPTY)
582 }
583 pub fn from_disabled(features: BitFlags<PalletFeature>) -> Self {
584 Self(features)
585 }
586 pub fn is_enabled(&self, feature: PalletFeature) -> bool {
587 !self.0.contains(feature)
588 }
589}
590impl_codec_bitflags!(PalletFeatures, u64, PalletFeature);
591
592#[bitflags]
594#[repr(u8)]
595#[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
596pub enum CollectionRole {
597 Issuer,
599 Freezer,
601 Admin,
603}
604
605#[derive(Clone, Copy, PartialEq, Eq, Default, RuntimeDebug)]
607pub struct CollectionRoles(pub BitFlags<CollectionRole>);
608
609impl CollectionRoles {
610 pub fn none() -> Self {
611 Self(BitFlags::EMPTY)
612 }
613 pub fn has_role(&self, role: CollectionRole) -> bool {
614 self.0.contains(role)
615 }
616 pub fn add_role(&mut self, role: CollectionRole) {
617 self.0.insert(role);
618 }
619 pub fn max_roles() -> u8 {
620 let all: BitFlags<CollectionRole> = BitFlags::all();
621 all.len() as u8
622 }
623}
624impl_codec_bitflags!(CollectionRoles, u8, CollectionRole);
625
626#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo)]
627pub struct PreSignedMint<CollectionId, ItemId, AccountId, Deadline, Balance> {
628 pub collection: CollectionId,
630 pub item: ItemId,
632 pub attributes: Vec<(Vec<u8>, Vec<u8>)>,
634 pub metadata: Vec<u8>,
636 pub only_account: Option<AccountId>,
638 pub deadline: Deadline,
640 pub mint_price: Option<Balance>,
642}
643
644#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo)]
645pub struct PreSignedAttributes<CollectionId, ItemId, AccountId, Deadline> {
646 pub collection: CollectionId,
648 pub item: ItemId,
650 pub attributes: Vec<(Vec<u8>, Vec<u8>)>,
652 pub namespace: AttributeNamespace<AccountId>,
654 pub deadline: Deadline,
656}