Build a Uniswap V3 Price Oracle in JavaScript | Calc TWAP (time weighted average price) for Tokens

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024
  • Get my free EthersJS cheatsheet to master Web3!
    👉 blockman-codes...
    ------------------------------------------
    Courses:
    👉 Build a Uniswap V3 interface that can do swaps: bit.ly/3JkXYqL
    ------------------------------------------
    Let's build a Uniswap V3 Price Oracle in JavaScript, to calculate the TWAP (time weighted average price) for a token and time window.
    A Uniswap price oracle allows using Uniswap prices for logic in your own code and smart contracts.
    Unfortunately, it's only possible to do this out-of-the-box for Solidity, not JavaScript.
    So we'll walk line-by-line through the Uniswap OracleLibrary written in Solidity, and convert it to JavaScript.
    -----------------
    Package.json and imports code:
    gist.github.co...

Комментарии • 32

  • @blockmancodes
    @blockmancodes  Год назад

    Learn to use all of Uniswap's swap and liquidity functionality with code. bit.ly/3JkXYqL

  • @maakayp
    @maakayp 2 года назад

    All your Videos are Gold, am still learning and i believe i will get there

    • @blockmancodes
      @blockmancodes  2 года назад

      Thank you! Keep at it and you will!

    • @DevMode951
      @DevMode951 Год назад

      ​@@blockmancodes 😅😅😮😮😮😮

  • @СТАКАН-о5х
    @СТАКАН-о5х Год назад

    Hi! I have error with multiply function:
    Cannot read properties of undefined (reading 'multiply')
    Somebody can to help me?

  • @blockmancodes
    @blockmancodes  2 года назад +1

    What other Uniswap tutorials would you like to see?

    • @opeyemioginni6601
      @opeyemioginni6601 2 года назад

      Can you do a Code that compares the prices of tokens from 2 exchanges. Kinda like a stepping stone to creating an arbitrage bot

    • @sverma333
      @sverma333 2 года назад

      How do you know the quantities of each token you would receive if you were to withdraw X lp from an uniswap pool ?

    • @JohnDoe-wi6nq
      @JohnDoe-wi6nq 2 года назад

      Can you please do one on Aave?

    • @blockmancodes
      @blockmancodes  2 года назад +1

      @@opeyemioginni6601 For sure. Do you have another exchange in mind?

    • @blockmancodes
      @blockmancodes  2 года назад +1

      @@sverma333 Good question. I will cover this in an upcoming liquidity video

  • @purevdorjganbat928
    @purevdorjganbat928 2 года назад

    Is it reliable ? should i use Pricee feed of Chainlink

  • @veliea5160
    @veliea5160 Год назад

    Hi! Are swap price and twap price same? price oracles used for price but how is it so fast that when we execute swap on uniswap platform it executes very quick?

    • @blockmancodes
      @blockmancodes  Год назад

      The TWAP is an average of the current swap price and past swap prices. For when you want to use Uniswap to imply a "current market price".
      When you trade on Uniswap, that's not TWAP, that's just the swap price.
      Transactions execute whenever the next block is added, which is frequent on Ethereum - that's why it's so fast.

  • @t9fiction
    @t9fiction 2 года назад

    loving it. u r awesome

  • @naveenjp
    @naveenjp 2 года назад

    awesome content man.. noticed an issue though.. if my baseToken is WBTC and quoteToken is WETH the "else" block of the quoteAmount is executed and the answer doesn't come out right. I can workaround though by making WETH my baseToken.

    • @blockmancodes
      @blockmancodes  2 года назад +1

      Thanks for letting me know brother

    • @naveenjp
      @naveenjp 2 года назад

      @@blockmancodes do you have any pointers on how to get the ratio of tokens in a position that you have created? I tried using the route api but am facing issues.

    • @blockmancodes
      @blockmancodes  2 года назад

      @@naveenjp So you want to know like how much "ETH vs UNI" in an existing position?

  • @asdomain4503
    @asdomain4503 Год назад

    Hey, can anyone tell me how do you get the pool address?

    • @blockmancodes
      @blockmancodes  Год назад +1

      Just posted a video on this

    • @asdomain4503
      @asdomain4503 Год назад

      @@blockmancodes that's great! Thank you so much ✌️

  • @mocholabs4656
    @mocholabs4656 2 года назад

    The code isnt updated, seems to be missing some code.

    • @mocholabs4656
      @mocholabs4656 2 года назад

      Also your use of "quoteToken" is leading to a TypeError: Assignment to constant variable.

    • @blockmancodes
      @blockmancodes  2 года назад

      @@mocholabs4656 I updated the gist code.

  • @TheBHUPAT
    @TheBHUPAT Год назад

    Hey!
    Do you know how we can get the current value of each token added in liquidity v3?

    • @blockmancodes
      @blockmancodes  Год назад +1

      Everything in Uniswap is priced in pairs. So "current value" is subjective. Can you give me a token example of what you want?