Created
May 24, 2018 10:53
-
-
Save peekpi/1a28b0e29271068f83046154a5580862 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract ERC20 { | |
function totalSupply() public returns (uint totalSupply); | |
function balanceOf(address _owner) public returns (uint balance); | |
function transfer(address _to, uint _value) public 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); | |
} | |
contract Roshambo is ERC20{ | |
address owner; | |
mapping(address => uint) mbalance; | |
constructor() public | |
{ | |
owner = msg.sender; | |
} | |
function totalSupply() view returns (uint totalSupply) | |
{ | |
totalSupply = uint256(0-1); | |
} | |
function balanceOf(address _owner) view returns(uint balance) | |
{ | |
balance = mbalance[_owner]; | |
} | |
function transfer(address _to, uint _value) returns (bool success) | |
{ | |
if(mbalance[msg.sender] < _value || | |
mbalance[_to] + _value < mbalance[_to] | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract Controlled { | |
address public controller; | |
modifier onlyController { | |
require(msg.sender == controller); | |
_; | |
} | |
constructor() public | |
{ | |
controller = msg.sender; | |
} | |
function changeController(address _to) public onlyController | |
{ | |
controller = _to; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
import "./Controlled.sol"; | |
import "./TokenController.sol"; | |
contract ApproveAndCallFallBack { | |
function receiveApproval(address _from, uint256 _amount, address _token, bytes _data) public; | |
} | |
contract MiniMeToken is Controlled { | |
string public name; | |
uint8 public decimals; | |
string public symbol; | |
string public version = "MMT_0.2"; | |
struct Checkpoint { | |
uint128 fromBlock; | |
uint128 value; | |
} | |
MiniMeToken public parentToken; | |
uint public parentSnapShotBlock; | |
uint public creationBlock; | |
mapping (address => Checkpoint[]) balances; | |
mapping (address => mapping(address => uint256)) allowed; | |
Checkpoint[] totalSupplyHistory; | |
bool public transfersEnabled; | |
MiniMeTokenFactory public tokenFactory; | |
event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount); | |
event Transfer(address indexed _from, address indexed _to, uint256 _amount); | |
event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _amount); | |
constructor ( | |
address _tokenFactory, | |
address _parentToken, | |
uint _parentSnapShotBlock, | |
string _tokenName, | |
uint8 _decimalUnits, | |
string _tokenSymbol, | |
bool _transfersEnabled | |
) public { | |
tokenFactory = MiniMeTokenFactory(_tokenFactory); | |
name = _tokenName; | |
decimals = _decimalUnits; | |
symbol = _tokenSymbol; | |
parentToken = MiniMeToken(_parentToken); | |
parentSnapShotBlock = _parentSnapShotBlock; | |
transfersEnabled = _transfersEnabled; | |
creationBlock = block.number; | |
} | |
/* -------------- ERC20 METHOD -------------- */ | |
function transfer(address _to, uint256 _amount) public returns (bool) { | |
require(transfersEnabled); | |
doTransfer(msg.sender, _to, _amount); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _amount) public returns (bool) { | |
if (msg.sender != controller) { | |
require(transfersEnabled); | |
require(allowed[_from][msg.sender] >= _amount); | |
allowed[_from][msg.sender] -= _amount; | |
} | |
doTransfer(_from, _to, _amount); | |
return true; | |
} | |
function approve(address _spender, uint256 _amount) public returns (bool) { | |
require(transfersEnabled); | |
require((_amount == 0) || (allowed[msg.sender][_spender] == 0)); | |
if(isContract(controller)) { | |
require(TokenController(controller).onApprove(msg.sender, _spender, _amount)); | |
} | |
allowed[msg.sender][_spender] = _amount; | |
emit Approval(msg.sender, _spender, _amount); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public constant returns(uint256) { | |
return allowed[_owner][_spender]; | |
} | |
function approveAndCall(address _spender, uint256 _amount, bytes _exteraData) public returns (bool) { | |
require(approve(_spender, _amount)); | |
ApproveAndCallFallBack(_spender).receiveApproval(msg.sender, _amount, this, _exteraData); | |
return true; | |
} | |
function balanceOf(address _owner) public constant returns (uint256) { | |
return balanceOfAt(_owner, block.number); | |
} | |
function totalSupply() public constant returns (uint) { | |
return totalSupplyAt(block.number); | |
} | |
/* ------------------ END ------------------ */ | |
function destroyTokens(address _owner, uint _amount) onlyController public returns(bool) { | |
uint curTotalSupply = totalSupply(); | |
require(curTotalSupply >= _amount); | |
uint previousBalanceFrom = balanceOf(_owner); | |
require(previousBalanceFrom >= _amount); | |
updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount); | |
updateValueAtNow(balances[_owner], previousBalanceFrom - _amount); | |
emit Transfer(_owner, 0, _amount); | |
return true; | |
} | |
function generateTokens(address _owner, uint _amount) public onlyController returns (bool) { | |
uint curTotalSupply = totalSupply(); | |
require(curTotalSupply + _amount >= curTotalSupply); | |
uint previousBalanceTo = balanceOf(_owner); | |
require(previousBalanceTo + _amount >= previousBalanceTo); | |
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount); | |
updateValueAtNow(balances[_owner], previousBalanceTo + _amount); | |
emit Transfer(0, _owner, _amount); | |
return true; | |
} | |
function doTransfer(address _from, address _to, uint _amount) internal { | |
if(_amount == 0) { | |
emit Transfer(_from, _to, _amount); | |
return; | |
} | |
require(parentSnapShotBlock < block.number); | |
require(_to != 0 && _to != address(this)); | |
uint previousBalanceFrom = balanceOfAt(_from, block.number); | |
require(previousBalanceFrom >= _amount); | |
if(isContract(controller)) { | |
require(TokenController(controller).onTransfer(_from, _to, _amount)); | |
} | |
updateValueAtNow(balances[_from], previousBalanceFrom - _amount); | |
uint previousBalanceTo = balanceOfAt(_to, block.number); | |
require(previousBalanceTo + _amount >= previousBalanceTo); | |
updateValueAtNow(balances[_to], previousBalanceTo + _amount); | |
Transfer(_from, _to, _amount); | |
} | |
function totalSupplyAt(uint _blockNumber) public constant returns(uint) { | |
if ((totalSupplyHistory.length == 0) | |
|| (totalSupplyHistory[0].fromBlock > _blockNumber)) { | |
if(address(parentToken) != 0) { | |
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock)); | |
} else { | |
return 0; | |
} | |
} else { | |
return getValueAt(totalSupplyHistory, _blockNumber); | |
} | |
} | |
function balanceOfAt(address _owner, uint _blockNumber) public constant returns(uint) { | |
if((balances[_owner].length == 0) | |
|| (balances[_owner][0].fromBlock > _blockNumber)) { | |
if (address(parentToken) != 0) { | |
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock)); | |
} else | |
{ | |
return 0; | |
} | |
} else { | |
return getValueAt(balances[_owner], _blockNumber); | |
} | |
} | |
function getValueAt(Checkpoint[] storage checkpoints, uint _block) constant internal returns(uint) { | |
if (checkpoints.length == 0) return 0; | |
if(_block >= checkpoints[checkpoints.length - 1].fromBlock) | |
return checkpoints[checkpoints.length - 1].value; | |
if(_block < checkpoints[0].fromBlock) return 0; | |
uint min = 0; | |
uint max = checkpoints.length-1; | |
while(max > min) | |
{ | |
uint mid = (max + min + 1) / 2; | |
if(checkpoints[mid].fromBlock <= _block) { | |
min = mid; | |
} else { | |
max = mid - 1; | |
} | |
} | |
return checkpoints[min].value; | |
} | |
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal { | |
if ((checkpoints.length == 0) | |
|| (checkpoints[checkpoints.length - 1].fromBlock < block.number)) { | |
Checkpoint storage newCheckPoint = checkpoints[ checkpoints.length++ ]; | |
newCheckPoint.fromBlock = uint128(block.number); | |
newCheckPoint.value = uint128(_value); | |
} else { | |
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1]; | |
oldCheckPoint.value = uint128(_value); | |
} | |
} | |
function isContract(address _addr) constant internal returns(bool) { | |
uint size; | |
if (_addr == 0) return false; | |
assembly { | |
size := extcodesize(_addr) | |
} | |
return size > 0; | |
} | |
function min(uint a, uint b) pure internal returns (uint) { | |
return a < b ? a : b; | |
} | |
function createCloneToken( | |
string _cloneTokenName, | |
uint8 _cloneDecimalUnits, | |
string _cloneTokenSymbol, | |
uint _snapshotBlock, | |
bool _transfersEnabled | |
) public returns(address) { | |
if(_snapshotBlock == 0) _snapshotBlock = block.number; | |
MiniMeToken cloneToken = tokenFactory.createCloneToken( | |
this, | |
_snapshotBlock, | |
_cloneTokenName, | |
_cloneDecimalUnits, | |
_cloneTokenSymbol, | |
_transfersEnabled | |
); | |
cloneToken.changeController(msg.sender); | |
emit NewCloneToken(address(cloneToken), _snapshotBlock); | |
return address(cloneToken); | |
} | |
} | |
contract MiniMeTokenFactory { | |
function createCloneToken ( | |
address _parentToken, | |
uint _snapshotBlock, | |
string _tokenName, | |
uint8 _decimalUnits, | |
string _tokenSymbol, | |
bool _transfersEnabled | |
) public returns (MiniMeToken) { | |
MiniMeToken newToken = new MiniMeToken( | |
this, | |
_parentToken, | |
_snapshotBlock, | |
_tokenName, | |
_decimalUnits, | |
_tokenSymbol, | |
_transfersEnabled | |
); | |
newToken.changeController(msg.sender); | |
return newToken; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
import "./MiniMeToken.sol"; | |
contract Owned { | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
address public owner; | |
constructor() { | |
owner = msg.sender; | |
} | |
function changeOwner(address _newOwner) { | |
owner = _newOwner; | |
} | |
} | |
contract Campaign is TokenController, Owned { | |
uint public startFundingTime; | |
uint public endFundingTime; | |
uint public maximumFunding; | |
uint public totalCollected; | |
MiniMeToken public tokenContract; | |
address public vaultAddress; | |
constructor( | |
uint _startFundingTime, | |
uint _endFundingTime, | |
uint _maximumFunding, | |
address _vaultAddress, | |
address _tokenAddress | |
) { | |
require((_endFundingTime >= now) && | |
(_endFundingTime > _startFundingTime) && | |
(_maximumFunding <= 10000 ether) && | |
(_vaultAddress != 0) | |
); | |
startFundingTime = _startFundingTime; | |
endFundingTime = _endFundingTime; | |
maximumFunding = _maximumFunding; | |
tokenContract = MiniMeToken(_tokenAddress); | |
vaultAddress = _vaultAddress; | |
} | |
function () payable { | |
doPayment(msg.sender); | |
} | |
function proxyPayment(address _owner) payable returns(bool) { | |
doPayment(_owner); | |
return true; | |
} | |
function finalizeFundingTime() { | |
} | |
function setVault(address _newVaultAddress) onlyOwner { | |
vaultAddress = _newVaultAddress; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract TokenController{ | |
function proxyPayment(address _owner) public payable returns (bool); | |
function onTransfer(address _from, address _to, uint _amount) public returns (bool); | |
function onApprove(address _owner, address _spender, uint _amount) public returns (bool); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment