diff --git a/CHANGELOG.md b/CHANGELOG.md index 7275a1e43b..e0b1c75c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed + +- Set max asset ID restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) + ### Fixed - Kusama People: clear requested judgements that do not have corresponding deposits reserved ([polkadot-fellows/runtimes#339](https://github.com/polkadot-fellows/runtimes/pull/339)) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index fff90be3ff..1e0ad3b0a3 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -60,8 +60,8 @@ use frame_support::{ ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, - TransformOrigin, WithdrawReasons, + ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, + Equals, InstanceFilter, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight}, BoundedVec, PalletId, @@ -283,6 +283,27 @@ parameter_types! { /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; +/// Ensure that the proposed asset id is less than `50_000_000` and origin is signed. +pub struct EnsureLessThanAutoIncrement; +impl EnsureOriginWithArg + for EnsureLessThanAutoIncrement +{ + type Success = AccountId; + fn try_origin( + o: RuntimeOrigin, + a: &AssetIdForTrustBackedAssets, + ) -> Result { + if *a >= 50_000_000 { + return Err(o); + } + as EnsureOrigin>::try_origin(o) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result { + as EnsureOrigin>::try_successful_origin() + } +} + // Called "Trust Backed" assets because these are generally registered by some account, and users of // the asset assume it has some claimed backing. The pallet is called `Assets` in // `construct_runtime` to avoid breaking changes on storage reads. @@ -294,7 +315,7 @@ impl pallet_assets::Config for Runtime { type AssetId = AssetIdForTrustBackedAssets; type AssetIdParameter = codec::Compact; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; + type CreateOrigin = EnsureLessThanAutoIncrement; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f52b4c6ea2..3f5d1a65bb 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -94,8 +94,8 @@ use frame_support::{ parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, NeverEnsureOrigin, - TransformOrigin, WithdrawReasons, + ConstU32, ConstU64, ConstU8, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, Equals, + InstanceFilter, NeverEnsureOrigin, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -301,6 +301,27 @@ parameter_types! { /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; +/// Ensure that the proposed asset id is less than `50_000_000` and origin is signed. +pub struct EnsureLessThanAutoIncrement; +impl EnsureOriginWithArg + for EnsureLessThanAutoIncrement +{ + type Success = AccountId; + fn try_origin( + o: RuntimeOrigin, + a: &AssetIdForTrustBackedAssets, + ) -> Result { + if *a >= 50_000_000 { + return Err(o); + } + as EnsureOrigin>::try_origin(o) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result { + as EnsureOrigin>::try_successful_origin() + } +} + // Called "Trust Backed" assets because these are generally registered by some account, and users of // the asset assume it has some claimed backing. The pallet is called `Assets` in // `construct_runtime` to avoid breaking changes on storage reads. @@ -312,7 +333,7 @@ impl pallet_assets::Config for Runtime { type AssetId = AssetIdForTrustBackedAssets; type AssetIdParameter = codec::Compact; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; + type CreateOrigin = EnsureLessThanAutoIncrement; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase;