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

Farm energy fix #920

Draft
wants to merge 69 commits into
base: feat/v3.1
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
44cbbf1
Farm tests with original caller merge fix
psorinionut Apr 8, 2024
e4cfd13
clippy fixes
psorinionut Apr 8, 2024
80bcfba
Merge branch 'rc/v3.0' into farm-tests-with-original-caller-merge-fix
dorin-iancu Apr 9, 2024
dd4cb71
Github actions on rc branches
psorinionut Apr 9, 2024
c2a2d27
Merge pull request #881 from multiversx/github-actions-rc-branches
psorinionut Apr 9, 2024
4aaa01f
Merge branch 'rc/v3.0' into farm-tests-with-original-caller-merge-fix
psorinionut Apr 9, 2024
b21ea70
Router check pair refactor
psorinionut Apr 10, 2024
16f0d72
clippy fixes
psorinionut Apr 10, 2024
e09da89
framework update v0.48.0
psorinionut Apr 11, 2024
b01507b
add check on enable swap by user
psorinionut Apr 11, 2024
19e8ce3
Farm staking merge fix + unit tests
psorinionut Apr 11, 2024
74c16af
use FarmStakingWrapper for merge endpoint
psorinionut Apr 12, 2024
154b56a
Merge pull request #875 from multiversx/farm-tests-with-original-call…
psorinionut Apr 12, 2024
04ecfe4
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 12, 2024
0d174b9
Merge branch 'rc/v3.0' into framework-upgrade-v0.48.0
andrei-marinica Apr 12, 2024
7bdcf2f
Merge pull request #887 from multiversx/framework-upgrade-v0.48.0
andrei-marinica Apr 12, 2024
4463206
upgrade annotation
andrei-marinica Apr 12, 2024
0f92c4f
cargo fmt
andrei-marinica Apr 12, 2024
cb32307
Merge pull request #889 from multiversx/upgrade-annotation
andrei-marinica Apr 12, 2024
1f215e6
Merge branch 'rc/v3.0' into router-check-is-pair-refactor
psorinionut Apr 12, 2024
88ab1ca
router fix after framework upgrade
psorinionut Apr 12, 2024
baa4c13
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 12, 2024
c572908
energy factory tests
psorinionut Apr 12, 2024
ef12603
remove unneeded check
psorinionut Apr 15, 2024
6b5442e
total farm position through simple lock test
psorinionut Apr 15, 2024
f9b5a0d
farm updated tests
psorinionut Apr 15, 2024
ec4b550
add back the router reverse check pair logic
psorinionut Apr 16, 2024
954d65c
code cleanup
psorinionut Apr 16, 2024
a97b9c3
Merge pull request #886 from multiversx/router-check-is-pair-refactor
psorinionut Apr 16, 2024
6c2a608
farm staking proxy unit tests
psorinionut Apr 16, 2024
a470bc3
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 16, 2024
4544a92
merge logic update orig owner in a separate fn for safer future impl …
psorinionut Apr 16, 2024
27085fb
Merge pull request #888 from multiversx/farm-staking-tests-with-merge…
psorinionut Apr 17, 2024
08ef135
Merge branch 'rc/v3.0' into v3.0-various-unit-tests
psorinionut Apr 17, 2024
ee10fe1
clippy fixes
psorinionut Apr 18, 2024
fe7e92d
Proxy-dex: farm: original caller negative test
CostinCarabas Apr 23, 2024
e993235
original caller merge fix
psorinionut Apr 23, 2024
031b36a
proxy_dex: more unit tests
CostinCarabas Apr 23, 2024
6516b36
farm staking additional tests
psorinionut Apr 24, 2024
6eb7113
proxy_dex: more unit tests
CostinCarabas Apr 24, 2024
1a1f276
code coverage update
psorinionut Apr 24, 2024
01a0959
Merge pull request #897 from multiversx/original-caller-merge-fix
psorinionut Apr 29, 2024
aed790b
Merge branch 'rc/v3.0' into v3.0-various-unit-tests
psorinionut Apr 29, 2024
6101651
Merge pull request #890 from multiversx/v3.0-various-unit-tests
psorinionut Apr 29, 2024
5587d14
Merge branch 'rc/v3.0' into additional-farm-staking-tests
psorinionut Apr 29, 2024
9c04db5
clippy fixes
psorinionut Apr 29, 2024
19c6abf
Merge pull request #898 from multiversx/additional-farm-staking-tests
psorinionut Apr 29, 2024
a222bd3
Merge branch 'rc/v3.0' into github-actions-code-coverage-update
psorinionut Apr 29, 2024
0ef7b61
Merge branch 'rc/v3.0' into proxy-dex-unit-tests
psorinionut Apr 29, 2024
e3c3196
Merge pull request #899 from multiversx/proxy-dex-unit-tests
psorinionut Apr 29, 2024
7713e19
Merge branch 'rc/v3.0' into github-actions-code-coverage-update
psorinionut Apr 29, 2024
effd81c
force rebuild github actions
psorinionut Apr 29, 2024
297cf73
Merge pull request #900 from multiversx/github-actions-code-coverage-…
psorinionut Apr 29, 2024
1761d54
Total farm position test in proxy dex
psorinionut Apr 29, 2024
77218ba
Merge pull request #903 from multiversx/proxy-dex-total-farm-position…
psorinionut Apr 29, 2024
8e8d180
Metastaking claim total farm position fix
psorinionut May 1, 2024
db82bb5
Merge pull request #904 from multiversx/metastaking-total-farm-positi…
psorinionut May 3, 2024
067064b
Energy factory unit test audit update
psorinionut May 7, 2024
867a88d
clippy fix
psorinionut May 9, 2024
c8f3f21
farm energy fix
dorin-iancu May 13, 2024
d8a5d6f
more fixes + test
dorin-iancu May 13, 2024
4578311
fix for old users
dorin-iancu May 13, 2024
9803759
proxy dex unit tests audit update
psorinionut May 14, 2024
23f0e2d
Merge pull request #905 from multiversx/energy-factory-unit-test-audi…
psorinionut May 14, 2024
eebb627
Merge branch 'rc/v3.0' into proxy-dex-unit-tests-update
psorinionut May 14, 2024
55088f8
proxy dex unit test scenario improvement
psorinionut May 14, 2024
3f2314a
Merge branch 'rc/v3.0' into farm-energy-fix
dorin-iancu May 15, 2024
a0671e6
Merge pull request #912 from multiversx/proxy-dex-unit-tests-update
psorinionut May 15, 2024
fab29de
Merge branch 'rc/v3.0' into farm-energy-fix
psorinionut May 15, 2024
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
Prev Previous commit
Next Next commit
fix for old users
  • Loading branch information
dorin-iancu committed May 13, 2024
commit 457831115b775283fba97d5df5d18c9fbb51665a
33 changes: 23 additions & 10 deletions dex/farm/src/base_functions.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ use core::marker::PhantomData;
use common_errors::ERROR_ZERO_AMOUNT;
use common_structs::FarmToken;
use common_structs::FarmTokenAttributes;
use common_structs::PaymentsVec;
use contexts::storage_cache::StorageCache;

use farm_base_impl::base_traits_impl::{DefaultFarmWrapper, FarmContract};
@@ -83,6 +84,7 @@ pub trait BaseFunctionsModule:
);

self.delete_user_energy_if_needed::<FC>(
&base_enter_farm_result.context.additional_farm_tokens,
&base_enter_farm_result.context.additional_attributes,
);

@@ -102,7 +104,8 @@ pub trait BaseFunctionsModule:
caller: ManagedAddress,
) -> ClaimRewardsResultWrapper<Self::Api> {
let payments = self.call_value().all_esdt_transfers().clone_value();
let base_claim_rewards_result = self.claim_rewards_base::<FC>(caller.clone(), payments);
let base_claim_rewards_result =
self.claim_rewards_base::<FC>(caller.clone(), payments.clone());

let output_farm_token_payment = base_claim_rewards_result.new_farm_token.payment.clone();
let rewards_payment = base_claim_rewards_result.rewards;
@@ -111,7 +114,10 @@ pub trait BaseFunctionsModule:
&base_claim_rewards_result.storage_cache.farm_token_supply,
);

self.delete_user_energy_if_needed::<FC>(&base_claim_rewards_result.context.all_attributes);
self.delete_user_energy_if_needed::<FC>(
&payments,
&base_claim_rewards_result.context.all_attributes,
);

self.emit_claim_rewards_event(
&caller,
@@ -134,7 +140,7 @@ pub trait BaseFunctionsModule:
) -> EsdtTokenPayment<Self::Api> {
let payments = self.call_value().all_esdt_transfers().clone_value();
let base_compound_rewards_result =
self.compound_rewards_base::<FC>(caller.clone(), payments);
self.compound_rewards_base::<FC>(caller.clone(), payments.clone());

let output_farm_token_payment = base_compound_rewards_result.new_farm_token.payment.clone();

@@ -143,6 +149,7 @@ pub trait BaseFunctionsModule:
);

self.delete_user_energy_if_needed::<FC>(
&payments,
&base_compound_rewards_result.context.all_attributes,
);

@@ -163,7 +170,7 @@ pub trait BaseFunctionsModule:
caller: ManagedAddress,
payment: EsdtTokenPayment,
) -> ExitFarmResultWrapper<Self::Api> {
let base_exit_farm_result = self.exit_farm_base::<FC>(caller.clone(), payment);
let base_exit_farm_result = self.exit_farm_base::<FC>(caller.clone(), payment.clone());

let mut farming_token_payment = base_exit_farm_result.farming_token_payment;
let reward_payment = base_exit_farm_result.reward_payment;
@@ -172,9 +179,12 @@ pub trait BaseFunctionsModule:
&base_exit_farm_result.storage_cache.farm_token_supply,
);

self.delete_user_energy_if_needed::<FC>(&ManagedVec::from_single_item(
base_exit_farm_result.context.farm_token.attributes.clone(),
));
self.delete_user_energy_if_needed::<FC>(
&ManagedVec::from_single_item(payment),
&ManagedVec::from_single_item(
base_exit_farm_result.context.farm_token.attributes.clone(),
),
);

FC::apply_penalty(
self,
@@ -212,7 +222,7 @@ pub trait BaseFunctionsModule:
all_attributes.push(attr);
}

self.delete_user_energy_if_needed::<FC>(&all_attributes);
self.delete_user_energy_if_needed::<FC>(&payments, &all_attributes);

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

@@ -279,12 +289,15 @@ pub trait BaseFunctionsModule:

fn delete_user_energy_if_needed<FC: FarmContract<FarmSc = Self>>(
&self,
payments: &PaymentsVec<Self::Api>,
all_attributes: &ManagedVec<FC::AttributesType>,
) {
let mut processed_users = ManagedMap::new();
for attr in all_attributes {
for (payment, attr) in payments.iter().zip(all_attributes.into_iter()) {
let original_owner = attr.get_original_owner();
if processed_users.contains(original_owner.as_managed_buffer()) {
if processed_users.contains(original_owner.as_managed_buffer())
|| self.is_old_farm_position(payment.token_nonce)
{
continue;
}

4 changes: 3 additions & 1 deletion farm-staking/farm-staking/src/claim_stake_farm_rewards.rs
Original file line number Diff line number Diff line change
@@ -63,11 +63,12 @@ pub trait ClaimStakeFarmRewardsModule:
opt_new_farming_amount: Option<BigUint>,
) -> ClaimRewardsResultType<Self::Api> {
self.migrate_old_farm_positions(&original_caller);

let payment = self.call_value().single_esdt();
let mut claim_result = self
.claim_rewards_base_no_farm_token_mint::<FarmStakingWrapper<Self>>(
original_caller.clone(),
ManagedVec::from_single_item(payment),
ManagedVec::from_single_item(payment.clone()),
);

let mut virtual_farm_token = claim_result.new_farm_token.clone();
@@ -88,6 +89,7 @@ pub trait ClaimStakeFarmRewardsModule:
}

self.delete_user_energy_if_needed::<FarmStakingWrapper<Self>>(
&ManagedVec::from_single_item(payment),
&claim_result.context.all_attributes,
);

6 changes: 4 additions & 2 deletions farm-staking/farm-staking/src/compound_stake_farm_rewards.rs
Original file line number Diff line number Diff line change
@@ -35,16 +35,18 @@ pub trait CompoundStakeFarmRewardsModule:
fn compound_rewards(&self) -> EsdtTokenPayment {
let caller = self.blockchain().get_caller();
self.migrate_old_farm_positions(&caller);

let payments = self.get_non_empty_payments();
let compound_result =
self.compound_rewards_base::<FarmStakingWrapper<Self>>(caller.clone(), payments);
let compound_result = self
.compound_rewards_base::<FarmStakingWrapper<Self>>(caller.clone(), payments.clone());

let new_farm_token = compound_result.new_farm_token.payment.clone();
self.send_payment_non_zero(&caller, &new_farm_token);

self.set_farm_supply_for_current_week(&compound_result.storage_cache.farm_token_supply);

self.delete_user_energy_if_needed::<FarmStakingWrapper<Self>>(
&payments,
&compound_result.context.all_attributes,
);

9 changes: 6 additions & 3 deletions farm-staking/farm-staking/src/delete_energy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common_structs::FarmToken;
use common_structs::{FarmToken, PaymentsVec};
use farm_base_impl::base_traits_impl::FarmContract;

multiversx_sc::imports!();
@@ -26,12 +26,15 @@ pub trait DeleteEnergyModule:
{
fn delete_user_energy_if_needed<FC: FarmContract<FarmSc = Self>>(
&self,
payments: &PaymentsVec<Self::Api>,
all_attributes: &ManagedVec<FC::AttributesType>,
) {
let mut processed_users = ManagedMap::new();
for attr in all_attributes {
for (payment, attr) in payments.iter().zip(all_attributes.into_iter()) {
let original_owner = attr.get_original_owner();
if processed_users.contains(original_owner.as_managed_buffer()) {
if processed_users.contains(original_owner.as_managed_buffer())
|| self.is_old_farm_position(payment.token_nonce)
{
continue;
}

2 changes: 1 addition & 1 deletion farm-staking/farm-staking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ pub trait FarmStaking:
all_attributes.push(attr);
}

self.delete_user_energy_if_needed::<FC>(&all_attributes);
self.delete_user_energy_if_needed::<FC>(&payments, &all_attributes);

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

1 change: 1 addition & 0 deletions farm-staking/farm-staking/src/stake_farm.rs
Original file line number Diff line number Diff line change
@@ -88,6 +88,7 @@ pub trait StakeFarmModule:
self.set_farm_supply_for_current_week(&enter_result.storage_cache.farm_token_supply);

self.delete_user_energy_if_needed::<FarmStakingWrapper<Self>>(
&enter_result.context.additional_farm_tokens,
&enter_result.context.additional_attributes,
);

5 changes: 3 additions & 2 deletions farm-staking/farm-staking/src/unstake_farm.rs
Original file line number Diff line number Diff line change
@@ -75,8 +75,8 @@ pub trait UnstakeFarmModule:
) -> ExitFarmWithPartialPosResultType<Self::Api> {
let migrated_amount = self.migrate_old_farm_positions(&original_caller);

let exit_result =
self.exit_farm_base::<FarmStakingWrapper<Self>>(original_caller.clone(), payment);
let exit_result = self
.exit_farm_base::<FarmStakingWrapper<Self>>(original_caller.clone(), payment.clone());

self.decrease_old_farm_positions(migrated_amount, &original_caller);

@@ -93,6 +93,7 @@ pub trait UnstakeFarmModule:
self.set_farm_supply_for_current_week(&exit_result.storage_cache.farm_token_supply);

self.delete_user_energy_if_needed::<FarmStakingWrapper<Self>>(
&ManagedVec::from_single_item(payment),
&ManagedVec::from_single_item(exit_result.context.farm_token.attributes.clone()),
);

Loading