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

Поділитися
Вставка
  • Опубліковано 3 гру 2024
  • Get my free EthersJS cheatsheet to master Web3!
    👉 blockman-codes...
    ------------------------------------------
    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.co...

КОМЕНТАРІ • 51

  • @blockmancodes
    @blockmancodes  Рік тому

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

  • @andrewliffey
    @andrewliffey Рік тому

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

  • @CodeWithJoe
    @CodeWithJoe 2 роки тому +4

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

  • @folego
    @folego 10 місяців тому

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

  • @prolingua
    @prolingua 11 місяців тому +1

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

    • @J4KC
      @J4KC 8 місяців тому

      same doubt

    • @turboblast88
      @turboblast88 3 місяці тому

      The baseToken and quoteToken are not actually used and could be removed. What is happening is that he is finding the pool address, looking up the pool and then pulling out the tick amount. The tick amount contains the pricing info. He then demonstrates once we have a tick how to make sense of it. The tick amount in this code is hard-coded and is being used as an example, we could then add code to pull the tick in real time from some pair.

  • @agneyastra8785
    @agneyastra8785 2 роки тому +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  2 роки тому

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

    • @agneyastra8785
      @agneyastra8785 2 роки тому

      @@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  2 роки тому +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

  • @dzsobacsi
    @dzsobacsi Рік тому

    Thanks for the great video! It works well here!

  • @ikniz2005
    @ikniz2005 4 місяці тому

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

  • @almail207
    @almail207 8 місяців тому

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

  • @Superraziel
    @Superraziel 2 роки тому

    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

  • @Tidalanime
    @Tidalanime 2 роки тому

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

  • @ducnguyen6581
    @ducnguyen6581 Рік тому

    How do you get currentTick programmatically?

    • @blockmancodes
      @blockmancodes  Рік тому

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

  • @quantum-awareness
    @quantum-awareness 2 роки тому

    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 2 роки тому

      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

  • @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.

  • @РусланВалеев-и9е

    How to do the same for Arbitrum chain?

    • @blockmancodes
      @blockmancodes  Рік тому

      Adding to my todo list

    • @GlitchDev1
      @GlitchDev1 Рік тому

      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

  • @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

    • @Antonym-b5o
      @Antonym-b5o 9 місяців тому

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

  • @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

    • @Max-g1c
      @Max-g1c Рік тому +1

      @@blockmancodes How to calculate this

  • @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?

    • @Max-g1c
      @Max-g1c Рік тому

      @@blockmancodes large swaps won't work obviously