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

Max asset ID restriction for new trusted assets #346

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 27 additions & 3 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -278,11 +278,35 @@ parameter_types! {
// https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271
pub const MetadataDepositBase: Balance = system_para_deposit(1, 68);
pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1);
/// The asset ID's auto increment for trusted assets planned with the next release.
pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000;
}

/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;

/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is
/// signed.
pub struct EnsureLessThanAutoIncrement;
impl EnsureOriginWithArg<RuntimeOrigin, AssetIdForTrustBackedAssets>
for EnsureLessThanAutoIncrement
{
type Success = AccountId;
fn try_origin(
o: RuntimeOrigin,
a: &AssetIdForTrustBackedAssets,
) -> Result<Self::Success, RuntimeOrigin> {
if a >= &TrustAssetIdAutoIncrement::get() {
muharem marked this conversation as resolved.
Show resolved Hide resolved
return Err(o);
}
<EnsureSigned<AccountId> as EnsureOrigin<RuntimeOrigin>>::try_origin(o)
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result<RuntimeOrigin, ()> {
<EnsureSigned<AccountId> as EnsureOrigin<RuntimeOrigin>>::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.
Expand All @@ -294,7 +318,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type CreateOrigin = EnsureLessThanAutoIncrement;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
Expand Down
30 changes: 27 additions & 3 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -296,11 +296,35 @@ parameter_types! {
// https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271
pub const MetadataDepositBase: Balance = system_para_deposit(1, 68);
pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1);
/// The asset ID's auto increment for trusted assets planned with the next release.
pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000;
}

/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;

/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is
/// signed.
pub struct EnsureLessThanAutoIncrement;
impl EnsureOriginWithArg<RuntimeOrigin, AssetIdForTrustBackedAssets>
for EnsureLessThanAutoIncrement
{
type Success = AccountId;
fn try_origin(
o: RuntimeOrigin,
a: &AssetIdForTrustBackedAssets,
) -> Result<Self::Success, RuntimeOrigin> {
if a >= &TrustAssetIdAutoIncrement::get() {
muharem marked this conversation as resolved.
Show resolved Hide resolved
return Err(o);
}
<EnsureSigned<AccountId> as EnsureOrigin<RuntimeOrigin>>::try_origin(o)
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result<RuntimeOrigin, ()> {
<EnsureSigned<AccountId> as EnsureOrigin<RuntimeOrigin>>::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.
Expand All @@ -312,7 +336,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type CreateOrigin = EnsureLessThanAutoIncrement;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
Expand Down
Loading