Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flashloan receiver #207

Merged
merged 5 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
IBlueLiquidateCallback,
IBlueRepayCallback,
IBlueSupplyCallback,
IBlueSupplyCollateralCallback
IBlueSupplyCollateralCallback,
IBlueFlashBorrower
} from "src/interfaces/IBlueCallbacks.sol";
import {IIrm} from "src/interfaces/IIrm.sol";
import {IERC20} from "src/interfaces/IERC20.sol";
import {IFlashLender} from "src/interfaces/IFlashLender.sol";
import {IFlashBorrower} from "src/interfaces/IFlashBorrower.sol";

import {Errors} from "./libraries/Errors.sol";
import {SharesMath} from "src/libraries/SharesMath.sol";
Expand All @@ -35,7 +34,7 @@ struct Signature {
bytes32 s;
}

contract Blue is IFlashLender {
contract Blue {
using SharesMath for uint256;
using FixedPointMathLib for uint256;
using SafeTransferLib for IERC20;
Expand Down Expand Up @@ -288,13 +287,12 @@ contract Blue is IFlashLender {

// Flash Loans.

/// @inheritdoc IFlashLender
function flashLoan(IFlashBorrower receiver, address token, uint256 amount, bytes calldata data) external {
IERC20(token).safeTransfer(address(receiver), amount);
function flashLoan(address token, uint256 amount, bytes calldata data) external {
IERC20(token).safeTransfer(msg.sender, amount);

receiver.onBlueFlashLoan(msg.sender, token, amount, data);
IBlueFlashBorrower(msg.sender).onBlueFlashLoan(token, amount, data);

IERC20(token).safeTransferFrom(address(receiver), address(this), amount);
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
}

// Authorizations.
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/IBlueCallbacks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ interface IBlueSupplyCallback {
interface IBlueSupplyCollateralCallback {
function onBlueSupplyCollateral(uint256 amount, bytes calldata data) external;
}

interface IBlueFlashBorrower {
function onBlueFlashLoan(address token, uint256 amount, bytes calldata data) external;
}
11 changes: 0 additions & 11 deletions src/interfaces/IFlashBorrower.sol

This file was deleted.

13 changes: 0 additions & 13 deletions src/interfaces/IFlashLender.sol

This file was deleted.

26 changes: 0 additions & 26 deletions src/mocks/FlashBorrowerMock.sol

This file was deleted.

11 changes: 7 additions & 4 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import {ERC20Mock as ERC20} from "src/mocks/ERC20Mock.sol";
import {OracleMock as Oracle} from "src/mocks/OracleMock.sol";
import {IrmMock as Irm} from "src/mocks/IrmMock.sol";
import {FlashBorrowerMock} from "src/mocks/FlashBorrowerMock.sol";

contract BlueTest is
Test,
Expand All @@ -41,7 +40,6 @@ contract BlueTest is
Irm private irm;
Market public market;
Id public id;
FlashBorrowerMock internal flashBorrower;

function setUp() public {
// Create Blue.
Expand All @@ -52,7 +50,6 @@ contract BlueTest is
collateralAsset = new ERC20("collateral", "C", 18);
borrowableOracle = new Oracle();
collateralOracle = new Oracle();
flashBorrower = new FlashBorrowerMock(blue);

irm = new Irm(blue);

Expand Down Expand Up @@ -741,7 +738,7 @@ contract BlueTest is
borrowableAsset.setBalance(address(this), amount);
blue.supply(market, amount, address(this), hex"");

blue.flashLoan(flashBorrower, address(borrowableAsset), amount, bytes(""));
blue.flashLoan(address(borrowableAsset), amount, bytes(""));

assertEq(borrowableAsset.balanceOf(address(blue)), amount, "balanceOf");
}
Expand Down Expand Up @@ -834,6 +831,8 @@ contract BlueTest is
assertEq(blue.collateral(market.id(), address(this)), 0, "no withdraw collateral");
}

// Callback functions.

function onBlueSupply(uint256 amount, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
Expand Down Expand Up @@ -877,6 +876,10 @@ contract BlueTest is
borrowableAsset.approve(address(blue), repaid);
}
}

function onBlueFlashLoan(address token, uint256 amount, bytes calldata) external {
ERC20(token).approve(address(blue), amount);
}
}

function neq(Market memory a, Market memory b) pure returns (bool) {
Expand Down