Skip to content

Instantly share code, notes, and snippets.

@adenot
Created February 25, 2018 23:53
Show Gist options
  • Save adenot/d4aeebef7fdd71b6d04d2966992214ec to your computer and use it in GitHub Desktop.
Save adenot/d4aeebef7fdd71b6d04d2966992214ec to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.18;
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract ReturnX is Ownable {
using SafeMath for uint256;
uint256 public minDeposit;
uint256 public maxDeposit;
string public icoCode;
uint256 public hardCap;
uint256 public totalInvested;
uint16 participants;
function ReturnX(uint256 _minDeposit, uint256 _maxDeposit, uint256 _hardCap, string _icoCode) {
minDeposit = _minDeposit;
maxDeposit = _maxDeposit;
hardCap = _hardCap;
icoCode = _icoCode;
participants = 0;
totalInvested = 0;
}
function () public payable {
deposit();
}
mapping (address => uint) balances;
function deposit() public payable {
require(msg.value > 0);
require((msg.value + balances[msg.sender]) >= minDeposit);
require((msg.value + balances[msg.sender]) <= maxDeposit);
require((msg.value + totalInvested) <= hardCap);
balances[msg.sender] += msg.value;
totalInvested += msg.value;
participants++;
}
function widthdraw(uint256 value) public {
require(balances[msg.sender] > 0);
if (value == 0) {
value = balances[msg.sender];
}
balances[msg.sender] = balances[msg.sender] - value;
msg.sender.transfer(value);
totalInvested -= value;
if (balances[msg.sender] == 0) {
participants--;
}
}
function balance() public constant returns (uint256) {
return balances[msg.sender];
}
function getParticipants() public constant returns (uint16) {
return participants;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment