PatrickAlphaC / aave_web3_py

web3.py way to interact with aave

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Python + Aave Python + Aave


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:

  1. Approve our ETH to be swapped for WETH
  2. Swap an amount of ETH for WETH
  3. Using deposit_to_aave we deposit the WETH as collateral
  4. We use that collateral to borrow LINK with borrow_erc20
  5. Then, we pay it back!
  6. 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 Address
  • PRIVATE_KEY: Your Private Key from your Wallet
  • KOVAN_RPC_URL: Your Kovan connection to the blockchain. You can get a URL from a service like Infura or ]Alchemy. An example would be https://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

  1. Get some kovan ETH

  2. Get some WETH

python get_weth.py
  1. 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.

  1. Get some WETH
python get_weth.py
  1. Run the script!
python aave_borrow_web3.py

About

web3.py way to interact with aave

License:MIT License


Languages

Language:Python 99.6%Language:Shell 0.4%