Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Move LockableCurrency trait to fungible::Lockable and deprecate LockableCurrency #12887

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9a537f9
WIP move LockableCurrency to fungibles
tonyalaribe Nov 28, 2022
c1a5824
rename Lockable and LockIdentifier to funginbles::*
tonyalaribe Nov 30, 2022
cc39dc4
fix imports further
tonyalaribe Nov 30, 2022
2c34ec4
change Lockable from fungible to fungibles
tonyalaribe Dec 2, 2022
35174e0
Merge branch 'master' into aa/lockable-for-assets
tonyalaribe Dec 2, 2022
6595afe
reintroduce LockableCurrency but marked as deprecated
tonyalaribe Dec 2, 2022
b7e1941
Merge branch 'aa/lockable-for-assets' of github.com:paritytech/substr…
tonyalaribe Dec 5, 2022
3f806c7
Merge branch 'master' into aa/lockable-for-assets
tonyalaribe Dec 5, 2022
c4e11b6
fix imports
tonyalaribe Dec 5, 2022
cf328be
Merge branch 'aa/lockable-for-assets' of github.com:paritytech/substr…
tonyalaribe Dec 5, 2022
d0970e3
fix imports
tonyalaribe Dec 5, 2022
6cdfd70
Merge branch 'master' into aa/lockable-for-assets
tonyalaribe Dec 5, 2022
c6f5693
cargo fmt
tonyalaribe Dec 5, 2022
1716ed0
add allow deprecated warnings
tonyalaribe Dec 5, 2022
928bb4d
remove unused benchmark import
tonyalaribe Dec 6, 2022
71c4860
fix some of the docs
tonyalaribe Dec 6, 2022
eac6e5d
fix failing doctest check
tonyalaribe Dec 6, 2022
4e90a73
reexport LockIdentifier and LockableCurrency from support/traits
tonyalaribe Dec 6, 2022
4691034
reexport LockIdentifier and LockableCurrency from support/traits
tonyalaribe Dec 6, 2022
a022c8c
allow using deprecated re-export
tonyalaribe Dec 6, 2022
9c00601
Merge remote-tracking branch 'origin/master' into aa/lockable-for-assets
Dec 6, 2022
bc35b27
Merge remote-tracking branch 'origin/master' into aa/lockable-for-assets
Dec 7, 2022
2050f85
replace LockableCurrency and LockIdentifier with a module alias
tonyalaribe Dec 7, 2022
9432b9d
Update frame/support/src/traits/tokens/fungibles/lockable.rs
tonyalaribe Dec 7, 2022
1e1c43e
Update frame/staking/src/pallet/mod.rs
tonyalaribe Dec 8, 2022
f3c69a0
Update frame/support/src/traits.rs
tonyalaribe Dec 8, 2022
0a5a820
REVERT removing fungibles::Lockable import
tonyalaribe Dec 8, 2022
101f352
Merge remote-tracking branch 'origin/master' into aa/lockable-for-assets
tonyalaribe Dec 9, 2022
16212b5
switch from fungibles to fungible
tonyalaribe Dec 9, 2022
9caf89a
fix fmt
tonyalaribe Dec 9, 2022
f0bd8ab
fix imports in benchmarks
tonyalaribe Dec 9, 2022
2a7f615
Update README.md
tonyalaribe Dec 9, 2022
97b3ee1
Update README.md
tonyalaribe Dec 9, 2022
eacb6c0
reintroduce LockableCurrency and LockIdentifiers as copies, so fungib…
tonyalaribe Dec 15, 2022
3c195c7
Merge branch 'aa/lockable-for-assets-2' of github.com:paritytech/subs…
tonyalaribe Dec 15, 2022
b8fad5e
Merge branch 'master' into aa/lockable-for-assets-2
tonyalaribe Dec 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ use frame_support::{
pallet_prelude::Get,
parameter_types,
traits::{
fungible::ItemOf, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32,
Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter,
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
fungible, fungible::ItemOf, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16,
ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance,
InstanceFilter, KeyOwnerProofSystem, Nothing, OnUnbalanced, U128CurrencyToVote,
WithdrawReasons,
},
weights::{
Expand Down Expand Up @@ -1006,7 +1006,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.
Expand Down
8 changes: 4 additions & 4 deletions frame/balances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/fungible/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
Expand Down Expand Up @@ -88,13 +88,13 @@ pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as fra

```

The Staking module uses the `LockableCurrency` trait to lock a stash account's funds:
The Staking module uses the `fungible::Lockable` trait to lock a stash account's funds:

```rust
use frame_support::traits::{WithdrawReasons, LockableCurrency};
use frame_support::traits::{WithdrawReasons, fungible};
use sp_runtime::traits::Bounded;
pub trait Config: frame_system::Config {
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
type Currency: fungible::Lockable<Self::AccountId, Moment=Self::BlockNumber>;
}

fn update_ledger<T: Config>(
Expand Down
22 changes: 11 additions & 11 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::fungible::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
Expand Down Expand Up @@ -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 `fungible::Lockable` trait to lock a stash account's funds:
//!
//! ```
//! use frame_support::traits::{WithdrawReasons, LockableCurrency};
//! use frame_support::traits::{WithdrawReasons, fungible, fungible::Lockable};
//! use sp_runtime::traits::Bounded;
//! pub trait Config: frame_system::Config {
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
//! type Currency: fungible::Lockable<Self::AccountId, Moment=Self::BlockNumber>;
//! }
//! # struct StakingLedger<T: Config> {
//! # stash: <T as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -174,8 +174,8 @@ use frame_support::{
tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence},
Currency, DefensiveSaturating, ExistenceRequirement,
ExistenceRequirement::{AllowDeath, KeepAlive},
Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency, OnUnbalanced,
ReservableCurrency, SignedImbalance, StoredMap, TryDrop, WithdrawReasons,
Get, Imbalance, NamedReservableCurrency, OnUnbalanced, ReservableCurrency, SignedImbalance,
StoredMap, TryDrop, WithdrawReasons,
},
WeakBoundedVec,
};
Expand Down Expand Up @@ -668,7 +668,7 @@ impl BitOr for Reasons {
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct BalanceLock<Balance> {
/// 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.
Expand Down Expand Up @@ -2137,7 +2137,7 @@ where
}
}

impl<T: Config<I>, I: 'static> LockableCurrency<T::AccountId> for Pallet<T, I>
impl<T: Config<I>, I: 'static> fungible::Lockable<T::AccountId> for Pallet<T, I>
where
T::Balance: MaybeSerializeDeserialize + Debug,
{
Expand All @@ -2148,7 +2148,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,
Expand All @@ -2170,7 +2170,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,
Expand Down Expand Up @@ -2199,7 +2199,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[..]);
Expand Down
6 changes: 3 additions & 3 deletions frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ macro_rules! decl_tests {
use frame_support::{
assert_noop, assert_storage_noop, assert_ok, assert_err,
traits::{
LockableCurrency, LockIdentifier, WithdrawReasons,
fungible, fungible::Lockable, WithdrawReasons,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you don't include fungible::Lockable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this, if fungible::Lockable isn't included:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, got it :)

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 });
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use frame_support::{
parameter_types,
storage::child,
traits::{
BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, LockableCurrency, OnIdle,
fungible::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle,
OnInitialize, ReservableCurrency, WithdrawReasons,
},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
Expand Down
2 changes: 1 addition & 1 deletion frame/conviction-voting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{Currency, Get},
};
use sp_runtime::traits::Bounded;
use sp_std::collections::btree_map::BTreeMap;
Expand Down
8 changes: 4 additions & 4 deletions frame/conviction-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use frame_support::{
dispatch::{DispatchError, DispatchResult},
ensure,
traits::{
fungible, Currency, Get, LockIdentifier, LockableCurrency, PollStatus, Polling,
ReservableCurrency, WithdrawReasons,
fungible, fungible::Lockable, Currency, Get, PollStatus, Polling, ReservableCurrency,
WithdrawReasons,
},
};
use sp_runtime::{
Expand Down Expand Up @@ -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<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type BalanceOf<T, I = ()> =
Expand Down Expand Up @@ -104,7 +104,7 @@ pub mod pallet {
type WeightInfo: WeightInfo;
/// Currency type with which voting happens.
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
+ fungible::Lockable<Self::AccountId, Moment = Self::BlockNumber>
+ fungible::Inspect<Self::AccountId>;

/// The implementation of the logic which conducts polls.
Expand Down
10 changes: 6 additions & 4 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ use frame_support::{
ensure,
traits::{
defensive_prelude::*,
fungible,
fungible::Lockable,
schedule::{v3::Named as ScheduleNamed, DispatchTime},
Bounded, Currency, Get, LockIdentifier, LockableCurrency, OnUnbalanced, QueryPreimage,
ReservableCurrency, StorePreimage, WithdrawReasons,
Bounded, Currency, Get, OnUnbalanced, QueryPreimage, ReservableCurrency, StorePreimage,
WithdrawReasons,
},
weights::Weight,
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -234,7 +236,7 @@ pub mod pallet {

/// Currency type for this pallet.
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
+ fungible::Lockable<Self::AccountId, Moment = Self::BlockNumber>;

/// The period between a proposal being approved and enacted.
///
Expand Down
10 changes: 5 additions & 5 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
use codec::{Decode, Encode};
use frame_support::{
traits::{
defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency,
CurrencyToVote, Get, InitializeMembers, LockIdentifier, LockableCurrency, OnUnbalanced,
defensive_prelude::*, fungible, fungible::Lockable, ChangeMembers, Contains,
ContainsLengthBound, Currency, CurrencyToVote, Get, InitializeMembers, OnUnbalanced,
ReservableCurrency, SortedMembers, WithdrawReasons,
},
weights::Weight,
Expand Down Expand Up @@ -199,10 +199,10 @@ pub mod pallet {

/// Identifier for the elections-phragmen pallet's lock
#[pallet::constant]
type PalletId: Get<LockIdentifier>;
type PalletId: Get<fungible::LockIdentifier>;

/// The currency that people are electing with.
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
type Currency: fungible::Lockable<Self::AccountId, Moment = Self::BlockNumber>
+ ReservableCurrency<Self::AccountId>;

/// What to do when the members change.
Expand Down Expand Up @@ -1280,7 +1280,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;
}
Expand Down
9 changes: 3 additions & 6 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,7 @@ mod tests {

use frame_support::{
assert_err, parameter_types,
traits::{
ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, LockableCurrency,
WithdrawReasons,
},
traits::{fungible, ConstU32, ConstU64, ConstU8, Currency, WithdrawReasons},
weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee},
};
use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo};
Expand Down Expand Up @@ -1258,11 +1255,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(|| {
<pallet_balances::Pallet<Runtime> as LockableCurrency<Balance>>::set_lock(
<pallet_balances::Pallet<Runtime> as fungible::Lockable<Balance>>::set_lock(
id, &1, 110, lock,
);
let xt = TestXt::new(
Expand Down
7 changes: 3 additions & 4 deletions frame/referenda/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file is part of Substrate.

// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -68,11 +66,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,
Expand Down Expand Up @@ -133,7 +132,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 {
Expand Down
5 changes: 3 additions & 2 deletions frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use frame_support::{
dispatch::WithPostDispatchInfo,
pallet_prelude::*,
traits::{
Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get,
Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons,
fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult,
EstimateNextNewSession, Get, Imbalance, OnUnbalanced, TryCollect, UnixTime,
WithdrawReasons,
},
weights::Weight,
};
Expand Down
8 changes: 4 additions & 4 deletions frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use frame_support::{
dispatch::Codec,
pallet_prelude::*,
traits::{
Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin,
EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, TryCollect,
fungible, fungible::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult,
DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect,
UnixTime,
},
weights::Weight,
Expand All @@ -50,7 +50,7 @@ use crate::{
ValidatorPrefs,
};

const STAKING_ID: LockIdentifier = *b"staking ";
const STAKING_ID: fungible::LockIdentifier = *b"staking ";
// The speculative number of spans are used as an input of the weight annotation of
// [`Call::unbond`], as the post dipatch weight may depend on the number of slashing span on the
// account which is not provided as an input. The value set should be conservative but sensible.
Expand Down Expand Up @@ -82,7 +82,7 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
/// The staking balance.
type Currency: LockableCurrency<
type Currency: fungible::Lockable<
Self::AccountId,
Moment = Self::BlockNumber,
Balance = Self::CurrencyBalance,
Expand Down
1 change: 1 addition & 0 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this?

pub use tokens::{
currency::{
ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency,
Expand Down
3 changes: 3 additions & 0 deletions frame/support/src/traits/tokens/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ use sp_runtime::traits::Saturating;

mod balanced;
mod imbalance;
mod lockable;
pub use lockable::{LockIdentifier, Lockable};

pub use balanced::{Balanced, Unbalanced};
pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance};

Expand Down
Loading