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 rewards aggregation in merge endpoints #940

Merged
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
2 changes: 2 additions & 0 deletions dex/farm-with-locked-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub trait Farm:
}

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
NoMintWrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);

let boosted_rewards = self.claim_only_boosted_payment(user);
Expand Down Expand Up @@ -265,6 +266,7 @@ pub trait Farm:
require!(percentage <= MAX_PERCENT, "Invalid percentage");

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
NoMintWrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);

self.boosted_yields_rewards_percentage().set(percentage);
Expand Down
7 changes: 7 additions & 0 deletions dex/farm/src/base_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ pub trait BaseFunctionsModule:

FC::check_and_update_user_farm_position(self, orig_caller, &payments);

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);

FC::generate_aggregated_rewards(self, &mut storage_cache);

self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply);

self.merge_from_payments_and_burn(payments, &token_mapper)
}

Expand Down
2 changes: 2 additions & 0 deletions dex/farm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub trait Farm:
}

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
Wrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);

let boosted_rewards = self.claim_only_boosted_payment(user);
Expand Down Expand Up @@ -266,6 +267,7 @@ pub trait Farm:
require!(percentage <= MAX_PERCENT, "Invalid percentage");

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
Wrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);

self.boosted_yields_rewards_percentage().set(percentage);
Expand Down
8 changes: 8 additions & 0 deletions farm-staking/farm-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ pub trait FarmStaking:

FC::check_and_update_user_farm_position(self, orig_caller, &payments);

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);

FC::generate_aggregated_rewards(self, &mut storage_cache);

self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply);

self.merge_from_payments_and_burn(payments, &token_mapper)
}

Expand All @@ -153,6 +160,7 @@ pub trait FarmStaking:
require!(percentage <= MAX_PERCENT, "Invalid percentage");

let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
FarmStakingWrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);

self.boosted_yields_rewards_percentage().set(percentage);
Expand Down
8 changes: 6 additions & 2 deletions farm-staking/farm-staking/src/unbond_farm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
multiversx_sc::imports!();

use contexts::storage_cache::StorageCache;
use farm_base_impl::base_traits_impl::FarmContract;

use crate::token_attributes::UnbondSftAttributes;
use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::UnbondSftAttributes};

#[multiversx_sc::module]
pub trait UnbondFarmModule:
Expand Down Expand Up @@ -32,7 +33,7 @@ pub trait UnbondFarmModule:
#[payable("*")]
#[endpoint(unbondFarm)]
fn unbond_farm(&self) -> EsdtTokenPayment {
let storage_cache = StorageCache::new(self);
let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);

let farm_token_mapper = self.farm_token();
Expand All @@ -48,6 +49,9 @@ pub trait UnbondFarmModule:
"Unbond period not over"
);

FarmStakingWrapper::<Self>::generate_aggregated_rewards(self, &mut storage_cache);
self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply);

farm_token_mapper.nft_burn(payment.token_nonce, &payment.amount);

let caller = self.blockchain().get_caller();
Expand Down
Loading