Skip to content

Commit

Permalink
Add custom metadata and parameters for asset registry (#398)
Browse files Browse the repository at this point in the history
* Modify CustomMetadata struct to hold blockchain and symbol info for assets in asset registry

* Fmt
  • Loading branch information
bogdanS98 authored Jan 18, 2024
1 parent 2be0703 commit b786560
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
5 changes: 4 additions & 1 deletion runtime/amplitude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use zenlink_protocol::{AssetBalance, MultiAssetsHandler, PairInfo};
pub use parachain_staking::InflationInfo;

use codec::Encode;
use scale_info::TypeInfo;

use smallvec::smallvec;
use sp_api::impl_runtime_apis;
Expand Down Expand Up @@ -830,6 +831,8 @@ impl orml_tokens::Config for Runtime {

parameter_types! {
pub const NativeCurrencyId: CurrencyId = CurrencyId::Native;
#[derive(Clone, Eq, PartialEq, Debug, TypeInfo)]
pub const StringLimit: u32 = 50;
}

impl orml_currencies::Config for Runtime {
Expand All @@ -841,7 +844,7 @@ impl orml_currencies::Config for Runtime {

impl orml_asset_registry::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CustomMetadata = asset_registry::CustomMetadata;
type CustomMetadata = asset_registry::CustomMetadata<StringLimit>;
type AssetId = CurrencyId;
type AuthorityOrigin = asset_registry::AssetAuthority;
type AssetProcessor = asset_registry::CustomAssetProcessor;
Expand Down
28 changes: 22 additions & 6 deletions runtime/common/src/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,37 @@ use frame_system::EnsureRoot;
use orml_traits::asset_registry::{AssetMetadata, AssetProcessor};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::DispatchError;
use sp_core::Get;
use sp_runtime::{BoundedVec, DispatchError};
use sp_std::fmt::Debug;
use spacewalk_primitives::CurrencyId;

pub use spacewalk_primitives::CustomMetadata;
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct CustomMetadata<T: Get<u32> + TypeInfo + Clone + Eq + Debug + Send + Sync> {
pub dia_keys: DiaKeys<T>,
pub fee_per_second: u128,
}

#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct DiaKeys<T: Get<u32> + TypeInfo + Clone + Eq + Debug + Send + Sync> {
pub blockchain: BoundedVec<u8, T>,
pub symbol: BoundedVec<u8, T>,
}

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub struct CustomAssetProcessor;

impl AssetProcessor<CurrencyId, AssetMetadata<Balance, CustomMetadata>> for CustomAssetProcessor {
impl<T> AssetProcessor<CurrencyId, AssetMetadata<Balance, CustomMetadata<T>>>
for CustomAssetProcessor
where
T: Get<u32> + TypeInfo + Clone + Eq + Debug + Send + Sync + 'static,
{
fn pre_register(
id: Option<CurrencyId>,
metadata: AssetMetadata<Balance, CustomMetadata>,
) -> Result<(CurrencyId, AssetMetadata<Balance, CustomMetadata>), DispatchError> {
metadata: AssetMetadata<Balance, CustomMetadata<T>>,
) -> Result<(CurrencyId, AssetMetadata<Balance, CustomMetadata<T>>), DispatchError> {
match id {
Some(id) => Ok((id, metadata)),
None => Err(DispatchError::Other("asset-registry: AssetId is required")),
Expand All @@ -27,7 +43,7 @@ impl AssetProcessor<CurrencyId, AssetMetadata<Balance, CustomMetadata>> for Cust

fn post_register(
_id: CurrencyId,
_asset_metadata: AssetMetadata<Balance, CustomMetadata>,
_asset_metadata: AssetMetadata<Balance, CustomMetadata<T>>,
) -> Result<(), DispatchError> {
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion runtime/foucoco/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ impl orml_tokens::Config for Runtime {

parameter_types! {
pub const NativeCurrencyId: CurrencyId = CurrencyId::Native;
#[derive(Clone, Eq, PartialEq, Debug, TypeInfo)]
pub const StringLimit: u32 = 50;
}

impl orml_currencies::Config for Runtime {
Expand All @@ -844,7 +846,7 @@ impl orml_currencies::Config for Runtime {

impl orml_asset_registry::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CustomMetadata = asset_registry::CustomMetadata;
type CustomMetadata = asset_registry::CustomMetadata<StringLimit>;
type AssetId = CurrencyId;
type AuthorityOrigin = asset_registry::AssetAuthority;
type AssetProcessor = asset_registry::CustomAssetProcessor;
Expand Down
5 changes: 4 additions & 1 deletion runtime/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use zenlink_protocol::{AssetBalance, MultiAssetsHandler, PairInfo};
pub use parachain_staking::InflationInfo;

use codec::Encode;
use scale_info::TypeInfo;

use smallvec::smallvec;
use sp_api::impl_runtime_apis;
Expand Down Expand Up @@ -735,6 +736,8 @@ impl orml_tokens::Config for Runtime {

parameter_types! {
pub const NativeCurrencyId: CurrencyId = CurrencyId::Native;
#[derive(Clone, Eq, PartialEq, Debug, TypeInfo)]
pub const StringLimit: u32 = 50;
}

impl orml_currencies::Config for Runtime {
Expand All @@ -746,7 +749,7 @@ impl orml_currencies::Config for Runtime {

impl orml_asset_registry::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CustomMetadata = asset_registry::CustomMetadata;
type CustomMetadata = asset_registry::CustomMetadata<StringLimit>;
type AssetId = CurrencyId;
type AuthorityOrigin = asset_registry::AssetAuthority;
type AssetProcessor = asset_registry::CustomAssetProcessor;
Expand Down

0 comments on commit b786560

Please sign in to comment.