Skip to content

Commit

Permalink
Optimize asset registry (#1445)
Browse files Browse the repository at this point in the history
* optimize asset-registry & remove unused call

* backup asset-registry pallet
  • Loading branch information
SunTiebing authored Sep 29, 2024
1 parent 0aaf2cd commit c081548
Show file tree
Hide file tree
Showing 18 changed files with 2,496 additions and 890 deletions.
140 changes: 3 additions & 137 deletions pallets/asset-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,12 @@

use super::*;
use crate::Pallet as AssetRegistry;
use bifrost_primitives::{CurrencyId, TokenSymbol};
use bifrost_primitives::CurrencyId;
use frame_benchmarking::{benchmarks, v1::BenchmarkError};
use frame_support::{assert_ok, traits::UnfilteredDispatchable};
use sp_runtime::traits::UniqueSaturatedFrom;

benchmarks! {
register_native_asset {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)]));

let call = Call::<T>::register_native_asset {
currency_id: Token(TokenSymbol::DOT),
location: Box::new(versioned_location.clone()),
metadata: Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(1u128),
})
};
}: {call.dispatch_bypass_filter(origin)?}
verify {
assert_eq!(
AssetMetadatas::<T>::get(AssetIds::NativeAssetId(Token(
TokenSymbol::DOT
))),
Some(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(1u128),
})
);
}

update_native_asset {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)]));

assert_ok!(AssetRegistry::<T>::register_native_asset(
origin.clone(),
Token(TokenSymbol::DOT),
Box::new(versioned_location.clone()),
Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(1u128),
})
));

let call = Call::<T>::update_native_asset {
currency_id: Token(TokenSymbol::DOT),
location: Box::new(versioned_location.clone()),
metadata: Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
decimals: 13,
minimal_balance: BalanceOf::<T>::unique_saturated_from(2u128),
})
};
}: {call.dispatch_bypass_filter(origin)?}
verify {
assert_eq!(
AssetMetadatas::<T>::get(AssetIds::NativeAssetId(Token(
TokenSymbol::DOT
))),
Some(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
decimals: 13,
minimal_balance: BalanceOf::<T>::unique_saturated_from(2u128),
})
);
}

register_token_metadata {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
Expand Down Expand Up @@ -143,70 +73,6 @@ benchmarks! {
)
}

register_vstoken_metadata {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"KSM Native Token".to_vec(),
symbol: b"KSM".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(0u128),
};
let v_metadata = AssetMetadata {
name: b"Voucher Slot KSM".to_vec(),
symbol: b"vsKSM".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(0u128),
};
assert_ok!(AssetRegistry::<T>::register_token_metadata(
origin.clone(),
Box::new(metadata.clone())
));

let call = Call::<T>::register_vstoken_metadata {
token_id: 0
};
}: {call.dispatch_bypass_filter(origin)?}
verify {
assert_eq!(
CurrencyMetadatas::<T>::get(CurrencyId::VSToken2(0)),
Some(v_metadata.clone())
)
}

register_vsbond_metadata {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"KSM Native Token".to_vec(),
symbol: b"KSM".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(0u128),
};
let name = "vsBOND-KSM-2001-10-20".as_bytes().to_vec();
let v_metadata = AssetMetadata {
name: name.clone(),
symbol: name,
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(0u128),
};
assert_ok!(AssetRegistry::<T>::register_token_metadata(
origin.clone(),
Box::new(metadata.clone())
));

let call = Call::<T>::register_vsbond_metadata {
token_id: 0,
para_id:2001,
first_slot:10,
last_slot:20
};
}: {call.dispatch_bypass_filter(origin)?}
verify {
assert_eq!(
CurrencyMetadatas::<T>::get(CurrencyId::VSBond2(0, 2001, 10, 20)),
Some(v_metadata.clone())
)
}

register_location {
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
Expand All @@ -217,7 +83,7 @@ benchmarks! {
};
let versioned_location = VersionedLocation::V4(Location::new(1, [Parachain(2001)]));

let location: xcm::v3::Location = versioned_location.clone().try_into().unwrap();
let location: xcm::v4::Location = versioned_location.clone().try_into().unwrap();

assert_ok!(AssetRegistry::<T>::register_token_metadata(
origin.clone(),
Expand All @@ -232,7 +98,7 @@ benchmarks! {
}: {call.dispatch_bypass_filter(origin)?}
verify {
assert_eq!(
LocationToCurrencyIds::<T>::get(location),
LocationToCurrencyIds::<T>::get(location.clone()),
Some(Token2(0))
);
assert_eq!(
Expand Down
Loading

0 comments on commit c081548

Please sign in to comment.