Skip to content

Commit

Permalink
Change rewards calculation for backers
Browse files Browse the repository at this point in the history
  • Loading branch information
F3Joule committed Nov 2, 2023
1 parent 3127ddf commit 3d2b098
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pallets/creator-staking/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ impl<T: Config> Pallet<T> {
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.
Expand Down Expand Up @@ -370,7 +369,7 @@ impl<T: Config> Pallet<T> {
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()
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/creator-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pallets/creator-staking/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3d2b098

Please sign in to comment.