From 098b2ca203a5c296db14cb2ee62179728a000367 Mon Sep 17 00:00:00 2001 From: lowkeynicc Date: Mon, 22 Jan 2024 14:52:46 -0500 Subject: [PATCH] sdk: add settle pnl option to cost basis calc --- sdk/src/math/position.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/src/math/position.ts b/sdk/src/math/position.ts index 7a47e8dea..a166d6878 100644 --- a/sdk/src/math/position.ts +++ b/sdk/src/math/position.ts @@ -237,12 +237,16 @@ export function calculateEntryPrice(userPosition: PerpPosition): BN { * @param userPosition * @returns Precision: PRICE_PRECISION (10^10) */ -export function calculateCostBasis(userPosition: PerpPosition): BN { +export function calculateCostBasis( + userPosition: PerpPosition, + includeSettledPnl = false +): BN { if (userPosition.baseAssetAmount.eq(ZERO)) { return ZERO; } return userPosition.quoteAssetAmount + .add(includeSettledPnl ? userPosition.settledPnl : ZERO) .mul(PRICE_PRECISION) .mul(AMM_TO_QUOTE_PRECISION_RATIO) .div(userPosition.baseAssetAmount)