From 9a537f92c584f645e0bd12ebc8a6969474e2f115 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Mon, 28 Nov 2022 19:54:27 +0200 Subject: [PATCH 01/20] WIP move LockableCurrency to fungibles --- frame/balances/src/lib.rs | 4 +- frame/balances/src/tests.rs | 2 +- frame/contracts/src/tests.rs | 4 +- frame/conviction-voting/src/lib.rs | 4 +- frame/democracy/src/lib.rs | 4 +- frame/elections-phragmen/src/lib.rs | 4 +- frame/executive/src/lib.rs | 4 +- frame/staking/src/pallet/impls.rs | 2 +- frame/staking/src/pallet/mod.rs | 4 +- frame/support/src/traits.rs | 12 ++- frame/support/src/traits/tokens/currency.rs | 7 +- .../src/traits/tokens/currency/lockable.rs | 86 +++++++++---------- frame/support/src/traits/tokens/fungible.rs | 3 + .../src/traits/tokens/fungible/lockable.rs | 65 ++++++++++++++ frame/vesting/src/lib.rs | 6 +- 15 files changed, 145 insertions(+), 66 deletions(-) create mode 100644 frame/support/src/traits/tokens/fungible/lockable.rs diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index d3085152eba6c..bfe892dc1b915 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -173,7 +173,7 @@ use frame_support::{ tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence}, Currency, DefensiveSaturating, ExistenceRequirement, ExistenceRequirement::{AllowDeath, KeepAlive}, - Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency, OnUnbalanced, + Get, Imbalance, LockIdentifier, Lockable, NamedReservableCurrency, OnUnbalanced, ReservableCurrency, SignedImbalance, StoredMap, TryDrop, WithdrawReasons, }, WeakBoundedVec, @@ -2119,7 +2119,7 @@ where } } -impl, I: 'static> LockableCurrency for Pallet +impl, I: 'static> Lockable for Pallet where T::Balance: MaybeSerializeDeserialize + Debug, { diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 83944caf9f7ff..10b71d3b03695 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -28,7 +28,7 @@ macro_rules! decl_tests { use frame_support::{ assert_noop, assert_storage_noop, assert_ok, assert_err, traits::{ - LockableCurrency, LockIdentifier, WithdrawReasons, + Lockable, LockIdentifier, WithdrawReasons, Currency, ReservableCurrency, ExistenceRequirement::AllowDeath } }; diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 7054ceb07a6fc..61dd432c6ec06 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -37,8 +37,8 @@ use frame_support::{ parameter_types, storage::child, traits::{ - BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, LockableCurrency, OnIdle, - OnInitialize, ReservableCurrency, WithdrawReasons, + BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, Lockable, OnIdle, OnInitialize, + ReservableCurrency, WithdrawReasons, }, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index 3ecc6e56be94e..d4be039fcefff 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -31,7 +31,7 @@ use frame_support::{ dispatch::{DispatchError, DispatchResult}, ensure, traits::{ - fungible, Currency, Get, LockIdentifier, LockableCurrency, PollStatus, Polling, + fungible, Currency, Get, LockIdentifier, Lockable, PollStatus, Polling, ReservableCurrency, WithdrawReasons, }, }; @@ -104,7 +104,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// Currency type with which voting happens. type Currency: ReservableCurrency - + LockableCurrency + + Lockable + fungible::Inspect; /// The implementation of the logic which conducts polls. diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index cf954d4800eee..cec36cb262580 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -158,7 +158,7 @@ use frame_support::{ traits::{ defensive_prelude::*, schedule::{v3::Named as ScheduleNamed, DispatchTime}, - Bounded, Currency, Get, LockIdentifier, LockableCurrency, OnUnbalanced, QueryPreimage, + Bounded, Currency, Get, LockIdentifier, Lockable, OnUnbalanced, QueryPreimage, ReservableCurrency, StorePreimage, WithdrawReasons, }, weights::Weight, @@ -234,7 +234,7 @@ pub mod pallet { /// Currency type for this pallet. type Currency: ReservableCurrency - + LockableCurrency; + + Lockable; /// The period between a proposal being approved and enacted. /// diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 165a8fcab429b..1034ff7b678fa 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -102,7 +102,7 @@ use codec::{Decode, Encode}; use frame_support::{ traits::{ defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency, - CurrencyToVote, Get, InitializeMembers, LockIdentifier, LockableCurrency, OnUnbalanced, + CurrencyToVote, Get, InitializeMembers, LockIdentifier, Lockable, OnUnbalanced, ReservableCurrency, SortedMembers, WithdrawReasons, }, weights::Weight, @@ -202,7 +202,7 @@ pub mod pallet { type PalletId: Get; /// The currency that people are electing with. - type Currency: LockableCurrency + type Currency: Lockable + ReservableCurrency; /// What to do when the members change. diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index b7884efccf685..dea2fc492cca7 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -608,7 +608,7 @@ mod tests { use frame_support::{ assert_err, parameter_types, traits::{ - ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, LockableCurrency, + ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, Lockable, WithdrawReasons, }, weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee}, @@ -1176,7 +1176,7 @@ mod tests { let execute_with_lock = |lock: WithdrawReasons| { let mut t = new_test_ext(1); t.execute_with(|| { - as LockableCurrency>::set_lock( + as Lockable>::set_lock( id, &1, 110, lock, ); let xt = TestXt::new( diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index c22a2bd2d1f77..a12ca7b6b3e52 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -26,7 +26,7 @@ use frame_support::{ pallet_prelude::*, traits::{ Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get, - Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, + Imbalance, Lockable, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, }, weights::Weight, }; diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 8fddba2150370..4bb0888453054 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -25,7 +25,7 @@ use frame_support::{ pallet_prelude::*, traits::{ Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, - EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, TryCollect, + EstimateNextNewSession, Get, LockIdentifier, Lockable, OnUnbalanced, TryCollect, UnixTime, }, weights::Weight, @@ -78,7 +78,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { /// The staking balance. - type Currency: LockableCurrency< + type Currency: Lockable< Self::AccountId, Moment = Self::BlockNumber, Balance = Self::CurrencyBalance, diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index f09b715a970ad..fade24b77ef85 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -22,10 +22,16 @@ pub mod tokens; pub use tokens::{ currency::{ - Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency, - TotalIssuanceOf, VestingSchedule, + // , LockIdentifier, LockableCurrency + Currency, + NamedReservableCurrency, + ReservableCurrency, + TotalIssuanceOf, + VestingSchedule, }, - fungible, fungibles, + fungible, + fungible::lockable::{LockIdentifier, Lockable}, + fungibles, imbalance::{Imbalance, OnUnbalanced, SignedImbalance}, BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons, }; diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index d0beb66d34923..f538d76546635 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -32,7 +32,12 @@ use sp_std::fmt::Debug; mod reservable; pub use reservable::{NamedReservableCurrency, ReservableCurrency}; mod lockable; -pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; +use super::fungible; + +// pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; +// pub use fungible::lockable::Lockable; +pub use fungible::lockable::{LockIdentifier, Lockable}; +pub use lockable::VestingSchedule; /// Abstraction over a fungible assets system. pub trait Currency { diff --git a/frame/support/src/traits/tokens/currency/lockable.rs b/frame/support/src/traits/tokens/currency/lockable.rs index a10edd6e3e874..5c8f9eb710ec2 100644 --- a/frame/support/src/traits/tokens/currency/lockable.rs +++ b/frame/support/src/traits/tokens/currency/lockable.rs @@ -20,49 +20,49 @@ use super::{super::misc::WithdrawReasons, Currency}; use crate::{dispatch::DispatchResult, traits::misc::Get}; -/// An identifier for a lock. Used for disambiguating different locks so that -/// they can be individually replaced or removed. -pub type LockIdentifier = [u8; 8]; - -/// A currency whose accounts can have liquidity restrictions. -pub trait LockableCurrency: Currency { - /// The quantity used to denote time; usually just a `BlockNumber`. - type Moment; - - /// The maximum number of locks a user should have on their account. - type MaxLocks: Get; - - /// Create a new balance lock on account `who`. - /// - /// If the new lock is valid (i.e. not already expired), it will push the struct to - /// the `Locks` vec in storage. Note that you can lock more funds than a user has. - /// - /// If the lock `id` already exists, this will update it. - fn set_lock( - id: LockIdentifier, - who: &AccountId, - amount: Self::Balance, - reasons: WithdrawReasons, - ); - - /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all - /// parameters or creates a new one if it does not exist. - /// - /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it - /// applies the most severe constraints of the two, while `set_lock` replaces the lock - /// with the new parameters. As in, `extend_lock` will set: - /// - maximum `amount` - /// - bitwise mask of all `reasons` - fn extend_lock( - id: LockIdentifier, - who: &AccountId, - amount: Self::Balance, - reasons: WithdrawReasons, - ); - - /// Remove an existing lock. - fn remove_lock(id: LockIdentifier, who: &AccountId); -} +// /// An identifier for a lock. Used for disambiguating different locks so that +// /// they can be individually replaced or removed. +// pub type LockIdentifier = [u8; 8]; + +// /// A currency whose accounts can have liquidity restrictions. +// pub trait LockableCurrency: Currency { +// /// The quantity used to denote time; usually just a `BlockNumber`. +// type Moment; + +// /// The maximum number of locks a user should have on their account. +// type MaxLocks: Get; + +// /// Create a new balance lock on account `who`. +// /// +// /// If the new lock is valid (i.e. not already expired), it will push the struct to +// /// the `Locks` vec in storage. Note that you can lock more funds than a user has. +// /// +// /// If the lock `id` already exists, this will update it. +// fn set_lock( +// id: LockIdentifier, +// who: &AccountId, +// amount: Self::Balance, +// reasons: WithdrawReasons, +// ); + +// /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all +// /// parameters or creates a new one if it does not exist. +// /// +// /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it +// /// applies the most severe constraints of the two, while `set_lock` replaces the lock +// /// with the new parameters. As in, `extend_lock` will set: +// /// - maximum `amount` +// /// - bitwise mask of all `reasons` +// fn extend_lock( +// id: LockIdentifier, +// who: &AccountId, +// amount: Self::Balance, +// reasons: WithdrawReasons, +// ); + +// /// Remove an existing lock. +// fn remove_lock(id: LockIdentifier, who: &AccountId); +// } /// A vesting schedule over a currency. This allows a particular currency to have vesting limits /// applied to it. diff --git a/frame/support/src/traits/tokens/fungible.rs b/frame/support/src/traits/tokens/fungible.rs index 90aadb6d8daa6..561e1712c9752 100644 --- a/frame/support/src/traits/tokens/fungible.rs +++ b/frame/support/src/traits/tokens/fungible.rs @@ -29,8 +29,11 @@ use sp_runtime::traits::Saturating; mod balanced; mod imbalance; +pub mod lockable; + pub use balanced::{Balanced, Unbalanced}; pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance}; +pub use lockable::Lockable; /// Trait for providing balance-inspection access to a fungible asset. pub trait Inspect { diff --git a/frame/support/src/traits/tokens/fungible/lockable.rs b/frame/support/src/traits/tokens/fungible/lockable.rs new file mode 100644 index 0000000000000..a0b6310497e7b --- /dev/null +++ b/frame/support/src/traits/tokens/fungible/lockable.rs @@ -0,0 +1,65 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! The lockable currency trait and some associated types. + +use super::{super::misc::WithdrawReasons, currency::Currency}; +use crate::{dispatch::DispatchResult, traits::misc::Get}; + +/// An identifier for a lock. Used for disambiguating different locks so that +/// they can be individually replaced or removed. +pub type LockIdentifier = [u8; 8]; + +/// A currency whose accounts can have liquidity restrictions. +pub trait Lockable: Currency { + /// The quantity used to denote time; usually just a `BlockNumber`. + type Moment; + + /// The maximum number of locks a user should have on their account. + type MaxLocks: Get; + + /// Create a new balance lock on account `who`. + /// + /// If the new lock is valid (i.e. not already expired), it will push the struct to + /// the `Locks` vec in storage. Note that you can lock more funds than a user has. + /// + /// If the lock `id` already exists, this will update it. + fn set_lock( + id: LockIdentifier, + who: &AccountId, + amount: Self::Balance, + reasons: WithdrawReasons, + ); + + /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all + /// parameters or creates a new one if it does not exist. + /// + /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it + /// applies the most severe constraints of the two, while `set_lock` replaces the lock + /// with the new parameters. As in, `extend_lock` will set: + /// - maximum `amount` + /// - bitwise mask of all `reasons` + fn extend_lock( + id: LockIdentifier, + who: &AccountId, + amount: Self::Balance, + reasons: WithdrawReasons, + ); + + /// Remove an existing lock. + fn remove_lock(id: LockIdentifier, who: &AccountId); +} diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index a92f94baf6cf9..bde1082c36367 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -62,7 +62,7 @@ use frame_support::{ ensure, storage::bounded_vec::BoundedVec, traits::{ - Currency, ExistenceRequirement, Get, LockIdentifier, LockableCurrency, VestingSchedule, + Currency, ExistenceRequirement, Get, LockIdentifier, Lockable, VestingSchedule, WithdrawReasons, }, weights::Weight, @@ -84,7 +84,7 @@ pub use weights::WeightInfo; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; type MaxLocksOf = - <::Currency as LockableCurrency<::AccountId>>::MaxLocks; + <::Currency as Lockable<::AccountId>>::MaxLocks; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; const VESTING_ID: LockIdentifier = *b"vesting "; @@ -159,7 +159,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency trait. - type Currency: LockableCurrency; + type Currency: Lockable; /// Convert the block number into a balance. type BlockNumberToBalance: Convert>; From c1a58245abce91f0e6f08eb695c18e79fd6869a6 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Wed, 30 Nov 2022 11:35:42 +0200 Subject: [PATCH 02/20] rename Lockable and LockIdentifier to funginbles::* --- bin/node/runtime/src/lib.rs | 8 ++-- frame/balances/src/lib.rs | 14 +++--- frame/conviction-voting/src/lib.rs | 8 ++-- frame/democracy/src/lib.rs | 10 ++-- frame/elections-phragmen/src/lib.rs | 8 ++-- frame/executive/src/lib.rs | 3 +- frame/referenda/src/lib.rs | 5 +- frame/staking/src/pallet/impls.rs | 5 +- frame/staking/src/pallet/mod.rs | 8 ++-- frame/support/src/traits.rs | 11 +---- frame/support/src/traits/tokens/currency.rs | 4 -- .../src/traits/tokens/currency/lockable.rs | 48 +------------------ frame/support/src/traits/tokens/fungible.rs | 4 +- .../src/traits/tokens/fungible/lockable.rs | 2 +- frame/vesting/src/lib.rs | 11 +++-- 15 files changed, 49 insertions(+), 100 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index cff33e0918981..15379b8041fb9 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -32,9 +32,9 @@ use frame_support::{ pallet_prelude::Get, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, - EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, - LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons, + fungible, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, + EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, Nothing, + OnUnbalanced, U128CurrencyToVote, WithdrawReasons, }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, @@ -1001,7 +1001,7 @@ parameter_types! { pub const DesiredRunnersUp: u32 = 7; pub const MaxVoters: u32 = 10 * 1000; pub const MaxCandidates: u32 = 1000; - pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; + pub const ElectionsPhragmenPalletId: fungible::LockIdentifier = *b"phrelect"; } // Make sure that there are no more than `MaxMembers` members elected via elections-phragmen. diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index bfe892dc1b915..0a8ad7c444f85 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -173,8 +173,8 @@ use frame_support::{ tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence}, Currency, DefensiveSaturating, ExistenceRequirement, ExistenceRequirement::{AllowDeath, KeepAlive}, - Get, Imbalance, LockIdentifier, Lockable, NamedReservableCurrency, OnUnbalanced, - ReservableCurrency, SignedImbalance, StoredMap, TryDrop, WithdrawReasons, + Get, Imbalance, NamedReservableCurrency, OnUnbalanced, ReservableCurrency, SignedImbalance, + StoredMap, TryDrop, WithdrawReasons, }, WeakBoundedVec, }; @@ -658,7 +658,7 @@ impl BitOr for Reasons { #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct BalanceLock { /// An identifier for this lock. Only one lock may be in existence for each identifier. - pub id: LockIdentifier, + pub id: fungible::LockIdentifier, /// The amount which the free balance may not drop below when this lock is in effect. pub amount: Balance, /// If true, then the lock remains in effect even for payment of transaction fees. @@ -2119,7 +2119,7 @@ where } } -impl, I: 'static> Lockable for Pallet +impl, I: 'static> fungible::Lockable for Pallet where T::Balance: MaybeSerializeDeserialize + Debug, { @@ -2130,7 +2130,7 @@ where // Set a lock on the balance of `who`. // Is a no-op if lock amount is zero or `reasons` `is_none()`. fn set_lock( - id: LockIdentifier, + id: fungible::LockIdentifier, who: &T::AccountId, amount: T::Balance, reasons: WithdrawReasons, @@ -2152,7 +2152,7 @@ where // Extend a lock on the balance of `who`. // Is a no-op if lock amount is zero or `reasons` `is_none()`. fn extend_lock( - id: LockIdentifier, + id: fungible::LockIdentifier, who: &T::AccountId, amount: T::Balance, reasons: WithdrawReasons, @@ -2181,7 +2181,7 @@ where Self::update_locks(who, &locks[..]); } - fn remove_lock(id: LockIdentifier, who: &T::AccountId) { + fn remove_lock(id: fungible::LockIdentifier, who: &T::AccountId) { let mut locks = Self::locks(who); locks.retain(|l| l.id != id); Self::update_locks(who, &locks[..]); diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index d4be039fcefff..2dec1ce9a8507 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -31,8 +31,8 @@ use frame_support::{ dispatch::{DispatchError, DispatchResult}, ensure, traits::{ - fungible, Currency, Get, LockIdentifier, Lockable, PollStatus, Polling, - ReservableCurrency, WithdrawReasons, + fungible, fungible::Lockable, Currency, Get, PollStatus, Polling, ReservableCurrency, + WithdrawReasons, }, }; use sp_runtime::{ @@ -60,7 +60,7 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -const CONVICTION_VOTING_ID: LockIdentifier = *b"pyconvot"; +const CONVICTION_VOTING_ID: fungible::LockIdentifier = *b"pyconvot"; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; type BalanceOf = @@ -104,7 +104,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// Currency type with which voting happens. type Currency: ReservableCurrency - + Lockable + + fungible::Lockable + fungible::Inspect; /// The implementation of the logic which conducts polls. diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index cec36cb262580..ddba3fcd1fbd8 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -157,9 +157,11 @@ use frame_support::{ ensure, traits::{ defensive_prelude::*, + fungible, + fungible::Lockable, schedule::{v3::Named as ScheduleNamed, DispatchTime}, - Bounded, Currency, Get, LockIdentifier, Lockable, OnUnbalanced, QueryPreimage, - ReservableCurrency, StorePreimage, WithdrawReasons, + Bounded, Currency, Get, OnUnbalanced, QueryPreimage, ReservableCurrency, StorePreimage, + WithdrawReasons, }, weights::Weight, }; @@ -189,7 +191,7 @@ pub mod benchmarking; pub mod migrations; -const DEMOCRACY_ID: LockIdentifier = *b"democrac"; +const DEMOCRACY_ID: fungible::LockIdentifier = *b"democrac"; /// A proposal index. pub type PropIndex = u32; @@ -234,7 +236,7 @@ pub mod pallet { /// Currency type for this pallet. type Currency: ReservableCurrency - + Lockable; + + fungible::Lockable; /// The period between a proposal being approved and enacted. /// diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 1034ff7b678fa..ef24d02c4528a 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -101,8 +101,8 @@ use codec::{Decode, Encode}; use frame_support::{ traits::{ - defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency, - CurrencyToVote, Get, InitializeMembers, LockIdentifier, Lockable, OnUnbalanced, + defensive_prelude::*, fungible, fungible::Lockable, ChangeMembers, Contains, + ContainsLengthBound, Currency, CurrencyToVote, Get, InitializeMembers, OnUnbalanced, ReservableCurrency, SortedMembers, WithdrawReasons, }, weights::Weight, @@ -199,10 +199,10 @@ pub mod pallet { /// Identifier for the elections-phragmen pallet's lock #[pallet::constant] - type PalletId: Get; + type PalletId: Get; /// The currency that people are electing with. - type Currency: Lockable + type Currency: fungible::Lockable + ReservableCurrency; /// What to do when the members change. diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index dea2fc492cca7..4847eb8a7e716 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -608,8 +608,7 @@ mod tests { use frame_support::{ assert_err, parameter_types, traits::{ - ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, Lockable, - WithdrawReasons, + ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, Lockable, WithdrawReasons, }, weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee}, }; diff --git a/frame/referenda/src/lib.rs b/frame/referenda/src/lib.rs index ba5f4aec956b1..b483eaae3852a 100644 --- a/frame/referenda/src/lib.rs +++ b/frame/referenda/src/lib.rs @@ -68,11 +68,12 @@ use codec::{Codec, Encode}; use frame_support::{ ensure, traits::{ + fungible, schedule::{ v3::{Anon as ScheduleAnon, Named as ScheduleNamed}, DispatchTime, }, - Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage, + Currency, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage, ReservableCurrency, StorePreimage, VoteTally, }, BoundedVec, @@ -132,7 +133,7 @@ macro_rules! impl_tracksinfo_get { }; } -const ASSEMBLY_ID: LockIdentifier = *b"assembly"; +const ASSEMBLY_ID: fungible::LockIdentifier = *b"assembly"; #[frame_support::pallet] pub mod pallet { diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index a12ca7b6b3e52..5f1f488fa304f 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -25,8 +25,9 @@ use frame_support::{ dispatch::WithPostDispatchInfo, pallet_prelude::*, traits::{ - Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get, - Imbalance, Lockable, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, + fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, + EstimateNextNewSession, Get, Imbalance, OnUnbalanced, TryCollect, UnixTime, + WithdrawReasons, }, weights::Weight, }; diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 4bb0888453054..7f918f1af7380 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -24,8 +24,8 @@ use frame_support::{ dispatch::Codec, pallet_prelude::*, traits::{ - Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, - EstimateNextNewSession, Get, LockIdentifier, Lockable, OnUnbalanced, TryCollect, + fungible, fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, + DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect, UnixTime, }, weights::Weight, @@ -50,7 +50,7 @@ use crate::{ ValidatorPrefs, }; -const STAKING_ID: LockIdentifier = *b"staking "; +const STAKING_ID: fungible::LockIdentifier = *b"staking "; #[frame_support::pallet] pub mod pallet { @@ -78,7 +78,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { /// The staking balance. - type Currency: Lockable< + type Currency: fungible::Lockable< Self::AccountId, Moment = Self::BlockNumber, Balance = Self::CurrencyBalance, diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index fade24b77ef85..cb96ba6572b4c 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -22,16 +22,9 @@ pub mod tokens; pub use tokens::{ currency::{ - // , LockIdentifier, LockableCurrency - Currency, - NamedReservableCurrency, - ReservableCurrency, - TotalIssuanceOf, - VestingSchedule, + Currency, NamedReservableCurrency, ReservableCurrency, TotalIssuanceOf, VestingSchedule, }, - fungible, - fungible::lockable::{LockIdentifier, Lockable}, - fungibles, + fungible, fungibles, imbalance::{Imbalance, OnUnbalanced, SignedImbalance}, BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons, }; diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index f538d76546635..da4a2b1c479c9 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -32,11 +32,7 @@ use sp_std::fmt::Debug; mod reservable; pub use reservable::{NamedReservableCurrency, ReservableCurrency}; mod lockable; -use super::fungible; -// pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; -// pub use fungible::lockable::Lockable; -pub use fungible::lockable::{LockIdentifier, Lockable}; pub use lockable::VestingSchedule; /// Abstraction over a fungible assets system. diff --git a/frame/support/src/traits/tokens/currency/lockable.rs b/frame/support/src/traits/tokens/currency/lockable.rs index 5c8f9eb710ec2..5b7cad3b5c1d3 100644 --- a/frame/support/src/traits/tokens/currency/lockable.rs +++ b/frame/support/src/traits/tokens/currency/lockable.rs @@ -17,52 +17,8 @@ //! The lockable currency trait and some associated types. -use super::{super::misc::WithdrawReasons, Currency}; -use crate::{dispatch::DispatchResult, traits::misc::Get}; - -// /// An identifier for a lock. Used for disambiguating different locks so that -// /// they can be individually replaced or removed. -// pub type LockIdentifier = [u8; 8]; - -// /// A currency whose accounts can have liquidity restrictions. -// pub trait LockableCurrency: Currency { -// /// The quantity used to denote time; usually just a `BlockNumber`. -// type Moment; - -// /// The maximum number of locks a user should have on their account. -// type MaxLocks: Get; - -// /// Create a new balance lock on account `who`. -// /// -// /// If the new lock is valid (i.e. not already expired), it will push the struct to -// /// the `Locks` vec in storage. Note that you can lock more funds than a user has. -// /// -// /// If the lock `id` already exists, this will update it. -// fn set_lock( -// id: LockIdentifier, -// who: &AccountId, -// amount: Self::Balance, -// reasons: WithdrawReasons, -// ); - -// /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all -// /// parameters or creates a new one if it does not exist. -// /// -// /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it -// /// applies the most severe constraints of the two, while `set_lock` replaces the lock -// /// with the new parameters. As in, `extend_lock` will set: -// /// - maximum `amount` -// /// - bitwise mask of all `reasons` -// fn extend_lock( -// id: LockIdentifier, -// who: &AccountId, -// amount: Self::Balance, -// reasons: WithdrawReasons, -// ); - -// /// Remove an existing lock. -// fn remove_lock(id: LockIdentifier, who: &AccountId); -// } +use super::Currency; +use crate::dispatch::DispatchResult; /// A vesting schedule over a currency. This allows a particular currency to have vesting limits /// applied to it. diff --git a/frame/support/src/traits/tokens/fungible.rs b/frame/support/src/traits/tokens/fungible.rs index 561e1712c9752..f0db4589a85fd 100644 --- a/frame/support/src/traits/tokens/fungible.rs +++ b/frame/support/src/traits/tokens/fungible.rs @@ -29,11 +29,11 @@ use sp_runtime::traits::Saturating; mod balanced; mod imbalance; -pub mod lockable; +mod lockable; pub use balanced::{Balanced, Unbalanced}; pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance}; -pub use lockable::Lockable; +pub use lockable::{LockIdentifier, Lockable}; /// Trait for providing balance-inspection access to a fungible asset. pub trait Inspect { diff --git a/frame/support/src/traits/tokens/fungible/lockable.rs b/frame/support/src/traits/tokens/fungible/lockable.rs index a0b6310497e7b..bf968d6e4fd39 100644 --- a/frame/support/src/traits/tokens/fungible/lockable.rs +++ b/frame/support/src/traits/tokens/fungible/lockable.rs @@ -18,7 +18,7 @@ //! The lockable currency trait and some associated types. use super::{super::misc::WithdrawReasons, currency::Currency}; -use crate::{dispatch::DispatchResult, traits::misc::Get}; +use crate::traits::misc::Get; /// An identifier for a lock. Used for disambiguating different locks so that /// they can be individually replaced or removed. diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index bde1082c36367..f478271da461a 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -62,7 +62,7 @@ use frame_support::{ ensure, storage::bounded_vec::BoundedVec, traits::{ - Currency, ExistenceRequirement, Get, LockIdentifier, Lockable, VestingSchedule, + fungible, fungible::Lockable, Currency, ExistenceRequirement, Get, VestingSchedule, WithdrawReasons, }, weights::Weight, @@ -83,11 +83,12 @@ pub use weights::WeightInfo; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -type MaxLocksOf = - <::Currency as Lockable<::AccountId>>::MaxLocks; +type MaxLocksOf = <::Currency as fungible::Lockable< + ::AccountId, +>>::MaxLocks; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -const VESTING_ID: LockIdentifier = *b"vesting "; +const VESTING_ID: fungible::LockIdentifier = *b"vesting "; // A value placed in storage that represents the current version of the Vesting storage. // This value is used by `on_runtime_upgrade` to determine whether we run storage migration logic. @@ -159,7 +160,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency trait. - type Currency: Lockable; + type Currency: fungible::Lockable; /// Convert the block number into a balance. type BlockNumberToBalance: Convert>; From cc39dc4ab4f911699853cdec5d30cb9a745baecb Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Wed, 30 Nov 2022 16:25:06 +0200 Subject: [PATCH 03/20] fix imports further --- frame/balances/src/tests.rs | 6 +++--- frame/contracts/src/tests.rs | 2 +- frame/elections-phragmen/src/lib.rs | 2 +- frame/executive/src/lib.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 10b71d3b03695..2ce6ea5f8b7d0 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -28,15 +28,15 @@ macro_rules! decl_tests { use frame_support::{ assert_noop, assert_storage_noop, assert_ok, assert_err, traits::{ - Lockable, LockIdentifier, WithdrawReasons, + fungible, fungible::Lockable, WithdrawReasons, Currency, ReservableCurrency, ExistenceRequirement::AllowDeath } }; use pallet_transaction_payment::{ChargeTransactionPayment, Multiplier}; use frame_system::RawOrigin; - const ID_1: LockIdentifier = *b"1 "; - const ID_2: LockIdentifier = *b"2 "; + const ID_1: fungible::LockIdentifier = *b"1 "; + const ID_2: fungible::LockIdentifier = *b"2 "; pub const CALL: &<$test as frame_system::Config>::RuntimeCall = &RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 0, value: 0 }); diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 61dd432c6ec06..6283a3b07ead0 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -37,7 +37,7 @@ use frame_support::{ parameter_types, storage::child, traits::{ - BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, Lockable, OnIdle, OnInitialize, + fungible::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, OnInitialize, ReservableCurrency, WithdrawReasons, }, weights::{constants::WEIGHT_PER_SECOND, Weight}, diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index ef24d02c4528a..64b8a0c9c3a6a 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1274,7 +1274,7 @@ mod tests { } parameter_types! { - pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; + pub const ElectionsPhragmenPalletId: fungible::LockIdentifier = *b"phrelect"; pub const PhragmenMaxVoters: u32 = 1000; pub const PhragmenMaxCandidates: u32 = 100; } diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 4847eb8a7e716..4bea41103e0b2 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -608,7 +608,7 @@ mod tests { use frame_support::{ assert_err, parameter_types, traits::{ - ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, Lockable, WithdrawReasons, + fungible, ConstU32, ConstU64, ConstU8, Currency, WithdrawReasons, }, weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee}, }; @@ -1171,11 +1171,11 @@ mod tests { #[test] fn can_pay_for_tx_fee_on_full_lock() { - let id: LockIdentifier = *b"0 "; + let id: fungible::LockIdentifier = *b"0 "; let execute_with_lock = |lock: WithdrawReasons| { let mut t = new_test_ext(1); t.execute_with(|| { - as Lockable>::set_lock( + as fungible::Lockable>::set_lock( id, &1, 110, lock, ); let xt = TestXt::new( From 2c34ec4d8d38f8bfb880ebdcdd9888b520581e91 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Fri, 2 Dec 2022 12:36:52 +0200 Subject: [PATCH 04/20] change Lockable from fungible to fungibles --- bin/node/runtime/src/lib.rs | 4 ++-- frame/balances/src/lib.rs | 14 ++++++++------ frame/balances/src/tests.rs | 6 +++--- frame/contracts/src/tests.rs | 2 +- frame/conviction-voting/src/benchmarking.rs | 2 +- frame/conviction-voting/src/lib.rs | 8 ++++---- frame/democracy/src/lib.rs | 8 ++++---- frame/elections-phragmen/src/lib.rs | 8 ++++---- frame/executive/src/lib.rs | 8 +++----- frame/referenda/src/lib.rs | 6 ++---- frame/staking/src/pallet/impls.rs | 2 +- frame/staking/src/pallet/mod.rs | 6 +++--- frame/support/src/traits/tokens/fungible.rs | 2 -- frame/support/src/traits/tokens/fungibles.rs | 2 ++ .../tokens/{fungible => fungibles}/lockable.rs | 0 frame/vesting/src/lib.rs | 8 ++++---- 16 files changed, 42 insertions(+), 44 deletions(-) rename frame/support/src/traits/tokens/{fungible => fungibles}/lockable.rs (100%) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 15379b8041fb9..f344940cf5579 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -32,7 +32,7 @@ use frame_support::{ pallet_prelude::Get, parameter_types, traits::{ - fungible, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, + fungibles, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons, }, @@ -1001,7 +1001,7 @@ parameter_types! { pub const DesiredRunnersUp: u32 = 7; pub const MaxVoters: u32 = 10 * 1000; pub const MaxCandidates: u32 = 1000; - pub const ElectionsPhragmenPalletId: fungible::LockIdentifier = *b"phrelect"; + pub const ElectionsPhragmenPalletId: fungibles::LockIdentifier = *b"phrelect"; } // Make sure that there are no more than `MaxMembers` members elected via elections-phragmen. diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 0a8ad7c444f85..37dea1e973891 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -170,7 +170,9 @@ use frame_support::{ ensure, pallet_prelude::DispatchResult, traits::{ - tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence}, + tokens::{ + fungible, fungibles, BalanceStatus as Status, DepositConsequence, WithdrawConsequence, + }, Currency, DefensiveSaturating, ExistenceRequirement, ExistenceRequirement::{AllowDeath, KeepAlive}, Get, Imbalance, NamedReservableCurrency, OnUnbalanced, ReservableCurrency, SignedImbalance, @@ -658,7 +660,7 @@ impl BitOr for Reasons { #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct BalanceLock { /// An identifier for this lock. Only one lock may be in existence for each identifier. - pub id: fungible::LockIdentifier, + pub id: fungibles::LockIdentifier, /// The amount which the free balance may not drop below when this lock is in effect. pub amount: Balance, /// If true, then the lock remains in effect even for payment of transaction fees. @@ -2119,7 +2121,7 @@ where } } -impl, I: 'static> fungible::Lockable for Pallet +impl, I: 'static> fungibles::Lockable for Pallet where T::Balance: MaybeSerializeDeserialize + Debug, { @@ -2130,7 +2132,7 @@ where // Set a lock on the balance of `who`. // Is a no-op if lock amount is zero or `reasons` `is_none()`. fn set_lock( - id: fungible::LockIdentifier, + id: fungibles::LockIdentifier, who: &T::AccountId, amount: T::Balance, reasons: WithdrawReasons, @@ -2152,7 +2154,7 @@ where // Extend a lock on the balance of `who`. // Is a no-op if lock amount is zero or `reasons` `is_none()`. fn extend_lock( - id: fungible::LockIdentifier, + id: fungibles::LockIdentifier, who: &T::AccountId, amount: T::Balance, reasons: WithdrawReasons, @@ -2181,7 +2183,7 @@ where Self::update_locks(who, &locks[..]); } - fn remove_lock(id: fungible::LockIdentifier, who: &T::AccountId) { + fn remove_lock(id: fungibles::LockIdentifier, who: &T::AccountId) { let mut locks = Self::locks(who); locks.retain(|l| l.id != id); Self::update_locks(who, &locks[..]); diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 2ce6ea5f8b7d0..44a71b93257db 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -28,15 +28,15 @@ macro_rules! decl_tests { use frame_support::{ assert_noop, assert_storage_noop, assert_ok, assert_err, traits::{ - fungible, fungible::Lockable, WithdrawReasons, + fungibles, fungibles::Lockable, WithdrawReasons, Currency, ReservableCurrency, ExistenceRequirement::AllowDeath } }; use pallet_transaction_payment::{ChargeTransactionPayment, Multiplier}; use frame_system::RawOrigin; - const ID_1: fungible::LockIdentifier = *b"1 "; - const ID_2: fungible::LockIdentifier = *b"2 "; + const ID_1: fungibles::LockIdentifier = *b"1 "; + const ID_2: fungibles::LockIdentifier = *b"2 "; pub const CALL: &<$test as frame_system::Config>::RuntimeCall = &RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 0, value: 0 }); diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 6283a3b07ead0..454758bd4759c 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -37,7 +37,7 @@ use frame_support::{ parameter_types, storage::child, traits::{ - fungible::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, OnInitialize, + fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, OnInitialize, ReservableCurrency, WithdrawReasons, }, weights::{constants::WEIGHT_PER_SECOND, Weight}, diff --git a/frame/conviction-voting/src/benchmarking.rs b/frame/conviction-voting/src/benchmarking.rs index 117bb7fe22989..e985ad5cf05c8 100644 --- a/frame/conviction-voting/src/benchmarking.rs +++ b/frame/conviction-voting/src/benchmarking.rs @@ -23,7 +23,7 @@ use assert_matches::assert_matches; use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account}; use frame_support::{ dispatch::RawOrigin, - traits::{fungible, Currency, Get}, + traits::{fungibles, Currency, Get}, }; use sp_runtime::traits::Bounded; use sp_std::collections::btree_map::BTreeMap; diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index 2dec1ce9a8507..992b532fb93ed 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -31,8 +31,8 @@ use frame_support::{ dispatch::{DispatchError, DispatchResult}, ensure, traits::{ - fungible, fungible::Lockable, Currency, Get, PollStatus, Polling, ReservableCurrency, - WithdrawReasons, + fungible, fungibles, fungibles::Lockable, Currency, Get, PollStatus, Polling, + ReservableCurrency, WithdrawReasons, }, }; use sp_runtime::{ @@ -60,7 +60,7 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -const CONVICTION_VOTING_ID: fungible::LockIdentifier = *b"pyconvot"; +const CONVICTION_VOTING_ID: fungibles::LockIdentifier = *b"pyconvot"; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; type BalanceOf = @@ -104,7 +104,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// Currency type with which voting happens. type Currency: ReservableCurrency - + fungible::Lockable + + fungibles::Lockable + fungible::Inspect; /// The implementation of the logic which conducts polls. diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index ddba3fcd1fbd8..096122cb1caa5 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -157,8 +157,8 @@ use frame_support::{ ensure, traits::{ defensive_prelude::*, - fungible, - fungible::Lockable, + fungibles, + fungibles::Lockable, schedule::{v3::Named as ScheduleNamed, DispatchTime}, Bounded, Currency, Get, OnUnbalanced, QueryPreimage, ReservableCurrency, StorePreimage, WithdrawReasons, @@ -191,7 +191,7 @@ pub mod benchmarking; pub mod migrations; -const DEMOCRACY_ID: fungible::LockIdentifier = *b"democrac"; +const DEMOCRACY_ID: fungibles::LockIdentifier = *b"democrac"; /// A proposal index. pub type PropIndex = u32; @@ -236,7 +236,7 @@ pub mod pallet { /// Currency type for this pallet. type Currency: ReservableCurrency - + fungible::Lockable; + + fungibles::Lockable; /// The period between a proposal being approved and enacted. /// diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 64b8a0c9c3a6a..13190237ea784 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -101,7 +101,7 @@ use codec::{Decode, Encode}; use frame_support::{ traits::{ - defensive_prelude::*, fungible, fungible::Lockable, ChangeMembers, Contains, + defensive_prelude::*, fungibles, fungibles::Lockable, ChangeMembers, Contains, ContainsLengthBound, Currency, CurrencyToVote, Get, InitializeMembers, OnUnbalanced, ReservableCurrency, SortedMembers, WithdrawReasons, }, @@ -199,10 +199,10 @@ pub mod pallet { /// Identifier for the elections-phragmen pallet's lock #[pallet::constant] - type PalletId: Get; + type PalletId: Get; /// The currency that people are electing with. - type Currency: fungible::Lockable + type Currency: fungibles::Lockable + ReservableCurrency; /// What to do when the members change. @@ -1274,7 +1274,7 @@ mod tests { } parameter_types! { - pub const ElectionsPhragmenPalletId: fungible::LockIdentifier = *b"phrelect"; + pub const ElectionsPhragmenPalletId: fungibles::LockIdentifier = *b"phrelect"; pub const PhragmenMaxVoters: u32 = 1000; pub const PhragmenMaxCandidates: u32 = 100; } diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 4bea41103e0b2..f4b51a267fad7 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -607,9 +607,7 @@ mod tests { use frame_support::{ assert_err, parameter_types, - traits::{ - fungible, ConstU32, ConstU64, ConstU8, Currency, WithdrawReasons, - }, + traits::{fungibles, ConstU32, ConstU64, ConstU8, Currency, WithdrawReasons}, weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee}, }; use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo}; @@ -1171,11 +1169,11 @@ mod tests { #[test] fn can_pay_for_tx_fee_on_full_lock() { - let id: fungible::LockIdentifier = *b"0 "; + let id: fungibles::LockIdentifier = *b"0 "; let execute_with_lock = |lock: WithdrawReasons| { let mut t = new_test_ext(1); t.execute_with(|| { - as fungible::Lockable>::set_lock( + as fungibles::Lockable>::set_lock( id, &1, 110, lock, ); let xt = TestXt::new( diff --git a/frame/referenda/src/lib.rs b/frame/referenda/src/lib.rs index b483eaae3852a..8db614f07e008 100644 --- a/frame/referenda/src/lib.rs +++ b/frame/referenda/src/lib.rs @@ -1,5 +1,3 @@ -// This file is part of Substrate. - // Copyright (C) 2017-2022 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 @@ -68,7 +66,7 @@ use codec::{Codec, Encode}; use frame_support::{ ensure, traits::{ - fungible, + fungibles, schedule::{ v3::{Anon as ScheduleAnon, Named as ScheduleNamed}, DispatchTime, @@ -133,7 +131,7 @@ macro_rules! impl_tracksinfo_get { }; } -const ASSEMBLY_ID: fungible::LockIdentifier = *b"assembly"; +const ASSEMBLY_ID: fungibles::LockIdentifier = *b"assembly"; #[frame_support::pallet] pub mod pallet { diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 5f1f488fa304f..34e12fbcf6adf 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -25,7 +25,7 @@ use frame_support::{ dispatch::WithPostDispatchInfo, pallet_prelude::*, traits::{ - fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, + fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get, Imbalance, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, }, diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 7f918f1af7380..fd0c494fa6723 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -24,7 +24,7 @@ use frame_support::{ dispatch::Codec, pallet_prelude::*, traits::{ - fungible, fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, + fungibles, fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect, UnixTime, }, @@ -50,7 +50,7 @@ use crate::{ ValidatorPrefs, }; -const STAKING_ID: fungible::LockIdentifier = *b"staking "; +const STAKING_ID: fungibles::LockIdentifier = *b"staking "; #[frame_support::pallet] pub mod pallet { @@ -78,7 +78,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { /// The staking balance. - type Currency: fungible::Lockable< + type Currency: fungibles::Lockable< Self::AccountId, Moment = Self::BlockNumber, Balance = Self::CurrencyBalance, diff --git a/frame/support/src/traits/tokens/fungible.rs b/frame/support/src/traits/tokens/fungible.rs index f0db4589a85fd..40668ab131569 100644 --- a/frame/support/src/traits/tokens/fungible.rs +++ b/frame/support/src/traits/tokens/fungible.rs @@ -29,11 +29,9 @@ use sp_runtime::traits::Saturating; mod balanced; mod imbalance; -mod lockable; pub use balanced::{Balanced, Unbalanced}; pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance}; -pub use lockable::{LockIdentifier, Lockable}; /// Trait for providing balance-inspection access to a fungible asset. pub trait Inspect { diff --git a/frame/support/src/traits/tokens/fungibles.rs b/frame/support/src/traits/tokens/fungibles.rs index 8c370e9a0d8b5..61f47cf945bcd 100644 --- a/frame/support/src/traits/tokens/fungibles.rs +++ b/frame/support/src/traits/tokens/fungibles.rs @@ -33,7 +33,9 @@ pub mod metadata; pub use balanced::{Balanced, Unbalanced}; mod imbalance; pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance}; +mod lockable; pub mod roles; +pub use lockable::{LockIdentifier, Lockable}; /// Trait for providing balance-inspection access to a set of named fungible assets. pub trait Inspect { diff --git a/frame/support/src/traits/tokens/fungible/lockable.rs b/frame/support/src/traits/tokens/fungibles/lockable.rs similarity index 100% rename from frame/support/src/traits/tokens/fungible/lockable.rs rename to frame/support/src/traits/tokens/fungibles/lockable.rs diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index f478271da461a..226f539a740f8 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -62,7 +62,7 @@ use frame_support::{ ensure, storage::bounded_vec::BoundedVec, traits::{ - fungible, fungible::Lockable, Currency, ExistenceRequirement, Get, VestingSchedule, + fungibles, fungibles::Lockable, Currency, ExistenceRequirement, Get, VestingSchedule, WithdrawReasons, }, weights::Weight, @@ -83,12 +83,12 @@ pub use weights::WeightInfo; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -type MaxLocksOf = <::Currency as fungible::Lockable< +type MaxLocksOf = <::Currency as fungibles::Lockable< ::AccountId, >>::MaxLocks; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -const VESTING_ID: fungible::LockIdentifier = *b"vesting "; +const VESTING_ID: fungibles::LockIdentifier = *b"vesting "; // A value placed in storage that represents the current version of the Vesting storage. // This value is used by `on_runtime_upgrade` to determine whether we run storage migration logic. @@ -160,7 +160,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency trait. - type Currency: fungible::Lockable; + type Currency: fungibles::Lockable; /// Convert the block number into a balance. type BlockNumberToBalance: Convert>; From 6595afe54ef89ccb0b7128f52b012f1289f6fad3 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Fri, 2 Dec 2022 13:05:16 +0200 Subject: [PATCH 05/20] reintroduce LockableCurrency but marked as deprecated --- .../src/traits/tokens/currency/lockable.rs | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/frame/support/src/traits/tokens/currency/lockable.rs b/frame/support/src/traits/tokens/currency/lockable.rs index 5b7cad3b5c1d3..f0dc2dfc21d1d 100644 --- a/frame/support/src/traits/tokens/currency/lockable.rs +++ b/frame/support/src/traits/tokens/currency/lockable.rs @@ -17,8 +17,54 @@ //! The lockable currency trait and some associated types. -use super::Currency; -use crate::dispatch::DispatchResult; +use super::{super::misc::WithdrawReasons, Currency}; +use crate::{dispatch::DispatchResult, traits::misc::Get}; + +/// An identifier for a lock. Used for disambiguating different locks so that +/// they can be individually replaced or removed. +#[deprecated(note = "Deprecated in favour of using fungibles::LockIdentifier type")] +pub type LockIdentifier = [u8; 8]; + +/// A currency whose accounts can have liquidity restrictions. +#[deprecated(note = "Deprecated in favour of using fungibles::Lockable trait")] +pub trait LockableCurrency: Currency { + /// The quantity used to denote time; usually just a `BlockNumber`. + type Moment; + + /// The maximum number of locks a user should have on their account. + type MaxLocks: Get; + + /// Create a new balance lock on account `who`. + /// + /// If the new lock is valid (i.e. not already expired), it will push the struct to + /// the `Locks` vec in storage. Note that you can lock more funds than a user has. + /// + /// If the lock `id` already exists, this will update it. + fn set_lock( + id: LockIdentifier, + who: &AccountId, + amount: Self::Balance, + reasons: WithdrawReasons, + ); + + /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all + /// parameters or creates a new one if it does not exist. + /// + /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it + /// applies the most severe constraints of the two, while `set_lock` replaces the lock + /// with the new parameters. As in, `extend_lock` will set: + /// - maximum `amount` + /// - bitwise mask of all `reasons` + fn extend_lock( + id: LockIdentifier, + who: &AccountId, + amount: Self::Balance, + reasons: WithdrawReasons, + ); + + /// Remove an existing lock. + fn remove_lock(id: LockIdentifier, who: &AccountId); +} /// A vesting schedule over a currency. This allows a particular currency to have vesting limits /// applied to it. From c4e11b627b9fd1c69b5a15086ab28bde79cdbde0 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Mon, 5 Dec 2022 14:57:45 +0200 Subject: [PATCH 06/20] fix imports --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 0c321cbc3a6aa..0610f562d8d92 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -34,7 +34,7 @@ use frame_support::{ traits::{ fungibles, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, - LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons, + Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons, }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, From d0970e33379ef58d5d11e2a78c4a4da630423efb Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Mon, 5 Dec 2022 15:12:13 +0200 Subject: [PATCH 07/20] fix imports --- frame/support/src/traits.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 9b5300dfc5739..a9252d9926f9b 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -22,8 +22,8 @@ pub mod tokens; pub use tokens::{ currency::{ - ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency, - ReservableCurrency, TotalIssuanceOf, VestingSchedule, + ActiveIssuanceOf, Currency, NamedReservableCurrency, ReservableCurrency, TotalIssuanceOf, + VestingSchedule, }, fungible, fungibles, imbalance::{Imbalance, OnUnbalanced, SignedImbalance}, From c6f569320bbb8c88795c7003721dbf3fb79e6bee Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Mon, 5 Dec 2022 15:50:45 +0200 Subject: [PATCH 08/20] cargo fmt --- bin/node/runtime/src/lib.rs | 7 ++++--- frame/contracts/src/tests.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index d631f3bba781c..af14db0f02408 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -32,9 +32,10 @@ use frame_support::{ pallet_prelude::Get, parameter_types, traits::{ - fungibles, fungible::ItemOf, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, - EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, - Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons, + fungible::ItemOf, fungibles, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, + ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, + InstanceFilter, KeyOwnerProofSystem, Nothing, OnUnbalanced, U128CurrencyToVote, + WithdrawReasons, }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index f4823f33eae35..f4c8889ef05f4 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -37,8 +37,8 @@ use frame_support::{ parameter_types, storage::child, traits::{ - fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, OnInitialize, - ReservableCurrency, WithdrawReasons, + fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, + OnInitialize, ReservableCurrency, WithdrawReasons, }, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; From 1716ed00b3a32b81b59de47b1de6b17191645d60 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Mon, 5 Dec 2022 16:51:53 +0200 Subject: [PATCH 09/20] add allow deprecated warnings --- frame/support/src/traits/tokens/currency/lockable.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frame/support/src/traits/tokens/currency/lockable.rs b/frame/support/src/traits/tokens/currency/lockable.rs index f0dc2dfc21d1d..d63f624671670 100644 --- a/frame/support/src/traits/tokens/currency/lockable.rs +++ b/frame/support/src/traits/tokens/currency/lockable.rs @@ -22,10 +22,12 @@ use crate::{dispatch::DispatchResult, traits::misc::Get}; /// An identifier for a lock. Used for disambiguating different locks so that /// they can be individually replaced or removed. +#[allow(dead_code)] #[deprecated(note = "Deprecated in favour of using fungibles::LockIdentifier type")] pub type LockIdentifier = [u8; 8]; /// A currency whose accounts can have liquidity restrictions. +#[allow(dead_code)] #[deprecated(note = "Deprecated in favour of using fungibles::Lockable trait")] pub trait LockableCurrency: Currency { /// The quantity used to denote time; usually just a `BlockNumber`. @@ -40,6 +42,7 @@ pub trait LockableCurrency: Currency { /// the `Locks` vec in storage. Note that you can lock more funds than a user has. /// /// If the lock `id` already exists, this will update it. + #[allow(deprecated)] fn set_lock( id: LockIdentifier, who: &AccountId, @@ -55,6 +58,7 @@ pub trait LockableCurrency: Currency { /// with the new parameters. As in, `extend_lock` will set: /// - maximum `amount` /// - bitwise mask of all `reasons` + #[allow(deprecated)] fn extend_lock( id: LockIdentifier, who: &AccountId, @@ -63,6 +67,7 @@ pub trait LockableCurrency: Currency { ); /// Remove an existing lock. + #[allow(deprecated)] fn remove_lock(id: LockIdentifier, who: &AccountId); } From 928bb4d0498ec0a65937aa6be607ea73d08ac47e Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 10:35:12 +0200 Subject: [PATCH 10/20] remove unused benchmark import --- frame/conviction-voting/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/conviction-voting/src/benchmarking.rs b/frame/conviction-voting/src/benchmarking.rs index e985ad5cf05c8..4bebc6a97c49b 100644 --- a/frame/conviction-voting/src/benchmarking.rs +++ b/frame/conviction-voting/src/benchmarking.rs @@ -23,7 +23,7 @@ use assert_matches::assert_matches; use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account}; use frame_support::{ dispatch::RawOrigin, - traits::{fungibles, Currency, Get}, + traits::{Currency, Get}, }; use sp_runtime::traits::Bounded; use sp_std::collections::btree_map::BTreeMap; From 71c4860acac8b6d22c5197d70f0c54b5022d3ef0 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 10:43:52 +0200 Subject: [PATCH 11/20] fix some of the docs --- frame/balances/README.md | 8 ++++---- frame/balances/src/lib.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frame/balances/README.md b/frame/balances/README.md index 93e424a89c721..d32fffbf0e7ad 100644 --- a/frame/balances/README.md +++ b/frame/balances/README.md @@ -57,7 +57,7 @@ that you need, then you can avoid coupling with the Balances module. fungible assets system. - [`ReservableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.ReservableCurrency.html): Functions for dealing with assets that can be reserved from an account. -- [`LockableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.LockableCurrency.html): Functions for +- [`Lockable`](https://docs.rs/frame-support/latest/frame_support/traits/fungibles/trait.Lockable.html): Functions for dealing with accounts that allow liquidity restrictions. - [`Imbalance`](https://docs.rs/frame-support/latest/frame_support/traits/trait.Imbalance.html): Functions for handling imbalances between total issuance in the system and account balances. Must be used when a function @@ -88,13 +88,13 @@ pub type NegativeImbalanceOf = <::Currency as Currency<; + type Currency: fungibles::Lockable; } fn update_ledger( diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index ab6b4cd2b4dc9..f2e3f8b05e344 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -79,7 +79,7 @@ //! - [`ReservableCurrency`](frame_support::traits::ReservableCurrency): //! - [`NamedReservableCurrency`](frame_support::traits::NamedReservableCurrency): //! Functions for dealing with assets that can be reserved from an account. -//! - [`LockableCurrency`](frame_support::traits::LockableCurrency): Functions for +//! - [`Lockable`](frame_support::traits::fungibles::Lockable): Functions for //! dealing with accounts that allow liquidity restrictions. //! - [`Imbalance`](frame_support::traits::Imbalance): Functions for handling //! imbalances between total issuance in the system and account balances. Must be used when a @@ -113,13 +113,13 @@ //! # fn main() {} //! ``` //! -//! The Staking pallet uses the `LockableCurrency` trait to lock a stash account's funds: +//! The Staking pallet uses the `fungibles::Lockable` trait to lock a stash account's funds: //! //! ``` -//! use frame_support::traits::{WithdrawReasons, LockableCurrency}; +//! use frame_support::traits::{WithdrawReasons, fungibles::Lockable}; //! use sp_runtime::traits::Bounded; //! pub trait Config: frame_system::Config { -//! type Currency: LockableCurrency; +//! type Currency: fungibles::Lockable; //! } //! # struct StakingLedger { //! # stash: ::AccountId, From eac6e5d9fb100ff80eb08325d10cd0e59c9d6bb5 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 11:51:17 +0200 Subject: [PATCH 12/20] fix failing doctest check --- frame/balances/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index f2e3f8b05e344..7ec4b118b0be4 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -116,7 +116,7 @@ //! The Staking pallet uses the `fungibles::Lockable` trait to lock a stash account's funds: //! //! ``` -//! use frame_support::traits::{WithdrawReasons, fungibles::Lockable}; +//! use frame_support::traits::{WithdrawReasons, fungibles, fungibles::Lockable}; //! use sp_runtime::traits::Bounded; //! pub trait Config: frame_system::Config { //! type Currency: fungibles::Lockable; From 4e90a73e14dd4e6311e87c96ec35971b70a51ef6 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 13:04:15 +0200 Subject: [PATCH 13/20] reexport LockIdentifier and LockableCurrency from support/traits --- frame/support/src/traits.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 14813d4f7d14d..1b1d5d68cb52c 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -22,8 +22,8 @@ pub mod tokens; pub use tokens::{ currency::{ - ActiveIssuanceOf, Currency, NamedReservableCurrency, ReservableCurrency, TotalIssuanceOf, - VestingSchedule, + ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency, + ReservableCurrency, TotalIssuanceOf, VestingSchedule, }, fungible, fungibles, imbalance::{Imbalance, OnUnbalanced, SignedImbalance}, From 469103463652cad170398f41bffaa6d16172e0e4 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 13:17:42 +0200 Subject: [PATCH 14/20] reexport LockIdentifier and LockableCurrency from support/traits --- frame/support/src/traits/tokens/currency.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index 456bc6a509893..48247b6021798 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -32,8 +32,7 @@ use sp_std::fmt::Debug; mod reservable; pub use reservable::{NamedReservableCurrency, ReservableCurrency}; mod lockable; - -pub use lockable::VestingSchedule; +pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; /// Abstraction over a fungible assets system. pub trait Currency { From a022c8c6ad4b8543ff25b809c773398061a06f05 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 6 Dec 2022 13:31:33 +0200 Subject: [PATCH 15/20] allow using deprecated re-export --- frame/support/src/traits.rs | 1 + frame/support/src/traits/tokens/currency.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 1b1d5d68cb52c..7efdf7ec04850 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -20,6 +20,7 @@ //! NOTE: If you're looking for `parameter_types`, it has moved in to the top-level module. pub mod tokens; +#[allow(deprecated)] pub use tokens::{ currency::{ ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency, diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index 48247b6021798..1b20e81b62e61 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -32,6 +32,7 @@ use sp_std::fmt::Debug; mod reservable; pub use reservable::{NamedReservableCurrency, ReservableCurrency}; mod lockable; +#[allow(deprecated)] pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; /// Abstraction over a fungible assets system. From 2050f85d423b7034bd7d48a440586b751f262bbc Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Wed, 7 Dec 2022 16:51:41 +0200 Subject: [PATCH 16/20] replace LockableCurrency and LockIdentifier with a module alias --- frame/support/src/traits.rs | 2 + frame/support/src/traits/tokens/currency.rs | 6 +- .../src/traits/tokens/currency/lockable.rs | 55 +------------------ 3 files changed, 8 insertions(+), 55 deletions(-) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 3a831d9c27cc6..c5a8696833840 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -31,6 +31,8 @@ pub use tokens::{ nonfungible, nonfungibles, BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons, }; +// pub use fungibles::{LockIdentifier, Lockable as LockableCurrency}; + mod members; #[allow(deprecated)] pub use members::{AllowAll, DenyAll, Filter}; diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index 1b20e81b62e61..29603198e9a2b 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -32,8 +32,10 @@ use sp_std::fmt::Debug; mod reservable; pub use reservable::{NamedReservableCurrency, ReservableCurrency}; mod lockable; -#[allow(deprecated)] -pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule}; + +#[deprecated(note = "Deprecated in favour of using fungibles::Lockable trait directly")] +pub use super::fungibles::{LockIdentifier, Lockable as LockableCurrency}; +pub use lockable::VestingSchedule; /// Abstraction over a fungible assets system. pub trait Currency { diff --git a/frame/support/src/traits/tokens/currency/lockable.rs b/frame/support/src/traits/tokens/currency/lockable.rs index d63f624671670..5b7cad3b5c1d3 100644 --- a/frame/support/src/traits/tokens/currency/lockable.rs +++ b/frame/support/src/traits/tokens/currency/lockable.rs @@ -17,59 +17,8 @@ //! The lockable currency trait and some associated types. -use super::{super::misc::WithdrawReasons, Currency}; -use crate::{dispatch::DispatchResult, traits::misc::Get}; - -/// An identifier for a lock. Used for disambiguating different locks so that -/// they can be individually replaced or removed. -#[allow(dead_code)] -#[deprecated(note = "Deprecated in favour of using fungibles::LockIdentifier type")] -pub type LockIdentifier = [u8; 8]; - -/// A currency whose accounts can have liquidity restrictions. -#[allow(dead_code)] -#[deprecated(note = "Deprecated in favour of using fungibles::Lockable trait")] -pub trait LockableCurrency: Currency { - /// The quantity used to denote time; usually just a `BlockNumber`. - type Moment; - - /// The maximum number of locks a user should have on their account. - type MaxLocks: Get; - - /// Create a new balance lock on account `who`. - /// - /// If the new lock is valid (i.e. not already expired), it will push the struct to - /// the `Locks` vec in storage. Note that you can lock more funds than a user has. - /// - /// If the lock `id` already exists, this will update it. - #[allow(deprecated)] - fn set_lock( - id: LockIdentifier, - who: &AccountId, - amount: Self::Balance, - reasons: WithdrawReasons, - ); - - /// Changes a balance lock (selected by `id`) so that it becomes less liquid in all - /// parameters or creates a new one if it does not exist. - /// - /// Calling `extend_lock` on an existing lock `id` differs from `set_lock` in that it - /// applies the most severe constraints of the two, while `set_lock` replaces the lock - /// with the new parameters. As in, `extend_lock` will set: - /// - maximum `amount` - /// - bitwise mask of all `reasons` - #[allow(deprecated)] - fn extend_lock( - id: LockIdentifier, - who: &AccountId, - amount: Self::Balance, - reasons: WithdrawReasons, - ); - - /// Remove an existing lock. - #[allow(deprecated)] - fn remove_lock(id: LockIdentifier, who: &AccountId); -} +use super::Currency; +use crate::dispatch::DispatchResult; /// A vesting schedule over a currency. This allows a particular currency to have vesting limits /// applied to it. From 9432b9d4f200b35243297c221fd4c61531d703ab Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Wed, 7 Dec 2022 16:36:55 +0100 Subject: [PATCH 17/20] Update frame/support/src/traits/tokens/fungibles/lockable.rs --- frame/support/src/traits/tokens/fungibles/lockable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/traits/tokens/fungibles/lockable.rs b/frame/support/src/traits/tokens/fungibles/lockable.rs index bf968d6e4fd39..185b40eae9b28 100644 --- a/frame/support/src/traits/tokens/fungibles/lockable.rs +++ b/frame/support/src/traits/tokens/fungibles/lockable.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The lockable currency trait and some associated types. +//! The Lockable trait and some associated types. use super::{super::misc::WithdrawReasons, currency::Currency}; use crate::traits::misc::Get; From 1e1c43e052eadce9a7322d0aad3fa69e92e05fd2 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Thu, 8 Dec 2022 12:37:20 +0200 Subject: [PATCH 18/20] Update frame/staking/src/pallet/mod.rs Co-authored-by: Squirrel --- frame/staking/src/pallet/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index fd0c494fa6723..eb663854e18bb 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -24,7 +24,7 @@ use frame_support::{ dispatch::Codec, pallet_prelude::*, traits::{ - fungibles, fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, + fungibles, Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect, UnixTime, }, From f3c69a00b93fa1e356f1aa857053b0523626e40d Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Thu, 8 Dec 2022 12:37:28 +0200 Subject: [PATCH 19/20] Update frame/support/src/traits.rs Co-authored-by: Squirrel --- frame/support/src/traits.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index c5a8696833840..256d5bb466e4a 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -31,7 +31,6 @@ pub use tokens::{ nonfungible, nonfungibles, BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons, }; -// pub use fungibles::{LockIdentifier, Lockable as LockableCurrency}; mod members; #[allow(deprecated)] From 0a5a820a5ab549ed1589950e2601639f4b040e22 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Thu, 8 Dec 2022 13:00:31 +0200 Subject: [PATCH 20/20] REVERT removing fungibles::Lockable import --- frame/staking/src/pallet/mod.rs | 2 +- frame/support/src/traits.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index eb663854e18bb..fd0c494fa6723 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -24,7 +24,7 @@ use frame_support::{ dispatch::Codec, pallet_prelude::*, traits::{ - fungibles, Currency, CurrencyToVote, Defensive, DefensiveResult, + fungibles, fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect, UnixTime, }, diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 256d5bb466e4a..3a831d9c27cc6 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -31,7 +31,6 @@ pub use tokens::{ nonfungible, nonfungibles, BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons, }; - mod members; #[allow(deprecated)] pub use members::{AllowAll, DenyAll, Filter};