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

M-01 (OZ Audit) #24

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract contract BalancerFlashloanDirectMintHandler is IonHandlerBase, IFlashLo
IFlashLoanRecipient(address(this)),
addresses,
amounts,
abi.encode(msg.sender, initialDeposit, resultingAdditionalCollateral, maxResultingDebt)
abi.encode(msg.sender, initialDeposit, resultingAdditionalCollateral)
);

flashloanInitiated = 1;
Expand Down Expand Up @@ -139,7 +139,7 @@ abstract contract BalancerFlashloanDirectMintHandler is IonHandlerBase, IFlashLo
IFlashLoanRecipient(address(this)),
addresses,
amounts,
abi.encode(msg.sender, initialDeposit, resultingAdditionalCollateral, maxResultingDebt)
abi.encode(msg.sender, initialDeposit, resultingAdditionalCollateral)
);

flashloanInitiated = 1;
Expand Down Expand Up @@ -172,16 +172,15 @@ abstract contract BalancerFlashloanDirectMintHandler is IonHandlerBase, IFlashLo
if (flashloanInitiated != 2) revert ExternalBalancerFlashloanNotAllowed();

IERC20Balancer token = tokens[0];
(address user, uint256 initialDeposit, uint256 resultingAdditionalCollateral, uint256 maxResultingDebt) =
abi.decode(userData, (address, uint256, uint256, uint256));
(address user, uint256 initialDeposit, uint256 resultingAdditionalCollateral) =
abi.decode(userData, (address, uint256, uint256));

// Flashloaned WETH needs to be converted into collateral asset
if (address(token) == address(WETH)) {
uint256 collateralFromDeposit = _depositWethForLst(amounts[0]);

// Sanity checks
assert(collateralFromDeposit + initialDeposit == resultingAdditionalCollateral);
assert(collateralFromDeposit <= maxResultingDebt);

// AmountToBorrow.IS_MIN because we want to make sure enough is borrowed to cover flashloan
_depositAndBorrow(user, address(this), resultingAdditionalCollateral, amounts[0], AmountToBorrow.IS_MIN);
Expand All @@ -194,7 +193,6 @@ abstract contract BalancerFlashloanDirectMintHandler is IonHandlerBase, IFlashLo

// Sanity checks
assert(amounts[0] + initialDeposit == resultingAdditionalCollateral);
assert(wethToBorrow <= maxResultingDebt);

// AmountToBorrow.IS_MIN because we want to make sure enough is borrowed to cover flashloan
_depositAndBorrow(user, address(this), resultingAdditionalCollateral, wethToBorrow, AmountToBorrow.IS_MIN);
Expand Down