Skip to content

Commit

Permalink
Adds default config for assets pallet (#3637)
Browse files Browse the repository at this point in the history
Step in #171
  • Loading branch information
gupnik committed Mar 12, 2024
1 parent 7a644fa commit 7315a9b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
43 changes: 42 additions & 1 deletion substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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.
Expand Down
16 changes: 1 addition & 15 deletions substrate/frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7315a9b

Please sign in to comment.