Created
January 28, 2018 17:09
-
-
Save bitdollarfund/d11175ea855b54b0818960bc0c02305a to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity 0.4.18; | |
import './Token.sol'; | |
import './SafeMath.sol'; | |
/** | |
* @title BTDVesting1Yr | |
* @dev BTDVesting1Yr is a token holder contract that allows the specified beneficiary | |
* to claim stored tokens after 3 month intervals | |
*/ | |
contract BTDVesting1Yr is SafeMath { | |
address public beneficiary; | |
uint256 public fundingEndBlock; | |
bool private initClaim = false; // state tracking variables | |
uint256 public firstRelease; // vesting times | |
bool private firstDone = false; | |
uint256 public secondRelease; | |
bool private secondDone = false; | |
uint256 public thirdRelease; | |
bool private thirdDone = false; | |
uint256 public fourthRelease; | |
Token public ERC20Token; // ERC20 basic token contract to hold | |
enum Stages { | |
initClaim, | |
firstRelease, | |
secondRelease, | |
thirdRelease, | |
fourthRelease | |
} | |
Stages public stage = Stages.initClaim; | |
modifier atStage(Stages _stage) { | |
if(stage == _stage) _; | |
} | |
function BTDVesting1Yr(address _token, uint256 fundingEndBlockInput) public { | |
require(_token != address(0)); | |
beneficiary = msg.sender; | |
fundingEndBlock = fundingEndBlockInput; | |
ERC20Token = Token(_token); | |
} | |
function changeBeneficiary(address newBeneficiary) external { | |
require(newBeneficiary != address(0)); | |
require(msg.sender == beneficiary); | |
beneficiary = newBeneficiary; | |
} | |
function updateFundingEndBlock(uint256 newFundingEndBlock) public { | |
require(msg.sender == beneficiary); | |
require(block.number < fundingEndBlock); | |
require(block.number < newFundingEndBlock); | |
fundingEndBlock = newFundingEndBlock; | |
} | |
function checkBalance() constant public returns (uint256 tokenBalance) { | |
return ERC20Token.balanceOf(this); | |
} | |
// in total 15% of BTD tokens will be sent to this contract | |
// EXPENSE ALLOCATION: 6.0% | TEAM ALLOCATION: 9.0% (vest over 1 years) | |
// 3.0% - Marketing | initalPayment: 1.8% | |
// 1% - Security | firstRelease: 1.8% | |
// 1% - Legal | secondRelease: 1.8% | |
// 0.5% - Advisors | thirdRelease: 1.8% | |
// 0.5% - Bounty | fourthRelease: 1.8% | |
// initial claim is tot expenses + initial team payment | |
// initial claim is thus (6.0 + 1.8)/15 = 52.0% of BTD tokens sent here | |
// each other release (for team) is 12.0% of tokens sent here | |
function claim() external { | |
require(msg.sender == beneficiary); | |
require(block.number > fundingEndBlock); | |
uint256 balance = ERC20Token.balanceOf(this); | |
// in reverse order so stages changes don't carry within one claim | |
fourth_release(balance); | |
third_release(balance); | |
second_release(balance); | |
first_release(balance); | |
init_claim(balance); | |
} | |
function nextStage() private { | |
stage = Stages(uint256(stage) + 1); | |
} | |
function init_claim(uint256 balance) private atStage(Stages.initClaim) { | |
firstRelease = now + 13 weeks; // assign 4 claiming times | |
secondRelease = firstRelease + 13 weeks; | |
thirdRelease = secondRelease + 13 weeks; | |
fourthRelease = thirdRelease + 13 weeks; | |
uint256 amountToTransfer = safeMul(balance, 52000000000) / 100000000000; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // now 48.0% tokens left | |
nextStage(); | |
} | |
function first_release(uint256 balance) private atStage(Stages.firstRelease) { | |
require(now > firstRelease); | |
uint256 amountToTransfer = balance / 4; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // send 25 % of team releases | |
nextStage(); | |
} | |
function second_release(uint256 balance) private atStage(Stages.secondRelease) { | |
require(now > secondRelease); | |
uint256 amountToTransfer = balance / 3; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // send 25 % of team releases | |
nextStage(); | |
} | |
function third_release(uint256 balance) private atStage(Stages.thirdRelease) { | |
require(now > thirdRelease); | |
uint256 amountToTransfer = balance / 2; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // send 25 % of team releases | |
nextStage(); | |
} | |
function fourth_release(uint256 balance) private atStage(Stages.fourthRelease) { | |
require(now > fourthRelease); | |
ERC20Token.transfer(beneficiary, balance); // send remaining 25 % of team releases | |
} | |
function claimOtherTokens(address _token) external { | |
require(msg.sender == beneficiary); | |
require(_token != address(0)); | |
Token token = Token(_token); | |
require(token != ERC20Token); | |
uint256 balance = token.balanceOf(this); | |
token.transfer(beneficiary, balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment