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 position first audit fixes #772

Merged
merged 28 commits into from
Sep 29, 2023

Conversation

psorinionut
Copy link
Contributor

No description provided.

fn default() -> Self {
Self {
total_farm_position: BigUint::zero(),
allow_external_claim_boosted_rewards: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

we need a new bool here: migrated. And to keep that even if total_farm_position gets to 0 again. Or to not delete claimProgressWeek from user.

fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) {
let caller = self.blockchain().get_caller();
let user_total_farm_position_mapper = self.user_total_farm_position(&caller);
if user_total_farm_position_mapper.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no need for this if. Actually the user must have a farm position before making this allow call.

let user_total_farm_position_struct = sc.get_user_total_farm_position_struct(user);
if user_total_farm_position_struct.total_farm_position == BigUint::zero() {
let user_total_farm_position = sc.get_user_total_farm_position(user);
if user_total_farm_position.total_farm_position == BigUint::zero()
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this if. Make farm_position_increase += farm_position.amount if the farm_position is old.

Also Do not decrease_user_farm_position for old_farm_positions.

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);

let boosted_rewards = self.claim_only_boosted_payment(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

if the payments are old tokens - we need to increase the total_position of the user. If they are new tokens we have to check and change total_positions if original_user != caller.

I think we could make a function called = adjust_total_position - which gets the payments and computes the total_position for the user and decreases for original_user.

We do not need to claim_boosted_rewards.

let user_total_farm_position = user_total_farm_position_struct.total_farm_position;
if user_total_farm_position == BigUint::zero() {
return BigUint::zero();
if user_farm_position > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this if is not needed.

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);

let boosted_rewards = self.claim_only_boosted_payment(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to claim boosted - only adjust_total_positions as explained in a comment before.

+ energy_query::EnergyQueryModule
+ utils::UtilsModule
{
fn check_claim_progress_for_merge(&self, caller: &ManagedAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why deleted ?

@@ -86,8 +86,10 @@ pub trait UnstakeFarmModule:
"Exit amount is bigger than the payment amount"
);

let boosted_rewards = self.claim_only_boosted_payment(&original_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

adjust position and claim boosted.

None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()),
let caller = self.blockchain().get_caller();

let boosted_rewards = self.claim_only_boosted_payment(&original_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

adjust position and claim boosted. like everywhere. in farms as well. for entering and exiting. For merging we need only adjust_position.

self.check_claim_progress_for_merge(&caller);
let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller);

let boosted_rewards = self.claim_only_boosted_payment(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

Only adjust_positions - no need for claim boosted here.

@github-actions
Copy link

github-actions bot commented Sep 18, 2023

Contract comparison - from 249c3ee to 36be963

Path                                                                                             size                  has-allocator                     has-format
mx-exchange-sc
- pause-all/pause-all.wasm 5438 No No
mx-exchange-sc/dex
- farm/farm.wasm 39645 ➡️ 38696 🟢 No No
- farm-with-locked-rewards/farm-with-locked-rewards.wasm 39306 ➡️ 38299 🟢 No No
- governance/governance.wasm 17283 No No
- pair
- - pair.wasm 30521 ➡️ 30520 🟢 No No
- - pair-full.wasm 31968 ➡️ 31970 🔴 No No
- - safe-price-view.wasm 7862 No No
- pair-mock/pair-mock.wasm 5474 No No
- price-discovery/price-discovery.wasm 16254 No No
- proxy-deployer/proxy-deployer.wasm 4457 No No
- router/router.wasm 25991 No No
mx-exchange-sc/energy-integration
- energy-factory-mock/energy-factory-mock.wasm 4233 No No
- energy-update/energy-update.wasm 1510 No No
- fees-collector/fees-collector.wasm 18400 ➡️ 18531 🔴 No No
- governance-v2/governance-v2.wasm 16822 No No
mx-exchange-sc/farm-staking
- farm-staking/farm-staking.wasm 42902 ➡️ 42863 🟢 No No
- farm-staking-proxy/farm-staking-proxy.wasm 21021 ➡️ 18629 🟢 No No
- metabonding-staking/metabonding-staking.wasm 9593 No No
mx-exchange-sc/locked-asset
- distribution/distribution.wasm 14358 No No
- energy-factory/energy-factory.wasm 34193 No No
- factory/factory.wasm 30374 ➡️ 30375 🔴 No No
- lkmex-transfer/lkmex-transfer.wasm 11214 No No
- locked-token-wrapper/locked-token-wrapper.wasm 14291 No No
- proxy_dex/proxy_dex.wasm 34335 ➡️ 34017 🟢 No No
- simple-lock/simple-lock.wasm 24299 ➡️ 24111 🟢 No No
- simple-lock-whitelist/simple-lock-whitelist.wasm 25946 ➡️ 25759 🟢 No No
- token-unstake/token-unstake.wasm 13625 No No

let token_attributes: FarmTokenAttributes<Self::Api> =
farm_token_mapper.get_token_attributes(farm_position.token_nonce);

if &token_attributes.original_owner == caller {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this check.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete it safely.

@@ -163,7 +162,10 @@ pub trait Farm:
"Exit amount is bigger than the payment amount"
);

let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment);
let boosted_rewards = self.claim_only_boosted_payment(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

Call migrate_old_farm_position here as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

claim rewards and make a new position for the whole payment.

Do the same on farm-staking.

@@ -162,7 +156,10 @@ pub trait Farm:
"Exit amount is bigger than the payment amount"
);

let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment);
let boosted_rewards = self.claim_only_boosted_payment(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

call migrate_old_position before claim_boosted

@@ -180,7 +189,7 @@ pub trait Farm:
self.send_payment_non_zero(&caller, &exit_farm_result.rewards);
self.send_payment_non_zero(&caller, &remaining_farm_payment);

self.clear_user_energy_if_needed(&orig_caller, &remaining_farm_payment.amount);
self.clear_user_energy_if_needed(&orig_caller);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not clear.

@psorinionut psorinionut merged commit ff4f6b1 into farm-position-functionality Sep 29, 2023
4 checks passed
@psorinionut psorinionut deleted the farm-position-fixes branch September 29, 2023 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants