diff --git a/Cargo.lock b/Cargo.lock index 1f0e0e8e9..04b884f64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3915,7 +3915,7 @@ dependencies = [ [[package]] name = "hydradx-traits" -version = "2.4.0" +version = "2.5.0" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -6196,7 +6196,7 @@ dependencies = [ [[package]] name = "pallet-asset-registry" -version = "2.2.3" +version = "2.2.4" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/pallets/asset-registry/Cargo.toml b/pallets/asset-registry/Cargo.toml index 6c3d103da..a2238fa13 100644 --- a/pallets/asset-registry/Cargo.toml +++ b/pallets/asset-registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-asset-registry" -version = "2.2.3" +version = "2.2.4" description = "Pallet for asset registry management" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index e04778035..aa5ece555 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -46,7 +46,7 @@ pub use pallet::*; use crate::types::{AssetDetails, AssetMetadata}; use frame_support::BoundedVec; -use hydradx_traits::{Registry, ShareTokenRegistry}; +use hydradx_traits::{AssetKind, CreateRegistry, Registry, ShareTokenRegistry}; #[frame_support::pallet] pub mod pallet { @@ -614,3 +614,12 @@ impl GetByKey> for XcmRateLimitsInRegi Pallet::::assets(k).and_then(|details| details.xcm_rate_limit) } } + +impl CreateRegistry for Pallet { + type Error = DispatchError; + + fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: T::Balance) -> Result { + let bounded_name: BoundedVec = Self::to_bounded_name(name.to_vec())?; + Pallet::::register_asset(bounded_name, kind.into(), existential_deposit, None, None) + } +} diff --git a/pallets/asset-registry/src/types.rs b/pallets/asset-registry/src/types.rs index 7488bcc6a..364354e41 100644 --- a/pallets/asset-registry/src/types.rs +++ b/pallets/asset-registry/src/types.rs @@ -19,6 +19,7 @@ use frame_support::pallet_prelude::*; use scale_info::TypeInfo; use sp_std::vec::Vec; +use hydradx_traits::AssetKind; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -26,8 +27,21 @@ use serde::{Deserialize, Serialize}; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum AssetType { Token, - PoolShare(AssetId, AssetId), + PoolShare(AssetId, AssetId), // Use XYX instead + XYK, StableSwap, + Bond, +} + +impl From for AssetType { + fn from(value: AssetKind) -> Self { + match value { + AssetKind::Token => Self::Token, + AssetKind::XYK => Self::XYK, + AssetKind::StableSwap => Self::StableSwap, + AssetKind::Bond => Self::Bond, + } + } } #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 170ccf1d1..e78c571cb 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-traits" -version = "2.4.0" +version = "2.5.0" description = "Shared traits" authors = ["GalacticCouncil"] edition = "2021" diff --git a/traits/src/registry.rs b/traits/src/registry.rs index 4b795553b..231c07d93 100644 --- a/traits/src/registry.rs +++ b/traits/src/registry.rs @@ -16,6 +16,7 @@ pub trait Registry { } } +// Use CreateRegistry if possible pub trait ShareTokenRegistry: Registry { fn retrieve_shared_asset(name: &AssetName, assets: &[AssetId]) -> Result; @@ -38,6 +39,19 @@ pub trait ShareTokenRegistry: Registry { + type Error; + fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: Balance) -> Result; +} + // Deprecated. // TODO: the following macro is commented out for a reason for now - due to failing clippy in CI // #[deprecated(since = "0.6.0", note = "Please use `AccountIdFor` instead")]