use latest client for risk stats

This commit is contained in:
tjs 2023-05-14 13:15:22 -04:00
parent cfa95dfd9c
commit d88ebb909b
3 changed files with 95 additions and 309 deletions

View File

@ -19,7 +19,7 @@
},
"dependencies": {
"@blockworks-foundation/mango-feeds": "0.1.6",
"@blockworks-foundation/mango-v4": "^0.14.2",
"@blockworks-foundation/mango-v4": "^0.15.0",
"@headlessui/react": "1.6.6",
"@heroicons/react": "2.0.10",
"@metaplex-foundation/js": "0.18.3",

View File

@ -1,15 +1,13 @@
import useMangoGroup from 'hooks/useMangoGroup'
import type { NextPage } from 'next'
// import { ReactNode, useCallback, useEffect, useState } from 'react'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
// import {
// toUiDecimalsForQuote,
// HealthType,
// PerpOrder,
// } from '@blockworks-foundation/mango-v4'
// import mangoStore from '@store/mangoStore'
import { DashboardNavbar } from '.'
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
import { useQuery } from '@tanstack/react-query'
import mangoStore from '@store/mangoStore'
import { getRiskStats } from '@blockworks-foundation/mango-v4'
import { PublicKey } from '@solana/web3.js'
import { formatNumericValue } from 'utils/numbers'
export async function getStaticProps({ locale }: { locale: string }) {
return {
@ -19,10 +17,38 @@ export async function getStaticProps({ locale }: { locale: string }) {
}
}
type TableData = {
title: string
data: Array<Record<string, string | number>>
}
const formatValue = (val: string | number | PublicKey) => {
if (val instanceof PublicKey) {
return val.toString()
}
if (typeof val === 'string') {
return val
} else {
return formatNumericValue(val)
}
}
const RiskDashboard: NextPage = () => {
const { group } = useMangoGroup()
// const { mangoTokens } = useJupiterMints()
// const client = mangoStore(s => s.client)
const client = mangoStore((s) => s.client)
const { data, isLoading, isFetching } = useQuery(
['risks'],
() => group && getRiskStats(client, group),
{
cacheTime: 1000 * 60 * 10,
retry: 3,
refetchOnWindowFocus: true,
enabled: !!group,
}
)
console.log('resp', isLoading, isFetching, data)
return (
<div className="grid grid-cols-12">
@ -30,302 +56,62 @@ const RiskDashboard: NextPage = () => {
<div className="p-8 pb-20 text-th-fgd-1 md:pb-16 xl:p-10">
<h1>Dashboard</h1>
<DashboardNavbar />
{group ? (
{group && data ? (
<div className="mt-4">
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 1a: Liqors acquire liabs and assets. The assets and
liabs are sum of max assets and max liabs for any token
which would be liquidated to fix the health of a mango
account. This would be the slippage they would face on
buying-liabs/offloading-assets tokens acquired from unhealth
accounts after a 20% drop
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Coin
</Th>
<Th xBorder className="text-right">
Oracle price
</Th>
<Th xBorder className="text-right">
On-chain price
</Th>
<Th xBorder className="text-right">
Future price
</Th>
<Th xBorder className="text-right">
Liq fee
</Th>
<Th xBorder className="text-right">
Liabs
</Th>
<Th xBorder className="text-right">
Liabs slippage
</Th>
<Th xBorder className="text-right">
Assets
</Th>
<Th xBorder className="text-right">
Assets slippage
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
Bonk
</Td>
<Td xBorder className="text-right">
4.432e-7
</Td>
<Td xBorder className="text-right">
4.432e-7
</Td>
<Td xBorder className="text-right">
2.6592e-7
</Td>
<Td xBorder className="text-right">
20.000%
</Td>
<Td xBorder className="text-right">
0$
</Td>
<Td xBorder className="text-right">
0.00%
</Td>
<Td xBorder className="text-right">
0.671$
</Td>
<Td xBorder className="text-right">
0.29%
</Td>
</TrBody>
</tbody>
</Table>
</div>
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 1b: Liqors acquire liabs and assets. The assets and
liabs are sum of max assets and max liabs for any token
which would be liquidated to fix the health of a mango
account. This would be the slippage they would face on
buying-liabs/offloading-assets tokens acquired from unhealth
accounts after a 20% rally
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Coin
</Th>
<Th xBorder className="text-right">
Oracle price
</Th>
<Th xBorder className="text-right">
On-chain price
</Th>
<Th xBorder className="text-right">
Future price
</Th>
<Th xBorder className="text-right">
Liq fee
</Th>
<Th xBorder className="text-right">
Liabs
</Th>
<Th xBorder className="text-right">
Liabs slippage
</Th>
<Th xBorder className="text-right">
Assets
</Th>
<Th xBorder className="text-right">
Assets slippage
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
Bonk
</Td>
<Td xBorder className="text-right">
4.432e-7
</Td>
<Td xBorder className="text-right">
4.432e-7
</Td>
<Td xBorder className="text-right">
2.6592e-7
</Td>
<Td xBorder className="text-right">
20.000%
</Td>
<Td xBorder className="text-right">
0$
</Td>
<Td xBorder className="text-right">
0.00%
</Td>
<Td xBorder className="text-right">
0.671$
</Td>
<Td xBorder className="text-right">
0.29%
</Td>
</TrBody>
</tbody>
</Table>
</div>
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 2a: Perp notional that liqor need to liquidate after a
20% drop
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Market
</Th>
<Th xBorder className="text-right">
Price
</Th>
<Th xBorder className="text-right">
Future Price
</Th>
<Th xBorder className="text-right">
Notional Position
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
ETH-PERP
</Td>
<Td xBorder className="text-right">
1878.63
</Td>
<Td xBorder className="text-right">
1127.18
</Td>
<Td xBorder className="text-right">
1,851.732$
</Td>
</TrBody>
</tbody>
</Table>
</div>
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 2b: Perp notional that liqor need to liquidate after a
20% rally
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Market
</Th>
<Th xBorder className="text-right">
Price
</Th>
<Th xBorder className="text-right">
Future Price
</Th>
<Th xBorder className="text-right">
Notional Position
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
ETH-PERP
</Td>
<Td xBorder className="text-right">
1878.63
</Td>
<Td xBorder className="text-right">
1127.18
</Td>
<Td xBorder className="text-right">
1,851.732$
</Td>
</TrBody>
</tbody>
</Table>
</div>
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 3: Equity of known liqors from last month
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Account
</Th>
<Th xBorder className="text-right">
Equity
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
BNTDZJQrjNkjFxYAMCdKH2ShSM6Uwc28aAgit7ytVQJc
</Td>
<Td xBorder className="text-right">
15,034.376$
</Td>
</TrBody>
</tbody>
</Table>
</div>
<div className="mt-12">
<div className="mb-4">
<p className="text-th-fgd-4">
Table 4: Equity of known makers from last month
</p>
</div>
<Table>
<thead>
<TrHead className="border">
<Th xBorder className="text-left">
Account
</Th>
<Th xBorder className="text-right">
Equity
</Th>
</TrHead>
</thead>
<tbody>
<TrBody>
<Td xBorder className="text-left">
BNTDZJQrjNkjFxYAMCdKH2ShSM6Uwc28aAgit7ytVQJc
</Td>
<Td xBorder className="text-right">
529.325$
</Td>
</TrBody>
</tbody>
</Table>
</div>
{Object.entries(data).map(
([tableType, table]: [string, TableData]) => {
return (
<div className="mt-12" key={tableType}>
<div className="mb-4">
<p className="text-th-fgd-4">{table.title}</p>
</div>
<Table>
<thead>
<TrHead className="border">
{Object.keys(table.data[0]).map(
(colName: string) => {
return (
<Th
xBorder
className="text-left"
key={colName}
>
{colName}
</Th>
)
}
)}
</TrHead>
</thead>
<tbody>
{table.data.map((rowData, index: number) => {
return (
<TrBody key={index}>
{Object.values(rowData).map(
(
colVal: string | number | PublicKey,
idx: number
) => {
return (
<Td
xBorder
className="text-left"
key={idx}
>
{formatValue(colVal)}
</Td>
)
}
)}
</TrBody>
)
})}
</tbody>
</Table>
</div>
)
}
)}
</div>
) : (
'Loading'

View File

@ -21,10 +21,10 @@
dependencies:
ws "^8.13.0"
"@blockworks-foundation/mango-v4@^0.14.2":
version "0.14.2"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.14.2.tgz#7be5f5bfc8de6c59740a1b1471dde54812cb4e30"
integrity sha512-BWPymt0cFfIH6xHiCoTfZTSZ7M5ne2wH8AbeLROopYPZn0Aur8mds4ohW03RJXmIBBrpE0AMelGyWDRxP5f+EQ==
"@blockworks-foundation/mango-v4@^0.15.0":
version "0.15.0"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.15.0.tgz#d9548daa038168c50d22617420d134811666a782"
integrity sha512-/u/7P7B2BQUdZ9Ee3BAPwNX+lvSBw6CD3DczySZ18DO4NB2YJycqIjIC3Nm7ulZTScJp/dSf5pU9z/sV9UtAiA==
dependencies:
"@coral-xyz/anchor" "^0.26.0"
"@project-serum/serum" "0.13.65"