@@ -25,7 +25,7 @@ use frame_support::{
2525 ensure,
2626 pallet_prelude:: DispatchResult ,
2727 traits:: {
28- tokens:: { fungible, BalanceStatus as Status , Fortitude :: Polite , Precision :: BestEffort } ,
28+ tokens:: { fungible, BalanceStatus as Status , Fortitude :: Polite , Precision :: BestEffort , Preservation :: { self , Preserve , Protect } } ,
2929 Currency , DefensiveSaturating , ExistenceRequirement ,
3030 ExistenceRequirement :: AllowDeath ,
3131 Get , Imbalance , InspectLockableCurrency , LockIdentifier , LockableCurrency ,
@@ -487,6 +487,27 @@ where
487487 )
488488 . unwrap_or_else ( |_| SignedImbalance :: Positive ( Self :: PositiveImbalance :: zero ( ) ) )
489489 }
490+
491+ fn transferrable_balance (
492+ who : & T :: AccountId ,
493+ preservation : Preservation ,
494+ ) -> Self :: Balance {
495+ let a = Self :: account ( who) ;
496+ let mut untouchable = a. frozen ;
497+ // If we want to keep our provider ref..
498+ if preservation == Preserve
499+ // ..or we don't want the account to die and our provider ref is needed for it to live..
500+ || preservation == Protect && !a. free . is_zero ( ) &&
501+ frame_system:: Pallet :: < T > :: providers ( who) == 1
502+ // ..or we don't care about the account dying but our provider ref is required..
503+ || preservation == Expendable && !a. free . is_zero ( ) &&
504+ !frame_system:: Pallet :: < T > :: can_dec_provider ( who)
505+ {
506+ // ..then the ED needed..
507+ untouchable = untouchable. max ( T :: ExistentialDeposit :: get ( ) ) ;
508+ }
509+ a. free . saturating_sub ( untouchable)
510+ }
490511}
491512
492513impl < T : Config < I > , I : ' static > ReservableCurrency < T :: AccountId > for Pallet < T , I >
0 commit comments