-
Notifications
You must be signed in to change notification settings - Fork 4
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
contrib: live position & oracle price updates v1 #577
contrib: live position & oracle price updates v1 #577
Conversation
@0xcryptovenom is attempting to deploy a commit to the adrena Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 feedback! Thank you for the PR 🙏
src/hooks/usePositions.ts
Outdated
positions && positions.length > 0 | ||
? Array.from( | ||
new Set( | ||
...positions.flatMap((position) => [ |
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.
The token prices used to calculate the PnL are:
const exitPriceUi = tokenPrices[custody.tradeTokenInfo.symbol];
const collateralTokenPriceUi =
tokenPrices[collateralCustody.tokenInfo.symbol];
Reminder:
On a SOL LONG position, JITOSOL is the CollateralToken, SOL is the the TradeToken.
On a BONK LONG position, BONK is the CollateralToken, BONK is the the TradeToken.
On a SOL SHORT position, USDC is the CollateralToken, SOL is the the TradeToken.
Can use getTokenSymbol(position.token.symbol)
to get the trade token
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 guess this is where we need to be careful.
My assumption is that we always need to react to the price changes of both the collateral token & the trade token, is this correct?
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.
Re-reading this now..
You're saying my assumption is indeed correct, but actually we don't care about position.token.symbol
because it doesn't really reflect the trade token, only getTokenSymbol(position.token.symbol)
does.
I'm making a commit in that sense, let me know how it looks then:
fixup: usePositions should react to the Trade Token price changes obtained through getTokenSymbol(position.token.symbol)
3d9a9a8
to
f0423bb
Compare
- introduce a selectStreamingTokenPricesFallback selector: - select streaming token prices, fallback to regular token price - introduce a stopStreamingTokenPrices action + creator: - reset the streaming token prices state to initial state - dispatch the stopStreamingTokenPrices when closing streaming. - fetchUserPositions, fetchAndSubscribeToFullUserPositions, usePositions now leverage selectStreamingTokenPricesFallback under the hood
…ained through getTokenSymbol(position.token.symbol)
…tion although the user positions are only fetched after user's wallet is connected, the AdrenaClient.connection (from the user-scoped program's provider attached to the client), may not yet be available. this is fine because we still have the read-only program available, we can fetch positions.
…arket price + liquidable
b56b349
to
135d8c2
Compare
const candidate = | ||
selectedAction === 'long' | ||
? tokenB ?? pickDefaultToken(positions) | ||
: tokenACandidate[0]; | ||
|
||
if (tokenACandidate.some((t) => t.symbol === candidate.symbol)) { | ||
setTokenA(candidate); |
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.
For slightly improved performance, we could move this out of the effect & do it during the render, similarly to the other state updates below.
There's also a lot more room for refactoring.
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 let you do your magic
Created a new PR and deployed |
Draft: not tested at all yet, but should mostly work.
Description
Changes
usePositions
hookRelated issues & PRs