v3-sdk
v3-sdk copied to clipboard
What is the right price amongst 3 Liquidity Pools of the same Token Pair on V3?
I would post this issue on uniswap/uniswap-v3-core by posting issues there is forbidden:
(why is that?)
anyway, setting this aside... querying the subgraph I discovered that there can be multiple Liquidity Pools for a given token pair, as having a different fee tier, one can create a new LP for an already existing pair.
The question is, how do we determine price given multiple LPs for the same token pair? How does frontend tackle this?
Example using DAI/USDC Pair
The Query
{
token(id:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48") {
id
symbol
whitelistPools(where:{token0:"0x6b175474e89094c44da98b954eedeac495271d0f"}) {
id
feeTier
liquidity
token0Price
token1Price
token0 {
symbol
}
}
}
}
The Response
{
"data": {
"token": {
"id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"symbol": "USDC",
"whitelistPools": [
{
"feeTier": "10000",
"id": "0x6958686b6348c3d6d5f2dca3106a5c09c156873a",
"liquidity": "24405430160684491",
"token0": {
"symbol": "DAI"
},
"token0Price": "1.000097347797523468560923036695158",
"token1Price": "0.9999026616781477783833621614227994"
},
{
"feeTier": "500",
"id": "0x6c6bc977e13df9b0de53b251522280bb72383700",
"liquidity": "166739955719276340984048",
"token0": {
"symbol": "DAI"
},
"token0Price": "0.999375896994654300981013045872989",
"token1Price": "1.000624492753149756391698159238136"
},
{
"feeTier": "3000",
"id": "0xa63b490aa077f541c9d64bfc1cc0db2a752157b5",
"liquidity": "1983087073471302739",
"token0": {
"symbol": "DAI"
},
"token0Price": "0.9998697244241236777590508333027245",
"token1Price": "1.000130292549813281560606342941779"
}
]
}
}
}
It just picks the best one, whatever that means.
So you try the 3, see what has the best price for you, and that it.
If you only wants a price for an oracle, I would advise to use the 0.05% with some liquidity locked for ever.
This is because the smaller the fee, the more accurate the price is, because arb bots are capable to be more efficient and more correctly match prices for tiny differences.
Thank you @Jorropo for the reply! A few follow up questions:
So you try the 3, see what has the best price for you, and that it.
Shouldn't Liquidity of the LP also be important? How can I determine that?
If you only wants a price for an oracle, I would advise to use the 0.05% with some liquidity locked for ever.
What does it mean "use the 0.05% with some liquidity locked for ever"? Is this documented somewhere? Who locks liquidity and how?
Thank you
Shouldn't Liquidity of the LP also be important? How can I determine that?
Yes, that is included in the "try" part. Either you implement V3 in JS or Go or whatever or you use the quoter contract.
What does it mean "use the 0.05% with some liquidity locked for ever"?
If your goal is a reliable oracle, locking liquidity is a great way to unsure eternity. If all LPs removed their liquidity from the pool your oracle wouldn't work anymore because it wouldn't be arbed anymore.
If you add let's say 1m in a very broad range liquidity and send the NFT to 0xdEaD
or mint through your oracle contract or whatever that will hold on the position forever, you know that it's impossible for all LPs to remove their liquidity, because their will always be that locked liquidity you added.
- What is the "quoter" contract? What is its address? Documentation?
- How do I lock liquidity? Where is the documentation for that?
Thank you :pray:
- What is the "quoter" contract? What is its address? Documentation?
https://docs.uniswap.org/protocol/reference/periphery/lens/Quoter https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/lens/Quoter.sol https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/lens/QuoterV2.sol
- How do I lock liquidity? Where is the documentation for that?
Just transfer the NFT to the 0xdEaD
address.
Since 0xdEaD
isn't a real account, no one has the key, nor it's a contract, no one will ever be able to remove it, because to do so you would need access to the 0xdEaD
address, but you can't.
TL;DR just transfer the NFT to an account no one has access to.
However you can't just pick random bytes, if you do so people will accusate you to actually have access to that account, so you use the 0xdEaD
account since this is a well known patern and people will not doubt it (0xdEaD
is actually 0x000000000000000000000000000000000000dEaD
, it is unlikely (like impossible unlikely) to find a key with such public key in the first place, the high number of zeros make that task impossible, or if you can do that, ETH isn't secure anyway).
Thank you @Jorropo but I am afraid I am more confused now and nowhere near understanding how to get a quote...
First, the "quoter", after close examination, requires "the fee". Which means, that it can quote for a single pool. Which means, that my primary question, remains unanswered (how to determine price between multiple LPs of the same token-pair).
Second, I am way more confused with your "lock liquidity" reply. As you know, I am new to this space and I am missing way too much context. How does an NFT got involved in getting a quote for a token-pair? What is the 0xdEaD
address and why is it important? ... In any case, I do not believe that course is something that fits my requirements...
Going back to my original requirements, what I need, is to get a quote from Uniswap V3 for a given token-pair. In V2 that was very straightforward:
- Query the Factory contract for the token-pair --> Get the Liquidity Pool.
- Query the Liquidity Pool for each tokens reserves.
- Divide the token reserves to get an accurate quote of the token-pair.
You personally know my, our, struggle, to perform the same operation on V3, which even produced a Price Calculating library that I authored.
Going back to your original answer and my remark, this is what I understand I need to do:
- We have to calculate price for all Liquidity Pools of the same pair.
- We have to pick the lowest price amongst the LPs.
- We have to check if the liquidity of the lowest price LP is "adequate".
Point 3, is kind of problematic. What is deemed "adequate"? Is there a defined threshold by uniswap? Is it arbitrary? Who judges if the liquidity is adequate?
And what, is now, the most important question: How do we determine the liquidity of an LP? - there is no relevant mention in the documentation: https://docs.uniswap.org/protocol/reference/core/UniswapV3Pool
And the liquidity
property of the subgraph is of unknown unit... There's another open issue in regards to the fact that the subgraph is completely undocumented: https://github.com/Uniswap/uniswap-v3-subgraph/issues/37
I am still at a loss on how to proceed.
@thanpolas is this question answered? I have same one.
Thank you @Jorropo but I am afraid I am more confused now and nowhere near understanding how to get a quote...
First, the "quoter", after close examination, requires "the fee". Which means, that it can quote for a single pool. Which means, that my primary question, remains unanswered (how to determine price between multiple LPs of the same token-pair).
Second, I am way more confused with your "lock liquidity" reply. As you know, I am new to this space and I am missing way too much context. How does an NFT got involved in getting a quote for a token-pair? What is the
0xdEaD
address and why is it important? ... In any case, I do not believe that course is something that fits my requirements...Going back to my original requirements, what I need, is to get a quote from Uniswap V3 for a given token-pair. In V2 that was very straightforward:
- Query the Factory contract for the token-pair --> Get the Liquidity Pool.
- Query the Liquidity Pool for each tokens reserves.
- Divide the token reserves to get an accurate quote of the token-pair.
You personally know my, our, struggle, to perform the same operation on V3, which even produced a Price Calculating library that I authored.
Going back to your original answer and my remark, this is what I understand I need to do:
- We have to calculate price for all Liquidity Pools of the same pair.
- We have to pick the lowest price amongst the LPs.
- We have to check if the liquidity of the lowest price LP is "adequate".
Point 3, is kind of problematic. What is deemed "adequate"? Is there a defined threshold by uniswap? Is it arbitrary? Who judges if the liquidity is adequate?
And what, is now, the most important question: How do we determine the liquidity of an LP? - there is no relevant mention in the documentation: https://docs.uniswap.org/protocol/reference/core/UniswapV3Pool
And the
liquidity
property of the subgraph is of unknown unit... There's another open issue in regards to the fact that the subgraph is completely undocumented: Uniswap/v3-subgraph#37I am still at a loss on how to proceed.
Have you found anyway to determine these things?