Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@naps62
Created November 11, 2022 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naps62/21394e017d7f0a8a76b50853baca0fa1 to your computer and use it in GitHub Desktop.
Save naps62/21394e017d7f0a8a76b50853baca0fa1 to your computer and use it in GitHub Desktop.
UniswapV3: Swap USDT->WETH->RPL
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);
}
}
@naps62
Copy link
Author

naps62 commented Nov 11, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment