Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.18;
- // File: contracts/Interfaces/ERC223Interface.sol
- contract ERC223Interface {
- function transfer(address to, uint value, bytes data) public returns (bool);
- event Transfer(address indexed from, address indexed to, uint value, bytes data);
- }
- // File: contracts/Interfaces/ERC223ReceivingContract.sol
- contract ERC223ReceivingContract {
- /**
- * @dev Standard ERC223 function that will handle incoming token transfers.
- *
- * @param _from Token sender address.
- * @param _value Amount of tokens.
- * @param _data Transaction metadata.
- */
- function tokenFallback(address _from, uint _value, bytes _data) public;
- }
- // File: contracts/Interfaces/MasterDepositInterface.sol
- contract MasterDepositInterface {
- address public coldWallet1;
- address public coldWallet2;
- uint public percentage;
- function fireDepositToChildEvent(uint _amount) public;
- function fireDepositERC223ToChildEvent(uint _amount, address _tokenAddress) public;
- }
- // File: zeppelin-solidity/contracts/ReentrancyGuard.sol
- /**
- * @title Helps contracts guard agains reentrancy attacks.
- * @author Remco Bloemen <remco@2Ï€.com>
- * @notice If you mark a function `nonReentrant`, you should also
- * mark it `external`.
- */
- contract ReentrancyGuard {
- /**
- * @dev We use a single lock for the whole contract.
- */
- bool private reentrancy_lock = false;
- /**
- * @dev Prevents a contract from calling itself, directly or indirectly.
- * @notice If you mark a function `nonReentrant`, you should also
- * mark it `external`. Calling one nonReentrant function from
- * another is not supported. Instead, you can implement a
- * `private` function doing the actual work, and a `external`
- * wrapper marked as `nonReentrant`.
- */
- modifier nonReentrant() {
- require(!reentrancy_lock);
- reentrancy_lock = true;
- _;
- reentrancy_lock = false;
- }
- }
- // File: zeppelin-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) {
- 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;
- }
- }
- // File: zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
- /**
- * @title ERC20Basic
- * @dev Simpler version of ERC20 interface
- * @dev 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: zeppelin-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/ChildDeposit.sol
- contract ChildDeposit is ERC223ReceivingContract,ReentrancyGuard {
- using SafeMath for uint;
- MasterDepositInterface public master;
- function ChildDeposit() {
- master = MasterDepositInterface(msg.sender);
- }
- // ETH handling
- function() public payable nonReentrant {
- address wallet1 = master.coldWallet1();
- address wallet2 = master.coldWallet2();
- uint percentage = master.percentage();
- master.fireDepositToChildEvent(msg.value);
- uint coldWallet1Share = msg.value.mul(percentage).div(100);
- uint coldWallet2Share = msg.value - coldWallet1Share;
- wallet1.transfer(coldWallet1Share);
- wallet2.transfer(coldWallet2Share);
- }
- // ERC223 handling
- function tokenFallback(address _from, uint _value, bytes _data) public nonReentrant {
- address wallet1 = master.coldWallet1();
- address wallet2 = master.coldWallet2();
- uint percentage = master.percentage();
- master.fireDepositERC223ToChildEvent(_value, msg.sender);
- uint coldWallet1Share = _value.mul(percentage).div(100);
- uint coldWallet2Share = _value - coldWallet1Share;
- ERC223Interface(msg.sender).transfer(wallet1,coldWallet1Share, _data);
- ERC223Interface(msg.sender).transfer(wallet2,coldWallet2Share, _data);
- }
- function withdraw(address _tokenAddress, uint _value, address _destination) public onlyMaster nonReentrant {
- ERC20(_tokenAddress).transfer(_destination, _value);
- }
- modifier onlyMaster() {
- require(msg.sender == address(master));
- _;
- }
- }
- // File: zeppelin-solidity/contracts/ownership/Ownable.sol
- /**
- * @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;
- event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
- /**
- * @dev The Ownable constructor sets the original `owner` of the contract to the sender
- * account.
- */
- function Ownable() public {
- owner = msg.sender;
- }
- /**
- * @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));
- OwnershipTransferred(owner, newOwner);
- owner = newOwner;
- }
- }
- // File: zeppelin-solidity/contracts/ownership/Claimable.sol
- /**
- * @title Claimable
- * @dev Extension for the Ownable contract, where the ownership needs to be claimed.
- * This allows the new owner to accept the transfer.
- */
- contract Claimable is Ownable {
- address public pendingOwner;
- /**
- * @dev Modifier throws if called by any account other than the pendingOwner.
- */
- modifier onlyPendingOwner() {
- require(msg.sender == pendingOwner);
- _;
- }
- /**
- * @dev Allows the current owner to set the pendingOwner address.
- * @param newOwner The address to transfer ownership to.
- */
- function transferOwnership(address newOwner) onlyOwner public {
- pendingOwner = newOwner;
- }
- /**
- * @dev Allows the pendingOwner address to finalize the transfer.
- */
- function claimOwnership() onlyPendingOwner public {
- OwnershipTransferred(owner, pendingOwner);
- owner = pendingOwner;
- pendingOwner = address(0);
- }
- }
- // File: contracts/MasterDeposit.sol
- contract MasterDeposit is MasterDepositInterface, Claimable, ReentrancyGuard {
- using SafeMath for uint;
- mapping (address => bool) public childDeposits;
- address public depositCreator;
- event CreatedDepositEvent (
- address indexed _depositAddress
- );
- event DepositToChildEvent(
- address indexed _depositAddress,
- uint _amount
- );
- event DepositERC223ToChildEvent(
- address indexed _depositAddress,
- uint _amount,
- address _tokenAddress
- );
- // function MasterDeposit(address _wallet1, address _wallet2, uint _percentage) {
- function MasterDeposit() {
- // require(_wallet1 != address(0));
- // require(_wallet2 != address(0));
- // percentage = _percentage;
- // coldWallet1 = _wallet1;
- // coldWallet2 = _wallet2;
- percentage = 50;
- coldWallet1 = 0x000a96d9b98224c931f4fa36be8d1dd05b9a1d05;
- coldWallet2 = 0x00d6593cf0a88ef8a72922d97cdd15c4afd7c2b3;
- }
- function createChildDeposits(uint _count) public onlyDepositCreatorOrMaster {
- for (uint i = 0; i < _count; i++) {
- ChildDeposit childDeposit = new ChildDeposit();
- childDeposits[address(childDeposit)] = true;
- CreatedDepositEvent(address(childDeposit));
- }
- }
- function setDepositCreator(address _depositCreator) public onlyOwner {
- require(_depositCreator != address(0));
- depositCreator = _depositCreator;
- }
- function setColdWallet1SplitPercentage(uint _percentage) public onlyOwner {
- percentage = _percentage;
- }
- function fireDepositToChildEvent(uint _amount) public onlyChildContract {
- DepositToChildEvent(msg.sender, _amount);
- }
- function fireDepositERC223ToChildEvent(uint _amount, address _tokenAddress) public onlyChildContract {
- DepositERC223ToChildEvent(msg.sender, _amount, _tokenAddress);
- }
- function setColdWallet1(address _coldWallet1) public onlyOwner {
- require(_coldWallet1 != address(0));
- coldWallet1 = _coldWallet1;
- }
- function setColdWallet2(address _coldWallet2) public onlyOwner {
- require(_coldWallet2 != address(0));
- coldWallet2 = _coldWallet2;
- }
- function transferTokens(address[] _deposits, address _tokenContractAddress) public onlyOwner nonReentrant {
- for (uint i = 0; i < _deposits.length; i++) {
- address deposit = _deposits[i];
- uint erc20Balance = ERC20(_tokenContractAddress).balanceOf(deposit);
- if (erc20Balance == 0) {
- continue;
- }
- uint coldWallet1Share = erc20Balance.mul(percentage).div(100);
- uint coldWallet2Share = erc20Balance - coldWallet1Share;
- ChildDeposit(deposit).withdraw(_tokenContractAddress,coldWallet1Share, coldWallet1);
- ChildDeposit(deposit).withdraw(_tokenContractAddress,coldWallet2Share, coldWallet2);
- }
- }
- modifier onlyChildContract() {
- require(childDeposits[msg.sender]);
- _;
- }
- modifier onlyDepositCreatorOrMaster() {
- require(msg.sender == owner || msg.sender == depositCreator);
- _;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement