-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
explore page: use common numeraire #223
Conversation
src/pages/trade/model/useSummary.ts
Outdated
queries: quoteAssets.map(asset => ({ | ||
queryKey: ['multipleSummaries', asset, 'USDC'] as const, | ||
queryFn: async () => { | ||
return apiFetch<SummaryData | NoSummaryData>('/api/summary', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the /api/stats
and /api/summaries
endpoints from pindexer may be returning incorrect information, impacting metrics like "total trading volume (24h)" and the largest "trading pair (24h volume)" for the USDC/USDY pair.
previous discussions suggest that this may not simply be related to the denom exponents not being handled properly. cc @cronokirby
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is it possible to implement USDC price calculation using SQL?
As I understood the code correctly, it firstly calls useSummaries
, waits for it to fetch, and then makes multiple requests to /api/summary
with USDC as a quote asset. In my tests, these sequential requests run from 1s to 3s. It's not a bad score, but we can sure do better. Plus, I think that making multiple requests (right now 6 /api/summary
requests are made in parallel) are highly error prone and not-so-scalable.
We could change this to an improved SQL query. That's just one join with the sub-table where quote assets are USDC and multiplication method. This could also unblock sorting by calculated volume, limit and filter the results correctly.
issue (realized while writing question before): with this solution, we cannot sort the assets by usdc volume. For now, it is sorted by trade amount, which is not as useful for users as volume.
@VanishMax coming back to this, is this something we still want to try to implementing using SQL, or is the current approach of using useMultipleSummaries sufficient? you mentioned referencing another PR that was doing something similar related to pricing? I think we can also just iterate on this separately? |
@TalDerei Here's the code I mentioned before: https://github.com/penumbra-zone/dex-explorer/pull/204/files#diff-389f7431dcbf5738fe1724971d0c7a329fba1bd4b7058c49dd5abbd9d875a5f6R91 I believe it's more efficient and easier to implement – the left join of the summary with usdc prices table. |
Not a blocker for merging this, but perhaps we should instead add a column to pindexer for doing this in advance. |
// TODO: should this be `direct_volume_over_window`? | ||
let volume = toValueView({ | ||
amount: summary.liquidity, | ||
metadata: quoteAsset, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: should this have been summary.direct_volume_over_window
rather than summary.liquidity
? cc @VanishMax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought the stats should display the total existing liquidity (that's probably what i'd like to see on such page) but we sure can always change it
/** | ||
* Calculates USDC-normalized amounts for trading pair values (volume or liquidity) | ||
*/ | ||
export function calculateEquivalentInUSDC( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
price calculations utility method
todo: sanity check accuracy of all consumers of calculateEquivalentInUSDC
, specifically the values (volume / liquidity) and metadata being passed in.
// Converts liquidity and trading volume to their equivalent USDC prices if `usdc_price` is available | ||
if (summary.usdc_price && usdc) { | ||
liquidity = calculateEquivalentInUSDC(summary.liquidity, summary.usdc_price, quoteAsset, usdc); | ||
|
||
directVolume = calculateEquivalentInUSDC( | ||
summary.direct_volume_over_window, | ||
summary.usdc_price, | ||
quoteAsset, | ||
usdc, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: BTC and USDY still have strange denom coming out of pindexer – we should check if penumbra-zone/penumbra#4981 sufficiently addresses this. cc @cronokirby
![Screenshot 2025-01-12 at 2 01 37 PM](https://private-user-images.githubusercontent.com/70081547/402389933-9d58f27f-cb35-4e36-9b46-a11715d020d3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MTIyMDcsIm5iZiI6MTczODkxMTkwNywicGF0aCI6Ii83MDA4MTU0Ny80MDIzODk5MzMtOWQ1OGYyN2YtY2IzNS00ZTM2LTliNDYtYTExNzE1ZDAyMGQzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDA3MDUwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYxYjA0OGIwMDEzMzA5NjdiNmEyYjM0ZmYxZmI1YTViNGRhMTllZjAwZTkyZjFmYTZjZTQ2YjExODY2NzY0MjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.nRU2SITJ1mjwqiJDmYISJlIhK_j20p3RhAUWB3YBG-0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | ||
|
||
// Converts liquidity and trading volume to their equivalent USDC prices if `usdc_price` is available | ||
if (stats.usdc_price && largestPairEnd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor non-blocking comments. Feel free to merge
); | ||
|
||
// TODO: create `pnum.multiply()` utility: https://github.com/penumbra-zone/dex-explorer/issues/231 | ||
const result = liquidityOrVolume * usdcPrice * 10 ** expDiff; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I see @JasonMHasperhoven using .times()
function on BigNumber in collab with pnum
. Maybe this could help? https://github.com/penumbra-zone/dex-explorer/blob/main/src/pages/trade/model/positions.ts#L285
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine for now, and seems to work correctly based on running on a new reindex; we should probably move back some of this logic into pindexer, but we can refactor subsequently.
references #188
useSummary
useQuery into/trade/api
,/api/summary
, and denominates the trading pair liquidity and volume in USDC,api/stats
,