Created
November 11, 2022 19:42
-
-
Save naps62/21394e017d7f0a8a76b50853baca0fa1 to your computer and use it in GitHub Desktop.
UniswapV3: Swap USDT->WETH->RPL
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.8.13; | |
import "forge-std/Script.sol"; | |
interface UniV3 { | |
struct ExactInputParams { | |
bytes path; | |
address recipient; | |
uint256 amountIn; | |
uint256 amountOutMinimum; | |
} | |
function exactInput(ExactInputParams memory params) external; | |
} | |
interface IERC20 { | |
function approve(address, uint256) external; | |
function balanceOf(address) external view returns (uint256); | |
} | |
contract CounterScript is Script { | |
address USDT = address(0xdAC17F958D2ee523a2206206994597C13D831ec7); | |
address WETH = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
address RPL = address(0xD33526068D116cE69F19A9ee46F0bd304F21A51f); | |
address UNIV3 = address(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45); | |
uint24 usdt_weth_fee = 500; | |
uint24 weth_rpl_fee = 10000; | |
function setUp() public {} | |
function run() public { | |
vm.broadcast(msg.sender); | |
IERC20(RPL).approve(UNIV3, type(uint256).max); | |
bytes memory path = abi.encodePacked( | |
USDT, | |
usdt_weth_fee, | |
WETH, | |
weth_rpl_fee, | |
RPL | |
); | |
uint256 amountIn = IERC20(USDT).balanceOf(msg.sender); | |
// slippage. current price is at $14.98, I want to accept at most $15.20 | |
uint256 amountOutMinimum = ((amountIn * 10**12) / 152) * 10; | |
UniV3.ExactInputParams memory input = UniV3.ExactInputParams({ | |
path: path, | |
recipient: msg.sender, | |
amountIn: amountIn, | |
amountOutMinimum: amountOutMinimum | |
}); | |
vm.broadcast(msg.sender); | |
UniV3(UNIV3).exactInput(input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I mistakenly sent $USDT to my RocketPool wallet instead of first swapping it for $RPL, which is what I wanted to stake.
So now I'm left having to somehow swap it or transfer it out, from a wallet that I don't want to compromise in any way (i.e.: there's no way I'm gonna plug this into metamask).
ended up writing a forge script to handle this for me directly on the server where the encrypted private key file already lived