Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zokunei
Copy link
Collaborator

@Zokunei Zokunei commented Jan 5, 2024

No description provided.

Copy link
Collaborator Author

@Zokunei Zokunei left a 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
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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

Copy link

@imrtlfarm imrtlfarm left a 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";

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);

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;

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);

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; ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants