use latest client; update perp positions table with new pnl calcs
This commit is contained in:
parent
579f4ddd58
commit
e5dff1c8c3
|
@ -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 = () => {
|
|||
<Th className="text-right">{t('trade:size')}</Th>
|
||||
<Th className="text-right">{t('trade:notional')}</Th>
|
||||
<Th className="text-right">{t('trade:entry-price')}</Th>
|
||||
<Th className="text-right">Redeemable PnL</Th>
|
||||
<Th className="text-right">Realized PnL</Th>
|
||||
<Th className="text-right">Unsettled PnL</Th>
|
||||
<Th className="text-right">PnL</Th>
|
||||
</TrHead>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -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 (
|
||||
<TrBody key={`${position.marketIndex}`} className="my-1 p-2">
|
||||
|
@ -96,7 +101,7 @@ const PerpPositions = () => {
|
|||
<Td className="text-right">
|
||||
<PerpSideBadge basePosition={basePosition} />
|
||||
</Td>
|
||||
<Td className="text-right">
|
||||
<Td className="text-right font-mono">
|
||||
<p className="flex justify-end">
|
||||
{isSelectedMarket ? (
|
||||
<LinkButton
|
||||
|
@ -123,20 +128,15 @@ const PerpPositions = () => {
|
|||
)}
|
||||
</div>
|
||||
</Td>
|
||||
<Td className={`text-right font-mono`}>
|
||||
<div>{formatDecimal(unsettledPnl, market.baseDecimals)}</div>
|
||||
</Td>
|
||||
<Td
|
||||
className={`text-right font-mono ${
|
||||
unsettledPnl > 0 ? 'text-th-up' : 'text-th-down'
|
||||
cummulativePnl > 0 ? 'text-th-up' : 'text-th-down'
|
||||
}`}
|
||||
>
|
||||
<div>{formatFixedDecimals(unsettledPnl, true)}</div>
|
||||
</Td>
|
||||
<Td className="text-right">
|
||||
<div>
|
||||
$
|
||||
{/* {numberFormat.format(
|
||||
position.perpSpotTransfers.toNumber()
|
||||
)} */}
|
||||
</div>
|
||||
<div>{formatFixedDecimals(cummulativePnl, true)}</div>
|
||||
</Td>
|
||||
</TrBody>
|
||||
)
|
||||
|
|
|
@ -204,7 +204,7 @@ const UnsettledTrades = ({
|
|||
</Td>
|
||||
<Td className="text-right font-mono">
|
||||
{formatDecimal(
|
||||
position.getEquityUi(group, market),
|
||||
position.getUnsettledPnlUi(group, market),
|
||||
market.baseDecimals
|
||||
)}
|
||||
</Td>
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -441,17 +441,29 @@ const Dashboard: NextPage = () => {
|
|||
/>
|
||||
<KeyValuePair
|
||||
label="Maint Asset/Liab Weight"
|
||||
value={`${perpMarket.maintAssetWeight.toFixed(
|
||||
value={`${perpMarket.maintBaseAssetWeight.toFixed(
|
||||
4
|
||||
)}/
|
||||
${perpMarket.maintLiabWeight.toFixed(4)}`}
|
||||
${perpMarket.maintBaseLiabWeight.toFixed(4)}`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Init Asset/Liab Weight"
|
||||
value={`${perpMarket.initAssetWeight.toFixed(
|
||||
value={`${perpMarket.initBaseAssetWeight.toFixed(
|
||||
4
|
||||
)}/
|
||||
${perpMarket.initLiabWeight.toFixed(4)}`}
|
||||
${perpMarket.initBaseLiabWeight.toFixed(4)}`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Maint PNL Asset weight"
|
||||
value={`${perpMarket.maintPnlAssetWeight.toFixed(
|
||||
4
|
||||
)}`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Init PNL Asset weight"
|
||||
value={`${perpMarket.initPnlAssetWeight.toFixed(
|
||||
4
|
||||
)}`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Liquidation Fee"
|
||||
|
@ -500,10 +512,6 @@ const Dashboard: NextPage = () => {
|
|||
label="Oracle: Max Staleness"
|
||||
value={`${perpMarket.oracleConfig.maxStalenessSlots} slots`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Trusted Market"
|
||||
value={`${perpMarket.trustedMarket}`}
|
||||
/>
|
||||
<KeyValuePair
|
||||
label="Group Insurance Fund"
|
||||
value={`${perpMarket.groupInsuranceFund}`}
|
||||
|
|
11
yarn.lock
11
yarn.lock
|
@ -52,7 +52,7 @@
|
|||
|
||||
"@blockworks-foundation/mango-v4@https://github.com/blockworks-foundation/mango-v4.git#ts-client":
|
||||
version "0.0.1-beta.6"
|
||||
resolved "https://github.com/blockworks-foundation/mango-v4.git#59ef05ebe95ed5ca947ab5cfecf97c4c9fc99740"
|
||||
resolved "https://github.com/blockworks-foundation/mango-v4.git#adc9140ad2a3c2e9c3b425b8804d9415f2a05067"
|
||||
dependencies:
|
||||
"@project-serum/anchor" "^0.25.0"
|
||||
"@project-serum/serum" "^0.13.65"
|
||||
|
@ -4844,7 +4844,14 @@ node-addon-api@^2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
|
||||
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==
|
||||
|
||||
node-fetch@2, node-fetch@2.6.7, node-fetch@^2.6.1:
|
||||
node-fetch@2, node-fetch@^2.6.1:
|
||||
version "2.6.8"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.8.tgz#a68d30b162bc1d8fd71a367e81b997e1f4d4937e"
|
||||
integrity sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg==
|
||||
dependencies:
|
||||
whatwg-url "^5.0.0"
|
||||
|
||||
node-fetch@2.6.7:
|
||||
version "2.6.7"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
||||
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
|
||||
|
|
Loading…
Reference in New Issue