Skip to content

Commit

Permalink
revert farm staking unbond changes
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Aug 2, 2024
1 parent b147571 commit a28f0a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 101 deletions.
11 changes: 2 additions & 9 deletions farm-staking/farm-staking/src/unbond_farm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
multiversx_sc::imports!();

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

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

#[multiversx_sc::module]
pub trait UnbondFarmModule:
Expand All @@ -17,7 +16,6 @@ pub trait UnbondFarmModule:
+ pausable::PausableModule
+ permissions_module::PermissionsModule
+ multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule
+ farm_base_impl::base_farm_init::BaseFarmInitModule
+ farm_base_impl::base_farm_validation::BaseFarmValidationModule
+ utils::UtilsModule
+ farm_boosted_yields::FarmBoostedYieldsModule
Expand All @@ -33,7 +31,7 @@ pub trait UnbondFarmModule:
#[payable("*")]
#[endpoint(unbondFarm)]
fn unbond_farm(&self) -> EsdtTokenPayment {
let mut storage_cache = StorageCache::new(self);
let 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 @@ -49,11 +47,6 @@ pub trait UnbondFarmModule:
"Unbond period not over"
);

let current_week = self.get_current_week();
self.perform_weekly_update(current_week);
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
92 changes: 0 additions & 92 deletions farm-staking/farm-staking/tests/farm_staking_energy_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,95 +1730,3 @@ fn merge_farm_position_per_week_test() {
Some(&expected_attributes),
);
}

#[test]
fn unbond_farm_position_per_week_test() {
DebugApi::dummy();
let mut fs_setup =
FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj);

fs_setup.set_boosted_yields_factors();
fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE);

let first_user = fs_setup.user_address.clone();
let farm_in_amount = 100_000_000;

fs_setup.set_user_energy(&first_user, 10_000, 0, 10);
fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0);
fs_setup.check_farm_token_supply(farm_in_amount);

fs_setup.unstake_farm_no_checks(&first_user, farm_in_amount / 2, 1);
fs_setup.check_farm_token_supply(farm_in_amount / 2);

fs_setup.check_farm_rps(0u64);

fs_setup.b_mock.set_block_nonce(100);
fs_setup.b_mock.set_block_epoch(6);
fs_setup.set_user_energy(&first_user, 1_000, 6, 1);

// Reset user balance
fs_setup
.b_mock
.set_esdt_balance(&first_user, FARMING_TOKEN_ID, &rust_biguint!(0));

let mut current_farm_rps = 0;
fs_setup.check_farm_rps(current_farm_rps);

// advance 1 week
fs_setup.set_user_energy(&first_user, 1_000, 13, 1);
fs_setup.b_mock.set_block_nonce(200);
fs_setup.b_mock.set_block_epoch(13);

fs_setup.unbond_farm(
2,
farm_in_amount / 2,
farm_in_amount / 2,
farm_in_amount / 2,
);

let mut user_balance = farm_in_amount / 2;
fs_setup
.b_mock
.check_esdt_balance(&first_user, REWARD_TOKEN_ID, &rust_biguint!(user_balance));

let farm_rps_increase = 6_000_000u64;
current_farm_rps += farm_rps_increase;
fs_setup.check_farm_rps(current_farm_rps);

// advance 1 week
fs_setup.set_user_energy(&first_user, 1_000, 15, 1);
fs_setup.b_mock.set_block_nonce(300);
fs_setup.b_mock.set_block_epoch(15);

let boosted_rewards_for_week = 100;
user_balance += boosted_rewards_for_week;
fs_setup.claim_boosted_rewards_for_user(
&first_user,
&first_user,
boosted_rewards_for_week,
&rust_biguint!(user_balance),
);

// User should have the following balance: unstake_amount + boosted_rewards_week_2
fs_setup
.b_mock
.check_esdt_balance(&first_user, REWARD_TOKEN_ID, &rust_biguint!(user_balance));

current_farm_rps += farm_rps_increase / 2; //user existed with half position
fs_setup.check_farm_rps(current_farm_rps);

let expected_attributes = StakingFarmTokenAttributes::<DebugApi> {
reward_per_share: managed_biguint!(0),
compounded_reward: managed_biguint!(0),
current_farm_amount: managed_biguint!(farm_in_amount),
original_owner: managed_address!(&first_user),
};

fs_setup.b_mock.check_nft_balance(
&first_user,
FARM_TOKEN_ID,
1,
&rust_biguint!(farm_in_amount / 2),
Some(&expected_attributes),
);
}

0 comments on commit a28f0a4

Please sign in to comment.