-
Notifications
You must be signed in to change notification settings - Fork 5
/
AuraPenaltyForwarder.sol
58 lines (46 loc) · 1.82 KB
/
AuraPenaltyForwarder.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
import { IExtraRewardsDistributor } from "./Interfaces.sol";
import { IERC20 } from "@openzeppelin/contracts-0.8/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts-0.8/token/ERC20/utils/SafeERC20.sol";
/**
* @title AuraPenaltyForwarder
* @dev Receives a given token and forwards it on to a distribution contract. Used during
* the bootstrapping period to forward AURA rewards to the extra rewards distributor.
*/
contract AuraPenaltyForwarder {
using SafeERC20 for IERC20;
IExtraRewardsDistributor public immutable distributor;
IERC20 public immutable token;
uint256 public immutable distributionDelay;
uint256 public lastDistribution;
event Forwarded(uint256 amount);
/**
* @dev During deployment approves the distributor to spend all tokens
* @param _distributor Contract that will distribute tokens
* @param _token Token to be distributed
* @param _delay Delay between each distribution trigger
*/
constructor(
address _distributor,
address _token,
uint256 _delay
) {
distributor = IExtraRewardsDistributor(_distributor);
token = IERC20(_token);
distributionDelay = _delay;
lastDistribution = block.timestamp;
token.safeApprove(address(distributor), type(uint256).max);
}
/**
* @dev Forwards the complete balance of token in this contract to the distributor
*/
function forward() public {
require(block.timestamp > lastDistribution + distributionDelay, "!elapsed");
lastDistribution = block.timestamp;
uint256 bal = token.balanceOf(address(this));
require(bal > 0, "!empty");
distributor.addReward(address(token), bal);
emit Forwarded(bal);
}
}