SHARE
TWEET

Untitled

a guest Jul 17th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity >=0.5.0 <0.6.0;
  2.  
  3. library SafeMath {
  4.     function add(uint256 a, uint256 b) internal pure returns (uint256) {
  5.         uint256 c = a + b;
  6.         require(c >= a, "SafeMath: addition overflow");
  7.         return c;
  8.     }
  9.  
  10.     function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  11.         require(b <= a, "SafeMath: subtraction overflow");
  12.         uint256 c = a - b;
  13.         return c;
  14.     }
  15.  
  16.     function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  17.         if (a == 0) {
  18.             return 0;
  19.         }
  20.  
  21.         uint256 c = a * b;
  22.         require(c / a == b, "SafeMath: multiplication overflow");
  23.         return c;
  24.     }
  25.  
  26.     function div(uint256 a, uint256 b) internal pure returns (uint256) {
  27.         require(b > 0, "SafeMath: division by zero");
  28.         uint256 c = a / b;
  29.         return c;
  30.     }
  31. }
  32.  
  33. contract IERC20{
  34.     function transfer(address recipient, uint256 amount) external returns (bool success);
  35. }
  36.  
  37. contract IUniswap{
  38.     function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) external payable returns (uint256  tokens_bought);
  39. }
  40.  
  41. contract ForceSend {
  42.     function forceSend(address payable recipient) external payable {
  43.         selfdestruct(recipient);
  44.     }
  45. }
  46.  
  47. contract UniswapDonate {
  48.     using SafeMath for uint256;
  49.    
  50.     function donate(address _token, address payable _exchange) external payable {
  51.         // TODO: calculate amount where donated ratio and ratio in contract is the same
  52.         // using half of msg.value gives a slightly more to arbitrageurs than necessary
  53.         uint256 ethAmount = msg.value.div(2);
  54.        
  55.         uint256 tokensBought = IUniswap(_exchange).ethToTokenSwapInput.value(msg.value.sub(ethAmount))(1, block.timestamp);
  56.        
  57.         ForceSend s = new ForceSend();
  58.        
  59.         s.forceSend.value(ethAmount)(_exchange);
  60.         IERC20(_token).transfer(_exchange, tokensBought);
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top