Skip to content

Instantly share code, notes, and snippets.

@D-Nice
Created July 6, 2017 16:12
Show Gist options
  • Save D-Nice/5fab953f4df9f5df77014e09085c697c to your computer and use it in GitHub Desktop.
Save D-Nice/5fab953f4df9f5df77014e09085c697c to your computer and use it in GitHub Desktop.
underhanded ICO submission
pragma solidity ^0.4.0;
contract ERC20 {
function totalSupply() constant returns (uint totalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns (bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
pragma solidity ^0.4.0;
import "browser/token.sol";
// ICO with promise to have a complete and ready product developed, before the end of the ICO
// To guarantee the promise, investors are given up to the last day to request a refund of their investment
// Tokens are priced at a constant rate for simplicity
contract MerdeICO is MerdeToken {
string public name = "MerdeToken";
string public symbol = "MTN";
uint256 public price;
address public owner;
uint256 public decimals = 6;
uint256 refundStart;
uint256 refundEnd;
uint256 start;
uint256 end;
uint256 tokenSupply;
// ICO CONSTRUCTOR
// Promise to provide working product during ICO period of 1 week
function MerdeICO() {
// fixed rate at which tokens are priced
price = 1000;
// ico starts immediately on deployment
start = now;
// ico ends 1 week after deployment with promise of a finished product
end = safeAdd(now, 1 weeks);
// allow refunds at the halfway point of the ICO
refundStart = end;
// allow refunds until the last day of the ICO if product undelivered
Du refundEnd = safeAdd(now, 2 weeks);
// set deployer as the owner for later fund redemption
owner = msg.sender;
}
// ICO PERIOD functions
// check to ensure it is during the ICO period so funds can be accepted and
// exchanged for tokens
function isDuringICO() private constant returns (bool) {
if (now < end) return true;
else return false;
}
// simple payable function to set the sender as the token holder
function () payable {
// only allow token creation and acceptance of payment during ICO period
if (!isDuringICO()) throw;
reserveTokens(msg.sender);
}
// reserves tokens for users, which become permanent after ico and refund
// allows proxy recipients
function reserveTokens(address _recipient) payable {
if (msg.value == 0) {
throw;
}
uint tokens = msg.value/price;
tokenSupply = safeAdd(tokenSupply, tokens);
balances[_recipient] = safeAdd(balances[_recipient], tokens);
}
// POST ICO PERIOD, Refund stage activates for token holders
// check to ensure it is now the refund period
function isDuringRefund() private constant returns (bool) {
if (now > refundStart && now < refundEnd) return true;
else return false;
}
// Ability for unsatisfied token holders to get a full refund of their funds
// Immediately after ICO ends, if they are unhappy with released product.
function refund() {
// check to ensure the msg sender actually owns a token balance
// and whether we are in the refund period for this function to be called
if (balances[msg.sender] == 0 || balances[msg.sender] > tokenSupply || !isDuringRefund()) throw;
uint savedBalance = balances[msg.sender];
balances[msg.sender] = 0;
// refund the sender their invested amount and destroy the said tokens
if(msg.sender.send(safeMul(savedBalance, price))) {
tokenSupply = safeSub(tokenSupply, savedBalance);
} else {
// if sending fails, throw and revert state
throw;
}
}
// POST ICO/REFUND Functions for owner to redeem the funds for their project
// check to determine whether we are in the ICO/refund phase or not
function isDuringRefundAndICO() private constant returns (bool) {
if (now > start && now < refundEnd) return true;
else return false;
}
function ownerRedeemSomeFunds(uint _amt) {
// check that balance is sufficient with input amount
// and that it is past the ICO and Refund periods, else throw
if (_amt > this.balance || _amt == 0 || msg.sender != owner || isDuringRefundAndICO()) throw;
// owner may redeem chosen amount here from the balance
owner.send(_amt);
}
function ownerRedeemAllFunds() {
// check that balance is sufficient with input amount
// and that it is past the ICO and Refund periods, else throw
if (isDuringRefundAndICO() || msg.sender != owner) throw;
// owner may redeem chosen amount here from the balance
owner.send(this.balance);
}
}
pragma solidity ^0.4.0;
contract SafeMath {
function safeMul(uint a, uint b) constant internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeSub(uint a, uint b) constant internal returns (uint) {
assert(b <= a);
return a - b;
}
function safeAdd(uint a, uint b) constant internal returns (uint) {
uint c = a + b;
assert(c>=a && c>=b);
return c;
}
function assert(bool assertion) constant internal {
if (!assertion) throw;
}
}
pragma solidity ^0.4.0;
import "browser/safemath.sol";
import "browser/erc20.sol";
contract MerdeToken is SafeMath, ERC20 {
function totalSupply() constant returns (uint totalSupply) {
return tokenSupply;
}
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) allowed;
mapping (address => uint256) balances;
string public name = "TokenName";
string public symbol = "TNM";
uint256 public price;
address public owner;
uint256 public decimals = 6;
uint256 refundStart;
uint256 refundEnd;
uint256 now;
uint256 end;
uint256 tokenSupply;
function transfer(address _to, uint256 _value) 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) returns (bool success){
var _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) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment