Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
fff8e040
Commit
fff8e040
authored
Oct 13, 2017
by
Martín Triay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TokenVesting] vestedAmount returns the historical vested amount
parent
74636b73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
TokenVesting.sol
contracts/token/TokenVesting.sol
+21
-16
TokenVesting.js
test/TokenVesting.js
+1
-2
No files found.
contracts/token/TokenVesting.sol
View file @
fff8e040
...
...
@@ -57,14 +57,15 @@ contract TokenVesting is Ownable {
*/
function release(ERC20Basic token) public {
uint256 vested = vestedAmount(token);
uint256 unreleased = releasableAmount(token);
require(
vest
ed > 0);
require(
unreleas
ed > 0);
token.safeTransfer(beneficiary,
vest
ed);
token.safeTransfer(beneficiary,
unreleas
ed);
released[token] = released[token].add(
vest
ed);
released[token] = released[token].add(
unreleas
ed);
Released(
vest
ed);
Released(
unreleas
ed);
}
/**
...
...
@@ -78,12 +79,12 @@ contract TokenVesting is Ownable {
uint256 balance = token.balanceOf(this);
uint256
vested = vested
Amount(token);
uint256
vesting = balance - vested
;
uint256
unreleased = releasable
Amount(token);
uint256
refund = balance.sub(unreleased)
;
revoked[token] = true;
token.safeTransfer(owner,
vesting
);
token.safeTransfer(owner,
refund
);
Revoked();
}
...
...
@@ -92,20 +93,24 @@ contract TokenVesting is Ownable {
* @dev Calculates the amount that has already vested but hasn't been released yet.
* @param token ERC20 token which is being vested
*/
function releasableAmount(ERC20Basic token) public constant returns (uint256) {
return vestedAmount(token).sub(released[token]);
}
/**
* @dev Calculates the amount that has already vested.
* @param token ERC20 token which is being vested
*/
function vestedAmount(ERC20Basic token) public constant returns (uint256) {
uint256 currentBalance = token.balanceOf(this);
uint256 totalBalance = currentBalance.add(released[token]);
if (now < cliff) {
return 0;
} else if (now >= start + duration || revoked[token]) {
return to
ken.balanceOf(this)
;
return to
talBalance
;
} else {
uint256 currentBalance = token.balanceOf(this);
uint256 totalBalance = currentBalance.add(released[token]);
uint256 vested = totalBalance.mul(now - start).div(duration);
uint256 unreleased = vested.sub(released[token]);
// currentBalance can be 0 in case of vesting being revoked earlier.
return Math.min256(currentBalance, unreleased);
return totalBalance.mul(now - start).div(duration);
}
}
}
test/TokenVesting.js
View file @
fff8e040
...
...
@@ -83,12 +83,11 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
await
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
12
));
const
vested
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
const
balance
=
await
this
.
token
.
balanceOf
(
this
.
vesting
.
address
);
await
this
.
vesting
.
revoke
(
this
.
token
.
address
,
{
from
:
owner
});
const
ownerBalance
=
await
this
.
token
.
balanceOf
(
owner
);
ownerBalance
.
should
.
bignumber
.
equal
(
balance
.
sub
(
vested
));
ownerBalance
.
should
.
bignumber
.
equal
(
amount
.
sub
(
vested
));
});
it
(
'should keep the vested tokens when revoked by owner'
,
async
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment