Skip to content

feat: add getMultiMarketPositionsPnL for portfolio real-time PnL#82

Open
arthurka-o wants to merge 2 commits intomainfrom
multi-market-pnl
Open

feat: add getMultiMarketPositionsPnL for portfolio real-time PnL#82
arthurka-o wants to merge 2 commits intomainfrom
multi-market-pnl

Conversation

@arthurka-o
Copy link
Contributor

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.

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.
@arthurka-o
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +893 to +894
this.sdk.lbsc.getLbscAddress().then((addr) => {
lbscAddress = addr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant