@@ -166,24 +166,11 @@ pub mod pallet {
166166 ) ,
167167 > ;
168168
169- // after the interval_multiplier period, we change the `min_bonded_dhx_daily_u128` using either
170- // interval_multiplier_current (i.e. 2x current `min_bonded_dhx_daily_u128`) by default or override that
171- // if we have set a value for the next value to schedule if we want a fixed value `next_min_bonded_dhx_daily_u128`
172- // instead of a multiplier.
173- // i.e. 10:1 initially then if multi_curr is 2, then after say 5 days it changes to min_bonded 20 (i.e. 20:1)
174- // i.e. 10:1 initially then if multi_curr is 0.5 then after say 5 days it changes to min_bonded 5 (i.e. 5:1)
175- // i.e. 10:1 initially then if multi_curr is whatever, but next_min_bonded is 14 then that overrides after say 5 days it changes to min_bonded 14 (i.e. 14:1),
176- // which is a specific ratio (to get the same using multi_curr, we'd need ratio of 1.5)
177- // (lets skip this setting a specific value option)
178- // after each interval_multiplier_days.
179- // where all those values may be change by governance
180-
181- // #[pallet::storage]
182- // #[pallet::getter(fn rewards_multiplier_interval_days)]
183- // pub(super) type RewardsAllowanceDHXForDate<T: Config> = StorageMap<_, Blake2_128Concat,
184- // Date,
185- // BalanceOf<T>
186- // >;
169+ // set to 1 for addition, or 2 for multiplication by the stored value to change the
170+ // min. bonded dhx value after every rewards_multiplier_next_period_days.
171+ #[ pallet:: storage]
172+ #[ pallet:: getter( fn rewards_multiplier_operation) ]
173+ pub ( super ) type RewardsMultiplierOperation < T : Config > = StorageValue < _ , u8 > ;
187174
188175 #[ pallet:: storage]
189176 #[ pallet:: getter( fn rewards_aggregated_dhx_for_all_miners_for_date) ]
@@ -255,6 +242,7 @@ pub mod pallet {
255242 pub rewards_multiplier_current_ratio : u32 ,
256243 pub rewards_multiplier_current_period_days_total : u32 ,
257244 pub rewards_multiplier_current_period_days_remaining : ( Date , Date , u32 , u32 ) ,
245+ pub rewards_multiplier_operation : u8 ,
258246 pub rewards_aggregated_dhx_for_all_miners_for_date : Vec < ( Date , BalanceOf < T > ) > ,
259247 pub rewards_accumulated_dhx_for_miner_for_date : Vec < ( ( Date , T :: AccountId ) , BalanceOf < T > ) > ,
260248 pub registered_dhx_miners : Vec < T :: AccountId > ,
@@ -275,16 +263,17 @@ pub mod pallet {
275263 rewards_allowance_dhx_daily : 5_000_000_000_000_000_000_000u128 ,
276264 rewards_multiplier_paused : false ,
277265 rewards_multiplier_reset : false ,
278- rewards_multiplier_default_ratio : 2u32 ,
279- rewards_multiplier_next_ratio : 2u32 ,
266+ rewards_multiplier_default_ratio : 10u32 ,
267+ rewards_multiplier_next_ratio : 10u32 ,
280268 // FIXME - setup for different amount of days each month and leap years
281- rewards_multiplier_default_period_days : 30u32 ,
269+ rewards_multiplier_default_period_days : 90u32 ,
282270 // FIXME - setup for different amount of days each month and leap years
283- rewards_multiplier_next_period_days : 30u32 ,
284- rewards_multiplier_current_ratio : 2u32 ,
271+ rewards_multiplier_next_period_days : 90u32 ,
272+ rewards_multiplier_current_ratio : 10u32 ,
285273 // FIXME - setup for different amount of days each month and leap years
286- rewards_multiplier_current_period_days_total : 30u32 ,
274+ rewards_multiplier_current_period_days_total : 90u32 ,
287275 rewards_multiplier_current_period_days_remaining : Default :: default ( ) ,
276+ rewards_multiplier_operation : 1u8 ,
288277 rewards_aggregated_dhx_for_all_miners_for_date : Default :: default ( ) ,
289278 rewards_accumulated_dhx_for_miner_for_date : Default :: default ( ) ,
290279 registered_dhx_miners : vec ! [
@@ -333,6 +322,7 @@ pub mod pallet {
333322 for ( a) in & self . registered_dhx_miners {
334323 <RegisteredDHXMiners < T > >:: append ( a) ;
335324 }
325+ <RewardsMultiplierOperation < T > >:: put ( & self . rewards_multiplier_operation ) ;
336326 for ( a, b) in & self . rewards_aggregated_dhx_for_all_miners_for_date {
337327 <RewardsAggregatedDHXForAllMinersForDate < T > >:: insert ( a, b) ;
338328 }
@@ -398,6 +388,10 @@ pub mod pallet {
398388 /// Note: There may be some leftover for the day so we record it here
399389 /// \[date, remaining_rewards_allowance_today\]
400390 DistributedRewardsAllowanceDHXForDate ( Date , BalanceOf < T > ) ,
391+
392+ /// Changed the min. bonded DHX daily using a ratio, using either an addition or multiplication operation
393+ /// \[start_date_period, new_min_dhx_bonded, modified_old_min_dhx_bonded_using_ratio, operation_used, next_period_days\]
394+ ChangedMinBondedDHXDailyUsingNewRewardsMultiplier ( Date , BalanceOf < T > , u32 , u8 , u32 ) ,
401395 }
402396
403397 // Errors inform users that something went wrong should be descriptive and have helpful documentation
@@ -504,35 +498,35 @@ pub mod pallet {
504498 log:: info!( "Unable to get rm_reset" ) ;
505499 }
506500
507- let mut rm_default_ratio = 2u32 ;
501+ let mut rm_default_ratio = 10u32 ;
508502 if let Some ( _rm_default_ratio) = <RewardsMultiplierDefaultRatio < T > >:: get ( ) {
509503 rm_default_ratio = _rm_default_ratio;
510504 } else {
511505 log:: info!( "Unable to get rm_default_ratio" ) ;
512506 }
513507
514- let mut rm_default_period_days = 30u32 ;
508+ let mut rm_default_period_days = 90u32 ;
515509 if let Some ( _rm_default_period_days) = <RewardsMultiplierDefaultPeriodDays < T > >:: get ( ) {
516510 rm_default_period_days = _rm_default_period_days;
517511 } else {
518512 log:: info!( "Unable to get rm_default_period_days" ) ;
519513 }
520514
521- let mut rm_next_ratio = 2u32 ;
515+ let mut rm_next_ratio = 10u32 ;
522516 if let Some ( _rm_next_ratio) = <RewardsMultiplierNextRatio < T > >:: get ( ) {
523517 rm_next_ratio = _rm_next_ratio;
524518 } else {
525519 log:: info!( "Unable to get rm_next_ratio" ) ;
526520 }
527521
528- let mut rm_next_period_days = 30u32 ;
522+ let mut rm_next_period_days = 90u32 ;
529523 if let Some ( _rm_next_period_days) = <RewardsMultiplierNextPeriodDays < T > >:: get ( ) {
530524 rm_next_period_days = _rm_next_period_days;
531525 } else {
532526 log:: info!( "Unable to get rm_next_period_days" ) ;
533527 }
534528
535- let mut rm_current_ratio = 2u32 ;
529+ let mut rm_current_ratio = 10u32 ;
536530 if let Some ( _rm_current_ratio) = <RewardsMultiplierCurrentRatio < T > >:: get ( ) {
537531 rm_current_ratio = _rm_current_ratio;
538532 } else {
@@ -549,8 +543,8 @@ pub mod pallet {
549543 let mut rm_current_period_days_remaining = (
550544 0 . into ( ) ,
551545 0 . into ( ) ,
552- 30u32 ,
553- 30u32 ,
546+ 90u32 ,
547+ 90u32 ,
554548 ) ;
555549 if let Some ( _rm_current_period_days_remaining) = <RewardsMultiplierCurrentPeriodDaysRemaining < T > >:: get ( ) {
556550 rm_current_period_days_remaining = _rm_current_period_days_remaining;
@@ -665,21 +659,53 @@ pub mod pallet {
665659 }
666660 log:: info!( "min_bonded_dhx_daily_u128: {:?}" , min_bonded_dhx_daily_u128. clone( ) ) ;
667661
668- // Multiply, handling overflow
669- let new_min_bonded_dhx_daily_as_fixed128;
670- // use fixed point numbers incase result is a fraction
671- // FIXME - do i have to convert from u32 to u128 for rm_next_ratio for this to work?
672- let _new_min_bonded_dhx_daily_as_fixed128 =
673- U64F64 :: from_num ( min_bonded_dhx_daily_u128. clone ( ) )
674- . checked_mul ( U64F64 :: from_num ( rm_next_ratio. clone ( ) ) ) ;
675- match _new_min_bonded_dhx_daily_as_fixed128 {
676- None => {
677- log:: error!( "Unable to multiply min_bonded_dhx_daily_u128 with rm_next_ratio due to StorageOverflow" ) ;
678- return 0 ;
679- } ,
680- Some ( x) => {
681- new_min_bonded_dhx_daily_as_fixed128 = x;
662+ let rewards_multipler_operation;
663+ if let Some ( _rewards_multipler_operation) = <RewardsMultiplierOperation < T > >:: get ( ) {
664+ rewards_multipler_operation = _rewards_multipler_operation;
665+ } else {
666+ log:: error!( "Unable to retrieve rewards_multipler_operation" ) ;
667+ return 0 ;
668+ }
669+
670+ let mut new_min_bonded_dhx_daily_as_fixed128 = FixedU128 :: from_num ( 10 ) ;
671+
672+ // case of addition
673+ if rewards_multipler_operation == 1u8 {
674+ // Addition, handling overflow
675+
676+ // use fixed point numbers incase result is a fraction
677+ let _new_min_bonded_dhx_daily_as_fixed128 =
678+ U64F64 :: from_num ( min_bonded_dhx_daily_u128. clone ( ) )
679+ . checked_add ( U64F64 :: from_num ( rm_next_ratio. clone ( ) ) ) ;
680+ match _new_min_bonded_dhx_daily_as_fixed128 {
681+ None => {
682+ log:: error!( "Unable to add min_bonded_dhx_daily_u128 with rm_next_ratio due to StorageOverflow" ) ;
683+ return 0 ;
684+ } ,
685+ Some ( x) => {
686+ new_min_bonded_dhx_daily_as_fixed128 = x;
687+ }
682688 }
689+ // case of multiplication
690+ } else if rewards_multipler_operation == 2u8 {
691+ // Multiply, handling overflow
692+
693+ // use fixed point numbers incase result is a fraction
694+ let _new_min_bonded_dhx_daily_as_fixed128 =
695+ U64F64 :: from_num ( min_bonded_dhx_daily_u128. clone ( ) )
696+ . checked_mul ( U64F64 :: from_num ( rm_next_ratio. clone ( ) ) ) ;
697+ match _new_min_bonded_dhx_daily_as_fixed128 {
698+ None => {
699+ log:: error!( "Unable to multiply min_bonded_dhx_daily_u128 with rm_next_ratio due to StorageOverflow" ) ;
700+ return 0 ;
701+ } ,
702+ Some ( x) => {
703+ new_min_bonded_dhx_daily_as_fixed128 = x;
704+ }
705+ }
706+ } else {
707+ log:: error!( "Unsupported rewards_multipler_operation value" ) ;
708+ return 0 ;
683709 }
684710
685711 // round down the fixed point number to the nearest integer of type u128
@@ -700,9 +726,17 @@ pub mod pallet {
700726 <MinBondedDHXDaily < T > >:: put ( new_min_bonded_dhx_daily_as_balance. clone ( ) ) ;
701727 log:: info!( "New MinBondedDHXDaily {:?} {:?}" , start_of_requested_date_millis. clone( ) , new_min_bonded_dhx_daily_as_u128. clone( ) ) ;
702728
703- // FIXME - can we automatically change the next period days value to 28, 29, 30, or 31
729+ // FIXME - can we automatically change the next period days value to (~90 days depending on days in included months 28, 29, 30, or 31)
704730 // depending on the date? and do this from genesis too?
705731
732+ Self :: deposit_event ( Event :: ChangedMinBondedDHXDailyUsingNewRewardsMultiplier (
733+ start_of_requested_date_millis. clone ( ) ,
734+ new_min_bonded_dhx_daily_as_balance. clone ( ) ,
735+ rm_next_ratio. clone ( ) ,
736+ rewards_multipler_operation. clone ( ) ,
737+ rm_next_period_days. clone ( ) ,
738+ ) ) ;
739+
706740 // Set the current ratio (for this next period) to the value that was set as the
707741 // next ratio (perhaps by governance)
708742 <RewardsMultiplierCurrentRatio < T > >:: put ( rm_next_ratio. clone ( ) ) ;
@@ -711,6 +745,8 @@ pub mod pallet {
711745 // next period days (perhaps by governance)
712746 <RewardsMultiplierNextPeriodDays < T > >:: put ( rm_next_period_days. clone ( ) ) ;
713747
748+ <RewardsMultiplierCurrentPeriodDaysTotal < T > >:: put ( rm_next_period_days. clone ( ) ) ;
749+
714750 // Restart the days remaining for the next period
715751 <RewardsMultiplierCurrentPeriodDaysRemaining < T > >:: put (
716752 (
0 commit comments