Skip to content

Commit 558b538

Browse files
committed
add existential deposit
1 parent 252750a commit 558b538

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

asset-registry/src/lib.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use frame_support::{log, pallet_prelude::*};
66
use frame_system::pallet_prelude::*;
77
pub use module::*;
88
use orml_traits::asset_registry::{FixedConversionRateProvider, WeightToFeeConverter};
9+
use orml_traits::GetByKey;
910
use scale_info::TypeInfo;
11+
use sp_runtime::traits::AtLeast32BitUnsigned;
12+
use sp_runtime::traits::Bounded;
1013
use sp_runtime::{traits::Member, DispatchResult};
1114
use sp_std::prelude::*;
1215
use xcm::latest::prelude::*;
@@ -18,12 +21,13 @@ pub trait AssetProcessor<AssetId, Metadata> {
1821
}
1922

2023
#[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> {
2225
pub decimals: u32,
2326
pub name: Vec<u8>,
2427
pub symbol: Vec<u8>,
28+
pub existential_deposit: Balance,
2529
pub location: Option<MultiLocation>,
26-
pub additional: T,
30+
pub additional: CustomMetadata,
2731
}
2832

2933
#[frame_support::pallet]
@@ -40,7 +44,16 @@ pub mod module {
4044

4145
type AuthorityOrigin: EnsureOrigin<<Self as frame_system::Config>::Origin>;
4246

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>;
4457
// /// Weight information for extrinsics in this module.
4558
// type WeightInfo: WeightInfo;
4659
}
@@ -56,7 +69,7 @@ pub mod module {
5669
pub enum Event<T: Config> {
5770
RegisteredAsset {
5871
asset_id: T::AssetId,
59-
metadata: AssetMetadata<T::CustomMetadata>,
72+
metadata: AssetMetadata<T::Balance, T::CustomMetadata>,
6073
},
6174
SetLocation {
6275
asset_id: T::AssetId,
@@ -68,7 +81,7 @@ pub mod module {
6881
#[pallet::storage]
6982
#[pallet::getter(fn get_metadata)]
7083
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>;
7285

7386
/// The total issuance of a token type.
7487
#[pallet::storage]
@@ -110,7 +123,7 @@ pub mod module {
110123
#[pallet::weight(0)]
111124
pub fn register_asset(
112125
origin: OriginFor<T>,
113-
metadata: AssetMetadata<T::CustomMetadata>,
126+
metadata: AssetMetadata<T::Balance, T::CustomMetadata>,
114127
asset_id: Option<T::AssetId>,
115128
) -> DispatchResult {
116129
let _ = T::AuthorityOrigin::ensure_origin(origin)?;
@@ -165,7 +178,9 @@ pub mod module {
165178
}
166179

167180
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>> {
169184
let asset_id = MultiLocationLookup::<T>::get(location)?;
170185
Metadata::<T>::get(asset_id)
171186
}
@@ -273,3 +288,16 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> Drop for AssetRegistryTrader<W, R>
273288
}
274289
}
275290
}
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

Comments
 (0)