Description
So i wanted to try to withdraw the assets that i landed on aave. Ichecked the aave v2 documentetation and it told me to use the withdraw function, i used it as it told me to and everytime this error pops up:
VirtualMachineError: revert: 6
Can someone help me?
P.S. The rest of the code works fine it's the withdrawing that is giving me problems
from brownie import network, config, interface
from scripts.helpful_scripts import get_account
from scripts.get_weth import get_weth
from web3 import Web3
amount = Web3.toWei(0.1, "ether")
def main():
account = get_account()
erc20_token_address = config["networks"][network.show_active()]["weth_token"]
if network.show_active() in ["mainnet-fork"]:
get_weth()
# ABI
# Address
lending_pool = get_lending_pool()
# Approve sending our ERC20 tokens
approve_erc20(amount, lending_pool.address, erc20_token_address, account)
print("Depositing in aave....")
tx_deposit = lending_pool.deposit(
erc20_token_address, amount, account.address, 0, {"from": account}
)
tx_deposit.wait(1)
print("Deposited!")
# ... how much can we borrow?
borrowable_eth, total_debt = get_borrowable_data(lending_pool, account)
print("Let's borrow!")
# DAI in terms of ETH
dai_to_eht_price = get_asset_price(
config["networks"][network.show_active()]["dai_eth_price_feed"]
)
amount_dai_to_borrow = (1 / dai_to_eht_price) * (borrowable_eth * 0.95)
# borrowable eth to -> 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("You borrowed some DAI!")
get_borrowable_data(lending_pool, account)
print("Repaying DAI borrowed...")
repay_all(Web3.toWei(amount_dai_to_borrow, "ether"), lending_pool, account)
get_borrowable_data(lending_pool, account)
print("Withdrawing lended assets...")
withdraw(erc20_token_address, amount, account, lending_pool)
get_borrowable_data(lending_pool, account)
print("You just deposited, borrowed and repayed with aave, brownie, and chianlink ")
def withdraw(erc20_token_address, amount, account, lending_pool):
approve_erc20(amount, lending_pool.address, erc20_token_address, account)
withdraw_tx = lending_pool.withdraw(
erc20_token_address, amount, account.address, {"from": account}
)
withdraw_tx.wait(1)
print("Withdrawed!")
return withdraw_tx