Coder Social home page Coder Social logo

brownie-mix / aave-flashloan-mix Goto Github PK

View Code? Open in Web Editor NEW
398.0 16.0 267.0 360 KB

A Brownie mix containing all you need to get started with developing flash loans

License: GNU Affero General Public License v3.0

Solidity 78.91% Python 20.81% Shell 0.28%
brownie web3

aave-flashloan-mix's Introduction

Aave Flash Loan Brownie Mix

Aave Banner

Adapted from aave/flashloan-box by mrdavey.

This Brownie mix comes with everything you need to start developing on flash loans.

This mix is configured for use with Ganache on a forked mainnet.

It supports both Aave V1 and V2.

Installation and Setup

  1. Install Brownie & Ganache-CLI, if you haven't already.

  2. Sign up for Infura and generate an API key. Store it in the WEB3_INFURA_PROJECT_ID environment variable. You can learn more about environment variables here. If you're unfamiliar with environment variables you can just add all these commands to your .env file and run source .env when you're done.

export WEB3_INFURA_PROJECT_ID=YourProjectID
  1. Sign up for Etherscan and generate an API key. This is required for fetching source codes of the mainnet contracts we will be interacting with. Store the API key in the ETHERSCAN_TOKEN environment variable.
export ETHERSCAN_TOKEN=YourApiToken
  1. Download the mix.
brownie bake aave-flashloan
  1. Add your PRIVATE_KEY environment variable, with a private key from you wallet.. *Note: If using metamask, you'll have to add a 0x to the start of your private key)

Quickstart (Kovan)

We can see our flash loans on Etherscan via the Kovan testnet. If you're rather *run everything locally, check out the Basic Console Use.

  1. Get some WETH. We need this to pay the preimum that flash loans cost.
$ brownie run scripts/get_weth.py --network kovan
  1. Deploy the flash loan contract. This will also fund the contract with WETH to pay the flash loan fee if it's not funded.
$ brownie run scripts/deployment_v2.py --network kovan
  1. Execute the flash loan
$ brownie run scripts/run_flash_loan_v2.py --network kovan

This will print out an etherscan URL to see the flash loan transaction. Like this one.

Basic Console Use

To perform a simple flash loan in a development environment:

  1. Open the Brownie console. This automatically launches Ganache on a forked mainnet.
$ brownie console
  1. Create variables for the Aave lending pool.
>>> aave_lending_pool_v2 = "0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5"
  1. Deploy the FlashloanV2.sol contract.
>>> flashloan = FlashloanV2.deploy(aave_lending_pool_v2, {"from": accounts[0]})
Transaction sent: 0xb0f70b42d2cec9c027b664e9f37490ad50fb934e61f0c58cfe5a77d96dfad681
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 8
  FlashloanV2.constructor confirmed - Block: 11577534   Gas used: 957504 (7.98%)
  FlashloanV2 deployed at: 0x420b1099B9eF5baba6D92029594eF45E19A04A4A
  1. Transfer some Ether in form of WETH to the newly deployed contract. We must do this because we have not implemented any custom flash loan logic, otherwise the loan will fail from an inability to pay the fee.
>>> WETH = Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
>>> accounts[0].transfer(WETH, "1 ether")
Transaction sent: 0x29ac98c861356bc65e19407d8389e53f8c3d9a05513a8610c9de2ef013aac525
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 10
  Transaction confirmed - Block: 11577536   Gas used: 28431 (0.24%)
>>> WETH.transfer(flashloan, "1 ether", {"from": accounts[0]})
Transaction sent: 0x1bff7e44779eb92d426bc432d22ecb9821e0b66afb66d48404a23e37b34044e6
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 11
  ERC20.transfer confirmed - Block: 11577537   Gas used: 36794 (0.31%)
  1. Now we are ready to perform our first flash loan!
>>> tx = flashloan.flashloan(WETH, {"from": accounts[0]})
Transaction sent: 0x335530e6d2b7588ee4727b35ae1ed8634a264aca04b325640101ec1c2b89d499
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 12
  FlashloanV2.flashloan confirmed - Block: 11577538   Gas used: 193010 (1.61%)

Implementing Flash Loan Logic

contracts/v2/FlashloanV2.sol is where you implement your own logic for flash loans. In particular:

  • The size of the loan is set in line 89 in flashloan.
  • Custom flash loan logic is added after line 31 in executeOperation.

See the Aave documentation on Performing a Flash Loan for more detailed information.

Testing

To run the tests:

brownie test

The example tests provided in this mix start by transfering funds to the FlashloanV2.sol contract. This ensures that the loan executes succesfully without any custom logic. Once you have built your own logic, you should edit tests/test_flashloan_v2.py and remove this initial funding logic.

See the Brownie documentation for more detailed information on testing your project.

Debugging Failed Transactions

Use the --interactive flag to open a console immediatly after each failing test:

brownie test --interactive

Within the console, transaction data is available in the history container:

>>> history
[<Transaction '0x50f41e2a3c3f44e5d57ae294a8f872f7b97de0cb79b2a4f43cf9f2b6bac61fb4'>,
 <Transaction '0x7af1ce1c30de8b939f481fd6c340226415428f7e6b59e09d7fa5383939091824'>]

Examine the TransactionReceipt for the failed test to determine what went wrong. For example, to view a traceback:

>>> tx = history[-1]
>>> tx.traceback()

Traceback for '0x7af1ce1c30de8b939f481fd6c340226415428f7e6b59e09d7fa5383939091824':


Trace step 13656, 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 13750, 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 13937, 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 13937, program counter 16308:
  File "contracts/dependencies/openzeppelin/contracts/SafeERC20.sol", line 55, in SafeERC20.callOptionalReturn:    
    (bool success, bytes memory returndata) = address(token).call(data);

To view a tree map of how the transaction executed:

>>> tx.call_trace()

Call trace for '0x7af1ce1c30de8b939f481fd6c340226415428f7e6b59e09d7fa5383939091824':
Initial call cost  [21432 gas]
FlashloanV2.flashloan  0:14132  [3717 / 174153 gas]
└── ILendingPoolV2.flashLoan  [CALL]  662:14120  [1996 / 170436 gas]
    └── LendingPool.flashLoan  [DELEGATECALL]  759:14107  [218057 / 168440 gas]
        ├── ValidationLogic.validateFlashloan  1428:1461  [106 gas]
        ├── SafeMath.mul  1752:1779  [100 gas]
        ├── SafeMath.div  1783:1831  [161 gas]
        ├── IAtoken  [CALL]  1963:2807  [1914 / 20764 gas]
        │   └── AToken.transferUnderlyingTo  [DELEGATECALL]  2060:2795  [2988 / 18850 gas]
        │       └── ERC20.transfer  [CALL]  2422:2695  [15862 gas]
        ├── FlashloanV2.executeOperation  [CALL]  3252:3904  [3035 / 11055 gas]
        │   └── ERC20.approve  [CALL]  3681:3836  [8020 gas]
        ├── SafeMath.add  4186:4204  [59 gas]
        ├── ReserveLogic.updateState  4270:5480  [10868 / 17605 gas]
        │   ├── InitializableImmutableAdminUpgradeabilityProxy.scaledTotalSupply  [STATICCALL]  4322:4500  [1908 / 3663 gas]
        │   │   └── VariableDebtToken.scaledTotalSupply  [DELEGATECALL]  4419:4488  [1755 gas]
        │   ├── ReserveLogic._updateIndexes  4593:4758  [995 / 1352 gas]
        │   │   ├── MathUtils.calculateLinearInterest  4620:4678  [53 / 183 gas]
        │   │   │   └── SafeMath.sub  4630:4671  [130 gas]
        │   │   ├── WadRayMath.ray  4685:4689  [15 gas]
        │   │   ├── SafeMath.mul  4696:4723  [100 gas]
        │   │   └── SafeMath.add  4732:4750  [59 gas]
        │   ├── WadRayMath.rayMul  4766:4836  [238 gas]
        │   ├── MathUtils.calculateCompoundedInterest  4919:4985  [80 / 210 gas]
        │   │   └── SafeMath.sub  4937:4978  [130 gas]
        │   ├── WadRayMath.rayMul  5018:5088  [238 gas]
        │   ├── WadRayMath.rayMul  5097:5167  [244 gas]
        │   ├── SafeMath.mul  5179:5206  [100 gas]
        │   ├── SafeMath.mul  5210:5237  [100 gas]
        │   ├── SafeMath.mul  5256:5283  [100 gas]
        │   ├── SafeMath.mul  5287:5314  [100 gas]
        │   ├── SafeMath.mul  5318:5345  [100 gas]
        │   ├── SafeMath.mul  5363:5390  [100 gas]
        │   ├── WadRayMath.ray  5394:5398  [15 gas]
        │   ├── SafeMath.add  5402:5420  [59 gas]
        │   ├── SafeMath.add  5424:5442  [59 gas]
        │   └── SafeMath.add  5446:5464  [59 gas]
        ├── WadRayMath.rayMul  5495:5565  [245 gas]
        ├── ReserveLogic._mintToTreasury  5672:7537  [2857 / 14960 gas]
        │   ├── ReserveConfiguration.getReserveFactor  5748:5756  [824 gas]
        │   ├── InitializableImmutableAdminUpgradeabilityProxy.getSupplyData  [STATICCALL]  5820:6706  [1929 / 9318 gas]
        │   │   └── StableDebtToken.getSupplyData  [DELEGATECALL]  5917:6694  [7389 gas]
        │   ├── WadRayMath.rayMul  6813:6883  [245 gas]
        │   ├── WadRayMath.rayMul  6893:6963  [244 gas]
        │   ├── MathUtils.calculateCompoundedInterest  6984:7042  [54 / 191 gas]
        │   │   └── SafeMath.sub  6994:7035  [137 gas]
        │   ├── WadRayMath.rayMul  7075:7145  [244 gas]
        │   ├── WadRayMath.rayMul  7154:7224  [245 gas]
        │   ├── SafeMath.mul  7236:7263  [100 gas]
        │   ├── SafeMath.mul  7267:7294  [100 gas]
        │   ├── SafeMath.mul  7313:7340  [100 gas]
        │   ├── SafeMath.mul  7344:7371  [100 gas]
        │   ├── SafeMath.mul  7375:7402  [100 gas]
        │   ├── SafeMath.mul  7420:7447  [100 gas]
        │   ├── WadRayMath.ray  7451:7455  [15 gas]
        │   ├── SafeMath.add  7459:7477  [59 gas]
        │   ├── SafeMath.add  7481:7499  [59 gas]
        │   └── SafeMath.add  7503:7521  [59 gas]
        ├── WadRayMath.rayMul  7552:7622  [244 gas]
        ├── SafeMath.add  7650:7668  [59 gas]
        ├── SafeMath.sub  7672:7713  [137 gas]
        ├── SafeMath.sub  7724:7765  [137 gas]
        ├── PercentageMath.percentMul  7788:7860  [255 gas]
        ├── IAtoken  [CALL]  7938:8460  [1911 / 19056 gas]
        │   └── AToken.mintToTreasury  [DELEGATECALL]  8035:8448  [17145 gas]
        ├── IAtoken.totalSupply  [STATICCALL]  8530:9167  [1908 / 9796 gas]
        │   └── AToken.totalSupply  [DELEGATECALL]  8627:9155  [3006 / 7888 gas]
        │       └── ILendingPoolV2.getReserveNormalizedIncome  [STATICCALL]  8755:9048  [1911 / 4882 gas]
        │           └── LendingPool.getReserveNormalizedIncome  [DELEGATECALL]  8852:9036  [1237 / 2971 gas]
        │               └── ReserveLogic.getNormalizedIncome  8963:9006  [1734 gas]
        ├── ReserveLogic.cumulateToLiquidityIndex  9246:9616  [2768 / 3626 gas]
        │   ├── WadRayMath.wadToRay  9253:9294  [131 gas]
        │   ├── WadRayMath.wadToRay  9299:9340  [138 gas]
        │   ├── WadRayMath.rayDiv  9344:9423  [270 gas]
        │   ├── WadRayMath.ray  9431:9435  [15 gas]
        │   ├── SafeMath.add  9440:9458  [59 gas]
        │   └── WadRayMath.rayMul  9478:9548  [245 gas]
        ├── ReserveLogic.updateInterestRates  9656:11398  [6759 / 20432 gas]
        │   ├── InitializableImmutableAdminUpgradeabilityProxy.getTotalSupplyAndAvgRate  [STATICCALL]  9767:10627  [1915 / 7639 gas]
        │   │   └── StableDebtToken.getTotalSupplyAndAvgRate  [DELEGATECALL]  9864:10615  [5724 gas]
        │   ├── InitializableImmutableAdminUpgradeabilityProxy.scaledTotalSupply  [STATICCALL]  10769:10947  [1908 / 3663 gas]
        │   │   └── VariableDebtToken.scaledTotalSupply  [DELEGATECALL]  10866:10935  [1755 gas]
        │   ├── WadRayMath.rayMul  11001:11071  [245 gas]
        │   ├── ERC20.balanceOf  [STATICCALL]  11137:11247  [1934 gas]
        │   ├── SafeMath.add  11328:11346  [59 gas]
        │   └── SafeMath.sub  11350:11391  [133 gas]
        ├── ReserveConfiguration.getReserveFactor  11415:11423  [824 gas]
        ├── DefaultReserveInterestRateStrategy.calculateInterestRates  [STATICCALL]  11507:13284  [7330 / 11175 gas]
        │   ├── ILendingPoolAddressesProviderV2.getLendingRateOracle  [STATICCALL]  11838:11954  [1959 gas]
        │   └── LendingRateOracle.getMarketBorrowRate  [STATICCALL]  12031:12129  [1886 gas]
        └── SafeERC20.safeTransferFrom  13657:14107  [291 / -180413 gas]
            └── SafeERC20.callOptionalReturn  13751:14107  [-183382 / -180704 gas]
                ├── Address.isContract  13762:13784  [769 gas]
                └── ERC20.transferFrom  [CALL]  13938:14045  [1909 gas]

See the Brownie documentation for more detailed information on debugging failed transactions.

Deployment

When you are finished testing and ready to deploy to the mainnet:

  1. Import a keystore into Brownie for the account you wish to deploy from. Add this as a PRIVATE_KEY environment variable.
  2. Run the deployment script on the mainnet using the following command:
$ brownie run scripts/deployment_v2.py --network mainnet

Known issues

No access to archive state errors

If you are using Ganache to fork a network, then you may have issues with the blockchain archive state every 30 minutes. This is due to your node provider (i.e. Infura) only allowing free users access to 30 minutes of archive state. To solve this, upgrade to a paid plan, or simply restart your ganache instance and redploy your contracts.

Troubleshooting

See our Troubleshooting Errors documentation.

Resources

aave-flashloan-mix's People

Contributors

emilianobonassi avatar iamdefinitelyahuman avatar molecula451 avatar mrdavey avatar patrickalphac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aave-flashloan-mix's Issues

Increasing the loan amount

Increasing the amount from 1 ether (to any of 2, 5, 10 ether) in FlashloanV2.sol:89 leads to the following error:

ValueError: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

Trying to interact with the overloaded flashloan function in the run_flash_loan_v2.py script via

tx = flashloan.flashloan([weth], [5 * 1e18], {"from": acct})

also leads to the same error. Everything works fine as long as I only flash 1 ether.

What is the correct way to increase the loan amount?

Unable to publish and verify contract

Adding publish_source=True as an argument to the deploy function inside deployment_v2.py does still deploy the contract, but the contract is always unable to verify. I have tried publishing the contract through this method, as well as using the brownie console but it never seems to work for me.

image

Thanks for the repo, by the way. Very useful.

private key must be exactly 32 bytes long

Hey there,

I am currently experiencing the issue that i can not use my MetaMask Private key.
Brownie is able to detect the Private Key but is not able to preceed and exiting with following error:

ValueError: The private key must be exactly 32 bytes long, instead of 67 bytes.

"0x" ist set
0xisset

brownie-config.yaml includes "dotenv: .env"

Am not really sure how to resolve this issue and would be very thankful for help!

Cheers,
Kevin

aave v3 flash loan

The implementation changes slightly from AAVE V2 to V3. Would it be interesting to have a V3 implementation as well?
Thanks for your amazing work!

How to withdraw from the smart contract to the wallet

Hi Everyone,

I managed to deploy the smart contract and perform the flash loans. However, I don't know how to withdraw the funds from the smart contract.
Let's talk with the case on hand:

To do the flashloan, funds are transferred from wallet to the contract with transaction https://kovan.etherscan.io/tx/0x9c3d95bd9ddb14e7debfe9153724f7b3aaf0d981b4657d1a000e2d70860eff44 to cover the fees. Then I'm able to execute the flashloan correctly.

However, now the contract has a balance, that should be transferred back to my wallet. So my doubt is:

  • How do I transfer the balance on the contract back to my wallet?
  • Could be that the code is effectively transferring the profit back to the wallet, but I am not seeing it because there is no profit in the transaction I did? It was only the flashloan, so there is a loss for the fees.

Thanks for who can clarify me this.

ConnectionError: Status 404 when retrieving repo brownie-mix/aave-flash information from GHAPI: 'Not Found'

When I was installing aave-flash by running brownie bake aave-flash, I have this error.
I've updated the GitHub token and still getting this error

aave-flashloan-mix git/main*  26s
(flashloan) ❯ brownie bake aave-flash
Brownie v1.17.1 - Python development framework for Ethereum

  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/bake.py", line 26, in main
    path = project.from_brownie_mix(args["<mix>"], args["<path>"], args["--force"])
  File "brownie/project/main.py", line 608, in from_brownie_mix
    default_branch = _get_mix_default_branch(project_name, headers)
  File "brownie/project/main.py", line 1036, in _get_mix_default_branch
    raise ConnectionError(msg)
ConnectionError: Status 404 when retrieving repo brownie-mix/aave-flash information from GHAPI: 'Not Found'

Missing or forbidden.
If this issue persists, generate a Github API token and store it as the environment variable `GITHUB_TOKEN`:
https://github.blog/2013-05-16-personal-api-tokens/

"ConnectionError" with "api-kovan.etherscan.io". Why? pls!

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api-kovan.etherscan.io', port=443): Max retries exceeded with url: /api?module=contract&action=getsourcecode&address=0x8c43d532314f05C1807f606771CE4d2cb006cA3a&apiKey=ANBNBT6PU6QT5979R7NS61641GH31GEAA3 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc8c121cbe0>: Failed to establish a new connection: [Errno 110] Connection timed out'))

Gas fees issue

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

Insufficient funds error message after running get_weth.py

error: raise ValueError(exc["message"]) from None
ValueError: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 1000049572000396576 and got: 0.
Does this script fund the wallet or do I have to fund it seperately via Metamask. Please advise.
Thanks
EF

flashloan.flashloan() got an unexpected argument 'block_identifier'

Hello, I have gone through all the steps however cannot run the last step of tx = flashloan.flashloan(WETH, {"from": accounts[2]})
It returns an error of
File "<console>", line 1, in <module> File "eth_brownie-1.17.2-py3.9.egg/brownie/network/contract.py", line 1303, in __call__ return fn(*args, block_identifier=block_identifier, override=override) # type: ignore TypeError: __call__() got an unexpected keyword argument 'block_identifier'

ValueError: invalid literal for int() with base 16: '0x'

I'm trying to run the example code in the README and I'm running into an error when I try to execute the following line:

>>> WETH = Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")

Here's my traceback:

  File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 923, in __init__
    contract = self.from_explorer(address, owner=owner, silent=True)
  File "brownie/network/contract.py", line 1102, in from_explorer
    if int(implementation_eip1967.hex(), 16):
ValueError: invalid literal for int() with base 16: '0x'

Is it expecting an int?

Thanks in advance for the help.

[Quickstart Kovan] ValueError: Gas estimation failed: 'The execution failed due to an exception.'

Hi, while following the steps to test the repo on the Kovan test network I ran into this issue : **. get_weth.py works well, I can see the ETH being replaced by WETH on Metamask, deployement_v2 works fine too (the contract is visible on etherscan). The issue resides in run_flash_loan_v2.py at line 20 : tx = flashloan.flashloan(weth, {"from": acct}). Could you help me out. Thx in advance

** : brownie run scripts/run_flash_loan_v2.py --network kovan
Brownie v1.15.2 - Python development framework for Ethereum

AaveFlashloanMixProject is the active project.

Running 'scripts/run_flash_loan_v2.py::main'...
Getting Flashloan contract...
Funding Flashloan contract with WETH...
Transaction sent: 0x1e9e940aacbbf711e8e406078c17b2bf7a6a787828ef85f596e6007dcd4a6241
Gas price: 1.1 gwei Gas limit: 56934 Nonce: 150
WethInterface.transfer confirmed - Block: 26576860 Gas used: 51759 (90.91%)

Executing Flashloan...
File "brownie/_cli/run.py", line 49, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, 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 1338, in call
return fn(*args) # type: ignore
File "brownie/network/contract.py", line 1691, in call
return self.transact(*args)
File "brownie/network/contract.py", line 1565, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 658, in transfer
gas_limit = Wei(gas_limit) or self._gas_limit(to, amount, gas_price, gas_buffer, data)
File "brownie/network/account.py", line 425, in _gas_limit
gas_limit = self.estimate_gas(to, amount, gas_price, data or "")
File "brownie/network/account.py", line 618, in estimate_gas
raise ValueError(
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.

Something wrong with "flashloan = FlashloanV2[len(FlashloanV2) - 1]".

brownie run scripts/run_flash_loan_v2.py --network kovan

File "./scripts/run_flash_loan_v2.py", line 18, in main
print(FlashloanV2[-1])
File "brownie/network/contract.py", line 158, in getitem
return self._contracts[i]
IndexError: list index out of range

Here is some of the code:

def main(): 
    acct = accounts.add(config["wallets"]["from_key"])
    print("Getting Flashloan contract...")
    flashloan = FlashloanV2[len(FlashloanV2) - 1]
    weth = interface.WethInterface(config["networks"][network.show_active()]["weth"])<br class="Apple-interchange-newline">

So I print(len(FlashLoanV2)) and get 0.
seems like it can't read FlashLoanV2 object as an array, so I can't get the address in it through FlashLoanV2[...].
How to solve this, it's because of my python version or something else?
Thanks!

gas required exceeds allowance (12487735) or always failing transaction

Hi, Thank you for this repo. Very nice.

I deployed a contract, on the mainnet, based on your kit with my own parts added. When I try to call the flashloan function I get the following error.

Any advice ?

acct
<LocalAccount '0x513E95Eec3bAC74802b4b2D859e802f17eAE57a9'>
flashloan
<MyFlashloanContract Contract '0x80be9fBea39Ae56d090148c4EF96f7f7f4Dc9Aa1'>
tx = flashloan.flashloan(eth_reserve,10000000000000000,chai_reserve, {"from": acct})
File "", line 1, in
File "c:\users\alexander, line line, in in
return self.transact(*args)
File "c:\users\alexander, line line, in in
return tx["from"].transfer(
File "c:\users\alexander, line line, in in
"gas": Wei(gas_limit) or self._gas_limit(to, amount, gas_buffer, data),
File "c:\users\alexander, line line, in in
gas_limit = self.estimate_gas(to, amount, data or "")
File "c:\users\alexander, line line, in in
return web3.eth.estimateGas(
File "c:\users\alexander, line line, in in
return self.web3.manager.request_blocking(
File "c:\users\alexander, line line, in in
raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'gas required exceeds allowance (12463323) or always failing transaction'}

Best,
Alexander

Error when I run the get WETH command: brownie run scripts/get_weth.py --network kovan

After setting up the environment and when I run the get WETH command: brownie run scripts/get_weth.py --network kovan i get the following error:
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli_main_.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli\run.py", line 44, in main
network.connect(CONFIG.argv["network"])
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py", line 40, in connect
web3.connect(host, active.get("timeout", 30))
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 52, in connect
uri = _expand_environment_vars(uri)
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 183, in _expand_environment_vars
raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
ValueError: Unable to expand environment variable in host setting: 'https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID'
PS C:\Users\Ash> brownie run scripts/run_flash_loan_v2.py --network kovan
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli_main_.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli\run.py", line 44, in main
network.connect(CONFIG.argv["network"])
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py", line 40, in connect
web3.connect(host, active.get("timeout", 30))
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 52, in connect
uri = _expand_environment_vars(uri)
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 183, in expand_environment_vars
raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
rownie_cli_main
.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli\run.py", line 44, in main
network.connect(CONFIG.argv["network"])
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py", line 40, in connect
web3.connect(host, active.get("timeout", 30))
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 52, in connect
uri = _expand_environment_vars(uri)
File "..local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\web3.py", line 183, in _expand_environment_vars
raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
ValueError: Unable to expand environment variable in host setting: 'https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID'
PS C:\Users\Ash> brownie --version
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

Gas estimation failed: If you wish to broadcast, you must set the gas limit manually.

Hi there,

First of all, thank you for the template!

I was running into an error executing run_flash_loan_v2.py after successfully deploying the contract on Kovan (see message below).

The error message asks to set the gas limit manually - I did this in the brownie-config.yaml using gas_limit: 100000000000 but the error persists.

Any ideas how to resolve this?

Many thanks

Running 'scripts/run_flash_loan_v2.py::main'...
Getting Flashloan contract...
Executing Flashloan...
File "brownie/_cli/run.py", line 49, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, 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 1323, in call
return fn(*args) # type: ignore
File "brownie/network/contract.py", line 1676, in call
return self.transact(*args)
File "brownie/network/contract.py", line 1550, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 600, in transfer
gas_limit = Wei(gas_limit) or self._gas_limit(to, amount, gas_price, gas_buffer, data)
File "brownie/network/account.py", line 367, in _gas_limit
gas_limit = self.estimate_gas(to, amount, gas_price, data or "")
File "brownie/network/account.py", line 560, in estimate_gas
raise ValueError(
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.

issue with FlashLoan.deploy()

const FlashLoan = await hre.ethers.getContractFactory("FlashLoan");

const flashLoan = await FlashLoan.deploy("0x012bAC54348C0E635dCAc9D5FB99f06F24136C9A");

Flash Loan is not deployed. Address is POOLADDRESSPROVIDER AAVE-V3 for Sepolia Testnet.

Unable to expand environment variable in host setting: 'https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID'

On executing brownie run scripts/get_weth.py --network kovan the below error occurs:

"INFO: Could not find files for the given pattern(s).
Brownie v1.14.6 - Python development framework for Ethereum

AaveFlashloanMixProject is the active project.
File "c:\users\ajith\appdata\local\programs\python\python39\lib\site-packages\brownie_cli_main_.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "c:\users\ajith\appdata\local\programs\python\python39\lib\site-packages\brownie_cli\run.py", line 43, in main
network.connect(CONFIG.argv["network"])
File "c:\users\ajith\appdata\local\programs\python\python39\lib\site-packages\brownie\network\main.py", line 40, in connect
web3.connect(host, active.get("timeout", 30))
File "c:\users\ajith\appdata\local\programs\python\python39\lib\site-packages\brownie\network\web3.py", line 52, in connect
uri = _expand_environment_vars(uri)
File "c:\users\ajith\appdata\local\programs\python\python39\lib\site-packages\brownie\network\web3.py", line 183, in _expand_environment_vars
raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
ValueError: Unable to expand environment variable in host setting: 'https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID'"

New Brownie Mix for Gitlab

I have a working implementation of brownie/ganache/docker for use with Gitlab's CI/CD that I think would make a great Mix.

I'm fully aware that this is definitely the wrong place for this question, but I couldn't see anywhere in the Github organization on how to contribute a new Mix. @iamdefinitelyahuman if this is something you think would be beneficial, could you reach out with how to get it added? thank you!

VirtualMachineError: revert

I tried running brownie run scripts/deployment_v2.py

But got this error

Running 'scripts/deployment_v2.py::main'...
Transaction sent: 0x0737917f12b9853ad747ba7c649107b4d019ea0725d4f0160de68eb54268d959
  Gas price: 0.0 gwei   Gas limit: 6721975   Nonce: 5
  FlashloanV2.constructor confirmed (reverted) - Block: 11   Gas used: 122628 (1.82%)

  File "brownie/_cli/run.py", line 49, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/deployment_v2.py", line 17, in main
    flashloan = FlashloanV2.deploy(
  File "brownie/network/contract.py", line 593, in __call__
    return tx["from"].deploy(
  File "brownie/network/account.py", line 505, in deploy
    receipt._raise_if_reverted(exc)
  File "brownie/network/transaction.py", line 393, in _raise_if_reverted
    raise exc._with_attr(
VirtualMachineError: revert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.