-
Notifications
You must be signed in to change notification settings - Fork 36
/
TreasuryVester.sol
62 lines (50 loc) · 1.87 KB
/
TreasuryVester.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
59
60
61
62
pragma solidity 0.6.12;
import "./SafeMath.sol";
contract TreasuryVester {
using SafeMath for uint;
address public immutable gtc;
address public recipient;
uint public immutable vestingAmount;
uint public immutable vestingBegin;
uint public immutable vestingCliff;
uint public immutable vestingEnd;
uint public lastUpdate;
constructor(
address gtc_,
address recipient_,
uint vestingAmount_,
uint vestingBegin_,
uint vestingCliff_,
uint vestingEnd_
) public {
require(vestingBegin_ >= block.timestamp, 'TreasuryVester::constructor: vesting begin too early');
require(vestingCliff_ >= vestingBegin_, 'TreasuryVester::constructor: cliff is too early');
require(vestingEnd_ > vestingCliff_, 'TreasuryVester::constructor: end is too early');
gtc = gtc_;
recipient = recipient_;
vestingAmount = vestingAmount_;
vestingBegin = vestingBegin_;
vestingCliff = vestingCliff_;
vestingEnd = vestingEnd_;
lastUpdate = vestingBegin_;
}
function setRecipient(address recipient_) public {
require(msg.sender == recipient, 'TreasuryVester::setRecipient: unauthorized');
recipient = recipient_;
}
function claim() public {
require(block.timestamp >= vestingCliff, 'TreasuryVester::claim: not time yet');
uint amount;
if (block.timestamp >= vestingEnd) {
amount = IGtc(gtc).balanceOf(address(this));
} else {
amount = vestingAmount.mul(block.timestamp - lastUpdate).div(vestingEnd - vestingBegin);
lastUpdate = block.timestamp;
}
IGtc(gtc).transfer(recipient, amount);
}
}
interface IGtc {
function balanceOf(address account) external view returns (uint);
function transfer(address dst, uint rawAmount) external returns (bool);
}