Skip to content

Instantly share code, notes, and snippets.

@dnzdlklc
Last active May 3, 2023 13:34
Show Gist options
  • Save dnzdlklc/f59799e8d8a42caa6983e66e9a618713 to your computer and use it in GitHub Desktop.
Save dnzdlklc/f59799e8d8a42caa6983e66e9a618713 to your computer and use it in GitHub Desktop.
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ILocker.sol";
import "./interfaces/IVoter.sol";
contract EmissionsDepositor is Ownable {
IERC20 public token;
uint256 public constant amount = 100 * (10**6) * (10**18); // 100m MRHB reserved
uint256 constant DAY = 86400;
uint256 public constant weeksInYear = 52;
uint256 public constant years = 4;
uint256 public dc;
// Locker contract responsible for locks
ILocker public immutable locker;
// Voter contract responsible for proposal tracking
IVoter public immutable voter;
// To track when last transfer was made i.e. transfers only once per week
uint256 public lastTransferWeek;
constructor(
address _token,
address _locker,
address _voter,
uint256 _dc
) {
require(_dc <= 10**18, "Dc should be between 0 and 1");
token = IERC20(_token);
locker = ILocker(_locker);
voter = IVoter(_voter);
dc = _dc;
}
function _isThursday() internal view returns (bool) {
uint256 week = locker.getWeek();
uint256 weekStartTimestamp = locker.startTime() + week * WEEK;
uint256 dayOfWeek = (weekStartTimestamp / DAY) % 7;
return dayOfWeek == 3;
}
function _getWav() internal view returns (uint256) {
return amount / (weeksInYear * years);
}
function _getMintAmount(uint256 week) internal view returns (uint256) {
uint256 wav = _getWav();
uint256 numerator = 52 * years + 1 - 2 * week;
uint256 denominator = 52 * years;
return wav * (1 - (numerator * dc) / denominator);
}
function transferToVoter() external {
uint256 currentWeek = locker.getWeek();
require(currentWeek != lastTransferWeek, "Transfer already done for this week");
require(_isThursday(), "Can only transfer on Thursdays");
uint256 mintAmount = _getMintAmount(currentWeek);
require(token.balanceOf(address(this)) >= mintAmount, "Insufficient token balance");
token.transfer(voter, mintAmount);
lastTransferWeek = currentWeek;
}
}
@dnzdlklc
Copy link
Author

dnzdlklc commented May 3, 2023

Needs events and withdraw function to withdraw back to given multisig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment