Lesson 10: Gas estimation failed ERROR #767
-
Hey there, Keep getting the following error when trying to deploy on the Kovan network. When testing on local Ganache everything works great. I wondered if it was a Eth balance issue so I got more than enough Kovan Eth from the faucet. Still getting the error and I've even gone as far as copying and pasting the code from the Github repository. Here's my aave_borrow.py script: from brownie import network, config, interface
from scripts.helpful_scripts import get_account
from scripts.get_weth import get_weth
from web3 import Web3
# 0.1
AMOUNT = Web3.toWei(0.1, "ether")
def main():
account = get_account()
erc20_address = config["networks"][network.show_active()]["weth_token"]
if network.show_active() in ["mainnet-fork"]:
get_weth()
lending_pool = get_lending_pool()
approve_tx = approve_erc20(AMOUNT, lending_pool.address, erc20_address, account)
print("Depositing...")
tx = lending_pool.deposit(
erc20_address, AMOUNT, account.address, 0, {"from": account}
)
tx.wait(1)
print("Deposited!")
# ...how much?
borrowable_eth, total_debt = get_borrowable_data(lending_pool, account)
print("Let's borrow!")
# DAI in terms of ETH
dai_eth_price = get_asset_price(
config["networks"][network.show_active()]["dai_eth_price_feed"]
)
amount_dai_to_borrow = (1 / dai_eth_price) * (borrowable_eth * 0.95)
# borrowable_eth -> borrowable_dai * 95%\
print(f"We are going to borrow {amount_dai_to_borrow} DAI")
# Now we will borrow!
dai_address = config["networks"][network.show_active()]["dai_token"]
borrow_tx = lending_pool.borrow(
dai_address,
Web3.toWei(amount_dai_to_borrow, "ether"),
1,
0,
account.address,
{"from": account},
)
borrow_tx.wait(1)
print("We borrowed some DAI!")
get_borrowable_data(lending_pool, account)
repay_all(AMOUNT, lending_pool, account)
print(
"You just deposited, borrowed, and repayed with Aave, Brownie, and Chainlink!"
)
def repay_all(amount, lending_pool, account):
approve_erc20(
Web3.toWei(amount, "ether"),
lending_pool,
config["networks"][network.show_active()]["dai_token"],
account,
)
repay_tx = lending_pool.repay(
config["networks"][network.show_active()]["dai_token"],
amount,
1,
account.address,
{"from": account},
)
repay_tx.wait(1)
print("Repaid!")
def get_asset_price(price_feed_address):
dai_eth_price_feed = interface.AggregatorV3Interface(price_feed_address)
latest_price = dai_eth_price_feed.latestRoundData()[1]
converted_latest_price = Web3.fromWei(latest_price, "ether")
print(f"The DAI/ETH price is {converted_latest_price}")
return float(converted_latest_price)
def get_borrowable_data(lending_pool, account):
(
total_collateral_eth,
total_debt_eth,
available_borrow_eth,
current_liquidation_threshold,
ltv,
health_factor,
) = lending_pool.getUserAccountData(account.address)
available_borrow_eth = Web3.fromWei(available_borrow_eth, "ether")
total_collateral_eth = Web3.fromWei(total_collateral_eth, "ether")
total_debt_eth = Web3.fromWei(total_debt_eth, "ether")
print(f"You have {total_collateral_eth} worth of ETH deposited.")
print(f"You have {total_debt_eth} worth of ETH borrowed.")
print(f"You can borrow {available_borrow_eth} worth of ETH.")
return (float(available_borrow_eth), float(total_debt_eth))
def approve_erc20(amount, spender, erc20_address, account):
print("Approving ERC20 token...")
erc20 = interface.IERC20(erc20_address)
tx = erc20.approve(spender, amount, {"from": account})
tx.wait(1)
print("Approved!")
return tx
def get_lending_pool():
lending_pool_addresses_provider = interface.ILendingPoolAddressesProvider(
config["networks"][network.show_active()]["lending_pool_addresses_provider"]
)
lending_pool_address = lending_pool_addresses_provider.getLendingPool()
lending_pool = interface.ILendingPool(lending_pool_address)
return lending_pool |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello @jacobbins I tried to reproduce the error with not luck as is runs ok on my side, however the error catch my attention when saying is reverting because is getting None. This could be due to your account.
wallets:
from_key: ${PRIVATE_KEY}
|
Beta Was this translation helpful? Give feedback.
-
Hi Guys, The code looks fine, I copied it from the repo... Hopefully we'll figure it out together. |
Beta Was this translation helpful? Give feedback.
Hello @jacobbins I tried to reproduce the error with not luck as is runs ok on my side, however the error catch my attention when saying is reverting because is getting None. This could be due to your account.
brownie-config.yaml
using:.env