Get Price from Tick for Uniswap V3 Pool | JavaScript Coding Tutorial

Поделиться
HTML-код
  • Опубликовано: 23 окт 2022
  • Get my free EthersJS cheatsheet to master Web3!
    👉 blockman-codes.ck.page/91b29a...
    ------------------------------------------
    Courses:
    👉 Build a Uniswap V3 interface that can do swaps: bit.ly/3JkXYqL
    ------------------------------------------
    How do you get price from a tick for a Uniswap V3 pool.The current price of a swap in a Uniswap V3 pool is stored as a tick. Let's write code to do the math that converts an arbitrary tick value into the human readable swap price for 2 assets in a Uniswap V3 pool.
    ----------------
    Code:
    gist.github.com/BlockmanCodes...
  • НаукаНаука

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

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

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

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

    Thanks for the great video! It works well here!

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

    this worked for me too. Thank you so much. !!

  • @ikniz2005
    @ikniz2005 7 часов назад

    hi there. now the tick value is bigger, and the code does not suit that big tick value anymore

  • @folego
    @folego 5 месяцев назад

    Working here, but how I get the opposite? The second token vs the first one?

  • @almail207
    @almail207 3 месяца назад

    *uck uniswap and its x96, x192, squareRoots, ticks and all v3. God, how nice and simple v2 is!

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

    your videos are really interesting.
    Tell me something I need to take the price from uniswap of many contracts, I have the base contract and the quota contract, and the two decimals. how do I do without having the currentTick?
    help me thanks

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

      I don't understand 100%. Can you rephrase your question?

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

    Hi, what are the "provider" , 'basetoken' and 'quotetoken'' used for ?

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

      It was a copy/paste error. You don't need them

  • @prolingua
    @prolingua 6 месяцев назад +1

    In the code, I don't see the use of baseToken, quoteToken and provider.
    What are they for?

    • @J4KC
      @J4KC 3 месяца назад

      same doubt

  • @CodeWithJoe
    @CodeWithJoe Год назад +4

    do you have a discord or telegram or any way to contact yu?

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

    how can i make this work with a input token which is different from the paired token.
    i wanna quote when buying with eth but the token is paired with usdc

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

      It sounds like you want the price denominated in ETH?
      You could just use the token/ETH pool, or take the cost in USD and convert it to the equivilent amount of ETH

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

      @@blockmancodes found the quoting contract and figured out how to route the quoting.

  • @user-hg7rm4vq2i
    @user-hg7rm4vq2i Год назад

    I want to get the liquidity volume of the current price? What should I do?

  • @ducnguyen6581
    @ducnguyen6581 10 месяцев назад

    How do you get currentTick programmatically?

    • @blockmancodes
      @blockmancodes  10 месяцев назад

      Call "slot0" function on pool contract. It's inside, along with other data

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

    Hi thank you for videos, they definitely best one in this topic. Sorry for maybe incredibly stupid questions, I am just get interested in all that and wanted to try it. I have really small experience in programming and I want to ask about things you usually skip because, I guess, everyone here already know about that). So questions like how fill your .env folder, how to work with testnets that are still valid and how use your code in the current site in the first place. Could you help me with this please if you don't mind. Thanks in advance.

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

      Start with this. The docs for dotenv (.env)

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

      @@blockmancodes Thank you so I watched your video about "Stake tokens on Uniswap V3" and want to ask what should I put into .env INFURA_URL_TESTNET= (what's testnet would you will use for that now and where you can get data to put here?Also what should I do to work with real net, Polygon for example?) WALLET_ADDRESS= (Metamask adress) WALLET_SECRET=(Secret key, right?).

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

      @@agneyastra8785 I think I used Ropsten testnet when I made this but that's not active anymore.
      Create an account on Infura. And get a URL for Goerli testnet. Put that there.
      And yes for WALLET_ADDRESS and WALLET_SECRET.
      Hold off on a mainnet until you get it working flawlessly on a testnet

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

    what if your input amount is much bigger than the liquidity of slot0

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

      The tick will move. Different liquidity at each tick is the essence of uniswap V3

    • @user-fs4xc9nn6c
      @user-fs4xc9nn6c 11 месяцев назад +1

      @@blockmancodes How to calculate this

  • @user-vy1lo2gr8d
    @user-vy1lo2gr8d Год назад

    How to do the same for Arbitrum chain?

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

      Adding to my todo list

    • @GlitchDev1
      @GlitchDev1 8 месяцев назад

      in case you still have a problem.
      if tick is negative convert it into positive and you should get the right price. Dont know why. but works for me

  • @quantum-awareness
    @quantum-awareness Год назад

    and what about how can we get the Tick programatically? it would be nice to have a video about that (or a section within this video) Thank you

    • @quantum-awareness
      @quantum-awareness Год назад

      actually it works, you just have to make sure the provider is connected correctly,

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

      @@quantum-awareness Nice!

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

      With the Factory contract and then interface you can get the pool
      Just remember the pool you find could be 500,3000 or 10000 fee

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

    very cool, is there a repo with the code?

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

      Thank you! I'll be posting code for all new videos, but I don't think I have this code anymore

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

      Added a link to the code

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

    Is the best way to get Price in v3?

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

      Quoter2 contract

    • @user-cg1pq2kh6t
      @user-cg1pq2kh6t 4 месяца назад

      ​@@blockmancodes Are we have a way to got the last price without Gas? The Quoter2 has a writable functions with a gas....

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

    Where are you calling Uniswap?

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

      So we're not calling Uniswap here. We're rewriting the logic of how Uniswap does the calculation. And passing in an arbitrary value to convert.

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

    This does not work

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

      Can you elaborate on what is not working?

    • @user-fs4xc9nn6c
      @user-fs4xc9nn6c 11 месяцев назад

      @@blockmancodes large swaps won't work obviously