-
Notifications
You must be signed in to change notification settings - Fork 2
/
DoTrustLender.sol
42 lines (33 loc) · 1.18 KB
/
DoTrustLender.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @title DoTrustLender
* @author Calyptus
*/
contract DoTrustLender is ReentrancyGuard {
using Address for address;
IERC20 public immutable calyptusToken;
constructor (address tokenAddress) {
calyptusToken = IERC20(tokenAddress);
}
function flashLoan(
uint256 borrowAmount,
address borrower,
address target,
bytes calldata data
)
external
nonReentrant
{
uint256 balanceBefore = calyptusToken.balanceOf(address(this));
require(balanceBefore >= borrowAmount, "Not enough tokens in pool");
calyptusToken.transfer(borrower, borrowAmount);
target.functionCall(data);
// @audit-info this lets the caller of this function make this contract call anyone and access any function
uint256 balanceAfter = calyptusToken.balanceOf(address(this));
require(balanceAfter >= balanceBefore, "Flash loan hasn't been paid back");
}
}