From 2dd5a94e97353b144723054f1826fa268e3713b4 Mon Sep 17 00:00:00 2001 From: Manuel Montenegro Date: Thu, 19 Sep 2024 11:32:02 +0200 Subject: [PATCH 1/2] Add sketch of TACoRewardsDispenser contract --- contracts/contracts/TACoRewardsDispenser.sol | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 contracts/contracts/TACoRewardsDispenser.sol diff --git a/contracts/contracts/TACoRewardsDispenser.sol b/contracts/contracts/TACoRewardsDispenser.sol new file mode 100644 index 00000000..54c9b594 --- /dev/null +++ b/contracts/contracts/TACoRewardsDispenser.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +pragma solidity 0.8.23; + +contract TACoRewardsDispenser { + IProxy public claimableRewards; // TODO: what interface to use for claimabeRewards contract? + IApplication public tacoApplication; + + constructor(IProxy _claimableRewards, IApplication) { + // TODO: we need some checks here using "require" + claimableRewards = _claimableRewards; + tacoApplication = _tacoApplication; + } + + // TODO: what are the arguments? what is done here? + function allocatedRewards () {} +} From 023e19b18704e7d4a11179b685c01db29e958639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Thu, 19 Sep 2024 12:12:53 +0200 Subject: [PATCH 2/2] Draft for dispenseRewardsForCycle() method --- contracts/contracts/TACoRewardsDispenser.sol | 34 +++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/contracts/contracts/TACoRewardsDispenser.sol b/contracts/contracts/TACoRewardsDispenser.sol index 54c9b594..9f939295 100644 --- a/contracts/contracts/TACoRewardsDispenser.sol +++ b/contracts/contracts/TACoRewardsDispenser.sol @@ -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) { // 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; + + // 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); + } }