Sample Uniswap Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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