difftreelog
Merge branch 'feature/switch-from-currecy-trait-to-fungible-v2' into feature/update-polkadot-v0.9.42
in: master
7 files changed
pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233//! Benchmarking setup for pallet-collator-selection3435use super::*;3637#[allow(unused)]38use crate::Pallet as CollatorSelection;39use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};40use frame_support::{41 assert_ok,42 codec::Decode,43 traits::{Currency, EnsureOrigin, Get},44};45use frame_system::{EventRecord, RawOrigin};46use pallet_authorship::EventHandler;47use pallet_session::{self as session, SessionManager};48use pallet_configuration::{49 self as configuration, BalanceOf,50 CollatorSelectionDesiredCollatorsOverride as DesiredCollators,51 CollatorSelectionLicenseBondOverride as LicenseBond,52};53use sp_std::prelude::*;5455const SEED: u32 = 0;5657// TODO: remove if this is given in substrate commit.58macro_rules! whitelist {59 ($acc:ident) => {60 frame_benchmarking::benchmarking::add_to_whitelist(61 frame_system::Account::<T>::hashed_key_for(&$acc).into(),62 );63 };64}6566fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {67 let events = frame_system::Pallet::<T>::events();68 let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();69 // compare to the last event record70 let EventRecord { event, .. } = &events[events.len() - 1];71 assert_eq!(event, &system_event);72}7374fn create_funded_user<T: Config>(75 string: &'static str,76 n: u32,77 balance_factor: u32,78) -> T::AccountId {79 let user = account(string, n, SEED);80 let balance = balance_unit::<T>() * balance_factor.into();81 let _ = T::Currency::make_free_balance_be(&user, balance);82 user83}8485fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {86 use rand::{RngCore, SeedableRng};8788 let keys = {89 let mut keys = [0u8; 128];9091 if c > 0 {92 let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);93 rng.fill_bytes(&mut keys);94 }9596 keys97 };9899 Decode::decode(&mut &keys[..]).unwrap()100}101102fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {103 (create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))104}105106fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {107 let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();108109 for (who, keys) in validators.clone() {110 <session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();111 }112113 validators.into_iter().map(|(who, _)| who).collect()114}115116fn register_invulnerables<T: Config + configuration::Config>(count: u32) {117 let candidates = (0..count)118 .map(|c| account("candidate", c, SEED))119 .collect::<Vec<_>>();120121 for who in candidates {122 <CollatorSelection<T>>::add_invulnerable(123 T::UpdateOrigin::try_successful_origin().unwrap(),124 who,125 )126 .unwrap();127 }128}129130fn register_candidates<T: Config + configuration::Config>(count: u32) {131 let candidates = (0..count)132 .map(|c| account("candidate", c, SEED))133 .collect::<Vec<_>>();134 assert!(135 <LicenseBond<T>>::get() > 0u32.into(),136 "Bond cannot be zero!"137 );138139 for who in candidates {140 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());141 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();142 <CollatorSelection<T>>::onboard(RawOrigin::Signed(who).into()).unwrap();143 }144}145146fn get_licenses<T: Config + configuration::Config>(count: u32) {147 let candidates = (0..count)148 .map(|c| account("candidate", c, SEED))149 .collect::<Vec<_>>();150 assert!(151 <LicenseBond<T>>::get() > 0u32.into(),152 "Bond cannot be zero!"153 );154155 for who in candidates {156 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());157 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();158 }159}160161/// `Currency::minimum_balance` was used originally, but in unique-chain, we have162/// zero existential deposit, thus triggering zero bond assertion.163fn balance_unit<T: Config>() -> <T::Currency as Currency<T::AccountId>>::Balance {164 200u32.into()165}166167/// Our benchmarking environment already has invulnerables registered.168const INITIAL_INVULNERABLES: u32 = 2;169170benchmarks! {171 where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }172173 // todo:collator this and all the following do not work for some reason, going all the way up to 10 in length174 // Both invulnerables and candidates count together against MaxCollators.175 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)176 add_invulnerable {177 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;178 register_validators::<T>(b);179 register_invulnerables::<T>(b);180181 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);182183 let new_invulnerable: T::AccountId = whitelisted_caller();184 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();185 T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());186187 <session::Pallet<T>>::set_keys(188 RawOrigin::Signed(new_invulnerable.clone()).into(),189 keys::<T>(b + 1),190 Vec::new()191 ).unwrap();192193 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();194 }: {195 assert_ok!(196 <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())197 );198 }199 verify {200 assert_last_event::<T>(Event::InvulnerableAdded{invulnerable: new_invulnerable}.into());201 }202203 remove_invulnerable {204 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;205 register_validators::<T>(b);206 register_invulnerables::<T>(b);207208 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();209 let leaving = <Invulnerables<T>>::get().last().unwrap().clone();210 whitelist!(leaving);211 }: {212 assert_ok!(213 <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())214 );215 }216 verify {217 assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: leaving}.into());218 }219220 get_license {221 let c in 1 .. T::MaxCollators::get() - 1;222223 <LicenseBond<T>>::put(balance_unit::<T>());224225 register_validators::<T>(c);226 get_licenses::<T>(c);227228 let caller: T::AccountId = whitelisted_caller();229 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();230 T::Currency::make_free_balance_be(&caller, bond.clone());231232 <session::Pallet<T>>::set_keys(233 RawOrigin::Signed(caller.clone()).into(),234 keys::<T>(c + 1),235 Vec::new()236 ).unwrap();237238 }: _(RawOrigin::Signed(caller.clone()))239 verify {240 assert_last_event::<T>(Event::LicenseObtained{account_id: caller, deposit: bond / 2u32.into()}.into());241 }242243 // worst case is when we have all the max-candidate slots filled except one, and we fill that244 // one.245 onboard {246 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;247248 <LicenseBond<T>>::put(balance_unit::<T>());249 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES + 1);250251 register_validators::<T>(c);252 register_candidates::<T>(c);253254 let caller: T::AccountId = whitelisted_caller();255 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();256 T::Currency::make_free_balance_be(&caller, bond.clone());257258 let origin = RawOrigin::Signed(caller.clone());259260 <session::Pallet<T>>::set_keys(261 origin.clone().into(),262 keys::<T>(c + 1),263 Vec::new()264 ).unwrap();265266 assert_ok!(267 <CollatorSelection<T>>::get_license(origin.clone().into())268 );269 }: _(origin)270 verify {271 assert_last_event::<T>(Event::CandidateAdded{account_id: caller}.into());272 }273274 // worst case is the last candidate leaving.275 offboard {276 let c in 1 .. T::MaxCollators::get();277 <LicenseBond<T>>::put(balance_unit::<T>());278 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);279280 register_validators::<T>(c);281 register_candidates::<T>(c);282283 let leaving = <Candidates<T>>::get().last().unwrap().clone();284 whitelist!(leaving);285 }: _(RawOrigin::Signed(leaving.clone()))286 verify {287 assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());288 }289290 // worst case is the last candidate leaving.291 release_license {292 let c in 1 .. T::MaxCollators::get();293 let bond = balance_unit::<T>();294 <LicenseBond<T>>::put(bond);295 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);296297 register_validators::<T>(c);298 register_candidates::<T>(c);299300 let leaving = <Candidates<T>>::get().last().unwrap().clone();301 whitelist!(leaving);302 }: _(RawOrigin::Signed(leaving.clone()))303 verify {304 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());305 }306307 // worst case is the last candidate leaving.308 force_release_license {309 let c in 1 .. T::MaxCollators::get();310 let bond = balance_unit::<T>();311 <LicenseBond<T>>::put(bond);312 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);313314 register_validators::<T>(c);315 register_candidates::<T>(c);316317 let leaving = <Candidates<T>>::get().last().unwrap().clone();318 whitelist!(leaving);319 let origin = T::UpdateOrigin::try_successful_origin().unwrap();320 }: {321 assert_ok!(322 <CollatorSelection<T>>::force_release_license(origin, leaving.clone())323 );324 }325 verify {326 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());327 }328329 // worst case is paying a non-existing candidate account.330 note_author {331 <LicenseBond<T>>::put(balance_unit::<T>());332 T::Currency::make_free_balance_be(333 &<CollatorSelection<T>>::account_id(),334 balance_unit::<T>() * 4u32.into(),335 );336 let author = account("author", 0, SEED);337 let new_block: T::BlockNumber = 10u32.into();338339 frame_system::Pallet::<T>::set_block_number(new_block);340 assert!(T::Currency::free_balance(&author) == 0u32.into());341 }: {342 <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone())343 } verify {344 assert!(T::Currency::free_balance(&author) > 0u32.into());345 assert_eq!(frame_system::Pallet::<T>::block_number(), new_block);346 }347348 // worst case for new session.349 new_session {350 let r in 1 .. T::MaxCollators::get();351 let c in 1 .. T::MaxCollators::get();352353 <LicenseBond<T>>::put(balance_unit::<T>());354 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);355 frame_system::Pallet::<T>::set_block_number(0u32.into());356357 register_validators::<T>(c);358 register_candidates::<T>(c);359360 let new_block: T::BlockNumber = 1800u32.into();361 let zero_block: T::BlockNumber = 0u32.into();362 let candidates = <Candidates<T>>::get();363364 let non_removals = c.saturating_sub(r);365366 for i in 0..c {367 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), zero_block);368 }369370 if non_removals > 0 {371 for i in 0..non_removals {372 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);373 }374 } else {375 for i in 0..c {376 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);377 }378 }379380 let pre_length = <Candidates<T>>::get().len();381382 frame_system::Pallet::<T>::set_block_number(new_block);383384 assert!(<Candidates<T>>::get().len() == c as usize);385 }: {386 <CollatorSelection<T> as SessionManager<_>>::new_session(0)387 } verify {388 if c > r {389 assert!(<Candidates<T>>::get().len() < pre_length);390 } else {391 assert!(<Candidates<T>>::get().len() == pre_length);392 }393 }394}395396impl_benchmark_test_suite!(397 CollatorSelection,398 crate::mock::new_test_ext(),399 crate::mock::Test,400);pallets/collator-selection/src/lib.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/lib.rs
+++ b/pallets/collator-selection/src/lib.rs
@@ -92,6 +92,7 @@
#[frame_support::pallet]
pub mod pallet {
+ use super::*;
pub use crate::weights::WeightInfo;
use core::ops::Div;
use frame_support::{
@@ -100,8 +101,10 @@
pallet_prelude::*,
sp_runtime::traits::{AccountIdConversion, CheckedSub, Saturating, Zero},
traits::{
- Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, ReservableCurrency,
+ EnsureOrigin,
+ fungible::{Balanced, BalancedHold, Inspect, InspectHold, Mutate, MutateHold},
ValidatorRegistration,
+ tokens::{Precision, Preservation},
},
BoundedVec, PalletId,
};
@@ -158,6 +161,9 @@
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
+
+ #[pallet::constant]
+ type LicenceBondIdentifier: Get<<<Self as pallet_configuration::Config>::Currency as InspectHold<Self::AccountId>>::Reason>;
}
#[pallet::pallet]
@@ -361,7 +367,7 @@
let deposit = <LicenseBond<T>>::get();
- T::Currency::reserve(&who, deposit)?;
+ T::Currency::hold(&T::LicenceBondIdentifier::get(), &who, deposit)?;
LicenseDepositOf::<T>::insert(who.clone(), deposit);
Self::deposit_event(Event::LicenseObtained {
@@ -523,17 +529,24 @@
let slashed = T::SlashRatio::get() * deposit;
let remaining = deposit - slashed;
- let (imbalance, _) = T::Currency::slash_reserved(who, slashed);
+ let (imbalance, _) =
+ T::Currency::slash(&T::LicenceBondIdentifier::get(), who, slashed);
//T::Currency::unreserve(who, remaining);
deposit_returned = remaining;
- T::Currency::resolve_creating(&T::TreasuryAccountId::get(), imbalance);
+ T::Currency::resolve(&T::TreasuryAccountId::get(), imbalance)
+ .map_err(|_| DispatchError::Other("Failed to deposit imbalance"))?;
} else {
//T::Currency::unreserve(who, deposit);
deposit_returned = deposit;
}
- T::Currency::unreserve(who, deposit_returned);
+ T::Currency::release(
+ &T::LicenceBondIdentifier::get(),
+ who,
+ deposit_returned,
+ Precision::Exact,
+ )?;
Ok(())
} else {
Err(Error::<T>::NoLicense.into())
@@ -594,12 +607,12 @@
fn note_author(author: T::AccountId) {
let pot = Self::account_id();
// assumes an ED will be sent to pot.
- let reward = T::Currency::free_balance(&pot)
+ let reward = T::Currency::balance(&pot)
.checked_sub(&T::Currency::minimum_balance())
.unwrap_or_else(Zero::zero)
.div(2u32.into());
// `reward` is half of pot account minus ED, this should never fail.
- let _success = T::Currency::transfer(&pot, &author, reward, KeepAlive);
+ let _success = T::Currency::transfer(&pot, &author, reward, Preservation::Preserve);
debug_assert!(_success.is_ok());
<LastAuthoredBlock<T>>::insert(author, frame_system::Pallet::<T>::block_number());
pallets/collator-selection/src/tests.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -417,7 +417,10 @@
fn authorship_event_handler() {
new_test_ext().execute_with(|| {
// put 100 in the pot + 5 for ED
- Balances::make_free_balance_be(&CollatorSelection::account_id(), 105);
+ <pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::set_balance(
+ &CollatorSelection::account_id(),
+ 105,
+ );
// 4 is the default author.
assert_eq!(Balances::free_balance(4), 100);
@@ -441,7 +444,10 @@
// Nothing panics, no reward when no ED in balance
Authorship::on_initialize(1);
// put some money into the pot at ED
- Balances::make_free_balance_be(&CollatorSelection::account_id(), 5);
+ <pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::set_balance(
+ &CollatorSelection::account_id(),
+ 5,
+ );
// 4 is the default author.
assert_eq!(Balances::free_balance(4), 100);
get_license_and_onboard(4);
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -27,12 +27,12 @@
MAX_PROPERTIES_PER_ITEM,
};
use frame_support::{
- traits::{Currency, Get},
+ traits::{Get, fungible::Balanced, Imbalance, tokens::Precision},
pallet_prelude::ConstU32,
BoundedVec,
};
use core::convert::TryInto;
-use sp_runtime::DispatchError;
+use sp_runtime::{DispatchError, traits::Zero};
const SEED: u32 = 1;
@@ -85,7 +85,12 @@
) -> Result<CollectionId, DispatchError>,
cast: impl FnOnce(CollectionHandle<T>) -> R,
) -> Result<R, DispatchError> {
- <T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());
+ let imbalance = <T as Config>::Currency::deposit(
+ &owner.as_sub(),
+ T::CollectionCreationPrice::get(),
+ Precision::Exact,
+ )?;
+ debug_assert!(imbalance.peek().is_zero());
let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -64,7 +64,11 @@
use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
ensure,
- traits::{Imbalance, Get, Currency, WithdrawReasons, ExistenceRequirement},
+ traits::{
+ Get,
+ fungible::{Balanced, Debt, Inspect},
+ tokens::{Imbalance, Precision, Preservation},
+ },
dispatch::Pays,
transactional, fail,
};
@@ -85,7 +89,7 @@
pub use pallet::*;
use sp_core::H160;
-use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
+use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, traits::Zero};
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
@@ -424,7 +428,6 @@
use super::*;
use dispatch::CollectionDispatch;
use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};
- use frame_support::traits::Currency;
use up_data_structs::{TokenId, mapping::TokenAddressMapping};
use scale_info::TypeInfo;
use weights::WeightInfo;
@@ -440,12 +443,12 @@
type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
/// Handler of accounts and payment.
- type Currency: Currency<Self::AccountId>;
+ type Currency: Balanced<Self::AccountId> + Inspect<Self::AccountId>;
/// Set price to create a collection.
#[pallet::constant]
type CollectionCreationPrice: Get<
- <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
+ <<Self as Config>::Currency as Inspect<Self::AccountId>>::Balance,
>;
/// Dispatcher of operations on collections.
@@ -1112,21 +1115,17 @@
// Take a (non-refundable) deposit of collection creation
{
- let mut imbalance =
- <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();
- imbalance.subsume(
- <<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(
- &T::TreasuryAccountId::get(),
- T::CollectionCreationPrice::get(),
- ),
- );
- <T as Config>::Currency::settle(
- payer.as_sub(),
- imbalance,
- WithdrawReasons::TRANSFER,
- ExistenceRequirement::KeepAlive,
- )
- .map_err(|_| Error::<T>::NotSufficientFounds)?;
+ let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
+ imbalance.subsume(<T as Config>::Currency::deposit(
+ &T::TreasuryAccountId::get(),
+ T::CollectionCreationPrice::get(),
+ Precision::Exact,
+ )?);
+ let credit =
+ <T as Config>::Currency::settle(payer.as_sub(), imbalance, Preservation::Preserve)
+ .map_err(|_| Error::<T>::NotSufficientFounds)?;
+
+ debug_assert!(credit.peek().is_zero())
}
<CreatedCollectionCount<T>>::put(created_count);
pallets/configuration/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/configuration/src/benchmarking.rs
+++ b/pallets/configuration/src/benchmarking.rs
@@ -19,7 +19,7 @@
use super::*;
use frame_benchmarking::benchmarks;
use frame_system::{EventRecord, RawOrigin};
-use frame_support::{assert_ok, traits::Currency};
+use frame_support::{assert_ok, traits::fungible::Inspect};
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
@@ -68,7 +68,7 @@
}
set_collator_selection_license_bond {
- let bond_cost: Option<BalanceOf<T>> = Some(T::Currency::minimum_balance() * 10u32.into());
+ let bond_cost: Option<BalanceOf<T>> = Some(T::Balances::minimum_balance() * 10u32.into());
}: {
assert_ok!(
<Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost.clone())
pallets/configuration/src/lib.rsdiffbeforeafterboth--- a/pallets/configuration/src/lib.rs
+++ b/pallets/configuration/src/lib.rs
@@ -42,7 +42,7 @@
mod pallet {
use super::*;
use frame_support::{
- traits::{Get, ReservableCurrency, Currency},
+ traits::{fungible, Get, ReservableCurrency, Currency},
pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType},
log,
};
@@ -50,15 +50,19 @@
pub use crate::weights::WeightInfo;
pub type BalanceOf<T> =
- <<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
+ <<T as Config>::Currency as fungible::Inspect<<T as SystemConfig>::AccountId>>::Balance;
#[pallet::config]
pub trait Config: frame_system::Config {
/// Overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
- /// The currency mechanism.
- type Currency: ReservableCurrency<Self::AccountId>;
+ type Currency: fungible::Inspect<Self::AccountId>
+ + fungible::Mutate<Self::AccountId>
+ + fungible::MutateFreeze<Self::AccountId>
+ + fungible::InspectHold<Self::AccountId>
+ + fungible::MutateHold<Self::AccountId>
+ + fungible::BalancedHold<Self::AccountId>;
#[pallet::constant]
type DefaultWeightToFeeCoefficient: Get<u64>;