Last active
October 7, 2017 20:14
-
-
Save NarbonneCryptoBank/2caa57b2caeb7f4d82ba86241b4c1b32 to your computer and use it in GitHub Desktop.
Narbonne Credit Coin (NCC)
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.16; | |
contract owned { | |
address public owner; | |
address public candidate; | |
function owned() payable { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require(owner == msg.sender); | |
_; | |
} | |
function changeOwner(address _owner) onlyOwner public { | |
require(_owner != 0); | |
candidate = _owner; | |
} | |
function confirmOwner() public { | |
assert(candidate != 0x0); | |
require(candidate == msg.sender); | |
owner = candidate; | |
delete candidate; | |
} | |
} | |
contract SafeMath { | |
function safeSub(uint a, uint b) internal returns (uint) { | |
assert(b <= a); | |
return a - b; | |
} | |
function safeAdd(uint a, uint b) internal returns (uint) { | |
uint c = a + b; | |
assert(c >= a && c >= b); | |
return c; | |
} | |
} | |
contract ERC20 { | |
uint public totalSupply; | |
function balanceOf( address who ) constant returns (uint value); | |
function allowance( address owner, address spender ) constant returns (uint _allowance); | |
function transfer( address to, uint value) returns (bool ok); | |
function transferFrom( address from, address to, uint value) returns (bool ok); | |
function approve( address spender, uint value ) returns (bool ok); | |
event Transfer( address indexed from, address indexed to, uint value); | |
event Approval( address indexed owner, address indexed spender, uint value); | |
} | |
contract Crowdsale is owned, ERC20, SafeMath { | |
uint256 public totalSupply; | |
mapping(address => uint256) balances; | |
enum State { Disabled, Crowdsale, Active } | |
State public contract_state = State.Disabled; | |
uint public startTime; | |
event NewState(State state); | |
modifier crowdsaleState { | |
require(contract_state == State.Crowdsale); | |
_; | |
} | |
function Crowdsale() payable owned { | |
assert(contract_state == State.Disabled); | |
totalSupply = 0; | |
startTime = 1507212000; | |
contract_state = State.Crowdsale; | |
NewState(contract_state); | |
} | |
function () payable crowdsaleState { | |
require(msg.value >= 0.01 ether); | |
uint256 marketSupply = 600000000; | |
uint256 _tokens = msg.value / 0.00012 ether * 1 ether; | |
assert(_tokens > 0); | |
uint bonus = 0; | |
if (now < startTime + 11 days) { | |
if (msg.value < 5 ether) { | |
bonus = 40; | |
} else if (msg.value < 100 ether) { | |
bonus = 60; | |
} else if (msg.value >= 100 ether) { | |
bonus = 100; | |
} | |
} else if (now >= startTime + 11 days && now < startTime + 26 days) { | |
bonus = 0; | |
} else if (now >= startTime + 26 days && now < startTime + 27 days) { | |
bonus = 25; | |
} else if (now <= startTime + 34 days) { | |
bonus = 20; | |
} else if (now <= startTime + 41 days) { | |
bonus = 15; | |
} else if (now <= startTime + 48 days) { | |
bonus = 10; | |
} else if (now <= startTime + 55 days) { | |
bonus = 5; | |
} | |
_tokens += _tokens * bonus / 100; | |
uint256 restTokens = marketSupply - (totalSupply / 1 ether); | |
assert(restTokens > 0); | |
if (_tokens / 1 ether > restTokens) { | |
uint256 tokensAsBonus = restTokens * bonus / 100; | |
uint256 tokensAvailable = restTokens - tokensAsBonus; | |
assert(totalSupply + tokensAvailable + tokensAsBonus == marketSupply); | |
uint256 spentWei = tokensAvailable * 0.00012 ether; | |
assert(spentWei < msg.value); | |
msg.sender.transfer(msg.value - spentWei); | |
_tokens = (tokensAvailable + tokensAsBonus) * 1 ether; | |
} | |
mintTokens(msg.sender, _tokens); | |
} | |
function mintTokens(address _who, uint256 amount) internal { | |
balances[_who] = safeAdd(balances[_who], amount); | |
Transfer(this, _who, amount); | |
totalSupply = safeAdd(totalSupply, amount); | |
} | |
function finishCrowdsale() crowdsaleState onlyOwner returns (bool success) { | |
mintTokens(owner, (totalSupply / 60) * 40); | |
contract_state = State.Active; | |
NewState(contract_state); | |
return true; | |
} | |
} | |
contract Token is Crowdsale { | |
string public constant version = "1.0"; | |
string public constant name = "Narbonne"; | |
string public constant symbol = "NCC"; | |
uint8 public constant decimals = 18; | |
mapping (address => mapping (address => uint)) public allowed; | |
modifier onlyPayloadSize(uint size) { | |
require(msg.data.length >= size + 4); | |
_; | |
} | |
function balanceOf(address _who) constant returns (uint256) { | |
return balances[_who]; | |
} | |
function transfer(address _to, uint256 _value) public onlyPayloadSize(2 * 32) returns (bool success) { | |
balances[msg.sender] = safeSub(balances[msg.sender], _value); | |
balances[_to] = safeAdd(balances[_to], _value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public onlyPayloadSize(3 * 32) returns (bool success) { | |
uint _allowance = allowed[_from][msg.sender]; | |
balances[_to] = safeAdd(balances[_to], _value); | |
balances[_from] = safeSub(balances[_from], _value); | |
allowed[_from][msg.sender] = safeSub(_allowance, _value); | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
require((_value == 0) || (allowed[msg.sender][_spender] == 0)); | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public constant | |
returns (uint remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} | |
contract MyICO is Token { | |
function withdrawEther() public onlyOwner { | |
owner.transfer(this.balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment