-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix rewarder hooks and add RollingRewarder #31
base: master
Are you sure you want to change the base?
Conversation
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.
pushed a branch incorporating most of the changes recommended here, since I wanted to make changes to the base Reliquary contract to avoid all the poolBalance calculations in RollingRewarder. please still look at the comments
import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
import "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
|
||
/// @title Simple rewarder that distributes its own token based on a ratio to rewards emitted by the Reliquary |
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.
think this was just copied from MultiplierRewarder but could use updating
) SingleAssetRewarder(_rewardToken, _reliquary) { | ||
poolId = _poolId; | ||
|
||
uint256[] memory _multipliers = IReliquary(_reliquary) |
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 believe these lines are equivalent to multipliers = IReliquary(_reliquary).getLevelInfo(_poolId).multipliers;
if (_lastIssuanceTimestamp < _lastDistributionTime) { | ||
uint256 timeLeft = _lastDistributionTime - _lastIssuanceTimestamp; //time left until final distribution | ||
uint256 notIssued = getRewardAmount(timeLeft); //how many tokens are left to issue | ||
amount = amount + (notIssued); // add to the funding amount that hasnt been issued |
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.
nit: no parentheses needed
uint256 newAmountMultiplied = amount * multipliers[newLevel]; | ||
|
||
_issueTokens( | ||
_poolBalance() - newAmountMultiplied + oldAmountMultiplied |
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 _poolBalance()
has to be offset here, best to do subtraction last to avoid underflow.
multipliers[newLevel]; | ||
|
||
_issueTokens( | ||
_poolBalance() - newAmountMultiplied + oldAmountMultiplied |
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.
_poolBalance() + oldAmountMultiplied - newAmountMultiplied
contract RewardsPool { | ||
address public immutable RewardToken; | ||
address public Rewarder; | ||
uint256 public lastRetrievedTime; |
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.
unused?
using SafeERC20 for IERC20; | ||
|
||
uint256 public immutable ACC_REWARD_PRECISION = 1e18; | ||
uint256 public immutable REWARD_PER_SECOND_PRECISION = 1e2; |
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.
1e2
seems quite low, recommend at least using BPS (10_000
)
*/ | ||
function onReward( | ||
uint relicId, | ||
uint rewardAmount, |
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 comment out this variable to silence the compiler warning
uint, // rewardAmount
constructor(address _rewardToken, address rewarder) { | ||
RewardToken = _rewardToken; | ||
Rewarder = rewarder; | ||
IERC20(RewardToken).approve(Rewarder, type(uint256).max); |
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.
probably more gas efficient to use the stack variables rather than reading from storage here
|
||
contract RewardsPool { | ||
address public immutable RewardToken; | ||
address public Rewarder; |
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.
Rewarder
can't be changed so may as well make it immutable
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.
in order to find comments
@@ -2,12 +2,65 @@ | |||
|
|||
pragma solidity ^0.8.15; | |||
|
|||
import "../Reliquary.sol"; |
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.
is this useful? if not delete
uint oldLevel, | ||
uint newLevel | ||
) external override onlyReliquary { | ||
super._onReward(relicId, rewardAmount, to); |
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.
maybe specify the contract we inherit from instead of using super
override | ||
returns (address[] memory rewardTokens, uint[] memory rewardAmounts) | ||
{ | ||
uint length = childrenRewarders.length() + 1; |
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.
maybe it could make more sense to have the parent rewarder not have a reward token of its own and only manage, but is probably fine as is if it is too breaking of a change
uint oldAmount, | ||
uint oldLevel, | ||
uint newLevel | ||
) external override onlyReliquary { | ||
super._onReward(relicId, rewardAmount, to); |
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 as above
uint256[] memory _multipliers = IReliquary(_reliquary) | ||
.getLevelInfo(_poolId) | ||
.multipliers; | ||
for (uint i; i < _multipliers.length; ) { |
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 loop
No description provided.