Skip to content

Commit 7315a9b

Browse files
authored
Adds default config for assets pallet (#3637)
Step in #171
1 parent 7a644fa commit 7315a9b

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

substrate/frame/assets/src/lib.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,42 @@ pub mod pallet {
226226
}
227227
}
228228

229-
#[pallet::config]
229+
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
230+
pub mod config_preludes {
231+
use super::*;
232+
use frame_support::{derive_impl, traits::ConstU64};
233+
pub struct TestDefaultConfig;
234+
235+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
236+
impl frame_system::DefaultConfig for TestDefaultConfig {}
237+
238+
#[frame_support::register_default_impl(TestDefaultConfig)]
239+
impl DefaultConfig for TestDefaultConfig {
240+
#[inject_runtime_type]
241+
type RuntimeEvent = ();
242+
type Balance = u64;
243+
type RemoveItemsLimit = ConstU32<5>;
244+
type AssetId = u32;
245+
type AssetIdParameter = u32;
246+
type AssetDeposit = ConstU64<1>;
247+
type AssetAccountDeposit = ConstU64<10>;
248+
type MetadataDepositBase = ConstU64<1>;
249+
type MetadataDepositPerByte = ConstU64<1>;
250+
type ApprovalDeposit = ConstU64<1>;
251+
type StringLimit = ConstU32<50>;
252+
type Extra = ();
253+
type CallbackHandle = ();
254+
type WeightInfo = ();
255+
#[cfg(feature = "runtime-benchmarks")]
256+
type BenchmarkHelper = ();
257+
}
258+
}
259+
260+
#[pallet::config(with_default)]
230261
/// The module configuration trait.
231262
pub trait Config<I: 'static = ()>: frame_system::Config {
232263
/// The overarching event type.
264+
#[pallet::no_default_bounds]
233265
type RuntimeEvent: From<Event<Self, I>>
234266
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
235267

@@ -262,10 +294,12 @@ pub mod pallet {
262294
type AssetIdParameter: Parameter + From<Self::AssetId> + Into<Self::AssetId> + MaxEncodedLen;
263295

264296
/// The currency mechanism.
297+
#[pallet::no_default]
265298
type Currency: ReservableCurrency<Self::AccountId>;
266299

267300
/// Standard asset class creation is only allowed if the origin attempting it and the
268301
/// asset class are in this set.
302+
#[pallet::no_default]
269303
type CreateOrigin: EnsureOriginWithArg<
270304
Self::RuntimeOrigin,
271305
Self::AssetId,
@@ -274,28 +308,34 @@ pub mod pallet {
274308

275309
/// The origin which may forcibly create or destroy an asset or otherwise alter privileged
276310
/// attributes.
311+
#[pallet::no_default]
277312
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
278313

279314
/// The basic amount of funds that must be reserved for an asset.
280315
#[pallet::constant]
316+
#[pallet::no_default_bounds]
281317
type AssetDeposit: Get<DepositBalanceOf<Self, I>>;
282318

283319
/// The amount of funds that must be reserved for a non-provider asset account to be
284320
/// maintained.
285321
#[pallet::constant]
322+
#[pallet::no_default_bounds]
286323
type AssetAccountDeposit: Get<DepositBalanceOf<Self, I>>;
287324

288325
/// The basic amount of funds that must be reserved when adding metadata to your asset.
289326
#[pallet::constant]
327+
#[pallet::no_default_bounds]
290328
type MetadataDepositBase: Get<DepositBalanceOf<Self, I>>;
291329

292330
/// The additional funds that must be reserved for the number of bytes you store in your
293331
/// metadata.
294332
#[pallet::constant]
333+
#[pallet::no_default_bounds]
295334
type MetadataDepositPerByte: Get<DepositBalanceOf<Self, I>>;
296335

297336
/// The amount of funds that must be reserved when creating a new approval.
298337
#[pallet::constant]
338+
#[pallet::no_default_bounds]
299339
type ApprovalDeposit: Get<DepositBalanceOf<Self, I>>;
300340

301341
/// The maximum length of a name or symbol stored on-chain.
@@ -304,6 +344,7 @@ pub mod pallet {
304344

305345
/// A hook to allow a per-asset, per-account minimum balance to be enforced. This must be
306346
/// respected in all permissionless operations.
347+
#[pallet::no_default]
307348
type Freezer: FrozenBalance<Self::AssetId, Self::AccountId, Self::Balance>;
308349

309350
/// Additional data to be stored with an account's asset balance.

substrate/frame/assets/src/mock.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,13 @@ impl AssetsCallbackHandle {
108108
}
109109
}
110110

111+
#[derive_impl(crate::config_preludes::TestDefaultConfig)]
111112
impl Config for Test {
112-
type RuntimeEvent = RuntimeEvent;
113-
type Balance = u64;
114-
type AssetId = u32;
115-
type AssetIdParameter = u32;
116113
type Currency = Balances;
117114
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
118115
type ForceOrigin = frame_system::EnsureRoot<u64>;
119-
type AssetDeposit = ConstU64<1>;
120-
type AssetAccountDeposit = ConstU64<10>;
121-
type MetadataDepositBase = ConstU64<1>;
122-
type MetadataDepositPerByte = ConstU64<1>;
123-
type ApprovalDeposit = ConstU64<1>;
124-
type StringLimit = ConstU32<50>;
125116
type Freezer = TestFreezer;
126-
type WeightInfo = ();
127117
type CallbackHandle = AssetsCallbackHandle;
128-
type Extra = ();
129-
type RemoveItemsLimit = ConstU32<5>;
130-
#[cfg(feature = "runtime-benchmarks")]
131-
type BenchmarkHelper = ();
132118
}
133119

134120
use std::collections::HashMap;

0 commit comments

Comments
 (0)