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

Add sketch of TACoRewardsDispenser contract #337

Open
wants to merge 2 commits into
base: main
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
43 changes: 43 additions & 0 deletions contracts/contracts/TACoRewardsDispenser.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

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(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 ·
}

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