@@ -66,7 +66,7 @@ use sp_std::{cmp, convert::Infallible, marker, prelude::*, vec::Vec};
66
66
67
67
use orml_traits:: {
68
68
arithmetic:: { self , Signed } ,
69
- currency:: TransferAll ,
69
+ currency:: { OnDeposit , OnSlash , OnTransfer , TransferAll } ,
70
70
BalanceStatus , GetByKey , Happened , LockIdentifier , MultiCurrency , MultiCurrencyExtended , MultiLockableCurrency ,
71
71
MultiReservableCurrency , NamedMultiReservableCurrency , OnDust ,
72
72
} ;
@@ -173,6 +173,8 @@ pub use module::*;
173
173
174
174
#[ frame_support:: pallet]
175
175
pub mod module {
176
+ use orml_traits:: currency:: { OnDeposit , OnSlash , OnTransfer } ;
177
+
176
178
use super :: * ;
177
179
178
180
#[ pallet:: config]
@@ -216,6 +218,15 @@ pub mod module {
216
218
/// Handler to burn or transfer account's dust
217
219
type OnDust : OnDust < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
218
220
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
+
219
230
/// Handler for when an account was created
220
231
type OnNewTokenAccount : Happened < ( Self :: AccountId , Self :: CurrencyId ) > ;
221
232
@@ -894,6 +905,7 @@ impl<T: Config> Pallet<T> {
894
905
return Ok ( ( ) ) ;
895
906
}
896
907
908
+ T :: OnTransfer :: on_transfer ( currency_id, from, to, amount) ?;
897
909
Self :: try_mutate_account ( to, currency_id, |to_account, _existed| -> DispatchResult {
898
910
Self :: try_mutate_account ( from, currency_id, |from_account, _existed| -> DispatchResult {
899
911
from_account. free = from_account
@@ -1019,6 +1031,7 @@ impl<T: Config> Pallet<T> {
1019
1031
return Ok ( ( ) ) ;
1020
1032
}
1021
1033
1034
+ T :: OnDeposit :: on_deposit ( currency_id, who, amount) ?;
1022
1035
Self :: try_mutate_account ( who, currency_id, |account, existed| -> DispatchResult {
1023
1036
if require_existed {
1024
1037
ensure ! ( existed, Error :: <T >:: DeadAccount ) ;
@@ -1114,6 +1127,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
1114
1127
return amount;
1115
1128
}
1116
1129
1130
+ T :: OnSlash :: on_slash ( currency_id, who, amount) ;
1117
1131
let account = Self :: accounts ( who, currency_id) ;
1118
1132
let free_slashed_amount = account. free . min ( amount) ;
1119
1133
// 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> {
1280
1294
return value;
1281
1295
}
1282
1296
1297
+ T :: OnSlash :: on_slash ( currency_id, who, value) ;
1283
1298
let reserved_balance = Self :: reserved_balance ( currency_id, who) ;
1284
1299
let actual = reserved_balance. min ( value) ;
1285
1300
Self :: mutate_account ( who, currency_id, |account, _| {
0 commit comments