Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity >=0.5.0 <0.6.0;
- library SafeMath {
- function add(uint256 a, uint256 b) internal pure returns (uint256) {
- uint256 c = a + b;
- require(c >= a, "SafeMath: addition overflow");
- return c;
- }
- function sub(uint256 a, uint256 b) internal pure returns (uint256) {
- require(b <= a, "SafeMath: subtraction overflow");
- uint256 c = a - b;
- return c;
- }
- function mul(uint256 a, uint256 b) internal pure returns (uint256) {
- if (a == 0) {
- return 0;
- }
- uint256 c = a * b;
- require(c / a == b, "SafeMath: multiplication overflow");
- return c;
- }
- function div(uint256 a, uint256 b) internal pure returns (uint256) {
- require(b > 0, "SafeMath: division by zero");
- uint256 c = a / b;
- return c;
- }
- }
- contract IERC20{
- function transfer(address recipient, uint256 amount) external returns (bool success);
- }
- contract IUniswap{
- function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) external payable returns (uint256 tokens_bought);
- }
- contract ForceSend {
- function forceSend(address payable recipient) external payable {
- selfdestruct(recipient);
- }
- }
- contract UniswapDonate {
- using SafeMath for uint256;
- function donate(address _token, address payable _exchange) external payable {
- // TODO: calculate amount where donated ratio and ratio in contract is the same
- // using half of msg.value gives a slightly more to arbitrageurs than necessary
- uint256 ethAmount = msg.value.div(2);
- uint256 tokensBought = IUniswap(_exchange).ethToTokenSwapInput.value(msg.value.sub(ethAmount))(1, block.timestamp);
- ForceSend s = new ForceSend();
- s.forceSend.value(ethAmount)(_exchange);
- IERC20(_token).transfer(_exchange, tokensBought);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement