use frame_support::pallet_prelude::*;
use sp_runtime::DispatchResult;
use sp_std::fmt::Debug;
use xcm::v4::prelude::*;
use xcm::VersionedLocation;
pub trait WeightToFeeConverter {
fn convert_weight_to_fee(location: &Location, weight: Weight) -> Option<u128>;
}
pub trait FixedConversionRateProvider {
fn get_fee_per_second(location: &Location) -> 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(())
}
}
#[derive(TypeInfo, Encode, Decode, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound, MaxEncodedLen)]
#[codec(mel_bound(skip_type_params(StringLimit)))]
#[scale_info(skip_type_params(StringLimit))]
pub struct AssetMetadata<Balance, CustomMetadata, StringLimit: Get<u32>>
where
Balance: Clone + Debug + Eq + PartialEq,
CustomMetadata: Parameter + Member + TypeInfo,
{
pub decimals: u32,
pub name: BoundedVec<u8, StringLimit>,
pub symbol: BoundedVec<u8, StringLimit>,
pub existential_deposit: Balance,
pub location: Option<VersionedLocation>,
pub additional: CustomMetadata,
}
pub trait Inspect {
type AssetId;
type Balance: Clone + Debug + Eq + PartialEq;
type CustomMetadata: Parameter + Member + TypeInfo;
type StringLimit: Get<u32>;
fn asset_id(location: &Location) -> Option<Self::AssetId>;
fn metadata(
asset_id: &Self::AssetId,
) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>>;
fn metadata_by_location(
location: &Location,
) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>>;
fn location(asset_id: &Self::AssetId) -> Result<Option<Location>, DispatchError>;
}
pub trait Mutate: Inspect {
fn register_asset(
asset_id: Option<Self::AssetId>,
metadata: AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>,
) -> DispatchResult;
fn update_asset(
asset_id: Self::AssetId,
decimals: Option<u32>,
name: Option<BoundedVec<u8, Self::StringLimit>>,
symbol: Option<BoundedVec<u8, Self::StringLimit>>,
existential_deposit: Option<Self::Balance>,
location: Option<Option<VersionedLocation>>,
additional: Option<Self::CustomMetadata>,
) -> DispatchResult;
}