Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 6 additions & 18 deletions src/CommonFlashLoanHelper.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;

import {IBalancerVault} from "src/interfaces/balancer/IBalancerVault.sol";
import {IFlashLoanRecipient} from "src/interfaces/balancer/IFlashLoanRecipient.sol";
import {ILowLevelVault} from "src/interfaces/ILowLevelVault.sol";
import {IWETH} from "src/interfaces/tokens/IWETH.sol";
import {IstEth} from "src/interfaces/tokens/IstEth.sol";
import {IwstEth} from "src/interfaces/tokens/IwstEth.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IFlashLoanHelperErrors} from "src/interfaces/IFlashLoanHelperErrors.sol";
import {IFlashLoanHelperEvents} from "src/interfaces/IFlashLoanHelperEvents.sol";
import {IMoprho} from "src/interfaces/IMoprho.sol";

abstract contract CommonFlashLoanHelper is IFlashLoanHelperErrors, IFlashLoanHelperEvents {
IBalancerVault constant BALANCER_VAULT = IBalancerVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
IMoprho constant MORPHO = IMoprho(0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need both. So copypaste and we can make 2 folder balancer_flashloan and morpho_flashloan

IWETH constant WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IstEth constant STETH = IstEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
IwstEth constant WSTETH = IwstEth(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
Expand All @@ -26,24 +25,13 @@ abstract contract CommonFlashLoanHelper is IFlashLoanHelperErrors, IFlashLoanHel
}

function _startFlashLoan(uint256 flashAmount, bytes memory data) internal {
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = WETH;
uint256[] memory amounts = new uint256[](1);
amounts[0] = flashAmount;

BALANCER_VAULT.flashLoan(IFlashLoanRecipient(address(this)), tokens, amounts, data);
MORPHO.flashLoan(address(WETH), flashAmount, data);
}

function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external {
require(msg.sender == address(BALANCER_VAULT), UnauthorizedFlashLoan());
require(address(tokens[0]) == address(WETH) && feeAmounts[0] == 0, InvalidFlashLoanParams());
function onMorphoFlashLoan(uint256 assets, bytes memory data) external {
require(msg.sender == address(MORPHO), UnauthorizedFlashLoan());

_handleFlashLoan(userData, amounts[0]);
_handleFlashLoan(data, assets);
}

function _checkUnauthorizedReceive() internal view virtual {
Expand Down
2 changes: 1 addition & 1 deletion src/FlashLoanMintHelperWstethAndWeth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract FlashLoanMintHelperWstethAndWeth is CommonFlashLoanHelper {
// forge-lint: disable-next-line(unsafe-typecast)
LTV_VAULT.executeLowLevelRebalanceShares(int256(sharesToMint));

WETH.safeTransfer(address(BALANCER_VAULT), flashAmount);
WETH.forceApprove(address(MORPHO), flashAmount);

LTV_VAULT.safeTransfer(user, sharesToMint);

Expand Down
2 changes: 1 addition & 1 deletion src/FlashLoanRedeemHelperWstethAndWeth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract FlashLoanRedeemHelperWstethAndWeth is CommonFlashLoanHelper {
ReceiverNotWhitelisted(user)
);
WETH.safeTransfer(user, expectedWEth);
WETH.safeTransfer(address(BALANCER_VAULT), flashAmount);
WETH.forceApprove(address(MORPHO), flashAmount);

emit SharesRedeemed(user, sharesToRedeem);
}
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/IMoprho.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;

interface IMoprho {
function flashLoan(address token, uint256 assets, bytes calldata data) external;
}
14 changes: 0 additions & 14 deletions src/interfaces/balancer/IBalancerVault.sol

This file was deleted.

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

This file was deleted.