mango-v4-ui/components/token/TokenParams.tsx

215 lines
8.4 KiB
TypeScript
Raw Normal View History

2023-04-30 19:16:29 -07:00
import {
Bank,
I80F48,
toUiDecimals,
toUiDecimalsForQuote,
} from '@blockworks-foundation/mango-v4'
import Tooltip from '@components/shared/Tooltip'
import { ArrowTopRightOnSquareIcon } from '@heroicons/react/20/solid'
import { BN } from '@coral-xyz/anchor'
2023-05-02 21:19:50 -07:00
import mangoStore from '@store/mangoStore'
2023-05-01 03:55:22 -07:00
import { getOracleProvider } from 'hooks/useOracleProvider'
2023-04-30 19:16:29 -07:00
import { useTranslation } from 'next-i18next'
import { useMemo } from 'react'
2023-05-01 03:55:22 -07:00
import { formatCurrencyValue } from 'utils/numbers'
2023-04-30 19:16:29 -07:00
const TokenParams = ({ bank }: { bank: Bank }) => {
const { t } = useTranslation(['common', 'activity', 'token'])
const [oracleProvider, oracleLinkPath] = useMemo(() => {
2023-05-01 03:55:22 -07:00
if (!bank) return ['Unavaliable', '']
return getOracleProvider(bank)
2023-04-30 19:16:29 -07:00
}, [bank])
2023-05-02 21:19:50 -07:00
const mintInfo = useMemo(() => {
const group = mangoStore.getState().group
if (!bank || !group) return
return group.mintInfosMapByMint.get(bank.mint.toString())
}, [bank])
2023-04-30 19:16:29 -07:00
return (
<div className="grid grid-cols-1 border-b border-th-bkg-3 md:grid-cols-2">
<div className="col-span-1 border-b border-th-bkg-3 px-6 py-4 md:col-span-2">
2023-05-01 03:55:22 -07:00
<h2 className="text-base">{`${bank.name} ${t('token:parameters')}`}</h2>
2023-04-30 19:16:29 -07:00
</div>
<div className="col-span-1 px-6 pt-4 md:border-r md:border-th-bkg-3">
2023-04-30 19:16:29 -07:00
<div className="flex justify-between pb-4">
<Tooltip content={t('token:tooltip-init-asset-liability-weight')}>
<p className="tooltip-underline">
{t('token:init-asset-liability-weight')}
</p>
</Tooltip>
<div className="flex space-x-2">
<p className="font-mono text-th-fgd-2">
{bank.scaledInitAssetWeight(bank.price).toFixed(2)}
2023-04-30 19:16:29 -07:00
</p>
<span className="text-th-fgd-4">|</span>
2023-05-02 17:26:32 -07:00
<p className="font-mono text-th-fgd-2">
{bank.scaledInitLiabWeight(bank.price).toFixed(2)}
2023-05-02 17:26:32 -07:00
</p>
2023-04-30 19:16:29 -07:00
</div>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip content={t('token:tooltip-maint-asset-liability-weight')}>
<p className="tooltip-underline">
{t('token:maint-asset-liability-weight')}
</p>
</Tooltip>
<div className="flex space-x-2">
<p className="font-mono text-th-fgd-2">
{bank.maintAssetWeight.toFixed(2)}
</p>
<span className="text-th-fgd-4">|</span>
2023-05-02 17:26:32 -07:00
<p className="font-mono text-th-fgd-2">
{bank.maintLiabWeight.toFixed(2)}
</p>
2023-04-30 19:16:29 -07:00
</div>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip content={t('tooltip-borrow-fee')}>
<p className="tooltip-underline">{t('borrow-fee')}</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
{(100 * bank.loanOriginationFeeRate.toNumber()).toFixed(2)}%
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
2023-05-01 03:55:22 -07:00
<Tooltip content={t('token:tooltip-borrow-upkeep-rate')}>
<p className="tooltip-underline">{t('token:borrow-upkeep-rate')}</p>
2023-04-30 19:16:29 -07:00
</Tooltip>
<p className="font-mono text-th-fgd-2">
{(100 * bank.loanFeeRate.toNumber()).toFixed(2)}%
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip
content={t('token:tooltip-liquidation-fee', { symbol: bank.name })}
>
<p className="tooltip-underline">{t('activity:liquidation-fee')}</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
{(bank.liquidationFee.toNumber() * 100).toFixed(2)}%
</p>
</div>
2023-05-02 21:19:50 -07:00
{mintInfo ? (
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip
content={t('trade:tooltip-insured', { tokenOrMarket: bank.name })}
>
<p className="tooltip-underline">
{t('trade:insured', { token: '' })}
</p>
</Tooltip>
<p className="text-th-fgd-2">
{mintInfo.groupInsuranceFund ? t('yes') : t('no')}
</p>
</div>
) : null}
2023-04-30 19:16:29 -07:00
<div className="flex justify-between border-y border-th-bkg-3 py-4 md:border-b-0">
<Tooltip content={t('token:tooltip-deposit-borrow-scaling-start')}>
<p className="tooltip-underline">
{t('token:deposit-borrow-scaling-start')}
</p>
</Tooltip>
<div className="flex space-x-2">
<p className="font-mono text-th-fgd-2">
{bank.name === 'USDC'
? `$${toUiDecimalsForQuote(
2023-07-21 11:47:53 -07:00
bank.depositWeightScaleStartQuote,
).toExponential(1)}`
: formatCurrencyValue(
2023-07-21 11:47:53 -07:00
toUiDecimalsForQuote(bank.depositWeightScaleStartQuote),
)}
2023-04-30 19:16:29 -07:00
</p>
<span className="text-th-fgd-4">|</span>
<p className="font-mono text-th-fgd-2">
{bank.name === 'USDC'
? `$${toUiDecimalsForQuote(
2023-07-21 11:47:53 -07:00
bank.depositWeightScaleStartQuote,
).toExponential(1)}`
: formatCurrencyValue(
2023-07-21 11:47:53 -07:00
toUiDecimalsForQuote(bank.borrowWeightScaleStartQuote),
)}
2023-04-30 19:16:29 -07:00
</p>
</div>
</div>
</div>
<div className="col-span-1 px-6 pb-4 md:pt-4">
<div className="flex justify-between pb-4">
2023-05-01 03:55:22 -07:00
<Tooltip content={t('token:tooltip-net-borrow-period')}>
<p className="tooltip-underline">{t('token:net-borrow-period')}</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
2023-05-02 20:05:23 -07:00
{bank.netBorrowLimitWindowSizeTs.div(new BN(3600)).toNumber()}h
2023-05-01 03:55:22 -07:00
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
2023-04-30 19:16:29 -07:00
<Tooltip content={t('token:tooltip-net-borrows-in-period')}>
<p className="tooltip-underline">
{t('token:net-borrows-in-period')}
</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
2023-05-01 03:55:22 -07:00
{formatCurrencyValue(
toUiDecimalsForQuote(
2023-07-21 11:47:53 -07:00
I80F48.fromI64(bank.netBorrowsInWindow).mul(bank.price),
),
2023-04-30 19:16:29 -07:00
)}
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip content={t('token:tooltip-net-borrow-limit-in-period')}>
<p className="tooltip-underline">
{t('token:net-borrow-limit-in-period')}
</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
2023-05-01 03:55:22 -07:00
{formatCurrencyValue(
2023-07-21 11:47:53 -07:00
toUiDecimals(bank.netBorrowLimitPerWindowQuote, 6),
2023-04-30 19:16:29 -07:00
)}
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<p>{t('token:oracle')}</p>
2023-05-29 20:35:19 -07:00
{oracleLinkPath ? (
<a
className="flex items-center"
href={oracleLinkPath}
target="_blank"
rel="noopener noreferrer"
>
<span className="mr-1.5">{oracleProvider}</span>
<ArrowTopRightOnSquareIcon className="h-4 w-4" />
</a>
) : (
<p className="text-th-fgd-2">{oracleProvider}</p>
)}
2023-04-30 19:16:29 -07:00
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip content={t('token:tooltip-oracle-confidence')}>
<p className="tooltip-underline">{t('token:oracle-confidence')}</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
{(100 * bank.oracleConfig.confFilter.toNumber()).toFixed(2)}%
</p>
</div>
<div className="flex justify-between border-t border-th-bkg-3 py-4">
<Tooltip
content={t('token:tooltip-oracle-staleness', {
slots: bank.oracleConfig.maxStalenessSlots.toNumber(),
})}
>
<p className="tooltip-underline">{t('token:oracle-staleness')}</p>
</Tooltip>
<p className="font-mono text-th-fgd-2">
{bank.oracleConfig.maxStalenessSlots.toNumber()}{' '}
<span className="font-body text-th-fgd-4">Slots</span>
</p>
</div>
</div>
</div>
)
}
export default TokenParams