Move LockableCurrency trait to fungibles::Lockable and deprecate LockableCurrency (#12798)

* WIP move LockableCurrency to fungibles

* rename Lockable and LockIdentifier to funginbles::*

* fix imports further

* change Lockable from fungible to fungibles

* reintroduce LockableCurrency but marked as deprecated

* fix imports

* fix imports

* cargo fmt

* add allow deprecated warnings

* remove unused benchmark import

* fix some of the docs

* fix failing doctest check

* reexport LockIdentifier and LockableCurrency from support/traits

* reexport LockIdentifier and LockableCurrency from support/traits

* allow using deprecated re-export

* replace LockableCurrency and LockIdentifier with a module alias

* Update frame/support/src/traits/tokens/fungibles/lockable.rs

* Update frame/staking/src/pallet/mod.rs

Co-authored-by: Squirrel <gilescope@gmail.com>

* Update frame/support/src/traits.rs

Co-authored-by: Squirrel <gilescope@gmail.com>

* REVERT removing fungibles::Lockable import

Co-authored-by: parity-processbot <>
Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
Anthony Alaribe
2022-12-08 14:47:13 +02:00
committed by GitHub
parent 39cb3b06cd
commit 9a014d1ecd
20 changed files with 135 additions and 105 deletions
+1
View File
@@ -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,
@@ -32,7 +32,10 @@ use sp_std::fmt::Debug;
mod reservable;
pub use reservable::{NamedReservableCurrency, ReservableCurrency};
mod lockable;
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<AccountId> {
@@ -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<AccountId>: Currency<AccountId> {
/// 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<u32>;
/// 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.
@@ -29,6 +29,7 @@ use sp_runtime::traits::Saturating;
mod balanced;
mod imbalance;
pub use balanced::{Balanced, Unbalanced};
pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance};
@@ -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<AccountId> {
@@ -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 trait and some associated types.
use super::{super::misc::WithdrawReasons, currency::Currency};
use crate::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<AccountId>: Currency<AccountId> {
/// 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<u32>;
/// 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);
}