Skip to content

Commit

Permalink
Merge pull request #362 from Phoenix-Protocol-Group/356-phoam-023-con…
Browse files Browse the repository at this point in the history
…fusing-variable-naming

Stake: renames shares_per_point to points_per_share
  • Loading branch information
ueco-jb authored Jul 15, 2024
2 parents 2e95a8b + 5c572a6 commit 25d1dc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions contracts/stake/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl StakingTrait for Staking {
}

let distribution = Distribution {
shares_per_point: 1u128,
points_per_share: 1u128,
shares_leftover: 0u64,
distributed_total: 0u128,
withdrawable_total: 0u128,
Expand Down Expand Up @@ -321,7 +321,7 @@ impl StakingTrait for Staking {
// Full amount is added here to total withdrawable, as it should not be considered on its own
// on future distributions - even if because of calculation offsets it is not fully
// distributed, the error is handled by leftover.
distribution.shares_per_point += points_per_share;
distribution.points_per_share += points_per_share;
distribution.distributed_total += amount;
distribution.withdrawable_total += amount;

Expand Down Expand Up @@ -506,7 +506,7 @@ impl StakingTrait for Staking {
let curve = get_reward_curve(&env, &distribution_address);
let annualized_payout = calculate_annualized_payout(curve, now);
let apr = annualized_payout
/ (total_stake_power as u128 * distribution.shares_per_point) as i128;
/ (total_stake_power as u128 * distribution.points_per_share) as i128;

aprs.push_back(AnnualizedReward {
asset: distribution_address.clone(),
Expand Down
8 changes: 4 additions & 4 deletions contracts/stake/src/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn get_reward_curve(env: &Env, asset: &Address) -> Option<Curve> {
#[derive(Debug, Default, Clone)]
pub struct Distribution {
/// How many shares is single point worth
pub shares_per_point: u128,
pub points_per_share: u128,
/// Shares which were not fully distributed on previous distributions, and should be redistributed
pub shares_leftover: u64,
/// Total rewards distributed by this contract.
Expand Down Expand Up @@ -92,12 +92,12 @@ pub fn update_rewards(
}
let diff = new_rewards_power - old_rewards_power;
// Apply the points correction with the calculated difference.
let ppw = distribution.shares_per_point;
let ppw = distribution.points_per_share;
apply_points_correction(env, user, asset, diff, ppw);
}

/// Applies points correction for given address.
/// `shares_per_point` is current value from `SHARES_PER_POINT` - not loaded in function, to
/// `points_per_share` is current value from `POINTS_PER_SHARE` - not loaded in function, to
/// avoid multiple queries on bulk updates.
/// `diff` is the points change
fn apply_points_correction(
Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn withdrawable_rewards(
adjustment: &WithdrawAdjustment,
config: &Config,
) -> u128 {
let ppw = distribution.shares_per_point;
let ppw = distribution.points_per_share;

let stakes: i128 = get_stakes(env, owner).total_stake;
// Decimal::one() represents the standart multiplier per token
Expand Down

0 comments on commit 25d1dc1

Please sign in to comment.