From 3d2b098b9120ac9527f1517a95d8bb17d1bd2788 Mon Sep 17 00:00:00 2001 From: Vlad Proshchavaiev <32250097+F3Joule@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:12:35 +0200 Subject: [PATCH] Change rewards calculation for backers --- pallets/creator-staking/src/functions.rs | 5 ++--- pallets/creator-staking/src/lib.rs | 2 +- pallets/creator-staking/src/tests/tests.rs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pallets/creator-staking/src/functions.rs b/pallets/creator-staking/src/functions.rs index b699987c..99c04e12 100644 --- a/pallets/creator-staking/src/functions.rs +++ b/pallets/creator-staking/src/functions.rs @@ -216,9 +216,8 @@ impl Pallet { Perbill::from_rational(creator_info.total_staked, era_info.staked); let creator_reward_share = creator_proportional_stake * era_info.rewards.creators; - let combined_backers_reward_share = creator_proportional_stake * era_info.rewards.backers; - (creator_reward_share, combined_backers_reward_share) + (creator_reward_share, era_info.rewards.backers) } /// This utility function converts the PalletId specified in `Config` into an account ID. @@ -370,7 +369,7 @@ impl Pallet { if let Some(reward_and_stake) = Self::general_era_info(era) { let (_, combined_backers_reward_share) = Self::distributed_rewards_between_creator_and_backers(creator_stake_info, &reward_and_stake); - Perbill::from_rational(staked, creator_stake_info.total_staked) * combined_backers_reward_share + Perbill::from_rational(staked, reward_and_stake.staked) * combined_backers_reward_share } else { Zero::zero() } diff --git a/pallets/creator-staking/src/lib.rs b/pallets/creator-staking/src/lib.rs index 693b13e0..326a46ef 100644 --- a/pallets/creator-staking/src/lib.rs +++ b/pallets/creator-staking/src/lib.rs @@ -619,7 +619,7 @@ pub mod pallet { let (_, combined_backers_reward_share) = Self::distributed_rewards_between_creator_and_backers(&staking_info, &reward_and_stake); let backer_reward = - Perbill::from_rational(backer_staked, staking_info.total_staked) * combined_backers_reward_share; + Perbill::from_rational(backer_staked, reward_and_stake.staked) * combined_backers_reward_share; // FIXME: we mustn't modify `backer_stakes` here! let can_restake_reward = Self::ensure_can_restake_reward( diff --git a/pallets/creator-staking/src/tests/tests.rs b/pallets/creator-staking/src/tests/tests.rs index 82272eb3..2a954024 100644 --- a/pallets/creator-staking/src/tests/tests.rs +++ b/pallets/creator-staking/src/tests/tests.rs @@ -1750,7 +1750,7 @@ fn distributed_rewards_between_creator_and_backers_util() { CreatorStaking::distributed_rewards_between_creator_and_backers(&staking_points, &era_info); let creator_stake_ratio = Perbill::from_rational(staked_on_creator, total_staked); - let calculated_backers_reward = creator_stake_ratio * base_backers_reward; + let calculated_backers_reward = base_backers_reward; let calculated_dev_reward = creator_stake_ratio * base_creators_reward; assert_eq!(calculated_dev_reward, creator_reward_share); assert_eq!(calculated_backers_reward, combined_backers_reward_share);