Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 2.94 KB

File metadata and controls

58 lines (41 loc) · 2.94 KB

AAVE-Uniswap

项目介绍

a simple contract that lets you create and unwind leveraged positions on Aave 👻 by integrating with Uniswap 🦄, plus some testing courtesy of Hardhat👷. The Aave Ape combines two Defi protocols, Aave (for lending) and Uniswap (for swapping).

AAVE Interacting with Aave starts with the Lending Pool Addresses Provider — this is the source of truth for Aave V2’s latest contract addresses:

  • LendingPool: where the depositing & borrowing happens 🏦
  • ProtocolDataProvider: provides easy-to-access information about reserves & users 📊
  • PriceOracle: provides secure price feeds 💱

uniswapv2 Interacting with Uniswap V2 all happens through the Uniswap Router02.

key point

We can create a constructor that lets us set the two addresses we need (the AddressesProvider and the Router). Once we then have the addresses and the interfaces, we can create helper functions to instantiate contracts so that we can interact with them, and fetch Aave reserve data from the ProtocolDataProvider.

Assuming you have an apeAsset you want to go long and a borrowAsset you want to go short this ape function lets a user carry out the following steps in one transaction

  • Calculate the maximum amount the user is able to borrow in the borrowAsset, based on their collateral (this relies on getAvailableBorrowInAsset)
  • Borrow that amount of borrowAsset from Aave V2 on behalf of the user

This requires the user to have delegated credit to the Aave Ape contract, so that it can borrow from Aave on the user’s behalf — see more about Credit Delegation

  • Approve the borrowAsset for trading on Uniswap
  • Swap the borrowAsset for the maximum available amount of the apeAsset via Uniswap V2
  • Deposit the apeAsset back into Aave on behalf of the user

unwindApe Borrow the amount needed to repay their borrowAsset debt via a flashloan from Aave V2.

operating steps

hardhat run --network kovan scripts/deploy.js

参考链接