-
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
allow setting first week epoch in farm #835
Changes from all commits
c8632cb
d902eb3
abad7ad
39d6bda
4a818dc
2ed5386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,6 +283,12 @@ where | |
sc: &<Self as FarmContract>::FarmSc, | ||
caller: &ManagedAddress<<<Self as FarmContract>::FarmSc as ContractBase>::Api>, | ||
) -> BigUint<<<Self as FarmContract>::FarmSc as ContractBase>::Api> { | ||
let current_epoch = sc.blockchain().get_block_epoch(); | ||
let first_week_start_epoch = sc.first_week_start_epoch().get(); | ||
if first_week_start_epoch > current_epoch { | ||
return BigUint::zero(); | ||
} | ||
|
||
let user_total_farm_position = sc.get_user_total_farm_position(caller); | ||
let user_farm_position = user_total_farm_position.total_farm_position; | ||
|
||
|
@@ -304,15 +310,17 @@ where | |
storage_cache: &mut StorageCache<Self::FarmSc>, | ||
) { | ||
let total_reward = Self::mint_per_block_rewards(sc, &storage_cache.reward_token_id); | ||
if total_reward > 0u64 { | ||
storage_cache.reward_reserve += &total_reward; | ||
let split_rewards = sc.take_reward_slice(total_reward); | ||
|
||
if storage_cache.farm_token_supply != 0u64 { | ||
let increase = (&split_rewards.base_farm * &storage_cache.division_safety_constant) | ||
/ &storage_cache.farm_token_supply; | ||
storage_cache.reward_per_share += &increase; | ||
} | ||
if total_reward == 0u64 { | ||
return; | ||
} | ||
|
||
storage_cache.reward_reserve += &total_reward; | ||
let split_rewards = sc.take_reward_slice(total_reward); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a check in the |
||
|
||
if storage_cache.farm_token_supply != 0u64 { | ||
let increase = (&split_rewards.base_farm * &storage_cache.division_safety_constant) | ||
/ &storage_cache.farm_token_supply; | ||
storage_cache.reward_per_share += &increase; | ||
} | ||
} | ||
|
||
|
@@ -323,6 +331,12 @@ where | |
token_attributes: &Self::AttributesType, | ||
storage_cache: &StorageCache<Self::FarmSc>, | ||
) -> BigUint<<Self::FarmSc as ContractBase>::Api> { | ||
let current_epoch = sc.blockchain().get_block_epoch(); | ||
let first_week_start_epoch = sc.first_week_start_epoch().get(); | ||
if first_week_start_epoch > current_epoch { | ||
return BigUint::zero(); | ||
} | ||
|
||
let base_farm_reward = DefaultFarmWrapper::<T>::calculate_rewards( | ||
sc, | ||
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.
Do we need the extra check in place? We already have the check when computing the actual rewards. Maybe we accept that until the first_week_start_epoch is reached, we don't fail the endpoint, and just return 0. Then, after we pass that particular epoch, we avoid the 2 extra reads.