-
Notifications
You must be signed in to change notification settings - Fork 1
/
XTT-ForeverLocker.sol
153 lines (123 loc) · 4.1 KB
/
XTT-ForeverLocker.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "./SafeERC20.sol";
/**
* @dev A token holder contract that will allow a beneficiary to extract the
* tokens after a given release time.
*
* Useful for simple vesting schedules like "advisors get all of their tokens
* after 1 year".
*/
contract TokenTimelock {
using SafeERC20 for IERC20;
// ERC20 basic token contract being held
IERC20 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
address private _unlocker;
// timestamp when token release is enabled
uint256 private _releaseTime;
constructor (IERC20 token_, address beneficiary_, uint256 releaseTime_) {
// solhint-disable-next-line not-rely-on-time
require(
releaseTime_ > block.timestamp,
"TokenTimelock: release time is before current time"
);
require(beneficiary_ != address(0), "beneficiary_: beneficiary is the zero address");
_token = token_;
_beneficiary = beneficiary_;
_unlocker = beneficiary_;
_releaseTime = releaseTime_;
}
/**
* @return the token being held.
*/
function token() public view virtual returns (IERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view virtual returns (address) {
return _beneficiary;
}
/**
* @return the unlocker of the tokens.
*/
function unlocker() public view virtual returns (address) {
return _unlocker;
}
/**
* @return the time when the tokens are released.
*/
function releaseTime() public view virtual returns (uint256) {
return _releaseTime;
}
/**
*@notice Extend Lock Time.
*/
//Declare an Event
event ExtendedLockTime(
address indexed from,
uint256 indexed oldValue,
uint256 indexed newValue
);
function extendLockTime(uint256 newReleaseTime_) external virtual {
require(_unlocker == msg.sender, "Ownable: caller is not the current unlocker");
require(
newReleaseTime_ > releaseTime(),
"TokenTimelock: new release time can't be before the current release time"
);
require(
newReleaseTime_ <= releaseTime() + 365 days,
"TokenTimelock: new release time can't be longer than the current release time + 365 days"
);
uint256 oldValue = _releaseTime;
_releaseTime = newReleaseTime_;
//Emit an event
emit ExtendedLockTime(msg.sender, oldValue, _releaseTime);
}
/**
*@notice Set new unlocker address.
*/
//Declare an Event
event SetNewUnlocker(
address indexed from,
address indexed oldUnlocker,
address indexed newUnlocker
);
function setUnlocker(address newUnlocker_) external virtual {
require(
_unlocker == msg.sender,
"Ownable: caller is not the current unlocker"
);
require(
newUnlocker_ != address(0),
"newUnlocker_: new UnLocker is the zero address"
);
address oldUnlocker = _unlocker;
_unlocker = newUnlocker_;
//Emit an event
emit SetNewUnlocker(msg.sender, oldUnlocker, _unlocker);
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
/*Removed Release Function*/
/*
function release(uint256 releasedValue_) external virtual {
// solhint-disable-next-line not-rely-on-time
require(
block.timestamp >= releaseTime(),
"TokenTimelock: current time is before release time"
);
uint256 amount = releasedValue_;//token().balanceOf(address(this));
require(amount > 0, "TokenTimelock: no tokens to release");
require(
unlocker() == msg.sender,
"Ownable: caller is not the current unlocker"
);
token().safeTransfer(beneficiary(), amount);
}
*/
}