@@ -6,7 +6,10 @@ use frame_support::{log, pallet_prelude::*};
6
6
use frame_system:: pallet_prelude:: * ;
7
7
pub use module:: * ;
8
8
use orml_traits:: asset_registry:: { FixedConversionRateProvider , WeightToFeeConverter } ;
9
+ use orml_traits:: GetByKey ;
9
10
use scale_info:: TypeInfo ;
11
+ use sp_runtime:: traits:: AtLeast32BitUnsigned ;
12
+ use sp_runtime:: traits:: Bounded ;
10
13
use sp_runtime:: { traits:: Member , DispatchResult } ;
11
14
use sp_std:: prelude:: * ;
12
15
use xcm:: latest:: prelude:: * ;
@@ -18,12 +21,13 @@ pub trait AssetProcessor<AssetId, Metadata> {
18
21
}
19
22
20
23
#[ derive( scale_info:: TypeInfo , Encode , Decode , Clone , Eq , PartialEq , Debug ) ]
21
- pub struct AssetMetadata < T : Parameter + Member + TypeInfo > {
24
+ pub struct AssetMetadata < Balance , CustomMetadata : Parameter + Member + TypeInfo > {
22
25
pub decimals : u32 ,
23
26
pub name : Vec < u8 > ,
24
27
pub symbol : Vec < u8 > ,
28
+ pub existential_deposit : Balance ,
25
29
pub location : Option < MultiLocation > ,
26
- pub additional : T ,
30
+ pub additional : CustomMetadata ,
27
31
}
28
32
29
33
#[ frame_support:: pallet]
@@ -40,7 +44,16 @@ pub mod module {
40
44
41
45
type AuthorityOrigin : EnsureOrigin < <Self as frame_system:: Config >:: Origin > ;
42
46
43
- type ProcessAsset : AssetProcessor < Self :: AssetId , AssetMetadata < Self :: CustomMetadata > > ;
47
+ type ProcessAsset : AssetProcessor < Self :: AssetId , AssetMetadata < Self :: Balance , Self :: CustomMetadata > > ;
48
+
49
+ /// The balance type.
50
+ type Balance : Parameter
51
+ + Member
52
+ + AtLeast32BitUnsigned
53
+ + Default
54
+ + Copy
55
+ + MaybeSerializeDeserialize
56
+ + Into < u128 > ;
44
57
// /// Weight information for extrinsics in this module.
45
58
// type WeightInfo: WeightInfo;
46
59
}
@@ -56,7 +69,7 @@ pub mod module {
56
69
pub enum Event < T : Config > {
57
70
RegisteredAsset {
58
71
asset_id : T :: AssetId ,
59
- metadata : AssetMetadata < T :: CustomMetadata > ,
72
+ metadata : AssetMetadata < T :: Balance , T :: CustomMetadata > ,
60
73
} ,
61
74
SetLocation {
62
75
asset_id : T :: AssetId ,
@@ -68,7 +81,7 @@ pub mod module {
68
81
#[ pallet:: storage]
69
82
#[ pallet:: getter( fn get_metadata) ]
70
83
pub type Metadata < T : Config > =
71
- StorageMap < _ , Twox64Concat , T :: AssetId , AssetMetadata < T :: CustomMetadata > , OptionQuery > ;
84
+ StorageMap < _ , Twox64Concat , T :: AssetId , AssetMetadata < T :: Balance , T :: CustomMetadata > , OptionQuery > ;
72
85
73
86
/// The total issuance of a token type.
74
87
#[ pallet:: storage]
@@ -110,7 +123,7 @@ pub mod module {
110
123
#[ pallet:: weight( 0 ) ]
111
124
pub fn register_asset (
112
125
origin : OriginFor < T > ,
113
- metadata : AssetMetadata < T :: CustomMetadata > ,
126
+ metadata : AssetMetadata < T :: Balance , T :: CustomMetadata > ,
114
127
asset_id : Option < T :: AssetId > ,
115
128
) -> DispatchResult {
116
129
let _ = T :: AuthorityOrigin :: ensure_origin ( origin) ?;
@@ -165,7 +178,9 @@ pub mod module {
165
178
}
166
179
167
180
impl < T : Config > Pallet < T > {
168
- pub fn fetch_metadata_by_location ( location : & MultiLocation ) -> Option < AssetMetadata < T :: CustomMetadata > > {
181
+ pub fn fetch_metadata_by_location (
182
+ location : & MultiLocation ,
183
+ ) -> Option < AssetMetadata < T :: Balance , T :: CustomMetadata > > {
169
184
let asset_id = MultiLocationLookup :: < T > :: get ( location) ?;
170
185
Metadata :: < T > :: get ( asset_id)
171
186
}
@@ -273,3 +288,16 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> Drop for AssetRegistryTrader<W, R>
273
288
}
274
289
}
275
290
}
291
+
292
+ // Return Existential deposit of an asset. Implementing this trait allows it to
293
+ // be used in the tokens::ExistentialDeposits config item
294
+ impl < T : Config > GetByKey < T :: AssetId , T :: Balance > for Pallet < T > {
295
+ fn get ( k : & T :: AssetId ) -> T :: Balance {
296
+ if let Some ( metadata) = Self :: get_metadata ( k) {
297
+ metadata. existential_deposit
298
+ } else {
299
+ // Asset does not exist - not supported
300
+ T :: Balance :: max_value ( )
301
+ }
302
+ }
303
+ }
0 commit comments