Skip to content

Instantly share code, notes, and snippets.

@anubhavgirdhar
Created August 6, 2020 13:33
Show Gist options
  • Save anubhavgirdhar/86512e685288221aeaf131bb93ef327f to your computer and use it in GitHub Desktop.
Save anubhavgirdhar/86512e685288221aeaf131bb93ef327f 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=
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;
}
}
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;
}
}
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;
}
}
pragma solidity 0.5.0;
contract HashMyFunction{
address[] public ids;
function hashMe(address[] memory employeeToken,address payable[] memory employeeAddr,uint[] memory values) public pure returns(bytes memory){
return abi.encodeWithSignature("massPayout(address,address[],address[],uint256[])",0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, employeeToken,employeeAddr,values);
}
function test() external pure returns (bytes memory){
return abi.encodeWithSelector(bytes4(keccak256('setAuthority(address)')));
}
function ens() external pure returns (bytes32){
return bytes32(keccak256('delilah'));
}
function ens1() external pure returns (bytes32){
return bytes32(keccak256('ears'));
}
function ens2() external pure returns (bytes32){
return bytes32(keccak256('fork'));
}
function ens3() external pure returns (bytes32){
return bytes32(keccak256('gear'));
}
function ens4() external pure returns (bytes32){
return bytes32(keccak256('hen'));
}
function addIds(address x, address y, address z) external returns (address[] memory){
ids.push(x);
ids.push(y);
ids.push(z);
return ids;
}
function getIds() public view returns (address[] memory){
return ids;
}
}
pragma solidity ^0.6.0;
interface IDefaultResolver {
function name(bytes32 node) external view returns (string memory);
}
pragma solidity ^0.6.0;
interface IENS {
function setOwner(bytes32 node, address owner) external;
function setSubnodeRecord(
bytes32 node,
bytes32 label,
address owner,
address resolver,
uint64 ttl
) external;
function setSubnodeOwner(
bytes32 node,
bytes32 label,
address owner
) external returns (bytes32);
}
pragma solidity ^0.6.0;
interface IENSResolver {
function setAddr(bytes32 node, address addr) external;
}
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
/**
* @title ERC-1620 Money Streaming Standard
* @author Sablier
* @dev See https://eips.ethereum.org/EIPS/eip-1620
*/
interface IERC1620 {
/**
* @notice Emits when a stream is successfully created.
*/
event CreateStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
uint256 deposit,
address tokenAddress,
uint256 startTime,
uint256 stopTime
);
/**
* @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream.
*/
event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount);
/**
* @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis.
*/
event CancelStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
uint256 senderBalance,
uint256 recipientBalance
);
function balanceOf(uint256 streamId, address who) external view returns (uint256 balance);
function getStream(uint256 streamId)
external
view
returns (
address sender,
address recipient,
uint256 deposit,
address token,
uint256 startTime,
uint256 stopTime,
uint256 remainingBalance,
uint256 ratePerSecond
);
function createSalary(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
external
returns (uint256 streamId);
function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool);
function cancelStream(uint256 streamId) external returns (bool);
}
pragma solidity ^0.6.0;
interface ERC20 {
function totalSupply() external view returns (uint supply);
function balanceOf(address _owner) external view returns (uint balance);
function transfer(address _to, uint _value) external returns (bool success);
function transferFrom(address _from, address _to, uint _value) external returns (bool success);
function approve(address _spender, uint _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint remaining);
function decimals() external view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
pragma solidity ^0.6.0;
interface IParcelWallet {
function setEns(bytes32 node, address addr,string calldata _name) external;
}
pragma solidity ^0.6.0;
interface IReverseRegistrar {
function setName(string calldata name) external returns (bytes32);
function node(address addr) external pure returns (bytes32);
}
pragma solidity ^0.6.0;
interface IUniswap {
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
}
pragma solidity ^0.6.0;
import "./parcelWallet.sol";
import "./IENS.sol";
import "./IERC20.sol";
import "./IParcelWallet.sol";
import "./IDefaultResolver.sol";
contract ParcelRegistry {
mapping(address => address) public registered;
address[] public registeredWallets;
address public publicResolverAddr = 0xf6305c19e814d2a75429Fd637d01F7ee0E77d615;
IENSResolver ENSResolver = IENSResolver(publicResolverAddr);
IENS ENSRegistry = IENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
ERC20 dai = ERC20(0xc3dbf84Abb494ce5199D5d4D815b10EC29529ff8);
ERC20 usdc = ERC20(0x472d88e5246d9bF2AB925615fc580336430679Ae);
// modifier oneAccount {
// require(registered[msg.sender] == address(0), "account exists");
// _;
// }
function changeENSOwner(bytes32 _node, address _newOwner) external {
ENSRegistry.setOwner(_node, _newOwner);
}
function getParcelWallets() external view returns (address[] memory){
return registeredWallets;
}
function register(
bytes32 _node,
bytes32 _label,
bytes32 _ownerNode,
string calldata _name
) external payable returns (address) {
ENSRegistry.setSubnodeRecord(
_node,
_label,
address(this),
publicResolverAddr,
0
);
ENSResolver.setAddr(_ownerNode, address(this));
ParcelWallet newAccount = new ParcelWallet(msg.sender);
address payable parcelWallet = address(newAccount);
ENSRegistry.setSubnodeOwner(_node, _label, parcelWallet);
IParcelWallet myAccount = IParcelWallet(parcelWallet);
myAccount.setEns(_ownerNode, parcelWallet,_name);
// Send funds to the new account
bool funded = fundAccount(parcelWallet);
require(funded, "not enough funds");
registered[msg.sender] = parcelWallet;
registeredWallets.push(parcelWallet);
return address(newAccount);
}
function fundAccount(address payable _address) internal returns (bool) {
dai.transfer(_address,1000 * 1e18);
usdc.transfer(_address,1000 * 1e18);
_address.transfer(1e18);
return true;
}
}
pragma solidity ^0.6.0;
import "./parcelWallet.sol";
import "./IENS.sol";
import "./IERC20.sol";
import "./IParcelWallet.sol";
import "./IDefaultResolver.sol";
contract ParcelRegistry {
mapping(address => address) public registered;
address[] public registeredWallets;
address public publicResolverAddr = 0xf6305c19e814d2a75429Fd637d01F7ee0E77d615;
IENSResolver ENSResolver = IENSResolver(publicResolverAddr);
IENS ENSRegistry = IENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
// address public reverseRegistrar = 0x6F628b68b30Dc3c17f345c9dbBb1E483c2b7aE5c;
// IReverseRegistrar ReverseRegistrar = IReverseRegistrar(reverseRegistrar);
// address public defaultResolver = 0x084b1c3C81545d370f3634392De611CaaBFf8148;
// IDefaultResolver DefaultResolver = IDefaultResolver(defaultResolver);
// modifier oneAccount {
// require(registered[msg.sender] == address(0), "account exists");
// _;
// }
function changeENSOwner(bytes32 _node, address _newOwner) external {
ENSRegistry.setOwner(_node, _newOwner);
}
function getParcelWallets() external view returns (address[] memory){
return registeredWallets;
}
function register(
bytes32 _node,
bytes32 _label,
bytes32 _ownerNode,
string calldata _name
) external payable returns (address) {
ENSRegistry.setSubnodeRecord(
_node,
_label,
address(this),
publicResolverAddr,
0
);
ENSResolver.setAddr(_ownerNode, address(this));
ParcelWallet newAccount = new ParcelWallet(msg.sender);
registered[msg.sender] = address(newAccount);
ENSRegistry.setSubnodeOwner(_node, _label, address(newAccount));
IParcelWallet myAccount = IParcelWallet(address(newAccount));
myAccount.setEns(_ownerNode, address(newAccount),_name);
// ERC20 erc20 = ERC20(0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735);
// erc20.transfer(address(newAccount),5000000000000000000);
registeredWallets.push(address(newAccount));
return address(newAccount);
}
// function lookUpEns(address _address) external view returns (string memory){
// bytes32 nameHash = ReverseRegistrar.node(_address);
// return DefaultResolver.name(nameHash);
// }
}
// parcelWallet.eth -- 0x8aa11e132053c70aed92114c5742dba99df7dd7aebb53dbb8361065f02ff1f87
// delilah -- 0xfb4e7c2c07f8f84285f8512bdb07eb0fd360aaf85124d7baaa9c446a8c357aac
// fork -- 0x9575ee8093561ec60b3c163aea3838187bacdd0951b7aeeddd4d5a1aecdd787e
// fork.parelwallet.eth -- 0x87afc9f1678d1faa1439134efb782c61fec5bcbb7f835df974b56dc203701b3b
// delilah.parcelwallet.eth -- 0xa204af42bde00cfb7746149143f0a2ad090653f8de8ca5a25f5c7773ee3de1a9
// parcelid.eth ---- 0x15eac8f5a11394d34a5b1073c9555027ae0ad90090cfa79b91bf12b4a3413670
//delilah.parcelid.eth ---- 0xe70ec8a964956485d7e66c1cbaf6ad8240e27cd7149704e4e0ebd5c83fcd47e0
pragma solidity ^0.6.0;
import "./IENSResolver.sol";
import "./IUniswap.sol";
import "./IERC1620.sol";
import "./IReverseRegistrar.sol";
contract ParcelStorage {
address public factoryAddress;
address public owner;
mapping(uint8 => string) public files;
uint256[] public streamIds;
address public publicResolverAddr = 0xf6305c19e814d2a75429Fd637d01F7ee0E77d615;
IENSResolver ENSResolver = IENSResolver(publicResolverAddr);
address public reverseRegistrar = 0x6F628b68b30Dc3c17f345c9dbBb1E483c2b7aE5c;
IReverseRegistrar ReverseRegistrar = IReverseRegistrar(reverseRegistrar);
address public ethAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public uniswapRouterAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswap uniswap = IUniswap(uniswapRouterAddress);
address public WETH_ADDRESS = 0xc778417E063141139Fce010982780140Aa0cD5Ab;
address public sablierAddress = 0x7ee114C3628Ca90119fC699f03665bF9dB8f5faF;
IERC1620 sablier = IERC1620(sablierAddress); // get a handle for the Sablier contract
}
pragma solidity ^0.6.0;
import "./IENSResolver.sol";
import "./IUniswap.sol";
import "./IERC1620.sol";
import "./IReverseRegistrar.sol";
contract ParcelStorage {
address public owner;
mapping(uint8 => string) public files;
uint256[] public streamIds;
address public publicResolverAddr = 0xf6305c19e814d2a75429Fd637d01F7ee0E77d615;
IENSResolver ENSResolver = IENSResolver(publicResolverAddr);
address public reverseRegistrar = 0x6F628b68b30Dc3c17f345c9dbBb1E483c2b7aE5c;
IReverseRegistrar ReverseRegistrar = IReverseRegistrar(reverseRegistrar);
address public ethAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public uniswapRouterAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswap uniswap = IUniswap(uniswapRouterAddress);
address public WETH_ADDRESS = 0xc778417E063141139Fce010982780140Aa0cD5Ab;
address public sablierAddress = 0x7ee114C3628Ca90119fC699f03665bF9dB8f5faF;
IERC1620 sablier = IERC1620(sablierAddress); // get a handle for the Sablier contract
}
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "./parcelStor.sol";
import "./IERC20.sol";
contract ParcelWallet is ParcelStorage {
constructor(address _owner, address _factory) public {
owner = _owner;
factoryAddress = _factory;
}
modifier onlyOwner {
require(msg.sender == owner, "Not the Owner");
_;
}
function addFile(uint8 index, string calldata hash) external onlyOwner {
files[index] = hash;
}
function setEns(bytes32 node, address addr,string calldata _name) external {
ENSResolver.setAddr(node, addr);
ReverseRegistrar.setName(_name);
}
function getStreamIds() public view returns (uint256[] memory) {
return streamIds;
}
// Rinkeby Addresses
// DAI : "0xc3dbf84Abb494ce5199D5d4D815b10EC29529ff8",
// WETH : "0xc778417e063141139fce010982780140aa0cd5ab"
// USDC : "0x472d88e5246d9bF2AB925615fc580336430679Ae"
function massPayout(
address employerToken,
address[] memory employeeToken,
address payable[] memory employeeAddress,
uint256[] memory values
) public payable {
for (uint256 i = 0; i < employeeAddress.length; i++) {
if (employerToken == employeeToken[i]) {
_send(employeeToken[i], employeeAddress[i], values[i]);
} else {
if (
employerToken != ethAddress &&
employeeToken[i] != ethAddress
) {
address[] memory _path = new address[](2);
_path[0] = employerToken;
_path[1] = employeeToken[i];
swapTokenToToken(_path, values[i], employeeAddress[i]);
}else {
revert("either dai or usdc");
}
// if (employerToken == ethAddress) {
// address[] memory _path = new address[](2);
// _path[0] = WETH_ADDRESS;
// _path[1] = employeeToken[i];
// // uint256[] memory returnedAmount = getAmount(
// // _path,
// // values[i]
// // );
// uniswap.swapETHForExactTokens{value:address(this).balance}(
// values[i],
// _path,
// employeeAddress[i],
// now + 12000
// );
// }
// if (
// employerToken != ethAddress &&
// employeeToken[i] == ethAddress
// ) {
// address[] memory _path = new address[](2);
// _path[0] = employerToken;
// _path[1] = WETH_ADDRESS;
// swapExactTokensToEth(_path, values[i], employeeAddress[i]);
// }
}
}
}
function swapTokenToToken(
address[] memory path,
uint256 amountOut,
address _employeeAddresss
) internal {
// uint256[] memory returnedAmount = getAmount(path, amountIn);
ERC20 erc20 = ERC20(path[0]);
erc20.approve(uniswapRouterAddress, uint(-1));
uniswap.swapTokensForExactTokens(
amountOut,
uint(-1),
path,
_employeeAddresss,
now + 12000
);
}
// function swapExactTokensToEth(
// address[] memory path,
// uint256 amountIn,
// address _employeeAddresss
// ) internal {
// uint256[] memory returnedAmount = getAmount(path, amountIn);
// ERC20 erc20 = ERC20(path[0]);
// erc20.approve(uniswapRouterAddress, amountIn);
// uniswap.swapExactTokensForETH(
// returnedAmount[0],
// returnedAmount[1],
// path,
// _employeeAddresss,
// now + 12000
// );
// }
// function swapExactEthToTokens(address[] memory path, uint amountInEth) public payable {
// uint[] memory returnedAmount = getAmount(path,amountInEth);
// uniswap.swapExactETHForTokens.value(amountInEth)(returnedAmount[1],path,address(this), now + 12000);
// }
function getAmount(address[] memory path, uint256 amountInEth)
public
view
returns (uint256[] memory)
{
uint256[] memory returnedAmount = uniswap.getAmountsOut(
amountInEth,
path
);
return returnedAmount;
}
function _send(
address _employeeToken,
address payable _employeeAddress,
uint256 _value
) internal {
if (_employeeToken == ethAddress) {
(_employeeAddress).transfer(_value);
} else {
ERC20 erc20 = ERC20(_employeeToken);
erc20.transfer(_employeeAddress, _value);
}
}
// "0xc7ad46e0b8a400bb3c915120d284aafba8fc4735",["0x4dbcdf9b62e891a7cec5a2568c3f4faf9e8abe2b","0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],["0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f","0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f"],["100000000000000000","100000000000000000"]
// "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],["0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f","0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f"],["100000000000000000","100000000000000000"]
// Money Streaming
function streamMoney(address[] calldata recipients,uint256[] calldata values, address[] calldata tokensToStream, uint256[] calldata stopTime)external returns (uint256[] memory) {
for(uint i = 0; i < recipients.length; i++){
ERC20 token = ERC20(tokensToStream[i]); // get a handle for the token contract
token.approve(address(sablier),uint(-1));
// the stream id is needed later to withdraw from or cancel the stream
uint256 streamId = sablier.createSalary(recipients[i], values[i], tokensToStream[i], block.timestamp , block.timestamp + stopTime[i]);
streamIds.push(streamId);
}
return streamIds;
}
function withdraw()external {
ERC20 erc20 = ERC20(0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735);
uint bal = erc20.balanceOf(address(this));
erc20.transfer(msg.sender,bal);
}
fallback() external payable {}
receive() external payable {}
}
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "./parcelStorage.sol";
import "./IERC20.sol";
contract ParcelWallet is ParcelStorage {
constructor(address _owner) public {
owner = _owner;
}
modifier onlyOwner {
require(msg.sender == owner, "Not the Owner");
_;
}
function addFile(uint8 index, string calldata hash) external onlyOwner {
files[index] = hash;
}
function setEns(bytes32 node, address addr,string calldata _name) external {
ENSResolver.setAddr(node, addr);
ReverseRegistrar.setName(_name);
}
function getStreamIds() public view returns (uint256[] memory) {
return streamIds;
}
// Rinkeby Addresses
// DAI : "0xc3dbf84Abb494ce5199D5d4D815b10EC29529ff8",
// WETH : "0xc778417e063141139fce010982780140aa0cd5ab"
// USDC : "0x472d88e5246d9bF2AB925615fc580336430679Ae"
function massPayout(
address employerToken,
address[] memory employeeToken,
address payable[] memory employeeAddress,
uint256[] memory values
) public payable {
for (uint256 i = 0; i < employeeAddress.length; i++) {
if (employerToken == employeeToken[i]) {
_send(employeeToken[i], employeeAddress[i], values[i]);
} else {
if (
employerToken != ethAddress &&
employeeToken[i] != ethAddress
) {
address[] memory _path = new address[](2);
_path[0] = employerToken;
_path[1] = employeeToken[i];
swapTokenToToken(_path, values[i], employeeAddress[i]);
}else {
revert("either dai or usdc");
}
// if (employerToken == ethAddress) {
// address[] memory _path = new address[](2);
// _path[0] = WETH_ADDRESS;
// _path[1] = employeeToken[i];
// // uint256[] memory returnedAmount = getAmount(
// // _path,
// // values[i]
// // );
// uniswap.swapETHForExactTokens{value:address(this).balance}(
// values[i],
// _path,
// employeeAddress[i],
// now + 12000
// );
// }
// if (
// employerToken != ethAddress &&
// employeeToken[i] == ethAddress
// ) {
// address[] memory _path = new address[](2);
// _path[0] = employerToken;
// _path[1] = WETH_ADDRESS;
// swapExactTokensToEth(_path, values[i], employeeAddress[i]);
// }
}
}
}
function swapTokenToToken(
address[] memory path,
uint256 amountOut,
address _employeeAddresss
) internal {
// uint256[] memory returnedAmount = getAmount(path, amountIn);
ERC20 erc20 = ERC20(path[0]);
erc20.approve(uniswapRouterAddress, uint(-1));
uniswap.swapTokensForExactTokens(
amountOut,
uint(-1),
path,
_employeeAddresss,
now + 12000
);
}
// function swapExactTokensToEth(
// address[] memory path,
// uint256 amountIn,
// address _employeeAddresss
// ) internal {
// uint256[] memory returnedAmount = getAmount(path, amountIn);
// ERC20 erc20 = ERC20(path[0]);
// erc20.approve(uniswapRouterAddress, amountIn);
// uniswap.swapExactTokensForETH(
// returnedAmount[0],
// returnedAmount[1],
// path,
// _employeeAddresss,
// now + 12000
// );
// }
// function swapExactEthToTokens(address[] memory path, uint amountInEth) public payable {
// uint[] memory returnedAmount = getAmount(path,amountInEth);
// uniswap.swapExactETHForTokens.value(amountInEth)(returnedAmount[1],path,address(this), now + 12000);
// }
function getAmount(address[] memory path, uint256 amountInEth)
public
view
returns (uint256[] memory)
{
uint256[] memory returnedAmount = uniswap.getAmountsOut(
amountInEth,
path
);
return returnedAmount;
}
function _send(
address _employeeToken,
address payable _employeeAddress,
uint256 _value
) internal {
if (_employeeToken == ethAddress) {
(_employeeAddress).transfer(_value);
} else {
ERC20 erc20 = ERC20(_employeeToken);
erc20.transfer(_employeeAddress, _value);
}
}
// "0xc7ad46e0b8a400bb3c915120d284aafba8fc4735",["0x4dbcdf9b62e891a7cec5a2568c3f4faf9e8abe2b","0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],["0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f","0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f"],["100000000000000000","100000000000000000"]
// "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],["0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f","0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f"],["100000000000000000","100000000000000000"]
// Money Streaming
function streamMoney(address[] calldata recipients,uint256[] calldata values, address[] calldata tokensToStream, uint256[] calldata stopTime)external returns (uint256[] memory) {
for(uint i = 0; i < recipients.length; i++){
ERC20 token = ERC20(tokensToStream[i]); // get a handle for the token contract
token.approve(address(sablier),uint(-1));
// the stream id is needed later to withdraw from or cancel the stream
uint256 streamId = sablier.createSalary(recipients[i], values[i], tokensToStream[i], block.timestamp , block.timestamp + stopTime[i]);
streamIds.push(streamId);
}
return streamIds;
}
function withdraw()external {
ERC20 erc20 = ERC20(0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735);
uint bal = erc20.balanceOf(address(this));
erc20.transfer(msg.sender,bal);
}
fallback() external payable {}
receive() external payable {}
}
/**
*Submitted for verification at Etherscan.io on 2020-06-30
*/
/**
*Submitted for verification at Etherscan.io on 2018-08-03
*/
pragma solidity ^0.4.24;
// File: contracts/Ownable.sol
/**
* Copyright CENTRE SECZ 2018
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
pragma solidity ^0.4.24;
/**
* @title Ownable
* @dev The Ownable contract from https://github.com/zeppelinos/labs/blob/master/upgradeability_ownership/contracts/ownership/Ownable.sol
* branch: master commit: 3887ab77b8adafba4a26ace002f3a684c1a3388b modified to:
* 1) Add emit prefix to OwnershipTransferred event (7/13/18)
* 2) Replace constructor with constructor syntax (7/13/18)
* 3) consolidate OwnableStorage into this contract
*/
contract Ownable {
// Owner of the contract
address private _owner;
/**
* @dev Event to show ownership has been transferred
* @param previousOwner representing the address of the previous owner
* @param newOwner representing the address of the new owner
*/
event OwnershipTransferred(address previousOwner, address newOwner);
/**
* @dev The constructor sets the original owner of the contract to the sender account.
*/
constructor() public {
setOwner(msg.sender);
}
/**
* @dev Tells the address of the owner
* @return the address of the owner
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Sets a new owner address
*/
function setOwner(address newOwner) internal {
_owner = newOwner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner());
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner(), newOwner);
setOwner(newOwner);
}
}
// File: contracts/Blacklistable.sol
/**
* Copyright CENTRE SECZ 2018
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
pragma solidity ^0.4.24;
/**
* @title Blacklistable Token
* @dev Allows accounts to be blacklisted by a "blacklister" role
*/
contract Blacklistable is Ownable {
address public blacklister;
mapping(address => bool) internal blacklisted;
event Blacklisted(address indexed _account);
event UnBlacklisted(address indexed _account);
event BlacklisterChanged(address indexed newBlacklister);
/**
* @dev Throws if called by any account other than the blacklister
*/
modifier onlyBlacklister() {
require(msg.sender == blacklister);
_;
}
/**
* @dev Throws if argument account is blacklisted
* @param _account The address to check
*/
modifier notBlacklisted(address _account) {
require(blacklisted[_account] == false);
_;
}
/**
* @dev Checks if account is blacklisted
* @param _account The address to check
*/
function isBlacklisted(address _account) public view returns (bool) {
return blacklisted[_account];
}
/**
* @dev Adds account to blacklist
* @param _account The address to blacklist
*/
function blacklist(address _account) public onlyBlacklister {
blacklisted[_account] = true;
emit Blacklisted(_account);
}
/**
* @dev Removes account from blacklist
* @param _account The address to remove from the blacklist
*/
function unBlacklist(address _account) public onlyBlacklister {
blacklisted[_account] = false;
emit UnBlacklisted(_account);
}
function updateBlacklister(address _newBlacklister) public onlyOwner {
require(_newBlacklister != address(0));
blacklister = _newBlacklister;
emit BlacklisterChanged(blacklister);
}
}
// File: contracts/Pausable.sol
/**
* Copyright CENTRE SECZ 2018
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
pragma solidity ^0.4.24;
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
* Based on openzeppelin tag v1.10.0 commit: feb665136c0dae9912e08397c1a21c4af3651ef3
* Modifications:
* 1) Added pauser role, switched pause/unpause to be onlyPauser (6/14/2018)
* 2) Removed whenNotPause/whenPaused from pause/unpause (6/14/2018)
* 3) Removed whenPaused (6/14/2018)
* 4) Switches ownable library to use zeppelinos (7/12/18)
* 5) Remove constructor (7/13/18)
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
event PauserChanged(address indexed newAddress);
address public pauser;
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev throws if called by any account other than the pauser
*/
modifier onlyPauser() {
require(msg.sender == pauser);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyPauser public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyPauser public {
paused = false;
emit Unpause();
}
/**
* @dev update the pauser role
*/
function updatePauser(address _newPauser) onlyOwner public {
require(_newPauser != address(0));
pauser = _newPauser;
emit PauserChanged(pauser);
}
}
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// Gas optimization: this is cheaper than asserting '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;
}
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 a / b;
}
/**
* @dev Subtracts 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 c) {
c = a + b;
assert(c >= a);
return c;
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* See https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
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 Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
// File: contracts/FiatTokenV1.sol
/**
* Copyright CENTRE SECZ 2018
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
pragma solidity ^0.4.24;
/**
* @title FiatToken
* @dev ERC20 Token backed by fiat reserves
*/
contract FiatTokenV1 is Ownable, ERC20, Pausable, Blacklistable {
using SafeMath for uint256;
string public name;
string public symbol;
uint8 public decimals;
string public currency;
address public masterMinter;
bool internal initialized;
mapping(address => uint256) internal balances;
mapping(address => mapping(address => uint256)) internal allowed;
uint256 internal totalSupply_ = 0;
mapping(address => bool) internal minters;
mapping(address => uint256) internal minterAllowed;
event Mint(address indexed minter, address indexed to, uint256 amount);
event Burn(address indexed burner, uint256 amount);
event MinterConfigured(address indexed minter, uint256 minterAllowedAmount);
event MinterRemoved(address indexed oldMinter);
event MasterMinterChanged(address indexed newMasterMinter);
function initialize(
string _name,
string _symbol,
string _currency,
uint8 _decimals
) public {
name = _name;
symbol = _symbol;
currency = _currency;
decimals = _decimals;
initialized = true;
}
/**
* @dev Throws if called by any account other than a minter
*/
modifier onlyMinters() {
require(minters[msg.sender] == true);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint. Must be less than or equal to the minterAllowance of the caller.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) public returns (bool) {
require(_to != address(0));
require(_amount > 0);
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(msg.sender, _to, _amount);
emit Transfer(0x0, _to, _amount);
return true;
}
/**
* @dev Throws if called by any account other than the masterMinter
*/
modifier onlyMasterMinter() {
require(msg.sender == masterMinter);
_;
}
/**
* @dev Get minter allowance for an account
* @param minter The address of the minter
*/
function minterAllowance(address minter) public view returns (uint256) {
return minterAllowed[minter];
}
/**
* @dev Checks if account is a minter
* @param account The address to check
*/
function isMinter(address account) public view returns (bool) {
return minters[account];
}
/**
* @dev Get allowed amount for an account
* @param owner address The account owner
* @param spender address The account spender
*/
function allowance(address owner, address spender) public view returns (uint256) {
return allowed[owner][spender];
}
/**
* @dev Get totalSupply of token
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev Get token balance of an account
* @param account address The account
*/
function balanceOf(address account) public view returns (uint256) {
return balances[account];
}
/**
* @dev Adds blacklisted check to approve
* @return True if the operation was successful.
*/
function approve(address _spender, uint256 _value) whenNotPaused notBlacklisted(msg.sender) notBlacklisted(_spender) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @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
* @return bool success
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused notBlacklisted(_to) notBlacklisted(msg.sender) notBlacklisted(_from) 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);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
* @return bool success
*/
function transfer(address _to, uint256 _value) whenNotPaused notBlacklisted(msg.sender) notBlacklisted(_to) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Function to add/update a new minter
* @param minter The address of the minter
* @param minterAllowedAmount The minting amount allowed for the minter
* @return True if the operation was successful.
*/
function configureMinter(address minter, uint256 minterAllowedAmount) whenNotPaused onlyMasterMinter public returns (bool) {
minters[minter] = true;
minterAllowed[minter] = minterAllowedAmount;
emit MinterConfigured(minter, minterAllowedAmount);
return true;
}
/**
* @dev Function to remove a minter
* @param minter The address of the minter to remove
* @return True if the operation was successful.
*/
function removeMinter(address minter) onlyMasterMinter public returns (bool) {
minters[minter] = false;
minterAllowed[minter] = 0;
emit MinterRemoved(minter);
return true;
}
/**
* @dev allows a minter to burn some of its own tokens
* Validates that caller is a minter and that sender is not blacklisted
* amount is less than or equal to the minter's account balance
* @param _amount uint256 the amount of tokens to be burned
*/
function burn(uint256 _amount) whenNotPaused onlyMinters notBlacklisted(msg.sender) public {
uint256 balance = balances[msg.sender];
require(_amount > 0);
require(balance >= _amount);
totalSupply_ = totalSupply_.sub(_amount);
balances[msg.sender] = balance.sub(_amount);
emit Burn(msg.sender, _amount);
emit Transfer(msg.sender, address(0), _amount);
}
function updateMasterMinter(address _newMasterMinter) onlyOwner public {
require(_newMasterMinter != address(0));
masterMinter = _newMasterMinter;
emit MasterMinterChanged(masterMinter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment