Created
January 28, 2018 17:15
-
-
Save bitdollarfund/3552f1c8e6234f137e24d7c5d125e78f 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 BTDVesting4Wk | |
* @dev BTDVesting4Wk is a token holder contract that allows the specified beneficiary | |
* to claim stored tokens after 1 week intervals | |
*/ | |
contract BTDVesting4Wk 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 BTDVesting4Wk(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); | |
} | |
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 + 1 weeks; // assign 4 claiming times | |
secondRelease = firstRelease + 1 weeks; | |
thirdRelease = secondRelease + 1 weeks; | |
fourthRelease = thirdRelease + 1 weeks; | |
uint256 amountToTransfer = safeMul(balance, 20000000000) / 100000000000; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // now 80.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 % | |
nextStage(); | |
} | |
function second_release(uint256 balance) private atStage(Stages.secondRelease) { | |
require(now > secondRelease); | |
uint256 amountToTransfer = balance / 3; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // send 25 % | |
nextStage(); | |
} | |
function third_release(uint256 balance) private atStage(Stages.thirdRelease) { | |
require(now > thirdRelease); | |
uint256 amountToTransfer = balance / 2; | |
ERC20Token.transfer(beneficiary, amountToTransfer); // send 25 % | |
nextStage(); | |
} | |
function fourth_release(uint256 balance) private atStage(Stages.fourthRelease) { | |
require(now > fourthRelease); | |
ERC20Token.transfer(beneficiary, balance); // send remaining 25 % | |
} | |
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