Advertisement
Guest User

DepositContract

a guest
Mar 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.06 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2.  
  3. // File: contracts/Interfaces/ERC223Interface.sol
  4.  
  5. contract ERC223Interface {
  6. function transfer(address to, uint value, bytes data) public returns (bool);
  7. event Transfer(address indexed from, address indexed to, uint value, bytes data);
  8. }
  9.  
  10. // File: contracts/Interfaces/ERC223ReceivingContract.sol
  11.  
  12. contract ERC223ReceivingContract {
  13. /**
  14. * @dev Standard ERC223 function that will handle incoming token transfers.
  15. *
  16. * @param _from Token sender address.
  17. * @param _value Amount of tokens.
  18. * @param _data Transaction metadata.
  19. */
  20. function tokenFallback(address _from, uint _value, bytes _data) public;
  21. }
  22.  
  23. // File: contracts/Interfaces/MasterDepositInterface.sol
  24.  
  25. contract MasterDepositInterface {
  26. address public coldWallet1;
  27. address public coldWallet2;
  28. uint public percentage;
  29. function fireDepositToChildEvent(uint _amount) public;
  30. function fireDepositERC223ToChildEvent(uint _amount, address _tokenAddress) public;
  31. }
  32.  
  33. // File: zeppelin-solidity/contracts/ReentrancyGuard.sol
  34.  
  35. /**
  36. * @title Helps contracts guard agains reentrancy attacks.
  37. * @author Remco Bloemen <remco@2Ï€.com>
  38. * @notice If you mark a function `nonReentrant`, you should also
  39. * mark it `external`.
  40. */
  41. contract ReentrancyGuard {
  42.  
  43. /**
  44. * @dev We use a single lock for the whole contract.
  45. */
  46. bool private reentrancy_lock = false;
  47.  
  48. /**
  49. * @dev Prevents a contract from calling itself, directly or indirectly.
  50. * @notice If you mark a function `nonReentrant`, you should also
  51. * mark it `external`. Calling one nonReentrant function from
  52. * another is not supported. Instead, you can implement a
  53. * `private` function doing the actual work, and a `external`
  54. * wrapper marked as `nonReentrant`.
  55. */
  56. modifier nonReentrant() {
  57. require(!reentrancy_lock);
  58. reentrancy_lock = true;
  59. _;
  60. reentrancy_lock = false;
  61. }
  62.  
  63. }
  64.  
  65. // File: zeppelin-solidity/contracts/math/SafeMath.sol
  66.  
  67. /**
  68. * @title SafeMath
  69. * @dev Math operations with safety checks that throw on error
  70. */
  71. library SafeMath {
  72.  
  73. /**
  74. * @dev Multiplies two numbers, throws on overflow.
  75. */
  76. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  77. if (a == 0) {
  78. return 0;
  79. }
  80. uint256 c = a * b;
  81. assert(c / a == b);
  82. return c;
  83. }
  84.  
  85. /**
  86. * @dev Integer division of two numbers, truncating the quotient.
  87. */
  88. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  89. // assert(b > 0); // Solidity automatically throws when dividing by 0
  90. uint256 c = a / b;
  91. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  92. return c;
  93. }
  94.  
  95. /**
  96. * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  97. */
  98. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  99. assert(b <= a);
  100. return a - b;
  101. }
  102.  
  103. /**
  104. * @dev Adds two numbers, throws on overflow.
  105. */
  106. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  107. uint256 c = a + b;
  108. assert(c >= a);
  109. return c;
  110. }
  111. }
  112.  
  113. // File: zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
  114.  
  115. /**
  116. * @title ERC20Basic
  117. * @dev Simpler version of ERC20 interface
  118. * @dev see https://github.com/ethereum/EIPs/issues/179
  119. */
  120. contract ERC20Basic {
  121. function totalSupply() public view returns (uint256);
  122. function balanceOf(address who) public view returns (uint256);
  123. function transfer(address to, uint256 value) public returns (bool);
  124. event Transfer(address indexed from, address indexed to, uint256 value);
  125. }
  126.  
  127. // File: zeppelin-solidity/contracts/token/ERC20/ERC20.sol
  128.  
  129. /**
  130. * @title ERC20 interface
  131. * @dev see https://github.com/ethereum/EIPs/issues/20
  132. */
  133. contract ERC20 is ERC20Basic {
  134. function allowance(address owner, address spender) public view returns (uint256);
  135. function transferFrom(address from, address to, uint256 value) public returns (bool);
  136. function approve(address spender, uint256 value) public returns (bool);
  137. event Approval(address indexed owner, address indexed spender, uint256 value);
  138. }
  139.  
  140. // File: contracts/ChildDeposit.sol
  141.  
  142. contract ChildDeposit is ERC223ReceivingContract,ReentrancyGuard {
  143.  
  144. using SafeMath for uint;
  145. MasterDepositInterface public master;
  146.  
  147. function ChildDeposit() {
  148. master = MasterDepositInterface(msg.sender);
  149. }
  150.  
  151. // ETH handling
  152. function() public payable nonReentrant {
  153. address wallet1 = master.coldWallet1();
  154. address wallet2 = master.coldWallet2();
  155. uint percentage = master.percentage();
  156. master.fireDepositToChildEvent(msg.value);
  157. uint coldWallet1Share = msg.value.mul(percentage).div(100);
  158. uint coldWallet2Share = msg.value - coldWallet1Share;
  159. wallet1.transfer(coldWallet1Share);
  160. wallet2.transfer(coldWallet2Share);
  161. }
  162.  
  163. // ERC223 handling
  164. function tokenFallback(address _from, uint _value, bytes _data) public nonReentrant {
  165. address wallet1 = master.coldWallet1();
  166. address wallet2 = master.coldWallet2();
  167. uint percentage = master.percentage();
  168.  
  169. master.fireDepositERC223ToChildEvent(_value, msg.sender);
  170. uint coldWallet1Share = _value.mul(percentage).div(100);
  171. uint coldWallet2Share = _value - coldWallet1Share;
  172.  
  173. ERC223Interface(msg.sender).transfer(wallet1,coldWallet1Share, _data);
  174. ERC223Interface(msg.sender).transfer(wallet2,coldWallet2Share, _data);
  175. }
  176.  
  177. function withdraw(address _tokenAddress, uint _value, address _destination) public onlyMaster nonReentrant {
  178. ERC20(_tokenAddress).transfer(_destination, _value);
  179. }
  180.  
  181. modifier onlyMaster() {
  182. require(msg.sender == address(master));
  183. _;
  184. }
  185.  
  186. }
  187.  
  188. // File: zeppelin-solidity/contracts/ownership/Ownable.sol
  189.  
  190. /**
  191. * @title Ownable
  192. * @dev The Ownable contract has an owner address, and provides basic authorization control
  193. * functions, this simplifies the implementation of "user permissions".
  194. */
  195. contract Ownable {
  196. address public owner;
  197.  
  198.  
  199. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  200.  
  201.  
  202. /**
  203. * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  204. * account.
  205. */
  206. function Ownable() public {
  207. owner = msg.sender;
  208. }
  209.  
  210. /**
  211. * @dev Throws if called by any account other than the owner.
  212. */
  213. modifier onlyOwner() {
  214. require(msg.sender == owner);
  215. _;
  216. }
  217.  
  218. /**
  219. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  220. * @param newOwner The address to transfer ownership to.
  221. */
  222. function transferOwnership(address newOwner) public onlyOwner {
  223. require(newOwner != address(0));
  224. OwnershipTransferred(owner, newOwner);
  225. owner = newOwner;
  226. }
  227.  
  228. }
  229.  
  230. // File: zeppelin-solidity/contracts/ownership/Claimable.sol
  231.  
  232. /**
  233. * @title Claimable
  234. * @dev Extension for the Ownable contract, where the ownership needs to be claimed.
  235. * This allows the new owner to accept the transfer.
  236. */
  237. contract Claimable is Ownable {
  238. address public pendingOwner;
  239.  
  240. /**
  241. * @dev Modifier throws if called by any account other than the pendingOwner.
  242. */
  243. modifier onlyPendingOwner() {
  244. require(msg.sender == pendingOwner);
  245. _;
  246. }
  247.  
  248. /**
  249. * @dev Allows the current owner to set the pendingOwner address.
  250. * @param newOwner The address to transfer ownership to.
  251. */
  252. function transferOwnership(address newOwner) onlyOwner public {
  253. pendingOwner = newOwner;
  254. }
  255.  
  256. /**
  257. * @dev Allows the pendingOwner address to finalize the transfer.
  258. */
  259. function claimOwnership() onlyPendingOwner public {
  260. OwnershipTransferred(owner, pendingOwner);
  261. owner = pendingOwner;
  262. pendingOwner = address(0);
  263. }
  264. }
  265.  
  266. // File: contracts/MasterDeposit.sol
  267.  
  268. contract MasterDeposit is MasterDepositInterface, Claimable, ReentrancyGuard {
  269.  
  270. using SafeMath for uint;
  271. mapping (address => bool) public childDeposits;
  272. address public depositCreator;
  273.  
  274. event CreatedDepositEvent (
  275. address indexed _depositAddress
  276. );
  277.  
  278. event DepositToChildEvent(
  279. address indexed _depositAddress,
  280. uint _amount
  281. );
  282.  
  283. event DepositERC223ToChildEvent(
  284. address indexed _depositAddress,
  285. uint _amount,
  286. address _tokenAddress
  287. );
  288.  
  289. // function MasterDeposit(address _wallet1, address _wallet2, uint _percentage) {
  290. function MasterDeposit() {
  291. // require(_wallet1 != address(0));
  292. // require(_wallet2 != address(0));
  293. // percentage = _percentage;
  294. // coldWallet1 = _wallet1;
  295. // coldWallet2 = _wallet2;
  296.  
  297. percentage = 50;
  298. coldWallet1 = 0x000a96d9b98224c931f4fa36be8d1dd05b9a1d05;
  299. coldWallet2 = 0x00d6593cf0a88ef8a72922d97cdd15c4afd7c2b3;
  300. }
  301.  
  302. function createChildDeposits(uint _count) public onlyDepositCreatorOrMaster {
  303. for (uint i = 0; i < _count; i++) {
  304. ChildDeposit childDeposit = new ChildDeposit();
  305. childDeposits[address(childDeposit)] = true;
  306. CreatedDepositEvent(address(childDeposit));
  307. }
  308. }
  309.  
  310. function setDepositCreator(address _depositCreator) public onlyOwner {
  311. require(_depositCreator != address(0));
  312. depositCreator = _depositCreator;
  313. }
  314.  
  315. function setColdWallet1SplitPercentage(uint _percentage) public onlyOwner {
  316. percentage = _percentage;
  317. }
  318.  
  319. function fireDepositToChildEvent(uint _amount) public onlyChildContract {
  320. DepositToChildEvent(msg.sender, _amount);
  321. }
  322.  
  323. function fireDepositERC223ToChildEvent(uint _amount, address _tokenAddress) public onlyChildContract {
  324. DepositERC223ToChildEvent(msg.sender, _amount, _tokenAddress);
  325. }
  326.  
  327. function setColdWallet1(address _coldWallet1) public onlyOwner {
  328. require(_coldWallet1 != address(0));
  329. coldWallet1 = _coldWallet1;
  330. }
  331.  
  332. function setColdWallet2(address _coldWallet2) public onlyOwner {
  333. require(_coldWallet2 != address(0));
  334. coldWallet2 = _coldWallet2;
  335. }
  336.  
  337. function transferTokens(address[] _deposits, address _tokenContractAddress) public onlyOwner nonReentrant {
  338. for (uint i = 0; i < _deposits.length; i++) {
  339. address deposit = _deposits[i];
  340. uint erc20Balance = ERC20(_tokenContractAddress).balanceOf(deposit);
  341. if (erc20Balance == 0) {
  342. continue;
  343. }
  344. uint coldWallet1Share = erc20Balance.mul(percentage).div(100);
  345. uint coldWallet2Share = erc20Balance - coldWallet1Share;
  346. ChildDeposit(deposit).withdraw(_tokenContractAddress,coldWallet1Share, coldWallet1);
  347. ChildDeposit(deposit).withdraw(_tokenContractAddress,coldWallet2Share, coldWallet2);
  348. }
  349. }
  350.  
  351. modifier onlyChildContract() {
  352. require(childDeposits[msg.sender]);
  353. _;
  354. }
  355.  
  356. modifier onlyDepositCreatorOrMaster() {
  357. require(msg.sender == owner || msg.sender == depositCreator);
  358. _;
  359. }
  360.  
  361. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement