Skip to content

Instantly share code, notes, and snippets.

@makarovas
Created February 28, 2023 18:14
Show Gist options
  • Save makarovas/0e2252b9359bbfd81a17d76d3076a0ff to your computer and use it in GitHub Desktop.
Save makarovas/0e2252b9359bbfd81a17d76d3076a0ff to your computer and use it in GitHub Desktop.
Solidity uniswap flashloan boat
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
contract FlashLoanBot {
address constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address constant USDC_ADDRESS = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant USDT_ADDRESS = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
uint constant AMOUNT_IN = 1 ether;
uint constant AMOUNT_OUT_MIN = 1;
uint constant DEADLINE = block.timestamp + 1200; // 20 minutes from now
IUniswapV2Router02 public router;
constructor() {
router = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
function startFlashLoan() external {
// Define the tokens and amounts for the flashloan trade
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = USDT_ADDRESS;
// Execute the flashloan trade on Uniswap
router.swapExactTokensForTokens(
AMOUNT_IN,
AMOUNT_OUT_MIN,
path,
address(this),
DEADLINE
);
// Implement your custom logic here
// ...
// Return the borrowed tokens to the lending pool
IERC20(DAI_ADDRESS).transfer(UNISWAP_ROUTER_ADDRESS, AMOUNT_IN);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment