ERC20时间锁

使用https://github.com/OpenZeppelin/openzeppelin-contracts 中的

openzeppelin-contracts/contracts/token/ERC20/TokenTimelock.sol,为每个人放置 release 的时间和数量。

使用说明整理文档==>link

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
pragma solidity ^0.5.0;

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".
*
* For a more complete vesting schedule, see {TokenVesting}.
*/
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;

// timestamp when token release is enabled
uint256 private _releaseTime;

constructor (IERC20 token, address beneficiary, uint256 releaseTime) public {
// solhint-disable-next-line not-rely-on-time
require(releaseTime > block.timestamp, "TokenTimelock: release time is before current time");
_token = token;
_beneficiary = beneficiary;
_releaseTime = releaseTime;
}

/**
* @return the token being held.
*/
function token() public view returns (IERC20) {
return _token;
}

/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}

/**
* @return the time when the tokens are released.
*/
function releaseTime() public view returns (uint256) {
return _releaseTime;
}

/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
// solhint-disable-next-line not-rely-on-time
require(block.timestamp >= _releaseTime, "TokenTimelock: current time is before release time");

uint256 amount = _token.balanceOf(address(this));
require(amount > 0, "TokenTimelock: no tokens to release");

_token.safeTransfer(_beneficiary, amount);
}
}