mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 07:05:44 +00:00
Non-Interactive Staking (#12610)
* Improve naming. * More improvements to naming * Fungible counterpart * Shared pot instead of reserve * Transferable receipts * Better naming * Use u128 for counterpart * Partial thawing * Docs * Remove AdminOrigin * Integrate into Kitchen Sink * Thaw throttling * Remove todo * Docs * Fix benchmarks * Building * Tests work * New benchmarks * Benchmarking tests * Test new defensive_saturating_* functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Formatting * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Events added * Fix kitchensink * Update frame/nis/src/lib.rs Co-authored-by: Xiliang Chen <xlchen1291@gmail.com> * Review niggles * Remove genesis build requirements * Grumbles * Fixes * Fixes * Fixes * Update frame/nis/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update primitives/runtime/src/traits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Formatting * Fixes * Fix node genesis config Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix node chain specs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use free asset ID as counterpart Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Account for rounding errors in fund_deficit bench Relaxes the check for the NIS account balance in the fund_deficit bench from equality from to checking for 99.999% equality. The exact deviation for the kitchensink runtime config is 1.24e-10 percent but could vary if the config is changed. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix * Rename * Fixes * Fixes * Formatting Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Xiliang Chen <xlchen1291@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -17,8 +17,14 @@
|
||||
|
||||
//! The reservable currency trait.
|
||||
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::Get;
|
||||
|
||||
use super::{super::misc::BalanceStatus, Currency};
|
||||
use crate::dispatch::{DispatchError, DispatchResult};
|
||||
use crate::{
|
||||
dispatch::{DispatchError, DispatchResult},
|
||||
traits::{ExistenceRequirement, SignedImbalance, WithdrawReasons},
|
||||
};
|
||||
|
||||
/// A currency where funds can be reserved from the user.
|
||||
pub trait ReservableCurrency<AccountId>: Currency<AccountId> {
|
||||
@@ -111,7 +117,7 @@ impl<AccountId> ReservableCurrency<AccountId> for () {
|
||||
pub trait NamedReservableCurrency<AccountId>: ReservableCurrency<AccountId> {
|
||||
/// An identifier for a reserve. Used for disambiguating different reserves so that
|
||||
/// they can be individually replaced or removed.
|
||||
type ReserveIdentifier;
|
||||
type ReserveIdentifier: codec::Encode + TypeInfo + 'static;
|
||||
|
||||
/// Deducts up to `value` from reserved balance of `who`. This function cannot fail.
|
||||
///
|
||||
@@ -236,3 +242,144 @@ pub trait NamedReservableCurrency<AccountId>: ReservableCurrency<AccountId> {
|
||||
Self::repatriate_reserved_named(id, slashed, beneficiary, value, status).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapter to allow a `NamedReservableCurrency` to be passed as regular `ReservableCurrency`
|
||||
/// together with an `Id`.
|
||||
///
|
||||
/// All "anonymous" operations are then implemented as their named counterparts with the given `Id`.
|
||||
pub struct WithName<NamedReservable, Id, AccountId>(
|
||||
sp_std::marker::PhantomData<(NamedReservable, Id, AccountId)>,
|
||||
);
|
||||
impl<
|
||||
NamedReservable: NamedReservableCurrency<AccountId>,
|
||||
Id: Get<NamedReservable::ReserveIdentifier>,
|
||||
AccountId,
|
||||
> Currency<AccountId> for WithName<NamedReservable, Id, AccountId>
|
||||
{
|
||||
type Balance = <NamedReservable as Currency<AccountId>>::Balance;
|
||||
type PositiveImbalance = <NamedReservable as Currency<AccountId>>::PositiveImbalance;
|
||||
type NegativeImbalance = <NamedReservable as Currency<AccountId>>::NegativeImbalance;
|
||||
|
||||
fn total_balance(who: &AccountId) -> Self::Balance {
|
||||
NamedReservable::total_balance(who)
|
||||
}
|
||||
fn can_slash(who: &AccountId, value: Self::Balance) -> bool {
|
||||
NamedReservable::can_slash(who, value)
|
||||
}
|
||||
fn total_issuance() -> Self::Balance {
|
||||
NamedReservable::total_issuance()
|
||||
}
|
||||
fn minimum_balance() -> Self::Balance {
|
||||
NamedReservable::minimum_balance()
|
||||
}
|
||||
fn burn(amount: Self::Balance) -> Self::PositiveImbalance {
|
||||
NamedReservable::burn(amount)
|
||||
}
|
||||
fn issue(amount: Self::Balance) -> Self::NegativeImbalance {
|
||||
NamedReservable::issue(amount)
|
||||
}
|
||||
fn pair(amount: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) {
|
||||
NamedReservable::pair(amount)
|
||||
}
|
||||
fn free_balance(who: &AccountId) -> Self::Balance {
|
||||
NamedReservable::free_balance(who)
|
||||
}
|
||||
fn ensure_can_withdraw(
|
||||
who: &AccountId,
|
||||
amount: Self::Balance,
|
||||
reasons: WithdrawReasons,
|
||||
new_balance: Self::Balance,
|
||||
) -> DispatchResult {
|
||||
NamedReservable::ensure_can_withdraw(who, amount, reasons, new_balance)
|
||||
}
|
||||
|
||||
fn transfer(
|
||||
source: &AccountId,
|
||||
dest: &AccountId,
|
||||
value: Self::Balance,
|
||||
existence_requirement: ExistenceRequirement,
|
||||
) -> DispatchResult {
|
||||
NamedReservable::transfer(source, dest, value, existence_requirement)
|
||||
}
|
||||
fn slash(who: &AccountId, value: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) {
|
||||
NamedReservable::slash(who, value)
|
||||
}
|
||||
fn deposit_into_existing(
|
||||
who: &AccountId,
|
||||
value: Self::Balance,
|
||||
) -> Result<Self::PositiveImbalance, DispatchError> {
|
||||
NamedReservable::deposit_into_existing(who, value)
|
||||
}
|
||||
fn resolve_into_existing(
|
||||
who: &AccountId,
|
||||
value: Self::NegativeImbalance,
|
||||
) -> Result<(), Self::NegativeImbalance> {
|
||||
NamedReservable::resolve_into_existing(who, value)
|
||||
}
|
||||
fn deposit_creating(who: &AccountId, value: Self::Balance) -> Self::PositiveImbalance {
|
||||
NamedReservable::deposit_creating(who, value)
|
||||
}
|
||||
fn resolve_creating(who: &AccountId, value: Self::NegativeImbalance) {
|
||||
NamedReservable::resolve_creating(who, value)
|
||||
}
|
||||
fn withdraw(
|
||||
who: &AccountId,
|
||||
value: Self::Balance,
|
||||
reasons: WithdrawReasons,
|
||||
liveness: ExistenceRequirement,
|
||||
) -> Result<Self::NegativeImbalance, DispatchError> {
|
||||
NamedReservable::withdraw(who, value, reasons, liveness)
|
||||
}
|
||||
fn settle(
|
||||
who: &AccountId,
|
||||
value: Self::PositiveImbalance,
|
||||
reasons: WithdrawReasons,
|
||||
liveness: ExistenceRequirement,
|
||||
) -> Result<(), Self::PositiveImbalance> {
|
||||
NamedReservable::settle(who, value, reasons, liveness)
|
||||
}
|
||||
fn make_free_balance_be(
|
||||
who: &AccountId,
|
||||
balance: Self::Balance,
|
||||
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance> {
|
||||
NamedReservable::make_free_balance_be(who, balance)
|
||||
}
|
||||
}
|
||||
impl<
|
||||
NamedReservable: NamedReservableCurrency<AccountId>,
|
||||
Id: Get<NamedReservable::ReserveIdentifier>,
|
||||
AccountId,
|
||||
> ReservableCurrency<AccountId> for WithName<NamedReservable, Id, AccountId>
|
||||
{
|
||||
fn can_reserve(who: &AccountId, value: Self::Balance) -> bool {
|
||||
NamedReservable::can_reserve(who, value)
|
||||
}
|
||||
|
||||
fn slash_reserved(
|
||||
who: &AccountId,
|
||||
value: Self::Balance,
|
||||
) -> (Self::NegativeImbalance, Self::Balance) {
|
||||
NamedReservable::slash_reserved_named(&Id::get(), who, value)
|
||||
}
|
||||
|
||||
fn reserved_balance(who: &AccountId) -> Self::Balance {
|
||||
NamedReservable::reserved_balance_named(&Id::get(), who)
|
||||
}
|
||||
|
||||
fn reserve(who: &AccountId, value: Self::Balance) -> DispatchResult {
|
||||
NamedReservable::reserve_named(&Id::get(), who, value)
|
||||
}
|
||||
|
||||
fn unreserve(who: &AccountId, value: Self::Balance) -> Self::Balance {
|
||||
NamedReservable::unreserve_named(&Id::get(), who, value)
|
||||
}
|
||||
|
||||
fn repatriate_reserved(
|
||||
slashed: &AccountId,
|
||||
beneficiary: &AccountId,
|
||||
value: Self::Balance,
|
||||
status: BalanceStatus,
|
||||
) -> Result<Self::Balance, DispatchError> {
|
||||
NamedReservable::repatriate_reserved_named(&Id::get(), slashed, beneficiary, value, status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
/// is returned and nothing is changed. If successful, the amount of tokens reduced is returned.
|
||||
///
|
||||
/// The default implementation just uses `withdraw` along with `reducible_balance` to ensure
|
||||
/// that is doesn't fail.
|
||||
/// that it doesn't fail.
|
||||
fn slash(who: &AccountId, amount: Self::Balance) -> Result<Self::Balance, DispatchError> {
|
||||
Self::burn_from(who, Self::reducible_balance(who, false).min(amount))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user