From 34c21b806dc10f6ee3a82bc6c231ff8ac97b9d50 Mon Sep 17 00:00:00 2001 From: Erwan Date: Tue, 23 Jan 2024 10:04:54 -0500 Subject: [PATCH] staking(funding): adjust reward amount flow --- .../component/governance/src/component/view.rs | 1 - .../core/component/stake/src/funding_stream.rs | 17 +++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/core/component/governance/src/component/view.rs b/crates/core/component/governance/src/component/view.rs index 3b3cf72873..c571f7569c 100644 --- a/crates/core/component/governance/src/component/view.rs +++ b/crates/core/component/governance/src/component/view.rs @@ -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 {}", diff --git a/crates/core/component/stake/src/funding_stream.rs b/crates/core/component/stake/src/funding_stream.rs index 9347bdb7e2..423dbfd3b1 100644 --- a/crates/core/component/stake/src/funding_stream.rs +++ b/crates/core/component/stake/src/funding_stream.rs @@ -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")