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/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 2f5f4935c..a823a71c7 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -55,7 +55,7 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio fn is_old_farm_position(&self, token_nonce: Nonce) -> bool { let farm_position_migration_block_nonce = self.farm_position_migration_block_nonce().get(); - token_nonce < farm_position_migration_block_nonce + token_nonce > 0 && token_nonce < farm_position_migration_block_nonce } #[endpoint(allowExternalClaimBoostedRewards)] diff --git a/common/modules/farm/farm_base_impl/src/exit_farm.rs b/common/modules/farm/farm_base_impl/src/exit_farm.rs index eefe7c65f..315abe421 100644 --- a/common/modules/farm/farm_base_impl/src/exit_farm.rs +++ b/common/modules/farm/farm_base_impl/src/exit_farm.rs @@ -44,8 +44,6 @@ pub trait BaseExitFarmModule: self.blockchain(), ); - FC::decrease_user_farm_position(self, &payment); - FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &exit_farm_context.farm_token.payment.amount; @@ -64,6 +62,8 @@ pub trait BaseExitFarmModule: ); storage_cache.reward_reserve -= &reward; + FC::decrease_user_farm_position(self, &payment); + let farming_token_amount = token_attributes.get_total_supply(); let farming_token_payment = EsdtTokenPayment::new( storage_cache.farming_token_id.clone(), diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index c2723738e..c7937d583 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -8,10 +8,9 @@ multiversx_sc::derive_imports!(); use common_structs::FarmTokenAttributes; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; -use mergeable::Mergeable; 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, }, @@ -34,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 @@ -150,36 +148,19 @@ pub trait Farm: #[endpoint(exitFarm)] fn exit_farm_endpoint( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let mut payment = self.call_value().single_esdt(); - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); - - 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); - - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); + let payment = self.call_value().single_esdt(); - payment.amount = exit_amount; + self.migrate_old_farm_positions(&orig_caller); let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - let mut rewards = exit_farm_result.rewards; - rewards.merge_with(boosted_rewards_full_position); + let rewards = exit_farm_result.rewards; self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); - self.send_payment_non_zero(&caller, &remaining_farm_payment); let locked_rewards_payment = self.send_to_lock_contract_non_zero( rewards.token_identifier.clone(), @@ -190,12 +171,7 @@ pub trait Farm: self.clear_user_energy_if_needed(&orig_caller); - ( - exit_farm_result.farming_tokens, - locked_rewards_payment, - remaining_farm_payment, - ) - .into() + (exit_farm_result.farming_tokens, locked_rewards_payment).into() } #[payable("*")] @@ -203,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)] @@ -237,7 +221,7 @@ pub trait Farm: self.send_to_lock_contract_non_zero( self.reward_token_id().get(), boosted_rewards, - caller.clone(), + user.clone(), user.clone(), ) } diff --git a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs index f795108e6..f8858aaf8 100644 --- a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs +++ b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs @@ -413,25 +413,16 @@ where result } - pub fn exit_farm( - &mut self, - user: &Address, - farm_token_nonce: u64, - farm_token_amount: u64, - exit_farm_amount: u64, - ) { + pub fn exit_farm(&mut self, user: &Address, farm_token_nonce: u64, exit_farm_amount: u64) { self.b_mock .execute_esdt_transfer( user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::Some(managed_address!(user)), - ); + let _ = sc.exit_farm_endpoint(OptionalValue::Some(managed_address!(user))); }, ) .assert_ok(); diff --git a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs index db4f9e7bc..5d7bdf7be 100644 --- a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs +++ b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs @@ -149,7 +149,7 @@ fn farm_with_boosted_yields_no_proxy_test() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index f4f23bc78..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; @@ -17,11 +16,9 @@ use exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }; use farm_base_impl::base_traits_impl::FarmContract; -use mergeable::Mergeable; pub type EnterFarmResultType = DoubleMultiPayment; -pub type ExitFarmWithPartialPosResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; +pub type ExitFarmWithPartialPosResultType = DoubleMultiPayment; #[multiversx_sc::contract] pub trait Farm: @@ -36,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 @@ -156,47 +152,23 @@ pub trait Farm: #[endpoint(exitFarm)] fn exit_farm_endpoint( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let mut payment = self.call_value().single_esdt(); - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); + let payment = self.call_value().single_esdt(); - 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); - - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); - - payment.amount = exit_amount; + self.migrate_old_farm_positions(&orig_caller); - let mut exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - exit_farm_result - .rewards - .merge_with(boosted_rewards_full_position); + let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); self.send_payment_non_zero(&caller, &exit_farm_result.rewards); - self.send_payment_non_zero(&caller, &remaining_farm_payment); self.clear_user_energy_if_needed(&orig_caller); - ( - exit_farm_result.farming_tokens, - exit_farm_result.rewards, - remaining_farm_payment, - ) - .into() + (exit_farm_result.farming_tokens, exit_farm_result.rewards).into() } #[payable("*")] @@ -204,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_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 8dfac6b79..7fe7c53d3 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -149,7 +149,7 @@ fn farm_with_boosted_yields_test() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -262,7 +262,7 @@ fn farm_claim_boosted_yields_for_other_user_test() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -434,7 +434,7 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -625,7 +625,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -706,7 +706,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { farm_setup.set_user_energy(&second_user, 4_000, 13, 1); farm_setup.set_user_energy(&third_user, 1, 13, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 8, 1, 1); + farm_setup.exit_farm(&third_user, 8, 1); // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards // 7_500 base farm, 2_500 boosted yields @@ -718,7 +718,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { farm_setup.set_user_energy(&second_user, 4_000, 20, 1); farm_setup.set_user_energy(&third_user, 1, 20, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 9, 1, 1); + farm_setup.exit_farm(&third_user, 9, 1); // advance week farm_setup.b_mock.set_block_epoch(22); @@ -875,7 +875,7 @@ fn farm_enter_with_multiple_farm_token() { farm_setup.set_user_energy(&second_user, 4_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -990,7 +990,7 @@ fn farm_claim_with_minimum_tokens() { farm_setup.set_user_energy(&second_user, 90_000, 6, 1); farm_setup.set_user_energy(&third_user, 1, 6, 1); farm_setup.enter_farm(&third_user, 1); - farm_setup.exit_farm(&third_user, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); diff --git a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs index 7c610556c..4f144d8c4 100644 --- a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs +++ b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs @@ -185,10 +185,9 @@ where farm_token_nonce, &farm_out_amount.clone(), |sc| { - let exit_amount = to_managed_biguint(farm_out_amount); - let multi_result = sc.exit_farm_endpoint(exit_amount, OptionalValue::None); + let multi_result = sc.exit_farm_endpoint(OptionalValue::None); - let (first_result, second_result, _third_result) = multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, 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 b50f5ecde..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) @@ -513,25 +515,16 @@ where result } - pub fn exit_farm( - &mut self, - user: &Address, - farm_token_nonce: u64, - farm_token_amount: u64, - exit_farm_amount: u64, - ) { + pub fn exit_farm(&mut self, user: &Address, farm_token_nonce: u64, exit_farm_amount: u64) { self.b_mock .execute_esdt_transfer( user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::None, - ); + let _ = sc.exit_farm_endpoint(OptionalValue::None); }, ) .assert_ok(); @@ -541,7 +534,6 @@ where &mut self, user: &Address, farm_token_nonce: u64, - farm_token_amount: u64, exit_farm_amount: u64, known_proxy: &Address, ) { @@ -551,12 +543,9 @@ where &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::Some(managed_address!(user)), - ); + let _ = sc.exit_farm_endpoint(OptionalValue::Some(managed_address!(user))); }, ) .assert_ok(); diff --git a/dex/farm/tests/farm_setup/single_user_farm_setup.rs b/dex/farm/tests/farm_setup/single_user_farm_setup.rs index 13644ee88..1e23f999b 100644 --- a/dex/farm/tests/farm_setup/single_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/single_user_farm_setup.rs @@ -222,13 +222,9 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let multi_result = sc.exit_farm_endpoint( - managed_biguint!(farm_token_amount), - OptionalValue::None, - ); + let multi_result = sc.exit_farm_endpoint(OptionalValue::None); - let (first_result, second_result, remaining_farm_amount) = - multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, @@ -246,7 +242,6 @@ where ); assert_eq!(second_result.token_nonce, 0); assert_eq!(second_result.amount, managed_biguint!(expected_mex_out)); - assert_eq!(remaining_farm_amount.amount, managed_biguint!(0)); }, ) .assert_ok(); diff --git a/dex/farm/tests/farm_single_user_test.rs b/dex/farm/tests/farm_single_user_test.rs index 9adc893fa..c3df21b83 100644 --- a/dex/farm/tests/farm_single_user_test.rs +++ b/dex/farm/tests/farm_single_user_test.rs @@ -396,7 +396,7 @@ fn test_farm_through_simple_lock() { 2, &rust_biguint!(1_000_000_000), |sc| { - let exit_farm_result = sc.exit_farm_locked_token(managed_biguint!(1_000_000_000)); + let exit_farm_result = sc.exit_farm_locked_token(); let (locked_tokens, reward_tokens) = exit_farm_result.into_tuple(); assert_eq!( @@ -594,7 +594,7 @@ fn test_farm_through_simple_lock() { 7, &rust_biguint!(1_000_000_000), |sc| { - let exit_farm_result = sc.exit_farm_locked_token(managed_biguint!(1_000_000_000)); + let exit_farm_result = sc.exit_farm_locked_token(); let (locked_tokens, _reward_tokens) = exit_farm_result.into_tuple(); assert_eq!( diff --git a/dex/fuzz/src/fuzz_farm.rs b/dex/fuzz/src/fuzz_farm.rs index 1ef8e2463..c30e94442 100644 --- a/dex/fuzz/src/fuzz_farm.rs +++ b/dex/fuzz/src/fuzz_farm.rs @@ -8,7 +8,7 @@ pub mod fuzz_farm_test { use std::cmp::Ordering; use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; - use multiversx_sc_scenario::{managed_biguint, rust_biguint, DebugApi}; + use multiversx_sc_scenario::{rust_biguint, DebugApi}; use crate::fuzz_data::fuzz_data_tests::*; use farm::*; @@ -179,7 +179,7 @@ pub mod fuzz_farm_test { farm_token_nonce, &farm_out_amount, |sc| { - sc.exit_farm_endpoint(managed_biguint!(seed), OptionalValue::None); + sc.exit_farm_endpoint(OptionalValue::None); }, ); diff --git a/dex/scenarios/exit_farm.scen.json b/dex/scenarios/exit_farm.scen.json index 9a3ec697d..495520be4 100644 --- a/dex/scenarios/exit_farm.scen.json +++ b/dex/scenarios/exit_farm.scen.json @@ -25,9 +25,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -42,11 +40,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/exit_farm_too_soon.scen.json b/dex/scenarios/exit_farm_too_soon.scen.json index 8280af81e..72b596bda 100644 --- a/dex/scenarios/exit_farm_too_soon.scen.json +++ b/dex/scenarios/exit_farm_too_soon.scen.json @@ -47,9 +47,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "1,000,000,000", "gasPrice": "0" }, @@ -64,11 +62,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -125,9 +118,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "1,000,000,000", "gasPrice": "0" }, @@ -142,11 +133,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/exit_mex_farm.scen.json b/dex/scenarios/exit_mex_farm.scen.json index 03e17bb16..3cc9dca89 100644 --- a/dex/scenarios/exit_mex_farm.scen.json +++ b/dex/scenarios/exit_mex_farm.scen.json @@ -26,9 +26,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -43,11 +41,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:50,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_1.scen.json b/dex/scenarios/farm_reward_distr_scen_1.scen.json index 348847c77..e45afaa8e 100644 --- a/dex/scenarios/farm_reward_distr_scen_1.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_1.scen.json @@ -167,9 +167,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -184,11 +182,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:450" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -211,9 +204,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -228,11 +219,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:350" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_2.scen.json b/dex/scenarios/farm_reward_distr_scen_2.scen.json index bcab014a5..fc607055a 100644 --- a/dex/scenarios/farm_reward_distr_scen_2.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_2.scen.json @@ -210,9 +210,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -227,11 +225,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:428" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -260,9 +253,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +268,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:414" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +296,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +311,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:457" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_3.scen.json b/dex/scenarios/farm_reward_distr_scen_3.scen.json index b3a3442a4..b850e7bd9 100644 --- a/dex/scenarios/farm_reward_distr_scen_3.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_3.scen.json @@ -260,9 +260,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +275,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:371" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +303,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +318,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:285" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -360,9 +346,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -377,11 +361,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:242" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_4.scen.json b/dex/scenarios/farm_reward_distr_scen_4.scen.json index 629b2f5f9..0a9dbaf60 100644 --- a/dex/scenarios/farm_reward_distr_scen_4.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_4.scen.json @@ -260,9 +260,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +275,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:3,714,285,714,284,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +303,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +318,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:2,857,142,857,142,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -360,9 +346,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -377,11 +361,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:2,428,571,428,571,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", 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-proxy/src/external_contracts_interactions.rs b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs index d8b3a5258..17d32d056 100644 --- a/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs +++ b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs @@ -47,21 +47,19 @@ pub trait ExternalContractsInteractionsModule: orig_caller: ManagedAddress, lp_farm_token_nonce: u64, lp_farm_token_amount: BigUint, - exit_amount: BigUint, ) -> LpFarmExitResult { let lp_farm_token_id = self.lp_farm_token_id().get(); let lp_farm_address = self.lp_farm_address().get(); let exit_farm_result: ExitFarmWithPartialPosResultType = self .lp_farm_proxy_obj(lp_farm_address) - .exit_farm_endpoint(exit_amount, orig_caller) + .exit_farm_endpoint(orig_caller) .with_esdt_transfer((lp_farm_token_id, lp_farm_token_nonce, lp_farm_token_amount)) .execute_on_dest_context(); - let (lp_tokens, lp_farm_rewards, remaining_farm_tokens) = exit_farm_result.into_tuple(); + let (lp_tokens, lp_farm_rewards) = exit_farm_result.into_tuple(); LpFarmExitResult { lp_tokens, lp_farm_rewards, - remaining_farm_tokens, } } @@ -138,7 +136,6 @@ pub trait ExternalContractsInteractionsModule: staking_tokens: EsdtTokenPayment, farm_token_nonce: u64, farm_token_amount: BigUint, - exit_amount: BigUint, ) -> StakingFarmExitResult { let staking_farm_token_id = self.staking_farm_token_id().get(); let mut payments = ManagedVec::from_single_item(staking_tokens); @@ -151,16 +148,14 @@ pub trait ExternalContractsInteractionsModule: let staking_farm_address = self.staking_farm_address().get(); let unstake_result: ExitFarmWithPartialPosResultType = self .staking_farm_proxy_obj(staking_farm_address) - .unstake_farm_through_proxy(exit_amount, orig_caller) + .unstake_farm_through_proxy(orig_caller) .with_multi_token_transfer(payments) .execute_on_dest_context(); - let (unbond_staking_farm_token, staking_rewards, remaining_farm_tokens) = - unstake_result.into_tuple(); + let (unbond_staking_farm_token, staking_rewards) = unstake_result.into_tuple(); StakingFarmExitResult { unbond_staking_farm_token, staking_rewards, - remaining_farm_tokens, } } diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs deleted file mode 100644 index 84be38ae0..000000000 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs +++ /dev/null @@ -1,108 +0,0 @@ -use common_structs::PaymentsVec; - -use crate::{dual_yield_token::DualYieldTokenAttributes, result_types::MergeResult}; - -use mergeable::Mergeable; -use unwrappable::Unwrappable; - -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -#[multiversx_sc::module] -pub trait ProxyMergePosModule: - crate::dual_yield_token::DualYieldTokenModule - + crate::external_contracts_interactions::ExternalContractsInteractionsModule - + crate::lp_farm_token::LpFarmTokenModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + utils::UtilsModule - + token_send::TokenSendModule - + sc_whitelist_module::SCWhitelistModule - + super::claim::ProxyClaimModule -{ - #[payable("*")] - #[endpoint(mergeMetastakingWithStakingToken)] - fn merge_metastaking_with_staking_token(&self) -> MergeResult { - let mut payments = self.call_value().all_esdt_transfers().clone_value(); - require!( - payments.len() >= 2, - "Must send metastaking token and at least a staking token" - ); - - let dual_yield_token = self.pop_first_payment(&mut payments); - let dual_yield_token_mapper = self.dual_yield_token(); - dual_yield_token_mapper.require_same_token(&dual_yield_token.token_identifier); - - let mut attributes: DualYieldTokenAttributes = self - .get_attributes_as_part_of_fixed_supply(&dual_yield_token, &dual_yield_token_mapper); - dual_yield_token_mapper.nft_burn(dual_yield_token.token_nonce, &dual_yield_token.amount); - - let caller = self.blockchain().get_caller(); - let staking_farm_rewards = self.claim_staking_rewards_before_merge(&caller, &payments); - - let staking_amount_before_merge = attributes.get_total_staking_token_amount(); - for farm_staking_token in &payments { - attributes.real_pos_token_amount += &farm_staking_token.amount; - } - - let mut dual_yield_claim_result = self.claim_dual_yield( - &caller, - OptionalValue::None, - staking_amount_before_merge, - attributes, - ); - dual_yield_claim_result - .staking_farm_rewards - .merge_with(staking_farm_rewards); - - let new_dual_yield_tokens = self.create_dual_yield_tokens( - &dual_yield_token_mapper, - &dual_yield_claim_result.new_dual_yield_attributes, - ); - let merge_result = MergeResult { - lp_farm_rewards: dual_yield_claim_result.lp_farm_rewards, - staking_farm_rewards: dual_yield_claim_result.staking_farm_rewards, - new_dual_yield_tokens, - }; - - merge_result.send_and_return(self, &caller) - } - - fn claim_staking_rewards_before_merge( - &self, - caller: &ManagedAddress, - farm_staking_tokens: &PaymentsVec, - ) -> EsdtTokenPayment { - let staking_farm_token_id = self.staking_farm_token_id().get(); - let mut opt_staking_farm_rewards = Option::::None; - for farm_staking_token in farm_staking_tokens { - require!( - farm_staking_token.token_identifier == staking_farm_token_id, - "Invalid staking farm token" - ); - - let staking_claim_result = self.staking_farm_claim_rewards( - caller.clone(), - farm_staking_token.token_identifier, - farm_staking_token.token_nonce, - farm_staking_token.amount.clone(), - farm_staking_token.amount, - ); - - match &mut opt_staking_farm_rewards { - Some(rew) => rew.merge_with(staking_claim_result.staking_farm_rewards), - None => { - opt_staking_farm_rewards = Some(staking_claim_result.staking_farm_rewards); - } - }; - - let new_staking_farm_tokens = staking_claim_result.new_staking_farm_tokens; - self.send().esdt_local_burn( - &new_staking_farm_tokens.token_identifier, - new_staking_farm_tokens.token_nonce, - &new_staking_farm_tokens.amount, - ); - } - - opt_staking_farm_rewards.unwrap_or_panic::() - } -} diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs index c78527aa6..920b96eb0 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs @@ -20,7 +20,6 @@ pub trait ProxyUnstakeModule: &self, pair_first_token_min_amount: BigUint, pair_second_token_min_amount: BigUint, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> UnstakeResult { let caller = self.blockchain().get_caller(); @@ -32,20 +31,12 @@ pub trait ProxyUnstakeModule: let full_attributes: DualYieldTokenAttributes = dual_yield_token_mapper.get_token_attributes(payment.token_nonce); - require!( - exit_amount > 0 && exit_amount <= payment.amount, - "Invalid exit amount" - ); - - let full_attributes_adjusted: DualYieldTokenAttributes = - full_attributes.clone().into_part(&payment.amount); let exit_attributes: DualYieldTokenAttributes = - full_attributes.clone().into_part(&exit_amount); + full_attributes.into_part(&payment.amount); let lp_farm_exit_result = self.lp_farm_exit( orig_caller.clone(), - full_attributes_adjusted.lp_farm_token_nonce, - full_attributes_adjusted.lp_farm_token_amount, + exit_attributes.lp_farm_token_nonce, exit_attributes.lp_farm_token_amount, ); let remove_liq_result = self.pair_remove_liquidity( @@ -57,36 +48,16 @@ pub trait ProxyUnstakeModule: let staking_farm_exit_result = self.staking_farm_unstake( orig_caller.clone(), remove_liq_result.staking_token_payment, - full_attributes_adjusted.staking_farm_token_nonce, - full_attributes_adjusted.staking_farm_token_amount.clone(), + exit_attributes.staking_farm_token_nonce, exit_attributes.staking_farm_token_amount.clone(), ); - let opt_new_dual_yield_tokens = if exit_amount < payment.amount { - let remaining_lp_farm_tokens = lp_farm_exit_result.remaining_farm_tokens.amount; - let remaining_staking_farm_tokens = full_attributes_adjusted.staking_farm_token_amount - - exit_attributes.staking_farm_token_amount; - let new_attributes = DualYieldTokenAttributes { - lp_farm_token_nonce: full_attributes_adjusted.lp_farm_token_nonce, - lp_farm_token_amount: remaining_lp_farm_tokens, - staking_farm_token_nonce: full_attributes_adjusted.staking_farm_token_nonce, - staking_farm_token_amount: remaining_staking_farm_tokens, - }; - let new_dual_yield_tokens = - self.create_dual_yield_tokens(&dual_yield_token_mapper, &new_attributes); - - Some(new_dual_yield_tokens) - } else { - None - }; - let caller = self.blockchain().get_caller(); let unstake_result = UnstakeResult { other_token_payment: remove_liq_result.other_token_payment, lp_farm_rewards: lp_farm_exit_result.lp_farm_rewards, staking_rewards: staking_farm_exit_result.staking_rewards, unbond_staking_farm_token: staking_farm_exit_result.unbond_staking_farm_token, - opt_new_dual_yield_tokens, }; dual_yield_token_mapper.nft_burn(payment.token_nonce, &payment.amount); diff --git a/farm-staking/farm-staking-proxy/src/result_types.rs b/farm-staking/farm-staking-proxy/src/result_types.rs index af40a59f0..65e0cf238 100644 --- a/farm-staking/farm-staking-proxy/src/result_types.rs +++ b/farm-staking/farm-staking-proxy/src/result_types.rs @@ -13,7 +13,6 @@ pub struct LpFarmClaimRewardsResult { pub struct LpFarmExitResult { pub lp_tokens: EsdtTokenPayment, pub lp_farm_rewards: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } // staking farm @@ -31,7 +30,6 @@ pub struct StakingFarmClaimRewardsResult { pub struct StakingFarmExitResult { pub unbond_staking_farm_token: EsdtTokenPayment, pub staking_rewards: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } // pair @@ -92,7 +90,6 @@ pub struct UnstakeResult { pub lp_farm_rewards: EsdtTokenPayment, pub staking_rewards: EsdtTokenPayment, pub unbond_staking_farm_token: EsdtTokenPayment, - pub opt_new_dual_yield_tokens: Option>, } impl UnstakeResult { @@ -107,10 +104,6 @@ impl UnstakeResult { payments.push(self.staking_rewards.clone()); payments.push(self.unbond_staking_farm_token.clone()); - if let Some(new_dual_yield_tokens) = &self.opt_new_dual_yield_tokens { - payments.push(new_dual_yield_tokens.clone()); - } - sc.send_multiple_tokens_if_not_zero(to, &payments); self diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs index 5eae751fd..c81d579ab 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs @@ -234,12 +234,11 @@ fn unstake_partial_position_test() { &setup.proxy_wrapper, DUAL_YIELD_TOKEN_ID, dual_yield_token_nonce_after_stake, - &rust_biguint!(dual_yield_token_amount), + &rust_biguint!(dual_yield_token_amount / 2), |sc| { let results = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(dual_yield_token_amount / 2), OptionalValue::None, ); @@ -270,47 +269,23 @@ fn unstake_partial_position_test() { managed_token_id!(STAKING_FARM_TOKEN_ID) ); assert_eq!(unbond_tokens.amount, dual_yield_token_amount / 2); - - let new_dual_yield_tokens = results.opt_new_dual_yield_tokens.unwrap(); - assert_eq!( - new_dual_yield_tokens.token_identifier, - managed_token_id!(DUAL_YIELD_TOKEN_ID) - ); - assert_eq!(new_dual_yield_tokens.amount, dual_yield_token_amount / 2); }, ) .assert_ok(); - let expected_new_dual_yield_attributes = DualYieldTokenAttributes:: { - lp_farm_token_nonce: 1, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 2), - staking_farm_token_nonce: 1, - staking_farm_token_amount: managed_biguint!(1_001_000_000 / 2), - }; - let new_dual_yield_token_nonce = dual_yield_token_nonce_after_stake + 1; - let new_dual_yield_token_amount = dual_yield_token_amount / 2; - setup.b_mock.check_nft_balance( - &setup.user_addr, - DUAL_YIELD_TOKEN_ID, - new_dual_yield_token_nonce, - &rust_biguint!(new_dual_yield_token_amount), - Some(&expected_new_dual_yield_attributes), - ); - - // unstake with the new dual yield tokens + // unstake with the remaining dual yield tokens setup .b_mock .execute_esdt_transfer( &setup.user_addr, &setup.proxy_wrapper, DUAL_YIELD_TOKEN_ID, - new_dual_yield_token_nonce, - &rust_biguint!(new_dual_yield_token_amount), + dual_yield_token_nonce_after_stake, + &rust_biguint!(dual_yield_token_amount / 2), |sc| { let results = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(new_dual_yield_token_amount), OptionalValue::None, ); @@ -341,9 +316,6 @@ fn unstake_partial_position_test() { managed_token_id!(STAKING_FARM_TOKEN_ID) ); assert_eq!(unbond_tokens.amount, 1_001_000_000 / 2); - - // no new dual yield tokens created - assert!(results.opt_new_dual_yield_tokens.is_none()); }, ) .assert_ok(); diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs index 945a36418..00b2e2e0f 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs @@ -271,7 +271,6 @@ where let received_tokens = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(dual_yield_token_amount), OptionalValue::None, ); @@ -405,9 +404,8 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let (unbond_farm_tokens, reward_tokens, _) = sc - .unstake_farm(managed_biguint!(farm_token_amount), OptionalValue::None) - .into_tuple(); + let (unbond_farm_tokens, reward_tokens) = + sc.unstake_farm(OptionalValue::None).into_tuple(); unbond_token_nonce = unbond_farm_tokens.token_nonce; assert_eq!(reward_tokens.amount, expected_rewards_amount); 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 556a2ef17..4e31662b2 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 @@ -50,7 +50,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: } fn migrate_old_farm_positions(&self, caller: &ManagedAddress) { - let payments = self.get_non_empty_payments(); + let payments = self.call_value().all_esdt_transfers().clone_value(); let farm_token_mapper = self.farm_token(); let farm_token_id = farm_token_mapper.get_token_id(); for farm_position in &payments { 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)] diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 39acc348d..6b529e0fb 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -1,7 +1,6 @@ multiversx_sc::imports!(); use farm::ExitFarmWithPartialPosResultType; -use mergeable::Mergeable; use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::UnbondSftAttributes}; @@ -36,21 +35,19 @@ pub trait UnstakeFarmModule: #[endpoint(unstakeFarm)] fn unstake_farm( &self, - exit_amount: BigUint, opt_original_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); let payment = self.call_value().single_esdt(); - self.unstake_farm_common(original_caller, payment, exit_amount, None) + self.unstake_farm_common(original_caller, payment, None) } #[payable("*")] #[endpoint(unstakeFarmThroughProxy)] fn unstake_farm_through_proxy( &self, - exit_amount: BigUint, original_caller: ManagedAddress, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); @@ -66,43 +63,19 @@ pub trait UnstakeFarmModule: "Invalid staking token received" ); - self.unstake_farm_common( - original_caller, - second_payment, - exit_amount, - Some(first_payment.amount), - ) + self.unstake_farm_common(original_caller, second_payment, Some(first_payment.amount)) } fn unstake_farm_common( &self, original_caller: ManagedAddress, - mut payment: EsdtTokenPayment, - exit_amount: BigUint, + payment: EsdtTokenPayment, opt_unbond_amount: Option, ) -> ExitFarmWithPartialPosResultType { - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); - - let boosted_rewards = self.claim_only_boosted_payment(&original_caller); - let boosted_rewards_full_position = - EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); - - payment.amount = exit_amount; + self.migrate_old_farm_positions(&original_caller); - let mut exit_result = + let exit_result = self.exit_farm_base::>(original_caller.clone(), payment); - exit_result - .reward_payment - .merge_with(boosted_rewards_full_position); let unbond_token_amount = opt_unbond_amount.unwrap_or(exit_result.farming_token_payment.amount); @@ -113,7 +86,6 @@ pub trait UnstakeFarmModule: self.create_and_send_unbond_tokens(&caller, farm_token_id, unbond_token_amount); self.send_payment_non_zero(&caller, &exit_result.reward_payment); - self.send_payment_non_zero(&caller, &remaining_farm_payment); self.clear_user_energy_if_needed(&original_caller); self.set_farm_supply_for_current_week(&exit_result.storage_cache.farm_token_supply); @@ -126,12 +98,7 @@ pub trait UnstakeFarmModule: exit_result.storage_cache, ); - ( - unbond_farm_token, - exit_result.reward_payment, - remaining_farm_payment, - ) - .into() + (unbond_farm_token, exit_result.reward_payment).into() } fn create_and_send_unbond_tokens( diff --git a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs index 9ce3d963e..b2c3c5b3f 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -7,7 +7,7 @@ use farm_staking::{ }; use farm_staking_setup::*; use multiversx_sc::codec::multi_types::OptionalValue; -use multiversx_sc_scenario::{managed_biguint, rust_biguint, DebugApi}; +use multiversx_sc_scenario::{rust_biguint, DebugApi}; #[test] fn farm_staking_with_energy_setup_test() { @@ -121,7 +121,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { 3, &rust_biguint!(10), |sc| { - let _ = sc.unstake_farm(managed_biguint!(10), OptionalValue::None); + let _ = sc.unstake_farm(OptionalValue::None); }, ) .assert_ok(); @@ -217,7 +217,7 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { 3, &rust_biguint!(10), |sc| { - let _ = sc.unstake_farm(managed_biguint!(10), OptionalValue::None); + let _ = sc.unstake_farm(OptionalValue::None); }, ) .assert_ok(); diff --git a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs index 01e768862..51841149f 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -328,10 +328,9 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let multi_result = - sc.unstake_farm(managed_biguint!(farm_token_amount), OptionalValue::None); + let multi_result = sc.unstake_farm(OptionalValue::None); - let (first_result, second_result, _) = multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, diff --git a/locked-asset/proxy_dex/src/farm_interactions.rs b/locked-asset/proxy_dex/src/farm_interactions.rs index ee9a62f30..0ccabdb33 100644 --- a/locked-asset/proxy_dex/src/farm_interactions.rs +++ b/locked-asset/proxy_dex/src/farm_interactions.rs @@ -13,7 +13,6 @@ pub struct EnterFarmResultWrapper { pub struct ExitFarmResultWrapper { pub farming_tokens: EsdtTokenPayment, pub reward_tokens: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } #[multiversx_sc::module] @@ -43,20 +42,18 @@ pub trait FarmInteractionsModule { &self, farm_address: ManagedAddress, farm_token: EsdtTokenPayment, - exit_amount: BigUint, ) -> ExitFarmResultWrapper { let original_caller = self.blockchain().get_caller(); let raw_result: ExitFarmWithPartialPosResultType = self .farm_contract_proxy(farm_address) - .exit_farm_endpoint(exit_amount, original_caller) + .exit_farm_endpoint(original_caller) .with_esdt_transfer(farm_token) .execute_on_dest_context(); - let (farming_tokens, reward_tokens, remaining_farm_tokens) = raw_result.into_tuple(); + let (farming_tokens, reward_tokens) = raw_result.into_tuple(); ExitFarmResultWrapper { farming_tokens, reward_tokens, - remaining_farm_tokens, } } diff --git a/locked-asset/proxy_dex/src/proxy_farm.rs b/locked-asset/proxy_dex/src/proxy_farm.rs index beb6cf425..49db77bd4 100644 --- a/locked-asset/proxy_dex/src/proxy_farm.rs +++ b/locked-asset/proxy_dex/src/proxy_farm.rs @@ -16,8 +16,7 @@ pub struct FarmingFarmTokenPair { pub farm_token: EsdtTokenPayment, } -pub type ExitFarmProxyResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; +pub type ExitFarmProxyResultType = MultiValue2, EsdtTokenPayment>; pub type ClaimRewardsFarmProxyResultType = MultiValue2, EsdtTokenPayment>; #[multiversx_sc::module] @@ -152,11 +151,7 @@ pub trait ProxyFarmModule: #[payable("*")] #[endpoint(exitFarmProxy)] - fn exit_farm_proxy( - &self, - farm_address: ManagedAddress, - exit_amount: BigUint, - ) -> ExitFarmProxyResultType { + fn exit_farm_proxy(&self, farm_address: ManagedAddress) -> ExitFarmProxyResultType { self.require_is_intermediated_farm(&farm_address); self.require_wrapped_farm_token_id_not_empty(); self.require_wrapped_lp_token_id_not_empty(); @@ -175,22 +170,14 @@ pub trait ProxyFarmModule: .into_part(&payment.amount); let exit_result = self.call_exit_farm( farm_address.clone(), - wrapped_farm_attributes_for_exit.farm_token, - exit_amount.clone(), + wrapped_farm_attributes_for_exit.farm_token.clone(), ); - let mut remaining_wrapped_tokens = payment.clone(); - remaining_wrapped_tokens.amount = exit_result.remaining_farm_tokens.amount; - self.burn_if_base_asset(&exit_result.farming_tokens); - let mut payment_used_for_exit = payment.clone(); - payment_used_for_exit.amount = exit_amount.clone(); - let wrapped_attributes_used_for_exit_farm: WrappedFarmTokenAttributes = - full_wrapped_farm_attributes.into_part(&exit_amount); let wrapped_farm_tokens_for_initial_tokens = WrappedFarmToken { - payment: payment_used_for_exit, - attributes: wrapped_attributes_used_for_exit_farm.clone(), + payment: payment.clone(), + attributes: wrapped_farm_attributes_for_exit.clone(), }; let caller = self.blockchain().get_caller(); @@ -203,24 +190,18 @@ pub trait ProxyFarmModule: self.send_payment_non_zero(&caller, &initial_proxy_farming_tokens); self.send_payment_non_zero(&caller, &exit_result.reward_tokens); - self.send_payment_non_zero(&caller, &remaining_wrapped_tokens); - wrapped_farm_token_mapper.nft_burn(payment.token_nonce, &exit_amount); + wrapped_farm_token_mapper.nft_burn(payment.token_nonce, &payment.amount); self.emit_exit_farm_proxy_event( &caller, &farm_address, payment, - wrapped_attributes_used_for_exit_farm, + wrapped_farm_attributes_for_exit, exit_result.reward_tokens.clone(), ); - ( - initial_proxy_farming_tokens, - exit_result.reward_tokens, - remaining_wrapped_tokens, - ) - .into() + (initial_proxy_farming_tokens, exit_result.reward_tokens).into() } fn handle_farm_penalty_and_get_output_proxy_farming_token( diff --git a/locked-asset/proxy_dex/tests/proxy_farm_test.rs b/locked-asset/proxy_dex/tests/proxy_farm_test.rs index bfa289fde..8463560e5 100644 --- a/locked-asset/proxy_dex/tests/proxy_farm_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_farm_test.rs @@ -240,8 +240,7 @@ fn farm_proxy_actions_test() { 3, &rust_biguint!(USER_BALANCE), |sc| { - let output = sc - .exit_farm_proxy(managed_address!(&farm_addr), managed_biguint!(USER_BALANCE)); + let output = sc.exit_farm_proxy(managed_address!(&farm_addr)); let output_lp_token = output.0 .0; assert_eq!(output_lp_token.token_nonce, 1); assert_eq!(output_lp_token.amount, USER_BALANCE); @@ -442,12 +441,9 @@ fn farm_with_wrapped_lp_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &expected_lp_token_amount, + &(expected_lp_token_amount.clone() / rust_biguint!(2)), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr)); }, ) .assert_ok(); @@ -758,12 +754,9 @@ fn farm_proxy_partial_exit_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &rust_biguint!(USER_BALANCE), + &rust_biguint!(USER_BALANCE / 2), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(USER_BALANCE / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr)); }, ) .assert_ok(); @@ -936,12 +929,9 @@ fn farm_proxy_partial_exit_with_penalty_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &rust_biguint!(USER_BALANCE), + &rust_biguint!(USER_BALANCE / 2), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(USER_BALANCE / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr)); }, ) .assert_ok(); @@ -1159,10 +1149,7 @@ fn different_farm_locked_token_nonce_merging_test() { 3, &rust_biguint!(USER_BALANCE * 2), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_addr), - managed_biguint!(USER_BALANCE * 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_addr)); }, ) .assert_ok(); diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index fe099d430..1d5339db2 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -8,7 +8,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", "version_check", ] @@ -31,12 +31,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -314,12 +308,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -336,12 +324,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -351,9 +333,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "386c2727eba66bc5e502e470d7afa55fdd69aedff440c508bb9ba85aec36a52a" dependencies = [ "bitflags", "hashbrown", @@ -365,20 +347,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "0f1e15b46c17b87c0c7cdd79b041a4abd7f3a2b45f3c993f6ce38c0f233e82b6" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "9a7bc0762cd6d88f8bc54805bc652b042a61cd7fbc2d0a325010f088b78fb2ac" dependencies = [ "hex", "proc-macro2", @@ -388,9 +369,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "050510b6b9836b24b4a73bb7878c58c268d56bde1c6eb0f9a88dce9a6518507b" dependencies = [ "hex", "proc-macro2", @@ -401,21 +382,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "3b55fe3585cbc745bd7b9793be4bcb3aa7f1869ced7a0981f3d47e6a832c6311" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "b059f22dfc3eb45aa015f6f20f28ed34dc42a65b42d282f8ac9b799b12e2942c" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -476,9 +456,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -628,18 +608,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -659,25 +627,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/proxy_dex/wasm/src/lib.rs b/locked-asset/proxy_dex/wasm/src/lib.rs index 892463480..096dff097 100644 --- a/locked-asset/proxy_dex/wasm/src/lib.rs +++ b/locked-asset/proxy_dex/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 27 #![no_std] -#![feature(alloc_error_handler, lang_items)] + +// Configuration that works with rustc < 1.73.0. +// TODO: Recommended rustc version: 1.73.0 or newer. +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,31 +21,33 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { proxy_dex ( - registerProxyPair - setTransferRoleWrappedLpToken - registerProxyFarm - setTransferRoleWrappedFarmToken - getAssetTokenId - getLockedTokenIds - getOldLockedTokenId - getOldFactoryAddress - getWrappedLpTokenId - getWrappedFarmTokenId - addPairToIntermediate - removeIntermediatedPair - addFarmToIntermediate - removeIntermediatedFarm - getIntermediatedPairs - getIntermediatedFarms - addLiquidityProxy - removeLiquidityProxy - enterFarmProxy - exitFarmProxy - claimRewardsProxy - mergeWrappedFarmTokens - mergeWrappedLpTokens - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + registerProxyPair => register_proxy_pair + setTransferRoleWrappedLpToken => set_transfer_role_wrapped_lp_token + registerProxyFarm => register_proxy_farm + setTransferRoleWrappedFarmToken => set_transfer_role_wrapped_farm_token + getAssetTokenId => get_asset_token_id_view + getLockedTokenIds => get_locked_token_ids_view + getOldLockedTokenId => old_locked_token_id + getOldFactoryAddress => old_factory_address + getWrappedLpTokenId => wrapped_lp_token + getWrappedFarmTokenId => wrapped_farm_token + addPairToIntermediate => add_pair_to_intermediate + removeIntermediatedPair => remove_intermediated_pair + addFarmToIntermediate => add_farm_to_intermediate + removeIntermediatedFarm => remove_intermediated_farm + getIntermediatedPairs => intermediated_pairs + getIntermediatedFarms => intermediated_farms + addLiquidityProxy => add_liquidity_proxy + removeLiquidityProxy => remove_liquidity_proxy + enterFarmProxy => enter_farm_proxy_endpoint + exitFarmProxy => exit_farm_proxy + claimRewardsProxy => claim_rewards_proxy + mergeWrappedFarmTokens => merge_wrapped_farm_tokens_endpoint + mergeWrappedLpTokens => merge_wrapped_lp_tokens_endpoint + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { proxy_dex } diff --git a/locked-asset/simple-lock/elrond.json b/locked-asset/simple-lock/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/locked-asset/simple-lock/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/locked-asset/simple-lock/src/farm_interactions.rs b/locked-asset/simple-lock/src/farm_interactions.rs index d68e5ae62..4748f8ec5 100644 --- a/locked-asset/simple-lock/src/farm_interactions.rs +++ b/locked-asset/simple-lock/src/farm_interactions.rs @@ -11,7 +11,7 @@ type ClaimRewardsResultType = MultiValue2, EsdtTokenPayment>; const ENTER_FARM_RESULTS_LEN: usize = 2; -const EXIT_FARM_RESULTS_LEN: usize = 3; +const EXIT_FARM_RESULTS_LEN: usize = 2; const CLAIM_REWARDS_RESULTS_LEN: usize = 2; pub struct EnterFarmResultWrapper { @@ -22,7 +22,6 @@ pub struct EnterFarmResultWrapper { pub struct ExitFarmResultWrapper { pub initial_farming_tokens: EsdtTokenPayment, pub reward_tokens: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } pub struct FarmClaimRewardsResultWrapper { @@ -51,7 +50,6 @@ mod farm_proxy { #[endpoint(exitFarm)] fn exit_farm( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmResultType; @@ -106,12 +104,11 @@ pub trait FarmInteractionsModule { farm_token: TokenIdentifier, farm_token_nonce: u64, farm_token_amount: BigUint, - exit_amount: BigUint, caller: ManagedAddress, ) -> ExitFarmResultWrapper { let raw_results: RawResultsType = self .farm_proxy(farm_address) - .exit_farm(exit_amount, caller) + .exit_farm(caller) .with_esdt_transfer(EsdtTokenPayment::new( farm_token, farm_token_nonce, @@ -124,12 +121,10 @@ pub trait FarmInteractionsModule { let initial_farming_tokens = results_wrapper.decode_next_result(); let reward_tokens = results_wrapper.decode_next_result(); - let remaining_farm_tokens = results_wrapper.decode_next_result(); ExitFarmResultWrapper { initial_farming_tokens, reward_tokens, - remaining_farm_tokens, } } diff --git a/locked-asset/simple-lock/src/proxy_farm.rs b/locked-asset/simple-lock/src/proxy_farm.rs index 43ea8b6c8..c6ab28659 100644 --- a/locked-asset/simple-lock/src/proxy_farm.rs +++ b/locked-asset/simple-lock/src/proxy_farm.rs @@ -199,18 +199,11 @@ pub trait ProxyFarmModule: /// - farm reward tokens #[payable("*")] #[endpoint(exitFarmLockedToken)] - fn exit_farm_locked_token( - &self, - exit_amount: BigUint, - ) -> ExitFarmThroughProxyResultType { - require!(exit_amount > 0u64, "Exit amount must be greater than 0"); + fn exit_farm_locked_token(&self) -> ExitFarmThroughProxyResultType { let payment: EsdtTokenPayment = self.call_value().single_esdt(); - require!( - exit_amount > 0u64 && exit_amount <= payment.amount, - "Invalid exit amount" - ); + let farm_proxy_token_attributes: FarmProxyTokenAttributes = - self.validate_payment_and_get_farm_proxy_token_attributes(&payment, &exit_amount); + self.validate_payment_and_get_farm_proxy_token_attributes(&payment); let farm_address = self.try_get_farm_address( &farm_proxy_token_attributes.farming_token_id, @@ -222,7 +215,6 @@ pub trait ProxyFarmModule: farm_proxy_token_attributes.farm_token_id, farm_proxy_token_attributes.farm_token_nonce, payment.amount, - exit_amount, caller.clone(), ); require!( @@ -253,15 +245,6 @@ pub trait ProxyFarmModule: ); } - if exit_farm_result.remaining_farm_tokens.amount > 0 { - self.send().direct_esdt( - &caller, - &payment.token_identifier, - payment.token_nonce, - &exit_farm_result.remaining_farm_tokens.amount, - ); - } - (lp_proxy_token_payment, exit_farm_result.reward_tokens).into() } @@ -279,7 +262,7 @@ pub trait ProxyFarmModule: fn farm_claim_rewards_locked_token(&self) -> FarmClaimRewardsThroughProxyResultType { let payment: EsdtTokenPayment = self.call_value().single_esdt(); let mut farm_proxy_token_attributes: FarmProxyTokenAttributes = - self.validate_payment_and_get_farm_proxy_token_attributes(&payment, &payment.amount); + self.validate_payment_and_get_farm_proxy_token_attributes(&payment); let farm_address = self.try_get_farm_address( &farm_proxy_token_attributes.farming_token_id, @@ -337,7 +320,6 @@ pub trait ProxyFarmModule: fn validate_payment_and_get_farm_proxy_token_attributes( &self, payment: &EsdtTokenPayment, - exit_amount: &BigUint, ) -> FarmProxyTokenAttributes { require!(payment.amount > 0, NO_PAYMENT_ERR_MSG); @@ -347,7 +329,7 @@ pub trait ProxyFarmModule: let farm_proxy_token_attributes: FarmProxyTokenAttributes = farm_proxy_token_mapper.get_token_attributes(payment.token_nonce); - farm_proxy_token_mapper.nft_burn(payment.token_nonce, exit_amount); + farm_proxy_token_mapper.nft_burn(payment.token_nonce, &payment.amount); farm_proxy_token_attributes } diff --git a/locked-asset/simple-lock/wasm/Cargo.lock b/locked-asset/simple-lock/wasm/Cargo.lock index 270c2aca4..cb879951a 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -8,7 +8,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", "version_check", ] @@ -31,12 +31,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -88,12 +82,6 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "math" version = "0.0.0" @@ -101,12 +89,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -116,9 +98,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "386c2727eba66bc5e502e470d7afa55fdd69aedff440c508bb9ba85aec36a52a" dependencies = [ "bitflags", "hashbrown", @@ -130,20 +112,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "0f1e15b46c17b87c0c7cdd79b041a4abd7f3a2b45f3c993f6ce38c0f233e82b6" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "9a7bc0762cd6d88f8bc54805bc652b042a61cd7fbc2d0a325010f088b78fb2ac" dependencies = [ "hex", "proc-macro2", @@ -153,9 +134,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "050510b6b9836b24b4a73bb7878c58c268d56bde1c6eb0f9a88dce9a6518507b" dependencies = [ "hex", "proc-macro2", @@ -166,21 +147,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "3b55fe3585cbc745bd7b9793be4bcb3aa7f1869ced7a0981f3d47e6a832c6311" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "b059f22dfc3eb45aa015f6f20f28ed34dc42a65b42d282f8ac9b799b12e2942c" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -209,9 +189,9 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -287,37 +267,3 @@ name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/simple-lock/wasm/src/lib.rs b/locked-asset/simple-lock/wasm/src/lib.rs index 042660883..afe83b5ff 100644 --- a/locked-asset/simple-lock/wasm/src/lib.rs +++ b/locked-asset/simple-lock/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 21 #![no_std] -#![feature(alloc_error_handler, lang_items)] + +// Configuration that works with rustc < 1.73.0. +// TODO: Recommended rustc version: 1.73.0 or newer. +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,25 +21,27 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { simple_lock ( - lockTokens - unlockTokens - issueLockedToken - getLockedTokenId - issueLpProxyToken - addLpToWhitelist - removeLpFromWhitelist - addLiquidityLockedToken - removeLiquidityLockedToken - getKnownLiquidityPools - getLpProxyTokenId - issueFarmProxyToken - addFarmToWhitelist - removeFarmFromWhitelist - enterFarmLockedToken - exitFarmLockedToken - farmClaimRewardsLockedToken - getKnownFarms - getFarmProxyTokenId - callBack + init => init + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + issueLockedToken => issue_locked_token + getLockedTokenId => locked_token + issueLpProxyToken => issue_lp_proxy_token + addLpToWhitelist => add_lp_to_whitelist + removeLpFromWhitelist => remove_lp_from_whitelist + addLiquidityLockedToken => add_liquidity_locked_token + removeLiquidityLockedToken => remove_liquidity_locked_token + getKnownLiquidityPools => known_liquidity_pools + getLpProxyTokenId => lp_proxy_token + issueFarmProxyToken => issue_farm_proxy_token + addFarmToWhitelist => add_farm_to_whitelist + removeFarmFromWhitelist => remove_farm_from_whitelist + enterFarmLockedToken => enter_farm_locked_token + exitFarmLockedToken => exit_farm_locked_token + farmClaimRewardsLockedToken => farm_claim_rewards_locked_token + getKnownFarms => known_farms + getFarmProxyTokenId => farm_proxy_token ) } + +multiversx_sc_wasm_adapter::async_callback! { simple_lock }