Skip to content

Instantly share code, notes, and snippets.

@TheRyanMiller
Created January 18, 2021 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRyanMiller/add5b79f2209b8f2be5321a27600f1f0 to your computer and use it in GitHub Desktop.
Save TheRyanMiller/add5b79f2209b8f2be5321a27600f1f0 to your computer and use it in GitHub Desktop.
Sample Uniswap Integration
pragma solidity ^0.6.0;
// SPDX-License-Identifier: MIT
import {IUniswapV2Router02} from "../interfaces/uniswap.sol";
/**
@title UniBless
@notice A sample contract showing how to send ETH to Uniswap ETH/wBTC pool, and bless the wBTC outputs to another address
*/
contract UniBless {
uint256 public totalSupply;
// Interfaces
IUniswapV2Router02 public constant uniswapRouter = IUniswapV2Router02(address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D));
// Tokens
address public constant weth = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
address public constant wbtc = address(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);
// Blesssings
address public constant blessed = address(0x33A4622B82D4c04a53e170c638B944ce27cffce3);
event Received(uint256 amount);
event Bless(address blesser, address blessed, uint256 amount);
event Approval(address owner, address spender, uint256 value);
/** shared logic for transfer and transferFrom */
function bless() public payable {
require(msg.value > 0, "Insufficient funds");
uint amountOutMin = 0;
address[] memory path = new address[](2);
path[0] = weth;
path[1] = wbtc;
uint256[] memory amounts = uniswapRouter.swapExactETHForTokens{value: msg.value}(amountOutMin, path, blessed, now + 50);
uint256 outAmount = amounts[amounts.length - 1];
emit Bless(msg.sender, blessed, outAmount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment