DeFi
DeFi

Reputation: 97

TypeError: Invalid type for argument in function call

I am going through AAVE v2 flash loan docs and trying out their flash loan boiler plate code. I upgraded the compiler version to 0.8.0. I am getting the following error message.

TypeError: Type contract ILendingPool is not implicitly convertible to expected type uint256.
  --> contracts/MyFlashLoan.sol:36:46:
   |
36 |            IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
   |                                              ^^^^^^^^^^^^


TypeError: Invalid type for argument in function call. Invalid implicit conversion from type(address[1] memory) to address requested.
  --> contracts/MyFlashLoan.sol:36:38:
   |
36 |            IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
   |                                      ^^^^^^^^^^^^^^^^^^^^^


Error HH600: Compilation failed

The code I am trying to compile is as follows,

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import 'hardhat/console.sol';
import { FlashLoanReceiverBase } from './FlashLoanReceiverBase.sol';
import { ILendingPool } from './interfaces/ILendingPool.sol';
import { ILendingPoolAddressesProvider } from './interfaces/ILendingPoolAddressesProvider.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

contract MyFlashLoan is FlashLoanReceiverBase {
    
    constructor(ILendingPoolAddressesProvider _addressProvider) 
    FlashLoanReceiverBase(_addressProvider) {}

    function executeOperation(
        address[] calldata assets, 
        uint256[] calldata amounts, 
        uint256[] calldata premiums, 
        address initiator, 
        bytes calldata params
    )
        external 
        override 
        returns(bool)
    {
            // Flash Loan Code.

        // Approve allowances for the lending pool to pull owed amounts
        for( uint i = 0; i < assets.length;i++){
           uint amountOwing = amounts[i].add(premiums[i]);
           IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
        }
        return true;
    }
}

Why am I getting the above error message? and how can I correct it ?

Upvotes: 0

Views: 300

Answers (1)

Muhammad Hassan
Muhammad Hassan

Reputation: 479

You have to type cast it to make it address payable, in the following manner.

IERC20(assets[i]).approve(payable(address[LENDING_POOL]), amountOwing);

I believe from 0.8 onwards you have to explicitly make the address payable, as you are clearly approving the address before making a transferfrom call.

Upvotes: 1

Related Questions