Skip to content

Instantly share code, notes, and snippets.

@anhgien
Created May 7, 2018 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhgien/55a7edd4887c36686484bbf619db8801 to your computer and use it in GitHub Desktop.
Save anhgien/55a7edd4887c36686484bbf619db8801 to your computer and use it in GitHub Desktop.
CTU Token
pragma solidity ^0.4.21;
import './TokenOffering.sol';
import './WithdrawTrack.sol';
contract ContractiumToken is TokenOffering, WithdrawTrack {
string public constant name = "Contractium";
string public constant symbol = "CTU";
uint8 public constant decimals = 18;
uint256 public constant INITIAL_SUPPLY = 3000000000 * (10 ** uint256(decimals));
uint256 public constant INITIAL_TOKEN_OFFERING = 900000000 * (10 ** uint256(decimals));
uint256 public constant INITIAL_BONUSRATE_ONE_ETH = 0;
uint256 public unitsOneEthCanBuy = 15000;
// total ether funds
uint256 internal totalWeiRaised;
function ContractiumToken() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
startOffering(INITIAL_TOKEN_OFFERING, INITIAL_BONUSRATE_ONE_ETH);
emit Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
function() public payable {
require(msg.sender != owner);
// number of tokens to sale in wei
uint256 amount = msg.value.mul(unitsOneEthCanBuy);
// amount of bonus tokens
uint256 amountBonus = msg.value.mul(bonusRateOneEth);
// amount with bonus value
amount = amount.add(amountBonus);
preValidatePurchase(amount);
require(balances[owner] >= amount);
totalWeiRaised = totalWeiRaised.add(msg.value);
// increase current amount of tokens offered
currentTokenOfferingRaised = currentTokenOfferingRaised.add(amount);
balances[owner] = balances[owner].sub(amount);
balances[msg.sender] = balances[msg.sender].add(amount);
emit Transfer(owner, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to owner
owner.transfer(msg.value);
}
}
pragma solidity ^0.4.21;
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
/**
* @title Offer to sell tokens
*/
contract TokenOffering is StandardToken, Ownable {
bool public offeringEnabled;
// maximum amount of tokens being sold in current offering session
uint256 public currentTotalTokenOffering;
// amount of tokens raised in current offering session
uint256 public currentTokenOfferingRaised;
// number of bonus tokens per one ETH
uint256 public bonusRateOneEth;
/**
* @dev
* @param _bonusRateOneEth number of bonus tokens per one ETH
*/
function setBonusRate(uint256 _bonusRateOneEth) public onlyOwner {
bonusRateOneEth = _bonusRateOneEth;
}
/**
* @dev Check for fundraising in current offering
* @param _amount amount of tokens in wei want to buy
* @return accept or not accept to fund
*/
// function isOfferingAccepted(uint256 _amount) internal view returns (bool) {
// require(_amount > 0);
// return (offeringEnabled && currentTokenOfferingRaised + _amount <= currentTotalTokenOffering);
// }
/**
* @dev Validation of fundraising in current offering
* @param _amount amount of tokens in wei want to buy
*/
function preValidatePurchase(uint256 _amount) internal {
require(_amount > 0);
require(offeringEnabled);
require(currentTokenOfferingRaised.add(_amount) <= currentTotalTokenOffering);
}
/**
* @dev Stop selling in current offering session
*/
function stopOffering() public onlyOwner {
offeringEnabled = false;
}
/**
* @dev Resume selling in current offering session
*/
function resumeOffering() public onlyOwner {
offeringEnabled = true;
}
/**
* @dev Start a new offering session
* @param _tokenOffering amount of token in offering session
* @param _bonusRateOneEth number of bonus tokens per one ETH
*/
function startOffering(uint256 _tokenOffering, uint256 _bonusRateOneEth) public onlyOwner returns (bool) {
require(_tokenOffering <= balances[owner]);
currentTokenOfferingRaised = 0;
currentTotalTokenOffering = _tokenOffering;
offeringEnabled = true;
setBonusRate(_bonusRateOneEth);
return true;
}
}
pragma solidity ^0.4.21;
// pragma experimental ABIEncoderV2;
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
contract WithdrawTrack is StandardToken, Ownable {
struct TrackInfo {
address to;
uint256 amountToken;
string withdrawId;
}
mapping(string => TrackInfo) withdrawTracks;
function withdrawToken(address _to, uint256 _amountToken, string _withdrawId) public onlyOwner returns (bool) {
bool result = transfer(_to, _amountToken);
if (result) {
withdrawTracks[_withdrawId] = TrackInfo(_to, _amountToken, _withdrawId);
}
return result;
}
function withdrawTrackOf(string _withdrawId) public view returns (address to, uint256 amountToken) {
TrackInfo track = withdrawTracks[_withdrawId];
return (track.to, track.amountToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment