Skip to content

Commit

Permalink
Merge pull request #24 from Ion-Protocol/hrikb/M-01
Browse files Browse the repository at this point in the history
M-01 (OZ Audit)
  • Loading branch information
HrikB committed Jan 17, 2024
2 parents 2774943 + 300f3c8 commit 4b7c35a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 @@ -140,7 +140,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 @@ -173,16 +173,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 @@ -195,7 +194,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

0 comments on commit 4b7c35a

Please sign in to comment.