Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add claimBoostedRewards endpoint in Fees Collector #789

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/modules/farm/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions dex/farm-with-locked-rewards/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions dex/farm/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions energy-integration/fees-collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ pub trait FeesCollector:
fn upgrade(&self) {}

#[endpoint(claimRewards)]
fn claim_rewards(
fn claim_rewards_endpoint(
&self,
opt_original_caller: OptionalValue<ManagedAddress>,
) -> PaymentsVec<Self::Api> {
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<ManagedAddress>,
) -> PaymentsVec<Self::Api> {
require!(self.not_paused(), "Cannot claim while paused");

let original_caller = match opt_original_caller {
OptionalValue::Some(user) => {
Expand All @@ -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::Api> {
self.accumulate_additional_locked_tokens();

let wrapper = FeesCollectorWrapper::new();
let mut rewards = self.claim_multi(&wrapper, &original_caller);
if rewards.is_empty() {
Expand All @@ -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,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
})
}

Expand Down
7 changes: 4 additions & 3 deletions energy-integration/fees-collector/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions energy-integration/governance-v2/tests/gov_test_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
&fees_collector_wrapper,
&rust_biguint!(0),
|sc| {
sc.claim_rewards(OptionalValue::None);
sc.claim_rewards_endpoint(OptionalValue::None);
},
)
.assert_ok();
Expand All @@ -140,7 +140,7 @@ where
&fees_collector_wrapper,
&rust_biguint!(0),
|sc| {
sc.claim_rewards(OptionalValue::None);
sc.claim_rewards_endpoint(OptionalValue::None);
},
)
.assert_ok();
Expand All @@ -151,7 +151,7 @@ where
&fees_collector_wrapper,
&rust_biguint!(0),
|sc| {
sc.claim_rewards(OptionalValue::None);
sc.claim_rewards_endpoint(OptionalValue::None);
},
)
.assert_ok();
Expand Down
5 changes: 3 additions & 2 deletions farm-staking/farm-staking/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down