Skip to content

Commit

Permalink
Merge pull request #1365 from gmx-io/hotfix-market-pnl
Browse files Browse the repository at this point in the history
get market pnl from contracts again
  • Loading branch information
gmxer authored Nov 4, 2024
2 parents 5374c66 + eff0787 commit 6fb83c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/domain/synthetics/markets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export type MarketInfo = Market &
borrowingFactorPerSecondForLongs: bigint;
borrowingFactorPerSecondForShorts: bigint;

pnlLongMax?: bigint;
pnlShortMax?: bigint;
pnlLongMin?: bigint;
pnlShortMin?: bigint;

fundingFactorPerSecond: bigint;
longsPayShorts: boolean;

Expand Down
9 changes: 9 additions & 0 deletions src/domain/synthetics/markets/useMarketsInfoRequest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type MarketValues = Pick<
| "virtualPoolAmountForLongToken"
| "virtualPoolAmountForShortToken"
| "virtualInventoryForPositions"
| "pnlLongMax"
| "pnlShortMax"
| "pnlLongMin"
| "pnlShortMin"
>;

/**
Expand Down Expand Up @@ -393,6 +397,11 @@ function useMarketsValuesRequest({
borrowingFactorPerSecondForLongs: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForLongs,
borrowingFactorPerSecondForShorts: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForShorts,

pnlLongMax: poolValueInfoMax.longPnl,
pnlShortMax: poolValueInfoMax.shortPnl,
pnlLongMin: poolValueInfoMin.longPnl,
pnlShortMin: poolValueInfoMin.shortPnl,

fundingFactorPerSecond: nextFunding.fundingFactorPerSecond,
longsPayShorts: nextFunding.longsPayShorts,

Expand Down
11 changes: 11 additions & 0 deletions src/domain/synthetics/markets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ export function getPriceForPnl(prices: TokenPrices, isLong: boolean, maximize: b
}

export function getMarketPnl(marketInfo: MarketInfo, isLong: boolean, maximize: boolean) {
let res: bigint | undefined = undefined;
if (maximize) {
res = isLong ? marketInfo.pnlLongMax : marketInfo.pnlShortMax;
} else {
res = isLong ? marketInfo.pnlLongMin : marketInfo.pnlShortMin;
}

if (res !== undefined) {
return res;
}

const openInterestUsd = getOpenInterestUsd(marketInfo, isLong);
const openInterestInTokens = getOpenInterestInTokens(marketInfo, isLong);

Expand Down

0 comments on commit 6fb83c8

Please sign in to comment.