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

Adds default config for assets pallet #3637

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading