-
Notifications
You must be signed in to change notification settings - Fork 4
/
Flash-Loan-Arbitrage.sol
80 lines (58 loc) · 2.35 KB
/
Flash-Loan-Arbitrage.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "https://github.com/aave/aave-v3-core/blob/master/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol";
import "https://github.com/aave/aave-v3-core/blob/master/contracts/dependencies/openzeppelin/contracts/IERC20.sol";
interface IUniswapV2Router {
function getAmountsOut(uint amountIn, address[] memory path) external view returns (uint[] memory amounts);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
}
contract SimpleFlashLoan is FlashLoanSimpleReceiverBase {
address payable owner;
IUniswapV2Router public uniswapRouter;
address public uniswapRouterAddress;
constructor(address _addressProvider, address _uniswapRouterAddress)
FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider))
{
uniswapRouterAddress = _uniswapRouterAddress;
uniswapRouter = IUniswapV2Router(_uniswapRouterAddress);
}
function fn_RequestFlashLoan(address _token, uint256 _amount) public {
address receiverAddress = address(this);
address asset = _token;
uint256 amount = _amount;
bytes memory params = "";
uint16 referralCode = 0;
POOL.flashLoanSimple(
receiverAddress,
asset,
amount,
params,
referralCode
);
}
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override returns (bool) {
address weth = 0x52D800ca262522580CeBAD275395ca6e7598C014;
path[0] = asset;
path[1] = weth;
uint256 deadline = block.timestamp + 15;
IERC20(asset).approve(uniswapRouterAddress, amount);
uniswapRouter.swapExactTokensForTokens(amount, 0, path, address(this), deadline);
uint256 totalAmount = amount + premium;
IERC20(asset).approve(address(POOL), totalAmount);
return true;
}
receive() external payable {}
}