diff --git a/asset-registry/src/impls.rs b/asset-registry/src/impls.rs index cdc314434..1703ebea8 100644 --- a/asset-registry/src/impls.rs +++ b/asset-registry/src/impls.rs @@ -1,7 +1,9 @@ -use crate::{module::*, AssetMetadata}; +use crate::module::*; use frame_support::{log, pallet_prelude::*, weights::constants::WEIGHT_PER_SECOND}; use orml_traits::{ - asset_registry::{AssetProcessor, FixedConversionRateProvider, WeightToFeeConverter}, + asset_registry::{ + AssetMetadata, AssetProcessor, FixedConversionRateProvider, Inspect, Mutate, WeightToFeeConverter, + }, GetByKey, }; use sp_runtime::FixedPointNumber; @@ -10,7 +12,8 @@ use sp_runtime::{ ArithmeticError, FixedU128, }; use sp_std::prelude::*; -use xcm::v2::prelude::*; +use xcm::latest::prelude::*; +use xcm::VersionedMultiLocation; use xcm_builder::TakeRevenue; use xcm_executor::{traits::WeightTrader, Assets}; @@ -169,3 +172,54 @@ impl GetByKey for ExistentialDeposits { } } } + +impl Inspect for Pallet { + type AssetId = T::AssetId; + type Balance = T::Balance; + type CustomMetadata = T::CustomMetadata; + + fn asset_id(location: &MultiLocation) -> Option { + Pallet::::location_to_asset_id(location) + } + + fn metadata(id: &Self::AssetId) -> Option> { + Pallet::::metadata(id) + } + + fn metadata_by_location(location: &MultiLocation) -> Option> { + Pallet::::fetch_metadata_by_location(location) + } + + fn location(asset_id: &Self::AssetId) -> Result, DispatchError> { + Pallet::::multilocation(asset_id) + } +} + +impl Mutate for Pallet { + fn register_asset( + asset_id: Option, + metadata: AssetMetadata, + ) -> DispatchResult { + Pallet::::do_register_asset(metadata, asset_id) + } + + fn update_asset( + asset_id: Self::AssetId, + decimals: Option, + name: Option>, + symbol: Option>, + existential_deposit: Option, + location: Option>, + additional: Option, + ) -> DispatchResult { + Pallet::::do_update_asset( + asset_id, + decimals, + name, + symbol, + existential_deposit, + location, + additional, + ) + } +} diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index a3fc951d6..21150e8b2 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -4,6 +4,7 @@ #![allow(clippy::large_enum_variant)] use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg, transactional}; use frame_system::pallet_prelude::*; +pub use orml_traits::asset_registry::AssetMetadata; use orml_traits::asset_registry::AssetProcessor; use scale_info::TypeInfo; use sp_runtime::{ @@ -25,17 +26,6 @@ mod mock; #[cfg(test)] mod tests; -/// Data describing the asset properties. -#[derive(scale_info::TypeInfo, Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)] -pub struct AssetMetadata { - pub decimals: u32, - pub name: Vec, - pub symbol: Vec, - pub existential_deposit: Balance, - pub location: Option, - pub additional: CustomMetadata, -} - #[frame_support::pallet] pub mod module { use super::*; diff --git a/traits/src/asset_registry.rs b/traits/src/asset_registry.rs index 23b090e35..a57c29cd7 100644 --- a/traits/src/asset_registry.rs +++ b/traits/src/asset_registry.rs @@ -1,5 +1,8 @@ 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; @@ -15,3 +18,45 @@ pub trait AssetProcessor { Ok(()) } } + +/// Data describing the asset properties. +#[derive(scale_info::TypeInfo, Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)] +pub struct AssetMetadata { + pub decimals: u32, + pub name: Vec, + pub symbol: Vec, + pub existential_deposit: Balance, + pub location: Option, + 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; + fn metadata(asset_id: &Self::AssetId) -> Option>; + fn metadata_by_location(location: &MultiLocation) -> Option>; + fn location(asset_id: &Self::AssetId) -> Result, DispatchError>; +} + +pub trait Mutate: Inspect { + fn register_asset( + asset_id: Option, + metadata: AssetMetadata, + ) -> DispatchResult; + + fn update_asset( + asset_id: Self::AssetId, + decimals: Option, + name: Option>, + symbol: Option>, + existential_deposit: Option, + location: Option>, + additional: Option, + ) -> DispatchResult; +}