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
647fc139
Commit
647fc139
authored
Oct 11, 2017
by
Francisco Giordano
Committed by
GitHub
Oct 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #492 from frangio/fix-vesting-revoke
TokenVesting bugfix
parents
5aba967d
d5e0714f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
TokenVesting.sol
contracts/token/TokenVesting.sol
+21
-13
TokenVesting.js
test/TokenVesting.js
+15
-6
No files found.
contracts/token/TokenVesting.sol
View file @
647fc139
pragma solidity ^0.4.11;
pragma solidity ^0.4.11;
import './ERC20Basic.sol';
import './ERC20Basic.sol';
import './SafeERC20.sol';
import '../ownership/Ownable.sol';
import '../ownership/Ownable.sol';
import '../math/Math.sol';
import '../math/Math.sol';
import '../math/SafeMath.sol';
import '../math/SafeMath.sol';
...
@@ -13,20 +14,22 @@ import '../math/SafeMath.sol';
...
@@ -13,20 +14,22 @@ import '../math/SafeMath.sol';
*/
*/
contract TokenVesting is Ownable {
contract TokenVesting is Ownable {
using SafeMath for uint256;
using SafeMath for uint256;
using SafeERC20 for ERC20Basic;
event Released(uint256 amount);
event Released(uint256 amount);
event Revoked();
event Revoked();
// beneficiary of tokens after they are released
// beneficiary of tokens after they are released
address beneficiary;
address
public
beneficiary;
uint256 cliff;
uint256
public
cliff;
uint256 start;
uint256
public
start;
uint256 duration;
uint256
public
duration;
bool revocable;
bool
public
revocable;
mapping (address => uint256) released;
mapping (address => uint256) public released;
mapping (address => bool) public revoked;
/**
/**
* @dev Creates a vesting contract that vests its balance of any ERC20 token to the
* @dev Creates a vesting contract that vests its balance of any ERC20 token to the
...
@@ -52,12 +55,12 @@ contract TokenVesting is Ownable {
...
@@ -52,12 +55,12 @@ contract TokenVesting is Ownable {
* @notice Transfers vested tokens to beneficiary.
* @notice Transfers vested tokens to beneficiary.
* @param token ERC20 token which is being vested
* @param token ERC20 token which is being vested
*/
*/
function release(ERC20Basic token) {
function release(ERC20Basic token)
public
{
uint256 vested = vestedAmount(token);
uint256 vested = vestedAmount(token);
require(vested > 0);
require(vested > 0);
token.
t
ransfer(beneficiary, vested);
token.
safeT
ransfer(beneficiary, vested);
released[token] = released[token].add(vested);
released[token] = released[token].add(vested);
...
@@ -65,17 +68,22 @@ contract TokenVesting is Ownable {
...
@@ -65,17 +68,22 @@ contract TokenVesting is Ownable {
}
}
/**
/**
* @notice Allows the owner to revoke the vesting. Tokens already vested remain in the contract.
* @notice Allows the owner to revoke the vesting. Tokens already vested
* remain in the contract, the rest are returned to the owner.
* @param token ERC20 token which is being vested
* @param token ERC20 token which is being vested
*/
*/
function revoke(ERC20Basic token) onlyOwner {
function revoke(ERC20Basic token)
public
onlyOwner {
require(revocable);
require(revocable);
require(!revoked[token]);
uint256 balance = token.balanceOf(this);
uint256 balance = token.balanceOf(this);
uint256 vested = vestedAmount(token);
uint256 vested = vestedAmount(token);
uint256 vesting = balance - vested;
token.transfer(owner, balance - vested);
revoked[token] = true;
token.safeTransfer(owner, vesting);
Revoked();
Revoked();
}
}
...
@@ -84,10 +92,10 @@ contract TokenVesting is Ownable {
...
@@ -84,10 +92,10 @@ 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 vestedAmount(ERC20Basic token) constant returns (uint256) {
function vestedAmount(ERC20Basic token)
public
constant returns (uint256) {
if (now < cliff) {
if (now < cliff) {
return 0;
return 0;
} else if (now >= start + duration) {
} else if (now >= start + duration
|| revoked[token]
) {
return token.balanceOf(this);
return token.balanceOf(this);
} else {
} else {
uint256 currentBalance = token.balanceOf(this);
uint256 currentBalance = token.balanceOf(this);
...
...
test/TokenVesting.js
View file @
647fc139
...
@@ -80,8 +80,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
...
@@ -80,8 +80,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
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
1
));
await
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
12
));
await
this
.
vesting
.
release
(
this
.
token
.
address
);
const
vested
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
const
vested
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
const
balance
=
await
this
.
token
.
balanceOf
(
this
.
vesting
.
address
);
const
balance
=
await
this
.
token
.
balanceOf
(
this
.
vesting
.
address
);
...
@@ -93,15 +92,25 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
...
@@ -93,15 +92,25 @@ 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
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
1
));
await
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
12
));
await
this
.
vesting
.
release
(
this
.
token
.
address
);
const
vestedPre
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
await
this
.
vesting
.
revoke
(
this
.
token
.
address
,
{
from
:
owner
});
const
vestedPost
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
vestedPre
.
should
.
bignumber
.
equal
(
vestedPost
);
});
it
(
'should fail to be revoked a second time'
,
async
function
()
{
await
increaseTimeTo
(
this
.
start
+
this
.
cliff
+
duration
.
weeks
(
12
));
const
vested
=
await
this
.
vesting
.
vestedAmount
(
this
.
token
.
address
);
const
vested
=
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
});
const
balance
=
await
this
.
token
.
balanceOf
(
this
.
vesting
.
address
);
await
this
.
vesting
.
revoke
(
this
.
token
.
address
,
{
from
:
owner
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
balance
.
should
.
bignumber
.
equal
(
vested
);
});
});
});
});
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