Comments (11)
Hi,
FlashloanV2 is Withdrawable hence you can use the function withdraw.
Something like the below would withdraw all the weth you have in your flashloan for instance.
from aave-flashloan-mix.
Thank you @ch1ch0gz for your solution, at least this is a step forward.
Even though, when I run it, I get an error. Here is the response after running "brownie run scripts/withdraw_function.py --network kovan":
`Brownie v1.17.2 - Python development framework for Ethereum
AaveFlashloanMixFunzionaYesmodificareCopyProject is the active project.
Running 'scripts/withdraw_function.py::main'...
Getting flashloan contract...
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/_cli/run.py", line 51, in main
return_value, frame = run(
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/withdraw_function.py", line 14, in main
tx = flashloan.Withdraw(weth, {"from": acct})
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/network/contract.py", line 763, in getattribute
raise AttributeError(f"Contract '{self._name}' object has no attribute '{name}'")
AttributeError: Contract 'FlashloanV2' object has no attribute 'Withdraw'`
Can you tell me what am I missing?
from aave-flashloan-mix.
Has your flashLoan contract got "contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable " withdrawable inherit?
from aave-flashloan-mix.
I think you are right, I do not have that line in any file, and I expecially paid attention at contract.py, and I do not have that line.
Can you provide the whole function, so I can add it there and see how it turns out to work?
from aave-flashloan-mix.
i think you are missing adding the import Withdrawable on FlashLoanReceiverBaseV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
import { SafeMath } from '@openzeppelin/contracts/math/SafeMath.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { SafeERC20 } from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import { IFlashLoanReceiverV2 } from './../../../interfaces/v2/IFlashLoanReceiverV2.sol';
import { ILendingPoolAddressesProviderV2 } from './../../../interfaces/v2/ILendingPoolAddressesProviderV2.sol';
import { ILendingPoolV2 } from './../../../interfaces/v2/ILendingPoolV2.sol';
import "../../utils/Withdrawable.sol";
/**
!!!
Never keep funds permanently on your FlashLoanReceiverBase contract as they could be
exposed to a 'griefing' attack, where the stored funds are used by an attacker.
!!!
*/
abstract contract FlashLoanReceiverBaseV2 is IFlashLoanReceiverV2 {
using SafeERC20 for IERC20;
using SafeMath for uint256;
ILendingPoolAddressesProviderV2 public immutable override ADDRESSES_PROVIDER;
ILendingPoolV2 public immutable override LENDING_POOL;
constructor(address provider) public {
ADDRESSES_PROVIDER = ILendingPoolAddressesProviderV2(provider);
LENDING_POOL = ILendingPoolV2(ILendingPoolAddressesProviderV2(provider).getLendingPool());
}
receive() payable external {}
}
And the Withdrawable.sol looks like
pragma solidity ^0.6.6;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
Ensures that any contract that inherits from this contract is able to
withdraw funds that are accidentally received or stuck.
*/
contract Withdrawable is Ownable {
using SafeERC20 for ERC20;
address constant ETHER = address(0);
event LogWithdraw(
address indexed _from,
address indexed _assetAddress,
uint amount
);
/**
* @dev Withdraw asset.
* @param _assetAddress Asset to be withdrawn.
*/
function withdraw(address _assetAddress) public onlyOwner {
uint assetBalance;
if (_assetAddress == ETHER) {
address self = address(this); // workaround for a possible solidity bug
assetBalance = self.balance;
msg.sender.transfer(assetBalance);
} else {
assetBalance = ERC20(_assetAddress).balanceOf(address(this));
ERC20(_assetAddress).safeTransfer(msg.sender, assetBalance);
}
emit LogWithdraw(msg.sender, _assetAddress, assetBalance);
}
}
from aave-flashloan-mix.
Has your flashLoan contract got "contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable " withdrawable inherit?
Here I was talking about Flashloan.sol which is another file you need to modify.
from aave-flashloan-mix.
@ch1ch0gz your advices here are outstanding. Me and probably all the people reading this thread owe you a big thank you.
Please check your email, I sent you something via GitHub :) .
Now, I was messing around with the code, I did not solve this mystery, but I have some error logs I want you to take a look at.
- First, I compared Withdrawable.sol and FlashLoanReceiverBaseV2.sol with the code you provided, and I can confirm I have the exact same code.
- Based on your response of March 16 2022, I created the file "withdraw_function.py" which has the following code:
---Code Begins---
from brownie import FlashloanV2, accounts, config, network, interface
def main():
"""
Withdraw Tokens from flashloanW
"""
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"])
tx = flashloan.Withdraw(weth, {"from": acct})
return flashloan
---Code Ends---
- I do not see a file Flashloan.sol, but I have FlashloanV2.sol, I guess this is the file you are referring to, right?
In my file I have the line "contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable" exactly as wrote by @PatrickAlphaC in https://github.com/brownie-mix/aave-flashloan-mix/blob/master/contracts/v2/FlashloanV2.sol
If I run "brownie run scripts/withdraw_function.py --network kovan" having the line "contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable" in FlashloanV2.sol I get:
---Code Begins---
Brownie v1.17.2 - Python development framework for Ethereum
Compiling contracts...
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
Generating build data...
- OpenZeppelin/[email protected]/Context
- OpenZeppelin/[email protected]/Ownable
- OpenZeppelin/[email protected]/SafeMath
- OpenZeppelin/[email protected]/ERC20
- OpenZeppelin/[email protected]/IERC20
- OpenZeppelin/[email protected]/SafeERC20
- OpenZeppelin/[email protected]/Address
- Withdrawable
- FlashloanV2
- FlashLoanReceiverBaseV2
- IFlashLoanReceiverV2
- ILendingPoolAddressesProviderV2
- ILendingPoolV2
- DataTypes
AaveFlashloanMixFunzionaYesmodificareCopyProject is the active project.
Running 'scripts/withdraw_function.py::main'...
Getting flashloan contract...
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/_cli/run.py", line 51, in main
return_value, frame = run(
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/withdraw_function.py", line 12, in main
flashloan = FlashloanV2[len(FlashloanV2) - 1]
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/network/contract.py", line 174, in getitem
return self._contracts[i]
IndexError: list index out of range
---Code Ends---
Now, if I run "brownie run scripts/withdraw_function.py --network kovan" having the line you suggested "contract FlashloanV2_aave is FlashLoanReceiverBaseV2, Withdrawable" in FlashloanV2.sol I get:
---Code Begins---
Brownie v1.17.2 - Python development framework for Ethereum
Compiling contracts...
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
Generating build data...
- OpenZeppelin/[email protected]/Context
- OpenZeppelin/[email protected]/Ownable
- OpenZeppelin/[email protected]/SafeMath
- OpenZeppelin/[email protected]/ERC20
- OpenZeppelin/[email protected]/IERC20
- OpenZeppelin/[email protected]/SafeERC20
- OpenZeppelin/[email protected]/Address
- Withdrawable
- FlashloanV2_aave
- FlashLoanReceiverBaseV2
- IFlashLoanReceiverV2
- ILendingPoolAddressesProviderV2
- ILendingPoolV2
- DataTypes
AaveFlashloanMixFunzionaYesmodificareCopyProject is the active project.
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/_cli/run.py", line 51, in main
return_value, frame = run(
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/project/scripts.py", line 53, in run
module = _import_from_path(script)
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/project/scripts.py", line 149, in _import_from_path
_import_cache[import_str] = importlib.import_module(import_str)
File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "./scripts/withdraw_function.py", line 1, in
from brownie import FlashloanV2, accounts, config, network, interface
ImportError: cannot import name 'FlashloanV2' from 'brownie' (/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/init.py)
---Code Ends---
Said all that, still the withdrawal from the smart contract to the wallet does not get execute successfully. Suggestions?
from aave-flashloan-mix.
Can you quickly try having
in your FlashloanV2.sol contract instead of
Flashloan_aave is a different flashloan I am playing with.
from aave-flashloan-mix.
The response is get is :
Brownie v1.17.2 - Python development framework for Ethereum
Compiling contracts...
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
Generating build data...
OpenZeppelin/[email protected]/Context
OpenZeppelin/[email protected]/Ownable
OpenZeppelin/[email protected]/SafeMath
OpenZeppelin/[email protected]/ERC20
OpenZeppelin/[email protected]/IERC20
OpenZeppelin/[email protected]/SafeERC20
OpenZeppelin/[email protected]/Address
Withdrawable
FlashloanV2
FlashLoanReceiverBaseV2
IFlashLoanReceiverV2
ILendingPoolAddressesProviderV2
ILendingPoolV2
DataTypes
Running 'scripts/withdraw_function.py::main'...
Getting flashloan contract...
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/_cli/run.py", line 51, in main
return_value, frame = run(
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/withdraw_function.py", line 12, in main
flashloan = FlashloanV2[len(FlashloanV2) - 1]
File "/usr/local/lib/python3.9/dist-packages/eth_brownie-1.17.2-py3.9.egg/brownie/network/contract.py", line 174, in getitem
return self._contracts[i]
IndexError: list index out of range
from aave-flashloan-mix.
@ch1ch0gz thank you i solved it with your guide i want to send you an email to say thank you but i didn't find your email
from aave-flashloan-mix.
@ch1ch0gz Hello i just sent you a message on twitter, i just saw this and i'd need your assistance
from aave-flashloan-mix.
Related Issues (20)
- Unable to expand environment variable in host setting: 'https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID' HOT 3
- Gas estimation failed: If you wish to broadcast, you must set the gas limit manually. HOT 1
- 401 Client Error: Unauthorized for url: https://kovan
- VirtualMachineError: revert HOT 2
- [Quickstart Kovan] ValueError: Gas estimation failed: 'The execution failed due to an exception.' HOT 34
- Will this rune on Polygon with some modification HOT 1
- ConnectionError: Status 404 when retrieving repo brownie-mix/aave-flash information from GHAPI: 'Not Found' HOT 1
- Insufficient funds error message after running get_weth.py HOT 9
- Error when I run the get WETH command: brownie run scripts/get_weth.py --network kovan HOT 3
- Flash
- can't run brownie tests HOT 2
- New Brownie Mix for Gitlab
- flashloan.flashloan() got an unexpected argument 'block_identifier'
- Increasing the loan amount
- "ConnectionError" with "api-kovan.etherscan.io". Why? pls!
- private key must be exactly 32 bytes long
- Gas fees issue HOT 2
- aave v3 flash loan HOT 2
- It cannot be tested as the kovan network shutted down after the merge HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aave-flashloan-mix.