update vesting

This commit is contained in:
poma 2021-08-27 15:48:35 +03:00
parent 3bf91737c3
commit 9f03d790e7
No known key found for this signature in database
GPG Key ID: BA20CB01FE165657
2 changed files with 18 additions and 12 deletions

View File

@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./ENS.sol";
/**
* @title Vesting
@ -14,16 +13,17 @@ import "./ENS.sol";
* typical vesting scheme, with a cliff and vesting period. Optionally revocable by the
* owner.
*/
contract Vesting is EnsResolve {
contract Vesting {
using SafeERC20 for IERC20;
using SafeMath for uint256;
uint256 public constant SECONDS_PER_MONTH = 30 days;
event Released(uint256 amount);
event BeneficiaryChanged(address newBeneficiary);
// beneficiary of tokens after they are released
address public immutable beneficiary;
address public beneficiary;
IERC20 public immutable token;
uint256 public immutable cliffInMonths;
@ -40,16 +40,16 @@ contract Vesting is EnsResolve {
* @param _durationInMonths duration in months of the period in which the tokens will vest
*/
constructor(
bytes32 _token,
address _token,
address _beneficiary,
uint256 _startTimestamp,
uint256 _cliffInMonths,
uint256 _durationInMonths
) public {
require(_beneficiary != address(0), "Beneficiary cannot be empty");
require(_cliffInMonths <= _durationInMonths, "Cliff is greater than duration");
require(_cliffInMonths <= _durationInMonths, "Cliff cannot be greater than duration");
token = IERC20(resolve(_token));
token = IERC20(_token);
beneficiary = _beneficiary;
durationInMonths = _durationInMonths;
cliffInMonths = _cliffInMonths;
@ -69,6 +69,17 @@ contract Vesting is EnsResolve {
emit Released(vested);
}
/**
* @notice Allows beneficiary to change his/her address.
* @param _beneficiary address of the beneficiary to whom vested tokens are transferred
*/
function setBeneficiary(address _beneficiary) public {
require(msg.sender == beneficiary, "Not authorized");
require(_beneficiary != address(0), "Beneficiary cannot be empty");
beneficiary = _beneficiary;
emit BeneficiaryChanged(_beneficiary);
}
/**
* @dev Calculates the amount that has already vested but hasn't been released yet.
*/
@ -94,7 +105,6 @@ contract Vesting is EnsResolve {
uint256 vested = totalBalance.mul(elapsedMonths).div(durationInMonths);
uint256 unreleased = vested.sub(released);
// currentBalance can be 0 in case of vesting being revoked earlier.
return Math.min(currentBalance, unreleased);
}
}

View File

@ -8,17 +8,13 @@ import "./Timestamp.sol";
contract VestingMock is Vesting, Timestamp {
constructor(
bytes32 _token,
address _token,
address _beneficiary,
uint256 _startTimestamp,
uint256 _cliffInMonths,
uint256 _durationInMonths
) public Vesting(_token, _beneficiary, _startTimestamp, _cliffInMonths, _durationInMonths) {}
function resolve(bytes32 addr) public view override returns (address) {
return address(uint160(uint256(addr) >> (12 * 8)));
}
function blockTimestamp() public view override(Timestamp, Vesting) returns (uint256) {
return Timestamp.blockTimestamp();
}