Skip to content

Commit

Permalink
add check for max balance before call to amountOut
Browse files Browse the repository at this point in the history
  • Loading branch information
jpick713 authored Jul 26, 2024
1 parent d5a15d3 commit ba69990
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/flash/AerodromeFlashswapHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ abstract contract AerodromeFlashswapHandler is IonHandlerBase, IPoolCallee {
// sync balances with reserves to avoid cases where there are unpredictable fee calculations
IPool(address(AERODROME_POOL)).sync();
}
// revert if trying to take all (or more) of the collateral
if(amountToLeverage >= balanceOut){
revert AmountInTooHigh(amountToLeverage, balanceOut);
}

uint256 amountToPay = _calculateAmountToPay(balanceIn, balanceOut, amountToLeverage, balanceIn*balanceOut);
console.log("Amount to Pay: ", amountToPay);
Expand Down Expand Up @@ -245,6 +249,10 @@ abstract contract AerodromeFlashswapHandler is IonHandlerBase, IPoolCallee {
IPool(address(AERODROME_POOL)).sync();
}

// revert if trying to take all (or more) of the weth
if(debtToRemove >= balanceOut){
revert AmountInTooHigh(debtToRemove, balanceOut);
}
uint256 amountToPay = _calculateAmountToPay(balanceIn, balanceOut, debtToRemove, balanceIn*balanceOut);

// This protects against a potential sandwich attack
Expand Down

0 comments on commit ba69990

Please sign in to comment.