mirror of
				https://github.com/Instadapp/aave-protocol-v2.git
				synced 2024-07-29 21:47:30 +00:00 
			
		
		
		
	- Added batch of modes to flashLoan()
This commit is contained in:
		
							parent
							
								
									c4753bec66
								
							
						
					
					
						commit
						913a6a9237
					
				| 
						 | 
				
			
			@ -106,7 +106,7 @@ interface ILendingPool {
 | 
			
		|||
   **/
 | 
			
		||||
  event FlashLoan(
 | 
			
		||||
    address indexed target,
 | 
			
		||||
    uint256 mode,
 | 
			
		||||
    uint256[] modes,
 | 
			
		||||
    address[] assets,
 | 
			
		||||
    uint256[] amounts,
 | 
			
		||||
    uint256[] premiums,
 | 
			
		||||
| 
						 | 
				
			
			@ -286,7 +286,7 @@ interface ILendingPool {
 | 
			
		|||
   * @param receiver The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface.
 | 
			
		||||
   * @param assets the address of the principal reserve
 | 
			
		||||
   * @param amounts the amount requested for this flashloan
 | 
			
		||||
   * @param mode the flashloan mode
 | 
			
		||||
   * @param modes the flashloan mode
 | 
			
		||||
   * @param params a bytes array to be sent to the flashloan executor
 | 
			
		||||
   * @param referralCode the referral code of the caller
 | 
			
		||||
   **/
 | 
			
		||||
| 
						 | 
				
			
			@ -294,7 +294,7 @@ interface ILendingPool {
 | 
			
		|||
    address receiver,
 | 
			
		||||
    address[] calldata assets,
 | 
			
		||||
    uint256[] calldata amounts,
 | 
			
		||||
    uint256 mode,
 | 
			
		||||
    uint256[] calldata modes,
 | 
			
		||||
    bytes calldata params,
 | 
			
		||||
    uint16 referralCode
 | 
			
		||||
  ) external;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -502,7 +502,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
 | 
			
		|||
   * @param receiverAddress The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface.
 | 
			
		||||
   * @param assets The addresss of the assets being flashborrowed
 | 
			
		||||
   * @param amounts The amounts requested for this flashloan for each asset
 | 
			
		||||
   * @param mode Type of the debt to open if the flash loan is not returned. 0 -> Don't open any debt, just revert, 1 -> stable, 2 -> variable
 | 
			
		||||
   * @param modes Types of the debt to open if the flash loan is not returned. 0 -> Don't open any debt, just revert, 1 -> stable, 2 -> variable
 | 
			
		||||
   * @param params Variadic packed params to pass to the receiver as extra information
 | 
			
		||||
   * @param referralCode Referral code of the flash loan
 | 
			
		||||
   **/
 | 
			
		||||
| 
						 | 
				
			
			@ -510,7 +510,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
 | 
			
		|||
    address receiverAddress,
 | 
			
		||||
    address[] calldata assets,
 | 
			
		||||
    uint256[] calldata amounts,
 | 
			
		||||
    uint256 mode,
 | 
			
		||||
    uint256[] calldata modes,
 | 
			
		||||
    bytes calldata params,
 | 
			
		||||
    uint16 referralCode
 | 
			
		||||
  ) external override {
 | 
			
		||||
| 
						 | 
				
			
			@ -518,13 +518,12 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
 | 
			
		|||
 | 
			
		||||
    FlashLoanLocalVars memory vars;
 | 
			
		||||
 | 
			
		||||
    ValidationLogic.validateFlashloan(assets, amounts, mode);
 | 
			
		||||
    ValidationLogic.validateFlashloan(assets, amounts, modes);
 | 
			
		||||
 | 
			
		||||
    address[] memory aTokenAddresses = new address[](assets.length);
 | 
			
		||||
    uint256[] memory premiums = new uint256[](assets.length);
 | 
			
		||||
 | 
			
		||||
    vars.receiver = IFlashLoanReceiver(receiverAddress);
 | 
			
		||||
    vars.debtMode = ReserveLogic.InterestRateMode(mode);
 | 
			
		||||
 | 
			
		||||
    for (vars.i = 0; vars.i < assets.length; vars.i++) {
 | 
			
		||||
      aTokenAddresses[vars.i] = _reserves[assets[vars.i]].aTokenAddress;
 | 
			
		||||
| 
						 | 
				
			
			@ -546,7 +545,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
 | 
			
		|||
      vars.currentAmount = amounts[vars.i];
 | 
			
		||||
      vars.currentPremium = premiums[vars.i];
 | 
			
		||||
      vars.currentATokenAddress = aTokenAddresses[vars.i];
 | 
			
		||||
 | 
			
		||||
      vars.debtMode = ReserveLogic.InterestRateMode(modes[vars.i]);
 | 
			
		||||
      vars.currentAmountPlusPremium = vars.currentAmount.add(vars.currentPremium);
 | 
			
		||||
 | 
			
		||||
      if (vars.debtMode == ReserveLogic.InterestRateMode.NONE) {
 | 
			
		||||
| 
						 | 
				
			
			@ -576,14 +575,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
 | 
			
		|||
            msg.sender,
 | 
			
		||||
            msg.sender,
 | 
			
		||||
            vars.currentAmount,
 | 
			
		||||
            mode,
 | 
			
		||||
            modes[vars.i],
 | 
			
		||||
            vars.currentATokenAddress,
 | 
			
		||||
            referralCode,
 | 
			
		||||
            false
 | 
			
		||||
          )
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
      emit FlashLoan(receiverAddress, mode, assets, amounts, premiums, referralCode);
 | 
			
		||||
      emit FlashLoan(receiverAddress, modes, assets, amounts, premiums, referralCode);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -326,17 +326,26 @@ library ValidationLogic {
 | 
			
		|||
 | 
			
		||||
  /**
 | 
			
		||||
   * @dev validates a flashloan action
 | 
			
		||||
   * @param mode the flashloan mode (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan)
 | 
			
		||||
   * @param modes the flashloan modes (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan)
 | 
			
		||||
   * @param assets the assets being flashborrowed
 | 
			
		||||
   * @param amounts the amounts for each asset being borrowed
 | 
			
		||||
   **/
 | 
			
		||||
  function validateFlashloan(
 | 
			
		||||
    address[] memory assets,
 | 
			
		||||
    uint256[] memory amounts,
 | 
			
		||||
    uint256 mode
 | 
			
		||||
    uint256[] memory modes
 | 
			
		||||
  ) internal pure {
 | 
			
		||||
    require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE);
 | 
			
		||||
    require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
 | 
			
		||||
    require(
 | 
			
		||||
      assets.length == amounts.length && assets.length == modes.length,
 | 
			
		||||
      Errors.INCONSISTENT_FLASHLOAN_PARAMS
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    for (uint256 i = 0; i < modes.length; i++) {
 | 
			
		||||
      require(
 | 
			
		||||
        modes[i] <= uint256(ReserveLogic.InterestRateMode.VARIABLE),
 | 
			
		||||
        Errors.INVALID_FLASHLOAN_MODE
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
      _mockFlashLoanReceiver.address,
 | 
			
		||||
      [weth.address],
 | 
			
		||||
      [ethers.utils.parseEther('0.8')],
 | 
			
		||||
      0,
 | 
			
		||||
      [0],
 | 
			
		||||
      '0x10',
 | 
			
		||||
      '0'
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
      _mockFlashLoanReceiver.address,
 | 
			
		||||
      [weth.address],
 | 
			
		||||
      ['1000720000000000000'],
 | 
			
		||||
      0,
 | 
			
		||||
      [0],
 | 
			
		||||
      '0x10',
 | 
			
		||||
      '0'
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			@ -107,7 +107,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
          _mockFlashLoanReceiver.address,
 | 
			
		||||
          [weth.address],
 | 
			
		||||
          [ethers.utils.parseEther('0.8')],
 | 
			
		||||
          0,
 | 
			
		||||
          [0],
 | 
			
		||||
          '0x10',
 | 
			
		||||
          '0'
 | 
			
		||||
        )
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +127,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
          _mockFlashLoanReceiver.address,
 | 
			
		||||
          [weth.address],
 | 
			
		||||
          [ethers.utils.parseEther('0.8')],
 | 
			
		||||
          0,
 | 
			
		||||
          [0],
 | 
			
		||||
          '0x10',
 | 
			
		||||
          '0'
 | 
			
		||||
        )
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
          _mockFlashLoanReceiver.address,
 | 
			
		||||
          [weth.address],
 | 
			
		||||
          [ethers.utils.parseEther('0.8')],
 | 
			
		||||
          4,
 | 
			
		||||
          [4],
 | 
			
		||||
          '0x10',
 | 
			
		||||
          '0'
 | 
			
		||||
        )
 | 
			
		||||
| 
						 | 
				
			
			@ -175,7 +175,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
        _mockFlashLoanReceiver.address,
 | 
			
		||||
        [weth.address],
 | 
			
		||||
        [ethers.utils.parseEther('0.8')],
 | 
			
		||||
        2,
 | 
			
		||||
        [2],
 | 
			
		||||
        '0x10',
 | 
			
		||||
        '0'
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +201,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
        _mockFlashLoanReceiver.address,
 | 
			
		||||
        [weth.address],
 | 
			
		||||
        ['1004415000000000000'], //slightly higher than the available liquidity
 | 
			
		||||
        2,
 | 
			
		||||
        [2],
 | 
			
		||||
        '0x10',
 | 
			
		||||
        '0'
 | 
			
		||||
      ),
 | 
			
		||||
| 
						 | 
				
			
			@ -213,7 +213,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
    const {pool, deployer, weth} = testEnv;
 | 
			
		||||
 | 
			
		||||
    await expect(
 | 
			
		||||
      pool.flashLoan(deployer.address, [weth.address], ['1000000000000000000'], 2, '0x10', '0')
 | 
			
		||||
      pool.flashLoan(deployer.address, [weth.address], ['1000000000000000000'], [2], '0x10', '0')
 | 
			
		||||
    ).to.be.reverted;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -241,7 +241,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
      _mockFlashLoanReceiver.address,
 | 
			
		||||
      [usdc.address],
 | 
			
		||||
      [flashloanAmount],
 | 
			
		||||
      0,
 | 
			
		||||
      [0],
 | 
			
		||||
      '0x10',
 | 
			
		||||
      '0'
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			@ -283,7 +283,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
          _mockFlashLoanReceiver.address,
 | 
			
		||||
          [usdc.address],
 | 
			
		||||
          [flashloanAmount],
 | 
			
		||||
          2,
 | 
			
		||||
          [2],
 | 
			
		||||
          '0x10',
 | 
			
		||||
          '0'
 | 
			
		||||
        )
 | 
			
		||||
| 
						 | 
				
			
			@ -309,7 +309,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
 | 
			
		||||
    await pool
 | 
			
		||||
      .connect(caller.signer)
 | 
			
		||||
      .flashLoan(_mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], 2, '0x10', '0');
 | 
			
		||||
      .flashLoan(_mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], [2], '0x10', '0');
 | 
			
		||||
    const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
 | 
			
		||||
      usdc.address
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			@ -344,7 +344,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
    await expect(
 | 
			
		||||
      pool
 | 
			
		||||
        .connect(caller.signer)
 | 
			
		||||
        .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 0, '0x10', '0')
 | 
			
		||||
        .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [0], '0x10', '0')
 | 
			
		||||
    ).to.be.revertedWith(SAFEERC20_LOWLEVEL_CALL);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -359,7 +359,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
 | 
			
		|||
 | 
			
		||||
    await pool
 | 
			
		||||
      .connect(caller.signer)
 | 
			
		||||
      .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, '0x10', '0');
 | 
			
		||||
      .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [1], '0x10', '0');
 | 
			
		||||
 | 
			
		||||
    const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -187,7 +187,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
 | 
			
		|||
    await expect(
 | 
			
		||||
      pool
 | 
			
		||||
        .connect(caller.signer)
 | 
			
		||||
        .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, '0x10', '0')
 | 
			
		||||
        .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [1], '0x10', '0')
 | 
			
		||||
    ).revertedWith(IS_PAUSED);
 | 
			
		||||
 | 
			
		||||
    // Unpause pool
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user