Last active
September 29, 2016 06:12
-
-
Save Gustav-Simonsson/8ed1f81752049fdaa27f3f685124a694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Simple vesting contract. amount of tokens `owner` can withdraw is | |
linear to how far they are in the vesting schedule. | |
E.g. if `period` is 4 years then after 2 years 50% can be withdrawn. | |
The vesting is continous, allowing `owner` to withdraw at any time. | |
*/ | |
pragma solidity ^0.4.2; | |
contract Vested { | |
address owner; | |
uint original_amount; | |
uint created; | |
uint cliff; | |
uint fully_vested; | |
function Vested(address _owner, uint period, uint _cliff) payable { | |
owner = _owner; | |
original_amount = msg.value; | |
created = now; | |
cliff = _cliff; | |
fully_vested = now + period; | |
} | |
function withdraw(uint amount) { | |
if (msg.sender != owner) { throw; } | |
if (now < (created + cliff)) { throw; } | |
uint allowed; | |
if (now >= fully_vested) { | |
allowed = this.balance; | |
} else { | |
// improve precision by mul with constant factor before div | |
uint mul = ((fully_vested - created) * 1000) / (now - created); | |
uint vested = (original_amount * mul) / 1000; | |
allowed = vested - (original_amount - this.balance); | |
} | |
if (amount > allowed) { throw; } | |
if (!owner.send(amount)) { throw; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment