0

Contract address: 0x2138fF6dB5125F68E69152679D340c09d09eDEF0

USDC token address goerli: 0x9FD21bE27A2B059a288229361E2fA632D8D2d074

I sent USDC to the contract which I can see it when I invoke the "getBalance" function. But, when using that same USDC address that I just checked for getBalance and I invoke the "requestFlashLoan" I get the following error:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Returned error: {"jsonrpc":"2.0","error":"execution reverted: 27","id":2959704706602566}

Can Any suggest anything? Here is my code

// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import {FlashLoanSimpleReceiverBase} from "https://github.com/aave/aave-v3-core/blob/master/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import {IPoolAddressesProvider} from "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol";
import {IERC20} from "https://github.com/aave/aave-v3-core/blob/master/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 should have the borrowed funds by this point
        uint256 amountOwned = amount + premium;
        IERC20(asset).approve(address(POOL), amountOwned);

        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

1

The loan isn't taken from your contract. Your contract only serves as an interface for the Aave's protocol (0x7b5C526B7F8dfdff278b4a3e045083FBA4028790). So the problem is that Aave's Pool address doesn't own the tokens you wish to borrow.

Maybe try looking into the Aave protocol a bit further and supply the protocol with your token before borrowing it.

3
  • Looks like ill need to have some AAVE test USDC sent to my wallet. Looks like the test USDC token contract is: 0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43 I can add it to my metamask but cant seem to find where to have it sent. But thank you!
    – JaySnel
    Jun 15, 2023 at 14:18
  • Everything is now working as expected!
    – JaySnel
    Jun 15, 2023 at 16:56
  • Great, Im glad it helped :)
    – Nal Luksic
    Jun 16, 2023 at 7:54

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.