0

I have succesfully deployed the contract to the goerli testnet, via hardhat. However when I try to call the requestFlashLoan function with metamask, the transaction suggested gas fee seems unusually large and fails with the error "Fail with error '27'". I have found this to mean 'The caller of the function is not the lending pool configurator'. However I am still stuck on how to actually fix this.

Been stuck on this for a couple of days now, any direction would be much appreciated!

Tx : https://goerli.etherscan.io/tx/0xfb200d7dafa42dc811a19e984b75ae966951f12b8864d10995491a644044a3f8

Transaction Fail with error '2

Metamask contract integration

My solidity code is below.

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10; // .10 because thats the version a lot of the aave contracts that will be used are on.

import {FlashLoanSimpleReceiverBase} from "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import {IPoolAddressesProvider} from "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import {IERC20} from "@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol";

contract FlashLoan is FlashLoanSimpleReceiverBase {
    address payable owner;

    constructor(address _addressProvider)
        FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider))
    {
        owner = payable(msg.sender);
    }

    function executeOperation(
        address asset,
        uint256 amount,
        uint256 premium,
        address initiator,
        bytes calldata params
    ) external override returns (bool) {
        // we have the borrowed funds
        // Logic
        uint256 amountOwed = amount + premium;
        IERC20(asset).approve(address(POOL), amountOwed);

        return true;
    }

    function requestFlashLoan(address _token, uint256 _amount) public {
        address recieverAddress = address(this);
        address asset = _token;
        uint256 amount = _amount;
        bytes memory params = "";
        uint16 referralCode = 0;

        POOL.flashLoanSimple(recieverAddress, asset, amount, params, referralCode);
    }

    function getBalance(address _tokenAddress) external view returns (uint256) {
        return IERC20(_tokenAddress).balanceOf(address(this));
    }

    function withdraw(address _tokenAddress) external onlyOwner {
        IERC20 token = IERC20(_tokenAddress);
        token.transfer(msg.sender, token.balanceOf(address(this)));
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the contract owner can call this function");
        _;
    }

    receive() external payable {}
}

1 Answer 1

0

i think you try to borrow to a wrong address token pool.<

The function requestFlashLoan(_token, _amount) takes 2 parameters : address of token you want to borrow and amount

I think you pass a wrong address of token to first parameter.

Try to use this official address of USDC Pool on AAVE V3 Testnet : 0xa2025b15a1757311bfd68cb14eaefcc237af5b43

(see this address on documentation : https://docs.aave.com/developers/deployed-contracts/v3-testnet-addresses)

All addresses of tokens you can borrow on a flashloan is on this documentation

I think my answer will help you :)

enter image description here

1
  • Yes that did it! Very much appreciated! If somebody could upvote this for me would be great! Nov 26, 2022 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.