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...
Learn to use all of Uniswap's swap and liquidity functionality with code. bit.ly/3JkXYqL
this worked for me too. Thank you so much. !!
You're welcome!
do you have a discord or telegram or any way to contact yu?
Working here, but how I get the opposite? The second token vs the first one?
In the code, I don't see the use of baseToken, quoteToken and provider.
What are they for?
same doubt
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.
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.
Start with this. The docs for dotenv (.env)
@@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?).
@@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
Thanks for the great video! It works well here!
Thanks brother!
hi there. now the tick value is bigger, and the code does not suit that big tick value anymore
*uck uniswap and its x96, x192, squareRoots, ticks and all v3. God, how nice and simple v2 is!
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
I don't understand 100%. Can you rephrase your question?
Hi, what are the "provider" , 'basetoken' and 'quotetoken'' used for ?
It was a copy/paste error. You don't need them
I want to get the liquidity volume of the current price? What should I do?
maybe suck some tick?
How do you get currentTick programmatically?
Call "slot0" function on pool contract. It's inside, along with other data
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
actually it works, you just have to make sure the provider is connected correctly,
@@quantum-awareness Nice!
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
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
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
@@blockmancodes found the quoting contract and figured out how to route the quoting.
How to do the same for Arbitrum chain?
Adding to my todo list
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
very cool, is there a repo with the code?
Thank you! I'll be posting code for all new videos, but I don't think I have this code anymore
Added a link to the code
Is the best way to get Price in v3?
Quoter2 contract
@@blockmancodes Are we have a way to got the last price without Gas? The Quoter2 has a writable functions with a gas....
what if your input amount is much bigger than the liquidity of slot0
The tick will move. Different liquidity at each tick is the essence of uniswap V3
@@blockmancodes How to calculate this
Where are you calling Uniswap?
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.
This does not work
Can you elaborate on what is not working?
@@blockmancodes large swaps won't work obviously