From 26607bd71aec9303891c3a65b2e0be53bd2bfaf4 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 7 Dec 2023 16:22:35 +0200 Subject: [PATCH 1/2] Add claimBoostedRewards endpoint in Fees Collector --- energy-integration/fees-collector/src/lib.rs | 29 ++++++++++++++++--- .../tests/fees_collector_test_setup/mod.rs | 4 +-- .../fees-collector/wasm/src/lib.rs | 7 +++-- .../governance-v2/tests/gov_test_setup/mod.rs | 6 ++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/energy-integration/fees-collector/src/lib.rs b/energy-integration/fees-collector/src/lib.rs index cf1d8b6c8..b5a37d7fb 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -48,13 +48,24 @@ pub trait FeesCollector: fn upgrade(&self) {} #[endpoint(claimRewards)] - fn claim_rewards( + fn claim_rewards_endpoint( &self, opt_original_caller: OptionalValue, ) -> PaymentsVec { require!(self.not_paused(), "Cannot claim while paused"); - self.accumulate_additional_locked_tokens(); + let caller = self.blockchain().get_caller(); + let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + + self.claim_rewards(caller, original_caller) + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_original_caller: OptionalValue, + ) -> PaymentsVec { + require!(self.not_paused(), "Cannot claim while paused"); let original_caller = match opt_original_caller { OptionalValue::Some(user) => { @@ -67,6 +78,16 @@ pub trait FeesCollector: OptionalValue::None => self.blockchain().get_caller(), }; + self.claim_rewards(original_caller.clone(), original_caller) + } + + fn claim_rewards( + &self, + caller: ManagedAddress, + original_caller: ManagedAddress, + ) -> PaymentsVec { + self.accumulate_additional_locked_tokens(); + let wrapper = FeesCollectorWrapper::new(); let mut rewards = self.claim_multi(&wrapper, &original_caller); if rewards.is_empty() { @@ -90,14 +111,14 @@ pub trait FeesCollector: } if !rewards.is_empty() { - self.send().direct_multi(&original_caller, &rewards); + self.send().direct_multi(&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, - original_caller.clone(), + caller, original_caller, ); 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 2809ac297..359c4eeb5 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 @@ -225,14 +225,14 @@ where pub fn claim(&mut self, user: &Address) -> TxResult { self.b_mock .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { - let _ = sc.claim_rewards(OptionalValue::None); + let _ = sc.claim_rewards_endpoint(OptionalValue::None); }) } 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))); + let _ = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); }) } diff --git a/energy-integration/fees-collector/wasm/src/lib.rs b/energy-integration/fees-collector/wasm/src/lib.rs index b0f3b7178..f8d4ac038 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: 38 +// Endpoints: 39 // Async Callback (empty): 1 -// Total number of exported functions: 40 +// Total number of exported functions: 41 #![no_std] @@ -23,7 +23,8 @@ multiversx_sc_wasm_adapter::endpoints! { ( init => init upgrade => upgrade - claimRewards => claim_rewards + claimRewards => claim_rewards_endpoint + claimBoostedRewards => claim_boosted_rewards addKnownContracts => add_known_contracts removeKnownContracts => remove_known_contracts addKnownTokens => add_known_tokens diff --git a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs index 520b5b0b4..8c5cc9242 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -121,7 +121,7 @@ where &fees_collector_wrapper, &rust_biguint!(0), |sc| { - sc.claim_rewards(OptionalValue::None); + sc.claim_rewards_endpoint(OptionalValue::None); }, ) .assert_ok(); @@ -132,7 +132,7 @@ where &fees_collector_wrapper, &rust_biguint!(0), |sc| { - sc.claim_rewards(OptionalValue::None); + sc.claim_rewards_endpoint(OptionalValue::None); }, ) .assert_ok(); @@ -143,7 +143,7 @@ where &fees_collector_wrapper, &rust_biguint!(0), |sc| { - sc.claim_rewards(OptionalValue::None); + sc.claim_rewards_endpoint(OptionalValue::None); }, ) .assert_ok(); From 56a8e770400a589c85cae86c9998990ea14ff1b4 Mon Sep 17 00:00:00 2001 From: Sorin Petreasca Date: Thu, 14 Dec 2023 16:01:00 +0200 Subject: [PATCH 2/2] add getAllowExternalClaimRewards view in farms --- common/modules/farm/config/src/config.rs | 6 ++++++ dex/farm-with-locked-rewards/wasm/src/lib.rs | 5 +++-- dex/farm/wasm/src/lib.rs | 5 +++-- farm-staking/farm-staking/wasm/src/lib.rs | 5 +++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index e65056062..b712765e5 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -45,6 +45,12 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio .set(user_total_farm_position); } + #[view(getAllowExternalClaimRewards)] + fn get_allow_external_claim_rewards(&self, user: ManagedAddress) -> bool { + let user_total_farm_position = self.get_user_total_farm_position(&user); + user_total_farm_position.allow_external_claim_boosted_rewards + } + #[inline] fn is_active(&self) -> bool { let state = self.state().get(); diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index 94154f32c..e1b1ca74e 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: 68 // Async Callback: 1 -// Total number of exported functions: 69 +// Total number of exported functions: 70 #![no_std] @@ -35,6 +35,7 @@ multiversx_sc_wasm_adapter::endpoints! { getRewardPerShare => reward_per_share getRewardReserve => reward_reserve allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards getFarmingTokenId => farming_token_id getRewardTokenId => reward_token_id getPerBlockRewardAmount => per_block_reward_amount diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index f760737d3..ef653de72 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 67 #![no_std] @@ -36,6 +36,7 @@ multiversx_sc_wasm_adapter::endpoints! { getRewardPerShare => reward_per_share getRewardReserve => reward_reserve allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards getFarmingTokenId => farming_token_id getRewardTokenId => reward_token_id getPerBlockRewardAmount => per_block_reward_amount diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index b938d5475..1baf98ce9 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: 70 // Async Callback: 1 -// Total number of exported functions: 71 +// Total number of exported functions: 72 #![no_std] @@ -38,6 +38,7 @@ multiversx_sc_wasm_adapter::endpoints! { getRewardPerShare => reward_per_share getRewardReserve => reward_reserve allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards getFarmingTokenId => farming_token_id getRewardTokenId => reward_token_id getPerBlockRewardAmount => per_block_reward_amount