Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
fix .
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjscksdn98 committed Oct 25, 2023
1 parent 59e1f62 commit 0e1fa70
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 65 deletions.
10 changes: 0 additions & 10 deletions frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ impl<T: Config<I>, I: 'static> fungibles::Inspect<<T as SystemConfig>::AccountId
.unwrap_or(Zero::zero())
}

fn evm_reducible_balance(
asset: Self::AssetId,
who: &<T as SystemConfig>::AccountId,
preservation: Preservation,
_: Fortitude,
) -> Self::Balance {
Pallet::<T, I>::reducible_balance(asset, who, !matches!(preservation, Expendable))
.unwrap_or(Zero::zero())
}

fn can_deposit(
asset: Self::AssetId,
who: &<T as SystemConfig>::AccountId,
Expand Down
23 changes: 22 additions & 1 deletion frame/balances/src/impl_currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_support::{
ensure,
pallet_prelude::DispatchResult,
traits::{
tokens::{fungible, BalanceStatus as Status, Fortitude::Polite, Precision::BestEffort},
tokens::{fungible, BalanceStatus as Status, Fortitude::Polite, Precision::BestEffort, Preservation::{self, Preserve, Protect}},
Currency, DefensiveSaturating, ExistenceRequirement,
ExistenceRequirement::AllowDeath,
Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency,
Expand Down Expand Up @@ -476,6 +476,27 @@ where
)
.unwrap_or_else(|_| SignedImbalance::Positive(Self::PositiveImbalance::zero()))
}

fn evm_reducible_balance(
who: &T::AccountId,
preservation: Preservation,
) -> Self::Balance {
let a = Self::account(who);
let mut untouchable = a.frozen;
// If we want to keep our provider ref..
if preservation == Preserve
// ..or we don't want the account to die and our provider ref is needed for it to live..
|| preservation == Protect && !a.free.is_zero() &&
frame_system::Pallet::<T>::providers(who) == 1
// ..or we don't care about the account dying but our provider ref is required..
|| preservation == Expendable && !a.free.is_zero() &&
!frame_system::Pallet::<T>::can_dec_provider(who)
{
// ..then the ED needed..
untouchable = untouchable.max(T::ExistentialDeposit::get());
}
a.free.saturating_sub(untouchable)
}
}

impl<T: Config<I>, I: 'static> ReservableCurrency<T::AccountId> for Pallet<T, I>
Expand Down
26 changes: 0 additions & 26 deletions frame/balances/src/impl_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,6 @@ impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>
// Liquid balance is what is neither on hold nor frozen/required for provider.
a.free.saturating_sub(untouchable)
}
/// This method will only be used until migrations to fungible traits are done.
fn evm_reducible_balance(
who: &T::AccountId,
preservation: Preservation,
force: Fortitude,
) -> Self::Balance {
let a = Self::account(who);
let mut untouchable = Zero::zero();
if force == Polite {
// In the case for EVM, we only care about frozen balance.
untouchable = a.frozen;
}
// If we want to keep our provider ref..
if preservation == Preserve
// ..or we don't want the account to die and our provider ref is needed for it to live..
|| preservation == Protect && !a.free.is_zero() &&
frame_system::Pallet::<T>::providers(who) == 1
// ..or we don't care about the account dying but our provider ref is required..
|| preservation == Expendable && !a.free.is_zero() &&
!frame_system::Pallet::<T>::can_dec_provider(who)
{
// ..then the ED needed..
untouchable = untouchable.max(T::ExistentialDeposit::get());
}
a.free.saturating_sub(untouchable)
}
fn can_deposit(
who: &T::AccountId,
amount: Self::Balance,
Expand Down
3 changes: 0 additions & 3 deletions frame/nis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ impl<T> FunInspect<T> for NoCounterpart<T> {
fn reducible_balance(_: &T, _: Preservation, _: Fortitude) -> u32 {
0
}
fn evm_reducible_balance(_: &T, _: Preservation, _: Fortitude) -> u32 {
0
}
fn can_deposit(_: &T, _: u32, _: Provenance) -> DepositConsequence {
DepositConsequence::Success
}
Expand Down
16 changes: 15 additions & 1 deletion frame/support/src/traits/tokens/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use super::{
imbalance::{Imbalance, SignedImbalance},
misc::{Balance, ExistenceRequirement, WithdrawReasons},
misc::{Balance, ExistenceRequirement, WithdrawReasons}, Preservation,
};
use crate::{
dispatch::{DispatchError, DispatchResult},
Expand Down Expand Up @@ -213,6 +213,17 @@ pub trait Currency<AccountId> {
who: &AccountId,
balance: Self::Balance,
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>;

/// Get the maximum amount that `who` can withdraw/transfer successfully based on whether the
/// account should be kept alive (`preservation`) or whether we are willing to force the
/// reduction and potentially go below user-level restrictions on the minimum amount of the
/// account.
///
/// Always less than or equal to `balance()`.
fn evm_reducible_balance(
who: &AccountId,
preservation: Preservation,
) -> Self::Balance;
}

/// A non-const `Get` implementation parameterised by a `Currency` impl which provides the result
Expand Down Expand Up @@ -319,4 +330,7 @@ impl<AccountId> Currency<AccountId> for () {
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance> {
SignedImbalance::Positive(())
}
fn evm_reducible_balance(_: &AccountId, _: Preservation) -> u32 {
0
}
}
8 changes: 7 additions & 1 deletion frame/support/src/traits/tokens/currency/reservable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_core::Get;
use super::{super::misc::BalanceStatus, Currency};
use crate::{
dispatch::{DispatchError, DispatchResult},
traits::{ExistenceRequirement, SignedImbalance, WithdrawReasons},
traits::{ExistenceRequirement, SignedImbalance, WithdrawReasons, tokens::Preservation},
};

/// A currency where funds can be reserved from the user.
Expand Down Expand Up @@ -344,6 +344,12 @@ impl<
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance> {
NamedReservable::make_free_balance_be(who, balance)
}
fn evm_reducible_balance(
who: &AccountId,
preservation: Preservation,
) -> Self::Balance {
NamedReservable::evm_reducible_balance(who, preservation)
}
}
impl<
NamedReservable: NamedReservableCurrency<AccountId>,
Expand Down
12 changes: 0 additions & 12 deletions frame/support/src/traits/tokens/fungible/item_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ impl<
) -> Self::Balance {
<F as fungibles::Inspect<AccountId>>::reducible_balance(A::get(), who, preservation, force)
}
fn evm_reducible_balance(
who: &AccountId,
preservation: Preservation,
force: Fortitude,
) -> Self::Balance {
<F as fungibles::Inspect<AccountId>>::evm_reducible_balance(
A::get(),
who,
preservation,
force,
)
}
fn can_deposit(
who: &AccountId,
amount: Self::Balance,
Expand Down
5 changes: 0 additions & 5 deletions frame/support/src/traits/tokens/fungible/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ pub trait Inspect<AccountId>: Sized {
preservation: Preservation,
force: Fortitude,
) -> Self::Balance;
fn evm_reducible_balance(
who: &AccountId,
preservation: Preservation,
force: Fortitude,
) -> Self::Balance;

/// Returns `true` if the balance of `who` may be increased by `amount`.
///
Expand Down
6 changes: 0 additions & 6 deletions frame/support/src/traits/tokens/fungibles/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ pub trait Inspect<AccountId>: Sized {
preservation: Preservation,
force: Fortitude,
) -> Self::Balance;
fn evm_reducible_balance(
asset: Self::AssetId,
who: &AccountId,
preservation: Preservation,
force: Fortitude,
) -> Self::Balance;

/// Returns `true` if the `asset` balance of `who` may be increased by `amount`.
///
Expand Down

0 comments on commit 0e1fa70

Please sign in to comment.