diff --git a/components/stats/MangoStats.tsx b/components/stats/MangoStats.tsx
index 9553f8e7..1586ddec 100644
--- a/components/stats/MangoStats.tsx
+++ b/components/stats/MangoStats.tsx
@@ -1,31 +1,15 @@
-import SheenLoader from '@components/shared/SheenLoader'
-import mangoStore, { TokenStatsItem } from '@store/mangoStore'
-import useMangoGroup from 'hooks/useMangoGroup'
-import { useTranslation } from 'next-i18next'
-import dynamic from 'next/dynamic'
-import { useMemo } from 'react'
-import dayjs from 'dayjs'
-import { numberCompacter } from 'utils/numbers'
+import mangoStore from '@store/mangoStore'
+import TotalDepositBorrowCharts from './TotalDepositBorrowCharts'
+// import { useTranslation } from 'next-i18next'
// import { PerpMarket } from '@blockworks-foundation/mango-v4'
-const DetailedAreaChart = dynamic(
- () => import('@components/shared/DetailedAreaChart'),
- { ssr: false }
-)
-
-interface TotalValueItem {
- date: string
- borrowValue: number
- depositValue: number
-}
const MangoStats = () => {
- const { t } = useTranslation(['common', 'token', 'trade'])
+ // const { t } = useTranslation(['common', 'token', 'trade'])
const tokenStats = mangoStore((s) => s.tokenStats.data)
const loadingStats = mangoStore((s) => s.tokenStats.loading)
// const perpStats = mangoStore((s) => s.perpStats.data)
// const loadingPerpStats = mangoStore((s) => s.perpStats.loading)
// const perpMarkets = mangoStore((s) => s.perpMarkets)
- const { group } = useMangoGroup()
// const totalFeeValues = useMemo(() => {
// if (!perpStats.length) return []
@@ -72,111 +56,12 @@ const MangoStats = () => {
// }, 0)
// }, [perpMarkets])
- const totalDepositBorrowValues = useMemo(() => {
- if (!tokenStats) return []
- const values: TotalValueItem[] = tokenStats.reduce(
- (a: TotalValueItem[], c: TokenStatsItem) => {
- const hasDate = a.find((d: TotalValueItem) => d.date === c.date_hour)
- if (!hasDate) {
- a.push({
- date: c.date_hour,
- depositValue: Math.floor(c.total_deposits * c.price),
- borrowValue: Math.floor(c.total_borrows * c.price),
- })
- } else {
- hasDate.depositValue =
- hasDate.depositValue + Math.floor(c.total_deposits * c.price)
- hasDate.borrowValue =
- hasDate.borrowValue + Math.floor(c.total_borrows * c.price)
- }
- return a
- },
- []
- )
- return values.reverse()
- }, [tokenStats])
-
- const banks = useMemo(() => {
- if (group) {
- const rawBanks = Array.from(group?.banksMapByName, ([key, value]) => ({
- key,
- value,
- }))
- return rawBanks
- }
- return []
- }, [group])
-
- const [currentTotalDepositValue, currentTotalBorrowValue] = useMemo(() => {
- if (banks.length) {
- return [
- banks.reduce(
- (a, c) => a + c.value[0].uiPrice * c.value[0].uiDeposits(),
- 0
- ),
- banks.reduce(
- (a, c) => a + c.value[0].uiPrice * c.value[0].uiBorrows(),
- 0
- ),
- ]
- }
- return [0, 0]
- }, [banks])
-
return (
- {loadingStats ? (
-
- ) : totalDepositBorrowValues.length ? (
-
- `$${numberCompacter.format(x)}`}
- title={t('total-deposit-value')}
- xKey="date"
- yKey={'depositValue'}
- />
-
- ) : null}
- {loadingStats ? (
-
- ) : totalDepositBorrowValues.length ? (
-
- `$${numberCompacter.format(x)}`}
- title={t('total-borrow-value')}
- xKey="date"
- yKey={'borrowValue'}
- />
-
- ) : null}
+
{/* uncomment below when perps launch */}
{/* {loadingPerpStats ? (
diff --git a/components/stats/TotalDepositBorrowCharts.tsx b/components/stats/TotalDepositBorrowCharts.tsx
new file mode 100644
index 00000000..d7487954
--- /dev/null
+++ b/components/stats/TotalDepositBorrowCharts.tsx
@@ -0,0 +1,170 @@
+import SheenLoader from '@components/shared/SheenLoader'
+import { TokenStatsItem } from '@store/mangoStore'
+import useMangoGroup from 'hooks/useMangoGroup'
+import { useTranslation } from 'next-i18next'
+import dynamic from 'next/dynamic'
+import { useMemo, useState } from 'react'
+import dayjs from 'dayjs'
+import { numberCompacter } from 'utils/numbers'
+const DetailedAreaChart = dynamic(
+ () => import('@components/shared/DetailedAreaChart'),
+ { ssr: false }
+)
+
+interface TotalValueItem {
+ date: string
+ borrowValue: number
+ depositValue: number
+}
+
+const TotalDepositBorrowCharts = ({
+ tokenStats,
+ loadingStats,
+}: {
+ tokenStats: TokenStatsItem[] | null
+ loadingStats: boolean
+}) => {
+ const { t } = useTranslation(['common', 'token', 'trade'])
+ const [borrowDaysToShow, setBorrowDaysToShow] = useState('30')
+ const [depositDaysToShow, setDepositDaysToShow] = useState('30')
+ const { group } = useMangoGroup()
+
+ const totalDepositBorrowValues = useMemo(() => {
+ if (!tokenStats) return []
+ const values: TotalValueItem[] = tokenStats.reduce(
+ (a: TotalValueItem[], c: TokenStatsItem) => {
+ const hasDate = a.find((d: TotalValueItem) => d.date === c.date_hour)
+ if (!hasDate) {
+ a.push({
+ date: c.date_hour,
+ depositValue: Math.floor(c.total_deposits * c.price),
+ borrowValue: Math.floor(c.total_borrows * c.price),
+ })
+ } else {
+ hasDate.depositValue =
+ hasDate.depositValue + Math.floor(c.total_deposits * c.price)
+ hasDate.borrowValue =
+ hasDate.borrowValue + Math.floor(c.total_borrows * c.price)
+ }
+ return a
+ },
+ []
+ )
+ return values.reverse()
+ }, [tokenStats])
+
+ const filteredBorrowValues = useMemo(() => {
+ if (!totalDepositBorrowValues) return []
+ if (borrowDaysToShow !== '30') {
+ const seconds = Number(borrowDaysToShow) * 86400
+ const data = totalDepositBorrowValues.filter((d) => {
+ const dataTime = new Date(d.date).getTime() / 1000
+ const now = new Date().getTime() / 1000
+ const limit = now - seconds
+ return dataTime >= limit
+ })
+ return data
+ }
+ return totalDepositBorrowValues
+ }, [totalDepositBorrowValues, borrowDaysToShow])
+
+ const filteredDepositValues = useMemo(() => {
+ if (!totalDepositBorrowValues) return []
+ if (depositDaysToShow !== '30') {
+ const seconds = Number(depositDaysToShow) * 86400
+ const data = totalDepositBorrowValues.filter((d) => {
+ const dataTime = new Date(d.date).getTime() / 1000
+ const now = new Date().getTime() / 1000
+ const limit = now - seconds
+ return dataTime >= limit
+ })
+ return data
+ }
+ return totalDepositBorrowValues
+ }, [totalDepositBorrowValues, depositDaysToShow])
+
+ const banks = useMemo(() => {
+ if (group) {
+ const rawBanks = Array.from(group?.banksMapByName, ([key, value]) => ({
+ key,
+ value,
+ }))
+ return rawBanks
+ }
+ return []
+ }, [group])
+
+ const [currentTotalDepositValue, currentTotalBorrowValue] = useMemo(() => {
+ if (banks.length) {
+ return [
+ banks.reduce(
+ (a, c) => a + c.value[0].uiPrice * c.value[0].uiDeposits(),
+ 0
+ ),
+ banks.reduce(
+ (a, c) => a + c.value[0].uiPrice * c.value[0].uiBorrows(),
+ 0
+ ),
+ ]
+ }
+ return [0, 0]
+ }, [banks])
+
+ return loadingStats ? (
+ <>
+
+
+ >
+ ) : totalDepositBorrowValues.length ? (
+ <>
+
+ `$${numberCompacter.format(x)}`}
+ title={t('total-deposit-value')}
+ xKey="date"
+ yKey={'depositValue'}
+ />
+
+
+ `$${numberCompacter.format(x)}`}
+ title={t('total-borrow-value')}
+ xKey="date"
+ yKey={'borrowValue'}
+ />
+
+ >
+ ) : null
+}
+
+export default TotalDepositBorrowCharts
diff --git a/components/trade/PerpPositions.tsx b/components/trade/PerpPositions.tsx
index da26ec48..b667178a 100644
--- a/components/trade/PerpPositions.tsx
+++ b/components/trade/PerpPositions.tsx
@@ -8,6 +8,7 @@ import useMangoGroup from 'hooks/useMangoGroup'
import useSelectedMarket from 'hooks/useSelectedMarket'
import { useTranslation } from 'next-i18next'
import {
+ formatDecimal,
formatFixedDecimals,
getDecimalCount,
numberFormat,
@@ -66,8 +67,8 @@ const PerpPositions = () => {
{t('trade:size')} |
{t('trade:notional')} |
{t('trade:entry-price')} |
-
Redeemable PnL |
-
Realized PnL |
+
Unsettled PnL |
+
PnL |
@@ -86,7 +87,11 @@ const PerpPositions = () => {
if (!basePosition) return null
- const unsettledPnl = position.getEquityUi(group, market)
+ const unsettledPnl = position.getUnsettledPnlUi(group, market)
+ const cummulativePnl = position.cumulativePnlOverPositionLifetimeUi(
+ group,
+ market
+ )
return (
@@ -96,7 +101,7 @@ const PerpPositions = () => {
|
-
+ |
{isSelectedMarket ? (
{
)}
|
+
+ {formatDecimal(unsettledPnl, market.baseDecimals)}
+ |
0 ? 'text-th-up' : 'text-th-down'
+ cummulativePnl > 0 ? 'text-th-up' : 'text-th-down'
}`}
>
- {formatFixedDecimals(unsettledPnl, true)}
- |
-
-
- $
- {/* {numberFormat.format(
- position.perpSpotTransfers.toNumber()
- )} */}
-
+ {formatFixedDecimals(cummulativePnl, true)}
|
)
diff --git a/components/trade/UnsettledTrades.tsx b/components/trade/UnsettledTrades.tsx
index 8a106fd8..677c0177 100644
--- a/components/trade/UnsettledTrades.tsx
+++ b/components/trade/UnsettledTrades.tsx
@@ -204,7 +204,7 @@ const UnsettledTrades = ({
{formatDecimal(
- position.getEquityUi(group, market),
+ position.getUnsettledPnlUi(group, market),
market.baseDecimals
)}
|
diff --git a/hooks/useUnsettledPerpPositions.ts b/hooks/useUnsettledPerpPositions.ts
index 4de44901..88c95a66 100644
--- a/hooks/useUnsettledPerpPositions.ts
+++ b/hooks/useUnsettledPerpPositions.ts
@@ -7,8 +7,8 @@ const useUnsettledPerpPositions = () => {
return perpPositions.filter((p) => {
const market = group?.getPerpMarketByMarketIndex(p.marketIndex)
- if (!market) return false
- return p.getPnl(market).toNumber() > 0
+ if (!market || !group) return false
+ return p.getUnsettledPnlUi(group, market) !== 0
})
}
diff --git a/pages/dashboard/index.tsx b/pages/dashboard/index.tsx
index d443f5fa..b3d6434f 100644
--- a/pages/dashboard/index.tsx
+++ b/pages/dashboard/index.tsx
@@ -441,17 +441,29 @@ const Dashboard: NextPage = () => {
/>
+
+
{
label="Oracle: Max Staleness"
value={`${perpMarket.oracleConfig.maxStalenessSlots} slots`}
/>
-