diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index dbc7ea16b..c7937d583 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -10,7 +10,7 @@ use contexts::storage_cache::StorageCache; use core::marker::PhantomData; use farm::{ - base_functions::{BaseFunctionsModule, ClaimRewardsResultType, Wrapper}, + base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }, @@ -33,7 +33,6 @@ 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 @@ -180,16 +179,24 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> EsdtTokenPayment { + ) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - self.check_claim_progress_for_merge(&orig_caller); + self.migrate_old_farm_positions(&orig_caller); + let boosted_rewards = self.claim_only_boosted_payment(&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, + ); - merged_farm_token + (merged_farm_token, locked_rewards_payment).into() } #[endpoint(claimBoostedRewards)] diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 7f019ed08..13f3a29d0 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -7,7 +7,6 @@ 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; @@ -34,7 +33,6 @@ 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 @@ -178,16 +176,23 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> EsdtTokenPayment { + ) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - self.check_claim_progress_for_merge(&orig_caller); self.migrate_old_farm_positions(&orig_caller); + let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + let boosted_rewards_payment = if boosted_rewards > 0 { + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards) + } else { + EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()) + }; + let merged_farm_token = self.merge_farm_tokens::>(); self.send_payment_non_zero(&caller, &merged_farm_token); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); - merged_farm_token + (merged_farm_token, boosted_rewards_payment).into() } #[endpoint(claimBoostedRewards)] diff --git a/dex/farm/src/progress_update.rs b/dex/farm/src/progress_update.rs deleted file mode 100644 index 48e4b7644..000000000 --- a/dex/farm/src/progress_update.rs +++ /dev/null @@ -1,27 +0,0 @@ -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 819d87cfe..0168b2bf6 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -335,7 +335,9 @@ 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); + let (out_farm_token, _boosted_rewards) = sc + .merge_farm_tokens_endpoint(OptionalValue::None) + .into_tuple(); assert_eq!( out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) diff --git a/dex/scenarios/merge_tokens.scen.json b/dex/scenarios/merge_tokens.scen.json index 1a0b187cb..ed059f31b 100644 --- a/dex/scenarios/merge_tokens.scen.json +++ b/dex/scenarios/merge_tokens.scen.json @@ -30,7 +30,8 @@ }, "expect": { "out": [ - "0x0000000b4641524d2d6162636465660000000000000003000000040bebc200" + "0x0000000b4641524d2d6162636465660000000000000003000000040bebc200", + "0x0000000c5745474c442d616263646566000000000000000000000000" ], "status": "0", "message": "", @@ -63,4 +64,4 @@ } } ] -} +} \ No newline at end of file diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index c9941ced1..42820dd3f 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -7,6 +7,7 @@ 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; @@ -42,7 +43,6 @@ 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,11 +92,17 @@ pub trait FarmStaking: #[payable("*")] #[endpoint(mergeFarmTokens)] - fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment { + fn merge_farm_tokens_endpoint(&self) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); - self.check_claim_progress_for_merge(&caller); self.migrate_old_farm_positions(&caller); + let boosted_rewards = self.claim_only_boosted_payment(&caller); + let boosted_rewards_payment = if boosted_rewards > 0 { + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards) + } else { + EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()) + }; + let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); let output_attributes: StakingFarmTokenAttributes = @@ -105,8 +111,9 @@ 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(&caller, &boosted_rewards_payment); - merged_farm_token + (merged_farm_token, boosted_rewards_payment).into() } #[view(calculateRewardsForGivenPosition)]