brownie-mix / aave-flashloan-mix

A Brownie mix containing all you need to get started with developing flash loans
GNU Affero General Public License v3.0
399 stars 275 forks source link

Gas fees issue #30

Open Abdel364 opened 2 years ago

Abdel364 commented 2 years ago

i have run the flashloan contract for the first time it went well but the second time it gives me this error Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually. and i do have testnet eth and everything can someone help me please

Devilla commented 2 years ago

I tried reproducing the above for Kovan @PatrickAlphaC how much the gas fee should be adequate

$ brownie run scripts/run_flash_loan_v2.py --network kovan
Brownie v1.19.0 - Python development framework for Ethereum

AaveFlashloanProject is the active project.

Running 'scripts/run_flash_loan_v2.py::main'...
Getting Flashloan contract...
Executing Flashloan...
  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/run_flash_loan_v2.py", line 20, in main
    tx = flashloan.flashloan(weth, {"from": acct})
  File "brownie/network/contract.py", line 1489, in __call__
    return fn(*args, **kwargs)  # type: ignore
  File "brownie/network/contract.py", line 1861, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1734, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 644, in transfer
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 727, in _make_transaction
    raise VirtualMachineError(e) from None
  File "brownie/exceptions.py", line 93, in __init__
    raise ValueError(str(exc)) from None
ValueError: Gas estimation failed: 'The execution failed due to an exception.'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
Devilla commented 2 years ago

So I traced back the error a callback from SafeERC20 responsible for this issue

 Trace step 14203, program counter 6555:
  File "contracts/protocol/lendingpool/LendingPool.sol", lines 532-536, in LendingPool.flashLoan:    
    IERC20(vars.currentAsset).safeTransferFrom(
      receiverAddress,
      vars.currentATokenAddress,
      vars.currentAmountPlusPremium
    );
Trace step 14297, program counter 11619:
  File "contracts/dependencies/openzeppelin/contracts/SafeERC20.sol", line 36, in SafeERC20.safeTransferFrom:    
    callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
Trace step 14484, program counter 16308:
  File "contracts/dependencies/openzeppelin/contracts/SafeERC20.sol", line 55, in SafeERC20.callOptionalReturn:    
    (bool success, bytes memory returndata) = address(token).call(data);
Trace step 14484, program counter 16308:
  File "contracts/dependencies/openzeppelin/contracts/SafeERC20.sol", line 55, in SafeERC20.callOptionalReturn:    
    (bool success, bytes memory returndata) = address(token).call(data);