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

claim boosted in merge endpoints #774

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions dex/farm-with-locked-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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
Expand Down Expand Up @@ -180,16 +179,24 @@ pub trait Farm:
fn merge_farm_tokens_endpoint(
&self,
opt_orig_caller: OptionalValue<ManagedAddress>,
) -> EsdtTokenPayment<Self::Api> {
) -> DoubleMultiPayment<Self::Api> {
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::<NoMintWrapper<Self>>();

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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clippy fixes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

orig_caller.clone(),
);

merged_farm_token
(merged_farm_token, locked_rewards_payment).into()
}

#[endpoint(claimBoostedRewards)]
Expand Down
15 changes: 10 additions & 5 deletions dex/farm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -178,16 +176,23 @@ pub trait Farm:
fn merge_farm_tokens_endpoint(
&self,
opt_orig_caller: OptionalValue<ManagedAddress>,
) -> EsdtTokenPayment<Self::Api> {
) -> DoubleMultiPayment<Self::Api> {
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::<Wrapper<Self>>();
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)]
Expand Down
27 changes: 0 additions & 27 deletions dex/farm/src/progress_update.rs

This file was deleted.

4 changes: 3 additions & 1 deletion dex/farm/tests/farm_setup/multi_user_farm_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions farm-staking/farm-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -92,11 +92,17 @@ pub trait FarmStaking:

#[payable("*")]
#[endpoint(mergeFarmTokens)]
fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment<Self::Api> {
fn merge_farm_tokens_endpoint(&self) -> DoubleMultiPayment<Self::Api> {
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<Self::Api> =
Expand All @@ -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)]
Expand Down