Commit 1697518d by Jorge Izquierdo

Make vested stock calculation more testable

parent 93e7984c
...@@ -26,4 +26,3 @@ contract SafeMath { ...@@ -26,4 +26,3 @@ contract SafeMath {
if (!assertion) throw; if (!assertion) throw;
} }
} }
...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment