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

Feat/auto compounding schedules #224

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions contracts/badger-geyser/RewardsLogger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract RewardsLogger is AccessControlUpgradeable {
}

mapping(address => UnlockSchedule[]) public unlockSchedules;
mapping(address => UnlockSchedule[]) public autoCompoundingSchedules;

event UnlockScheduleSet(
address indexed beneficiary,
Expand All @@ -48,6 +49,29 @@ contract RewardsLogger is AccessControlUpgradeable {
uint256 indexed timestamp,
uint256 indexed blockNumber
);

event AutoCompoundingScheduleSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

what is an auto compounding schedule

address indexed beneficiary,
address token,
uint256 totalAmount,
uint256 start,
uint256 end,
uint256 duration,
uint256 indexed timestamp,
uint256 indexed blockNumber
);
event AutoCompoundingScheduleModified(
uint256 index,
address indexed beneficiary,
address token,
uint256 totalAmount,
uint256 start,
uint256 end,
uint256 duration,
uint256 indexed timestamp,
uint256 indexed blockNumber
);

event DiggPegRewards(address indexed beneficiary, uint256 response, uint256 rate, uint256 indexed timestamp, uint256 indexed blockNumber);

function initialize(address initialAdmin_, address initialManager_) external initializer {
Expand All @@ -64,6 +88,7 @@ contract RewardsLogger is AccessControlUpgradeable {

// ===== Permissioned Functions: Manager =====

// Tree Emissions
function setUnlockSchedule(
address beneficiary,
address token,
Expand All @@ -89,6 +114,32 @@ contract RewardsLogger is AccessControlUpgradeable {
emit UnlockScheduleModified(index, beneficiary, token, totalAmount, start, end, duration, block.number, block.timestamp);
}

// Auto-compounding Emissions
function setAutoCompoundingUnlockSchedule(
address beneficiary,
address token,
uint256 totalAmount,
uint256 start,
uint256 end,
uint256 duration
) external onlyManager {
autoCompoundingSchedules[beneficiary].push(UnlockSchedule(beneficiary, token, totalAmount, start, end, duration));
emit AutoCompoundingScheduleSet(beneficiary, token, totalAmount, start, end, duration, block.number, block.timestamp);
}

function modifyAutoCompoundingUnlockSchedule(
uint256 index,
address beneficiary,
address token,
uint256 totalAmount,
uint256 start,
uint256 end,
uint256 duration
) external onlyManager {
autoCompoundingSchedules[beneficiary][index] = UnlockSchedule(beneficiary, token, totalAmount, start, end, duration);
emit AutoCompoundingScheduleModified(index, beneficiary, token, totalAmount, start, end, duration, block.number, block.timestamp);
}

function setDiggPegRewards(
address beneficiary,
uint256 response,
Expand All @@ -102,9 +153,24 @@ contract RewardsLogger is AccessControlUpgradeable {
return unlockSchedules[beneficiary];
}

/// @dev Return all auto-compounding schedules for a given beneficiary
function getAllAutoCompoundingSchedulesFor(address beneficiary) external view returns (UnlockSchedule[] memory) {
return autoCompoundingSchedules[beneficiary];
}

/// @dev Return all unlock schedules for a given beneficiary + token
function getUnlockSchedulesFor(address beneficiary, address token) external view returns (UnlockSchedule[] memory) {
UnlockSchedule[] memory schedules = unlockSchedules[beneficiary];
return _filterSchedulesByToken(schedules, token);
}

/// @dev Return all auto-compounding schedules for a given beneficiary + token
function getAutoCompoundingSchedulesFor(address beneficiary, address token) external view returns (UnlockSchedule[] memory) {
UnlockSchedule[] memory schedules = autoCompoundingSchedules[beneficiary];
return _filterSchedulesByToken(schedules, token);
}

function _filterSchedulesByToken(UnlockSchedule[] memory schedules, address token) internal pure returns (UnlockSchedule[] memory) {
uint256 numMatchingEntries = 0;

// Determine how many matching entries there are
Expand Down