Made some TokenVesting public functions private. (#1427)
* Made some TokenVesting public functions private.
* Fixed linter error.
(cherry picked from commit df3c113711)
This commit is contained in:
committed by
Leo Arias
parent
c5a8680a9c
commit
3b34436b44
@ -114,7 +114,7 @@ contract TokenVesting is Ownable {
|
|||||||
* @param token ERC20 token which is being vested
|
* @param token ERC20 token which is being vested
|
||||||
*/
|
*/
|
||||||
function release(IERC20 token) public {
|
function release(IERC20 token) public {
|
||||||
uint256 unreleased = releasableAmount(token);
|
uint256 unreleased = _releasableAmount(token);
|
||||||
|
|
||||||
require(unreleased > 0);
|
require(unreleased > 0);
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ contract TokenVesting is Ownable {
|
|||||||
|
|
||||||
uint256 balance = token.balanceOf(address(this));
|
uint256 balance = token.balanceOf(address(this));
|
||||||
|
|
||||||
uint256 unreleased = releasableAmount(token);
|
uint256 unreleased = _releasableAmount(token);
|
||||||
uint256 refund = balance.sub(unreleased);
|
uint256 refund = balance.sub(unreleased);
|
||||||
|
|
||||||
_revoked[token] = true;
|
_revoked[token] = true;
|
||||||
@ -150,15 +150,15 @@ contract TokenVesting is Ownable {
|
|||||||
* @dev Calculates the amount that has already vested but hasn't been released yet.
|
* @dev Calculates the amount that has already vested but hasn't been released yet.
|
||||||
* @param token ERC20 token which is being vested
|
* @param token ERC20 token which is being vested
|
||||||
*/
|
*/
|
||||||
function releasableAmount(IERC20 token) public view returns (uint256) {
|
function _releasableAmount(IERC20 token) private view returns (uint256) {
|
||||||
return vestedAmount(token).sub(_released[token]);
|
return _vestedAmount(token).sub(_released[token]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Calculates the amount that has already vested.
|
* @dev Calculates the amount that has already vested.
|
||||||
* @param token ERC20 token which is being vested
|
* @param token ERC20 token which is being vested
|
||||||
*/
|
*/
|
||||||
function vestedAmount(IERC20 token) public view returns (uint256) {
|
function _vestedAmount(IERC20 token) private view returns (uint256) {
|
||||||
uint256 currentBalance = token.balanceOf(this);
|
uint256 currentBalance = token.balanceOf(this);
|
||||||
uint256 totalBalance = currentBalance.add(_released[token]);
|
uint256 totalBalance = currentBalance.add(_released[token]);
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|||||||
it('should return the non-vested tokens when revoked by owner', async function () {
|
it('should return the non-vested tokens when revoked by owner', async function () {
|
||||||
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
|
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
|
||||||
|
|
||||||
const vested = await this.vesting.vestedAmount(this.token.address);
|
const vested = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
|
||||||
|
|
||||||
await this.vesting.revoke(this.token.address, { from: owner });
|
await this.vesting.revoke(this.token.address, { from: owner });
|
||||||
|
|
||||||
@ -125,23 +125,22 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|||||||
it('should keep the vested tokens when revoked by owner', async function () {
|
it('should keep the vested tokens when revoked by owner', async function () {
|
||||||
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
|
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
|
||||||
|
|
||||||
const vestedPre = await this.vesting.vestedAmount(this.token.address);
|
const vestedPre = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
|
||||||
|
|
||||||
await this.vesting.revoke(this.token.address, { from: owner });
|
await this.vesting.revoke(this.token.address, { from: owner });
|
||||||
|
|
||||||
const vestedPost = await this.vesting.vestedAmount(this.token.address);
|
const vestedPost = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
|
||||||
|
|
||||||
vestedPre.should.bignumber.equal(vestedPost);
|
vestedPre.should.bignumber.equal(vestedPost);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to be revoked a second time', async function () {
|
it('should fail to be revoked a second time', async function () {
|
||||||
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
|
|
||||||
|
|
||||||
await this.vesting.vestedAmount(this.token.address);
|
|
||||||
|
|
||||||
await this.vesting.revoke(this.token.address, { from: owner });
|
await this.vesting.revoke(this.token.address, { from: owner });
|
||||||
|
|
||||||
await shouldFail.reverting(this.vesting.revoke(this.token.address, { from: owner }));
|
await shouldFail.reverting(this.vesting.revoke(this.token.address, { from: owner }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function vestedAmount (total, now, start, cliffDuration, duration) {
|
||||||
|
return (now < start + cliffDuration) ? 0 : Math.round(total * (now - start) / duration);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user