Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdraw from aave with brownie #50

Open
tulLazy opened this issue Sep 17, 2022 · 1 comment
Open

Withdraw from aave with brownie #50

tulLazy opened this issue Sep 17, 2022 · 1 comment

Comments

@tulLazy
Copy link

tulLazy commented Sep 17, 2022

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

@QingyangKong
Copy link

Hi @tulLazy , it seems the problem is nothing with Chainlink. Would you like to create an issue in Aave repository where developers may be more familiar with the withdraw function in Aave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants