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...
Learn to use all of Uniswap's swap and liquidity functionality with code. bit.ly/3JkXYqL
All your Videos are Gold, am still learning and i believe i will get there
Thank you! Keep at it and you will!
@@blockmancodes 😅😅😮😮😮😮
Hi! I have error with multiply function:
Cannot read properties of undefined (reading 'multiply')
Somebody can to help me?
What other Uniswap tutorials would you like to see?
Can you do a Code that compares the prices of tokens from 2 exchanges. Kinda like a stepping stone to creating an arbitrage bot
How do you know the quantities of each token you would receive if you were to withdraw X lp from an uniswap pool ?
Can you please do one on Aave?
@@opeyemioginni6601 For sure. Do you have another exchange in mind?
@@sverma333 Good question. I will cover this in an upcoming liquidity video
Is it reliable ? should i use Pricee feed of Chainlink
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?
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.
loving it. u r awesome
Thanks brother!
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.
Thanks for letting me know brother
@@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.
@@naveenjp So you want to know like how much "ETH vs UNI" in an existing position?
Hey, can anyone tell me how do you get the pool address?
Just posted a video on this
@@blockmancodes that's great! Thank you so much ✌️
The code isnt updated, seems to be missing some code.
Also your use of "quoteToken" is leading to a TypeError: Assignment to constant variable.
@@mocholabs4656 I updated the gist code.
Hey!
Do you know how we can get the current value of each token added in liquidity v3?
Everything in Uniswap is priced in pairs. So "current value" is subjective. Can you give me a token example of what you want?