Adds default config for assets pallet (#3637)

Step in https://github.com/paritytech/polkadot-sdk/issues/171
This commit is contained in:
gupnik
2024-03-12 10:12:58 +05:30
committed by GitHub
parent 7a644fa082
commit 7315a9b8fd
2 changed files with 43 additions and 16 deletions
+42 -1
View File
@@ -226,10 +226,42 @@ pub mod pallet {
}
}
#[pallet::config]
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::*;
use frame_support::{derive_impl, traits::ConstU64};
pub struct TestDefaultConfig;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}
#[frame_support::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
#[inject_runtime_type]
type RuntimeEvent = ();
type Balance = u64;
type RemoveItemsLimit = ConstU32<5>;
type AssetId = u32;
type AssetIdParameter = u32;
type AssetDeposit = ConstU64<1>;
type AssetAccountDeposit = ConstU64<10>;
type MetadataDepositBase = ConstU64<1>;
type MetadataDepositPerByte = ConstU64<1>;
type ApprovalDeposit = ConstU64<1>;
type StringLimit = ConstU32<50>;
type Extra = ();
type CallbackHandle = ();
type WeightInfo = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
}
#[pallet::config(with_default)]
/// The module configuration trait.
pub trait Config<I: 'static = ()>: frame_system::Config {
/// The overarching event type.
#[pallet::no_default_bounds]
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
@@ -262,10 +294,12 @@ pub mod pallet {
type AssetIdParameter: Parameter + From<Self::AssetId> + Into<Self::AssetId> + MaxEncodedLen;
/// The currency mechanism.
#[pallet::no_default]
type Currency: ReservableCurrency<Self::AccountId>;
/// Standard asset class creation is only allowed if the origin attempting it and the
/// asset class are in this set.
#[pallet::no_default]
type CreateOrigin: EnsureOriginWithArg<
Self::RuntimeOrigin,
Self::AssetId,
@@ -274,28 +308,34 @@ pub mod pallet {
/// The origin which may forcibly create or destroy an asset or otherwise alter privileged
/// attributes.
#[pallet::no_default]
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// The basic amount of funds that must be reserved for an asset.
#[pallet::constant]
#[pallet::no_default_bounds]
type AssetDeposit: Get<DepositBalanceOf<Self, I>>;
/// The amount of funds that must be reserved for a non-provider asset account to be
/// maintained.
#[pallet::constant]
#[pallet::no_default_bounds]
type AssetAccountDeposit: Get<DepositBalanceOf<Self, I>>;
/// The basic amount of funds that must be reserved when adding metadata to your asset.
#[pallet::constant]
#[pallet::no_default_bounds]
type MetadataDepositBase: Get<DepositBalanceOf<Self, I>>;
/// The additional funds that must be reserved for the number of bytes you store in your
/// metadata.
#[pallet::constant]
#[pallet::no_default_bounds]
type MetadataDepositPerByte: Get<DepositBalanceOf<Self, I>>;
/// The amount of funds that must be reserved when creating a new approval.
#[pallet::constant]
#[pallet::no_default_bounds]
type ApprovalDeposit: Get<DepositBalanceOf<Self, I>>;
/// The maximum length of a name or symbol stored on-chain.
@@ -304,6 +344,7 @@ pub mod pallet {
/// A hook to allow a per-asset, per-account minimum balance to be enforced. This must be
/// respected in all permissionless operations.
#[pallet::no_default]
type Freezer: FrozenBalance<Self::AssetId, Self::AccountId, Self::Balance>;
/// Additional data to be stored with an account's asset balance.
+1 -15
View File
@@ -108,27 +108,13 @@ impl AssetsCallbackHandle {
}
}
#[derive_impl(crate::config_preludes::TestDefaultConfig)]
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = u64;
type AssetId = u32;
type AssetIdParameter = u32;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
type ForceOrigin = frame_system::EnsureRoot<u64>;
type AssetDeposit = ConstU64<1>;
type AssetAccountDeposit = ConstU64<10>;
type MetadataDepositBase = ConstU64<1>;
type MetadataDepositPerByte = ConstU64<1>;
type ApprovalDeposit = ConstU64<1>;
type StringLimit = ConstU32<50>;
type Freezer = TestFreezer;
type WeightInfo = ();
type CallbackHandle = AssetsCallbackHandle;
type Extra = ();
type RemoveItemsLimit = ConstU32<5>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
use std::collections::HashMap;