@@ -8,7 +8,7 @@ use codec::{FullCodec, HasCompact};
8
8
use frame_support:: { pallet_prelude:: * , traits:: MaxEncodedLen } ;
9
9
use orml_traits:: RewardHandler ;
10
10
use sp_runtime:: {
11
- traits:: { AtLeast32BitUnsigned , MaybeSerializeDeserialize , Member , Saturating , Zero } ,
11
+ traits:: { AtLeast32BitUnsigned , Bounded , MaybeSerializeDeserialize , Member , Saturating , Zero } ,
12
12
FixedPointNumber , FixedPointOperand , FixedU128 , RuntimeDebug ,
13
13
} ;
14
14
use sp_std:: {
@@ -102,8 +102,13 @@ impl<T: Config> Pallet<T> {
102
102
}
103
103
104
104
Pools :: < T > :: mutate ( pool, |pool_info| {
105
- let proportion = FixedU128 :: checked_from_rational ( add_amount, pool_info. total_shares ) . unwrap_or_default ( ) ;
106
- let reward_inflation = proportion. saturating_mul_int ( pool_info. total_rewards ) ;
105
+ let reward_inflation = if pool_info. total_shares . is_zero ( ) {
106
+ Zero :: zero ( )
107
+ } else {
108
+ let proportion = FixedU128 :: checked_from_rational ( add_amount, pool_info. total_shares )
109
+ . unwrap_or_else ( FixedU128 :: max_value) ;
110
+ proportion. saturating_mul_int ( pool_info. total_rewards )
111
+ } ;
107
112
108
113
pool_info. total_shares = pool_info. total_shares . saturating_add ( add_amount) ;
109
114
pool_info. total_rewards = pool_info. total_rewards . saturating_add ( reward_inflation) ;
@@ -132,7 +137,8 @@ impl<T: Config> Pallet<T> {
132
137
}
133
138
134
139
Pools :: < T > :: mutate ( pool, |pool_info| {
135
- let proportion = FixedU128 :: checked_from_rational ( remove_amount, * share) . unwrap_or_default ( ) ;
140
+ let proportion = FixedU128 :: checked_from_rational ( remove_amount, * share)
141
+ . expect ( "share is gte remove_amount and not zero which checked before; qed" ) ;
136
142
let withdrawn_rewards_to_remove = proportion. saturating_mul_int ( * withdrawn_rewards) ;
137
143
138
144
pool_info. total_shares = pool_info. total_shares . saturating_sub ( remove_amount) ;
0 commit comments