feat: add getMultiMarketPositionsPnL for portfolio real-time PnL#82
feat: add getMultiMarketPositionsPnL for portfolio real-time PnL#82arthurka-o wants to merge 2 commits intomainfrom
Conversation
Adds a new SDK method that fetches PnL data for positions across multiple markets in a single multicall. Folds LBSC oracle price into the same batch to minimize RPC calls. Also extracts convertPnLToStable as a shared private method and exports MultiMarketPnLResult / PositionPnLEntry types.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a77896cbaf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pnlUSDT = this.convertPnLToStable(pnl, posLayout.loan, oraclePrice); | ||
| } | ||
|
|
||
| const key = `${layout.marketAddress}-${posLayout.positionId}`; |
There was a problem hiding this comment.
Include walletAddress in multi-market position keys
The result map key is built as marketAddress-positionId, but each on-chain read is parameterized by both walletAddress and positionId. If marketGroups contains two positions with the same market and position ID but different wallets, the later entry silently overwrites the earlier one, so callers get incomplete/incorrect PnL data for valid inputs.
Useful? React with 👍 / 👎.
| this.sdk.lbsc.getLbscAddress().then((addr) => { | ||
| lbscAddress = addr; |
There was a problem hiding this comment.
Gracefully handle LBSC address lookup failures
When any position has a loan, getLbscAddress() is added into Promise.all without error handling, so a transient RPC/read failure rejects the whole method and drops all market PnL results. This defeats the method’s partial-failure behavior (allowFailure: true) and should fall back to returning OVL PnL without USDT conversion instead of throwing.
Useful? React with 👍 / 👎.
…ositionsPnL Catch getLbscAddress() errors so a transient RPC failure doesn't reject the entire method. LBSC positions fall back to static SDK values while non-LBSC positions still get real-time PnL.
Adds a new SDK method that fetches PnL data for positions across multiple markets in a single multicall. Folds LBSC oracle price into the same batch to minimize RPC calls.
Also extracts convertPnLToStable as a shared private method and exports MultiMarketPnLResult / PositionPnLEntry types.