@@ -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 ,
@@ -510,6 +510,27 @@ where
510510 )
511511 . unwrap_or_else ( |_| SignedImbalance :: Positive ( Self :: PositiveImbalance :: zero ( ) ) )
512512 }
513+
514+ fn transferrable_balance (
515+ who : & T :: AccountId ,
516+ preservation : Preservation ,
517+ ) -> Self :: Balance {
518+ let a = Self :: account ( who) ;
519+ let mut untouchable = a. frozen ;
520+ // If we want to keep our provider ref..
521+ if preservation == Preserve
522+ // ..or we don't want the account to die and our provider ref is needed for it to live..
523+ || preservation == Protect && !a. free . is_zero ( ) &&
524+ frame_system:: Pallet :: < T > :: providers ( who) == 1
525+ // ..or we don't care about the account dying but our provider ref is required..
526+ || preservation == Expendable && !a. free . is_zero ( ) &&
527+ !frame_system:: Pallet :: < T > :: can_dec_provider ( who)
528+ {
529+ // ..then the ED needed..
530+ untouchable = untouchable. max ( T :: ExistentialDeposit :: get ( ) ) ;
531+ }
532+ a. free . saturating_sub ( untouchable)
533+ }
513534}
514535
515536impl < T : Config < I > , I : ' static > ReservableCurrency < T :: AccountId > for Pallet < T , I >
0 commit comments