@@ -7,23 +7,23 @@ use sp_std::vec::Vec;
77pub struct AverageDistribution ;
88impl < Balance : BalanceT + FixedPointOperand > DistributionStrategy < Balance > for AverageDistribution {
99 fn get_bond_distributions (
10- total_bonded_amounts : Vec < ( DerivativeIndex , Balance ) > ,
10+ bonded_amounts : Vec < ( DerivativeIndex , Balance , Balance ) > ,
1111 input : Balance ,
1212 cap : Balance ,
1313 min_nominator_bond : Balance ,
1414 ) -> Vec < ( DerivativeIndex , Balance ) > {
15- let length = TryInto :: < Balance > :: try_into ( total_bonded_amounts . len ( ) ) . unwrap_or_default ( ) ;
15+ let length = TryInto :: < Balance > :: try_into ( bonded_amounts . len ( ) ) . unwrap_or_default ( ) ;
1616 if length. is_zero ( ) {
1717 return Default :: default ( ) ;
1818 }
1919
2020 let mut distributions: Vec < ( DerivativeIndex , Balance ) > = vec ! [ ] ;
2121 let amount = input. checked_div ( & length) . unwrap_or_default ( ) ;
22- for ( index, bonded ) in total_bonded_amounts . into_iter ( ) {
23- if amount. saturating_add ( bonded ) < min_nominator_bond {
22+ for ( index, active_bonded , total_bonded ) in bonded_amounts . into_iter ( ) {
23+ if amount. saturating_add ( active_bonded ) < min_nominator_bond {
2424 continue ;
2525 }
26- let amount = cap. saturating_sub ( bonded ) . min ( amount) ;
26+ let amount = cap. saturating_sub ( total_bonded ) . min ( amount) ;
2727 if amount. is_zero ( ) {
2828 continue ;
2929 }
@@ -84,29 +84,29 @@ impl<Balance: BalanceT + FixedPointOperand> DistributionStrategy<Balance> for Av
8484pub struct MaxMinDistribution ;
8585impl < Balance : BalanceT + FixedPointOperand > DistributionStrategy < Balance > for MaxMinDistribution {
8686 fn get_bond_distributions (
87- mut total_bonded_amounts : Vec < ( DerivativeIndex , Balance ) > ,
87+ mut bonded_amounts : Vec < ( DerivativeIndex , Balance , Balance ) > ,
8888 input : Balance ,
8989 cap : Balance ,
9090 min_nominator_bond : Balance ,
9191 ) -> Vec < ( DerivativeIndex , Balance ) > {
9292 // ascending sequence
93- total_bonded_amounts . sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) ) ;
93+ bonded_amounts . sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) ) ;
9494
9595 let mut distributions: Vec < ( DerivativeIndex , Balance ) > = vec ! [ ] ;
9696 let mut remain = input;
9797
98- for ( index, bonded ) in total_bonded_amounts . into_iter ( ) {
98+ for ( index, active_bonded , total_bonded ) in bonded_amounts . into_iter ( ) {
9999 if remain. is_zero ( ) {
100100 break ;
101101 }
102- let amount = cap. saturating_sub ( bonded ) . min ( remain) ;
102+ let amount = cap. saturating_sub ( total_bonded ) . min ( remain) ;
103103 if amount. is_zero ( ) {
104104 // `bonding_amounts` is an ascending sequence
105105 // if occurs an item that exceed the cap, the items after this one must all be exceeded
106106 break ;
107107 }
108108
109- if amount. saturating_add ( bonded ) < min_nominator_bond {
109+ if amount. saturating_add ( active_bonded ) < min_nominator_bond {
110110 continue ;
111111 }
112112
0 commit comments