0

I am able to deploy a smart contract, and even fund it with WETH from my metamask wallet without any gas estimation failures. When I try to execute my flashloan on this smart contract, however, I get this gas estimation failure.

Is this because the smart contract itself needs normal ETH to cover gas fees? Or is there another reason for this to be happening?

I was able to run a flashloan on a previously deployed smart contract, and I don't think I ever deposited normal ETH into it so this has kind of caught me off guard.

Thanks in advance

Here is the code of the contract I am trying to run in Solidity

contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable, ChainlinkClient {

uint256 public volume;

constructor(address _addressProvider) FlashLoanReceiverBaseV2(_addressProvider) public {}

/**
 * @dev This function must be called only be the LENDING_POOL and takes care of repaying
 * active debt positions, migrating collateral and incurring new V2 debt token debt.
 *
 * @param assets The array of flash loaned assets used to repay debts.
 * @param amounts The array of flash loaned asset amounts used to repay debts.
 * @param premiums The array of premiums incurred as additional debts.
 * @param initiator The address that initiated the flash loan, unused.
 * @param params The byte array containing, in this case, the arrays of aTokens and aTokenAmounts.
 */
function executeOperation(
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata premiums,
    address initiator,
    bytes calldata params
)
    external
    override
    returns (bool)
{
    
    //
    // This contract now has the funds requested.
    // Your logic goes here.
    //

    // * Network: Kovan
    // * Oracle: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
    // * Job ID: 29fa9aa13bf1468788b7cc4a500a45b8
    // * Fee: 0.1 LINK

    // address oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
    // bytes32 jobId = "29fa9aa13bf1468788b7cc4a500a45b8";
    // uint256 fee = 0.1 * 10 ** 18;
    // address weth_address = 0xd0A1E359811322d97991E03f863a0C30C2cF029C;
    
    // IERC20(weth_address).transfer(0xeB2D7e847b52FC05321D95d5066bE131c604d7f6, 90000000000000000);

    // requestVolumeData(jobId, oracle, fee);
    
    // At the end of your logic above, this contract owes
    // the flashloaned amounts + premiums.
    // Therefore ensure your contract has enough to repay
    // these amounts.
    
    // Approve the LendingPool contract allowance to *pull* the owed amount
    for (uint i = 0; i < assets.length; i++) {
        uint amountOwing = amounts[i].add(premiums[i]);
        IERC20(assets[i]).approve(address(LENDING_POOL), amountOwing);
    }

    // LENDING_POOL.withdraw(weth_address, 1, 0xeB2D7e847b52FC05321D95d5066bE131c604d7f6);
    
    return true;
}

function _flashloan(address[] memory assets, uint256[] memory amounts) internal {
    address receiverAddress = address(this);

    address onBehalfOf = address(this);
    bytes memory params = "";
    uint16 referralCode = 0;

    uint256[] memory modes = new uint256[](assets.length);

    // 0 = no debt (flash), 1 = stable, 2 = variable
    for (uint256 i = 0; i < assets.length; i++) {
        modes[i] = 0;
    }

    LENDING_POOL.flashLoan(
        receiverAddress,
        assets,
        amounts,
        modes,
        onBehalfOf,
        params,
        referralCode
    );
}
/*
 *  Flash multiple assets 
 */
function flashloan(address[] memory assets, uint256[] memory amounts) public onlyOwner {
    _flashloan(assets, amounts);
}

/*
 *  Flash loan 1000000000000000000 wei (1 ether) worth of `_asset`
 */
function flashloan(address _asset) public onlyOwner {
    bytes memory data = "";
    uint amount = 1 ether;

    address[] memory assets = new address[](1);
    assets[0] = _asset;

    uint256[] memory amounts = new uint256[](1);
    amounts[0] = amount;

    _flashloan(assets, amounts);
}

This is basically the aave-flashloan mix for eth-brownie. You can find the code here https://github.com/brownie-mix/aave-flashloan-mix

LENDING_POOL.flashloan is the big one here... it comes from the repo above, under /contracts/v2/ILendingPoolV2.sol

I don't know the source code for that, as it seems like its imported from somewhere, so I don't know what exact function it uses.

2
  • It is impossible to know without the source code of the function called.
    – Ismael
    Jun 3 at 5:46
  • @Ismael I added the code to the contract, hopefully that is what you need Jun 3 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.