Skip to content

Commit 073f108

Browse files
authored
Merge pull request #162 from curvefi/task/max-ltv
task: show MAX LTV
2 parents 1f4024b + 63e45ec commit 073f108

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

apps/lend/src/components/DetailsMarket/components/MarketParameters.tsx

+36-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SubTitle } from '@/components/DetailsMarket/styles'
88
import Box from '@/ui/Box'
99
import Chip from '@/ui/Typography/Chip'
1010
import DetailInfo from '@/ui/DetailInfo'
11+
import Icon from '@/ui/Icon'
1112

1213
const MarketParameters = ({
1314
rChainId,
@@ -18,6 +19,7 @@ const MarketParameters = ({
1819
rOwmId: string
1920
type: 'borrow' | 'supply'
2021
}) => {
22+
const isAdvanceMode = useStore((state) => state.isAdvanceMode)
2123
const owmData = useStore((state) => state.markets.owmDatasMapper[rChainId]?.[rOwmId])
2224
const loanPricesResp = useStore((state) => state.markets.pricesMapper[rChainId]?.[rOwmId])
2325
const parametersResp = useStore((state) => state.markets.statsParametersMapper[rChainId]?.[rOwmId])
@@ -29,14 +31,15 @@ const MarketParameters = ({
2931
const { pricePerShare, error: pricePerShareError } = vaultPricePerShareResp ?? {}
3032

3133
// prettier-ignore
32-
const marketDetails: { label: string; value: string | number | undefined; formatOptions?: NumberFormatOptions; title?: string; isError: string; isRow?: boolean }[][] = type === 'borrow' ?
34+
const marketDetails: { label: string; value: string | number | undefined; formatOptions?: NumberFormatOptions; title?: string; isError: string; isRow?: boolean, isAdvance?: boolean; tooltip?: string }[][] = type === 'borrow' ?
3335
[
3436
[
3537
{ label: t`AMM swap fee`, value: parameters?.fee, formatOptions: { ...FORMAT_OPTIONS.PERCENT, maximumSignificantDigits: 3 }, isError: parametersError },
3638
{ label: t`Admin fee`, value: parameters?.admin_fee, formatOptions: { ...FORMAT_OPTIONS.PERCENT, maximumSignificantDigits: 3 }, isError: parametersError },
3739
{ label: t`A`, value: parameters?.A, formatOptions: { useGrouping: false }, isError: parametersError },
3840
{ label: t`Loan discount`, value: parameters?.loan_discount, formatOptions: { ...FORMAT_OPTIONS.PERCENT, maximumSignificantDigits: 2 }, isError: parametersError },
3941
{ label: t`Liquidation discount`, value: parameters?.liquidation_discount, formatOptions: { ...FORMAT_OPTIONS.PERCENT, maximumSignificantDigits: 2 }, isError: parametersError },
42+
{ label: t`Max LTV`, value: _getMaxLTV( parameters?.A, parameters?.loan_discount), formatOptions: { ...FORMAT_OPTIONS.PERCENT, maximumSignificantDigits: 2 }, isError: parametersError, isAdvance: true, tooltip: t`Max possible loan at N=4` },
4043
],
4144
[
4245
{ label: t`Base price`, value: prices?.basePrice, formatOptions: { showAllFractionDigits: true }, title: t`Prices`, isError: pricesError },
@@ -59,24 +62,32 @@ const MarketParameters = ({
5962
const isError = (idx === 0 && !!parametersError) || (idx === 1 && pricesError)
6063
return (
6164
<div key={`details-${idx}`}>
62-
{details.map(({ label, value, formatOptions, title, isError, isRow }) => {
65+
{details.map(({ label, value, formatOptions, title, isError, isRow, isAdvance, tooltip }) => {
66+
const show = typeof isAdvance === 'undefined' || (isAdvance && isAdvanceMode)
6367
return (
6468
<React.Fragment key={label}>
65-
{title && <SubTitle>{title}</SubTitle>}
66-
{isRow ? (
67-
<Box grid>
68-
<Chip isBold>{label}:</Chip>
69-
<strong>{formatNumber(value, { ...(formatOptions ?? {}), defaultValue: '-' })}</strong>
70-
</Box>
71-
) : (
72-
<DetailInfo key={label} label={label}>
73-
{isError ? (
74-
'?'
69+
{show ? (
70+
<>
71+
{title && <SubTitle>{title}</SubTitle>}
72+
{isRow ? (
73+
<Box grid>
74+
<Chip isBold>{label}:</Chip>
75+
<strong>{formatNumber(value, { ...(formatOptions ?? {}), defaultValue: '-' })}</strong>
76+
</Box>
7577
) : (
76-
<strong>{formatNumber(value, { ...(formatOptions ?? {}), defaultValue: '-' })}</strong>
78+
<DetailInfo key={label} label={label}>
79+
{isError ? (
80+
'?'
81+
) : (
82+
<Chip {...(tooltip ? { tooltip, tooltipProps: { noWrap: true } } : {})} isBold>
83+
{formatNumber(value, { ...(formatOptions ?? {}), defaultValue: '-' })}
84+
{tooltip && <Icon className="svg-tooltip" name="InformationSquare" size={16} />}
85+
</Chip>
86+
)}
87+
</DetailInfo>
7788
)}
78-
</DetailInfo>
79-
)}
89+
</>
90+
) : null}
8091
</React.Fragment>
8192
)
8293
})}
@@ -87,4 +98,14 @@ const MarketParameters = ({
8798
)
8899
}
89100

101+
// In [1]: ltv = lambda x: ((x[0] - 1) / x[0])**2 * (1 - x[1])
102+
// In [2]: ltv((30, 0.11))
103+
// Out[2]: 0.8316555555555556
104+
// where x[0] is A, x[1] is loan discount normalised between 0 and 1 (so 11% is 0.11). multiply ltv by 100 to show percentage.
105+
// always show 'max ltv' which is the max possible loan at N=4 (not advisable but hey it exists!).
106+
function _getMaxLTV(a: string | undefined, loanDiscount: string | undefined) {
107+
if (typeof a === 'undefined' || typeof loanDiscount === 'undefined') return ''
108+
return ((+a - 1) / +a) ** 2 * (1 - +loanDiscount / 100) * 100
109+
}
110+
90111
export default MarketParameters

0 commit comments

Comments
 (0)