Created
March 26, 2019 09:38
-
-
Save mksamanes/4865c252deb7042fb7e169cf34ab3825 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.5.6+commit.b259423e.js&optimize=false&gist=
This file contains hidden or 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.5.6; | |
import "./erc20.sol"; | |
contract AccessLog { | |
address public owner; // Trader wallet | |
address public manager; | |
TradToken private accessToken; | |
modifier onlyManager() { | |
require(msg.sender == manager, "Only visible for tokens owners"); | |
_; | |
} | |
constructor(address _owner, address _manager) public { | |
manager = _manager; | |
owner = _owner; | |
accessToken = new TradToken("TRC", "Access Token"); | |
ERC20Interface(accessToken).transfer(manager, 1); | |
ERC20Interface(accessToken).transfer(owner, 1); | |
} | |
function enableAccountAccess(address _account) public onlyManager { | |
require(ERC20Interface(accessToken).balanceOf(_account) == 0, "Duplicated account"); | |
ERC20Interface(accessToken).transfer(_account, 1); | |
} | |
function doIHaveAccess() view public returns(string memory) { | |
require(ERC20Interface(accessToken).balanceOf(msg.sender) == 1, "You don't have access"); | |
return "You have access"; | |
} | |
function disableAccountAccess(address _account) public onlyManager { | |
require(_account != owner, "Owner cannot disable the account"); | |
require(ERC20Interface(accessToken).balanceOf(_account) > 0, "Disabled account"); | |
ERC20Interface(accessToken).transferFrom(_account, address(this), ERC20Interface(accessToken).balanceOf(_account)); | |
} | |
} |
This file contains hidden or 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.22 <0.6.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
constructor(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public view returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
This file contains hidden or 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
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./ballot.sol"; | |
contract test3 { | |
Ballot ballotToTest; | |
function beforeAll () public { | |
ballotToTest = new Ballot(2); | |
} | |
function checkWinningProposal () public { | |
ballotToTest.vote(1); | |
Assert.equal(ballotToTest.winningProposal(), uint(1), "1 should be the winning proposal"); | |
} | |
function checkWinninProposalWithReturnValue () public view returns (bool) { | |
return ballotToTest.winningProposal() == 1; | |
} | |
} |
This file contains hidden or 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.5.6; | |
// ---------------------------------------------------------------------------- | |
// 'FIXED' 'Example Fixed Supply Token' token contract | |
// | |
// Symbol : FIXED | |
// Name : Example Fixed Supply Token | |
// Total supply: 1,000,000.000000000000000000 | |
// Decimals : 18 | |
// | |
// Enjoy. | |
// | |
// (c) BokkyPooBah / Bok Consulting Pty Ltd 2018. The MIT Licence. | |
// ---------------------------------------------------------------------------- | |
// ---------------------------------------------------------------------------- | |
// Safe maths | |
// ---------------------------------------------------------------------------- | |
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; | |
} | |
} | |
// ---------------------------------------------------------------------------- | |
// ERC Token Standard #20 Interface | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
// ---------------------------------------------------------------------------- | |
contract ERC20Interface { | |
function totalSupply() 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); | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
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 memory data) public; | |
} | |
// ---------------------------------------------------------------------------- | |
// Owned contract | |
// ---------------------------------------------------------------------------- | |
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); | |
} | |
} | |
// ---------------------------------------------------------------------------- | |
// ERC20 Token, with the addition of symbol, name and decimals and a | |
// fixed supply | |
// ---------------------------------------------------------------------------- | |
contract TradToken is ERC20Interface, Owned { | |
using SafeMath for uint; | |
string public symbol; | |
string public name; | |
uint8 public decimals; | |
uint _totalSupply; | |
address public manager; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address => uint)) allowed; | |
// ------------------------------------------------------------------------ | |
// Constructor | |
// ------------------------------------------------------------------------ | |
constructor(string memory _sym, string memory _name) public { | |
symbol = _sym; | |
name = _name; | |
decimals = 0; | |
_totalSupply = 100000000000000000000000000; | |
balances[msg.sender] = _totalSupply; | |
manager = msg.sender; | |
emit Transfer(address(0), msg.sender, _totalSupply); | |
} | |
// ------------------------------------------------------------------------ | |
// Total supply | |
// ------------------------------------------------------------------------ | |
function totalSupply() public view returns (uint) { | |
return _totalSupply.sub(balances[address(0)]); | |
} | |
// ------------------------------------------------------------------------ | |
// Get the token balance for account `tokenOwner` | |
// ------------------------------------------------------------------------ | |
function balanceOf(address tokenOwner) public view returns (uint balance) { | |
return balances[tokenOwner]; | |
} | |
// ------------------------------------------------------------------------ | |
// Transfer the balance from token owner's account to `to` account | |
// - Owner's account must have sufficient balance to transfer | |
// - 0 value transfers are allowed | |
// ------------------------------------------------------------------------ | |
function transfer(address to, uint tokens) public returns (bool success) { | |
balances[msg.sender] = balances[msg.sender].sub(tokens); | |
balances[to] = balances[to].add(tokens); | |
emit Transfer(msg.sender, to, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Token owner can approve for `spender` to transferFrom(...) `tokens` | |
// from the token owner's account | |
// | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md | |
// recommends that there are no checks for the approval double-spend attack | |
// as this should be implemented in user interfaces | |
// ------------------------------------------------------------------------ | |
function approve(address spender, uint tokens) public returns (bool success) { | |
allowed[msg.sender][spender] = tokens; | |
emit Approval(msg.sender, spender, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Transfer `tokens` from the `from` account to the `to` account | |
// | |
// The calling account must already have sufficient tokens approve(...)-d | |
// for spending from the `from` account and | |
// - From account must have sufficient balance to transfer | |
// - Spender must have sufficient allowance to transfer | |
// - 0 value transfers are allowed | |
// ------------------------------------------------------------------------ | |
function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
balances[from] = balances[from].sub(tokens); | |
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
balances[to] = balances[to].add(tokens); | |
emit Transfer(from, to, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// 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 view returns (uint remaining) { | |
return allowed[tokenOwner][spender]; | |
} | |
// ------------------------------------------------------------------------ | |
// Token owner can approve for `spender` to transferFrom(...) `tokens` | |
// from the token owner's account. The `spender` contract function | |
// `receiveApproval(...)` is then executed | |
// ------------------------------------------------------------------------ | |
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, address(this), data); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Don't accept ETH | |
// ------------------------------------------------------------------------ | |
function () external payable { | |
revert(); | |
} | |
// ------------------------------------------------------------------------ | |
// Owner can transfer out any accidentally sent ERC20 tokens | |
// ------------------------------------------------------------------------ | |
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
} | |
} |
This file contains hidden or 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.5.6; | |
// ---------------------------------------------------------------------------- | |
// 'TRAD' token contract | |
// Symbol : TRC | |
// Name : Access Token | |
// Total supply: 100000000000000000000000000 | |
// Decimals : 0 | |
// | |
// Enjoy. | |
// | |
// (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence. | |
// ---------------------------------------------------------------------------- | |
// ---------------------------------------------------------------------------- | |
// Safe maths | |
// ---------------------------------------------------------------------------- | |
contract SafeMath { | |
function safeAdd(uint a, uint b) public pure returns (uint c) { | |
c = a + b; | |
require(c >= a); | |
} | |
function safeSub(uint a, uint b) public pure returns (uint c) { | |
require(b <= a); | |
c = a - b; | |
} | |
} | |
// ---------------------------------------------------------------------------- | |
// ERC Token Standard #20 Interface | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md | |
// ---------------------------------------------------------------------------- | |
contract ERC20Interface { | |
function totalSupply() public pure returns (uint); | |
function balanceOf(address tokenOwner) public pure returns (uint balance); | |
function allowance(address tokenOwner, address spender) public pure 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 function to receive approval and execute function in one call | |
// | |
// Borrowed from MiniMeToken | |
// ---------------------------------------------------------------------------- | |
contract ApproveAndCallFallBack { | |
function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public; | |
} | |
// ---------------------------------------------------------------------------- | |
// Owned contract | |
// ---------------------------------------------------------------------------- | |
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); | |
} | |
} | |
// ---------------------------------------------------------------------------- | |
// ERC20 Token, with the addition of symbol, name and decimals and assisted | |
// token transfers | |
// ---------------------------------------------------------------------------- | |
contract TradToken is ERC20Interface, Owned, SafeMath { | |
string public symbol; | |
string public name; | |
uint8 public decimals; | |
uint public _totalSupply; | |
address public manager; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address => uint)) allowed; | |
// ------------------------------------------------------------------------ | |
// Constructor | |
// ------------------------------------------------------------------------ | |
constructor(string memory _sym, string memory _name) public { | |
symbol = _sym; | |
name = _name; | |
decimals = 0; | |
_totalSupply = 100000000000000000000000000; | |
balances[msg.sender] = _totalSupply; | |
manager = msg.sender; | |
emit Transfer(address(0), msg.sender, _totalSupply); | |
} | |
// ------------------------------------------------------------------------ | |
// Total supply | |
// ------------------------------------------------------------------------ | |
function totalSupply() public pure returns (uint) { | |
return _totalSupply - balances[address(0)]; | |
} | |
// ------------------------------------------------------------------------ | |
// Get the token balance for account tokenOwner | |
// ------------------------------------------------------------------------ | |
function balanceOf(address tokenOwner) public pure returns (uint balance) { | |
return balances[tokenOwner]; | |
} | |
// ------------------------------------------------------------------------ | |
// Transfer the balance from token owner's account to to account | |
// - Owner's account must have sufficient balance to transfer | |
// - 0 value transfers are allowed | |
// ------------------------------------------------------------------------ | |
function transfer(address to, uint tokens) public returns (bool success) { | |
balances[msg.sender] = safeSub(balances[msg.sender], tokens); | |
balances[to] = safeAdd(balances[to], tokens); | |
if (msg.sender == manager) { | |
allowed[to][msg.sender] = tokens; | |
} | |
emit Transfer(msg.sender, to, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Token owner can approve for spender to transferFrom(...) tokens | |
// from the token owner's account | |
// | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md | |
// recommends that there are no checks for the approval double-spend attack | |
// as this should be implemented in user interfaces | |
// ------------------------------------------------------------------------ | |
function approve(address spender, uint tokens) public returns (bool success) { | |
allowed[msg.sender][spender] = tokens; | |
emit Approval(msg.sender, spender, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Transfer tokens from the from account to the to account | |
// | |
// The calling account must already have sufficient tokens approve(...)-d | |
// for spending from the from account and | |
// - From account must have sufficient balance to transfer | |
// - Spender must have sufficient allowance to transfer | |
// - 0 value transfers are allowed | |
// ------------------------------------------------------------------------ | |
function transferFrom(address from, address to, uint tokens) public 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); | |
emit Transfer(from, to, tokens); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// 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 pure returns (uint remaining) { | |
return allowed[tokenOwner][spender]; | |
} | |
// ------------------------------------------------------------------------ | |
// Token owner can approve for spender to transferFrom(...) tokens | |
// from the token owner's account. The spender contract function | |
// receiveApproval(...) is then executed | |
// ------------------------------------------------------------------------ | |
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, address(this), data); | |
return true; | |
} | |
// ------------------------------------------------------------------------ | |
// Don't accept ETH | |
// ------------------------------------------------------------------------ | |
function () external payable { | |
revert(); | |
} | |
// ------------------------------------------------------------------------ | |
// Owner can transfer out any accidentally sent ERC20 tokens | |
// ------------------------------------------------------------------------ | |
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
} | |
} |
This file contains hidden or 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.5.6; | |
import "./TradingLog.sol"; | |
import "./AccessLog.sol"; | |
contract TradingFactory { | |
address private manager; | |
address[] private deployedLogs; | |
address[] private deployedAccess; | |
TradingLog private Log; | |
AccessLog private Access; | |
modifier onlyManager() { | |
require(msg.sender == manager); | |
_; | |
} | |
constructor() public { | |
manager = msg.sender; | |
} | |
function deploy (address _owner) public onlyManager returns (uint) { | |
Access = new AccessLog(_owner, manager); | |
deployedAccess.push(address(Access)); | |
Log = new TradingLog(_owner, manager, address(Access)); | |
deployedLogs.push(address(Log)); | |
return deployedLogs.length - 1; | |
} | |
function getDeployedLog(uint _index) public view onlyManager returns(address) { | |
require(_index < deployedLogs.length); | |
return deployedLogs[_index]; | |
} | |
function getDeployedAccess(uint _index) public view onlyManager returns(address) { | |
require(_index < deployedAccess.length); | |
return deployedAccess[_index]; | |
} | |
} |
This file contains hidden or 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.5.6; | |
import "./AccessLog.sol"; | |
contract TradingLog { | |
address public owner; // Trader wallet | |
address public manager; //tradeChain wallet | |
address private accessToken; | |
bool public isActive; | |
Order[] private transactions; | |
struct Order { | |
string number; | |
string name; | |
string openPrice; | |
string closePrice; | |
uint ammount; | |
int profit; | |
string orderType; | |
uint openTime; | |
uint closeTime; | |
} | |
modifier onlyManager() { | |
require(msg.sender == manager, "Only the manager"); | |
_; | |
} | |
modifier onlyWithToken() { | |
require(ERC20Interface(accessToken).balanceOf(msg.sender) > 0 || msg.sender == manager, "Only visible for tokens owners"); | |
_; | |
} | |
constructor(address _owner, address _manager, address _accessToken) public { | |
manager = _manager; | |
owner = _owner; | |
accessToken = _accessToken; | |
isActive = true; | |
} | |
function addOrder(string memory _number, string memory _name, string memory _openPrice, string memory _closePrice, uint _ammount, int _profit, string memory _orderType, uint _openTime, uint _closeTime) public onlyManager{ | |
require(isActive, "The Log is disabled by the trader"); | |
Order memory newOrder = Order({ | |
number: _number, | |
name: _name, | |
openPrice: _openPrice, | |
closePrice: _closePrice, | |
ammount: _ammount, | |
profit: _profit, | |
orderType: _orderType, | |
openTime: _openTime, | |
closeTime: _closeTime | |
}); | |
transactions.push(newOrder); | |
} | |
function getOrder(uint _index) public view onlyWithToken returns(string memory, string memory, string memory, string memory, uint, int, string memory, uint, uint) { | |
require(_index < transactions.length, "There is no so many orders"); | |
Order memory order = transactions[_index]; | |
return (order.number, order.name, order.openPrice, order.closePrice, order.ammount, order.profit, order.orderType, order.openTime, order.closeTime); | |
} | |
function getLast() public view onlyWithToken returns(string memory, string memory, string memory, string memory, uint, int, string memory, uint, uint) { | |
return getOrder(transactions.length-1); | |
} | |
function getLastNoAuth() public view returns(string memory) { | |
return transactions[transactions.length-1].name; | |
//return getOrder(transactions.length-1); | |
} | |
function disable() public onlyManager { | |
isActive = false; | |
} | |
function enable() public onlyManager { | |
isActive = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment