@@ -73,7 +73,7 @@ pub enum DistributionControl<T: Config> {
7373/// Accumulate emissions for a specific agent, distributes if control is met.
7474pub ( crate ) fn do_accumulate_emissions < T : Config > (
7575 agent : & T :: AccountId ,
76- stream : & StreamId ,
76+ stream_id : & StreamId ,
7777 imbalance : & mut NegativeImbalanceOf < T > ,
7878) {
7979 let initial_balance = imbalance. peek ( ) ;
@@ -83,7 +83,7 @@ pub(crate) fn do_accumulate_emissions<T: Config>(
8383 return ;
8484 }
8585
86- let streams = AccumulatedStreamAmounts :: < T > :: iter_prefix ( ( agent, stream ) ) ;
86+ let streams = AccumulatedStreamAmounts :: < T > :: iter_prefix ( ( agent, stream_id ) ) ;
8787 for ( permission_id, accumulated) in streams {
8888 let Some ( contract) = Permissions :: < T > :: get ( permission_id) else {
8989 continue ;
@@ -104,7 +104,7 @@ pub(crate) fn do_accumulate_emissions<T: Config>(
104104 continue ;
105105 }
106106
107- let Some ( percentage) = streams. get ( stream ) else {
107+ let Some ( percentage) = streams. get ( stream_id ) else {
108108 continue ;
109109 } ;
110110
@@ -118,9 +118,15 @@ pub(crate) fn do_accumulate_emissions<T: Config>(
118118 . peek ( ) ;
119119
120120 AccumulatedStreamAmounts :: < T > :: set (
121- ( agent, stream , & permission_id) ,
121+ ( agent, stream_id , & permission_id) ,
122122 Some ( accumulated. saturating_add ( delegated_amount) ) ,
123123 ) ;
124+
125+ Pallet :: < T > :: deposit_event ( Event :: AccumulatedEmission {
126+ permission_id,
127+ stream_id : * stream_id,
128+ amount : delegated_amount,
129+ } ) ;
124130 }
125131}
126132
@@ -176,8 +182,10 @@ pub(crate) fn do_auto_distribution<T: Config>(
176182 }
177183}
178184
179- #[ derive( Clone , Copy , Debug ) ]
180- pub ( crate ) enum DistributionReason {
185+ #[ derive(
186+ Encode , Decode , Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , TypeInfo , MaxEncodedLen ,
187+ ) ]
188+ pub enum DistributionReason {
181189 Automatic ,
182190 Manual ,
183191}
@@ -227,7 +235,6 @@ pub(crate) fn do_distribute_emission<T: Config>(
227235 do_distribute_to_targets (
228236 & mut imbalance,
229237 permission_id,
230- contract,
231238 emission_scope,
232239 Some ( stream) ,
233240 total_weight,
@@ -268,7 +275,6 @@ pub(crate) fn do_distribute_emission<T: Config>(
268275 do_distribute_to_targets (
269276 & mut imbalance,
270277 permission_id,
271- contract,
272278 emission_scope,
273279 None ,
274280 total_weight,
@@ -288,7 +294,6 @@ pub(crate) fn do_distribute_emission<T: Config>(
288294fn do_distribute_to_targets < T : Config > (
289295 imbalance : & mut NegativeImbalanceOf < T > ,
290296 permission_id : PermissionId ,
291- contract : & PermissionContract < T > ,
292297 emission_scope : & EmissionScope < T > ,
293298 stream : Option < & StreamId > ,
294299 total_weight : FixedU128 ,
@@ -322,25 +327,13 @@ fn do_distribute_to_targets<T: Config>(
322327 }
323328
324329 T :: Currency :: resolve_creating ( target, imbalance) ;
325- }
326330
327- let amount = initial_balance. saturating_sub ( imbalance. peek ( ) ) ;
328- if !amount. is_zero ( ) {
329- <Pallet < T > >:: deposit_event ( match reason {
330- DistributionReason :: Automatic => Event :: AutoDistributionExecuted {
331- delegator : contract. delegator . clone ( ) ,
332- recipient : contract. recipient . clone ( ) ,
333- permission_id,
334- stream_id : None ,
335- amount,
336- } ,
337- DistributionReason :: Manual => Event :: PermissionExecuted {
338- delegator : contract. delegator . clone ( ) ,
339- recipient : contract. recipient . clone ( ) ,
340- permission_id,
341- stream_id : None ,
342- amount,
343- } ,
331+ Pallet :: < T > :: deposit_event ( Event :: EmissionDistribution {
332+ permission_id,
333+ stream_id : stream. cloned ( ) ,
334+ target : target. clone ( ) ,
335+ amount : target_amount,
336+ reason,
344337 } ) ;
345338 }
346339}
0 commit comments