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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions contracts/Reliquary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ contract Reliquary is
fromPosition.rewardDebt = newFromAmount * multiplier / ACC_REWARD_PRECISION;
newPosition.rewardDebt = amount * multiplier / ACC_REWARD_PRECISION;

address _rewarder = rewarder[poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onSplit(fromId, newId, amount, fromAmount, level);
}

emit ReliquaryEvents.CreateRelic(poolId, to, newId);
emit ReliquaryEvents.Split(fromId, newId, amount);
}
Expand Down Expand Up @@ -528,6 +533,20 @@ contract Reliquary is
toPosition.rewardDebt = vars.newToAmount * vars.accRewardPerShare
* levels[vars.poolId].multipliers[vars.newToLevel] / ACC_REWARD_PRECISION;

address _rewarder = rewarder[vars.poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onShift(
fromId,
toId,
amount,
vars.fromAmount,
vars.toAmount,
vars.fromLevel,
vars.oldToLevel,
vars.newToLevel
);
}

emit ReliquaryEvents.Shift(fromId, toId, amount);
}

Expand Down Expand Up @@ -572,6 +591,19 @@ contract Reliquary is
_burn(fromId);
delete positionForId[fromId];

address _rewarder = rewarder[poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onMerge(
fromId,
toId,
fromAmount,
toAmount,
fromLevel,
oldToLevel,
newToLevel
);
}

emit ReliquaryEvents.Merge(fromId, toId, fromAmount);
}

Expand Down Expand Up @@ -762,19 +794,38 @@ contract Reliquary is
}
address _rewarder = rewarder[poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onReward(relicId, received, harvestTo);
IRewarder(_rewarder).onReward(
relicId,
received,
harvestTo,
vars.oldAmount,
vars.oldLevel,
vars.newLevel
);
}
}

if (kind == Kind.DEPOSIT) {
address _rewarder = rewarder[poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onDeposit(relicId, amount);
IRewarder(_rewarder).onDeposit(
relicId,
amount,
vars.oldAmount,
vars.oldLevel,
vars.newLevel
);
}
} else if (kind == Kind.WITHDRAW) {
address _rewarder = rewarder[poolId];
if (_rewarder != address(0)) {
IRewarder(_rewarder).onWithdraw(relicId, amount);
IRewarder(_rewarder).onWithdraw(
relicId,
amount,
vars.oldAmount,
vars.oldLevel,
vars.newLevel
);
}
}
}
Expand Down
61 changes: 57 additions & 4 deletions contracts/interfaces/IRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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


interface IRewarder {
function onReward(uint relicId, uint rewardAmount, address to) external;
function onReward(
uint relicId,
uint rewardAmount,
address to,
uint amount,
uint oldLevel,
uint newLevel
) external;

function onDeposit(
uint relicId,
uint depositAmount,
uint oldAmount,
uint oldLevel,
uint newLevel
) external;

function onWithdraw(
uint relicId,
uint withdrawalAmount,
uint oldAmount,
uint oldLevel,
uint newLevel
) external;

function onSplit(
uint fromId,
uint newId,
uint amount,
uint fromAmount,
uint level
) external;

function onDeposit(uint relicId, uint depositAmount) external;
function onShift(
uint fromId,
uint toId,
uint amount,
uint oldFromAmount,
uint oldToAmount,
uint fromLevel,
uint oldToLevel,
uint newToLevel
) external;

function onWithdraw(uint relicId, uint withdrawalAmount) external;
function onMerge(
uint fromId,
uint toId,
uint fromAmount,
uint toAmount,
uint fromLevel,
uint oldToLevel,
uint newToLevel
) external;

function pendingTokens(uint relicId, uint rewardAmount) external view returns (address[] memory, uint[] memory);
function pendingTokens(
uint relicId,
uint rewardAmount
) external view returns (address[] memory, uint[] memory);
}
12 changes: 12 additions & 0 deletions contracts/interfaces/IRollingRewarder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.15;

import "./IRewarder.sol";

interface IRollingRewarder is IRewarder {

function fund() external;

function setRewardsPool(address _rewardsPool) external;
}
28 changes: 28 additions & 0 deletions contracts/rewarders/ChildMultiplierRewarder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import "./ChildRewarder.sol";
import "./MultiplierRewarder.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";

contract ChildMultiplierRewarder is MultiplierRewarder, ChildRewarder, Ownable {

constructor(
uint _rewardMultiplier,
address _rewardToken,
address _reliquary
) MultiplierRewarder(_rewardMultiplier, _rewardToken, _reliquary) ChildRewarder() {}

function onReward(
uint relicId,
uint rewardAmount,
address to,
uint, // oldAmount,
uint, // oldLevel,
uint // newLevel
) external override(IRewarder, MultiplierRewarder) onlyParent {
_onReward(relicId, rewardAmount, to);
}

}
21 changes: 7 additions & 14 deletions contracts/rewarders/ChildRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@

pragma solidity ^0.8.17;

import "./MultiplierRewarderOwnable.sol";
import "../interfaces/IRewarder.sol";

/// @title Child rewarder contract to be deployed and called by a ParentRewarder, rather than directly by the Reliquary.
contract ChildRewarder is MultiplierRewarderOwnable {
abstract contract ChildRewarder is IRewarder {
/// @notice Address of ParentRewarder which deployed this contract
address public immutable parent;

modifier onlyParent() {
require(msg.sender == address(parent), "Only parent can call this function.");
require(
msg.sender == address(parent),
"Only parent can call this function."
);
_;
}

/**
* @dev Contructor called on deployment of this contract.
* @param _rewardMultiplier Amount to multiply reward by, relative to BASIS_POINTS.
* @param _rewardToken Address of token rewards are distributed in.
* @param _reliquary Address of Reliquary this rewarder will read state from.
*/
constructor(uint _rewardMultiplier, address _rewardToken, address _reliquary)
MultiplierRewarderOwnable(_rewardMultiplier, _rewardToken, _reliquary)
{
constructor() {
parent = msg.sender;
}

/// @inheritdoc SingleAssetRewarder
function onReward(uint relicId, uint rewardAmount, address to) external override onlyParent {
super._onReward(relicId, rewardAmount, to);
}
}
43 changes: 41 additions & 2 deletions contracts/rewarders/DepositBonusRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ contract DepositBonusRewarder is SingleAssetRewarder {
}

/// @inheritdoc SingleAssetRewarder
function onDeposit(uint relicId, uint depositAmount) external override onlyReliquary {
function onDeposit(
uint relicId,
uint depositAmount,
uint, // oldAmount,
uint, // oldLevel,
uint // newLevel
) external override onlyReliquary {
if (depositAmount >= minimum) {
uint _lastDepositTime = lastDepositTime[relicId];
uint timestamp = block.timestamp;
Expand All @@ -49,7 +55,10 @@ contract DepositBonusRewarder is SingleAssetRewarder {
/// @inheritdoc SingleAssetRewarder
function onWithdraw(
uint relicId,
uint //withdrawalAmount
uint, // withdrawalAmount,
uint, // oldAmount,
uint, // oldLevel,
uint // newLevel
) external override onlyReliquary {
uint _lastDepositTime = lastDepositTime[relicId];
delete lastDepositTime[relicId];
Expand Down Expand Up @@ -94,4 +103,34 @@ contract DepositBonusRewarder is SingleAssetRewarder {
claimed = false;
}
}

// Required overrides
function onSplit(
uint fromId,
uint newId,
uint amount,
uint fromAmount,
uint level
) external override {}

function onShift(
uint fromId,
uint toId,
uint amount,
uint oldFromAmount,
uint oldToAmount,
uint fromLevel,
uint oldToLevel,
uint newToLevel
) external override {}

function onMerge(
uint fromId,
uint toId,
uint fromAmount,
uint toAmount,
uint fromLevel,
uint oldToLevel,
uint newToLevel
) external override {}
}
Loading
Loading