From 16576f1b0ad91ddfbfb02c9b3a37ea2feecd69eb Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Mon, 18 Sep 2023 14:05:12 +0300 Subject: [PATCH] readded claim progress check --- .github/workflows/actions.yml | 1 - dex/farm-with-locked-rewards/src/lib.rs | 17 ++++-------- dex/farm/src/lib.rs | 13 ++++----- dex/farm/src/progress_update.rs | 27 +++++++++++++++++++ .../tests/farm_setup/multi_user_farm_setup.rs | 4 +-- farm-staking/farm-staking/src/lib.rs | 16 +++-------- 6 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 dex/farm/src/progress_update.rs diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index c5fdba201..f6acbaa50 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -4,7 +4,6 @@ on: push: branches: [ main, feat/* ] pull_request: - branches: [ main, feat/* ] workflow_dispatch: permissions: diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 0205b1fca..30d02d00c 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -11,7 +11,7 @@ use core::marker::PhantomData; use mergeable::Mergeable; use farm::{ - base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, + base_functions::{BaseFunctionsModule, ClaimRewardsResultType, Wrapper}, exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }, @@ -34,6 +34,7 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + farm::base_functions::BaseFunctionsModule + farm::exit_penalty::ExitPenaltyModule + + farm::progress_update::ProgressUpdateModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -199,23 +200,15 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> DoubleMultiPayment { + ) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - - let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + self.check_claim_progress_for_merge(&orig_caller); let merged_farm_token = self.merge_farm_tokens::>(); self.send_payment_non_zero(&caller, &merged_farm_token); - let locked_rewards_payment = self.send_to_lock_contract_non_zero( - self.reward_token_id().get(), - boosted_rewards, - caller, - orig_caller.clone(), - ); - - (merged_farm_token, locked_rewards_payment).into() + merged_farm_token } #[endpoint(claimBoostedRewards)] diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index f7cfbd5f6..77d96d25a 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -7,6 +7,7 @@ multiversx_sc::derive_imports!(); pub mod base_functions; pub mod exit_penalty; +pub mod progress_update; use base_functions::{ClaimRewardsResultType, DoubleMultiPayment, Wrapper}; use common_structs::FarmTokenAttributes; @@ -35,6 +36,7 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + base_functions::BaseFunctionsModule + exit_penalty::ExitPenaltyModule + + progress_update::ProgressUpdateModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -197,20 +199,15 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> DoubleMultiPayment { + ) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - - let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); - let boosted_rewards_full_position = - EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + self.check_claim_progress_for_merge(&orig_caller); let merged_farm_token = self.merge_farm_tokens::>(); - self.send_payment_non_zero(&caller, &merged_farm_token); - self.send_payment_non_zero(&orig_caller, &boosted_rewards_full_position); - (merged_farm_token, boosted_rewards_full_position).into() + merged_farm_token } #[endpoint(claimBoostedRewards)] diff --git a/dex/farm/src/progress_update.rs b/dex/farm/src/progress_update.rs new file mode 100644 index 000000000..48e4b7644 --- /dev/null +++ b/dex/farm/src/progress_update.rs @@ -0,0 +1,27 @@ +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait ProgressUpdateModule: + week_timekeeping::WeekTimekeepingModule + + weekly_rewards_splitting::WeeklyRewardsSplittingModule + + weekly_rewards_splitting::events::WeeklyRewardsSplittingEventsModule + + weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo + + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + + energy_query::EnergyQueryModule + + utils::UtilsModule +{ + fn check_claim_progress_for_merge(&self, caller: &ManagedAddress) { + let claim_progress_mapper = self.current_claim_progress(caller); + if claim_progress_mapper.is_empty() { + return; + } + + let current_week = self.get_current_week(); + let claim_progress = claim_progress_mapper.get(); + require!( + claim_progress.week == current_week, + "The user claim progress must be up to date." + ) + } +} diff --git a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs index f619c64fa..b50f5ecde 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -335,9 +335,7 @@ where self.b_mock .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { - let (out_farm_token, _) = sc - .merge_farm_tokens_endpoint(OptionalValue::None) - .into_tuple(); + let out_farm_token = sc.merge_farm_tokens_endpoint(OptionalValue::None); assert_eq!( out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index e22ae0dfe..c4142784a 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -7,7 +7,6 @@ multiversx_sc::derive_imports!(); use base_impl_wrapper::FarmStakingWrapper; use contexts::storage_cache::StorageCache; -use farm::base_functions::DoubleMultiPayment; use farm_base_impl::base_traits_impl::FarmContract; use fixed_supply_token::FixedSupplyToken; use token_attributes::StakingFarmTokenAttributes; @@ -43,6 +42,7 @@ pub trait FarmStaking: + farm_base_impl::claim_rewards::BaseClaimRewardsModule + farm_base_impl::compound_rewards::BaseCompoundRewardsModule + farm_base_impl::exit_farm::BaseExitFarmModule + + farm::progress_update::ProgressUpdateModule + utils::UtilsModule + farm_token_roles::FarmTokenRolesModule + stake_farm::StakeFarmModule @@ -92,16 +92,9 @@ pub trait FarmStaking: #[payable("*")] #[endpoint(mergeFarmTokens)] - fn merge_farm_tokens_endpoint( - &self, - opt_orig_caller: OptionalValue, - ) -> DoubleMultiPayment { + fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); - let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - - let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); - let boosted_rewards_full_position = - EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + self.check_claim_progress_for_merge(&caller); let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); @@ -111,9 +104,8 @@ pub trait FarmStaking: let merged_farm_token = token_mapper.nft_create(new_token_amount, &output_attributes); self.send_payment_non_zero(&caller, &merged_farm_token); - self.send_payment_non_zero(&orig_caller, &boosted_rewards_full_position); - (merged_farm_token, boosted_rewards_full_position).into() + merged_farm_token } #[view(calculateRewardsForGivenPosition)]