Awesome
<br/> <p align="center"> <a href="https://chain.link" target="_blank"> <img src="https://raw.githubusercontent.com/PatrickAlphaC/aave_web3_py/main/img/aave.png" width="225" alt="Python + Aave"> <img src="https://raw.githubusercontent.com/PatrickAlphaC/aave_web3_py/main/img/python.png" width="225" alt="Python + Aave"> </a> </p> <br/>aave_web3_py
Put down collateral, Borrow, and repay a loan from Aave! Use this to short assets and accrue interest.
You can see a brownie version of this here.
In our aave_borrow_web3.py
script, we do the following:
- Approve our
ETH
to be swapped forWETH
- Swap an
amount
ofETH
forWETH
- Using
deposit_to_aave
we deposit theWETH
as collateral - We use that collateral to borrow
LINK
withborrow_erc20
- Then, we pay it back!
- We can view the txs on etherscan to see what's going on under the hood.
Setup
You'll need python installed.
pip install -r requirements.txt
You'll need the following environment variables. You can set them all in your .env
file:
export MY_ADDRESS=<YOUR_WALLET_ADDRESS>
export PRIVATE_KEY=<YOUR_PRIVATE_KEY> # Remember to start it with "0x"
export KOVAN_RPC_URL='URL'
# Optional... But can be very helpful
export MAINNET_RPC_URL='URL'
MY_ADDRESS
: Your Wallet AddressPRIVATE_KEY
: Your Private Key from your WalletKOVAN_RPC_URL
: Your Kovan connection to the blockchain. You can get a URL from a service like Infura or ]Alchemy. An example would behttps://kovan.infura.io/v3/fffffffffffffffffffff
MAINNET_RPC_URL
: Same as above, but for mainnet.
And last, be sure to check the aave_link_token if you're using a testnet LINK token. Aave sometimes changes the token they use on testnet to keep liquidity. Also, feel free to check the Aave docs as well, to learn more about the tools we are using.
Quickstart - kovan
-
Get some WETH
python get_weth.py
- Run the script!
python aave_borrow_web3.py
Quickstart - mainnet-fork
Optional for running locally:
If you want to run locally, you can install ganache-cli
and yarn
. Here is where you can install yarn.
yarn global add ganache-cli
Then, you can run ganache-cli --fork $MAINNET_RPC_URL
and set the active
network in the config.yaml
to mainnet-fork
.
You'll need to set your private key to a private key from your forked mainnet.
- Get some WETH
python get_weth.py
- Run the script!
python aave_borrow_web3.py