Solidity version updated to 0.5.3-2
This commit is contained in:
parent
c72d41f558
commit
a89db947ca
|
@ -1,4 +1,4 @@
|
||||||
pragma solidity 0.4.26;
|
pragma solidity 0.5.3;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// 'DECA' DEcentralized CArbon tokens - ITDE (initial token distribution event)
|
// 'DECA' DEcentralized CArbon tokens - ITDE (initial token distribution event)
|
||||||
|
@ -16,6 +16,7 @@ pragma solidity 0.4.26;
|
||||||
// fork and modifications to fix DECA's ICO needs by p1r0 <p1r0@neetsec.com> and kaicudon <kaicudon@neetsec.com>
|
// fork and modifications to fix DECA's ICO needs by p1r0 <p1r0@neetsec.com> and kaicudon <kaicudon@neetsec.com>
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Safe maths
|
// Safe maths
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -38,14 +39,15 @@ contract SafeMath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// ERC Token Standard #20 Interface
|
// ERC Token Standard #20 Interface
|
||||||
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
|
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
contract ERC20Interface {
|
contract ERC20Interface {
|
||||||
function totalSupply() public constant returns (uint);
|
function getTotalSupply() public view returns (uint);
|
||||||
function balanceOf(address tokenOwner) public constant returns (uint balance);
|
function balanceOf(address tokenOwner) public view returns (uint balance);
|
||||||
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
|
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
|
||||||
function transfer(address to, uint tokens) public returns (bool success);
|
function transfer(address to, uint tokens) public returns (bool success);
|
||||||
function approve(address spender, uint tokens) public returns (bool success);
|
function approve(address spender, uint tokens) public returns (bool success);
|
||||||
function transferFrom(address from, address to, uint tokens) public returns (bool success);
|
function transferFrom(address from, address to, uint tokens) public returns (bool success);
|
||||||
|
@ -54,22 +56,24 @@ contract ERC20Interface {
|
||||||
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
|
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Contract function to receive approval and execute function in one call
|
// Contract function to receive approval and execute function in one call
|
||||||
//
|
//
|
||||||
// Borrowed from MiniMeToken
|
// Borrowed from MiniMeToken
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
contract ApproveAndCallFallBack {
|
contract ApproveAndCallFallBack {
|
||||||
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
|
function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Owned contract
|
// Owned contract
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
contract Owned {
|
contract Owned {
|
||||||
address public owner;
|
address payable public owner;
|
||||||
address public newOwner;
|
address payable public newOwner;
|
||||||
string public _CCDBAddress;
|
string public CCDBAddress;
|
||||||
|
|
||||||
event OwnershipTransferred(address indexed _from, address indexed _to);
|
event OwnershipTransferred(address indexed _from, address indexed _to);
|
||||||
|
|
||||||
|
@ -82,14 +86,12 @@ contract Owned {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCCDBAddress(string CCDBAddress) public onlyOwner {
|
function updateCCDBAddress(string memory _CCDBAddress) public onlyOwner {
|
||||||
_CCDBAddress = CCDBAddress;
|
CCDBAddress = _CCDBAddress;
|
||||||
}
|
}
|
||||||
|
function transferOwnership(address payable _newOwner) public onlyOwner {
|
||||||
function transferOwnership(address _newOwner) public onlyOwner {
|
|
||||||
newOwner = _newOwner;
|
newOwner = _newOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
function acceptOwnership() public {
|
function acceptOwnership() public {
|
||||||
require(msg.sender == newOwner);
|
require(msg.sender == newOwner);
|
||||||
emit OwnershipTransferred(owner, newOwner);
|
emit OwnershipTransferred(owner, newOwner);
|
||||||
|
@ -98,36 +100,68 @@ contract Owned {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// ERC20 Token, with the addition of symbol, name and decimals and assisted
|
// ERC20 Token, with the addition of symbol, name and decimals and assisted
|
||||||
// token transfers
|
// token transfers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
contract DECAToken is ERC20Interface, Owned, SafeMath {
|
contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
string public symbol = "DECA";
|
string public symbol;
|
||||||
string public name = "DEcentralized CArbon tokens";
|
string public name;
|
||||||
uint8 public decimals = 18;
|
uint8 public decimals;
|
||||||
uint public _totalSupply;
|
uint public totalSupply;
|
||||||
//for testing change weeks for hours...
|
uint public startDate;
|
||||||
uint public preICOEnds = now + 1 hours;
|
uint public preICOEnds;
|
||||||
uint public bonus1Ends = now + 3 hours;
|
uint public bonus1Ends;
|
||||||
uint public bonus2Ends = now + 6 hours;
|
uint public bonus2Ends;
|
||||||
uint public endDate = now + 11 hours;
|
uint public endDate;
|
||||||
|
|
||||||
mapping(address => uint) balances;
|
mapping(address => uint) balances;
|
||||||
mapping(address => mapping(address => uint)) allowed;
|
mapping(address => mapping(address => uint)) allowed;
|
||||||
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Constructor
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
constructor () public {
|
||||||
|
symbol = "DECA";
|
||||||
|
name = "DEcentralized CArbon tokens";
|
||||||
|
decimals = 18;
|
||||||
|
//for testing change weeks for days...
|
||||||
|
preICOEnds = now + 1 days;
|
||||||
|
bonus1Ends = now + 3 days;
|
||||||
|
bonus2Ends = now + 6 days;
|
||||||
|
endDate = now + 11 days;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier onlyValidAddress(address addr) {
|
||||||
|
require(addr != address(0), "Address cannot be zero");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier onlySufficientBalance(address from, uint256 tokens) {
|
||||||
|
require(tokens <= balances[from], "Insufficient balance");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier onlySufficientAllowance(address owner, address spender, uint256 value) {
|
||||||
|
require(value <= allowed[owner][spender], "Insufficient allowance");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Total supply: Get the total token supply
|
// Total supply: Get the total token supply
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
function totalSupply() public constant returns (uint) {
|
function getTotalSupply() public view returns (uint) {
|
||||||
return _totalSupply - balances[address(0)];
|
return totalSupply - balances[address(0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Get the token balance for account `tokenOwner`
|
// Get the token balance for account `tokenOwner`
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function balanceOf(address tokenOwner) public constant returns (uint balance) {
|
function balanceOf(address tokenOwner) public view returns (uint balance) {
|
||||||
return balances[tokenOwner];
|
return balances[tokenOwner];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +170,7 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
// - Owner's account must have sufficient balance to transfer
|
// - Owner's account must have sufficient balance to transfer
|
||||||
// - 0 value transfers are allowed
|
// - 0 value transfers are allowed
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function transfer(address to, uint tokens) public returns (bool success) {
|
function transfer(address to, uint tokens) public onlySufficientBalance(msg.sender, tokens) returns (bool success) {
|
||||||
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
|
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
|
||||||
balances[to] = safeAdd(balances[to], tokens);
|
balances[to] = safeAdd(balances[to], tokens);
|
||||||
emit Transfer(msg.sender, to, tokens);
|
emit Transfer(msg.sender, to, tokens);
|
||||||
|
@ -152,35 +186,42 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
// as this should be implemented in user interfaces
|
// as this should be implemented in user interfaces
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function approve(address spender, uint tokens) public returns (bool success) {
|
function approve(address spender, uint tokens) public returns (bool success) {
|
||||||
// approve should only be called when setting an initial allowance,
|
allowed[msg.sender][spender] = tokens;
|
||||||
// or when resetting it to zero. To increase and decrease it, use
|
emit Approval(msg.sender, spender, tokens);
|
||||||
// 'increaseApproval' and 'decreaseApproval'
|
return true;
|
||||||
if (allowed[msg.sender][spender] == 0 || tokens == 0){
|
|
||||||
emit Approval(msg.sender, spender, tokens);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// ------------------------------------------------------------------------
|
||||||
* approve should be called when allowed[spender] == 0. To increment
|
// Increases the amount of tokens that an owner allowed to a spender.
|
||||||
* allowed value is better to use this function to avoid 2 calls (and wait until
|
//
|
||||||
* the first transaction is mined)
|
// approve should be called when _allowance[spender] == 0. To increment
|
||||||
*/
|
// allowed value is better to use this function to avoid 2 calls (and wait until
|
||||||
function increaseApproval (address spender, uint tokens) public returns (bool success){
|
// the first transaction is mined)
|
||||||
allowed[msg.sender][spender] = safeAdd(allowed[msg.sender][spender], tokens);
|
// 'spender' The address which will spend the funds.
|
||||||
|
// 'addedValue' The amount of tokens to increase the allowance by.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
function increaseAllowance(address spender, uint256 addedValue) public
|
||||||
|
onlyValidAddress(spender)
|
||||||
|
returns (bool){
|
||||||
|
allowed[msg.sender][spender] = safeAdd(allowed[msg.sender][spender], addedValue);
|
||||||
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
|
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decreaseApproval (address spender, uint tokens) public returns (bool success) {
|
// ------------------------------------------------------------------------
|
||||||
uint oldValue = allowed[msg.sender][spender];
|
// Decreases the amount of tokens that an owner allowed to a spender.
|
||||||
if (tokens > oldValue) {
|
//
|
||||||
allowed[msg.sender][spender] = 0;
|
// approve should be called when _allowance[spender] == 0. To decrement
|
||||||
}
|
// allowed value is better to use this function to avoid 2 calls (and wait until
|
||||||
else{
|
// the first transaction is mined)
|
||||||
allowed[msg.sender][spender] = safeSub(oldValue, tokens);
|
// 'spender' The address which will spend the funds.
|
||||||
}
|
// 'param' subtractedValue The amount of tokens to decrease the allowance by.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
function decreaseAllowance(address spender, uint256 subtractedValue) public
|
||||||
|
onlyValidAddress(spender)
|
||||||
|
onlySufficientAllowance(msg.sender, spender, subtractedValue)
|
||||||
|
returns (bool){
|
||||||
|
allowed[msg.sender][spender] = safeSub(allowed[msg.sender][spender], subtractedValue);
|
||||||
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
|
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +235,11 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
// - Spender must have sufficient allowance to transfer
|
// - Spender must have sufficient allowance to transfer
|
||||||
// - 0 value transfers are allowed
|
// - 0 value transfers are allowed
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
|
function transferFrom(address from, address to, uint tokens) public
|
||||||
|
onlyValidAddress(to)
|
||||||
|
onlySufficientBalance(from, tokens)
|
||||||
|
onlySufficientAllowance(from, msg.sender, tokens)
|
||||||
|
returns (bool success) {
|
||||||
balances[from] = safeSub(balances[from], tokens);
|
balances[from] = safeSub(balances[from], tokens);
|
||||||
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
|
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
|
||||||
balances[to] = safeAdd(balances[to], tokens);
|
balances[to] = safeAdd(balances[to], tokens);
|
||||||
|
@ -206,7 +251,7 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
// Returns the amount of tokens approved by the owner that can be
|
// Returns the amount of tokens approved by the owner that can be
|
||||||
// transferred to the spender's account
|
// transferred to the spender's account
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
|
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
|
||||||
return allowed[tokenOwner][spender];
|
return allowed[tokenOwner][spender];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,24 +260,24 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
// from the token owner's account. The `spender` contract function
|
// from the token owner's account. The `spender` contract function
|
||||||
// `receiveApproval(...)` is then executed
|
// `receiveApproval(...)` is then executed
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
|
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
|
||||||
allowed[msg.sender][spender] = tokens;
|
allowed[msg.sender][spender] = tokens;
|
||||||
emit Approval(msg.sender, spender, tokens);
|
emit Approval(msg.sender, spender, tokens);
|
||||||
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
|
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// 1,000 DECA Tokens per 1 ETH
|
// 1,000 DECA Tokens per 1 ETH
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
function () public payable {
|
function () external payable {
|
||||||
require(now <= endDate);
|
require(now >= startDate && now <= endDate);
|
||||||
uint tokens;
|
uint tokens;
|
||||||
uint toOwner;
|
uint toOwner;
|
||||||
uint toSender;
|
uint toSender;
|
||||||
uint divBy;
|
uint percentage;
|
||||||
|
|
||||||
divBy = 10; // division to get 10%
|
percentage = 2; // percentage that goes to the owner
|
||||||
|
|
||||||
if (now <= preICOEnds) {
|
if (now <= preICOEnds) {
|
||||||
tokens = msg.value * 2000;
|
tokens = msg.value * 2000;
|
||||||
|
@ -243,20 +288,14 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
} else {
|
} else {
|
||||||
tokens = msg.value * 1000;
|
tokens = msg.value * 1000;
|
||||||
}
|
}
|
||||||
toOwner = safeDiv(tokens, divBy); // divBy to get the percentage assigned to the contract owner (for exchange to Cabron Credits)
|
toOwner = safeDiv(tokens, percentage); // percentage assigned to the contract owner (DAO)
|
||||||
toSender = tokens; // tokens goes to sender
|
toSender = tokens; // tokens goes to sender
|
||||||
balances[msg.sender] = safeAdd(balances[msg.sender], toSender);
|
balances[msg.sender] = safeAdd(balances[msg.sender], toSender);
|
||||||
balances[owner] = safeAdd(balances[owner], toOwner);
|
balances[owner] = safeAdd(balances[owner], toOwner);
|
||||||
_totalSupply = safeAdd(_totalSupply, safeAdd(toSender,toOwner));
|
totalSupply = safeAdd(totalSupply, safeAdd(tokens,safeDiv(tokens, percentage)));
|
||||||
emit Transfer(address(0), msg.sender, toSender);
|
emit Transfer(address(0), msg.sender, toSender);
|
||||||
emit Transfer(address(0), owner, toOwner);
|
emit Transfer(address(0), owner, toOwner);
|
||||||
}
|
address(owner).transfer(msg.value);
|
||||||
|
|
||||||
//Close down the ICO and Claim the Ether.
|
|
||||||
function getETH() public onlyOwner {
|
|
||||||
require(now >= endDate );
|
|
||||||
// transfer the ETH balance in the contract to the owner
|
|
||||||
owner.transfer(address(this).balance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -265,4 +304,4 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
|
||||||
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
|
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
|
||||||
return ERC20Interface(tokenAddress).transfer(owner, tokens);
|
return ERC20Interface(tokenAddress).transfer(owner, tokens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue