-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8307da6
commit 50e87ac
Showing
9 changed files
with
295 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol'; | ||
|
||
contract UniV3Integration { | ||
ISwapRouter router; | ||
|
||
function doSomethingWithSwapRouter() public { | ||
// router.exactInput(...); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
pragma abicoder v2; | ||
|
||
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; | ||
import "@uniswap/v3-periphery/contracts/interfaces/IQuoter.sol"; | ||
|
||
interface IUniswapRouter is ISwapRouter { | ||
function refundETH() external payable; | ||
} | ||
|
||
contract Uniswap3 { | ||
IUniswapRouter public constant uniswapRouter = IUniswapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); | ||
IQuoter public constant quoter = IQuoter(0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6); | ||
address private constant multiDaiKovan = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa; | ||
address private constant WETH9 = 0xd0A1E359811322d97991E03f863a0C30C2cF029C; | ||
|
||
function convertExactEthToDai() external payable { | ||
require(msg.value > 0, "Must pass non 0 ETH amount"); | ||
|
||
uint256 deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend! | ||
address tokenIn = WETH9; | ||
address tokenOut = multiDaiKovan; | ||
uint24 fee = 3000; | ||
address recipient = msg.sender; | ||
uint256 amountIn = msg.value; | ||
uint256 amountOutMinimum = 1; | ||
uint160 sqrtPriceLimitX96 = 0; | ||
|
||
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams( | ||
tokenIn, | ||
tokenOut, | ||
fee, | ||
recipient, | ||
deadline, | ||
amountIn, | ||
amountOutMinimum, | ||
sqrtPriceLimitX96 | ||
); | ||
|
||
uniswapRouter.exactInputSingle{ value: msg.value }(params); | ||
uniswapRouter.refundETH(); | ||
|
||
// refund leftover ETH to user | ||
(bool success,) = msg.sender.call{ value: address(this).balance }(""); | ||
require(success, "refund failed"); | ||
} | ||
|
||
function convertEthToExactDai(uint256 daiAmount) external payable { | ||
require(daiAmount > 0, "Must pass non 0 DAI amount"); | ||
require(msg.value > 0, "Must pass non 0 ETH amount"); | ||
|
||
uint256 deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend! | ||
address tokenIn = WETH9; | ||
address tokenOut = multiDaiKovan; | ||
uint24 fee = 3000; | ||
address recipient = msg.sender; | ||
uint256 amountOut = daiAmount; | ||
uint256 amountInMaximum = msg.value; | ||
uint160 sqrtPriceLimitX96 = 0; | ||
|
||
ISwapRouter.ExactOutputSingleParams memory params = ISwapRouter.ExactOutputSingleParams( | ||
tokenIn, | ||
tokenOut, | ||
fee, | ||
recipient, | ||
deadline, | ||
amountOut, | ||
amountInMaximum, | ||
sqrtPriceLimitX96 | ||
); | ||
|
||
uniswapRouter.exactOutputSingle{ value: msg.value }(params); | ||
uniswapRouter.refundETH(); | ||
|
||
// refund leftover ETH to user | ||
(bool success,) = msg.sender.call{ value: address(this).balance }(""); | ||
require(success, "refund failed"); | ||
} | ||
|
||
// do not used on-chain, gas inefficient! | ||
function getEstimatedETHforDAI(uint daiAmount) external payable returns (uint256) { | ||
address tokenIn = WETH9; | ||
address tokenOut = multiDaiKovan; | ||
uint24 fee = 3000; | ||
uint160 sqrtPriceLimitX96 = 0; | ||
|
||
return quoter.quoteExactOutputSingle( | ||
tokenIn, | ||
tokenOut, | ||
fee, | ||
daiAmount, | ||
sqrtPriceLimitX96 | ||
); | ||
} | ||
|
||
// important to receive ETH | ||
receive() payable external {} | ||
} |
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
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
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
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
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
Oops, something went wrong.