From 4ad9758127e3c21c095175411105d5fcd8eb83da Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 15 Aug 2023 01:31:04 +0300 Subject: [PATCH 01/58] farm position functionality --- common/modules/farm/farm_base_impl/Cargo.toml | 3 + .../farm/farm_base_impl/src/claim_rewards.rs | 7 +- .../farm_base_impl/src/compound_rewards.rs | 7 +- .../farm/farm_base_impl/src/enter_farm.rs | 6 + .../farm/farm_base_impl/src/exit_farm.rs | 5 +- common/modules/farm/farm_base_impl/src/lib.rs | 1 + common/modules/farm/farm_position/Cargo.toml | 27 +++++ .../farm/farm_position/src/farm_position.rs | 103 ++++++++++++++++++ dex/farm-with-locked-rewards/Cargo.toml | 3 + dex/farm-with-locked-rewards/elrond.json | 3 - dex/farm-with-locked-rewards/src/lib.rs | 1 + dex/farm-with-locked-rewards/wasm/Cargo.lock | 15 +++ dex/farm-with-locked-rewards/wasm/src/lib.rs | 7 +- dex/farm/Cargo.toml | 3 + dex/farm/src/base_functions.rs | 13 ++- dex/farm/src/claim_boost_only.rs | 32 ++++++ dex/farm/src/lib.rs | 1 + dex/farm/wasm/Cargo.lock | 14 +++ dex/farm/wasm/src/lib.rs | 7 +- 19 files changed, 246 insertions(+), 12 deletions(-) create mode 100644 common/modules/farm/farm_position/Cargo.toml create mode 100644 common/modules/farm/farm_position/src/farm_position.rs delete mode 100644 dex/farm-with-locked-rewards/elrond.json diff --git a/common/modules/farm/farm_base_impl/Cargo.toml b/common/modules/farm/farm_base_impl/Cargo.toml index db5644507..91ac14e3d 100644 --- a/common/modules/farm/farm_base_impl/Cargo.toml +++ b/common/modules/farm/farm_base_impl/Cargo.toml @@ -12,6 +12,9 @@ path = "../config" [dependencies.farm_token] path = "../farm_token" +[dependencies.farm_position] +path = "../farm_position" + [dependencies.rewards] path = "../rewards" diff --git a/common/modules/farm/farm_base_impl/src/claim_rewards.rs b/common/modules/farm/farm_base_impl/src/claim_rewards.rs index 256828ca3..a00eb7fac 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -26,6 +26,7 @@ pub trait BaseClaimRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -58,11 +59,15 @@ pub trait BaseClaimRewardsModule: self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); let claim_rewards_context = ClaimRewardsContext::::new( - payments, + payments.clone(), &storage_cache.farm_token_id, self.blockchain(), ); + for payment in &payments { + self.check_and_update_user_farm_position(&caller, &payment); + } + FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &claim_rewards_context.first_farm_token.payment.amount; diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index 0b17976f4..db4221970 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -27,6 +27,7 @@ pub trait BaseCompoundRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -46,11 +47,15 @@ pub trait BaseCompoundRewardsModule: ); let compound_rewards_context = CompoundRewardsContext::::new( - payments, + payments.clone(), &storage_cache.farm_token_id, self.blockchain(), ); + for payment in &payments { + self.check_and_update_user_farm_position(&caller, &payment); + } + FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &compound_rewards_context.first_farm_token.payment.amount; diff --git a/common/modules/farm/farm_base_impl/src/enter_farm.rs b/common/modules/farm/farm_base_impl/src/enter_farm.rs index 79f9e5df9..a7b763eac 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -24,6 +24,7 @@ pub trait BaseEnterFarmModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -44,6 +45,11 @@ pub trait BaseEnterFarmModule: &storage_cache.farm_token_id, ); + for additional_payment in &enter_farm_context.additional_farm_tokens { + self.check_and_update_user_farm_position(&caller, &additional_payment); + } + self.increase_user_farm_position(&caller, &enter_farm_context.farming_token_payment.amount); + FC::generate_aggregated_rewards(self, &mut storage_cache); storage_cache.farm_token_supply += &enter_farm_context.farming_token_payment.amount; 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 c60dd7a73..a058f6a55 100644 --- a/common/modules/farm/farm_base_impl/src/exit_farm.rs +++ b/common/modules/farm/farm_base_impl/src/exit_farm.rs @@ -24,6 +24,7 @@ pub trait BaseExitFarmModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -39,11 +40,13 @@ pub trait BaseExitFarmModule: self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); let exit_farm_context = ExitFarmContext::::new( - payment, + payment.clone(), &storage_cache.farm_token_id, self.blockchain(), ); + self.decrease_user_farm_position(&payment); + FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &exit_farm_context.farm_token.payment.amount; diff --git a/common/modules/farm/farm_base_impl/src/lib.rs b/common/modules/farm/farm_base_impl/src/lib.rs index f63df2820..a3449779a 100644 --- a/common/modules/farm/farm_base_impl/src/lib.rs +++ b/common/modules/farm/farm_base_impl/src/lib.rs @@ -21,6 +21,7 @@ pub trait FarmBaseImpl: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + events::EventsModule diff --git a/common/modules/farm/farm_position/Cargo.toml b/common/modules/farm/farm_position/Cargo.toml new file mode 100644 index 000000000..c3b8beda4 --- /dev/null +++ b/common/modules/farm/farm_position/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "farm_position" +version = "0.0.0" +authors = ["MultiversX "] +edition = "2021" + +[lib] +path = "src/farm_position.rs" + +[dependencies.multiversx-sc] +version = "=0.39.4" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.multiversx-sc-modules] +version = "=0.39.4" + +[dependencies.farm_token] +path = "../farm_token" + +[dependencies.utils] +path = "../../utils" + +[dependencies.permissions_module] +path = "../../permissions_module" + +[dependencies.common_structs] +path = "../../../common_structs" diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs new file mode 100644 index 000000000..24a998a8a --- /dev/null +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -0,0 +1,103 @@ +#![no_std] + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::FarmTokenAttributes; + +#[multiversx_sc::module] +pub trait FarmPositionModule: + farm_token::FarmTokenModule + + utils::UtilsModule + + permissions_module::PermissionsModule + + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule +{ + #[payable("*")] + #[endpoint(updateTotalFarmPosition)] + fn update_total_farm_position(&self) { + let caller = self.blockchain().get_caller(); + let payments = self.get_non_empty_payments(); + let farm_token_mapper = self.farm_token(); + let farm_token_id = farm_token_mapper.get_token_id(); + let mut new_total_farm_position = BigUint::zero(); + for farm_position in &payments { + require!( + farm_position.token_identifier == farm_token_id, + "Bad payment token" + ); + let token_attributes: FarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner != &caller { + self.user_total_farm_position(&token_attributes.original_owner) + .update(|user_farm_position| { + if *user_farm_position > farm_position.amount { + *user_farm_position -= &farm_position.amount; + } else { + *user_farm_position = BigUint::zero(); + } + }); + } + + new_total_farm_position += farm_position.amount; + } + + let user_current_farm_position = self.user_total_farm_position(&caller).get(); + if new_total_farm_position > user_current_farm_position { + self.user_total_farm_position(&caller) + .set(new_total_farm_position) + } + } + + fn check_and_update_user_farm_position( + &self, + user: &ManagedAddress, + farm_position: &EsdtTokenPayment, + ) { + let farm_token_mapper = self.farm_token(); + let token_attributes: FarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner != user { + self.user_total_farm_position(&token_attributes.original_owner) + .update(|user_farm_position| { + if *user_farm_position > farm_position.amount { + *user_farm_position -= &farm_position.amount; + } else { + *user_farm_position = BigUint::zero(); + } + }); + + self.user_total_farm_position(user) + .update(|user_farm_position| *user_farm_position += &farm_position.amount); + } + } + + fn increase_user_farm_position( + &self, + user: &ManagedAddress, + new_farm_position_amount: &BigUint, + ) { + self.user_total_farm_position(user) + .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + } + + fn decrease_user_farm_position(&self, farm_position: &EsdtTokenPayment) { + let farm_token_mapper = self.farm_token(); + let token_attributes: FarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + self.user_total_farm_position(&token_attributes.original_owner) + .update(|user_farm_position| { + if *user_farm_position > farm_position.amount { + *user_farm_position -= &farm_position.amount; + } else { + *user_farm_position = BigUint::zero(); + } + }); + } + + #[view(getUserTotalFarmPosition)] + #[storage_mapper("userTotalFarmPosition")] + fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; +} diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index 3052499d2..b5abb39a5 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -16,6 +16,9 @@ path = "../../common/modules/farm/config" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" +[dependencies.farm_position] +path = "../../common/modules/farm/farm_position" + [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/dex/farm-with-locked-rewards/elrond.json b/dex/farm-with-locked-rewards/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/dex/farm-with-locked-rewards/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 0bfbff59b..663d51783 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -26,6 +26,7 @@ pub trait Farm: + token_send::TokenSendModule + locking_module::lock_with_energy_module::LockWithEnergyModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + utils::UtilsModule + pausable::PausableModule + permissions_module::PermissionsModule diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 83649b5f2..9242ee202 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -198,6 +199,7 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "locking_module", @@ -231,6 +233,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -244,6 +247,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index d4f9e0650..906ec4642 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 62 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 64 +// Total number of exported functions: 67 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -40,6 +40,8 @@ multiversx_sc_wasm_adapter::endpoints! { registerFarmToken getFarmTokenId getFarmTokenSupply + updateTotalFarmPosition + getUserTotalFarmPosition addToPauseWhitelist removeFromPauseWhitelist pause @@ -59,6 +61,7 @@ multiversx_sc_wasm_adapter::endpoints! { getMinimumFarmingEpoch getBurnGasLimit getPairContractManagedAddress + claimBoostedRewards setBoostedYieldsRewardsPercentage collectUndistributedBoostedRewards getBoostedYieldsRewardsPercentage diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index f2cca8bf7..4e30b4394 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -16,6 +16,9 @@ path = "../../common/modules/farm/config" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" +[dependencies.farm_position] +path = "../../common/modules/farm/farm_position" + [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 317ae4c1c..9108dd5cb 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -47,6 +47,7 @@ pub trait BaseFunctionsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + events::EventsModule @@ -186,6 +187,11 @@ pub trait BaseFunctionsModule: let token_mapper = self.farm_token(); token_mapper.require_all_same_token(&payments); + let caller = self.blockchain().get_caller(); + for payment in &payments { + self.check_and_update_user_farm_position(&caller, &payment); + } + let output_attributes: FC::AttributesType = self.merge_from_payments_and_burn(payments, &token_mapper); let new_token_amount = output_attributes.get_total_supply(); @@ -236,15 +242,18 @@ where sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, token_attributes: &::AttributesType, - farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, + _farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { if &token_attributes.original_owner != caller { sc.update_energy_and_progress(caller); + } + let user_total_farm_position_mapper = sc.user_total_farm_position(caller); + if user_total_farm_position_mapper.is_empty() { return BigUint::zero(); } - sc.claim_boosted_yields_rewards(caller, farm_token_amount) + sc.claim_boosted_yields_rewards(caller, user_total_farm_position_mapper.get()) } } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 88d445df8..6cd8c2ca1 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -7,6 +7,7 @@ pub trait ClaimBoostOnlyModule: config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + week_timekeeping::WeekTimekeepingModule + pausable::PausableModule @@ -31,6 +32,37 @@ pub trait ClaimBoostOnlyModule: + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule + crate::base_functions::BaseFunctionsModule { + #[payable("*")] + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_orig_caller: OptionalValue, + ) -> EsdtTokenPayment { + let orig_caller = match opt_orig_caller { + OptionalValue::Some(orig_caller) => orig_caller, + OptionalValue::None => self.blockchain().get_caller(), + }; + + let reward_token_id = self.reward_token_id().get(); + let user_total_farm_position_mapper = self.user_total_farm_position(&orig_caller); + if user_total_farm_position_mapper.is_empty() { + return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); + } + + let reward = + self.claim_boosted_yields_rewards(&orig_caller, user_total_farm_position_mapper.get()); + if reward > 0 { + self.reward_reserve().update(|reserve| *reserve -= &reward); + } + + let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); + self.send_payment_non_zero(&orig_caller, &boosted_rewards); + + self.update_energy_and_progress(&orig_caller); + + boosted_rewards + } + fn claim_only_boosted_payment( &self, caller: &ManagedAddress, diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 34975a2a5..e2a4fe30d 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -30,6 +30,7 @@ pub trait Farm: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + sc_whitelist_module::SCWhitelistModule diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 97ea7e292..210fdddf6 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -201,6 +202,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -214,6 +216,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 9ec1c0a1c..00b4b4931 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 59 +// Endpoints: 62 // Async Callback: 1 -// Total number of exported functions: 61 +// Total number of exported functions: 64 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -37,6 +37,8 @@ multiversx_sc_wasm_adapter::endpoints! { registerFarmToken getFarmTokenId getFarmTokenSupply + updateTotalFarmPosition + getUserTotalFarmPosition addToPauseWhitelist removeFromPauseWhitelist pause @@ -56,6 +58,7 @@ multiversx_sc_wasm_adapter::endpoints! { getMinimumFarmingEpoch getBurnGasLimit getPairContractManagedAddress + claimBoostedRewards setBoostedYieldsRewardsPercentage collectUndistributedBoostedRewards getBoostedYieldsRewardsPercentage From b4c924cd09aead57509216246c8f4d8f145776d1 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 15 Aug 2023 01:37:26 +0300 Subject: [PATCH 02/58] updateTotalFarmPosition endpoint fix --- common/modules/farm/farm_position/src/farm_position.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index 24a998a8a..60cba3c2c 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -47,6 +47,8 @@ pub trait FarmPositionModule: self.user_total_farm_position(&caller) .set(new_total_farm_position) } + + self.send().direct_multi(&caller, &payments); } fn check_and_update_user_farm_position( From 667c19ad806606b3d0010ca4dd326ad3f06bfd3d Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 15 Aug 2023 01:44:12 +0300 Subject: [PATCH 03/58] clippy fix --- common/modules/farm/farm_position/src/farm_position.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index 60cba3c2c..d5bb3e009 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -28,7 +28,7 @@ pub trait FarmPositionModule: let token_attributes: FarmTokenAttributes = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if &token_attributes.original_owner != &caller { + if token_attributes.original_owner != caller { self.user_total_farm_position(&token_attributes.original_owner) .update(|user_farm_position| { if *user_farm_position > farm_position.amount { From 8348f525323835ae6e4d5baa504f4ee3fa8a99f3 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 15 Aug 2023 16:59:01 +0300 Subject: [PATCH 04/58] fixes after review --- .../farm/farm_base_impl/src/claim_rewards.rs | 4 +- .../farm_base_impl/src/compound_rewards.rs | 4 +- .../farm/farm_base_impl/src/enter_farm.rs | 8 ++-- .../farm/farm_position/src/farm_position.rs | 48 ++++++++++++------- dex/farm-with-locked-rewards/wasm/src/lib.rs | 6 ++- dex/farm/src/base_functions.rs | 12 +---- dex/farm/src/claim_boost_only.rs | 30 ++++++------ dex/farm/wasm/src/lib.rs | 6 ++- 8 files changed, 63 insertions(+), 55 deletions(-) diff --git a/common/modules/farm/farm_base_impl/src/claim_rewards.rs b/common/modules/farm/farm_base_impl/src/claim_rewards.rs index a00eb7fac..11ba65338 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -64,9 +64,7 @@ pub trait BaseClaimRewardsModule: self.blockchain(), ); - for payment in &payments { - self.check_and_update_user_farm_position(&caller, &payment); - } + self.check_and_update_user_farm_position(&caller, &payments); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index db4221970..5fbed98d4 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -52,9 +52,7 @@ pub trait BaseCompoundRewardsModule: self.blockchain(), ); - for payment in &payments { - self.check_and_update_user_farm_position(&caller, &payment); - } + self.check_and_update_user_farm_position(&caller, &payments); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_base_impl/src/enter_farm.rs b/common/modules/farm/farm_base_impl/src/enter_farm.rs index a7b763eac..15bc9c2fa 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -45,9 +45,11 @@ pub trait BaseEnterFarmModule: &storage_cache.farm_token_id, ); - for additional_payment in &enter_farm_context.additional_farm_tokens { - self.check_and_update_user_farm_position(&caller, &additional_payment); - } + // The order is important - first check and update, then increase position + self.check_and_update_user_farm_position( + &caller, + &enter_farm_context.additional_farm_tokens, + ); self.increase_user_farm_position(&caller, &enter_farm_context.farming_token_payment.amount); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index d5bb3e009..ad34e4147 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -3,7 +3,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use common_structs::FarmTokenAttributes; +use common_structs::{FarmTokenAttributes, PaymentsVec}; #[multiversx_sc::module] pub trait FarmPositionModule: @@ -51,27 +51,36 @@ pub trait FarmPositionModule: self.send().direct_multi(&caller, &payments); } + #[endpoint(setAllowExternalClaimBoostedRewards)] + fn set_allow_external_claim_boosted_rewards(&self, allow: bool) { + let caller = self.blockchain().get_caller(); + self.allow_external_claim_boosted_rewards(&caller) + .set(allow); + } + fn check_and_update_user_farm_position( &self, user: &ManagedAddress, - farm_position: &EsdtTokenPayment, + farm_positions: &PaymentsVec, ) { let farm_token_mapper = self.farm_token(); - let token_attributes: FarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); + let mut total_farm_position = BigUint::zero(); + let mut farm_position_increase = BigUint::zero(); + for farm_position in farm_positions { + total_farm_position += &farm_position.amount; + let token_attributes: FarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if &token_attributes.original_owner != user { - self.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position| { - if *user_farm_position > farm_position.amount { - *user_farm_position -= &farm_position.amount; - } else { - *user_farm_position = BigUint::zero(); - } - }); - - self.user_total_farm_position(user) - .update(|user_farm_position| *user_farm_position += &farm_position.amount); + if &token_attributes.original_owner != user { + self.decrease_user_farm_position(&farm_position); + farm_position_increase += &farm_position.amount; + } + } + + if self.user_total_farm_position(user).get() == 0 { + self.increase_user_farm_position(user, &total_farm_position); + } else if farm_position_increase > 0 { + self.increase_user_farm_position(user, &farm_position_increase); } } @@ -102,4 +111,11 @@ pub trait FarmPositionModule: #[view(getUserTotalFarmPosition)] #[storage_mapper("userTotalFarmPosition")] fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; + + #[view(getAllowExternalClaimBoostedRewards)] + #[storage_mapper("allowExternalClaimBoostedRewards")] + fn allow_external_claim_boosted_rewards( + &self, + user: &ManagedAddress, + ) -> SingleValueMapper; } diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index 906ec4642..e679e068f 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 65 +// Endpoints: 67 // Async Callback: 1 -// Total number of exported functions: 67 +// Total number of exported functions: 69 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -41,7 +41,9 @@ multiversx_sc_wasm_adapter::endpoints! { getFarmTokenId getFarmTokenSupply updateTotalFarmPosition + setAllowExternalClaimBoostedRewards getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards addToPauseWhitelist removeFromPauseWhitelist pause diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 9108dd5cb..4557de643 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -188,9 +188,7 @@ pub trait BaseFunctionsModule: token_mapper.require_all_same_token(&payments); let caller = self.blockchain().get_caller(); - for payment in &payments { - self.check_and_update_user_farm_position(&caller, &payment); - } + self.check_and_update_user_farm_position(&caller, &payments); let output_attributes: FC::AttributesType = self.merge_from_payments_and_burn(payments, &token_mapper); @@ -242,7 +240,6 @@ where sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, token_attributes: &::AttributesType, - _farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { if &token_attributes.original_owner != caller { sc.update_energy_and_progress(caller); @@ -297,12 +294,7 @@ where token_attributes, storage_cache, ); - let boosted_yield_rewards = Self::calculate_boosted_rewards( - sc, - caller, - token_attributes, - farm_token_amount.clone(), - ); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller, token_attributes); base_farm_reward + boosted_yield_rewards } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 6cd8c2ca1..7d8c320b5 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -34,31 +34,34 @@ pub trait ClaimBoostOnlyModule: { #[payable("*")] #[endpoint(claimBoostedRewards)] - fn claim_boosted_rewards( - &self, - opt_orig_caller: OptionalValue, - ) -> EsdtTokenPayment { - let orig_caller = match opt_orig_caller { - OptionalValue::Some(orig_caller) => orig_caller, + fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { + let user = match opt_user { + OptionalValue::Some(user) => { + require!( + self.allow_external_claim_boosted_rewards(&user).get(), + "Cannot claim rewards for this address" + ); + user + } OptionalValue::None => self.blockchain().get_caller(), }; let reward_token_id = self.reward_token_id().get(); - let user_total_farm_position_mapper = self.user_total_farm_position(&orig_caller); + let user_total_farm_position_mapper = self.user_total_farm_position(&user); if user_total_farm_position_mapper.is_empty() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } let reward = - self.claim_boosted_yields_rewards(&orig_caller, user_total_farm_position_mapper.get()); + self.claim_boosted_yields_rewards(&user, user_total_farm_position_mapper.get()); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); - self.send_payment_non_zero(&orig_caller, &boosted_rewards); + self.send_payment_non_zero(&user, &boosted_rewards); - self.update_energy_and_progress(&orig_caller); + self.update_energy_and_progress(&user); boosted_rewards } @@ -73,12 +76,7 @@ pub trait ClaimBoostOnlyModule: let token_attributes = self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = Wrapper::::calculate_boosted_rewards( - self, - caller, - &token_attributes, - payment.amount.clone(), - ); + let reward = Wrapper::::calculate_boosted_rewards(self, caller, &token_attributes); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 00b4b4931..9b312e5e1 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 62 +// Endpoints: 64 // Async Callback: 1 -// Total number of exported functions: 64 +// Total number of exported functions: 66 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -38,7 +38,9 @@ multiversx_sc_wasm_adapter::endpoints! { getFarmTokenId getFarmTokenSupply updateTotalFarmPosition + setAllowExternalClaimBoostedRewards getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards addToPauseWhitelist removeFromPauseWhitelist pause From 5d2d0201205d5af40cc91edfcf3ebc3a1dcc9741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 22 Aug 2023 11:54:56 +0300 Subject: [PATCH 05/58] Fixes after review --- .../farm/farm_position/src/farm_position.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index ad34e4147..3762698c4 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -29,14 +29,7 @@ pub trait FarmPositionModule: farm_token_mapper.get_token_attributes(farm_position.token_nonce); if token_attributes.original_owner != caller { - self.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position| { - if *user_farm_position > farm_position.amount { - *user_farm_position -= &farm_position.amount; - } else { - *user_farm_position = BigUint::zero(); - } - }); + self.decrease_user_farm_position(&farm_position); } new_total_farm_position += farm_position.amount; @@ -64,9 +57,15 @@ pub trait FarmPositionModule: farm_positions: &PaymentsVec, ) { let farm_token_mapper = self.farm_token(); + let farm_token_id = farm_token_mapper.get_token_id(); let mut total_farm_position = BigUint::zero(); let mut farm_position_increase = BigUint::zero(); for farm_position in farm_positions { + require!( + farm_position.token_identifier == farm_token_id, + "Bad payment token" + ); + total_farm_position += &farm_position.amount; let token_attributes: FarmTokenAttributes = farm_token_mapper.get_token_attributes(farm_position.token_nonce); From 5e05e327c85116333a48a47ad3dbca81f7ec7962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 22 Aug 2023 12:40:11 +0300 Subject: [PATCH 06/58] farm-staking: Fixed module dependencies --- farm-staking/farm-staking/Cargo.toml | 3 +++ farm-staking/farm-staking/src/claim_stake_farm_rewards.rs | 1 + farm-staking/farm-staking/src/compound_stake_farm_rewards.rs | 1 + farm-staking/farm-staking/src/lib.rs | 1 + farm-staking/farm-staking/src/stake_farm.rs | 1 + farm-staking/farm-staking/src/unstake_farm.rs | 1 + 6 files changed, 8 insertions(+) diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index d4d155aee..d8e0202f1 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -31,6 +31,9 @@ path = "../../common/modules/farm/farm_base_impl" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" +[dependencies.farm_position] +path = "../../common/modules/farm/farm_position" + [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index f8bef0283..831e70564 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -16,6 +16,7 @@ pub trait ClaimStakeFarmRewardsModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::claim_rewards::BaseClaimRewardsModule diff --git a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs index e51f3b66e..e2e08485f 100644 --- a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs @@ -14,6 +14,7 @@ pub trait CompoundStakeFarmRewardsModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::compound_rewards::BaseCompoundRewardsModule diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index d1874d0b4..256013d52 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -34,6 +34,7 @@ pub trait FarmStaking: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index a50dca4b8..d662c81a6 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -18,6 +18,7 @@ pub trait StakeFarmModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 4c9675153..4b9af2666 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -18,6 +18,7 @@ pub trait UnstakeFarmModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::exit_farm::BaseExitFarmModule From 4f6bbd3682bb215e22faf8733129a1a2e94160e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 23 Aug 2023 09:19:29 +0300 Subject: [PATCH 07/58] farm-staking: farm position functionality --- .../farm/farm_position/src/farm_position.rs | 13 ++----- .../farm-staking/src/base_impl_wrapper.rs | 9 ++--- .../src/claim_only_boosted_staking_rewards.rs | 36 ++++++++++++++++++- .../farm-staking/src/custom_rewards.rs | 2 ++ farm-staking/farm-staking/src/unbond_farm.rs | 1 + 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index 3762698c4..739f7e9e3 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -18,13 +18,10 @@ pub trait FarmPositionModule: let caller = self.blockchain().get_caller(); let payments = self.get_non_empty_payments(); let farm_token_mapper = self.farm_token(); - let farm_token_id = farm_token_mapper.get_token_id(); let mut new_total_farm_position = BigUint::zero(); for farm_position in &payments { - require!( - farm_position.token_identifier == farm_token_id, - "Bad payment token" - ); + farm_token_mapper.require_same_token(&farm_position.token_identifier); + let token_attributes: FarmTokenAttributes = farm_token_mapper.get_token_attributes(farm_position.token_nonce); @@ -57,14 +54,10 @@ pub trait FarmPositionModule: farm_positions: &PaymentsVec, ) { let farm_token_mapper = self.farm_token(); - let farm_token_id = farm_token_mapper.get_token_id(); let mut total_farm_position = BigUint::zero(); let mut farm_position_increase = BigUint::zero(); for farm_position in farm_positions { - require!( - farm_position.token_identifier == farm_token_id, - "Bad payment token" - ); + farm_token_mapper.require_same_token(&farm_position.token_identifier); total_farm_position += &farm_position.amount; let token_attributes: FarmTokenAttributes = diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 1d25e1cdc..4165a2314 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -13,6 +13,7 @@ pub trait FarmStakingTraits = + rewards::RewardsModule + config::ConfigModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -47,15 +48,16 @@ where sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, token_attributes: &::AttributesType, - farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { if &token_attributes.original_owner != caller { sc.update_energy_and_progress(caller); - + } + let user_total_farm_position_mapper = sc.user_total_farm_position(caller); + if user_total_farm_position_mapper.is_empty() { return BigUint::zero(); } - sc.claim_boosted_yields_rewards(caller, farm_token_amount) + sc.claim_boosted_yields_rewards(caller, user_total_farm_position_mapper.get()) } } @@ -138,7 +140,6 @@ where sc, caller, token_attributes, - farm_token_amount.clone(), ); base_farm_reward + boosted_yield_rewards 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 a41cb1249..e58669a04 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 @@ -7,6 +7,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + week_timekeeping::WeekTimekeepingModule + pausable::PausableModule @@ -24,6 +25,40 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule + crate::custom_rewards::CustomRewardsModule { + #[payable("*")] + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { + let user = match opt_user { + OptionalValue::Some(user) => { + require!( + self.allow_external_claim_boosted_rewards(&user).get(), + "Cannot claim rewards for this address" + ); + user + } + OptionalValue::None => self.blockchain().get_caller(), + }; + + let reward_token_id = self.reward_token_id().get(); + let user_total_farm_position_mapper = self.user_total_farm_position(&user); + if user_total_farm_position_mapper.is_empty() { + return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); + } + + let reward = + self.claim_boosted_yields_rewards(&user, user_total_farm_position_mapper.get()); + if reward > 0 { + self.reward_reserve().update(|reserve| *reserve -= &reward); + } + + let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); + self.send_payment_non_zero(&user, &boosted_rewards); + + self.update_energy_and_progress(&user); + + boosted_rewards + } + // Cannot import the one from farm, as the Wrapper struct has different dependencies fn claim_only_boosted_payment( &self, @@ -39,7 +74,6 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: self, caller, &token_attributes, - payment.amount.clone(), ); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); diff --git a/farm-staking/farm-staking/src/custom_rewards.rs b/farm-staking/farm-staking/src/custom_rewards.rs index 64bf431ee..79689b96b 100644 --- a/farm-staking/farm-staking/src/custom_rewards.rs +++ b/farm-staking/farm-staking/src/custom_rewards.rs @@ -17,6 +17,8 @@ pub trait CustomRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + + utils::UtilsModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/farm-staking/farm-staking/src/unbond_farm.rs b/farm-staking/farm-staking/src/unbond_farm.rs index 7e85a2a2c..f6ee2d96c 100644 --- a/farm-staking/farm-staking/src/unbond_farm.rs +++ b/farm-staking/farm-staking/src/unbond_farm.rs @@ -12,6 +12,7 @@ pub trait UnbondFarmModule: + events::EventsModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + farm_position::FarmPositionModule + sc_whitelist_module::SCWhitelistModule + pausable::PausableModule + permissions_module::PermissionsModule From 97b52fabfa773ddb235cbf822de9f2eed704ea57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 23 Aug 2023 09:34:35 +0300 Subject: [PATCH 08/58] farm_position: compilation dependencies --- dex/pair-mock/wasm/src/lib.rs | 2 +- dex/proxy-deployer/wasm/Cargo.lock | 14 ++++++++++++++ energy-integration/energy-update/wasm/Cargo.lock | 14 ++++++++++++++ farm-staking/farm-staking-proxy/wasm/Cargo.lock | 15 +++++++++++++++ farm-staking/farm-staking/wasm/Cargo.lock | 15 +++++++++++++++ farm-staking/farm-staking/wasm/src/lib.rs | 9 +++++++-- locked-asset/proxy_dex/wasm/Cargo.lock | 15 +++++++++++++++ 7 files changed, 81 insertions(+), 3 deletions(-) diff --git a/dex/pair-mock/wasm/src/lib.rs b/dex/pair-mock/wasm/src/lib.rs index 0634dae52..54b9b427e 100644 --- a/dex/pair-mock/wasm/src/lib.rs +++ b/dex/pair-mock/wasm/src/lib.rs @@ -19,7 +19,7 @@ multiversx_sc_wasm_adapter::endpoints! { pair_mock ( addInitialLiquidity - updateAndGetTokensForGivenPositionWithSafePrice + getTokensForGivenPositionWithSafePrice ) } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 3d762a9be..63cde5917 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -193,6 +194,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -206,6 +208,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 5173db1ce..55e0dd4b1 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -172,6 +172,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -211,6 +212,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -224,6 +226,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index 6b8cfa51d..d4a937ad4 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -198,6 +199,7 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "math", @@ -254,6 +256,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -267,6 +270,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 4584bdf1a..0d71b7fcd 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -198,6 +199,7 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "math", @@ -232,6 +234,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -245,6 +248,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index f168969c1..da5f11351 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Endpoints: 69 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 71 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -52,6 +52,10 @@ multiversx_sc_wasm_adapter::endpoints! { removeAdmin updateOwnerOrAdmin getPermissions + updateTotalFarmPosition + setAllowExternalClaimBoostedRewards + getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards setBurnRoleForAddress stakeFarmThroughProxy stakeFarm @@ -61,6 +65,7 @@ multiversx_sc_wasm_adapter::endpoints! { unstakeFarm unstakeFarmThroughProxy unbondFarm + claimBoostedRewards setBoostedYieldsRewardsPercentage collectUndistributedBoostedRewards getBoostedYieldsRewardsPercentage diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index fe099d430..7ff19d6d2 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -198,6 +199,7 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", + "farm_position", "farm_token", "fixed-supply-token", "locking_module", @@ -223,6 +225,7 @@ dependencies = [ "config", "contexts", "events", + "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -236,6 +239,18 @@ dependencies = [ "utils", ] +[[package]] +name = "farm_position" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "permissions_module", + "utils", +] + [[package]] name = "farm_token" version = "0.0.0" From b70b0de3308c1d8c66d2cad8ce55d3461a279aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 23 Aug 2023 15:05:41 +0300 Subject: [PATCH 09/58] farm-staking: Fix tests --- common/modules/farm/config/src/config.rs | 12 ++ .../farm_base_impl/src/base_traits_impl.rs | 56 +++++ .../farm/farm_base_impl/src/claim_rewards.rs | 3 +- .../farm_base_impl/src/compound_rewards.rs | 3 +- .../farm/farm_base_impl/src/enter_farm.rs | 5 +- .../farm/farm_base_impl/src/exit_farm.rs | 3 +- common/modules/farm/farm_base_impl/src/lib.rs | 1 - .../farm/farm_position/src/farm_position.rs | 197 +++++++++--------- dex/farm-with-locked-rewards/src/lib.rs | 1 - dex/farm-with-locked-rewards/wasm/src/lib.rs | 10 +- dex/farm/src/base_functions.rs | 4 +- dex/farm/src/claim_boost_only.rs | 9 +- dex/farm/src/lib.rs | 1 - dex/farm/wasm/src/lib.rs | 10 +- .../governance-v2/wasm/src/lib.rs | 6 +- .../farm-staking/src/base_impl_wrapper.rs | 59 +++++- .../src/claim_only_boosted_staking_rewards.rs | 1 - .../src/claim_stake_farm_rewards.rs | 1 - .../src/compound_stake_farm_rewards.rs | 1 - .../farm-staking/src/custom_rewards.rs | 1 - farm-staking/farm-staking/src/lib.rs | 1 - farm-staking/farm-staking/src/stake_farm.rs | 1 - farm-staking/farm-staking/src/unbond_farm.rs | 1 - farm-staking/farm-staking/src/unstake_farm.rs | 1 - farm-staking/farm-staking/wasm/src/lib.rs | 10 +- 25 files changed, 252 insertions(+), 146 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 38606f280..bd80456ff 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -38,4 +38,16 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio #[view(getDivisionSafetyConstant)] #[storage_mapper("division_safety_constant")] fn division_safety_constant(&self) -> SingleValueMapper; + + #[view(getUserTotalFarmPosition)] + #[storage_mapper("userTotalFarmPosition")] + fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; + + #[view(getAllowExternalClaimBoostedRewards)] + #[storage_mapper("allowExternalClaimBoostedRewards")] + fn allow_external_claim_boosted_rewards( + &self, + user: &ManagedAddress, + ) -> SingleValueMapper; + } diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index eaa86c5ac..7839efbbf 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -6,6 +6,7 @@ use contexts::storage_cache::StorageCache; use core::marker::PhantomData; use fixed_supply_token::FixedSupplyToken; use mergeable::Mergeable; +use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use rewards::RewardsModule; pub trait AllBaseFarmImplTraits = @@ -187,6 +188,61 @@ pub trait FarmContract { _storage_cache: &StorageCache, ) { } + + fn check_and_update_user_farm_position( + sc: &Self::FarmSc, + user: &ManagedAddress<::Api>, + farm_positions: &PaymentsVec<::Api>, + ) { + let farm_token_mapper = sc.farm_token(); + let mut total_farm_position = BigUint::zero(); + let mut farm_position_increase = BigUint::zero(); + for farm_position in farm_positions { + farm_token_mapper.require_same_token(&farm_position.token_identifier); + + total_farm_position += &farm_position.amount; + let token_attributes: FarmTokenAttributes<::Api> = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner != user { + Self::decrease_user_farm_position(sc, &farm_position); + farm_position_increase += &farm_position.amount; + } + } + + if sc.user_total_farm_position(user).get() == 0 { + Self::increase_user_farm_position(sc, user, &total_farm_position); + } else if farm_position_increase > 0 { + Self::increase_user_farm_position(sc, user, &farm_position_increase); + } + } + + fn increase_user_farm_position( + sc: &Self::FarmSc, + user: &ManagedAddress<::Api>, + new_farm_position_amount: &BigUint<::Api>, + ) { + sc.user_total_farm_position(user) + .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + } + + fn decrease_user_farm_position( + sc: &Self::FarmSc, + farm_position: &EsdtTokenPayment<::Api>, + ) { + let farm_token_mapper = sc.farm_token(); + let token_attributes: FarmTokenAttributes<::Api> = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + sc.user_total_farm_position(&token_attributes.original_owner) + .update(|user_farm_position| { + if *user_farm_position > farm_position.amount { + *user_farm_position -= &farm_position.amount; + } else { + *user_farm_position = BigUint::zero(); + } + }); + } } pub struct DefaultFarmWrapper diff --git a/common/modules/farm/farm_base_impl/src/claim_rewards.rs b/common/modules/farm/farm_base_impl/src/claim_rewards.rs index 11ba65338..85b0e7ef6 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -26,7 +26,6 @@ pub trait BaseClaimRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -64,7 +63,7 @@ pub trait BaseClaimRewardsModule: self.blockchain(), ); - self.check_and_update_user_farm_position(&caller, &payments); + FC::check_and_update_user_farm_position(self, &caller, &payments); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index 5fbed98d4..6a00848a4 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -27,7 +27,6 @@ pub trait BaseCompoundRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -52,7 +51,7 @@ pub trait BaseCompoundRewardsModule: self.blockchain(), ); - self.check_and_update_user_farm_position(&caller, &payments); + FC::check_and_update_user_farm_position(self, &caller, &payments); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_base_impl/src/enter_farm.rs b/common/modules/farm/farm_base_impl/src/enter_farm.rs index 15bc9c2fa..e7628cf76 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -24,7 +24,6 @@ pub trait BaseEnterFarmModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -46,11 +45,11 @@ pub trait BaseEnterFarmModule: ); // The order is important - first check and update, then increase position - self.check_and_update_user_farm_position( + FC::check_and_update_user_farm_position(self, &caller, &enter_farm_context.additional_farm_tokens, ); - self.increase_user_farm_position(&caller, &enter_farm_context.farming_token_payment.amount); + FC::increase_user_farm_position(self, &caller, &enter_farm_context.farming_token_payment.amount); FC::generate_aggregated_rewards(self, &mut storage_cache); 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 a058f6a55..eefe7c65f 100644 --- a/common/modules/farm/farm_base_impl/src/exit_farm.rs +++ b/common/modules/farm/farm_base_impl/src/exit_farm.rs @@ -24,7 +24,6 @@ pub trait BaseExitFarmModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -45,7 +44,7 @@ pub trait BaseExitFarmModule: self.blockchain(), ); - self.decrease_user_farm_position(&payment); + FC::decrease_user_farm_position(self, &payment); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/common/modules/farm/farm_base_impl/src/lib.rs b/common/modules/farm/farm_base_impl/src/lib.rs index a3449779a..f63df2820 100644 --- a/common/modules/farm/farm_base_impl/src/lib.rs +++ b/common/modules/farm/farm_base_impl/src/lib.rs @@ -21,7 +21,6 @@ pub trait FarmBaseImpl: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + events::EventsModule diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs index 739f7e9e3..a7e12663c 100644 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ b/common/modules/farm/farm_position/src/farm_position.rs @@ -3,7 +3,6 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use common_structs::{FarmTokenAttributes, PaymentsVec}; #[multiversx_sc::module] pub trait FarmPositionModule: @@ -12,102 +11,102 @@ pub trait FarmPositionModule: + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule { - #[payable("*")] - #[endpoint(updateTotalFarmPosition)] - fn update_total_farm_position(&self) { - let caller = self.blockchain().get_caller(); - let payments = self.get_non_empty_payments(); - let farm_token_mapper = self.farm_token(); - let mut new_total_farm_position = BigUint::zero(); - for farm_position in &payments { - farm_token_mapper.require_same_token(&farm_position.token_identifier); - - let token_attributes: FarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if token_attributes.original_owner != caller { - self.decrease_user_farm_position(&farm_position); - } - - new_total_farm_position += farm_position.amount; - } - - let user_current_farm_position = self.user_total_farm_position(&caller).get(); - if new_total_farm_position > user_current_farm_position { - self.user_total_farm_position(&caller) - .set(new_total_farm_position) - } - - self.send().direct_multi(&caller, &payments); - } - - #[endpoint(setAllowExternalClaimBoostedRewards)] - fn set_allow_external_claim_boosted_rewards(&self, allow: bool) { - let caller = self.blockchain().get_caller(); - self.allow_external_claim_boosted_rewards(&caller) - .set(allow); - } - - fn check_and_update_user_farm_position( - &self, - user: &ManagedAddress, - farm_positions: &PaymentsVec, - ) { - let farm_token_mapper = self.farm_token(); - let mut total_farm_position = BigUint::zero(); - let mut farm_position_increase = BigUint::zero(); - for farm_position in farm_positions { - farm_token_mapper.require_same_token(&farm_position.token_identifier); - - total_farm_position += &farm_position.amount; - let token_attributes: FarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if &token_attributes.original_owner != user { - self.decrease_user_farm_position(&farm_position); - farm_position_increase += &farm_position.amount; - } - } - - if self.user_total_farm_position(user).get() == 0 { - self.increase_user_farm_position(user, &total_farm_position); - } else if farm_position_increase > 0 { - self.increase_user_farm_position(user, &farm_position_increase); - } - } - - fn increase_user_farm_position( - &self, - user: &ManagedAddress, - new_farm_position_amount: &BigUint, - ) { - self.user_total_farm_position(user) - .update(|user_farm_position| *user_farm_position += new_farm_position_amount); - } - - fn decrease_user_farm_position(&self, farm_position: &EsdtTokenPayment) { - let farm_token_mapper = self.farm_token(); - let token_attributes: FarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - self.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position| { - if *user_farm_position > farm_position.amount { - *user_farm_position -= &farm_position.amount; - } else { - *user_farm_position = BigUint::zero(); - } - }); - } - - #[view(getUserTotalFarmPosition)] - #[storage_mapper("userTotalFarmPosition")] - fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; - - #[view(getAllowExternalClaimBoostedRewards)] - #[storage_mapper("allowExternalClaimBoostedRewards")] - fn allow_external_claim_boosted_rewards( - &self, - user: &ManagedAddress, - ) -> SingleValueMapper; + // #[payable("*")] + // #[endpoint(updateTotalFarmPosition)] + // fn update_total_farm_position(&self) { + // let caller = self.blockchain().get_caller(); + // let payments = self.get_non_empty_payments(); + // let farm_token_mapper = self.farm_token(); + // let mut new_total_farm_position = BigUint::zero(); + // for farm_position in &payments { + // farm_token_mapper.require_same_token(&farm_position.token_identifier); + + // let token_attributes: FarmTokenAttributes = + // farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + // if token_attributes.original_owner != caller { + // self.decrease_user_farm_position(&farm_position); + // } + + // new_total_farm_position += farm_position.amount; + // } + + // let user_current_farm_position = self.user_total_farm_position(&caller).get(); + // if new_total_farm_position > user_current_farm_position { + // self.user_total_farm_position(&caller) + // .set(new_total_farm_position) + // } + + // self.send().direct_multi(&caller, &payments); + // } + + // #[endpoint(setAllowExternalClaimBoostedRewards)] + // fn set_allow_external_claim_boosted_rewards(&self, allow: bool) { + // let caller = self.blockchain().get_caller(); + // self.allow_external_claim_boosted_rewards(&caller) + // .set(allow); + // } + + // fn check_and_update_user_farm_position( + // &self, + // user: &ManagedAddress, + // farm_positions: &PaymentsVec, + // ) { + // let farm_token_mapper = self.farm_token(); + // let mut total_farm_position = BigUint::zero(); + // let mut farm_position_increase = BigUint::zero(); + // for farm_position in farm_positions { + // farm_token_mapper.require_same_token(&farm_position.token_identifier); + + // total_farm_position += &farm_position.amount; + // let token_attributes: FarmTokenAttributes = + // farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + // if &token_attributes.original_owner != user { + // self.decrease_user_farm_position(&farm_position); + // farm_position_increase += &farm_position.amount; + // } + // } + + // if self.user_total_farm_position(user).get() == 0 { + // self.increase_user_farm_position(user, &total_farm_position); + // } else if farm_position_increase > 0 { + // self.increase_user_farm_position(user, &farm_position_increase); + // } + // } + + // fn increase_user_farm_position( + // &self, + // user: &ManagedAddress, + // new_farm_position_amount: &BigUint, + // ) { + // self.user_total_farm_position(user) + // .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + // } + + // fn decrease_user_farm_position(&self, farm_position: &EsdtTokenPayment) { + // let farm_token_mapper = self.farm_token(); + // let token_attributes: FarmTokenAttributes = + // farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + // self.user_total_farm_position(&token_attributes.original_owner) + // .update(|user_farm_position| { + // if *user_farm_position > farm_position.amount { + // *user_farm_position -= &farm_position.amount; + // } else { + // *user_farm_position = BigUint::zero(); + // } + // }); + // } + + // #[view(getUserTotalFarmPosition)] + // #[storage_mapper("userTotalFarmPosition")] + // fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; + + // #[view(getAllowExternalClaimBoostedRewards)] + // #[storage_mapper("allowExternalClaimBoostedRewards")] + // fn allow_external_claim_boosted_rewards( + // &self, + // user: &ManagedAddress, + // ) -> SingleValueMapper; } diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 663d51783..0bfbff59b 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -26,7 +26,6 @@ pub trait Farm: + token_send::TokenSendModule + locking_module::lock_with_energy_module::LockWithEnergyModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + utils::UtilsModule + pausable::PausableModule + permissions_module::PermissionsModule diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index e679e068f..48baeb9fc 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 67 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 69 +// Total number of exported functions: 67 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -33,6 +33,8 @@ multiversx_sc_wasm_adapter::endpoints! { getPerBlockRewardAmount getLastRewardBlockNonce getDivisionSafetyConstant + getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards setLockingScAddress setLockEpochs getLockingScAddress @@ -40,10 +42,6 @@ multiversx_sc_wasm_adapter::endpoints! { registerFarmToken getFarmTokenId getFarmTokenSupply - updateTotalFarmPosition - setAllowExternalClaimBoostedRewards - getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards addToPauseWhitelist removeFromPauseWhitelist pause diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 4557de643..a243bac15 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -13,6 +13,7 @@ use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::{DefaultFarmWrapper, FarmContract}; use fixed_supply_token::FixedSupplyToken; + use crate::exit_penalty; pub type DoubleMultiPayment = MultiValue2, EsdtTokenPayment>; @@ -47,7 +48,6 @@ pub trait BaseFunctionsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + events::EventsModule @@ -188,7 +188,7 @@ pub trait BaseFunctionsModule: token_mapper.require_all_same_token(&payments); let caller = self.blockchain().get_caller(); - self.check_and_update_user_farm_position(&caller, &payments); + FC::check_and_update_user_farm_position(self, &caller, &payments); let output_attributes: FC::AttributesType = self.merge_from_payments_and_burn(payments, &token_mapper); diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 7d8c320b5..15fe9cb5a 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -1,5 +1,7 @@ multiversx_sc::imports!(); + + use crate::base_functions::Wrapper; #[multiversx_sc::module] @@ -7,7 +9,6 @@ pub trait ClaimBoostOnlyModule: config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + week_timekeeping::WeekTimekeepingModule + pausable::PausableModule @@ -34,7 +35,10 @@ pub trait ClaimBoostOnlyModule: { #[payable("*")] #[endpoint(claimBoostedRewards)] - fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { + fn claim_boosted_rewards( + &self, + opt_user: OptionalValue + ) -> EsdtTokenPayment { let user = match opt_user { OptionalValue::Some(user) => { require!( @@ -47,6 +51,7 @@ pub trait ClaimBoostOnlyModule: }; let reward_token_id = self.reward_token_id().get(); + let user_total_farm_position_mapper = self.user_total_farm_position(&user); if user_total_farm_position_mapper.is_empty() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index e2a4fe30d..34975a2a5 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -30,7 +30,6 @@ pub trait Farm: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + sc_whitelist_module::SCWhitelistModule diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 9b312e5e1..dbb8e6d3d 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Endpoints: 62 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 64 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -34,13 +34,11 @@ multiversx_sc_wasm_adapter::endpoints! { getPerBlockRewardAmount getLastRewardBlockNonce getDivisionSafetyConstant + getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards registerFarmToken getFarmTokenId getFarmTokenSupply - updateTotalFarmPosition - setAllowExternalClaimBoostedRewards - getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards addToPauseWhitelist removeFromPauseWhitelist pause diff --git a/energy-integration/governance-v2/wasm/src/lib.rs b/energy-integration/governance-v2/wasm/src/lib.rs index 5115397b6..6c2f6e7e2 100644 --- a/energy-integration/governance-v2/wasm/src/lib.rs +++ b/energy-integration/governance-v2/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 29 +// Endpoints: 27 // Async Callback (empty): 1 -// Total number of exported functions: 31 +// Total number of exported functions: 29 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -38,8 +38,6 @@ multiversx_sc_wasm_adapter::endpoints! { getUserVotedProposals getProposalVotes getProposalStatus - getUserVotingPower - getVotingPowerEquivalent getFeesCollectorAddress setEnergyFactoryAddress getEnergyFactoryAddress diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 4165a2314..25b41733d 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -5,6 +5,7 @@ use core::marker::PhantomData; use common_structs::FarmToken; use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::FarmContract; +use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use crate::token_attributes::StakingFarmTokenAttributes; @@ -13,7 +14,6 @@ pub trait FarmStakingTraits = + rewards::RewardsModule + config::ConfigModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -189,4 +189,61 @@ where original_owner: caller, } } + + + fn check_and_update_user_farm_position( + sc: &Self::FarmSc, + user: &ManagedAddress<::Api>, + farm_positions: &PaymentsVec<::Api>, + ) { + let farm_token_mapper = sc.farm_token(); + let mut total_farm_position = BigUint::zero(); + let mut farm_position_increase = BigUint::zero(); + for farm_position in farm_positions { + farm_token_mapper.require_same_token(&farm_position.token_identifier); + + total_farm_position += &farm_position.amount; + let token_attributes: StakingFarmTokenAttributes<::Api> = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner != user { + Self::decrease_user_farm_position(sc, &farm_position); + farm_position_increase += &farm_position.amount; + } + } + + if sc.user_total_farm_position(user).get() == 0 { + Self::increase_user_farm_position(sc, user, &total_farm_position); + } else if farm_position_increase > 0 { + Self::increase_user_farm_position(sc, user, &farm_position_increase); + } + } + + fn increase_user_farm_position( + sc: &Self::FarmSc, + user: &ManagedAddress<::Api>, + new_farm_position_amount: &BigUint<::Api>, + ) { + sc.user_total_farm_position(user) + .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + } + + fn decrease_user_farm_position( + sc: &Self::FarmSc, + farm_position: &EsdtTokenPayment<::Api>, + ) { + let farm_token_mapper = sc.farm_token(); + let token_attributes: StakingFarmTokenAttributes<::Api> = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + sc.user_total_farm_position(&token_attributes.original_owner) + .update(|user_farm_position| { + if *user_farm_position > farm_position.amount { + *user_farm_position -= &farm_position.amount; + } else { + *user_farm_position = BigUint::zero(); + } + }); + } + } 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 e58669a04..f69569933 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 @@ -7,7 +7,6 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + week_timekeeping::WeekTimekeepingModule + pausable::PausableModule diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index 831e70564..f8bef0283 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -16,7 +16,6 @@ pub trait ClaimStakeFarmRewardsModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::claim_rewards::BaseClaimRewardsModule diff --git a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs index e2e08485f..e51f3b66e 100644 --- a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs @@ -14,7 +14,6 @@ pub trait CompoundStakeFarmRewardsModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::compound_rewards::BaseCompoundRewardsModule diff --git a/farm-staking/farm-staking/src/custom_rewards.rs b/farm-staking/farm-staking/src/custom_rewards.rs index 79689b96b..4677cae1d 100644 --- a/farm-staking/farm-staking/src/custom_rewards.rs +++ b/farm-staking/farm-staking/src/custom_rewards.rs @@ -17,7 +17,6 @@ pub trait CustomRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + utils::UtilsModule + pausable::PausableModule + permissions_module::PermissionsModule diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 256013d52..d1874d0b4 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -34,7 +34,6 @@ pub trait FarmStaking: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index d662c81a6..a50dca4b8 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -18,7 +18,6 @@ pub trait StakeFarmModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule diff --git a/farm-staking/farm-staking/src/unbond_farm.rs b/farm-staking/farm-staking/src/unbond_farm.rs index f6ee2d96c..7e85a2a2c 100644 --- a/farm-staking/farm-staking/src/unbond_farm.rs +++ b/farm-staking/farm-staking/src/unbond_farm.rs @@ -12,7 +12,6 @@ pub trait UnbondFarmModule: + events::EventsModule + token_send::TokenSendModule + farm_token::FarmTokenModule - + farm_position::FarmPositionModule + sc_whitelist_module::SCWhitelistModule + pausable::PausableModule + permissions_module::PermissionsModule diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 4b9af2666..4c9675153 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -18,7 +18,6 @@ pub trait UnstakeFarmModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_position::FarmPositionModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::exit_farm::BaseExitFarmModule diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index da5f11351..f054fa567 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 69 +// Endpoints: 67 // Async Callback: 1 -// Total number of exported functions: 71 +// Total number of exported functions: 69 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -37,6 +37,8 @@ multiversx_sc_wasm_adapter::endpoints! { getPerBlockRewardAmount getLastRewardBlockNonce getDivisionSafetyConstant + getUserTotalFarmPosition + getAllowExternalClaimBoostedRewards registerFarmToken getFarmTokenId getFarmTokenSupply @@ -52,10 +54,6 @@ multiversx_sc_wasm_adapter::endpoints! { removeAdmin updateOwnerOrAdmin getPermissions - updateTotalFarmPosition - setAllowExternalClaimBoostedRewards - getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards setBurnRoleForAddress stakeFarmThroughProxy stakeFarm From 8997f70e4913ae7c5621538aef6479362dccd03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 23 Aug 2023 17:55:05 +0300 Subject: [PATCH 10/58] Remove farm-position code --- common/modules/farm/farm_base_impl/Cargo.toml | 3 - common/modules/farm/farm_position/Cargo.toml | 27 ----- .../farm/farm_position/src/farm_position.rs | 112 ------------------ dex/farm-with-locked-rewards/Cargo.toml | 3 - dex/farm-with-locked-rewards/wasm/Cargo.lock | 15 --- dex/farm/Cargo.toml | 3 - dex/farm/wasm/Cargo.lock | 14 --- dex/proxy-deployer/wasm/Cargo.lock | 14 --- .../energy-update/wasm/Cargo.lock | 14 --- .../farm-staking-proxy/wasm/Cargo.lock | 15 --- farm-staking/farm-staking/Cargo.toml | 3 - farm-staking/farm-staking/wasm/Cargo.lock | 15 --- locked-asset/proxy_dex/wasm/Cargo.lock | 15 --- 13 files changed, 253 deletions(-) delete mode 100644 common/modules/farm/farm_position/Cargo.toml delete mode 100644 common/modules/farm/farm_position/src/farm_position.rs diff --git a/common/modules/farm/farm_base_impl/Cargo.toml b/common/modules/farm/farm_base_impl/Cargo.toml index 91ac14e3d..db5644507 100644 --- a/common/modules/farm/farm_base_impl/Cargo.toml +++ b/common/modules/farm/farm_base_impl/Cargo.toml @@ -12,9 +12,6 @@ path = "../config" [dependencies.farm_token] path = "../farm_token" -[dependencies.farm_position] -path = "../farm_position" - [dependencies.rewards] path = "../rewards" diff --git a/common/modules/farm/farm_position/Cargo.toml b/common/modules/farm/farm_position/Cargo.toml deleted file mode 100644 index c3b8beda4..000000000 --- a/common/modules/farm/farm_position/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "farm_position" -version = "0.0.0" -authors = ["MultiversX "] -edition = "2021" - -[lib] -path = "src/farm_position.rs" - -[dependencies.multiversx-sc] -version = "=0.39.4" -features = ["esdt-token-payment-legacy-decode"] - -[dependencies.multiversx-sc-modules] -version = "=0.39.4" - -[dependencies.farm_token] -path = "../farm_token" - -[dependencies.utils] -path = "../../utils" - -[dependencies.permissions_module] -path = "../../permissions_module" - -[dependencies.common_structs] -path = "../../../common_structs" diff --git a/common/modules/farm/farm_position/src/farm_position.rs b/common/modules/farm/farm_position/src/farm_position.rs deleted file mode 100644 index a7e12663c..000000000 --- a/common/modules/farm/farm_position/src/farm_position.rs +++ /dev/null @@ -1,112 +0,0 @@ -#![no_std] - -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - - -#[multiversx_sc::module] -pub trait FarmPositionModule: - farm_token::FarmTokenModule - + utils::UtilsModule - + permissions_module::PermissionsModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule -{ - // #[payable("*")] - // #[endpoint(updateTotalFarmPosition)] - // fn update_total_farm_position(&self) { - // let caller = self.blockchain().get_caller(); - // let payments = self.get_non_empty_payments(); - // let farm_token_mapper = self.farm_token(); - // let mut new_total_farm_position = BigUint::zero(); - // for farm_position in &payments { - // farm_token_mapper.require_same_token(&farm_position.token_identifier); - - // let token_attributes: FarmTokenAttributes = - // farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - // if token_attributes.original_owner != caller { - // self.decrease_user_farm_position(&farm_position); - // } - - // new_total_farm_position += farm_position.amount; - // } - - // let user_current_farm_position = self.user_total_farm_position(&caller).get(); - // if new_total_farm_position > user_current_farm_position { - // self.user_total_farm_position(&caller) - // .set(new_total_farm_position) - // } - - // self.send().direct_multi(&caller, &payments); - // } - - // #[endpoint(setAllowExternalClaimBoostedRewards)] - // fn set_allow_external_claim_boosted_rewards(&self, allow: bool) { - // let caller = self.blockchain().get_caller(); - // self.allow_external_claim_boosted_rewards(&caller) - // .set(allow); - // } - - // fn check_and_update_user_farm_position( - // &self, - // user: &ManagedAddress, - // farm_positions: &PaymentsVec, - // ) { - // let farm_token_mapper = self.farm_token(); - // let mut total_farm_position = BigUint::zero(); - // let mut farm_position_increase = BigUint::zero(); - // for farm_position in farm_positions { - // farm_token_mapper.require_same_token(&farm_position.token_identifier); - - // total_farm_position += &farm_position.amount; - // let token_attributes: FarmTokenAttributes = - // farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - // if &token_attributes.original_owner != user { - // self.decrease_user_farm_position(&farm_position); - // farm_position_increase += &farm_position.amount; - // } - // } - - // if self.user_total_farm_position(user).get() == 0 { - // self.increase_user_farm_position(user, &total_farm_position); - // } else if farm_position_increase > 0 { - // self.increase_user_farm_position(user, &farm_position_increase); - // } - // } - - // fn increase_user_farm_position( - // &self, - // user: &ManagedAddress, - // new_farm_position_amount: &BigUint, - // ) { - // self.user_total_farm_position(user) - // .update(|user_farm_position| *user_farm_position += new_farm_position_amount); - // } - - // fn decrease_user_farm_position(&self, farm_position: &EsdtTokenPayment) { - // let farm_token_mapper = self.farm_token(); - // let token_attributes: FarmTokenAttributes = - // farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - // self.user_total_farm_position(&token_attributes.original_owner) - // .update(|user_farm_position| { - // if *user_farm_position > farm_position.amount { - // *user_farm_position -= &farm_position.amount; - // } else { - // *user_farm_position = BigUint::zero(); - // } - // }); - // } - - // #[view(getUserTotalFarmPosition)] - // #[storage_mapper("userTotalFarmPosition")] - // fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; - - // #[view(getAllowExternalClaimBoostedRewards)] - // #[storage_mapper("allowExternalClaimBoostedRewards")] - // fn allow_external_claim_boosted_rewards( - // &self, - // user: &ManagedAddress, - // ) -> SingleValueMapper; -} diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index b5abb39a5..3052499d2 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -16,9 +16,6 @@ path = "../../common/modules/farm/config" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" -[dependencies.farm_position] -path = "../../common/modules/farm/farm_position" - [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 9242ee202..83649b5f2 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -199,7 +198,6 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "locking_module", @@ -233,7 +231,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -247,18 +244,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index 4e30b4394..f2cca8bf7 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -16,9 +16,6 @@ path = "../../common/modules/farm/config" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" -[dependencies.farm_position] -path = "../../common/modules/farm/farm_position" - [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 210fdddf6..97ea7e292 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -202,7 +201,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -216,18 +214,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 63cde5917..3d762a9be 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -194,7 +193,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -208,18 +206,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 55e0dd4b1..5173db1ce 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -172,7 +172,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -212,7 +211,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -226,18 +224,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index d4a937ad4..6b8cfa51d 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -199,7 +198,6 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "math", @@ -256,7 +254,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -270,18 +267,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index d8e0202f1..d4d155aee 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -31,9 +31,6 @@ path = "../../common/modules/farm/farm_base_impl" [dependencies.farm_token] path = "../../common/modules/farm/farm_token" -[dependencies.farm_position] -path = "../../common/modules/farm/farm_position" - [dependencies.rewards] path = "../../common/modules/farm/rewards" diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 0d71b7fcd..4584bdf1a 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -199,7 +198,6 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "math", @@ -234,7 +232,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -248,18 +245,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index 7ff19d6d2..fe099d430 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -154,7 +154,6 @@ dependencies = [ "events", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -199,7 +198,6 @@ dependencies = [ "farm", "farm-boosted-yields", "farm_base_impl", - "farm_position", "farm_token", "fixed-supply-token", "locking_module", @@ -225,7 +223,6 @@ dependencies = [ "config", "contexts", "events", - "farm_position", "farm_token", "fixed-supply-token", "mergeable", @@ -239,18 +236,6 @@ dependencies = [ "utils", ] -[[package]] -name = "farm_position" -version = "0.0.0" -dependencies = [ - "common_structs", - "farm_token", - "multiversx-sc", - "multiversx-sc-modules", - "permissions_module", - "utils", -] - [[package]] name = "farm_token" version = "0.0.0" From d37f593aa91da6d7a2c8d01381991307a7323e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 24 Aug 2023 09:02:37 +0300 Subject: [PATCH 11/58] farm-staking: Remove merge for dual staking --- farm-staking/farm-staking-proxy/src/lib.rs | 1 - .../src/proxy_actions/merge_pos.rs | 108 ----- .../src/proxy_actions/mod.rs | 1 - .../tests/composed_pos_test.rs | 453 ------------------ .../farm-staking-proxy/wasm/src/lib.rs | 5 +- 5 files changed, 2 insertions(+), 566 deletions(-) delete mode 100644 farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs delete mode 100644 farm-staking/farm-staking-proxy/tests/composed_pos_test.rs diff --git a/farm-staking/farm-staking-proxy/src/lib.rs b/farm-staking/farm-staking-proxy/src/lib.rs index 8f97fd0a6..f9c5d5e2f 100644 --- a/farm-staking/farm-staking-proxy/src/lib.rs +++ b/farm-staking/farm-staking-proxy/src/lib.rs @@ -20,7 +20,6 @@ pub trait FarmStakingProxy: + proxy_actions::stake::ProxyStakeModule + proxy_actions::claim::ProxyClaimModule + proxy_actions::unstake::ProxyUnstakeModule - + proxy_actions::merge_pos::ProxyMergePosModule { #[init] fn init( 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 4a0f89031..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(); - 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/mod.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs index 59916511b..3270b0f79 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs @@ -1,4 +1,3 @@ pub mod claim; -pub mod merge_pos; pub mod stake; pub mod unstake; diff --git a/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs b/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs deleted file mode 100644 index 76b13a8f8..000000000 --- a/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs +++ /dev/null @@ -1,453 +0,0 @@ -pub mod constants; -pub mod staking_farm_with_lp_external_contracts; -pub mod staking_farm_with_lp_staking_contract_interactions; -pub mod staking_farm_with_lp_staking_contract_setup; - -multiversx_sc::imports!(); - -use constants::*; -use farm_staking::stake_farm::StakeFarmModule; -use farm_staking_proxy::dual_yield_token::DualYieldTokenAttributes; -use farm_staking_proxy::proxy_actions::claim::ProxyClaimModule; -use farm_staking_proxy::proxy_actions::merge_pos::ProxyMergePosModule; - -use farm_staking_proxy::proxy_actions::unstake::ProxyUnstakeModule; -use multiversx_sc::codec::Empty; -use multiversx_sc_scenario::{ - managed_biguint, rust_biguint, testing_framework::TxTokenTransfer, DebugApi, -}; -use staking_farm_with_lp_staking_contract_interactions::*; - -#[test] -fn combine_metastaking_with_staking_pos_test() { - let _ = DebugApi::dummy(); - let mut setup = FarmStakingSetup::new( - pair::contract_obj, - farm::contract_obj, - farm_staking::contract_obj, - farm_staking_proxy::contract_obj, - ); - - let expected_staking_token_amount = 1_001_000_000; // safe price of USER_TOTAL_LP_TOKENS in RIDE tokens - let _ = setup.stake_farm_lp_proxy(1, USER_TOTAL_LP_TOKENS, 1, expected_staking_token_amount); - - let user_addr = setup.user_addr.clone(); - let composed_pos_full_amount = 1_000_000; - setup.b_mock.set_esdt_balance( - &user_addr, - STAKING_TOKEN_ID, - &rust_biguint!(composed_pos_full_amount), - ); - - // proxy needs the burn role now the tokens - setup.b_mock.set_esdt_local_roles( - setup.proxy_wrapper.address_ref(), - STAKING_FARM_TOKEN_ID, - &[EsdtLocalRole::NftBurn], - ); - - // stake 1/4 and then 3/4 of the tokens - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 2, - &rust_biguint!(composed_pos_full_amount / 4), - None, - ); - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 3, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - None, - ); - - // merge metastaking pos with two staking tokens - let merge_payments = vec![ - TxTokenTransfer { - token_identifier: DUAL_YIELD_TOKEN_ID.to_vec(), - nonce: 1, - value: rust_biguint!(expected_staking_token_amount), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 2, - value: rust_biguint!(composed_pos_full_amount / 4), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 3, - value: rust_biguint!(composed_pos_full_amount * 3 / 4), - }, - ]; - setup - .b_mock - .execute_esdt_multi_transfer(&user_addr, &setup.proxy_wrapper, &merge_payments, |sc| { - sc.merge_metastaking_with_staking_token(); - }) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 2, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 6, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim rewards with composed pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim again - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 4, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 8, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - setup - .b_mock - .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); - setup.b_mock.set_block_epoch(20); - - // unstake - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount - ); - }, - ) - .assert_ok(); -} - -#[test] -fn combine_metastaking_with_staking_pos_partial_actions_test() { - let _ = DebugApi::dummy(); - let mut setup = FarmStakingSetup::new( - pair::contract_obj, - farm::contract_obj, - farm_staking::contract_obj, - farm_staking_proxy::contract_obj, - ); - - let expected_staking_token_amount = 1_001_000_000; // safe price of USER_TOTAL_LP_TOKENS in RIDE tokens - let _ = setup.stake_farm_lp_proxy(1, USER_TOTAL_LP_TOKENS, 1, expected_staking_token_amount); - - let user_addr = setup.user_addr.clone(); - let composed_pos_full_amount = 1_000_000; - setup.b_mock.set_esdt_balance( - &user_addr, - STAKING_TOKEN_ID, - &rust_biguint!(composed_pos_full_amount), - ); - - // proxy needs the burn role now the tokens - setup.b_mock.set_esdt_local_roles( - setup.proxy_wrapper.address_ref(), - STAKING_FARM_TOKEN_ID, - &[EsdtLocalRole::NftBurn], - ); - - // stake 1/4 and then 3/4 of the tokens - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 2, - &rust_biguint!(composed_pos_full_amount / 4), - None, - ); - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 3, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - None, - ); - - // merge half of metastaking pos with two staking tokens - let merge_payments = vec![ - TxTokenTransfer { - token_identifier: DUAL_YIELD_TOKEN_ID.to_vec(), - nonce: 1, - value: rust_biguint!(expected_staking_token_amount / 2), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 2, - value: rust_biguint!(composed_pos_full_amount / 4), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 3, - value: rust_biguint!(composed_pos_full_amount * 3 / 4), - }, - ]; - setup - .b_mock - .execute_esdt_multi_transfer(&user_addr, &setup.proxy_wrapper, &merge_payments, |sc| { - sc.merge_metastaking_with_staking_token(); - }) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount / 2), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 2, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 2), - virtual_pos_token_nonce: 6, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 2), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim rewards with part of composed pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount / 4), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount / 4), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 4), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 4), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount / 2), - }), - ); - - setup - .b_mock - .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); - setup.b_mock.set_block_epoch(20); - - // unstake partial - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount / 4), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount / 8), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount / 4 - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount / 8 - ); - assert_eq!( - unstake_result.opt_new_dual_yield_tokens.unwrap().amount, - expected_staking_token_amount / 8 - ); - }, - ) - .assert_ok(); - - // check leftover token attributes - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount / 8), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 8), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 8), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount / 4), - }), - ); - - // unstake remaining pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount / 8), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount / 8), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount / 4 - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount / 8 - ); - assert!(unstake_result.opt_new_dual_yield_tokens.is_none(),); - }, - ) - .assert_ok(); -} diff --git a/farm-staking/farm-staking-proxy/wasm/src/lib.rs b/farm-staking/farm-staking-proxy/wasm/src/lib.rs index 5aea5b134..57bdc0840 100644 --- a/farm-staking/farm-staking-proxy/wasm/src/lib.rs +++ b/farm-staking/farm-staking-proxy/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 16 +// Endpoints: 15 // Async Callback: 1 -// Total number of exported functions: 18 +// Total number of exported functions: 17 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -33,7 +33,6 @@ multiversx_sc_wasm_adapter::endpoints! { stakeFarmTokens claimDualYield unstakeFarmTokens - mergeMetastakingWithStakingToken callBack ) } From 6580dbad0b327b2c90c04035dd448aa07bc5fc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 29 Aug 2023 10:00:02 +0300 Subject: [PATCH 12/58] farm/farm-staking: Update energy after claim --- dex/farm/src/lib.rs | 10 ++++++++-- .../farm-staking/src/claim_stake_farm_rewards.rs | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 34975a2a5..cf53e0b68 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -118,10 +118,13 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let claim_rewards_result = self.claim_rewards::>(orig_caller); + let claim_rewards_result = self.claim_rewards::>(orig_caller.clone()); + self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); self.send_payment_non_zero(&caller, &claim_rewards_result.rewards); + self.update_energy_and_progress(&orig_caller); + claim_rewards_result.into() } @@ -134,9 +137,12 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let output_farm_token_payment = self.compound_rewards::>(orig_caller); + let output_farm_token_payment = self.compound_rewards::>(orig_caller.clone()); + self.send_payment_non_zero(&caller, &output_farm_token_payment); + self.update_energy_and_progress(&orig_caller); + output_farm_token_payment } diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index f8bef0283..bea77d267 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -63,7 +63,7 @@ pub trait ClaimStakeFarmRewardsModule: let payment = self.call_value().single_esdt(); let mut claim_result = self .claim_rewards_base_no_farm_token_mint::>( - original_caller, + original_caller.clone(), ManagedVec::from_single_item(payment), ); @@ -78,6 +78,8 @@ pub trait ClaimStakeFarmRewardsModule: self.set_farm_supply_for_current_week(&claim_result.storage_cache.farm_token_supply); } + self.update_energy_and_progress(&original_caller); + let new_farm_token_nonce = self.send().esdt_nft_create_compact( &virtual_farm_token.payment.token_identifier, &virtual_farm_token.payment.amount, From 5d7a8489f3f7dfe8b5093f7899203615e29a1f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 29 Aug 2023 12:33:55 +0300 Subject: [PATCH 13/58] fees-collector: Fixes after review --- energy-integration/fees-collector/src/config.rs | 8 ++++++++ energy-integration/fees-collector/src/lib.rs | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/energy-integration/fees-collector/src/config.rs b/energy-integration/fees-collector/src/config.rs index 9a369df9a..64c61c239 100644 --- a/energy-integration/fees-collector/src/config.rs +++ b/energy-integration/fees-collector/src/config.rs @@ -78,4 +78,12 @@ pub trait ConfigModule { #[storage_mapper("allTokens")] fn all_tokens(&self) -> SingleValueMapper>; + + #[view(getAllowExternalClaimRewards)] + #[storage_mapper("allowExternalClaimRewards")] + fn allow_external_claim_rewards( + &self, + user: &ManagedAddress, + ) -> SingleValueMapper; + } diff --git a/energy-integration/fees-collector/src/lib.rs b/energy-integration/fees-collector/src/lib.rs index da7698e88..79c29a233 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -53,8 +53,17 @@ pub trait FeesCollector: self.accumulate_additional_locked_tokens(); - let caller = self.blockchain().get_caller(); - let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + let original_caller = match opt_original_caller { + OptionalValue::Some(user) => { + require!( + self.allow_external_claim_rewards(&user).get(), + "Cannot claim rewards for this address" + ); + user + } + OptionalValue::None => self.blockchain().get_caller(), + }; + let wrapper = FeesCollectorWrapper::new(); let mut rewards = self.claim_multi(&wrapper, &original_caller); @@ -79,14 +88,14 @@ pub trait FeesCollector: } if !rewards.is_empty() { - self.send().direct_multi(&caller, &rewards); + self.send().direct_multi(&original_caller, &rewards); } if total_locked_token_rewards_amount > 0 { let locked_rewards = self.lock_virtual( self.get_base_token_id(), total_locked_token_rewards_amount, - caller, + original_caller.clone(), original_caller, ); From b445da153dff385be1318e609407a40773f45a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 29 Aug 2023 12:34:13 +0300 Subject: [PATCH 14/58] Clippy fixes and compiling dependencies --- energy-integration/fees-collector/wasm/src/lib.rs | 5 +++-- farm-staking/metabonding-staking/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/energy-integration/fees-collector/wasm/src/lib.rs b/energy-integration/fees-collector/wasm/src/lib.rs index 74fbfdf40..141b80dc6 100644 --- a/energy-integration/fees-collector/wasm/src/lib.rs +++ b/energy-integration/fees-collector/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 35 +// Endpoints: 36 // Async Callback (empty): 1 -// Total number of exported functions: 37 +// Total number of exported functions: 38 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -26,6 +26,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLockedTokenId getAllTokens getAllKnownContracts + getAllowExternalClaimRewards getLastActiveWeekForUser getUserEnergyForWeek getLastGlobalUpdateWeek diff --git a/farm-staking/metabonding-staking/src/lib.rs b/farm-staking/metabonding-staking/src/lib.rs index 9b3387a78..ebd1967e5 100644 --- a/farm-staking/metabonding-staking/src/lib.rs +++ b/farm-staking/metabonding-staking/src/lib.rs @@ -74,7 +74,7 @@ pub trait MetabondingStaking: require!(!entry_mapper.is_empty(), "Must stake first"); let mut user_entry: UserEntry = entry_mapper.get(); - let unstake_amount = user_entry.unstake_amount.clone(); + let unstake_amount = user_entry.unstake_amount; require!(unstake_amount > 0, "Must unstake first"); let current_epoch = self.blockchain().get_block_epoch(); From e46c4d2790a7580364e03c85e717acfd5b9f1a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 29 Aug 2023 12:38:34 +0300 Subject: [PATCH 15/58] Update common/modules/farm/farm_base_impl/src/base_traits_impl.rs Co-authored-by: dorin-iancu <72252689+dorin-iancu@users.noreply.github.com> --- common/modules/farm/farm_base_impl/src/base_traits_impl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 7839efbbf..5ac1c4369 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -216,7 +216,7 @@ pub trait FarmContract { Self::increase_user_farm_position(sc, user, &farm_position_increase); } } - +#[inline] fn increase_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, From ea612c1081ba831b757c505c8aa861fdcee0da20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 29 Aug 2023 16:58:30 +0300 Subject: [PATCH 16/58] Fixes after review --- common/modules/farm/config/src/config.rs | 43 ++++++++++++++++--- .../farm_base_impl/src/base_traits_impl.rs | 20 ++++++--- .../farm/farm_base_impl/src/enter_farm.rs | 9 +++- dex/farm-with-locked-rewards/wasm/src/lib.rs | 5 +-- dex/farm/src/base_functions.rs | 11 ++--- dex/farm/src/claim_boost_only.rs | 15 +++---- dex/farm/wasm/src/lib.rs | 5 +-- dex/governance/src/weight.rs | 4 +- .../fees-collector/src/config.rs | 6 +-- energy-integration/fees-collector/src/lib.rs | 1 - energy-integration/governance-v2/src/lib.rs | 2 +- .../farm-staking/src/base_impl_wrapper.rs | 33 +++++++------- .../src/claim_only_boosted_staking_rewards.rs | 16 +++---- farm-staking/farm-staking/wasm/src/lib.rs | 5 +-- 14 files changed, 99 insertions(+), 76 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index bd80456ff..909a5cfbb 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -8,6 +8,22 @@ use pausable::State; pub const DEFAULT_NFT_DEPOSIT_MAX_LEN: usize = 10; +#[derive( + ManagedVecItem, + TopEncode, + TopDecode, + NestedEncode, + NestedDecode, + TypeAbi, + Clone, + PartialEq, + Debug, +)] +pub struct UserTotalFarmPositionStruct { + pub total_farm_position: BigUint, + pub allow_external_claim_boosted_rewards: bool, +} + #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { #[inline] @@ -16,6 +32,24 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio state == State::Active } + fn get_user_total_farm_position(&self, user: &ManagedAddress) -> BigUint { + self.user_total_farm_position(user) + .set_if_empty(UserTotalFarmPositionStruct { + total_farm_position: BigUint::zero(), + allow_external_claim_boosted_rewards: false, + }); + + self.user_total_farm_position(user) + .get() + .total_farm_position + } + + fn get_allow_external_claim_boosted_rewards(&self, user: &ManagedAddress) -> bool { + self.user_total_farm_position(user) + .get() + .allow_external_claim_boosted_rewards + } + #[view(getFarmingTokenId)] #[storage_mapper("farming_token_id")] fn farming_token_id(&self) -> SingleValueMapper; @@ -41,13 +75,8 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio #[view(getUserTotalFarmPosition)] #[storage_mapper("userTotalFarmPosition")] - fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; - - #[view(getAllowExternalClaimBoostedRewards)] - #[storage_mapper("allowExternalClaimBoostedRewards")] - fn allow_external_claim_boosted_rewards( + fn user_total_farm_position( &self, user: &ManagedAddress, - ) -> SingleValueMapper; - + ) -> SingleValueMapper>; } diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 5ac1c4369..63f5957b0 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -210,20 +210,23 @@ pub trait FarmContract { } } - if sc.user_total_farm_position(user).get() == 0 { + let user_total_farm_position = sc.get_user_total_farm_position(user); + if user_total_farm_position == BigUint::zero() { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); } } -#[inline] + #[inline] fn increase_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, new_farm_position_amount: &BigUint<::Api>, ) { sc.user_total_farm_position(user) - .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + .update(|user_farm_position_struct| { + user_farm_position_struct.total_farm_position += new_farm_position_amount + }); } fn decrease_user_farm_position( @@ -235,12 +238,15 @@ pub trait FarmContract { farm_token_mapper.get_token_attributes(farm_position.token_nonce); sc.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position| { - if *user_farm_position > farm_position.amount { - *user_farm_position -= &farm_position.amount; + .update(|user_farm_position_struct| { + let mut user_total_farm_position = + user_farm_position_struct.total_farm_position.clone(); + if user_total_farm_position > farm_position.amount { + user_total_farm_position -= &farm_position.amount; } else { - *user_farm_position = BigUint::zero(); + user_total_farm_position = BigUint::zero(); } + user_farm_position_struct.total_farm_position = user_total_farm_position; }); } } diff --git a/common/modules/farm/farm_base_impl/src/enter_farm.rs b/common/modules/farm/farm_base_impl/src/enter_farm.rs index e7628cf76..02e20d42a 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -45,11 +45,16 @@ pub trait BaseEnterFarmModule: ); // The order is important - first check and update, then increase position - FC::check_and_update_user_farm_position(self, + FC::check_and_update_user_farm_position( + self, &caller, &enter_farm_context.additional_farm_tokens, ); - FC::increase_user_farm_position(self, &caller, &enter_farm_context.farming_token_payment.amount); + FC::increase_user_farm_position( + self, + &caller, + &enter_farm_context.farming_token_payment.amount, + ); FC::generate_aggregated_rewards(self, &mut storage_cache); diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index 48baeb9fc..a124d3269 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 65 +// Endpoints: 64 // Async Callback: 1 -// Total number of exported functions: 67 +// Total number of exported functions: 66 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -34,7 +34,6 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce getDivisionSafetyConstant getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards setLockingScAddress setLockEpochs getLockingScAddress diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index a243bac15..fad4e0908 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -13,7 +13,6 @@ use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::{DefaultFarmWrapper, FarmContract}; use fixed_supply_token::FixedSupplyToken; - use crate::exit_penalty; pub type DoubleMultiPayment = MultiValue2, EsdtTokenPayment>; @@ -241,16 +240,18 @@ where caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, token_attributes: &::AttributesType, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - if &token_attributes.original_owner != caller { + let original_owner = &token_attributes.original_owner; + + if original_owner != caller { sc.update_energy_and_progress(caller); } - let user_total_farm_position_mapper = sc.user_total_farm_position(caller); - if user_total_farm_position_mapper.is_empty() { + let user_total_farm_position = sc.get_user_total_farm_position(original_owner); + if user_total_farm_position == BigUint::zero() { return BigUint::zero(); } - sc.claim_boosted_yields_rewards(caller, user_total_farm_position_mapper.get()) + sc.claim_boosted_yields_rewards(caller, user_total_farm_position) } } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 15fe9cb5a..9159337d9 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -1,7 +1,5 @@ multiversx_sc::imports!(); - - use crate::base_functions::Wrapper; #[multiversx_sc::module] @@ -37,12 +35,12 @@ pub trait ClaimBoostOnlyModule: #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards( &self, - opt_user: OptionalValue + opt_user: OptionalValue, ) -> EsdtTokenPayment { let user = match opt_user { OptionalValue::Some(user) => { require!( - self.allow_external_claim_boosted_rewards(&user).get(), + self.get_allow_external_claim_boosted_rewards(&user), "Cannot claim rewards for this address" ); user @@ -51,14 +49,13 @@ pub trait ClaimBoostOnlyModule: }; let reward_token_id = self.reward_token_id().get(); - - let user_total_farm_position_mapper = self.user_total_farm_position(&user); - if user_total_farm_position_mapper.is_empty() { + + let user_total_farm_position = self.get_user_total_farm_position(&user); + if user_total_farm_position == BigUint::zero() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } - let reward = - self.claim_boosted_yields_rewards(&user, user_total_farm_position_mapper.get()); + let reward = self.claim_boosted_yields_rewards(&user, user_total_farm_position); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index dbb8e6d3d..4f3c13441 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 62 +// Endpoints: 61 // Async Callback: 1 -// Total number of exported functions: 64 +// Total number of exported functions: 63 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -35,7 +35,6 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce getDivisionSafetyConstant getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards registerFarmToken getFarmTokenId getFarmTokenSupply diff --git a/dex/governance/src/weight.rs b/dex/governance/src/weight.rs index 2eda127a1..07b075f95 100644 --- a/dex/governance/src/weight.rs +++ b/dex/governance/src/weight.rs @@ -27,9 +27,7 @@ pub trait Lib: config::Config { if let Some(provider) = self.price_providers().get(&payment.token_identifier) { let call_result: MultiValue2, EsdtTokenPayment> = self.price_provider_proxy(provider) - .get_tokens_for_given_position_with_safe_price( - payment.amount.clone(), - ) + .get_tokens_for_given_position_with_safe_price(payment.amount.clone()) .execute_on_dest_context(); let (token1, token2) = call_result.into_tuple(); diff --git a/energy-integration/fees-collector/src/config.rs b/energy-integration/fees-collector/src/config.rs index 64c61c239..1e1a850a0 100644 --- a/energy-integration/fees-collector/src/config.rs +++ b/energy-integration/fees-collector/src/config.rs @@ -81,9 +81,5 @@ pub trait ConfigModule { #[view(getAllowExternalClaimRewards)] #[storage_mapper("allowExternalClaimRewards")] - fn allow_external_claim_rewards( - &self, - user: &ManagedAddress, - ) -> SingleValueMapper; - + fn allow_external_claim_rewards(&self, user: &ManagedAddress) -> SingleValueMapper; } diff --git a/energy-integration/fees-collector/src/lib.rs b/energy-integration/fees-collector/src/lib.rs index 79c29a233..f2aef7a34 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -64,7 +64,6 @@ pub trait FeesCollector: OptionalValue::None => self.blockchain().get_caller(), }; - let wrapper = FeesCollectorWrapper::new(); let mut rewards = self.claim_multi(&wrapper, &original_caller); if rewards.is_empty() { diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 584d43008..e2b27e5c6 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -37,7 +37,7 @@ pub trait GovernanceV2: /// - `quorum_percentage` - the minimum number of (`votes` minus `downvotes`) at the end of voting period /// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal /// - `votingPeriodInBlocks` - Number of blocks the voting period lasts (voting delay does not count towards this) - /// - `withdraw_percentage_defeated` - Percetange of the fee to be returned if proposal defetead + /// - `withdraw_percentage_defeated` - Percetange of the fee to be returned if proposal defetead /// - `energy_factory_address` /// - `fees_collector_address` /// - `fee_token` - The token used to pay the fee diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 25b41733d..51575b19a 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -52,12 +52,12 @@ where if &token_attributes.original_owner != caller { sc.update_energy_and_progress(caller); } - let user_total_farm_position_mapper = sc.user_total_farm_position(caller); - if user_total_farm_position_mapper.is_empty() { + let user_total_farm_position = sc.get_user_total_farm_position(caller); + if user_total_farm_position == BigUint::zero() { return BigUint::zero(); } - sc.claim_boosted_yields_rewards(caller, user_total_farm_position_mapper.get()) + sc.claim_boosted_yields_rewards(caller, user_total_farm_position) } } @@ -136,11 +136,7 @@ where ) -> BigUint<::Api> { let base_farm_reward = Self::calculate_base_farm_rewards(farm_token_amount, token_attributes, storage_cache); - let boosted_yield_rewards = Self::calculate_boosted_rewards( - sc, - caller, - token_attributes, - ); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller, token_attributes); base_farm_reward + boosted_yield_rewards } @@ -190,7 +186,6 @@ where } } - fn check_and_update_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, @@ -211,8 +206,8 @@ where farm_position_increase += &farm_position.amount; } } - - if sc.user_total_farm_position(user).get() == 0 { + let user_total_farm_position = sc.get_user_total_farm_position(user); + if user_total_farm_position == BigUint::zero() { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); @@ -225,7 +220,9 @@ where new_farm_position_amount: &BigUint<::Api>, ) { sc.user_total_farm_position(user) - .update(|user_farm_position| *user_farm_position += new_farm_position_amount); + .update(|user_farm_position_struct| { + user_farm_position_struct.total_farm_position += new_farm_position_amount + }); } fn decrease_user_farm_position( @@ -237,13 +234,15 @@ where farm_token_mapper.get_token_attributes(farm_position.token_nonce); sc.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position| { - if *user_farm_position > farm_position.amount { - *user_farm_position -= &farm_position.amount; + .update(|user_farm_position_struct| { + let mut user_total_farm_position = + user_farm_position_struct.total_farm_position.clone(); + if user_total_farm_position > farm_position.amount { + user_total_farm_position -= &farm_position.amount; } else { - *user_farm_position = BigUint::zero(); + user_total_farm_position = BigUint::zero(); } + user_farm_position_struct.total_farm_position = user_total_farm_position; }); } - } 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 f69569933..a9b7605ee 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 @@ -30,7 +30,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: let user = match opt_user { OptionalValue::Some(user) => { require!( - self.allow_external_claim_boosted_rewards(&user).get(), + self.get_allow_external_claim_boosted_rewards(&user), "Cannot claim rewards for this address" ); user @@ -39,13 +39,12 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: }; let reward_token_id = self.reward_token_id().get(); - let user_total_farm_position_mapper = self.user_total_farm_position(&user); - if user_total_farm_position_mapper.is_empty() { + let user_total_farm_position = self.get_user_total_farm_position(&user); + if user_total_farm_position == BigUint::zero() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } - let reward = - self.claim_boosted_yields_rewards(&user, user_total_farm_position_mapper.get()); + let reward = self.claim_boosted_yields_rewards(&user, user_total_farm_position); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } @@ -69,11 +68,8 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: let token_attributes = self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = FarmStakingWrapper::::calculate_boosted_rewards( - self, - caller, - &token_attributes, - ); + let reward = + FarmStakingWrapper::::calculate_boosted_rewards(self, caller, &token_attributes); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index f054fa567..d3322ea4e 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 67 +// Endpoints: 66 // Async Callback: 1 -// Total number of exported functions: 69 +// Total number of exported functions: 68 #![no_std] #![feature(alloc_error_handler, lang_items)] @@ -38,7 +38,6 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce getDivisionSafetyConstant getUserTotalFarmPosition - getAllowExternalClaimBoostedRewards registerFarmToken getFarmTokenId getFarmTokenSupply From 9bdf09c241fc1757b02c80d1ed1a941665a96e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 30 Aug 2023 17:26:45 +0300 Subject: [PATCH 17/58] Fixes after review --- common/modules/farm/config/src/config.rs | 15 +++++---------- .../farm/farm_base_impl/src/base_traits_impl.rs | 4 ++-- dex/farm/src/base_functions.rs | 4 +++- dex/farm/src/claim_boost_only.rs | 16 +++++++--------- .../farm-staking/src/base_impl_wrapper.rs | 7 ++++--- .../src/claim_only_boosted_staking_rewards.rs | 15 +++++++-------- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 909a5cfbb..c7768500f 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -32,22 +32,17 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio state == State::Active } - fn get_user_total_farm_position(&self, user: &ManagedAddress) -> BigUint { + fn get_user_total_farm_position_struct( + &self, + user: &ManagedAddress, + ) -> UserTotalFarmPositionStruct { self.user_total_farm_position(user) .set_if_empty(UserTotalFarmPositionStruct { total_farm_position: BigUint::zero(), allow_external_claim_boosted_rewards: false, }); - self.user_total_farm_position(user) - .get() - .total_farm_position - } - - fn get_allow_external_claim_boosted_rewards(&self, user: &ManagedAddress) -> bool { - self.user_total_farm_position(user) - .get() - .allow_external_claim_boosted_rewards + self.user_total_farm_position(user).get() } #[view(getFarmingTokenId)] diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 63f5957b0..81aa35955 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -210,8 +210,8 @@ pub trait FarmContract { } } - let user_total_farm_position = sc.get_user_total_farm_position(user); - if user_total_farm_position == BigUint::zero() { + let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(user); + if user_total_farm_position_struct.total_farm_position == BigUint::zero() { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index fad4e0908..15c6f8d3b 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -246,7 +246,9 @@ where sc.update_energy_and_progress(caller); } - let user_total_farm_position = sc.get_user_total_farm_position(original_owner); + let user_total_farm_position_struct = + sc.get_user_total_farm_position_struct(original_owner); + let user_total_farm_position = user_total_farm_position_struct.total_farm_position; if user_total_farm_position == BigUint::zero() { return BigUint::zero(); } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 9159337d9..1851bfd0c 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -38,19 +38,17 @@ pub trait ClaimBoostOnlyModule: opt_user: OptionalValue, ) -> EsdtTokenPayment { let user = match opt_user { - OptionalValue::Some(user) => { - require!( - self.get_allow_external_claim_boosted_rewards(&user), - "Cannot claim rewards for this address" - ); - user - } + OptionalValue::Some(user) => user, OptionalValue::None => self.blockchain().get_caller(), }; + let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); + require!( + user_total_farm_position_struct.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); let reward_token_id = self.reward_token_id().get(); - - let user_total_farm_position = self.get_user_total_farm_position(&user); + let user_total_farm_position = user_total_farm_position_struct.total_farm_position; if user_total_farm_position == BigUint::zero() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 51575b19a..abe646541 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -52,7 +52,8 @@ where if &token_attributes.original_owner != caller { sc.update_energy_and_progress(caller); } - let user_total_farm_position = sc.get_user_total_farm_position(caller); + let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(caller); + let user_total_farm_position = user_total_farm_position_struct.total_farm_position; if user_total_farm_position == BigUint::zero() { return BigUint::zero(); } @@ -206,8 +207,8 @@ where farm_position_increase += &farm_position.amount; } } - let user_total_farm_position = sc.get_user_total_farm_position(user); - if user_total_farm_position == BigUint::zero() { + let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(user); + if user_total_farm_position_struct.total_farm_position == BigUint::zero() { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); 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 a9b7605ee..9b91f526b 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 @@ -28,18 +28,17 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { let user = match opt_user { - OptionalValue::Some(user) => { - require!( - self.get_allow_external_claim_boosted_rewards(&user), - "Cannot claim rewards for this address" - ); - user - } + OptionalValue::Some(user) => user, OptionalValue::None => self.blockchain().get_caller(), }; + let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); + require!( + user_total_farm_position_struct.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); let reward_token_id = self.reward_token_id().get(); - let user_total_farm_position = self.get_user_total_farm_position(&user); + let user_total_farm_position = user_total_farm_position_struct.total_farm_position; if user_total_farm_position == BigUint::zero() { return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } From 07f41a3af8b6935de7ad6ace340acace06b03d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 09:33:59 +0300 Subject: [PATCH 18/58] Fix minor issue --- dex/farm/src/claim_boost_only.rs | 13 ++++++++----- .../src/claim_only_boosted_staking_rewards.rs | 14 ++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 1851bfd0c..c917983a0 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -37,15 +37,18 @@ pub trait ClaimBoostOnlyModule: &self, opt_user: OptionalValue, ) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); let user = match opt_user { OptionalValue::Some(user) => user, - OptionalValue::None => self.blockchain().get_caller(), + OptionalValue::None => caller.clone(), }; let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); - require!( - user_total_farm_position_struct.allow_external_claim_boosted_rewards, - "Cannot claim rewards for this address" - ); + if user != caller { + require!( + user_total_farm_position_struct.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } let reward_token_id = self.reward_token_id().get(); let user_total_farm_position = user_total_farm_position_struct.total_farm_position; 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 9b91f526b..ce3c5ef2f 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 @@ -27,16 +27,18 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: #[payable("*")] #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); let user = match opt_user { OptionalValue::Some(user) => user, - OptionalValue::None => self.blockchain().get_caller(), + OptionalValue::None => caller.clone(), }; let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); - require!( - user_total_farm_position_struct.allow_external_claim_boosted_rewards, - "Cannot claim rewards for this address" - ); - + if user != caller { + require!( + user_total_farm_position_struct.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } let reward_token_id = self.reward_token_id().get(); let user_total_farm_position = user_total_farm_position_struct.total_farm_position; if user_total_farm_position == BigUint::zero() { From 14baa0a42064756a750e3ddad049bc2c4052811f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 09:34:09 +0300 Subject: [PATCH 19/58] fees-collector:Add test for "claim for other user" --- .../tests/fees_collector_rust_test.rs | 132 ++++++++++++++++++ .../tests/fees_collector_test_setup/mod.rs | 14 ++ 2 files changed, 146 insertions(+) diff --git a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs index c840080e5..db4c3aace 100644 --- a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs +++ b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs @@ -463,6 +463,138 @@ fn claim_second_week_test() { ); } +#[test] +fn claim_for_other_user_test() { + let rust_zero = rust_biguint!(0); + let mut fc_setup = + FeesCollectorSetup::new(fees_collector::contract_obj, energy_factory::contract_obj); + + let first_user = fc_setup.b_mock.create_user_account(&rust_zero); + let second_user = fc_setup.b_mock.create_user_account(&rust_zero); + + fc_setup.set_energy(&first_user, 500, 1_000); + fc_setup.set_energy(&second_user, 500, 9_000); + + fc_setup.deposit(FIRST_TOKEN_ID, USER_BALANCE).assert_ok(); + fc_setup + .deposit(SECOND_TOKEN_ID, USER_BALANCE / 2) + .assert_ok(); + + // user claim first week - user only get registered for week 2, without receiving rewards + fc_setup.claim(&first_user).assert_ok(); + fc_setup.claim(&second_user).assert_ok(); + + // advance week + fc_setup.advance_week(); + + // increase first user's energy + fc_setup.set_energy(&first_user, 1000, 2_000); + + // claim week 2 - receives rewards accumulated in week 1, and gets new energy saved + fc_setup + .claim_for_user(&first_user, &second_user) + .assert_user_error("Cannot claim rewards for this address"); + + fc_setup.allow_external_claim_rewards(&first_user).assert_ok(); + // claim week 2 - receives rewards accumulated in week 1, and gets new energy saved + + fc_setup + .claim_for_user(&first_user, &second_user) + .assert_ok(); + + fc_setup + .b_mock + .execute_query(&fc_setup.fc_wrapper, |sc| { + let mut expected_total_rewards = ManagedVec::new(); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(FIRST_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE), + )); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(SECOND_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE / 2), + )); + assert_eq!(expected_total_rewards, sc.total_rewards_for_week(1).get()); + }) + .assert_ok(); + + let first_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 1_000u32 / 10_000u32; + let first_user_expected_second_token_amt = + rust_biguint!(USER_BALANCE / 2) * 1_000u32 / 10_000u32; + + fc_setup.b_mock.check_esdt_balance( + &first_user, + FIRST_TOKEN_ID, + &first_user_expected_first_token_amt, + ); + fc_setup.b_mock.check_esdt_balance( + &first_user, + SECOND_TOKEN_ID, + &first_user_expected_second_token_amt, + ); + + let current_epoch = fc_setup.current_epoch; + fc_setup + .b_mock + .execute_query(&fc_setup.fc_wrapper, |sc| { + // fees were cleared and accumulated in the total_rewards mapper + assert_eq!( + sc.accumulated_fees(1, &managed_token_id!(FIRST_TOKEN_ID)) + .get(), + managed_biguint!(0) + ); + assert_eq!( + sc.accumulated_fees(1, &managed_token_id!(SECOND_TOKEN_ID)) + .get(), + managed_biguint!(0) + ); + + let mut expected_total_rewards = ManagedVec::new(); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(FIRST_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE), + )); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(SECOND_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE / 2), + )); + assert_eq!(sc.total_rewards_for_week(1).get(), expected_total_rewards); + + // first user's new energy is added to week 2 + let first_user_energy = Energy::new( + BigInt::from(managed_biguint!(2_000)), + current_epoch, + managed_biguint!(1_000), + ); + + // 10_000 total prev week + // first user's tokens get removed, as they expired + // so we only decrease by second user's 500 tokens worth of energy + // + // - 7 * 500 global decrease (-3_500) + // - 1_000 (first user's surplus energy) + // + 2_000 (first user's new energy) + // = 7_500 + assert_eq!(sc.total_energy_for_week(2).get(), 7_500); + assert_eq!(sc.total_locked_tokens_for_week(2).get(), 1_500); + assert_eq!(sc.last_global_update_week().get(), 2); + + assert_eq!( + sc.current_claim_progress(&managed_address!(&first_user)) + .get(), + ClaimProgress { + energy: first_user_energy, + week: 2 + } + ); + }) + .assert_ok(); +} + #[test] fn claim_inactive_week_test() { let rust_zero = rust_biguint!(0); diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index e3524ce65..399fc574e 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -227,6 +227,20 @@ where }) } + pub fn claim_for_user(&mut self, owner: &Address, broker: &Address) -> TxResult { + self.b_mock + .execute_tx(broker, &self.fc_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.claim_rewards(OptionalValue::Some(managed_address!(owner))); + }) + } + + pub fn allow_external_claim_rewards(&mut self, user: &Address) -> TxResult { + self.b_mock + .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.allow_external_claim_rewards(&managed_address!(user)).set(true); + }) + } + pub fn set_energy(&mut self, user: &Address, total_locked_tokens: u64, energy_amount: u64) { let current_epoch = self.current_epoch; self.b_mock From 63de49e99efbe6fe4aa2726320709f257c755a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 13:23:14 +0300 Subject: [PATCH 20/58] Clippy fixes --- dex/farm/src/claim_boost_only.rs | 1 + .../farm-staking/src/claim_only_boosted_staking_rewards.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index c917983a0..55d7504ba 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -40,6 +40,7 @@ pub trait ClaimBoostOnlyModule: let caller = self.blockchain().get_caller(); let user = match opt_user { OptionalValue::Some(user) => user, + #[allow(clippy::redundant_clone)] OptionalValue::None => caller.clone(), }; let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); 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 ce3c5ef2f..f34fefb94 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 @@ -30,6 +30,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: let caller = self.blockchain().get_caller(); let user = match opt_user { OptionalValue::Some(user) => user, + #[allow(clippy::redundant_clone)] OptionalValue::None => caller.clone(), }; let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); From 0e7141ce91b53b79439b6422679b42371c936cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 13:23:59 +0300 Subject: [PATCH 21/58] farm: Add claim boosted for other user test --- dex/farm/tests/farm_multi_user_test.rs | 96 +++++++++++++++++++ .../tests/farm_setup/multi_user_farm_setup.rs | 34 +++++++ .../tests/fees_collector_rust_test.rs | 4 +- .../tests/fees_collector_test_setup/mod.rs | 4 +- 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 45b388ba0..8f9bfda0d 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -219,6 +219,102 @@ fn farm_with_boosted_yields_test() { ); } +#[test] +fn farm_claim_boosted_yields_for_other_user_test() { + let _ = DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enter farm + let first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_user.clone(); + let third_user = farm_setup.third_user.clone(); + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, first_farm_token_amount); + + // second user enter farm + let second_farm_token_amount = 50_000_000; + let second_user = farm_setup.second_user.clone(); + farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.enter_farm(&second_user, second_farm_token_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_amount); + let _ = farm_setup.claim_rewards(&second_user, 2, second_farm_token_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + 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); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + farm_setup.set_user_energy(&second_user, 4_000, 10, 1); + + // Second user claims for himself + let total_farm_tokens = first_farm_token_amount + second_farm_token_amount; + let second_base_farm_amt = second_farm_token_amount * 7_500 / total_farm_tokens; + let second_boosted_amt = 1533; // 4000 energy & 50_000_000 farm tokens + let second_total = second_base_farm_amt + second_boosted_amt; + + let second_receveived_reward_amt = + farm_setup.claim_rewards(&second_user, 4, second_farm_token_amount); + assert_eq!(second_receveived_reward_amt, second_total); + + farm_setup + .b_mock + .check_nft_balance::>( + &second_user, + FARM_TOKEN_ID, + 6, + &rust_biguint!(second_farm_token_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_receveived_reward_amt), + ); + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2500 * 3 * 1_000 / 5_000 + 2500 * 2 * 100_000_000 / 150_000_000) / (3 + 2) + // (1500 + 3333) / (5) = 966 + let first_boosted_amt = 966; // 1000 energy & 100_000_000 farm tokens + + // Second user claim boosted rewards for first user + farm_setup.allow_external_claim_rewards(&first_user); + + let first_receveived_boosted_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &second_user); + assert_eq!(first_receveived_boosted_amt, first_boosted_amt); + + // First user should receive the boosted rewards + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_receveived_boosted_amt), + ); +} + #[test] fn farm_change_boosted_yields_factors_test() { let _ = DebugApi::dummy(); 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 aa669401e..83e300386 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -2,6 +2,7 @@ use common_structs::FarmTokenAttributes; use config::ConfigModule; +use farm::claim_boost_only::ClaimBoostOnlyModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::{ storage::mappers::StorageTokenWrapper, @@ -401,6 +402,27 @@ where result } + pub fn claim_boosted_rewards_for_user(&mut self, owner: &Address, broker: &Address) -> u64 { + self.last_farm_token_nonce += 1; + + let mut result = 0; + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let reward_payment = + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + assert_eq!( + reward_payment.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(reward_payment.token_nonce, 0); + + result = reward_payment.amount.to_u64().unwrap(); + }) + .assert_ok(); + + result + } + pub fn claim_rewards_known_proxy( &mut self, user: &Address, @@ -493,6 +515,18 @@ where .assert_ok(); } + pub fn allow_external_claim_rewards(&mut self, user: &Address) { + self.b_mock + .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.user_total_farm_position(&managed_address!(user)).update( + |user_total_farm_position_struct| { + user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; + }, + ); + }) + .assert_ok(); + } + pub fn update_energy_for_user(&mut self) { let b_mock = &mut self.b_mock; let user_addr = &self.first_user; diff --git a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs index db4c3aace..9ca1441ad 100644 --- a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs +++ b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs @@ -495,7 +495,9 @@ fn claim_for_other_user_test() { .claim_for_user(&first_user, &second_user) .assert_user_error("Cannot claim rewards for this address"); - fc_setup.allow_external_claim_rewards(&first_user).assert_ok(); + fc_setup + .allow_external_claim_rewards(&first_user) + .assert_ok(); // claim week 2 - receives rewards accumulated in week 1, and gets new energy saved fc_setup diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index 399fc574e..e1d6b37e5 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -237,7 +237,9 @@ where pub fn allow_external_claim_rewards(&mut self, user: &Address) -> TxResult { self.b_mock .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { - let _ = sc.allow_external_claim_rewards(&managed_address!(user)).set(true); + let _ = sc + .allow_external_claim_rewards(&managed_address!(user)) + .set(true); }) } From f40d64ab22359dfc2ae5f14c3eb56d66765fa6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 13:24:16 +0300 Subject: [PATCH 22/58] farm-staking:Add test claim for other user --- .../tests/farm_staking_energy_test.rs | 95 +++++++++++++++++++ .../tests/farm_staking_setup/mod.rs | 44 +++++++++ 2 files changed, 139 insertions(+) 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 d7afaf744..551ae1e6b 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -148,3 +148,98 @@ fn farm_staking_boosted_rewards_with_energy_test() { ); fs_setup.check_farm_token_supply(farm_in_amount); } + +#[test] +fn farm_staking_claim_boosted_rewards_for_user_test() { + let _ = DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + + let farm_in_amount = 100_000_000; + fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &fs_setup.user_address, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_nonce(10); + + // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 3, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(managed_biguint!(10), OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + + // value taken from the "test_unstake_farm" test + // originally, it was 40, but since 25% of the rewards go to boosted yields + // rewards are now only 3/4 * 40 = 30 + // + // 10 reserved for boosted yields -> 30 + 10 + let expected_boosted_reward_token_out = 10; + let expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); + + // Random_user claim boosted rewards for user + fs_setup.allow_external_claim_rewards(&fs_setup.user_address.clone()); + fs_setup.claim_boosted_rewards_for_user( + &fs_setup.user_address.clone(), + &rand_user, + expected_boosted_reward_token_out, + &expected_farming_token_balance, + ); + fs_setup.check_farm_token_supply(farm_in_amount); +} 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 0ad97a738..d1128ea84 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -1,3 +1,4 @@ +use farm_staking::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, BigInt, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; @@ -274,6 +275,37 @@ where ); } + pub fn claim_boosted_rewards_for_user( + &mut self, + owner: &Address, + broker: &Address, + expected_reward_token_out: u64, + expected_user_reward_token_balance: &RustBigUint, + ) { + self.b_mock + .execute_tx(&broker, &self.farm_wrapper, &rust_biguint!(0u64), |sc| { + let payment_result = + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + + assert_eq!( + payment_result.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(payment_result.token_nonce, 0); + assert_eq!( + payment_result.amount, + managed_biguint!(expected_reward_token_out) + ); + }) + .assert_ok(); + + self.b_mock.check_esdt_balance( + &self.user_address, + REWARD_TOKEN_ID, + expected_user_reward_token_balance, + ); + } + #[allow(clippy::too_many_arguments)] pub fn unstake_farm( &mut self, @@ -383,6 +415,18 @@ where .assert_ok(); } + pub fn allow_external_claim_rewards(&mut self, user: &Address) { + self.b_mock + .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.user_total_farm_position(&managed_address!(user)).update( + |user_total_farm_position_struct| { + user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; + }, + ); + }) + .assert_ok(); + } + pub fn set_block_nonce(&mut self, block_nonce: u64) { self.b_mock.set_block_nonce(block_nonce); } From ff3f040840a54be146aae778b32e1232957c59e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 13:32:27 +0300 Subject: [PATCH 23/58] Fixes after review --- farm-staking/farm-staking/src/base_impl_wrapper.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index abe646541..adf6136a5 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -236,14 +236,7 @@ where sc.user_total_farm_position(&token_attributes.original_owner) .update(|user_farm_position_struct| { - let mut user_total_farm_position = - user_farm_position_struct.total_farm_position.clone(); - if user_total_farm_position > farm_position.amount { - user_total_farm_position -= &farm_position.amount; - } else { - user_total_farm_position = BigUint::zero(); - } - user_farm_position_struct.total_farm_position = user_total_farm_position; + user_farm_position_struct.total_farm_position -= farm_position.amount.clone() }); } } From f1496d5f8d53b88c6f41354f531a13149a66b70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 14:43:21 +0300 Subject: [PATCH 24/58] farm: compound_rewards_base bug fix Correctly update total farm position --- common/modules/farm/farm_base_impl/src/base_traits_impl.rs | 4 ++-- common/modules/farm/farm_base_impl/src/compound_rewards.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 81aa35955..d3260a170 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -221,11 +221,11 @@ pub trait FarmContract { fn increase_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, - new_farm_position_amount: &BigUint<::Api>, + increase_farm_position_amount: &BigUint<::Api>, ) { sc.user_total_farm_position(user) .update(|user_farm_position_struct| { - user_farm_position_struct.total_farm_position += new_farm_position_amount + user_farm_position_struct.total_farm_position += increase_farm_position_amount }); } diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index 6a00848a4..74a5f74d6 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -52,7 +52,6 @@ pub trait BaseCompoundRewardsModule: ); FC::check_and_update_user_farm_position(self, &caller, &payments); - FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &compound_rewards_context.first_farm_token.payment.amount; @@ -75,7 +74,7 @@ pub trait BaseCompoundRewardsModule: let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_compound_rewards_initial_attributes( self, - caller, + caller.clone(), token_attributes, storage_cache.reward_per_share.clone(), &reward, @@ -86,6 +85,8 @@ pub trait BaseCompoundRewardsModule: &farm_token_mapper, ); + FC::increase_user_farm_position(self, &caller, &reward); + let first_farm_token = &compound_rewards_context.first_farm_token.payment; farm_token_mapper.nft_burn(first_farm_token.token_nonce, &first_farm_token.amount); self.send() From 98aa8365a6c29ff5ff7f80b54973270108ca7867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 14:53:09 +0300 Subject: [PATCH 25/58] Refactor clippy fix --- dex/farm/src/claim_boost_only.rs | 15 +++++++-------- .../src/claim_only_boosted_staking_rewards.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs index 55d7504ba..82a2d4ffc 100644 --- a/dex/farm/src/claim_boost_only.rs +++ b/dex/farm/src/claim_boost_only.rs @@ -38,13 +38,12 @@ pub trait ClaimBoostOnlyModule: opt_user: OptionalValue, ) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); - let user = match opt_user { + let user = match &opt_user { OptionalValue::Some(user) => user, - #[allow(clippy::redundant_clone)] - OptionalValue::None => caller.clone(), + OptionalValue::None => &caller, }; - let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); - if user != caller { + let user_total_farm_position_struct = self.get_user_total_farm_position_struct(user); + if user != &caller { require!( user_total_farm_position_struct.allow_external_claim_boosted_rewards, "Cannot claim rewards for this address" @@ -57,15 +56,15 @@ pub trait ClaimBoostOnlyModule: return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } - let reward = self.claim_boosted_yields_rewards(&user, user_total_farm_position); + let reward = self.claim_boosted_yields_rewards(user, user_total_farm_position); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); - self.send_payment_non_zero(&user, &boosted_rewards); + self.send_payment_non_zero(user, &boosted_rewards); - self.update_energy_and_progress(&user); + self.update_energy_and_progress(user); boosted_rewards } 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 f34fefb94..03253057b 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 @@ -28,13 +28,13 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); - let user = match opt_user { + let user = match &opt_user { OptionalValue::Some(user) => user, #[allow(clippy::redundant_clone)] - OptionalValue::None => caller.clone(), + OptionalValue::None => &caller, }; - let user_total_farm_position_struct = self.get_user_total_farm_position_struct(&user); - if user != caller { + let user_total_farm_position_struct = self.get_user_total_farm_position_struct(user); + if user != &caller { require!( user_total_farm_position_struct.allow_external_claim_boosted_rewards, "Cannot claim rewards for this address" @@ -46,15 +46,15 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); } - let reward = self.claim_boosted_yields_rewards(&user, user_total_farm_position); + let reward = self.claim_boosted_yields_rewards(user, user_total_farm_position); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); - self.send_payment_non_zero(&user, &boosted_rewards); + self.send_payment_non_zero(user, &boosted_rewards); - self.update_energy_and_progress(&user); + self.update_energy_and_progress(user); boosted_rewards } From f371569355d7ec77ab9a4d2934c57f756e0c7466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 31 Aug 2023 17:22:03 +0300 Subject: [PATCH 26/58] Clippy fix for test setup --- dex/farm/tests/farm_setup/multi_user_farm_setup.rs | 2 +- .../fees-collector/tests/fees_collector_test_setup/mod.rs | 3 +-- farm-staking/farm-staking/tests/farm_staking_setup/mod.rs | 4 ++-- .../tests/energy_factory_setup/unbond_sc_mock.rs | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) 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 83e300386..c70d3a3ae 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -518,7 +518,7 @@ where pub fn allow_external_claim_rewards(&mut self, user: &Address) { self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { - let _ = sc.user_total_farm_position(&managed_address!(user)).update( + sc.user_total_farm_position(&managed_address!(user)).update( |user_total_farm_position_struct| { user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; }, diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index e1d6b37e5..1d6d73e5d 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -237,8 +237,7 @@ where pub fn allow_external_claim_rewards(&mut self, user: &Address) -> TxResult { self.b_mock .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { - let _ = sc - .allow_external_claim_rewards(&managed_address!(user)) + sc.allow_external_claim_rewards(&managed_address!(user)) .set(true); }) } 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 d1128ea84..cbdb0ddd1 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -283,7 +283,7 @@ where expected_user_reward_token_balance: &RustBigUint, ) { self.b_mock - .execute_tx(&broker, &self.farm_wrapper, &rust_biguint!(0u64), |sc| { + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0u64), |sc| { let payment_result = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); @@ -418,7 +418,7 @@ where pub fn allow_external_claim_rewards(&mut self, user: &Address) { self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { - let _ = sc.user_total_farm_position(&managed_address!(user)).update( + sc.user_total_farm_position(&managed_address!(user)).update( |user_total_farm_position_struct| { user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; }, diff --git a/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs b/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs index 1b472a676..c993b7e24 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs @@ -35,11 +35,11 @@ impl UnbondScMock { pub fn send_to_user(&self) { let [locked_tokens, unlocked_tokens] = self.call_value().multi_esdt(); - let locked_tokens_burn_amount = unlocked_tokens.amount.clone(); + let locked_tokens_burn_amount = &unlocked_tokens.amount; self.send().esdt_local_burn( &locked_tokens.token_identifier, locked_tokens.token_nonce, - &locked_tokens_burn_amount, + locked_tokens_burn_amount, ); let (dest_user, ()) = From 5b00a9c7f4b582572702513839ea6dc0cee0bf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 4 Sep 2023 09:36:28 +0300 Subject: [PATCH 27/58] Give boosted energy even after unlock xMEX --- .../weekly-rewards-splitting/src/lib.rs | 28 +++----- .../tests/fees_collector_rust_test.rs | 65 ------------------- .../mod.rs | 2 +- 3 files changed, 11 insertions(+), 84 deletions(-) diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs index 8120994a9..9268023bd 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs @@ -86,25 +86,17 @@ pub trait WeeklyRewardsSplittingModule: let mut all_rewards = ManagedVec::new(); - // for the case when a user locks, enters the weekly rewards, and then unlocks. - // Then, they wait for a long period, and start claiming, - // getting rewards they shouldn't have access to. - // In this case, they receive no rewards, and their progress is reset - if current_user_energy.get_energy_amount_raw() - >= calculated_energy_for_current_epoch.get_energy_amount_raw() - { - let total_weeks_to_claim = current_week - claim_progress.week; - if total_weeks_to_claim > USER_MAX_CLAIM_WEEKS { - let extra_weeks = total_weeks_to_claim - USER_MAX_CLAIM_WEEKS; - claim_progress.advance_multiple_weeks(extra_weeks); - } + let total_weeks_to_claim = current_week - claim_progress.week; + if total_weeks_to_claim > USER_MAX_CLAIM_WEEKS { + let extra_weeks = total_weeks_to_claim - USER_MAX_CLAIM_WEEKS; + claim_progress.advance_multiple_weeks(extra_weeks); + } - let weeks_to_claim = core::cmp::min(total_weeks_to_claim, USER_MAX_CLAIM_WEEKS); - for _ in 0..weeks_to_claim { - let rewards_for_week = self.claim_single(wrapper, &mut claim_progress); - if !rewards_for_week.is_empty() { - all_rewards.append_vec(rewards_for_week); - } + let weeks_to_claim = core::cmp::min(total_weeks_to_claim, USER_MAX_CLAIM_WEEKS); + for _ in 0..weeks_to_claim { + let rewards_for_week = self.claim_single(wrapper, &mut claim_progress); + if !rewards_for_week.is_empty() { + all_rewards.append_vec(rewards_for_week); } } diff --git a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs index 9ca1441ad..2c22c309a 100644 --- a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs +++ b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs @@ -700,71 +700,6 @@ fn claim_inactive_week_test() { ); } -#[test] -fn try_claim_after_unlock() { - let rust_zero = rust_biguint!(0); - let mut fc_setup = - FeesCollectorSetup::new(fees_collector::contract_obj, energy_factory::contract_obj); - - let first_user = fc_setup.b_mock.create_user_account(&rust_zero); - let second_user = fc_setup.b_mock.create_user_account(&rust_zero); - - fc_setup.set_energy(&first_user, 50, 3_000); - fc_setup.set_energy(&second_user, 50, 9_000); - - fc_setup.deposit(FIRST_TOKEN_ID, USER_BALANCE).assert_ok(); - fc_setup - .deposit(SECOND_TOKEN_ID, USER_BALANCE / 2) - .assert_ok(); - - // user claim first week - users only get registered for week 2, without receiving rewards - fc_setup.claim(&first_user).assert_ok(); - fc_setup.claim(&second_user).assert_ok(); - - // advance week - fc_setup.advance_week(); - - // deposit rewards week 2 - fc_setup.deposit(FIRST_TOKEN_ID, USER_BALANCE).assert_ok(); - fc_setup - .deposit(SECOND_TOKEN_ID, USER_BALANCE / 2) - .assert_ok(); - - // decrease user energy - fc_setup.set_energy(&first_user, 50, 1_000); - - // only first user claims in second week - fc_setup.claim(&first_user).assert_ok(); - - // no rewards are received, as energy decreased from the calculated amount - fc_setup - .b_mock - .check_esdt_balance(&first_user, FIRST_TOKEN_ID, &rust_zero); - fc_setup - .b_mock - .check_esdt_balance(&first_user, SECOND_TOKEN_ID, &rust_zero); - - let current_epoch = fc_setup.current_epoch; - fc_setup - .b_mock - .execute_query(&fc_setup.fc_wrapper, |sc| { - let first_user_energy = Energy::new( - BigInt::from(managed_biguint!(1_000)), - current_epoch, - managed_biguint!(50), - ); - assert_eq!( - sc.current_claim_progress(&managed_address!(&first_user)) - .get(), - ClaimProgress { - energy: first_user_energy, - week: 2 - } - ); - }) - .assert_ok(); -} - #[test] fn locked_token_buckets_shifting_test() { let rust_zero = rust_biguint!(0); diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs index 02729ff2d..3b18eed52 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs @@ -76,7 +76,7 @@ where &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); - let mut block_round = 1; + let mut block_round: u64 = 1; b_mock.set_block_round(block_round); b_mock.set_block_nonce(BLOCK_NONCE_FIRST_ADD_LIQ); From 00dc45d05792db3ce6cdb22189f4b65c04bbfe38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 4 Sep 2023 17:04:56 +0300 Subject: [PATCH 28/58] Fixes after review --- common/modules/farm/farm_base_impl/src/base_traits_impl.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index d3260a170..964c014fe 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -217,6 +217,7 @@ pub trait FarmContract { Self::increase_user_farm_position(sc, user, &farm_position_increase); } } + #[inline] fn increase_user_farm_position( sc: &Self::FarmSc, From 249c3eefa7d8ae8920d838c243036d2cf4cbe754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 7 Sep 2023 11:02:28 +0300 Subject: [PATCH 29/58] Fix clippy --- .../tests/farm_with_locked_rewards_test.rs | 4 +- dex/farm/tests/farm_multi_user_test.rs | 18 +-- .../farm_setup/single_user_farm_setup.rs | 4 +- dex/farm/tests/farm_single_user_test.rs | 2 +- dex/pair/tests/pair_rs_test.rs | 4 +- dex/price-discovery/tests/price_disc_tests.rs | 2 +- dex/router/tests/router_test.rs | 4 +- .../tests/fees_collector_test_setup/mod.rs | 2 +- .../src/proxy_actions/merge_pos.rs | 108 ++++++++++++++++++ .../tests/staking_farm_with_lp.rs | 2 +- .../tests/farm_staking_energy_test.rs | 6 +- .../farm-staking/tests/farm_staking_test.rs | 12 +- .../tests/metabonding_staking_setup/mod.rs | 2 +- .../tests/energy_factory_setup/mod.rs | 2 +- .../energy-factory/tests/old_tokens_test.rs | 8 +- .../tests/token_merging_test.rs | 10 +- .../factory/tests/factory_setup/mod.rs | 2 +- locked-asset/factory/tests/unlock_test.rs | 2 +- .../tests/locked_token_wrapping_test.rs | 4 +- .../tests/proxy_dex_test_setup/mod.rs | 2 +- .../tests/whitelist_test.rs | 2 +- locked-asset/simple-lock/tests/rust_test.rs | 2 +- .../tests/token_unstake_setup/mod.rs | 2 +- .../token-unstake/tests/unlock_early_test.rs | 2 +- 24 files changed, 158 insertions(+), 50 deletions(-) create mode 100644 farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs 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 941c08f8e..db4f9e7bc 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 @@ -12,7 +12,7 @@ mod farm_with_locked_rewards_setup; #[test] fn farm_with_no_boost_no_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmSetup::new( farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, @@ -112,7 +112,7 @@ fn farm_with_no_boost_no_proxy_test() { #[test] fn farm_with_boosted_yields_no_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmSetup::new( farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 9135f8c24..182de5c8c 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -13,7 +13,7 @@ use weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo; #[test] fn farm_with_no_boost_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -111,7 +111,7 @@ fn farm_with_no_boost_test() { #[test] fn farm_with_boosted_yields_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -223,7 +223,7 @@ fn farm_with_boosted_yields_test() { #[test] fn farm_claim_boosted_yields_for_other_user_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -319,7 +319,7 @@ fn farm_claim_boosted_yields_for_other_user_test() { #[test] fn farm_change_boosted_yields_factors_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -382,7 +382,7 @@ fn farm_change_boosted_yields_factors_test() { #[test] fn farm_boosted_yields_claim_with_different_user_pos_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -484,7 +484,7 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { #[test] fn farm_known_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -583,7 +583,7 @@ fn farm_known_proxy_test() { #[test] fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -833,7 +833,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { #[test] fn farm_enter_with_multiple_farm_token() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -948,7 +948,7 @@ fn farm_enter_with_multiple_farm_token() { #[test] fn farm_claim_with_minimum_tokens() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, 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 6dd2620e7..13644ee88 100644 --- a/dex/farm/tests/farm_setup/single_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/single_user_farm_setup.rs @@ -184,7 +184,7 @@ where }) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let expected_attributes = FarmTokenAttributes:: { reward_per_share: managed_biguint!(expected_reward_per_share), @@ -300,7 +300,7 @@ where ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let expected_attributes = FarmTokenAttributes:: { reward_per_share: managed_biguint!(expected_reward_per_share), entering_epoch: 0, diff --git a/dex/farm/tests/farm_single_user_test.rs b/dex/farm/tests/farm_single_user_test.rs index eb5c9f61c..9adc893fa 100644 --- a/dex/farm/tests/farm_single_user_test.rs +++ b/dex/farm/tests/farm_single_user_test.rs @@ -209,7 +209,7 @@ fn test_farm_through_simple_lock() { const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456"; const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456"; - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); let b_mock = &mut farm_setup.blockchain_wrapper; diff --git a/dex/pair/tests/pair_rs_test.rs b/dex/pair/tests/pair_rs_test.rs index ea2a2cf52..eb90a88f6 100644 --- a/dex/pair/tests/pair_rs_test.rs +++ b/dex/pair/tests/pair_rs_test.rs @@ -956,7 +956,7 @@ fn test_locked_asset() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); pair_setup.b_mock.check_nft_balance( &pair_setup.user_address, LOCKED_TOKEN_ID, @@ -1077,7 +1077,7 @@ fn add_liquidity_through_simple_lock_proxy() { ); pair_setup.b_mock.set_block_epoch(5); - let _ = DebugApi::dummy(); + DebugApi::dummy(); // lock some tokens first pair_setup diff --git a/dex/price-discovery/tests/price_disc_tests.rs b/dex/price-discovery/tests/price_disc_tests.rs index db0905cf8..a6cfbec43 100644 --- a/dex/price-discovery/tests/price_disc_tests.rs +++ b/dex/price-discovery/tests/price_disc_tests.rs @@ -367,7 +367,7 @@ fn redeem_ok() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let first_user_expected_launched_tokens_balance = rust_biguint!(5_000_000_000u64 * 600_000_000 / 1_100_000_000); pd_setup.blockchain_wrapper.check_nft_balance( diff --git a/dex/router/tests/router_test.rs b/dex/router/tests/router_test.rs index 17e74be21..b4b7ad010 100644 --- a/dex/router/tests/router_test.rs +++ b/dex/router/tests/router_test.rs @@ -347,7 +347,7 @@ fn user_enable_pair_swaps_through_router_test() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user, LOCKED_TOKEN_ID, @@ -518,7 +518,7 @@ fn user_enable_pair_swaps_fail_test() { .assert_ok(); let custom_locked_token = b"LTOK2-123456"; - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.set_nft_balance( &user, custom_locked_token, diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index 6b0fdb9e0..2809ac297 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -108,7 +108,7 @@ where &rust_biguint!(USER_BALANCE * 2), ); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.set_nft_balance( &depositor_address, 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 new file mode 100644 index 000000000..2a81f2cf4 --- /dev/null +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs @@ -0,0 +1,108 @@ +farm-staking/farm-staking-proxy/tests/composed_pos_test.rsuse 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/tests/staking_farm_with_lp.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs index e54f13dc6..b15c69cc0 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 @@ -207,7 +207,7 @@ fn unstake_through_proxy_after_claim() { #[test] fn unstake_partial_position_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = FarmStakingSetup::new( pair::contract_obj, farm::contract_obj, 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 df50ae354..9ce3d963e 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -20,7 +20,7 @@ fn farm_staking_with_energy_setup_test() { #[test] fn farm_staking_boosted_rewards_no_energy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -56,7 +56,7 @@ fn farm_staking_boosted_rewards_no_energy_test() { #[test] fn farm_staking_boosted_rewards_with_energy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -153,7 +153,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { #[test] fn farm_staking_claim_boosted_rewards_for_user_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); diff --git a/farm-staking/farm-staking/tests/farm_staking_test.rs b/farm-staking/farm-staking/tests/farm_staking_test.rs index 271efe5c2..ed0925510 100644 --- a/farm-staking/farm-staking/tests/farm_staking_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_test.rs @@ -16,7 +16,7 @@ fn test_farm_setup() { #[test] fn test_enter_farm() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -28,7 +28,7 @@ fn test_enter_farm() { #[test] fn test_unstake_farm() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -70,7 +70,7 @@ fn test_unstake_farm() { #[test] fn test_claim_rewards() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -147,13 +147,13 @@ where #[test] fn test_enter_farm_twice() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let _ = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); } #[test] fn test_exit_farm_after_enter_twice() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); let farm_in_amount = 100_000_000; @@ -183,7 +183,7 @@ fn test_exit_farm_after_enter_twice() { #[test] fn test_unbond() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); diff --git a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs b/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs index b32812145..a4b8effeb 100644 --- a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs +++ b/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs @@ -47,7 +47,7 @@ where mbs_builder: MetabondingStakingObjBuilder, laf_builder: LockedAssetFactoryObjBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); diff --git a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs index f6693c2fe..de10068c0 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs @@ -52,7 +52,7 @@ where ScBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, { pub fn new(sc_builder: ScBuilder) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/energy-factory/tests/old_tokens_test.rs b/locked-asset/energy-factory/tests/old_tokens_test.rs index 2e45d0d83..d4bd57a3c 100644 --- a/locked-asset/energy-factory/tests/old_tokens_test.rs +++ b/locked-asset/energy-factory/tests/old_tokens_test.rs @@ -21,7 +21,7 @@ use multiversx_sc_scenario::{ #[test] fn extend_lock_period_old_token_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -140,7 +140,7 @@ fn extend_lock_period_old_token_test() { #[test] fn min_period_migrated_token_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -250,7 +250,7 @@ fn min_period_migrated_token_test() { #[test] fn min_period_migrated_token_test2() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -370,7 +370,7 @@ fn min_period_migrated_token_test2() { #[test] fn check_initial_old_unlock_schedule_decode_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); diff --git a/locked-asset/energy-factory/tests/token_merging_test.rs b/locked-asset/energy-factory/tests/token_merging_test.rs index 00b4ede93..b32445506 100644 --- a/locked-asset/energy-factory/tests/token_merging_test.rs +++ b/locked-asset/energy-factory/tests/token_merging_test.rs @@ -31,7 +31,7 @@ use multiversx_sc_scenario::{managed_token_id_wrapped, rust_biguint, DebugApi}; #[test] fn token_merging_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -101,7 +101,7 @@ fn token_merging_test() { #[test] fn token_merging_different_years_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -171,7 +171,7 @@ fn token_merging_different_years_test() { #[test] fn token_merging_different_years2_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -241,7 +241,7 @@ fn token_merging_different_years2_test() { #[test] fn test_specific_tokens_merge() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); @@ -371,7 +371,7 @@ fn test_specific_tokens_merge() { #[test] fn merge_same_schedule_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let user = setup.first_user.clone(); let unlock_epoch = to_start_of_month(LOCK_OPTIONS[0]); diff --git a/locked-asset/factory/tests/factory_setup/mod.rs b/locked-asset/factory/tests/factory_setup/mod.rs index 9fec3157d..633805223 100644 --- a/locked-asset/factory/tests/factory_setup/mod.rs +++ b/locked-asset/factory/tests/factory_setup/mod.rs @@ -50,7 +50,7 @@ where factory_builder: FactoryBuilder, energy_factory_builder: EnergyFactoryBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/factory/tests/unlock_test.rs b/locked-asset/factory/tests/unlock_test.rs index b1e26d7d7..057cf409c 100644 --- a/locked-asset/factory/tests/unlock_test.rs +++ b/locked-asset/factory/tests/unlock_test.rs @@ -775,7 +775,7 @@ fn test_aggregated_unlock_schedule_with_1_offset() { #[test] fn update_energy_after_old_token_unlock_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = FactorySetup::new(factory::contract_obj, energy_factory::contract_obj); diff --git a/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs b/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs index 13edf221e..812b114e9 100644 --- a/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs +++ b/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs @@ -19,7 +19,7 @@ static WRAPPED_TOKEN_ID: &[u8] = b"WRAPPED-123456"; #[test] fn token_wrap_unwrap_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); @@ -179,7 +179,7 @@ fn token_wrap_unwrap_test() { #[test] fn tokens_wrap_unwrap_test2() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); diff --git a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs index 413ddb980..c93cfc924 100644 --- a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs +++ b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs @@ -87,7 +87,7 @@ where farm_locked_builder: FarmLockedObjBuilder, simple_lock_builder: SimpleLockObjBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); diff --git a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs b/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs index d2f335ec1..54bb650a5 100644 --- a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs +++ b/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs @@ -82,7 +82,7 @@ fn lock_whitelist_test() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user_addr, LOCKED_TOKEN_ID, diff --git a/locked-asset/simple-lock/tests/rust_test.rs b/locked-asset/simple-lock/tests/rust_test.rs index 8b760049a..7b3395672 100644 --- a/locked-asset/simple-lock/tests/rust_test.rs +++ b/locked-asset/simple-lock/tests/rust_test.rs @@ -66,7 +66,7 @@ fn lock_unlock_test() { .assert_ok(); // needed for the managed types in LockedTokenAttributes - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user_addr, LOCKED_TOKEN_ID, diff --git a/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs b/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs index 5191fe7b8..edac051d7 100644 --- a/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs +++ b/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs @@ -65,7 +65,7 @@ where energy_factory_builder: EnergyFactoryBuilder, unstake_sc_builder: UnstakeScBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/token-unstake/tests/unlock_early_test.rs b/locked-asset/token-unstake/tests/unlock_early_test.rs index 5da1c4021..985796d94 100644 --- a/locked-asset/token-unstake/tests/unlock_early_test.rs +++ b/locked-asset/token-unstake/tests/unlock_early_test.rs @@ -9,7 +9,7 @@ use token_unstake_setup::*; #[test] fn double_unlock_early_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = TokenUnstakeSetup::new(energy_factory::contract_obj, token_unstake::contract_obj); let first_user = setup.first_user.clone(); From 4b4e0b713f54349a47ecd0dba0ff866d6bcd6689 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Wed, 13 Sep 2023 11:14:56 +0300 Subject: [PATCH 30/58] farm position first audit fixes --- common/modules/farm/config/src/config.rs | 48 ++++-- .../farm_base_impl/src/base_traits_impl.rs | 41 +++-- .../farm/farm_base_impl/src/claim_rewards.rs | 4 +- .../farm_base_impl/src/compound_rewards.rs | 3 +- dex/farm-with-locked-rewards/src/lib.rs | 121 +++++++++------ dex/farm-with-locked-rewards/wasm/Cargo.lock | 84 ++-------- dex/farm-with-locked-rewards/wasm/src/lib.rs | 142 +++++++++-------- dex/farm/src/base_functions.rs | 29 ++-- dex/farm/src/claim_boost_only.rs | 90 ----------- dex/farm/src/lib.rs | 107 ++++++++----- dex/farm/src/progress_update.rs | 27 ---- dex/farm/tests/farm_multi_user_test.rs | 8 +- .../tests/farm_setup/multi_user_farm_setup.rs | 9 +- dex/farm/wasm/Cargo.lock | 84 ++-------- dex/farm/wasm/src/lib.rs | 136 ++++++++-------- .../farm-boosted-yields/src/lib.rs | 9 +- energy-integration/fees-collector/elrond.json | 3 - .../fees-collector/src/config.rs | 7 + .../fees-collector/wasm/Cargo.lock | 84 ++-------- .../fees-collector/wasm/src/lib.rs | 85 +++++----- .../src/proxy_actions/merge_pos.rs | 2 +- .../farm-staking-proxy/wasm/Cargo.lock | 84 ++-------- .../farm-staking-proxy/wasm/src/lib.rs | 39 +++-- farm-staking/farm-staking/elrond.json | 3 - .../farm-staking/src/base_impl_wrapper.rs | 34 ++-- .../src/claim_only_boosted_staking_rewards.rs | 41 ++--- .../farm-staking/src/custom_rewards.rs | 2 +- farm-staking/farm-staking/src/lib.rs | 30 +++- farm-staking/farm-staking/src/stake_farm.rs | 20 ++- farm-staking/farm-staking/src/unstake_farm.rs | 6 +- .../tests/farm_staking_setup/mod.rs | 4 +- farm-staking/farm-staking/wasm/Cargo.lock | 84 ++-------- farm-staking/farm-staking/wasm/src/lib.rs | 146 +++++++++--------- 33 files changed, 682 insertions(+), 934 deletions(-) delete mode 100644 dex/farm/src/claim_boost_only.rs delete mode 100644 dex/farm/src/progress_update.rs delete mode 100644 energy-integration/fees-collector/elrond.json delete mode 100644 farm-staking/farm-staking/elrond.json diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index c7768500f..cb1385ba3 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -19,11 +19,20 @@ pub const DEFAULT_NFT_DEPOSIT_MAX_LEN: usize = 10; PartialEq, Debug, )] -pub struct UserTotalFarmPositionStruct { +pub struct UserTotalFarmPosition { pub total_farm_position: BigUint, pub allow_external_claim_boosted_rewards: bool, } +impl Default for UserTotalFarmPosition { + fn default() -> Self { + Self { + total_farm_position: BigUint::zero(), + allow_external_claim_boosted_rewards: false, + } + } +} + #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { #[inline] @@ -32,17 +41,36 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio state == State::Active } - fn get_user_total_farm_position_struct( + fn get_user_total_farm_position( &self, user: &ManagedAddress, - ) -> UserTotalFarmPositionStruct { - self.user_total_farm_position(user) - .set_if_empty(UserTotalFarmPositionStruct { - total_farm_position: BigUint::zero(), - allow_external_claim_boosted_rewards: false, - }); + ) -> UserTotalFarmPosition { + let user_total_farm_position_mapper = self.user_total_farm_position(user); + if user_total_farm_position_mapper.is_empty() { + UserTotalFarmPosition::default() + } else { + user_total_farm_position_mapper.get() + } + } - self.user_total_farm_position(user).get() + #[endpoint(allowExternalClaimBoostedRewards)] + fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { + let caller = self.blockchain().get_caller(); + let user_total_farm_position_mapper = self.user_total_farm_position(&caller); + if user_total_farm_position_mapper.is_empty() { + require!( + allow_external_claim, + "Can only set to true if there is no farm position" + ); + let mut new_user_farm_position: UserTotalFarmPosition = + UserTotalFarmPosition::default(); + new_user_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + } else { + user_total_farm_position_mapper.update(|user_total_farm_position| { + user_total_farm_position.allow_external_claim_boosted_rewards = + allow_external_claim; + }); + } } #[view(getFarmingTokenId)] @@ -73,5 +101,5 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio fn user_total_farm_position( &self, user: &ManagedAddress, - ) -> SingleValueMapper>; + ) -> SingleValueMapper>; } diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 964c014fe..728d7097f 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -210,8 +210,10 @@ pub trait FarmContract { } } - let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(user); - if user_total_farm_position_struct.total_farm_position == BigUint::zero() { + let user_total_farm_position = sc.get_user_total_farm_position(user); + if user_total_farm_position.total_farm_position == BigUint::zero() + && total_farm_position > 0 + { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); @@ -224,10 +226,10 @@ pub trait FarmContract { user: &ManagedAddress<::Api>, increase_farm_position_amount: &BigUint<::Api>, ) { + let mut user_total_farm_position = sc.get_user_total_farm_position(user); + user_total_farm_position.total_farm_position += increase_farm_position_amount; sc.user_total_farm_position(user) - .update(|user_farm_position_struct| { - user_farm_position_struct.total_farm_position += increase_farm_position_amount - }); + .set(user_total_farm_position); } fn decrease_user_farm_position( @@ -238,17 +240,24 @@ pub trait FarmContract { let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - sc.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position_struct| { - let mut user_total_farm_position = - user_farm_position_struct.total_farm_position.clone(); - if user_total_farm_position > farm_position.amount { - user_total_farm_position -= &farm_position.amount; - } else { - user_total_farm_position = BigUint::zero(); - } - user_farm_position_struct.total_farm_position = user_total_farm_position; - }); + let mut user_total_farm_position = + sc.get_user_total_farm_position(&token_attributes.original_owner); + + if user_total_farm_position.total_farm_position > farm_position.amount { + user_total_farm_position.total_farm_position -= &farm_position.amount; + } else { + user_total_farm_position.total_farm_position = BigUint::zero(); + } + + if user_total_farm_position.total_farm_position == 0 + && user_total_farm_position.allow_external_claim_boosted_rewards == false + { + sc.user_total_farm_position(&token_attributes.original_owner) + .clear(); + } else { + sc.user_total_farm_position(&token_attributes.original_owner) + .set(user_total_farm_position); + } } } diff --git a/common/modules/farm/farm_base_impl/src/claim_rewards.rs b/common/modules/farm/farm_base_impl/src/claim_rewards.rs index 85b0e7ef6..d9dfe293e 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -63,8 +63,6 @@ pub trait BaseClaimRewardsModule: self.blockchain(), ); - FC::check_and_update_user_farm_position(self, &caller, &payments); - FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &claim_rewards_context.first_farm_token.payment.amount; @@ -83,6 +81,8 @@ pub trait BaseClaimRewardsModule: ); storage_cache.reward_reserve -= &reward; + FC::check_and_update_user_farm_position(self, &caller, &payments); + let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_claim_rewards_initial_attributes( self, diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index 74a5f74d6..06e52585c 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -51,7 +51,6 @@ pub trait BaseCompoundRewardsModule: self.blockchain(), ); - FC::check_and_update_user_farm_position(self, &caller, &payments); FC::generate_aggregated_rewards(self, &mut storage_cache); let farm_token_amount = &compound_rewards_context.first_farm_token.payment.amount; @@ -71,6 +70,8 @@ pub trait BaseCompoundRewardsModule: storage_cache.reward_reserve -= &reward; storage_cache.farm_token_supply += &reward; + FC::check_and_update_user_farm_position(self, &caller, &payments); + let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_compound_rewards_initial_attributes( self, diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 948ed0739..0205b1fca 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, Wrapper}, + base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }, @@ -34,8 +34,6 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + farm::base_functions::BaseFunctionsModule + farm::exit_penalty::ExitPenaltyModule - + farm::progress_update::ProgressUpdateModule - + farm::claim_boost_only::ClaimBoostOnlyModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -89,19 +87,16 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let payments = self.get_non_empty_payments(); - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => { - let unlocked_rewards = self.claim_only_boosted_payment(&orig_caller, &p); - self.send_to_lock_contract_non_zero( - unlocked_rewards.token_identifier, - unlocked_rewards.amount, - caller.clone(), - orig_caller.clone(), - ) - } - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), + let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + let boosted_rewards_payment = if boosted_rewards > 0 { + self.send_to_lock_contract_non_zero( + self.reward_token_id().get(), + boosted_rewards, + caller.clone(), + orig_caller.clone(), + ) + } else { + EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()) }; let new_farm_token = self.enter_farm::>(orig_caller.clone()); @@ -109,7 +104,7 @@ pub trait Farm: self.update_energy_and_progress(&orig_caller); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } #[payable("*")] @@ -163,7 +158,10 @@ pub trait Farm: "Exit amount is bigger than the payment amount" ); - let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment); + 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, @@ -186,7 +184,7 @@ pub trait Farm: orig_caller.clone(), ); - self.clear_user_energy_if_needed(&orig_caller, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&orig_caller); ( exit_farm_result.farming_tokens, @@ -196,41 +194,57 @@ pub trait Farm: .into() } - #[view(calculateRewardsForGivenPosition)] - fn calculate_rewards_for_given_position( - &self, - user: ManagedAddress, - farm_token_amount: BigUint, - attributes: FarmTokenAttributes, - ) -> BigUint { - self.require_queried(); - - let mut storage_cache = StorageCache::new(self); - NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); - - NoMintWrapper::::calculate_rewards( - self, - &user, - &farm_token_amount, - &attributes, - &storage_cache, - ) - } - #[payable("*")] #[endpoint(mergeFarmTokens)] 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); + + 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); - 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() + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_user: OptionalValue, + ) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); + let user = match &opt_user { + OptionalValue::Some(user) => user, + OptionalValue::None => &caller, + }; + let user_total_farm_position = self.get_user_total_farm_position(user); + if user != &caller { + require!( + user_total_farm_position.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } + + let boosted_rewards = self.claim_only_boosted_payment(&user); + let locked_rewards_payment = self.send_to_lock_contract_non_zero( + self.reward_token_id().get(), + boosted_rewards, + caller.clone(), + user.clone(), + ); + + locked_rewards_payment } #[endpoint(startProduceRewards)] @@ -251,6 +265,27 @@ pub trait Farm: self.set_per_block_rewards::>(per_block_amount); } + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + user: ManagedAddress, + farm_token_amount: BigUint, + attributes: FarmTokenAttributes, + ) -> BigUint { + self.require_queried(); + + let mut storage_cache = StorageCache::new(self); + NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + NoMintWrapper::::calculate_rewards( + self, + &user, + &farm_token_amount, + &attributes, + &storage_cache, + ) + } + fn send_to_lock_contract_non_zero( &self, token_id: TokenIdentifier, diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 83649b5f2..edf24d617 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/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" @@ -322,12 +316,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" @@ -344,12 +332,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" @@ -359,9 +341,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", @@ -373,20 +355,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", @@ -396,9 +377,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", @@ -409,21 +390,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]] @@ -484,9 +464,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -605,18 +585,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" @@ -636,25 +604,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/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index a124d3269..eab8f6b92 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,12 +5,15 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 67 #![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,70 +21,73 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_with_locked_rewards ( - enterFarm - claimRewards - exitFarm - calculateRewardsForGivenPosition - mergeFarmTokens - startProduceRewards - endProduceRewards - setPerBlockRewardAmount - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - getUserTotalFarmPosition - setLockingScAddress - setLockEpochs - getLockingScAddress - getLockEpochs - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - set_penalty_percent - set_minimum_farming_epochs - set_burn_gas_limit - getPenaltyPercent - getMinimumFarmingEpoch - getBurnGasLimit - getPairContractManagedAddress - claimBoostedRewards - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + enterFarm => enter_farm_endpoint + claimRewards => claim_rewards_endpoint + exitFarm => exit_farm_endpoint + mergeFarmTokens => merge_farm_tokens_endpoint + claimBoostedRewards => claim_boosted_rewards + startProduceRewards => start_produce_rewards_endpoint + endProduceRewards => end_produce_rewards_endpoint + setPerBlockRewardAmount => set_per_block_rewards_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + setLockingScAddress => set_locking_sc_address + setLockEpochs => set_lock_epochs + getLockingScAddress => locking_sc_address + getLockEpochs => lock_epochs + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_burn_gas_limit => set_burn_gas_limit + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getBurnGasLimit => burn_gas_limit + getPairContractManagedAddress => pair_contract_address + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_with_locked_rewards } diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 38fd37014..d67d5db7d 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -195,6 +195,15 @@ pub trait BaseFunctionsModule: token_mapper.nft_create(new_token_amount, &output_attributes) } + fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { + let reward = Wrapper::::calculate_boosted_rewards(self, caller); + if reward > 0 { + self.reward_reserve().update(|reserve| *reserve -= &reward); + } + + reward + } + fn end_produce_rewards>(&self) { let mut storage = StorageCache::new(self); FC::generate_aggregated_rewards(self, &mut storage); @@ -238,22 +247,16 @@ where pub fn calculate_boosted_rewards( sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, - token_attributes: &::AttributesType, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - let original_owner = &token_attributes.original_owner; - - if original_owner != caller { - sc.update_energy_and_progress(caller); - } + let user_total_farm_position = sc.get_user_total_farm_position(caller); + let user_farm_position = user_total_farm_position.total_farm_position; + let mut boosted_rewards = BigUint::zero(); - let user_total_farm_position_struct = - sc.get_user_total_farm_position_struct(original_owner); - let user_total_farm_position = user_total_farm_position_struct.total_farm_position; - if user_total_farm_position == BigUint::zero() { - return BigUint::zero(); + if user_farm_position > 0 { + boosted_rewards = sc.claim_boosted_yields_rewards(caller, user_farm_position); } - sc.claim_boosted_yields_rewards(caller, user_total_farm_position) + boosted_rewards } } @@ -297,7 +300,7 @@ where token_attributes, storage_cache, ); - let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller, token_attributes); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller); base_farm_reward + boosted_yield_rewards } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs deleted file mode 100644 index 82a2d4ffc..000000000 --- a/dex/farm/src/claim_boost_only.rs +++ /dev/null @@ -1,90 +0,0 @@ -multiversx_sc::imports!(); - -use crate::base_functions::Wrapper; - -#[multiversx_sc::module] -pub trait ClaimBoostOnlyModule: - config::ConfigModule - + rewards::RewardsModule - + farm_token::FarmTokenModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + week_timekeeping::WeekTimekeepingModule - + pausable::PausableModule - + permissions_module::PermissionsModule - + 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 - + token_send::TokenSendModule - + events::EventsModule - + crate::exit_penalty::ExitPenaltyModule - + farm_base_impl::base_farm_init::BaseFarmInitModule - + farm_base_impl::base_farm_validation::BaseFarmValidationModule - + farm_base_impl::enter_farm::BaseEnterFarmModule - + farm_base_impl::claim_rewards::BaseClaimRewardsModule - + farm_base_impl::compound_rewards::BaseCompoundRewardsModule - + farm_base_impl::exit_farm::BaseExitFarmModule - + utils::UtilsModule - + farm_boosted_yields::FarmBoostedYieldsModule - + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule - + crate::base_functions::BaseFunctionsModule -{ - #[payable("*")] - #[endpoint(claimBoostedRewards)] - fn claim_boosted_rewards( - &self, - opt_user: OptionalValue, - ) -> EsdtTokenPayment { - let caller = self.blockchain().get_caller(); - let user = match &opt_user { - OptionalValue::Some(user) => user, - OptionalValue::None => &caller, - }; - let user_total_farm_position_struct = self.get_user_total_farm_position_struct(user); - if user != &caller { - require!( - user_total_farm_position_struct.allow_external_claim_boosted_rewards, - "Cannot claim rewards for this address" - ); - } - - let reward_token_id = self.reward_token_id().get(); - let user_total_farm_position = user_total_farm_position_struct.total_farm_position; - if user_total_farm_position == BigUint::zero() { - return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); - } - - let reward = self.claim_boosted_yields_rewards(user, user_total_farm_position); - if reward > 0 { - self.reward_reserve().update(|reserve| *reserve -= &reward); - } - - let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); - self.send_payment_non_zero(user, &boosted_rewards); - - self.update_energy_and_progress(user); - - boosted_rewards - } - - fn claim_only_boosted_payment( - &self, - caller: &ManagedAddress, - payment: &EsdtTokenPayment, - ) -> EsdtTokenPayment { - let farm_token_mapper = self.farm_token(); - farm_token_mapper.require_same_token(&payment.token_identifier); - - let token_attributes = - self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = Wrapper::::calculate_boosted_rewards(self, caller, &token_attributes); - if reward > 0 { - self.reward_reserve().update(|reserve| *reserve -= &reward); - } - - let reward_token_id = self.reward_token_id().get(); - EsdtTokenPayment::new(reward_token_id, 0, reward) - } -} diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index cf53e0b68..79204f89e 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -6,9 +6,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); pub mod base_functions; -pub mod claim_boost_only; pub mod exit_penalty; -pub mod progress_update; use base_functions::{ClaimRewardsResultType, DoubleMultiPayment, Wrapper}; use common_structs::FarmTokenAttributes; @@ -37,8 +35,6 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + base_functions::BaseFunctionsModule + exit_penalty::ExitPenaltyModule - + progress_update::ProgressUpdateModule - + claim_boost_only::ClaimBoostOnlyModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -93,20 +89,20 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let payments = self.get_non_empty_payments(); - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => self.claim_only_boosted_payment(&orig_caller, &p), - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), + 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 new_farm_token = self.enter_farm::>(orig_caller.clone()); self.send_payment_non_zero(&caller, &new_farm_token); - self.send_payment_non_zero(&caller, &boosted_rewards); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); self.update_energy_and_progress(&orig_caller); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } #[payable("*")] @@ -123,8 +119,6 @@ pub trait Farm: self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); self.send_payment_non_zero(&caller, &claim_rewards_result.rewards); - self.update_energy_and_progress(&orig_caller); - claim_rewards_result.into() } @@ -162,7 +156,10 @@ pub trait Farm: "Exit amount is bigger than the payment amount" ); - let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment); + 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, @@ -180,7 +177,7 @@ pub trait Farm: 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, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&orig_caller); ( exit_farm_result.farming_tokens, @@ -190,41 +187,52 @@ pub trait Farm: .into() } - #[view(calculateRewardsForGivenPosition)] - fn calculate_rewards_for_given_position( - &self, - user: ManagedAddress, - farm_token_amount: BigUint, - attributes: FarmTokenAttributes, - ) -> BigUint { - self.require_queried(); - - let mut storage_cache = StorageCache::new(self); - Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); - - Wrapper::::calculate_rewards( - self, - &user, - &farm_token_amount, - &attributes, - &storage_cache, - ) - } - #[payable("*")] #[endpoint(mergeFarmTokens)] 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); + + 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 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 + (merged_farm_token, boosted_rewards_full_position).into() + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_user: OptionalValue, + ) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); + let user = match &opt_user { + OptionalValue::Some(user) => user, + OptionalValue::None => &caller, + }; + let user_total_farm_position = self.get_user_total_farm_position(user); + if user != &caller { + require!( + user_total_farm_position.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } + + let boosted_rewards = self.claim_only_boosted_payment(&user); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + + self.send_payment_non_zero(user, &boosted_rewards_payment); + + boosted_rewards_payment } #[endpoint(startProduceRewards)] @@ -244,4 +252,25 @@ pub trait Farm: self.require_caller_has_admin_permissions(); self.set_per_block_rewards::>(per_block_amount); } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + user: ManagedAddress, + farm_token_amount: BigUint, + attributes: FarmTokenAttributes, + ) -> BigUint { + self.require_queried(); + + let mut storage_cache = StorageCache::new(self); + Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + Wrapper::::calculate_rewards( + self, + &user, + &farm_token_amount, + &attributes, + &storage_cache, + ) + } } 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 182de5c8c..8dfac6b79 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -459,11 +459,15 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { ); // second user claim with first user's pos - // user will only receive rewards for base farm, no boosted rewards + // user will receive both base and boosted rewards, as the claims uses his already saved total token amount let second_base_farm_amt = first_farm_token_amount * 7_500 / total_farm_tokens; + let second_boosted_rewards = 1_533; let second_receveived_reward_amt = farm_setup.claim_rewards(&second_user, 3, first_farm_token_amount); - assert_eq!(second_receveived_reward_amt, second_base_farm_amt); + assert_eq!( + second_receveived_reward_amt, + second_base_farm_amt + second_boosted_rewards + ); farm_setup .b_mock 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 9c8926160..f619c64fa 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -3,7 +3,6 @@ use common_structs::FarmTokenAttributes; use config::ConfigModule; -use farm::claim_boost_only::ClaimBoostOnlyModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::{ storage::mappers::StorageTokenWrapper, @@ -336,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, _) = sc + .merge_farm_tokens_endpoint(OptionalValue::None) + .into_tuple(); assert_eq!( out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) @@ -567,8 +568,8 @@ where self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { sc.user_total_farm_position(&managed_address!(user)).update( - |user_total_farm_position_struct| { - user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; + |user_total_farm_position| { + user_total_farm_position.allow_external_claim_boosted_rewards = true; }, ); }) diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 97ea7e292..c987ae22b 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/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" @@ -292,12 +286,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" @@ -314,12 +302,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" @@ -329,9 +311,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", @@ -343,20 +325,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", @@ -366,9 +347,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", @@ -379,21 +360,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]] @@ -454,9 +434,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -575,18 +555,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" @@ -606,25 +574,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/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 4f3c13441..a522fc32f 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,12 +5,15 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 61 +// Endpoints: 62 // Async Callback: 1 -// Total number of exported functions: 63 +// Total number of exported functions: 64 #![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,67 +21,70 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm ( - enterFarm - claimRewards - compoundRewards - exitFarm - calculateRewardsForGivenPosition - mergeFarmTokens - startProduceRewards - endProduceRewards - setPerBlockRewardAmount - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - getUserTotalFarmPosition - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - set_penalty_percent - set_minimum_farming_epochs - set_burn_gas_limit - getPenaltyPercent - getMinimumFarmingEpoch - getBurnGasLimit - getPairContractManagedAddress - claimBoostedRewards - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + enterFarm => enter_farm_endpoint + claimRewards => claim_rewards_endpoint + compoundRewards => compound_rewards_endpoint + exitFarm => exit_farm_endpoint + mergeFarmTokens => merge_farm_tokens_endpoint + claimBoostedRewards => claim_boosted_rewards + startProduceRewards => start_produce_rewards_endpoint + endProduceRewards => end_produce_rewards_endpoint + setPerBlockRewardAmount => set_per_block_rewards_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_burn_gas_limit => set_burn_gas_limit + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getBurnGasLimit => burn_gas_limit + getPairContractManagedAddress => pair_contract_address + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm } diff --git a/energy-integration/farm-boosted-yields/src/lib.rs b/energy-integration/farm-boosted-yields/src/lib.rs index fc441b515..931c58f9d 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -129,17 +129,14 @@ pub trait FarmBoostedYieldsModule: self.farm_supply_for_week(current_week).set(farm_supply); } - fn clear_user_energy_if_needed( - &self, - original_caller: &ManagedAddress, - user_remaining_farm_tokens: &BigUint, - ) { + fn clear_user_energy_if_needed(&self, original_caller: &ManagedAddress) { let opt_config = self.try_get_boosted_yields_config(); + let user_total_farm_position = self.get_user_total_farm_position(original_caller); if let Some(config) = opt_config { let boosted_yields_factors = config.get_latest_factors(); self.clear_user_energy( original_caller, - user_remaining_farm_tokens, + &user_total_farm_position.total_farm_position, &boosted_yields_factors.min_farm_amount, ); } diff --git a/energy-integration/fees-collector/elrond.json b/energy-integration/fees-collector/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/energy-integration/fees-collector/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/energy-integration/fees-collector/src/config.rs b/energy-integration/fees-collector/src/config.rs index 1e1a850a0..a21dc6d6b 100644 --- a/energy-integration/fees-collector/src/config.rs +++ b/energy-integration/fees-collector/src/config.rs @@ -60,6 +60,13 @@ pub trait ConfigModule { self.all_tokens().set(&all_tokens_vec); } + #[endpoint(setAllowExternalClaimRewards)] + fn set_allow_external_claim_rewards(&self, allow_external_claim_rewards: bool) { + let caller = self.blockchain().get_caller(); + self.allow_external_claim_rewards(&caller) + .set(allow_external_claim_rewards); + } + #[view(getLockedTokenId)] #[storage_mapper("lockedTokenId")] fn locked_token_id(&self) -> SingleValueMapper; diff --git a/energy-integration/fees-collector/wasm/Cargo.lock b/energy-integration/fees-collector/wasm/Cargo.lock index 601610441..86c6f1c94 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/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" @@ -161,12 +155,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" @@ -183,12 +171,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" @@ -198,9 +180,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", @@ -212,20 +194,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", @@ -235,9 +216,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", @@ -248,21 +229,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]] @@ -291,9 +271,9 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -380,18 +360,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" @@ -411,25 +379,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/energy-integration/fees-collector/wasm/src/lib.rs b/energy-integration/fees-collector/wasm/src/lib.rs index 141b80dc6..a3065aeaf 100644 --- a/energy-integration/fees-collector/wasm/src/lib.rs +++ b/energy-integration/fees-collector/wasm/src/lib.rs @@ -5,12 +5,15 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 36 +// Endpoints: 37 // Async Callback (empty): 1 -// Total number of exported functions: 38 +// Total number of exported functions: 39 #![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,43 +21,45 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { fees_collector ( - claimRewards - addKnownContracts - removeKnownContracts - addKnownTokens - removeKnownTokens - getLockedTokenId - getAllTokens - getAllKnownContracts - getAllowExternalClaimRewards - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - depositSwapFees - getAccumulatedFees - setLockedTokensPerBlock - getLastLockedTokensAddWeek - getLockedTokensPerBlock - setLockingScAddress - setLockEpochs - getLockingScAddress - getLockEpochs - setEnergyFactoryAddress - getEnergyFactoryAddress - getCurrentWeek - getFirstWeekStartEpoch - pause - unpause - isPaused - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted + init => init + claimRewards => claim_rewards + addKnownContracts => add_known_contracts + removeKnownContracts => remove_known_contracts + addKnownTokens => add_known_tokens + removeKnownTokens => remove_known_tokens + setAllowExternalClaimRewards => set_allow_external_claim_rewards + getLockedTokenId => locked_token_id + getAllTokens => get_all_tokens + getAllKnownContracts => known_contracts + getAllowExternalClaimRewards => allow_external_claim_rewards + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + depositSwapFees => deposit_swap_fees + getAccumulatedFees => accumulated_fees + setLockedTokensPerBlock => set_locked_tokens_per_block + getLastLockedTokensAddWeek => last_locked_token_add_week + getLockedTokensPerBlock => locked_tokens_per_block + setLockingScAddress => set_locking_sc_address + setLockEpochs => set_lock_epochs + getLockingScAddress => locking_sc_address + getLockEpochs => lock_epochs + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} 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 index 2a81f2cf4..84be38ae0 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs @@ -1,4 +1,4 @@ -farm-staking/farm-staking-proxy/tests/composed_pos_test.rsuse common_structs::PaymentsVec; +use common_structs::PaymentsVec; use crate::{dual_yield_token::DualYieldTokenAttributes, result_types::MergeResult}; diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index 6b8cfa51d..45a3fea4f 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/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" @@ -345,12 +339,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" @@ -367,12 +355,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" @@ -382,9 +364,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", @@ -396,20 +378,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", @@ -419,9 +400,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", @@ -432,21 +413,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]] @@ -507,9 +487,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" 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/farm-staking/farm-staking-proxy/wasm/src/lib.rs b/farm-staking/farm-staking-proxy/wasm/src/lib.rs index 57bdc0840..4223b260d 100644 --- a/farm-staking/farm-staking-proxy/wasm/src/lib.rs +++ b/farm-staking/farm-staking-proxy/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 17 #![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,21 +21,23 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_staking_proxy ( - registerDualYieldToken - getDualYieldTokenId - getLpFarmAddress - getStakingFarmAddress - getPairAddress - getStakingTokenId - getFarmTokenId - getLpTokenId - getLpFarmTokenId - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - stakeFarmTokens - claimDualYield - unstakeFarmTokens - callBack + init => init + registerDualYieldToken => register_dual_yield_token + getDualYieldTokenId => dual_yield_token + getLpFarmAddress => lp_farm_address + getStakingFarmAddress => staking_farm_address + getPairAddress => pair_address + getStakingTokenId => staking_token_id + getFarmTokenId => staking_farm_token_id + getLpTokenId => lp_token_id + getLpFarmTokenId => lp_farm_token_id + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + stakeFarmTokens => stake_farm_tokens + claimDualYield => claim_dual_yield_endpoint + unstakeFarmTokens => unstake_farm_tokens ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_staking_proxy } diff --git a/farm-staking/farm-staking/elrond.json b/farm-staking/farm-staking/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/farm-staking/farm-staking/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index adf6136a5..54e221a95 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -47,18 +47,16 @@ where pub fn calculate_boosted_rewards( sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, - token_attributes: &::AttributesType, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - if &token_attributes.original_owner != caller { - sc.update_energy_and_progress(caller); - } - let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(caller); - let user_total_farm_position = user_total_farm_position_struct.total_farm_position; - if user_total_farm_position == BigUint::zero() { - return BigUint::zero(); + let user_total_farm_position = sc.get_user_total_farm_position(caller); + let user_farm_position = user_total_farm_position.total_farm_position; + let mut boosted_rewards = BigUint::zero(); + + if user_farm_position > 0 { + boosted_rewards = sc.claim_boosted_yields_rewards(caller, user_farm_position); } - sc.claim_boosted_yields_rewards(caller, user_total_farm_position) + boosted_rewards } } @@ -137,7 +135,7 @@ where ) -> BigUint<::Api> { let base_farm_reward = Self::calculate_base_farm_rewards(farm_token_amount, token_attributes, storage_cache); - let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller, token_attributes); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller); base_farm_reward + boosted_yield_rewards } @@ -207,8 +205,10 @@ where farm_position_increase += &farm_position.amount; } } - let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(user); - if user_total_farm_position_struct.total_farm_position == BigUint::zero() { + let user_total_farm_position = sc.get_user_total_farm_position(user); + if user_total_farm_position.total_farm_position == BigUint::zero() + && total_farm_position > 0 + { Self::increase_user_farm_position(sc, user, &total_farm_position); } else if farm_position_increase > 0 { Self::increase_user_farm_position(sc, user, &farm_position_increase); @@ -220,10 +220,10 @@ where user: &ManagedAddress<::Api>, new_farm_position_amount: &BigUint<::Api>, ) { + let mut user_total_farm_position = sc.get_user_total_farm_position(user); + user_total_farm_position.total_farm_position += new_farm_position_amount; sc.user_total_farm_position(user) - .update(|user_farm_position_struct| { - user_farm_position_struct.total_farm_position += new_farm_position_amount - }); + .set(user_total_farm_position); } fn decrease_user_farm_position( @@ -235,8 +235,8 @@ where farm_token_mapper.get_token_attributes(farm_position.token_nonce); sc.user_total_farm_position(&token_attributes.original_owner) - .update(|user_farm_position_struct| { - user_farm_position_struct.total_farm_position -= farm_position.amount.clone() + .update(|user_total_farm_position| { + user_total_farm_position.total_farm_position -= farm_position.amount.clone() }); } } 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 03253057b..83e609e92 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 @@ -30,53 +30,32 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: let caller = self.blockchain().get_caller(); let user = match &opt_user { OptionalValue::Some(user) => user, - #[allow(clippy::redundant_clone)] OptionalValue::None => &caller, }; - let user_total_farm_position_struct = self.get_user_total_farm_position_struct(user); + let user_total_farm_position = self.get_user_total_farm_position(user); if user != &caller { require!( - user_total_farm_position_struct.allow_external_claim_boosted_rewards, + user_total_farm_position.allow_external_claim_boosted_rewards, "Cannot claim rewards for this address" ); } - let reward_token_id = self.reward_token_id().get(); - let user_total_farm_position = user_total_farm_position_struct.total_farm_position; - if user_total_farm_position == BigUint::zero() { - return EsdtTokenPayment::new(reward_token_id, 0, BigUint::zero()); - } - - let reward = self.claim_boosted_yields_rewards(user, user_total_farm_position); - if reward > 0 { - self.reward_reserve().update(|reserve| *reserve -= &reward); - } - let boosted_rewards = EsdtTokenPayment::new(reward_token_id, 0, reward); - self.send_payment_non_zero(user, &boosted_rewards); + let boosted_rewards = self.claim_only_boosted_payment(&user); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - self.update_energy_and_progress(user); + self.send_payment_non_zero(user, &boosted_rewards_payment); - boosted_rewards + boosted_rewards_payment } // Cannot import the one from farm, as the Wrapper struct has different dependencies - fn claim_only_boosted_payment( - &self, - caller: &ManagedAddress, - payment: &EsdtTokenPayment, - ) -> EsdtTokenPayment { - let farm_token_mapper = self.farm_token(); - farm_token_mapper.require_same_token(&payment.token_identifier); - - let token_attributes = - self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = - FarmStakingWrapper::::calculate_boosted_rewards(self, caller, &token_attributes); + fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { + let reward = FarmStakingWrapper::::calculate_boosted_rewards(self, caller); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } - let reward_token_id = self.reward_token_id().get(); - EsdtTokenPayment::new(reward_token_id, 0, reward) + reward } } diff --git a/farm-staking/farm-staking/src/custom_rewards.rs b/farm-staking/farm-staking/src/custom_rewards.rs index 4677cae1d..de7fd29a0 100644 --- a/farm-staking/farm-staking/src/custom_rewards.rs +++ b/farm-staking/farm-staking/src/custom_rewards.rs @@ -9,7 +9,7 @@ use crate::base_impl_wrapper::FarmStakingWrapper; pub const MAX_PERCENT: u64 = 10_000; pub const BLOCKS_IN_YEAR: u64 = 31_536_000 / 6; // seconds_in_year / 6_seconds_per_block -const MAX_MIN_UNBOND_EPOCHS: u64 = 30; +pub const MAX_MIN_UNBOND_EPOCHS: u64 = 30; #[multiversx_sc::module] pub trait CustomRewardsModule: diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index d1874d0b4..e22ae0dfe 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -2,14 +2,17 @@ #![allow(clippy::from_over_into)] #![feature(trait_alias)] +multiversx_sc::imports!(); +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; -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); +use crate::custom_rewards::MAX_MIN_UNBOND_EPOCHS; pub mod base_impl_wrapper; pub mod claim_only_boosted_staking_rewards; @@ -40,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 @@ -79,16 +81,27 @@ pub trait FarmStaking: ); require!(max_apr > 0u64, "Invalid max APR percentage"); - self.max_annual_percentage_rewards().set(&max_apr); + self.max_annual_percentage_rewards().set_if_empty(&max_apr); - self.try_set_min_unbond_epochs(min_unbond_epochs); + require!( + min_unbond_epochs <= MAX_MIN_UNBOND_EPOCHS, + "Invalid min unbond epochs" + ); + self.min_unbond_epochs().set_if_empty(min_unbond_epochs); } #[payable("*")] #[endpoint(mergeFarmTokens)] - fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment { + fn merge_farm_tokens_endpoint( + &self, + opt_orig_caller: OptionalValue, + ) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); - self.check_claim_progress_for_merge(&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); let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); @@ -98,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(&orig_caller, &boosted_rewards_full_position); - merged_farm_token + (merged_farm_token, boosted_rewards_full_position).into() } #[view(calculateRewardsForGivenPosition)] diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index 8524a2b4f..2da477f52 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -71,22 +71,26 @@ pub trait StakeFarmModule: original_caller: ManagedAddress, payments: PaymentsVec, ) -> EnterFarmResultType { - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => self.claim_only_boosted_payment(&original_caller, &p), - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), + let caller = self.blockchain().get_caller(); + + let boosted_rewards = self.claim_only_boosted_payment(&original_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 enter_result = - self.enter_farm_base::>(original_caller, payments); + self.enter_farm_base::>(original_caller.clone(), payments); - let caller = self.blockchain().get_caller(); let new_farm_token = enter_result.new_farm_token.payment.clone(); self.send_payment_non_zero(&caller, &new_farm_token); - self.send_payment_non_zero(&caller, &boosted_rewards); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); self.set_farm_supply_for_current_week(&enter_result.storage_cache.farm_token_supply); + self.update_energy_and_progress(&original_caller); + self.emit_enter_farm_event( &caller, enter_result.context.farming_token_payment, @@ -95,6 +99,6 @@ pub trait StakeFarmModule: enter_result.storage_cache, ); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } } diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 4c9675153..39acc348d 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -86,8 +86,10 @@ pub trait UnstakeFarmModule: "Exit amount is bigger than the payment amount" ); + let boosted_rewards = self.claim_only_boosted_payment(&original_caller); let boosted_rewards_full_position = - self.claim_only_boosted_payment(&original_caller, &payment); + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + let remaining_farm_payment = EsdtTokenPayment::new( payment.token_identifier.clone(), payment.token_nonce, @@ -113,7 +115,7 @@ pub trait UnstakeFarmModule: 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, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&original_caller); self.set_farm_supply_for_current_week(&exit_result.storage_cache.farm_token_supply); self.emit_exit_farm_event( 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 f46b63dbd..01e768862 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -421,8 +421,8 @@ where self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { sc.user_total_farm_position(&managed_address!(user)).update( - |user_total_farm_position_struct| { - user_total_farm_position_struct.allow_external_claim_boosted_rewards = true; + |user_total_farm_position| { + user_total_farm_position.allow_external_claim_boosted_rewards = true; }, ); }) diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 4584bdf1a..6b4032061 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/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" @@ -323,12 +317,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" @@ -345,12 +333,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" @@ -360,9 +342,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", @@ -374,20 +356,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", @@ -397,9 +378,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", @@ -410,21 +391,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]] @@ -485,9 +465,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -606,18 +586,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" @@ -637,25 +605,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/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index d3322ea4e..1ff8628b8 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,12 +5,15 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 66 +// Endpoints: 67 // Async Callback: 1 -// Total number of exported functions: 68 +// Total number of exported functions: 69 #![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,72 +21,75 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_staking ( - mergeFarmTokens - calculateRewardsForGivenPosition - topUpRewards - endProduceRewards - setPerBlockRewardAmount - setMaxApr - setMinUnbondEpochs - startProduceRewards - getAccumulatedRewards - getRewardCapacity - getAnnualPercentageRewards - getMinUnbondEpochs - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - getUserTotalFarmPosition - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - setBurnRoleForAddress - stakeFarmThroughProxy - stakeFarm - claimRewards - claimRewardsWithNewValue - compoundRewards - unstakeFarm - unstakeFarmThroughProxy - unbondFarm - claimBoostedRewards - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + mergeFarmTokens => merge_farm_tokens_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + topUpRewards => top_up_rewards + endProduceRewards => end_produce_rewards + setPerBlockRewardAmount => set_per_block_rewards + setMaxApr => set_max_apr + setMinUnbondEpochs => set_min_unbond_epochs_endpoint + startProduceRewards => start_produce_rewards_endpoint + getAccumulatedRewards => accumulated_rewards + getRewardCapacity => reward_capacity + getAnnualPercentageRewards => max_annual_percentage_rewards + getMinUnbondEpochs => min_unbond_epochs + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + setBurnRoleForAddress => set_burn_role_for_address + stakeFarmThroughProxy => stake_farm_through_proxy + stakeFarm => stake_farm_endpoint + claimRewards => claim_rewards + claimRewardsWithNewValue => claim_rewards_with_new_value + compoundRewards => compound_rewards + unstakeFarm => unstake_farm + unstakeFarmThroughProxy => unstake_farm_through_proxy + unbondFarm => unbond_farm + claimBoostedRewards => claim_boosted_rewards + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_staking } From c044821d4f0c6cd85b1571e5210beaaaa82aea3e Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Mon, 18 Sep 2023 13:25:46 +0300 Subject: [PATCH 31/58] metastaking refactor --- common/modules/farm/config/src/config.rs | 30 +++---- .../farm_base_impl/src/base_traits_impl.rs | 45 +++-------- dex/farm-with-locked-rewards/wasm/src/lib.rs | 5 +- dex/farm/src/base_functions.rs | 7 +- dex/farm/src/lib.rs | 5 ++ dex/farm/wasm/src/lib.rs | 5 +- .../src/dual_yield_token.rs | 81 ++----------------- .../src/external_contracts_interactions.rs | 24 ------ .../src/proxy_actions/claim.rs | 12 ++- .../src/proxy_actions/stake.rs | 14 +--- .../src/proxy_actions/unstake.rs | 59 ++++---------- .../farm-staking-proxy/src/result_types.rs | 5 -- .../tests/staking_farm_with_lp.rs | 41 +++------- .../mod.rs | 5 +- .../farm-staking/src/base_impl_wrapper.rs | 24 +++--- farm-staking/farm-staking/wasm/src/lib.rs | 5 +- 16 files changed, 96 insertions(+), 271 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index cb1385ba3..2f5f4935c 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -53,24 +53,22 @@ 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 + } + #[endpoint(allowExternalClaimBoostedRewards)] fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { let caller = self.blockchain().get_caller(); let user_total_farm_position_mapper = self.user_total_farm_position(&caller); - if user_total_farm_position_mapper.is_empty() { - require!( - allow_external_claim, - "Can only set to true if there is no farm position" - ); - let mut new_user_farm_position: UserTotalFarmPosition = - UserTotalFarmPosition::default(); - new_user_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; - } else { - user_total_farm_position_mapper.update(|user_total_farm_position| { - user_total_farm_position.allow_external_claim_boosted_rewards = - allow_external_claim; - }); - } + require!( + !user_total_farm_position_mapper.is_empty(), + "User must have a farm position" + ); + user_total_farm_position_mapper.update(|user_total_farm_position| { + user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + }); } #[view(getFarmingTokenId)] @@ -102,4 +100,8 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio &self, user: &ManagedAddress, ) -> SingleValueMapper>; + + #[view(getFarmPositionMigrationBlockNonce)] + #[storage_mapper("farm_position_migration_block_nonce")] + fn farm_position_migration_block_nonce(&self) -> SingleValueMapper; } diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 728d7097f..c03775abc 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -195,29 +195,20 @@ pub trait FarmContract { farm_positions: &PaymentsVec<::Api>, ) { let farm_token_mapper = sc.farm_token(); - let mut total_farm_position = BigUint::zero(); - let mut farm_position_increase = BigUint::zero(); for farm_position in farm_positions { + let is_old_farm_position = sc.is_old_farm_position(farm_position.token_nonce); farm_token_mapper.require_same_token(&farm_position.token_identifier); - total_farm_position += &farm_position.amount; let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if &token_attributes.original_owner != user { + if is_old_farm_position { + Self::increase_user_farm_position(sc, user, &farm_position.amount); + } else if &token_attributes.original_owner != user { Self::decrease_user_farm_position(sc, &farm_position); - farm_position_increase += &farm_position.amount; + Self::increase_user_farm_position(sc, user, &farm_position.amount); } } - - let user_total_farm_position = sc.get_user_total_farm_position(user); - if user_total_farm_position.total_farm_position == BigUint::zero() - && total_farm_position > 0 - { - Self::increase_user_farm_position(sc, user, &total_farm_position); - } else if farm_position_increase > 0 { - Self::increase_user_farm_position(sc, user, &farm_position_increase); - } } #[inline] @@ -240,24 +231,14 @@ pub trait FarmContract { let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - let mut user_total_farm_position = - sc.get_user_total_farm_position(&token_attributes.original_owner); - - if user_total_farm_position.total_farm_position > farm_position.amount { - user_total_farm_position.total_farm_position -= &farm_position.amount; - } else { - user_total_farm_position.total_farm_position = BigUint::zero(); - } - - if user_total_farm_position.total_farm_position == 0 - && user_total_farm_position.allow_external_claim_boosted_rewards == false - { - sc.user_total_farm_position(&token_attributes.original_owner) - .clear(); - } else { - sc.user_total_farm_position(&token_attributes.original_owner) - .set(user_total_farm_position); - } + sc.user_total_farm_position(&token_attributes.original_owner) + .update(|user_total_farm_position| { + if user_total_farm_position.total_farm_position > farm_position.amount { + user_total_farm_position.total_farm_position -= &farm_position.amount; + } else { + user_total_farm_position.total_farm_position = BigUint::zero(); + } + }); } } diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index eab8f6b92..ae9c8fced 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 65 +// Endpoints: 66 // Async Callback: 1 -// Total number of exported functions: 67 +// Total number of exported functions: 68 #![no_std] @@ -40,6 +40,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce setLockingScAddress => set_locking_sc_address setLockEpochs => set_lock_epochs getLockingScAddress => locking_sc_address diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index d67d5db7d..fb5c5dfce 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -250,13 +250,8 @@ where ) -> BigUint<<::FarmSc as ContractBase>::Api> { let user_total_farm_position = sc.get_user_total_farm_position(caller); let user_farm_position = user_total_farm_position.total_farm_position; - let mut boosted_rewards = BigUint::zero(); - if user_farm_position > 0 { - boosted_rewards = sc.claim_boosted_yields_rewards(caller, user_farm_position); - } - - boosted_rewards + sc.claim_boosted_yields_rewards(caller, user_farm_position) } } diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 79204f89e..f7cfbd5f6 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -78,6 +78,11 @@ pub trait Farm: let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let block_nonce = self.blockchain().get_block_nonce(); + self.farm_position_migration_block_nonce() + .set_if_empty(block_nonce); } #[payable("*")] diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index a522fc32f..4acae57d7 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 62 +// Endpoints: 63 // Async Callback: 1 -// Total number of exported functions: 64 +// Total number of exported functions: 65 #![no_std] @@ -41,6 +41,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token getFarmTokenSupply => farm_token_supply diff --git a/farm-staking/farm-staking-proxy/src/dual_yield_token.rs b/farm-staking/farm-staking-proxy/src/dual_yield_token.rs index f1e2eedd0..56a311d85 100644 --- a/farm-staking/farm-staking-proxy/src/dual_yield_token.rs +++ b/farm-staking/farm-staking-proxy/src/dual_yield_token.rs @@ -1,84 +1,19 @@ use fixed_supply_token::FixedSupplyToken; -use multiversx_sc::codec::{NestedDecodeInput, TopDecodeInput}; multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -#[derive(TypeAbi, TopEncode, PartialEq, Debug, Clone)] +#[derive(TypeAbi, TopEncode, TopDecode, Clone, PartialEq, Debug)] pub struct DualYieldTokenAttributes { pub lp_farm_token_nonce: u64, pub lp_farm_token_amount: BigUint, - pub virtual_pos_token_nonce: u64, - pub virtual_pos_token_amount: BigUint, - pub real_pos_token_amount: BigUint, -} - -impl DualYieldTokenAttributes { - pub fn new( - lp_farm_token_nonce: u64, - lp_farm_token_amount: BigUint, - virtual_pos_token_nonce: u64, - virtual_pos_token_amount: BigUint, - ) -> Self { - DualYieldTokenAttributes { - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - real_pos_token_amount: BigUint::zero(), - } - } - - pub fn get_total_staking_token_amount(&self) -> BigUint { - &self.virtual_pos_token_amount + &self.real_pos_token_amount - } -} - -impl TopDecode for DualYieldTokenAttributes { - fn top_decode(input: I) -> Result - where - I: TopDecodeInput, - { - let mut buffer = input.into_nested_buffer(); - Self::dep_decode(&mut buffer) - } -} - -impl NestedDecode for DualYieldTokenAttributes { - fn dep_decode(input: &mut I) -> Result { - let lp_farm_token_nonce = u64::dep_decode(input)?; - let lp_farm_token_amount = BigUint::dep_decode(input)?; - let virtual_pos_token_nonce = u64::dep_decode(input)?; - let virtual_pos_token_amount = BigUint::dep_decode(input)?; - - if input.is_depleted() { - return Result::Ok(DualYieldTokenAttributes::new( - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - )); - } - - let real_pos_token_amount = BigUint::dep_decode(input)?; - - if !input.is_depleted() { - return Result::Err(DecodeError::INPUT_TOO_LONG); - } - - Result::Ok(DualYieldTokenAttributes { - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - real_pos_token_amount, - }) - } + pub staking_farm_token_nonce: u64, + pub staking_farm_token_amount: BigUint, } impl FixedSupplyToken for DualYieldTokenAttributes { fn get_total_supply(&self) -> BigUint { - self.virtual_pos_token_amount.clone() + self.staking_farm_token_amount.clone() } fn into_part(self, payment_amount: &BigUint) -> Self { @@ -88,15 +23,13 @@ impl FixedSupplyToken for DualYieldTokenAttributes { let new_lp_farm_token_amount = self.rule_of_three_non_zero_result(payment_amount, &self.lp_farm_token_amount); - let new_virtual_pos_amount = payment_amount.clone(); - let new_real_pos_amount = self.rule_of_three(payment_amount, &self.real_pos_token_amount); + let new_staking_farm_token_amount = payment_amount.clone(); DualYieldTokenAttributes { lp_farm_token_nonce: self.lp_farm_token_nonce, lp_farm_token_amount: new_lp_farm_token_amount, - virtual_pos_token_nonce: self.virtual_pos_token_nonce, - virtual_pos_token_amount: new_virtual_pos_amount, - real_pos_token_amount: new_real_pos_amount, + staking_farm_token_nonce: self.staking_farm_token_nonce, + staking_farm_token_amount: new_staking_farm_token_amount, } } } 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 933a93cfd..d8b3a5258 100644 --- a/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs +++ b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs @@ -164,30 +164,6 @@ pub trait ExternalContractsInteractionsModule: } } - fn staking_farm_unstake_user_position( - &self, - orig_caller: ManagedAddress, - farm_token_nonce: u64, - farm_token_amount: BigUint, - exit_amount: BigUint, - ) -> StakingFarmExitResult { - let staking_farm_token_id = self.staking_farm_token_id().get(); - let staking_farm_address = self.staking_farm_address().get(); - let unstake_result: ExitFarmWithPartialPosResultType = self - .staking_farm_proxy_obj(staking_farm_address) - .unstake_farm(exit_amount, orig_caller) - .with_esdt_transfer((staking_farm_token_id, farm_token_nonce, farm_token_amount)) - .execute_on_dest_context(); - let (unbond_staking_farm_token, staking_rewards, remaining_farm_tokens) = - unstake_result.into_tuple(); - - StakingFarmExitResult { - unbond_staking_farm_token, - staking_rewards, - remaining_farm_tokens, - } - } - // pair fn pair_remove_liquidity( diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs index 3f90583e2..fe84fa65d 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs @@ -34,7 +34,7 @@ pub trait ProxyClaimModule: let internal_claim_result = self.claim_dual_yield( &caller, opt_orig_caller, - attributes.get_total_staking_token_amount(), + attributes.staking_farm_token_amount.clone(), attributes, ); @@ -66,8 +66,7 @@ pub trait ProxyClaimModule: attributes.lp_farm_token_nonce, &attributes.lp_farm_token_amount, ); - let lp_tokens_safe_price = self.get_lp_tokens_safe_price(lp_tokens_in_position); - let new_staking_farm_value = &lp_tokens_safe_price + &attributes.real_pos_token_amount; + let new_staking_farm_value = self.get_lp_tokens_safe_price(lp_tokens_in_position); let staking_farm_token_id = self.staking_farm_token_id().get(); let lp_farm_token_id = self.lp_farm_token_id().get(); @@ -80,7 +79,7 @@ pub trait ProxyClaimModule: let staking_farm_claim_rewards_result = self.staking_farm_claim_rewards( orig_caller, staking_farm_token_id, - attributes.virtual_pos_token_nonce, + attributes.staking_farm_token_nonce, staking_claim_amount, new_staking_farm_value, ); @@ -90,9 +89,8 @@ pub trait ProxyClaimModule: let new_attributes = DualYieldTokenAttributes { lp_farm_token_nonce: new_lp_farm_tokens.token_nonce, lp_farm_token_amount: new_lp_farm_tokens.amount, - virtual_pos_token_nonce: new_staking_farm_tokens.token_nonce, - virtual_pos_token_amount: lp_tokens_safe_price, - real_pos_token_amount: attributes.real_pos_token_amount, + staking_farm_token_nonce: new_staking_farm_tokens.token_nonce, + staking_farm_token_amount: new_staking_farm_tokens.amount, }; InternalClaimResult { diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs index 1cfe2047c..d39dd7f2c 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs @@ -36,15 +36,14 @@ pub trait ProxyStakeModule: let staking_farm_token_id = self.staking_farm_token_id().get(); let mut additional_staking_farm_tokens = ManagedVec::new(); let mut additional_lp_farm_tokens = ManagedVec::new(); - let mut total_user_real_staking_tokens = BigUint::zero(); for p in &additional_payments { let attributes: DualYieldTokenAttributes = self.get_attributes_as_part_of_fixed_supply(&p, &dual_yield_token_mapper); additional_staking_farm_tokens.push(EsdtTokenPayment::new( staking_farm_token_id.clone(), - attributes.virtual_pos_token_nonce, - attributes.get_total_staking_token_amount(), + attributes.staking_farm_token_nonce, + attributes.staking_farm_token_amount, )); additional_lp_farm_tokens.push(EsdtTokenPayment::new( @@ -53,8 +52,6 @@ pub trait ProxyStakeModule: attributes.lp_farm_token_amount, )); - total_user_real_staking_tokens += attributes.real_pos_token_amount; - dual_yield_token_mapper.nft_burn(p.token_nonce, &p.amount); } @@ -76,14 +73,11 @@ pub trait ProxyStakeModule: additional_lp_farm_tokens, ); - let new_staking_farm_token_amount = - &received_staking_farm_token.amount - &total_user_real_staking_tokens; let new_attributes = DualYieldTokenAttributes { lp_farm_token_nonce: merged_lp_farm_tokens.token_nonce, lp_farm_token_amount: merged_lp_farm_tokens.amount, - virtual_pos_token_nonce: received_staking_farm_token.token_nonce, - virtual_pos_token_amount: new_staking_farm_token_amount, - real_pos_token_amount: total_user_real_staking_tokens, + staking_farm_token_nonce: received_staking_farm_token.token_nonce, + staking_farm_token_amount: received_staking_farm_token.amount, }; let new_dual_yield_tokens = self.create_dual_yield_tokens(&dual_yield_token_mapper, &new_attributes); 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 59e65f4e0..c78527aa6 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs @@ -1,5 +1,4 @@ use fixed_supply_token::FixedSupplyToken; -use mergeable::Mergeable; use crate::{dual_yield_token::DualYieldTokenAttributes, result_types::UnstakeResult}; @@ -32,24 +31,21 @@ pub trait ProxyUnstakeModule: let full_attributes: DualYieldTokenAttributes = dual_yield_token_mapper.get_token_attributes(payment.token_nonce); - let total_for_nonce = full_attributes.get_total_supply(); - require!( - payment.amount == total_for_nonce, - "Must exit with full position as payment" - ); + require!( exit_amount > 0 && exit_amount <= payment.amount, "Invalid exit amount" ); - let full_staking_token_amount = full_attributes.get_total_staking_token_amount(); + let full_attributes_adjusted: DualYieldTokenAttributes = + full_attributes.clone().into_part(&payment.amount); let exit_attributes: DualYieldTokenAttributes = full_attributes.clone().into_part(&exit_amount); let lp_farm_exit_result = self.lp_farm_exit( orig_caller.clone(), - full_attributes.lp_farm_token_nonce, - full_attributes.lp_farm_token_amount, + full_attributes_adjusted.lp_farm_token_nonce, + full_attributes_adjusted.lp_farm_token_amount, exit_attributes.lp_farm_token_amount, ); let remove_liq_result = self.pair_remove_liquidity( @@ -58,40 +54,23 @@ pub trait ProxyUnstakeModule: pair_second_token_min_amount, ); - let remaining_total_staking_farm_tokens = - &full_staking_token_amount - &exit_attributes.virtual_pos_token_amount; let staking_farm_exit_result = self.staking_farm_unstake( orig_caller.clone(), remove_liq_result.staking_token_payment, - full_attributes.virtual_pos_token_nonce, - full_staking_token_amount, - exit_attributes.virtual_pos_token_amount.clone(), + full_attributes_adjusted.staking_farm_token_nonce, + full_attributes_adjusted.staking_farm_token_amount.clone(), + exit_attributes.staking_farm_token_amount.clone(), ); - let opt_unstake_user_pos_result = if exit_attributes.real_pos_token_amount > 0 { - let res = self.staking_farm_unstake_user_position( - orig_caller, - full_attributes.virtual_pos_token_nonce, - remaining_total_staking_farm_tokens, - exit_attributes.real_pos_token_amount.clone(), - ); - Some(res) - } else { - None - }; - - let opt_new_dual_yield_tokens = if exit_amount != total_for_nonce { + 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_virtual_farm_tokens = - full_attributes.virtual_pos_token_amount - exit_attributes.virtual_pos_token_amount; - let remaining_real_farm_tokens = - full_attributes.real_pos_token_amount - exit_attributes.real_pos_token_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.lp_farm_token_nonce, + lp_farm_token_nonce: full_attributes_adjusted.lp_farm_token_nonce, lp_farm_token_amount: remaining_lp_farm_tokens, - virtual_pos_token_nonce: full_attributes.virtual_pos_token_nonce, - virtual_pos_token_amount: remaining_virtual_farm_tokens, - real_pos_token_amount: remaining_real_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); @@ -101,20 +80,12 @@ pub trait ProxyUnstakeModule: None }; - let mut total_staking_rewards = staking_farm_exit_result.staking_rewards; - let opt_unbond_token = opt_unstake_user_pos_result.map(|res| { - total_staking_rewards.merge_with(res.staking_rewards); - - res.unbond_staking_farm_token - }); - 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: total_staking_rewards, + staking_rewards: staking_farm_exit_result.staking_rewards, unbond_staking_farm_token: staking_farm_exit_result.unbond_staking_farm_token, - opt_unbond_staking_farm_token_for_user_pos: opt_unbond_token, opt_new_dual_yield_tokens, }; diff --git a/farm-staking/farm-staking-proxy/src/result_types.rs b/farm-staking/farm-staking-proxy/src/result_types.rs index f1adc4335..af40a59f0 100644 --- a/farm-staking/farm-staking-proxy/src/result_types.rs +++ b/farm-staking/farm-staking-proxy/src/result_types.rs @@ -92,7 +92,6 @@ pub struct UnstakeResult { pub lp_farm_rewards: EsdtTokenPayment, pub staking_rewards: EsdtTokenPayment, pub unbond_staking_farm_token: EsdtTokenPayment, - pub opt_unbond_staking_farm_token_for_user_pos: Option>, pub opt_new_dual_yield_tokens: Option>, } @@ -108,10 +107,6 @@ impl UnstakeResult { payments.push(self.staking_rewards.clone()); payments.push(self.unbond_staking_farm_token.clone()); - if let Some(unbond_for_user_pos) = &self.opt_unbond_staking_farm_token_for_user_pos { - payments.push(unbond_for_user_pos.clone()); - } - if let Some(new_dual_yield_tokens) = &self.opt_new_dual_yield_tokens { payments.push(new_dual_yield_tokens.clone()); } 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 b15c69cc0..5eae751fd 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 @@ -226,26 +226,6 @@ fn unstake_partial_position_test() { let dual_yield_token_amount = 1_001_000_000; - // unstake with half position - wrong payment amount - setup - .b_mock - .execute_esdt_transfer( - &setup.user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - dual_yield_token_nonce_after_stake, - &rust_biguint!(dual_yield_token_amount / 2), - |sc| { - let _ = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(dual_yield_token_amount / 4), - OptionalValue::None, - ); - }, - ) - .assert_user_error("Must exit with full position as payment"); - // unstake with half position - ok setup .b_mock @@ -268,7 +248,7 @@ fn unstake_partial_position_test() { wegld_payment.token_identifier, managed_token_id!(WEGLD_TOKEN_ID) ); - assert_eq!(wegld_payment.amount, 1_001_000_000 / 2); + assert_eq!(wegld_payment.amount, dual_yield_token_amount / 2); let lp_farm_rewards = results.lp_farm_rewards; assert_eq!( @@ -289,14 +269,14 @@ fn unstake_partial_position_test() { unbond_tokens.token_identifier, managed_token_id!(STAKING_FARM_TOKEN_ID) ); - assert_eq!(unbond_tokens.amount, 1_001_000_000 / 2); + 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, 1_001_000_000 / 2); + assert_eq!(new_dual_yield_tokens.amount, dual_yield_token_amount / 2); }, ) .assert_ok(); @@ -304,9 +284,8 @@ fn unstake_partial_position_test() { let expected_new_dual_yield_attributes = DualYieldTokenAttributes:: { lp_farm_token_nonce: 1, lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 2), - virtual_pos_token_nonce: 1, - virtual_pos_token_amount: managed_biguint!(1_001_000_000 / 2), - real_pos_token_amount: managed_biguint!(0), + 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; @@ -464,9 +443,8 @@ fn test_stake_farm_through_proxy_with_merging() { Some(&DualYieldTokenAttributes:: { lp_farm_token_nonce: 1, lp_farm_token_amount: managed_biguint!(400_000_000), - virtual_pos_token_nonce: 1, - virtual_pos_token_amount: managed_biguint!(400_000_000), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(400_000_000), }), ) }); @@ -495,9 +473,8 @@ fn test_stake_farm_through_proxy_with_merging() { Some(&DualYieldTokenAttributes:: { lp_farm_token_nonce: 2, lp_farm_token_amount: managed_biguint!(1_000_000_000), - virtual_pos_token_nonce: 2, - virtual_pos_token_amount: managed_biguint!(1_000_000_000), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: 2, + staking_farm_token_amount: managed_biguint!(1_000_000_000), }), ) }); 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 8be6d9b13..945a36418 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 @@ -156,9 +156,8 @@ where let expected_dual_yield_attributes = DualYieldTokenAttributes:: { lp_farm_token_nonce, lp_farm_token_amount: managed_biguint!(lp_farm_token_stake_amount), - virtual_pos_token_nonce: expected_staking_farm_token_nonce, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: expected_staking_farm_token_nonce, + staking_farm_token_amount: managed_biguint!(expected_staking_token_amount), }; self.b_mock.check_nft_balance( diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 54e221a95..72a5f7f56 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -191,28 +191,20 @@ where farm_positions: &PaymentsVec<::Api>, ) { let farm_token_mapper = sc.farm_token(); - let mut total_farm_position = BigUint::zero(); - let mut farm_position_increase = BigUint::zero(); for farm_position in farm_positions { + let is_old_farm_position = sc.is_old_farm_position(farm_position.token_nonce); farm_token_mapper.require_same_token(&farm_position.token_identifier); - total_farm_position += &farm_position.amount; let token_attributes: StakingFarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if &token_attributes.original_owner != user { + if is_old_farm_position { + Self::increase_user_farm_position(sc, user, &farm_position.amount); + } else if &token_attributes.original_owner != user { Self::decrease_user_farm_position(sc, &farm_position); - farm_position_increase += &farm_position.amount; + Self::increase_user_farm_position(sc, user, &farm_position.amount); } } - let user_total_farm_position = sc.get_user_total_farm_position(user); - if user_total_farm_position.total_farm_position == BigUint::zero() - && total_farm_position > 0 - { - Self::increase_user_farm_position(sc, user, &total_farm_position); - } else if farm_position_increase > 0 { - Self::increase_user_farm_position(sc, user, &farm_position_increase); - } } fn increase_user_farm_position( @@ -236,7 +228,11 @@ where sc.user_total_farm_position(&token_attributes.original_owner) .update(|user_total_farm_position| { - user_total_farm_position.total_farm_position -= farm_position.amount.clone() + if user_total_farm_position.total_farm_position > farm_position.amount { + user_total_farm_position.total_farm_position -= &farm_position.amount; + } else { + user_total_farm_position.total_farm_position = BigUint::zero(); + } }); } } diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index 1ff8628b8..9dfb64c19 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 67 +// Endpoints: 68 // Async Callback: 1 -// Total number of exported functions: 69 +// Total number of exported functions: 70 #![no_std] @@ -43,6 +43,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token getFarmTokenSupply => farm_token_supply From 16576f1b0ad91ddfbfb02c9b3a37ea2feecd69eb Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Mon, 18 Sep 2023 14:05:12 +0300 Subject: [PATCH 32/58] 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)] From 3fc935a05a15f2d88f31e49265faf8d6d6b2f681 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Mon, 18 Sep 2023 14:12:13 +0300 Subject: [PATCH 33/58] clippy fixes --- .github/workflows/actions.yml | 1 + dex/farm-with-locked-rewards/src/lib.rs | 8 +++----- dex/farm/src/lib.rs | 2 +- .../src/claim_only_boosted_staking_rewards.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f6acbaa50..c5fdba201 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -4,6 +4,7 @@ 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 30d02d00c..b189cfd80 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -229,15 +229,13 @@ pub trait Farm: ); } - let boosted_rewards = self.claim_only_boosted_payment(&user); - let locked_rewards_payment = self.send_to_lock_contract_non_zero( + let boosted_rewards = self.claim_only_boosted_payment(user); + self.send_to_lock_contract_non_zero( self.reward_token_id().get(), boosted_rewards, caller.clone(), user.clone(), - ); - - locked_rewards_payment + ) } #[endpoint(startProduceRewards)] diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 77d96d25a..d1775471c 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -228,7 +228,7 @@ pub trait Farm: ); } - let boosted_rewards = self.claim_only_boosted_payment(&user); + let boosted_rewards = self.claim_only_boosted_payment(user); let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); 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 83e609e92..f1138d6c0 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 @@ -40,7 +40,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: ); } - let boosted_rewards = self.claim_only_boosted_payment(&user); + let boosted_rewards = self.claim_only_boosted_payment(user); let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); From be142a314f9a0fb56403c97fbc7ab75d21bd44f4 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Mon, 18 Sep 2023 18:22:27 +0300 Subject: [PATCH 34/58] dedicated migration function for old positions --- .../farm_base_impl/src/base_traits_impl.rs | 13 +++++++---- dex/farm-with-locked-rewards/src/lib.rs | 4 ++++ dex/farm/src/base_functions.rs | 21 +++++++++++++++++ dex/farm/src/lib.rs | 6 +++++ .../farm-staking/src/base_impl_wrapper.rs | 18 ++++++++++----- .../src/claim_only_boosted_staking_rewards.rs | 23 ++++++++++++++++++- .../src/claim_stake_farm_rewards.rs | 2 ++ .../src/compound_stake_farm_rewards.rs | 2 ++ farm-staking/farm-staking/src/lib.rs | 1 + farm-staking/farm-staking/src/stake_farm.rs | 2 +- 10 files changed, 80 insertions(+), 12 deletions(-) diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index c03775abc..8f44e8971 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -196,15 +196,16 @@ pub trait FarmContract { ) { let farm_token_mapper = sc.farm_token(); for farm_position in farm_positions { - let is_old_farm_position = sc.is_old_farm_position(farm_position.token_nonce); + if sc.is_old_farm_position(farm_position.token_nonce) { + continue; + } + farm_token_mapper.require_same_token(&farm_position.token_identifier); let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if is_old_farm_position { - Self::increase_user_farm_position(sc, user, &farm_position.amount); - } else if &token_attributes.original_owner != user { + if &token_attributes.original_owner != user { Self::decrease_user_farm_position(sc, &farm_position); Self::increase_user_farm_position(sc, user, &farm_position.amount); } @@ -227,6 +228,10 @@ pub trait FarmContract { sc: &Self::FarmSc, farm_position: &EsdtTokenPayment<::Api>, ) { + if sc.is_old_farm_position(farm_position.token_nonce) { + return; + } + let farm_token_mapper = sc.farm_token(); let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index b189cfd80..c2723738e 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -88,6 +88,7 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_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 { self.send_to_lock_contract_non_zero( @@ -117,6 +118,8 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); + self.migrate_old_farm_positions(&orig_caller); + let payments = self.call_value().all_esdt_transfers().clone_value(); let base_claim_rewards_result = self.claim_rewards_base::>(orig_caller.clone(), payments); @@ -204,6 +207,7 @@ pub trait Farm: 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 merged_farm_token = self.merge_farm_tokens::>(); self.send_payment_non_zero(&caller, &merged_farm_token); diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index fb5c5dfce..f3512a5f8 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -204,6 +204,27 @@ pub trait BaseFunctionsModule: reward } + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) { + let payments = self.get_non_empty_payments(); + let farm_token_mapper = self.farm_token(); + let farm_token_id = farm_token_mapper.get_token_id(); + for farm_position in &payments { + if farm_position.token_identifier == farm_token_id + && self.is_old_farm_position(farm_position.token_nonce) + { + let token_attributes: FarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner == caller { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += farm_position.amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + } + } + } + fn end_produce_rewards>(&self) { let mut storage = StorageCache::new(self); FC::generate_aggregated_rewards(self, &mut storage); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index d1775471c..f4f23bc78 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -96,6 +96,7 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_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) @@ -121,6 +122,8 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); + self.migrate_old_farm_positions(&orig_caller); + let claim_rewards_result = self.claim_rewards::>(orig_caller.clone()); self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); @@ -138,6 +141,8 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); + self.migrate_old_farm_positions(&orig_caller); + let output_farm_token_payment = self.compound_rewards::>(orig_caller.clone()); self.send_payment_non_zero(&caller, &output_farm_token_payment); @@ -203,6 +208,7 @@ pub trait Farm: 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 merged_farm_token = self.merge_farm_tokens::>(); self.send_payment_non_zero(&caller, &merged_farm_token); diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 72a5f7f56..2b671677f 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -192,28 +192,30 @@ where ) { let farm_token_mapper = sc.farm_token(); for farm_position in farm_positions { - let is_old_farm_position = sc.is_old_farm_position(farm_position.token_nonce); + if sc.is_old_farm_position(farm_position.token_nonce) { + continue; + } + farm_token_mapper.require_same_token(&farm_position.token_identifier); let token_attributes: StakingFarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); - if is_old_farm_position { - Self::increase_user_farm_position(sc, user, &farm_position.amount); - } else if &token_attributes.original_owner != user { + if &token_attributes.original_owner != user { Self::decrease_user_farm_position(sc, &farm_position); Self::increase_user_farm_position(sc, user, &farm_position.amount); } } } + #[inline] fn increase_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, - new_farm_position_amount: &BigUint<::Api>, + increase_farm_position_amount: &BigUint<::Api>, ) { let mut user_total_farm_position = sc.get_user_total_farm_position(user); - user_total_farm_position.total_farm_position += new_farm_position_amount; + user_total_farm_position.total_farm_position += increase_farm_position_amount; sc.user_total_farm_position(user) .set(user_total_farm_position); } @@ -222,6 +224,10 @@ where sc: &Self::FarmSc, farm_position: &EsdtTokenPayment<::Api>, ) { + if sc.is_old_farm_position(farm_position.token_nonce) { + return; + } + let farm_token_mapper = sc.farm_token(); let token_attributes: StakingFarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); 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 f1138d6c0..9144e0b29 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 @@ -1,4 +1,4 @@ -use crate::base_impl_wrapper::FarmStakingWrapper; +use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::StakingFarmTokenAttributes}; multiversx_sc::imports!(); @@ -49,6 +49,27 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: boosted_rewards_payment } + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) { + let payments = self.get_non_empty_payments(); + let farm_token_mapper = self.farm_token(); + let farm_token_id = farm_token_mapper.get_token_id(); + for farm_position in &payments { + if farm_position.token_identifier == farm_token_id + && self.is_old_farm_position(farm_position.token_nonce) + { + let token_attributes: StakingFarmTokenAttributes = + farm_token_mapper.get_token_attributes(farm_position.token_nonce); + + if &token_attributes.original_owner == caller { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += farm_position.amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + } + } + } + // Cannot import the one from farm, as the Wrapper struct has different dependencies fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { let reward = FarmStakingWrapper::::calculate_boosted_rewards(self, caller); diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index bea77d267..e3d0b1dc4 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -7,6 +7,7 @@ use crate::base_impl_wrapper::FarmStakingWrapper; #[multiversx_sc::module] pub trait ClaimStakeFarmRewardsModule: crate::custom_rewards::CustomRewardsModule + + crate::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule + rewards::RewardsModule + config::ConfigModule + events::EventsModule @@ -60,6 +61,7 @@ pub trait ClaimStakeFarmRewardsModule: original_caller: ManagedAddress, opt_new_farming_amount: Option, ) -> ClaimRewardsResultType { + self.migrate_old_farm_positions(&original_caller); let payment = self.call_value().single_esdt(); let mut claim_result = self .claim_rewards_base_no_farm_token_mint::>( diff --git a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs index e51f3b66e..a7d83d574 100644 --- a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs @@ -5,6 +5,7 @@ multiversx_sc::imports!(); #[multiversx_sc::module] pub trait CompoundStakeFarmRewardsModule: crate::custom_rewards::CustomRewardsModule + + crate::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule + rewards::RewardsModule + config::ConfigModule + events::EventsModule @@ -32,6 +33,7 @@ pub trait CompoundStakeFarmRewardsModule: #[endpoint(compoundRewards)] fn compound_rewards(&self) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); + self.migrate_old_farm_positions(&caller); let payments = self.get_non_empty_payments(); let compound_result = self.compound_rewards_base::>(caller.clone(), payments); diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index c4142784a..c9941ced1 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -95,6 +95,7 @@ pub trait FarmStaking: fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); self.check_claim_progress_for_merge(&caller); + self.migrate_old_farm_positions(&caller); let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index 2da477f52..bd5f6481a 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -72,7 +72,7 @@ pub trait StakeFarmModule: payments: PaymentsVec, ) -> EnterFarmResultType { let caller = self.blockchain().get_caller(); - + self.migrate_old_farm_positions(&original_caller); let boosted_rewards = self.claim_only_boosted_payment(&original_caller); let boosted_rewards_payment = if boosted_rewards > 0 { EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards) From a77b7609f7167c215f74e76e2c958131f6162393 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 19 Sep 2023 13:39:42 +0300 Subject: [PATCH 35/58] remove caller check in migrate old position func --- dex/farm/src/base_functions.rs | 13 ++++--------- .../src/claim_only_boosted_staking_rewards.rs | 15 +++++---------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index f3512a5f8..b98a49d5f 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -212,15 +212,10 @@ pub trait BaseFunctionsModule: if farm_position.token_identifier == farm_token_id && self.is_old_farm_position(farm_position.token_nonce) { - let token_attributes: FarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if &token_attributes.original_owner == caller { - let mut user_total_farm_position = self.get_user_total_farm_position(caller); - user_total_farm_position.total_farm_position += farm_position.amount; - self.user_total_farm_position(caller) - .set(user_total_farm_position); - } + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += farm_position.amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); } } } 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 9144e0b29..556a2ef17 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 @@ -1,4 +1,4 @@ -use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::StakingFarmTokenAttributes}; +use crate::base_impl_wrapper::FarmStakingWrapper; multiversx_sc::imports!(); @@ -57,15 +57,10 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: if farm_position.token_identifier == farm_token_id && self.is_old_farm_position(farm_position.token_nonce) { - let token_attributes: StakingFarmTokenAttributes = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if &token_attributes.original_owner == caller { - let mut user_total_farm_position = self.get_user_total_farm_position(caller); - user_total_farm_position.total_farm_position += farm_position.amount; - self.user_total_farm_position(caller) - .set(user_total_farm_position); - } + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += farm_position.amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); } } } From 3fe300e1b0949c7edd51bd48d9bc005c0d0bbb79 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 19 Sep 2023 16:53:54 +0300 Subject: [PATCH 36/58] remove exit amount parameter from farms --- .github/workflows/actions.yml | 1 - common/modules/farm/config/src/config.rs | 2 +- .../farm/farm_base_impl/src/exit_farm.rs | 4 +- dex/farm-with-locked-rewards/src/lib.rs | 31 +------ .../farm_with_locked_rewards_setup/mod.rs | 15 +--- .../tests/farm_with_locked_rewards_test.rs | 2 +- dex/farm/src/lib.rs | 36 ++------ dex/farm/tests/farm_multi_user_test.rs | 16 ++-- .../farm_setup/farm_rewards_distr_setup.rs | 5 +- .../tests/farm_setup/multi_user_farm_setup.rs | 23 ++--- .../farm_setup/single_user_farm_setup.rs | 9 +- dex/farm/tests/farm_single_user_test.rs | 4 +- dex/fuzz/src/fuzz_farm.rs | 4 +- .../src/external_contracts_interactions.rs | 13 +-- .../src/proxy_actions/unstake.rs | 35 +------- .../farm-staking-proxy/src/result_types.rs | 7 -- .../tests/staking_farm_with_lp.rs | 36 +------- .../mod.rs | 6 +- .../src/claim_only_boosted_staking_rewards.rs | 2 +- farm-staking/farm-staking/src/unstake_farm.rs | 45 ++-------- .../tests/farm_staking_energy_test.rs | 6 +- .../tests/farm_staking_setup/mod.rs | 5 +- .../proxy_dex/src/farm_interactions.rs | 7 +- locked-asset/proxy_dex/src/proxy_farm.rs | 35 ++------ .../proxy_dex/tests/proxy_farm_test.rs | 29 ++----- locked-asset/proxy_dex/wasm/Cargo.lock | 84 ++++--------------- locked-asset/proxy_dex/wasm/src/lib.rs | 59 +++++++------ locked-asset/simple-lock/elrond.json | 3 - .../simple-lock/src/farm_interactions.rs | 9 +- locked-asset/simple-lock/src/proxy_farm.rs | 28 ++----- locked-asset/simple-lock/wasm/Cargo.lock | 84 ++++--------------- locked-asset/simple-lock/wasm/src/lib.rs | 47 ++++++----- 32 files changed, 175 insertions(+), 517 deletions(-) delete mode 100644 locked-asset/simple-lock/elrond.json 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..60130ad11 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -8,7 +8,6 @@ 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}, @@ -150,36 +149,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 payment = self.call_value().single_esdt(); - 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 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 +172,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("*")] 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..7f019ed08 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -17,11 +17,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: @@ -156,47 +154,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 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 payment = self.call_value().single_esdt(); - 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("*")] 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..819d87cfe 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -513,25 +513,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 +532,6 @@ where &mut self, user: &Address, farm_token_nonce: u64, - farm_token_amount: u64, exit_farm_amount: u64, known_proxy: &Address, ) { @@ -551,12 +541,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/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/unstake.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs index c78527aa6..f17fb26b7 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.clone().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/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 } From 37c9ebc9ee73a5980a21b337fc7ff8ebec682df8 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 19 Sep 2023 16:58:49 +0300 Subject: [PATCH 37/58] clippy fix --- farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f17fb26b7..920b96eb0 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs @@ -32,7 +32,7 @@ pub trait ProxyUnstakeModule: dual_yield_token_mapper.get_token_attributes(payment.token_nonce); let exit_attributes: DualYieldTokenAttributes = - full_attributes.clone().into_part(&payment.amount); + full_attributes.into_part(&payment.amount); let lp_farm_exit_result = self.lp_farm_exit( orig_caller.clone(), From 9859e47cdcee4df9b42b63b9a61a538194c4def6 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 19 Sep 2023 17:21:26 +0300 Subject: [PATCH 38/58] tests fixes --- dex/scenarios/exit_farm.scen.json | 9 +------ dex/scenarios/exit_farm_too_soon.scen.json | 18 ++----------- dex/scenarios/exit_mex_farm.scen.json | 9 +------ .../farm_reward_distr_scen_1.scen.json | 18 ++----------- .../farm_reward_distr_scen_2.scen.json | 27 +++---------------- .../farm_reward_distr_scen_3.scen.json | 27 +++---------------- .../farm_reward_distr_scen_4.scen.json | 27 +++---------------- 7 files changed, 15 insertions(+), 120 deletions(-) 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", From d9fd8418184e3207daea03145ebd25eb1754a4af Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Wed, 20 Sep 2023 10:38:49 +0300 Subject: [PATCH 39/58] remove metastaking ProxyMergePosModule --- .../src/proxy_actions/merge_pos.rs | 108 ------------------ 1 file changed, 108 deletions(-) delete mode 100644 farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs 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::() - } -} From 65930cea8e24edad99369e17ce0bc9e35798cd6e Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Wed, 20 Sep 2023 10:59:12 +0300 Subject: [PATCH 40/58] send rewards to user in claim_boosted_rewards --- dex/farm-with-locked-rewards/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 60130ad11..dbc7ea16b 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -214,7 +214,7 @@ pub trait Farm: self.send_to_lock_contract_non_zero( self.reward_token_id().get(), boosted_rewards, - caller.clone(), + user.clone(), user.clone(), ) } From ee6644c7675d1aa700b12f2781394ef745947692 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Wed, 20 Sep 2023 13:51:01 +0300 Subject: [PATCH 41/58] claim boosted in merge endpoints --- dex/farm-with-locked-rewards/src/lib.rs | 17 ++++++++---- dex/farm/src/lib.rs | 15 +++++++---- dex/farm/src/progress_update.rs | 27 ------------------- .../tests/farm_setup/multi_user_farm_setup.rs | 4 ++- farm-staking/farm-staking/src/lib.rs | 15 ++++++++--- 5 files changed, 36 insertions(+), 42 deletions(-) delete mode 100644 dex/farm/src/progress_update.rs diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index dbc7ea16b..f998d6d1c 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.clone(), + orig_caller.clone(), + ); - 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/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)] From 1e9ec9215fe337812c1d352d8bb006d5040382b2 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Wed, 20 Sep 2023 14:59:50 +0300 Subject: [PATCH 42/58] clippy and test fix --- dex/farm-with-locked-rewards/src/lib.rs | 4 ++-- dex/scenarios/merge_tokens.scen.json | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index f998d6d1c..c7937d583 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -192,8 +192,8 @@ pub trait Farm: let locked_rewards_payment = self.send_to_lock_contract_non_zero( self.reward_token_id().get(), boosted_rewards, - caller.clone(), - orig_caller.clone(), + caller, + orig_caller, ); (merged_farm_token, locked_rewards_payment).into() 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 From bbff63748cbd527a274dd857292af0f058347101 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 21 Sep 2023 01:25:00 +0300 Subject: [PATCH 43/58] audit fixes (2) --- common/modules/farm/config/src/config.rs | 22 ++++---- .../farm_base_impl/src/base_traits_impl.rs | 4 +- dex/farm-with-locked-rewards/src/lib.rs | 9 +++- dex/farm/src/base_functions.rs | 53 +++++++++++++++++-- dex/farm/src/lib.rs | 8 +-- .../src/claim_only_boosted_staking_rewards.rs | 27 ++++++++-- farm-staking/farm-staking/src/lib.rs | 28 ++++++++++ farm-staking/farm-staking/src/unstake_farm.rs | 4 +- 8 files changed, 123 insertions(+), 32 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index a823a71c7..29bc8838c 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -54,21 +54,17 @@ 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 > 0 && token_nonce < farm_position_migration_block_nonce + let farm_position_migration_nonce = self.farm_position_migration_nonce().get(); + token_nonce > 0 && token_nonce < farm_position_migration_nonce } #[endpoint(allowExternalClaimBoostedRewards)] fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { let caller = self.blockchain().get_caller(); - let user_total_farm_position_mapper = self.user_total_farm_position(&caller); - require!( - !user_total_farm_position_mapper.is_empty(), - "User must have a farm position" - ); - user_total_farm_position_mapper.update(|user_total_farm_position| { - user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; - }); + let mut user_total_farm_position = self.get_user_total_farm_position(&caller); + user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + self.user_total_farm_position(&caller) + .set(user_total_farm_position); } #[view(getFarmingTokenId)] @@ -101,7 +97,7 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio user: &ManagedAddress, ) -> SingleValueMapper>; - #[view(getFarmPositionMigrationBlockNonce)] - #[storage_mapper("farm_position_migration_block_nonce")] - fn farm_position_migration_block_nonce(&self) -> SingleValueMapper; + #[view(getFarmPositionMigrationNonce)] + #[storage_mapper("farm_position_migration_nonce")] + fn farm_position_migration_nonce(&self) -> SingleValueMapper; } diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index 8f44e8971..f2ccc293c 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -196,12 +196,12 @@ pub trait FarmContract { ) { let farm_token_mapper = sc.farm_token(); for farm_position in farm_positions { + farm_token_mapper.require_same_token(&farm_position.token_identifier); + if sc.is_old_farm_position(farm_position.token_nonce) { continue; } - farm_token_mapper.require_same_token(&farm_position.token_identifier); - let token_attributes: FarmTokenAttributes<::Api> = farm_token_mapper.get_token_attributes(farm_position.token_nonce); diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index c7937d583..9ac50d388 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -75,6 +75,9 @@ pub trait Farm: let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + self.try_set_farm_position_migration_nonce(); } #[payable("*")] @@ -155,11 +158,13 @@ pub trait Farm: let payment = self.call_value().single_esdt(); - self.migrate_old_farm_positions(&orig_caller); + let migrated_amount = self.migrate_old_farm_positions(&orig_caller); let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - let rewards = exit_farm_result.rewards; + self.decrease_old_farm_positions(migrated_amount, &orig_caller); + + let rewards = exit_farm_result.rewards; self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); let locked_rewards_payment = self.send_to_lock_contract_non_zero( diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index b98a49d5f..ba576b5e5 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -204,20 +204,63 @@ pub trait BaseFunctionsModule: reward } - fn migrate_old_farm_positions(&self, caller: &ManagedAddress) { + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) -> BigUint { let payments = self.get_non_empty_payments(); let farm_token_mapper = self.farm_token(); let farm_token_id = farm_token_mapper.get_token_id(); + let mut migrated_amount = BigUint::zero(); for farm_position in &payments { if farm_position.token_identifier == farm_token_id && self.is_old_farm_position(farm_position.token_nonce) { - let mut user_total_farm_position = self.get_user_total_farm_position(caller); - user_total_farm_position.total_farm_position += farm_position.amount; - self.user_total_farm_position(caller) - .set(user_total_farm_position); + migrated_amount += farm_position.amount; } } + + if migrated_amount > 0 { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += &migrated_amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + + return migrated_amount; + } + + fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { + if migrated_amount == BigUint::zero() { + return; + } + self.user_total_farm_position(caller) + .update(|user_total_farm_position| { + user_total_farm_position.total_farm_position -= migrated_amount; + }); + } + + fn try_set_farm_position_migration_nonce(&self) { + if !self.farm_position_migration_nonce().is_empty() { + return; + } + + let farm_token_mapper = self.farm_token(); + + let attributes = FarmTokenAttributes { + reward_per_share: BigUint::zero(), + entering_epoch: 0, + compounded_reward: BigUint::zero(), + current_farm_amount: BigUint::zero(), + original_owner: self.blockchain().get_sc_address(), + }; + + let migration_farm_token = farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + + self.farm_position_migration_nonce() + .set(migration_farm_token.token_nonce); + + farm_token_mapper.nft_burn( + migration_farm_token.token_nonce, + &migration_farm_token.amount, + ) } fn end_produce_rewards>(&self) { diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 13f3a29d0..c7364b322 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -78,9 +78,7 @@ pub trait Farm: self.first_week_start_epoch().set_if_empty(current_epoch); // Farm position migration code - let block_nonce = self.blockchain().get_block_nonce(); - self.farm_position_migration_block_nonce() - .set_if_empty(block_nonce); + self.try_set_farm_position_migration_nonce(); } #[payable("*")] @@ -159,10 +157,12 @@ pub trait Farm: let payment = self.call_value().single_esdt(); - self.migrate_old_farm_positions(&orig_caller); + let migrated_amount = self.migrate_old_farm_positions(&orig_caller); let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); + self.decrease_old_farm_positions(migrated_amount, &orig_caller); + self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); self.send_payment_non_zero(&caller, &exit_farm_result.rewards); 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 4e31662b2..fd1ac89e1 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 @@ -49,20 +49,37 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: boosted_rewards_payment } - fn migrate_old_farm_positions(&self, caller: &ManagedAddress) { + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) -> BigUint { 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(); + let mut migrated_amount = BigUint::zero(); for farm_position in &payments { if farm_position.token_identifier == farm_token_id && self.is_old_farm_position(farm_position.token_nonce) { - let mut user_total_farm_position = self.get_user_total_farm_position(caller); - user_total_farm_position.total_farm_position += farm_position.amount; - self.user_total_farm_position(caller) - .set(user_total_farm_position); + migrated_amount += farm_position.amount; } } + + if migrated_amount > 0 { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += &migrated_amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + + return migrated_amount; + } + + fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { + if migrated_amount == BigUint::zero() { + return; + } + self.user_total_farm_position(caller) + .update(|user_total_farm_position| { + user_total_farm_position.total_farm_position -= migrated_amount; + }); } // Cannot import the one from farm, as the Wrapper struct has different dependencies diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 42820dd3f..d3a0cee74 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -88,6 +88,9 @@ pub trait FarmStaking: "Invalid min unbond epochs" ); self.min_unbond_epochs().set_if_empty(min_unbond_epochs); + + // Farm position migration code + self.try_set_farm_position_migration_nonce(); } #[payable("*")] @@ -144,4 +147,29 @@ pub trait FarmStaking: "May only call this function through VM query" ); } + + fn try_set_farm_position_migration_nonce(&self) { + if !self.farm_position_migration_nonce().is_empty() { + return; + } + + let farm_token_mapper = self.farm_token(); + + let attributes = StakingFarmTokenAttributes { + reward_per_share: BigUint::zero(), + compounded_reward: BigUint::zero(), + current_farm_amount: BigUint::zero(), + original_owner: self.blockchain().get_sc_address(), + }; + + let migration_farm_token = farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + + self.farm_position_migration_nonce() + .set(migration_farm_token.token_nonce); + + farm_token_mapper.nft_burn( + migration_farm_token.token_nonce, + &migration_farm_token.amount, + ) + } } diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 6b529e0fb..e40642b4f 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -72,11 +72,13 @@ pub trait UnstakeFarmModule: payment: EsdtTokenPayment, opt_unbond_amount: Option, ) -> ExitFarmWithPartialPosResultType { - self.migrate_old_farm_positions(&original_caller); + let migrated_amount = self.migrate_old_farm_positions(&original_caller); let exit_result = self.exit_farm_base::>(original_caller.clone(), payment); + self.decrease_old_farm_positions(migrated_amount, &original_caller); + let unbond_token_amount = opt_unbond_amount.unwrap_or(exit_result.farming_token_payment.amount); let farm_token_id = exit_result.storage_cache.farm_token_id.clone(); From 4303c0c65f7e98fbceeec4259ac1604400accce6 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 21 Sep 2023 02:04:55 +0300 Subject: [PATCH 44/58] default migration nonce fix --- dex/farm-with-locked-rewards/wasm/src/lib.rs | 2 +- dex/farm/src/base_functions.rs | 23 ++++++++++++------- dex/farm/wasm/src/lib.rs | 2 +- .../src/claim_only_boosted_staking_rewards.rs | 2 +- farm-staking/farm-staking/src/lib.rs | 21 +++++++++++------ farm-staking/farm-staking/wasm/src/lib.rs | 2 +- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index ae9c8fced..64c73e3cc 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -40,7 +40,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position - getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce + getFarmPositionMigrationNonce => farm_position_migration_nonce setLockingScAddress => set_locking_sc_address setLockEpochs => set_lock_epochs getLockingScAddress => locking_sc_address diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index ba576b5e5..fe95ce920 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -19,6 +19,8 @@ pub type DoubleMultiPayment = MultiValue2, EsdtTokenPayme pub type ClaimRewardsResultType = DoubleMultiPayment; pub type ExitFarmResultType = DoubleMultiPayment; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; + pub struct ClaimRewardsResultWrapper { pub new_farm_token: EsdtTokenPayment, pub rewards: EsdtTokenPayment, @@ -224,7 +226,7 @@ pub trait BaseFunctionsModule: .set(user_total_farm_position); } - return migrated_amount; + migrated_amount } fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { @@ -252,15 +254,20 @@ pub trait BaseFunctionsModule: original_owner: self.blockchain().get_sc_address(), }; - let migration_farm_token = farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { + let migration_farm_token = + farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + farm_token_mapper.nft_burn( + migration_farm_token.token_nonce, + &migration_farm_token.amount, + ); + migration_farm_token.token_nonce + } else { + DEFAULT_FARM_POSITION_MIGRATION_NONCE + }; self.farm_position_migration_nonce() - .set(migration_farm_token.token_nonce); - - farm_token_mapper.nft_burn( - migration_farm_token.token_nonce, - &migration_farm_token.amount, - ) + .set(migration_farm_token_nonce); } fn end_produce_rewards>(&self) { diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 4acae57d7..78415bd2c 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -41,7 +41,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position - getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce + getFarmPositionMigrationNonce => farm_position_migration_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token getFarmTokenSupply => farm_token_supply 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 fd1ac89e1..71e7ab9e3 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 @@ -69,7 +69,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: .set(user_total_farm_position); } - return migrated_amount; + migrated_amount } fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index d3a0cee74..81c4d4d1b 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -25,6 +25,8 @@ pub mod token_attributes; pub mod unbond_farm; pub mod unstake_farm; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; + #[multiversx_sc::contract] pub trait FarmStaking: custom_rewards::CustomRewardsModule @@ -162,14 +164,19 @@ pub trait FarmStaking: original_owner: self.blockchain().get_sc_address(), }; - let migration_farm_token = farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { + let migration_farm_token = + farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); + farm_token_mapper.nft_burn( + migration_farm_token.token_nonce, + &migration_farm_token.amount, + ); + migration_farm_token.token_nonce + } else { + DEFAULT_FARM_POSITION_MIGRATION_NONCE + }; self.farm_position_migration_nonce() - .set(migration_farm_token.token_nonce); - - farm_token_mapper.nft_burn( - migration_farm_token.token_nonce, - &migration_farm_token.amount, - ) + .set(migration_farm_token_nonce); } } diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index 9dfb64c19..fedf1dba8 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -43,7 +43,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLastRewardBlockNonce => last_reward_block_nonce getDivisionSafetyConstant => division_safety_constant getUserTotalFarmPosition => user_total_farm_position - getFarmPositionMigrationBlockNonce => farm_position_migration_block_nonce + getFarmPositionMigrationNonce => farm_position_migration_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token getFarmTokenSupply => farm_token_supply From 767f452b63295451a849f07bd8a3dba30fa41990 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 21 Sep 2023 11:32:51 +0300 Subject: [PATCH 45/58] use GetCurrentESDTNFTNonce VM endpoint --- dex/farm/src/base_functions.rs | 18 +++--------------- farm-staking/farm-staking/src/lib.rs | 17 +++-------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index fe95ce920..bbe12a49f 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -246,22 +246,10 @@ pub trait BaseFunctionsModule: let farm_token_mapper = self.farm_token(); - let attributes = FarmTokenAttributes { - reward_per_share: BigUint::zero(), - entering_epoch: 0, - compounded_reward: BigUint::zero(), - current_farm_amount: BigUint::zero(), - original_owner: self.blockchain().get_sc_address(), - }; - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let migration_farm_token = - farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); - farm_token_mapper.nft_burn( - migration_farm_token.token_nonce, - &migration_farm_token.amount, - ); - migration_farm_token.token_nonce + let token_identifier = farm_token_mapper.get_token_id_ref(); + self.blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) } else { DEFAULT_FARM_POSITION_MIGRATION_NONCE }; diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 81c4d4d1b..26622a02b 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -157,21 +157,10 @@ pub trait FarmStaking: let farm_token_mapper = self.farm_token(); - let attributes = StakingFarmTokenAttributes { - reward_per_share: BigUint::zero(), - compounded_reward: BigUint::zero(), - current_farm_amount: BigUint::zero(), - original_owner: self.blockchain().get_sc_address(), - }; - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let migration_farm_token = - farm_token_mapper.nft_create(BigUint::from(1u64), &attributes); - farm_token_mapper.nft_burn( - migration_farm_token.token_nonce, - &migration_farm_token.amount, - ); - migration_farm_token.token_nonce + let token_identifier = farm_token_mapper.get_token_id_ref(); + self.blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) } else { DEFAULT_FARM_POSITION_MIGRATION_NONCE }; From 8100d5732761e889a244ad4a5347ccfa7bdf422b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 21 Sep 2023 12:53:41 +0300 Subject: [PATCH 46/58] try_set_farm_position_migration_nonce: code dup Moved try_set_farm_position_migration_nonce to common modules to remove code duplication. --- common/modules/farm/config/src/config.rs | 34 +++++++++++++++++++----- dex/farm-with-locked-rewards/src/lib.rs | 3 ++- dex/farm/src/base_functions.rs | 19 ------------- dex/farm/src/lib.rs | 3 ++- farm-staking/farm-staking/src/lib.rs | 24 ++--------------- 5 files changed, 33 insertions(+), 50 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 29bc8838c..ea4d856e0 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -7,6 +7,7 @@ use common_structs::Nonce; use pausable::State; pub const DEFAULT_NFT_DEPOSIT_MAX_LEN: usize = 10; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; #[derive( ManagedVecItem, @@ -35,6 +36,16 @@ impl Default for UserTotalFarmPosition { #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { + + #[endpoint(allowExternalClaimBoostedRewards)] + fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { + let caller = self.blockchain().get_caller(); + let mut user_total_farm_position = self.get_user_total_farm_position(&caller); + user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + self.user_total_farm_position(&caller) + .set(user_total_farm_position); + } + #[inline] fn is_active(&self) -> bool { let state = self.state().get(); @@ -58,15 +69,24 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio token_nonce > 0 && token_nonce < farm_position_migration_nonce } - #[endpoint(allowExternalClaimBoostedRewards)] - fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { - let caller = self.blockchain().get_caller(); - let mut user_total_farm_position = self.get_user_total_farm_position(&caller); - user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; - self.user_total_farm_position(&caller) - .set(user_total_farm_position); + fn try_set_farm_position_migration_nonce(&self, farm_token_mapper: NonFungibleTokenMapper) { + if !self.farm_position_migration_nonce().is_empty() { + return; + } + + let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { + let token_identifier = farm_token_mapper.get_token_id_ref(); + self.blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) + } else { + DEFAULT_FARM_POSITION_MIGRATION_NONCE + }; + + self.farm_position_migration_nonce() + .set(migration_farm_token_nonce); } + #[view(getFarmingTokenId)] #[storage_mapper("farming_token_id")] fn farming_token_id(&self) -> SingleValueMapper; diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 9ac50d388..27421ac16 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -77,7 +77,8 @@ pub trait Farm: self.first_week_start_epoch().set_if_empty(current_epoch); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index bbe12a49f..968e3381d 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -239,25 +239,6 @@ pub trait BaseFunctionsModule: }); } - fn try_set_farm_position_migration_nonce(&self) { - if !self.farm_position_migration_nonce().is_empty() { - return; - } - - let farm_token_mapper = self.farm_token(); - - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let token_identifier = farm_token_mapper.get_token_id_ref(); - self.blockchain() - .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) - } else { - DEFAULT_FARM_POSITION_MIGRATION_NONCE - }; - - self.farm_position_migration_nonce() - .set(migration_farm_token_nonce); - } - fn end_produce_rewards>(&self) { let mut storage = StorageCache::new(self); FC::generate_aggregated_rewards(self, &mut storage); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index c7364b322..5a18d41e3 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -78,7 +78,8 @@ pub trait Farm: self.first_week_start_epoch().set_if_empty(current_epoch); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 26622a02b..5bd41cecf 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -25,8 +25,6 @@ pub mod token_attributes; pub mod unbond_farm; pub mod unstake_farm; -pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; - #[multiversx_sc::contract] pub trait FarmStaking: custom_rewards::CustomRewardsModule @@ -92,7 +90,8 @@ pub trait FarmStaking: self.min_unbond_epochs().set_if_empty(min_unbond_epochs); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] @@ -149,23 +148,4 @@ pub trait FarmStaking: "May only call this function through VM query" ); } - - fn try_set_farm_position_migration_nonce(&self) { - if !self.farm_position_migration_nonce().is_empty() { - return; - } - - let farm_token_mapper = self.farm_token(); - - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let token_identifier = farm_token_mapper.get_token_id_ref(); - self.blockchain() - .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) - } else { - DEFAULT_FARM_POSITION_MIGRATION_NONCE - }; - - self.farm_position_migration_nonce() - .set(migration_farm_token_nonce); - } } From aba2e4ec4b0517a57567ab85aa279e386e5e4a00 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 22 Sep 2023 11:23:05 +0300 Subject: [PATCH 47/58] fix farm_position_migration_nonce set function --- common/modules/farm/config/src/config.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index ea4d856e0..e65056062 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -36,7 +36,6 @@ impl Default for UserTotalFarmPosition { #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { - #[endpoint(allowExternalClaimBoostedRewards)] fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { let caller = self.blockchain().get_caller(); @@ -69,15 +68,20 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio token_nonce > 0 && token_nonce < farm_position_migration_nonce } - fn try_set_farm_position_migration_nonce(&self, farm_token_mapper: NonFungibleTokenMapper) { + fn try_set_farm_position_migration_nonce( + &self, + farm_token_mapper: NonFungibleTokenMapper, + ) { if !self.farm_position_migration_nonce().is_empty() { return; } let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { let token_identifier = farm_token_mapper.get_token_id_ref(); - self.blockchain() - .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) + let current_nonce = self + .blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier); + current_nonce + DEFAULT_FARM_POSITION_MIGRATION_NONCE } else { DEFAULT_FARM_POSITION_MIGRATION_NONCE }; @@ -86,7 +90,6 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio .set(migration_farm_token_nonce); } - #[view(getFarmingTokenId)] #[storage_mapper("farming_token_id")] fn farming_token_id(&self) -> SingleValueMapper; From 494b301a09df5ad60d19a240123c8bf2f0b747a4 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 26 Sep 2023 14:04:32 +0300 Subject: [PATCH 48/58] farm position functionality tests --- .../tests/farm_with_locked_rewards_test.rs | 107 ++++ dex/farm/tests/farm_multi_user_test.rs | 96 --- .../tests/farm_setup/multi_user_farm_setup.rs | 58 +- dex/farm/tests/total_farm_position_test.rs | 546 ++++++++++++++++++ 4 files changed, 708 insertions(+), 99 deletions(-) create mode 100644 dex/farm/tests/total_farm_position_test.rs 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 5d7bdf7be..8a9fb8793 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 @@ -228,3 +228,110 @@ fn farm_with_boosted_yields_no_proxy_test() { None, ); } + +#[test] +fn total_farm_position_claim_with_locked_rewards_test() { + DebugApi::dummy(); + let mut farm_setup = FarmSetup::new( + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }), + ); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }), + ); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + let total_farm_tokens = farm_in_amount * 2; + + // first user claim with half total position + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2_500 * 3 * 1_000 / 1_000 + 2_500 * 2 * 100_000_000 / 100_000_000) / (3 + 2) + // (7_500 + 2_500) / (5) = 2_500 + let first_boosted_amt = 2_500; // 1000 energy & 100_000_000 farm tokens + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&first_user, 3, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + // Check user receive locked rewards + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + LOCKED_REWARD_TOKEN_ID, + 1, + &rust_biguint!(first_received_reward_amt), + None, + ); +} diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 7fe7c53d3..03315b184 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -221,102 +221,6 @@ fn farm_with_boosted_yields_test() { ); } -#[test] -fn farm_claim_boosted_yields_for_other_user_test() { - DebugApi::dummy(); - let mut farm_setup = MultiUserFarmSetup::new( - farm::contract_obj, - energy_factory_mock::contract_obj, - energy_update::contract_obj, - ); - - farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - farm_setup.set_boosted_yields_factors(); - farm_setup.b_mock.set_block_epoch(2); - - // first user enter farm - let first_farm_token_amount = 100_000_000; - let first_user = farm_setup.first_user.clone(); - let third_user = farm_setup.third_user.clone(); - - farm_setup.set_user_energy(&first_user, 1_000, 2, 1); - farm_setup.enter_farm(&first_user, first_farm_token_amount); - - // second user enter farm - let second_farm_token_amount = 50_000_000; - let second_user = farm_setup.second_user.clone(); - farm_setup.set_user_energy(&second_user, 4_000, 2, 1); - farm_setup.enter_farm(&second_user, second_farm_token_amount); - - // users claim rewards to get their energy registered - let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_amount); - let _ = farm_setup.claim_rewards(&second_user, 2, second_farm_token_amount); - - // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards - // 7_500 base farm, 2_500 boosted yields - farm_setup.b_mock.set_block_nonce(10); - - // random tx on end of week 1, to cummulate rewards - farm_setup.b_mock.set_block_epoch(6); - farm_setup.set_user_energy(&first_user, 1_000, 6, 1); - 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); - - // advance 1 week - farm_setup.b_mock.set_block_epoch(10); - farm_setup.set_user_energy(&first_user, 1_000, 10, 1); - farm_setup.set_user_energy(&second_user, 4_000, 10, 1); - - // Second user claims for himself - let total_farm_tokens = first_farm_token_amount + second_farm_token_amount; - let second_base_farm_amt = second_farm_token_amount * 7_500 / total_farm_tokens; - let second_boosted_amt = 1533; // 4000 energy & 50_000_000 farm tokens - let second_total = second_base_farm_amt + second_boosted_amt; - - let second_receveived_reward_amt = - farm_setup.claim_rewards(&second_user, 4, second_farm_token_amount); - assert_eq!(second_receveived_reward_amt, second_total); - - farm_setup - .b_mock - .check_nft_balance::>( - &second_user, - FARM_TOKEN_ID, - 6, - &rust_biguint!(second_farm_token_amount), - None, - ); - - farm_setup.b_mock.check_esdt_balance( - &second_user, - REWARD_TOKEN_ID, - &rust_biguint!(second_receveived_reward_amt), - ); - - // Boosted yields rewards formula - // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) - // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) - // (2500 * 3 * 1_000 / 5_000 + 2500 * 2 * 100_000_000 / 150_000_000) / (3 + 2) - // (1500 + 3333) / (5) = 966 - let first_boosted_amt = 966; // 1000 energy & 100_000_000 farm tokens - - // Second user claim boosted rewards for first user - farm_setup.allow_external_claim_rewards(&first_user); - - let first_receveived_boosted_amt = - farm_setup.claim_boosted_rewards_for_user(&first_user, &second_user); - assert_eq!(first_receveived_boosted_amt, first_boosted_amt); - - // First user should receive the boosted rewards - farm_setup.b_mock.check_esdt_balance( - &first_user, - REWARD_TOKEN_ID, - &rust_biguint!(first_receveived_boosted_amt), - ); -} - #[test] fn farm_change_boosted_yields_factors_test() { DebugApi::dummy(); 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 0168b2bf6..fea83e1d3 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -2,7 +2,7 @@ #![allow(deprecated)] use common_structs::FarmTokenAttributes; -use config::ConfigModule; +use config::{ConfigModule, UserTotalFarmPosition}; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::{ storage::mappers::StorageTokenWrapper, @@ -472,6 +472,18 @@ where result } + pub fn claim_boosted_rewards_for_user_expect_error( + &mut self, + owner: &Address, + broker: &Address, + ) { + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + }) + .assert_error(4, "Cannot claim rewards for this address"); + } + pub fn claim_rewards_known_proxy( &mut self, user: &Address, @@ -551,12 +563,13 @@ where .assert_ok(); } - pub fn allow_external_claim_rewards(&mut self, user: &Address) { + pub fn allow_external_claim_rewards(&mut self, user: &Address, allow_external_claim: bool) { self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { sc.user_total_farm_position(&managed_address!(user)).update( |user_total_farm_position| { - user_total_farm_position.allow_external_claim_boosted_rewards = true; + user_total_farm_position.allow_external_claim_boosted_rewards = + allow_external_claim; }, ); }) @@ -637,4 +650,43 @@ where }) .assert_ok(); } + + pub fn check_farm_token_supply(&mut self, expected_farm_token_supply: u64) { + let b_mock = &mut self.b_mock; + b_mock + .execute_query(&self.farm_wrapper, |sc| { + let actual_farm_supply = sc.farm_token_supply().get(); + assert_eq!( + managed_biguint!(expected_farm_token_supply), + actual_farm_supply + ); + }) + .assert_ok(); + } + + pub fn set_user_total_farm_position(&mut self, user_addr: &Address, new_farm_position: u64) { + self.b_mock + .execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let mut user_farm_position = UserTotalFarmPosition::default(); + user_farm_position.total_farm_position = managed_biguint!(new_farm_position); + sc.user_total_farm_position(&managed_address!(&user_addr)) + .set(user_farm_position); + }) + .assert_ok(); + } + + pub fn check_user_total_farm_position(&mut self, user_addr: &Address, expected_amount: u64) { + self.b_mock + .execute_query(&self.farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(&user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get().total_farm_position + ); + } + }) + .assert_ok(); + } } diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs new file mode 100644 index 000000000..55bc51903 --- /dev/null +++ b/dex/farm/tests/total_farm_position_test.rs @@ -0,0 +1,546 @@ +#![allow(deprecated)] + +mod farm_setup; + +use common_structs::FarmTokenAttributes; +use config::ConfigModule; +use farm_setup::multi_user_farm_setup::{MultiUserFarmSetup, BOOSTED_YIELDS_PERCENTAGE}; +use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; + +use crate::farm_setup::multi_user_farm_setup::{FARM_TOKEN_ID, REWARD_TOKEN_ID}; + +#[test] +fn total_farm_position_claim_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }), + ); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }), + ); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + let total_farm_tokens = farm_in_amount * 2; + + // first user claim with half total position + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2_500 * 3 * 1_000 / 1_000 + 2_500 * 2 * 100_000_000 / 100_000_000) / (3 + 2) + // (7_500 + 2_500) / (5) = 2_500 + let first_boosted_amt = 2_500; // 1000 energy & 100_000_000 farm tokens + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&first_user, 3, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); +} + +#[test] +fn allow_external_claim_rewards_setting_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enter farm + let first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_user.clone(); + let third_user = farm_setup.third_user.clone(); + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, first_farm_token_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_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, 3, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + let first_boosted_amt = 2500; + + // Second user claim boosted rewards for first user + farm_setup.allow_external_claim_rewards(&first_user, true); + + let first_received_boosted_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &third_user); + assert_eq!(first_received_boosted_amt, first_boosted_amt); + + // First user should receive the boosted rewards + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_boosted_amt), + ); + + // Check allow external claim is set to false + farm_setup.allow_external_claim_rewards(&first_user, false); + + farm_setup.claim_boosted_rewards_for_user_expect_error(&first_user, &third_user); +} + +#[test] +fn test_total_farm_position_claim_for_other_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enter farm + let first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_user.clone(); + let third_user = farm_setup.third_user.clone(); + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, first_farm_token_amount); + + // second user enter farm + let second_farm_token_amount = 50_000_000; + let second_user = farm_setup.second_user.clone(); + farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.enter_farm(&second_user, second_farm_token_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_amount); + let _ = farm_setup.claim_rewards(&second_user, 2, second_farm_token_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + 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); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + farm_setup.set_user_energy(&second_user, 4_000, 10, 1); + + // Second user claims for himself + let total_farm_tokens = first_farm_token_amount + second_farm_token_amount; + let second_base_farm_amt = second_farm_token_amount * 7_500 / total_farm_tokens; + let second_boosted_amt = 1533; // 4000 energy & 50_000_000 farm tokens + let second_total = second_base_farm_amt + second_boosted_amt; + + let second_received_reward_amt = + farm_setup.claim_rewards(&second_user, 4, second_farm_token_amount); + assert_eq!(second_received_reward_amt, second_total); + + farm_setup + .b_mock + .check_nft_balance::>( + &second_user, + FARM_TOKEN_ID, + 6, + &rust_biguint!(second_farm_token_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_received_reward_amt), + ); + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2500 * 3 * 1_000 / 5_000 + 2500 * 2 * 100_000_000 / 150_000_000) / (3 + 2) + // (1500 + 3333) / (5) = 966 + let first_boosted_amt = 966; // 1000 energy & 100_000_000 farm tokens + + // Second user claim boosted rewards for first user + farm_setup.allow_external_claim_rewards(&first_user, true); + + let first_received_boosted_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &second_user); + assert_eq!(first_received_boosted_amt, first_boosted_amt); + + // First user should receive the boosted rewards + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_boosted_amt), + ); +} + +#[test] +fn farm_total_position_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(2); + }, + ) + .assert_ok(); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 2, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + let total_farm_tokens = farm_in_amount * 2; + + // first user claim with half total position + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + + let first_boosted_amt = 2_000; // claim boosted with only half total position - not full rewards + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&first_user, 3, farm_in_amount); + + // Should be equal to half base generated rewards + partial boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); + + // advance 10 more blocks - 10_000 more total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(20); + + // random tx on end of week 2, to cummulate rewards + farm_setup.b_mock.set_block_epoch(13); + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.set_user_energy(&temp_user, 1, 13, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 6, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&first_user, 1_000, 20, 1); + + // user claims with old position - should migrate his entire position + let second_received_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + let second_base_farm_amt = (farm_in_amount * 7_500 / total_farm_tokens) * 2; // user claims with initial position (2 weeks worth of rewards) + let second_boosted_amt = 2_500; // claim boosted with entire total position - receives full rewards + let second_total_rewards = second_base_farm_amt + second_boosted_amt; + assert_eq!(second_received_reward_amt, second_total_rewards); +} + +#[test] +fn farm_total_position_exit_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(2); + }, + ) + .assert_ok(); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 2, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + // first user exist farm with old position + farm_setup.exit_farm(&first_user, 1, farm_in_amount); + + // user farm position should be unchanged + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // User should receive half base rewards and full boosted rewards + let total_farm_tokens = farm_in_amount * 2; + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + let first_boosted_amt = 2_500; + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_total_rewards), + ); +} + +#[test] +fn no_boosted_rewards_penalty_for_exit_farm_test() { + DebugApi::dummy(); + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(5); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 5, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 2, farm_in_amount); + + // advance to week 1 + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of the week, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance to week 2 + farm_setup.b_mock.set_block_nonce(20); + + // random tx on end of the week, to cummulate rewards + farm_setup.b_mock.set_block_epoch(13); + farm_setup.set_user_energy(&temp_user, 1, 13, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 5, 1); + + // advance to week 3 + farm_setup.b_mock.set_block_nonce(30); + + // random tx on end of the week, to cummulate rewards + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&temp_user, 1, 20, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 6, 1); + + // advance to week 4 + farm_setup.b_mock.set_block_epoch(25); + farm_setup.set_user_energy(&first_user, 0, 25, 1); + + // first user claims 3 weeks worth of rewards (2-4) + let total_farm_tokens = farm_in_amount * 2; + let first_base_farm_amt = (farm_in_amount * 7_500 / total_farm_tokens) * 3; + let first_boosted_amt = 2_500 * 3; + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_receveived_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_receveived_reward_amt, first_total_rewards); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_receveived_reward_amt), + ); +} From 772779a56f237b148a77539a303525c12fd6eaad Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 26 Sep 2023 14:16:21 +0300 Subject: [PATCH 49/58] allow_external_claim_rewards_setting extra check --- dex/farm/tests/farm_setup/multi_user_farm_setup.rs | 10 ++++++---- dex/farm/tests/total_farm_position_test.rs | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) 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 fea83e1d3..2e74ab42c 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -667,9 +667,11 @@ where pub fn set_user_total_farm_position(&mut self, user_addr: &Address, new_farm_position: u64) { self.b_mock .execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| { - let mut user_farm_position = UserTotalFarmPosition::default(); - user_farm_position.total_farm_position = managed_biguint!(new_farm_position); - sc.user_total_farm_position(&managed_address!(&user_addr)) + let user_farm_position = UserTotalFarmPosition { + total_farm_position: managed_biguint!(new_farm_position), + ..Default::default() + }; + sc.user_total_farm_position(&managed_address!(user_addr)) .set(user_farm_position); }) .assert_ok(); @@ -679,7 +681,7 @@ where self.b_mock .execute_query(&self.farm_wrapper, |sc| { let user_total_farm_position_mapper = - sc.user_total_farm_position(&managed_address!(&user_addr)); + sc.user_total_farm_position(&managed_address!(user_addr)); if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { assert_eq!( managed_biguint!(expected_amount), diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index 55bc51903..a15287e44 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -169,6 +169,11 @@ fn allow_external_claim_rewards_setting_test() { &rust_biguint!(first_received_boosted_amt), ); + // User who called the claim function should not receive anything + farm_setup + .b_mock + .check_esdt_balance(&third_user, REWARD_TOKEN_ID, &rust_biguint!(0)); + // Check allow external claim is set to false farm_setup.allow_external_claim_rewards(&first_user, false); From d790945bbd94b1515259963e77a8acd842524f2a Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 26 Sep 2023 14:24:47 +0300 Subject: [PATCH 50/58] total_farm_position_claim_for_other extra check --- dex/farm/tests/total_farm_position_test.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index a15287e44..1dbfc672b 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -181,7 +181,7 @@ fn allow_external_claim_rewards_setting_test() { } #[test] -fn test_total_farm_position_claim_for_other_test() { +fn total_farm_position_claim_for_other_test() { DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, @@ -274,6 +274,13 @@ fn test_total_farm_position_claim_for_other_test() { REWARD_TOKEN_ID, &rust_biguint!(first_received_boosted_amt), ); + + // Second user has the same amount of reward tokens + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_received_reward_amt), + ); } #[test] From 0ee2b4271e8f8f1948bf0acd4fbf423fae962c69 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Tue, 26 Sep 2023 14:43:30 +0300 Subject: [PATCH 51/58] farm position tests updates --- dex/farm/tests/total_farm_position_test.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index 1dbfc672b..26756ebaa 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -392,6 +392,8 @@ fn farm_total_position_migration_test() { // user claims with old position - should migrate his entire position let second_received_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); + let second_base_farm_amt = (farm_in_amount * 7_500 / total_farm_tokens) * 2; // user claims with initial position (2 weeks worth of rewards) let second_boosted_amt = 2_500; // claim boosted with entire total position - receives full rewards let second_total_rewards = second_base_farm_amt + second_boosted_amt; @@ -479,7 +481,7 @@ fn farm_total_position_exit_migration_test() { } #[test] -fn no_boosted_rewards_penalty_for_exit_farm_test() { +fn no_boosted_rewards_penalty_for_no_energy_test() { DebugApi::dummy(); DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( @@ -519,9 +521,12 @@ fn no_boosted_rewards_penalty_for_exit_farm_test() { // advance to week 2 farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + + // User unlocks XMEX and has no energy + farm_setup.set_user_energy(&first_user, 0, 13, 1); // random tx on end of the week, to cummulate rewards - farm_setup.b_mock.set_block_epoch(13); farm_setup.set_user_energy(&temp_user, 1, 13, 1); farm_setup.enter_farm(&temp_user, 1); farm_setup.exit_farm(&temp_user, 5, 1); @@ -537,7 +542,6 @@ fn no_boosted_rewards_penalty_for_exit_farm_test() { // advance to week 4 farm_setup.b_mock.set_block_epoch(25); - farm_setup.set_user_energy(&first_user, 0, 25, 1); // first user claims 3 weeks worth of rewards (2-4) let total_farm_tokens = farm_in_amount * 2; From 4262fa1e8ba883b5f0e7e9438488fd5d2d580ddc Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 28 Sep 2023 19:36:45 +0300 Subject: [PATCH 52/58] farm staking full position claim test --- .../tests/farm_staking_energy_test.rs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) 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 b2c3c5b3f..230d84747 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -245,3 +245,114 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { ); fs_setup.check_farm_token_supply(farm_in_amount); } + +#[test] +fn farm_staking_full_position_boosted_rewards_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + + let farm_in_amount = 50_000_000; + fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &fs_setup.user_address, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_nonce(10); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 4, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + + let expected_base_rewards = 15; + let expected_boosted_rewards = 10; + let mut expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) + + expected_base_rewards + + expected_boosted_rewards + ); + let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + + // Should receive half base rewards and full boosted rewards + fs_setup.claim_rewards( + farm_in_amount, + 2, + expected_base_rewards + expected_boosted_rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 6, + expected_reward_per_share, + ); + + // Should receive half base rewards and no boosted rewards + expected_farming_token_balance += expected_base_rewards; + fs_setup.claim_rewards( + farm_in_amount, + 3, + expected_base_rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 7, + expected_reward_per_share, + ); + fs_setup.check_farm_token_supply(farm_in_amount * 2); +} From 36be9634322a7cf8d4ce9e0fbadedcf47983e63e Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 10:11:05 +0300 Subject: [PATCH 53/58] clippy fix --- farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 920b96eb0..2faf021a3 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs @@ -49,7 +49,7 @@ pub trait ProxyUnstakeModule: orig_caller.clone(), remove_liq_result.staking_token_payment, exit_attributes.staking_farm_token_nonce, - exit_attributes.staking_farm_token_amount.clone(), + exit_attributes.staking_farm_token_amount, ); let caller = self.blockchain().get_caller(); From 5acf5e4f35b53e218832f06fcba1cc55b8be55d4 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 11:06:34 +0300 Subject: [PATCH 54/58] build & cargo lock --- dex/governance/wasm/Cargo.lock | 80 ++--------- dex/governance/wasm/src/lib.rs | 50 ++++--- dex/pair-mock/wasm/Cargo.lock | 80 ++--------- dex/pair-mock/wasm/src/lib.rs | 12 +- dex/pair/wasm-pair-full/Cargo.lock | 84 ++--------- dex/pair/wasm-pair-full/src/lib.rs | 134 +++++++++--------- dex/pair/wasm-safe-price-view/Cargo.lock | 84 ++--------- dex/pair/wasm-safe-price-view/src/lib.rs | 27 ++-- dex/pair/wasm/Cargo.lock | 84 ++--------- dex/pair/wasm/src/lib.rs | 116 +++++++-------- dex/price-discovery/wasm/Cargo.lock | 84 ++--------- dex/price-discovery/wasm/src/lib.rs | 63 ++++---- dex/proxy-deployer/wasm/Cargo.lock | 84 ++--------- dex/proxy-deployer/wasm/src/lib.rs | 16 ++- dex/router/wasm/Cargo.lock | 84 ++--------- dex/router/wasm/src/lib.rs | 74 +++++----- .../energy-factory-mock/wasm/Cargo.lock | 84 ++--------- .../energy-factory-mock/wasm/src/lib.rs | 16 ++- .../energy-update/wasm/Cargo.lock | 84 ++--------- .../energy-update/wasm/src/lib.rs | 10 +- .../governance-v2/wasm/Cargo.lock | 84 ++--------- .../governance-v2/wasm/src/lib.rs | 62 ++++---- .../metabonding-staking/wasm/Cargo.lock | 30 ++-- .../metabonding-staking/wasm/src/lib.rs | 28 ++-- locked-asset/distribution/wasm/Cargo.lock | 30 ++-- locked-asset/distribution/wasm/src/lib.rs | 38 ++--- locked-asset/energy-factory/wasm/Cargo.lock | 84 ++--------- locked-asset/energy-factory/wasm/src/lib.rs | 73 +++++----- locked-asset/factory/wasm/Cargo.lock | 30 ++-- locked-asset/factory/wasm/src/lib.rs | 57 ++++---- locked-asset/lkmex-transfer/wasm/Cargo.lock | 84 ++--------- locked-asset/lkmex-transfer/wasm/src/lib.rs | 30 ++-- .../locked-token-wrapper/wasm/Cargo.lock | 84 ++--------- .../locked-token-wrapper/wasm/src/lib.rs | 25 ++-- .../simple-lock-whitelist/wasm/Cargo.lock | 84 ++--------- .../simple-lock-whitelist/wasm/src/lib.rs | 57 ++++---- locked-asset/token-unstake/wasm/Cargo.lock | 84 ++--------- locked-asset/token-unstake/wasm/src/lib.rs | 28 ++-- pause-all/wasm/Cargo.lock | 84 ++--------- pause-all/wasm/src/lib.rs | 22 +-- 40 files changed, 806 insertions(+), 1642 deletions(-) diff --git a/dex/governance/wasm/Cargo.lock b/dex/governance/wasm/Cargo.lock index ebe14cc18..193e4531f 100644 --- a/dex/governance/wasm/Cargo.lock +++ b/dex/governance/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" @@ -85,23 +79,11 @@ 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 = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[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", @@ -113,20 +95,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", @@ -136,9 +117,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", @@ -149,12 +130,11 @@ dependencies = [ [[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]] @@ -183,9 +163,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", ] @@ -237,37 +217,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/dex/governance/wasm/src/lib.rs b/dex/governance/wasm/src/lib.rs index bfedec764..3e106b05e 100644 --- a/dex/governance/wasm/src/lib.rs +++ b/dex/governance/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 23 #![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,28 +21,29 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { governance ( - propose - upvote - downvote - execute - redeem - changeQuorum - changeMinTokenBalanceForProposing - changeVotingDelayInBlocks - changeVotingPeriodInBlocks - changeGovernanceTokenIds - changePriceProviders - getGovernanceTokenId - getQuorum - getMinWeightForProposal - getVotingDelayInBlocks - getVotingPeriodInBlocks - getProposal - getProposalIdCounter - getVoteNFTId - getMexTokenId - getProposalStatus + init => init + propose => propose + upvote => upvote + downvote => downvote + execute => execute + redeem => redeem + changeQuorum => change_quorum + changeMinTokenBalanceForProposing => change_min_weight_for_proposal + changeVotingDelayInBlocks => change_voting_delay_in_blocks + changeVotingPeriodInBlocks => change_voting_period_in_blocks + changeGovernanceTokenIds => change_governance_token_ids + changePriceProviders => change_price_providers + getGovernanceTokenId => governance_token_ids + getQuorum => quorum + getMinWeightForProposal => min_weight_for_proposal + getVotingDelayInBlocks => voting_delay_in_blocks + getVotingPeriodInBlocks => voting_period_in_blocks + getProposal => proposal + getProposalIdCounter => proposal_id_counter + getVoteNFTId => vote_nft_id + getMexTokenId => mex_token_id + getProposalStatus => get_proposal_status_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair-mock/wasm/Cargo.lock b/dex/pair-mock/wasm/Cargo.lock index fdfb68d12..0fbb17cd7 100644 --- a/dex/pair-mock/wasm/Cargo.lock +++ b/dex/pair-mock/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" @@ -92,23 +86,11 @@ dependencies = [ "either", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[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", @@ -120,20 +102,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", @@ -143,9 +124,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", @@ -156,12 +137,11 @@ dependencies = [ [[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]] @@ -207,9 +187,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", ] @@ -261,37 +241,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/dex/pair-mock/wasm/src/lib.rs b/dex/pair-mock/wasm/src/lib.rs index 54b9b427e..77325383a 100644 --- a/dex/pair-mock/wasm/src/lib.rs +++ b/dex/pair-mock/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 4 #![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,9 +21,10 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pair_mock ( - addInitialLiquidity - getTokensForGivenPositionWithSafePrice + init => init + addInitialLiquidity => add_initial_liquidity + getTokensForGivenPositionWithSafePrice => get_tokens_for_given_position_with_safe_price ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair/wasm-pair-full/Cargo.lock b/dex/pair/wasm-pair-full/Cargo.lock index 9077209cd..b337ee608 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/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" @@ -168,12 +162,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +178,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" @@ -205,9 +187,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", @@ -219,20 +201,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", @@ -242,9 +223,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", @@ -255,21 +236,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]] @@ -338,9 +318,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -436,18 +416,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" @@ -467,25 +435,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/dex/pair/wasm-pair-full/src/lib.rs b/dex/pair/wasm-pair-full/src/lib.rs index 30efb71cb..9c6650e16 100644 --- a/dex/pair/wasm-pair-full/src/lib.rs +++ b/dex/pair/wasm-pair-full/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 65 #![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,70 +21,71 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pair ( - addInitialLiquidity - addLiquidity - removeLiquidity - removeLiquidityAndBuyBackAndBurnToken - swapNoFeeAndForward - swapTokensFixedInput - swapTokensFixedOutput - setLpTokenIdentifier - getTokensForGivenPosition - getReservesAndTotalSupply - getAmountOut - getAmountIn - getEquivalent - getFeeState - whitelist - removeWhitelist - addTrustedSwapPair - removeTrustedSwapPair - setupFeesCollector - setFeeOn - getFeeDestinations - getTrustedSwapPairs - getWhitelistedManagedAddresses - getFeesCollectorAddress - getFeesCollectorCutPercentage - setStateActiveNoSwaps - setFeePercents - getLpTokenIdentifier - getTotalFeePercent - getSpecialFee - getRouterManagedAddress - getFirstTokenId - getSecondTokenId - getTotalSupply - getInitialLiquidtyAdder - getReserve - getSafePriceCurrentIndex - updateAndGetTokensForGivenPositionWithSafePrice - updateAndGetSafePrice - setLockingDeadlineEpoch - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getLockingDeadlineEpoch - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - getLpTokensSafePriceByDefaultOffset - getLpTokensSafePriceByRoundOffset - getLpTokensSafePriceByTimestampOffset - getLpTokensSafePrice - getSafePriceByDefaultOffset - getSafePriceByRoundOffset - getSafePriceByTimestampOffset - getSafePrice - getPriceObservation + init => init + addInitialLiquidity => add_initial_liquidity + addLiquidity => add_liquidity + removeLiquidity => remove_liquidity + removeLiquidityAndBuyBackAndBurnToken => remove_liquidity_and_burn_token + swapNoFeeAndForward => swap_no_fee + swapTokensFixedInput => swap_tokens_fixed_input + swapTokensFixedOutput => swap_tokens_fixed_output + setLpTokenIdentifier => set_lp_token_identifier + getTokensForGivenPosition => get_tokens_for_given_position + getReservesAndTotalSupply => get_reserves_and_total_supply + getAmountOut => get_amount_out_view + getAmountIn => get_amount_in_view + getEquivalent => get_equivalent + getFeeState => is_fee_enabled + whitelist => whitelist_endpoint + removeWhitelist => remove_whitelist + addTrustedSwapPair => add_trusted_swap_pair + removeTrustedSwapPair => remove_trusted_swap_pair + setupFeesCollector => setup_fees_collector + setFeeOn => set_fee_on + getFeeDestinations => get_fee_destinations + getTrustedSwapPairs => get_trusted_swap_pairs + getWhitelistedManagedAddresses => get_whitelisted_managed_addresses + getFeesCollectorAddress => fees_collector_address + getFeesCollectorCutPercentage => fees_collector_cut_percentage + setStateActiveNoSwaps => set_state_active_no_swaps + setFeePercents => set_fee_percent + getLpTokenIdentifier => get_lp_token_identifier + getTotalFeePercent => total_fee_percent + getSpecialFee => special_fee_percent + getRouterManagedAddress => router_address + getFirstTokenId => first_token_id + getSecondTokenId => second_token_id + getTotalSupply => lp_token_supply + getInitialLiquidtyAdder => initial_liquidity_adder + getReserve => pair_reserve + getSafePriceCurrentIndex => safe_price_current_index + updateAndGetTokensForGivenPositionWithSafePrice => update_and_get_tokens_for_given_position_with_safe_price + updateAndGetSafePrice => update_and_get_safe_price + setLockingDeadlineEpoch => set_locking_deadline_epoch + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getLockingDeadlineEpoch => locking_deadline_epoch + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + getLpTokensSafePriceByDefaultOffset => get_lp_tokens_safe_price_by_default_offset + getLpTokensSafePriceByRoundOffset => get_lp_tokens_safe_price_by_round_offset + getLpTokensSafePriceByTimestampOffset => get_lp_tokens_safe_price_by_timestamp_offset + getLpTokensSafePrice => get_lp_tokens_safe_price + getSafePriceByDefaultOffset => get_safe_price_by_default_offset + getSafePriceByRoundOffset => get_safe_price_by_round_offset + getSafePriceByTimestampOffset => get_safe_price_by_timestamp_offset + getSafePrice => get_safe_price + getPriceObservation => get_price_observation_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair/wasm-safe-price-view/Cargo.lock b/dex/pair/wasm-safe-price-view/Cargo.lock index c8995accb..805ded42d 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/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" @@ -168,12 +162,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +178,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" @@ -205,9 +187,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", @@ -219,20 +201,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", @@ -242,9 +223,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", @@ -255,21 +236,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]] @@ -330,9 +310,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -436,18 +416,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" @@ -467,25 +435,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/dex/pair/wasm-safe-price-view/src/lib.rs b/dex/pair/wasm-safe-price-view/src/lib.rs index a41f72fd1..c5f78382f 100644 --- a/dex/pair/wasm-safe-price-view/src/lib.rs +++ b/dex/pair/wasm-safe-price-view/src/lib.rs @@ -10,24 +10,29 @@ // Total number of exported functions: 11 #![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!(); +multiversx_sc_wasm_adapter::external_view_init! {} + multiversx_sc_wasm_adapter::external_view_endpoints! { pair ( - getLpTokensSafePriceByDefaultOffset - getLpTokensSafePriceByRoundOffset - getLpTokensSafePriceByTimestampOffset - getLpTokensSafePrice - getSafePriceByDefaultOffset - getSafePriceByRoundOffset - getSafePriceByTimestampOffset - getSafePrice - getPriceObservation + getLpTokensSafePriceByDefaultOffset => get_lp_tokens_safe_price_by_default_offset + getLpTokensSafePriceByRoundOffset => get_lp_tokens_safe_price_by_round_offset + getLpTokensSafePriceByTimestampOffset => get_lp_tokens_safe_price_by_timestamp_offset + getLpTokensSafePrice => get_lp_tokens_safe_price + getSafePriceByDefaultOffset => get_safe_price_by_default_offset + getSafePriceByRoundOffset => get_safe_price_by_round_offset + getSafePriceByTimestampOffset => get_safe_price_by_timestamp_offset + getSafePrice => get_safe_price + getPriceObservation => get_price_observation_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair/wasm/Cargo.lock b/dex/pair/wasm/Cargo.lock index a2f6f1a44..e53ad1a13 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/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" @@ -168,12 +162,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" @@ -190,12 +178,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" @@ -205,9 +187,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", @@ -219,20 +201,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", @@ -242,9 +223,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", @@ -255,21 +236,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]] @@ -338,9 +318,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", ] @@ -436,18 +416,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" @@ -467,25 +435,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/dex/pair/wasm/src/lib.rs b/dex/pair/wasm/src/lib.rs index d692b1d2b..9f65c8a35 100644 --- a/dex/pair/wasm/src/lib.rs +++ b/dex/pair/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 56 #![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,61 +21,62 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pair ( - addInitialLiquidity - addLiquidity - removeLiquidity - removeLiquidityAndBuyBackAndBurnToken - swapNoFeeAndForward - swapTokensFixedInput - swapTokensFixedOutput - setLpTokenIdentifier - getTokensForGivenPosition - getReservesAndTotalSupply - getAmountOut - getAmountIn - getEquivalent - getFeeState - whitelist - removeWhitelist - addTrustedSwapPair - removeTrustedSwapPair - setupFeesCollector - setFeeOn - getFeeDestinations - getTrustedSwapPairs - getWhitelistedManagedAddresses - getFeesCollectorAddress - getFeesCollectorCutPercentage - setStateActiveNoSwaps - setFeePercents - getLpTokenIdentifier - getTotalFeePercent - getSpecialFee - getRouterManagedAddress - getFirstTokenId - getSecondTokenId - getTotalSupply - getInitialLiquidtyAdder - getReserve - getSafePriceCurrentIndex - updateAndGetTokensForGivenPositionWithSafePrice - updateAndGetSafePrice - setLockingDeadlineEpoch - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getLockingDeadlineEpoch - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState + init => init + addInitialLiquidity => add_initial_liquidity + addLiquidity => add_liquidity + removeLiquidity => remove_liquidity + removeLiquidityAndBuyBackAndBurnToken => remove_liquidity_and_burn_token + swapNoFeeAndForward => swap_no_fee + swapTokensFixedInput => swap_tokens_fixed_input + swapTokensFixedOutput => swap_tokens_fixed_output + setLpTokenIdentifier => set_lp_token_identifier + getTokensForGivenPosition => get_tokens_for_given_position + getReservesAndTotalSupply => get_reserves_and_total_supply + getAmountOut => get_amount_out_view + getAmountIn => get_amount_in_view + getEquivalent => get_equivalent + getFeeState => is_fee_enabled + whitelist => whitelist_endpoint + removeWhitelist => remove_whitelist + addTrustedSwapPair => add_trusted_swap_pair + removeTrustedSwapPair => remove_trusted_swap_pair + setupFeesCollector => setup_fees_collector + setFeeOn => set_fee_on + getFeeDestinations => get_fee_destinations + getTrustedSwapPairs => get_trusted_swap_pairs + getWhitelistedManagedAddresses => get_whitelisted_managed_addresses + getFeesCollectorAddress => fees_collector_address + getFeesCollectorCutPercentage => fees_collector_cut_percentage + setStateActiveNoSwaps => set_state_active_no_swaps + setFeePercents => set_fee_percent + getLpTokenIdentifier => get_lp_token_identifier + getTotalFeePercent => total_fee_percent + getSpecialFee => special_fee_percent + getRouterManagedAddress => router_address + getFirstTokenId => first_token_id + getSecondTokenId => second_token_id + getTotalSupply => lp_token_supply + getInitialLiquidtyAdder => initial_liquidity_adder + getReserve => pair_reserve + getSafePriceCurrentIndex => safe_price_current_index + updateAndGetTokensForGivenPositionWithSafePrice => update_and_get_tokens_for_given_position_with_safe_price + updateAndGetSafePrice => update_and_get_safe_price + setLockingDeadlineEpoch => set_locking_deadline_epoch + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getLockingDeadlineEpoch => locking_deadline_epoch + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index 7e6dc4c5b..58f80eb2d 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/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" @@ -120,12 +114,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" @@ -142,12 +130,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" @@ -157,9 +139,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", @@ -171,20 +153,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", @@ -194,9 +175,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", @@ -207,21 +188,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]] @@ -268,9 +248,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", ] @@ -356,37 +336,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/dex/price-discovery/wasm/src/lib.rs b/dex/price-discovery/wasm/src/lib.rs index 7c227533c..0a3ed110d 100644 --- a/dex/price-discovery/wasm/src/lib.rs +++ b/dex/price-discovery/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 29 #![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,33 +21,35 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { price_discovery ( - deposit - withdraw - redeem - getCurrentPrice - getMinLaunchedTokenPrice - getPricePrecision - getLaunchedTokenId - getAcceptedTokenId - getLaunchedTokenBalance - getAcceptedTokenBalance - getStartBlock - getEndBlock - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getCurrentPhase - getNoLimitPhaseDurationBlocks - getLinearPenaltyPhaseDurationBlocks - getFixedPenaltyPhaseDurationBlocks - getPenaltyMinPercentage - getPenaltyMaxPercentage - getFixedPenaltyPercentage - issueRedeemToken - createInitialRedeemTokens - getRedeemTokenId - getRedeemTokenTotalCirculatingSupply - callBack + init => init + deposit => deposit + withdraw => withdraw + redeem => redeem + getCurrentPrice => calculate_price + getMinLaunchedTokenPrice => min_launched_token_price + getPricePrecision => price_precision + getLaunchedTokenId => launched_token_id + getAcceptedTokenId => accepted_token_id + getLaunchedTokenBalance => launched_token_balance + getAcceptedTokenBalance => accepted_token_balance + getStartBlock => start_block + getEndBlock => end_block + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getCurrentPhase => get_current_phase + getNoLimitPhaseDurationBlocks => no_limit_phase_duration_blocks + getLinearPenaltyPhaseDurationBlocks => linear_penalty_phase_duration_blocks + getFixedPenaltyPhaseDurationBlocks => fixed_penalty_phase_duration_blocks + getPenaltyMinPercentage => penalty_min_percentage + getPenaltyMaxPercentage => penalty_max_percentage + getFixedPenaltyPercentage => fixed_penalty_percentage + issueRedeemToken => issue_redeem_token + createInitialRedeemTokens => create_initial_redeem_tokens + getRedeemTokenId => redeem_token + getRedeemTokenTotalCirculatingSupply => redeem_token_total_circulating_supply ) } + +multiversx_sc_wasm_adapter::async_callback! { price_discovery } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 3d762a9be..f632f6425 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/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" @@ -284,12 +278,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" @@ -306,12 +294,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" @@ -321,9 +303,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", @@ -335,20 +317,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", @@ -358,9 +339,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", @@ -371,21 +352,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]] @@ -446,9 +426,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", ] @@ -586,18 +566,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" @@ -617,25 +585,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/dex/proxy-deployer/wasm/src/lib.rs b/dex/proxy-deployer/wasm/src/lib.rs index bdf618263..b8d5311f2 100644 --- a/dex/proxy-deployer/wasm/src/lib.rs +++ b/dex/proxy-deployer/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 6 #![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,11 +21,12 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { proxy_deployer ( - deployFarm - callFarmEndpoint - getAllDeployedFarms - getDeployerFarmAddresses + init => init + deployFarm => deploy_farm + callFarmEndpoint => call_farm_endpoint + getAllDeployedFarms => get_all_deployed_farms + getDeployerFarmAddresses => deployer_farm_addresses ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/router/wasm/Cargo.lock b/dex/router/wasm/Cargo.lock index 6746dd43d..610c44b89 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/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" @@ -168,12 +162,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" @@ -190,12 +178,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" @@ -205,9 +187,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", @@ -219,20 +201,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", @@ -242,9 +223,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", @@ -255,21 +236,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]] @@ -330,9 +310,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", ] @@ -448,18 +428,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" @@ -479,25 +447,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/dex/router/wasm/src/lib.rs b/dex/router/wasm/src/lib.rs index 28609e0ab..a33c1a146 100644 --- a/dex/router/wasm/src/lib.rs +++ b/dex/router/wasm/src/lib.rs @@ -5,12 +5,15 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 30 +// Endpoints: 31 // Async Callback: 1 -// Total number of exported functions: 32 +// Total number of exported functions: 33 #![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,36 +21,39 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { router ( - pause - resume - createPair - upgradePair - issueLpToken - setLocalRoles - setLocalRolesOwner - removePair - setFeeOn - setFeeOff - setPairCreationEnabled - getPairCreationEnabled - getState - getOwner - getAllPairsManagedAddresses - getAllPairTokens - getAllPairContractMetadata - getPair - clearPairTemporaryOwnerStorage - setTemporaryOwnerPeriod - setPairTemplateAddress - getPairTemplateAddress - getTemporaryOwnerPeriod - multiPairSwap - configEnableByUserParameters - addCommonTokensForUserPairs - removeCommonTokensForUserPairs - setSwapEnabledByUser - getEnableSwapByUserConfig - getCommonTokensForUserPairs - callBack + init => init + pause => pause + resume => resume + createPair => create_pair_endpoint + upgradePair => upgrade_pair_endpoint + issueLpToken => issue_lp_token + setLocalRoles => set_local_roles + setLocalRolesOwner => set_local_roles_owner + removePair => remove_pair + setFeeOn => set_fee_on + setFeeOff => set_fee_off + setPairCreationEnabled => set_pair_creation_enabled + migratePairMap => migrate_pair_map + getPairCreationEnabled => pair_creation_enabled + getState => state + getOwner => owner + getAllPairsManagedAddresses => get_all_pairs_addresses + getAllPairTokens => get_all_token_pairs + getAllPairContractMetadata => get_all_pair_contract_metadata + getPair => get_pair + clearPairTemporaryOwnerStorage => clear_pair_temporary_owner_storage + setTemporaryOwnerPeriod => set_temporary_owner_period + setPairTemplateAddress => set_pair_template_address + getPairTemplateAddress => pair_template_address + getTemporaryOwnerPeriod => temporary_owner_period + multiPairSwap => multi_pair_swap + configEnableByUserParameters => config_enable_by_user_parameters + addCommonTokensForUserPairs => add_common_tokens_for_user_pairs + removeCommonTokensForUserPairs => remove_common_tokens_for_user_pairs + setSwapEnabledByUser => set_swap_enabled_by_user + getEnableSwapByUserConfig => try_get_config + getCommonTokensForUserPairs => common_tokens_for_user_pairs ) } + +multiversx_sc_wasm_adapter::async_callback! { router } diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 1b1924b82..1c8ed2d30 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/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" @@ -144,12 +138,6 @@ dependencies = [ "utils", ] -[[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" @@ -157,12 +145,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" @@ -172,9 +154,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", @@ -186,20 +168,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", @@ -209,9 +190,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", @@ -222,21 +203,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]] @@ -265,9 +245,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", ] @@ -353,37 +333,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/energy-integration/energy-factory-mock/wasm/src/lib.rs b/energy-integration/energy-factory-mock/wasm/src/lib.rs index bfa562d58..89a4cb257 100644 --- a/energy-integration/energy-factory-mock/wasm/src/lib.rs +++ b/energy-integration/energy-factory-mock/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 6 #![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,11 +21,12 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_factory_mock ( - setUserEnergy - getEnergyAmountForUser - getEnergyEntryForUser - setUserEnergyAfterLockedTokenTransfer + init => init + setUserEnergy => set_user_energy + getEnergyAmountForUser => get_energy_amount_for_user + getEnergyEntryForUser => get_energy_entry_for_user + setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 5173db1ce..d178e0eef 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/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" @@ -302,12 +296,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" @@ -324,12 +312,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" @@ -339,9 +321,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", @@ -353,20 +335,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", @@ -376,9 +357,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", @@ -389,21 +370,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]] @@ -464,9 +444,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", ] @@ -585,18 +565,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" @@ -616,25 +584,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/energy-integration/energy-update/wasm/src/lib.rs b/energy-integration/energy-update/wasm/src/lib.rs index 9ddd60e4c..18eb3df45 100644 --- a/energy-integration/energy-update/wasm/src/lib.rs +++ b/energy-integration/energy-update/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 3 #![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,8 +21,9 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_update ( - updateFarmsEnergyForUser + init => init + updateFarmsEnergyForUser => update_farms_energy_for_user ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/energy-integration/governance-v2/wasm/Cargo.lock b/energy-integration/governance-v2/wasm/Cargo.lock index 40bcf7baa..7c57cce9a 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/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" @@ -172,12 +166,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" @@ -194,12 +182,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" @@ -209,9 +191,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", @@ -223,20 +205,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", @@ -246,9 +227,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", @@ -259,21 +240,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]] @@ -311,9 +291,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", ] @@ -400,18 +380,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" @@ -431,25 +399,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/energy-integration/governance-v2/wasm/src/lib.rs b/energy-integration/governance-v2/wasm/src/lib.rs index 6c2f6e7e2..bcf9529fb 100644 --- a/energy-integration/governance-v2/wasm/src/lib.rs +++ b/energy-integration/governance-v2/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 29 #![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,34 +21,35 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { governance_v2 ( - propose - vote - cancel - withdrawDeposit - changeMinEnergyForProposal - changeMinFeeForProposal - changeQuorumPercentage - changeVotingDelayInBlocks - changeVotingPeriodInBlocks - getMinEnergyForPropose - getMinFeeForPropose - getQuorum - getVotingDelayInBlocks - getVotingPeriodInBlocks - getFeeTokenId - getWithdrawPercentageDefeated - getProposals - getUserVotedProposals - getProposalVotes - getProposalStatus - getFeesCollectorAddress - setEnergyFactoryAddress - getEnergyFactoryAddress - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions + init => init + propose => propose + vote => vote + cancel => cancel + withdrawDeposit => withdraw_deposit + changeMinEnergyForProposal => change_min_energy_for_propose + changeMinFeeForProposal => change_min_fee_for_propose + changeQuorumPercentage => change_quorum_percentage + changeVotingDelayInBlocks => change_voting_delay_in_blocks + changeVotingPeriodInBlocks => change_voting_period_in_blocks + getMinEnergyForPropose => min_energy_for_propose + getMinFeeForPropose => min_fee_for_propose + getQuorum => quorum_percentage + getVotingDelayInBlocks => voting_delay_in_blocks + getVotingPeriodInBlocks => voting_period_in_blocks + getFeeTokenId => fee_token_id + getWithdrawPercentageDefeated => withdraw_percentage_defeated + getProposals => proposals + getUserVotedProposals => user_voted_proposals + getProposalVotes => proposal_votes + getProposalStatus => get_proposal_status + getFeesCollectorAddress => fees_collector_address + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/farm-staking/metabonding-staking/wasm/Cargo.lock b/farm-staking/metabonding-staking/wasm/Cargo.lock index dbb5e6cc5..9661f1ca4 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.lock +++ b/farm-staking/metabonding-staking/wasm/Cargo.lock @@ -196,9 +196,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", @@ -210,20 +210,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", @@ -233,9 +232,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", @@ -246,21 +245,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]] @@ -289,9 +287,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", ] diff --git a/farm-staking/metabonding-staking/wasm/src/lib.rs b/farm-staking/metabonding-staking/wasm/src/lib.rs index 337c0ea4b..ce110b30f 100644 --- a/farm-staking/metabonding-staking/wasm/src/lib.rs +++ b/farm-staking/metabonding-staking/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 12 #![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,17 +21,18 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { metabonding_staking ( - stakeLockedAsset - unstake - unbond - getStakedAmountForUser - getUserEntry - getSnapshot - getLockedAssetTokenId - getLockedAssetFactoryAddress - getTotalLockedAssetSupply - getUserList + init => init + stakeLockedAsset => stake_locked_asset + unstake => unstake + unbond => unbond + getStakedAmountForUser => get_staked_amount_for_user + getUserEntry => get_user_entry + getSnapshot => get_snapshot + getLockedAssetTokenId => locked_asset_token_id + getLockedAssetFactoryAddress => locked_asset_factory_address + getTotalLockedAssetSupply => total_locked_asset_supply + getUserList => user_list ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/distribution/wasm/Cargo.lock b/locked-asset/distribution/wasm/Cargo.lock index e1cc0fc9e..1575c3ab3 100644 --- a/locked-asset/distribution/wasm/Cargo.lock +++ b/locked-asset/distribution/wasm/Cargo.lock @@ -196,9 +196,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", @@ -210,20 +210,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", @@ -233,9 +232,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", @@ -246,21 +245,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]] @@ -289,9 +287,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", ] diff --git a/locked-asset/distribution/wasm/src/lib.rs b/locked-asset/distribution/wasm/src/lib.rs index 829e87945..7713b182b 100644 --- a/locked-asset/distribution/wasm/src/lib.rs +++ b/locked-asset/distribution/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 17 #![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,22 +21,23 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { distribution ( - setCommunityDistribution - setPerUserDistributedLockedAssets - claimLockedAssets - clearUnclaimableAssets - undoLastCommunityDistribution - undoUserDistributedAssetsBetweenEpochs - setUnlockPeriod - calculateLockedAssets - deleteUserDistributedLockedAssets - getUsersDistributedLockedAssetsLength - getUnlockPeriod - getCommunityDistributionList - getAssetTokenId - startGlobalOperation - endGlobalOperation + init => init + setCommunityDistribution => set_community_distribution + setPerUserDistributedLockedAssets => set_per_user_distributed_locked_assets + claimLockedAssets => claim_locked_assets + clearUnclaimableAssets => clear_unclaimable_assets + undoLastCommunityDistribution => undo_last_community_distrib + undoUserDistributedAssetsBetweenEpochs => undo_user_assets_between_epochs + setUnlockPeriod => set_unlock_period + calculateLockedAssets => calculate_locked_assets_view + deleteUserDistributedLockedAssets => delete_user_distributed_locked_assets + getUsersDistributedLockedAssetsLength => get_users_distributed_locked_assets_length + getUnlockPeriod => unlock_period + getCommunityDistributionList => community_distribution_list + getAssetTokenId => asset_token_id + startGlobalOperation => global_op_start + endGlobalOperation => global_op_stop ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index 4ce7c14d7..6f19aab26 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/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" @@ -128,12 +122,6 @@ dependencies = [ "utils", ] -[[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" @@ -141,12 +129,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" @@ -156,9 +138,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", @@ -170,20 +152,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", @@ -193,9 +174,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", @@ -206,21 +187,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]] @@ -249,9 +229,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", ] @@ -337,37 +317,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/energy-factory/wasm/src/lib.rs b/locked-asset/energy-factory/wasm/src/lib.rs index d496bd0d2..213c94146 100644 --- a/locked-asset/energy-factory/wasm/src/lib.rs +++ b/locked-asset/energy-factory/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 34 #![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,38 +21,40 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_factory ( - lockTokens - unlockTokens - issueLockedToken - getLockedTokenId - getBaseAssetTokenId - getLegacyLockedTokenId - getEnergyEntryForUser - getEnergyAmountForUser - addLockOptions - getLockOptions - unlockEarly - reduceLockPeriod - getPenaltyAmount - setTokenUnstakeAddress - revertUnstake - getTokenUnstakeScAddress - setEnergyForOldTokens - updateEnergyAfterOldTokenUnlock - migrateOldTokens - pause - unpause - isPaused - setTransferRoleLockedToken - setBurnRoleLockedToken - mergeTokens - lockVirtual - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - addToTokenTransferWhitelist - removeFromTokenTransferWhitelist - setUserEnergyAfterLockedTokenTransfer - callBack + init => init + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + issueLockedToken => issue_locked_token + getLockedTokenId => locked_token + getBaseAssetTokenId => base_asset_token_id + getLegacyLockedTokenId => legacy_locked_token_id + getEnergyEntryForUser => get_updated_energy_entry_for_user + getEnergyAmountForUser => get_energy_amount_for_user + addLockOptions => add_lock_options + getLockOptions => get_lock_options_view + unlockEarly => unlock_early + reduceLockPeriod => reduce_lock_period + getPenaltyAmount => calculate_penalty_amount + setTokenUnstakeAddress => set_token_unstake_address + revertUnstake => revert_unstake + getTokenUnstakeScAddress => token_unstake_sc_address + setEnergyForOldTokens => set_energy_for_old_tokens + updateEnergyAfterOldTokenUnlock => update_energy_after_old_token_unlock + migrateOldTokens => migrate_old_tokens + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status + setTransferRoleLockedToken => set_transfer_role + setBurnRoleLockedToken => set_burn_role + mergeTokens => merge_tokens_endpoint + lockVirtual => lock_virtual + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + addToTokenTransferWhitelist => add_to_token_transfer_whitelist + removeFromTokenTransferWhitelist => remove_from_token_transfer_whitelist + setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer ) } + +multiversx_sc_wasm_adapter::async_callback! { energy_factory } diff --git a/locked-asset/factory/wasm/Cargo.lock b/locked-asset/factory/wasm/Cargo.lock index ca5df67df..2e3b4d55a 100644 --- a/locked-asset/factory/wasm/Cargo.lock +++ b/locked-asset/factory/wasm/Cargo.lock @@ -187,9 +187,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", @@ -201,20 +201,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", @@ -224,9 +223,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", @@ -237,21 +236,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]] @@ -280,9 +278,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", ] diff --git a/locked-asset/factory/wasm/src/lib.rs b/locked-asset/factory/wasm/src/lib.rs index e5250b664..3593ccb49 100644 --- a/locked-asset/factory/wasm/src/lib.rs +++ b/locked-asset/factory/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 26 #![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,30 +21,32 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { factory ( - whitelist - removeWhitelist - createAndForwardCustomPeriod - createAndForward - unlockAssets - lockAssets - setUnlockPeriod - registerLockedAssetToken - setInitEpoch - getInitEpoch - getWhitelistedContracts - getDefaultUnlockPeriod - getLockedAssetTokenId - getAssetTokenId - getUnlockScheduleForSFTNonce - getCacheSize - mergeTokens - getExtendedAttributesActivationNonce - setLockedTokenBurnRoleForAddress - setTransferRoleOldLockedToken - setNewFactoryAddress - pause - unpause - isPaused - callBack + init => init + whitelist => whitelist + removeWhitelist => remove_whitelist + createAndForwardCustomPeriod => create_and_forward_custom_period + createAndForward => create_and_forward + unlockAssets => unlock_assets + lockAssets => lock_assets + setUnlockPeriod => set_unlock_period + registerLockedAssetToken => register_locked_asset_token + setInitEpoch => set_init_epoch + getInitEpoch => init_epoch + getWhitelistedContracts => whitelisted_contracts + getDefaultUnlockPeriod => default_unlock_period + getLockedAssetTokenId => locked_asset_token + getAssetTokenId => asset_token_id + getUnlockScheduleForSFTNonce => get_unlock_schedule_for_sft_nonce + getCacheSize => get_cache_size + mergeTokens => merge_tokens + getExtendedAttributesActivationNonce => extended_attributes_activation_nonce + setLockedTokenBurnRoleForAddress => set_locked_token_burn_role_for_address + setTransferRoleOldLockedToken => set_transfer_role_old_locked_token + setNewFactoryAddress => set_new_factory_address + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status ) } + +multiversx_sc_wasm_adapter::async_callback! { factory } diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index 0956bbfca..817559577 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/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" @@ -128,12 +122,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "lkmex-transfer" version = "0.0.0" @@ -163,12 +151,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" @@ -178,9 +160,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", @@ -192,20 +174,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", @@ -215,9 +196,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", @@ -228,21 +209,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]] @@ -280,9 +260,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", ] @@ -368,37 +348,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/lkmex-transfer/wasm/src/lib.rs b/locked-asset/lkmex-transfer/wasm/src/lib.rs index 5b48ab16b..88d45c5f9 100644 --- a/locked-asset/lkmex-transfer/wasm/src/lib.rs +++ b/locked-asset/lkmex-transfer/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 13 #![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,18 +21,19 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { lkmex_transfer ( - withdraw - cancelTransfer - lockFunds - getScheduledTransfers - getAllSenders - setEnergyFactoryAddress - getEnergyFactoryAddress - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions + init => init + withdraw => withdraw + cancelTransfer => cancel_transfer + lockFunds => lock_funds + getScheduledTransfers => get_scheduled_transfers + getAllSenders => all_senders + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.lock b/locked-asset/locked-token-wrapper/wasm/Cargo.lock index 389a26cc8..37781138a 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/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" @@ -136,12 +130,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "lkmex-transfer" version = "0.0.0" @@ -187,12 +175,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" @@ -202,9 +184,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", @@ -216,20 +198,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", @@ -239,9 +220,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", @@ -252,21 +233,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]] @@ -304,9 +284,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", ] @@ -392,37 +372,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/locked-token-wrapper/wasm/src/lib.rs b/locked-asset/locked-token-wrapper/wasm/src/lib.rs index efae1ed5e..dd7c8fd96 100644 --- a/locked-asset/locked-token-wrapper/wasm/src/lib.rs +++ b/locked-asset/locked-token-wrapper/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 10 #![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,14 +21,16 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { locked_token_wrapper ( - wrapLockedToken - unwrapLockedToken - issueWrappedToken - setTransferRoleWrappedToken - unsetTransferRoleWrappedToken - getWrappedTokenId - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + wrapLockedToken => wrap_locked_token_endpoint + unwrapLockedToken => unwrap_locked_token_endpoint + issueWrappedToken => issue_wrapped_token + setTransferRoleWrappedToken => set_transfer_role + unsetTransferRoleWrappedToken => unset_transfer_role + getWrappedTokenId => wrapped_token + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { locked_token_wrapper } diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock b/locked-asset/simple-lock-whitelist/wasm/Cargo.lock index 678cb0db6..fcf6f4e9a 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock +++ b/locked-asset/simple-lock-whitelist/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", ] @@ -307,37 +287,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-whitelist/wasm/src/lib.rs b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs index 2d42f0f2c..8d60bed84 100644 --- a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs +++ b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 26 #![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,30 +21,32 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { simple_lock_whitelist ( - setTransferRoleLockedToken - setTransferRoleProxyLpToken - setTransferRoleProxyFarmToken - setLockedToken - lockTokens - unlockTokens - getTokenWhitelist - issueLockedToken - getLockedTokenId - issueLpProxyToken - addLpToWhitelist - removeLpFromWhitelist - addLiquidityLockedToken - removeLiquidityLockedToken - getKnownLiquidityPools - getLpProxyTokenId - issueFarmProxyToken - addFarmToWhitelist - removeFarmFromWhitelist - enterFarmLockedToken - exitFarmLockedToken - farmClaimRewardsLockedToken - getKnownFarms - getFarmProxyTokenId - callBack + init => init + setTransferRoleLockedToken => set_transfer_role + setTransferRoleProxyLpToken => set_transfer_role_proxy_lp + setTransferRoleProxyFarmToken => set_transfer_role_proxy_farm + setLockedToken => set_locked_token + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + getTokenWhitelist => token_whitelist + 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_whitelist } diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index 4a78e1d16..45ca8458f 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/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" @@ -135,12 +129,6 @@ dependencies = [ "utils", ] -[[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" @@ -148,12 +136,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" @@ -163,9 +145,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", @@ -177,20 +159,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", @@ -200,9 +181,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", @@ -213,21 +194,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]] @@ -256,9 +236,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", ] @@ -367,18 +347,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" @@ -386,25 +354,3 @@ dependencies = [ "common-types", "multiversx-sc", ] - -[[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/token-unstake/wasm/src/lib.rs b/locked-asset/token-unstake/wasm/src/lib.rs index e0ac873af..f2f371c21 100644 --- a/locked-asset/token-unstake/wasm/src/lib.rs +++ b/locked-asset/token-unstake/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 12 #![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,17 +21,18 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { token_unstake ( - getUnbondEpochs - getUnlockedTokensForUser - claimUnlockedTokens - cancelUnbond - depositUserTokens - depositFees - getFeesBurnPercentage - getFeesCollectorAddress - setEnergyFactoryAddress - getEnergyFactoryAddress + init => init + getUnbondEpochs => unbond_epochs + getUnlockedTokensForUser => unlocked_tokens_for_user + claimUnlockedTokens => claim_unlocked_tokens + cancelUnbond => cancel_unbond + depositUserTokens => deposit_user_tokens + depositFees => deposit_fees + getFeesBurnPercentage => fees_burn_percentage + getFeesCollectorAddress => fees_collector_address + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/pause-all/wasm/Cargo.lock b/pause-all/wasm/Cargo.lock index 8dfdb7105..af898789c 100644 --- a/pause-all/wasm/Cargo.lock +++ b/pause-all/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" @@ -77,23 +71,11 @@ 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 = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[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", @@ -105,20 +87,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", @@ -128,9 +109,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", @@ -141,21 +122,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]] @@ -218,9 +198,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", ] @@ -272,37 +252,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/pause-all/wasm/src/lib.rs b/pause-all/wasm/src/lib.rs index 6177d8585..d92fcfc45 100644 --- a/pause-all/wasm/src/lib.rs +++ b/pause-all/wasm/src/lib.rs @@ -10,7 +10,10 @@ // Total number of exported functions: 9 #![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,14 +21,15 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pause_all ( - addPausableContracts - removePausableContracts - pauseSelected - pauseAll - resumeSelected - resumeAll - getPausableContracts + init => init + addPausableContracts => add_pausable_contracts + removePausableContracts => remove_pausable_contracts + pauseSelected => pause_selected + pauseAll => pause_all + resumeSelected => resume_selected + resumeAll => resume_all + getPausableContracts => pausable_contracts ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} From d1a9e72347da846125e3ec3517a8f4a1fe0044a5 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 11:08:38 +0300 Subject: [PATCH 55/58] github actions update --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f6acbaa50..c5fdba201 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -4,6 +4,7 @@ on: push: branches: [ main, feat/* ] pull_request: + branches: [ main, feat/* ] workflow_dispatch: permissions: From 2e3652481ff6ddda269bcf22c7bcfda3361a84be Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 12:26:25 +0300 Subject: [PATCH 56/58] clippy fix --- dex/farm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 5a18d41e3..74456ad5c 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -119,7 +119,7 @@ pub trait Farm: self.migrate_old_farm_positions(&orig_caller); - let claim_rewards_result = self.claim_rewards::>(orig_caller.clone()); + let claim_rewards_result = self.claim_rewards::>(orig_caller); self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); self.send_payment_non_zero(&caller, &claim_rewards_result.rewards); From 67a7d4277d5a6d25534f3a2882b7d88593a2554e Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 12:39:15 +0300 Subject: [PATCH 57/58] cargo lock fix --- dex/farm-with-locked-rewards/wasm/Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index ac4fd1333..17a37e607 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -392,7 +392,6 @@ dependencies = [ name = "multiversx-sc-modules" version = "0.43.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b55fe3585cbc745bd7b9793be4bcb3aa7f1869ced7a0981f3d47e6a832c6311" checksum = "e5c160745bf0c997146fa816a19fba8a8d0517e99ed30cc514eca0967f2eed74" dependencies = [ "multiversx-sc", From 4dc02033c33d2ed89ab0ccc4b7529b976467979e Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Fri, 29 Sep 2023 12:56:08 +0300 Subject: [PATCH 58/58] farm with lock rewards cargo lock fix --- dex/farm-with-locked-rewards/wasm/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 17a37e607..102fabc1d 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -379,7 +379,7 @@ dependencies = [ name = "multiversx-sc-derive" version = "0.43.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "050510b6b9836b24b4a73bb7878c58c268d56bde1c6eb0f9a88dce9a6518507b" +checksum = "23fead13b29d79f702e021926402588e9a7822ed9dfadfdfe71c436dce100e4f" dependencies = [ "hex", "proc-macro2", @@ -401,7 +401,7 @@ dependencies = [ name = "multiversx-sc-wasm-adapter" version = "0.43.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b059f22dfc3eb45aa015f6f20f28ed34dc42a65b42d282f8ac9b799b12e2942c" +checksum = "9f6fce7b968fec7ea27f6fef909d4149e515e31aa2486a93dcd7c72a8a01e571" dependencies = [ "multiversx-sc", ]