diff --git a/frame/balances/src/impl_fungible.rs b/frame/balances/src/impl_fungible.rs index 81bfa808adddf..9b01f0760967a 100644 --- a/frame/balances/src/impl_fungible.rs +++ b/frame/balances/src/impl_fungible.rs @@ -68,13 +68,31 @@ impl, I: 'static> fungible::Inspect for Pallet // 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 { - Self::account(who).usable() + 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::::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::::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,