Coder Social home page Coder Social logo

de-fi-aave's Introduction

  1. Deposit collateral: ETH/WETH ✅
  2. Borrow another asset: DAI ✅
  3. Repay the DAI ✅

// FORKING // TradeOffs

Pros: Quick,easy,resemble what's on mainnet Cons: We need an API, some contracts are complex to work with

Process:

Depositing

getWeth:

  • First we have to get weth from the getWeth contract
  • we used the mainnet contract address 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • In this process we used forking techinque.
  • In forking we can interact with same blockchain.
  • After we got weth in our wallet

Lending pool

  • we have to get the address of lending pool
  • we deposit the weth in lending pool

Lending pool address provider

  • there are multiple lending pool
  • so we have to get the address of the lending pool in order to depoist our WETH
  • we use the lendingPoolAddressProvider interface to get the address of lendingPool.

lending pool

async function getLendingPool(account)

  • Now that we have the address of the lending pool
  • we can get the access using the address of lending pool.
  • Now we can deposit but but but before depositing we need to give access aave to get WETH from wallet.
  • We need to approve IERC20 so that it can access wallet

IERC20

async function approveErc20(erc20Address, spenderAddress, amountToSpend, account)

  • With the help of function of IERC20 contract.
  • We can approve for the access of our wallet.

Depositing

await lendingPool.deposit(address asset,uint256 amount,address onBehalfOf,uint16 referralCode)

  • using above line we can deposit we in the leding pool.

Borrowing

getBorrowUserData

  • Before borrowing we need to know about
    • how much we can borrow
    • how much we have in collatoral
    • how much we have borrowed
  • liquidation concept
    • we you have 1ETH collatoral and borrowed 1.8ETH then you will get liquidated
    • Liquidation Threshold: The liquidation threshold is the percentrage at which a person is defined as undercollateralised. For example, a Liquidation threshold of 80% means that if the value rises above 80% of the collateral, the position is undercollateralised and could be liquidated.
    • if you have borrowed money more than you put up then people can take your collateral because they are paying for your loans.

GetDaiPrice

  • Now we have info about how much can buy and how much debt we have
  • before borrowing the DAI we need the conversion rate of ETH-DAI.
  • for this we are going to use chainlink priceFeeds.

BorrwoDai

  • Now that we know the exchange price of DAI/ETH
  • we can borrow the DAI

Explanining how all the transactions work

  • when we deposit our collatoral we actually get back an A token or an interset paring token
  • It tracks how much collatoral or in our case how much WETH token we have deposited in the aave protocol.
  • When we want to withdraw our WETH token we burn these A tokens.
  1. First I have deposited WETH in my wallet.
  2. In order to deposit in aave, I have fetched the address of lending pool
  3. Deposited WETH token into lending pool
  4. Then borrowed DAI with my deposited WETH as a collatoral.
  5. After repayment of the DAI back to the aave/lending pool there is still some DAI left as borrowed
  6. That lefted DAI is the intereset on the borrowed DAI. -------------------- COMPLETE WHOLE PROCESS -------------------------

de-fi-aave's People

Contributors

yoharsh14 avatar

Watchers

 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.