-
Notifications
You must be signed in to change notification settings - Fork 70
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
[CU-2rb5h66] update reward pool #1346
Conversation
Task linked: CU-2rb5h66 Update reward pool |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
frame/staking-rewards/src/lib.rs
Outdated
ensure!( | ||
reward.max_rewards > reward.total_rewards + reward_update.amount, | ||
Error::<T>::MaxRewardExceeded | ||
); | ||
|
||
reward.total_rewards = reward | ||
.total_rewards | ||
.safe_add(&reward_update.amount) | ||
.map_err(|_| ArithmeticError::Overflow)?; |
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.
ensure!( | |
reward.max_rewards > reward.total_rewards + reward_update.amount, | |
Error::<T>::MaxRewardExceeded | |
); | |
reward.total_rewards = reward | |
.total_rewards | |
.safe_add(&reward_update.amount) | |
.map_err(|_| ArithmeticError::Overflow)?; | |
let new_total_rewards = reward | |
.total_rewards | |
.safe_add(&reward_update.amount)?; | |
ensure!( | |
reward.max_rewards >= new_total_rewards, | |
Error::<T>::MaxRewardExceeded | |
); | |
reward.total_rewards = new_total_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.
No need to check for Overflow
?
frame/staking-rewards/src/lib.rs
Outdated
for (asset_id, reward) in inner_rewards.iter_mut() { | ||
match reward_updates.get(asset_id) { | ||
Some(reward_update) => { | ||
ensure!( | ||
reward.max_rewards > reward.total_rewards + reward_update.amount, | ||
Error::<T>::MaxRewardExceeded | ||
); | ||
|
||
reward.total_rewards = reward | ||
.total_rewards | ||
.safe_add(&reward_update.amount) | ||
.map_err(|_| ArithmeticError::Overflow)?; | ||
// reward.total_rewards = reward.total_rewards | ||
// .safe_add(elapsed_time * pool.reward_rate) | ||
// .map_err(|_| ArithmeticError::Overflow)?; | ||
reward.reward_rate = reward_update.reward_rate; | ||
}, | ||
None => (), | ||
} | ||
} |
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.
As a note, this is possible without mutability. It would be much nicer if it was possible to iterate over a bounded map directly - I've opened paritytech/substrate#11866 to suggest an API to provide that functionality
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.
That would be much nicer to read!
Timestamp::set_timestamp(200000); | ||
|
||
let pool_init_config = get_default_reward_pool(); | ||
assert_ok!(StakingRewards::create_reward_pool(Origin::root(), pool_init_config)); |
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.
Check that the RewardPoolCreated
is emitted and get the pool_id
from there (could extract this to a helper function in the tests, will surely be used elsewhere)
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.
For what I see in another test, the pool_count()
is used as pool_id
. Will this be enough?
Issue
https://app.clickup.com/t/2rb5h66
Checklist
book/
to reflect changes made by this PR (if applicable)