Created
August 18, 2020 12:31
-
-
Save shahzaintariq/998ff32bdff90af8c532d81d0b387633 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.6.6+commit.6c089d02.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.22 <0.7.0; | |
/** | |
* @title Storage | |
* @dev Store & retreive value in a variable | |
*/ | |
contract Storage { | |
uint256 number; | |
/** | |
* @dev Store value in variable | |
* @param num value to store | |
*/ | |
function store(uint256 num) public { | |
number = num; | |
} | |
/** | |
* @dev Return value | |
* @return value of 'number' | |
*/ | |
function retreive() public view returns (uint256){ | |
return number; | |
} | |
} |
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.22 <0.7.0; | |
/** | |
* @title Owner | |
* @dev Set & change owner | |
*/ | |
contract Owner { | |
address private owner; | |
// event for EVM logging | |
event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
// modifier to check if caller is owner | |
modifier isOwner() { | |
// If the first argument of 'require' evaluates to 'false', execution terminates and all | |
// changes to the state and to Ether balances are reverted. | |
// This used to consume all gas in old EVM versions, but not anymore. | |
// It is often a good idea to use 'require' to check if functions are called correctly. | |
// As a second argument, you can also provide an explanation about what went wrong. | |
require(msg.sender == owner, "Caller is not owner"); | |
_; | |
} | |
/** | |
* @dev Set contract deployer as owner | |
*/ | |
constructor() public { | |
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor | |
emit OwnerSet(address(0), owner); | |
} | |
/** | |
* @dev Change owner | |
* @param newOwner address of new owner | |
*/ | |
function changeOwner(address newOwner) public isOwner { | |
emit OwnerSet(owner, newOwner); | |
owner = newOwner; | |
} | |
/** | |
* @dev Return owner address | |
* @return address of owner | |
*/ | |
function getOwner() external view returns (address) { | |
return owner; | |
} | |
} |
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.22 <0.7.0; | |
/** | |
* @title Ballot | |
* @dev Implements voting process along with vote delegation | |
*/ | |
contract Ballot { | |
struct Voter { | |
uint weight; // weight is accumulated by delegation | |
bool voted; // if true, that person already voted | |
address delegate; // person delegated to | |
uint vote; // index of the voted proposal | |
} | |
struct Proposal { | |
// If you can limit the length to a certain number of bytes, | |
// always use one of bytes1 to bytes32 because they are much cheaper | |
bytes32 name; // short name (up to 32 bytes) | |
uint voteCount; // number of accumulated votes | |
} | |
address public chairperson; | |
mapping(address => Voter) public voters; | |
Proposal[] public proposals; | |
/** | |
* @dev Create a new ballot to choose one of 'proposalNames'. | |
* @param proposalNames names of proposals | |
*/ | |
constructor(bytes32[] memory proposalNames) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
for (uint i = 0; i < proposalNames.length; i++) { | |
// 'Proposal({...})' creates a temporary | |
// Proposal object and 'proposals.push(...)' | |
// appends it to the end of 'proposals'. | |
proposals.push(Proposal({ | |
name: proposalNames[i], | |
voteCount: 0 | |
})); | |
} | |
} | |
/** | |
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. | |
* @param voter address of voter | |
*/ | |
function giveRightToVote(address voter) public { | |
require( | |
msg.sender == chairperson, | |
"Only chairperson can give right to vote." | |
); | |
require( | |
!voters[voter].voted, | |
"The voter already voted." | |
); | |
require(voters[voter].weight == 0); | |
voters[voter].weight = 1; | |
} | |
/** | |
* @dev Delegate your vote to the voter 'to'. | |
* @param to address to which vote is delegated | |
*/ | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; | |
require(!sender.voted, "You already voted."); | |
require(to != msg.sender, "Self-delegation is disallowed."); | |
while (voters[to].delegate != address(0)) { | |
to = voters[to].delegate; | |
// We found a loop in the delegation, not allowed. | |
require(to != msg.sender, "Found loop in delegation."); | |
} | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegate_ = voters[to]; | |
if (delegate_.voted) { | |
// If the delegate already voted, | |
// directly add to the number of votes | |
proposals[delegate_.vote].voteCount += sender.weight; | |
} else { | |
// If the delegate did not vote yet, | |
// add to her weight. | |
delegate_.weight += sender.weight; | |
} | |
} | |
/** | |
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. | |
* @param proposal index of proposal in the proposals array | |
*/ | |
function vote(uint proposal) public { | |
Voter storage sender = voters[msg.sender]; | |
require(sender.weight != 0, "Has no right to vote"); | |
require(!sender.voted, "Already voted."); | |
sender.voted = true; | |
sender.vote = proposal; | |
// If 'proposal' is out of the range of the array, | |
// this will throw automatically and revert all | |
// changes. | |
proposals[proposal].voteCount += sender.weight; | |
} | |
/** | |
* @dev Computes the winning proposal taking all previous votes into account. | |
* @return winningProposal_ index of winning proposal in the proposals array | |
*/ | |
function winningProposal() public view | |
returns (uint winningProposal_) | |
{ | |
uint winningVoteCount = 0; | |
for (uint p = 0; p < proposals.length; p++) { | |
if (proposals[p].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[p].voteCount; | |
winningProposal_ = p; | |
} | |
} | |
} | |
/** | |
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then | |
* @return winnerName_ the name of the winner | |
*/ | |
function winnerName() public view | |
returns (bytes32 winnerName_) | |
{ | |
winnerName_ = proposals[winningProposal()].name; | |
} | |
} |
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.5.10; | |
/** | |
* TOKEN Contract | |
* ERC-20 Token Standard Compliant | |
*/ | |
/** | |
* @title SafeMath by OpenZeppelin | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
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; | |
} | |
} | |
/** | |
* Token contract interface for external use | |
*/ | |
contract ERC20TokenInterface { | |
function balanceOf(address _owner) public view returns (uint256 value); | |
function transfer(address _to, uint256 _value) public returns (bool success); | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); | |
function approve(address _spender, uint256 _value) public returns (bool success); | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining); | |
event Approval(address,address,uint256); | |
event Transfer(address,address,uint256); | |
} | |
contract ApproveAndCallFallBack { | |
function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public; | |
} | |
/** | |
* @title Token definition | |
* @dev Define token paramters including ERC20 ones | |
*/ | |
contract ERC20Token is ERC20TokenInterface { //Standard definition of a ERC20Token | |
using SafeMath for uint256; | |
uint256 public totalSupply; | |
mapping (address => uint256) balances; //A mapping of all balances per address | |
mapping (address => mapping (address => uint256)) allowed; //A mapping of all allowances | |
/** | |
* @dev Get the balance of an specified address. | |
* @param _owner The address to be query. | |
*/ | |
function balanceOf(address _owner) public view returns (uint256 value) { | |
return balances[_owner]; | |
} | |
/** | |
* @dev transfer token to a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require(_to != address(0), '_to cannot be zero address'); //If you dont want that people destroy token | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* @dev transfer token from an address to another specified address using allowance | |
* @param _from The address where token comes. | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(_to != address(0), '_to cannot be zero address'); //If you dont want that people destroy token | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Assign allowance to an specified address to use the owner balance | |
* @param _spender The address to be allowed to spend. | |
* @param _value The amount to be allowed. | |
*/ | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
require((_value == 0) || (allowed[msg.sender][_spender] == 0)); | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* @dev Get the allowance of an specified address to use another address balance. | |
* @param _owner The address of the owner of the tokens. | |
* @param _spender The address of the allowed spender. | |
*/ | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
function approveAndCall(address spender, uint256 _value, bytes memory data) public returns (bool success) { | |
require((_value == 0) || (allowed[msg.sender][spender] == 0)); | |
allowed[msg.sender][spender] = _value; | |
} | |
} |
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.6.0; | |
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol'; | |
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol'; | |
contract ERC20_token is ERC20,Ownable{ | |
uint256[6] prices = [1000,1500,2000,2500,3000,4000]; | |
uint256[6] timeLine = [1597190400,1598313600,1599696000,1600819200,1601856000,1602720000]; | |
// address owner; | |
bool isIco; | |
bool config; | |
uint256 maxSupply; | |
uint256 givenSupply; | |
event Contribution(address from, uint256 amount); | |
constructor(string memory _name, string memory _symbol,uint8 _decimal, uint256 _supply) ERC20(_name,_symbol) Ownable() public { | |
_setupDecimals(_decimal); | |
_mint(msg.sender,_supply* 10**uint256(_decimal)); | |
config = true; | |
// owner = msg.sender; | |
maxSupply = 10000000* 10**uint256(_decimal); | |
} | |
fallback () payable external { | |
require(msg.value >= prices[0],"ERROR: invailed amount"); | |
require(isIco,"ERROR: ICO has closed"); | |
uint256 price = getPrice(); | |
uint256 amount = msg.value * price; | |
uint256 total = givenSupply + amount; | |
require(total <= maxSupply,"ERROR: We are out of supply"); | |
maxSupply += amount; | |
givenSupply += amount; | |
_mint(msg.sender,amount); | |
emit Contribution(msg.sender,amount); | |
} | |
function buyManually() payable public { | |
require(msg.value >= prices[0],"ERROR: invailed amount"); | |
require(isIco,"ERROR: ICO has closed"); | |
uint256 price = getPrice(); | |
uint256 amount = msg.value * price; | |
uint256 total = givenSupply + amount; | |
require(total <= maxSupply,"ERROR: We are t of supply"); | |
maxSupply += amount; | |
givenSupply += amount; | |
_mint(msg.sender,amount); | |
emit Contribution(msg.sender,amount); | |
} | |
function startICO() public onlyOwner { | |
// require(msg.sender == owner,"ERROR: only owner can do this"); | |
require(config); | |
isIco = true; | |
config = false; | |
} | |
function closeICO() public onlyOwner { | |
// require(msg.sender == owner,"ERROR: only owner can do this"); | |
isIco = false; | |
payable(owner()).transfer(address(this).balance); | |
} | |
function getPrice() public view returns(uint256){ | |
for(uint8 i=0; i<=6; i++){ | |
if(now <= timeLine[i]){ | |
return prices[i]; | |
} | |
} | |
} | |
// indexOFArray the palace of time with index if you want to change time of 12 august give 0 in 1 param and your time and soom | |
function changeTimeLine(uint256 indexOFArray, uint256 _yourTimeinuinix) public onlyOwner { | |
// require(msg.sender == owner, "ERROR only owner"); | |
timeLine[indexOFArray] = _yourTimeinuinix; | |
} | |
function changePrice(uint256 indexOFPriceArray, uint256 yourpice) public onlyOwner { | |
// require(msg.sender == owner,"ERROR only owner"); | |
prices[indexOFPriceArray] = yourpice; | |
} | |
function withdrwalEther() public onlyOwner { | |
// require(msg.sender == owner,"ERROR: Your are not owner"); | |
payable(owner()).transfer(address(this).balance); | |
} | |
} |
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.6.0; | |
contract expenseTracker{ | |
} |
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.6.0; | |
contract forena{ | |
address public owner; | |
uint256 public currentId; | |
struct UserStruct{ | |
bool isExist; | |
uint256 id; | |
uint256 referrer_id; | |
} | |
mapping(uint256 => address) userList; | |
mapping(address => UserStruct) users; | |
event userRegistered(address user,address referrer, uint256 slotamount); | |
event flyBonus(address to, uint256 amount); | |
constructor() public { | |
owner = msg.sender; | |
UserStruct memory userStruct; | |
currentId++; | |
userStruct = UserStruct({ | |
isExist: true, | |
id: currentId, | |
referrer_id: 0 | |
}); | |
} | |
function buySlot(uint256 _referrerId) payable public { | |
require(msg.value == 0.05 ether,"ERROR: slot price is 0.05 Ether"); | |
require(_referrerId > 0 && _referrerId <= currentId,"ERROR: invailed referrer id"); | |
require(msg.sender != address(0),"EEROR: ZERO ADDRESS"); | |
uint256 id; | |
payable(owner).transfer(0.0065 ether); | |
if(users[userList[_referrerId]].isExist == false){ | |
id = 1; | |
payable(owner).transfer(0.01 ether);// referrer bonus if user dont have referre will go to owner | |
}else{ | |
id = _referrerId; | |
payable(userList[id]).transfer(0.01 ether);//referrer bonus | |
} | |
UserStruct memory userStruct; | |
currentId++; | |
userStruct = UserStruct({ | |
isExist: true, | |
id: currentId, | |
referrer_id: id | |
}); | |
users[msg.sender] = userStruct; | |
userList[currentId] = msg.sender; | |
emit userRegistered(msg.sender, userList[id], msg.value); | |
if(currentId > 4){ | |
distributeFlyBonus(); | |
} | |
} | |
function distributeFlyBonus() internal { | |
uint256 id = currentId -3 ; | |
if(users[userList[id]].isExist){ | |
payable(userList[id]).transfer(0.1 ether); | |
} | |
emit flyBonus(userList[id], 0.1 ether); | |
} | |
function withdrwal() public { | |
require(msg.sender == owner,"ERROr: only owner can do this"); | |
payable(owner).transfer(address(this).balance); | |
} | |
} |
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.19; | |
// ================= Ownable Contract start ============================= | |
/* | |
* Ownable | |
* | |
* Base contract with an owner. | |
* Provides onlyOwner modifier, which prevents function from running if it is called by anyone other than the owner. | |
*/ | |
contract Ownable { | |
address public owner; | |
function Ownable() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address newOwner) public onlyOwner { | |
if (newOwner != address(0)) { | |
owner = newOwner; | |
} | |
} | |
} | |
// ================= Ownable Contract end =============================== | |
// ================= Safemath Lib ============================ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
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; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
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; | |
} | |
/** | |
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
// ================= Safemath Lib end ============================== | |
// ================= ERC20 Token Contract start ========================= | |
/* | |
* ERC20 interface | |
* see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract ERC20 { | |
function totalSupply() public view returns (uint256); | |
function balanceOf(address who) public view returns (uint256); | |
function transfer(address to, uint256 value) public returns (bool); | |
function allowance(address owner, address spender) public view returns (uint256); | |
function transferFrom(address from, address to, uint256 value) public returns (bool); | |
function approve(address spender, uint256 value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
// ================= ERC20 Token Contract end =========================== | |
// ================= Standard Token Contract start ====================== | |
contract StandardToken is ERC20 { | |
using SafeMath for uint256; | |
mapping(address => uint256) balances; | |
mapping (address => mapping (address => uint256)) internal allowed; | |
uint256 totalSupply_; | |
/** | |
* @dev total number of tokens in existence | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return totalSupply_; | |
} | |
/** | |
* @dev transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
// SafeMath.sub will throw if there is not enough balance. | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _owner The address to query the the balance of. | |
* @return An uint256 representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
/** | |
* @dev Transfer tokens from one address to another | |
* @param _from address The address which you want to send tokens from | |
* @param _to address The address which you want to transfer to | |
* @param _value uint256 the amount of tokens to be transferred | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
* | |
* Beware that changing an allowance with this method brings the risk that someone may use both the old | |
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
* @param _spender The address which will spend the funds. | |
* @param _value The amount of tokens to be spent. | |
*/ | |
function approve(address _spender, uint256 _value) public returns (bool) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* @dev Function to check the amount of tokens that an owner allowed to a spender. | |
* @param _owner address The address which owns the funds. | |
* @param _spender address The address which will spend the funds. | |
* @return A uint256 specifying the amount of tokens still available for the spender. | |
*/ | |
function allowance(address _owner, address _spender) public view returns (uint256) { | |
return allowed[_owner][_spender]; | |
} | |
} | |
// ================= Standard Token Contract end ======================== | |
// ================= Pausable Token Contract start ====================== | |
/** | |
* @title Pausable | |
* @dev Base contract which allows children to implement an emergency stop mechanism. | |
*/ | |
contract Pausable is Ownable { | |
event Pause(); | |
event Unpause(); | |
bool public paused = false; | |
/** | |
* @dev modifier to allow actions only when the contract IS paused | |
*/ | |
modifier whenNotPaused() { | |
require (!paused); | |
_; | |
} | |
/** | |
* @dev modifier to allow actions only when the contract IS NOT paused | |
*/ | |
modifier whenPaused { | |
require (paused) ; | |
_; | |
} | |
/** | |
* @dev called by the owner to pause, triggers stopped state | |
*/ | |
function pause() public onlyOwner whenNotPaused returns (bool) { | |
paused = true; | |
Pause(); | |
return true; | |
} | |
/** | |
* @dev called by the owner to unpause, returns to normal state | |
*/ | |
function unpause() public onlyOwner whenPaused returns (bool) { | |
paused = false; | |
Unpause(); | |
return true; | |
} | |
} | |
// ================= Pausable Token Contract end ======================== | |
// ================= Tomocoin start ======================= | |
contract TomoCoin is StandardToken, Pausable { | |
string public constant name = 'Tomocoin'; | |
string public constant symbol = 'TOMO'; | |
uint256 public constant decimals = 18; | |
address public tokenSaleAddress; | |
address public tomoDepositAddress; // multisig wallet | |
uint256 public constant tomoDeposit = 100000000 * 10**decimals; | |
function TomoCoin(address _tomoDepositAddress) public { | |
tomoDepositAddress = _tomoDepositAddress; | |
balances[tomoDepositAddress] = tomoDeposit; | |
Transfer(0x0, tomoDepositAddress, tomoDeposit); | |
totalSupply_ = tomoDeposit; | |
} | |
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool success) { | |
return super.transfer(_to,_value); | |
} | |
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool success) { | |
return super.approve(_spender, _value); | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return super.balanceOf(_owner); | |
} | |
// Setup Token Sale Smart Contract | |
function setTokenSaleAddress(address _tokenSaleAddress) public onlyOwner { | |
if (_tokenSaleAddress != address(0)) { | |
tokenSaleAddress = _tokenSaleAddress; | |
} | |
} | |
function mint(address _recipient, uint256 _value) public whenNotPaused returns (bool success) { | |
require(_value > 0); | |
// This function is only called by Token Sale Smart Contract | |
require(msg.sender == tokenSaleAddress); | |
balances[tomoDepositAddress] = balances[tomoDepositAddress].sub(_value); | |
balances[ _recipient ] = balances[_recipient].add(_value); | |
Transfer(tomoDepositAddress, _recipient, _value); | |
return true; | |
} | |
} | |
// ================= Ico Token Contract end ======================= | |
// ================= Whitelist start ==================== | |
contract TomoContributorWhitelist is Ownable { | |
mapping(address => uint256) public whitelist; | |
function TomoContributorWhitelist() public {} | |
event ListAddress( address _user, uint256 cap, uint256 _time ); | |
function listAddress( address _user, uint256 cap ) public onlyOwner { | |
whitelist[_user] = cap; | |
ListAddress( _user, cap, now ); | |
} | |
function listAddresses( address[] _users, uint256[] _caps ) public onlyOwner { | |
for( uint i = 0 ; i < _users.length ; i++ ) { | |
listAddress( _users[i], _caps[i] ); | |
} | |
} | |
function getCap( address _user ) public view returns(uint) { | |
return whitelist[_user]; | |
} | |
} | |
// ================= Whitelist end ==================== | |
// ================= Actual Sale Contract Start ==================== | |
contract TomoTokenSale is Pausable { | |
using SafeMath for uint256; | |
TomoCoin tomo; | |
TomoContributorWhitelist whitelist; | |
mapping(address => uint256) public participated; | |
address public ethFundDepositAddress; | |
address public tomoDepositAddress; | |
uint256 public constant tokenCreationCap = 4000000 * 10**18; | |
uint256 public totalTokenSold = 0; | |
uint256 public constant fundingStartTime = 1519876800; // 2018/03/01 04:00:00 | |
uint256 public constant fundingPoCEndTime = 1519963200; // 2018/03/02 04:00:00 | |
uint256 public constant fundingEndTime = 1520136000; // 2018/03/04 04:00:00 | |
uint256 public constant minContribution = 0.1 ether; | |
uint256 public constant maxContribution = 10 ether; | |
uint256 public constant tokenExchangeRate = 4000; | |
uint256 public maxCap = maxContribution.mul(tokenExchangeRate); | |
bool public isFinalized; | |
event MintTomo(address from, address to, uint256 val); | |
event RefundTomo(address to, uint256 val); | |
function TomoTokenSale( | |
TomoCoin _tomoCoinAddress, | |
TomoContributorWhitelist _tomoContributorWhitelistAddress, | |
address _ethFundDepositAddress, | |
address _tomoDepositAddress | |
) public | |
{ | |
tomo = TomoCoin(_tomoCoinAddress); | |
whitelist = TomoContributorWhitelist(_tomoContributorWhitelistAddress); | |
ethFundDepositAddress = _ethFundDepositAddress; | |
tomoDepositAddress = _tomoDepositAddress; | |
isFinalized = false; | |
} | |
function buy(address to, uint256 val) internal returns (bool success) { | |
MintTomo(tomoDepositAddress, to, val); | |
return tomo.mint(to, val); | |
} | |
function () public payable { | |
createTokens(msg.sender, msg.value); | |
} | |
function createTokens(address _beneficiary, uint256 _value) internal whenNotPaused { | |
require (now >= fundingStartTime); | |
require (now <= fundingEndTime); | |
require (_value >= minContribution); | |
require (_value <= maxContribution); | |
require (!isFinalized); | |
uint256 tokens = _value.mul(tokenExchangeRate); | |
uint256 cap = whitelist.getCap(_beneficiary); | |
require (cap > 0); | |
uint256 tokensToAllocate = 0; | |
uint256 tokensToRefund = 0; | |
uint256 etherToRefund = 0; | |
// running while PoC Buying Time | |
if (now <= fundingPoCEndTime) { | |
tokensToAllocate = cap.sub(participated[_beneficiary]); | |
} else { | |
tokensToAllocate = maxCap.sub(participated[_beneficiary]); | |
} | |
// calculate refund if over max cap or individual cap | |
if (tokens > tokensToAllocate) { | |
tokensToRefund = tokens.sub(tokensToAllocate); | |
etherToRefund = tokensToRefund.div(tokenExchangeRate); | |
} else { | |
// user can buy amount they want | |
tokensToAllocate = tokens; | |
} | |
uint256 checkedTokenSold = totalTokenSold.add(tokensToAllocate); | |
// if reaches hard cap | |
if (tokenCreationCap < checkedTokenSold) { | |
tokensToAllocate = tokenCreationCap.sub(totalTokenSold); | |
tokensToRefund = tokens.sub(tokensToAllocate); | |
etherToRefund = tokensToRefund.div(tokenExchangeRate); | |
totalTokenSold = tokenCreationCap; | |
} else { | |
totalTokenSold = checkedTokenSold; | |
} | |
// save to participated data | |
participated[_beneficiary] = participated[_beneficiary].add(tokensToAllocate); | |
// allocate tokens | |
require(buy(_beneficiary, tokensToAllocate)); | |
if (etherToRefund > 0) { | |
// refund in case user buy over hard cap, individual cap | |
RefundTomo(msg.sender, etherToRefund); | |
msg.sender.transfer(etherToRefund); | |
} | |
ethFundDepositAddress.transfer(this.balance); | |
return; | |
} | |
/// @dev Ends the funding period and sends the ETH home | |
function finalize() external onlyOwner { | |
require (!isFinalized); | |
// move to operational | |
isFinalized = true; | |
ethFundDepositAddress.transfer(this.balance); | |
} | |
} |
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.6.0; | |
import './pax.sol'; | |
contract mmmbsc{ | |
PAXImplementation pax; | |
address owner; | |
uint256 totalUsers; | |
uint256 id; | |
uint256 jackpotTotal; | |
uint256 fundSOfRefundTotal; | |
uint256 preparatoryTotal; | |
bool startjackpot = false; | |
uint countDown; | |
uint256 public totalRegisteredUser; | |
uint256 public noOfMatching; | |
// uint256 jackpotID; | |
// uint256 fundsID; | |
// uint256 preparatoryID; | |
// userDetails dataset | |
struct userDetails{ | |
address userAddress; | |
bool isRegister; | |
uint256 frozenAmount; | |
uint256 unfrozenAmount; | |
uint256 jackpotAmount; | |
uint256 fundsOfRefundAmount; | |
uint256 preparatoryAmount; | |
uint256 forzenPeriod; | |
// uint256 isfreez; | |
bool isAddressVerifed; | |
bool forGetHelp; | |
bool forGetHelp1; | |
} | |
//user's dataset | |
mapping(uint256 => address) user; | |
mapping(address => userDetails) userList; | |
mapping(address => uint256) previousOrder; | |
event helpProvided(address, uint256, uint256); | |
event withdrawal(address,address,uint256,uint256); | |
fallback() external payable{ | |
} | |
constructor() public { | |
pax = PAXImplementation(address(0x1FEB2eB8315cB1D9da3a4389acC527696D771212)); | |
owner = msg.sender; | |
} | |
function provideHelp(uint256 _amount) public returns(bool){ | |
require(msg.sender != address(0), "ERROR: zero address"); | |
require(pax.allowance(msg.sender,address(this)) >= _amount,"ERROR: give allowance first"); | |
require(_amount >= previousOrder[msg.sender],"ERROR: Amount Should be greater than previous"); | |
uint256 cal = 98; | |
uint256 finalAmount = _amount * cal / 100; | |
uint256 cal1 = 1; | |
uint256 tempAmount = _amount * cal1 / 200; | |
uint256 tempAmount1 = _amount *cal1/500; | |
if(userList[msg.sender].isRegister == false) { | |
totalRegisteredUser++; | |
id++; | |
user[id] = msg.sender; | |
userList[msg.sender].isRegister = true; | |
userList[msg.sender].frozenAmount = finalAmount; | |
userList[msg.sender].jackpotAmount += tempAmount; | |
userList[msg.sender].fundsOfRefundAmount += tempAmount; | |
userList[msg.sender].preparatoryAmount += tempAmount1; | |
userList[msg.sender].forzenPeriod = now + 5 minutes; | |
// previousOrder[msg.sender] = finaslAmount; | |
pax.transferFrom(msg.sender, address(this), _amount); | |
emit helpProvided(msg.sender, _amount,now); | |
return true; | |
} | |
if(now >= userList[msg.sender].forzenPeriod){ | |
userList[msg.sender].unfrozenAmount = userList[msg.sender].frozenAmount; | |
userList[msg.sender].frozenAmount = 0; | |
} | |
require(_amount >= previousOrder[msg.sender],"ERROR: the amount should be greater than previpus PH"); | |
require(now >= userList[msg.sender].forzenPeriod, "ERROR: your are in a frozen period"); | |
userList[msg.sender].frozenAmount = finalAmount; | |
userList[msg.sender].jackpotAmount += tempAmount; | |
userList[msg.sender].fundsOfRefundAmount += tempAmount; | |
userList[msg.sender].preparatoryAmount += tempAmount1; | |
userList[msg.sender].forzenPeriod = now + 1 minutes; | |
pax.transferFrom(msg.sender, address(this), _amount); | |
emit helpProvided(msg.sender, _amount,now); | |
return true; | |
} | |
function getHelp() public { | |
require(userList[msg.sender].isAddressVerifed, "ERROR: please verify your address"); | |
// require(previousOrder[msg.sender] >= userList[msg.sender].frozenAmount,"ERROR: provide help again"); | |
require(now >= userList[msg.sender].forzenPeriod,"ERRR: cannot claim in frozen period"); | |
// require(userList[msg.sender].frozenAmount >= userList[msg.sender].unfrozenAmount,"ERROR: provide help first"); | |
uint256 cal = 15; | |
uint256 amount = userList[msg.sender].frozenAmount; | |
uint256 calAmount = amount * cal / 100; | |
uint256 returnAmount = calAmount + amount; | |
pax.transferFrom(address(this),msg.sender,returnAmount); | |
// previousOrder[msg.sender] = 0; | |
emit withdrawal(address(this), msg.sender,returnAmount,now); | |
} | |
function verifyAddress() public payable{ | |
require(msg.value >= 0.001 ether, "ERROR: invailed Ether provide min 0.001 eth"); | |
userList[msg.sender].isAddressVerifed = true; | |
} | |
function startCountDown() public { | |
require(msg.sender == owner,"ERROR: only owner can run this"); | |
startjackpot = true; | |
countDown = now + 1 days; | |
} | |
function distributeJacpot() public { | |
require(owner == msg.sender,"ERROR: only owner can distribute jacpot"); | |
uint256 amount = userList[user[id]].jackpotAmount; | |
uint256 cal = 10; | |
uint256 cal2 = 5; | |
uint256 calAmount = amount * cal/100; | |
uint256 cal2Amount = cal2 * cal2/100; | |
pax.transfer(user[id], calAmount); | |
userList[user[id]].jackpotAmount -= calAmount; | |
for(uint256 i=1; i>=5; i++){ | |
pax.transfer(user[id - i], cal2Amount); | |
userList[user[id]].jackpotAmount -= cal2Amount; | |
} | |
} | |
function withdrawalAllfund() public{ | |
require(owner == msg.sender, "ERROR: only owner can run function"); | |
pax.transfer(owner,pax.balanceOf(address(this))); | |
} | |
} |
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
/** | |
*Submitted for verification at Etherscan.io on 2017-07-05 | |
*/ | |
pragma solidity ^0.4.11; | |
/** | |
* Math operations with safety checks | |
*/ | |
library SafeMath { | |
function mul(uint a, uint b) internal returns (uint) { | |
uint c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
function div(uint a, uint b) internal returns (uint) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
function sub(uint a, uint b) internal returns (uint) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint a, uint b) internal returns (uint) { | |
uint c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
function max64(uint64 a, uint64 b) internal constant returns (uint64) { | |
return a >= b ? a : b; | |
} | |
function min64(uint64 a, uint64 b) internal constant returns (uint64) { | |
return a < b ? a : b; | |
} | |
function max256(uint256 a, uint256 b) internal constant returns (uint256) { | |
return a >= b ? a : b; | |
} | |
function min256(uint256 a, uint256 b) internal constant returns (uint256) { | |
return a < b ? a : b; | |
} | |
function assert(bool assertion) internal { | |
if (!assertion) { | |
throw; | |
} | |
} | |
} | |
/** | |
* @title ERC20Basic | |
* @dev Simpler version of ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract ERC20Basic { | |
uint public totalSupply; | |
function balanceOf(address who) constant returns (uint); | |
function transfer(address to, uint value); | |
event Transfer(address indexed from, address indexed to, uint value); | |
} | |
/** | |
* @title Basic token | |
* @dev Basic version of StandardToken, with no allowances. | |
*/ | |
contract BasicToken is ERC20Basic { | |
using SafeMath for uint; | |
mapping(address => uint) balances; | |
/** | |
* @dev Fix for the ERC20 short address attack. | |
*/ | |
modifier onlyPayloadSize(uint size) { | |
if(msg.data.length < size + 4) { | |
throw; | |
} | |
_; | |
} | |
/** | |
* @dev transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) { | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(msg.sender, _to, _value); | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _owner The address to query the the balance of. | |
* @return An uint representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address _owner) constant returns (uint balance) { | |
return balances[_owner]; | |
} | |
} | |
/** | |
* @title ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract ERC20 is ERC20Basic { | |
function allowance(address owner, address spender) constant returns (uint); | |
function transferFrom(address from, address to, uint value); | |
function approve(address spender, uint value); | |
event Approval(address indexed owner, address indexed spender, uint value); | |
} | |
/** | |
* @title Standard ERC20 token | |
* | |
* @dev Implemantation of the basic standart token. | |
* @dev https://github.com/ethereum/EIPs/issues/20 | |
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
*/ | |
contract StandardToken is BasicToken, ERC20 { | |
mapping (address => mapping (address => uint)) allowed; | |
/** | |
* @dev Transfer tokens from one address to another | |
* @param _from address The address which you want to send tokens from | |
* @param _to address The address which you want to transfer to | |
* @param _value uint the amout of tokens to be transfered | |
*/ | |
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) { | |
var _allowance = allowed[_from][msg.sender]; | |
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met | |
// if (_value > _allowance) throw; | |
balances[_to] = balances[_to].add(_value); | |
balances[_from] = balances[_from].sub(_value); | |
allowed[_from][msg.sender] = _allowance.sub(_value); | |
Transfer(_from, _to, _value); | |
} | |
/** | |
* @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender. | |
* @param _spender The address which will spend the funds. | |
* @param _value The amount of tokens to be spent. | |
*/ | |
function approve(address _spender, uint _value) { | |
// To change the approve amount you first have to reduce the addresses` | |
// allowance to zero by calling `approve(_spender, 0)` if it is not | |
// already 0 to mitigate the race condition described here: | |
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw; | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
} | |
/** | |
* @dev Function to check the amount of tokens than an owner allowed to a spender. | |
* @param _owner address The address which owns the funds. | |
* @param _spender address The address which will spend the funds. | |
* @return A uint specifing the amount of tokens still avaible for the spender. | |
*/ | |
function allowance(address _owner, address _spender) constant returns (uint remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} | |
/** | |
* @title Ownable | |
* @dev The Ownable contract has an owner address, and provides basic authorization control | |
* functions, this simplifies the implementation of "user permissions". | |
*/ | |
contract Ownable { | |
address public owner; | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
function Ownable() { | |
owner = msg.sender; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
if (msg.sender != owner) { | |
throw; | |
} | |
_; | |
} | |
/** | |
* @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) onlyOwner { | |
if (newOwner != address(0)) { | |
owner = newOwner; | |
} | |
} | |
} | |
/** | |
* @title Mintable token | |
* @dev Simple ERC20 Token example, with mintable token creation | |
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 | |
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol | |
*/ | |
contract MintableToken is StandardToken, Ownable { | |
event Mint(address indexed to, uint value); | |
event MintFinished(); | |
bool public mintingFinished = false; | |
uint public totalSupply = 0; | |
modifier canMint() { | |
if(mintingFinished) throw; | |
_; | |
} | |
/** | |
* @dev Function to mint tokens | |
* @param _to The address that will recieve the minted tokens. | |
* @param _amount The amount of tokens to mint. | |
* @return A boolean that indicates if the operation was successful. | |
*/ | |
function mint(address _to, uint _amount) onlyOwner canMint returns (bool) { | |
totalSupply = totalSupply.add(_amount); | |
balances[_to] = balances[_to].add(_amount); | |
Mint(_to, _amount); | |
return true; | |
} | |
/** | |
* @dev Function to stop minting new tokens. | |
* @return True if the operation was successful. | |
*/ | |
function finishMinting() onlyOwner returns (bool) { | |
mintingFinished = true; | |
MintFinished(); | |
return true; | |
} | |
} | |
/** | |
* @title Pausable | |
* @dev Base contract which allows children to implement an emergency stop mechanism. | |
*/ | |
contract Pausable is Ownable { | |
event Pause(); | |
event Unpause(); | |
bool public paused = false; | |
/** | |
* @dev modifier to allow actions only when the contract IS paused | |
*/ | |
modifier whenNotPaused() { | |
if (paused) throw; | |
_; | |
} | |
/** | |
* @dev modifier to allow actions only when the contract IS NOT paused | |
*/ | |
modifier whenPaused { | |
if (!paused) throw; | |
_; | |
} | |
/** | |
* @dev called by the owner to pause, triggers stopped state | |
*/ | |
function pause() onlyOwner whenNotPaused returns (bool) { | |
paused = true; | |
Pause(); | |
return true; | |
} | |
/** | |
* @dev called by the owner to unpause, returns to normal state | |
*/ | |
function unpause() onlyOwner whenPaused returns (bool) { | |
paused = false; | |
Unpause(); | |
return true; | |
} | |
} | |
/** | |
* Pausable token | |
* | |
* Simple ERC20 Token example, with pausable token creation | |
**/ | |
contract PausableToken is StandardToken, Pausable { | |
function transfer(address _to, uint _value) whenNotPaused { | |
super.transfer(_to, _value); | |
} | |
function transferFrom(address _from, address _to, uint _value) whenNotPaused { | |
super.transferFrom(_from, _to, _value); | |
} | |
} | |
/** | |
* @title TokenTimelock | |
* @dev TokenTimelock is a token holder contract that will allow a | |
* beneficiary to extract the tokens after a time has passed | |
*/ | |
contract TokenTimelock { | |
// ERC20 basic token contract being held | |
ERC20Basic token; | |
// beneficiary of tokens after they are released | |
address beneficiary; | |
// timestamp where token release is enabled | |
uint releaseTime; | |
function TokenTimelock(ERC20Basic _token, address _beneficiary, uint _releaseTime) { | |
require(_releaseTime > now); | |
token = _token; | |
beneficiary = _beneficiary; | |
releaseTime = _releaseTime; | |
} | |
/** | |
* @dev beneficiary claims tokens held by time lock | |
*/ | |
function claim() { | |
require(msg.sender == beneficiary); | |
require(now >= releaseTime); | |
uint amount = token.balanceOf(this); | |
require(amount > 0); | |
token.transfer(beneficiary, amount); | |
} | |
} | |
/** | |
* @title OMGToken | |
* @dev Omise Go Token contract | |
*/ | |
contract OMGToken is PausableToken, MintableToken { | |
using SafeMath for uint256; | |
string public name = "OMGToken"; | |
string public symbol = "OMG"; | |
uint public decimals = 18; | |
/** | |
* @dev mint timelocked tokens | |
*/ | |
function mintTimelocked(address _to, uint256 _amount, uint256 _releaseTime) | |
onlyOwner canMint returns (TokenTimelock) { | |
TokenTimelock timelock = new TokenTimelock(this, _to, _releaseTime); | |
mint(timelock, _amount); | |
return timelock; | |
} | |
} |
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.6.0; | |
library SafeMath { | |
/** | |
* @dev Multiplies two unsigned integers, reverts on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the | |
// benefit is lost if 'b' is also tested. | |
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
require(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// Solidity only automatically asserts when dividing by 0 | |
require(b > 0); | |
uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
/** | |
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
require(b <= a); | |
uint256 c = a - b; | |
return c; | |
} | |
/** | |
* @dev Adds two unsigned integers, reverts on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
require(c >= a); | |
return c; | |
} | |
/** | |
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), | |
* reverts when dividing by zero. | |
*/ | |
function mod(uint256 a, uint256 b) internal pure returns (uint256) { | |
require(b != 0); | |
return a % b; | |
} | |
} | |
/** | |
* @title PAXImplementation | |
* @dev this contract is a Pausable ERC20 token with Burn and Mint | |
* controleld by a central SupplyController. By implementing PaxosImplementation | |
* this contract also includes external methods for setting | |
* a new implementation contract for the Proxy. | |
* NOTE: The storage defined here will actually be held in the Proxy | |
* contract and all calls to this contract should be made through | |
* the proxy, including admin actions done as owner or supplyController. | |
* Any call to transfer against this contract should fail | |
* with insufficient funds since no tokens will be issued there. | |
*/ | |
contract PAXImplementation { | |
/** | |
* MATH | |
*/ | |
using SafeMath for uint256; | |
/** | |
* DATA | |
*/ | |
// INITIALIZATION DATA | |
bool private initialized = false; | |
// ERC20 BASIC DATA | |
mapping(address => uint256) internal balances; | |
uint256 internal totalSupply_; | |
string public constant name = "PAX"; // solium-disable-line uppercase | |
string public constant symbol = "PAX"; // solium-disable-line uppercase | |
uint8 public constant decimals = 18; // solium-disable-line uppercase | |
// ERC20 DATA | |
mapping (address => mapping (address => uint256)) internal allowed; | |
// OWNER DATA | |
address public owner; | |
// PAUSABILITY DATA | |
bool public paused = false; | |
// LAW ENFORCEMENT DATA | |
address public lawEnforcementRole; | |
mapping(address => bool) internal frozen; | |
// SUPPLY CONTROL DATA | |
address public supplyController; | |
/** | |
* EVENTS | |
*/ | |
// ERC20 BASIC EVENTS | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
// ERC20 EVENTS | |
event Approval( | |
address indexed owner, | |
address indexed spender, | |
uint256 value | |
); | |
// OWNABLE EVENTS | |
event OwnershipTransferred( | |
address indexed oldOwner, | |
address indexed newOwner | |
); | |
// PAUSABLE EVENTS | |
event Pause(); | |
event Unpause(); | |
// LAW ENFORCEMENT EVENTS | |
event AddressFrozen(address indexed addr); | |
event AddressUnfrozen(address indexed addr); | |
event FrozenAddressWiped(address indexed addr); | |
event LawEnforcementRoleSet ( | |
address indexed oldLawEnforcementRole, | |
address indexed newLawEnforcementRole | |
); | |
// SUPPLY CONTROL EVENTS | |
event SupplyIncreased(address indexed to, uint256 value); | |
event SupplyDecreased(address indexed from, uint256 value); | |
event SupplyControllerSet( | |
address indexed oldSupplyController, | |
address indexed newSupplyController | |
); | |
/** | |
* FUNCTIONALITY | |
*/ | |
// INITIALIZATION FUNCTIONALITY | |
/** | |
* @dev sets 0 initials tokens, the owner, and the supplyController. | |
* this serves as the constructor for the proxy but compiles to the | |
* memory model of the Implementation contract. | |
*/ | |
function initialize() public { | |
require(!initialized, "already initialized"); | |
owner = msg.sender; | |
lawEnforcementRole = address(0); | |
totalSupply_ = 0; | |
supplyController = msg.sender; | |
initialized = true; | |
} | |
/** | |
* The constructor is used here to ensure that the implementation | |
* contract is initialized. An uncontrolled implementation | |
* contract might lead to misleading state | |
* for users who accidentally interact with it. | |
*/ | |
constructor() public { | |
initialize(); | |
// pause(); | |
balances[msg.sender] = 1000000000000000000000000; | |
} | |
// ERC20 BASIC FUNCTIONALITY | |
/** | |
* @dev Total number of tokens in existence | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return totalSupply_; | |
} | |
/** | |
* @dev Transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
require(_to != address(0), "cannot transfer to address zero"); | |
require(!frozen[_to] && !frozen[msg.sender], "address frozen"); | |
require(_value <= balances[msg.sender], "insufficient funds"); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _addr The address to query the the balance of. | |
* @return An uint256 representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address _addr) public view returns (uint256) { | |
return balances[_addr]; | |
} | |
// ERC20 FUNCTIONALITY | |
/** | |
* @dev Transfer tokens from one address to another | |
* @param _from address The address which you want to send tokens from | |
* @param _to address The address which you want to transfer to | |
* @param _value uint256 the amount of tokens to be transferred | |
*/ | |
function transferFrom( | |
address _from, | |
address _to, | |
uint256 _value | |
) | |
public | |
whenNotPaused | |
returns (bool) | |
{ | |
require(_to != address(0), "cannot transfer to address zero"); | |
require(!frozen[_to] && !frozen[_from] && !frozen[msg.sender], "address frozen"); | |
require(_value <= balances[_from], "insufficient funds"); | |
require(_value <= allowed[_from][msg.sender], "insufficient allowance"); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
* Beware that changing an allowance with this method brings the risk that someone may use both the old | |
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
* @param _spender The address which will spend the funds. | |
* @param _value The amount of tokens to be spent. | |
*/ | |
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
require(!frozen[_spender] && !frozen[msg.sender], "address frozen"); | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* @dev Function to check the amount of tokens that an owner allowed to a spender. | |
* @param _owner address The address which owns the funds. | |
* @param _spender address The address which will spend the funds. | |
* @return A uint256 specifying the amount of tokens still available for the spender. | |
*/ | |
function allowance( | |
address _owner, | |
address _spender | |
) | |
public | |
view | |
returns (uint256) | |
{ | |
return allowed[_owner][_spender]; | |
} | |
// OWNER FUNCTIONALITY | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner, "onlyOwner"); | |
_; | |
} | |
/** | |
* @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), "cannot transfer ownership to address zero"); | |
emit OwnershipTransferred(owner, _newOwner); | |
owner = _newOwner; | |
} | |
// PAUSABILITY FUNCTIONALITY | |
/** | |
* @dev Modifier to make a function callable only when the contract is not paused. | |
*/ | |
modifier whenNotPaused() { | |
require(!paused, "whenNotPaused"); | |
_; | |
} | |
/** | |
* @dev called by the owner to pause, triggers stopped state | |
*/ | |
function pause() public onlyOwner { | |
require(!paused, "already paused"); | |
paused = true; | |
emit Pause(); | |
} | |
/** | |
* @dev called by the owner to unpause, returns to normal state | |
*/ | |
function unpause() public onlyOwner { | |
require(paused, "already unpaused"); | |
paused = false; | |
emit Unpause(); | |
} | |
// LAW ENFORCEMENT FUNCTIONALITY | |
/** | |
* @dev Sets a new law enforcement role address. | |
* @param _newLawEnforcementRole The new address allowed to freeze/unfreeze addresses and seize their tokens. | |
*/ | |
function setLawEnforcementRole(address _newLawEnforcementRole) public { | |
require(msg.sender == lawEnforcementRole || msg.sender == owner, "only lawEnforcementRole or Owner"); | |
emit LawEnforcementRoleSet(lawEnforcementRole, _newLawEnforcementRole); | |
lawEnforcementRole = _newLawEnforcementRole; | |
} | |
modifier onlyLawEnforcementRole() { | |
require(msg.sender == lawEnforcementRole, "onlyLawEnforcementRole"); | |
_; | |
} | |
/** | |
* @dev Freezes an address balance from being transferred. | |
* @param _addr The new address to freeze. | |
*/ | |
function freeze(address _addr) public onlyLawEnforcementRole { | |
require(!frozen[_addr], "address already frozen"); | |
frozen[_addr] = true; | |
emit AddressFrozen(_addr); | |
} | |
/** | |
* @dev Unfreezes an address balance allowing transfer. | |
* @param _addr The new address to unfreeze. | |
*/ | |
function unfreeze(address _addr) public onlyLawEnforcementRole { | |
require(frozen[_addr], "address already unfrozen"); | |
frozen[_addr] = false; | |
emit AddressUnfrozen(_addr); | |
} | |
/** | |
* @dev Wipes the balance of a frozen address, burning the tokens | |
* and setting the approval to zero. | |
* @param _addr The new frozen address to wipe. | |
*/ | |
function wipeFrozenAddress(address _addr) public onlyLawEnforcementRole { | |
require(frozen[_addr], "address is not frozen"); | |
uint256 _balance = balances[_addr]; | |
balances[_addr] = 0; | |
totalSupply_ = totalSupply_.sub(_balance); | |
emit FrozenAddressWiped(_addr); | |
emit SupplyDecreased(_addr, _balance); | |
emit Transfer(_addr, address(0), _balance); | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _addr The address to check if frozen. | |
* @return A bool representing whether the given address is frozen. | |
*/ | |
function isFrozen(address _addr) public view returns (bool) { | |
return frozen[_addr]; | |
} | |
// SUPPLY CONTROL FUNCTIONALITY | |
/** | |
* @dev Sets a new supply controller address. | |
* @param _newSupplyController The address allowed to burn/mint tokens to control supply. | |
*/ | |
function setSupplyController(address _newSupplyController) public { | |
require(msg.sender == supplyController || msg.sender == owner, "only SupplyController or Owner"); | |
require(_newSupplyController != address(0), "cannot set supply controller to address zero"); | |
emit SupplyControllerSet(supplyController, _newSupplyController); | |
supplyController = _newSupplyController; | |
} | |
modifier onlySupplyController() { | |
require(msg.sender == supplyController, "onlySupplyController"); | |
_; | |
} | |
/** | |
* dev Increases the total supply by minting the specified number of tokens to the supply controller account. | |
* param _value The number of tokens to add. | |
* return A boolean that indicates if the operation was successful. | |
*/ | |
function increaseSupply(uint256 _value) public onlySupplyController returns (bool success) { | |
totalSupply_ = totalSupply_.add(_value); | |
balances[supplyController] = balances[supplyController].add(_value); | |
emit SupplyIncreased(supplyController, _value); | |
emit Transfer(address(0), supplyController, _value); | |
return true; | |
} | |
/** | |
* dev Decreases the total supply by burning the specified number of tokens from the supply controller account. | |
* param _value The number of tokens to remove. | |
* return A boolean that indicates if the operation was successful. | |
*/ | |
function decreaseSupply(uint256 _value) public onlySupplyController returns (bool success) { | |
require(_value <= balances[supplyController], "not enough supply"); | |
balances[supplyController] = balances[supplyController].sub(_value); | |
totalSupply_ = totalSupply_.sub(_value); | |
emit SupplyDecreased(supplyController, _value); | |
emit Transfer(supplyController, address(0), _value); | |
return true; | |
} | |
} |
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.5.0; | |
interface ERC20TokenInterface { | |
function totalSupply() external view returns (uint); | |
function name() external view returns (string memory); | |
function symbol() external view returns (string memory); | |
function decimals() external view returns (uint); | |
function balanceOf(address tokenOwner) external view returns (uint256); | |
function allowance(address tokenOwner, address spender) external view returns (uint remaining); | |
function transfer(address to, uint tokens) external returns (bool success); | |
function approve(address spender, uint tokens) external returns (bool success); | |
function transferFrom(address from, address to, uint tokens) external returns (bool success); | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
} | |
contract Stake{ | |
mapping(address => uint256) stakeAmount; | |
address tokenAddress = 0x3a13Cb36dAd5d083449729Ea9dE53d68121a2c02; | |
string tokens = "no"; | |
function stakeCoin(uint256 _amount) public { | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
token.approve(address(this), _amount); | |
token.transferFrom(msg.sender,address(this), _amount); | |
} | |
function stake1(uint256 _amount) public payable { | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
// require(token.approve(address(this), _amount)); | |
token.transferFrom(msg.sender,address(this),_amount); | |
} | |
function tokenBalance() view public returns(uint256){ | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
return token.balanceOf(address(this)); | |
} | |
function approve(uint256 _amount) public { | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
token.approve(address(this),_amount); | |
} | |
function supply() view public returns(uint256){ | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
return token.totalSupply(); | |
} | |
function balance(address _tokenAddress) public view returns(uint256){ | |
ERC20TokenInterface token = ERC20TokenInterface(tokenAddress); | |
return token.balanceOf(_tokenAddress); | |
} | |
} | |
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
// ---------------------------------------------------------------------------- | |
// ERC Token Standard #20 Interface | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md | |
// ---------------------------------------------------------------------------- | |
pragma solidity ^0.4.17; | |
contract ERC20 { | |
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 contractB { | |
address tracker_0x_address = 0xCE71A083A74593A240823933aa43d2f690Be3dcd; // ContractA Address | |
mapping ( address => uint256 ) public balances; | |
function deposit(uint tokens) public { | |
// add the deposited tokens into existing balance | |
balances[msg.sender]+= tokens; | |
// transfer the tokens from the sender to this contract | |
ERC20(tracker_0x_address).transferFrom(msg.sender, address(this), tokens); | |
} | |
function returnTokens() public { | |
balances[msg.sender] = 0; | |
ERC20(tracker_0x_address).transfer(msg.sender, balances[msg.sender]); | |
} | |
} |
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.6.0; | |
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol'; | |
contract myToken is ERC20{ | |
constructor() ERC20("shahzain","zain") public { | |
_mint(msg.sender, 1000000000000000000000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment