-
Notifications
You must be signed in to change notification settings - Fork 46
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
farm position first audit fixes #772
Conversation
fn default() -> Self { | ||
Self { | ||
total_farm_position: BigUint::zero(), | ||
allow_external_claim_boosted_rewards: false, |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
dex/farm/src/base_functions.rs
Outdated
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
farm-staking/farm-staking/src/lib.rs
Outdated
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); |
There was a problem hiding this comment.
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.
Contract comparison - from 249c3ee to 36be963
|
dex/farm/src/base_functions.rs
Outdated
let token_attributes: FarmTokenAttributes<Self::Api> = | ||
farm_token_mapper.get_token_attributes(farm_position.token_nonce); | ||
|
||
if &token_attributes.original_owner == caller { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
dex/farm/src/lib.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not clear.
claim boosted in merge endpoints
remove exit amount parameter from farms
Moved try_set_farm_position_migration_nonce to common modules to remove code duplication.
audit fixes (2)
farm position functionality tests
No description provided.