Skip to content

Commit

Permalink
staking(funding): adjust reward amount flow
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Jan 23, 2024
1 parent 755610d commit 34c21b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion crates/core/component/governance/src/component/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {
};

// Check that the unbonded amount is correct relative to that exchange rate
// TODO(erwan): fix impl
if rate_data.unbonded_amount(value.amount).value() != unbonded_amount.value() {
anyhow::bail!(
"unbonded amount {}{} does not correspond to {} staked delegation tokens for validator {} using the exchange rate at the start of proposal {}",
Expand Down
17 changes: 9 additions & 8 deletions crates/core/component/stake/src/funding_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,20 @@ impl FundingStream {
let prev_base_reward_rate =
(prev_base_reward_rate / *FP_SCALING_FACTOR).expect("nonzero divisor");

// We compute the net rate after commission:
let previous_net_rate =
(commission_rate * prev_base_exchange_rate).expect("does not overflow");
// Then, we compute the cumulative depreciation for this pool:
let staking_tokens = (total_delegation_tokens * prev_base_exchange_rate)
.expect("exchange rate is between 0 and 1");

// We compute the amount of staking tokens in the pool:
let staking_tokens =
(total_delegation_tokens * previous_net_rate).expect("does not overflow");
// Now, we can compute the total reward amount for this pool:
let total_reward_amount =
(staking_tokens * prev_base_reward_rate).expect("does not overflow");

/* ********** Compute the reward amount for this funding stream ************* */
let reward_amount = (staking_tokens * prev_base_reward_rate).expect("does not overflow");
let stream_reward_amount =
(total_reward_amount * commission_rate).expect("commission rate is between 0 and 1");
/* ************************************************************************** */

reward_amount
stream_reward_amount
.round_down()
.try_into()
.expect("does not overflow")
Expand Down

0 comments on commit 34c21b8

Please sign in to comment.