diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index e03cb80fe..972ddbbd7 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -227,6 +227,7 @@ pub trait Farm: } let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); let boosted_rewards = self.claim_only_boosted_payment(user); @@ -265,6 +266,7 @@ pub trait Farm: require!(percentage <= MAX_PERCENT, "Invalid percentage"); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.boosted_yields_rewards_percentage().set(percentage); diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index d6455a2b7..dad01984e 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -192,6 +192,13 @@ pub trait BaseFunctionsModule: FC::check_and_update_user_farm_position(self, orig_caller, &payments); + let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + + FC::generate_aggregated_rewards(self, &mut storage_cache); + + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + self.merge_from_payments_and_burn(payments, &token_mapper) } diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 211b05e02..aeabcaaa0 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -229,6 +229,7 @@ pub trait Farm: } let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); let boosted_rewards = self.claim_only_boosted_payment(user); @@ -266,6 +267,7 @@ pub trait Farm: require!(percentage <= MAX_PERCENT, "Invalid percentage"); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.boosted_yields_rewards_percentage().set(percentage); diff --git a/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs b/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs index 79d433dfe..4969f3ddb 100644 --- a/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs +++ b/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs @@ -42,6 +42,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: } let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); let boosted_rewards = self.claim_only_boosted_payment(user); diff --git a/farm-staking/farm-staking/src/custom_rewards.rs b/farm-staking/farm-staking/src/custom_rewards.rs index 4d07dd5a4..024b8c5e2 100644 --- a/farm-staking/farm-staking/src/custom_rewards.rs +++ b/farm-staking/farm-staking/src/custom_rewards.rs @@ -51,6 +51,7 @@ pub trait CustomRewardsModule: self.require_caller_has_admin_permissions(); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); let reward_capacity_mapper = self.reward_capacity(); @@ -80,6 +81,7 @@ pub trait CustomRewardsModule: self.require_caller_has_admin_permissions(); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.produce_rewards_enabled().set(false); } @@ -90,6 +92,7 @@ pub trait CustomRewardsModule: require!(per_block_amount != 0, "Amount cannot be zero"); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.per_block_reward_amount().set(&per_block_amount); } @@ -100,6 +103,7 @@ pub trait CustomRewardsModule: require!(max_apr != 0, "Max APR cannot be zero"); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.max_annual_percentage_rewards().set(&max_apr); } diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index f783c7831..9cf4b1228 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -144,6 +144,13 @@ pub trait FarmStaking: FC::check_and_update_user_farm_position(self, orig_caller, &payments); + let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + + FC::generate_aggregated_rewards(self, &mut storage_cache); + + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + self.merge_from_payments_and_burn(payments, &token_mapper) } @@ -153,6 +160,7 @@ pub trait FarmStaking: require!(percentage <= MAX_PERCENT, "Invalid percentage"); let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); self.boosted_yields_rewards_percentage().set(percentage); diff --git a/farm-staking/farm-staking/src/unbond_farm.rs b/farm-staking/farm-staking/src/unbond_farm.rs index 7e85a2a2c..ec2044897 100644 --- a/farm-staking/farm-staking/src/unbond_farm.rs +++ b/farm-staking/farm-staking/src/unbond_farm.rs @@ -1,8 +1,9 @@ multiversx_sc::imports!(); use contexts::storage_cache::StorageCache; +use farm_base_impl::base_traits_impl::FarmContract; -use crate::token_attributes::UnbondSftAttributes; +use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::UnbondSftAttributes}; #[multiversx_sc::module] pub trait UnbondFarmModule: @@ -32,7 +33,7 @@ pub trait UnbondFarmModule: #[payable("*")] #[endpoint(unbondFarm)] fn unbond_farm(&self) -> EsdtTokenPayment { - let storage_cache = StorageCache::new(self); + let mut storage_cache = StorageCache::new(self); self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); let farm_token_mapper = self.farm_token(); @@ -48,6 +49,9 @@ pub trait UnbondFarmModule: "Unbond period not over" ); + FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + farm_token_mapper.nft_burn(payment.token_nonce, &payment.amount); let caller = self.blockchain().get_caller();