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
1697518d
Commit
1697518d
authored
Feb 10, 2017
by
Jorge Izquierdo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make vested stock calculation more testable
parent
93e7984c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
7 deletions
+10
-7
SafeMath.sol
contracts/SafeMath.sol
+0
-1
GrantableToken.sol
contracts/token/GrantableToken.sol
+10
-6
No files found.
contracts/SafeMath.sol
View file @
1697518d
...
@@ -26,4 +26,3 @@ contract SafeMath {
...
@@ -26,4 +26,3 @@ contract SafeMath {
if (!assertion) throw;
if (!assertion) throw;
}
}
}
}
contracts/token/GrantableToken.sol
View file @
1697518d
...
@@ -59,16 +59,20 @@ contract GrantableToken is StandardToken {
...
@@ -59,16 +59,20 @@ contract GrantableToken is StandardToken {
vested = vestedTokens(grant, uint64(now));
vested = vestedTokens(grant, uint64(now));
}
}
function vestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256 vestedTokens) {
function vestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
if (time < grant.cliff) return 0;
return calculateVestedTokens(grant.value, uint256(time), uint256(grant.start), uint256(grant.cliff), uint256(grant.vesting));
if (time > grant.vesting) return grant.value;
}
function calculateVestedTokens(uint256 tokens, uint256 time, uint256 start, uint256 cliff, uint256 vesting) constant returns (uint256 vestedTokens) {
if (time < cliff) return 0;
if (time > vesting) return tokens;
uint256 cliffTokens =
grant.value * uint256(grant.cliff - grant.start) / uint256(grant.vesting - grant.start
);
uint256 cliffTokens =
safeMul(tokens, (cliff - start) / (vesting - start)
);
vestedTokens = cliffTokens;
vestedTokens = cliffTokens;
uint256 vestingTokens = safeSub(
grant.value
, cliffTokens);
uint256 vestingTokens = safeSub(
tokens
, cliffTokens);
vestedTokens = safeAdd(vestedTokens, vestingTokens * (time -
uint256(grant.cliff)) / uint256(grant.vesting - grant.
start));
vestedTokens = safeAdd(vestedTokens, vestingTokens * (time -
cliff) / (vesting -
start));
}
}
function nonVestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
function nonVestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
...
...
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