@@ -66,7 +66,7 @@ use sp_std::{cmp, convert::Infallible, marker, prelude::*, vec::Vec};
6666
6767use orml_traits:: {
6868 arithmetic:: { self , Signed } ,
69- currency:: TransferAll ,
69+ currency:: { OnDeposit , OnSlash , OnTransfer , TransferAll } ,
7070 BalanceStatus , GetByKey , Happened , LockIdentifier , MultiCurrency , MultiCurrencyExtended , MultiLockableCurrency ,
7171 MultiReservableCurrency , NamedMultiReservableCurrency , OnDust ,
7272} ;
@@ -173,6 +173,8 @@ pub use module::*;
173173
174174#[ frame_support:: pallet]
175175pub mod module {
176+ use orml_traits:: currency:: { OnDeposit , OnSlash , OnTransfer } ;
177+
176178 use super :: * ;
177179
178180 #[ pallet:: config]
@@ -216,6 +218,15 @@ pub mod module {
216218 /// Handler to burn or transfer account's dust
217219 type OnDust : OnDust < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
218220
221+ /// Hook to run before slashing an account.
222+ type OnSlash : OnSlash < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
223+
224+ /// Hook to run before depositing into an account.
225+ type OnDeposit : OnDeposit < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
226+
227+ /// Hook to run before transferring from an account to another.
228+ type OnTransfer : OnTransfer < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
229+
219230 /// Handler for when an account was created
220231 type OnNewTokenAccount : Happened < ( Self :: AccountId , Self :: CurrencyId ) > ;
221232
@@ -894,6 +905,7 @@ impl<T: Config> Pallet<T> {
894905 return Ok ( ( ) ) ;
895906 }
896907
908+ T :: OnTransfer :: on_transfer ( currency_id, from, to, amount) ?;
897909 Self :: try_mutate_account ( to, currency_id, |to_account, _existed| -> DispatchResult {
898910 Self :: try_mutate_account ( from, currency_id, |from_account, _existed| -> DispatchResult {
899911 from_account. free = from_account
@@ -1019,6 +1031,7 @@ impl<T: Config> Pallet<T> {
10191031 return Ok ( ( ) ) ;
10201032 }
10211033
1034+ T :: OnDeposit :: on_deposit ( currency_id, who, amount) ?;
10221035 Self :: try_mutate_account ( who, currency_id, |account, existed| -> DispatchResult {
10231036 if require_existed {
10241037 ensure ! ( existed, Error :: <T >:: DeadAccount ) ;
@@ -1114,6 +1127,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
11141127 return amount;
11151128 }
11161129
1130+ T :: OnSlash :: on_slash ( currency_id, who, amount) ;
11171131 let account = Self :: accounts ( who, currency_id) ;
11181132 let free_slashed_amount = account. free . min ( amount) ;
11191133 // Cannot underflow because free_slashed_amount can never be greater than amount
@@ -1280,6 +1294,7 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
12801294 return value;
12811295 }
12821296
1297+ T :: OnSlash :: on_slash ( currency_id, who, value) ;
12831298 let reserved_balance = Self :: reserved_balance ( currency_id, who) ;
12841299 let actual = reserved_balance. min ( value) ;
12851300 Self :: mutate_account ( who, currency_id, |account, _| {
0 commit comments