From e02c2fd3885afc43f9ae4eef962e4741d42ba18b Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Mon, 22 Jul 2024 14:10:54 -0400 Subject: [PATCH] replaced todo with descriptive error --- contracts/distribution/dao-rewards-distributor/src/error.rs | 3 +++ contracts/distribution/dao-rewards-distributor/src/state.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/distribution/dao-rewards-distributor/src/error.rs b/contracts/distribution/dao-rewards-distributor/src/error.rs index d3b9fadb4..209eb7752 100644 --- a/contracts/distribution/dao-rewards-distributor/src/error.rs +++ b/contracts/distribution/dao-rewards-distributor/src/error.rs @@ -51,4 +51,7 @@ pub enum ContractError { #[error("There is no voting power registered, so no one will receive these funds")] NoVotingPowerNoRewards {}, + + #[error("Cannot update emission rate because this distribution has accumulated the maximum rewards. Start a new distribution with the new emission rate instead.")] + DistributionHistoryTooLarge {}, } diff --git a/contracts/distribution/dao-rewards-distributor/src/state.rs b/contracts/distribution/dao-rewards-distributor/src/state.rs index 1ae2f27e3..1ac69d481 100644 --- a/contracts/distribution/dao-rewards-distributor/src/state.rs +++ b/contracts/distribution/dao-rewards-distributor/src/state.rs @@ -273,10 +273,10 @@ impl DistributionState { }; // 2. add current epoch rewards earned to historical rewards - // TODO: what to do on overflow? self.historical_earned_puvp = self .historical_earned_puvp - .checked_add(self.active_epoch.total_earned_puvp)?; + .checked_add(self.active_epoch.total_earned_puvp) + .map_err(|_| ContractError::DistributionHistoryTooLarge {})?; // 3. deduct the distributed rewards amount from total funded amount, as // those rewards are no longer distributed in the new epoch