Skip to content

Commit

Permalink
Merge pull request #774 from multiversx/claim-boosted-in-merge-endpoints
Browse files Browse the repository at this point in the history
claim boosted in merge endpoints
  • Loading branch information
psorinionut authored Sep 20, 2023
2 parents 65930ce + 1e9ec92 commit c609e42
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 44 deletions.
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,
orig_caller,
);

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
5 changes: 3 additions & 2 deletions dex/scenarios/merge_tokens.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
},
"expect": {
"out": [
"0x0000000b4641524d2d6162636465660000000000000003000000040bebc200"
"0x0000000b4641524d2d6162636465660000000000000003000000040bebc200",
"0x0000000c5745474c442d616263646566000000000000000000000000"
],
"status": "0",
"message": "",
Expand Down Expand Up @@ -63,4 +64,4 @@
}
}
]
}
}
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

0 comments on commit c609e42

Please sign in to comment.