diff --git a/pallets/fusion/src/lib.rs b/pallets/fusion/src/lib.rs index 2493c1794..a9c0274cc 100644 --- a/pallets/fusion/src/lib.rs +++ b/pallets/fusion/src/lib.rs @@ -314,7 +314,7 @@ pub mod pallet { }, /// Event triggered when the Evm address and controller address are set for the Slash destination SlashDestinationSet { - evm_address: EvmAddress, + evm_address: Option, controller_address: Option, }, /// Event triggered when the compounding value is changed for a pool member @@ -397,6 +397,12 @@ pub mod pallet { FusionPaused, /// Event triggered when the Fusion pallet is unpaused. FusionUnpaused, + /// A slash was created + SlashCreated { slash: FusionSlash }, + /// A slash was applied + SlashApplied { slash: FusionSlash }, + /// A slash was manually cancelled + SlashCanceled { slash: FusionSlash }, } #[pallet::error] @@ -993,14 +999,20 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::create_currency())] pub fn set_slash_destination( origin: OriginFor, - evm_address: EvmAddress, + evm_address: Option, controller_address: Option, ) -> DispatchResult { ensure_root(origin)?; - SlashDestination::::put(evm_address); - - Self::do_set_controller_address(evm_address, controller_address.clone())?; + if let Some(evm_address) = evm_address { + SlashDestination::::put(evm_address); + Self::do_set_controller_address(evm_address, controller_address.clone())?; + } else { + if let Some(current_address) = SlashDestination::::get() { + Self::do_set_controller_address(current_address, None)?; + } + SlashDestination::::kill(); + } Self::deposit_event(Event::SlashDestinationSet { evm_address, @@ -1061,6 +1073,10 @@ pub mod pallet { Ok(()) })?; + Self::deposit_event(Event::::SlashCanceled { + slash: removed_slash, + }); + Ok(()) }) } @@ -1584,6 +1600,8 @@ impl Pallet { Self::add_to_currency_balance(slash_dest_evm, slash.currency_id, slash.slash_amount)?; } + Self::deposit_event(Event::SlashApplied { slash }); + Ok(()) } @@ -2259,14 +2277,14 @@ impl OnStakingUpdate> for Pallet { slash_amount: slash_fusion_amount, }; - if let Err(e) = Self::add_slash(new_slash) { + if let Err(e) = Self::add_slash(new_slash.clone()) { log::error!("Error while adding slash: {:?}", e); } + + Self::deposit_event(Event::SlashCreated { slash: new_slash }); }); }); } } - // TODO : We need a hook that will check the defer duration in each block and put the slash in treasury account if it's passed - // TODO : We need extrinsics to apply a slash immediately and to cancel a slash } }