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
f8124337
Commit
f8124337
authored
May 21, 2017
by
Jorge Izquierdo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactor and documentation
parent
713b4722
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
35 deletions
+34
-35
VestedToken.sol
contracts/token/VestedToken.sol
+34
-35
No files found.
contracts/token/VestedToken.sol
View file @
f8124337
pragma solidity ^0.4.8;
import "./StandardToken.sol";
import "./TransferableToken.sol";
contract VestedToken is StandardToken, TransferableToken {
struct TokenGrant {
address granter;
uint256 value;
address granter;
// 20 bytes
uint256 value;
// 32 bytes
uint64 cliff;
uint64 vesting;
uint64 start;
uint64 start;
// 3 * 8 = 24 bytes
bool revokable;
bool burnsOnRevoke;
}
bool burnsOnRevoke;
// 2 * 1 = 2 bits? or 2 bytes?
}
// total 78 bytes = 3 sstore per operation (32 per sstore)
mapping (address => TokenGrant[]) public grants;
event NewTokenGrant(address indexed from, address indexed to, uint256 value, uint256 grantId);
function grantVestedTokens(
address _to,
uint256 _value,
...
...
@@ -24,34 +25,32 @@ contract VestedToken is StandardToken, TransferableToken {
uint64 _cliff,
uint64 _vesting,
bool _revokable,
bool _burnsOnRevoke) {
bool _burnsOnRevoke
) public {
if (_cliff < _start) {
throw;
}
if (_vesting < _start) {
throw;
}
if (_vesting < _cliff) {
// Check for date inconsistencies that may cause unexpected behavior
if (_cliff < _start || _vesting < _cliff) {
throw;
}
grants[_to].push(
TokenGrant(
msg.sender,
_value,
_cliff,
_vesting,
_start,
_revokable,
_burnsOnRevoke
)
);
uint id =
grants[_to].push(
TokenGrant(
_revokable ? msg.sender : 0, // avoid storing an extra 20 bytes when it is non-revokable
_value,
_cliff,
_vesting,
_start,
_revokable,
_burnsOnRevoke
)
);
transfer(_to, _value);
NewTokenGrant(msg.sender, _to, _value, id);
}
function revokeTokenGrant(address _holder, uint _grantId) {
function revokeTokenGrant(address _holder, uint _grantId)
public
{
TokenGrant grant = grants[_holder][_grantId];
if (!grant.revokable) { // Check if grant was revokable
...
...
@@ -76,6 +75,15 @@ contract VestedToken is StandardToken, TransferableToken {
Transfer(_holder, receiver, nonVested);
}
function transferableTokens(address holder, uint64 time) constant public returns (uint256 nonVested) {
uint256 grantIndex = tokenGrantsCount(holder);
for (uint256 i = 0; i < grantIndex; i++) {
nonVested = safeAdd(nonVested, nonVestedTokens(grants[holder][i], time));
}
return min256(safeSub(balances[holder], nonVested), super.transferableTokens(holder, time));
}
function tokenGrantsCount(address _holder) constant returns (uint index) {
return grants[_holder].length;
}
...
...
@@ -138,13 +146,4 @@ contract VestedToken is StandardToken, TransferableToken {
date = max64(grants[holder][i].vesting, date);
}
}
function transferableTokens(address holder, uint64 time) constant public returns (uint256 nonVested) {
uint256 grantIndex = grants[holder].length;
for (uint256 i = 0; i < grantIndex; i++) {
nonVested = safeAdd(nonVested, nonVestedTokens(grants[holder][i], time));
}
return min256(safeSub(balances[holder], nonVested), super.transferableTokens(holder, time));
}
}
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