Skip to content

Commit

Permalink
Draft for dispenseRewardsForCycle() method
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Sep 19, 2024
1 parent 2dd5a94 commit 023e19b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions contracts/contracts/TACoRewardsDispenser.sol
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;

Check failure on line 8 in contracts/contracts/TACoRewardsDispenser.sol

View workflow job for this annotation

GitHub Actions / linting

Delete ····
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

View workflow job for this annotation

GitHub Actions / linting

Replace IERC20·_token,·IProxy·_claimableRewards,·IApplication·_tacoApplication,·uint256·_rewardsAPY with ⏎········IERC20·_token,⏎········IProxy·_claimableRewards,⏎········IApplication·_tacoApplication,⏎········uint256·_rewardsAPY⏎····
// TODO: we need some checks here using "require"
token = _token;
claimableRewards = _claimableRewards;
tacoApplication = _tacoApplication;
rewardsAPY = _rewardsAPY;

Check failure on line 20 in contracts/contracts/TACoRewardsDispenser.sol

View workflow job for this annotation

GitHub Actions / linting

Delete ·
}

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

Check failure on line 26 in contracts/contracts/TACoRewardsDispenser.sol

View workflow job for this annotation

GitHub Actions / linting

Provide an error message for require

// 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

View workflow job for this annotation

GitHub Actions / linting

Replace authorizedOverall·*·rewardsAPY·*·rewardCycleDuration·/·ONE_YEAR·/ with (authorizedOverall·*·rewardsAPY·*·rewardCycleDuration)·/⏎············ONE_YEAR·/⏎···········

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

0 comments on commit 023e19b

Please sign in to comment.