краудсейл от существующей солидности контрактного токена - PullRequest
0 голосов
/ 11 сентября 2018

Я начинаю с умных контрактов Solidity ethereum и пытаюсь заключить краудсейл-контракт на существующий токен, который я держу в своем кошельке.

Может ли кто-нибудь взглянуть на мой контракт и объяснить, что я здесь делаю не так?

Внимание! Обнаружена ошибка при выполнении контракта [Восстановлено]

Поздравил, Томас

pragma solidity ^0.4.24;

library SafeMath{

function add(uint a, uint b) internal pure returns (uint c) {
    c = a + b;
    require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
    require(b <= a);
    c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
    c = a * b;
    require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
    require(b > 0);
    c = a / b;
}
}

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 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);

event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint 
tokens);
}

contract Owned {
address public owner;
address public newOwner;

event OwnershipTransferred(address indexed _from, address indexed _to);

constructor() public {
    owner = msg.sender;
}

modifier onlyOwner {
    require(msg.sender == owner);
    _;
}

function transferOwnership(address _newOwner) public onlyOwner {
    newOwner = _newOwner;
}
function acceptOwnership() public {
    require(msg.sender == newOwner);
    emit OwnershipTransferred(owner, newOwner);
    owner = newOwner;
    newOwner = address(0);
}
}

contract Crowdsale is Owned{

using SafeMath for uint256;

ERC20Interface public token;

// Amount Raised
uint256 public weiRaised;

// Wallet where funds will be transfered
address public wallet;

// Is the crowdsale paused?
bool isCrowdsalePaused = false;

// the exchange rate
uint256 public rate;

// total ETH for sale
uint256 public cap;

uint8 public decimals;

event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

constructor() public {
    require(wallet != address(0));
    require(token != address(0));

    require(cap > 0);
    require(rate > 0);

    wallet = 0x000000000000000000000000000000000;
    token = ERC20Interface(0x0000000000000000000000000000000);

    decimals = 18;

    // 100.000 ETH
    cap = 100000 * 10**uint(decimals);

    // get the rate based on current amount raised
    if (weiRaised < 20000 * 10 ** uint(decimals)){
      rate = 1000;  
    }else if (weiRaised >= 20000 * 10 ** uint(decimals)){
        rate = 900;
    }else if (weiRaised >= 50000 * 10 ** uint(decimals)){
        rate = 800;
    }
}

function () external payable {
    buyTokens(msg.sender);
}

function buyTokens(address beneficiary) public payable {

    require(beneficiary != 0x0);

    uint256 amount = msg.value;

    require(isCrowdsalePaused == false);

    require(weiRaised.add(amount) <= cap);

    uint256 tokens = getTokenAmount(amount);

    weiRaised = weiRaised.add(amount);

    processPurchase(beneficiary, tokens);

    emit TokenPurchase(msg.sender, beneficiary, amount, tokens);

    forwardFunds();

}

function deliverTokens(address beneficiary,uint256 tokenAmount) internal{
    token.transferFrom(wallet, beneficiary, tokenAmount);
}

function processPurchase(address beneficiary,uint256 tokenAmount) internal{
    deliverTokens(beneficiary, tokenAmount);
}

function getTokenAmount(uint256 amount) internal view returns (uint256){
    return rate.mul(amount);
}

function forwardFunds() internal {
    wallet.transfer(msg.value);
}

function remainingTokens() public view returns (uint256) {
    return token.allowance(wallet, this);
}

function capReached() public view returns (bool) {
    return weiRaised >= cap;
}

function pauseCrowdsale() public onlyOwner {
    isCrowdsalePaused = true;
}

function resumeCrowdsale() public onlyOwner {
    isCrowdsalePaused = false;
}

function takeTokensBack() public onlyOwner
 {
     uint remainingTokensInTheContract = token.balanceOf(address(this));
     token.transfer(owner,remainingTokensInTheContract);
 }
}
...