Skip to content
Snippets Groups Projects

feat(runtime): create UDs manually with new call universalDividend.claim_uds

Merged Éloïs requested to merge elois-manual-ud into master
All threads resolved!
2 files
+ 42
4
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -213,21 +213,26 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new universal dividend is created
/// [amout, members_count]
/// A new universal dividend is created.
NewUdCreated {
amount: BalanceOf<T>,
index: UdIndex,
monetary_mass: BalanceOf<T>,
members_count: BalanceOf<T>,
},
/// The universal dividend has been re-evaluated
/// [new_ud_amount, monetary_mass, members_count]
/// The universal dividend has been re-evaluated.
UdReevalued {
new_ud_amount: BalanceOf<T>,
monetary_mass: BalanceOf<T>,
members_count: BalanceOf<T>,
},
/// DUs were automatically transferred as part of a member removal.
UdsAutoPaidAtRemoval {
count: UdIndex,
total: BalanceOf<T>,
who: T::AccountId,
},
/// A member claimed his UDs.
UdsClaimed {
count: UdIndex,
total: BalanceOf<T>,
@@ -409,5 +414,24 @@ pub mod pallet {
pub fn init_first_eligible_ud() -> FirstEligibleUd {
CurrentUdIndex::<T>::get().into()
}
pub fn on_removed_member(first_ud_index: UdIndex, who: &T::AccountId) -> Weight {
let current_ud_index = CurrentUdIndex::<T>::get();
if first_ud_index < current_ud_index {
let (uds_count, uds_total) = compute_claim_uds::compute_claim_uds(
current_ud_index,
first_ud_index,
PastReevals::<T>::get().into_iter(),
);
T::Currency::deposit_creating(who, uds_total);
Self::deposit_event(Event::UdsAutoPaidAtRemoval {
count: uds_count,
total: uds_total,
who: who.clone(),
});
T::DbWeight::get().reads_writes(2, 1)
} else {
T::DbWeight::get().reads(1)
}
}
}
}
Loading