Skip to content

Commit

Permalink
asset-registry: removed NativeAssetId from config + make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfridrich committed Oct 23, 2023
1 parent def81db commit 776f9cd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pallets/asset-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ benchmarks! {

register_external {
let caller: T::AccountId = account("caller", 0, 1);
T::Currency::update_balance(T::NativeAssetId::get(), &caller, (100_000 * UNIT) as i128)?;
T::Currency::update_balance(T::StorageFeesAssetId::get(), &caller, (100_000 * UNIT) as i128)?;

let expected_asset_id = Pallet::<T>::next_asset_id().unwrap();
let location: T::AssetNativeLocation = Default::default();
Expand Down
13 changes: 7 additions & 6 deletions pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ pub mod pallet {
#[pallet::constant]
type SequentialIdStartAt: Get<Self::AssetId>;

/// Native Asset Id
/// Id of the asset that is used to pay storage fees.
#[pallet::constant]
type NativeAssetId: Get<Self::AssetId>;
type StorageFeesAssetId: Get<Self::AssetId>;

/// Storage fees for external asset creation.
#[pallet::constant]
Expand Down Expand Up @@ -237,9 +237,10 @@ pub mod pallet {
let native_symbol = Pallet::<T>::try_into_bounded(Some(self.native_symbol.to_vec()))
.expect("Invalid native asset symbol!");

let native_asset_id = T::AssetId::from(0);
AssetIds::<T>::insert(
native_asset_name.as_ref().expect("Invalid native asset name!"),
T::NativeAssetId::get(),
native_asset_id,
);
let details = AssetDetails {
name: native_asset_name,
Expand All @@ -251,7 +252,7 @@ pub mod pallet {
is_sufficient: true,
};

Assets::<T>::insert(T::NativeAssetId::get(), details);
Assets::<T>::insert(native_asset_id, details);

self.registered_assets.iter().for_each(
|(id, name, ed, symbol, decimals, xcm_rate_limit, is_sufficient)| {
Expand Down Expand Up @@ -470,12 +471,12 @@ pub mod pallet {

if !T::StorageFees::get().is_zero() {
ensure!(
T::Currency::ensure_can_withdraw(T::NativeAssetId::get(), &who, T::StorageFees::get()).is_ok(),
T::Currency::ensure_can_withdraw(T::StorageFeesAssetId::get(), &who, T::StorageFees::get()).is_ok(),
Error::<T>::InsufficientBalance
);

T::Currency::transfer(
T::NativeAssetId::get(),
T::StorageFeesAssetId::get(),
&who,
&T::StorageFeesBeneficiary::get(),
T::StorageFees::get(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/asset-registry/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl pallet_asset_registry::Config for Test {
type AssetNativeLocation = AssetLocation;
type StringLimit = RegistryStringLimit;
type SequentialIdStartAt = SequentialIdStart;
type NativeAssetId = NativeAssetId;
type StorageFeesAssetId = NativeAssetId;
type StorageFees = StoreFees;
type StorageFeesBeneficiary = FeesBeneficiarry;
type WeightInfo = ();
Expand Down
12 changes: 6 additions & 6 deletions pallets/asset-registry/src/tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,12 @@ fn register_should_fail_when_name_is_too_long() {
Registry::register(
RuntimeOrigin::root(),
Some(asset_id),
Some(name.clone()),
Some(name),
AssetType::Token,
Some(ed),
Some(symbol.clone()),
Some(symbol),
Some(decimals),
Some(asset_location.clone()),
Some(asset_location),
Some(xcm_rate_limit),
is_sufficient
),
Expand Down Expand Up @@ -554,12 +554,12 @@ fn register_should_fail_when_symbol_is_too_long() {
Registry::register(
RuntimeOrigin::root(),
Some(asset_id),
Some(name.clone()),
Some(name),
AssetType::Token,
Some(ed),
Some(symbol.clone()),
Some(symbol),
Some(decimals),
Some(asset_location.clone()),
Some(asset_location),
Some(xcm_rate_limit),
is_sufficient
),
Expand Down
8 changes: 4 additions & 4 deletions pallets/asset-registry/src/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,12 @@ fn update_should_fail_when_name_is_too_long() {
Registry::update(
RuntimeOrigin::root(),
asset_id,
Some(name.clone()),
Some(name),
Some(AssetType::External),
Some(ed),
Some(xcm_rate_limit),
Some(is_sufficient),
Some(symbol.clone()),
Some(symbol),
Some(decimals),
None
),
Expand Down Expand Up @@ -679,12 +679,12 @@ fn update_should_fail_when_symbolis_too_long() {
Registry::update(
RuntimeOrigin::root(),
asset_id,
Some(name.clone()),
Some(name),
Some(AssetType::External),
Some(ed),
Some(xcm_rate_limit),
Some(is_sufficient),
Some(symbol.clone()),
Some(symbol),
Some(decimals),
None
),
Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl pallet_asset_registry::Config for Test {
type AssetNativeLocation = u8;
type StringLimit = RegistryStringLimit;
type SequentialIdStartAt = SequentialIdOffset;
type NativeAssetId = NativeAssetId;
type StorageFeesAssetId = NativeAssetId;
type StorageFees = StoreFees;
type StorageFeesBeneficiary = FeesBeneficiarry;
type WeightInfo = ();
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl pallet_asset_registry::Config for Runtime {
type AssetNativeLocation = AssetLocation;
type StringLimit = RegistryStrLimit;
type SequentialIdStartAt = SequentialIdOffset;
type NativeAssetId = NativeAssetId;
type StorageFeesAssetId = NativeAssetId;
type StorageFees = StoreFees;
type StorageFeesBeneficiary = TreasuryAccount;
type WeightInfo = weights::registry::HydraWeight<Runtime>;
Expand Down

0 comments on commit 776f9cd

Please sign in to comment.