@@ -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
@@ -890,6 +901,7 @@ impl<T: Config> Pallet<T> {
890901 amount : T :: Balance ,
891902 existence_requirement : ExistenceRequirement ,
892903 ) -> DispatchResult {
904+ T :: OnTransfer :: on_transfer ( currency_id, from, to, amount) ?;
893905 if amount. is_zero ( ) || from == to {
894906 return Ok ( ( ) ) ;
895907 }
@@ -1015,6 +1027,7 @@ impl<T: Config> Pallet<T> {
10151027 require_existed : bool ,
10161028 change_total_issuance : bool ,
10171029 ) -> DispatchResult {
1030+ T :: OnDeposit :: on_deposit ( currency_id, who, amount) ?;
10181031 if amount. is_zero ( ) {
10191032 return Ok ( ( ) ) ;
10201033 }
@@ -1110,6 +1123,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
11101123 /// reserved funds, however we err on the side of punishment if things
11111124 /// are inconsistent or `can_slash` wasn't used appropriately.
11121125 fn slash ( currency_id : Self :: CurrencyId , who : & T :: AccountId , amount : Self :: Balance ) -> Self :: Balance {
1126+ T :: OnSlash :: on_slash ( currency_id, who, amount) ;
11131127 if amount. is_zero ( ) {
11141128 return amount;
11151129 }
@@ -1276,6 +1290,7 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
12761290 ///
12771291 /// Is a no-op if the value to be slashed is zero.
12781292 fn slash_reserved ( currency_id : Self :: CurrencyId , who : & T :: AccountId , value : Self :: Balance ) -> Self :: Balance {
1293+ T :: OnSlash :: on_slash ( currency_id, who, value) ;
12791294 if value. is_zero ( ) {
12801295 return value;
12811296 }
0 commit comments