-
Notifications
You must be signed in to change notification settings - Fork 0
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
Streamed rewards #74
Streamed rewards #74
Conversation
5529222
to
ca9b6f1
Compare
if (amount == 0) { | ||
revert StakingManager__AmountCannotBeZero(); | ||
} | ||
|
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.
To be very defensive, I'd suggest we:
- Either ensure
amount
is at least1e18
or - Ensure
rewardPerSecond
is not0
While not super likely to happen, there's a chance to provide amount
and duration
such that rewardPerSecond
will round down to 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.
Actually, just noticed we're no longer calculating rewardsPerSecond
here. We should probably still have the check I've mentioned above.
src/RewardsStreamerMP.sol
Outdated
// FIXME: If newTotalWeight > previousTotalWeight, then (previousTotalWeight) / (newTotalWeight) is less than 1. | ||
// Multiplying rewardIndex by a fraction less than 1 reduces its value. | ||
// Users who have not updated their accountRewardIndex may see a reduction in their pending rewards. | ||
// Possible fix: adjust only when newTotalWeight < previousTotalWeight |
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.
@gravityblast I've been pondering on this comment for quite a while now and I can't quite understand what the issue here is. Can you give a concrete example that demonstrates the issue you're describing here?
6b1e0a2
to
2108d88
Compare
2108d88
to
1cfb7d5
Compare
… a real reward token balance
1cfb7d5
to
e52b6fc
Compare
|
||
RewardsStreamerMP.Account memory accountInfo = streamer.getAccount(p.account); | ||
|
||
assertEq(accountInfo.stakedBalance, p.stakedBalance, "wrong account staked balance"); | ||
assertEq(stakingToken.balanceOf(p.account), p.vaultBalance, "wrong vault balance"); | ||
assertEq(accountInfo.accountRewardIndex, p.rewardIndex, "wrong account reward index"); | ||
// assertEq(accountInfo.accountRewardIndex, p.rewardIndex, "wrong account reward index"); |
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 should remove the commented out lines
test/RewardsStreamerMP.t.sol
Outdated
@@ -241,7 +224,7 @@ contract IntegrationTest is RewardsStreamerMPTest { | |||
|
|||
// T3 | |||
vm.prank(admin); | |||
rewardToken.transfer(address(streamer), 1000e18); | |||
// rewardToken.transfer(address(streamer), 1000e18); |
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.
Leftover comment
test/RewardsStreamerMP.t.sol
Outdated
@@ -391,7 +370,7 @@ contract IntegrationTest is RewardsStreamerMPTest { | |||
|
|||
// T6 | |||
vm.prank(admin); | |||
rewardToken.transfer(address(streamer), 1000e18); | |||
// rewardToken.transfer(address(streamer), 1000e18); |
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.
Same here
streamer.setReward(2000e18, 10 days); | ||
// accrued is 1000 from the previous reward and still 0 for the new one | ||
assertEq(streamer.totalRewardsSupply(), 1000e18, "totalRewardsSupply should be 1000"); | ||
assertEq(streamer.totalRewardsAccrued(), 1000e18); |
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.
Ah, interesting. Looking at these assertions, I expected it to be the other way around:
totalRewardsSupply()
is what is "checkpointed"totalRewardsAccrued()
is "real-time" balance that is accrued until this point in time
Also, the comment says [...] and still 0 for the new one
but the 0
isn't reflected here anywhere.
Likely needs rewording?
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.
@0x-r4bbit yes so we have:
- 1000 accrued and saved to storage in
totalRewardsAccrued
- 0 pending
totalRewardsSupply
istotalRewardsAccrued
+ pending =1000
// FIXME: this is needed to update the global state and account MP | ||
// Later we should update the functions to use "real-time" values. | ||
streamer.updateGlobalState(); | ||
streamer.updateAccountMP(vaults[alice]); |
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.
re: the FIXME comment: can't we have the real-time functions be part of this PR?
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.
I'm preparing it for the next PR so we can merge this otherwise I have too many conflicts every day :-P
uint256 tolerance = 300; // 300 wei | ||
|
||
assertEq(streamer.totalRewardsSupply(), 100e18, "Total rewards supply mismatch"); | ||
assertApproxEqAbs(streamer.rewardsBalanceOf(vaults[alice]), 100e18, tolerance); |
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 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.
yes
…PendingRewards and fix specs
Description
first PR part of #65
Update the current implementation to set a reward for a specific period (like 10K tokens for 1 year) and stream that dynamically.
Checklist
Ensure you completed all of the steps below before submitting your pull request:
pnpm adorno
?pnpm verify
?