Git Product home page Git Product logo

bread-project's Introduction

๐Ÿ— scaffold-eth: Aave & the Ape

This branch demonstrates several ways to integrate Aave with scaffold-eth...

Lend is a simple React component, leveraging the Aave subgraph for market data, a custom useAaveData react hook to fetch user data, and aave-js to prepare transactions. Read more here!

The Aave Ape is a helper contract that lets you go long ("ape") the Aave asset of your choice, borrowing a "short" asset on Aave to buy more of the "ape" asset. It also lets you unwind your position with an Aave flashloan. We walk through the mechanics, testing and the simple Ape frontend in this post.

๐Ÿšจ This is experimental code written for educational & learning purposes only, use at your own risk! ๐Ÿšจ


Quickstart

git clone -b aave-ape https://github.com/austintgriffith/scaffold-eth.git aave-ape

cd aave-ape
yarn install

Local development

yarn start

In a second terminal window run:

yarn fork

This branch uses a local fork of mainnet, which is easy to do with Hardhat (see here to learn more). The template configuration uses an Infura node, however this is not a full archive node, so it will only work for an hour or so. To get a long-lasting fork...

  • Go to alchemyapi.io and get an API key for mainnet
  • Replace the Infura URL with an Alchemy URL with your API key (i.e. https://eth-mainnet.alchemyapi.io/v2/<API_KEY_HERE>) into the fork script on line 28 of /packages/hardhat/package.json

In a third terminal window run:

yarn test
yarn deploy

This tests then deploys the Aave Ape contract

๐Ÿ“ฑ Open http://localhost:3000 to see the app!

Running on Kovan

To run the frontend on Kovan, add the following to your .env file in packages/react-app/

REACT_APP_PROVIDER=https://kovan.infura.io/v3/486dde46d655482e8caa00620e447799
REACT_APP_NETWORK=kovan

To use the already-deployed Aave Ape contract, unzip the kovan-contracts.zip folder To deploy your own...

yarn generate
yarn account

Send your newly generated account some Kovan ETH, then run...

yarn workspace @scaffold-eth/hardhat hardhat --network kovan run scripts/deploy.js
yarn workspace @scaffold-eth/hardhat hardhat run scripts/publish.js

Running on Mainnet

To run the frontend on mainnet, add the following to your .env file in packages/react-app/

REACT_APP_PROVIDER=https://mainnet.infura.io/v3/486dde46d655482e8caa00620e447799
REACT_APP_NETWORK=mainnet

The Ape is not currently deployed on Mainnet

The components

๐ŸŽถ Quick note! The mainnet fork can take a little while to get going - you may need to refresh several times before everything is cached and the app is fast and loading ๐Ÿ’จ๐Ÿ’จ๐Ÿ’จ

Lend

This component is a lightweight take on the Aave V2 market. You can view your overall position, key market stats, and your detailed asset position, viewing in native / ETH / USD. You can also make the key Aave transactions (deposit, withdraw, borrow, repay).

Data is fetched via a custom useAaveData() hook. Data is sourced from Aave subgraphs for market data, and on-chain for user data (to enable local development)

Ape

This is an experimental contract as part of this branch. The Aave Ape smart contract lets you increase your leverage, based on collateral deposited in Aave. The component walks you through the stages, but...

  1. Select the token you want to go Long
  2. Select the token you want to Short
  3. Delegate credit to the AaveApe contract
  4. Call the ape() function, or the superApe() function to leverage up multiple times in one transaction. This function uses your collateral to borrow the Short asset, swaps that for the Long asset, then deposits that back into Aave.
  5. You can unwind your position by calling the unwindApe() function (you need to give the AaveApe contract an allowance on your aToken first, so it can withdraw it). Unwinding creates a flash loan to repay your owed amount in the Short token, then withdraws your Long token collateral, swaps it for the right amount of Short token, repays the flash loan and deposits any left-over collateral back into Aave

Other components

Swap

This is a minimum viable Uniswap UI (see more detail here), using token-lists. All you need to instantiate this is a provider with a signer (userProvider in scaffold-eth works fine!)

  • You can update the token-list for the Swap component in the "Hints" tab
  • Kudos to @ironsoul for the fresh Debounce hook

SnatchToken

One of the benefits of using a mainnet fork is that you can impersonate Ethereum accounts you don't own, which is great for getting your hands on tokens! Building on top of an initial component by @ironsoul, this lets you specify the target, the token you are after and the amount you would like.

  • Your target will need enough of the token, as well as some ETH to pay for the gas fee.
  • The list of tokens comes from the 1inch tokenlist

Approver

A minimal component for Approving specific accounts to spend your ERC20s, with mainnet tokens selectable from a tokenlist, plus an option to manually enter the ERC20 of your choice.

bread-project's People

Contributors

svdorn avatar

Stargazers

Shih-Yu Hwang avatar Jack Burrus avatar Parrot avatar

Watchers

James Cloos avatar Nima Cheraghi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.