Skip to content

Commit

Permalink
fix: add validation to simpleFlashLoan
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Valeri committed Nov 15, 2022
1 parent 078fa28 commit bf652c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
7 changes: 2 additions & 5 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,7 @@ library ValidationLogic {
) internal view {
require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
for (uint256 i = 0; i < assets.length; i++) {
DataTypes.ReserveConfigurationMap memory configuration = reservesData[assets[i]]
.configuration;
require(!configuration.getPaused(), Errors.RESERVE_PAUSED);
require(configuration.getActive(), Errors.RESERVE_INACTIVE);
require(configuration.getFlashLoanEnabled(), Errors.FLASHLOAN_DISABLED);
validateFlashloanSimple(reservesData[assets[i]]);
}
}

Expand All @@ -470,6 +466,7 @@ library ValidationLogic {
DataTypes.ReserveConfigurationMap memory configuration = reserve.configuration;
require(!configuration.getPaused(), Errors.RESERVE_PAUSED);
require(configuration.getActive(), Errors.RESERVE_INACTIVE);
require(configuration.getFlashLoanEnabled(), Errors.FLASHLOAN_DISABLED);
}

struct ValidateLiquidationCallLocalVars {
Expand Down
31 changes: 29 additions & 2 deletions test-suites/pool-simple-flashloan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import { waitForTx } from '@aave/deploy-v3';
makeSuite('Pool: Simple FlashLoan', (testEnv: TestEnv) => {
let _mockFlashLoanSimpleReceiver = {} as MockFlashLoanSimpleReceiver;

const { ERC20_TRANSFER_AMOUNT_EXCEEDS_BALANCE, INVALID_FLASHLOAN_EXECUTOR_RETURN } =
ProtocolErrors;
const {
ERC20_TRANSFER_AMOUNT_EXCEEDS_BALANCE,
INVALID_FLASHLOAN_EXECUTOR_RETURN,
FLASHLOAN_DISABLED,
} = ProtocolErrors;
const TOTAL_PREMIUM = 9;
const PREMIUM_TO_PROTOCOL = 3000;

Expand Down Expand Up @@ -178,6 +181,30 @@ makeSuite('Pool: Simple FlashLoan', (testEnv: TestEnv) => {
).to.be.equal(reservesBefore);
});

it('Takes a simple ETH flashloan after flashloaning disabled', async () => {
const { pool, configurator, helpersContract, weth } = testEnv;

expect(await configurator.setReserveFlashLoaning(weth.address, false));
let wethFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(weth.address);
expect(wethFlashLoanEnabled).to.be.equal(false);

const wethFlashBorrowedAmount = ethers.utils.parseEther('0.8');

await expect(
pool.flashLoanSimple(
_mockFlashLoanSimpleReceiver.address,
weth.address,
wethFlashBorrowedAmount,
'0x10',
'0'
)
).to.be.revertedWith(FLASHLOAN_DISABLED);

expect(await configurator.setReserveFlashLoaning(weth.address, true));
wethFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(weth.address);
expect(wethFlashLoanEnabled).to.be.equal(true);
});

it('Takes WETH flashloan, does not return the funds (revert expected)', async () => {
const { pool, weth, users } = testEnv;
const caller = users[1];
Expand Down

0 comments on commit bf652c2

Please sign in to comment.