Skip to content

Commit ba98831

Browse files
committed
wip
1 parent d299cee commit ba98831

File tree

1 file changed

+26
-46
lines changed
  • pallets/mining/rewards-allowance/src

1 file changed

+26
-46
lines changed

pallets/mining/rewards-allowance/src/lib.rs

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ pub mod pallet {
198198

199199
#[pallet::storage]
200200
#[pallet::getter(fn min_bonded_dhx_daily)]
201-
pub(super) type MinBondedDHXDaily<T: Config> = StorageValue<_, BalanceOf<T>>;
201+
pub(super) type MinBondedDHXDaily<T: Config> = StorageValue<_, u128>;
202202

203203
#[pallet::storage]
204204
#[pallet::getter(fn min_bonded_dhx_daily_default)]
205-
pub(super) type MinBondedDHXDailyDefault<T: Config> = StorageValue<_, BalanceOf<T>>;
205+
pub(super) type MinBondedDHXDailyDefault<T: Config> = StorageValue<_, u128>;
206206

207207
#[pallet::storage]
208208
#[pallet::getter(fn cooling_off_period_days)]
@@ -246,8 +246,8 @@ pub mod pallet {
246246
pub rewards_aggregated_dhx_for_all_miners_for_date: Vec<(Date, BalanceOf<T>)>,
247247
pub rewards_accumulated_dhx_for_miner_for_date: Vec<((Date, T::AccountId), BalanceOf<T>)>,
248248
pub registered_dhx_miners: Vec<T::AccountId>,
249-
pub min_bonded_dhx_daily: BalanceOf<T>,
250-
pub min_bonded_dhx_daily_default: BalanceOf<T>,
249+
pub min_bonded_dhx_daily: u128,
250+
pub min_bonded_dhx_daily_default: u128,
251251
pub cooling_off_period_days: u32,
252252
pub cooling_off_period_days_remaining: Vec<(T::AccountId, (Date, u32, u32))>,
253253
}
@@ -356,7 +356,7 @@ pub mod pallet {
356356
/// Storage of the default minimum DHX that must be bonded by each registered DHX miner each day
357357
/// to be eligible for rewards
358358
/// \[amount_dhx, sender\]
359-
SetMinBondedDHXDailyStored(u128, T::AccountId),
359+
SetMinBondedDHXDailyStored(BalanceOf<T>, T::AccountId),
360360

361361
/// Storage of the default cooling off period in days
362362
/// \[cooling_off_period_days\]
@@ -533,7 +533,7 @@ pub mod pallet {
533533
log::info!("Unable to get rm_current_ratio");
534534
}
535535

536-
let mut min_bonded_dhx_daily_default: BalanceOf<T>= 10u32.into();
536+
let mut min_bonded_dhx_daily_default: u128 = 10_000_000_000_000_000_000_u128; // 10 DHX
537537
if let Some(_min_bonded_dhx_daily_default) = <MinBondedDHXDailyDefault<T>>::get() {
538538
min_bonded_dhx_daily_default = _min_bonded_dhx_daily_default;
539539
} else {
@@ -641,23 +641,13 @@ pub mod pallet {
641641
// multiply the next ratio by the current min bonded dhx daily to determine the
642642
// new min. bonded dhx daily for the next period
643643

644-
// TODO - refactor to use `convert_balance_to_u128` instead of all the following
645-
let min_bonded_dhx_daily;
646-
if let Some(_min_bonded_dhx_daily) = <MinBondedDHXDaily<T>>::get() {
647-
min_bonded_dhx_daily = _min_bonded_dhx_daily;
648-
} else {
649-
log::error!("Unable to retrieve any min. bonded DHX daily");
650-
return 0;
651-
}
652-
653-
let min_bonded_dhx_daily_u128;
654-
if let Some(_min_bonded_dhx_daily_u128) = TryInto::<u128>::try_into(min_bonded_dhx_daily).ok() {
644+
let mut min_bonded_dhx_daily_u128 = 10_000_000_000_000_000_000_u128;
645+
if let Some(_min_bonded_dhx_daily_u128) = <MinBondedDHXDaily<T>>::get() {
655646
min_bonded_dhx_daily_u128 = _min_bonded_dhx_daily_u128;
656647
} else {
657-
log::error!("Unable to convert BalanceOf to u128 for min_bonded_dhx_daily");
648+
log::error!("Unable to retrieve any min. bonded DHX daily");
658649
return 0;
659650
}
660-
log::info!("min_bonded_dhx_daily_u128: {:?}", min_bonded_dhx_daily_u128.clone());
661651

662652
let rewards_multipler_operation;
663653
if let Some(_rewards_multipler_operation) = <RewardsMultiplierOperation<T>>::get() {
@@ -711,27 +701,28 @@ pub mod pallet {
711701
// round down the fixed point number to the nearest integer of type u128
712702
let new_min_bonded_dhx_daily_as_u128: u128 = new_min_bonded_dhx_daily_as_fixed128.floor().to_num::<u128>();
713703

714-
let new_min_bonded_dhx_daily_as_balance;
715-
let _new_min_bonded_dhx_daily_as_balance = Self::convert_u128_to_balance(new_min_bonded_dhx_daily_as_u128.clone());
716-
match _new_min_bonded_dhx_daily_as_balance {
704+
<MinBondedDHXDaily<T>>::put(new_min_bonded_dhx_daily_as_u128.clone());
705+
log::info!("New MinBondedDHXDaily {:?} {:?}", start_of_requested_date_millis.clone(), new_min_bonded_dhx_daily_as_u128.clone());
706+
707+
// FIXME - can we automatically change the next period days value to (~90 days depending on days in included months 28, 29, 30, or 31)
708+
// depending on the date? and do this from genesis too?
709+
710+
let new_min_bonded_dhx_daily;
711+
let _new_min_bonded_dhx_daily = Self::convert_u128_to_balance(new_min_bonded_dhx_daily_as_u128.clone());
712+
match _new_min_bonded_dhx_daily {
717713
Err(_e) => {
718714
log::error!("Unable to convert u128 to balance for new_min_bonded_dhx_daily");
719715
return 0;
720716
},
721717
Ok(ref x) => {
722-
new_min_bonded_dhx_daily_as_balance = x;
718+
new_min_bonded_dhx_daily = x;
723719
}
724720
}
725-
726-
<MinBondedDHXDaily<T>>::put(new_min_bonded_dhx_daily_as_balance.clone());
727-
log::info!("New MinBondedDHXDaily {:?} {:?}", start_of_requested_date_millis.clone(), new_min_bonded_dhx_daily_as_u128.clone());
728-
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)
730-
// depending on the date? and do this from genesis too?
721+
log::info!("new_min_bonded_dhx_daily: {:?}", new_min_bonded_dhx_daily.clone());
731722

732723
Self::deposit_event(Event::ChangedMinBondedDHXDailyUsingNewRewardsMultiplier(
733724
start_of_requested_date_millis.clone(),
734-
new_min_bonded_dhx_daily_as_balance.clone(),
725+
new_min_bonded_dhx_daily.clone(),
735726
rm_next_ratio.clone(),
736727
rewards_multipler_operation.clone(),
737728
rm_next_period_days.clone(),
@@ -858,24 +849,13 @@ pub mod pallet {
858849
}
859850
log::info!("set_bonded_dhx_of_account_for_date: {:?} {:?}", start_of_requested_date_millis.clone(), bonded_dhx_current_u128.clone());
860851

861-
// TODO - refactor to use `convert_balance_to_u128` instead of all the following
862-
let min_bonded_dhx_daily;
863-
let min_bonded_dhx_daily_to_try = <MinBondedDHXDaily<T>>::get();
864-
if let Some(_min_bonded_dhx_daily_to_try) = min_bonded_dhx_daily_to_try {
865-
min_bonded_dhx_daily = _min_bonded_dhx_daily_to_try;
866-
} else {
867-
log::error!("Unable to retrieve any min. bonded DHX daily");
868-
return 0;
869-
}
870-
871-
let min_bonded_dhx_daily_u128;
872-
if let Some(_min_bonded_dhx_daily_u128) = TryInto::<u128>::try_into(min_bonded_dhx_daily).ok() {
852+
let mut min_bonded_dhx_daily_u128 = 10_000_000_000_000_000_000_u128;
853+
if let Some(_min_bonded_dhx_daily_u128) = <MinBondedDHXDaily<T>>::get() {
873854
min_bonded_dhx_daily_u128 = _min_bonded_dhx_daily_u128;
874855
} else {
875-
log::error!("Unable to convert BalanceOf to u128 for min_bonded_dhx_daily");
856+
log::error!("Unable to retrieve any min. bonded DHX daily");
876857
return 0;
877858
}
878-
log::info!("min_bonded_dhx_daily_u128: {:?}", min_bonded_dhx_daily_u128.clone());
879859

880860
let mut is_bonding_min_dhx = false;
881861
if locks_first_amount_as_u128 >= min_bonded_dhx_daily_u128 {
@@ -1638,11 +1618,11 @@ pub mod pallet {
16381618

16391619
let min_bonded_dhx_daily_as_u128 = Self::convert_balance_to_u128(min_bonded_dhx_daily.clone())?;
16401620

1641-
<MinBondedDHXDaily<T>>::put(&min_bonded_dhx_daily.clone());
1621+
<MinBondedDHXDaily<T>>::put(&min_bonded_dhx_daily_as_u128.clone());
16421622
log::info!("set_min_bonded_dhx_daily: {:?}", &min_bonded_dhx_daily_as_u128);
16431623

16441624
Self::deposit_event(Event::SetMinBondedDHXDailyStored(
1645-
min_bonded_dhx_daily_as_u128.clone(),
1625+
min_bonded_dhx_daily.clone(),
16461626
_sender.clone(),
16471627
));
16481628

0 commit comments

Comments
 (0)