Skip to content

Can't call POOL.flashLoan provided by Aave #69

@Utatistics

Description

@Utatistics

I'm trying to call POOL.flashLoan provided by Aave core v3. This is for a test and done on forked mainnet using ganache/truffle.

contract FlashLoanArbitrage {

    IPool public POOL;
    
    constructor(
        address _poolAddressesProvider,
    )
    {
        IPoolAddressesProvider provider = IPoolAddressesProvider(_poolAddressesProvider);
        POOL = IPool(provider.getPool());  // Initialize the POOL contract
    }

    function executeFlashLoan(
        address[] calldata assets,
        uint256[] calldata flashLoanAmounts,
        uint256[] calldata modes,
        address onBehalfOf,
        bytes calldata params
    ) external {

        POOL.flashLoan(address(this), assets, flashLoanAmounts, modes, onBehalfOf, params, 0);
    }

}

In above Solidity code, as recommended in the official Aave documentation, I am using poolAddressProvider contract to obtain the address of the POOL contract. Then calling executeFlashLoan, which is my endpoint, shuold run POOL.flashloan to request the loan. However, callng this endpoint failes due to flashLoan not properly being called.

Since truffle debug did not provide much information to indicate what went wrong, I tried to directly call flashLoan via web3 python, which did not work either.

   pool_contract = w3.eth.contract(address=pool_address, abi=pool_abi)

    # Proceed with your existing code using POOL_contract
    address = '0xb9af6288810670DAb8bb01CB51A37Af334A90304'
    assets = ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]
    amounts = [Web3.to_wei(100, 'ether')]
    modes = [0]
    on_behalf_of = address
    params = b""

    logger.info(f'{address=}')
    logger.info(f'{assets=}')
    logger.info(f'{amounts=}')
    logger.info(f'{modes=}')
    logger.info(f'{on_behalf_of=}')
    logger.info(f'{params=}')

    try:
        result = pool_contract.functions.flashLoan(
            address,
            assets,
            amounts,
            modes,
            on_behalf_of,
            params,
            0
        ).call({'from': address})
        logger.info("Flash loan simulation successful. Result:", result)
    except Exception as e:
        logger.error("Flash loan simulation error: %s", e)


2024-10-27 12:13:09 [INFO] address='0xb9af6288810670DAb8bb01CB51A37Af334A90304'
2024-10-27 12:13:09 [INFO] assets=['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2']
2024-10-27 12:13:09 [INFO] amounts=[100000000000000000000]
2024-10-27 12:13:09 [INFO] modes=[0]
2024-10-27 12:13:09 [INFO] on_behalf_of='0xb9af6288810670DAb8bb01CB51A37Af334A90304'
2024-10-27 12:13:09 [INFO] params=b'' 
2024-10-27 12:14:15 [ERROR] Flash loan simulation error: ("The function 'flashLoan' was not found in this contract's abi.", ' Are you sure you provided the correct contract abi?')

Since the erorr suggests that contract abi (or its address) is not accurate, I checked the following:


function flashLoan(
    address receiverAddress,
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata interestRateModes,
    address onBehalfOf,
    bytes calldata params,
    uint16 referralCode
  ) public virtual override {
    DataTypes.FlashloanParams memory flashParams = DataTypes.FlashloanParams({
      receiverAddress: receiverAddress,
      assets: assets,
      amounts: amounts,
      interestRateModes: interestRateModes,
      onBehalfOf: onBehalfOf,
      params: params,
      referralCode: referralCode,
      flashLoanPremiumToProtocol: _flashLoanPremiumToProtocol,
      flashLoanPremiumTotal: _flashLoanPremiumTotal,
      reservesCount: _reservesCount,
      addressesProvider: address(ADDRESSES_PROVIDER),
      pool: address(this),
      userEModeCategory: _usersEModeCategory[onBehalfOf],
      isAuthorizedFlashBorrower: IACLManager(ADDRESSES_PROVIDER.getACLManager()).isFlashBorrower(
        msg.sender
      )
    });
 

I suspect that I might not be passing the parameters in the expected format, or not instanciating the POOL contract right, etc. Could anybody help me resolve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions