|
@@ -177,6 +177,9 @@ pub static MSG_FULL_CURATOR_OPENING_UNSUCCESSFUL_ROLE_STAKE_UNSTAKING_PERIOD_RED
|
|
|
"Role stake unstaking period for failed applicants redundant";
|
|
|
pub static MSG_FULL_CURATOR_OPENING_APPLICATION_DOES_NOT_EXIST: &str = "ApplicationDoesNotExist";
|
|
|
pub static MSG_FULL_CURATOR_OPENING_APPLICATION_NOT_ACTIVE: &str = "ApplicationNotInActiveStage";
|
|
|
+pub static MSG_FILL_CURATOR_OPENING_INVALID_NEXT_PAYMENT_BLOCK: &str =
|
|
|
+ "Reward policy has invalid next payment block number";
|
|
|
+pub static MSG_FILL_CURATOR_OPENING_MINT_DOES_NOT_EXIST: &str = "Working group mint does not exist";
|
|
|
|
|
|
// Errors for `withdraw_curator_application`
|
|
|
pub static MSG_WITHDRAW_CURATOR_APPLICATION_APPLICATION_DOES_NOT_EXIST: &str =
|
|
@@ -975,6 +978,14 @@ impl rstd::convert::From<WrappedError<members::MemberControllerAccountDidNotSign
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// The recurring reward if any to be assigned to an actor when filling in the position.
|
|
|
+#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)]
|
|
|
+pub struct RewardPolicy<Balance, BlockNumber> {
|
|
|
+ amount_per_payout: Balance,
|
|
|
+ next_payment_at_block: BlockNumber,
|
|
|
+ payout_interval: Option<BlockNumber>,
|
|
|
+}
|
|
|
+
|
|
|
// ======================================================================== //
|
|
|
// Move section above, this out in its own file later //
|
|
|
// ======================================================================== //
|
|
@@ -1427,6 +1438,7 @@ decl_module! {
|
|
|
origin,
|
|
|
curator_opening_id: CuratorOpeningId<T>,
|
|
|
successful_curator_application_ids: CuratorApplicationIdSet<T>,
|
|
|
+ reward_policy: Option<RewardPolicy<minting::BalanceOf<T>, T::BlockNumber>>
|
|
|
) {
|
|
|
// Ensure lead is set and is origin signer
|
|
|
let (lead_id, _lead) = Self::ensure_origin_is_set_lead(origin)?;
|
|
@@ -1485,6 +1497,21 @@ decl_module! {
|
|
|
)
|
|
|
)?;
|
|
|
|
|
|
+ let create_reward_settings = if let Some(policy) = reward_policy {
|
|
|
+ // A reward will need to be created so ensure our configured mint exists
|
|
|
+ let mint_id = Self::mint();
|
|
|
+
|
|
|
+ ensure!(<minting::Mints<T>>::exists(mint_id), MSG_FILL_CURATOR_OPENING_MINT_DOES_NOT_EXIST);
|
|
|
+
|
|
|
+ // Make sure valid parameters are selected for next payment at block number
|
|
|
+ ensure!(policy.next_payment_at_block > <system::Module<T>>::block_number(), MSG_FILL_CURATOR_OPENING_INVALID_NEXT_PAYMENT_BLOCK);
|
|
|
+
|
|
|
+ // The verified reward settings to use
|
|
|
+ Some((mint_id, policy))
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ };
|
|
|
+
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
|
//
|
|
@@ -1501,8 +1528,32 @@ decl_module! {
|
|
|
.clone()
|
|
|
.for_each(|(successful_curator_application, id, _)| {
|
|
|
|
|
|
- // No reward is established by default
|
|
|
- let reward_relationship: Option<RewardRelationshipId<T>> = None;
|
|
|
+ // Create a reward relationship
|
|
|
+ let reward_relationship = if let Some((mint_id, checked_policy)) = create_reward_settings.clone() {
|
|
|
+
|
|
|
+ // Create a new recipient for the new relationship
|
|
|
+ let recipient = <recurringrewards::Module<T>>::add_recipient();
|
|
|
+
|
|
|
+ // member must exist, since it was checked that it can enter the role
|
|
|
+ let member_profile = <members::Module<T>>::member_profile(successful_curator_application.member_id).unwrap();
|
|
|
+
|
|
|
+ // rewards are deposited in the member's root account
|
|
|
+ let reward_destination_account = member_profile.root_account;
|
|
|
+
|
|
|
+ // values have been checked so this should not fail!
|
|
|
+ let relationship_id = <recurringrewards::Module<T>>::add_reward_relationship(
|
|
|
+ mint_id,
|
|
|
+ recipient,
|
|
|
+ reward_destination_account,
|
|
|
+ checked_policy.amount_per_payout,
|
|
|
+ checked_policy.next_payment_at_block,
|
|
|
+ checked_policy.payout_interval,
|
|
|
+ ).expect("Failed to create reward relationship!");
|
|
|
+
|
|
|
+ Some(relationship_id)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ };
|
|
|
|
|
|
// Get possible stake for role
|
|
|
let application = hiring::ApplicationById::<T>::get(successful_curator_application.application_id);
|