-
Notifications
You must be signed in to change notification settings - Fork 7
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
Stake: Try to optimize the withdraw rewards function #395
Conversation
cb1c3af
to
7b016d5
Compare
4a625b4
to
1b62564
Compare
@@ -70,6 +72,13 @@ pub trait StakingTrait { | |||
|
|||
fn query_withdrawable_rewards(env: Env, address: Address) -> WithdrawableRewardsResponse; | |||
|
|||
fn query_withdrawable_rewards_ch( |
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 are you using shortened query_withdrawable_rewards_ch
instead of query_withdrawable_rewards_chunks
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.
Character limit per function name.
contracts/stake/src/contract.rs
Outdated
token_contract::Client::new(&env, &reward_token).transfer( | ||
&env.current_contract_address(), | ||
&sender, | ||
&pending_rewards, |
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.
wouldn't it better if we use env.contract_invoke
- should be better on the storage and (I'm not 100%) but it will avoid migration issues when we upgrade to next soroban-sdk
let (pending_reward, _) = | ||
calculate_pending_rewards_chunked(&env, &asset, &stakes, chunk_size, start_day); |
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 don't we return just pending_reward
since we're dropping the 2nd part of the tuple with _
from memory
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.
It's used in another call of that function.
let stake_age_days = | ||
((reward_day - stake.stake_timestamp) / SECONDS_PER_DAY).min(60); |
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.
what would happen if the user stakes their tokens after the reward_day
in question. Their stake.stake_timestamp
is set to the time they staked, which is more recent than reward_day
.
I'm not 100% sure that .skip_while(|&day| day < start_day.unwrap_or(last_claim_time))
would prevent us from getting to thath state, but last_claim_time
may still be before stake.stake_timestamp
. what if the user hasn't claimed rewards for a long time, last_claim_time
could be an old timestamp
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.
what would happen if the user stakes their tokens after the reward_day in question
Then it's getting filtered through skip_while(|&day: u64| day < last_claim_time))
what if the user hasn't claimed rewards for a long time, last_claim_time could be an old timestamp
last_claim_time
can be even 0 if user never claimed his rewards; That means he needs to start from the beginning of history of the rewards.
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.
LGTM
} | ||
|
||
stakes.last_reward_time = last_reward_day; | ||
save_stakes(&env, &sender, &stakes); |
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.
btw, I know logs are useless, but we should have some
No description provided.