1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use frame_support::pallet_prelude::*;
use sp_runtime::DispatchResult;
use sp_std::vec::Vec;
use xcm::latest::prelude::*;
use xcm::VersionedMultiLocation;

pub trait WeightToFeeConverter {
	fn convert_weight_to_fee(location: &MultiLocation, weight: Weight) -> Option<u128>;
}

pub trait FixedConversionRateProvider {
	fn get_fee_per_second(location: &MultiLocation) -> Option<u128>;
}

pub trait AssetProcessor<AssetId, Metadata> {
	fn pre_register(id: Option<AssetId>, asset_metadata: Metadata) -> Result<(AssetId, Metadata), DispatchError>;
	fn post_register(_id: AssetId, _asset_metadata: Metadata) -> Result<(), DispatchError> {
		Ok(())
	}
}

/// Data describing the asset properties.
#[derive(scale_info::TypeInfo, Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)]
pub struct AssetMetadata<Balance, CustomMetadata: Parameter + Member + TypeInfo> {
	pub decimals: u32,
	pub name: Vec<u8>,
	pub symbol: Vec<u8>,
	pub existential_deposit: Balance,
	pub location: Option<VersionedMultiLocation>,
	pub additional: CustomMetadata,
}

pub trait Inspect {
	/// AssetId type
	type AssetId;
	/// Balance type
	type Balance;
	/// Custom metadata type
	type CustomMetadata: Parameter + Member + TypeInfo;

	fn asset_id(location: &MultiLocation) -> Option<Self::AssetId>;
	fn metadata(asset_id: &Self::AssetId) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata>>;
	fn metadata_by_location(location: &MultiLocation) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata>>;
	fn location(asset_id: &Self::AssetId) -> Result<Option<MultiLocation>, DispatchError>;
}

pub trait Mutate: Inspect {
	fn register_asset(
		asset_id: Option<Self::AssetId>,
		metadata: AssetMetadata<Self::Balance, Self::CustomMetadata>,
	) -> DispatchResult;

	fn update_asset(
		asset_id: Self::AssetId,
		decimals: Option<u32>,
		name: Option<Vec<u8>>,
		symbol: Option<Vec<u8>>,
		existential_deposit: Option<Self::Balance>,
		location: Option<Option<VersionedMultiLocation>>,
		additional: Option<Self::CustomMetadata>,
	) -> DispatchResult;
}