Skip to content

Commit

Permalink
sdk: add settle pnl option to cost basis calc
Browse files Browse the repository at this point in the history
  • Loading branch information
lowkeynicc committed Jan 22, 2024
1 parent 807c037 commit 098b2ca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sdk/src/math/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 098b2ca

Please sign in to comment.