Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add generic create registry asset which accepts asset type #649

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 10 additions & 1 deletion pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

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 {
Expand Down Expand Up @@ -614,3 +614,12 @@
Pallet::<T>::assets(k).and_then(|details| details.xcm_rate_limit)
}
}

impl<T: Config> CreateRegistry<T::AssetId, T::Balance> for Pallet<T> {
type Error = DispatchError;

fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: T::Balance) -> Result<T::AssetId, Self::Error> {
let bounded_name: BoundedVec<u8, T::StringLimit> = Self::to_bounded_name(name.to_vec())?;
Pallet::<T>::register_asset(bounded_name, kind.into(), existential_deposit, None, None)

Check warning on line 623 in pallets/asset-registry/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/asset-registry/src/lib.rs#L621-L623

Added lines #L621 - L623 were not covered by tests
}
}
16 changes: 15 additions & 1 deletion pallets/asset-registry/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,29 @@
use scale_info::TypeInfo;
use sp_std::vec::Vec;

use hydradx_traits::AssetKind;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum AssetType<AssetId> {
Token,
PoolShare(AssetId, AssetId),
PoolShare(AssetId, AssetId), // Use XYX instead
XYK,
StableSwap,
Bond,
}

impl<AssetId> From<AssetKind> for AssetType<AssetId> {
fn from(value: AssetKind) -> Self {
match value {
AssetKind::Token => Self::Token,
AssetKind::XYK => Self::XYK,
AssetKind::StableSwap => Self::StableSwap,
AssetKind::Bond => Self::Bond,

Check warning on line 42 in pallets/asset-registry/src/types.rs

View check run for this annotation

Codecov / codecov/patch

pallets/asset-registry/src/types.rs#L37-L42

Added lines #L37 - L42 were not covered by tests
}
}
}

#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)]
Expand Down
2 changes: 1 addition & 1 deletion traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-traits"
version = "2.4.0"
version = "2.5.0"
description = "Shared traits"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
14 changes: 14 additions & 0 deletions traits/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub trait Registry<AssetId, AssetName, Balance, Error> {
}
}

// Use CreateRegistry if possible
pub trait ShareTokenRegistry<AssetId, AssetName, Balance, Error>: Registry<AssetId, AssetName, Balance, Error> {
fn retrieve_shared_asset(name: &AssetName, assets: &[AssetId]) -> Result<AssetId, Error>;

Expand All @@ -38,6 +39,19 @@ pub trait ShareTokenRegistry<AssetId, AssetName, Balance, Error>: Registry<Asset
}
}

#[derive(Eq, PartialEq, Copy, Clone)]
pub enum AssetKind {
Token,
XYK,
StableSwap,
Bond,
}

pub trait CreateRegistry<AssetId, Balance> {
type Error;
fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: Balance) -> Result<AssetId, Self::Error>;
}

// 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")]
Expand Down
Loading