Solidity version updated to 0.5.3-2

This commit is contained in:
Oscar Martinez 2019-10-23 17:43:22 -05:00
parent c72d41f558
commit a89db947ca
1 changed files with 106 additions and 67 deletions

View File

@ -1,4 +1,4 @@
pragma solidity 0.4.26;
pragma solidity 0.5.3;
// ----------------------------------------------------------------------------
// '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>
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
@ -38,14 +39,15 @@ contract SafeMath {
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function getTotalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, 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);
@ -54,22 +56,24 @@ contract ERC20Interface {
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
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
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
string public _CCDBAddress;
address payable public owner;
address payable public newOwner;
string public CCDBAddress;
event OwnershipTransferred(address indexed _from, address indexed _to);
@ -82,14 +86,12 @@ contract Owned {
_;
}
function updateCCDBAddress(string CCDBAddress) public onlyOwner {
_CCDBAddress = CCDBAddress;
function updateCCDBAddress(string memory _CCDBAddress) public onlyOwner {
CCDBAddress = _CCDBAddress;
}
function transferOwnership(address _newOwner) public onlyOwner {
function transferOwnership(address payable _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
@ -98,36 +100,68 @@ contract Owned {
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract DECAToken is ERC20Interface, Owned, SafeMath {
string public symbol = "DECA";
string public name = "DEcentralized CArbon tokens";
uint8 public decimals = 18;
uint public _totalSupply;
//for testing change weeks for hours...
uint public preICOEnds = now + 1 hours;
uint public bonus1Ends = now + 3 hours;
uint public bonus2Ends = now + 6 hours;
uint public endDate = now + 11 hours;
string public symbol;
string public name;
uint8 public decimals;
uint public totalSupply;
uint public startDate;
uint public preICOEnds;
uint public bonus1Ends;
uint public bonus2Ends;
uint public endDate;
mapping(address => uint) balances;
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
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
function getTotalSupply() public view returns (uint) {
return totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// 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];
}
@ -136,7 +170,7 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
// - Owner's account must have sufficient balance to transfer
// - 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[to] = safeAdd(balances[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
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
// approve should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'increaseApproval' and 'decreaseApproval'
if (allowed[msg.sender][spender] == 0 || tokens == 0){
emit Approval(msg.sender, spender, tokens);
return true;
}
return false;
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/*
* approve should be called when allowed[spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
*/
function increaseApproval (address spender, uint tokens) public returns (bool success){
allowed[msg.sender][spender] = safeAdd(allowed[msg.sender][spender], tokens);
// ------------------------------------------------------------------------
// Increases the amount of tokens that an owner allowed to a spender.
//
// 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
// the first transaction is mined)
// '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]);
return true;
}
function decreaseApproval (address spender, uint tokens) public returns (bool success) {
uint oldValue = allowed[msg.sender][spender];
if (tokens > oldValue) {
allowed[msg.sender][spender] = 0;
}
else{
allowed[msg.sender][spender] = safeSub(oldValue, tokens);
}
// ------------------------------------------------------------------------
// Decreases the amount of tokens that an owner allowed to a spender.
//
// 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
// the first transaction is mined)
// '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]);
return true;
}
@ -194,7 +235,11 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
// - Spender must have sufficient allowance to transfer
// - 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);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], 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
// 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];
}
@ -215,24 +260,24 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
// from the token owner's account. The `spender` contract function
// `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;
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;
}
// ------------------------------------------------------------------------
// 1,000 DECA Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
require(now <= endDate);
function () external payable {
require(now >= startDate && now <= endDate);
uint tokens;
uint toOwner;
uint toSender;
uint divBy;
uint percentage;
divBy = 10; // division to get 10%
percentage = 2; // percentage that goes to the owner
if (now <= preICOEnds) {
tokens = msg.value * 2000;
@ -243,20 +288,14 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
} else {
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
balances[msg.sender] = safeAdd(balances[msg.sender], toSender);
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), owner, toOwner);
}
//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);
address(owner).transfer(msg.value);
}
// ------------------------------------------------------------------------