forked from nucypher/nucypher-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft for dispenseRewardsForCycle() method
- Loading branch information
Showing
1 changed file
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity 0.8.23; | ||
pragma solidity ^0.8.0; | ||
|
||
contract TACoRewardsDispenser { | ||
uint256 public constant REWARDS_CALCULATION_BASE = 10000; | ||
uint256 public constant ONE_YEAR = 365 * 1 days; | ||
|
||
IERC20 public token; | ||
IProxy public claimableRewards; // TODO: what interface to use for claimabeRewards contract? | ||
IApplication public tacoApplication; | ||
// Rewards APY expressed wrt REWARDS_CALCULATION_BASE (e.g. 5% = 500) | ||
uint256 public rewardsAPY; | ||
|
||
constructor(IProxy _claimableRewards, IApplication) { | ||
constructor(IERC20 _token, IProxy _claimableRewards, IApplication _tacoApplication, uint256 _rewardsAPY) { | ||
Check failure on line 15 in contracts/contracts/TACoRewardsDispenser.sol
|
||
// TODO: we need some checks here using "require" | ||
token = _token; | ||
claimableRewards = _claimableRewards; | ||
tacoApplication = _tacoApplication; | ||
rewardsAPY = _rewardsAPY; | ||
} | ||
|
||
// TODO: what are the arguments? what is done here? | ||
function allocatedRewards () {} | ||
function dispenseRewardsForCycle() external { | ||
// This function can only be called once per rewards cycle, so it can be permissionless. | ||
uint256 periodFinish = tacoApplication.periodFinish(); | ||
require(block.timestamp >= periodFinish); | ||
|
||
// 1. Calculate rewards for this cycle | ||
uint256 rewardCycleDuration = tacoApplication.rewardDuration(); | ||
uint256 authorizedOverall = tacoApplication.authorizedOverall(); | ||
|
||
uint256 rewardsForCycle = authorizedOverall * rewardsAPY * rewardCycleDuration / ONE_YEAR / REWARDS_CALCULATION_BASE; | ||
Check failure on line 32 in contracts/contracts/TACoRewardsDispenser.sol
|
||
|
||
// 2. Get rewards from ClaimableRewards (or FutureRewards?) | ||
token.safeTransferFrom(claimableRewards, address(this), rewardsForCycle); | ||
|
||
// 3. Approve (invariant: before and after this TX this approval is always 0) | ||
token.approve(tacoApplication, rewardsForCycle); | ||
|
||
// 4. Push rewards for cycle | ||
tacoApplication.pushReward(rewardsForCycle); | ||
} | ||
} |