[bugfix] fix leverage and implement buffer for health (#374)
* [bugfix] fix leverage and implement buffer for health * [bugfix] properly remove council page from nav * [bugfix] ensure integer values for HC * [bugfix] infinite rerender withdraw + negative values
This commit is contained in:
parent
de185bf823
commit
9712573b00
@ -61,7 +61,7 @@ function AccountDetails(props: Props) {
|
|||||||
options={{ maxDecimals: 0, minDecimals: 0, suffix: '%' }}
|
options={{ maxDecimals: 0, minDecimals: 0, suffix: '%' }}
|
||||||
animate
|
animate
|
||||||
/>
|
/>
|
||||||
{updatedHealth && health !== updatedHealth && (
|
{updatedHealth > 0 && health !== updatedHealth && (
|
||||||
<>
|
<>
|
||||||
<ArrowRight
|
<ArrowRight
|
||||||
width={16}
|
width={16}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
import { Suspense } from 'react'
|
|
||||||
import { useParams } from 'react-router-dom'
|
|
||||||
|
|
||||||
import Card from 'components/Card'
|
|
||||||
import Loading from 'components/Loading'
|
|
||||||
import Text from 'components/Text'
|
|
||||||
|
|
||||||
function Content() {
|
|
||||||
const address = useParams().address || ''
|
|
||||||
|
|
||||||
return address ? (
|
|
||||||
<Text size='sm'>{`Council page for ${address}`}</Text>
|
|
||||||
) : (
|
|
||||||
<Text size='sm'>Council view only</Text>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Fallback() {
|
|
||||||
return <Loading className='h-4 w-50' />
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Overview() {
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
className='h-fit w-full justify-center bg-white/5'
|
|
||||||
title='Council'
|
|
||||||
contentClassName='px-4 py-6'
|
|
||||||
>
|
|
||||||
<Suspense fallback={<Fallback />}>
|
|
||||||
<Content />
|
|
||||||
</Suspense>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ export const menuTree: { page: Page; label: string }[] = [
|
|||||||
{ page: 'lend', label: 'Earn' },
|
{ page: 'lend', label: 'Earn' },
|
||||||
{ page: 'borrow', label: 'Borrow' },
|
{ page: 'borrow', label: 'Borrow' },
|
||||||
{ page: 'portfolio', label: 'Portfolio' },
|
{ page: 'portfolio', label: 'Portfolio' },
|
||||||
{ page: 'council', label: 'Council' },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function DesktopHeader() {
|
export default function DesktopHeader() {
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BN_ZERO } from 'constants/math'
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { HEALTH_BUFFER } from 'utils/constants'
|
||||||
|
|
||||||
export default function useHealthComputer(account?: Account) {
|
export default function useHealthComputer(account?: Account) {
|
||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
@ -41,7 +42,6 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
[prices, baseCurrency.denom],
|
[prices, baseCurrency.denom],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const vaultPositionValues = useMemo(() => {
|
const vaultPositionValues = useMemo(() => {
|
||||||
if (!account?.vaults) return null
|
if (!account?.vaults) return null
|
||||||
return account.vaults.reduce(
|
return account.vaults.reduce(
|
||||||
@ -141,6 +141,8 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
(denom: string, target: BorrowTarget) => {
|
(denom: string, target: BorrowTarget) => {
|
||||||
if (!healthComputer) return BN_ZERO
|
if (!healthComputer) return BN_ZERO
|
||||||
return BN(max_borrow_estimate_js(healthComputer, denom, target))
|
return BN(max_borrow_estimate_js(healthComputer, denom, target))
|
||||||
|
.times(1 - HEALTH_BUFFER)
|
||||||
|
.integerValue()
|
||||||
},
|
},
|
||||||
[healthComputer],
|
[healthComputer],
|
||||||
)
|
)
|
||||||
@ -149,6 +151,8 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
(denom: string) => {
|
(denom: string) => {
|
||||||
if (!healthComputer) return BN_ZERO
|
if (!healthComputer) return BN_ZERO
|
||||||
return BN(max_withdraw_estimate_js(healthComputer, denom))
|
return BN(max_withdraw_estimate_js(healthComputer, denom))
|
||||||
|
.times(1 - HEALTH_BUFFER)
|
||||||
|
.integerValue()
|
||||||
},
|
},
|
||||||
[healthComputer],
|
[healthComputer],
|
||||||
)
|
)
|
||||||
@ -158,6 +162,8 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
if (!healthComputer) return BN_ZERO
|
if (!healthComputer) return BN_ZERO
|
||||||
try {
|
try {
|
||||||
return BN(max_swap_estimate_js(healthComputer, from, to, kind))
|
return BN(max_swap_estimate_js(healthComputer, from, to, kind))
|
||||||
|
.times(1 - HEALTH_BUFFER)
|
||||||
|
.integerValue()
|
||||||
} catch {
|
} catch {
|
||||||
return BN_ZERO
|
return BN_ZERO
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,17 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
(denom: string) => {
|
(denom: string) => {
|
||||||
if (!account) return
|
if (!account) return
|
||||||
const deposit = account.deposits.find((deposit) => deposit.denom === denom)
|
const deposit = account.deposits.find((deposit) => deposit.denom === denom)
|
||||||
|
|
||||||
if (deposit) {
|
if (deposit) {
|
||||||
removeDeposits([...removedDeposits, deposit])
|
removeDeposits((prevRemovedDeposits) => {
|
||||||
|
return [
|
||||||
|
...prevRemovedDeposits.filter((removedDeposit) => removedDeposit.denom !== denom),
|
||||||
|
deposit,
|
||||||
|
]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[account, removedDeposits],
|
[account, removeDeposits],
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -79,7 +79,8 @@ export const calculateAccountBorrowRate = (
|
|||||||
|
|
||||||
export function calculateAccountLeverage(account: Account, prices: BNCoin[]) {
|
export function calculateAccountLeverage(account: Account, prices: BNCoin[]) {
|
||||||
const [deposits, lends, debts, vaults] = getAccountPositionValues(account, prices)
|
const [deposits, lends, debts, vaults] = getAccountPositionValues(account, prices)
|
||||||
return debts.dividedBy(deposits.plus(lends).plus(vaults)).plus(1)
|
const netValue = deposits.plus(lends).plus(vaults).minus(debts)
|
||||||
|
return debts.dividedBy(netValue).plus(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAmount(denom: string, coins: Coin[]): BigNumber {
|
export function getAmount(denom: string, coins: Coin[]): BigNumber {
|
||||||
|
@ -9,3 +9,5 @@ export const defaultFee: StdFee = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SECONDS_IN_A_YEAR = 31540000
|
export const SECONDS_IN_A_YEAR = 31540000
|
||||||
|
|
||||||
|
export const HEALTH_BUFFER = 0.01
|
||||||
|
Loading…
Reference in New Issue
Block a user